| author | |
| committer | |
| log | 5d55999d20c4d856ad9e0bd35a939e4aa3be3d0d |
| tree | c81bd55f63788495753a0086ec655e10427c8f1a |
| parent | 2407ee954b780e5a6a73f88b0865feff365c5ce5 |
| parent | bb83883acd9dee65423e836729eb0242c5e218ca |
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/32130212 files changed, 1092 insertions(+), 1948 deletions(-)
doc/langref.html.in+7-37| ... | @@ -624,11 +624,6 @@ | ... | @@ -624,11 +624,6 @@ |
| 624 | <td><code class="c">void</code></td> | 624 | <td><code class="c">void</code></td> |
| 625 | <td>Used for type-erased pointers.</td> | 625 | <td>Used for type-erased pointers.</td> |
| 626 | </tr> | 626 | </tr> |
| 627 | <tr> | ||
| 628 | <th scope="row">{#syntax#}void{#endsyntax#}</th> | ||
| 629 | <td>(none)</td> | ||
| 630 | <td>Always the value {#syntax#}void{}{#endsyntax#}</td> | ||
| 631 | </tr> | ||
| 632 | <tr> | 627 | <tr> |
| 633 | <th scope="row">{#syntax#}noreturn{#endsyntax#}</th> | 628 | <th scope="row">{#syntax#}noreturn{#endsyntax#}</th> |
| 634 | <td>(none)</td> | 629 | <td>(none)</td> |
| ... | @@ -1806,25 +1801,6 @@ const together = array1 ++ array2; | ... | @@ -1806,25 +1801,6 @@ const together = array1 ++ array2; |
| 1806 | mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre> | 1801 | mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre> |
| 1807 | </td> | 1802 | </td> |
| 1808 | </tr> | 1803 | </tr> |
| 1809 | <tr> | ||
| 1810 | <td>Array Multiplication</td> | ||
| 1811 | <td><pre>{#syntax#}a ** b{#endsyntax#}</pre></td> | ||
| 1812 | <td> | ||
| 1813 | <ul> | ||
| 1814 | <li>{#link|Arrays#}</li> | ||
| 1815 | </ul> | ||
| 1816 | </td> | ||
| 1817 | <td> | ||
| 1818 | <ul> | ||
| 1819 | <li>Only available when the length of {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li> | ||
| 1820 | </ul> | ||
| 1821 | </td> | ||
| 1822 | <td> | ||
| 1823 | <pre>{#syntax#}const mem = @import("std").mem; | ||
| 1824 | const pattern = "ab" ** 3; | ||
| 1825 | mem.eql(u8, pattern, "ababab"){#endsyntax#}</pre> | ||
| 1826 | </td> | ||
| 1827 | </tr> | ||
| 1828 | <tr> | 1804 | <tr> |
| 1829 | <td>Pointer Dereference</td> | 1805 | <td>Pointer Dereference</td> |
| 1830 | <td><pre>{#syntax#}a.*{#endsyntax#}</pre></td> | 1806 | <td><pre>{#syntax#}a.*{#endsyntax#}</pre></td> |
| ... | @@ -1882,7 +1858,7 @@ const B = error{Two}; | ... | @@ -1882,7 +1858,7 @@ const B = error{Two}; |
| 1882 | a!b | 1858 | a!b |
| 1883 | x{} | 1859 | x{} |
| 1884 | !x -x -%x ~x &x ?x | 1860 | !x -x -%x ~x &x ?x |
| 1885 | * / % ** *% *| || | 1861 | * / % *% *| || |
| 1886 | + - ++ +% -% +| -| | 1862 | + - ++ +% -% +| -| |
| 1887 | << >> <<| | 1863 | << >> <<| |
| 1888 | & ^ | orelse catch | 1864 | & ^ | orelse catch |
| ... | @@ -2371,7 +2347,7 @@ or | ... | @@ -2371,7 +2347,7 @@ or |
| 2371 | </p> | 2347 | </p> |
| 2372 | <p> | 2348 | <p> |
| 2373 | Like arrays, tuples have a .len field, can be indexed (provided the index is comptime-known) | 2349 | Like arrays, tuples have a .len field, can be indexed (provided the index is comptime-known) |
| 2374 | and work with the ++ and ** operators. They can also be iterated over with {#link|inline for#}. | 2350 | and work with the ++ operator. They can also be iterated over with {#link|inline for#}. |
| 2375 | </p> | 2351 | </p> |
| 2376 | {#code|test_tuples.zig#} | 2352 | {#code|test_tuples.zig#} |
| 2377 | 2353 | ||
| ... | @@ -2571,7 +2547,7 @@ or | ... | @@ -2571,7 +2547,7 @@ or |
| 2571 | {#header_close#} | 2547 | {#header_close#} |
| 2572 | 2548 | ||
| 2573 | {#header_open|Empty Blocks#} | 2549 | {#header_open|Empty Blocks#} |
| 2574 | <p>An empty block is equivalent to {#syntax#}void{}{#endsyntax#}:</p> | 2550 | <p>An empty block returns the single value of type {#syntax#}void{#endsyntax#}:</p> |
| 2575 | {#code|test_empty_block.zig#} | 2551 | {#code|test_empty_block.zig#} |
| 2576 | 2552 | ||
| 2577 | {#header_close#} | 2553 | {#header_close#} |
| ... | @@ -3159,10 +3135,6 @@ fn createFoo(param: i32) !Foo { | ... | @@ -3159,10 +3135,6 @@ fn createFoo(param: i32) !Foo { |
| 3159 | the verbosity and cognitive overhead of trying to make sure every exit path | 3135 | the verbosity and cognitive overhead of trying to make sure every exit path |
| 3160 | is covered. The deallocation code is always directly following the allocation code. | 3136 | is covered. The deallocation code is always directly following the allocation code. |
| 3161 | </p> | 3137 | </p> |
| 3162 | <p> | ||
| 3163 | The {#syntax#}errdefer{#endsyntax#} statement can optionally capture the error: | ||
| 3164 | </p> | ||
| 3165 | {#code|test_errdefer_capture.zig#} | ||
| 3166 | {#header_close#} | 3138 | {#header_close#} |
| 3167 | <p> | 3139 | <p> |
| 3168 | A couple of other tidbits about error handling: | 3140 | A couple of other tidbits about error handling: |
| ... | @@ -3627,7 +3599,7 @@ void do_a_thing(struct Foo *foo) { | ... | @@ -3627,7 +3599,7 @@ void do_a_thing(struct Foo *foo) { |
| 3627 | <p>For some types, {#link|@sizeOf#} is 0:</p> | 3599 | <p>For some types, {#link|@sizeOf#} is 0:</p> |
| 3628 | <ul> | 3600 | <ul> |
| 3629 | <li>{#link|void#}</li> | 3601 | <li>{#link|void#}</li> |
| 3630 | <li>The {#link|Integers#} {#syntax#}u0{#endsyntax#} and {#syntax#}i0{#endsyntax#}.</li> | 3602 | <li>The {#link|integer type|Integers#} {#syntax#}u0{#endsyntax#}.</li> |
| 3631 | <li>{#link|Arrays#} and {#link|Vectors#} with len 0, or with an element type that is a zero bit type.</li> | 3603 | <li>{#link|Arrays#} and {#link|Vectors#} with len 0, or with an element type that is a zero bit type.</li> |
| 3632 | <li>An {#link|enum#} with only 1 tag.</li> | 3604 | <li>An {#link|enum#} with only 1 tag.</li> |
| 3633 | <li>A {#link|struct#} with all fields being zero bit types.</li> | 3605 | <li>A {#link|struct#} with all fields being zero bit types.</li> |
| ... | @@ -7774,7 +7746,7 @@ ContainerField <- doc_comment? (KEYWORD_comptime / !KEYWORD_comptime) !KEYWORD_f | ... | @@ -7774,7 +7746,7 @@ ContainerField <- doc_comment? (KEYWORD_comptime / !KEYWORD_comptime) !KEYWORD_f |
| 7774 | BlockStatement | 7746 | BlockStatement |
| 7775 | <- Statement | 7747 | <- Statement |
| 7776 | / KEYWORD_defer BlockExprStatement | 7748 | / KEYWORD_defer BlockExprStatement |
| 7777 | / KEYWORD_errdefer Payload? BlockExprStatement | 7749 | / KEYWORD_errdefer BlockExprStatement |
| 7778 | / !ExprStatement (KEYWORD_comptime !BlockExpr)? VarAssignStatement | 7750 | / !ExprStatement (KEYWORD_comptime !BlockExpr)? VarAssignStatement |
| 7779 | 7751 | ||
| 7780 | Statement | 7752 | Statement |
| ... | @@ -8036,7 +8008,6 @@ MultiplyOp | ... | @@ -8036,7 +8008,6 @@ MultiplyOp |
| 8036 | / ASTERISK | 8008 | / ASTERISK |
| 8037 | / SLASH | 8009 | / SLASH |
| 8038 | / PERCENT | 8010 | / PERCENT |
| 8039 | / ASTERISK2 | ||
| 8040 | / ASTERISKPERCENT | 8011 | / ASTERISKPERCENT |
| 8041 | / ASTERISKPIPE | 8012 | / ASTERISKPIPE |
| 8042 | 8013 | ||
| ... | @@ -8083,11 +8054,11 @@ LabelableExpr | ... | @@ -8083,11 +8054,11 @@ LabelableExpr |
| 8083 | # Ptr specific | 8054 | # Ptr specific |
| 8084 | SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET | 8055 | SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET |
| 8085 | 8056 | ||
| 8086 | SinglePtrTypeStart <- ASTERISK / ASTERISK2 | 8057 | SinglePtrTypeStart <- ASTERISK |
| 8087 | 8058 | ||
| 8088 | ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET | 8059 | ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET |
| 8089 | 8060 | ||
| 8090 | ArrayTypeStart <- LBRACKET Expr !(ASTERISK / ASTERISK2) (COLON Expr)? RBRACKET | 8061 | ArrayTypeStart <- LBRACKET Expr !ASTERISK (COLON Expr)? RBRACKET |
| 8091 | 8062 | ||
| 8092 | # ContainerDecl specific | 8063 | # ContainerDecl specific |
| 8093 | ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE | 8064 | ContainerDeclAuto <- ContainerDeclType LBRACE ContainerMembers RBRACE |
| ... | @@ -8215,7 +8186,6 @@ BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip | ... | @@ -8215,7 +8186,6 @@ BUILTINIDENTIFIER <- '@'[A-Za-z_][A-Za-z0-9_]* skip |
| 8215 | AMPERSAND <- '&' ![=] skip | 8186 | AMPERSAND <- '&' ![=] skip |
| 8216 | AMPERSANDEQUAL <- '&=' skip | 8187 | AMPERSANDEQUAL <- '&=' skip |
| 8217 | ASTERISK <- '*' ![*%=|] skip | 8188 | ASTERISK <- '*' ![*%=|] skip |
| 8218 | ASTERISK2 <- '**' skip | ||
| 8219 | ASTERISKEQUAL <- '*=' skip | 8189 | ASTERISKEQUAL <- '*=' skip |
| 8220 | ASTERISKPERCENT <- '*%' ![=] skip | 8190 | ASTERISKPERCENT <- '*%' ![=] skip |
| 8221 | ASTERISKPERCENTEQUAL <- '*%=' skip | 8191 | ASTERISKPERCENTEQUAL <- '*%=' skip |
doc/langref/test_arrays.zig+2-8| ... | @@ -60,14 +60,8 @@ comptime { | ... | @@ -60,14 +60,8 @@ comptime { |
| 60 | assert(mem.eql(u8, hello_world, "hello world")); | 60 | assert(mem.eql(u8, hello_world, "hello world")); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | // ** does repeating patterns | ||
| 64 | const pattern = "ab" ** 3; | ||
| 65 | comptime { | ||
| 66 | assert(mem.eql(u8, pattern, "ababab")); | ||
| 67 | } | ||
| 68 | |||
| 69 | // initialize an array to zero | 63 | // initialize an array to zero |
| 70 | const all_zero = [_]u16{0} ** 10; | 64 | const all_zero: [10]u16 = @splat(0); |
| 71 | 65 | ||
| 72 | comptime { | 66 | comptime { |
| 73 | assert(all_zero.len == 10); | 67 | assert(all_zero.len == 10); |
| ... | @@ -96,7 +90,7 @@ test "compile-time array initialization" { | ... | @@ -96,7 +90,7 @@ test "compile-time array initialization" { |
| 96 | } | 90 | } |
| 97 | 91 | ||
| 98 | // call a function to initialize an array | 92 | // call a function to initialize an array |
| 99 | var more_points = [_]Point{makePoint(3)} ** 10; | 93 | var more_points: [10]Point = @splat(makePoint(3)); |
| 100 | fn makePoint(x: i32) Point { | 94 | fn makePoint(x: i32) Point { |
| 101 | return Point{ | 95 | return Point{ |
| 102 | .x = x, | 96 | .x = x, |
doc/langref/test_empty_block.zig-3| ... | @@ -3,10 +3,7 @@ const expectEqual = std.testing.expectEqual; | ... | @@ -3,10 +3,7 @@ const expectEqual = std.testing.expectEqual; |
| 3 | 3 | ||
| 4 | test { | 4 | test { |
| 5 | const a = {}; | 5 | const a = {}; |
| 6 | const b = void{}; | ||
| 7 | try expectEqual(void, @TypeOf(a)); | 6 | try expectEqual(void, @TypeOf(a)); |
| 8 | try expectEqual(void, @TypeOf(b)); | ||
| 9 | try expectEqual(a, b); | ||
| 10 | } | 7 | } |
| 11 | 8 | ||
| 12 | // test | 9 | // test |
doc/langref/test_errdefer_capture.zig deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | fn captureError(captured: *?anyerror) !void { | ||
| 4 | errdefer |err| { | ||
| 5 | captured.* = err; | ||
| 6 | } | ||
| 7 | return error.GeneralFailure; | ||
| 8 | } | ||
| 9 | |||
| 10 | test "errdefer capture" { | ||
| 11 | var captured: ?anyerror = null; | ||
| 12 | |||
| 13 | if (captureError(&captured)) unreachable else |err| { | ||
| 14 | try std.testing.expectEqual(error.GeneralFailure, captured.?); | ||
| 15 | try std.testing.expectEqual(error.GeneralFailure, err); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | // test | ||
doc/langref/test_multidimensional_arrays.zig+1-1| ... | @@ -24,7 +24,7 @@ test "multidimensional arrays" { | ... | @@ -24,7 +24,7 @@ test "multidimensional arrays" { |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | // Initialize a multidimensional array to zeros. | 26 | // Initialize a multidimensional array to zeros. |
| 27 | const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4; | 27 | const all_zero: [4][5]f32 = @splat(@splat(0)); |
| 28 | try expectEqual(0, all_zero[0][0]); | 28 | try expectEqual(0, all_zero[0][0]); |
| 29 | } | 29 | } |
| 30 | 30 |
doc/langref/test_tuples.zig+1-1| ... | @@ -8,7 +8,7 @@ test "tuple" { | ... | @@ -8,7 +8,7 @@ test "tuple" { |
| 8 | @as(f64, 12.34), | 8 | @as(f64, 12.34), |
| 9 | true, | 9 | true, |
| 10 | "hi", | 10 | "hi", |
| 11 | } ++ .{false} ** 2; | 11 | } ++ .{ false, false }; |
| 12 | try expectEqual(1234, values[0]); | 12 | try expectEqual(1234, values[0]); |
| 13 | try expectEqual(false, values[4]); | 13 | try expectEqual(false, values[4]); |
| 14 | inline for (values, 0..) |v, i| { | 14 | inline for (values, 0..) |v, i| { |
lib/compiler/build_runner.zig+1-1| ... | @@ -1557,7 +1557,7 @@ fn printUsage(b: *std.Build, w: *Writer) !void { | ... | @@ -1557,7 +1557,7 @@ fn printUsage(b: *std.Build, w: *Writer) !void { |
| 1557 | const name = try fmt.allocPrint(arena, " -D{s}=[{t}]", .{ option.name, option.type_id }); | 1557 | const name = try fmt.allocPrint(arena, " -D{s}=[{t}]", .{ option.name, option.type_id }); |
| 1558 | try w.print("{s:<30} {s}\n", .{ name, option.description }); | 1558 | try w.print("{s:<30} {s}\n", .{ name, option.description }); |
| 1559 | if (option.enum_options) |enum_options| { | 1559 | if (option.enum_options) |enum_options| { |
| 1560 | const padding = " " ** 33; | 1560 | const padding: [33]u8 = @splat(' '); |
| 1561 | try w.writeAll(padding ++ "Supported Values:\n"); | 1561 | try w.writeAll(padding ++ "Supported Values:\n"); |
| 1562 | for (enum_options) |enum_option| { | 1562 | for (enum_options) |enum_option| { |
| 1563 | try w.print(padding ++ " {s}\n", .{enum_option}); | 1563 | try w.print(padding ++ " {s}\n", .{enum_option}); |
lib/compiler/reduce/Walk.zig+1-6| ... | @@ -223,12 +223,8 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { | ... | @@ -223,12 +223,8 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { |
| 223 | return walkBlock(w, node, statements); | 223 | return walkBlock(w, node, statements); |
| 224 | }, | 224 | }, |
| 225 | 225 | ||
| 226 | .@"errdefer" => { | ||
| 227 | const expr = ast.nodeData(node).opt_token_and_node[1]; | ||
| 228 | return walkExpression(w, expr); | ||
| 229 | }, | ||
| 230 | |||
| 231 | .@"defer", | 226 | .@"defer", |
| 227 | .@"errdefer", | ||
| 232 | .@"comptime", | 228 | .@"comptime", |
| 233 | .@"nosuspend", | 229 | .@"nosuspend", |
| 234 | .@"suspend", | 230 | .@"suspend", |
| ... | @@ -252,7 +248,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { | ... | @@ -252,7 +248,6 @@ fn walkExpression(w: *Walk, node: Ast.Node.Index) Error!void { |
| 252 | .add_wrap, | 248 | .add_wrap, |
| 253 | .add_sat, | 249 | .add_sat, |
| 254 | .array_cat, | 250 | .array_cat, |
| 255 | .array_mult, | ||
| 256 | .assign, | 251 | .assign, |
| 257 | .assign_bit_and, | 252 | .assign_bit_and, |
| 258 | .assign_bit_or, | 253 | .assign_bit_or, |
lib/compiler/resinator/cvtres.zig+4-4| ... | @@ -321,7 +321,7 @@ pub fn writeCoff( | ... | @@ -321,7 +321,7 @@ pub fn writeCoff( |
| 321 | .checksum = 0, | 321 | .checksum = 0, |
| 322 | .number = 0, | 322 | .number = 0, |
| 323 | .selection = .NONE, | 323 | .selection = .NONE, |
| 324 | .unused = .{0} ** 3, | 324 | .unused = @splat(0), |
| 325 | }); | 325 | }); |
| 326 | 326 | ||
| 327 | try writeSymbol(writer, .{ | 327 | try writeSymbol(writer, .{ |
| ... | @@ -342,7 +342,7 @@ pub fn writeCoff( | ... | @@ -342,7 +342,7 @@ pub fn writeCoff( |
| 342 | .checksum = 0, | 342 | .checksum = 0, |
| 343 | .number = 0, | 343 | .number = 0, |
| 344 | .selection = .NONE, | 344 | .selection = .NONE, |
| 345 | .unused = .{0} ** 3, | 345 | .unused = @splat(0), |
| 346 | }); | 346 | }); |
| 347 | 347 | ||
| 348 | for (resource_symbols) |resource_symbol| { | 348 | for (resource_symbols) |resource_symbol| { |
| ... | @@ -353,11 +353,11 @@ pub fn writeCoff( | ... | @@ -353,11 +353,11 @@ pub fn writeCoff( |
| 353 | const name_bytes: [8]u8 = name_bytes: { | 353 | const name_bytes: [8]u8 = name_bytes: { |
| 354 | if (external_symbol_name.len > 8) { | 354 | if (external_symbol_name.len > 8) { |
| 355 | const string_table_offset: u32 = try string_table.put(allocator, external_symbol_name); | 355 | const string_table_offset: u32 = try string_table.put(allocator, external_symbol_name); |
| 356 | var bytes = [_]u8{0} ** 8; | 356 | var bytes: [8]u8 = @splat(0); |
| 357 | std.mem.writeInt(u32, bytes[4..8], string_table_offset, .little); | 357 | std.mem.writeInt(u32, bytes[4..8], string_table_offset, .little); |
| 358 | break :name_bytes bytes; | 358 | break :name_bytes bytes; |
| 359 | } else { | 359 | } else { |
| 360 | var symbol_shortname = [_]u8{0} ** 8; | 360 | var symbol_shortname: [8]u8 = @splat(0); |
| 361 | @memcpy(symbol_shortname[0..external_symbol_name.len], external_symbol_name); | 361 | @memcpy(symbol_shortname[0..external_symbol_name.len], external_symbol_name); |
| 362 | break :name_bytes symbol_shortname; | 362 | break :name_bytes symbol_shortname; |
| 363 | } | 363 | } |
lib/compiler/resinator/ico.zig+4-4| ... | @@ -183,7 +183,7 @@ pub const Entry = struct { | ... | @@ -183,7 +183,7 @@ pub const Entry = struct { |
| 183 | }; | 183 | }; |
| 184 | 184 | ||
| 185 | test "icon" { | 185 | test "icon" { |
| 186 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ [_]u8{0} ** 16; | 186 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 187 | var fbs: std.Io.Reader = .fixed(data); | 187 | var fbs: std.Io.Reader = .fixed(data); |
| 188 | const icon = try read(std.testing.allocator, &fbs, data.len); | 188 | const icon = try read(std.testing.allocator, &fbs, data.len); |
| 189 | defer icon.deinit(); | 189 | defer icon.deinit(); |
| ... | @@ -196,19 +196,19 @@ test "icon too many images" { | ... | @@ -196,19 +196,19 @@ test "icon too many images" { |
| 196 | // Note that with verifying that all data sizes are within the file bounds and >= 16, | 196 | // Note that with verifying that all data sizes are within the file bounds and >= 16, |
| 197 | // it's not possible to hit EOF when looking for more RESDIR structures, since they are | 197 | // it's not possible to hit EOF when looking for more RESDIR structures, since they are |
| 198 | // themselves 16 bytes long, so we'll always hit ImpossibleDataSize instead. | 198 | // themselves 16 bytes long, so we'll always hit ImpossibleDataSize instead. |
| 199 | const data = "\x00\x00\x01\x00\x02\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ [_]u8{0} ** 16; | 199 | const data = "\x00\x00\x01\x00\x02\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x16\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 200 | var fbs: std.Io.Reader = .fixed(data); | 200 | var fbs: std.Io.Reader = .fixed(data); |
| 201 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); | 201 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | test "icon data size past EOF" { | 204 | test "icon data size past EOF" { |
| 205 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x01\x00\x00\x16\x00\x00\x00" ++ [_]u8{0} ** 16; | 205 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x01\x00\x00\x16\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 206 | var fbs: std.Io.Reader = .fixed(data); | 206 | var fbs: std.Io.Reader = .fixed(data); |
| 207 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); | 207 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | test "icon data offset past EOF" { | 210 | test "icon data offset past EOF" { |
| 211 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x17\x00\x00\x00" ++ [_]u8{0} ** 16; | 211 | const data = "\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x10\x00\x10\x00\x00\x00\x17\x00\x00\x00" ++ @as([16]u8, @splat(0)); |
| 212 | var fbs: std.Io.Reader = .fixed(data); | 212 | var fbs: std.Io.Reader = .fixed(data); |
| 213 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); | 213 | try std.testing.expectError(error.ImpossibleDataSize, read(std.testing.allocator, &fbs, data.len)); |
| 214 | } | 214 | } |
lib/compiler/resinator/parse.zig+2-2| ... | @@ -138,8 +138,8 @@ pub const Parser = struct { | ... | @@ -138,8 +138,8 @@ pub const Parser = struct { |
| 138 | var optional_statements: std.ArrayList(*Node) = .empty; | 138 | var optional_statements: std.ArrayList(*Node) = .empty; |
| 139 | 139 | ||
| 140 | const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len; | 140 | const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len; |
| 141 | var statement_type_has_duplicates = [_]bool{false} ** num_statement_types; | 141 | var statement_type_has_duplicates: [num_statement_types]bool = @splat(false); |
| 142 | var last_statement_per_type = [_]?*Node{null} ** num_statement_types; | 142 | var last_statement_per_type: [num_statement_types]?*Node = @splat(null); |
| 143 | 143 | ||
| 144 | while (true) { | 144 | while (true) { |
| 145 | const lookahead_token = try self.lookaheadToken(.normal); | 145 | const lookahead_token = try self.lookaheadToken(.normal); |
lib/compiler/resinator/res.zig+1-1| ... | @@ -1068,7 +1068,7 @@ pub const FixedFileInfo = struct { | ... | @@ -1068,7 +1068,7 @@ pub const FixedFileInfo = struct { |
| 1068 | pub const key = std.unicode.utf8ToUtf16LeStringLiteral("VS_VERSION_INFO"); | 1068 | pub const key = std.unicode.utf8ToUtf16LeStringLiteral("VS_VERSION_INFO"); |
| 1069 | 1069 | ||
| 1070 | pub const Version = struct { | 1070 | pub const Version = struct { |
| 1071 | parts: [4]u16 = [_]u16{0} ** 4, | 1071 | parts: [4]u16 = @splat(0), |
| 1072 | 1072 | ||
| 1073 | pub fn mostSignificantCombinedParts(self: Version) u32 { | 1073 | pub fn mostSignificantCombinedParts(self: Version) u32 { |
| 1074 | return (@as(u32, self.parts[0]) << 16) + self.parts[1]; | 1074 | return (@as(u32, self.parts[0]) << 16) + self.parts[1]; |
lib/compiler/translate-c/ast.zig+11-21| ... | @@ -242,7 +242,7 @@ pub const Node = extern union { | ... | @@ -242,7 +242,7 @@ pub const Node = extern union { |
| 242 | 242 | ||
| 243 | /// array_type{} | 243 | /// array_type{} |
| 244 | empty_array, | 244 | empty_array, |
| 245 | /// [1]type{val} ** count | 245 | /// @as([count]type, @splat(val)) |
| 246 | array_filler, | 246 | array_filler, |
| 247 | 247 | ||
| 248 | /// comptime { if (!(lhs)) @compileError(rhs); } | 248 | /// comptime { if (!(lhs)) @compileError(rhs); } |
| ... | @@ -1976,28 +1976,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { | ... | @@ -1976,28 +1976,18 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex { |
| 1976 | .array_filler => { | 1976 | .array_filler => { |
| 1977 | const payload = node.castTag(.array_filler).?.data; | 1977 | const payload = node.castTag(.array_filler).?.data; |
| 1978 | 1978 | ||
| 1979 | const type_expr = try renderArrayType(c, 1, payload.type); | 1979 | const as_tok = try c.addToken(.builtin, "@as"); |
| 1980 | const l_brace = try c.addToken(.l_brace, "{"); | 1980 | _ = try c.addToken(.l_paren, "("); |
| 1981 | const val = try renderNode(c, payload.filler); | 1981 | const type_node = try renderArrayType(c, payload.count, payload.type); |
| 1982 | _ = try c.addToken(.r_brace, "}"); | 1982 | _ = try c.addToken(.comma, ","); |
| 1983 | const splat_node = try renderBuiltinCall(c, "@splat", &.{payload.filler}); | ||
| 1984 | _ = try c.addToken(.r_paren, ")"); | ||
| 1983 | 1985 | ||
| 1984 | const init = try c.addNode(.{ | ||
| 1985 | .tag = .array_init_one, | ||
| 1986 | .main_token = l_brace, | ||
| 1987 | .data = .{ .node_and_node = .{ | ||
| 1988 | type_expr, val, | ||
| 1989 | } }, | ||
| 1990 | }); | ||
| 1991 | return c.addNode(.{ | 1986 | return c.addNode(.{ |
| 1992 | .tag = .array_cat, | 1987 | .tag = .builtin_call_two, |
| 1993 | .main_token = try c.addToken(.asterisk_asterisk, "**"), | 1988 | .main_token = as_tok, |
| 1994 | .data = .{ .node_and_node = .{ | 1989 | .data = .{ .opt_node_and_opt_node = .{ |
| 1995 | init, | 1990 | .fromOptional(type_node), .fromOptional(splat_node), |
| 1996 | try c.addNode(.{ | ||
| 1997 | .tag = .number_literal, | ||
| 1998 | .main_token = try c.addTokenFmt(.number_literal, "{d}", .{payload.count}), | ||
| 1999 | .data = undefined, | ||
| 2000 | }), | ||
| 2001 | } }, | 1991 | } }, |
| 2002 | }); | 1992 | }); |
| 2003 | }, | 1993 | }, |
lib/compiler_rt/atomics.zig+1-1| ... | @@ -94,7 +94,7 @@ const SpinlockTable = struct { | ... | @@ -94,7 +94,7 @@ const SpinlockTable = struct { |
| 94 | } | 94 | } |
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | list: [max_spinlocks]Spinlock = [_]Spinlock{.{}} ** max_spinlocks, | 97 | list: [max_spinlocks]Spinlock = @splat(.{}), |
| 98 | 98 | ||
| 99 | // The spinlock table behaves as a really simple hash table, mapping | 99 | // The spinlock table behaves as a really simple hash table, mapping |
| 100 | // addresses to spinlocks. The mapping is not unique but that's only a | 100 | // addresses to spinlocks. The mapping is not unique but that's only a |
lib/compiler_rt/ssp.zig+2-2| ... | @@ -44,10 +44,10 @@ fn __chk_fail() callconv(.c) noreturn { | ... | @@ -44,10 +44,10 @@ fn __chk_fail() callconv(.c) noreturn { |
| 44 | 44 | ||
| 45 | // TODO: Initialize the canary with random data | 45 | // TODO: Initialize the canary with random data |
| 46 | var __stack_chk_guard: usize = blk: { | 46 | var __stack_chk_guard: usize = blk: { |
| 47 | var buf = [1]u8{0} ** @sizeOf(usize); | 47 | var buf: [@sizeOf(usize)]u8 = @splat(0); |
| 48 | buf[@sizeOf(usize) - 1] = 255; | 48 | buf[@sizeOf(usize) - 1] = 255; |
| 49 | buf[@sizeOf(usize) - 2] = '\n'; | 49 | buf[@sizeOf(usize) - 2] = '\n'; |
| 50 | break :blk @as(usize, @bitCast(buf)); | 50 | break :blk @bitCast(buf); |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 53 | fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.c) [*:0]u8 { | 53 | fn __strcpy_chk(dest: [*:0]u8, src: [*:0]const u8, dest_n: usize) callconv(.c) [*:0]u8 { |
lib/docs/wasm/Walk.zig+1-3| ... | @@ -709,7 +709,6 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index) | ... | @@ -709,7 +709,6 @@ fn expr(w: *Walk, scope: *Scope, parent_decl: Decl.Index, node: Ast.Node.Index) |
| 709 | .less_or_equal, | 709 | .less_or_equal, |
| 710 | .array_cat, | 710 | .array_cat, |
| 711 | 711 | ||
| 712 | .array_mult, | ||
| 713 | .error_union, | 712 | .error_union, |
| 714 | .merge_error_sets, | 713 | .merge_error_sets, |
| 715 | .bool_and, | 714 | .bool_and, |
| ... | @@ -1014,8 +1013,7 @@ fn block( | ... | @@ -1014,8 +1013,7 @@ fn block( |
| 1014 | 1013 | ||
| 1015 | .grouped_expression => try expr(w, scope, parent_decl, ast.nodeData(node).node_and_token[0]), | 1014 | .grouped_expression => try expr(w, scope, parent_decl, ast.nodeData(node).node_and_token[0]), |
| 1016 | 1015 | ||
| 1017 | .@"defer" => try expr(w, scope, parent_decl, ast.nodeData(node).node), | 1016 | .@"defer", .@"errdefer" => try expr(w, scope, parent_decl, ast.nodeData(node).node), |
| 1018 | .@"errdefer" => try expr(w, scope, parent_decl, ast.nodeData(node).opt_token_and_node[1]), | ||
| 1019 | 1017 | ||
| 1020 | else => try expr(w, scope, parent_decl, node), | 1018 | else => try expr(w, scope, parent_decl, node), |
| 1021 | } | 1019 | } |
lib/docs/wasm/html_render.zig+1-2| ... | @@ -302,7 +302,6 @@ pub fn fileSourceHtml( | ... | @@ -302,7 +302,6 @@ pub fn fileSourceHtml( |
| 302 | .minus_pipe_equal, | 302 | .minus_pipe_equal, |
| 303 | .asterisk, | 303 | .asterisk, |
| 304 | .asterisk_equal, | 304 | .asterisk_equal, |
| 305 | .asterisk_asterisk, | ||
| 306 | .asterisk_percent, | 305 | .asterisk_percent, |
| 307 | .asterisk_percent_equal, | 306 | .asterisk_percent_equal, |
| 308 | .asterisk_pipe, | 307 | .asterisk_pipe, |
| ... | @@ -328,7 +327,7 @@ pub fn fileSourceHtml( | ... | @@ -328,7 +327,7 @@ pub fn fileSourceHtml( |
| 328 | .tilde, | 327 | .tilde, |
| 329 | => try appendEscaped(out, slice), | 328 | => try appendEscaped(out, slice), |
| 330 | 329 | ||
| 331 | .invalid, .invalid_periodasterisks => return error.InvalidToken, | 330 | .invalid => return error.InvalidToken, |
| 332 | } | 331 | } |
| 333 | } | 332 | } |
| 334 | } | 333 | } |
lib/std/Io/Reader.zig-5| ... | @@ -2097,7 +2097,6 @@ test "deserialize signed LEB128" { | ... | @@ -2097,7 +2097,6 @@ test "deserialize signed LEB128" { |
| 2097 | try testing.expectEqual(std.math.minInt(i128), testLeb128(i128, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E")); | 2097 | try testing.expectEqual(std.math.minInt(i128), testLeb128(i128, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E")); |
| 2098 | 2098 | ||
| 2099 | // Specific cases | 2099 | // Specific cases |
| 2100 | try testing.expectEqual(0, testLeb128(i0, "\x00")); | ||
| 2101 | try testing.expectEqual(0, testLeb128(i2, "\x00")); | 2100 | try testing.expectEqual(0, testLeb128(i2, "\x00")); |
| 2102 | try testing.expectEqual(0, testLeb128(i8, "\x00")); | 2101 | try testing.expectEqual(0, testLeb128(i8, "\x00")); |
| 2103 | 2102 | ||
| ... | @@ -2134,8 +2133,6 @@ test "deserialize signed LEB128" { | ... | @@ -2134,8 +2133,6 @@ test "deserialize signed LEB128" { |
| 2134 | try testing.expectError(error.EndOfStream, testLeb128(i128, &end_of_stream)); | 2133 | try testing.expectError(error.EndOfStream, testLeb128(i128, &end_of_stream)); |
| 2135 | 2134 | ||
| 2136 | // Overflow | 2135 | // Overflow |
| 2137 | try testing.expectError(error.Overflow, testLeb128(i0, "\x01")); | ||
| 2138 | try testing.expectError(error.Overflow, testLeb128(i0, "\x7F")); | ||
| 2139 | try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x01")); | 2136 | try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x01")); |
| 2140 | try testing.expectError(error.Overflow, testLeb128(i8, "\xFF\x7E")); | 2137 | try testing.expectError(error.Overflow, testLeb128(i8, "\xFF\x7E")); |
| 2141 | try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x80\x40")); | 2138 | try testing.expectError(error.Overflow, testLeb128(i8, "\x80\x80\x40")); |
| ... | @@ -2145,7 +2142,6 @@ test "deserialize signed LEB128" { | ... | @@ -2145,7 +2142,6 @@ test "deserialize signed LEB128" { |
| 2145 | try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")); | 2142 | try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")); |
| 2146 | try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); | 2143 | try testing.expectError(error.Overflow, testLeb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40")); |
| 2147 | 2144 | ||
| 2148 | try testing.expectError(error.Overflow, testLeb128(i0, &overflow)); | ||
| 2149 | try testing.expectError(error.Overflow, testLeb128(i7, &overflow)); | 2145 | try testing.expectError(error.Overflow, testLeb128(i7, &overflow)); |
| 2150 | try testing.expectError(error.Overflow, testLeb128(i8, &overflow)); | 2146 | try testing.expectError(error.Overflow, testLeb128(i8, &overflow)); |
| 2151 | try testing.expectError(error.Overflow, testLeb128(i14, &overflow)); | 2147 | try testing.expectError(error.Overflow, testLeb128(i14, &overflow)); |
| ... | @@ -2159,7 +2155,6 @@ test "deserialize signed LEB128" { | ... | @@ -2159,7 +2155,6 @@ test "deserialize signed LEB128" { |
| 2159 | try testing.expectEqual(0x80, testLeb128(i64, "\x80\x81\x00")); | 2155 | try testing.expectEqual(0x80, testLeb128(i64, "\x80\x81\x00")); |
| 2160 | try testing.expectEqual(0x80, testLeb128(i64, "\x80\x81\x80\x00")); | 2156 | try testing.expectEqual(0x80, testLeb128(i64, "\x80\x81\x80\x00")); |
| 2161 | 2157 | ||
| 2162 | try testing.expectEqual(0, testLeb128(i0, &long_zero)); | ||
| 2163 | try testing.expectEqual(0, testLeb128(i7, &long_zero)); | 2158 | try testing.expectEqual(0, testLeb128(i7, &long_zero)); |
| 2164 | try testing.expectEqual(0, testLeb128(i8, &long_zero)); | 2159 | try testing.expectEqual(0, testLeb128(i8, &long_zero)); |
| 2165 | try testing.expectEqual(0, testLeb128(i14, &long_zero)); | 2160 | try testing.expectEqual(0, testLeb128(i14, &long_zero)); |
lib/std/Io/Threaded.zig+4-4| ... | @@ -6329,7 +6329,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -6329,7 +6329,7 @@ pub fn GetFinalPathNameByHandle( |
| 6329 | const MIN_SIZE = @sizeOf(windows.MOUNTMGR_MOUNT_POINT) + windows.MAX_PATH; | 6329 | const MIN_SIZE = @sizeOf(windows.MOUNTMGR_MOUNT_POINT) + windows.MAX_PATH; |
| 6330 | // We initialize the input buffer to all zeros for convenience since | 6330 | // We initialize the input buffer to all zeros for convenience since |
| 6331 | // `DeviceIoControl` with `IOCTL_MOUNTMGR_QUERY_POINTS` expects this. | 6331 | // `DeviceIoControl` with `IOCTL_MOUNTMGR_QUERY_POINTS` expects this. |
| 6332 | var input_buf: [MIN_SIZE]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINT)) = [_]u8{0} ** MIN_SIZE; | 6332 | var input_buf: [MIN_SIZE]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINT)) = @splat(0); |
| 6333 | var output_buf: [MIN_SIZE * 4]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINTS)) = undefined; | 6333 | var output_buf: [MIN_SIZE * 4]u8 align(@alignOf(windows.MOUNTMGR_MOUNT_POINTS)) = undefined; |
| 6334 | 6334 | ||
| 6335 | // This surprising path is a filesystem path to the mount manager on Windows. | 6335 | // This surprising path is a filesystem path to the mount manager on Windows. |
| ... | @@ -6409,7 +6409,7 @@ pub fn GetFinalPathNameByHandle( | ... | @@ -6409,7 +6409,7 @@ pub fn GetFinalPathNameByHandle( |
| 6409 | 6409 | ||
| 6410 | // 49 is the maximum length accepted by mountmgrIsVolumeName | 6410 | // 49 is the maximum length accepted by mountmgrIsVolumeName |
| 6411 | const vol_input_size = @sizeOf(windows.MOUNTMGR_TARGET_NAME) + (49 * 2); | 6411 | const vol_input_size = @sizeOf(windows.MOUNTMGR_TARGET_NAME) + (49 * 2); |
| 6412 | var vol_input_buf: [vol_input_size]u8 align(@alignOf(windows.MOUNTMGR_TARGET_NAME)) = [_]u8{0} ** vol_input_size; | 6412 | var vol_input_buf: [vol_input_size]u8 align(@alignOf(windows.MOUNTMGR_TARGET_NAME)) = @splat(0); |
| 6413 | // Note: If the path exceeds MAX_PATH, the Disk Management GUI doesn't accept the full path, | 6413 | // Note: If the path exceeds MAX_PATH, the Disk Management GUI doesn't accept the full path, |
| 6414 | // and instead if must be specified using a shortened form (e.g. C:\FOO~1\BAR~1\<...>). | 6414 | // and instead if must be specified using a shortened form (e.g. C:\FOO~1\BAR~1\<...>). |
| 6415 | // However, just to be sure we can handle any path length, we use PATH_MAX_WIDE here. | 6415 | // However, just to be sure we can handle any path length, we use PATH_MAX_WIDE here. |
| ... | @@ -8914,7 +8914,7 @@ fn isCygwinPty(file: File) Io.Cancelable!bool { | ... | @@ -8914,7 +8914,7 @@ fn isCygwinPty(file: File) Io.Cancelable!bool { |
| 8914 | // we can use this smaller buffer and just return false on any error from | 8914 | // we can use this smaller buffer and just return false on any error from |
| 8915 | // NtQueryInformationFile. | 8915 | // NtQueryInformationFile. |
| 8916 | const num_name_bytes = windows.MAX_PATH * 2; | 8916 | const num_name_bytes = windows.MAX_PATH * 2; |
| 8917 | var name_info_bytes align(@alignOf(windows.FILE.NAME_INFORMATION)) = [_]u8{0} ** (name_bytes_offset + num_name_bytes); | 8917 | var name_info_bytes: [name_bytes_offset + num_name_bytes]u8 align(@alignOf(windows.FILE.NAME_INFORMATION)) = @splat(0); |
| 8918 | 8918 | ||
| 8919 | var io_status_block: windows.IO_STATUS_BLOCK = undefined; | 8919 | var io_status_block: windows.IO_STATUS_BLOCK = undefined; |
| 8920 | const syscall: Syscall = try .start(); | 8920 | const syscall: Syscall = try .start(); |
| ... | @@ -16191,7 +16191,7 @@ fn windowsCreateProcessPathExt( | ... | @@ -16191,7 +16191,7 @@ fn windowsCreateProcessPathExt( |
| 16191 | var io_status: windows.IO_STATUS_BLOCK = undefined; | 16191 | var io_status: windows.IO_STATUS_BLOCK = undefined; |
| 16192 | 16192 | ||
| 16193 | const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".fields.len; | 16193 | const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".fields.len; |
| 16194 | var pathext_seen = [_]bool{false} ** num_supported_pathext; | 16194 | var pathext_seen: [num_supported_pathext]bool = @splat(false); |
| 16195 | var any_pathext_seen = false; | 16195 | var any_pathext_seen = false; |
| 16196 | var unappended_exists = false; | 16196 | var unappended_exists = false; |
| 16197 | 16197 |
lib/std/Io/Writer.zig+1-2| ... | @@ -781,7 +781,7 @@ test splatByteAll { | ... | @@ -781,7 +781,7 @@ test splatByteAll { |
| 781 | defer aw.deinit(); | 781 | defer aw.deinit(); |
| 782 | 782 | ||
| 783 | try aw.writer.splatByteAll('7', 45); | 783 | try aw.writer.splatByteAll('7', 45); |
| 784 | try testing.expectEqualStrings("7" ** 45, aw.writer.buffered()); | 784 | try testing.expectEqualStrings(&@as([45]u8, @splat('7')), aw.writer.buffered()); |
| 785 | } | 785 | } |
| 786 | 786 | ||
| 787 | pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void { | 787 | pub fn splatBytePreserve(w: *Writer, preserve: usize, byte: u8, n: usize) Error!void { |
| ... | @@ -1924,7 +1924,6 @@ test "serialize signed LEB128" { | ... | @@ -1924,7 +1924,6 @@ test "serialize signed LEB128" { |
| 1924 | try testLeb128Encoding(i128, std.math.minInt(i128), "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E"); | 1924 | try testLeb128Encoding(i128, std.math.minInt(i128), "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7E"); |
| 1925 | 1925 | ||
| 1926 | // Specific cases | 1926 | // Specific cases |
| 1927 | try testLeb128Encoding(i0, 0, "\x00"); | ||
| 1928 | try testLeb128Encoding(i8, 0, "\x00"); | 1927 | try testLeb128Encoding(i8, 0, "\x00"); |
| 1929 | 1928 | ||
| 1930 | try testLeb128Encoding(i2, -1, "\x7F"); | 1929 | try testLeb128Encoding(i2, -1, "\x7F"); |
lib/std/Io/net/HostName.zig+11-6| ... | @@ -76,9 +76,14 @@ test validate { | ... | @@ -76,9 +76,14 @@ test validate { |
| 76 | try validate("a-b.com"); | 76 | try validate("a-b.com"); |
| 77 | try validate("a.b.c.d.e.f.g"); | 77 | try validate("a.b.c.d.e.f.g"); |
| 78 | try validate("127.0.0.1"); // Also a valid hostname | 78 | try validate("127.0.0.1"); // Also a valid hostname |
| 79 | try validate("a" ** 63 ++ ".com"); // Label exactly 63 chars (valid) | 79 | |
| 80 | try validate("a." ** 127 ++ "a"); // Total length 255 (valid) | 80 | const many_a: [63]u8 = @splat('a'); |
| 81 | try validate("a." ** 127 ++ "a."); // Total length 255 + trailing dot (valid) | 81 | try validate(&many_a ++ ".com"); // Label exactly 63 chars (valid) |
| 82 | |||
| 83 | const many_a_dot_buf: [127][2]u8 = @splat(.{ 'a', '.' }); | ||
| 84 | const many_a_dot: []const u8 = @ptrCast(&many_a_dot_buf); | ||
| 85 | try validate(many_a_dot ++ "a"); // Total length 255 (valid) | ||
| 86 | try validate(many_a_dot ++ "a."); // Total length 255 + trailing dot (valid) | ||
| 82 | 87 | ||
| 83 | // Invalid hostnames | 88 | // Invalid hostnames |
| 84 | try std.testing.expectError(error.InvalidHostName, validate("")); | 89 | try std.testing.expectError(error.InvalidHostName, validate("")); |
| ... | @@ -92,9 +97,9 @@ test validate { | ... | @@ -92,9 +97,9 @@ test validate { |
| 92 | try std.testing.expectError(error.InvalidHostName, validate("host_name.com")); | 97 | try std.testing.expectError(error.InvalidHostName, validate("host_name.com")); |
| 93 | try std.testing.expectError(error.InvalidHostName, validate(".")); | 98 | try std.testing.expectError(error.InvalidHostName, validate(".")); |
| 94 | try std.testing.expectError(error.InvalidHostName, validate("..")); | 99 | try std.testing.expectError(error.InvalidHostName, validate("..")); |
| 95 | try std.testing.expectError(error.InvalidHostName, validate("a" ** 64 ++ ".com")); // Label length 64 (too long) | 100 | try std.testing.expectError(error.InvalidHostName, validate(&many_a ++ "a.com")); // Label length 64 (too long) |
| 96 | try std.testing.expectError(error.NameTooLong, validate("a." ** 127 ++ "ab")); // Total length 256 (too long) | 101 | try std.testing.expectError(error.NameTooLong, validate(many_a_dot ++ "ab")); // Total length 256 (too long) |
| 97 | try std.testing.expectError(error.NameTooLong, validate("a." ** 127 ++ "ab.")); // Total length 256 + trailing dot (too long) | 102 | try std.testing.expectError(error.NameTooLong, validate(many_a_dot ++ "ab.")); // Total length 256 + trailing dot (too long) |
| 98 | } | 103 | } |
| 99 | 104 | ||
| 100 | pub fn init(bytes: []const u8) ValidateError!HostName { | 105 | pub fn init(bytes: []const u8) ValidateError!HostName { |
lib/std/Random/ChaCha.zig+2-2| ... | @@ -14,7 +14,7 @@ const State = [8 * Cipher.block_length]u8; | ... | @@ -14,7 +14,7 @@ const State = [8 * Cipher.block_length]u8; |
| 14 | state: State, | 14 | state: State, |
| 15 | offset: usize, | 15 | offset: usize, |
| 16 | 16 | ||
| 17 | const nonce = [_]u8{0} ** Cipher.nonce_length; | 17 | const nonce: [Cipher.nonce_length]u8 = @splat(0); |
| 18 | 18 | ||
| 19 | pub const secret_seed_length = Cipher.key_length; | 19 | pub const secret_seed_length = Cipher.key_length; |
| 20 | 20 | ||
| ... | @@ -38,7 +38,7 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void { | ... | @@ -38,7 +38,7 @@ pub fn addEntropy(self: *Self, bytes: []const u8) void { |
| 38 | ); | 38 | ); |
| 39 | } | 39 | } |
| 40 | if (i < bytes.len) { | 40 | if (i < bytes.len) { |
| 41 | var k = [_]u8{0} ** Cipher.key_length; | 41 | var k: [Cipher.key_length]u8 = @splat(0); |
| 42 | const src = bytes[i..]; | 42 | const src = bytes[i..]; |
| 43 | @memcpy(k[0..src.len], src); | 43 | @memcpy(k[0..src.len], src); |
| 44 | Cipher.xor( | 44 | Cipher.xor( |
lib/std/Random/benchmark.zig+2-2| ... | @@ -55,12 +55,12 @@ const csprngs = [_]Rng{ | ... | @@ -55,12 +55,12 @@ const csprngs = [_]Rng{ |
| 55 | Rng{ | 55 | Rng{ |
| 56 | .ty = Random.Ascon, | 56 | .ty = Random.Ascon, |
| 57 | .name = "ascon", | 57 | .name = "ascon", |
| 58 | .init_u8s = &[_]u8{0} ** 32, | 58 | .init_u8s = &@as([32]u8, @splat(0)), |
| 59 | }, | 59 | }, |
| 60 | Rng{ | 60 | Rng{ |
| 61 | .ty = Random.ChaCha, | 61 | .ty = Random.ChaCha, |
| 62 | .name = "chacha", | 62 | .name = "chacha", |
| 63 | .init_u8s = &[_]u8{0} ** 32, | 63 | .init_u8s = &@as([32]u8, @splat(0)), |
| 64 | }, | 64 | }, |
| 65 | }; | 65 | }; |
| 66 | 66 |
lib/std/Random/test.zig+4-4| ... | @@ -383,8 +383,8 @@ test "Random shuffle" { | ... | @@ -383,8 +383,8 @@ test "Random shuffle" { |
| 383 | var prng = DefaultPrng.init(0); | 383 | var prng = DefaultPrng.init(0); |
| 384 | const random = prng.random(); | 384 | const random = prng.random(); |
| 385 | 385 | ||
| 386 | var seq = [_]u8{ 0, 1, 2, 3, 4 }; | 386 | var seq: [5]u8 = .{ 0, 1, 2, 3, 4 }; |
| 387 | var seen = [_]bool{false} ** 5; | 387 | var seen: [5]bool = @splat(false); |
| 388 | 388 | ||
| 389 | var i: usize = 0; | 389 | var i: usize = 0; |
| 390 | while (i < 1000) : (i += 1) { | 390 | while (i < 1000) : (i += 1) { |
| ... | @@ -421,8 +421,8 @@ fn testRange(r: Random, start: i8, end: i8) !void { | ... | @@ -421,8 +421,8 @@ fn testRange(r: Random, start: i8, end: i8) !void { |
| 421 | try testRangeBias(r, start, end, false); | 421 | try testRangeBias(r, start, end, false); |
| 422 | } | 422 | } |
| 423 | fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void { | 423 | fn testRangeBias(r: Random, start: i8, end: i8, biased: bool) !void { |
| 424 | const count = @as(usize, @intCast(@as(i32, end) - @as(i32, start))); | 424 | const count: usize = @intCast(@as(i32, end) - @as(i32, start)); |
| 425 | var values_buffer = [_]bool{false} ** 0x100; | 425 | var values_buffer: [0x100]bool = @splat(false); |
| 426 | const values = values_buffer[0..count]; | 426 | const values = values_buffer[0..count]; |
| 427 | var i: usize = 0; | 427 | var i: usize = 0; |
| 428 | while (i < count) { | 428 | while (i < count) { |
lib/std/Thread.zig+2-2| ... | @@ -1574,9 +1574,9 @@ const LinuxThreadImpl = struct { | ... | @@ -1574,9 +1574,9 @@ const LinuxThreadImpl = struct { |
| 1574 | }; | 1574 | }; |
| 1575 | 1575 | ||
| 1576 | fn testThreadName(io: Io, thread: *Thread) !void { | 1576 | fn testThreadName(io: Io, thread: *Thread) !void { |
| 1577 | const testCases = &[_][]const u8{ | 1577 | const testCases: []const []const u8 = &.{ |
| 1578 | "mythread", | 1578 | "mythread", |
| 1579 | "b" ** max_name_len, | 1579 | &@as([max_name_len]u8, @splat('b')), |
| 1580 | }; | 1580 | }; |
| 1581 | 1581 | ||
| 1582 | inline for (testCases) |tc| { | 1582 | inline for (testCases) |tc| { |
lib/std/base64.zig+5-5| ... | @@ -86,7 +86,7 @@ pub const Base64Encoder = struct { | ... | @@ -86,7 +86,7 @@ pub const Base64Encoder = struct { |
| 86 | /// A bunch of assertions, then simply pass the data right through. | 86 | /// A bunch of assertions, then simply pass the data right through. |
| 87 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Encoder { | 87 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Encoder { |
| 88 | assert(alphabet_chars.len == 64); | 88 | assert(alphabet_chars.len == 64); |
| 89 | var char_in_alphabet = [_]bool{false} ** 256; | 89 | var char_in_alphabet: [256]bool = @splat(false); |
| 90 | for (alphabet_chars) |c| { | 90 | for (alphabet_chars) |c| { |
| 91 | assert(!char_in_alphabet[c]); | 91 | assert(!char_in_alphabet[c]); |
| 92 | assert(pad_char == null or c != pad_char.?); | 92 | assert(pad_char == null or c != pad_char.?); |
| ... | @@ -176,12 +176,12 @@ pub const Base64Decoder = struct { | ... | @@ -176,12 +176,12 @@ pub const Base64Decoder = struct { |
| 176 | 176 | ||
| 177 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder { | 177 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8) Base64Decoder { |
| 178 | var result = Base64Decoder{ | 178 | var result = Base64Decoder{ |
| 179 | .char_to_index = [_]u8{invalid_char} ** 256, | 179 | .char_to_index = @splat(invalid_char), |
| 180 | .fast_char_to_index = .{[_]u32{invalid_char_tst} ** 256} ** 4, | 180 | .fast_char_to_index = @splat(@splat(invalid_char_tst)), |
| 181 | .pad_char = pad_char, | 181 | .pad_char = pad_char, |
| 182 | }; | 182 | }; |
| 183 | 183 | ||
| 184 | var char_in_alphabet = [_]bool{false} ** 256; | 184 | var char_in_alphabet: [256]bool = @splat(false); |
| 185 | for (alphabet_chars, 0..) |c, i| { | 185 | for (alphabet_chars, 0..) |c, i| { |
| 186 | assert(!char_in_alphabet[c]); | 186 | assert(!char_in_alphabet[c]); |
| 187 | assert(pad_char == null or c != pad_char.?); | 187 | assert(pad_char == null or c != pad_char.?); |
| ... | @@ -302,7 +302,7 @@ pub const Base64DecoderWithIgnore = struct { | ... | @@ -302,7 +302,7 @@ pub const Base64DecoderWithIgnore = struct { |
| 302 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8, ignore_chars: []const u8) Base64DecoderWithIgnore { | 302 | pub fn init(alphabet_chars: [64]u8, pad_char: ?u8, ignore_chars: []const u8) Base64DecoderWithIgnore { |
| 303 | var result = Base64DecoderWithIgnore{ | 303 | var result = Base64DecoderWithIgnore{ |
| 304 | .decoder = Base64Decoder.init(alphabet_chars, pad_char), | 304 | .decoder = Base64Decoder.init(alphabet_chars, pad_char), |
| 305 | .char_is_ignored = [_]bool{false} ** 256, | 305 | .char_is_ignored = @splat(false), |
| 306 | }; | 306 | }; |
| 307 | for (ignore_chars) |c| { | 307 | for (ignore_chars) |c| { |
| 308 | assert(result.decoder.char_to_index[c] == Base64Decoder.invalid_char); | 308 | assert(result.decoder.char_to_index[c] == Base64Decoder.invalid_char); |
lib/std/bit_set.zig+7-7| ... | @@ -406,24 +406,24 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type { | ... | @@ -406,24 +406,24 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type { |
| 406 | /// Deprecated: use `.empty`. | 406 | /// Deprecated: use `.empty`. |
| 407 | /// Creates a bit set with no elements present. | 407 | /// Creates a bit set with no elements present. |
| 408 | pub fn initEmpty() Self { | 408 | pub fn initEmpty() Self { |
| 409 | return .{ .masks = [_]MaskInt{0} ** num_masks }; | 409 | return .empty; |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | /// Deprecated: use `.full`. | 412 | /// Deprecated: use `.full`. |
| 413 | /// Creates a bit set with all elements present. | 413 | /// Creates a bit set with all elements present. |
| 414 | pub fn initFull() Self { | 414 | pub fn initFull() Self { |
| 415 | if (num_masks == 0) { | 415 | return .full; |
| 416 | return .{ .masks = .{} }; | ||
| 417 | } else { | ||
| 418 | return .{ .masks = [_]MaskInt{~@as(MaskInt, 0)} ** (num_masks - 1) ++ [_]MaskInt{last_item_mask} }; | ||
| 419 | } | ||
| 420 | } | 416 | } |
| 421 | 417 | ||
| 422 | /// A bit set with no elements present. | 418 | /// A bit set with no elements present. |
| 423 | pub const empty: Self = .{ .masks = @splat(0) }; | 419 | pub const empty: Self = .{ .masks = @splat(0) }; |
| 424 | 420 | ||
| 425 | /// A bit set with all elements present. | 421 | /// A bit set with all elements present. |
| 426 | pub const full: Self = .{ .masks = if (num_masks == 0) .{} else ([_]MaskInt{~@as(MaskInt, 0)} ** (num_masks - 1) ++ [_]MaskInt{last_item_mask}) }; | 422 | pub const full: Self = full: { |
| 423 | var masks: [num_masks]MaskInt = @splat(~@as(MaskInt, 0)); | ||
| 424 | if (num_masks > 0) masks[num_masks - 1] = last_item_mask; | ||
| 425 | break :full .{ .masks = masks }; | ||
| 426 | }; | ||
| 427 | 427 | ||
| 428 | /// Returns the number of bits in this bit set | 428 | /// Returns the number of bits in this bit set |
| 429 | pub inline fn capacity(self: Self) usize { | 429 | pub inline fn capacity(self: Self) usize { |
lib/std/c.zig+17-17| ... | @@ -7914,7 +7914,7 @@ pub const pthread_spinlock_t = switch (native_os) { | ... | @@ -7914,7 +7914,7 @@ pub const pthread_spinlock_t = switch (native_os) { |
| 7914 | 7914 | ||
| 7915 | pub const pthread_mutex_t = switch (native_os) { | 7915 | pub const pthread_mutex_t = switch (native_os) { |
| 7916 | .linux => extern struct { | 7916 | .linux => extern struct { |
| 7917 | data: [data_len]u8 align(@alignOf(usize)) = [_]u8{0} ** data_len, | 7917 | data: [data_len]u8 align(@alignOf(usize)) = @splat(0), |
| 7918 | 7918 | ||
| 7919 | const data_len = switch (native_abi) { | 7919 | const data_len = switch (native_abi) { |
| 7920 | .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24, | 7920 | .musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24, |
| ... | @@ -7930,7 +7930,7 @@ pub const pthread_mutex_t = switch (native_os) { | ... | @@ -7930,7 +7930,7 @@ pub const pthread_mutex_t = switch (native_os) { |
| 7930 | }, | 7930 | }, |
| 7931 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 7931 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 7932 | sig: c_long = 0x32AAABA7, | 7932 | sig: c_long = 0x32AAABA7, |
| 7933 | data: [data_len]u8 = [_]u8{0} ** data_len, | 7933 | data: [data_len]u8 = @splat(0), |
| 7934 | 7934 | ||
| 7935 | const data_len = if (@sizeOf(usize) == 8) 56 else 40; | 7935 | const data_len = if (@sizeOf(usize) == 8) 56 else 40; |
| 7936 | }, | 7936 | }, |
| ... | @@ -7966,10 +7966,10 @@ pub const pthread_mutex_t = switch (native_os) { | ... | @@ -7966,10 +7966,10 @@ pub const pthread_mutex_t = switch (native_os) { |
| 7966 | data: u64 = 0, | 7966 | data: u64 = 0, |
| 7967 | }, | 7967 | }, |
| 7968 | .fuchsia => extern struct { | 7968 | .fuchsia => extern struct { |
| 7969 | data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40, | 7969 | data: [40]u8 align(@alignOf(usize)) = @splat(0), |
| 7970 | }, | 7970 | }, |
| 7971 | .emscripten => extern struct { | 7971 | .emscripten => extern struct { |
| 7972 | data: [24]u8 align(4) = [_]u8{0} ** 24, | 7972 | data: [24]u8 align(4) = @splat(0), |
| 7973 | }, | 7973 | }, |
| 7974 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73 | 7974 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L68-L73 |
| 7975 | .serenity => extern struct { | 7975 | .serenity => extern struct { |
| ... | @@ -7983,11 +7983,11 @@ pub const pthread_mutex_t = switch (native_os) { | ... | @@ -7983,11 +7983,11 @@ pub const pthread_mutex_t = switch (native_os) { |
| 7983 | 7983 | ||
| 7984 | pub const pthread_cond_t = switch (native_os) { | 7984 | pub const pthread_cond_t = switch (native_os) { |
| 7985 | .linux => extern struct { | 7985 | .linux => extern struct { |
| 7986 | data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48, | 7986 | data: [48]u8 align(@alignOf(usize)) = @splat(0), |
| 7987 | }, | 7987 | }, |
| 7988 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 7988 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 7989 | sig: c_long = 0x3CB0B1BB, | 7989 | sig: c_long = 0x3CB0B1BB, |
| 7990 | data: [data_len]u8 = [_]u8{0} ** data_len, | 7990 | data: [data_len]u8 = @splat(0), |
| 7991 | const data_len = if (@sizeOf(usize) == 8) 40 else 24; | 7991 | const data_len = if (@sizeOf(usize) == 8) 40 else 24; |
| 7992 | }, | 7992 | }, |
| 7993 | .freebsd, .dragonfly, .openbsd => extern struct { | 7993 | .freebsd, .dragonfly, .openbsd => extern struct { |
| ... | @@ -8012,13 +8012,13 @@ pub const pthread_cond_t = switch (native_os) { | ... | @@ -8012,13 +8012,13 @@ pub const pthread_cond_t = switch (native_os) { |
| 8012 | lock: i32 = 0, | 8012 | lock: i32 = 0, |
| 8013 | }, | 8013 | }, |
| 8014 | .illumos => extern struct { | 8014 | .illumos => extern struct { |
| 8015 | flag: [4]u8 = [_]u8{0} ** 4, | 8015 | flag: [4]u8 = @splat(0), |
| 8016 | type: u16 = 0, | 8016 | type: u16 = 0, |
| 8017 | magic: u16 = 0x4356, | 8017 | magic: u16 = 0x4356, |
| 8018 | data: u64 = 0, | 8018 | data: u64 = 0, |
| 8019 | }, | 8019 | }, |
| 8020 | .fuchsia, .emscripten => extern struct { | 8020 | .fuchsia, .emscripten => extern struct { |
| 8021 | data: [48]u8 align(@alignOf(usize)) = [_]u8{0} ** 48, | 8021 | data: [48]u8 align(@alignOf(usize)) = @splat(0), |
| 8022 | }, | 8022 | }, |
| 8023 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84 | 8023 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L80-L84 |
| 8024 | .serenity => extern struct { | 8024 | .serenity => extern struct { |
| ... | @@ -8033,20 +8033,20 @@ pub const pthread_rwlock_t = switch (native_os) { | ... | @@ -8033,20 +8033,20 @@ pub const pthread_rwlock_t = switch (native_os) { |
| 8033 | .linux => switch (native_abi) { | 8033 | .linux => switch (native_abi) { |
| 8034 | .android, .androideabi => switch (@sizeOf(usize)) { | 8034 | .android, .androideabi => switch (@sizeOf(usize)) { |
| 8035 | 4 => extern struct { | 8035 | 4 => extern struct { |
| 8036 | data: [40]u8 align(@alignOf(usize)) = [_]u8{0} ** 40, | 8036 | data: [40]u8 align(@alignOf(usize)) = @splat(0), |
| 8037 | }, | 8037 | }, |
| 8038 | 8 => extern struct { | 8038 | 8 => extern struct { |
| 8039 | data: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, | 8039 | data: [56]u8 align(@alignOf(usize)) = @splat(0), |
| 8040 | }, | 8040 | }, |
| 8041 | else => @compileError("impossible pointer size"), | 8041 | else => @compileError("impossible pointer size"), |
| 8042 | }, | 8042 | }, |
| 8043 | else => extern struct { | 8043 | else => extern struct { |
| 8044 | data: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, | 8044 | data: [56]u8 align(@alignOf(usize)) = @splat(0), |
| 8045 | }, | 8045 | }, |
| 8046 | }, | 8046 | }, |
| 8047 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 8047 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 8048 | sig: c_long = 0x2DA8B3B4, | 8048 | sig: c_long = 0x2DA8B3B4, |
| 8049 | data: [192]u8 = [_]u8{0} ** 192, | 8049 | data: [192]u8 = @splat(0), |
| 8050 | }, | 8050 | }, |
| 8051 | .freebsd, .dragonfly, .openbsd => extern struct { | 8051 | .freebsd, .dragonfly, .openbsd => extern struct { |
| 8052 | ptr: ?*anyopaque = null, | 8052 | ptr: ?*anyopaque = null, |
| ... | @@ -8079,10 +8079,10 @@ pub const pthread_rwlock_t = switch (native_os) { | ... | @@ -8079,10 +8079,10 @@ pub const pthread_rwlock_t = switch (native_os) { |
| 8079 | writercv: pthread_cond_t = .{}, | 8079 | writercv: pthread_cond_t = .{}, |
| 8080 | }, | 8080 | }, |
| 8081 | .fuchsia => extern struct { | 8081 | .fuchsia => extern struct { |
| 8082 | size: [56]u8 align(@alignOf(usize)) = [_]u8{0} ** 56, | 8082 | size: [56]u8 align(@alignOf(usize)) = @splat(0), |
| 8083 | }, | 8083 | }, |
| 8084 | .emscripten => extern struct { | 8084 | .emscripten => extern struct { |
| 8085 | size: [32]u8 align(4) = [_]u8{0} ** 32, | 8085 | size: [32]u8 align(4) = @splat(0), |
| 8086 | }, | 8086 | }, |
| 8087 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86 | 8087 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L86 |
| 8088 | .serenity => extern struct { | 8088 | .serenity => extern struct { |
| ... | @@ -8170,8 +8170,8 @@ pub const sem_t = switch (native_os) { | ... | @@ -8170,8 +8170,8 @@ pub const sem_t = switch (native_os) { |
| 8170 | count: u32 = 0, | 8170 | count: u32 = 0, |
| 8171 | type: u16 = 0, | 8171 | type: u16 = 0, |
| 8172 | magic: u16 = 0x534d, | 8172 | magic: u16 = 0x534d, |
| 8173 | __pad1: [3]u64 = [_]u64{0} ** 3, | 8173 | __pad1: [3]u64 = @splat(0), |
| 8174 | __pad2: [2]u64 = [_]u64{0} ** 2, | 8174 | __pad2: [2]u64 = @splat(0), |
| 8175 | }, | 8175 | }, |
| 8176 | .openbsd, .netbsd, .dragonfly => ?*opaque {}, | 8176 | .openbsd, .netbsd, .dragonfly => ?*opaque {}, |
| 8177 | .haiku => extern struct { | 8177 | .haiku => extern struct { |
| ... | @@ -8235,7 +8235,7 @@ pub const Kevent = switch (native_os) { | ... | @@ -8235,7 +8235,7 @@ pub const Kevent = switch (native_os) { |
| 8235 | /// Opaque user data identifier. | 8235 | /// Opaque user data identifier. |
| 8236 | udata: usize, | 8236 | udata: usize, |
| 8237 | /// Future extensions. | 8237 | /// Future extensions. |
| 8238 | _ext: [4]u64 = [_]u64{0} ** 4, | 8238 | _ext: [4]u64 = @splat(0), |
| 8239 | }, | 8239 | }, |
| 8240 | .dragonfly => extern struct { | 8240 | .dragonfly => extern struct { |
| 8241 | ident: usize, | 8241 | ident: usize, |
lib/std/compress/flate/Decompress.zig+1-1| ... | @@ -723,7 +723,7 @@ fn HuffmanDecoder( | ... | @@ -723,7 +723,7 @@ fn HuffmanDecoder( |
| 723 | if (alphabet_size == 286) | 723 | if (alphabet_size == 286) |
| 724 | if (lens[256] == 0) return error.MissingEndOfBlockCode; | 724 | if (lens[256] == 0) return error.MissingEndOfBlockCode; |
| 725 | 725 | ||
| 726 | var count = [_]u16{0} ** (@as(usize, max_code_bits) + 1); | 726 | var count: [@as(usize, max_code_bits) + 1]u16 = @splat(0); |
| 727 | var max: usize = 0; | 727 | var max: usize = 0; |
| 728 | for (lens) |n| { | 728 | for (lens) |n| { |
| 729 | if (n == 0) continue; | 729 | if (n == 0) continue; |
lib/std/crypto.zig+3-3| ... | @@ -394,7 +394,7 @@ test "issue #4532: no index out of bounds" { | ... | @@ -394,7 +394,7 @@ test "issue #4532: no index out of bounds" { |
| 394 | }; | 394 | }; |
| 395 | 395 | ||
| 396 | inline for (types) |Hasher| { | 396 | inline for (types) |Hasher| { |
| 397 | var block = [_]u8{'#'} ** Hasher.block_length; | 397 | var block: [Hasher.block_length]u8 = @splat('#'); |
| 398 | var out1: [Hasher.digest_length]u8 = undefined; | 398 | var out1: [Hasher.digest_length]u8 = undefined; |
| 399 | var out2: [Hasher.digest_length]u8 = undefined; | 399 | var out2: [Hasher.digest_length]u8 = undefined; |
| 400 | const h0 = Hasher.init(.{}); | 400 | const h0 = Hasher.init(.{}); |
| ... | @@ -417,8 +417,8 @@ pub fn secureZero(comptime T: type, s: []volatile T) void { | ... | @@ -417,8 +417,8 @@ pub fn secureZero(comptime T: type, s: []volatile T) void { |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | test secureZero { | 419 | test secureZero { |
| 420 | var a = [_]u8{0xfe} ** 8; | 420 | var a: [8]u8 = @splat(0xFE); |
| 421 | var b = [_]u8{0xfe} ** 8; | 421 | var b: [8]u8 = @splat(0xFE); |
| 422 | 422 | ||
| 423 | @memset(&a, 0); | 423 | @memset(&a, 0); |
| 424 | secureZero(u8, &b); | 424 | secureZero(u8, &b); |
lib/std/crypto/25519/curve25519.zig+2-2| ... | @@ -41,7 +41,7 @@ pub const Curve25519 = struct { | ... | @@ -41,7 +41,7 @@ pub const Curve25519 = struct { |
| 41 | 41 | ||
| 42 | /// Multiply a point by the cofactor, returning WeakPublicKey if the element is in a small-order group. | 42 | /// Multiply a point by the cofactor, returning WeakPublicKey if the element is in a small-order group. |
| 43 | pub fn clearCofactor(p: Curve25519) WeakPublicKeyError!Curve25519 { | 43 | pub fn clearCofactor(p: Curve25519) WeakPublicKeyError!Curve25519 { |
| 44 | const cofactor = [_]u8{8} ++ [_]u8{0} ** 31; | 44 | const cofactor = [_]u8{8} ++ @as([31]u8, @splat(0)); |
| 45 | return ladder(p, cofactor, 4) catch return error.WeakPublicKey; | 45 | return ladder(p, cofactor, 4) catch return error.WeakPublicKey; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| ... | @@ -168,7 +168,7 @@ test "elligator2" { | ... | @@ -168,7 +168,7 @@ test "elligator2" { |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | test "small order check" { | 170 | test "small order check" { |
| 171 | var s: [32]u8 = [_]u8{1} ++ [_]u8{0} ** 31; | 171 | var s: [32]u8 = [_]u8{1} ++ @as([31]u8, @splat(0)); |
| 172 | const small_order_ss: [7][32]u8 = .{ | 172 | const small_order_ss: [7][32]u8 = .{ |
| 173 | .{ | 173 | .{ |
| 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 (order 4) | 174 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0 (order 4) |
lib/std/crypto/25519/edwards25519.zig+3-3| ... | @@ -470,7 +470,7 @@ pub const Edwards25519 = struct { | ... | @@ -470,7 +470,7 @@ pub const Edwards25519 = struct { |
| 470 | st.final(&hctx); | 470 | st.final(&hctx); |
| 471 | xctx = hctx[0..]; | 471 | xctx = hctx[0..]; |
| 472 | } | 472 | } |
| 473 | const empty_block = [_]u8{0} ** H.block_length; | 473 | const empty_block: [H.block_length]u8 = @splat(0); |
| 474 | var t = [3]u8{ 0, n * h_l, 0 }; | 474 | var t = [3]u8{ 0, n * h_l, 0 }; |
| 475 | var xctx_len_u8 = [1]u8{@as(u8, @intCast(xctx.len))}; | 475 | var xctx_len_u8 = [1]u8{@as(u8, @intCast(xctx.len))}; |
| 476 | var st = H.init(.{}); | 476 | var st = H.init(.{}); |
| ... | @@ -539,7 +539,7 @@ pub const Edwards25519 = struct { | ... | @@ -539,7 +539,7 @@ pub const Edwards25519 = struct { |
| 539 | const htest = @import("../test.zig"); | 539 | const htest = @import("../test.zig"); |
| 540 | 540 | ||
| 541 | test "packing/unpacking" { | 541 | test "packing/unpacking" { |
| 542 | const s = [_]u8{170} ++ [_]u8{0} ** 31; | 542 | const s = [1]u8{170} ++ @as([31]u8, @splat(0)); |
| 543 | var b = Edwards25519.basePoint; | 543 | var b = Edwards25519.basePoint; |
| 544 | const pk = try b.mul(s); | 544 | const pk = try b.mul(s); |
| 545 | var buf: [128]u8 = undefined; | 545 | var buf: [128]u8 = undefined; |
| ... | @@ -609,7 +609,7 @@ test "hash-to-curve operation" { | ... | @@ -609,7 +609,7 @@ test "hash-to-curve operation" { |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | test "implicit reduction of invalid scalars" { | 611 | test "implicit reduction of invalid scalars" { |
| 612 | const s = [_]u8{0} ** 31 ++ [_]u8{255}; | 612 | const s = @as([31]u8, @splat(0)) ++ [1]u8{255}; |
| 613 | const p1 = try Edwards25519.basePoint.mulPublic(s); | 613 | const p1 = try Edwards25519.basePoint.mulPublic(s); |
| 614 | const p2 = try Edwards25519.basePoint.mul(s); | 614 | const p2 = try Edwards25519.basePoint.mul(s); |
| 615 | const p3 = try p1.mulPublic(s); | 615 | const p3 = try p1.mulPublic(s); |
lib/std/crypto/25519/ristretto255.zig+2-2| ... | @@ -183,13 +183,13 @@ test "ristretto255" { | ... | @@ -183,13 +183,13 @@ test "ristretto255" { |
| 183 | q = q.dbl().add(p); | 183 | q = q.dbl().add(p); |
| 184 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E"); | 184 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E"); |
| 185 | 185 | ||
| 186 | const s = [_]u8{15} ++ [_]u8{0} ** 31; | 186 | const s = [_]u8{15} ++ @as([31]u8, @splat(0)); |
| 187 | const w = try p.mul(s); | 187 | const w = try p.mul(s); |
| 188 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E"); | 188 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E"); |
| 189 | 189 | ||
| 190 | try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p))); | 190 | try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p))); |
| 191 | 191 | ||
| 192 | const h = [_]u8{69} ** 32 ++ [_]u8{42} ** 32; | 192 | const h = @as([32]u8, @splat(69)) ++ @as([32]u8, @splat(42)); |
| 193 | const ph = Ristretto255.fromUniform(h); | 193 | const ph = Ristretto255.fromUniform(h); |
| 194 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19"); | 194 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19"); |
| 195 | } | 195 | } |
lib/std/crypto/25519/scalar.zig+6-6| ... | @@ -11,7 +11,7 @@ pub const field_order: u256 = 72370055773322622139731865630429942408571163593799 | ... | @@ -11,7 +11,7 @@ pub const field_order: u256 = 72370055773322622139731865630429942408571163593799 |
| 11 | pub const CompressedScalar = [32]u8; | 11 | pub const CompressedScalar = [32]u8; |
| 12 | 12 | ||
| 13 | /// Zero | 13 | /// Zero |
| 14 | pub const zero = [_]u8{0} ** 32; | 14 | pub const zero: [32]u8 = @splat(0); |
| 15 | 15 | ||
| 16 | const field_order_s = s: { | 16 | const field_order_s = s: { |
| 17 | var s: [32]u8 = undefined; | 17 | var s: [32]u8 = undefined; |
| ... | @@ -81,7 +81,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar { | ... | @@ -81,7 +81,7 @@ pub fn add(a: CompressedScalar, b: CompressedScalar) CompressedScalar { |
| 81 | 81 | ||
| 82 | /// Return -s (mod L) | 82 | /// Return -s (mod L) |
| 83 | pub fn neg(s: CompressedScalar) CompressedScalar { | 83 | pub fn neg(s: CompressedScalar) CompressedScalar { |
| 84 | const fs: [64]u8 = field_order_s ++ [_]u8{0} ** 32; | 84 | const fs: [64]u8 = field_order_s ++ @as([32]u8, @splat(0)); |
| 85 | var sx: [64]u8 = undefined; | 85 | var sx: [64]u8 = undefined; |
| 86 | sx[0..32].* = s; | 86 | sx[0..32].* = s; |
| 87 | @memset(sx[32..], 0); | 87 | @memset(sx[32..], 0); |
| ... | @@ -862,9 +862,9 @@ test "non-canonical scalar25519" { | ... | @@ -862,9 +862,9 @@ test "non-canonical scalar25519" { |
| 862 | } | 862 | } |
| 863 | 863 | ||
| 864 | test "mulAdd overflow check" { | 864 | test "mulAdd overflow check" { |
| 865 | const a: [32]u8 = [_]u8{0xff} ** 32; | 865 | const a: [32]u8 = @splat(0xff); |
| 866 | const b: [32]u8 = [_]u8{0xff} ** 32; | 866 | const b: [32]u8 = @splat(0xff); |
| 867 | const c: [32]u8 = [_]u8{0xff} ** 32; | 867 | const c: [32]u8 = @splat(0xff); |
| 868 | const x = mulAdd(a, b, c); | 868 | const x = mulAdd(a, b, c); |
| 869 | var buf: [128]u8 = undefined; | 869 | var buf: [128]u8 = undefined; |
| 870 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903"); | 870 | try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903"); |
| ... | @@ -886,7 +886,7 @@ test "random scalar" { | ... | @@ -886,7 +886,7 @@ test "random scalar" { |
| 886 | } | 886 | } |
| 887 | 887 | ||
| 888 | test "64-bit reduction" { | 888 | test "64-bit reduction" { |
| 889 | const bytes = field_order_s ++ [_]u8{0} ** 32; | 889 | const bytes = field_order_s ++ @as([32]u8, @splat(0)); |
| 890 | const x = Scalar.fromBytes64(bytes); | 890 | const x = Scalar.fromBytes64(bytes); |
| 891 | try std.testing.expect(x.isZero()); | 891 | try std.testing.expect(x.isZero()); |
| 892 | } | 892 | } |
lib/std/crypto/25519/x25519.zig+1-1| ... | @@ -181,7 +181,7 @@ test "rfc7748 1,000,000 iterations" { | ... | @@ -181,7 +181,7 @@ test "rfc7748 1,000,000 iterations" { |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | test "edwards25519 -> curve25519 map" { | 183 | test "edwards25519 -> curve25519 map" { |
| 184 | const ed_kp = try crypto.sign.Ed25519.KeyPair.generateDeterministic([_]u8{0x42} ** 32); | 184 | const ed_kp = try crypto.sign.Ed25519.KeyPair.generateDeterministic(@splat(0x42)); |
| 185 | const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp); | 185 | const mont_kp = try X25519.KeyPair.fromEd25519(ed_kp); |
| 186 | try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); | 186 | try htest.assertEqual("90e7595fc89e52fdfddce9c6a43d74dbf6047025ee0462d2d172e8b6a2841d6e", &mont_kp.secret_key); |
| 187 | try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key); | 187 | try htest.assertEqual("cc4f2cdb695dd766f34118eb67b98652fed1d8bc49c330b119bbfa8a64989378", &mont_kp.public_key); |
lib/std/crypto/Certificate.zig+1-1| ... | @@ -1092,7 +1092,7 @@ pub const rsa = struct { | ... | @@ -1092,7 +1092,7 @@ pub const rsa = struct { |
| 1092 | } | 1092 | } |
| 1093 | var m_p_buf: [8 + Hash.digest_length + Hash.digest_length]u8 = undefined; | 1093 | var m_p_buf: [8 + Hash.digest_length + Hash.digest_length]u8 = undefined; |
| 1094 | var m_p = m_p_buf[0 .. 8 + Hash.digest_length + sLen]; | 1094 | var m_p = m_p_buf[0 .. 8 + Hash.digest_length + sLen]; |
| 1095 | std.mem.copyForwards(u8, m_p, &([_]u8{0} ** 8)); | 1095 | std.mem.copyForwards(u8, m_p, @as(*const [8]u8, &@splat(0))); |
| 1096 | std.mem.copyForwards(u8, m_p[8..], &mHash); | 1096 | std.mem.copyForwards(u8, m_p[8..], &mHash); |
| 1097 | std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt); | 1097 | std.mem.copyForwards(u8, m_p[(8 + Hash.digest_length)..], salt); |
| 1098 | 1098 |
lib/std/crypto/Sha1.zig+1-1| ... | @@ -297,7 +297,7 @@ test "sha1 streaming" { | ... | @@ -297,7 +297,7 @@ test "sha1 streaming" { |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | test "sha1 aligned final" { | 299 | test "sha1 aligned final" { |
| 300 | var block = [_]u8{0} ** Sha1.block_length; | 300 | var block: [Sha1.block_length]u8 = @splat(0); |
| 301 | var out: [Sha1.digest_length]u8 = undefined; | 301 | var out: [Sha1.digest_length]u8 = undefined; |
| 302 | 302 | ||
| 303 | var h = Sha1.init(.{}); | 303 | var h = Sha1.init(.{}); |
lib/std/crypto/aegis.zig+45-39| ... | @@ -55,6 +55,14 @@ pub const Aegis256X2_256 = Aegis256XGeneric(2, 256); | ... | @@ -55,6 +55,14 @@ pub const Aegis256X2_256 = Aegis256XGeneric(2, 256); |
| 55 | /// AEGIS-256 with a 256 bit tag | 55 | /// AEGIS-256 with a 256 bit tag |
| 56 | pub const Aegis256_256 = Aegis256XGeneric(1, 256); | 56 | pub const Aegis256_256 = Aegis256XGeneric(1, 256); |
| 57 | 57 | ||
| 58 | /// `inline` to avoid needless binary bloat from generic instantiations since the arguments are | ||
| 59 | /// usually comptime-known and the function is a trivial leaf function. | ||
| 60 | inline fn repeat16u8(comptime count: usize, part: [16]u8) [16 * count]u8 { | ||
| 61 | const buf: [count][part.len]u8 = @splat(part); | ||
| 62 | const ptr: *const [16 * count]u8 = @ptrCast(&buf); | ||
| 63 | return ptr.*; | ||
| 64 | } | ||
| 65 | |||
| 58 | fn State128X(comptime degree: u7) type { | 66 | fn State128X(comptime degree: u7) type { |
| 59 | return struct { | 67 | return struct { |
| 60 | const AesBlockVec = crypto.core.aes.BlockVec(degree); | 68 | const AesBlockVec = crypto.core.aes.BlockVec(degree); |
| ... | @@ -67,10 +75,10 @@ fn State128X(comptime degree: u7) type { | ... | @@ -67,10 +75,10 @@ fn State128X(comptime degree: u7) type { |
| 67 | const alignment = AesBlockVec.native_word_size; | 75 | const alignment = AesBlockVec.native_word_size; |
| 68 | 76 | ||
| 69 | fn init(key: [16]u8, nonce: [16]u8) State { | 77 | fn init(key: [16]u8, nonce: [16]u8) State { |
| 70 | const c1 = AesBlockVec.fromBytes(&[16]u8{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd } ** degree); | 78 | const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd })); |
| 71 | const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree); | 79 | const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 })); |
| 72 | const key_block = AesBlockVec.fromBytes(&(key ** degree)); | 80 | const key_block = AesBlockVec.fromBytes(&repeat16u8(degree, key)); |
| 73 | const nonce_block = AesBlockVec.fromBytes(&(nonce ** degree)); | 81 | const nonce_block = AesBlockVec.fromBytes(&repeat16u8(degree, nonce)); |
| 74 | const blocks = [8]AesBlockVec{ | 82 | const blocks = [8]AesBlockVec{ |
| 75 | key_block.xorBlocks(nonce_block), | 83 | key_block.xorBlocks(nonce_block), |
| 76 | c1, | 84 | c1, |
| ... | @@ -84,7 +92,7 @@ fn State128X(comptime degree: u7) type { | ... | @@ -84,7 +92,7 @@ fn State128X(comptime degree: u7) type { |
| 84 | var state = State{ .blocks = blocks }; | 92 | var state = State{ .blocks = blocks }; |
| 85 | if (degree > 1) { | 93 | if (degree > 1) { |
| 86 | const context_block = ctx: { | 94 | const context_block = ctx: { |
| 87 | var contexts_bytes = [_]u8{0} ** aes_block_length; | 95 | var contexts_bytes: [aes_block_length]u8 = @splat(0); |
| 88 | for (0..degree) |i| { | 96 | for (0..degree) |i| { |
| 89 | contexts_bytes[i * 16] = @intCast(i); | 97 | contexts_bytes[i * 16] = @intCast(i); |
| 90 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); | 98 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); |
| ... | @@ -150,7 +158,7 @@ fn State128X(comptime degree: u7) type { | ... | @@ -150,7 +158,7 @@ fn State128X(comptime degree: u7) type { |
| 150 | const blocks = &state.blocks; | 158 | const blocks = &state.blocks; |
| 151 | const z0 = blocks[6].xorBlocks(blocks[1]).xorBlocks(blocks[2].andBlocks(blocks[3])); | 159 | const z0 = blocks[6].xorBlocks(blocks[1]).xorBlocks(blocks[2].andBlocks(blocks[3])); |
| 152 | const z1 = blocks[2].xorBlocks(blocks[5]).xorBlocks(blocks[6].andBlocks(blocks[7])); | 160 | const z1 = blocks[2].xorBlocks(blocks[5]).xorBlocks(blocks[6].andBlocks(blocks[7])); |
| 153 | var pad = [_]u8{0} ** rate; | 161 | var pad: [rate]u8 = @splat(0); |
| 154 | pad[0..aes_block_length].* = z0.toBytes(); | 162 | pad[0..aes_block_length].* = z0.toBytes(); |
| 155 | pad[aes_block_length..].* = z1.toBytes(); | 163 | pad[aes_block_length..].* = z1.toBytes(); |
| 156 | for (pad[0..src.len], src) |*p, x| p.* ^= x; | 164 | for (pad[0..src.len], src) |*p, x| p.* ^= x; |
| ... | @@ -214,7 +222,7 @@ fn State128X(comptime degree: u7) type { | ... | @@ -214,7 +222,7 @@ fn State128X(comptime degree: u7) type { |
| 214 | state.update(t, t); | 222 | state.update(t, t); |
| 215 | } | 223 | } |
| 216 | if (degree > 1) { | 224 | if (degree > 1) { |
| 217 | var v = [_]u8{0} ** rate; | 225 | var v: [rate]u8 = @splat(0); |
| 218 | switch (tag_bits) { | 226 | switch (tag_bits) { |
| 219 | 128 => { | 227 | 128 => { |
| 220 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes(); | 228 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes(); |
| ... | @@ -362,12 +370,12 @@ fn State256X(comptime degree: u7) type { | ... | @@ -362,12 +370,12 @@ fn State256X(comptime degree: u7) type { |
| 362 | const alignment = AesBlockVec.native_word_size; | 370 | const alignment = AesBlockVec.native_word_size; |
| 363 | 371 | ||
| 364 | fn init(key: [32]u8, nonce: [32]u8) State { | 372 | fn init(key: [32]u8, nonce: [32]u8) State { |
| 365 | const c1 = AesBlockVec.fromBytes(&[16]u8{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd } ** degree); | 373 | const c1 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0xdb, 0x3d, 0x18, 0x55, 0x6d, 0xc2, 0x2f, 0xf1, 0x20, 0x11, 0x31, 0x42, 0x73, 0xb5, 0x28, 0xdd })); |
| 366 | const c2 = AesBlockVec.fromBytes(&[16]u8{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 } ** degree); | 374 | const c2 = AesBlockVec.fromBytes(&repeat16u8(degree, .{ 0x0, 0x1, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15, 0x22, 0x37, 0x59, 0x90, 0xe9, 0x79, 0x62 })); |
| 367 | const key_block1 = AesBlockVec.fromBytes(key[0..16] ** degree); | 375 | const key_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, key[0..16].*)); |
| 368 | const key_block2 = AesBlockVec.fromBytes(key[16..32] ** degree); | 376 | const key_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, key[16..32].*)); |
| 369 | const nonce_block1 = AesBlockVec.fromBytes(nonce[0..16] ** degree); | 377 | const nonce_block1 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[0..16].*)); |
| 370 | const nonce_block2 = AesBlockVec.fromBytes(nonce[16..32] ** degree); | 378 | const nonce_block2 = AesBlockVec.fromBytes(&repeat16u8(degree, nonce[16..32].*)); |
| 371 | const kxn1 = key_block1.xorBlocks(nonce_block1); | 379 | const kxn1 = key_block1.xorBlocks(nonce_block1); |
| 372 | const kxn2 = key_block2.xorBlocks(nonce_block2); | 380 | const kxn2 = key_block2.xorBlocks(nonce_block2); |
| 373 | const blocks = [6]AesBlockVec{ | 381 | const blocks = [6]AesBlockVec{ |
| ... | @@ -381,7 +389,7 @@ fn State256X(comptime degree: u7) type { | ... | @@ -381,7 +389,7 @@ fn State256X(comptime degree: u7) type { |
| 381 | var state = State{ .blocks = blocks }; | 389 | var state = State{ .blocks = blocks }; |
| 382 | if (degree > 1) { | 390 | if (degree > 1) { |
| 383 | const context_block = ctx: { | 391 | const context_block = ctx: { |
| 384 | var contexts_bytes = [_]u8{0} ** aes_block_length; | 392 | var contexts_bytes: [aes_block_length]u8 = @splat(0); |
| 385 | for (0..degree) |i| { | 393 | for (0..degree) |i| { |
| 386 | contexts_bytes[i * 16] = @intCast(i); | 394 | contexts_bytes[i * 16] = @intCast(i); |
| 387 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); | 395 | contexts_bytes[i * 16 + 1] = @intCast(degree - 1); |
| ... | @@ -509,7 +517,7 @@ fn State256X(comptime degree: u7) type { | ... | @@ -509,7 +517,7 @@ fn State256X(comptime degree: u7) type { |
| 509 | state.update(t); | 517 | state.update(t); |
| 510 | } | 518 | } |
| 511 | if (degree > 1) { | 519 | if (degree > 1) { |
| 512 | var v = [_]u8{0} ** rate; | 520 | var v: [rate]u8 = @splat(0); |
| 513 | switch (tag_bits) { | 521 | switch (tag_bits) { |
| 514 | 128 => { | 522 | 128 => { |
| 515 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).toBytes(); | 523 | const tags = blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).xorBlocks(blocks[5]).toBytes(); |
| ... | @@ -746,9 +754,7 @@ fn AegisMac(comptime T: type) type { | ... | @@ -746,9 +754,7 @@ fn AegisMac(comptime T: type) type { |
| 746 | 754 | ||
| 747 | /// Initialize a state for the MAC function, with a default nonce | 755 | /// Initialize a state for the MAC function, with a default nonce |
| 748 | pub fn init(key: *const [key_length]u8) Mac { | 756 | pub fn init(key: *const [key_length]u8) Mac { |
| 749 | return Mac{ | 757 | return .{ .state = .init(key.*, @splat(0)) }; |
| 750 | .state = T.State.init(key.*, [_]u8{0} ** nonce_length), | ||
| 751 | }; | ||
| 752 | } | 758 | } |
| 753 | 759 | ||
| 754 | /// Add data to the state | 760 | /// Add data to the state |
| ... | @@ -781,7 +787,7 @@ fn AegisMac(comptime T: type) type { | ... | @@ -781,7 +787,7 @@ fn AegisMac(comptime T: type) type { |
| 781 | /// Return an authentication tag for the current state | 787 | /// Return an authentication tag for the current state |
| 782 | pub fn final(self: *Mac, out: *[mac_length]u8) void { | 788 | pub fn final(self: *Mac, out: *[mac_length]u8) void { |
| 783 | if (self.off > 0) { | 789 | if (self.off > 0) { |
| 784 | var pad = [_]u8{0} ** block_length; | 790 | var pad: [block_length]u8 = @splat(0); |
| 785 | @memcpy(pad[0..self.off], self.buf[0..self.off]); | 791 | @memcpy(pad[0..self.off], self.buf[0..self.off]); |
| 786 | self.state.absorb(&pad); | 792 | self.state.absorb(&pad); |
| 787 | } | 793 | } |
| ... | @@ -808,8 +814,8 @@ const htest = @import("test.zig"); | ... | @@ -808,8 +814,8 @@ const htest = @import("test.zig"); |
| 808 | const testing = std.testing; | 814 | const testing = std.testing; |
| 809 | 815 | ||
| 810 | test "Aegis128L test vector 1" { | 816 | test "Aegis128L test vector 1" { |
| 811 | const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 14; | 817 | const key: [Aegis128L.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([14]u8, @splat(0x00)); |
| 812 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 13; | 818 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([13]u8, @splat(0x00)); |
| 813 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; | 819 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; |
| 814 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; | 820 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; |
| 815 | var c: [m.len]u8 = undefined; | 821 | var c: [m.len]u8 = undefined; |
| ... | @@ -831,10 +837,10 @@ test "Aegis128L test vector 1" { | ... | @@ -831,10 +837,10 @@ test "Aegis128L test vector 1" { |
| 831 | } | 837 | } |
| 832 | 838 | ||
| 833 | test "Aegis128L test vector 2" { | 839 | test "Aegis128L test vector 2" { |
| 834 | const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16; | 840 | const key: [Aegis128L.key_length]u8 = @splat(0x00); |
| 835 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16; | 841 | const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00); |
| 836 | const ad = [_]u8{}; | 842 | const ad: [0]u8 = .{}; |
| 837 | const m = [_]u8{0x00} ** 16; | 843 | const m: [16]u8 = @splat(0x00); |
| 838 | var c: [m.len]u8 = undefined; | 844 | var c: [m.len]u8 = undefined; |
| 839 | var m2: [m.len]u8 = undefined; | 845 | var m2: [m.len]u8 = undefined; |
| 840 | var tag: [Aegis128L.tag_length]u8 = undefined; | 846 | var tag: [Aegis128L.tag_length]u8 = undefined; |
| ... | @@ -848,8 +854,8 @@ test "Aegis128L test vector 2" { | ... | @@ -848,8 +854,8 @@ test "Aegis128L test vector 2" { |
| 848 | } | 854 | } |
| 849 | 855 | ||
| 850 | test "Aegis128L test vector 3" { | 856 | test "Aegis128L test vector 3" { |
| 851 | const key: [Aegis128L.key_length]u8 = [_]u8{0x00} ** 16; | 857 | const key: [Aegis128L.key_length]u8 = @splat(0x00); |
| 852 | const nonce: [Aegis128L.nonce_length]u8 = [_]u8{0x00} ** 16; | 858 | const nonce: [Aegis128L.nonce_length]u8 = @splat(0x00); |
| 853 | const ad = [_]u8{}; | 859 | const ad = [_]u8{}; |
| 854 | const m = [_]u8{}; | 860 | const m = [_]u8{}; |
| 855 | var c: [m.len]u8 = undefined; | 861 | var c: [m.len]u8 = undefined; |
| ... | @@ -881,8 +887,8 @@ test "Aegis128X2 test vector 1" { | ... | @@ -881,8 +887,8 @@ test "Aegis128X2 test vector 1" { |
| 881 | } | 887 | } |
| 882 | 888 | ||
| 883 | test "Aegis256 test vector 1" { | 889 | test "Aegis256 test vector 1" { |
| 884 | const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** 30; | 890 | const key: [Aegis256.key_length]u8 = [_]u8{ 0x10, 0x01 } ++ @as([30]u8, @splat(0x00)); |
| 885 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** 29; | 891 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([29]u8, @splat(0x00)); |
| 886 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; | 892 | const ad = [8]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; |
| 887 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; | 893 | const m = [32]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }; |
| 888 | var c: [m.len]u8 = undefined; | 894 | var c: [m.len]u8 = undefined; |
| ... | @@ -904,10 +910,10 @@ test "Aegis256 test vector 1" { | ... | @@ -904,10 +910,10 @@ test "Aegis256 test vector 1" { |
| 904 | } | 910 | } |
| 905 | 911 | ||
| 906 | test "Aegis256 test vector 2" { | 912 | test "Aegis256 test vector 2" { |
| 907 | const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32; | 913 | const key: [Aegis256.key_length]u8 = @splat(0x00); |
| 908 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32; | 914 | const nonce: [Aegis256.nonce_length]u8 = @splat(0x00); |
| 909 | const ad = [_]u8{}; | 915 | const ad = [_]u8{}; |
| 910 | const m = [_]u8{0x00} ** 16; | 916 | const m: [16]u8 = @splat(0x00); |
| 911 | var c: [m.len]u8 = undefined; | 917 | var c: [m.len]u8 = undefined; |
| 912 | var m2: [m.len]u8 = undefined; | 918 | var m2: [m.len]u8 = undefined; |
| 913 | var tag: [Aegis256.tag_length]u8 = undefined; | 919 | var tag: [Aegis256.tag_length]u8 = undefined; |
| ... | @@ -921,8 +927,8 @@ test "Aegis256 test vector 2" { | ... | @@ -921,8 +927,8 @@ test "Aegis256 test vector 2" { |
| 921 | } | 927 | } |
| 922 | 928 | ||
| 923 | test "Aegis256 test vector 3" { | 929 | test "Aegis256 test vector 3" { |
| 924 | const key: [Aegis256.key_length]u8 = [_]u8{0x00} ** 32; | 930 | const key: [Aegis256.key_length]u8 = @splat(0x00); |
| 925 | const nonce: [Aegis256.nonce_length]u8 = [_]u8{0x00} ** 32; | 931 | const nonce: [Aegis256.nonce_length]u8 = @splat(0x00); |
| 926 | const ad = [_]u8{}; | 932 | const ad = [_]u8{}; |
| 927 | const m = [_]u8{}; | 933 | const m = [_]u8{}; |
| 928 | var c: [m.len]u8 = undefined; | 934 | var c: [m.len]u8 = undefined; |
| ... | @@ -954,7 +960,7 @@ test "Aegis256X4 test vector 1" { | ... | @@ -954,7 +960,7 @@ test "Aegis256X4 test vector 1" { |
| 954 | } | 960 | } |
| 955 | 961 | ||
| 956 | test "Aegis MAC" { | 962 | test "Aegis MAC" { |
| 957 | const key = [_]u8{0x00} ** Aegis128LMac.key_length; | 963 | const key: [Aegis128LMac.key_length]u8 = @splat(0x00); |
| 958 | var msg: [64]u8 = undefined; | 964 | var msg: [64]u8 = undefined; |
| 959 | for (&msg, 0..) |*m, i| { | 965 | for (&msg, 0..) |*m, i| { |
| 960 | m.* = @as(u8, @truncate(i)); | 966 | m.* = @as(u8, @truncate(i)); |
| ... | @@ -989,8 +995,8 @@ test "Aegis MAC" { | ... | @@ -989,8 +995,8 @@ test "Aegis MAC" { |
| 989 | } | 995 | } |
| 990 | 996 | ||
| 991 | test "AEGISMAC-128* test vectors" { | 997 | test "AEGISMAC-128* test vectors" { |
| 992 | const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (16 - 2); | 998 | const key = [_]u8{ 0x10, 0x01 } ++ @as([16 - 2]u8, @splat(0x00)); |
| 993 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (16 - 3); | 999 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([16 - 3]u8, @splat(0x00)); |
| 994 | var msg: [35]u8 = undefined; | 1000 | var msg: [35]u8 = undefined; |
| 995 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); | 1001 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); |
| 996 | var mac128: [16]u8 = undefined; | 1002 | var mac128: [16]u8 = undefined; |
| ... | @@ -1013,8 +1019,8 @@ test "AEGISMAC-128* test vectors" { | ... | @@ -1013,8 +1019,8 @@ test "AEGISMAC-128* test vectors" { |
| 1013 | } | 1019 | } |
| 1014 | 1020 | ||
| 1015 | test "AEGISMAC-256* test vectors" { | 1021 | test "AEGISMAC-256* test vectors" { |
| 1016 | const key = [_]u8{ 0x10, 0x01 } ++ [_]u8{0x00} ** (32 - 2); | 1022 | const key = [_]u8{ 0x10, 0x01 } ++ @as([32 - 2]u8, @splat(0x00)); |
| 1017 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ [_]u8{0x00} ** (32 - 3); | 1023 | const nonce = [_]u8{ 0x10, 0x00, 0x02 } ++ @as([32 - 3]u8, @splat(0x00)); |
| 1018 | var msg: [35]u8 = undefined; | 1024 | var msg: [35]u8 = undefined; |
| 1019 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); | 1025 | for (&msg, 0..) |*byte, i| byte.* = @truncate(i); |
| 1020 | var mac128: [16]u8 = undefined; | 1026 | var mac128: [16]u8 = undefined; |
lib/std/crypto/aes_ccm.zig+20-20| ... | @@ -201,7 +201,7 @@ fn AesCcm(comptime BlockCipher: type, comptime tag_len: usize, comptime nonce_le | ... | @@ -201,7 +201,7 @@ fn AesCcm(comptime BlockCipher: type, comptime tag_len: usize, comptime nonce_le |
| 201 | const total_ad_size = ad_len_size + ad.len; | 201 | const total_ad_size = ad_len_size + ad.len; |
| 202 | const remainder = total_ad_size % block_length; | 202 | const remainder = total_ad_size % block_length; |
| 203 | if (remainder > 0) { | 203 | if (remainder > 0) { |
| 204 | const padding = [_]u8{0} ** block_length; | 204 | const padding: [block_length]u8 = @splat(0); |
| 205 | ctx.update(padding[0 .. block_length - remainder]); | 205 | ctx.update(padding[0 .. block_length - remainder]); |
| 206 | } | 206 | } |
| 207 | } | 207 | } |
| ... | @@ -264,8 +264,8 @@ const fmt = std.fmt; | ... | @@ -264,8 +264,8 @@ const fmt = std.fmt; |
| 264 | const hexToBytes = fmt.hexToBytes; | 264 | const hexToBytes = fmt.hexToBytes; |
| 265 | 265 | ||
| 266 | test "Aes256Ccm8 - Encrypt decrypt round-trip" { | 266 | test "Aes256Ccm8 - Encrypt decrypt round-trip" { |
| 267 | const key: [32]u8 = [_]u8{0x42} ** 32; | 267 | const key: [32]u8 = @splat(0x42); |
| 268 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 268 | const nonce: [13]u8 = @splat(0x11); |
| 269 | const m = "Hello, World! This is a test message."; | 269 | const m = "Hello, World! This is a test message."; |
| 270 | var c: [m.len]u8 = undefined; | 270 | var c: [m.len]u8 = undefined; |
| 271 | var m2: [m.len]u8 = undefined; | 271 | var m2: [m.len]u8 = undefined; |
| ... | @@ -279,8 +279,8 @@ test "Aes256Ccm8 - Encrypt decrypt round-trip" { | ... | @@ -279,8 +279,8 @@ test "Aes256Ccm8 - Encrypt decrypt round-trip" { |
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | test "Aes256Ccm8 - Associated data" { | 281 | test "Aes256Ccm8 - Associated data" { |
| 282 | const key: [32]u8 = [_]u8{0x42} ** 32; | 282 | const key: [32]u8 = @splat(0x42); |
| 283 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 283 | const nonce: [13]u8 = @splat(0x11); |
| 284 | const m = "secret message"; | 284 | const m = "secret message"; |
| 285 | const ad = "additional authenticated data"; | 285 | const ad = "additional authenticated data"; |
| 286 | var c: [m.len]u8 = undefined; | 286 | var c: [m.len]u8 = undefined; |
| ... | @@ -299,9 +299,9 @@ test "Aes256Ccm8 - Associated data" { | ... | @@ -299,9 +299,9 @@ test "Aes256Ccm8 - Associated data" { |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | test "Aes256Ccm8 - Wrong key" { | 301 | test "Aes256Ccm8 - Wrong key" { |
| 302 | const key: [32]u8 = [_]u8{0x42} ** 32; | 302 | const key: [32]u8 = @splat(0x42); |
| 303 | const wrong_key: [32]u8 = [_]u8{0x43} ** 32; | 303 | const wrong_key: [32]u8 = @splat(0x43); |
| 304 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 304 | const nonce: [13]u8 = @splat(0x11); |
| 305 | const m = "secret"; | 305 | const m = "secret"; |
| 306 | var c: [m.len]u8 = undefined; | 306 | var c: [m.len]u8 = undefined; |
| 307 | var m2: [m.len]u8 = undefined; | 307 | var m2: [m.len]u8 = undefined; |
| ... | @@ -314,8 +314,8 @@ test "Aes256Ccm8 - Wrong key" { | ... | @@ -314,8 +314,8 @@ test "Aes256Ccm8 - Wrong key" { |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | test "Aes256Ccm8 - Corrupted ciphertext" { | 316 | test "Aes256Ccm8 - Corrupted ciphertext" { |
| 317 | const key: [32]u8 = [_]u8{0x42} ** 32; | 317 | const key: [32]u8 = @splat(0x42); |
| 318 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 318 | const nonce: [13]u8 = @splat(0x11); |
| 319 | const m = "secret message"; | 319 | const m = "secret message"; |
| 320 | var c: [m.len]u8 = undefined; | 320 | var c: [m.len]u8 = undefined; |
| 321 | var m2: [m.len]u8 = undefined; | 321 | var m2: [m.len]u8 = undefined; |
| ... | @@ -330,8 +330,8 @@ test "Aes256Ccm8 - Corrupted ciphertext" { | ... | @@ -330,8 +330,8 @@ test "Aes256Ccm8 - Corrupted ciphertext" { |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | test "Aes256Ccm8 - Empty plaintext" { | 332 | test "Aes256Ccm8 - Empty plaintext" { |
| 333 | const key: [32]u8 = [_]u8{0x42} ** 32; | 333 | const key: [32]u8 = @splat(0x42); |
| 334 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 334 | const nonce: [13]u8 = @splat(0x11); |
| 335 | const m = ""; | 335 | const m = ""; |
| 336 | var c: [m.len]u8 = undefined; | 336 | var c: [m.len]u8 = undefined; |
| 337 | var m2: [m.len]u8 = undefined; | 337 | var m2: [m.len]u8 = undefined; |
| ... | @@ -345,8 +345,8 @@ test "Aes256Ccm8 - Empty plaintext" { | ... | @@ -345,8 +345,8 @@ test "Aes256Ccm8 - Empty plaintext" { |
| 345 | } | 345 | } |
| 346 | 346 | ||
| 347 | test "Aes128Ccm8 - Basic functionality" { | 347 | test "Aes128Ccm8 - Basic functionality" { |
| 348 | const key: [16]u8 = [_]u8{0x42} ** 16; | 348 | const key: [16]u8 = @splat(0x42); |
| 349 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 349 | const nonce: [13]u8 = @splat(0x11); |
| 350 | const m = "Test AES-128-CCM"; | 350 | const m = "Test AES-128-CCM"; |
| 351 | var c: [m.len]u8 = undefined; | 351 | var c: [m.len]u8 = undefined; |
| 352 | var m2: [m.len]u8 = undefined; | 352 | var m2: [m.len]u8 = undefined; |
| ... | @@ -360,8 +360,8 @@ test "Aes128Ccm8 - Basic functionality" { | ... | @@ -360,8 +360,8 @@ test "Aes128Ccm8 - Basic functionality" { |
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | test "Aes256Ccm16 - 16-byte tag" { | 362 | test "Aes256Ccm16 - 16-byte tag" { |
| 363 | const key: [32]u8 = [_]u8{0x42} ** 32; | 363 | const key: [32]u8 = @splat(0x42); |
| 364 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 364 | const nonce: [13]u8 = @splat(0x11); |
| 365 | const m = "Test 16-byte tag"; | 365 | const m = "Test 16-byte tag"; |
| 366 | var c: [m.len]u8 = undefined; | 366 | var c: [m.len]u8 = undefined; |
| 367 | var m2: [m.len]u8 = undefined; | 367 | var m2: [m.len]u8 = undefined; |
| ... | @@ -845,8 +845,8 @@ test "Aes128Ccm0 - IEEE 802.15.4 Data Frame (Encryption-only)" { | ... | @@ -845,8 +845,8 @@ test "Aes128Ccm0 - IEEE 802.15.4 Data Frame (Encryption-only)" { |
| 845 | } | 845 | } |
| 846 | 846 | ||
| 847 | test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { | 847 | test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { |
| 848 | const key: [16]u8 = [_]u8{0x42} ** 16; | 848 | const key: [16]u8 = @splat(0x42); |
| 849 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 849 | const nonce: [13]u8 = @splat(0x11); |
| 850 | const m = ""; | 850 | const m = ""; |
| 851 | const ad = "some associated data"; | 851 | const ad = "some associated data"; |
| 852 | var c: [m.len]u8 = undefined; | 852 | var c: [m.len]u8 = undefined; |
| ... | @@ -861,8 +861,8 @@ test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { | ... | @@ -861,8 +861,8 @@ test "Aes128Ccm0 - Zero-length plaintext with encryption-only" { |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | test "Aes256Ccm0 - Basic encryption-only round-trip" { | 863 | test "Aes256Ccm0 - Basic encryption-only round-trip" { |
| 864 | const key: [32]u8 = [_]u8{0x42} ** 32; | 864 | const key: [32]u8 = @splat(0x42); |
| 865 | const nonce: [13]u8 = [_]u8{0x11} ** 13; | 865 | const nonce: [13]u8 = @splat(0x11); |
| 866 | const m = "Hello, CCM* encryption-only mode!"; | 866 | const m = "Hello, CCM* encryption-only mode!"; |
| 867 | var c: [m.len]u8 = undefined; | 867 | var c: [m.len]u8 = undefined; |
| 868 | var m2: [m.len]u8 = undefined; | 868 | var m2: [m.len]u8 = undefined; |
lib/std/crypto/aes_gcm.zig+10-12| ... | @@ -19,8 +19,6 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -19,8 +19,6 @@ fn AesGcm(comptime Aes: anytype) type { |
| 19 | pub const nonce_length = 12; | 19 | pub const nonce_length = 12; |
| 20 | pub const key_length = Aes.key_bits / 8; | 20 | pub const key_length = Aes.key_bits / 8; |
| 21 | 21 | ||
| 22 | const zeros = [_]u8{0} ** 16; | ||
| 23 | |||
| 24 | /// `c`: The ciphertext buffer to write the encrypted data to. | 22 | /// `c`: The ciphertext buffer to write the encrypted data to. |
| 25 | /// `tag`: The authentication tag buffer to write the computed tag to. | 23 | /// `tag`: The authentication tag buffer to write the computed tag to. |
| 26 | /// `m`: The plaintext message to encrypt. | 24 | /// `m`: The plaintext message to encrypt. |
| ... | @@ -33,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -33,7 +31,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 33 | 31 | ||
| 34 | const aes = Aes.initEnc(key); | 32 | const aes = Aes.initEnc(key); |
| 35 | var h: [16]u8 = undefined; | 33 | var h: [16]u8 = undefined; |
| 36 | aes.encrypt(&h, &zeros); | 34 | aes.encrypt(&h, &@splat(0)); |
| 37 | 35 | ||
| 38 | var t: [16]u8 = undefined; | 36 | var t: [16]u8 = undefined; |
| 39 | var j: [16]u8 = undefined; | 37 | var j: [16]u8 = undefined; |
| ... | @@ -75,7 +73,7 @@ fn AesGcm(comptime Aes: anytype) type { | ... | @@ -75,7 +73,7 @@ fn AesGcm(comptime Aes: anytype) type { |
| 75 | 73 | ||
| 76 | const aes = Aes.initEnc(key); | 74 | const aes = Aes.initEnc(key); |
| 77 | var h: [16]u8 = undefined; | 75 | var h: [16]u8 = undefined; |
| 78 | aes.encrypt(&h, &zeros); | 76 | aes.encrypt(&h, &@splat(0)); |
| 79 | 77 | ||
| 80 | var t: [16]u8 = undefined; | 78 | var t: [16]u8 = undefined; |
| 81 | var j: [16]u8 = undefined; | 79 | var j: [16]u8 = undefined; |
| ... | @@ -118,8 +116,8 @@ const htest = @import("test.zig"); | ... | @@ -118,8 +116,8 @@ const htest = @import("test.zig"); |
| 118 | const testing = std.testing; | 116 | const testing = std.testing; |
| 119 | 117 | ||
| 120 | test "Aes256Gcm - Empty message and no associated data" { | 118 | test "Aes256Gcm - Empty message and no associated data" { |
| 121 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 119 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 122 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 120 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 123 | const ad = ""; | 121 | const ad = ""; |
| 124 | const m = ""; | 122 | const m = ""; |
| 125 | var c: [m.len]u8 = undefined; | 123 | var c: [m.len]u8 = undefined; |
| ... | @@ -130,8 +128,8 @@ test "Aes256Gcm - Empty message and no associated data" { | ... | @@ -130,8 +128,8 @@ test "Aes256Gcm - Empty message and no associated data" { |
| 130 | } | 128 | } |
| 131 | 129 | ||
| 132 | test "Aes256Gcm - Associated data only" { | 130 | test "Aes256Gcm - Associated data only" { |
| 133 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 131 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 134 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 132 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 135 | const m = ""; | 133 | const m = ""; |
| 136 | const ad = "Test with associated data"; | 134 | const ad = "Test with associated data"; |
| 137 | var c: [m.len]u8 = undefined; | 135 | var c: [m.len]u8 = undefined; |
| ... | @@ -142,8 +140,8 @@ test "Aes256Gcm - Associated data only" { | ... | @@ -142,8 +140,8 @@ test "Aes256Gcm - Associated data only" { |
| 142 | } | 140 | } |
| 143 | 141 | ||
| 144 | test "Aes256Gcm - Message only" { | 142 | test "Aes256Gcm - Message only" { |
| 145 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 143 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 146 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 144 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 147 | const m = "Test with message only"; | 145 | const m = "Test with message only"; |
| 148 | const ad = ""; | 146 | const ad = ""; |
| 149 | var c: [m.len]u8 = undefined; | 147 | var c: [m.len]u8 = undefined; |
| ... | @@ -159,8 +157,8 @@ test "Aes256Gcm - Message only" { | ... | @@ -159,8 +157,8 @@ test "Aes256Gcm - Message only" { |
| 159 | } | 157 | } |
| 160 | 158 | ||
| 161 | test "Aes256Gcm - Message and associated data" { | 159 | test "Aes256Gcm - Message and associated data" { |
| 162 | const key: [Aes256Gcm.key_length]u8 = [_]u8{0x69} ** Aes256Gcm.key_length; | 160 | const key: [Aes256Gcm.key_length]u8 = @splat(0x69); |
| 163 | const nonce: [Aes256Gcm.nonce_length]u8 = [_]u8{0x42} ** Aes256Gcm.nonce_length; | 161 | const nonce: [Aes256Gcm.nonce_length]u8 = @splat(0x42); |
| 164 | const m = "Test with message"; | 162 | const m = "Test with message"; |
| 165 | const ad = "Test with associated data"; | 163 | const ad = "Test with associated data"; |
| 166 | var c: [m.len]u8 = undefined; | 164 | var c: [m.len]u8 = undefined; |
lib/std/crypto/aes_ocb.zig+9-9| ... | @@ -48,7 +48,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -48,7 +48,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | fn init(aes_enc_ctx: EncryptCtx) Lx { | 50 | fn init(aes_enc_ctx: EncryptCtx) Lx { |
| 51 | const zeros = [_]u8{0} ** 16; | 51 | const zeros: [16]u8 = @splat(0); |
| 52 | var star: Block = undefined; | 52 | var star: Block = undefined; |
| 53 | aes_enc_ctx.encrypt(&star, &zeros); | 53 | aes_enc_ctx.encrypt(&star, &zeros); |
| 54 | const dol = double(star); | 54 | const dol = double(star); |
| ... | @@ -62,8 +62,8 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -62,8 +62,8 @@ fn AesOcb(comptime Aes: anytype) type { |
| 62 | const full_blocks: usize = a.len / 16; | 62 | const full_blocks: usize = a.len / 16; |
| 63 | const x_max = if (full_blocks > 0) math.log2_int(usize, full_blocks) else 0; | 63 | const x_max = if (full_blocks > 0) math.log2_int(usize, full_blocks) else 0; |
| 64 | const lt = lx.precomp(x_max); | 64 | const lt = lx.precomp(x_max); |
| 65 | var sum = [_]u8{0} ** 16; | 65 | var sum: [16]u8 = @splat(0); |
| 66 | var offset = [_]u8{0} ** 16; | 66 | var offset: [16]u8 = @splat(0); |
| 67 | var i: usize = 0; | 67 | var i: usize = 0; |
| 68 | while (i < full_blocks) : (i += 1) { | 68 | while (i < full_blocks) : (i += 1) { |
| 69 | xorWith(&offset, lt[@ctz(i + 1)]); | 69 | xorWith(&offset, lt[@ctz(i + 1)]); |
| ... | @@ -74,7 +74,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -74,7 +74,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 74 | const leftover = a.len % 16; | 74 | const leftover = a.len % 16; |
| 75 | if (leftover > 0) { | 75 | if (leftover > 0) { |
| 76 | xorWith(&offset, lx.star); | 76 | xorWith(&offset, lx.star); |
| 77 | var padded = [_]u8{0} ** 16; | 77 | var padded: [16]u8 = @splat(0); |
| 78 | @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]); | 78 | @memcpy(padded[0..leftover], a[i * 16 ..][0..leftover]); |
| 79 | padded[leftover] = 0x80; | 79 | padded[leftover] = 0x80; |
| 80 | var e = xorBlocks(offset, padded); | 80 | var e = xorBlocks(offset, padded); |
| ... | @@ -85,7 +85,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -85,7 +85,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block { | 87 | fn getOffset(aes_enc_ctx: EncryptCtx, npub: [nonce_length]u8) Block { |
| 88 | var nx = [_]u8{0} ** 16; | 88 | var nx: [16]u8 = @splat(0); |
| 89 | nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1)); | 89 | nx[0] = @as(u8, @intCast(@as(u7, @truncate(tag_length * 8)) << 1)); |
| 90 | nx[16 - nonce_length - 1] = 1; | 90 | nx[16 - nonce_length - 1] = 1; |
| 91 | nx[nx.len - nonce_length ..].* = npub; | 91 | nx[nx.len - nonce_length ..].* = npub; |
| ... | @@ -121,7 +121,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -121,7 +121,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 121 | const lt = lx.precomp(x_max); | 121 | const lt = lx.precomp(x_max); |
| 122 | 122 | ||
| 123 | var offset = getOffset(aes_enc_ctx, npub); | 123 | var offset = getOffset(aes_enc_ctx, npub); |
| 124 | var sum = [_]u8{0} ** 16; | 124 | var sum: [16]u8 = @splat(0); |
| 125 | var i: usize = 0; | 125 | var i: usize = 0; |
| 126 | 126 | ||
| 127 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { | 127 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { |
| ... | @@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -155,7 +155,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 155 | xorWith(&offset, lx.star); | 155 | xorWith(&offset, lx.star); |
| 156 | var pad = offset; | 156 | var pad = offset; |
| 157 | aes_enc_ctx.encrypt(&pad, &pad); | 157 | aes_enc_ctx.encrypt(&pad, &pad); |
| 158 | var e = [_]u8{0} ** 16; | 158 | var e: [16]u8 = @splat(0); |
| 159 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); | 159 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); |
| 160 | e[leftover] = 0x80; | 160 | e[leftover] = 0x80; |
| 161 | for (m[i * 16 ..], 0..) |x, j| { | 161 | for (m[i * 16 ..], 0..) |x, j| { |
| ... | @@ -188,7 +188,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -188,7 +188,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 188 | const lt = lx.precomp(x_max); | 188 | const lt = lx.precomp(x_max); |
| 189 | 189 | ||
| 190 | var offset = getOffset(aes_enc_ctx, npub); | 190 | var offset = getOffset(aes_enc_ctx, npub); |
| 191 | var sum = [_]u8{0} ** 16; | 191 | var sum: [16]u8 = @splat(0); |
| 192 | var i: usize = 0; | 192 | var i: usize = 0; |
| 193 | 193 | ||
| 194 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { | 194 | while (wb > 0 and i + wb <= full_blocks) : (i += wb) { |
| ... | @@ -226,7 +226,7 @@ fn AesOcb(comptime Aes: anytype) type { | ... | @@ -226,7 +226,7 @@ fn AesOcb(comptime Aes: anytype) type { |
| 226 | for (c[i * 16 ..], 0..) |x, j| { | 226 | for (c[i * 16 ..], 0..) |x, j| { |
| 227 | m[i * 16 + j] = pad[j] ^ x; | 227 | m[i * 16 + j] = pad[j] ^ x; |
| 228 | } | 228 | } |
| 229 | var e = [_]u8{0} ** 16; | 229 | var e: [16]u8 = @splat(0); |
| 230 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); | 230 | @memcpy(e[0..leftover], m[i * 16 ..][0..leftover]); |
| 231 | e[leftover] = 0x80; | 231 | e[leftover] = 0x80; |
| 232 | xorWith(&sum, e); | 232 | xorWith(&sum, e); |
lib/std/crypto/argon2.zig+15-15| ... | @@ -281,9 +281,9 @@ fn processSegment( | ... | @@ -281,9 +281,9 @@ fn processSegment( |
| 281 | slice: u32, | 281 | slice: u32, |
| 282 | lane: u24, | 282 | lane: u24, |
| 283 | ) void { | 283 | ) void { |
| 284 | var addresses align(16) = [_]u64{0} ** block_length; | 284 | var addresses: [block_length]u64 align(16) = @splat(0); |
| 285 | var in align(16) = [_]u64{0} ** block_length; | 285 | var in: [block_length]u64 align(16) = @splat(0); |
| 286 | const zero align(16) = [_]u64{0} ** block_length; | 286 | const zero: [block_length]u64 align(16) = @splat(0); |
| 287 | if (mode == .argon2i or (mode == .argon2id and n == 0 and slice < sync_points / 2)) { | 287 | if (mode == .argon2i or (mode == .argon2id and n == 0 and slice < sync_points / 2)) { |
| 288 | in[0] = n; | 288 | in[0] = n; |
| 289 | in[1] = lane; | 289 | in[1] = lane; |
| ... | @@ -629,10 +629,10 @@ pub fn strVerify( | ... | @@ -629,10 +629,10 @@ pub fn strVerify( |
| 629 | test "argon2d" { | 629 | test "argon2d" { |
| 630 | if (true) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/30074 | 630 | if (true) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/30074 |
| 631 | 631 | ||
| 632 | const password = [_]u8{0x01} ** 32; | 632 | const password: [32]u8 = @splat(0x01); |
| 633 | const salt = [_]u8{0x02} ** 16; | 633 | const salt: [16]u8 = @splat(0x02); |
| 634 | const secret = [_]u8{0x03} ** 8; | 634 | const secret: [8]u8 = @splat(0x03); |
| 635 | const ad = [_]u8{0x04} ** 12; | 635 | const ad: [12]u8 = @splat(0x04); |
| 636 | 636 | ||
| 637 | var dk: [32]u8 = undefined; | 637 | var dk: [32]u8 = undefined; |
| 638 | try kdf( | 638 | try kdf( |
| ... | @@ -655,10 +655,10 @@ test "argon2d" { | ... | @@ -655,10 +655,10 @@ test "argon2d" { |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | test "argon2i" { | 657 | test "argon2i" { |
| 658 | const password = [_]u8{0x01} ** 32; | 658 | const password: [32]u8 = @splat(0x01); |
| 659 | const salt = [_]u8{0x02} ** 16; | 659 | const salt: [16]u8 = @splat(0x02); |
| 660 | const secret = [_]u8{0x03} ** 8; | 660 | const secret: [8]u8 = @splat(0x03); |
| 661 | const ad = [_]u8{0x04} ** 12; | 661 | const ad: [12]u8 = @splat(0x04); |
| 662 | 662 | ||
| 663 | var dk: [32]u8 = undefined; | 663 | var dk: [32]u8 = undefined; |
| 664 | try kdf( | 664 | try kdf( |
| ... | @@ -681,10 +681,10 @@ test "argon2i" { | ... | @@ -681,10 +681,10 @@ test "argon2i" { |
| 681 | } | 681 | } |
| 682 | 682 | ||
| 683 | test "argon2id" { | 683 | test "argon2id" { |
| 684 | const password = [_]u8{0x01} ** 32; | 684 | const password: [32]u8 = @splat(0x01); |
| 685 | const salt = [_]u8{0x02} ** 16; | 685 | const salt: [16]u8 = @splat(0x02); |
| 686 | const secret = [_]u8{0x03} ** 8; | 686 | const secret: [8]u8 = @splat(0x03); |
| 687 | const ad = [_]u8{0x04} ** 12; | 687 | const ad: [12]u8 = @splat(0x04); |
| 688 | 688 | ||
| 689 | var dk: [32]u8 = undefined; | 689 | var dk: [32]u8 = undefined; |
| 690 | try kdf( | 690 | try kdf( |
lib/std/crypto/bcrypt.zig+20-10| ... | @@ -868,20 +868,25 @@ test "bcrypt crypt format" { | ... | @@ -868,20 +868,25 @@ test "bcrypt crypt format" { |
| 868 | strVerify(s, "invalid password", verify_options), | 868 | strVerify(s, "invalid password", verify_options), |
| 869 | ); | 869 | ); |
| 870 | 870 | ||
| 871 | const password_100: []const u8 = password: { | ||
| 872 | const arr: [100][8]u8 = @splat("password".*); | ||
| 873 | break :password @ptrCast(&arr); | ||
| 874 | }; | ||
| 875 | |||
| 871 | var long_buf: [hash_length]u8 = undefined; | 876 | var long_buf: [hash_length]u8 = undefined; |
| 872 | var long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 877 | var long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 873 | 878 | ||
| 874 | try testing.expect(mem.startsWith(u8, long_s, crypt_format.prefix)); | 879 | try testing.expect(mem.startsWith(u8, long_s, crypt_format.prefix)); |
| 875 | try strVerify(long_s, "password" ** 100, verify_options); | 880 | try strVerify(long_s, password_100, verify_options); |
| 876 | try testing.expectError( | 881 | try testing.expectError( |
| 877 | error.PasswordVerificationFailed, | 882 | error.PasswordVerificationFailed, |
| 878 | strVerify(long_s, "password" ** 101, verify_options), | 883 | strVerify(long_s, password_100 ++ "password", verify_options), |
| 879 | ); | 884 | ); |
| 880 | 885 | ||
| 881 | hash_options.params.silently_truncate_password = true; | 886 | hash_options.params.silently_truncate_password = true; |
| 882 | verify_options.silently_truncate_password = true; | 887 | verify_options.silently_truncate_password = true; |
| 883 | long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 888 | long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 884 | try strVerify(long_s, "password" ** 101, verify_options); | 889 | try strVerify(long_s, password_100 ++ "password", verify_options); |
| 885 | 890 | ||
| 886 | try strVerify( | 891 | try strVerify( |
| 887 | "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe", | 892 | "$2b$08$WUQKyBCaKpziCwUXHiMVvu40dYVjkTxtWJlftl0PpjY2BxWSvFIEe", |
| ... | @@ -909,20 +914,25 @@ test "bcrypt phc format" { | ... | @@ -909,20 +914,25 @@ test "bcrypt phc format" { |
| 909 | strVerify(s, "invalid password", verify_options), | 914 | strVerify(s, "invalid password", verify_options), |
| 910 | ); | 915 | ); |
| 911 | 916 | ||
| 917 | const password_100: []const u8 = password: { | ||
| 918 | const arr: [100][8]u8 = @splat("password".*); | ||
| 919 | break :password @ptrCast(&arr); | ||
| 920 | }; | ||
| 921 | |||
| 912 | var long_buf: [hash_length * 2]u8 = undefined; | 922 | var long_buf: [hash_length * 2]u8 = undefined; |
| 913 | var long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 923 | var long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 914 | 924 | ||
| 915 | try testing.expect(mem.startsWith(u8, long_s, prefix)); | 925 | try testing.expect(mem.startsWith(u8, long_s, prefix)); |
| 916 | try strVerify(long_s, "password" ** 100, verify_options); | 926 | try strVerify(long_s, password_100, verify_options); |
| 917 | try testing.expectError( | 927 | try testing.expectError( |
| 918 | error.PasswordVerificationFailed, | 928 | error.PasswordVerificationFailed, |
| 919 | strVerify(long_s, "password" ** 101, verify_options), | 929 | strVerify(long_s, password_100 ++ "password", verify_options), |
| 920 | ); | 930 | ); |
| 921 | 931 | ||
| 922 | hash_options.params.silently_truncate_password = true; | 932 | hash_options.params.silently_truncate_password = true; |
| 923 | verify_options.silently_truncate_password = true; | 933 | verify_options.silently_truncate_password = true; |
| 924 | long_s = try strHash("password" ** 100, hash_options, &long_buf, io); | 934 | long_s = try strHash(password_100, hash_options, &long_buf, io); |
| 925 | try strVerify(long_s, "password" ** 101, verify_options); | 935 | try strVerify(long_s, password_100 ++ "password", verify_options); |
| 926 | 936 | ||
| 927 | try strVerify( | 937 | try strVerify( |
| 928 | "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc", | 938 | "$bcrypt$r=5$2NopntlgE2lX3cTwr4qz8A$r3T7iKYQNnY4hAhGjk9RmuyvgrYJZwc", |
lib/std/crypto/benchmark.zig+7-7| ... | @@ -173,7 +173,7 @@ const signatures = [_]Crypto{ | ... | @@ -173,7 +173,7 @@ const signatures = [_]Crypto{ |
| 173 | }; | 173 | }; |
| 174 | 174 | ||
| 175 | pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { | 175 | pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 176 | const msg = [_]u8{0} ** 64; | 176 | const msg: [64]u8 = @splat(0); |
| 177 | const key_pair = Signature.KeyPair.generate(io); | 177 | const key_pair = Signature.KeyPair.generate(io); |
| 178 | 178 | ||
| 179 | const start = benchTime(io); | 179 | const start = benchTime(io); |
| ... | @@ -200,7 +200,7 @@ const signature_verifications = [_]Crypto{ | ... | @@ -200,7 +200,7 @@ const signature_verifications = [_]Crypto{ |
| 200 | }; | 200 | }; |
| 201 | 201 | ||
| 202 | pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { | 202 | pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 203 | const msg = [_]u8{0} ** 64; | 203 | const msg: [64]u8 = @splat(0); |
| 204 | const key_pair = Signature.KeyPair.generate(io); | 204 | const key_pair = Signature.KeyPair.generate(io); |
| 205 | const sig = try key_pair.sign(&msg, null); | 205 | const sig = try key_pair.sign(&msg, null); |
| 206 | 206 | ||
| ... | @@ -223,7 +223,7 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign | ... | @@ -223,7 +223,7 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign |
| 223 | const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }}; | 223 | const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }}; |
| 224 | 224 | ||
| 225 | pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { | 225 | pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 { |
| 226 | const msg = [_]u8{0} ** 64; | 226 | const msg: [64]u8 = @splat(0); |
| 227 | const key_pair = Signature.KeyPair.generate(io); | 227 | const key_pair = Signature.KeyPair.generate(io); |
| 228 | const sig = try key_pair.sign(&msg, null); | 228 | const sig = try key_pair.sign(&msg, null); |
| 229 | 229 | ||
| ... | @@ -367,7 +367,7 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int, io: Io) | ... | @@ -367,7 +367,7 @@ pub fn benchmarkAes(comptime Aes: anytype, comptime count: comptime_int, io: Io) |
| 367 | random.bytes(key[0..]); | 367 | random.bytes(key[0..]); |
| 368 | const ctx = Aes.initEnc(key); | 368 | const ctx = Aes.initEnc(key); |
| 369 | 369 | ||
| 370 | var in = [_]u8{0} ** 16; | 370 | var in: [16]u8 = @splat(0); |
| 371 | 371 | ||
| 372 | const start = benchTime(io); | 372 | const start = benchTime(io); |
| 373 | { | 373 | { |
| ... | @@ -395,7 +395,7 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int, io: Io | ... | @@ -395,7 +395,7 @@ pub fn benchmarkAes8(comptime Aes: anytype, comptime count: comptime_int, io: Io |
| 395 | random.bytes(key[0..]); | 395 | random.bytes(key[0..]); |
| 396 | const ctx = Aes.initEnc(key); | 396 | const ctx = Aes.initEnc(key); |
| 397 | 397 | ||
| 398 | var in = [_]u8{0} ** (8 * 16); | 398 | var in: [8 * 16]u8 = @splat(0); |
| 399 | 399 | ||
| 400 | const start = benchTime(io); | 400 | const start = benchTime(io); |
| 401 | { | 401 | { |
| ... | @@ -444,7 +444,7 @@ fn benchmarkPwhash( | ... | @@ -444,7 +444,7 @@ fn benchmarkPwhash( |
| 444 | comptime count: comptime_int, | 444 | comptime count: comptime_int, |
| 445 | io: std.Io, | 445 | io: std.Io, |
| 446 | ) !f64 { | 446 | ) !f64 { |
| 447 | const password = "testpass" ** 2; | 447 | const password = "testpasstestpass"; |
| 448 | const opts = ty.HashOptions{ | 448 | const opts = ty.HashOptions{ |
| 449 | .allocator = allocator, | 449 | .allocator = allocator, |
| 450 | .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*, | 450 | .params = @as(*const ty.Params, @ptrCast(@alignCast(params))).*, |
| ... | @@ -456,7 +456,7 @@ fn benchmarkPwhash( | ... | @@ -456,7 +456,7 @@ fn benchmarkPwhash( |
| 456 | const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn"; | 456 | const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn"; |
| 457 | const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io; | 457 | const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io; |
| 458 | const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io; | 458 | const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io; |
| 459 | const salt: [16]u8 = .{0} ** 16; | 459 | const salt: [16]u8 = @splat(0); |
| 460 | 460 | ||
| 461 | const start = benchTime(io); | 461 | const start = benchTime(io); |
| 462 | { | 462 | { |
lib/std/crypto/blake2.zig+100-64| ... | @@ -199,7 +199,9 @@ test "blake2s160 single" { | ... | @@ -199,7 +199,9 @@ test "blake2s160 single" { |
| 199 | try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog"); | 199 | try htest.assertEqualHash(Blake2s160, h3, "The quick brown fox jumps over the lazy dog"); |
| 200 | 200 | ||
| 201 | const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; | 201 | const h4 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; |
| 202 | try htest.assertEqualHash(Blake2s160, h4, "a" ** 32 ++ "b" ** 32); | 202 | const repeat_a_32: [32]u8 = @splat('a'); |
| 203 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 204 | try htest.assertEqualHash(Blake2s160, h4, &repeat_a_32 ++ &repeat_b_32); | ||
| 203 | } | 205 | } |
| 204 | 206 | ||
| 205 | test "blake2s160 streaming" { | 207 | test "blake2s160 streaming" { |
| ... | @@ -227,27 +229,30 @@ test "blake2s160 streaming" { | ... | @@ -227,27 +229,30 @@ test "blake2s160 streaming" { |
| 227 | 229 | ||
| 228 | const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; | 230 | const h3 = "b60c4dc60e2681e58fbc24e77f07e02c69e72ed0"; |
| 229 | 231 | ||
| 232 | const repeat_a_32: [32]u8 = @splat('a'); | ||
| 233 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 234 | |||
| 230 | h = Blake2s160.init(.{}); | 235 | h = Blake2s160.init(.{}); |
| 231 | h.update("a" ** 32); | 236 | h.update(&repeat_a_32); |
| 232 | h.update("b" ** 32); | 237 | h.update(&repeat_b_32); |
| 233 | h.final(out[0..]); | 238 | h.final(out[0..]); |
| 234 | try htest.assertEqual(h3, out[0..]); | 239 | try htest.assertEqual(h3, out[0..]); |
| 235 | 240 | ||
| 236 | h = Blake2s160.init(.{}); | 241 | h = Blake2s160.init(.{}); |
| 237 | h.update("a" ** 32 ++ "b" ** 32); | 242 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 238 | h.final(out[0..]); | 243 | h.final(out[0..]); |
| 239 | try htest.assertEqual(h3, out[0..]); | 244 | try htest.assertEqual(h3, out[0..]); |
| 240 | 245 | ||
| 241 | const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68"; | 246 | const h4 = "4667fd60791a7fe41f939bca646b4529e296bd68"; |
| 242 | 247 | ||
| 243 | h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 248 | h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 244 | h.update("a" ** 32); | 249 | h.update(&repeat_a_32); |
| 245 | h.update("b" ** 32); | 250 | h.update(&repeat_b_32); |
| 246 | h.final(out[0..]); | 251 | h.final(out[0..]); |
| 247 | try htest.assertEqual(h4, out[0..]); | 252 | try htest.assertEqual(h4, out[0..]); |
| 248 | 253 | ||
| 249 | h = Blake2s160.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 254 | h = Blake2s160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 250 | h.update("a" ** 32 ++ "b" ** 32); | 255 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 251 | h.final(out[0..]); | 256 | h.final(out[0..]); |
| 252 | try htest.assertEqual(h4, out[0..]); | 257 | try htest.assertEqual(h4, out[0..]); |
| 253 | } | 258 | } |
| ... | @@ -256,7 +261,7 @@ test "comptime blake2s160" { | ... | @@ -256,7 +261,7 @@ test "comptime blake2s160" { |
| 256 | //comptime | 261 | //comptime |
| 257 | { | 262 | { |
| 258 | @setEvalBranchQuota(10000); | 263 | @setEvalBranchQuota(10000); |
| 259 | var block = [_]u8{0} ** Blake2s160.block_length; | 264 | var block: [Blake2s160.block_length]u8 = @splat(0); |
| 260 | var out: [Blake2s160.digest_length]u8 = undefined; | 265 | var out: [Blake2s160.digest_length]u8 = undefined; |
| 261 | 266 | ||
| 262 | const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f"; | 267 | const h1 = "2c56ad9d0b2c8b474aafa93ab307db2f0940105f"; |
| ... | @@ -282,7 +287,9 @@ test "blake2s224 single" { | ... | @@ -282,7 +287,9 @@ test "blake2s224 single" { |
| 282 | try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog"); | 287 | try htest.assertEqualHash(Blake2s224, h3, "The quick brown fox jumps over the lazy dog"); |
| 283 | 288 | ||
| 284 | const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; | 289 | const h4 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; |
| 285 | try htest.assertEqualHash(Blake2s224, h4, "a" ** 32 ++ "b" ** 32); | 290 | const repeat_a_32: [32]u8 = @splat('a'); |
| 291 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 292 | try htest.assertEqualHash(Blake2s224, h4, &repeat_a_32 ++ &repeat_b_32); | ||
| 286 | } | 293 | } |
| 287 | 294 | ||
| 288 | test "blake2s224 streaming" { | 295 | test "blake2s224 streaming" { |
| ... | @@ -308,29 +315,32 @@ test "blake2s224 streaming" { | ... | @@ -308,29 +315,32 @@ test "blake2s224 streaming" { |
| 308 | h.final(out[0..]); | 315 | h.final(out[0..]); |
| 309 | try htest.assertEqual(h2, out[0..]); | 316 | try htest.assertEqual(h2, out[0..]); |
| 310 | 317 | ||
| 318 | const repeat_a_32: [32]u8 = @splat('a'); | ||
| 319 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 320 | |||
| 311 | const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; | 321 | const h3 = "557381a78facd2b298640f4e32113e58967d61420af1aa939d0cfe01"; |
| 312 | 322 | ||
| 313 | h = Blake2s224.init(.{}); | 323 | h = Blake2s224.init(.{}); |
| 314 | h.update("a" ** 32); | 324 | h.update(&repeat_a_32); |
| 315 | h.update("b" ** 32); | 325 | h.update(&repeat_b_32); |
| 316 | h.final(out[0..]); | 326 | h.final(out[0..]); |
| 317 | try htest.assertEqual(h3, out[0..]); | 327 | try htest.assertEqual(h3, out[0..]); |
| 318 | 328 | ||
| 319 | h = Blake2s224.init(.{}); | 329 | h = Blake2s224.init(.{}); |
| 320 | h.update("a" ** 32 ++ "b" ** 32); | 330 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 321 | h.final(out[0..]); | 331 | h.final(out[0..]); |
| 322 | try htest.assertEqual(h3, out[0..]); | 332 | try htest.assertEqual(h3, out[0..]); |
| 323 | 333 | ||
| 324 | const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3"; | 334 | const h4 = "a4d6a9d253441b80e5dfd60a04db169ffab77aec56a2855c402828c3"; |
| 325 | 335 | ||
| 326 | h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 336 | h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 327 | h.update("a" ** 32); | 337 | h.update(&repeat_a_32); |
| 328 | h.update("b" ** 32); | 338 | h.update(&repeat_b_32); |
| 329 | h.final(out[0..]); | 339 | h.final(out[0..]); |
| 330 | try htest.assertEqual(h4, out[0..]); | 340 | try htest.assertEqual(h4, out[0..]); |
| 331 | 341 | ||
| 332 | h = Blake2s224.init(.{ .context = [_]u8{0x69} ** 8, .salt = [_]u8{0x42} ** 8 }); | 342 | h = Blake2s224.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 333 | h.update("a" ** 32 ++ "b" ** 32); | 343 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 334 | h.final(out[0..]); | 344 | h.final(out[0..]); |
| 335 | try htest.assertEqual(h4, out[0..]); | 345 | try htest.assertEqual(h4, out[0..]); |
| 336 | } | 346 | } |
| ... | @@ -338,7 +348,7 @@ test "blake2s224 streaming" { | ... | @@ -338,7 +348,7 @@ test "blake2s224 streaming" { |
| 338 | test "comptime blake2s224" { | 348 | test "comptime blake2s224" { |
| 339 | comptime { | 349 | comptime { |
| 340 | @setEvalBranchQuota(10000); | 350 | @setEvalBranchQuota(10000); |
| 341 | var block = [_]u8{0} ** Blake2s224.block_length; | 351 | var block: [Blake2s224.block_length]u8 = @splat(0); |
| 342 | var out: [Blake2s224.digest_length]u8 = undefined; | 352 | var out: [Blake2s224.digest_length]u8 = undefined; |
| 343 | 353 | ||
| 344 | const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576"; | 354 | const h1 = "86b7611563293f8c73627df7a6d6ba25ca0548c2a6481f7d116ee576"; |
| ... | @@ -364,7 +374,9 @@ test "blake2s256 single" { | ... | @@ -364,7 +374,9 @@ test "blake2s256 single" { |
| 364 | try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog"); | 374 | try htest.assertEqualHash(Blake2s256, h3, "The quick brown fox jumps over the lazy dog"); |
| 365 | 375 | ||
| 366 | const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; | 376 | const h4 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; |
| 367 | try htest.assertEqualHash(Blake2s256, h4, "a" ** 32 ++ "b" ** 32); | 377 | const repeat_a_32: [32]u8 = @splat('a'); |
| 378 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 379 | try htest.assertEqualHash(Blake2s256, h4, &repeat_a_32 ++ &repeat_b_32); | ||
| 368 | } | 380 | } |
| 369 | 381 | ||
| 370 | test "blake2s256 streaming" { | 382 | test "blake2s256 streaming" { |
| ... | @@ -390,16 +402,19 @@ test "blake2s256 streaming" { | ... | @@ -390,16 +402,19 @@ test "blake2s256 streaming" { |
| 390 | h.final(out[0..]); | 402 | h.final(out[0..]); |
| 391 | try htest.assertEqual(h2, out[0..]); | 403 | try htest.assertEqual(h2, out[0..]); |
| 392 | 404 | ||
| 405 | const repeat_a_32: [32]u8 = @splat('a'); | ||
| 406 | const repeat_b_32: [32]u8 = @splat('b'); | ||
| 407 | |||
| 393 | const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; | 408 | const h3 = "8d8711dade07a6b92b9a3ea1f40bee9b2c53ff3edd2a273dec170b0163568977"; |
| 394 | 409 | ||
| 395 | h = Blake2s256.init(.{}); | 410 | h = Blake2s256.init(.{}); |
| 396 | h.update("a" ** 32); | 411 | h.update(&repeat_a_32); |
| 397 | h.update("b" ** 32); | 412 | h.update(&repeat_b_32); |
| 398 | h.final(out[0..]); | 413 | h.final(out[0..]); |
| 399 | try htest.assertEqual(h3, out[0..]); | 414 | try htest.assertEqual(h3, out[0..]); |
| 400 | 415 | ||
| 401 | h = Blake2s256.init(.{}); | 416 | h = Blake2s256.init(.{}); |
| 402 | h.update("a" ** 32 ++ "b" ** 32); | 417 | h.update(&repeat_a_32 ++ &repeat_b_32); |
| 403 | h.final(out[0..]); | 418 | h.final(out[0..]); |
| 404 | try htest.assertEqual(h3, out[0..]); | 419 | try htest.assertEqual(h3, out[0..]); |
| 405 | } | 420 | } |
| ... | @@ -410,18 +425,21 @@ test "blake2s256 keyed" { | ... | @@ -410,18 +425,21 @@ test "blake2s256 keyed" { |
| 410 | const h1 = "10f918da4d74fab3302e48a5d67d03804b1ec95372a62a0f33b7c9fa28ba1ae6"; | 425 | const h1 = "10f918da4d74fab3302e48a5d67d03804b1ec95372a62a0f33b7c9fa28ba1ae6"; |
| 411 | const key = "secret_key"; | 426 | const key = "secret_key"; |
| 412 | 427 | ||
| 413 | Blake2s256.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key }); | 428 | const repeat_a_64: [64]u8 = @splat('a'); |
| 429 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 430 | |||
| 431 | Blake2s256.hash(&repeat_a_64 ++ &repeat_b_64, &out, .{ .key = key }); | ||
| 414 | try htest.assertEqual(h1, out[0..]); | 432 | try htest.assertEqual(h1, out[0..]); |
| 415 | 433 | ||
| 416 | var h = Blake2s256.init(.{ .key = key }); | 434 | var h = Blake2s256.init(.{ .key = key }); |
| 417 | h.update("a" ** 64 ++ "b" ** 64); | 435 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 418 | h.final(out[0..]); | 436 | h.final(out[0..]); |
| 419 | 437 | ||
| 420 | try htest.assertEqual(h1, out[0..]); | 438 | try htest.assertEqual(h1, out[0..]); |
| 421 | 439 | ||
| 422 | h = Blake2s256.init(.{ .key = key }); | 440 | h = Blake2s256.init(.{ .key = key }); |
| 423 | h.update("a" ** 64); | 441 | h.update(&repeat_a_64); |
| 424 | h.update("b" ** 64); | 442 | h.update(&repeat_b_64); |
| 425 | h.final(out[0..]); | 443 | h.final(out[0..]); |
| 426 | 444 | ||
| 427 | try htest.assertEqual(h1, out[0..]); | 445 | try htest.assertEqual(h1, out[0..]); |
| ... | @@ -430,7 +448,7 @@ test "blake2s256 keyed" { | ... | @@ -430,7 +448,7 @@ test "blake2s256 keyed" { |
| 430 | test "comptime blake2s256" { | 448 | test "comptime blake2s256" { |
| 431 | comptime { | 449 | comptime { |
| 432 | @setEvalBranchQuota(10000); | 450 | @setEvalBranchQuota(10000); |
| 433 | var block = [_]u8{0} ** Blake2s256.block_length; | 451 | var block: [Blake2s256.block_length]u8 = @splat(0); |
| 434 | var out: [Blake2s256.digest_length]u8 = undefined; | 452 | var out: [Blake2s256.digest_length]u8 = undefined; |
| 435 | 453 | ||
| 436 | const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3"; | 454 | const h1 = "ae09db7cd54f42b490ef09b6bc541af688e4959bb8c53f359a6f56e38ab454a3"; |
| ... | @@ -623,7 +641,9 @@ test "blake2b160 single" { | ... | @@ -623,7 +641,9 @@ test "blake2b160 single" { |
| 623 | try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog"); | 641 | try htest.assertEqualHash(Blake2b160, h3, "The quick brown fox jumps over the lazy dog"); |
| 624 | 642 | ||
| 625 | const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; | 643 | const h4 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; |
| 626 | try htest.assertEqualHash(Blake2b160, h4, "a" ** 64 ++ "b" ** 64); | 644 | const repeat_a_64: [64]u8 = @splat('a'); |
| 645 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 646 | try htest.assertEqualHash(Blake2b160, h4, &repeat_a_64 ++ &repeat_b_64); | ||
| 627 | } | 647 | } |
| 628 | 648 | ||
| 629 | test "blake2b160 streaming" { | 649 | test "blake2b160 streaming" { |
| ... | @@ -649,36 +669,39 @@ test "blake2b160 streaming" { | ... | @@ -649,36 +669,39 @@ test "blake2b160 streaming" { |
| 649 | h.final(out[0..]); | 669 | h.final(out[0..]); |
| 650 | try htest.assertEqual(h2, out[0..]); | 670 | try htest.assertEqual(h2, out[0..]); |
| 651 | 671 | ||
| 672 | const repeat_a_64: [64]u8 = @splat('a'); | ||
| 673 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 674 | |||
| 652 | const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; | 675 | const h3 = "43758f5de1740f651f1ae39de92260fe8bd5a11f"; |
| 653 | 676 | ||
| 654 | h = Blake2b160.init(.{}); | 677 | h = Blake2b160.init(.{}); |
| 655 | h.update("a" ** 64 ++ "b" ** 64); | 678 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 656 | h.final(out[0..]); | 679 | h.final(out[0..]); |
| 657 | try htest.assertEqual(h3, out[0..]); | 680 | try htest.assertEqual(h3, out[0..]); |
| 658 | 681 | ||
| 659 | h = Blake2b160.init(.{}); | 682 | h = Blake2b160.init(.{}); |
| 660 | h.update("a" ** 64); | 683 | h.update(&repeat_a_64); |
| 661 | h.update("b" ** 64); | 684 | h.update(&repeat_b_64); |
| 662 | h.final(out[0..]); | 685 | h.final(out[0..]); |
| 663 | try htest.assertEqual(h3, out[0..]); | 686 | try htest.assertEqual(h3, out[0..]); |
| 664 | 687 | ||
| 665 | h = Blake2b160.init(.{}); | 688 | h = Blake2b160.init(.{}); |
| 666 | h.update("a" ** 64); | 689 | h.update(&repeat_a_64); |
| 667 | h.update("b" ** 64); | 690 | h.update(&repeat_b_64); |
| 668 | h.final(out[0..]); | 691 | h.final(out[0..]); |
| 669 | try htest.assertEqual(h3, out[0..]); | 692 | try htest.assertEqual(h3, out[0..]); |
| 670 | 693 | ||
| 671 | const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc"; | 694 | const h4 = "72328f8a8200663752fc302d372b5dd9b49dd8dc"; |
| 672 | 695 | ||
| 673 | h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 696 | h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 674 | h.update("a" ** 64); | 697 | h.update(&repeat_a_64); |
| 675 | h.update("b" ** 64); | 698 | h.update(&repeat_b_64); |
| 676 | h.final(out[0..]); | 699 | h.final(out[0..]); |
| 677 | try htest.assertEqual(h4, out[0..]); | 700 | try htest.assertEqual(h4, out[0..]); |
| 678 | 701 | ||
| 679 | h = Blake2b160.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 702 | h = Blake2b160.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 680 | h.update("a" ** 64); | 703 | h.update(&repeat_a_64); |
| 681 | h.update("b" ** 64); | 704 | h.update(&repeat_b_64); |
| 682 | h.final(out[0..]); | 705 | h.final(out[0..]); |
| 683 | try htest.assertEqual(h4, out[0..]); | 706 | try htest.assertEqual(h4, out[0..]); |
| 684 | } | 707 | } |
| ... | @@ -686,7 +709,7 @@ test "blake2b160 streaming" { | ... | @@ -686,7 +709,7 @@ test "blake2b160 streaming" { |
| 686 | test "comptime blake2b160" { | 709 | test "comptime blake2b160" { |
| 687 | comptime { | 710 | comptime { |
| 688 | @setEvalBranchQuota(10000); | 711 | @setEvalBranchQuota(10000); |
| 689 | var block = [_]u8{0} ** Blake2b160.block_length; | 712 | var block: [Blake2b160.block_length]u8 = @splat(0); |
| 690 | var out: [Blake2b160.digest_length]u8 = undefined; | 713 | var out: [Blake2b160.digest_length]u8 = undefined; |
| 691 | 714 | ||
| 692 | const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9"; | 715 | const h1 = "8d26f158f564e3293b42f5e3d34263cb173aa9c9"; |
| ... | @@ -712,7 +735,9 @@ test "blake2b384 single" { | ... | @@ -712,7 +735,9 @@ test "blake2b384 single" { |
| 712 | try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog"); | 735 | try htest.assertEqualHash(Blake2b384, h3, "The quick brown fox jumps over the lazy dog"); |
| 713 | 736 | ||
| 714 | const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; | 737 | const h4 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; |
| 715 | try htest.assertEqualHash(Blake2b384, h4, "a" ** 64 ++ "b" ** 64); | 738 | const repeat_a_64: [64]u8 = @splat('a'); |
| 739 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 740 | try htest.assertEqualHash(Blake2b384, h4, &repeat_a_64 ++ &repeat_b_64); | ||
| 716 | } | 741 | } |
| 717 | 742 | ||
| 718 | test "blake2b384 streaming" { | 743 | test "blake2b384 streaming" { |
| ... | @@ -738,36 +763,39 @@ test "blake2b384 streaming" { | ... | @@ -738,36 +763,39 @@ test "blake2b384 streaming" { |
| 738 | h.final(out[0..]); | 763 | h.final(out[0..]); |
| 739 | try htest.assertEqual(h2, out[0..]); | 764 | try htest.assertEqual(h2, out[0..]); |
| 740 | 765 | ||
| 766 | const repeat_a_64: [64]u8 = @splat('a'); | ||
| 767 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 768 | |||
| 741 | const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; | 769 | const h3 = "b7283f0172fecbbd7eca32ce10d8a6c06b453cb3cf675b33eb4246f0da2bb94a6c0bdd6eec0b5fd71ec4fd51be80bf4c"; |
| 742 | 770 | ||
| 743 | h = Blake2b384.init(.{}); | 771 | h = Blake2b384.init(.{}); |
| 744 | h.update("a" ** 64 ++ "b" ** 64); | 772 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 745 | h.final(out[0..]); | 773 | h.final(out[0..]); |
| 746 | try htest.assertEqual(h3, out[0..]); | 774 | try htest.assertEqual(h3, out[0..]); |
| 747 | 775 | ||
| 748 | h = Blake2b384.init(.{}); | 776 | h = Blake2b384.init(.{}); |
| 749 | h.update("a" ** 64); | 777 | h.update(&repeat_a_64); |
| 750 | h.update("b" ** 64); | 778 | h.update(&repeat_b_64); |
| 751 | h.final(out[0..]); | 779 | h.final(out[0..]); |
| 752 | try htest.assertEqual(h3, out[0..]); | 780 | try htest.assertEqual(h3, out[0..]); |
| 753 | 781 | ||
| 754 | h = Blake2b384.init(.{}); | 782 | h = Blake2b384.init(.{}); |
| 755 | h.update("a" ** 64); | 783 | h.update(&repeat_a_64); |
| 756 | h.update("b" ** 64); | 784 | h.update(&repeat_b_64); |
| 757 | h.final(out[0..]); | 785 | h.final(out[0..]); |
| 758 | try htest.assertEqual(h3, out[0..]); | 786 | try htest.assertEqual(h3, out[0..]); |
| 759 | 787 | ||
| 760 | const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c"; | 788 | const h4 = "934c48fcb197031c71f583d92f98703510805e72142e0b46f5752d1e971bc86c355d556035613ff7a4154b4de09dac5c"; |
| 761 | 789 | ||
| 762 | h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 790 | h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 763 | h.update("a" ** 64); | 791 | h.update(&repeat_a_64); |
| 764 | h.update("b" ** 64); | 792 | h.update(&repeat_b_64); |
| 765 | h.final(out[0..]); | 793 | h.final(out[0..]); |
| 766 | try htest.assertEqual(h4, out[0..]); | 794 | try htest.assertEqual(h4, out[0..]); |
| 767 | 795 | ||
| 768 | h = Blake2b384.init(.{ .context = [_]u8{0x69} ** 16, .salt = [_]u8{0x42} ** 16 }); | 796 | h = Blake2b384.init(.{ .context = @splat(0x69), .salt = @splat(0x42) }); |
| 769 | h.update("a" ** 64); | 797 | h.update(&repeat_a_64); |
| 770 | h.update("b" ** 64); | 798 | h.update(&repeat_b_64); |
| 771 | h.final(out[0..]); | 799 | h.final(out[0..]); |
| 772 | try htest.assertEqual(h4, out[0..]); | 800 | try htest.assertEqual(h4, out[0..]); |
| 773 | } | 801 | } |
| ... | @@ -775,7 +803,7 @@ test "blake2b384 streaming" { | ... | @@ -775,7 +803,7 @@ test "blake2b384 streaming" { |
| 775 | test "comptime blake2b384" { | 803 | test "comptime blake2b384" { |
| 776 | comptime { | 804 | comptime { |
| 777 | @setEvalBranchQuota(20000); | 805 | @setEvalBranchQuota(20000); |
| 778 | var block = [_]u8{0} ** Blake2b384.block_length; | 806 | var block: [Blake2b384.block_length]u8 = @splat(0); |
| 779 | var out: [Blake2b384.digest_length]u8 = undefined; | 807 | var out: [Blake2b384.digest_length]u8 = undefined; |
| 780 | 808 | ||
| 781 | const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d"; | 809 | const h1 = "e8aa1931ea0422e4446fecdd25c16cf35c240b10cb4659dd5c776eddcaa4d922397a589404b46eb2e53d78132d05fd7d"; |
| ... | @@ -801,7 +829,9 @@ test "blake2b512 single" { | ... | @@ -801,7 +829,9 @@ test "blake2b512 single" { |
| 801 | try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog"); | 829 | try htest.assertEqualHash(Blake2b512, h3, "The quick brown fox jumps over the lazy dog"); |
| 802 | 830 | ||
| 803 | const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; | 831 | const h4 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; |
| 804 | try htest.assertEqualHash(Blake2b512, h4, "a" ** 64 ++ "b" ** 64); | 832 | const repeat_a_64: [64]u8 = @splat('a'); |
| 833 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 834 | try htest.assertEqualHash(Blake2b512, h4, &repeat_a_64 ++ &repeat_b_64); | ||
| 805 | } | 835 | } |
| 806 | 836 | ||
| 807 | test "blake2b512 streaming" { | 837 | test "blake2b512 streaming" { |
| ... | @@ -827,16 +857,19 @@ test "blake2b512 streaming" { | ... | @@ -827,16 +857,19 @@ test "blake2b512 streaming" { |
| 827 | h.final(out[0..]); | 857 | h.final(out[0..]); |
| 828 | try htest.assertEqual(h2, out[0..]); | 858 | try htest.assertEqual(h2, out[0..]); |
| 829 | 859 | ||
| 860 | const repeat_a_64: [64]u8 = @splat('a'); | ||
| 861 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 862 | |||
| 830 | const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; | 863 | const h3 = "049980af04d6a2cf16b4b49793c3ed7e40732073788806f2c989ebe9547bda0541d63abe298ec8955d08af48ae731f2e8a0bd6d201655a5473b4aa79d211b920"; |
| 831 | 864 | ||
| 832 | h = Blake2b512.init(.{}); | 865 | h = Blake2b512.init(.{}); |
| 833 | h.update("a" ** 64 ++ "b" ** 64); | 866 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 834 | h.final(out[0..]); | 867 | h.final(out[0..]); |
| 835 | try htest.assertEqual(h3, out[0..]); | 868 | try htest.assertEqual(h3, out[0..]); |
| 836 | 869 | ||
| 837 | h = Blake2b512.init(.{}); | 870 | h = Blake2b512.init(.{}); |
| 838 | h.update("a" ** 64); | 871 | h.update(&repeat_a_64); |
| 839 | h.update("b" ** 64); | 872 | h.update(&repeat_b_64); |
| 840 | h.final(out[0..]); | 873 | h.final(out[0..]); |
| 841 | try htest.assertEqual(h3, out[0..]); | 874 | try htest.assertEqual(h3, out[0..]); |
| 842 | } | 875 | } |
| ... | @@ -847,18 +880,21 @@ test "blake2b512 keyed" { | ... | @@ -847,18 +880,21 @@ test "blake2b512 keyed" { |
| 847 | const h1 = "8a978060ccaf582f388f37454363071ac9a67e3a704585fd879fb8a419a447e389c7c6de790faa20a7a7dccf197de736bc5b40b98a930b36df5bee7555750c4d"; | 880 | const h1 = "8a978060ccaf582f388f37454363071ac9a67e3a704585fd879fb8a419a447e389c7c6de790faa20a7a7dccf197de736bc5b40b98a930b36df5bee7555750c4d"; |
| 848 | const key = "secret_key"; | 881 | const key = "secret_key"; |
| 849 | 882 | ||
| 850 | Blake2b512.hash("a" ** 64 ++ "b" ** 64, &out, .{ .key = key }); | 883 | const repeat_a_64: [64]u8 = @splat('a'); |
| 884 | const repeat_b_64: [64]u8 = @splat('b'); | ||
| 885 | |||
| 886 | Blake2b512.hash(&repeat_a_64 ++ &repeat_b_64, &out, .{ .key = key }); | ||
| 851 | try htest.assertEqual(h1, out[0..]); | 887 | try htest.assertEqual(h1, out[0..]); |
| 852 | 888 | ||
| 853 | var h = Blake2b512.init(.{ .key = key }); | 889 | var h = Blake2b512.init(.{ .key = key }); |
| 854 | h.update("a" ** 64 ++ "b" ** 64); | 890 | h.update(&repeat_a_64 ++ &repeat_b_64); |
| 855 | h.final(out[0..]); | 891 | h.final(out[0..]); |
| 856 | 892 | ||
| 857 | try htest.assertEqual(h1, out[0..]); | 893 | try htest.assertEqual(h1, out[0..]); |
| 858 | 894 | ||
| 859 | h = Blake2b512.init(.{ .key = key }); | 895 | h = Blake2b512.init(.{ .key = key }); |
| 860 | h.update("a" ** 64); | 896 | h.update(&repeat_a_64); |
| 861 | h.update("b" ** 64); | 897 | h.update(&repeat_b_64); |
| 862 | h.final(out[0..]); | 898 | h.final(out[0..]); |
| 863 | 899 | ||
| 864 | try htest.assertEqual(h1, out[0..]); | 900 | try htest.assertEqual(h1, out[0..]); |
| ... | @@ -867,7 +903,7 @@ test "blake2b512 keyed" { | ... | @@ -867,7 +903,7 @@ test "blake2b512 keyed" { |
| 867 | test "comptime blake2b512" { | 903 | test "comptime blake2b512" { |
| 868 | comptime { | 904 | comptime { |
| 869 | @setEvalBranchQuota(12000); | 905 | @setEvalBranchQuota(12000); |
| 870 | var block = [_]u8{0} ** Blake2b512.block_length; | 906 | var block: [Blake2b512.block_length]u8 = @splat(0); |
| 871 | var out: [Blake2b512.digest_length]u8 = undefined; | 907 | var out: [Blake2b512.digest_length]u8 = undefined; |
| 872 | 908 | ||
| 873 | const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41"; | 909 | const h1 = "865939e120e6805438478841afb739ae4250cf372653078a065cdcfffca4caf798e6d462b65d658fc165782640eded70963449ae1500fb0f24981d7727e22c41"; |
lib/std/crypto/cbc_mac.zig+1-1| ... | @@ -21,7 +21,7 @@ pub fn CbcMac(comptime BlockCipher: type) type { | ... | @@ -21,7 +21,7 @@ pub fn CbcMac(comptime BlockCipher: type) type { |
| 21 | pub const mac_length = block_length; | 21 | pub const mac_length = block_length; |
| 22 | 22 | ||
| 23 | cipher_ctx: BlockCipherCtx, | 23 | cipher_ctx: BlockCipherCtx, |
| 24 | buf: Block = [_]u8{0} ** block_length, | 24 | buf: Block = @splat(0), |
| 25 | pos: usize = 0, | 25 | pos: usize = 0, |
| 26 | 26 | ||
| 27 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { | 27 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
lib/std/crypto/chacha20.zig+10-10| ... | @@ -648,7 +648,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -648,7 +648,7 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 648 | assert(c.len == m.len); | 648 | assert(c.len == m.len); |
| 649 | assert(m.len <= 64 * (@as(u39, 1 << 32) - 1)); | 649 | assert(m.len <= 64 * (@as(u39, 1 << 32) - 1)); |
| 650 | 650 | ||
| 651 | var polyKey = [_]u8{0} ** 32; | 651 | var polyKey: [32]u8 = @splat(0); |
| 652 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); | 652 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); |
| 653 | 653 | ||
| 654 | ChaChaIETF(rounds_nb).xor(c[0..m.len], m, 1, k, npub); | 654 | ChaChaIETF(rounds_nb).xor(c[0..m.len], m, 1, k, npub); |
| ... | @@ -656,13 +656,13 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -656,13 +656,13 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 656 | var mac = Poly1305.init(polyKey[0..]); | 656 | var mac = Poly1305.init(polyKey[0..]); |
| 657 | mac.update(ad); | 657 | mac.update(ad); |
| 658 | if (ad.len % 16 != 0) { | 658 | if (ad.len % 16 != 0) { |
| 659 | const zeros = [_]u8{0} ** 16; | 659 | const zeros: [16]u8 = @splat(0); |
| 660 | const padding = 16 - (ad.len % 16); | 660 | const padding = 16 - (ad.len % 16); |
| 661 | mac.update(zeros[0..padding]); | 661 | mac.update(zeros[0..padding]); |
| 662 | } | 662 | } |
| 663 | mac.update(c[0..m.len]); | 663 | mac.update(c[0..m.len]); |
| 664 | if (m.len % 16 != 0) { | 664 | if (m.len % 16 != 0) { |
| 665 | const zeros = [_]u8{0} ** 16; | 665 | const zeros: [16]u8 = @splat(0); |
| 666 | const padding = 16 - (m.len % 16); | 666 | const padding = 16 - (m.len % 16); |
| 667 | mac.update(zeros[0..padding]); | 667 | mac.update(zeros[0..padding]); |
| 668 | } | 668 | } |
| ... | @@ -685,20 +685,20 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { | ... | @@ -685,20 +685,20 @@ fn ChaChaPoly1305(comptime rounds_nb: usize) type { |
| 685 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { | 685 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { |
| 686 | assert(c.len == m.len); | 686 | assert(c.len == m.len); |
| 687 | 687 | ||
| 688 | var polyKey = [_]u8{0} ** 32; | 688 | var polyKey: [32]u8 = @splat(0); |
| 689 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); | 689 | ChaChaIETF(rounds_nb).xor(polyKey[0..], polyKey[0..], 0, k, npub); |
| 690 | 690 | ||
| 691 | var mac = Poly1305.init(polyKey[0..]); | 691 | var mac = Poly1305.init(polyKey[0..]); |
| 692 | 692 | ||
| 693 | mac.update(ad); | 693 | mac.update(ad); |
| 694 | if (ad.len % 16 != 0) { | 694 | if (ad.len % 16 != 0) { |
| 695 | const zeros = [_]u8{0} ** 16; | 695 | const zeros: [16]u8 = @splat(0); |
| 696 | const padding = 16 - (ad.len % 16); | 696 | const padding = 16 - (ad.len % 16); |
| 697 | mac.update(zeros[0..padding]); | 697 | mac.update(zeros[0..padding]); |
| 698 | } | 698 | } |
| 699 | mac.update(c); | 699 | mac.update(c); |
| 700 | if (c.len % 16 != 0) { | 700 | if (c.len % 16 != 0) { |
| 701 | const zeros = [_]u8{0} ** 16; | 701 | const zeros: [16]u8 = @splat(0); |
| 702 | const padding = 16 - (c.len % 16); | 702 | const padding = 16 - (c.len % 16); |
| 703 | mac.update(zeros[0..padding]); | 703 | mac.update(zeros[0..padding]); |
| 704 | } | 704 | } |
| ... | @@ -759,8 +759,8 @@ test "AEAD API" { | ... | @@ -759,8 +759,8 @@ test "AEAD API" { |
| 759 | const ad = "Additional data"; | 759 | const ad = "Additional data"; |
| 760 | 760 | ||
| 761 | inline for (aeads) |aead| { | 761 | inline for (aeads) |aead| { |
| 762 | const key = [_]u8{69} ** aead.key_length; | 762 | const key: [aead.key_length]u8 = @splat(69); |
| 763 | const nonce = [_]u8{42} ** aead.nonce_length; | 763 | const nonce: [aead.nonce_length]u8 = @splat(42); |
| 764 | var c: [m.len]u8 = undefined; | 764 | var c: [m.len]u8 = undefined; |
| 765 | var tag: [aead.tag_length]u8 = undefined; | 765 | var tag: [aead.tag_length]u8 = undefined; |
| 766 | var out: [m.len]u8 = undefined; | 766 | var out: [m.len]u8 = undefined; |
| ... | @@ -1138,8 +1138,8 @@ test "open" { | ... | @@ -1138,8 +1138,8 @@ test "open" { |
| 1138 | } | 1138 | } |
| 1139 | 1139 | ||
| 1140 | test "xchacha20" { | 1140 | test "xchacha20" { |
| 1141 | const key = [_]u8{69} ** 32; | 1141 | const key: [32]u8 = @splat(69); |
| 1142 | const nonce = [_]u8{42} ** 24; | 1142 | const nonce: [24]u8 = @splat(42); |
| 1143 | const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."; | 1143 | const m = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it."; |
| 1144 | { | 1144 | { |
| 1145 | var c: [m.len]u8 = undefined; | 1145 | var c: [m.len]u8 = undefined; |
lib/std/crypto/cmac.zig+2-2| ... | @@ -20,7 +20,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -20,7 +20,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 20 | cipher_ctx: BlockCipherCtx, | 20 | cipher_ctx: BlockCipherCtx, |
| 21 | k1: Block, | 21 | k1: Block, |
| 22 | k2: Block, | 22 | k2: Block, |
| 23 | buf: Block = [_]u8{0} ** block_length, | 23 | buf: Block = @splat(0), |
| 24 | pos: usize = 0, | 24 | pos: usize = 0, |
| 25 | 25 | ||
| 26 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { | 26 | pub fn create(out: *[mac_length]u8, msg: []const u8, key: *const [key_length]u8) void { |
| ... | @@ -31,7 +31,7 @@ pub fn Cmac(comptime BlockCipher: type) type { | ... | @@ -31,7 +31,7 @@ pub fn Cmac(comptime BlockCipher: type) type { |
| 31 | 31 | ||
| 32 | pub fn init(key: *const [key_length]u8) Self { | 32 | pub fn init(key: *const [key_length]u8) Self { |
| 33 | const cipher_ctx = BlockCipher.initEnc(key.*); | 33 | const cipher_ctx = BlockCipher.initEnc(key.*); |
| 34 | const zeros = [_]u8{0} ** block_length; | 34 | const zeros: [block_length]u8 = @splat(0); |
| 35 | var k1: Block = undefined; | 35 | var k1: Block = undefined; |
| 36 | cipher_ctx.encrypt(&k1, &zeros); | 36 | cipher_ctx.encrypt(&k1, &zeros); |
| 37 | k1 = double(k1); | 37 | k1 = double(k1); |
lib/std/crypto/codecs/asn1.zig+1-1| ... | @@ -233,7 +233,7 @@ test Element { | ... | @@ -233,7 +233,7 @@ test Element { |
| 233 | .slice = Element.Slice{ .start = 2, .end = short_form.len }, | 233 | .slice = Element.Slice{ .start = 2, .end = short_form.len }, |
| 234 | }, Element.decode(&short_form, 0)); | 234 | }, Element.decode(&short_form, 0)); |
| 235 | 235 | ||
| 236 | const long_form = [_]u8{ 0x30, 129, 129 } ++ [_]u8{0} ** 129; | 236 | const long_form = [_]u8{ 0x30, 129, 129 } ++ @as([129]u8, @splat(0)); |
| 237 | try std.testing.expectEqual(Element{ | 237 | try std.testing.expectEqual(Element{ |
| 238 | .tag = Tag.universal(.sequence, true), | 238 | .tag = Tag.universal(.sequence, true), |
| 239 | .slice = Element.Slice{ .start = 3, .end = long_form.len }, | 239 | .slice = Element.Slice{ .start = 3, .end = long_form.len }, |
lib/std/crypto/ecdsa.zig+9-9| ... | @@ -212,7 +212,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -212,7 +212,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 212 | fn finalizePrehashed(self: *Signer, msg_hash: [Hash.digest_length]u8) (IdentityElementError || NonCanonicalError)!Signature { | 212 | fn finalizePrehashed(self: *Signer, msg_hash: [Hash.digest_length]u8) (IdentityElementError || NonCanonicalError)!Signature { |
| 213 | const scalar_encoded_length = Curve.scalar.encoded_length; | 213 | const scalar_encoded_length = Curve.scalar.encoded_length; |
| 214 | const h_len = @max(Hash.digest_length, scalar_encoded_length); | 214 | const h_len = @max(Hash.digest_length, scalar_encoded_length); |
| 215 | var h: [h_len]u8 = [_]u8{0} ** (h_len - Hash.digest_length) ++ msg_hash; | 215 | var h: [h_len]u8 = @as([h_len - Hash.digest_length]u8, @splat(0)) ++ msg_hash; |
| 216 | 216 | ||
| 217 | std.debug.assert(h.len >= scalar_encoded_length); | 217 | std.debug.assert(h.len >= scalar_encoded_length); |
| 218 | const z = reduceToScalar(scalar_encoded_length, h[0..scalar_encoded_length].*); | 218 | const z = reduceToScalar(scalar_encoded_length, h[0..scalar_encoded_length].*); |
| ... | @@ -275,7 +275,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -275,7 +275,7 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 275 | fn verifyPrehashed(self: *Verifier, msg_hash: [Hash.digest_length]u8) VerifyError!void { | 275 | fn verifyPrehashed(self: *Verifier, msg_hash: [Hash.digest_length]u8) VerifyError!void { |
| 276 | const ht = Curve.scalar.encoded_length; | 276 | const ht = Curve.scalar.encoded_length; |
| 277 | const h_len = @max(Hash.digest_length, ht); | 277 | const h_len = @max(Hash.digest_length, ht); |
| 278 | var h: [h_len]u8 = [_]u8{0} ** (h_len - Hash.digest_length) ++ msg_hash; | 278 | var h: [h_len]u8 = @as([h_len - Hash.digest_length]u8, @splat(0)) ++ msg_hash; |
| 279 | 279 | ||
| 280 | const z = reduceToScalar(ht, h[0..ht].*); | 280 | const z = reduceToScalar(ht, h[0..ht].*); |
| 281 | if (z.isZero()) { | 281 | if (z.isZero()) { |
| ... | @@ -316,8 +316,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -316,8 +316,8 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 316 | /// | 316 | /// |
| 317 | /// Except in tests, applications should generally call `generate()` instead of this function. | 317 | /// Except in tests, applications should generally call `generate()` instead of this function. |
| 318 | pub fn generateDeterministic(seed: [seed_length]u8) IdentityElementError!KeyPair { | 318 | pub fn generateDeterministic(seed: [seed_length]u8) IdentityElementError!KeyPair { |
| 319 | const h = [_]u8{0x00} ** Hash.digest_length; | 319 | const h: [Hash.digest_length]u8 = @splat(0x00); |
| 320 | const k0 = [_]u8{0x01} ** SecretKey.encoded_length; | 320 | const k0: [SecretKey.encoded_length]u8 = @splat(0x01); |
| 321 | const secret_key = deterministicScalar(h, k0, seed).toBytes(.big); | 321 | const secret_key = deterministicScalar(h, k0, seed).toBytes(.big); |
| 322 | return fromSecretKey(SecretKey{ .bytes = secret_key }); | 322 | return fromSecretKey(SecretKey{ .bytes = secret_key }); |
| 323 | } | 323 | } |
| ... | @@ -367,11 +367,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -367,11 +367,11 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 367 | // Reduce the coordinate of a field element to the scalar field. | 367 | // Reduce the coordinate of a field element to the scalar field. |
| 368 | fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar { | 368 | fn reduceToScalar(comptime unreduced_len: usize, s: [unreduced_len]u8) Curve.scalar.Scalar { |
| 369 | if (unreduced_len >= 48) { | 369 | if (unreduced_len >= 48) { |
| 370 | var xs = [_]u8{0} ** 64; | 370 | var xs: [64]u8 = @splat(0); |
| 371 | @memcpy(xs[xs.len - s.len ..], s[0..]); | 371 | @memcpy(xs[xs.len - s.len ..], s[0..]); |
| 372 | return Curve.scalar.Scalar.fromBytes64(xs, .big); | 372 | return Curve.scalar.Scalar.fromBytes64(xs, .big); |
| 373 | } | 373 | } |
| 374 | var xs = [_]u8{0} ** 48; | 374 | var xs: [48]u8 = @splat(0); |
| 375 | @memcpy(xs[xs.len - s.len ..], s[0..]); | 375 | @memcpy(xs[xs.len - s.len ..], s[0..]); |
| 376 | return Curve.scalar.Scalar.fromBytes48(xs, .big); | 376 | return Curve.scalar.Scalar.fromBytes48(xs, .big); |
| 377 | } | 377 | } |
| ... | @@ -379,9 +379,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { | ... | @@ -379,9 +379,9 @@ pub fn Ecdsa(comptime Curve: type, comptime Hash: type) type { |
| 379 | // Create a deterministic scalar according to a secret key and optional noise. | 379 | // Create a deterministic scalar according to a secret key and optional noise. |
| 380 | // This uses the overly conservative scheme from the "Deterministic ECDSA and EdDSA Signatures with Additional Randomness" draft. | 380 | // This uses the overly conservative scheme from the "Deterministic ECDSA and EdDSA Signatures with Additional Randomness" draft. |
| 381 | fn deterministicScalar(h: [Hash.digest_length]u8, secret_key: Curve.scalar.CompressedScalar, noise: ?[noise_length]u8) Curve.scalar.Scalar { | 381 | fn deterministicScalar(h: [Hash.digest_length]u8, secret_key: Curve.scalar.CompressedScalar, noise: ?[noise_length]u8) Curve.scalar.Scalar { |
| 382 | var k = [_]u8{0x00} ** h.len; | 382 | var k: [h.len]u8 = @splat(0); |
| 383 | var m = [_]u8{0x00} ** (h.len + 1 + noise_length + secret_key.len + h.len); | 383 | var m: [h.len + 1 + noise_length + secret_key.len + h.len]u8 = @splat(0); |
| 384 | var t = [_]u8{0x00} ** Curve.scalar.encoded_length; | 384 | var t: [Curve.scalar.encoded_length]u8 = @splat(0); |
| 385 | const m_v = m[0..h.len]; | 385 | const m_v = m[0..h.len]; |
| 386 | const m_i = &m[m_v.len]; | 386 | const m_i = &m[m_v.len]; |
| 387 | const m_z = m[m_v.len + 1 ..][0..noise_length]; | 387 | const m_z = m[m_v.len + 1 ..][0..noise_length]; |
lib/std/crypto/ff.zig+2-2| ... | @@ -96,7 +96,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { | ... | @@ -96,7 +96,7 @@ pub fn Uint(comptime max_bits: comptime_int) type { |
| 96 | 96 | ||
| 97 | /// The zero integer. | 97 | /// The zero integer. |
| 98 | pub const zero: Self = .{ | 98 | pub const zero: Self = .{ |
| 99 | .limbs_buffer = [1]Limb{0} ** max_limbs_count, | 99 | .limbs_buffer = @splat(0), |
| 100 | .limbs_len = max_limbs_count, | 100 | .limbs_len = max_limbs_count, |
| 101 | }; | 101 | }; |
| 102 | 102 | ||
| ... | @@ -738,7 +738,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type { | ... | @@ -738,7 +738,7 @@ pub fn Modulus(comptime max_bits: comptime_int) type { |
| 738 | } | 738 | } |
| 739 | } else { | 739 | } else { |
| 740 | // Use a precomputation table for large exponents | 740 | // Use a precomputation table for large exponents |
| 741 | var pc = [1]Fe{x} ++ [_]Fe{self.zero} ** 14; | 741 | var pc: [15]Fe = [1]Fe{x} ++ @as([14]Fe, @splat(self.zero)); |
| 742 | if (!x.montgomery) { | 742 | if (!x.montgomery) { |
| 743 | self.toMontgomery(&pc[0]) catch unreachable; | 743 | self.toMontgomery(&pc[0]) catch unreachable; |
| 744 | } | 744 | } |
lib/std/crypto/ghash_polyval.zig+4-4| ... | @@ -417,8 +417,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { | ... | @@ -417,8 +417,8 @@ fn Hash(comptime endian: std.builtin.Endian, comptime shift_key: bool) type { |
| 417 | const htest = @import("test.zig"); | 417 | const htest = @import("test.zig"); |
| 418 | 418 | ||
| 419 | test "ghash" { | 419 | test "ghash" { |
| 420 | const key = [_]u8{0x42} ** 16; | 420 | const key: [16]u8 = @splat(0x42); |
| 421 | const m = [_]u8{0x69} ** 256; | 421 | const m: [256]u8 = @splat(0x69); |
| 422 | 422 | ||
| 423 | var st = Ghash.init(&key); | 423 | var st = Ghash.init(&key); |
| 424 | st.update(&m); | 424 | st.update(&m); |
| ... | @@ -467,8 +467,8 @@ test "ghash2" { | ... | @@ -467,8 +467,8 @@ test "ghash2" { |
| 467 | } | 467 | } |
| 468 | 468 | ||
| 469 | test "polyval" { | 469 | test "polyval" { |
| 470 | const key = [_]u8{0x42} ** 16; | 470 | const key: [16]u8 = @splat(0x42); |
| 471 | const m = [_]u8{0x69} ** 256; | 471 | const m: [256]u8 = @splat(0x69); |
| 472 | 472 | ||
| 473 | var st = Polyval.init(&key); | 473 | var st = Polyval.init(&key); |
| 474 | st.update(&m); | 474 | st.update(&m); |
lib/std/crypto/hkdf.zig+1-1| ... | @@ -72,7 +72,7 @@ pub fn Hkdf(comptime Hmac: type) type { | ... | @@ -72,7 +72,7 @@ pub fn Hkdf(comptime Hmac: type) type { |
| 72 | const htest = @import("test.zig"); | 72 | const htest = @import("test.zig"); |
| 73 | 73 | ||
| 74 | test "Hkdf" { | 74 | test "Hkdf" { |
| 75 | const ikm = [_]u8{0x0b} ** 22; | 75 | const ikm: [22]u8 = @splat(0x0b); |
| 76 | const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; | 76 | const salt = [_]u8{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c }; |
| 77 | const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; | 77 | const context = [_]u8{ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9 }; |
| 78 | const kdf = HkdfSha256; | 78 | const kdf = HkdfSha256; |
lib/std/crypto/isap.zig+3-3| ... | @@ -42,7 +42,7 @@ pub const IsapA128A = struct { | ... | @@ -42,7 +42,7 @@ pub const IsapA128A = struct { |
| 42 | break; | 42 | break; |
| 43 | } | 43 | } |
| 44 | } else { | 44 | } else { |
| 45 | var padded = [_]u8{0} ** 8; | 45 | var padded: [8]u8 = @splat(0); |
| 46 | @memcpy(padded[0..left], m[i..]); | 46 | @memcpy(padded[0..left], m[i..]); |
| 47 | padded[left] = 0x80; | 47 | padded[left] = 0x80; |
| 48 | isap.st.addBytes(&padded); | 48 | isap.st.addBytes(&padded); |
| ... | @@ -169,8 +169,8 @@ pub const IsapA128A = struct { | ... | @@ -169,8 +169,8 @@ pub const IsapA128A = struct { |
| 169 | }; | 169 | }; |
| 170 | 170 | ||
| 171 | test "ISAP" { | 171 | test "ISAP" { |
| 172 | const k = [_]u8{1} ** 16; | 172 | const k: [16]u8 = @splat(1); |
| 173 | const n = [_]u8{2} ** 16; | 173 | const n: [16]u8 = @splat(2); |
| 174 | var tag: [16]u8 = undefined; | 174 | var tag: [16]u8 = undefined; |
| 175 | const ad = "ad"; | 175 | const ad = "ad"; |
| 176 | var msg = "test"; | 176 | var msg = "test"; |
lib/std/crypto/kangarootwelve.zig+1-1| ... | @@ -881,7 +881,7 @@ fn ktMultiThreaded( | ... | @@ -881,7 +881,7 @@ fn ktMultiThreaded( |
| 881 | // Buffer for out-of-order results (select_buf slots get reused) | 881 | // Buffer for out-of-order results (select_buf slots get reused) |
| 882 | const pending_cv_buf = try allocator.alloc([leaves_per_batch * cv_size]u8, max_concurrent); | 882 | const pending_cv_buf = try allocator.alloc([leaves_per_batch * cv_size]u8, max_concurrent); |
| 883 | defer allocator.free(pending_cv_buf); | 883 | defer allocator.free(pending_cv_buf); |
| 884 | var pending_cv_lens: [256]usize = .{0} ** 256; | 884 | var pending_cv_lens: [256]usize = @splat(0); |
| 885 | 885 | ||
| 886 | var select_outstanding: usize = 0; | 886 | var select_outstanding: usize = 0; |
| 887 | var select: Select = .init(io, select_buf); | 887 | var select: Select = .init(io, select_buf); |
lib/std/crypto/keccak_p.zig+7-7| ... | @@ -40,7 +40,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -40,7 +40,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 40 | break :rc rc; | 40 | break :rc rc; |
| 41 | }; | 41 | }; |
| 42 | 42 | ||
| 43 | st: Block = [_]T{0} ** 25, | 43 | st: Block = @splat(0), |
| 44 | 44 | ||
| 45 | /// Initialize the state from a slice of bytes. | 45 | /// Initialize the state from a slice of bytes. |
| 46 | pub fn init(bytes: [block_bytes]u8) Self { | 46 | pub fn init(bytes: [block_bytes]u8) Self { |
| ... | @@ -70,7 +70,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -70,7 +70,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 70 | self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); | 70 | self.st[i / @sizeOf(T)] = mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); |
| 71 | } | 71 | } |
| 72 | if (i < bytes.len) { | 72 | if (i < bytes.len) { |
| 73 | var padded = [_]u8{0} ** @sizeOf(T); | 73 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 74 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); | 74 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); |
| 75 | self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little); | 75 | self.st[i / @sizeOf(T)] = mem.readInt(T, padded[0..], .little); |
| 76 | } | 76 | } |
| ... | @@ -89,7 +89,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -89,7 +89,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 89 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); | 89 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, bytes[i..][0..@sizeOf(T)], .little); |
| 90 | } | 90 | } |
| 91 | if (i < bytes.len) { | 91 | if (i < bytes.len) { |
| 92 | var padded = [_]u8{0} ** @sizeOf(T); | 92 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 93 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); | 93 | @memcpy(padded[0 .. bytes.len - i], bytes[i..]); |
| 94 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little); | 94 | self.st[i / @sizeOf(T)] ^= mem.readInt(T, padded[0..], .little); |
| 95 | } | 95 | } |
| ... | @@ -102,7 +102,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -102,7 +102,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 102 | mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little); | 102 | mem.writeInt(T, out[i..][0..@sizeOf(T)], self.st[i / @sizeOf(T)], .little); |
| 103 | } | 103 | } |
| 104 | if (i < out.len) { | 104 | if (i < out.len) { |
| 105 | var padded = [_]u8{0} ** @sizeOf(T); | 105 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 106 | mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little); | 106 | mem.writeInt(T, padded[0..], self.st[i / @sizeOf(T)], .little); |
| 107 | @memcpy(out[i..], padded[0 .. out.len - i]); | 107 | @memcpy(out[i..], padded[0 .. out.len - i]); |
| 108 | } | 108 | } |
| ... | @@ -118,7 +118,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -118,7 +118,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 118 | mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian); | 118 | mem.writeInt(T, out[i..][0..@sizeOf(T)], x, native_endian); |
| 119 | } | 119 | } |
| 120 | if (i < in.len) { | 120 | if (i < in.len) { |
| 121 | var padded = [_]u8{0} ** @sizeOf(T); | 121 | var padded: [@sizeOf(T)]u8 = @splat(0); |
| 122 | @memcpy(padded[0 .. in.len - i], in[i..]); | 122 | @memcpy(padded[0 .. in.len - i], in[i..]); |
| 123 | const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]); | 123 | const x = mem.readInt(T, &padded, native_endian) ^ mem.nativeToLittle(T, self.st[i / @sizeOf(T)]); |
| 124 | mem.writeInt(T, &padded, x, native_endian); | 124 | mem.writeInt(T, &padded, x, native_endian); |
| ... | @@ -140,7 +140,7 @@ pub fn KeccakF(comptime f: u11) type { | ... | @@ -140,7 +140,7 @@ pub fn KeccakF(comptime f: u11) type { |
| 140 | const st = &self.st; | 140 | const st = &self.st; |
| 141 | 141 | ||
| 142 | // theta | 142 | // theta |
| 143 | var t = [_]T{0} ** 5; | 143 | var t: [5]T = @splat(0); |
| 144 | inline for (0..5) |i| { | 144 | inline for (0..5) |i| { |
| 145 | inline for (0..5) |j| { | 145 | inline for (0..5) |j| { |
| 146 | t[i] ^= st[j * 5 + i]; | 146 | t[i] ^= st[j * 5 + i]; |
| ... | @@ -382,7 +382,7 @@ test "Keccak-f800" { | ... | @@ -382,7 +382,7 @@ test "Keccak-f800" { |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | test "squeeze" { | 384 | test "squeeze" { |
| 385 | var st = State(800, 256, 22).init([_]u8{0x80} ** 100, 0x01); | 385 | var st: State(800, 256, 22) = .init(@splat(0x80), 0x01); |
| 386 | 386 | ||
| 387 | var out0: [15]u8 = undefined; | 387 | var out0: [15]u8 = undefined; |
| 388 | var out1: [out0.len]u8 = undefined; | 388 | var out1: [out0.len]u8 = undefined; |
lib/std/crypto/md5.zig+1-1| ... | @@ -272,7 +272,7 @@ test "streaming" { | ... | @@ -272,7 +272,7 @@ test "streaming" { |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | test "aligned final" { | 274 | test "aligned final" { |
| 275 | var block = [_]u8{0} ** Md5.block_length; | 275 | const block: [Md5.block_length]u8 = @splat(0); |
| 276 | var out: [Md5.digest_length]u8 = undefined; | 276 | var out: [Md5.digest_length]u8 = undefined; |
| 277 | 277 | ||
| 278 | var h = Md5.init(.{}); | 278 | var h = Md5.init(.{}); |
lib/std/crypto/ml_dsa.zig+33-33| ... | @@ -156,7 +156,7 @@ const Params = struct { | ... | @@ -156,7 +156,7 @@ const Params = struct { |
| 156 | const Poly = struct { | 156 | const Poly = struct { |
| 157 | cs: [N]u32, | 157 | cs: [N]u32, |
| 158 | 158 | ||
| 159 | const zero: Poly = .{ .cs = .{0} ** N }; | 159 | const zero: Poly = .{ .cs = @splat(0) }; |
| 160 | 160 | ||
| 161 | // Add two polynomials (no normalization) | 161 | // Add two polynomials (no normalization) |
| 162 | fn add(a: Poly, b: Poly) Poly { | 162 | fn add(a: Poly, b: Poly) Poly { |
| ... | @@ -302,7 +302,7 @@ fn PolyVec(comptime len: u8) type { | ... | @@ -302,7 +302,7 @@ fn PolyVec(comptime len: u8) type { |
| 302 | ps: [len]Poly, | 302 | ps: [len]Poly, |
| 303 | 303 | ||
| 304 | const Self = @This(); | 304 | const Self = @This(); |
| 305 | const zero: Self = .{ .ps = .{Poly.zero} ** len }; | 305 | const zero: Self = .{ .ps = @splat(.zero) }; |
| 306 | 306 | ||
| 307 | /// Apply a unary operation to each polynomial in the vector | 307 | /// Apply a unary operation to each polynomial in the vector |
| 308 | fn map(v: Self, comptime op: fn (Poly) Poly) Self { | 308 | fn map(v: Self, comptime op: fn (Poly) Poly) Self { |
| ... | @@ -581,7 +581,7 @@ fn PolyVec(comptime len: u8) type { | ... | @@ -581,7 +581,7 @@ fn PolyVec(comptime len: u8) type { |
| 581 | 581 | ||
| 582 | /// Unpack hints from bytes | 582 | /// Unpack hints from bytes |
| 583 | fn unpackHint(comptime omega: u16, buf: []const u8) ?Self { | 583 | fn unpackHint(comptime omega: u16, buf: []const u8) ?Self { |
| 584 | var result: Self = .{ .ps = .{Poly.zero} ** len }; | 584 | var result: Self = .{ .ps = @splat(.zero) }; |
| 585 | var prev_sop: u8 = 0; // previous switch-over-point | 585 | var prev_sop: u8 = 0; // previous switch-over-point |
| 586 | 586 | ||
| 587 | for (0..len) |i| { | 587 | for (0..len) |i| { |
| ... | @@ -1839,7 +1839,7 @@ fn MLDSAImpl(comptime p: Params) type { | ... | @@ -1839,7 +1839,7 @@ fn MLDSAImpl(comptime p: Params) type { |
| 1839 | return Signer{ | 1839 | return Signer{ |
| 1840 | .h = h, | 1840 | .h = h, |
| 1841 | .secret_key = secret_key, | 1841 | .secret_key = secret_key, |
| 1842 | .rnd = noise orelse .{0} ** 32, | 1842 | .rnd = noise orelse @splat(0), |
| 1843 | }; | 1843 | }; |
| 1844 | } | 1844 | } |
| 1845 | 1845 | ||
| ... | @@ -2324,7 +2324,7 @@ test "decompose correctness for ML-DSA-87" { | ... | @@ -2324,7 +2324,7 @@ test "decompose correctness for ML-DSA-87" { |
| 2324 | 2324 | ||
| 2325 | test "polyDeriveUniform deterministic" { | 2325 | test "polyDeriveUniform deterministic" { |
| 2326 | // Test that polyDeriveUniform produces deterministic results | 2326 | // Test that polyDeriveUniform produces deterministic results |
| 2327 | const seed: [32]u8 = .{0x01} ++ .{0x00} ** 31; | 2327 | const seed: [32]u8 = .{0x01} ++ @as([31]u8, @splat(0x00)); |
| 2328 | const nonce: u16 = 0; | 2328 | const nonce: u16 = 0; |
| 2329 | 2329 | ||
| 2330 | const p1 = polyDeriveUniform(&seed, nonce); | 2330 | const p1 = polyDeriveUniform(&seed, nonce); |
| ... | @@ -2343,7 +2343,7 @@ test "polyDeriveUniform deterministic" { | ... | @@ -2343,7 +2343,7 @@ test "polyDeriveUniform deterministic" { |
| 2343 | 2343 | ||
| 2344 | test "polyDeriveUniform different nonces" { | 2344 | test "polyDeriveUniform different nonces" { |
| 2345 | // Test that different nonces produce different polynomials | 2345 | // Test that different nonces produce different polynomials |
| 2346 | const seed: [32]u8 = .{0x01} ++ .{0x00} ** 31; | 2346 | const seed: [32]u8 = .{0x01} ++ @as([31]u8, @splat(0x00)); |
| 2347 | 2347 | ||
| 2348 | const p1 = polyDeriveUniform(&seed, 0); | 2348 | const p1 = polyDeriveUniform(&seed, 0); |
| 2349 | const p2 = polyDeriveUniform(&seed, 1); | 2349 | const p2 = polyDeriveUniform(&seed, 1); |
| ... | @@ -2361,7 +2361,7 @@ test "polyDeriveUniform different nonces" { | ... | @@ -2361,7 +2361,7 @@ test "polyDeriveUniform different nonces" { |
| 2361 | 2361 | ||
| 2362 | test "expandS with eta=2" { | 2362 | test "expandS with eta=2" { |
| 2363 | // Test eta=2 sampling | 2363 | // Test eta=2 sampling |
| 2364 | const seed: [64]u8 = .{0x02} ++ .{0x00} ** 63; | 2364 | const seed: [64]u8 = .{0x02} ++ @as([63]u8, @splat(0x00)); |
| 2365 | const nonce: u16 = 0; | 2365 | const nonce: u16 = 0; |
| 2366 | 2366 | ||
| 2367 | const p = expandS(2, &seed, nonce); | 2367 | const p = expandS(2, &seed, nonce); |
| ... | @@ -2378,7 +2378,7 @@ test "expandS with eta=2" { | ... | @@ -2378,7 +2378,7 @@ test "expandS with eta=2" { |
| 2378 | 2378 | ||
| 2379 | test "expandS with eta=4" { | 2379 | test "expandS with eta=4" { |
| 2380 | // Test eta=4 sampling | 2380 | // Test eta=4 sampling |
| 2381 | const seed: [64]u8 = .{0x03} ++ .{0x00} ** 63; | 2381 | const seed: [64]u8 = .{0x03} ++ @as([63]u8, @splat(0x00)); |
| 2382 | const nonce: u16 = 0; | 2382 | const nonce: u16 = 0; |
| 2383 | 2383 | ||
| 2384 | const p = expandS(4, &seed, nonce); | 2384 | const p = expandS(4, &seed, nonce); |
| ... | @@ -2395,7 +2395,7 @@ test "expandS with eta=4" { | ... | @@ -2395,7 +2395,7 @@ test "expandS with eta=4" { |
| 2395 | test "sampleInBall has correct weight" { | 2395 | test "sampleInBall has correct weight" { |
| 2396 | // Test that ball polynomial has exactly tau non-zero coefficients | 2396 | // Test that ball polynomial has exactly tau non-zero coefficients |
| 2397 | const tau = 39; // From ML-DSA-44 | 2397 | const tau = 39; // From ML-DSA-44 |
| 2398 | const seed: [32]u8 = .{0x04} ++ .{0x00} ** 31; | 2398 | const seed: [32]u8 = .{0x03} ++ @as([31]u8, @splat(0x00)); |
| 2399 | 2399 | ||
| 2400 | const p = sampleInBall(tau, &seed); | 2400 | const p = sampleInBall(tau, &seed); |
| 2401 | 2401 | ||
| ... | @@ -2415,7 +2415,7 @@ test "sampleInBall has correct weight" { | ... | @@ -2415,7 +2415,7 @@ test "sampleInBall has correct weight" { |
| 2415 | test "sampleInBall deterministic" { | 2415 | test "sampleInBall deterministic" { |
| 2416 | // Test that ball sampling is deterministic | 2416 | // Test that ball sampling is deterministic |
| 2417 | const tau = 49; // From ML-DSA-65 | 2417 | const tau = 49; // From ML-DSA-65 |
| 2418 | const seed: [32]u8 = .{0x05} ++ .{0x00} ** 31; | 2418 | const seed: [32]u8 = .{0x05} ++ @as([31]u8, @splat(0x00)); |
| 2419 | 2419 | ||
| 2420 | const p1 = sampleInBall(tau, &seed); | 2420 | const p1 = sampleInBall(tau, &seed); |
| 2421 | const p2 = sampleInBall(tau, &seed); | 2421 | const p2 = sampleInBall(tau, &seed); |
| ... | @@ -2851,13 +2851,13 @@ test "Key generation basic - all variants" { | ... | @@ -2851,13 +2851,13 @@ test "Key generation basic - all variants" { |
| 2851 | .{ .variant = MLDSA65, .seed_byte = 0x65 }, | 2851 | .{ .variant = MLDSA65, .seed_byte = 0x65 }, |
| 2852 | .{ .variant = MLDSA87, .seed_byte = 0x87 }, | 2852 | .{ .variant = MLDSA87, .seed_byte = 0x87 }, |
| 2853 | }) |config| { | 2853 | }) |config| { |
| 2854 | const seed = [_]u8{config.seed_byte} ** 32; | 2854 | const seed: [32]u8 = @splat(config.seed_byte); |
| 2855 | try testKeyGenerationBasic(config.variant, seed); | 2855 | try testKeyGenerationBasic(config.variant, seed); |
| 2856 | } | 2856 | } |
| 2857 | } | 2857 | } |
| 2858 | 2858 | ||
| 2859 | test "Key generation determinism" { | 2859 | test "Key generation determinism" { |
| 2860 | const seed = [_]u8{ 0x12, 0x34, 0x56, 0x78 } ++ [_]u8{0xAB} ** 28; | 2860 | const seed = [_]u8{ 0x12, 0x34, 0x56, 0x78 } ++ @as([28]u8, @splat(0xAB)); |
| 2861 | 2861 | ||
| 2862 | // Generate two key pairs from the same seed | 2862 | // Generate two key pairs from the same seed |
| 2863 | const result1 = MLDSA44.newKeyFromSeed(&seed); | 2863 | const result1 = MLDSA44.newKeyFromSeed(&seed); |
| ... | @@ -2874,7 +2874,7 @@ test "Key generation determinism" { | ... | @@ -2874,7 +2874,7 @@ test "Key generation determinism" { |
| 2874 | } | 2874 | } |
| 2875 | 2875 | ||
| 2876 | test "Private key can compute public key" { | 2876 | test "Private key can compute public key" { |
| 2877 | const seed = [_]u8{0xFF} ** 32; | 2877 | const seed: [32]u8 = @splat(0xFF); |
| 2878 | const result = MLDSA44.newKeyFromSeed(&seed); | 2878 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2879 | const pk = result.pk; | 2879 | const pk = result.pk; |
| 2880 | const sk = result.sk; | 2880 | const sk = result.sk; |
| ... | @@ -2907,13 +2907,13 @@ test "Sign and verify - all variants" { | ... | @@ -2907,13 +2907,13 @@ test "Sign and verify - all variants" { |
| 2907 | .{ .variant = MLDSA65, .seed_byte = 0x65, .message = "Hello, ML-DSA-65!" }, | 2907 | .{ .variant = MLDSA65, .seed_byte = 0x65, .message = "Hello, ML-DSA-65!" }, |
| 2908 | .{ .variant = MLDSA87, .seed_byte = 0x87, .message = "Hello, ML-DSA-87!" }, | 2908 | .{ .variant = MLDSA87, .seed_byte = 0x87, .message = "Hello, ML-DSA-87!" }, |
| 2909 | }) |config| { | 2909 | }) |config| { |
| 2910 | const seed = [_]u8{config.seed_byte} ** 32; | 2910 | const seed: [32]u8 = @splat(config.seed_byte); |
| 2911 | try testSignAndVerify(config.variant, seed, config.message); | 2911 | try testSignAndVerify(config.variant, seed, config.message); |
| 2912 | } | 2912 | } |
| 2913 | } | 2913 | } |
| 2914 | 2914 | ||
| 2915 | test "Invalid signature rejection" { | 2915 | test "Invalid signature rejection" { |
| 2916 | const seed = [_]u8{0x99} ** 32; | 2916 | const seed: [32]u8 = @splat(0x99); |
| 2917 | const result = MLDSA44.newKeyFromSeed(&seed); | 2917 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2918 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 2918 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 2919 | 2919 | ||
| ... | @@ -2934,7 +2934,7 @@ test "Invalid signature rejection" { | ... | @@ -2934,7 +2934,7 @@ test "Invalid signature rejection" { |
| 2934 | } | 2934 | } |
| 2935 | 2935 | ||
| 2936 | test "Context string support" { | 2936 | test "Context string support" { |
| 2937 | const seed = [_]u8{0xAA} ** 32; | 2937 | const seed: [32]u8 = @splat(0xAA); |
| 2938 | const result = MLDSA44.newKeyFromSeed(&seed); | 2938 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2939 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 2939 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 2940 | 2940 | ||
| ... | @@ -2964,17 +2964,17 @@ test "Context string support" { | ... | @@ -2964,17 +2964,17 @@ test "Context string support" { |
| 2964 | try testing.expectError(error.SignatureVerificationFailed, sig2.verifyWithContext(message, kp.public_key, context1)); | 2964 | try testing.expectError(error.SignatureVerificationFailed, sig2.verifyWithContext(message, kp.public_key, context1)); |
| 2965 | 2965 | ||
| 2966 | // Test maximum context length (255 bytes) | 2966 | // Test maximum context length (255 bytes) |
| 2967 | const max_context = [_]u8{0xBB} ** 255; | 2967 | const max_context: [255]u8 = @splat(0xBB); |
| 2968 | const sig3 = try kp.signWithContext(message, null, &max_context); | 2968 | const sig3 = try kp.signWithContext(message, null, &max_context); |
| 2969 | try sig3.verifyWithContext(message, kp.public_key, &max_context); | 2969 | try sig3.verifyWithContext(message, kp.public_key, &max_context); |
| 2970 | 2970 | ||
| 2971 | // Test context too long (256 bytes should fail) | 2971 | // Test context too long (256 bytes should fail) |
| 2972 | const too_long_context = [_]u8{0xCC} ** 256; | 2972 | const too_long_context: [256]u8 = @splat(0xCC); |
| 2973 | try testing.expectError(error.ContextTooLong, kp.signWithContext(message, null, &too_long_context)); | 2973 | try testing.expectError(error.ContextTooLong, kp.signWithContext(message, null, &too_long_context)); |
| 2974 | } | 2974 | } |
| 2975 | 2975 | ||
| 2976 | test "Context string with streaming API" { | 2976 | test "Context string with streaming API" { |
| 2977 | const seed = [_]u8{0xDD} ** 32; | 2977 | const seed: [32]u8 = @splat(0xDD); |
| 2978 | const result = MLDSA44.newKeyFromSeed(&seed); | 2978 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 2979 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 2979 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 2980 | 2980 | ||
| ... | @@ -3002,12 +3002,12 @@ test "Context string with streaming API" { | ... | @@ -3002,12 +3002,12 @@ test "Context string with streaming API" { |
| 3002 | } | 3002 | } |
| 3003 | 3003 | ||
| 3004 | test "Signature determinism (same rnd)" { | 3004 | test "Signature determinism (same rnd)" { |
| 3005 | const seed = [_]u8{0x11} ** 32; | 3005 | const seed: [32]u8 = @splat(0x11); |
| 3006 | const result = MLDSA44.newKeyFromSeed(&seed); | 3006 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3007 | const sk = result.sk; | 3007 | const sk = result.sk; |
| 3008 | 3008 | ||
| 3009 | const message = "Deterministic test"; | 3009 | const message = "Deterministic test"; |
| 3010 | const rnd = [_]u8{0x22} ** 32; | 3010 | const rnd: [32]u8 = @splat(0x22); |
| 3011 | 3011 | ||
| 3012 | // Sign twice with same randomness using streaming API | 3012 | // Sign twice with same randomness using streaming API |
| 3013 | var st1 = try sk.signer(rnd); | 3013 | var st1 = try sk.signer(rnd); |
| ... | @@ -3023,7 +3023,7 @@ test "Signature determinism (same rnd)" { | ... | @@ -3023,7 +3023,7 @@ test "Signature determinism (same rnd)" { |
| 3023 | } | 3023 | } |
| 3024 | 3024 | ||
| 3025 | test "Signature toBytes/fromBytes roundtrip" { | 3025 | test "Signature toBytes/fromBytes roundtrip" { |
| 3026 | const seed = [_]u8{0x33} ** 32; | 3026 | const seed: [32]u8 = @splat(0x33); |
| 3027 | const result = MLDSA44.newKeyFromSeed(&seed); | 3027 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3028 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 3028 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 3029 | 3029 | ||
| ... | @@ -3043,7 +3043,7 @@ test "Signature toBytes/fromBytes roundtrip" { | ... | @@ -3043,7 +3043,7 @@ test "Signature toBytes/fromBytes roundtrip" { |
| 3043 | } | 3043 | } |
| 3044 | 3044 | ||
| 3045 | test "Empty message signing" { | 3045 | test "Empty message signing" { |
| 3046 | const seed = [_]u8{0x44} ** 32; | 3046 | const seed: [32]u8 = @splat(0x44); |
| 3047 | const result = MLDSA44.newKeyFromSeed(&seed); | 3047 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3048 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 3048 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 3049 | 3049 | ||
| ... | @@ -3057,12 +3057,12 @@ test "Empty message signing" { | ... | @@ -3057,12 +3057,12 @@ test "Empty message signing" { |
| 3057 | } | 3057 | } |
| 3058 | 3058 | ||
| 3059 | test "Long message signing" { | 3059 | test "Long message signing" { |
| 3060 | const seed = [_]u8{0x55} ** 32; | 3060 | const seed: [32]u8 = @splat(0x55); |
| 3061 | const result = MLDSA44.newKeyFromSeed(&seed); | 3061 | const result = MLDSA44.newKeyFromSeed(&seed); |
| 3062 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); | 3062 | const kp = try MLDSA44.KeyPair.fromSecretKey(result.sk); |
| 3063 | 3063 | ||
| 3064 | // Create a long message (1KB) | 3064 | // Create a long message (1KB) |
| 3065 | const long_message = [_]u8{0xAB} ** 1024; | 3065 | const long_message: [1024]u8 = @splat(0xAB); |
| 3066 | 3066 | ||
| 3067 | // Sign long message | 3067 | // Sign long message |
| 3068 | const sig = try kp.sign(&long_message, null); | 3068 | const sig = try kp.sign(&long_message, null); |
| ... | @@ -3209,7 +3209,7 @@ test "KeyPair API - generate and sign" { | ... | @@ -3209,7 +3209,7 @@ test "KeyPair API - generate and sign" { |
| 3209 | 3209 | ||
| 3210 | test "KeyPair API - generateDeterministic" { | 3210 | test "KeyPair API - generateDeterministic" { |
| 3211 | // Test deterministic key generation | 3211 | // Test deterministic key generation |
| 3212 | const seed = [_]u8{42} ** 32; | 3212 | const seed: [32]u8 = @splat(42); |
| 3213 | const kp1 = try MLDSA44.KeyPair.generateDeterministic(seed); | 3213 | const kp1 = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3214 | const kp2 = try MLDSA44.KeyPair.generateDeterministic(seed); | 3214 | const kp2 = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3215 | 3215 | ||
| ... | @@ -3240,7 +3240,7 @@ test "Signature verification with noise" { | ... | @@ -3240,7 +3240,7 @@ test "Signature verification with noise" { |
| 3240 | const msg = "Message to be signed with randomness"; | 3240 | const msg = "Message to be signed with randomness"; |
| 3241 | 3241 | ||
| 3242 | // Create some noise | 3242 | // Create some noise |
| 3243 | const noise = [_]u8{ 1, 2, 3, 4, 5 } ++ [_]u8{0} ** 27; | 3243 | const noise = [_]u8{ 1, 2, 3, 4, 5 } ++ @as([27]u8, @splat(0)); |
| 3244 | 3244 | ||
| 3245 | // Sign with noise | 3245 | // Sign with noise |
| 3246 | const sig = try kp.sign(msg, noise); | 3246 | const sig = try kp.sign(msg, noise); |
| ... | @@ -3262,7 +3262,7 @@ test "Signature verification failure" { | ... | @@ -3262,7 +3262,7 @@ test "Signature verification failure" { |
| 3262 | } | 3262 | } |
| 3263 | 3263 | ||
| 3264 | test "Streaming API - sign and verify" { | 3264 | test "Streaming API - sign and verify" { |
| 3265 | const seed = [_]u8{0x55} ** 32; | 3265 | const seed: [32]u8 = @splat(0x55); |
| 3266 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3266 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3267 | 3267 | ||
| 3268 | const msg = "Test message for streaming API"; | 3268 | const msg = "Test message for streaming API"; |
| ... | @@ -3279,7 +3279,7 @@ test "Streaming API - sign and verify" { | ... | @@ -3279,7 +3279,7 @@ test "Streaming API - sign and verify" { |
| 3279 | } | 3279 | } |
| 3280 | 3280 | ||
| 3281 | test "Streaming API - chunked message" { | 3281 | test "Streaming API - chunked message" { |
| 3282 | const seed = [_]u8{0x66} ** 32; | 3282 | const seed: [32]u8 = @splat(0x66); |
| 3283 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3283 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3284 | 3284 | ||
| 3285 | // Create a message in chunks | 3285 | // Create a message in chunks |
| ... | @@ -3313,7 +3313,7 @@ test "Streaming API - chunked message" { | ... | @@ -3313,7 +3313,7 @@ test "Streaming API - chunked message" { |
| 3313 | } | 3313 | } |
| 3314 | 3314 | ||
| 3315 | test "Streaming API - large message" { | 3315 | test "Streaming API - large message" { |
| 3316 | const seed = [_]u8{0x77} ** 32; | 3316 | const seed: [32]u8 = @splat(0x77); |
| 3317 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3317 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3318 | 3318 | ||
| 3319 | // Create a large message (1MB) | 3319 | // Create a large message (1MB) |
| ... | @@ -3344,7 +3344,7 @@ test "Streaming API - all parameter sets" { | ... | @@ -3344,7 +3344,7 @@ test "Streaming API - all parameter sets" { |
| 3344 | 3344 | ||
| 3345 | // ML-DSA-44 | 3345 | // ML-DSA-44 |
| 3346 | { | 3346 | { |
| 3347 | const seed = [_]u8{0x44} ** 32; | 3347 | const seed: [32]u8 = @splat(0x44); |
| 3348 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); | 3348 | const kp = try MLDSA44.KeyPair.generateDeterministic(seed); |
| 3349 | var signer = try kp.signer(null); | 3349 | var signer = try kp.signer(null); |
| 3350 | signer.update(test_msg); | 3350 | signer.update(test_msg); |
| ... | @@ -3356,7 +3356,7 @@ test "Streaming API - all parameter sets" { | ... | @@ -3356,7 +3356,7 @@ test "Streaming API - all parameter sets" { |
| 3356 | 3356 | ||
| 3357 | // ML-DSA-65 | 3357 | // ML-DSA-65 |
| 3358 | { | 3358 | { |
| 3359 | const seed = [_]u8{0x65} ** 32; | 3359 | const seed: [32]u8 = @splat(0x65); |
| 3360 | const kp = try MLDSA65.KeyPair.generateDeterministic(seed); | 3360 | const kp = try MLDSA65.KeyPair.generateDeterministic(seed); |
| 3361 | var signer = try kp.signer(null); | 3361 | var signer = try kp.signer(null); |
| 3362 | signer.update(test_msg); | 3362 | signer.update(test_msg); |
| ... | @@ -3368,7 +3368,7 @@ test "Streaming API - all parameter sets" { | ... | @@ -3368,7 +3368,7 @@ test "Streaming API - all parameter sets" { |
| 3368 | 3368 | ||
| 3369 | // ML-DSA-87 | 3369 | // ML-DSA-87 |
| 3370 | { | 3370 | { |
| 3371 | const seed = [_]u8{0x87} ** 32; | 3371 | const seed: [32]u8 = @splat(0x87); |
| 3372 | const kp = try MLDSA87.KeyPair.generateDeterministic(seed); | 3372 | const kp = try MLDSA87.KeyPair.generateDeterministic(seed); |
| 3373 | var signer = try kp.signer(null); | 3373 | var signer = try kp.signer(null); |
| 3374 | signer.update(test_msg); | 3374 | signer.update(test_msg); |
lib/std/crypto/ml_kem.zig+4-4| ... | @@ -615,7 +615,7 @@ const inv_ntt_reductions = [_]i16{ | ... | @@ -615,7 +615,7 @@ const inv_ntt_reductions = [_]i16{ |
| 615 | test "invNTTReductions bounds" { | 615 | test "invNTTReductions bounds" { |
| 616 | // Checks whether the reductions proposed by invNTTReductions | 616 | // Checks whether the reductions proposed by invNTTReductions |
| 617 | // don't overflow during invNTT(). | 617 | // don't overflow during invNTT(). |
| 618 | var xs = [_]i32{1} ** 256; // start at |x| ≤ q | 618 | var xs: [256]i32 = @splat(1); // start at |x| ≤ q |
| 619 | 619 | ||
| 620 | var r: usize = 0; | 620 | var r: usize = 0; |
| 621 | var layer: math.Log2Int(usize) = 1; | 621 | var layer: math.Log2Int(usize) = 1; |
| ... | @@ -797,7 +797,7 @@ const Poly = struct { | ... | @@ -797,7 +797,7 @@ const Poly = struct { |
| 797 | cs: [N]i16, | 797 | cs: [N]i16, |
| 798 | 798 | ||
| 799 | const encoded_length = N / 2 * 3; | 799 | const encoded_length = N / 2 * 3; |
| 800 | const zero: Poly = .{ .cs = .{0} ** N }; | 800 | const zero: Poly = .{ .cs = @splat(0) }; |
| 801 | 801 | ||
| 802 | // Add two polynomials (coefficients not normalized) | 802 | // Add two polynomials (coefficients not normalized) |
| 803 | fn add(a: Poly, b: Poly) Poly { | 803 | fn add(a: Poly, b: Poly) Poly { |
| ... | @@ -1011,7 +1011,7 @@ const Poly = struct { | ... | @@ -1011,7 +1011,7 @@ const Poly = struct { |
| 1011 | 1011 | ||
| 1012 | const out_length: usize = comptime @divTrunc(N * d, 8); | 1012 | const out_length: usize = comptime @divTrunc(N * d, 8); |
| 1013 | comptime assert(out_length * 8 == d * N); | 1013 | comptime assert(out_length * 8 == d * N); |
| 1014 | var out = [_]u8{0} ** out_length; | 1014 | var out: [out_length]u8 = @splat(0); |
| 1015 | 1015 | ||
| 1016 | while (in_off < N) { | 1016 | while (in_off < N) { |
| 1017 | // First we compress into in. | 1017 | // First we compress into in. |
| ... | @@ -1754,7 +1754,7 @@ const NistDRBG = struct { | ... | @@ -1754,7 +1754,7 @@ const NistDRBG = struct { |
| 1754 | } | 1754 | } |
| 1755 | 1755 | ||
| 1756 | fn init(seed: [48]u8) NistDRBG { | 1756 | fn init(seed: [48]u8) NistDRBG { |
| 1757 | var ret: NistDRBG = .{ .key = .{0} ** 32, .v = .{0} ** 16 }; | 1757 | var ret: NistDRBG = .{ .key = @splat(0), .v = @splat(0) }; |
| 1758 | ret.update(seed); | 1758 | ret.update(seed); |
| 1759 | return ret; | 1759 | return ret; |
| 1760 | } | 1760 | } |
lib/std/crypto/modes.zig+1-1| ... | @@ -183,7 +183,7 @@ test "ctr mode" { | ... | @@ -183,7 +183,7 @@ test "ctr mode" { |
| 183 | // Test 9: Large input (> 2*block_length, 100 bytes) | 183 | // Test 9: Large input (> 2*block_length, 100 bytes) |
| 184 | { | 184 | { |
| 185 | // Create a 100-byte input by extending with zeros | 185 | // Create a 100-byte input by extending with zeros |
| 186 | var in: [100]u8 = [_]u8{0} ** 100; | 186 | var in: [100]u8 = @splat(0); |
| 187 | @memcpy(in[0..64], &[_]u8{ | 187 | @memcpy(in[0..64], &[_]u8{ |
| 188 | 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, | 188 | 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, |
| 189 | 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, | 189 | 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, |
lib/std/crypto/pbkdf2.zig+1-1| ... | @@ -206,7 +206,7 @@ test "RFC 6070 16,777,216 iterations" { | ... | @@ -206,7 +206,7 @@ test "RFC 6070 16,777,216 iterations" { |
| 206 | const c = 16777216; | 206 | const c = 16777216; |
| 207 | const dk_len = 20; | 207 | const dk_len = 20; |
| 208 | 208 | ||
| 209 | var dk = [_]u8{0} ** dk_len; | 209 | var dk: [dk_len]u8 = @splat(0); |
| 210 | 210 | ||
| 211 | try pbkdf2(&dk, p, s, c, HmacSha1); | 211 | try pbkdf2(&dk, p, s, c, HmacSha1); |
| 212 | 212 |
lib/std/crypto/pcurves/p256/scalar.zig+3-3| ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { | ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { |
| 196 | } | 196 | } |
| 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| 198 | { | 198 | { |
| 199 | var b = [_]u8{0} ** encoded_length; | 199 | var b: [encoded_length]u8 = @splat(0); |
| 200 | const len = @min(s.len, 24); | 200 | const len = @min(s.len, 24); |
| 201 | b[0..len].* = s[0..len].*; | 201 | b[0..len].* = s[0..len].*; |
| 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; | 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 203 | } | 203 | } |
| 204 | if (s_.len >= 24) { | 204 | if (s_.len >= 24) { |
| 205 | var b = [_]u8{0} ** encoded_length; | 205 | var b: [encoded_length]u8 = @splat(0); |
| 206 | const len = @min(s.len - 24, 24); | 206 | const len = @min(s.len - 24, 24); |
| 207 | b[0..len].* = s[24..][0..len].*; | 207 | b[0..len].* = s[24..][0..len].*; |
| 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; | 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 209 | } | 209 | } |
| 210 | if (s_.len >= 48) { | 210 | if (s_.len >= 48) { |
| 211 | var b = [_]u8{0} ** encoded_length; | 211 | var b: [encoded_length]u8 = @splat(0); |
| 212 | const len = s.len - 48; | 212 | const len = s.len - 48; |
| 213 | b[0..len].* = s[48..][0..len].*; | 213 | b[0..len].* = s[48..][0..len].*; |
| 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; | 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; |
lib/std/crypto/pcurves/p384/scalar.zig+2-2| ... | @@ -184,13 +184,13 @@ const ScalarDouble = struct { | ... | @@ -184,13 +184,13 @@ const ScalarDouble = struct { |
| 184 | } | 184 | } |
| 185 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; | 185 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero }; |
| 186 | { | 186 | { |
| 187 | var b = [_]u8{0} ** encoded_length; | 187 | var b: [encoded_length]u8 = @splat(0); |
| 188 | const len = @min(s.len, 32); | 188 | const len = @min(s.len, 32); |
| 189 | b[0..len].* = s[0..len].*; | 189 | b[0..len].* = s[0..len].*; |
| 190 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; | 190 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 191 | } | 191 | } |
| 192 | if (s_.len >= 32) { | 192 | if (s_.len >= 32) { |
| 193 | var b = [_]u8{0} ** encoded_length; | 193 | var b: [encoded_length]u8 = @splat(0); |
| 194 | const len = @min(s.len - 32, 32); | 194 | const len = @min(s.len - 32, 32); |
| 195 | b[0..len].* = s[32..][0..len].*; | 195 | b[0..len].* = s[32..][0..len].*; |
| 196 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; | 196 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
lib/std/crypto/pcurves/secp256k1/scalar.zig+3-3| ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { | ... | @@ -196,19 +196,19 @@ const ScalarDouble = struct { |
| 196 | } | 196 | } |
| 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; | 197 | var t = ScalarDouble{ .x1 = undefined, .x2 = Fe.zero, .x3 = Fe.zero }; |
| 198 | { | 198 | { |
| 199 | var b = [_]u8{0} ** encoded_length; | 199 | var b: [encoded_length]u8 = @splat(0); |
| 200 | const len = @min(s.len, 24); | 200 | const len = @min(s.len, 24); |
| 201 | b[0..len].* = s[0..len].*; | 201 | b[0..len].* = s[0..len].*; |
| 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; | 202 | t.x1 = Fe.fromBytes(b, .little) catch unreachable; |
| 203 | } | 203 | } |
| 204 | if (s_.len >= 24) { | 204 | if (s_.len >= 24) { |
| 205 | var b = [_]u8{0} ** encoded_length; | 205 | var b: [encoded_length]u8 = @splat(0); |
| 206 | const len = @min(s.len - 24, 24); | 206 | const len = @min(s.len - 24, 24); |
| 207 | b[0..len].* = s[24..][0..len].*; | 207 | b[0..len].* = s[24..][0..len].*; |
| 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; | 208 | t.x2 = Fe.fromBytes(b, .little) catch unreachable; |
| 209 | } | 209 | } |
| 210 | if (s_.len >= 48) { | 210 | if (s_.len >= 48) { |
| 211 | var b = [_]u8{0} ** encoded_length; | 211 | var b: [encoded_length]u8 = @splat(0); |
| 212 | const len = s.len - 48; | 212 | const len = s.len - 48; |
| 213 | b[0..len].* = s[48..][0..len].*; | 213 | b[0..len].* = s[48..][0..len].*; |
| 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; | 214 | t.x3 = Fe.fromBytes(b, .little) catch unreachable; |
lib/std/crypto/pcurves/tests/p256.zig+5-5| ... | @@ -97,7 +97,7 @@ test "p256 public key is the neutral element (public verification)" { | ... | @@ -97,7 +97,7 @@ test "p256 public key is the neutral element (public verification)" { |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | test "p256 field element non-canonical encoding" { | 99 | test "p256 field element non-canonical encoding" { |
| 100 | const s = [_]u8{0xff} ** 32; | 100 | const s: [32]u8 = @splat(0xff); |
| 101 | try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little)); | 101 | try testing.expectError(error.NonCanonical, P256.Fe.fromBytes(s, .little)); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| ... | @@ -110,8 +110,8 @@ test "p256 neutral element decoding" { | ... | @@ -110,8 +110,8 @@ test "p256 neutral element decoding" { |
| 110 | test "p256 double base multiplication" { | 110 | test "p256 double base multiplication" { |
| 111 | const p1 = P256.basePoint; | 111 | const p1 = P256.basePoint; |
| 112 | const p2 = P256.basePoint.dbl(); | 112 | const p2 = P256.basePoint.dbl(); |
| 113 | const s1 = [_]u8{0x01} ** 32; | 113 | const s1: [32]u8 = @splat(0x01); |
| 114 | const s2 = [_]u8{0x02} ** 32; | 114 | const s2: [32]u8 = @splat(0x02); |
| 115 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 115 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 116 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 116 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 117 | try testing.expect(pr1.equivalent(pr2)); | 117 | try testing.expect(pr1.equivalent(pr2)); |
| ... | @@ -120,8 +120,8 @@ test "p256 double base multiplication" { | ... | @@ -120,8 +120,8 @@ test "p256 double base multiplication" { |
| 120 | test "p256 double base multiplication with large scalars" { | 120 | test "p256 double base multiplication with large scalars" { |
| 121 | const p1 = P256.basePoint; | 121 | const p1 = P256.basePoint; |
| 122 | const p2 = P256.basePoint.dbl(); | 122 | const p2 = P256.basePoint.dbl(); |
| 123 | const s1 = [_]u8{0xee} ** 32; | 123 | const s1: [32]u8 = @splat(0xee); |
| 124 | const s2 = [_]u8{0xdd} ** 32; | 124 | const s2: [32]u8 = @splat(0xdd); |
| 125 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 125 | const pr1 = try P256.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 126 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 126 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 127 | try testing.expect(pr1.equivalent(pr2)); | 127 | try testing.expect(pr1.equivalent(pr2)); |
lib/std/crypto/pcurves/tests/p384.zig+5-5| ... | @@ -100,7 +100,7 @@ test "p384 public key is the neutral element (public verification)" { | ... | @@ -100,7 +100,7 @@ test "p384 public key is the neutral element (public verification)" { |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | test "p384 field element non-canonical encoding" { | 102 | test "p384 field element non-canonical encoding" { |
| 103 | const s = [_]u8{0xff} ** 48; | 103 | const s: [48]u8 = @splat(0xff); |
| 104 | try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little)); | 104 | try testing.expectError(error.NonCanonical, P384.Fe.fromBytes(s, .little)); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| ... | @@ -113,8 +113,8 @@ test "p384 neutral element decoding" { | ... | @@ -113,8 +113,8 @@ test "p384 neutral element decoding" { |
| 113 | test "p384 double base multiplication" { | 113 | test "p384 double base multiplication" { |
| 114 | const p1 = P384.basePoint; | 114 | const p1 = P384.basePoint; |
| 115 | const p2 = P384.basePoint.dbl(); | 115 | const p2 = P384.basePoint.dbl(); |
| 116 | const s1 = [_]u8{0x01} ** 48; | 116 | const s1: [48]u8 = @splat(0x01); |
| 117 | const s2 = [_]u8{0x02} ** 48; | 117 | const s2: [48]u8 = @splat(0x02); |
| 118 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 118 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 119 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 119 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 120 | try testing.expect(pr1.equivalent(pr2)); | 120 | try testing.expect(pr1.equivalent(pr2)); |
| ... | @@ -123,8 +123,8 @@ test "p384 double base multiplication" { | ... | @@ -123,8 +123,8 @@ test "p384 double base multiplication" { |
| 123 | test "p384 double base multiplication with large scalars" { | 123 | test "p384 double base multiplication with large scalars" { |
| 124 | const p1 = P384.basePoint; | 124 | const p1 = P384.basePoint; |
| 125 | const p2 = P384.basePoint.dbl(); | 125 | const p2 = P384.basePoint.dbl(); |
| 126 | const s1 = [_]u8{0xee} ** 48; | 126 | const s1: [48]u8 = @splat(0xee); |
| 127 | const s2 = [_]u8{0xdd} ** 48; | 127 | const s2: [48]u8 = @splat(0xdd); |
| 128 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 128 | const pr1 = try P384.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 129 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 129 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 130 | try testing.expect(pr1.equivalent(pr2)); | 130 | try testing.expect(pr1.equivalent(pr2)); |
lib/std/crypto/pcurves/tests/secp256k1.zig+3-3| ... | @@ -109,7 +109,7 @@ test "secp256k1 public key is the neutral element (public verification)" { | ... | @@ -109,7 +109,7 @@ test "secp256k1 public key is the neutral element (public verification)" { |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | test "secp256k1 field element non-canonical encoding" { | 111 | test "secp256k1 field element non-canonical encoding" { |
| 112 | const s = [_]u8{0xff} ** 32; | 112 | const s: [32]u8 = @splat(0xff); |
| 113 | try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little)); | 113 | try testing.expectError(error.NonCanonical, Secp256k1.Fe.fromBytes(s, .little)); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| ... | @@ -122,8 +122,8 @@ test "secp256k1 neutral element decoding" { | ... | @@ -122,8 +122,8 @@ test "secp256k1 neutral element decoding" { |
| 122 | test "secp256k1 double base multiplication" { | 122 | test "secp256k1 double base multiplication" { |
| 123 | const p1 = Secp256k1.basePoint; | 123 | const p1 = Secp256k1.basePoint; |
| 124 | const p2 = Secp256k1.basePoint.dbl(); | 124 | const p2 = Secp256k1.basePoint.dbl(); |
| 125 | const s1 = [_]u8{0x01} ** 32; | 125 | const s1: [32]u8 = @splat(0x01); |
| 126 | const s2 = [_]u8{0x02} ** 32; | 126 | const s2: [32]u8 = @splat(0x02); |
| 127 | const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little); | 127 | const pr1 = try Secp256k1.mulDoubleBasePublic(p1, s1, p2, s2, .little); |
| 128 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); | 128 | const pr2 = (try p1.mul(s1, .little)).add(try p2.mul(s2, .little)); |
| 129 | try testing.expect(pr1.equivalent(pr2)); | 129 | try testing.expect(pr1.equivalent(pr2)); |
lib/std/crypto/salsa20.zig+8-8| ... | @@ -384,7 +384,7 @@ pub const XSalsa20Poly1305 = struct { | ... | @@ -384,7 +384,7 @@ pub const XSalsa20Poly1305 = struct { |
| 384 | pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void { | 384 | pub fn encrypt(c: []u8, tag: *[tag_length]u8, m: []const u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) void { |
| 385 | debug.assert(c.len == m.len); | 385 | debug.assert(c.len == m.len); |
| 386 | const extended = extend(rounds, k, npub); | 386 | const extended = extend(rounds, k, npub); |
| 387 | var block0 = [_]u8{0} ** 64; | 387 | var block0: [64]u8 = @splat(0); |
| 388 | const mlen0 = @min(32, m.len); | 388 | const mlen0 = @min(32, m.len); |
| 389 | @memcpy(block0[32..][0..mlen0], m[0..mlen0]); | 389 | @memcpy(block0[32..][0..mlen0], m[0..mlen0]); |
| 390 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); | 390 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); |
| ... | @@ -408,7 +408,7 @@ pub const XSalsa20Poly1305 = struct { | ... | @@ -408,7 +408,7 @@ pub const XSalsa20Poly1305 = struct { |
| 408 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { | 408 | pub fn decrypt(m: []u8, c: []const u8, tag: [tag_length]u8, ad: []const u8, npub: [nonce_length]u8, k: [key_length]u8) AuthenticationError!void { |
| 409 | debug.assert(c.len == m.len); | 409 | debug.assert(c.len == m.len); |
| 410 | const extended = extend(rounds, k, npub); | 410 | const extended = extend(rounds, k, npub); |
| 411 | var block0 = [_]u8{0} ** 64; | 411 | var block0: [64]u8 = @splat(0); |
| 412 | const mlen0 = @min(32, c.len); | 412 | const mlen0 = @min(32, c.len); |
| 413 | @memcpy(block0[32..][0..mlen0], c[0..mlen0]); | 413 | @memcpy(block0[32..][0..mlen0], c[0..mlen0]); |
| 414 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); | 414 | Salsa20.xor(block0[0..], block0[0..], 0, extended.key, extended.nonce); |
| ... | @@ -489,7 +489,7 @@ pub const Box = struct { | ... | @@ -489,7 +489,7 @@ pub const Box = struct { |
| 489 | /// Compute a secret suitable for `secretbox` given a recipient's public key and a sender's secret key. | 489 | /// Compute a secret suitable for `secretbox` given a recipient's public key and a sender's secret key. |
| 490 | pub fn createSharedSecret(public_key: [public_length]u8, secret_key: [secret_length]u8) (IdentityElementError || WeakPublicKeyError)![shared_length]u8 { | 490 | pub fn createSharedSecret(public_key: [public_length]u8, secret_key: [secret_length]u8) (IdentityElementError || WeakPublicKeyError)![shared_length]u8 { |
| 491 | const p = try X25519.scalarmult(secret_key, public_key); | 491 | const p = try X25519.scalarmult(secret_key, public_key); |
| 492 | const zero = [_]u8{0} ** 16; | 492 | const zero: [16]u8 = @splat(0); |
| 493 | return SalsaImpl(20).hsalsa(zero, p); | 493 | return SalsaImpl(20).hsalsa(zero, p); |
| 494 | } | 494 | } |
| 495 | 495 | ||
| ... | @@ -559,15 +559,15 @@ const htest = @import("test.zig"); | ... | @@ -559,15 +559,15 @@ const htest = @import("test.zig"); |
| 559 | test "(x)salsa20" { | 559 | test "(x)salsa20" { |
| 560 | if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299 | 560 | if (builtin.cpu.has(.riscv, .v) and builtin.zig_backend == .stage2_llvm) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/24299 |
| 561 | 561 | ||
| 562 | const key = [_]u8{0x69} ** 32; | 562 | const key: [32]u8 = @splat(0x69); |
| 563 | const nonce = [_]u8{0x42} ** 8; | 563 | const nonce: [8]u8 = @splat(0x42); |
| 564 | const msg = [_]u8{0} ** 20; | 564 | const msg: [20]u8 = @splat(0); |
| 565 | var c: [msg.len]u8 = undefined; | 565 | var c: [msg.len]u8 = undefined; |
| 566 | 566 | ||
| 567 | Salsa20.xor(&c, msg[0..], 0, key, nonce); | 567 | Salsa20.xor(&c, msg[0..], 0, key, nonce); |
| 568 | try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]); | 568 | try htest.assertEqual("30ff9933aa6534ff5207142593cd1fca4b23bdd8", c[0..]); |
| 569 | 569 | ||
| 570 | const extended_nonce = [_]u8{0x42} ** 24; | 570 | const extended_nonce: [24]u8 = @splat(0x42); |
| 571 | XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce); | 571 | XSalsa20.xor(&c, msg[0..], 0, key, extended_nonce); |
| 572 | try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]); | 572 | try htest.assertEqual("b4ab7d82e750ec07644fa3281bce6cd91d4243f9", c[0..]); |
| 573 | } | 573 | } |
| ... | @@ -637,7 +637,7 @@ test "xsalsa20poly1305 sealedbox" { | ... | @@ -637,7 +637,7 @@ test "xsalsa20poly1305 sealedbox" { |
| 637 | test "secretbox twoblocks" { | 637 | test "secretbox twoblocks" { |
| 638 | const key = [_]u8{ 0xc9, 0xc9, 0x4d, 0xcf, 0x68, 0xbe, 0x00, 0xe4, 0x7f, 0xe6, 0x13, 0x26, 0xfc, 0xc4, 0x2f, 0xd0, 0xdb, 0x93, 0x91, 0x1c, 0x09, 0x94, 0x89, 0xe1, 0x1b, 0x88, 0x63, 0x18, 0x86, 0x64, 0x8b, 0x7b }; | 638 | const key = [_]u8{ 0xc9, 0xc9, 0x4d, 0xcf, 0x68, 0xbe, 0x00, 0xe4, 0x7f, 0xe6, 0x13, 0x26, 0xfc, 0xc4, 0x2f, 0xd0, 0xdb, 0x93, 0x91, 0x1c, 0x09, 0x94, 0x89, 0xe1, 0x1b, 0x88, 0x63, 0x18, 0x86, 0x64, 0x8b, 0x7b }; |
| 639 | const nonce = [_]u8{ 0xa4, 0x33, 0xe9, 0x0a, 0x07, 0x68, 0x6e, 0x9a, 0x2b, 0x6d, 0xd4, 0x59, 0x04, 0x72, 0x3e, 0xd3, 0x8a, 0x67, 0x55, 0xc7, 0x9e, 0x3e, 0x77, 0xdc }; | 639 | const nonce = [_]u8{ 0xa4, 0x33, 0xe9, 0x0a, 0x07, 0x68, 0x6e, 0x9a, 0x2b, 0x6d, 0xd4, 0x59, 0x04, 0x72, 0x3e, 0xd3, 0x8a, 0x67, 0x55, 0xc7, 0x9e, 0x3e, 0x77, 0xdc }; |
| 640 | const msg = [_]u8{'a'} ** 97; | 640 | const msg: [97]u8 = @splat('a'); |
| 641 | var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined; | 641 | var ciphertext: [msg.len + SecretBox.tag_length]u8 = undefined; |
| 642 | SecretBox.seal(&ciphertext, &msg, nonce, key); | 642 | SecretBox.seal(&ciphertext, &msg, nonce, key); |
| 643 | try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext); | 643 | try htest.assertEqual("b05760e217288ba079caa2fd57fd3701784974ffcfda20fe523b89211ad8af065a6eb37cdb29d51aca5bd75dafdd21d18b044c54bb7c526cf576c94ee8900f911ceab0147e82b667a28c52d58ceb29554ff45471224d37b03256b01c119b89ff6d36855de8138d103386dbc9d971f52261", &ciphertext); |
lib/std/crypto/sha2.zig+2-2| ... | @@ -461,7 +461,7 @@ test "sha256 streaming" { | ... | @@ -461,7 +461,7 @@ test "sha256 streaming" { |
| 461 | } | 461 | } |
| 462 | 462 | ||
| 463 | test "sha256 aligned final" { | 463 | test "sha256 aligned final" { |
| 464 | var block = [_]u8{0} ** Sha256.block_length; | 464 | var block: [Sha256.block_length]u8 = @splat(0); |
| 465 | var out: [Sha256.digest_length]u8 = undefined; | 465 | var out: [Sha256.digest_length]u8 = undefined; |
| 466 | 466 | ||
| 467 | var h = Sha256.init(.{}); | 467 | var h = Sha256.init(.{}); |
| ... | @@ -833,7 +833,7 @@ test "sha512 streaming" { | ... | @@ -833,7 +833,7 @@ test "sha512 streaming" { |
| 833 | } | 833 | } |
| 834 | 834 | ||
| 835 | test "sha512 aligned final" { | 835 | test "sha512 aligned final" { |
| 836 | var block = [_]u8{0} ** Sha512.block_length; | 836 | var block: [Sha512.block_length]u8 = @splat(0); |
| 837 | var out: [Sha512.digest_length]u8 = undefined; | 837 | var out: [Sha512.digest_length]u8 = undefined; |
| 838 | 838 | ||
| 839 | var h = Sha512.init(.{}); | 839 | var h = Sha512.init(.{}); |
lib/std/crypto/sha3.zig+2-2| ... | @@ -543,7 +543,7 @@ test "sha3-256 streaming" { | ... | @@ -543,7 +543,7 @@ test "sha3-256 streaming" { |
| 543 | } | 543 | } |
| 544 | 544 | ||
| 545 | test "sha3-256 aligned final" { | 545 | test "sha3-256 aligned final" { |
| 546 | var block = [_]u8{0} ** Sha3_256.block_length; | 546 | var block: [Sha3_256.block_length]u8 = @splat(0); |
| 547 | var out: [Sha3_256.digest_length]u8 = undefined; | 547 | var out: [Sha3_256.digest_length]u8 = undefined; |
| 548 | 548 | ||
| 549 | var h = Sha3_256.init(.{}); | 549 | var h = Sha3_256.init(.{}); |
| ... | @@ -616,7 +616,7 @@ test "sha3-512 streaming" { | ... | @@ -616,7 +616,7 @@ test "sha3-512 streaming" { |
| 616 | } | 616 | } |
| 617 | 617 | ||
| 618 | test "sha3-512 aligned final" { | 618 | test "sha3-512 aligned final" { |
| 619 | var block = [_]u8{0} ** Sha3_512.block_length; | 619 | var block: [Sha3_512.block_length]u8 = @splat(0); |
| 620 | var out: [Sha3_512.digest_length]u8 = undefined; | 620 | var out: [Sha3_512.digest_length]u8 = undefined; |
| 621 | 621 | ||
| 622 | var h = Sha3_512.init(.{}); | 622 | var h = Sha3_512.init(.{}); |
lib/std/crypto/siphash.zig+1-1| ... | @@ -91,7 +91,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round | ... | @@ -91,7 +91,7 @@ fn SipHashStateless(comptime T: type, comptime c_rounds: usize, comptime d_round |
| 91 | 91 | ||
| 92 | self.msg_len +%= @as(u8, @truncate(b.len)); | 92 | self.msg_len +%= @as(u8, @truncate(b.len)); |
| 93 | 93 | ||
| 94 | var buf = [_]u8{0} ** 8; | 94 | var buf: [8]u8 = @splat(0); |
| 95 | @memcpy(buf[0..b.len], b); | 95 | @memcpy(buf[0..b.len], b); |
| 96 | buf[7] = self.msg_len; | 96 | buf[7] = self.msg_len; |
| 97 | self.round(buf); | 97 | self.round(buf); |
lib/std/crypto/timing_safe.zig+5-4| ... | @@ -207,8 +207,8 @@ test "eql (vectors)" { | ... | @@ -207,8 +207,8 @@ test "eql (vectors)" { |
| 207 | 207 | ||
| 208 | test compare { | 208 | test compare { |
| 209 | const expectEqual = std.testing.expectEqual; | 209 | const expectEqual = std.testing.expectEqual; |
| 210 | var a = [_]u8{10} ** 32; | 210 | var a: [32]u8 = @splat(10); |
| 211 | var b = [_]u8{10} ** 32; | 211 | var b: [32]u8 = @splat(10); |
| 212 | try expectEqual(compare(u8, &a, &b, .big), .eq); | 212 | try expectEqual(compare(u8, &a, &b, .big), .eq); |
| 213 | try expectEqual(compare(u8, &a, &b, .little), .eq); | 213 | try expectEqual(compare(u8, &a, &b, .little), .eq); |
| 214 | a[31] = 1; | 214 | a[31] = 1; |
| ... | @@ -228,7 +228,7 @@ test "add and sub" { | ... | @@ -228,7 +228,7 @@ test "add and sub" { |
| 228 | var a: [len]u8 = undefined; | 228 | var a: [len]u8 = undefined; |
| 229 | var b: [len]u8 = undefined; | 229 | var b: [len]u8 = undefined; |
| 230 | var c: [len]u8 = undefined; | 230 | var c: [len]u8 = undefined; |
| 231 | const zero = [_]u8{0} ** len; | 231 | const zero: [len]u8 = @splat(0); |
| 232 | var iterations: usize = 100; | 232 | var iterations: usize = 100; |
| 233 | while (iterations != 0) : (iterations -= 1) { | 233 | while (iterations != 0) : (iterations -= 1) { |
| 234 | io.random(&a); | 234 | io.random(&a); |
| ... | @@ -262,7 +262,8 @@ test classify { | ... | @@ -262,7 +262,8 @@ test classify { |
| 262 | declassify(&out); | 262 | declassify(&out); |
| 263 | 263 | ||
| 264 | // Comparing public data in non-constant time is acceptable. | 264 | // Comparing public data in non-constant time is acceptable. |
| 265 | try expect(!std.mem.eql(u8, &out, &[_]u8{0} ** out.len)); | 265 | const zeroes: [out.len]u8 = @splat(0); |
| 266 | try expect(!std.mem.eql(u8, &out, &zeroes)); | ||
| 266 | 267 | ||
| 267 | // Comparing secret data must be done in constant time. The result | 268 | // Comparing secret data must be done in constant time. The result |
| 268 | // is going to be considered as secret as well. | 269 | // is going to be considered as secret as well. |
lib/std/crypto/tls/Client.zig+10-9| ... | @@ -375,7 +375,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -375,7 +375,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 375 | const auth_tag = record_decoder.array(P.AEAD.tag_length).*; | 375 | const auth_tag = record_decoder.array(P.AEAD.tag_length).*; |
| 376 | const nonce = nonce: { | 376 | const nonce = nonce: { |
| 377 | const V = @Vector(P.AEAD.nonce_length, u8); | 377 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 378 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 378 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 379 | const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq))); | 379 | const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq))); |
| 380 | break :nonce @as(V, pv.server_handshake_iv) ^ operand; | 380 | break :nonce @as(V, pv.server_handshake_iv) ^ operand; |
| 381 | }; | 381 | }; |
| ... | @@ -415,7 +415,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -415,7 +415,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 415 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); | 415 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); |
| 416 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 416 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 417 | const V = @Vector(P.AEAD.nonce_length, u8); | 417 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 418 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 418 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 419 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); | 419 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); |
| 420 | break :nonce @as(V, pv.app_cipher.server_write_IV ++ record_iv) ^ operand; | 420 | break :nonce @as(V, pv.app_cipher.server_write_IV ++ record_iv) ^ operand; |
| 421 | }; | 421 | }; |
| ... | @@ -539,7 +539,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -539,7 +539,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 539 | const p = &@field(handshake_cipher, @tagName(tag.with())); | 539 | const p = &@field(handshake_cipher, @tagName(tag.with())); |
| 540 | const P = @TypeOf(p.*).A; | 540 | const P = @TypeOf(p.*).A; |
| 541 | const hello_hash = p.transcript_hash.peek(); | 541 | const hello_hash = p.transcript_hash.peek(); |
| 542 | const zeroes = [1]u8{0} ** P.Hash.digest_length; | 542 | const zeroes: [P.Hash.digest_length]u8 = @splat(0); |
| 543 | const early_secret = P.Hkdf.extract(&[1]u8{0}, &zeroes); | 543 | const early_secret = P.Hkdf.extract(&[1]u8{0}, &zeroes); |
| 544 | const empty_hash = tls.emptyHash(P.Hash); | 544 | const empty_hash = tls.emptyHash(P.Hash); |
| 545 | p.version = .{ .tls_1_3 = undefined }; | 545 | p.version = .{ .tls_1_3 = undefined }; |
| ... | @@ -791,7 +791,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -791,7 +791,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 791 | const pv = &p.version.tls_1_2; | 791 | const pv = &p.version.tls_1_2; |
| 792 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 792 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 793 | const V = @Vector(P.AEAD.nonce_length, u8); | 793 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 794 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 794 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 795 | const operand: V = pad ++ @as([8]u8, @bitCast(big(write_seq))); | 795 | const operand: V = pad ++ @as([8]u8, @bitCast(big(write_seq))); |
| 796 | break :nonce @as(V, pv.app_cipher.client_write_IV ++ pv.app_cipher.client_salt) ^ operand; | 796 | break :nonce @as(V, pv.app_cipher.client_write_IV ++ pv.app_cipher.client_salt) ^ operand; |
| 797 | }; | 797 | }; |
| ... | @@ -832,8 +832,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client | ... | @@ -832,8 +832,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client |
| 832 | } | 832 | } |
| 833 | switch (handshake_cipher) { | 833 | switch (handshake_cipher) { |
| 834 | inline else => |*p| { | 834 | inline else => |*p| { |
| 835 | const pad: [64]u8 = @splat(' '); | ||
| 835 | try main_cert_pub_key.verifySignature(&hsd, &.{ | 836 | try main_cert_pub_key.verifySignature(&hsd, &.{ |
| 836 | " " ** 64 ++ "TLS 1.3, server CertificateVerify\x00", | 837 | pad ++ "TLS 1.3, server CertificateVerify\x00", |
| 837 | &p.transcript_hash.peek(), | 838 | &p.transcript_hash.peek(), |
| 838 | }); | 839 | }); |
| 839 | p.transcript_hash.update(wrapped_handshake); | 840 | p.transcript_hash.update(wrapped_handshake); |
| ... | @@ -1066,7 +1067,7 @@ fn prepareCiphertextRecord( | ... | @@ -1066,7 +1067,7 @@ fn prepareCiphertextRecord( |
| 1066 | ciphertext_end += auth_tag.len; | 1067 | ciphertext_end += auth_tag.len; |
| 1067 | const nonce = nonce: { | 1068 | const nonce = nonce: { |
| 1068 | const V = @Vector(P.AEAD.nonce_length, u8); | 1069 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1069 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1070 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1070 | const operand: V = pad ++ mem.toBytes(big(c.write_seq)); | 1071 | const operand: V = pad ++ mem.toBytes(big(c.write_seq)); |
| 1071 | break :nonce @as(V, pv.client_iv) ^ operand; | 1072 | break :nonce @as(V, pv.client_iv) ^ operand; |
| 1072 | }; | 1073 | }; |
| ... | @@ -1103,7 +1104,7 @@ fn prepareCiphertextRecord( | ... | @@ -1103,7 +1104,7 @@ fn prepareCiphertextRecord( |
| 1103 | ciphertext_end += P.record_iv_length; | 1104 | ciphertext_end += P.record_iv_length; |
| 1104 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 1105 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 1105 | const V = @Vector(P.AEAD.nonce_length, u8); | 1106 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1106 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1107 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1107 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq))); | 1108 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq))); |
| 1108 | break :nonce @as(V, pv.client_write_IV ++ pv.client_salt) ^ operand; | 1109 | break :nonce @as(V, pv.client_write_IV ++ pv.client_salt) ^ operand; |
| 1109 | }; | 1110 | }; |
| ... | @@ -1185,7 +1186,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { | ... | @@ -1185,7 +1186,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { |
| 1185 | const auth_tag = (input.takeArray(P.AEAD.tag_length) catch unreachable).*; // already peeked | 1186 | const auth_tag = (input.takeArray(P.AEAD.tag_length) catch unreachable).*; // already peeked |
| 1186 | const nonce = nonce: { | 1187 | const nonce = nonce: { |
| 1187 | const V = @Vector(P.AEAD.nonce_length, u8); | 1188 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1188 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1189 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1189 | const operand: V = pad ++ mem.toBytes(big(c.read_seq)); | 1190 | const operand: V = pad ++ mem.toBytes(big(c.read_seq)); |
| 1190 | break :nonce @as(V, pv.server_iv) ^ operand; | 1191 | break :nonce @as(V, pv.server_iv) ^ operand; |
| 1191 | }; | 1192 | }; |
| ... | @@ -1211,7 +1212,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { | ... | @@ -1211,7 +1212,7 @@ fn readIndirect(c: *Client) Reader.Error!usize { |
| 1211 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); | 1212 | comptime std.math.shl(u64, std.math.maxInt(u64), 8 * P.record_iv_length); |
| 1212 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { | 1213 | const nonce: [P.AEAD.nonce_length]u8 = nonce: { |
| 1213 | const V = @Vector(P.AEAD.nonce_length, u8); | 1214 | const V = @Vector(P.AEAD.nonce_length, u8); |
| 1214 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1215 | const pad: [P.AEAD.nonce_length - 8]u8 = @splat(0); |
| 1215 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); | 1216 | const operand: V = pad ++ @as([8]u8, @bitCast(big(masked_read_seq))); |
| 1216 | break :nonce @as(V, pv.server_write_IV ++ record_iv) ^ operand; | 1217 | break :nonce @as(V, pv.server_write_IV ++ record_iv) ^ operand; |
| 1217 | }; | 1218 | }; |
lib/std/debug.zig+6-4| ... | @@ -1381,7 +1381,7 @@ test printLineFromFile { | ... | @@ -1381,7 +1381,7 @@ test printLineFromFile { |
| 1381 | try writer.flush(); | 1381 | try writer.flush(); |
| 1382 | 1382 | ||
| 1383 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); | 1383 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); |
| 1384 | try expectEqualStrings(("a" ** overlap) ++ "\n", aw.written()); | 1384 | try expectEqualStrings(&@as([overlap]u8, @splat('a')) ++ "\n", aw.written()); |
| 1385 | aw.clearRetainingCapacity(); | 1385 | aw.clearRetainingCapacity(); |
| 1386 | } | 1386 | } |
| 1387 | { | 1387 | { |
| ... | @@ -1395,7 +1395,7 @@ test printLineFromFile { | ... | @@ -1395,7 +1395,7 @@ test printLineFromFile { |
| 1395 | try writer.splatByteAll('a', std.heap.page_size_max); | 1395 | try writer.splatByteAll('a', std.heap.page_size_max); |
| 1396 | 1396 | ||
| 1397 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); | 1397 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); |
| 1398 | try expectEqualStrings(("a" ** std.heap.page_size_max) ++ "\n", aw.written()); | 1398 | try expectEqualStrings(&@as([std.heap.page_size_max]u8, @splat('a')) ++ "\n", aw.written()); |
| 1399 | aw.clearRetainingCapacity(); | 1399 | aw.clearRetainingCapacity(); |
| 1400 | } | 1400 | } |
| 1401 | { | 1401 | { |
| ... | @@ -1410,14 +1410,16 @@ test printLineFromFile { | ... | @@ -1410,14 +1410,16 @@ test printLineFromFile { |
| 1410 | 1410 | ||
| 1411 | try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 })); | 1411 | try expectError(error.EndOfStream, printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 })); |
| 1412 | 1412 | ||
| 1413 | const many_a: [3 * std.heap.page_size_max]u8 = @splat('a'); | ||
| 1414 | |||
| 1413 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); | 1415 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); |
| 1414 | try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "\n", aw.written()); | 1416 | try expectEqualStrings(&many_a ++ "\n", aw.written()); |
| 1415 | aw.clearRetainingCapacity(); | 1417 | aw.clearRetainingCapacity(); |
| 1416 | 1418 | ||
| 1417 | try writer.writeAll("a\na"); | 1419 | try writer.writeAll("a\na"); |
| 1418 | 1420 | ||
| 1419 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); | 1421 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 1, .column = 0 }); |
| 1420 | try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "a\n", aw.written()); | 1422 | try expectEqualStrings(&many_a ++ "a\n", aw.written()); |
| 1421 | aw.clearRetainingCapacity(); | 1423 | aw.clearRetainingCapacity(); |
| 1422 | 1424 | ||
| 1423 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); | 1425 | try printLineFromFile(io, output_stream, .{ .file_name = path, .line = 2, .column = 0 }); |
lib/std/debug/Dwarf.zig+1-1| ... | @@ -1346,7 +1346,7 @@ const FileEntry = struct { | ... | @@ -1346,7 +1346,7 @@ const FileEntry = struct { |
| 1346 | dir_index: u32 = 0, | 1346 | dir_index: u32 = 0, |
| 1347 | mtime: u64 = 0, | 1347 | mtime: u64 = 0, |
| 1348 | size: u64 = 0, | 1348 | size: u64 = 0, |
| 1349 | md5: [16]u8 = [1]u8{0} ** 16, | 1349 | md5: [16]u8 = @splat(0), |
| 1350 | }; | 1350 | }; |
| 1351 | 1351 | ||
| 1352 | const LineNumberProgram = struct { | 1352 | const LineNumberProgram = struct { |
lib/std/elf.zig+1-1| ... | @@ -3054,7 +3054,7 @@ pub const ar_hdr = extern struct { | ... | @@ -3054,7 +3054,7 @@ pub const ar_hdr = extern struct { |
| 3054 | fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 { | 3054 | fn genSpecialMemberName(comptime name: []const u8) *const [16]u8 { |
| 3055 | assert(name.len <= 16); | 3055 | assert(name.len <= 16); |
| 3056 | const padding = 16 - name.len; | 3056 | const padding = 16 - name.len; |
| 3057 | return name ++ &[_]u8{0x20} ** padding; | 3057 | return name ++ @as([padding]u8, @splat(0x20)); |
| 3058 | } | 3058 | } |
| 3059 | 3059 | ||
| 3060 | // Archive files start with the ARMAG identifying string. Then follows a | 3060 | // Archive files start with the ARMAG identifying string. Then follows a |
lib/std/enums.zig+1-1| ... | @@ -166,7 +166,7 @@ pub fn directEnumArrayDefault( | ... | @@ -166,7 +166,7 @@ pub fn directEnumArrayDefault( |
| 166 | init_values: EnumFieldStruct(E, Data, default), | 166 | init_values: EnumFieldStruct(E, Data, default), |
| 167 | ) [directEnumArrayLen(E, max_unused_slots)]Data { | 167 | ) [directEnumArrayLen(E, max_unused_slots)]Data { |
| 168 | const len = comptime directEnumArrayLen(E, max_unused_slots); | 168 | const len = comptime directEnumArrayLen(E, max_unused_slots); |
| 169 | var result: [len]Data = if (default) |d| [_]Data{d} ** len else undefined; | 169 | var result: [len]Data = @splat(default orelse undefined); |
| 170 | inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| { | 170 | inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| { |
| 171 | const enum_value = @field(E, f.name); | 171 | const enum_value = @field(E, f.name); |
| 172 | const index = @as(usize, @intCast(@intFromEnum(enum_value))); | 172 | const index = @as(usize, @intCast(@intFromEnum(enum_value))); |
lib/std/fmt.zig+5-1| ... | @@ -1194,8 +1194,12 @@ test bytesToHex { | ... | @@ -1194,8 +1194,12 @@ test bytesToHex { |
| 1194 | } | 1194 | } |
| 1195 | 1195 | ||
| 1196 | test hexToBytes { | 1196 | test hexToBytes { |
| 1197 | const repeated: []const u8 = repeated: { | ||
| 1198 | const buf: [32][2]u8 = @splat("90".*); | ||
| 1199 | break :repeated @ptrCast(&buf); | ||
| 1200 | }; | ||
| 1197 | var buf: [32]u8 = undefined; | 1201 | var buf: [32]u8 = undefined; |
| 1198 | try expectFmt("90" ** 32, "{X}", .{try hexToBytes(&buf, "90" ** 32)}); | 1202 | try expectFmt(repeated, "{X}", .{try hexToBytes(&buf, repeated)}); |
| 1199 | try expectFmt("ABCD", "{X}", .{try hexToBytes(&buf, "ABCD")}); | 1203 | try expectFmt("ABCD", "{X}", .{try hexToBytes(&buf, "ABCD")}); |
| 1200 | try expectFmt("", "{X}", .{try hexToBytes(&buf, "")}); | 1204 | try expectFmt("", "{X}", .{try hexToBytes(&buf, "")}); |
| 1201 | try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z")); | 1205 | try std.testing.expectError(error.InvalidCharacter, hexToBytes(&buf, "012Z")); |
lib/std/fmt/parse_float/decimal.zig+1-1| ... | @@ -80,7 +80,7 @@ pub fn Decimal(comptime T: type) type { | ... | @@ -80,7 +80,7 @@ pub fn Decimal(comptime T: type) type { |
| 80 | .num_digits = 0, | 80 | .num_digits = 0, |
| 81 | .decimal_point = 0, | 81 | .decimal_point = 0, |
| 82 | .truncated = false, | 82 | .truncated = false, |
| 83 | .digits = [_]u8{0} ** max_digits, | 83 | .digits = @splat(0), |
| 84 | }; | 84 | }; |
| 85 | } | 85 | } |
| 86 | 86 |
lib/std/fs/test.zig+7-3| ... | @@ -1449,11 +1449,15 @@ test "max file name component lengths" { | ... | @@ -1449,11 +1449,15 @@ test "max file name component lengths" { |
| 1449 | if (native_os == .windows) { | 1449 | if (native_os == .windows) { |
| 1450 | // U+FFFF is the character with the largest code point that is encoded as a single | 1450 | // U+FFFF is the character with the largest code point that is encoded as a single |
| 1451 | // WTF-16 code unit, so Windows allows for NAME_MAX of them. | 1451 | // WTF-16 code unit, so Windows allows for NAME_MAX of them. |
| 1452 | const maxed_windows_filename1 = ("\u{FFFF}".*) ** windows.NAME_MAX; | 1452 | const codepoint1 = "\u{FFFF}".*; |
| 1453 | const buf1: [windows.NAME_MAX][codepoint1.len]u8 = @splat(codepoint1); | ||
| 1454 | const maxed_windows_filename1: []const u8 = @ptrCast(&buf1); | ||
| 1453 | // This is also a code point that is encoded as one WTF-16 code unit, but | 1455 | // This is also a code point that is encoded as one WTF-16 code unit, but |
| 1454 | // three WTF-8 bytes, so it exercises the limits of both WTF-16 and WTF-8 encodings. | 1456 | // three WTF-8 bytes, so it exercises the limits of both WTF-16 and WTF-8 encodings. |
| 1455 | const maxed_windows_filename2 = ("€".*) ** windows.NAME_MAX; | 1457 | const codepoint2 = "€".*; |
| 1456 | try testFilenameLimits(io, tmp.dir, &maxed_windows_filename1, &maxed_windows_filename2); | 1458 | const buf2: [windows.NAME_MAX][codepoint2.len]u8 = @splat(codepoint2); |
| 1459 | const maxed_windows_filename2: []const u8 = @ptrCast(&buf2); | ||
| 1460 | try testFilenameLimits(io, tmp.dir, maxed_windows_filename1, maxed_windows_filename2); | ||
| 1457 | } else if (native_os == .wasi) { | 1461 | } else if (native_os == .wasi) { |
| 1458 | // On WASI, the maxed filename depends on the host OS, so in order for this test to | 1462 | // On WASI, the maxed filename depends on the host OS, so in order for this test to |
| 1459 | // work on any host, we need to use a length that will work for all platforms | 1463 | // work on any host, we need to use a length that will work for all platforms |
lib/std/hash/Adler32.zig+3-3| ... | @@ -88,15 +88,15 @@ test "sanity" { | ... | @@ -88,15 +88,15 @@ test "sanity" { |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | test "long" { | 90 | test "long" { |
| 91 | const long1 = [_]u8{1} ** 1024; | 91 | const long1: [1024]u8 = @splat(1); |
| 92 | try testing.expectEqual(@as(u32, 0x06780401), hash(long1[0..])); | 92 | try testing.expectEqual(@as(u32, 0x06780401), hash(long1[0..])); |
| 93 | 93 | ||
| 94 | const long2 = [_]u8{1} ** 1025; | 94 | const long2: [1025]u8 = @splat(1); |
| 95 | try testing.expectEqual(@as(u32, 0x0a7a0402), hash(long2[0..])); | 95 | try testing.expectEqual(@as(u32, 0x0a7a0402), hash(long2[0..])); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | test "very long" { | 98 | test "very long" { |
| 99 | const long = [_]u8{1} ** 5553; | 99 | const long: [5553]u8 = @splat(1); |
| 100 | try testing.expectEqual(@as(u32, 0x707f15b2), hash(long[0..])); | 100 | try testing.expectEqual(@as(u32, 0x707f15b2), hash(long[0..])); |
| 101 | } | 101 | } |
| 102 | 102 |
lib/std/hash/benchmark.zig+2-2| ... | @@ -93,13 +93,13 @@ const hashes = [_]Hash{ | ... | @@ -93,13 +93,13 @@ const hashes = [_]Hash{ |
| 93 | .ty = hash.SipHash64(1, 3), | 93 | .ty = hash.SipHash64(1, 3), |
| 94 | .name = "siphash64", | 94 | .name = "siphash64", |
| 95 | .has_crypto_api = true, | 95 | .has_crypto_api = true, |
| 96 | .init_u8s = &[_]u8{0} ** 16, | 96 | .init_u8s = &@as([16]u8, @splat(0)), |
| 97 | }, | 97 | }, |
| 98 | Hash{ | 98 | Hash{ |
| 99 | .ty = hash.SipHash128(1, 3), | 99 | .ty = hash.SipHash128(1, 3), |
| 100 | .name = "siphash128", | 100 | .name = "siphash128", |
| 101 | .has_crypto_api = true, | 101 | .has_crypto_api = true, |
| 102 | .init_u8s = &[_]u8{0} ** 16, | 102 | .init_u8s = &@as([16]u8, @splat(0)), |
| 103 | }, | 103 | }, |
| 104 | }; | 104 | }; |
| 105 | 105 |
lib/std/hash/wyhash.zig+1-1| ... | @@ -253,7 +253,7 @@ test "iterative api" { | ... | @@ -253,7 +253,7 @@ test "iterative api" { |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | test "iterative maintains last sixteen" { | 255 | test "iterative maintains last sixteen" { |
| 256 | const input = "Z" ** 48 ++ "01234567890abcdefg"; | 256 | const input = &@as([48]u8, @splat('Z')) ++ "01234567890abcdefg"; |
| 257 | const seed = 0; | 257 | const seed = 0; |
| 258 | 258 | ||
| 259 | for (0..17) |i| { | 259 | for (0..17) |i| { |
lib/std/heap/debug_allocator.zig+1-1| ... | @@ -164,7 +164,7 @@ pub fn DebugAllocator(comptime config: Config) type { | ... | @@ -164,7 +164,7 @@ pub fn DebugAllocator(comptime config: Config) type { |
| 164 | return struct { | 164 | return struct { |
| 165 | backing_allocator: Allocator = std.heap.page_allocator, | 165 | backing_allocator: Allocator = std.heap.page_allocator, |
| 166 | /// Tracks the active bucket, which is the one that has free slots in it. | 166 | /// Tracks the active bucket, which is the one that has free slots in it. |
| 167 | buckets: [small_bucket_count]?*BucketHeader = [1]?*BucketHeader{null} ** small_bucket_count, | 167 | buckets: [small_bucket_count]?*BucketHeader = @splat(null), |
| 168 | large_allocations: LargeAllocTable = .empty, | 168 | large_allocations: LargeAllocTable = .empty, |
| 169 | total_requested_bytes: @TypeOf(total_requested_bytes_init) = total_requested_bytes_init, | 169 | total_requested_bytes: @TypeOf(total_requested_bytes_init) = total_requested_bytes_init, |
| 170 | requested_memory_limit: @TypeOf(requested_memory_limit_init) = requested_memory_limit_init, | 170 | requested_memory_limit: @TypeOf(requested_memory_limit_init) = requested_memory_limit_init, |
lib/std/http.zig+1-1| ... | @@ -749,7 +749,7 @@ pub const BodyWriter = struct { | ... | @@ -749,7 +749,7 @@ pub const BodyWriter = struct { |
| 749 | /// How many zeroes to reserve for hex-encoded chunk length. | 749 | /// How many zeroes to reserve for hex-encoded chunk length. |
| 750 | const chunk_len_digits = 8; | 750 | const chunk_len_digits = 8; |
| 751 | const max_chunk_len: usize = std.math.pow(u64, 16, chunk_len_digits) - 1; | 751 | const max_chunk_len: usize = std.math.pow(u64, 16, chunk_len_digits) - 1; |
| 752 | const chunk_header_template = ("0" ** chunk_len_digits) ++ "\r\n"; | 752 | const chunk_header_template = @as([chunk_len_digits]u8, @splat('0')) ++ "\r\n"; |
| 753 | 753 | ||
| 754 | comptime { | 754 | comptime { |
| 755 | assert(max_chunk_len == std.math.maxInt(u32)); | 755 | assert(max_chunk_len == std.math.maxInt(u32)); |
lib/std/json/JSONTestSuite_test.zig+10-5| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | // This file was generated by _generate_JSONTestSuite.zig | 1 | //! This file was generated by _generate_JSONTestSuite.zig |
| 2 | // These test cases are sourced from: https://github.com/nst/JSONTestSuite | 2 | //! These test cases are sourced from: https://github.com/nst/JSONTestSuite |
| 3 | const ok = @import("./test.zig").ok; | 3 | const ok = @import("./test.zig").ok; |
| 4 | const err = @import("./test.zig").err; | 4 | const err = @import("./test.zig").err; |
| 5 | const any = @import("./test.zig").any; | 5 | const any = @import("./test.zig").any; |
| ... | @@ -104,7 +104,7 @@ test "i_string_utf16LE_no_BOM.json" { | ... | @@ -104,7 +104,7 @@ test "i_string_utf16LE_no_BOM.json" { |
| 104 | try any("[\x00\"\x00\xe9\x00\"\x00]\x00"); | 104 | try any("[\x00\"\x00\xe9\x00\"\x00]\x00"); |
| 105 | } | 105 | } |
| 106 | test "i_structure_500_nested_arrays.json" { | 106 | test "i_structure_500_nested_arrays.json" { |
| 107 | try any("[" ** 500 ++ "]" ** 500); | 107 | try any(&@as([500]u8, @splat('[')) ++ &@as([500]u8, @splat(']'))); |
| 108 | } | 108 | } |
| 109 | test "i_structure_UTF-8_BOM_empty_object.json" { | 109 | test "i_structure_UTF-8_BOM_empty_object.json" { |
| 110 | try any("\xef\xbb\xbf{}"); | 110 | try any("\xef\xbb\xbf{}"); |
| ... | @@ -527,7 +527,7 @@ test "n_string_with_trailing_garbage.json" { | ... | @@ -527,7 +527,7 @@ test "n_string_with_trailing_garbage.json" { |
| 527 | try err("\"\"x"); | 527 | try err("\"\"x"); |
| 528 | } | 528 | } |
| 529 | test "n_structure_100000_opening_arrays.json" { | 529 | test "n_structure_100000_opening_arrays.json" { |
| 530 | try err("[" ** 100000); | 530 | try err(&@as([100000]u8, @splat('['))); |
| 531 | } | 531 | } |
| 532 | test "n_structure_U+2060_word_joined.json" { | 532 | test "n_structure_U+2060_word_joined.json" { |
| 533 | try err("[\xe2\x81\xa0]"); | 533 | try err("[\xe2\x81\xa0]"); |
| ... | @@ -605,7 +605,12 @@ test "n_structure_open_array_comma.json" { | ... | @@ -605,7 +605,12 @@ test "n_structure_open_array_comma.json" { |
| 605 | try err("[,"); | 605 | try err("[,"); |
| 606 | } | 606 | } |
| 607 | test "n_structure_open_array_object.json" { | 607 | test "n_structure_open_array_object.json" { |
| 608 | try err("[{\"\":" ** 50000 ++ "\n"); | 608 | try err(str: { |
| 609 | const part = "[{\"\":"; | ||
| 610 | const buf: [50000][part.len]u8 = @splat(part.*); | ||
| 611 | const s: []const u8 = @ptrCast(&buf); | ||
| 612 | break :str s ++ "\n"; | ||
| 613 | }); | ||
| 609 | } | 614 | } |
| 610 | test "n_structure_open_array_open_object.json" { | 615 | test "n_structure_open_array_open_object.json" { |
| 611 | try err("[{"); | 616 | try err("[{"); |
lib/std/json/scanner_test.zig+28-17| ... | @@ -261,19 +261,28 @@ test "strings" { | ... | @@ -261,19 +261,28 @@ test "strings" { |
| 261 | } | 261 | } |
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | const nesting_test_cases = .{ | 264 | const nesting_test_cases = cases: { |
| 265 | .{ null, "[]" }, | 265 | const open_arrays: *const [1000]u8 = &@splat('['); |
| 266 | .{ null, "{}" }, | 266 | const close_arrays: *const [1000]u8 = &@splat(']'); |
| 267 | .{ error.SyntaxError, "[}" }, | 267 | |
| 268 | .{ error.SyntaxError, "{]" }, | 268 | const open_objects_buf: [1000][4]u8 = @splat("{\"\":".*); |
| 269 | .{ null, "[" ** 1000 ++ "]" ** 1000 }, | 269 | const open_objects: []const u8 = @ptrCast(&open_objects_buf); |
| 270 | .{ null, "{\"\":" ** 1000 ++ "0" ++ "}" ** 1000 }, | 270 | const close_objects: *const [1000]u8 = &@splat('}'); |
| 271 | .{ error.SyntaxError, "[" ** 1000 ++ "]" ** 999 ++ "}" }, | 271 | |
| 272 | .{ error.SyntaxError, "{\"\":" ** 1000 ++ "0" ++ "}" ** 999 ++ "]" }, | 272 | break :cases .{ |
| 273 | .{ error.SyntaxError, "[" ** 1000 ++ "]" ** 1001 }, | 273 | .{ null, "[]" }, |
| 274 | .{ error.SyntaxError, "{\"\":" ** 1000 ++ "0" ++ "}" ** 1001 }, | 274 | .{ null, "{}" }, |
| 275 | .{ error.UnexpectedEndOfInput, "[" ** 1000 ++ "]" ** 999 }, | 275 | .{ error.SyntaxError, "[}" }, |
| 276 | .{ error.UnexpectedEndOfInput, "{\"\":" ** 1000 ++ "0" ++ "}" ** 999 }, | 276 | .{ error.SyntaxError, "{]" }, |
| 277 | .{ null, open_arrays ++ close_arrays }, | ||
| 278 | .{ null, open_objects ++ "0" ++ close_objects }, | ||
| 279 | .{ error.SyntaxError, open_arrays ++ close_arrays[0..999] ++ "}" }, | ||
| 280 | .{ error.SyntaxError, open_objects ++ "0" ++ close_objects[0..999] ++ "]" }, | ||
| 281 | .{ error.SyntaxError, open_arrays ++ close_arrays ++ "]" }, | ||
| 282 | .{ error.SyntaxError, open_objects ++ "0" ++ close_objects ++ "}" }, | ||
| 283 | .{ error.UnexpectedEndOfInput, open_arrays ++ close_arrays[0..999] }, | ||
| 284 | .{ error.UnexpectedEndOfInput, open_objects ++ "0" ++ close_objects[0..999] }, | ||
| 285 | }; | ||
| 277 | }; | 286 | }; |
| 278 | 287 | ||
| 279 | test "nesting" { | 288 | test "nesting" { |
| ... | @@ -421,11 +430,12 @@ test "skipValue" { | ... | @@ -421,11 +430,12 @@ test "skipValue" { |
| 421 | try testSkipValue("{\"foo\": \"bar\\nbaz\"}"); | 430 | try testSkipValue("{\"foo\": \"bar\\nbaz\"}"); |
| 422 | 431 | ||
| 423 | // An absurd number of nestings | 432 | // An absurd number of nestings |
| 424 | const nestings = 1000; | 433 | const open_all: [1000]u8 = @splat('['); |
| 425 | try testSkipValue("[" ** nestings ++ "]" ** nestings); | 434 | const close_all: [1000]u8 = @splat(']'); |
| 435 | try testSkipValue(&(open_all ++ close_all)); | ||
| 426 | 436 | ||
| 427 | // Would a number token cause problems in a deeply-nested array? | 437 | // Would a number token cause problems in a deeply-nested array? |
| 428 | try testSkipValue("[" ** nestings ++ "0.118, 999, 881.99, 911.9, 725, 3" ++ "]" ** nestings); | 438 | try testSkipValue(&open_all ++ "0.118, 999, 881.99, 911.9, 725, 3" ++ &close_all); |
| 429 | 439 | ||
| 430 | // Mismatched brace/square bracket | 440 | // Mismatched brace/square bracket |
| 431 | try std.testing.expectError(error.SyntaxError, testSkipValue("[102, 111, 111}")); | 441 | try std.testing.expectError(error.SyntaxError, testSkipValue("[102, 111, 111}")); |
| ... | @@ -474,7 +484,8 @@ test "enableDiagnostics" { | ... | @@ -474,7 +484,8 @@ test "enableDiagnostics" { |
| 474 | 484 | ||
| 475 | inline for ([_]comptime_int{ 5, 6, 7, 99 }) |reps| { | 485 | inline for ([_]comptime_int{ 5, 6, 7, 99 }) |reps| { |
| 476 | // The error happens 1 byte before the end. | 486 | // The error happens 1 byte before the end. |
| 477 | const s = "[" ** reps ++ "}"; | 487 | const open_all: [reps]u8 = @splat('['); |
| 488 | const s = &open_all ++ "}"; | ||
| 478 | try testDiagnostics(error.SyntaxError, 1, s.len, s.len - 1, s); | 489 | try testDiagnostics(error.SyntaxError, 1, s.len, s.len - 1, s); |
| 479 | } | 490 | } |
| 480 | } | 491 | } |
lib/std/json/static.zig+2-2| ... | @@ -334,7 +334,7 @@ pub fn innerParse( | ... | @@ -334,7 +334,7 @@ pub fn innerParse( |
| 334 | if (.object_begin != try source.next()) return error.UnexpectedToken; | 334 | if (.object_begin != try source.next()) return error.UnexpectedToken; |
| 335 | 335 | ||
| 336 | var r: T = undefined; | 336 | var r: T = undefined; |
| 337 | var fields_seen = [_]bool{false} ** structInfo.fields.len; | 337 | var fields_seen: [structInfo.fields.len]bool = @splat(false); |
| 338 | 338 | ||
| 339 | while (true) { | 339 | while (true) { |
| 340 | var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?); | 340 | var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?); |
| ... | @@ -649,7 +649,7 @@ pub fn innerParseFromValue( | ... | @@ -649,7 +649,7 @@ pub fn innerParseFromValue( |
| 649 | if (source != .object) return error.UnexpectedToken; | 649 | if (source != .object) return error.UnexpectedToken; |
| 650 | 650 | ||
| 651 | var r: T = undefined; | 651 | var r: T = undefined; |
| 652 | var fields_seen = [_]bool{false} ** structInfo.fields.len; | 652 | var fields_seen: [structInfo.fields.len]bool = @splat(false); |
| 653 | 653 | ||
| 654 | var it = source.object.iterator(); | 654 | var it = source.object.iterator(); |
| 655 | while (it.next()) |kv| { | 655 | while (it.next()) |kv| { |
lib/std/json/static_test.zig-7| ... | @@ -22,7 +22,6 @@ const Primitives = struct { | ... | @@ -22,7 +22,6 @@ const Primitives = struct { |
| 22 | f32: f32, | 22 | f32: f32, |
| 23 | f64: f64, | 23 | f64: f64, |
| 24 | u0: u0, | 24 | u0: u0, |
| 25 | i0: i0, | ||
| 26 | u1: u1, | 25 | u1: u1, |
| 27 | i1: i1, | 26 | i1: i1, |
| 28 | u8: u8, | 27 | u8: u8, |
| ... | @@ -35,7 +34,6 @@ const primitives_0 = Primitives{ | ... | @@ -35,7 +34,6 @@ const primitives_0 = Primitives{ |
| 35 | .f32 = 0, | 34 | .f32 = 0, |
| 36 | .f64 = 0, | 35 | .f64 = 0, |
| 37 | .u0 = 0, | 36 | .u0 = 0, |
| 38 | .i0 = 0, | ||
| 39 | .u1 = 0, | 37 | .u1 = 0, |
| 40 | .i1 = 0, | 38 | .i1 = 0, |
| 41 | .u8 = 0, | 39 | .u8 = 0, |
| ... | @@ -48,7 +46,6 @@ const primitives_0_doc_0 = | ... | @@ -48,7 +46,6 @@ const primitives_0_doc_0 = |
| 48 | \\ "f32": 0, | 46 | \\ "f32": 0, |
| 49 | \\ "f64": 0, | 47 | \\ "f64": 0, |
| 50 | \\ "u0": 0, | 48 | \\ "u0": 0, |
| 51 | \\ "i0": 0, | ||
| 52 | \\ "u1": 0, | 49 | \\ "u1": 0, |
| 53 | \\ "i1": 0, | 50 | \\ "i1": 0, |
| 54 | \\ "u8": 0, | 51 | \\ "u8": 0, |
| ... | @@ -62,7 +59,6 @@ const primitives_0_doc_1 = // looks like a float. | ... | @@ -62,7 +59,6 @@ const primitives_0_doc_1 = // looks like a float. |
| 62 | \\ "f32": 0.0, | 59 | \\ "f32": 0.0, |
| 63 | \\ "f64": 0.0, | 60 | \\ "f64": 0.0, |
| 64 | \\ "u0": 0.0, | 61 | \\ "u0": 0.0, |
| 65 | \\ "i0": 0.0, | ||
| 66 | \\ "u1": 0.0, | 62 | \\ "u1": 0.0, |
| 67 | \\ "i1": 0.0, | 63 | \\ "i1": 0.0, |
| 68 | \\ "u8": 0.0, | 64 | \\ "u8": 0.0, |
| ... | @@ -76,7 +72,6 @@ const primitives_1 = Primitives{ | ... | @@ -76,7 +72,6 @@ const primitives_1 = Primitives{ |
| 76 | .f32 = 1073741824, | 72 | .f32 = 1073741824, |
| 77 | .f64 = 1152921504606846976, | 73 | .f64 = 1152921504606846976, |
| 78 | .u0 = 0, | 74 | .u0 = 0, |
| 79 | .i0 = 0, | ||
| 80 | .u1 = 1, | 75 | .u1 = 1, |
| 81 | .i1 = -1, | 76 | .i1 = -1, |
| 82 | .u8 = 255, | 77 | .u8 = 255, |
| ... | @@ -89,7 +84,6 @@ const primitives_1_doc_0 = | ... | @@ -89,7 +84,6 @@ const primitives_1_doc_0 = |
| 89 | \\ "f32": 1073741824, | 84 | \\ "f32": 1073741824, |
| 90 | \\ "f64": 1152921504606846976, | 85 | \\ "f64": 1152921504606846976, |
| 91 | \\ "u0": 0, | 86 | \\ "u0": 0, |
| 92 | \\ "i0": 0, | ||
| 93 | \\ "u1": 1, | 87 | \\ "u1": 1, |
| 94 | \\ "i1": -1, | 88 | \\ "i1": -1, |
| 95 | \\ "u8": 255, | 89 | \\ "u8": 255, |
| ... | @@ -103,7 +97,6 @@ const primitives_1_doc_1 = // float rounding. | ... | @@ -103,7 +97,6 @@ const primitives_1_doc_1 = // float rounding. |
| 103 | \\ "f32": 1073741825, | 97 | \\ "f32": 1073741825, |
| 104 | \\ "f64": 1152921504606846977, | 98 | \\ "f64": 1152921504606846977, |
| 105 | \\ "u0": 0, | 99 | \\ "u0": 0, |
| 106 | \\ "i0": 0, | ||
| 107 | \\ "u1": 1, | 100 | \\ "u1": 1, |
| 108 | \\ "i1": -1, | 101 | \\ "i1": -1, |
| 109 | \\ "u8": 255, | 102 | \\ "u8": 255, |
lib/std/math.zig+12-18| ... | @@ -1141,13 +1141,11 @@ test isPowerOfTwo { | ... | @@ -1141,13 +1141,11 @@ test isPowerOfTwo { |
| 1141 | pub fn ByteAlignedInt(comptime T: type) type { | 1141 | pub fn ByteAlignedInt(comptime T: type) type { |
| 1142 | const info = @typeInfo(T).int; | 1142 | const info = @typeInfo(T).int; |
| 1143 | const bits = (info.bits + 7) / 8 * 8; | 1143 | const bits = (info.bits + 7) / 8 * 8; |
| 1144 | const extended_type = std.meta.Int(info.signedness, bits); | 1144 | return @Int(info.signedness, bits); |
| 1145 | return extended_type; | ||
| 1146 | } | 1145 | } |
| 1147 | 1146 | ||
| 1148 | test ByteAlignedInt { | 1147 | test ByteAlignedInt { |
| 1149 | try testing.expect(ByteAlignedInt(u0) == u0); | 1148 | try testing.expect(ByteAlignedInt(u0) == u0); |
| 1150 | try testing.expect(ByteAlignedInt(i0) == i0); | ||
| 1151 | try testing.expect(ByteAlignedInt(u3) == u8); | 1149 | try testing.expect(ByteAlignedInt(u3) == u8); |
| 1152 | try testing.expect(ByteAlignedInt(u8) == u8); | 1150 | try testing.expect(ByteAlignedInt(u8) == u8); |
| 1153 | try testing.expect(ByteAlignedInt(i111) == i112); | 1151 | try testing.expect(ByteAlignedInt(i111) == i112); |
| ... | @@ -1218,7 +1216,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo( | ... | @@ -1218,7 +1216,7 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo( |
| 1218 | comptime assert(@typeInfo(T) == .int); | 1216 | comptime assert(@typeInfo(T) == .int); |
| 1219 | comptime assert(@typeInfo(T).int.signedness == .unsigned); | 1217 | comptime assert(@typeInfo(T).int.signedness == .unsigned); |
| 1220 | assert(value != 0); | 1218 | assert(value != 0); |
| 1221 | const PromotedType = std.meta.Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1); | 1219 | const PromotedType = @Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1); |
| 1222 | const ShiftType = std.math.Log2Int(PromotedType); | 1220 | const ShiftType = std.math.Log2Int(PromotedType); |
| 1223 | return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).int.bits - @clz(value - 1))); | 1221 | return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).int.bits - @clz(value - 1))); |
| 1224 | } | 1222 | } |
| ... | @@ -1230,7 +1228,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { | ... | @@ -1230,7 +1228,7 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { |
| 1230 | comptime assert(@typeInfo(T) == .int); | 1228 | comptime assert(@typeInfo(T) == .int); |
| 1231 | const info = @typeInfo(T).int; | 1229 | const info = @typeInfo(T).int; |
| 1232 | comptime assert(info.signedness == .unsigned); | 1230 | comptime assert(info.signedness == .unsigned); |
| 1233 | const PromotedType = std.meta.Int(info.signedness, info.bits + 1); | 1231 | const PromotedType = @Int(info.signedness, info.bits + 1); |
| 1234 | const overflowBit = @as(PromotedType, 1) << info.bits; | 1232 | const overflowBit = @as(PromotedType, 1) << info.bits; |
| 1235 | const x = ceilPowerOfTwoPromote(T, value); | 1233 | const x = ceilPowerOfTwoPromote(T, value); |
| 1236 | if (overflowBit & x != 0) { | 1234 | if (overflowBit & x != 0) { |
| ... | @@ -1442,19 +1440,17 @@ test lerp { | ... | @@ -1442,19 +1440,17 @@ test lerp { |
| 1442 | 1440 | ||
| 1443 | /// Returns the maximum value of integer type T. | 1441 | /// Returns the maximum value of integer type T. |
| 1444 | pub fn maxInt(comptime T: type) comptime_int { | 1442 | pub fn maxInt(comptime T: type) comptime_int { |
| 1445 | const info = @typeInfo(T); | 1443 | const info = @typeInfo(T).int; |
| 1446 | const bit_count = info.int.bits; | 1444 | return (1 << (info.bits - @intFromBool(info.signedness == .signed))) - 1; |
| 1447 | if (bit_count == 0) return 0; | ||
| 1448 | return (1 << (bit_count - @intFromBool(info.int.signedness == .signed))) - 1; | ||
| 1449 | } | 1445 | } |
| 1450 | 1446 | ||
| 1451 | /// Returns the minimum value of integer type T. | 1447 | /// Returns the minimum value of integer type T. |
| 1452 | pub fn minInt(comptime T: type) comptime_int { | 1448 | pub fn minInt(comptime T: type) comptime_int { |
| 1453 | const info = @typeInfo(T); | 1449 | const info = @typeInfo(T).int; |
| 1454 | const bit_count = info.int.bits; | 1450 | return switch (info.signedness) { |
| 1455 | if (info.int.signedness == .unsigned) return 0; | 1451 | .unsigned => 0, |
| 1456 | if (bit_count == 0) return 0; | 1452 | .signed => -(1 << (info.bits - 1)), |
| 1457 | return -(1 << (bit_count - 1)); | 1453 | }; |
| 1458 | } | 1454 | } |
| 1459 | 1455 | ||
| 1460 | test maxInt { | 1456 | test maxInt { |
| ... | @@ -1466,7 +1462,6 @@ test maxInt { | ... | @@ -1466,7 +1462,6 @@ test maxInt { |
| 1466 | try testing.expect(maxInt(u64) == 18446744073709551615); | 1462 | try testing.expect(maxInt(u64) == 18446744073709551615); |
| 1467 | try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455); | 1463 | try testing.expect(maxInt(u128) == 340282366920938463463374607431768211455); |
| 1468 | 1464 | ||
| 1469 | try testing.expect(maxInt(i0) == 0); | ||
| 1470 | try testing.expect(maxInt(i1) == 0); | 1465 | try testing.expect(maxInt(i1) == 0); |
| 1471 | try testing.expect(maxInt(i8) == 127); | 1466 | try testing.expect(maxInt(i8) == 127); |
| 1472 | try testing.expect(maxInt(i16) == 32767); | 1467 | try testing.expect(maxInt(i16) == 32767); |
| ... | @@ -1486,7 +1481,6 @@ test minInt { | ... | @@ -1486,7 +1481,6 @@ test minInt { |
| 1486 | try testing.expect(minInt(u64) == 0); | 1481 | try testing.expect(minInt(u64) == 0); |
| 1487 | try testing.expect(minInt(u128) == 0); | 1482 | try testing.expect(minInt(u128) == 0); |
| 1488 | 1483 | ||
| 1489 | try testing.expect(minInt(i0) == 0); | ||
| 1490 | try testing.expect(minInt(i1) == -1); | 1484 | try testing.expect(minInt(i1) == -1); |
| 1491 | try testing.expect(minInt(i8) == -128); | 1485 | try testing.expect(minInt(i8) == -128); |
| 1492 | try testing.expect(minInt(i16) == -32768); | 1486 | try testing.expect(minInt(i16) == -32768); |
| ... | @@ -1710,8 +1704,8 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt { | ... | @@ -1710,8 +1704,8 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt { |
| 1710 | if (@typeInfo(MaskInt) != .int) | 1704 | if (@typeInfo(MaskInt) != .int) |
| 1711 | @compileError("boolMask requires an integer mask type."); | 1705 | @compileError("boolMask requires an integer mask type."); |
| 1712 | 1706 | ||
| 1713 | if (MaskInt == u0 or MaskInt == i0) | 1707 | if (MaskInt == u0) |
| 1714 | @compileError("boolMask cannot convert to u0 or i0, they are too small."); | 1708 | @compileError("boolMask cannot convert to u0, it is too small."); |
| 1715 | 1709 | ||
| 1716 | // The u1 and i1 cases tend to overflow, | 1710 | // The u1 and i1 cases tend to overflow, |
| 1717 | // so we special case them here. | 1711 | // so we special case them here. |
lib/std/math/big/int.zig+3-3| ... | @@ -29,8 +29,8 @@ const Constants = struct { | ... | @@ -29,8 +29,8 @@ const Constants = struct { |
| 29 | }; | 29 | }; |
| 30 | const constants: Constants = blk: { | 30 | const constants: Constants = blk: { |
| 31 | @setEvalBranchQuota(2000); | 31 | @setEvalBranchQuota(2000); |
| 32 | var digits_per_limb = [_]u8{0} ** 37; | 32 | var digits_per_limb: [37]u8 = @splat(0); |
| 33 | var bases = [_]Limb{0} ** 37; | 33 | var bases: [37]Limb = @splat(0); |
| 34 | for (2..37) |base| { | 34 | for (2..37) |base| { |
| 35 | digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb))); | 35 | digits_per_limb[base] = @intCast(math.log(Limb, base, math.maxInt(Limb))); |
| 36 | bases[base] = std.math.pow(Limb, base, digits_per_limb[base]); | 36 | bases[base] = std.math.pow(Limb, base, digits_per_limb[base]); |
| ... | @@ -2391,7 +2391,7 @@ pub const Const = struct { | ... | @@ -2391,7 +2391,7 @@ pub const Const = struct { |
| 2391 | var limbs: [calcToStringLimbsBufferLen(available_len, 10)]Limb = undefined; | 2391 | var limbs: [calcToStringLimbsBufferLen(available_len, 10)]Limb = undefined; |
| 2392 | 2392 | ||
| 2393 | const biggest: Const = .{ | 2393 | const biggest: Const = .{ |
| 2394 | .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len), | 2394 | .limbs = &@as([available_len]Limb, @splat(comptime math.maxInt(Limb))), |
| 2395 | .positive = false, | 2395 | .positive = false, |
| 2396 | }; | 2396 | }; |
| 2397 | var buf: [biggest.sizeInBaseUpperBound(2)]u8 = undefined; | 2397 | var buf: [biggest.sizeInBaseUpperBound(2)]u8 = undefined; |
lib/std/math/big/int_test.zig+13-16| ... | @@ -602,7 +602,6 @@ test "bitcount/to" { | ... | @@ -602,7 +602,6 @@ test "bitcount/to" { |
| 602 | try testing.expectEqual(0, a.bitCountTwosComp()); | 602 | try testing.expectEqual(0, a.bitCountTwosComp()); |
| 603 | 603 | ||
| 604 | try testing.expectEqual(0, try a.toInt(u0)); | 604 | try testing.expectEqual(0, try a.toInt(u0)); |
| 605 | try testing.expectEqual(0, try a.toInt(i0)); | ||
| 606 | 605 | ||
| 607 | try a.set(-1); | 606 | try a.set(-1); |
| 608 | try testing.expectEqual(1, a.bitCountTwosComp()); | 607 | try testing.expectEqual(1, a.bitCountTwosComp()); |
| ... | @@ -631,7 +630,6 @@ test "fits" { | ... | @@ -631,7 +630,6 @@ test "fits" { |
| 631 | 630 | ||
| 632 | try a.set(0); | 631 | try a.set(0); |
| 633 | try testing.expect(a.fits(u0)); | 632 | try testing.expect(a.fits(u0)); |
| 634 | try testing.expect(a.fits(i0)); | ||
| 635 | 633 | ||
| 636 | try a.set(255); | 634 | try a.set(255); |
| 637 | try testing.expect(!a.fits(u0)); | 635 | try testing.expect(!a.fits(u0)); |
| ... | @@ -711,7 +709,6 @@ test "twos complement limit set" { | ... | @@ -711,7 +709,6 @@ test "twos complement limit set" { |
| 711 | try testTwosComplementLimit(u1); | 709 | try testTwosComplementLimit(u1); |
| 712 | try testTwosComplementLimit(i1); | 710 | try testTwosComplementLimit(i1); |
| 713 | try testTwosComplementLimit(u0); | 711 | try testTwosComplementLimit(u0); |
| 714 | try testTwosComplementLimit(i0); | ||
| 715 | try testTwosComplementLimit(u65); | 712 | try testTwosComplementLimit(u65); |
| 716 | try testTwosComplementLimit(i65); | 713 | try testTwosComplementLimit(i65); |
| 717 | } | 714 | } |
| ... | @@ -3354,7 +3351,7 @@ test "big int popcount" { | ... | @@ -3354,7 +3351,7 @@ test "big int popcount" { |
| 3354 | try popCountTest(&a, limb_bits * 2 + 1, limb_bits * 2 + 1); | 3351 | try popCountTest(&a, limb_bits * 2 + 1, limb_bits * 2 + 1); |
| 3355 | 3352 | ||
| 3356 | // Check very large numbers. | 3353 | // Check very large numbers. |
| 3357 | try a.setString(16, "ff00000100000100" ++ ("0000000000000000" ** 62)); | 3354 | try a.setString(16, "ff00000100000100" ++ &@as([16 * 62]u8, @splat('0'))); |
| 3358 | try popCountTest(&a, 4032, 10); | 3355 | try popCountTest(&a, 4032, 10); |
| 3359 | try popCountTest(&a, 6000, 10); | 3356 | try popCountTest(&a, 6000, 10); |
| 3360 | a.negate(); | 3357 | a.negate(); |
| ... | @@ -3462,13 +3459,13 @@ test "big int write twos complement +/- zero" { | ... | @@ -3462,13 +3459,13 @@ test "big int write twos complement +/- zero" { |
| 3462 | // Test zero | 3459 | // Test zero |
| 3463 | 3460 | ||
| 3464 | m.toConst().writeTwosComplement(buffer1[0..13], .little); | 3461 | m.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 3465 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3462 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3466 | m.toConst().writeTwosComplement(buffer1[0..13], .big); | 3463 | m.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 3467 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3464 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3468 | m.toConst().writeTwosComplement(buffer1[0..16], .little); | 3465 | m.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 3469 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3466 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3470 | m.toConst().writeTwosComplement(buffer1[0..16], .big); | 3467 | m.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 3471 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3468 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3472 | 3469 | ||
| 3473 | @memset(buffer1, 0xaa); | 3470 | @memset(buffer1, 0xaa); |
| 3474 | m.positive = false; | 3471 | m.positive = false; |
| ... | @@ -3476,13 +3473,13 @@ test "big int write twos complement +/- zero" { | ... | @@ -3476,13 +3473,13 @@ test "big int write twos complement +/- zero" { |
| 3476 | // Test negative zero | 3473 | // Test negative zero |
| 3477 | 3474 | ||
| 3478 | m.toConst().writeTwosComplement(buffer1[0..13], .little); | 3475 | m.toConst().writeTwosComplement(buffer1[0..13], .little); |
| 3479 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3476 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3480 | m.toConst().writeTwosComplement(buffer1[0..13], .big); | 3477 | m.toConst().writeTwosComplement(buffer1[0..13], .big); |
| 3481 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 13) ++ ([_]u8{0xaa} ** 3)), buffer1); | 3478 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xAA, 0xAA, 0xAA }, buffer1); |
| 3482 | m.toConst().writeTwosComplement(buffer1[0..16], .little); | 3479 | m.toConst().writeTwosComplement(buffer1[0..16], .little); |
| 3483 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3480 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3484 | m.toConst().writeTwosComplement(buffer1[0..16], .big); | 3481 | m.toConst().writeTwosComplement(buffer1[0..16], .big); |
| 3485 | try testing.expectEqualSlices(u8, &(([_]u8{0} ** 16)), buffer1); | 3482 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, buffer1); |
| 3486 | } | 3483 | } |
| 3487 | 3484 | ||
| 3488 | test "big int conversion write twos complement with padding" { | 3485 | test "big int conversion write twos complement with padding" { |
| ... | @@ -3559,7 +3556,7 @@ test "big int conversion write twos complement with padding" { | ... | @@ -3559,7 +3556,7 @@ test "big int conversion write twos complement with padding" { |
| 3559 | 3556 | ||
| 3560 | // Test 0 | 3557 | // Test 0 |
| 3561 | 3558 | ||
| 3562 | buffer = &([_]u8{0} ** 16); | 3559 | buffer = &@as([16]u8, @splat(0)); |
| 3563 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); | 3560 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 3564 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3561 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3565 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); | 3562 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| ... | @@ -3570,7 +3567,7 @@ test "big int conversion write twos complement with padding" { | ... | @@ -3570,7 +3567,7 @@ test "big int conversion write twos complement with padding" { |
| 3570 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3567 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3571 | 3568 | ||
| 3572 | bit_count = 0; | 3569 | bit_count = 0; |
| 3573 | buffer = &([_]u8{0xaa} ** 16); | 3570 | buffer = &@as([16]u8, @splat(0xaa)); |
| 3574 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); | 3571 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 3575 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3572 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3576 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); | 3573 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| ... | @@ -3595,13 +3592,13 @@ test "big int conversion write twos complement zero" { | ... | @@ -3595,13 +3592,13 @@ test "big int conversion write twos complement zero" { |
| 3595 | const bit_count: usize = 12 * 8 + 1; | 3592 | const bit_count: usize = 12 * 8 + 1; |
| 3596 | var buffer: []const u8 = undefined; | 3593 | var buffer: []const u8 = undefined; |
| 3597 | 3594 | ||
| 3598 | buffer = &([_]u8{0} ** 13); | 3595 | buffer = &@as([13]u8, @splat(0)); |
| 3599 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); | 3596 | m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned); |
| 3600 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3597 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3601 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); | 3598 | m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned); |
| 3602 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3599 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3603 | 3600 | ||
| 3604 | buffer = &([_]u8{0} ** 16); | 3601 | buffer = &@as([16]u8, @splat(0)); |
| 3605 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); | 3602 | m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned); |
| 3606 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); | 3603 | try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0)); |
| 3607 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); | 3604 | m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned); |
lib/std/math/nextafter.zig+1-2| ... | @@ -23,7 +23,7 @@ pub fn nextAfter(comptime T: type, x: T, y: T) T { | ... | @@ -23,7 +23,7 @@ pub fn nextAfter(comptime T: type, x: T, y: T) T { |
| 23 | fn nextAfterInt(comptime T: type, x: T, y: T) T { | 23 | fn nextAfterInt(comptime T: type, x: T, y: T) T { |
| 24 | comptime assert(@typeInfo(T) == .int or @typeInfo(T) == .comptime_int); | 24 | comptime assert(@typeInfo(T) == .int or @typeInfo(T) == .comptime_int); |
| 25 | return if (@typeInfo(T) == .int and @bitSizeOf(T) < 2) | 25 | return if (@typeInfo(T) == .int and @bitSizeOf(T) < 2) |
| 26 | // Special case for `i0`, `u0`, `i1`, and `u1`. | 26 | // Special case for `u0`, `i1`, and `u1`. |
| 27 | y | 27 | y |
| 28 | else if (y > x) | 28 | else if (y > x) |
| 29 | x + 1 | 29 | x + 1 |
| ... | @@ -102,7 +102,6 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T { | ... | @@ -102,7 +102,6 @@ fn nextAfterFloat(comptime T: type, x: T, y: T) T { |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | test "int" { | 104 | test "int" { |
| 105 | try expect(nextAfter(i0, 0, 0) == 0); | ||
| 106 | try expect(nextAfter(u0, 0, 0) == 0); | 105 | try expect(nextAfter(u0, 0, 0) == 0); |
| 107 | try expect(nextAfter(i1, 0, 0) == 0); | 106 | try expect(nextAfter(i1, 0, 0) == 0); |
| 108 | try expect(nextAfter(i1, 0, -1) == -1); | 107 | try expect(nextAfter(i1, 0, -1) == -1); |
lib/std/math/powi.zig+2-3| ... | @@ -15,12 +15,12 @@ const testing = std.testing; | ... | @@ -15,12 +15,12 @@ const testing = std.testing; |
| 15 | /// - Underflow: Absolute value of result smaller than 1 | 15 | /// - Underflow: Absolute value of result smaller than 1 |
| 16 | /// | 16 | /// |
| 17 | /// Edge case rules ordered by precedence: | 17 | /// Edge case rules ordered by precedence: |
| 18 | /// - powi(T, x, 0) = 1 unless T is i1, i0, u0 | 18 | /// - powi(T, x, 0) = 1 unless T is i1, u0 |
| 19 | /// - powi(T, 0, x) = 0 when x > 0 | 19 | /// - powi(T, 0, x) = 0 when x > 0 |
| 20 | /// - powi(T, 0, x) = Overflow | 20 | /// - powi(T, 0, x) = Overflow |
| 21 | /// - powi(T, 1, y) = 1 | 21 | /// - powi(T, 1, y) = 1 |
| 22 | /// - powi(T, -1, y) = -1 for y an odd integer | 22 | /// - powi(T, -1, y) = -1 for y an odd integer |
| 23 | /// - powi(T, -1, y) = 1 unless T is i1, i0, u0 | 23 | /// - powi(T, -1, y) = 1 unless T is i1, u0 |
| 24 | /// - powi(T, -1, y) = Overflow | 24 | /// - powi(T, -1, y) = Overflow |
| 25 | /// - powi(T, x, y) = Overflow when y >= @bitSizeOf(x) | 25 | /// - powi(T, x, y) = Overflow when y >= @bitSizeOf(x) |
| 26 | /// - powi(T, x, y) = Underflow when y < 0 | 26 | /// - powi(T, x, y) = Underflow when y < 0 |
| ... | @@ -189,7 +189,6 @@ test "powi.special" { | ... | @@ -189,7 +189,6 @@ test "powi.special" { |
| 189 | 189 | ||
| 190 | test "powi.narrow" { | 190 | test "powi.narrow" { |
| 191 | try testing.expectError(error.Overflow, powi(u0, 0, 0)); | 191 | try testing.expectError(error.Overflow, powi(u0, 0, 0)); |
| 192 | try testing.expectError(error.Overflow, powi(i0, 0, 0)); | ||
| 193 | try testing.expectError(error.Overflow, powi(i1, 0, 0)); | 192 | try testing.expectError(error.Overflow, powi(i1, 0, 0)); |
| 194 | try testing.expectError(error.Overflow, powi(i1, -1, 0)); | 193 | try testing.expectError(error.Overflow, powi(i1, -1, 0)); |
| 195 | try testing.expectError(error.Overflow, powi(i1, 0, -1)); | 194 | try testing.expectError(error.Overflow, powi(i1, 0, -1)); |
lib/std/math/signbit.zig-1| ... | @@ -13,7 +13,6 @@ pub fn signbit(x: anytype) bool { | ... | @@ -13,7 +13,6 @@ pub fn signbit(x: anytype) bool { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | test signbit { | 15 | test signbit { |
| 16 | try testInts(i0); | ||
| 17 | try testInts(u0); | 16 | try testInts(u0); |
| 18 | try testInts(i1); | 17 | try testInts(i1); |
| 19 | try testInts(u1); | 18 | try testInts(u1); |
lib/std/mem.zig+9-8| ... | @@ -359,7 +359,10 @@ test zeroes { | ... | @@ -359,7 +359,10 @@ test zeroes { |
| 359 | var a = zeroes(C_struct); | 359 | var a = zeroes(C_struct); |
| 360 | 360 | ||
| 361 | // Extern structs should have padding zeroed out. | 361 | // Extern structs should have padding zeroed out. |
| 362 | try testing.expectEqualSlices(u8, &[_]u8{0} ** @sizeOf(@TypeOf(a)), asBytes(&a)); | 362 | { |
| 363 | const num_bytes = @sizeOf(@TypeOf(a)); | ||
| 364 | try testing.expectEqualSlices(u8, &@as([num_bytes]u8, @splat(0)), @ptrCast(&a)); | ||
| 365 | } | ||
| 363 | 366 | ||
| 364 | a.y += 10; | 367 | a.y += 10; |
| 365 | 368 | ||
| ... | @@ -370,7 +373,6 @@ test zeroes { | ... | @@ -370,7 +373,6 @@ test zeroes { |
| 370 | comptime comptime_field: u8 = 5, | 373 | comptime comptime_field: u8 = 5, |
| 371 | 374 | ||
| 372 | integral_types: struct { | 375 | integral_types: struct { |
| 373 | integer_0: i0, | ||
| 374 | integer_8: i8, | 376 | integer_8: i8, |
| 375 | integer_16: i16, | 377 | integer_16: i16, |
| 376 | integer_32: i32, | 378 | integer_32: i32, |
| ... | @@ -405,7 +407,6 @@ test zeroes { | ... | @@ -405,7 +407,6 @@ test zeroes { |
| 405 | 407 | ||
| 406 | const b = zeroes(ZigStruct); | 408 | const b = zeroes(ZigStruct); |
| 407 | try testing.expectEqual(@as(u8, 5), b.comptime_field); | 409 | try testing.expectEqual(@as(u8, 5), b.comptime_field); |
| 408 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_0); | ||
| 409 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8); | 410 | try testing.expectEqual(@as(i8, 0), b.integral_types.integer_8); |
| 410 | try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16); | 411 | try testing.expectEqual(@as(i16, 0), b.integral_types.integer_16); |
| 411 | try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32); | 412 | try testing.expectEqual(@as(i32, 0), b.integral_types.integer_32); |
| ... | @@ -1589,7 +1590,7 @@ test find { | ... | @@ -1589,7 +1590,7 @@ test find { |
| 1589 | test "find multibyte" { | 1590 | test "find multibyte" { |
| 1590 | { | 1591 | { |
| 1591 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm | 1592 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm |
| 1592 | const haystack = [1]u16{0} ** 100 ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff }; | 1593 | const haystack = @as([100]u16, @splat(0)) ++ [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff }; |
| 1593 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; | 1594 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; |
| 1594 | try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100); | 1595 | try testing.expectEqual(findPos(u16, &haystack, 0, &needle), 100); |
| 1595 | 1596 | ||
| ... | @@ -1602,7 +1603,7 @@ test "find multibyte" { | ... | @@ -1602,7 +1603,7 @@ test "find multibyte" { |
| 1602 | 1603 | ||
| 1603 | { | 1604 | { |
| 1604 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm | 1605 | // make haystack and needle long enough to trigger Boyer-Moore-Horspool algorithm |
| 1605 | const haystack = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff } ++ [1]u16{0} ** 100; | 1606 | const haystack = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee, 0x00ff } ++ @as([100]u16, @splat(0)); |
| 1606 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; | 1607 | const needle = [_]u16{ 0xbbaa, 0xccbb, 0xddcc, 0xeedd, 0xffee }; |
| 1607 | try testing.expectEqual(lastIndexOf(u16, &haystack, &needle), 0); | 1608 | try testing.expectEqual(lastIndexOf(u16, &haystack, &needle), 0); |
| 1608 | 1609 | ||
| ... | @@ -4647,7 +4648,7 @@ test "sliceAsBytes with sentinel slice" { | ... | @@ -4647,7 +4648,7 @@ test "sliceAsBytes with sentinel slice" { |
| 4647 | } | 4648 | } |
| 4648 | 4649 | ||
| 4649 | test "sliceAsBytes with zero-bit element type" { | 4650 | test "sliceAsBytes with zero-bit element type" { |
| 4650 | const lots_of_nothing = [1]void{{}} ** 10_000; | 4651 | const lots_of_nothing: [10_000]void = @splat({}); |
| 4651 | const bytes = sliceAsBytes(&lots_of_nothing); | 4652 | const bytes = sliceAsBytes(&lots_of_nothing); |
| 4652 | try testing.expect(bytes.len == 0); | 4653 | try testing.expect(bytes.len == 0); |
| 4653 | } | 4654 | } |
| ... | @@ -4865,8 +4866,8 @@ test doNotOptimizeAway { | ... | @@ -4865,8 +4866,8 @@ test doNotOptimizeAway { |
| 4865 | doNotOptimizeAway(@as(u200, 0)); | 4866 | doNotOptimizeAway(@as(u200, 0)); |
| 4866 | doNotOptimizeAway(@as(f32, 0.0)); | 4867 | doNotOptimizeAway(@as(f32, 0.0)); |
| 4867 | doNotOptimizeAway(@as(f64, 0.0)); | 4868 | doNotOptimizeAway(@as(f64, 0.0)); |
| 4868 | doNotOptimizeAway([_]u8{0} ** 4); | 4869 | doNotOptimizeAway(@as([4]u8, @splat(0))); |
| 4869 | doNotOptimizeAway([_]u8{0} ** 100); | 4870 | doNotOptimizeAway(@as([100]u8, @splat(0))); |
| 4870 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); | 4871 | doNotOptimizeAway(@as(std.builtin.Endian, .little)); |
| 4871 | } | 4872 | } |
| 4872 | 4873 |
lib/std/meta.zig+1-1| ... | @@ -1067,7 +1067,7 @@ test hasUniqueRepresentation { | ... | @@ -1067,7 +1067,7 @@ test hasUniqueRepresentation { |
| 1067 | 1067 | ||
| 1068 | try testing.expect(!hasUniqueRepresentation(TestUnion4)); | 1068 | try testing.expect(!hasUniqueRepresentation(TestUnion4)); |
| 1069 | 1069 | ||
| 1070 | inline for ([_]type{ i0, u8, i16, u32, i64 }) |T| { | 1070 | inline for ([_]type{ u8, i16, u32, i64 }) |T| { |
| 1071 | try testing.expect(hasUniqueRepresentation(T)); | 1071 | try testing.expect(hasUniqueRepresentation(T)); |
| 1072 | try testing.expect(hasUniqueRepresentation(enum(T) { _ })); | 1072 | try testing.expect(hasUniqueRepresentation(enum(T) { _ })); |
| 1073 | } | 1073 | } |
lib/std/os/emscripten.zig+2-2| ... | @@ -373,7 +373,7 @@ pub const rusage = extern struct { | ... | @@ -373,7 +373,7 @@ pub const rusage = extern struct { |
| 373 | nsignals: isize, | 373 | nsignals: isize, |
| 374 | nvcsw: isize, | 374 | nvcsw: isize, |
| 375 | nivcsw: isize, | 375 | nivcsw: isize, |
| 376 | __reserved: [16]isize = [1]isize{0} ** 16, | 376 | __reserved: [16]isize = @splat(0), |
| 377 | 377 | ||
| 378 | pub const SELF = 0; | 378 | pub const SELF = 0; |
| 379 | pub const CHILDREN = -1; | 379 | pub const CHILDREN = -1; |
| ... | @@ -481,7 +481,7 @@ pub const Sigaction = extern struct { | ... | @@ -481,7 +481,7 @@ pub const Sigaction = extern struct { |
| 481 | 481 | ||
| 482 | pub const sigset_t = [1024 / 32]u32; | 482 | pub const sigset_t = [1024 / 32]u32; |
| 483 | pub fn sigemptyset() sigset_t { | 483 | pub fn sigemptyset() sigset_t { |
| 484 | return [_]u32{0} ** @typeInfo(sigset_t).array.len; | 484 | return @splat(0); |
| 485 | } | 485 | } |
| 486 | pub const siginfo_t = extern struct { | 486 | pub const siginfo_t = extern struct { |
| 487 | signo: i32, | 487 | signo: i32, |
lib/std/os/linux.zig+4-4| ... | @@ -2262,12 +2262,12 @@ pub fn sigrtmax() u8 { | ... | @@ -2262,12 +2262,12 @@ pub fn sigrtmax() u8 { |
| 2262 | 2262 | ||
| 2263 | /// Zig's version of sigemptyset. Returns initialized sigset_t. | 2263 | /// Zig's version of sigemptyset. Returns initialized sigset_t. |
| 2264 | pub fn sigemptyset() sigset_t { | 2264 | pub fn sigemptyset() sigset_t { |
| 2265 | return [_]SigsetElement{0} ** sigset_len; | 2265 | return @splat(0); |
| 2266 | } | 2266 | } |
| 2267 | 2267 | ||
| 2268 | /// Zig's version of sigfillset. Returns initalized sigset_t. | 2268 | /// Zig's version of sigfillset. Returns initalized sigset_t. |
| 2269 | pub fn sigfillset() sigset_t { | 2269 | pub fn sigfillset() sigset_t { |
| 2270 | return [_]SigsetElement{~@as(SigsetElement, 0)} ** sigset_len; | 2270 | return @splat(~@as(SigsetElement, 0)); |
| 2271 | } | 2271 | } |
| 2272 | 2272 | ||
| 2273 | fn sigset_bit_index(sig: SIG) struct { word: usize, mask: SigsetElement } { | 2273 | fn sigset_bit_index(sig: SIG) struct { word: usize, mask: SigsetElement } { |
| ... | @@ -6129,7 +6129,7 @@ pub const sockaddr = extern struct { | ... | @@ -6129,7 +6129,7 @@ pub const sockaddr = extern struct { |
| 6129 | flags: u8, | 6129 | flags: u8, |
| 6130 | 6130 | ||
| 6131 | /// The total size of this structure should be exactly the same as that of struct sockaddr. | 6131 | /// The total size of this structure should be exactly the same as that of struct sockaddr. |
| 6132 | zero: [3]u8 = [_]u8{0} ** 3, | 6132 | zero: [3]u8 = @splat(0), |
| 6133 | comptime { | 6133 | comptime { |
| 6134 | std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr)); | 6134 | std.debug.assert(@sizeOf(vm) == @sizeOf(sockaddr)); |
| 6135 | } | 6135 | } |
| ... | @@ -7475,7 +7475,7 @@ pub const rusage = extern struct { | ... | @@ -7475,7 +7475,7 @@ pub const rusage = extern struct { |
| 7475 | nsignals: isize, | 7475 | nsignals: isize, |
| 7476 | nvcsw: isize, | 7476 | nvcsw: isize, |
| 7477 | nivcsw: isize, | 7477 | nivcsw: isize, |
| 7478 | __reserved: [16]isize = [1]isize{0} ** 16, | 7478 | __reserved: [16]isize = @splat(0), |
| 7479 | 7479 | ||
| 7480 | pub const SELF = 0; | 7480 | pub const SELF = 0; |
| 7481 | pub const CHILDREN = -1; | 7481 | pub const CHILDREN = -1; |
lib/std/os/linux/IoUring/test.zig+34-30| ... | @@ -115,12 +115,12 @@ test "readv" { | ... | @@ -115,12 +115,12 @@ test "readv" { |
| 115 | // https://github.com/torvalds/linux/blob/v5.4/fs/io_uring.c#L3119-L3124 vs | 115 | // https://github.com/torvalds/linux/blob/v5.4/fs/io_uring.c#L3119-L3124 vs |
| 116 | // https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L6687-L6691 | 116 | // https://github.com/torvalds/linux/blob/v5.8/fs/io_uring.c#L6687-L6691 |
| 117 | // We therefore avoid stressing sparse fd sets here: | 117 | // We therefore avoid stressing sparse fd sets here: |
| 118 | var registered_fds = [_]linux.fd_t{0} ** 1; | 118 | var registered_fds: [1]linux.fd_t = .{0}; |
| 119 | const fd_index = 0; | 119 | const fd_index = 0; |
| 120 | registered_fds[fd_index] = file.handle; | 120 | registered_fds[fd_index] = file.handle; |
| 121 | try ring.register_files(registered_fds[0..]); | 121 | try ring.register_files(registered_fds[0..]); |
| 122 | 122 | ||
| 123 | var buffer = [_]u8{42} ** 128; | 123 | var buffer: [128]u8 = @splat(42); |
| 124 | var iovecs = [_]iovec{iovec{ .base = &buffer, .len = buffer.len }}; | 124 | var iovecs = [_]iovec{iovec{ .base = &buffer, .len = buffer.len }}; |
| 125 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .iovecs = iovecs[0..] }, 0); | 125 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .iovecs = iovecs[0..] }, 0); |
| 126 | try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode); | 126 | try testing.expectEqual(linux.IORING_OP.READV, sqe.opcode); |
| ... | @@ -133,7 +133,7 @@ test "readv" { | ... | @@ -133,7 +133,7 @@ test "readv" { |
| 133 | .res = buffer.len, | 133 | .res = buffer.len, |
| 134 | .flags = 0, | 134 | .flags = 0, |
| 135 | }, try ring.copy_cqe()); | 135 | }, try ring.copy_cqe()); |
| 136 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]); | 136 | try testing.expectEqualSlices(u8, &@as([buffer.len]u8, @splat(0)), buffer[0..]); |
| 137 | 137 | ||
| 138 | try ring.unregister_files(); | 138 | try ring.unregister_files(); |
| 139 | } | 139 | } |
| ... | @@ -156,11 +156,11 @@ test "writev/fsync/readv" { | ... | @@ -156,11 +156,11 @@ test "writev/fsync/readv" { |
| 156 | defer file.close(io); | 156 | defer file.close(io); |
| 157 | const fd = file.handle; | 157 | const fd = file.handle; |
| 158 | 158 | ||
| 159 | const buffer_write = [_]u8{42} ** 128; | 159 | const buffer_write: [128]u8 = @splat(42); |
| 160 | const iovecs_write = [_]iovec_const{ | 160 | const iovecs_write = [_]iovec_const{ |
| 161 | iovec_const{ .base = &buffer_write, .len = buffer_write.len }, | 161 | iovec_const{ .base = &buffer_write, .len = buffer_write.len }, |
| 162 | }; | 162 | }; |
| 163 | var buffer_read = [_]u8{0} ** 128; | 163 | var buffer_read: [128]u8 = @splat(0); |
| 164 | var iovecs_read = [_]iovec{ | 164 | var iovecs_read = [_]iovec{ |
| 165 | iovec{ .base = &buffer_read, .len = buffer_read.len }, | 165 | iovec{ .base = &buffer_read, .len = buffer_read.len }, |
| 166 | }; | 166 | }; |
| ... | @@ -225,8 +225,8 @@ test "write/read" { | ... | @@ -225,8 +225,8 @@ test "write/read" { |
| 225 | defer file.close(io); | 225 | defer file.close(io); |
| 226 | const fd = file.handle; | 226 | const fd = file.handle; |
| 227 | 227 | ||
| 228 | const buffer_write = [_]u8{97} ** 20; | 228 | const buffer_write: [20]u8 = @splat(97); |
| 229 | var buffer_read = [_]u8{98} ** 20; | 229 | var buffer_read: [20]u8 = @splat(98); |
| 230 | const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10); | 230 | const sqe_write = try ring.write(0x11111111, fd, buffer_write[0..], 10); |
| 231 | try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); | 231 | try testing.expectEqual(linux.IORING_OP.WRITE, sqe_write.opcode); |
| 232 | try testing.expectEqual(@as(u64, 10), sqe_write.off); | 232 | try testing.expectEqual(@as(u64, 10), sqe_write.off); |
| ... | @@ -276,8 +276,8 @@ test "splice/read" { | ... | @@ -276,8 +276,8 @@ test "splice/read" { |
| 276 | defer file_dst.close(io); | 276 | defer file_dst.close(io); |
| 277 | const fd_dst = file_dst.handle; | 277 | const fd_dst = file_dst.handle; |
| 278 | 278 | ||
| 279 | const buffer_write = [_]u8{97} ** 20; | 279 | const buffer_write: [20]u8 = @splat(97); |
| 280 | var buffer_read = [_]u8{98} ** 20; | 280 | var buffer_read: [20]u8 = @splat(98); |
| 281 | try file_src.writeStreamingAll(io, &buffer_write); | 281 | try file_src.writeStreamingAll(io, &buffer_write); |
| 282 | 282 | ||
| 283 | const fds = try std.Io.Threaded.pipe2(.{}); | 283 | const fds = try std.Io.Threaded.pipe2(.{}); |
| ... | @@ -542,7 +542,7 @@ test "sendmsg/recvmsg" { | ... | @@ -542,7 +542,7 @@ test "sendmsg/recvmsg" { |
| 542 | const client = try socket(address_server.family, posix.SOCK.DGRAM, 0); | 542 | const client = try socket(address_server.family, posix.SOCK.DGRAM, 0); |
| 543 | defer _ = linux.close(client); | 543 | defer _ = linux.close(client); |
| 544 | 544 | ||
| 545 | const buffer_send = [_]u8{42} ** 128; | 545 | const buffer_send: [128]u8 = @splat(42); |
| 546 | const iovecs_send = [_]iovec_const{ | 546 | const iovecs_send = [_]iovec_const{ |
| 547 | iovec_const{ .base = &buffer_send, .len = buffer_send.len }, | 547 | iovec_const{ .base = &buffer_send, .len = buffer_send.len }, |
| 548 | }; | 548 | }; |
| ... | @@ -560,7 +560,7 @@ test "sendmsg/recvmsg" { | ... | @@ -560,7 +560,7 @@ test "sendmsg/recvmsg" { |
| 560 | try testing.expectEqual(linux.IORING_OP.SENDMSG, sqe_sendmsg.opcode); | 560 | try testing.expectEqual(linux.IORING_OP.SENDMSG, sqe_sendmsg.opcode); |
| 561 | try testing.expectEqual(client, sqe_sendmsg.fd); | 561 | try testing.expectEqual(client, sqe_sendmsg.fd); |
| 562 | 562 | ||
| 563 | var buffer_recv = [_]u8{0} ** 128; | 563 | var buffer_recv: [128]u8 = @splat(0); |
| 564 | var iovecs_recv = [_]iovec{ | 564 | var iovecs_recv = [_]iovec{ |
| 565 | iovec{ .base = &buffer_recv, .len = buffer_recv.len }, | 565 | iovec{ .base = &buffer_recv, .len = buffer_recv.len }, |
| 566 | }; | 566 | }; |
| ... | @@ -944,7 +944,7 @@ test "register_files_update" { | ... | @@ -944,7 +944,7 @@ test "register_files_update" { |
| 944 | const file = try Io.Dir.openFileAbsolute(io, "/dev/zero", .{}); | 944 | const file = try Io.Dir.openFileAbsolute(io, "/dev/zero", .{}); |
| 945 | defer file.close(io); | 945 | defer file.close(io); |
| 946 | 946 | ||
| 947 | var registered_fds = [_]linux.fd_t{0} ** 2; | 947 | var registered_fds: [2]linux.fd_t = @splat(0); |
| 948 | const fd_index = 0; | 948 | const fd_index = 0; |
| 949 | const fd_index2 = 1; | 949 | const fd_index2 = 1; |
| 950 | registered_fds[fd_index] = file.handle; | 950 | registered_fds[fd_index] = file.handle; |
| ... | @@ -966,7 +966,7 @@ test "register_files_update" { | ... | @@ -966,7 +966,7 @@ test "register_files_update" { |
| 966 | registered_fds[fd_index2] = -1; | 966 | registered_fds[fd_index2] = -1; |
| 967 | try ring.register_files_update(0, registered_fds[0..]); | 967 | try ring.register_files_update(0, registered_fds[0..]); |
| 968 | 968 | ||
| 969 | var buffer = [_]u8{42} ** 128; | 969 | var buffer: [128]u8 = @splat(42); |
| 970 | { | 970 | { |
| 971 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .buffer = &buffer }, 0); | 971 | const sqe = try ring.read(0xcccccccc, fd_index, .{ .buffer = &buffer }, 0); |
| 972 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); | 972 | try testing.expectEqual(linux.IORING_OP.READ, sqe.opcode); |
| ... | @@ -978,7 +978,7 @@ test "register_files_update" { | ... | @@ -978,7 +978,7 @@ test "register_files_update" { |
| 978 | .res = buffer.len, | 978 | .res = buffer.len, |
| 979 | .flags = 0, | 979 | .flags = 0, |
| 980 | }, try ring.copy_cqe()); | 980 | }, try ring.copy_cqe()); |
| 981 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]); | 981 | try testing.expectEqualSlices(u8, &@as([buffer.len]u8, @splat(0)), buffer[0..]); |
| 982 | } | 982 | } |
| 983 | 983 | ||
| 984 | // Test with a non-zero offset | 984 | // Test with a non-zero offset |
| ... | @@ -999,7 +999,7 @@ test "register_files_update" { | ... | @@ -999,7 +999,7 @@ test "register_files_update" { |
| 999 | .res = buffer.len, | 999 | .res = buffer.len, |
| 1000 | .flags = 0, | 1000 | .flags = 0, |
| 1001 | }, try ring.copy_cqe()); | 1001 | }, try ring.copy_cqe()); |
| 1002 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer.len), buffer[0..]); | 1002 | try testing.expectEqualSlices(u8, &@as([buffer.len]u8, @splat(0)), buffer[0..]); |
| 1003 | } | 1003 | } |
| 1004 | 1004 | ||
| 1005 | try ring.register_files_update(0, registered_fds[0..]); | 1005 | try ring.register_files_update(0, registered_fds[0..]); |
| ... | @@ -1404,7 +1404,7 @@ test "provide_buffers: read" { | ... | @@ -1404,7 +1404,7 @@ test "provide_buffers: read" { |
| 1404 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1404 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1405 | 1405 | ||
| 1406 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); | 1406 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); |
| 1407 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); | 1407 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat(0)), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); |
| 1408 | } | 1408 | } |
| 1409 | 1409 | ||
| 1410 | // This read should fail | 1410 | // This read should fail |
| ... | @@ -1468,7 +1468,7 @@ test "provide_buffers: read" { | ... | @@ -1468,7 +1468,7 @@ test "provide_buffers: read" { |
| 1468 | try testing.expectEqual(used_buffer_id, reprovided_buffer_id); | 1468 | try testing.expectEqual(used_buffer_id, reprovided_buffer_id); |
| 1469 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1469 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1470 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); | 1470 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); |
| 1471 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); | 1471 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat(0)), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); |
| 1472 | } | 1472 | } |
| 1473 | } | 1473 | } |
| 1474 | 1474 | ||
| ... | @@ -1542,7 +1542,7 @@ test "remove_buffers" { | ... | @@ -1542,7 +1542,7 @@ test "remove_buffers" { |
| 1542 | try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4); | 1542 | try testing.expect(used_buffer_id >= 0 and used_buffer_id < 4); |
| 1543 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1543 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1544 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); | 1544 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); |
| 1545 | try testing.expectEqualSlices(u8, &([_]u8{0} ** buffer_len), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); | 1545 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat(0)), buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]); |
| 1546 | } | 1546 | } |
| 1547 | 1547 | ||
| 1548 | // Final read should _not_ work | 1548 | // Final read should _not_ work |
| ... | @@ -1608,7 +1608,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1608,7 +1608,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1608 | { | 1608 | { |
| 1609 | var i: usize = 0; | 1609 | var i: usize = 0; |
| 1610 | while (i < buffers.len) : (i += 1) { | 1610 | while (i < buffers.len) : (i += 1) { |
| 1611 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &([_]u8{'z'} ** buffer_len), 0); | 1611 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &@as([buffer_len]u8, @splat('z')), 0); |
| 1612 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | 1612 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1613 | } | 1613 | } |
| 1614 | 1614 | ||
| ... | @@ -1646,7 +1646,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1646,7 +1646,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1646 | 1646 | ||
| 1647 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); | 1647 | try testing.expectEqual(@as(u64, 0xdededede), cqe.user_data); |
| 1648 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; | 1648 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; |
| 1649 | try testing.expectEqualSlices(u8, &([_]u8{'z'} ** buffer_len), buffer); | 1649 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat('z')), buffer); |
| 1650 | } | 1650 | } |
| 1651 | 1651 | ||
| 1652 | // This recv should fail | 1652 | // This recv should fail |
| ... | @@ -1690,7 +1690,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1690,7 +1690,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1690 | // Redo 1 send on the server socket | 1690 | // Redo 1 send on the server socket |
| 1691 | 1691 | ||
| 1692 | { | 1692 | { |
| 1693 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &([_]u8{'w'} ** buffer_len), 0); | 1693 | _ = try ring.send(0xdeaddead, socket_test_harness.server, &@as([buffer_len]u8, @splat('w')), 0); |
| 1694 | try testing.expectEqual(@as(u32, 1), try ring.submit()); | 1694 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| 1695 | 1695 | ||
| 1696 | _ = try ring.copy_cqe(); | 1696 | _ = try ring.copy_cqe(); |
| ... | @@ -1724,7 +1724,7 @@ test "provide_buffers: accept/connect/send/recv" { | ... | @@ -1724,7 +1724,7 @@ test "provide_buffers: accept/connect/send/recv" { |
| 1724 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); | 1724 | try testing.expectEqual(@as(i32, buffer_len), cqe.res); |
| 1725 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); | 1725 | try testing.expectEqual(@as(u64, 0xdfdfdfdf), cqe.user_data); |
| 1726 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; | 1726 | const buffer = buffers[used_buffer_id][0..@as(usize, @intCast(cqe.res))]; |
| 1727 | try testing.expectEqualSlices(u8, &([_]u8{'w'} ** buffer_len), buffer); | 1727 | try testing.expectEqualSlices(u8, &@as([buffer_len]u8, @splat('w')), buffer); |
| 1728 | } | 1728 | } |
| 1729 | } | 1729 | } |
| 1730 | 1730 | ||
| ... | @@ -1784,8 +1784,8 @@ test "accept/connect/send_zc/recv" { | ... | @@ -1784,8 +1784,8 @@ test "accept/connect/send_zc/recv" { |
| 1784 | const socket_test_harness = try createSocketTestHarness(&ring); | 1784 | const socket_test_harness = try createSocketTestHarness(&ring); |
| 1785 | defer socket_test_harness.close(); | 1785 | defer socket_test_harness.close(); |
| 1786 | 1786 | ||
| 1787 | const buffer_send = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe }; | 1787 | const buffer_send: [15]u8 = .{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe }; |
| 1788 | var buffer_recv = [_]u8{0} ** 10; | 1788 | var buffer_recv: [10]u8 = @splat(0); |
| 1789 | 1789 | ||
| 1790 | // zero-copy send | 1790 | // zero-copy send |
| 1791 | const sqe_send = try ring.send_zc(0xeeeeeeee, socket_test_harness.client, buffer_send[0..], 0, 0); | 1791 | const sqe_send = try ring.send_zc(0xeeeeeeee, socket_test_harness.client, buffer_send[0..], 0, 0); |
| ... | @@ -1844,7 +1844,7 @@ test "accept_direct" { | ... | @@ -1844,7 +1844,7 @@ test "accept_direct" { |
| 1844 | }; | 1844 | }; |
| 1845 | 1845 | ||
| 1846 | // register direct file descriptors | 1846 | // register direct file descriptors |
| 1847 | var registered_fds = [_]linux.fd_t{-1} ** 2; | 1847 | var registered_fds: [2]linux.fd_t = @splat(-1); |
| 1848 | try ring.register_files(registered_fds[0..]); | 1848 | try ring.register_files(registered_fds[0..]); |
| 1849 | 1849 | ||
| 1850 | const listener_socket = try createListenerSocket(&address); | 1850 | const listener_socket = try createListenerSocket(&address); |
| ... | @@ -1856,7 +1856,7 @@ test "accept_direct" { | ... | @@ -1856,7 +1856,7 @@ test "accept_direct" { |
| 1856 | 1856 | ||
| 1857 | for (0..2) |_| { | 1857 | for (0..2) |_| { |
| 1858 | for (registered_fds, 0..) |_, i| { | 1858 | for (registered_fds, 0..) |_, i| { |
| 1859 | var buffer_recv = [_]u8{0} ** 16; | 1859 | var buffer_recv: [16]u8 = @splat(0); |
| 1860 | const buffer_send: []const u8 = data[0 .. data.len - i]; // make it different at each loop | 1860 | const buffer_send: []const u8 = data[0 .. data.len - i]; // make it different at each loop |
| 1861 | 1861 | ||
| 1862 | // submit accept, will chose registered fd and return index in cqe | 1862 | // submit accept, will chose registered fd and return index in cqe |
| ... | @@ -1932,7 +1932,7 @@ test "accept_multishot_direct" { | ... | @@ -1932,7 +1932,7 @@ test "accept_multishot_direct" { |
| 1932 | .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), | 1932 | .addr = @bitCast([4]u8{ 127, 0, 0, 1 }), |
| 1933 | }; | 1933 | }; |
| 1934 | 1934 | ||
| 1935 | var registered_fds = [_]linux.fd_t{-1} ** 2; | 1935 | var registered_fds: [2]linux.fd_t = @splat(-1); |
| 1936 | try ring.register_files(registered_fds[0..]); | 1936 | try ring.register_files(registered_fds[0..]); |
| 1937 | 1937 | ||
| 1938 | const listener_socket = try createListenerSocket(&address); | 1938 | const listener_socket = try createListenerSocket(&address); |
| ... | @@ -2011,7 +2011,7 @@ test "socket_direct/socket_direct_alloc/close_direct" { | ... | @@ -2011,7 +2011,7 @@ test "socket_direct/socket_direct_alloc/close_direct" { |
| 2011 | }; | 2011 | }; |
| 2012 | defer ring.deinit(); | 2012 | defer ring.deinit(); |
| 2013 | 2013 | ||
| 2014 | var registered_fds = [_]linux.fd_t{-1} ** 3; | 2014 | var registered_fds: [3]linux.fd_t = @splat(-1); |
| 2015 | try ring.register_files(registered_fds[0..]); | 2015 | try ring.register_files(registered_fds[0..]); |
| 2016 | 2016 | ||
| 2017 | // create socket in registered file descriptor at index 0 (last param) | 2017 | // create socket in registered file descriptor at index 0 (last param) |
| ... | @@ -2092,7 +2092,7 @@ test "openat_direct/close_direct" { | ... | @@ -2092,7 +2092,7 @@ test "openat_direct/close_direct" { |
| 2092 | }; | 2092 | }; |
| 2093 | defer ring.deinit(); | 2093 | defer ring.deinit(); |
| 2094 | 2094 | ||
| 2095 | var registered_fds = [_]linux.fd_t{-1} ** 3; | 2095 | var registered_fds: [3]linux.fd_t = @splat(-1); |
| 2096 | try ring.register_files(registered_fds[0..]); | 2096 | try ring.register_files(registered_fds[0..]); |
| 2097 | 2097 | ||
| 2098 | var tmp = std.testing.tmpDir(.{}); | 2098 | var tmp = std.testing.tmpDir(.{}); |
| ... | @@ -2562,7 +2562,11 @@ fn expect_buf_grp_cqe( | ... | @@ -2562,7 +2562,11 @@ fn expect_buf_grp_cqe( |
| 2562 | } | 2562 | } |
| 2563 | 2563 | ||
| 2564 | fn testSendRecv(ring: *IoUring, send_fd: posix.socket_t, recv_fd: posix.socket_t) !void { | 2564 | fn testSendRecv(ring: *IoUring, send_fd: posix.socket_t, recv_fd: posix.socket_t) !void { |
| 2565 | const buffer_send = "0123456789abcdf" ** 10; | 2565 | const buffer_send: []const u8 = comptime buf: { |
| 2566 | const part = "0123456789abcdf"; | ||
| 2567 | const repeated: [10][part.len]u8 = @splat(part.*); | ||
| 2568 | break :buf @ptrCast(&repeated); | ||
| 2569 | }; | ||
| 2566 | var buffer_recv: [buffer_send.len * 2]u8 = undefined; | 2570 | var buffer_recv: [buffer_send.len * 2]u8 = undefined; |
| 2567 | 2571 | ||
| 2568 | // 2 sends | 2572 | // 2 sends |
lib/std/os/linux/test.zig+1-1| ... | @@ -70,7 +70,7 @@ test "timer" { | ... | @@ -70,7 +70,7 @@ test "timer" { |
| 70 | try expect(err == .SUCCESS); | 70 | try expect(err == .SUCCESS); |
| 71 | 71 | ||
| 72 | const events_one: linux.epoll_event = undefined; | 72 | const events_one: linux.epoll_event = undefined; |
| 73 | var events = [_]linux.epoll_event{events_one} ** 8; | 73 | var events: [8]linux.epoll_event = @splat(events_one); |
| 74 | 74 | ||
| 75 | err = linux.errno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1)); | 75 | err = linux.errno(linux.epoll_wait(@as(i32, @intCast(epoll_fd)), &events, 8, -1)); |
| 76 | try expect(err == .SUCCESS); | 76 | try expect(err == .SUCCESS); |
lib/std/os/uefi/hii.zig+1-1| ... | @@ -66,7 +66,7 @@ pub const WideGlyph = extern struct { | ... | @@ -66,7 +66,7 @@ pub const WideGlyph = extern struct { |
| 66 | attributes: WideGlyphAttributes, | 66 | attributes: WideGlyphAttributes, |
| 67 | glyph_col_1: [19]u8, | 67 | glyph_col_1: [19]u8, |
| 68 | glyph_col_2: [19]u8, | 68 | glyph_col_2: [19]u8, |
| 69 | _pad: [3]u8 = [_]u8{0} ** 3, | 69 | _pad: [3]u8 = @splat(0), |
| 70 | }; | 70 | }; |
| 71 | 71 | ||
| 72 | pub const StringPackage = extern struct { | 72 | pub const StringPackage = extern struct { |
lib/std/posix/test.zig+2-2| ... | @@ -187,11 +187,11 @@ test "mmap" { | ... | @@ -187,11 +187,11 @@ test "mmap" { |
| 187 | try expectEqual(@as(usize, 1234), data.len); | 187 | try expectEqual(@as(usize, 1234), data.len); |
| 188 | 188 | ||
| 189 | // By definition the data returned by mmap is zero-filled | 189 | // By definition the data returned by mmap is zero-filled |
| 190 | try expect(mem.eql(u8, data, &[_]u8{0x00} ** 1234)); | 190 | try expect(mem.eql(u8, data, &@as([1234]u8, @splat(0x00)))); |
| 191 | 191 | ||
| 192 | // Make sure the memory is writeable as requested | 192 | // Make sure the memory is writeable as requested |
| 193 | @memset(data, 0x55); | 193 | @memset(data, 0x55); |
| 194 | try expect(mem.eql(u8, data, &[_]u8{0x55} ** 1234)); | 194 | try expect(mem.eql(u8, data, &@as([1234]u8, @splat(0x55)))); |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | const test_out_file = "os_tmp_test"; | 197 | const test_out_file = "os_tmp_test"; |
lib/std/tar.zig+8-4| ... | @@ -734,6 +734,10 @@ test PaxIterator { | ... | @@ -734,6 +734,10 @@ test PaxIterator { |
| 734 | value: []const u8 = undefined, | 734 | value: []const u8 = undefined, |
| 735 | err: ?anyerror = null, | 735 | err: ?anyerror = null, |
| 736 | }; | 736 | }; |
| 737 | const long_path: *const [1000]u8 = comptime path: { | ||
| 738 | const buf: [100][10]u8 = @splat("0123456789".*); | ||
| 739 | break :path @ptrCast(&buf); | ||
| 740 | }; | ||
| 737 | const cases = [_]struct { | 741 | const cases = [_]struct { |
| 738 | data: []const u8, | 742 | data: []const u8, |
| 739 | attrs: []const Attr, | 743 | attrs: []const Attr, |
| ... | @@ -816,9 +820,9 @@ test PaxIterator { | ... | @@ -816,9 +820,9 @@ test PaxIterator { |
| 816 | }, | 820 | }, |
| 817 | }, | 821 | }, |
| 818 | .{ // 1000 characters path | 822 | .{ // 1000 characters path |
| 819 | .data = "1011 path=" ++ "0123456789" ** 100 ++ "\n", | 823 | .data = "1011 path=" ++ long_path ++ "\n", |
| 820 | .attrs = &[_]Attr{ | 824 | .attrs = &[_]Attr{ |
| 821 | .{ .kind = .path, .value = "0123456789" ** 100 }, | 825 | .{ .kind = .path, .value = long_path }, |
| 822 | }, | 826 | }, |
| 823 | }, | 827 | }, |
| 824 | }; | 828 | }; |
| ... | @@ -879,7 +883,7 @@ test "header parse size" { | ... | @@ -879,7 +883,7 @@ test "header parse size" { |
| 879 | }; | 883 | }; |
| 880 | 884 | ||
| 881 | for (cases) |case| { | 885 | for (cases) |case| { |
| 882 | var bytes = [_]u8{0} ** Header.SIZE; | 886 | var bytes: [Header.SIZE]u8 = @splat(0); |
| 883 | @memcpy(bytes[124 .. 124 + case.in.len], case.in); | 887 | @memcpy(bytes[124 .. 124 + case.in.len], case.in); |
| 884 | var header = Header{ .bytes = &bytes }; | 888 | var header = Header{ .bytes = &bytes }; |
| 885 | if (case.err) |err| { | 889 | if (case.err) |err| { |
| ... | @@ -904,7 +908,7 @@ test "header parse mode" { | ... | @@ -904,7 +908,7 @@ test "header parse mode" { |
| 904 | .{ .in = "777777777777", .want = 0o77777777 }, | 908 | .{ .in = "777777777777", .want = 0o77777777 }, |
| 905 | }; | 909 | }; |
| 906 | for (cases) |case| { | 910 | for (cases) |case| { |
| 907 | var bytes = [_]u8{0} ** Header.SIZE; | 911 | var bytes: [Header.SIZE]u8 = @splat(0); |
| 908 | @memcpy(bytes[100 .. 100 + case.in.len], case.in); | 912 | @memcpy(bytes[100 .. 100 + case.in.len], case.in); |
| 909 | var header = Header{ .bytes = &bytes }; | 913 | var header = Header{ .bytes = &bytes }; |
| 910 | if (case.err) |err| { | 914 | if (case.err) |err| { |
lib/std/tar/Writer.zig+39-33| ... | @@ -193,23 +193,23 @@ pub const Header = extern struct { | ... | @@ -193,23 +193,23 @@ pub const Header = extern struct { |
| 193 | // numeric field of width w contains w minus 1 digits, and a null. | 193 | // numeric field of width w contains w minus 1 digits, and a null. |
| 194 | // Reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html | 194 | // Reference: https://www.gnu.org/software/tar/manual/html_node/Standard.html |
| 195 | // POSIX header: byte offset | 195 | // POSIX header: byte offset |
| 196 | name: [100]u8 = [_]u8{0} ** 100, // 0 | 196 | name: [100]u8 = @splat(0), // 0 |
| 197 | mode: [7:0]u8 = default_mode.file, // 100 | 197 | mode: [7:0]u8 = default_mode.file, // 100 |
| 198 | uid: [7:0]u8 = [_:0]u8{0} ** 7, // unused 108 | 198 | uid: [7:0]u8 = @splat(0), // unused 108 |
| 199 | gid: [7:0]u8 = [_:0]u8{0} ** 7, // unused 116 | 199 | gid: [7:0]u8 = @splat(0), // unused 116 |
| 200 | size: [11:0]u8 = [_:0]u8{'0'} ** 11, // 124 | 200 | size: [11:0]u8 = @splat('0'), // 124 |
| 201 | mtime: [11:0]u8 = [_:0]u8{'0'} ** 11, // 136 | 201 | mtime: [11:0]u8 = @splat('0'), // 136 |
| 202 | checksum: [7:0]u8 = [_:0]u8{' '} ** 7, // 148 | 202 | checksum: [7:0]u8 = @splat(' '), // 148 |
| 203 | typeflag: FileType = .regular, // 156 | 203 | typeflag: FileType = .regular, // 156 |
| 204 | linkname: [100]u8 = [_]u8{0} ** 100, // 157 | 204 | linkname: [100]u8 = @splat(0), // 157 |
| 205 | magic: [6]u8 = [_]u8{ 'u', 's', 't', 'a', 'r', 0 }, // 257 | 205 | magic: [6]u8 = .{ 'u', 's', 't', 'a', 'r', 0 }, // 257 |
| 206 | version: [2]u8 = [_]u8{ '0', '0' }, // 263 | 206 | version: [2]u8 = .{ '0', '0' }, // 263 |
| 207 | uname: [32]u8 = [_]u8{0} ** 32, // unused 265 | 207 | uname: [32]u8 = @splat(0), // unused 265 |
| 208 | gname: [32]u8 = [_]u8{0} ** 32, // unused 297 | 208 | gname: [32]u8 = @splat(0), // unused 297 |
| 209 | devmajor: [7:0]u8 = [_:0]u8{0} ** 7, // unused 329 | 209 | devmajor: [7:0]u8 = @splat(0), // unused 329 |
| 210 | devminor: [7:0]u8 = [_:0]u8{0} ** 7, // unused 337 | 210 | devminor: [7:0]u8 = @splat(0), // unused 337 |
| 211 | prefix: [155]u8 = [_]u8{0} ** 155, // 345 | 211 | prefix: [155]u8 = @splat(0), // 345 |
| 212 | pad: [12]u8 = [_]u8{0} ** 12, // unused 500 | 212 | pad: [12]u8 = @splat(0), // unused 500 |
| 213 | 213 | ||
| 214 | pub const FileType = enum(u8) { | 214 | pub const FileType = enum(u8) { |
| 215 | regular = '0', | 215 | regular = '0', |
| ... | @@ -342,26 +342,26 @@ pub const Header = extern struct { | ... | @@ -342,26 +342,26 @@ pub const Header = extern struct { |
| 342 | }, | 342 | }, |
| 343 | // no more both fits into name | 343 | // no more both fits into name |
| 344 | .{ | 344 | .{ |
| 345 | .in = &.{ "prefix", "0123456789/" ** 8 ++ "basename" }, | 345 | .in = &.{ "prefix", repeatString(8, "0123456789/") ++ "basename" }, |
| 346 | .out = &.{ "prefix", "0123456789/" ** 8 ++ "basename" }, | 346 | .out = &.{ "prefix", repeatString(8, "0123456789/") ++ "basename" }, |
| 347 | }, | 347 | }, |
| 348 | // put as much as you can into prefix the rest goes into name | 348 | // put as much as you can into prefix the rest goes into name |
| 349 | .{ | 349 | .{ |
| 350 | .in = &.{ "prefix", "0123456789/" ** 10 ++ "basename" }, | 350 | .in = &.{ "prefix", repeatString(10, "0123456789/") ++ "basename" }, |
| 351 | .out = &.{ "prefix/" ++ "0123456789/" ** 9 ++ "0123456789", "basename" }, | 351 | .out = &.{ "prefix/" ++ repeatString(9, "0123456789/") ++ "0123456789", "basename" }, |
| 352 | }, | 352 | }, |
| 353 | 353 | ||
| 354 | .{ | 354 | .{ |
| 355 | .in = &.{ "prefix", "0123456789/" ** 15 ++ "basename" }, | 355 | .in = &.{ "prefix", repeatString(15, "0123456789/") ++ "basename" }, |
| 356 | .out = &.{ "prefix/" ++ "0123456789/" ** 12 ++ "0123456789", "0123456789/0123456789/basename" }, | 356 | .out = &.{ "prefix/" ++ repeatString(12, "0123456789/") ++ "0123456789", "0123456789/0123456789/basename" }, |
| 357 | }, | 357 | }, |
| 358 | .{ | 358 | .{ |
| 359 | .in = &.{ "prefix", "0123456789/" ** 21 ++ "basename" }, | 359 | .in = &.{ "prefix", repeatString(21, "0123456789/") ++ "basename" }, |
| 360 | .out = &.{ "prefix/" ++ "0123456789/" ** 12 ++ "0123456789", "0123456789/" ** 8 ++ "basename" }, | 360 | .out = &.{ "prefix/" ++ repeatString(12, "0123456789/") ++ "0123456789", repeatString(8, "0123456789/") ++ "basename" }, |
| 361 | }, | 361 | }, |
| 362 | .{ | 362 | .{ |
| 363 | .in = &.{ "", "012345678/" ** 10 ++ "foo" }, | 363 | .in = &.{ "", repeatString(10, "012345678/") ++ "foo" }, |
| 364 | .out = &.{ "012345678/" ** 9 ++ "012345678", "foo" }, | 364 | .out = &.{ repeatString(9, "012345678/") ++ "012345678", "foo" }, |
| 365 | }, | 365 | }, |
| 366 | }; | 366 | }; |
| 367 | 367 | ||
| ... | @@ -378,10 +378,10 @@ pub const Header = extern struct { | ... | @@ -378,10 +378,10 @@ pub const Header = extern struct { |
| 378 | // basename can't fit into name (106 characters) | 378 | // basename can't fit into name (106 characters) |
| 379 | .{ .in = &.{ "zig", "test/cases/compile_errors/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig" } }, | 379 | .{ .in = &.{ "zig", "test/cases/compile_errors/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig" } }, |
| 380 | // cant fit into 255 + sep | 380 | // cant fit into 255 + sep |
| 381 | .{ .in = &.{ "prefix", "0123456789/" ** 22 ++ "basename" } }, | 381 | .{ .in = &.{ "prefix", repeatString(22, "0123456789/") ++ "basename" } }, |
| 382 | // can fit but sub_path can't be split (there is no separator) | 382 | // can fit but sub_path can't be split (there is no separator) |
| 383 | .{ .in = &.{ "prefix", "0123456789" ** 10 ++ "a" } }, | 383 | .{ .in = &.{ "prefix", repeatString(10, "0123456789") ++ "a" } }, |
| 384 | .{ .in = &.{ "prefix", "0123456789" ** 14 ++ "basename" } }, | 384 | .{ .in = &.{ "prefix", repeatString(14, "0123456789") ++ "basename" } }, |
| 385 | }; | 385 | }; |
| 386 | 386 | ||
| 387 | for (error_cases) |case| { | 387 | for (error_cases) |case| { |
| ... | @@ -404,11 +404,11 @@ test "write files" { | ... | @@ -404,11 +404,11 @@ test "write files" { |
| 404 | content: []const u8, | 404 | content: []const u8, |
| 405 | }{ | 405 | }{ |
| 406 | .{ .path = "foo", .content = "bar" }, | 406 | .{ .path = "foo", .content = "bar" }, |
| 407 | .{ .path = "a12345678/" ** 10 ++ "foo", .content = "a" ** 511 }, | 407 | .{ .path = repeatString(10, "a12345678/") ++ "foo", .content = repeatString(511, "a") }, |
| 408 | .{ .path = "b12345678/" ** 24 ++ "foo", .content = "b" ** 512 }, | 408 | .{ .path = repeatString(24, "b12345678/") ++ "foo", .content = repeatString(512, "b") }, |
| 409 | .{ .path = "c12345678/" ** 25 ++ "foo", .content = "c" ** 513 }, | 409 | .{ .path = repeatString(25, "c12345678/") ++ "foo", .content = repeatString(513, "c") }, |
| 410 | .{ .path = "d12345678/" ** 51 ++ "foo", .content = "d" ** 1025 }, | 410 | .{ .path = repeatString(51, "d12345678/") ++ "foo", .content = repeatString(1025, "d") }, |
| 411 | .{ .path = "e123456789" ** 11, .content = "e" }, | 411 | .{ .path = repeatString(11, "e123456789"), .content = "e" }, |
| 412 | }; | 412 | }; |
| 413 | 413 | ||
| 414 | var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined; | 414 | var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined; |
| ... | @@ -482,3 +482,9 @@ test "write files" { | ... | @@ -482,3 +482,9 @@ test "write files" { |
| 482 | try w.finishPedantically(); | 482 | try w.finishPedantically(); |
| 483 | } | 483 | } |
| 484 | } | 484 | } |
| 485 | |||
| 486 | /// Marked `inline` to avoid unnecessary binary float, since arguments are always comptime-known. | ||
| 487 | inline fn repeatString(comptime n: usize, comptime str: []const u8) []const u8 { | ||
| 488 | const buf: [n][str.len]u8 = @splat(str[0..str.len].*); | ||
| 489 | return @ptrCast(&buf); | ||
| 490 | } |
lib/std/tar/test.zig+6-2| ... | @@ -53,7 +53,7 @@ const trailing_slash_case: Case = .{ | ... | @@ -53,7 +53,7 @@ const trailing_slash_case: Case = .{ |
| 53 | .data = @embedFile("testdata/trailing-slash.tar"), | 53 | .data = @embedFile("testdata/trailing-slash.tar"), |
| 54 | .files = &[_]Case.File{ | 54 | .files = &[_]Case.File{ |
| 55 | .{ | 55 | .{ |
| 56 | .name = "123456789/" ** 30, | 56 | .name = @ptrCast(&@as([30][10]u8, @splat("123456789/".*))), |
| 57 | .kind = .directory, | 57 | .kind = .directory, |
| 58 | }, | 58 | }, |
| 59 | }, | 59 | }, |
| ... | @@ -64,7 +64,11 @@ const writer_big_long_case: Case = .{ | ... | @@ -64,7 +64,11 @@ const writer_big_long_case: Case = .{ |
| 64 | .data = @embedFile("testdata/writer-big-long.tar"), | 64 | .data = @embedFile("testdata/writer-big-long.tar"), |
| 65 | .files = &[_]Case.File{ | 65 | .files = &[_]Case.File{ |
| 66 | .{ | 66 | .{ |
| 67 | .name = "longname/" ** 15 ++ "16gig.txt", | 67 | .name = name: { |
| 68 | const buf: [15][9]u8 = @splat("longname/".*); | ||
| 69 | const dir: []const u8 = @ptrCast(&buf); | ||
| 70 | break :name dir ++ "16gig.txt"; | ||
| 71 | }, | ||
| 68 | .size = 16 * 1024 * 1024 * 1024, | 72 | .size = 16 * 1024 * 1024 * 1024, |
| 69 | .mode = 0o644, | 73 | .mode = 0o644, |
| 70 | .truncated = true, | 74 | .truncated = true, |
lib/std/unicode.zig+13-8| ... | @@ -275,11 +275,16 @@ fn utf8ValidateSliceImpl(input: []const u8, comptime surrogates: Surrogates) boo | ... | @@ -275,11 +275,16 @@ fn utf8ValidateSliceImpl(input: []const u8, comptime surrogates: Surrogates) boo |
| 275 | const s7 = 0x44; // accept 4, size 4 | 275 | const s7 = 0x44; // accept 4, size 4 |
| 276 | 276 | ||
| 277 | // Information about the first byte in a UTF-8 sequence. | 277 | // Information about the first byte in a UTF-8 sequence. |
| 278 | const first = comptime ([_]u8{as} ** 128) ++ ([_]u8{xx} ** 64) ++ [_]u8{ | 278 | const first = comptime first: { |
| 279 | xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, | 279 | const a: [128]u8 = @splat(as); |
| 280 | s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, | 280 | const b: [64]u8 = @splat(xx); |
| 281 | s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, | 281 | const c: [64]u8 = .{ |
| 282 | s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, | 282 | xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, |
| 283 | s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, | ||
| 284 | s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, | ||
| 285 | s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, | ||
| 286 | }; | ||
| 287 | break :first a ++ b ++ c; | ||
| 283 | }; | 288 | }; |
| 284 | 289 | ||
| 285 | const n = remaining.len; | 290 | const n = remaining.len; |
| ... | @@ -647,7 +652,7 @@ test "validate slice" { | ... | @@ -647,7 +652,7 @@ test "validate slice" { |
| 647 | 652 | ||
| 648 | // We skip a variable (based on recommended vector size) chunks of | 653 | // We skip a variable (based on recommended vector size) chunks of |
| 649 | // ASCII characters. Let's make sure we're chunking correctly. | 654 | // ASCII characters. Let's make sure we're chunking correctly. |
| 650 | const str = [_]u8{'a'} ** 550 ++ "\xc0"; | 655 | const str = @as([550]u8, @splat('a')) ++ "\xc0"; |
| 651 | for (0..str.len - 3) |i| { | 656 | for (0..str.len - 3) |i| { |
| 652 | try testing.expect(!utf8ValidateSlice(str[i..])); | 657 | try testing.expect(!utf8ValidateSlice(str[i..])); |
| 653 | } | 658 | } |
| ... | @@ -1394,7 +1399,7 @@ test "ArrayList functions on a re-used list" { | ... | @@ -1394,7 +1399,7 @@ test "ArrayList functions on a re-used list" { |
| 1394 | fn utf8ToUtf16LeStringLiteralImpl(comptime utf8: []const u8, comptime surrogates: Surrogates) *const [calcUtf16LeLenImpl(utf8, surrogates) catch |err| @compileError(err):0]u16 { | 1399 | fn utf8ToUtf16LeStringLiteralImpl(comptime utf8: []const u8, comptime surrogates: Surrogates) *const [calcUtf16LeLenImpl(utf8, surrogates) catch |err| @compileError(err):0]u16 { |
| 1395 | return comptime blk: { | 1400 | return comptime blk: { |
| 1396 | const len: usize = calcUtf16LeLenImpl(utf8, surrogates) catch unreachable; | 1401 | const len: usize = calcUtf16LeLenImpl(utf8, surrogates) catch unreachable; |
| 1397 | var utf16le: [len:0]u16 = [_:0]u16{0} ** len; | 1402 | var utf16le: [len:0]u16 = @splat(0); |
| 1398 | const utf16le_len = utf8ToUtf16LeImpl(&utf16le, utf8[0..], surrogates) catch |err| @compileError(err); | 1403 | const utf16le_len = utf8ToUtf16LeImpl(&utf16le, utf8[0..], surrogates) catch |err| @compileError(err); |
| 1399 | assert(len == utf16le_len); | 1404 | assert(len == utf16le_len); |
| 1400 | const final = utf16le; | 1405 | const final = utf16le; |
| ... | @@ -1640,7 +1645,7 @@ test "validate WTF-8 slice" { | ... | @@ -1640,7 +1645,7 @@ test "validate WTF-8 slice" { |
| 1640 | 1645 | ||
| 1641 | // We skip a variable (based on recommended vector size) chunks of | 1646 | // We skip a variable (based on recommended vector size) chunks of |
| 1642 | // ASCII characters. Let's make sure we're chunking correctly. | 1647 | // ASCII characters. Let's make sure we're chunking correctly. |
| 1643 | const str = [_]u8{'a'} ** 550 ++ "\xc0"; | 1648 | const str = @as([550]u8, @splat('a')) ++ "\xc0"; |
| 1644 | for (0..str.len - 3) |i| { | 1649 | for (0..str.len - 3) |i| { |
| 1645 | try testing.expect(!wtf8ValidateSlice(str[i..])); | 1650 | try testing.expect(!wtf8ValidateSlice(str[i..])); |
| 1646 | } | 1651 | } |
lib/std/unicode/throughput_test.zig+9-3| ... | @@ -63,21 +63,27 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -63,21 +63,27 @@ pub fn main(init: std.process.Init) !void { |
| 63 | try stdout.print("pure ASCII strings\n", .{}); | 63 | try stdout.print("pure ASCII strings\n", .{}); |
| 64 | try stdout.flush(); | 64 | try stdout.flush(); |
| 65 | { | 65 | { |
| 66 | const result = try benchmarkCodepointCount("hello" ** 16, io); | 66 | const part = "hello"; |
| 67 | const buf: [16][part.len]u8 = @splat(part.*); | ||
| 68 | const result = try benchmarkCodepointCount(@ptrCast(&buf), io); | ||
| 67 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); | 69 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | try stdout.print("pure Unicode strings\n", .{}); | 72 | try stdout.print("pure Unicode strings\n", .{}); |
| 71 | try stdout.flush(); | 73 | try stdout.flush(); |
| 72 | { | 74 | { |
| 73 | const result = try benchmarkCodepointCount("こんにちは" ** 16, io); | 75 | const part = "こんにちは"; |
| 76 | const buf: [16][part.len]u8 = @splat(part.*); | ||
| 77 | const result = try benchmarkCodepointCount(@ptrCast(&buf), io); | ||
| 74 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); | 78 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 75 | } | 79 | } |
| 76 | 80 | ||
| 77 | try stdout.print("mixed ASCII/Unicode strings\n", .{}); | 81 | try stdout.print("mixed ASCII/Unicode strings\n", .{}); |
| 78 | try stdout.flush(); | 82 | try stdout.flush(); |
| 79 | { | 83 | { |
| 80 | const result = try benchmarkCodepointCount("Hyvää huomenta" ** 16, io); | 84 | const part = "Hyvää huomenta"; |
| 85 | const buf: [16][part.len]u8 = @splat(part.*); | ||
| 86 | const result = try benchmarkCodepointCount(@ptrCast(&buf), io); | ||
| 81 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); | 87 | try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count }); |
| 82 | } | 88 | } |
| 83 | try stdout.flush(); | 89 | try stdout.flush(); |
lib/std/zig.zig-2| ... | @@ -811,7 +811,6 @@ pub const SimpleComptimeReason = enum(u32) { | ... | @@ -811,7 +811,6 @@ pub const SimpleComptimeReason = enum(u32) { |
| 811 | compile_error_string, | 811 | compile_error_string, |
| 812 | inline_assembly_code, | 812 | inline_assembly_code, |
| 813 | atomic_order, | 813 | atomic_order, |
| 814 | array_mul_factor, | ||
| 815 | slice_cat_operand, | 814 | slice_cat_operand, |
| 816 | inline_call_target, | 815 | inline_call_target, |
| 817 | generic_call_target, | 816 | generic_call_target, |
| ... | @@ -899,7 +898,6 @@ pub const SimpleComptimeReason = enum(u32) { | ... | @@ -899,7 +898,6 @@ pub const SimpleComptimeReason = enum(u32) { |
| 899 | .compile_error_string => "compile error string must be comptime-known", | 898 | .compile_error_string => "compile error string must be comptime-known", |
| 900 | .inline_assembly_code => "inline assembly code must be comptime-known", | 899 | .inline_assembly_code => "inline assembly code must be comptime-known", |
| 901 | .atomic_order => "atomic order must be comptime-known", | 900 | .atomic_order => "atomic order must be comptime-known", |
| 902 | .array_mul_factor => "array multiplication factor must be comptime-known", | ||
| 903 | .slice_cat_operand => "slice being concatenated must be comptime-known", | 901 | .slice_cat_operand => "slice being concatenated must be comptime-known", |
| 904 | .inline_call_target => "function being called inline must be comptime-known", | 902 | .inline_call_target => "function being called inline must be comptime-known", |
| 905 | .generic_call_target => "generic function being called must be comptime-known", | 903 | .generic_call_target => "generic function being called must be comptime-known", |
lib/std/zig/Ast.zig+5-28| ... | @@ -331,11 +331,6 @@ pub fn rootDecls(tree: Ast) []const Node.Index { | ... | @@ -331,11 +331,6 @@ pub fn rootDecls(tree: Ast) []const Node.Index { |
| 331 | 331 | ||
| 332 | pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void { | 332 | pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void { |
| 333 | switch (parse_error.tag) { | 333 | switch (parse_error.tag) { |
| 334 | .asterisk_after_ptr_deref => { | ||
| 335 | // Note that the token will point at the `.*` but ideally the source | ||
| 336 | // location would point to the `*` after the `.*`. | ||
| 337 | return w.writeAll("'.*' cannot be followed by '*'; are you missing a space?"); | ||
| 338 | }, | ||
| 339 | .chained_comparison_operators => { | 334 | .chained_comparison_operators => { |
| 340 | return w.writeAll("comparison operators cannot be chained"); | 335 | return w.writeAll("comparison operators cannot be chained"); |
| 341 | }, | 336 | }, |
| ... | @@ -687,7 +682,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -687,7 +682,6 @@ pub fn firstToken(tree: Ast, node: Node.Index) TokenIndex { |
| 687 | .mul, | 682 | .mul, |
| 688 | .div, | 683 | .div, |
| 689 | .mod, | 684 | .mod, |
| 690 | .array_mult, | ||
| 691 | .mul_wrap, | 685 | .mul_wrap, |
| 692 | .mul_sat, | 686 | .mul_sat, |
| 693 | .add, | 687 | .add, |
| ... | @@ -924,7 +918,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -924,7 +918,6 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 924 | .mul, | 918 | .mul, |
| 925 | .div, | 919 | .div, |
| 926 | .mod, | 920 | .mod, |
| 927 | .array_mult, | ||
| 928 | .mul_wrap, | 921 | .mul_wrap, |
| 929 | .mul_sat, | 922 | .mul_sat, |
| 930 | .add, | 923 | .add, |
| ... | @@ -952,8 +945,8 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { | ... | @@ -952,8 +945,8 @@ pub fn lastToken(tree: Ast, node: Node.Index) TokenIndex { |
| 952 | .switch_range, | 945 | .switch_range, |
| 953 | => n = tree.nodeData(n).node_and_node[1], | 946 | => n = tree.nodeData(n).node_and_node[1], |
| 954 | 947 | ||
| 955 | .test_decl, .@"errdefer" => n = tree.nodeData(n).opt_token_and_node[1], | 948 | .test_decl => n = tree.nodeData(n).opt_token_and_node[1], |
| 956 | .@"defer" => n = tree.nodeData(n).node, | 949 | .@"defer", .@"errdefer" => n = tree.nodeData(n).node, |
| 957 | .anyframe_type => n = tree.nodeData(n).token_and_node[1], | 950 | .anyframe_type => n = tree.nodeData(n).token_and_node[1], |
| 958 | 951 | ||
| 959 | .switch_case_one, | 952 | .switch_case_one, |
| ... | @@ -2111,9 +2104,7 @@ fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto | ... | @@ -2111,9 +2104,7 @@ fn fullFnProtoComponents(tree: Ast, info: full.FnProto.Components) full.FnProto |
| 2111 | 2104 | ||
| 2112 | fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType { | 2105 | fn fullPtrTypeComponents(tree: Ast, info: full.PtrType.Components) full.PtrType { |
| 2113 | const size: std.builtin.Type.Pointer.Size = switch (tree.tokenTag(info.main_token)) { | 2106 | const size: std.builtin.Type.Pointer.Size = switch (tree.tokenTag(info.main_token)) { |
| 2114 | .asterisk, | 2107 | .asterisk => .one, |
| 2115 | .asterisk_asterisk, | ||
| 2116 | => .one, | ||
| 2117 | .l_bracket => switch (tree.tokenTag(info.main_token + 1)) { | 2108 | .l_bracket => switch (tree.tokenTag(info.main_token + 1)) { |
| 2118 | .asterisk => if (tree.tokenTag(info.main_token + 2) == .identifier) .c else .many, | 2109 | .asterisk => if (tree.tokenTag(info.main_token + 2) == .identifier) .c else .many, |
| 2119 | else => .slice, | 2110 | else => .slice, |
| ... | @@ -2842,7 +2833,6 @@ pub const Error = struct { | ... | @@ -2842,7 +2833,6 @@ pub const Error = struct { |
| 2842 | } = .{ .none = {} }, | 2833 | } = .{ .none = {} }, |
| 2843 | 2834 | ||
| 2844 | pub const Tag = enum { | 2835 | pub const Tag = enum { |
| 2845 | asterisk_after_ptr_deref, | ||
| 2846 | chained_comparison_operators, | 2836 | chained_comparison_operators, |
| 2847 | decl_between_fields, | 2837 | decl_between_fields, |
| 2848 | expected_block, | 2838 | expected_block, |
| ... | @@ -3059,11 +3049,8 @@ pub const Node = struct { | ... | @@ -3059,11 +3049,8 @@ pub const Node = struct { |
| 3059 | /// a `assign_destructure` node or a parsing error occured. | 3049 | /// a `assign_destructure` node or a parsing error occured. |
| 3060 | aligned_var_decl, | 3050 | aligned_var_decl, |
| 3061 | /// `errdefer expr`, | 3051 | /// `errdefer expr`, |
| 3062 | /// `errdefer |payload| expr`. | ||
| 3063 | /// | 3052 | /// |
| 3064 | /// The `data` field is a `.opt_token_and_node`: | 3053 | /// The `data` field is a `.node` to the deferred expression. |
| 3065 | /// 1. a `OptionalTokenIndex` to the payload identifier, if any. | ||
| 3066 | /// 2. a `Node.Index` to the deferred expression. | ||
| 3067 | /// | 3054 | /// |
| 3068 | /// The `main_token` field is the `errdefer` token. | 3055 | /// The `main_token` field is the `errdefer` token. |
| 3069 | @"errdefer", | 3056 | @"errdefer", |
| ... | @@ -3071,7 +3058,7 @@ pub const Node = struct { | ... | @@ -3071,7 +3058,7 @@ pub const Node = struct { |
| 3071 | /// | 3058 | /// |
| 3072 | /// The `data` field is a `.node` to the deferred expression. | 3059 | /// The `data` field is a `.node` to the deferred expression. |
| 3073 | /// | 3060 | /// |
| 3074 | /// The `main_token` field is the `defer`. | 3061 | /// The `main_token` field is the `defer` token. |
| 3075 | @"defer", | 3062 | @"defer", |
| 3076 | /// `lhs catch rhs`, | 3063 | /// `lhs catch rhs`, |
| 3077 | /// `lhs catch |err| rhs`. | 3064 | /// `lhs catch |err| rhs`. |
| ... | @@ -3181,8 +3168,6 @@ pub const Node = struct { | ... | @@ -3181,8 +3168,6 @@ pub const Node = struct { |
| 3181 | div, | 3168 | div, |
| 3182 | /// `lhs % rhs`. The `main_token` field is the `%` token. | 3169 | /// `lhs % rhs`. The `main_token` field is the `%` token. |
| 3183 | mod, | 3170 | mod, |
| 3184 | /// `lhs ** rhs`. The `main_token` field is the `**` token. | ||
| 3185 | array_mult, | ||
| 3186 | /// `lhs *% rhs`. The `main_token` field is the `*%` token. | 3171 | /// `lhs *% rhs`. The `main_token` field is the `*%` token. |
| 3187 | mul_wrap, | 3172 | mul_wrap, |
| 3188 | /// `lhs *| rhs`. The `main_token` field is the `*|` token. | 3173 | /// `lhs *| rhs`. The `main_token` field is the `*|` token. |
| ... | @@ -3253,8 +3238,6 @@ pub const Node = struct { | ... | @@ -3253,8 +3238,6 @@ pub const Node = struct { |
| 3253 | /// | 3238 | /// |
| 3254 | /// The `main_token` is the asterisk if a single item pointer or the | 3239 | /// The `main_token` is the asterisk if a single item pointer or the |
| 3255 | /// lbracket if a slice, many-item pointer, or C-pointer. | 3240 | /// lbracket if a slice, many-item pointer, or C-pointer. |
| 3256 | /// The `main_token` might be a ** token, which is shared with a | ||
| 3257 | /// parent/child pointer type and may require special handling. | ||
| 3258 | ptr_type_aligned, | 3241 | ptr_type_aligned, |
| 3259 | /// `[*:lhs]rhs`, | 3242 | /// `[*:lhs]rhs`, |
| 3260 | /// `*rhs`, | 3243 | /// `*rhs`, |
| ... | @@ -3266,8 +3249,6 @@ pub const Node = struct { | ... | @@ -3266,8 +3249,6 @@ pub const Node = struct { |
| 3266 | /// | 3249 | /// |
| 3267 | /// The `main_token` is the asterisk if a single item pointer or the | 3250 | /// The `main_token` is the asterisk if a single item pointer or the |
| 3268 | /// lbracket if a slice, many-item pointer, or C-pointer. | 3251 | /// lbracket if a slice, many-item pointer, or C-pointer. |
| 3269 | /// The `main_token` might be a ** token, which is shared with a | ||
| 3270 | /// parent/child pointer type and may require special handling. | ||
| 3271 | ptr_type_sentinel, | 3252 | ptr_type_sentinel, |
| 3272 | /// The `data` field is a `.extra_and_node`: | 3253 | /// The `data` field is a `.extra_and_node`: |
| 3273 | /// 1. a `ExtraIndex` to `PtrType`. | 3254 | /// 1. a `ExtraIndex` to `PtrType`. |
| ... | @@ -3275,8 +3256,6 @@ pub const Node = struct { | ... | @@ -3275,8 +3256,6 @@ pub const Node = struct { |
| 3275 | /// | 3256 | /// |
| 3276 | /// The `main_token` is the asterisk if a single item pointer or the | 3257 | /// The `main_token` is the asterisk if a single item pointer or the |
| 3277 | /// lbracket if a slice, many-item pointer, or C-pointer. | 3258 | /// lbracket if a slice, many-item pointer, or C-pointer. |
| 3278 | /// The `main_token` might be a ** token, which is shared with a | ||
| 3279 | /// parent/child pointer type and may require special handling. | ||
| 3280 | ptr_type, | 3259 | ptr_type, |
| 3281 | /// The `data` field is a `.extra_and_node`: | 3260 | /// The `data` field is a `.extra_and_node`: |
| 3282 | /// 1. a `ExtraIndex` to `PtrTypeBitRange`. | 3261 | /// 1. a `ExtraIndex` to `PtrTypeBitRange`. |
| ... | @@ -3284,8 +3263,6 @@ pub const Node = struct { | ... | @@ -3284,8 +3263,6 @@ pub const Node = struct { |
| 3284 | /// | 3263 | /// |
| 3285 | /// The `main_token` is the asterisk if a single item pointer or the | 3264 | /// The `main_token` is the asterisk if a single item pointer or the |
| 3286 | /// lbracket if a slice, many-item pointer, or C-pointer. | 3265 | /// lbracket if a slice, many-item pointer, or C-pointer. |
| 3287 | /// The `main_token` might be a ** token, which is shared with a | ||
| 3288 | /// parent/child pointer type and may require special handling. | ||
| 3289 | ptr_type_bit_range, | 3266 | ptr_type_bit_range, |
| 3290 | /// `lhs[rhs..]` | 3267 | /// `lhs[rhs..]` |
| 3291 | /// | 3268 | /// |
lib/std/zig/Ast/Render.zig+1-25| ... | @@ -394,20 +394,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -394,20 +394,8 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 394 | return renderBlock(r, node, statements, space); | 394 | return renderBlock(r, node, statements, space); |
| 395 | }, | 395 | }, |
| 396 | 396 | ||
| 397 | .@"errdefer" => { | ||
| 398 | const defer_token = tree.nodeMainToken(node); | ||
| 399 | const maybe_payload_token, const expr = tree.nodeData(node).opt_token_and_node; | ||
| 400 | |||
| 401 | try renderToken(r, defer_token, .maybe_space); | ||
| 402 | if (maybe_payload_token.unwrap()) |payload_token| { | ||
| 403 | try renderToken(r, payload_token - 1, .none); // | | ||
| 404 | try renderIdentifier(r, payload_token, .none, .preserve_when_shadowing); // identifier | ||
| 405 | try renderToken(r, payload_token + 1, .maybe_space); // | | ||
| 406 | } | ||
| 407 | return renderExpression(r, expr, space); | ||
| 408 | }, | ||
| 409 | |||
| 410 | .@"defer", | 397 | .@"defer", |
| 398 | .@"errdefer", | ||
| 411 | .@"comptime", | 399 | .@"comptime", |
| 412 | .@"nosuspend", | 400 | .@"nosuspend", |
| 413 | .@"suspend", | 401 | .@"suspend", |
| ... | @@ -520,7 +508,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { | ... | @@ -520,7 +508,6 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void { |
| 520 | .add_wrap, | 508 | .add_wrap, |
| 521 | .add_sat, | 509 | .add_sat, |
| 522 | .array_cat, | 510 | .array_cat, |
| 523 | .array_mult, | ||
| 524 | .bang_equal, | 511 | .bang_equal, |
| 525 | .bit_and, | 512 | .bit_and, |
| 526 | .bit_or, | 513 | .bit_or, |
| ... | @@ -1040,16 +1027,6 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi | ... | @@ -1040,16 +1027,6 @@ fn renderPtrType(r: *Render, ptr_type: Ast.full.PtrType, space: Space) Error!voi |
| 1040 | 1027 | ||
| 1041 | switch (ptr_type.size) { | 1028 | switch (ptr_type.size) { |
| 1042 | .one => { | 1029 | .one => { |
| 1043 | // Since ** tokens exist and the same token is shared by two | ||
| 1044 | // nested pointer types, we check to see if we are the parent | ||
| 1045 | // in such a relationship. If so, skip rendering anything for | ||
| 1046 | // this pointer type and rely on the child to render our asterisk | ||
| 1047 | // as well when it renders the ** token. | ||
| 1048 | if (tree.tokenTag(main_token) == .asterisk_asterisk and | ||
| 1049 | main_token == tree.nodeMainToken(ptr_type.ast.child_type)) | ||
| 1050 | { | ||
| 1051 | return renderExpression(r, ptr_type.ast.child_type, space); | ||
| 1052 | } | ||
| 1053 | try renderToken(r, main_token, .none); // asterisk | 1030 | try renderToken(r, main_token, .none); // asterisk |
| 1054 | }, | 1031 | }, |
| 1055 | .many => { | 1032 | .many => { |
| ... | @@ -3235,7 +3212,6 @@ fn nodeCausesSliceOpSpace(tag: Ast.Node.Tag) bool { | ... | @@ -3235,7 +3212,6 @@ fn nodeCausesSliceOpSpace(tag: Ast.Node.Tag) bool { |
| 3235 | .add, | 3212 | .add, |
| 3236 | .add_wrap, | 3213 | .add_wrap, |
| 3237 | .array_cat, | 3214 | .array_cat, |
| 3238 | .array_mult, | ||
| 3239 | .assign, | 3215 | .assign, |
| 3240 | .assign_bit_and, | 3216 | .assign_bit_and, |
| 3241 | .assign_bit_or, | 3217 | .assign_bit_or, |
lib/std/zig/AstGen.zig+75-184| ... | @@ -507,7 +507,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins | ... | @@ -507,7 +507,6 @@ fn lvalExpr(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Ins |
| 507 | .less_than, | 507 | .less_than, |
| 508 | .less_or_equal, | 508 | .less_or_equal, |
| 509 | .array_cat, | 509 | .array_cat, |
| 510 | .array_mult, | ||
| 511 | .bool_and, | 510 | .bool_and, |
| 512 | .bool_or, | 511 | .bool_or, |
| 513 | .@"asm", | 512 | .@"asm", |
| ... | @@ -777,19 +776,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE | ... | @@ -777,19 +776,6 @@ fn expr(gz: *GenZir, scope: *Scope, ri: ResultInfo, node: Ast.Node.Index) InnerE |
| 777 | .less_or_equal => return simpleBinOp(gz, scope, ri, node, .cmp_lte), | 776 | .less_or_equal => return simpleBinOp(gz, scope, ri, node, .cmp_lte), |
| 778 | .array_cat => return simpleBinOp(gz, scope, ri, node, .array_cat), | 777 | .array_cat => return simpleBinOp(gz, scope, ri, node, .array_cat), |
| 779 | 778 | ||
| 780 | .array_mult => { | ||
| 781 | // This syntax form does not currently use the result type in the language specification. | ||
| 782 | // However, the result type can be used to emit more optimal code for large multiplications by | ||
| 783 | // having Sema perform a coercion before the multiplication operation. | ||
| 784 | const lhs_node, const rhs_node = tree.nodeData(node).node_and_node; | ||
| 785 | const result = try gz.addPlNode(.array_mul, node, Zir.Inst.ArrayMul{ | ||
| 786 | .res_ty = if (try ri.rl.resultType(gz, node)) |t| t else .none, | ||
| 787 | .lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node), | ||
| 788 | .rhs = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, rhs_node, .array_mul_factor), | ||
| 789 | }); | ||
| 790 | return rvalue(gz, ri, result, node); | ||
| 791 | }, | ||
| 792 | |||
| 793 | .error_union, .merge_error_sets => |tag| { | 779 | .error_union, .merge_error_sets => |tag| { |
| 794 | const inst_tag: Zir.Inst.Tag = switch (tag) { | 780 | const inst_tag: Zir.Inst.Tag = switch (tag) { |
| 795 | .error_union => .error_union_type, | 781 | .error_union => .error_union_type, |
| ... | @@ -2713,7 +2699,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As | ... | @@ -2713,7 +2699,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2713 | .alloc_inferred_comptime_mut, | 2699 | .alloc_inferred_comptime_mut, |
| 2714 | .make_ptr_const, | 2700 | .make_ptr_const, |
| 2715 | .array_cat, | 2701 | .array_cat, |
| 2716 | .array_mul, | ||
| 2717 | .array_type, | 2702 | .array_type, |
| 2718 | .array_type_sentinel, | 2703 | .array_type_sentinel, |
| 2719 | .elem_type, | 2704 | .elem_type, |
| ... | @@ -2875,7 +2860,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As | ... | @@ -2875,7 +2860,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2875 | .max, | 2860 | .max, |
| 2876 | .min, | 2861 | .min, |
| 2877 | .@"resume", | 2862 | .@"resume", |
| 2878 | .ret_err_value_code, | ||
| 2879 | .ret_ptr, | 2863 | .ret_ptr, |
| 2880 | .ret_type, | 2864 | .ret_type, |
| 2881 | .for_len, | 2865 | .for_len, |
| ... | @@ -2964,7 +2948,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As | ... | @@ -2964,7 +2948,6 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2964 | => break :b true, | 2948 | => break :b true, |
| 2965 | 2949 | ||
| 2966 | .@"defer" => unreachable, | 2950 | .@"defer" => unreachable, |
| 2967 | .defer_err_code => unreachable, | ||
| 2968 | } | 2951 | } |
| 2969 | } else switch (maybe_unused_result) { | 2952 | } else switch (maybe_unused_result) { |
| 2970 | .none => unreachable, | 2953 | .none => unreachable, |
| ... | @@ -2984,60 +2967,28 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As | ... | @@ -2984,60 +2967,28 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As |
| 2984 | return noreturn_src_node; | 2967 | return noreturn_src_node; |
| 2985 | } | 2968 | } |
| 2986 | 2969 | ||
| 2987 | fn countDefers(outer_scope: *Scope, inner_scope: *Scope) struct { | 2970 | fn anyErrdefers(outer_scope: *Scope, inner_scope: *Scope) bool { |
| 2988 | have_any: bool, | ||
| 2989 | have_normal: bool, | ||
| 2990 | have_err: bool, | ||
| 2991 | need_err_code: bool, | ||
| 2992 | } { | ||
| 2993 | var have_normal = false; | ||
| 2994 | var have_err = false; | ||
| 2995 | var need_err_code = false; | ||
| 2996 | var scope = inner_scope; | 2971 | var scope = inner_scope; |
| 2997 | while (scope != outer_scope) { | 2972 | while (scope != outer_scope) { |
| 2998 | switch (scope.unwrap()) { | 2973 | switch (scope.unwrap()) { |
| 2999 | .gen_zir => |gen_zir| scope = gen_zir.parent, | 2974 | .gen_zir => |gen_zir| scope = gen_zir.parent, |
| 3000 | .local_val => |local_val| scope = local_val.parent, | 2975 | .local_val => |local_val| scope = local_val.parent, |
| 3001 | .local_ptr => |local_ptr| scope = local_ptr.parent, | 2976 | .local_ptr => |local_ptr| scope = local_ptr.parent, |
| 3002 | .defer_normal => |defer_scope| { | 2977 | .defer_normal => |defer_normal| scope = defer_normal.parent, |
| 3003 | scope = defer_scope.parent; | 2978 | .defer_error => return true, |
| 3004 | |||
| 3005 | have_normal = true; | ||
| 3006 | }, | ||
| 3007 | .defer_error => |defer_scope| { | ||
| 3008 | scope = defer_scope.parent; | ||
| 3009 | |||
| 3010 | have_err = true; | ||
| 3011 | |||
| 3012 | const have_err_payload = defer_scope.remapped_err_code != .none; | ||
| 3013 | need_err_code = need_err_code or have_err_payload; | ||
| 3014 | }, | ||
| 3015 | .namespace => unreachable, | 2979 | .namespace => unreachable, |
| 3016 | .top => unreachable, | 2980 | .top => unreachable, |
| 3017 | } | 2981 | } |
| 3018 | } | 2982 | } |
| 3019 | return .{ | 2983 | return false; |
| 3020 | .have_any = have_normal or have_err, | ||
| 3021 | .have_normal = have_normal, | ||
| 3022 | .have_err = have_err, | ||
| 3023 | .need_err_code = need_err_code, | ||
| 3024 | }; | ||
| 3025 | } | 2984 | } |
| 3026 | 2985 | ||
| 3027 | const DefersToEmit = union(enum) { | ||
| 3028 | both: Zir.Inst.Ref, // err code | ||
| 3029 | both_sans_err, | ||
| 3030 | normal_only, | ||
| 3031 | }; | ||
| 3032 | |||
| 3033 | fn genDefers( | 2986 | fn genDefers( |
| 3034 | gz: *GenZir, | 2987 | gz: *GenZir, |
| 3035 | outer_scope: *Scope, | 2988 | outer_scope: *Scope, |
| 3036 | inner_scope: *Scope, | 2989 | inner_scope: *Scope, |
| 3037 | which_ones: DefersToEmit, | 2990 | which_ones: enum { normal_only, normal_and_error }, |
| 3038 | ) InnerError!void { | 2991 | ) InnerError!void { |
| 3039 | const gpa = gz.astgen.gpa; | ||
| 3040 | |||
| 3041 | var scope = inner_scope; | 2992 | var scope = inner_scope; |
| 3042 | while (scope != outer_scope) { | 2993 | while (scope != outer_scope) { |
| 3043 | switch (scope.unwrap()) { | 2994 | switch (scope.unwrap()) { |
| ... | @@ -3051,33 +3002,10 @@ fn genDefers( | ... | @@ -3051,33 +3002,10 @@ fn genDefers( |
| 3051 | .defer_error => |defer_scope| { | 3002 | .defer_error => |defer_scope| { |
| 3052 | scope = defer_scope.parent; | 3003 | scope = defer_scope.parent; |
| 3053 | switch (which_ones) { | 3004 | switch (which_ones) { |
| 3054 | .both_sans_err => { | 3005 | .normal_only => continue, |
| 3006 | .normal_and_error => { | ||
| 3055 | try gz.addDefer(defer_scope.index, defer_scope.len); | 3007 | try gz.addDefer(defer_scope.index, defer_scope.len); |
| 3056 | }, | 3008 | }, |
| 3057 | .both => |err_code| { | ||
| 3058 | if (defer_scope.remapped_err_code.unwrap()) |remapped_err_code| { | ||
| 3059 | try gz.instructions.ensureUnusedCapacity(gpa, 1); | ||
| 3060 | try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1); | ||
| 3061 | |||
| 3062 | const payload_index = try gz.astgen.addExtra(Zir.Inst.DeferErrCode{ | ||
| 3063 | .remapped_err_code = remapped_err_code, | ||
| 3064 | .index = defer_scope.index, | ||
| 3065 | .len = defer_scope.len, | ||
| 3066 | }); | ||
| 3067 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | ||
| 3068 | gz.astgen.instructions.appendAssumeCapacity(.{ | ||
| 3069 | .tag = .defer_err_code, | ||
| 3070 | .data = .{ .defer_err_code = .{ | ||
| 3071 | .err_code = err_code, | ||
| 3072 | .payload_index = payload_index, | ||
| 3073 | } }, | ||
| 3074 | }); | ||
| 3075 | gz.instructions.appendAssumeCapacity(new_index); | ||
| 3076 | } else { | ||
| 3077 | try gz.addDefer(defer_scope.index, defer_scope.len); | ||
| 3078 | } | ||
| 3079 | }, | ||
| 3080 | .normal_only => continue, | ||
| 3081 | } | 3009 | } |
| 3082 | }, | 3010 | }, |
| 3083 | .namespace => unreachable, | 3011 | .namespace => unreachable, |
| ... | @@ -3140,46 +3068,17 @@ fn deferStmt( | ... | @@ -3140,46 +3068,17 @@ fn deferStmt( |
| 3140 | defer defer_gen.unstack(); | 3068 | defer defer_gen.unstack(); |
| 3141 | 3069 | ||
| 3142 | const tree = gz.astgen.tree; | 3070 | const tree = gz.astgen.tree; |
| 3143 | var local_val_scope: Scope.LocalVal = undefined; | 3071 | const expr_node = tree.nodeData(node).node; |
| 3144 | var opt_remapped_err_code: Zir.Inst.OptionalIndex = .none; | 3072 | _ = try unusedResultExpr(&defer_gen, &defer_gen.base, expr_node); |
| 3145 | const sub_scope = if (scope_tag != .defer_error) &defer_gen.base else blk: { | 3073 | try checkUsed(gz, scope, &defer_gen.base); |
| 3146 | const payload_token = tree.nodeData(node).opt_token_and_node[0].unwrap() orelse break :blk &defer_gen.base; | ||
| 3147 | const ident_name = try gz.astgen.identAsString(payload_token); | ||
| 3148 | if (std.mem.eql(u8, tree.tokenSlice(payload_token), "_")) { | ||
| 3149 | try gz.astgen.appendErrorTok(payload_token, "discard of error capture; omit it instead", .{}); | ||
| 3150 | break :blk &defer_gen.base; | ||
| 3151 | } | ||
| 3152 | const remapped_err_code: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); | ||
| 3153 | opt_remapped_err_code = remapped_err_code.toOptional(); | ||
| 3154 | _ = try gz.astgen.appendPlaceholder(); | ||
| 3155 | const remapped_err_code_ref = remapped_err_code.toRef(); | ||
| 3156 | local_val_scope = .{ | ||
| 3157 | .parent = &defer_gen.base, | ||
| 3158 | .gen_zir = gz, | ||
| 3159 | .name = ident_name, | ||
| 3160 | .inst = remapped_err_code_ref, | ||
| 3161 | .token_src = payload_token, | ||
| 3162 | .id_cat = .capture, | ||
| 3163 | }; | ||
| 3164 | try gz.addDbgVar(.dbg_var_val, ident_name, remapped_err_code_ref); | ||
| 3165 | break :blk &local_val_scope.base; | ||
| 3166 | }; | ||
| 3167 | const expr_node = switch (scope_tag) { | ||
| 3168 | .defer_normal => tree.nodeData(node).node, | ||
| 3169 | .defer_error => tree.nodeData(node).opt_token_and_node[1], | ||
| 3170 | else => unreachable, | ||
| 3171 | }; | ||
| 3172 | _ = try unusedResultExpr(&defer_gen, sub_scope, expr_node); | ||
| 3173 | try checkUsed(gz, scope, sub_scope); | ||
| 3174 | _ = try defer_gen.addBreak(.break_inline, @enumFromInt(0), .void_value); | 3074 | _ = try defer_gen.addBreak(.break_inline, @enumFromInt(0), .void_value); |
| 3175 | 3075 | ||
| 3176 | const body = defer_gen.instructionsSlice(); | 3076 | const body = defer_gen.instructionsSlice(); |
| 3177 | const extra_insts: []const Zir.Inst.Index = if (opt_remapped_err_code.unwrap()) |ec| &.{ec} else &.{}; | 3077 | const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(body, &.{}); |
| 3178 | const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(body, extra_insts); | ||
| 3179 | 3078 | ||
| 3180 | const index: u32 = @intCast(gz.astgen.extra.items.len); | 3079 | const index: u32 = @intCast(gz.astgen.extra.items.len); |
| 3181 | try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len); | 3080 | try gz.astgen.extra.ensureUnusedCapacity(gz.astgen.gpa, body_len); |
| 3182 | gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, body, extra_insts); | 3081 | gz.astgen.appendBodyWithFixupsExtraRefsArrayList(&gz.astgen.extra, body, &.{}); |
| 3183 | 3082 | ||
| 3184 | const defer_scope = try block_arena.create(Scope.Defer); | 3083 | const defer_scope = try block_arena.create(Scope.Defer); |
| 3185 | 3084 | ||
| ... | @@ -3188,7 +3087,6 @@ fn deferStmt( | ... | @@ -3188,7 +3087,6 @@ fn deferStmt( |
| 3188 | .parent = scope, | 3087 | .parent = scope, |
| 3189 | .index = index, | 3088 | .index = index, |
| 3190 | .len = body_len, | 3089 | .len = body_len, |
| 3191 | .remapped_err_code = opt_remapped_err_code, | ||
| 3192 | }; | 3090 | }; |
| 3193 | return &defer_scope.base; | 3091 | return &defer_scope.base; |
| 3194 | } | 3092 | } |
| ... | @@ -4882,7 +4780,7 @@ fn testDecl( | ... | @@ -4882,7 +4780,7 @@ fn testDecl( |
| 4882 | .noalias_bits = 0, | 4780 | .noalias_bits = 0, |
| 4883 | 4781 | ||
| 4884 | // Tests don't have a prototype that needs hashing | 4782 | // Tests don't have a prototype that needs hashing |
| 4885 | .proto_hash = .{0} ** 16, | 4783 | .proto_hash = @splat(0), |
| 4886 | }); | 4784 | }); |
| 4887 | 4785 | ||
| 4888 | _ = try decl_block.addBreak(.break_inline, decl_inst, func_inst); | 4786 | _ = try decl_block.addBreak(.break_inline, decl_inst, func_inst); |
| ... | @@ -5882,7 +5780,7 @@ fn tryExpr( | ... | @@ -5882,7 +5780,7 @@ fn tryExpr( |
| 5882 | else => Zir.Inst.Tag.err_union_code, | 5780 | else => Zir.Inst.Tag.err_union_code, |
| 5883 | }; | 5781 | }; |
| 5884 | const err_code = try else_scope.addUnNode(err_tag, operand, node); | 5782 | const err_code = try else_scope.addUnNode(err_tag, operand, node); |
| 5885 | try genDefers(&else_scope, &fn_block.base, scope, .{ .both = err_code }); | 5783 | try genDefers(&else_scope, &fn_block.base, scope, .normal_and_error); |
| 5886 | try emitDbgStmt(&else_scope, try_lc); | 5784 | try emitDbgStmt(&else_scope, try_lc); |
| 5887 | _ = try else_scope.addUnNode(.ret_node, err_code, node); | 5785 | _ = try else_scope.addUnNode(.ret_node, err_code, node); |
| 5888 | 5786 | ||
| ... | @@ -8033,18 +7931,10 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -8033,18 +7931,10 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 8033 | // for detecting whether to add something to the function's inferred error set. | 7931 | // for detecting whether to add something to the function's inferred error set. |
| 8034 | const ident_token = tree.nodeMainToken(operand_node) + 2; | 7932 | const ident_token = tree.nodeMainToken(operand_node) + 2; |
| 8035 | const err_name_str_index = try astgen.identAsString(ident_token); | 7933 | const err_name_str_index = try astgen.identAsString(ident_token); |
| 8036 | const defer_counts = countDefers(defer_outer, scope); | 7934 | try genDefers(gz, defer_outer, scope, .normal_and_error); |
| 8037 | if (!defer_counts.need_err_code) { | ||
| 8038 | try genDefers(gz, defer_outer, scope, .both_sans_err); | ||
| 8039 | try emitDbgStmt(gz, ret_lc); | ||
| 8040 | _ = try gz.addStrTok(.ret_err_value, err_name_str_index, ident_token); | ||
| 8041 | return Zir.Inst.Ref.unreachable_value; | ||
| 8042 | } | ||
| 8043 | const err_code = try gz.addStrTok(.ret_err_value_code, err_name_str_index, ident_token); | ||
| 8044 | try genDefers(gz, defer_outer, scope, .{ .both = err_code }); | ||
| 8045 | try emitDbgStmt(gz, ret_lc); | 7935 | try emitDbgStmt(gz, ret_lc); |
| 8046 | _ = try gz.addUnNode(.ret_node, err_code, node); | 7936 | _ = try gz.addStrTok(.ret_err_value, err_name_str_index, ident_token); |
| 8047 | return Zir.Inst.Ref.unreachable_value; | 7937 | return .unreachable_value; |
| 8048 | } | 7938 | } |
| 8049 | 7939 | ||
| 8050 | const ri: ResultInfo = if (astgen.nodes_need_rl.contains(node)) .{ | 7940 | const ri: ResultInfo = if (astgen.nodes_need_rl.contains(node)) .{ |
| ... | @@ -8071,15 +7961,13 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -8071,15 +7961,13 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 8071 | }, | 7961 | }, |
| 8072 | .always => { | 7962 | .always => { |
| 8073 | // Value is always an error. Emit both error defers and regular defers. | 7963 | // Value is always an error. Emit both error defers and regular defers. |
| 8074 | const err_code = if (ri.rl == .ptr) try gz.addUnNode(.load, ri.rl.ptr.inst, node) else operand; | 7964 | try genDefers(gz, defer_outer, scope, .normal_and_error); |
| 8075 | try genDefers(gz, defer_outer, scope, .{ .both = err_code }); | ||
| 8076 | try emitDbgStmt(gz, ret_lc); | 7965 | try emitDbgStmt(gz, ret_lc); |
| 8077 | try gz.addRet(ri, operand, node); | 7966 | try gz.addRet(ri, operand, node); |
| 8078 | return Zir.Inst.Ref.unreachable_value; | 7967 | return Zir.Inst.Ref.unreachable_value; |
| 8079 | }, | 7968 | }, |
| 8080 | .maybe => { | 7969 | .maybe => { |
| 8081 | const defer_counts = countDefers(defer_outer, scope); | 7970 | if (!anyErrdefers(defer_outer, scope)) { |
| 8082 | if (!defer_counts.have_err) { | ||
| 8083 | // Only regular defers; no branch needed. | 7971 | // Only regular defers; no branch needed. |
| 8084 | try genDefers(gz, defer_outer, scope, .normal_only); | 7972 | try genDefers(gz, defer_outer, scope, .normal_only); |
| 8085 | try emitDbgStmt(gz, ret_lc); | 7973 | try emitDbgStmt(gz, ret_lc); |
| ... | @@ -8111,10 +7999,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -8111,10 +7999,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref |
| 8111 | var else_scope = gz.makeSubBlock(scope); | 7999 | var else_scope = gz.makeSubBlock(scope); |
| 8112 | defer else_scope.unstack(); | 8000 | defer else_scope.unstack(); |
| 8113 | 8001 | ||
| 8114 | const which_ones: DefersToEmit = if (!defer_counts.need_err_code) .both_sans_err else .{ | 8002 | try genDefers(&else_scope, defer_outer, scope, .normal_and_error); |
| 8115 | .both = try else_scope.addUnNode(.err_union_code, result, node), | ||
| 8116 | }; | ||
| 8117 | try genDefers(&else_scope, defer_outer, scope, which_ones); | ||
| 8118 | try emitDbgStmt(&else_scope, ret_lc); | 8003 | try emitDbgStmt(&else_scope, ret_lc); |
| 8119 | try else_scope.addRet(ri, operand, node); | 8004 | try else_scope.addRet(ri, operand, node); |
| 8120 | 8005 | ||
| ... | @@ -8173,39 +8058,42 @@ fn identifier( | ... | @@ -8173,39 +8058,42 @@ fn identifier( |
| 8173 | return rvalue(gz, ri, zir_const_ref, ident); | 8058 | return rvalue(gz, ri, zir_const_ref, ident); |
| 8174 | } | 8059 | } |
| 8175 | 8060 | ||
| 8176 | if (ident_name_raw.len >= 2) integer: { | 8061 | int_type: { |
| 8177 | // Keep in sync with logic in `comptimeExpr2`. | 8062 | if (ident_name_raw.len < 2) break :int_type; |
| 8178 | const first_c = ident_name_raw[0]; | 8063 | const signedness: std.builtin.Signedness = switch (ident_name_raw[0]) { |
| 8179 | if (first_c == 'i' or first_c == 'u') { | 8064 | 'u' => .unsigned, |
| 8180 | const signedness: std.builtin.Signedness = switch (first_c == 'i') { | 8065 | 'i' => .signed, |
| 8181 | true => .signed, | 8066 | else => break :int_type, |
| 8182 | false => .unsigned, | 8067 | }; |
| 8183 | }; | 8068 | // `u0` already handled by `primitive_instrs` |
| 8184 | if (ident_name_raw.len >= 3 and ident_name_raw[1] == '0') { | 8069 | if (std.mem.eql(u8, ident_name_raw, "i0")) { |
| 8185 | return astgen.failNode( | 8070 | return astgen.failNode(ident, "signed integer cannot have bit width 0", .{}); |
| 8186 | ident, | 8071 | } |
| 8187 | "primitive integer type '{s}' has leading zero", | 8072 | if (ident_name_raw[1] == '0') { |
| 8188 | .{ident_name_raw}, | 8073 | assert(ident_name_raw.len >= 3); // `u0` and `i0` handled |
| 8189 | ); | 8074 | return astgen.failNode( |
| 8190 | } | 8075 | ident, |
| 8191 | const bit_count = parseBitCount(ident_name_raw[1..]) catch |err| switch (err) { | 8076 | "primitive integer type '{s}' has leading zero", |
| 8192 | error.Overflow => return astgen.failNode( | 8077 | .{ident_name_raw}, |
| 8193 | ident, | 8078 | ); |
| 8194 | "primitive integer type '{s}' exceeds maximum bit width of 65535", | ||
| 8195 | .{ident_name_raw}, | ||
| 8196 | ), | ||
| 8197 | error.InvalidCharacter => break :integer, | ||
| 8198 | }; | ||
| 8199 | const result = try gz.add(.{ | ||
| 8200 | .tag = .int_type, | ||
| 8201 | .data = .{ .int_type = .{ | ||
| 8202 | .src_node = gz.nodeIndexToRelative(ident), | ||
| 8203 | .signedness = signedness, | ||
| 8204 | .bit_count = bit_count, | ||
| 8205 | } }, | ||
| 8206 | }); | ||
| 8207 | return rvalue(gz, ri, result, ident); | ||
| 8208 | } | 8079 | } |
| 8080 | const bit_count = parseBitCount(ident_name_raw[1..]) catch |err| switch (err) { | ||
| 8081 | error.Overflow => return astgen.failNode( | ||
| 8082 | ident, | ||
| 8083 | "primitive integer type '{s}' exceeds maximum bit width of 65535", | ||
| 8084 | .{ident_name_raw}, | ||
| 8085 | ), | ||
| 8086 | error.InvalidCharacter => break :int_type, | ||
| 8087 | }; | ||
| 8088 | const result = try gz.add(.{ | ||
| 8089 | .tag = .int_type, | ||
| 8090 | .data = .{ .int_type = .{ | ||
| 8091 | .src_node = gz.nodeIndexToRelative(ident), | ||
| 8092 | .signedness = signedness, | ||
| 8093 | .bit_count = bit_count, | ||
| 8094 | } }, | ||
| 8095 | }); | ||
| 8096 | return rvalue(gz, ri, result, ident); | ||
| 8209 | } | 8097 | } |
| 8210 | } | 8098 | } |
| 8211 | 8099 | ||
| ... | @@ -10222,32 +10110,37 @@ const primitive_instrs = std.StaticStringMap(Zir.Inst.Ref).initComptime(.{ | ... | @@ -10222,32 +10110,37 @@ const primitive_instrs = std.StaticStringMap(Zir.Inst.Ref).initComptime(.{ |
| 10222 | .{ "c_ushort", .c_ushort_type }, | 10110 | .{ "c_ushort", .c_ushort_type }, |
| 10223 | .{ "comptime_float", .comptime_float_type }, | 10111 | .{ "comptime_float", .comptime_float_type }, |
| 10224 | .{ "comptime_int", .comptime_int_type }, | 10112 | .{ "comptime_int", .comptime_int_type }, |
| 10225 | .{ "f128", .f128_type }, | ||
| 10226 | .{ "f16", .f16_type }, | ||
| 10227 | .{ "f32", .f32_type }, | ||
| 10228 | .{ "f64", .f64_type }, | ||
| 10229 | .{ "f80", .f80_type }, | ||
| 10230 | .{ "false", .bool_false }, | 10113 | .{ "false", .bool_false }, |
| 10231 | .{ "i16", .i16_type }, | ||
| 10232 | .{ "i32", .i32_type }, | ||
| 10233 | .{ "i64", .i64_type }, | ||
| 10234 | .{ "i128", .i128_type }, | ||
| 10235 | .{ "i8", .i8_type }, | ||
| 10236 | .{ "isize", .isize_type }, | ||
| 10237 | .{ "noreturn", .noreturn_type }, | 10114 | .{ "noreturn", .noreturn_type }, |
| 10238 | .{ "null", .null_value }, | 10115 | .{ "null", .null_value }, |
| 10239 | .{ "true", .bool_true }, | 10116 | .{ "true", .bool_true }, |
| 10240 | .{ "type", .type_type }, | 10117 | .{ "type", .type_type }, |
| 10118 | .{ "undefined", .undef }, | ||
| 10119 | .{ "void", .void_type }, | ||
| 10120 | |||
| 10121 | .{ "f16", .f16_type }, | ||
| 10122 | .{ "f32", .f32_type }, | ||
| 10123 | .{ "f64", .f64_type }, | ||
| 10124 | .{ "f80", .f80_type }, | ||
| 10125 | .{ "f128", .f128_type }, | ||
| 10126 | |||
| 10127 | .{ "u0", .u0_type }, | ||
| 10128 | .{ "u1", .u1_type }, | ||
| 10129 | .{ "u8", .u8_type }, | ||
| 10130 | .{ "i8", .i8_type }, | ||
| 10241 | .{ "u16", .u16_type }, | 10131 | .{ "u16", .u16_type }, |
| 10132 | .{ "i16", .i16_type }, | ||
| 10242 | .{ "u29", .u29_type }, | 10133 | .{ "u29", .u29_type }, |
| 10243 | .{ "u32", .u32_type }, | 10134 | .{ "u32", .u32_type }, |
| 10135 | .{ "i32", .i32_type }, | ||
| 10244 | .{ "u64", .u64_type }, | 10136 | .{ "u64", .u64_type }, |
| 10137 | .{ "i64", .i64_type }, | ||
| 10138 | .{ "u80", .u80_type }, | ||
| 10245 | .{ "u128", .u128_type }, | 10139 | .{ "u128", .u128_type }, |
| 10246 | .{ "u1", .u1_type }, | 10140 | .{ "i128", .i128_type }, |
| 10247 | .{ "u8", .u8_type }, | 10141 | .{ "u256", .u256_type }, |
| 10248 | .{ "undefined", .undef }, | ||
| 10249 | .{ "usize", .usize_type }, | 10142 | .{ "usize", .usize_type }, |
| 10250 | .{ "void", .void_type }, | 10143 | .{ "isize", .isize_type }, |
| 10251 | }); | 10144 | }); |
| 10252 | 10145 | ||
| 10253 | comptime { | 10146 | comptime { |
| ... | @@ -10399,7 +10292,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev | ... | @@ -10399,7 +10292,6 @@ fn nodeMayEvalToError(tree: *const Ast, start_node: Ast.Node.Index) BuiltinFn.Ev |
| 10399 | .add_wrap, | 10292 | .add_wrap, |
| 10400 | .add_sat, | 10293 | .add_sat, |
| 10401 | .array_cat, | 10294 | .array_cat, |
| 10402 | .array_mult, | ||
| 10403 | .assign, | 10295 | .assign, |
| 10404 | .assign_destructure, | 10296 | .assign_destructure, |
| 10405 | .assign_bit_and, | 10297 | .assign_bit_and, |
| ... | @@ -11239,7 +11131,6 @@ const Scope = struct { | ... | @@ -11239,7 +11131,6 @@ const Scope = struct { |
| 11239 | parent: *Scope, | 11131 | parent: *Scope, |
| 11240 | index: u32, | 11132 | index: u32, |
| 11241 | len: u32, | 11133 | len: u32, |
| 11242 | remapped_err_code: Zir.Inst.OptionalIndex = .none, | ||
| 11243 | }; | 11134 | }; |
| 11244 | 11135 | ||
| 11245 | /// Represents a global scope that has any number of declarations in it. | 11136 | /// Represents a global scope that has any number of declarations in it. |
lib/std/zig/AstRlAnnotate.zig+1-11| ... | @@ -141,11 +141,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -141,11 +141,7 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 141 | .asm_input, | 141 | .asm_input, |
| 142 | => unreachable, | 142 | => unreachable, |
| 143 | 143 | ||
| 144 | .@"errdefer" => { | 144 | .@"defer", .@"errdefer" => { |
| 145 | _ = try astrl.expr(tree.nodeData(node).opt_token_and_node[1], block, ResultInfo.none); | ||
| 146 | return false; | ||
| 147 | }, | ||
| 148 | .@"defer" => { | ||
| 149 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); | 145 | _ = try astrl.expr(tree.nodeData(node).node, block, ResultInfo.none); |
| 150 | return false; | 146 | return false; |
| 151 | }, | 147 | }, |
| ... | @@ -273,12 +269,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI | ... | @@ -273,12 +269,6 @@ fn expr(astrl: *AstRlAnnotate, node: Ast.Node.Index, block: ?*Block, ri: ResultI |
| 273 | return false; | 269 | return false; |
| 274 | }, | 270 | }, |
| 275 | 271 | ||
| 276 | .array_mult => { | ||
| 277 | const lhs, const rhs = tree.nodeData(node).node_and_node; | ||
| 278 | _ = try astrl.expr(lhs, block, ResultInfo.none); | ||
| 279 | _ = try astrl.expr(rhs, block, ResultInfo.type_only); | ||
| 280 | return false; | ||
| 281 | }, | ||
| 282 | .error_union, .merge_error_sets => { | 272 | .error_union, .merge_error_sets => { |
| 283 | const lhs, const rhs = tree.nodeData(node).node_and_node; | 273 | const lhs, const rhs = tree.nodeData(node).node_and_node; |
| 284 | _ = try astrl.expr(lhs, block, ResultInfo.none); | 274 | _ = try astrl.expr(lhs, block, ResultInfo.none); |
lib/std/zig/AstSmith.zig+5-11| ... | @@ -18,7 +18,6 @@ token_tag_buf: [2048]Token.Tag, | ... | @@ -18,7 +18,6 @@ token_tag_buf: [2048]Token.Tag, |
| 18 | token_start_buf: [2048]std.zig.Ast.ByteOffset, | 18 | token_start_buf: [2048]std.zig.Ast.ByteOffset, |
| 19 | tokens_len: usize, | 19 | tokens_len: usize, |
| 20 | 20 | ||
| 21 | /// For `.asterisk`, this also includes `.asterisk2` | ||
| 22 | not_token: ?Token.Tag, | 21 | not_token: ?Token.Tag, |
| 23 | not_token_comptime: bool, | 22 | not_token_comptime: bool, |
| 24 | /// ExprSuffix | 23 | /// ExprSuffix |
| ... | @@ -196,7 +195,6 @@ fn preservePegEndOfWord(a: *AstSmith) SourceError!void { | ... | @@ -196,7 +195,6 @@ fn preservePegEndOfWord(a: *AstSmith) SourceError!void { |
| 196 | /// Assumes the token has not been written yet | 195 | /// Assumes the token has not been written yet |
| 197 | fn addTokenTag(a: *AstSmith, tag: Token.Tag) SourceError!void { | 196 | fn addTokenTag(a: *AstSmith, tag: Token.Tag) SourceError!void { |
| 198 | assert(tag != a.not_token); | 197 | assert(tag != a.not_token); |
| 199 | if (a.not_token == .asterisk) assert(tag != .asterisk_asterisk); | ||
| 200 | a.not_token = null; | 198 | a.not_token = null; |
| 201 | 199 | ||
| 202 | if (a.not_token_comptime) assert(tag != .keyword_comptime); | 200 | if (a.not_token_comptime) assert(tag != .keyword_comptime); |
| ... | @@ -240,9 +238,7 @@ fn pegToken(a: *AstSmith, tag: Token.Tag) SourceError!void { | ... | @@ -240,9 +238,7 @@ fn pegToken(a: *AstSmith, tag: Token.Tag) SourceError!void { |
| 240 | 238 | ||
| 241 | switch (lexeme[0]) { | 239 | switch (lexeme[0]) { |
| 242 | '_', 'a'...'z', 'A'...'Z', '0'...'9' => try a.preservePegEndOfWord(), | 240 | '_', 'a'...'z', 'A'...'Z', '0'...'9' => try a.preservePegEndOfWord(), |
| 243 | '*' => if (a.tokens_len > 0 and a.source_buf[a.source_len - 1] == '*' and | 241 | '*' => if (a.tokens_len > 0 and a.source_buf[a.source_len - 1] == '*') { |
| 244 | a.token_tag_buf[a.tokens_len - 1] != .asterisk_asterisk) | ||
| 245 | { | ||
| 246 | try a.addSourceByte(' '); | 242 | try a.addSourceByte(' '); |
| 247 | }, | 243 | }, |
| 248 | '.' => if (a.tokens_len > 0 and switch (a.source_buf[a.source_len - 1]) { | 244 | '.' => if (a.tokens_len > 0 and switch (a.source_buf[a.source_len - 1]) { |
| ... | @@ -486,7 +482,7 @@ fn pegContainerField(a: *AstSmith) SourceError!void { | ... | @@ -486,7 +482,7 @@ fn pegContainerField(a: *AstSmith) SourceError!void { |
| 486 | /// BlockStatement | 482 | /// BlockStatement |
| 487 | /// <- Statement | 483 | /// <- Statement |
| 488 | /// / KEYWORD_defer BlockExprStatement | 484 | /// / KEYWORD_defer BlockExprStatement |
| 489 | /// / KEYWORD_errdefer Payload? BlockExprStatement | 485 | /// / KEYWORD_errdefer BlockExprStatement |
| 490 | /// / !ExprStatement (KEYWORD_comptime !BlockExpr)? VarAssignStatement | 486 | /// / !ExprStatement (KEYWORD_comptime !BlockExpr)? VarAssignStatement |
| 491 | fn pegBlockStatement(a: *AstSmith) SourceError!void { | 487 | fn pegBlockStatement(a: *AstSmith) SourceError!void { |
| 492 | const Kind = enum { | 488 | const Kind = enum { |
| ... | @@ -1723,13 +1719,11 @@ fn pegAdditionOp(a: *AstSmith) SourceError!void { | ... | @@ -1723,13 +1719,11 @@ fn pegAdditionOp(a: *AstSmith) SourceError!void { |
| 1723 | /// / ASTERISK | 1719 | /// / ASTERISK |
| 1724 | /// / SLASH | 1720 | /// / SLASH |
| 1725 | /// / PERCENT | 1721 | /// / PERCENT |
| 1726 | /// / ASTERISK2 | ||
| 1727 | /// / ASTERISKPERCENT | 1722 | /// / ASTERISKPERCENT |
| 1728 | /// / ASTERISKPIPE | 1723 | /// / ASTERISKPIPE |
| 1729 | fn pegMultiplyOp(a: *AstSmith) SourceError!void { | 1724 | fn pegMultiplyOp(a: *AstSmith) SourceError!void { |
| 1730 | const tags = [_]Token.Tag{ | 1725 | const tags = [_]Token.Tag{ |
| 1731 | .asterisk, | 1726 | .asterisk, |
| 1732 | .asterisk_asterisk, | ||
| 1733 | .pipe_pipe, | 1727 | .pipe_pipe, |
| 1734 | .slash, | 1728 | .slash, |
| 1735 | .percent, | 1729 | .percent, |
| ... | @@ -1865,9 +1859,9 @@ fn pegSliceTypeStart(a: *AstSmith) SourceError!void { | ... | @@ -1865,9 +1859,9 @@ fn pegSliceTypeStart(a: *AstSmith) SourceError!void { |
| 1865 | try a.pegToken(.r_bracket); | 1859 | try a.pegToken(.r_bracket); |
| 1866 | } | 1860 | } |
| 1867 | 1861 | ||
| 1868 | /// SinglePtrTypeStart <- ASTERISK / ASTERISK2 | 1862 | /// SinglePtrTypeStart <- ASTERISK |
| 1869 | fn pegSinglePtrTypeStart(a: *AstSmith) SourceError!void { | 1863 | fn pegSinglePtrTypeStart(a: *AstSmith) SourceError!void { |
| 1870 | try a.pegToken(if (!a.smith.value(bool)) .asterisk else .asterisk_asterisk); | 1864 | try a.pegToken(.asterisk); |
| 1871 | } | 1865 | } |
| 1872 | 1866 | ||
| 1873 | /// ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET | 1867 | /// ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET |
| ... | @@ -1889,7 +1883,7 @@ fn pegManyPtrTypeStart(a: *AstSmith) SourceError!void { | ... | @@ -1889,7 +1883,7 @@ fn pegManyPtrTypeStart(a: *AstSmith) SourceError!void { |
| 1889 | try a.pegToken(.r_bracket); | 1883 | try a.pegToken(.r_bracket); |
| 1890 | } | 1884 | } |
| 1891 | 1885 | ||
| 1892 | /// ArrayTypeStart <- LBRACKET !(ASTERISK / ASTERISK2) Expr (COLON Expr)? RBRACKET | 1886 | /// ArrayTypeStart <- LBRACKET !ASTERISK Expr (COLON Expr)? RBRACKET |
| 1893 | fn pegArrayTypeStart(a: *AstSmith) SourceError!void { | 1887 | fn pegArrayTypeStart(a: *AstSmith) SourceError!void { |
| 1894 | try a.pegToken(.l_bracket); | 1888 | try a.pegToken(.l_bracket); |
| 1895 | a.not_token = .asterisk; | 1889 | a.not_token = .asterisk; |
lib/std/zig/LibCInstallation.zig+1-1| ... | @@ -46,7 +46,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const | ... | @@ -46,7 +46,7 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const |
| 46 | found: bool, | 46 | found: bool, |
| 47 | allocated: ?[:0]u8, | 47 | allocated: ?[:0]u8, |
| 48 | }; | 48 | }; |
| 49 | var found_keys = [1]FoundKey{FoundKey{ .found = false, .allocated = null }} ** fields.len; | 49 | var found_keys: [fields.len]FoundKey = @splat(.{ .found = false, .allocated = null }); |
| 50 | errdefer { | 50 | errdefer { |
| 51 | self = .{}; | 51 | self = .{}; |
| 52 | for (found_keys) |found_key| { | 52 | for (found_keys) |found_key| { |
lib/std/zig/Parse.zig+4-69| ... | @@ -909,7 +909,7 @@ fn expectContainerField(p: *Parse) !Node.Index { | ... | @@ -909,7 +909,7 @@ fn expectContainerField(p: *Parse) !Node.Index { |
| 909 | /// BlockStatement | 909 | /// BlockStatement |
| 910 | /// <- Statement | 910 | /// <- Statement |
| 911 | /// / KEYWORD_defer BlockExprStatement | 911 | /// / KEYWORD_defer BlockExprStatement |
| 912 | /// / KEYWORD_errdefer Payload? BlockExprStatement | 912 | /// / KEYWORD_errdefer BlockExprStatement |
| 913 | /// / !ExprStatement (KEYWORD_comptime !BlockExpr)? VarAssignStatement | 913 | /// / !ExprStatement (KEYWORD_comptime !BlockExpr)? VarAssignStatement |
| 914 | /// | 914 | /// |
| 915 | /// Statement | 915 | /// Statement |
| ... | @@ -975,10 +975,7 @@ fn expectStatement(p: *Parse, is_block_level: bool) Error!Node.Index { | ... | @@ -975,10 +975,7 @@ fn expectStatement(p: *Parse, is_block_level: bool) Error!Node.Index { |
| 975 | .keyword_errdefer => if (is_block_level) return p.addNode(.{ | 975 | .keyword_errdefer => if (is_block_level) return p.addNode(.{ |
| 976 | .tag = .@"errdefer", | 976 | .tag = .@"errdefer", |
| 977 | .main_token = p.nextToken(), | 977 | .main_token = p.nextToken(), |
| 978 | .data = .{ .opt_token_and_node = .{ | 978 | .data = .{ .node = try p.expectBlockExprStatement() }, |
| 979 | try p.parsePayload(), | ||
| 980 | try p.expectBlockExprStatement(), | ||
| 981 | } }, | ||
| 982 | }), | 979 | }), |
| 983 | .keyword_if => return p.expectIfStatement(), | 980 | .keyword_if => return p.expectIfStatement(), |
| 984 | .keyword_enum, .keyword_struct, .keyword_union => { | 981 | .keyword_enum, .keyword_struct, .keyword_union => { |
| ... | @@ -1612,7 +1609,6 @@ const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec | ... | @@ -1612,7 +1609,6 @@ const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec |
| 1612 | .asterisk = .{ .prec = 70, .tag = .mul }, | 1609 | .asterisk = .{ .prec = 70, .tag = .mul }, |
| 1613 | .slash = .{ .prec = 70, .tag = .div }, | 1610 | .slash = .{ .prec = 70, .tag = .div }, |
| 1614 | .percent = .{ .prec = 70, .tag = .mod }, | 1611 | .percent = .{ .prec = 70, .tag = .mod }, |
| 1615 | .asterisk_asterisk = .{ .prec = 70, .tag = .array_mult }, | ||
| 1616 | .asterisk_percent = .{ .prec = 70, .tag = .mul_wrap }, | 1612 | .asterisk_percent = .{ .prec = 70, .tag = .mul_wrap }, |
| 1617 | .asterisk_pipe = .{ .prec = 70, .tag = .mul_sat }, | 1613 | .asterisk_pipe = .{ .prec = 70, .tag = .mul_sat }, |
| 1618 | }); | 1614 | }); |
| ... | @@ -1712,11 +1708,11 @@ fn expectPrefixExpr(p: *Parse) Error!Node.Index { | ... | @@ -1712,11 +1708,11 @@ fn expectPrefixExpr(p: *Parse) Error!Node.Index { |
| 1712 | /// | 1708 | /// |
| 1713 | /// SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET | 1709 | /// SliceTypeStart <- LBRACKET (COLON Expr)? RBRACKET |
| 1714 | /// | 1710 | /// |
| 1715 | /// SinglePtrTypeStart <- ASTERISK / ASTERISK2 | 1711 | /// SinglePtrTypeStart <- ASTERISK |
| 1716 | /// | 1712 | /// |
| 1717 | /// ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET | 1713 | /// ManyPtrTypeStart <- LBRACKET ASTERISK (LETTERC / COLON Expr)? RBRACKET |
| 1718 | /// | 1714 | /// |
| 1719 | /// ArrayTypeStart <- LBRACKET Expr !(ASTERISK / ASTERISK2) (COLON Expr)? RBRACKET | 1715 | /// ArrayTypeStart <- LBRACKET Expr !ASTERISK (COLON Expr)? RBRACKET |
| 1720 | /// | 1716 | /// |
| 1721 | /// BitAlign <- KEYWORD_align LPAREN Expr (COLON Expr COLON Expr)? RPAREN | 1717 | /// BitAlign <- KEYWORD_align LPAREN Expr (COLON Expr COLON Expr)? RPAREN |
| 1722 | fn parseTypeExpr(p: *Parse) Error!?Node.Index { | 1718 | fn parseTypeExpr(p: *Parse) Error!?Node.Index { |
| ... | @@ -1780,59 +1776,6 @@ fn parseTypeExpr(p: *Parse) Error!?Node.Index { | ... | @@ -1780,59 +1776,6 @@ fn parseTypeExpr(p: *Parse) Error!?Node.Index { |
| 1780 | }); | 1776 | }); |
| 1781 | } | 1777 | } |
| 1782 | }, | 1778 | }, |
| 1783 | .asterisk_asterisk => { | ||
| 1784 | const asterisk = p.nextToken(); | ||
| 1785 | const mods = try p.parsePtrModifiers(); | ||
| 1786 | const elem_type = try p.expectTypeExpr(); | ||
| 1787 | const inner: Node.Index = inner: { | ||
| 1788 | if (mods.bit_range_start != .none) { | ||
| 1789 | break :inner try p.addNode(.{ | ||
| 1790 | .tag = .ptr_type_bit_range, | ||
| 1791 | .main_token = asterisk, | ||
| 1792 | .data = .{ .extra_and_node = .{ | ||
| 1793 | try p.addExtra(Node.PtrTypeBitRange{ | ||
| 1794 | .sentinel = .none, | ||
| 1795 | .align_node = mods.align_node.unwrap().?, | ||
| 1796 | .addrspace_node = mods.addrspace_node, | ||
| 1797 | .bit_range_start = mods.bit_range_start.unwrap().?, | ||
| 1798 | .bit_range_end = mods.bit_range_end.unwrap().?, | ||
| 1799 | }), | ||
| 1800 | elem_type, | ||
| 1801 | } }, | ||
| 1802 | }); | ||
| 1803 | } else if (mods.addrspace_node != .none) { | ||
| 1804 | break :inner try p.addNode(.{ | ||
| 1805 | .tag = .ptr_type, | ||
| 1806 | .main_token = asterisk, | ||
| 1807 | .data = .{ .extra_and_node = .{ | ||
| 1808 | try p.addExtra(Node.PtrType{ | ||
| 1809 | .sentinel = .none, | ||
| 1810 | .align_node = mods.align_node, | ||
| 1811 | .addrspace_node = mods.addrspace_node, | ||
| 1812 | }), | ||
| 1813 | elem_type, | ||
| 1814 | } }, | ||
| 1815 | }); | ||
| 1816 | } else { | ||
| 1817 | break :inner try p.addNode(.{ | ||
| 1818 | .tag = .ptr_type_aligned, | ||
| 1819 | .main_token = asterisk, | ||
| 1820 | .data = .{ .opt_node_and_node = .{ | ||
| 1821 | mods.align_node, | ||
| 1822 | elem_type, | ||
| 1823 | } }, | ||
| 1824 | }); | ||
| 1825 | } | ||
| 1826 | }; | ||
| 1827 | return try p.addNode(.{ | ||
| 1828 | .tag = .ptr_type_aligned, | ||
| 1829 | .main_token = asterisk, | ||
| 1830 | .data = .{ .opt_node_and_node = .{ | ||
| 1831 | .none, | ||
| 1832 | inner, | ||
| 1833 | } }, | ||
| 1834 | }); | ||
| 1835 | }, | ||
| 1836 | .l_bracket => switch (p.tokenTag(p.tok_i + 1)) { | 1779 | .l_bracket => switch (p.tokenTag(p.tok_i + 1)) { |
| 1837 | .asterisk => { | 1780 | .asterisk => { |
| 1838 | const l_bracket = p.nextToken(); | 1781 | const l_bracket = p.nextToken(); |
| ... | @@ -3260,14 +3203,6 @@ fn parseSuffixOp(p: *Parse, lhs: Node.Index) !?Node.Index { | ... | @@ -3260,14 +3203,6 @@ fn parseSuffixOp(p: *Parse, lhs: Node.Index) !?Node.Index { |
| 3260 | .main_token = p.nextToken(), | 3203 | .main_token = p.nextToken(), |
| 3261 | .data = .{ .node = lhs }, | 3204 | .data = .{ .node = lhs }, |
| 3262 | }), | 3205 | }), |
| 3263 | .invalid_periodasterisks => { | ||
| 3264 | try p.warn(.asterisk_after_ptr_deref); | ||
| 3265 | return try p.addNode(.{ | ||
| 3266 | .tag = .deref, | ||
| 3267 | .main_token = p.nextToken(), | ||
| 3268 | .data = .{ .node = lhs }, | ||
| 3269 | }); | ||
| 3270 | }, | ||
| 3271 | .period => switch (p.tokenTag(p.tok_i + 1)) { | 3206 | .period => switch (p.tokenTag(p.tok_i + 1)) { |
| 3272 | .identifier => return try p.addNode(.{ | 3207 | .identifier => return try p.addNode(.{ |
| 3273 | .tag = .field_access, | 3208 | .tag = .field_access, |
lib/std/zig/TokenSmith.zig-6| ... | @@ -57,12 +57,6 @@ pub fn gen(smith: *Smith) TokenSmith { | ... | @@ -57,12 +57,6 @@ pub fn gen(smith: *Smith) TokenSmith { |
| 57 | @memcpy(t.source_buf[t.source_len..][0..lexeme.len], lexeme); | 57 | @memcpy(t.source_buf[t.source_len..][0..lexeme.len], lexeme); |
| 58 | t.source_len += @intCast(lexeme.len); | 58 | t.source_len += @intCast(lexeme.len); |
| 59 | 59 | ||
| 60 | if (tag == .invalid_periodasterisks) { | ||
| 61 | t.tag_buf[t.tags_len] = .asterisk; | ||
| 62 | t.start_buf[t.tags_len] = t.source_len - 1; | ||
| 63 | t.tags_len += 1; | ||
| 64 | } | ||
| 65 | |||
| 66 | t.source_buf[t.source_len] = '\n'; | 60 | t.source_buf[t.source_len] = '\n'; |
| 67 | t.source_len += 1; | 61 | t.source_len += 1; |
| 68 | } else sw: switch (tag) { | 62 | } else sw: switch (tag) { |
lib/std/zig/WindowsSdk.zig+1-1| ... | @@ -120,7 +120,7 @@ fn iterateAndFilterByVersion( | ... | @@ -120,7 +120,7 @@ fn iterateAndFilterByVersion( |
| 120 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue; | 120 | if (!std.mem.startsWith(u8, entry.name, prefix)) continue; |
| 121 | 121 | ||
| 122 | var version: Version = .{ | 122 | var version: Version = .{ |
| 123 | .nums = .{0} ** 4, | 123 | .nums = @splat(0), |
| 124 | .build = "", | 124 | .build = "", |
| 125 | }; | 125 | }; |
| 126 | const suffix = entry.name[prefix.len..]; | 126 | const suffix = entry.name[prefix.len..]; |
lib/std/zig/Zir.zig-54| ... | @@ -250,9 +250,6 @@ pub const Inst = struct { | ... | @@ -250,9 +250,6 @@ pub const Inst = struct { |
| 250 | /// Array concatenation. `a ++ b` | 250 | /// Array concatenation. `a ++ b` |
| 251 | /// Uses the `pl_node` union field. Payload is `Bin`. | 251 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 252 | array_cat, | 252 | array_cat, |
| 253 | /// Array multiplication `a ** b` | ||
| 254 | /// Uses the `pl_node` union field. Payload is `ArrayMul`. | ||
| 255 | array_mul, | ||
| 256 | /// `[N]T` syntax. No source location provided. | 253 | /// `[N]T` syntax. No source location provided. |
| 257 | /// Uses the `pl_node` union field. Payload is `Bin`. lhs is length, rhs is element type. | 254 | /// Uses the `pl_node` union field. Payload is `Bin`. lhs is length, rhs is element type. |
| 258 | array_type, | 255 | array_type, |
| ... | @@ -597,13 +594,6 @@ pub const Inst = struct { | ... | @@ -597,13 +594,6 @@ pub const Inst = struct { |
| 597 | /// name is added to it. | 594 | /// name is added to it. |
| 598 | /// Uses the `str_tok` union field. | 595 | /// Uses the `str_tok` union field. |
| 599 | ret_err_value, | 596 | ret_err_value, |
| 600 | /// A string name is provided which is an anonymous error set value. | ||
| 601 | /// If the current function has an inferred error set, the error given by the | ||
| 602 | /// name is added to it. | ||
| 603 | /// Results in the error code. Note that control flow is not diverted with | ||
| 604 | /// this instruction; a following 'ret' instruction will do the diversion. | ||
| 605 | /// Uses the `str_tok` union field. | ||
| 606 | ret_err_value_code, | ||
| 607 | /// Obtains a pointer to the return value. | 597 | /// Obtains a pointer to the return value. |
| 608 | /// Uses the `node` union field. | 598 | /// Uses the `node` union field. |
| 609 | ret_ptr, | 599 | ret_ptr, |
| ... | @@ -1066,9 +1056,6 @@ pub const Inst = struct { | ... | @@ -1066,9 +1056,6 @@ pub const Inst = struct { |
| 1066 | /// A defer statement. | 1056 | /// A defer statement. |
| 1067 | /// Uses the `defer` union field. | 1057 | /// Uses the `defer` union field. |
| 1068 | @"defer", | 1058 | @"defer", |
| 1069 | /// An errdefer statement with a code. | ||
| 1070 | /// Uses the `err_defer_code` union field. | ||
| 1071 | defer_err_code, | ||
| 1072 | 1059 | ||
| 1073 | /// Requests that Sema update the saved error return trace index for the enclosing | 1060 | /// Requests that Sema update the saved error return trace index for the enclosing |
| 1074 | /// block, if the operand is .none or of an error/error-union type. | 1061 | /// block, if the operand is .none or of an error/error-union type. |
| ... | @@ -1112,7 +1099,6 @@ pub const Inst = struct { | ... | @@ -1112,7 +1099,6 @@ pub const Inst = struct { |
| 1112 | .alloc_inferred_comptime_mut, | 1099 | .alloc_inferred_comptime_mut, |
| 1113 | .make_ptr_const, | 1100 | .make_ptr_const, |
| 1114 | .array_cat, | 1101 | .array_cat, |
| 1115 | .array_mul, | ||
| 1116 | .array_type, | 1102 | .array_type, |
| 1117 | .array_type_sentinel, | 1103 | .array_type_sentinel, |
| 1118 | .reify_int, | 1104 | .reify_int, |
| ... | @@ -1295,14 +1281,12 @@ pub const Inst = struct { | ... | @@ -1295,14 +1281,12 @@ pub const Inst = struct { |
| 1295 | .memmove, | 1281 | .memmove, |
| 1296 | .min, | 1282 | .min, |
| 1297 | .@"resume", | 1283 | .@"resume", |
| 1298 | .ret_err_value_code, | ||
| 1299 | .extended, | 1284 | .extended, |
| 1300 | .ret_ptr, | 1285 | .ret_ptr, |
| 1301 | .ret_type, | 1286 | .ret_type, |
| 1302 | .@"try", | 1287 | .@"try", |
| 1303 | .try_ptr, | 1288 | .try_ptr, |
| 1304 | .@"defer", | 1289 | .@"defer", |
| 1305 | .defer_err_code, | ||
| 1306 | .save_err_ret_index, | 1290 | .save_err_ret_index, |
| 1307 | .for_len, | 1291 | .for_len, |
| 1308 | .opt_eu_base_ptr_init, | 1292 | .opt_eu_base_ptr_init, |
| ... | @@ -1377,7 +1361,6 @@ pub const Inst = struct { | ... | @@ -1377,7 +1361,6 @@ pub const Inst = struct { |
| 1377 | .memmove, | 1361 | .memmove, |
| 1378 | .check_comptime_control_flow, | 1362 | .check_comptime_control_flow, |
| 1379 | .@"defer", | 1363 | .@"defer", |
| 1380 | .defer_err_code, | ||
| 1381 | .save_err_ret_index, | 1364 | .save_err_ret_index, |
| 1382 | .restore_err_ret_index_unconditional, | 1365 | .restore_err_ret_index_unconditional, |
| 1383 | .restore_err_ret_index_fn_entry, | 1366 | .restore_err_ret_index_fn_entry, |
| ... | @@ -1409,7 +1392,6 @@ pub const Inst = struct { | ... | @@ -1409,7 +1392,6 @@ pub const Inst = struct { |
| 1409 | .resolve_inferred_alloc, | 1392 | .resolve_inferred_alloc, |
| 1410 | .make_ptr_const, | 1393 | .make_ptr_const, |
| 1411 | .array_cat, | 1394 | .array_cat, |
| 1412 | .array_mul, | ||
| 1413 | .array_type, | 1395 | .array_type, |
| 1414 | .array_type_sentinel, | 1396 | .array_type_sentinel, |
| 1415 | .reify_int, | 1397 | .reify_int, |
| ... | @@ -1574,7 +1556,6 @@ pub const Inst = struct { | ... | @@ -1574,7 +1556,6 @@ pub const Inst = struct { |
| 1574 | .max, | 1556 | .max, |
| 1575 | .min, | 1557 | .min, |
| 1576 | .@"resume", | 1558 | .@"resume", |
| 1577 | .ret_err_value_code, | ||
| 1578 | .@"break", | 1559 | .@"break", |
| 1579 | .break_inline, | 1560 | .break_inline, |
| 1580 | .condbr, | 1561 | .condbr, |
| ... | @@ -1644,7 +1625,6 @@ pub const Inst = struct { | ... | @@ -1644,7 +1625,6 @@ pub const Inst = struct { |
| 1644 | .param_anytype = .str_tok, | 1625 | .param_anytype = .str_tok, |
| 1645 | .param_anytype_comptime = .str_tok, | 1626 | .param_anytype_comptime = .str_tok, |
| 1646 | .array_cat = .pl_node, | 1627 | .array_cat = .pl_node, |
| 1647 | .array_mul = .pl_node, | ||
| 1648 | .array_type = .pl_node, | 1628 | .array_type = .pl_node, |
| 1649 | .array_type_sentinel = .pl_node, | 1629 | .array_type_sentinel = .pl_node, |
| 1650 | .reify_int = .pl_node, | 1630 | .reify_int = .pl_node, |
| ... | @@ -1732,7 +1712,6 @@ pub const Inst = struct { | ... | @@ -1732,7 +1712,6 @@ pub const Inst = struct { |
| 1732 | .ret_load = .un_node, | 1712 | .ret_load = .un_node, |
| 1733 | .ret_implicit = .un_tok, | 1713 | .ret_implicit = .un_tok, |
| 1734 | .ret_err_value = .str_tok, | 1714 | .ret_err_value = .str_tok, |
| 1735 | .ret_err_value_code = .str_tok, | ||
| 1736 | .ret_ptr = .node, | 1715 | .ret_ptr = .node, |
| 1737 | .ret_type = .node, | 1716 | .ret_type = .node, |
| 1738 | .ptr_type = .ptr_type, | 1717 | .ptr_type = .ptr_type, |
| ... | @@ -1866,7 +1845,6 @@ pub const Inst = struct { | ... | @@ -1866,7 +1845,6 @@ pub const Inst = struct { |
| 1866 | .@"resume" = .un_node, | 1845 | .@"resume" = .un_node, |
| 1867 | 1846 | ||
| 1868 | .@"defer" = .@"defer", | 1847 | .@"defer" = .@"defer", |
| 1869 | .defer_err_code = .defer_err_code, | ||
| 1870 | 1848 | ||
| 1871 | .save_err_ret_index = .save_err_ret_index, | 1849 | .save_err_ret_index = .save_err_ret_index, |
| 1872 | .restore_err_ret_index_unconditional = .un_node, | 1850 | .restore_err_ret_index_unconditional = .un_node, |
| ... | @@ -2213,7 +2191,6 @@ pub const Inst = struct { | ... | @@ -2213,7 +2191,6 @@ pub const Inst = struct { |
| 2213 | /// and `[]Ref`. | 2191 | /// and `[]Ref`. |
| 2214 | pub const Ref = enum(u32) { | 2192 | pub const Ref = enum(u32) { |
| 2215 | u0_type, | 2193 | u0_type, |
| 2216 | i0_type, | ||
| 2217 | u1_type, | 2194 | u1_type, |
| 2218 | u8_type, | 2195 | u8_type, |
| 2219 | i8_type, | 2196 | i8_type, |
| ... | @@ -2484,10 +2461,6 @@ pub const Inst = struct { | ... | @@ -2484,10 +2461,6 @@ pub const Inst = struct { |
| 2484 | index: u32, | 2461 | index: u32, |
| 2485 | len: u32, | 2462 | len: u32, |
| 2486 | }, | 2463 | }, |
| 2487 | defer_err_code: struct { | ||
| 2488 | err_code: Ref, | ||
| 2489 | payload_index: u32, | ||
| 2490 | }, | ||
| 2491 | save_err_ret_index: struct { | 2464 | save_err_ret_index: struct { |
| 2492 | operand: Ref, // If error type (or .none), save new trace index | 2465 | operand: Ref, // If error type (or .none), save new trace index |
| 2493 | }, | 2466 | }, |
| ... | @@ -2538,7 +2511,6 @@ pub const Inst = struct { | ... | @@ -2538,7 +2511,6 @@ pub const Inst = struct { |
| 2538 | inst_node, | 2511 | inst_node, |
| 2539 | str_op, | 2512 | str_op, |
| 2540 | @"defer", | 2513 | @"defer", |
| 2541 | defer_err_code, | ||
| 2542 | save_err_ret_index, | 2514 | save_err_ret_index, |
| 2543 | elem_val_imm, | 2515 | elem_val_imm, |
| 2544 | declaration, | 2516 | declaration, |
| ... | @@ -3974,12 +3946,6 @@ pub const Inst = struct { | ... | @@ -3974,12 +3946,6 @@ pub const Inst = struct { |
| 3974 | column: u32, | 3946 | column: u32, |
| 3975 | }; | 3947 | }; |
| 3976 | 3948 | ||
| 3977 | pub const DeferErrCode = struct { | ||
| 3978 | remapped_err_code: Index, | ||
| 3979 | index: u32, | ||
| 3980 | len: u32, | ||
| 3981 | }; | ||
| 3982 | |||
| 3983 | pub const ValidateDestructure = struct { | 3949 | pub const ValidateDestructure = struct { |
| 3984 | /// The value being destructured. | 3950 | /// The value being destructured. |
| 3985 | operand: Ref, | 3951 | operand: Ref, |
| ... | @@ -3989,15 +3955,6 @@ pub const Inst = struct { | ... | @@ -3989,15 +3955,6 @@ pub const Inst = struct { |
| 3989 | expect_len: u32, | 3955 | expect_len: u32, |
| 3990 | }; | 3956 | }; |
| 3991 | 3957 | ||
| 3992 | pub const ArrayMul = struct { | ||
| 3993 | /// The result type of the array multiplication operation, or `.none` if none was available. | ||
| 3994 | res_ty: Ref, | ||
| 3995 | /// The LHS of the array multiplication. | ||
| 3996 | lhs: Ref, | ||
| 3997 | /// The RHS of the array multiplication. | ||
| 3998 | rhs: Ref, | ||
| 3999 | }; | ||
| 4000 | |||
| 4001 | pub const RestoreErrRetIndex = struct { | 3958 | pub const RestoreErrRetIndex = struct { |
| 4002 | src_node: Ast.Node.Offset, | 3959 | src_node: Ast.Node.Offset, |
| 4003 | /// If `.none`, restore the trace to its state upon function entry. | 3960 | /// If `.none`, restore the trace to its state upon function entry. |
| ... | @@ -4149,7 +4106,6 @@ fn findTrackableInner( | ... | @@ -4149,7 +4106,6 @@ fn findTrackableInner( |
| 4149 | .param_anytype, | 4106 | .param_anytype, |
| 4150 | .param_anytype_comptime, | 4107 | .param_anytype_comptime, |
| 4151 | .array_cat, | 4108 | .array_cat, |
| 4152 | .array_mul, | ||
| 4153 | .array_type, | 4109 | .array_type, |
| 4154 | .array_type_sentinel, | 4110 | .array_type_sentinel, |
| 4155 | .reify_int, | 4111 | .reify_int, |
| ... | @@ -4222,7 +4178,6 @@ fn findTrackableInner( | ... | @@ -4222,7 +4178,6 @@ fn findTrackableInner( |
| 4222 | .ret_load, | 4178 | .ret_load, |
| 4223 | .ret_implicit, | 4179 | .ret_implicit, |
| 4224 | .ret_err_value, | 4180 | .ret_err_value, |
| 4225 | .ret_err_value_code, | ||
| 4226 | .ret_ptr, | 4181 | .ret_ptr, |
| 4227 | .ret_type, | 4182 | .ret_type, |
| 4228 | .ptr_type, | 4183 | .ptr_type, |
| ... | @@ -4621,15 +4576,6 @@ fn findTrackableInner( | ... | @@ -4621,15 +4576,6 @@ fn findTrackableInner( |
| 4621 | try zir.findTrackableBody(gpa, contents, defers, body); | 4576 | try zir.findTrackableBody(gpa, contents, defers, body); |
| 4622 | } | 4577 | } |
| 4623 | }, | 4578 | }, |
| 4624 | .defer_err_code => { | ||
| 4625 | const inst_data = datas[@intFromEnum(inst)].defer_err_code; | ||
| 4626 | const extra = zir.extraData(Inst.DeferErrCode, inst_data.payload_index).data; | ||
| 4627 | const gop = try defers.getOrPut(gpa, extra.index); | ||
| 4628 | if (!gop.found_existing) { | ||
| 4629 | const body = zir.bodySlice(extra.index, extra.len); | ||
| 4630 | try zir.findTrackableBody(gpa, contents, defers, body); | ||
| 4631 | } | ||
| 4632 | }, | ||
| 4633 | } | 4579 | } |
| 4634 | } | 4580 | } |
| 4635 | 4581 |
lib/std/zig/ZonGen.zig-1| ... | @@ -166,7 +166,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator | ... | @@ -166,7 +166,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator |
| 166 | .less_than, | 166 | .less_than, |
| 167 | .less_or_equal, | 167 | .less_or_equal, |
| 168 | .array_cat, | 168 | .array_cat, |
| 169 | .array_mult, | ||
| 170 | .bool_and, | 169 | .bool_and, |
| 171 | .bool_or, | 170 | .bool_or, |
| 172 | .bool_not, | 171 | .bool_not, |
lib/std/zig/llvm/Builder.zig+3-7| ... | @@ -7628,9 +7628,7 @@ pub const Constant = enum(u32) { | ... | @@ -7628,9 +7628,7 @@ pub const Constant = enum(u32) { |
| 7628 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); | 7628 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); |
| 7629 | string: [ | 7629 | string: [ |
| 7630 | (std.math.big.int.Const{ | 7630 | (std.math.big.int.Const{ |
| 7631 | .limbs = &([1]std.math.big.Limb{ | 7631 | .limbs = &@as([expected_limbs]std.math.big.Limb, @splat(maxInt(std.math.big.Limb))), |
| 7632 | maxInt(std.math.big.Limb), | ||
| 7633 | } ** expected_limbs), | ||
| 7634 | .positive = false, | 7632 | .positive = false, |
| 7635 | }).sizeInBaseUpperBound(10) | 7633 | }).sizeInBaseUpperBound(10) |
| 7636 | ]u8, | 7634 | ]u8, |
| ... | @@ -9347,7 +9345,7 @@ pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant { | ... | @@ -9347,7 +9345,7 @@ pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant { |
| 9347 | .double => try self.doubleConst(std.math.nan(f64)), | 9345 | .double => try self.doubleConst(std.math.nan(f64)), |
| 9348 | .fp128 => try self.fp128Const(std.math.nan(f128)), | 9346 | .fp128 => try self.fp128Const(std.math.nan(f128)), |
| 9349 | .x86_fp80 => try self.x86_fp80Const(std.math.nan(f80)), | 9347 | .x86_fp80 => try self.x86_fp80Const(std.math.nan(f80)), |
| 9350 | .ppc_fp128 => try self.ppc_fp128Const(.{std.math.nan(f64)} ** 2), | 9348 | .ppc_fp128 => try self.ppc_fp128Const(@splat(.{std.math.nan(f64)})), |
| 9351 | else => unreachable, | 9349 | else => unreachable, |
| 9352 | }; | 9350 | }; |
| 9353 | } | 9351 | } |
| ... | @@ -10597,9 +10595,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void | ... | @@ -10597,9 +10595,7 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void |
| 10597 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); | 10595 | const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb)); |
| 10598 | string: [ | 10596 | string: [ |
| 10599 | (std.math.big.int.Const{ | 10597 | (std.math.big.int.Const{ |
| 10600 | .limbs = &([1]std.math.big.Limb{ | 10598 | .limbs = &@as([expected_limbs]std.math.big.Limb, @splat(maxInt(std.math.big.Limb))), |
| 10601 | maxInt(std.math.big.Limb), | ||
| 10602 | } ** expected_limbs), | ||
| 10603 | .positive = false, | 10599 | .positive = false, |
| 10604 | }).sizeInBaseUpperBound(10) | 10600 | }).sizeInBaseUpperBound(10) |
| 10605 | ]u8, | 10601 | ]u8, |
lib/std/zig/parser_test.zig+3-43| ... | @@ -298,19 +298,6 @@ test "zig fmt: decl between fields" { | ... | @@ -298,19 +298,6 @@ test "zig fmt: decl between fields" { |
| 298 | }); | 298 | }); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | test "zig fmt: errdefer with payload" { | ||
| 302 | try testCanonical( | ||
| 303 | \\pub fn main() anyerror!void { | ||
| 304 | \\ errdefer |a| x += 1; | ||
| 305 | \\ errdefer |a| {} | ||
| 306 | \\ errdefer |a| { | ||
| 307 | \\ x += 1; | ||
| 308 | \\ } | ||
| 309 | \\} | ||
| 310 | \\ | ||
| 311 | ); | ||
| 312 | } | ||
| 313 | |||
| 314 | test "zig fmt: nosuspend block" { | 301 | test "zig fmt: nosuspend block" { |
| 315 | try testCanonical( | 302 | try testCanonical( |
| 316 | \\pub fn main() anyerror!void { | 303 | \\pub fn main() anyerror!void { |
| ... | @@ -2777,13 +2764,6 @@ test "zig fmt: comments before var decl in struct" { | ... | @@ -2777,13 +2764,6 @@ test "zig fmt: comments before var decl in struct" { |
| 2777 | ); | 2764 | ); |
| 2778 | } | 2765 | } |
| 2779 | 2766 | ||
| 2780 | test "zig fmt: array literal with 1 item on 1 line" { | ||
| 2781 | try testCanonical( | ||
| 2782 | \\var s = []const u64{0} ** 25; | ||
| 2783 | \\ | ||
| 2784 | ); | ||
| 2785 | } | ||
| 2786 | |||
| 2787 | test "zig fmt: comments before global variables" { | 2767 | test "zig fmt: comments before global variables" { |
| 2788 | try testCanonical( | 2768 | try testCanonical( |
| 2789 | \\/// Foo copies keys and values before they go into the map, and | 2769 | \\/// Foo copies keys and values before they go into the map, and |
| ... | @@ -2924,7 +2904,7 @@ test "zig fmt: function attributes" { | ... | @@ -2924,7 +2904,7 @@ test "zig fmt: function attributes" { |
| 2924 | ); | 2904 | ); |
| 2925 | } | 2905 | } |
| 2926 | 2906 | ||
| 2927 | test "zig fmt: nested pointers with ** tokens" { | 2907 | test "zig fmt: deeply nested pointers" { |
| 2928 | try testCanonical( | 2908 | try testCanonical( |
| 2929 | \\const x: *u32 = undefined; | 2909 | \\const x: *u32 = undefined; |
| 2930 | \\const x: **u32 = undefined; | 2910 | \\const x: **u32 = undefined; |
| ... | @@ -3014,7 +2994,6 @@ test "zig fmt: infix operators" { | ... | @@ -3014,7 +2994,6 @@ test "zig fmt: infix operators" { |
| 3014 | \\ _ = i.i; | 2994 | \\ _ = i.i; |
| 3015 | \\ _ = i || i; | 2995 | \\ _ = i || i; |
| 3016 | \\ _ = i!i; | 2996 | \\ _ = i!i; |
| 3017 | \\ _ = i ** i; | ||
| 3018 | \\ _ = i ++ i; | 2997 | \\ _ = i ++ i; |
| 3019 | \\ _ = i orelse i; | 2998 | \\ _ = i orelse i; |
| 3020 | \\ _ = i % i; | 2999 | \\ _ = i % i; |
| ... | @@ -4578,7 +4557,7 @@ test "zig fmt: integer literals with underscore separators" { | ... | @@ -4578,7 +4557,7 @@ test "zig fmt: integer literals with underscore separators" { |
| 4578 | test "zig fmt: hex literals with underscore separators" { | 4557 | test "zig fmt: hex literals with underscore separators" { |
| 4579 | try testTransform( | 4558 | try testTransform( |
| 4580 | \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { | 4559 | \\pub fn orMask(a: [ 1_000 ]u64, b: [ 1_000] u64) [1_000]u64 { |
| 4581 | \\ var c: [1_000]u64 = [1]u64{ 0xFFFF_FFFF_FFFF_FFFF}**1_000; | 4560 | \\ var c: [1_000]u64 = @splat(0xFFFF_FFFF_FFFF_FFFF); |
| 4582 | \\ for (c [ 1_0 .. ], 0..) |_, i| { | 4561 | \\ for (c [ 1_0 .. ], 0..) |_, i| { |
| 4583 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; | 4562 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 4584 | \\ } | 4563 | \\ } |
| ... | @@ -4588,7 +4567,7 @@ test "zig fmt: hex literals with underscore separators" { | ... | @@ -4588,7 +4567,7 @@ test "zig fmt: hex literals with underscore separators" { |
| 4588 | \\ | 4567 | \\ |
| 4589 | , | 4568 | , |
| 4590 | \\pub fn orMask(a: [1_000]u64, b: [1_000]u64) [1_000]u64 { | 4569 | \\pub fn orMask(a: [1_000]u64, b: [1_000]u64) [1_000]u64 { |
| 4591 | \\ var c: [1_000]u64 = [1]u64{0xFFFF_FFFF_FFFF_FFFF} ** 1_000; | 4570 | \\ var c: [1_000]u64 = @splat(0xFFFF_FFFF_FFFF_FFFF); |
| 4592 | \\ for (c[1_0..], 0..) |_, i| { | 4571 | \\ for (c[1_0..], 0..) |_, i| { |
| 4593 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; | 4572 | \\ c[i] = (a[i] | b[i]) & 0xCCAA_CCAA_CCAA_CCAA; |
| 4594 | \\ } | 4573 | \\ } |
| ... | @@ -7096,25 +7075,6 @@ test "recovery: invalid global error set access" { | ... | @@ -7096,25 +7075,6 @@ test "recovery: invalid global error set access" { |
| 7096 | }); | 7075 | }); |
| 7097 | } | 7076 | } |
| 7098 | 7077 | ||
| 7099 | test "recovery: invalid asterisk after pointer dereference" { | ||
| 7100 | try testError( | ||
| 7101 | \\test "" { | ||
| 7102 | \\ var sequence = "repeat".*** 10; | ||
| 7103 | \\} | ||
| 7104 | , &[_]Error{ | ||
| 7105 | .asterisk_after_ptr_deref, | ||
| 7106 | .mismatched_binary_op_whitespace, | ||
| 7107 | }); | ||
| 7108 | try testError( | ||
| 7109 | \\test "" { | ||
| 7110 | \\ var sequence = "repeat".** 10&a; | ||
| 7111 | \\} | ||
| 7112 | , &[_]Error{ | ||
| 7113 | .asterisk_after_ptr_deref, | ||
| 7114 | .mismatched_binary_op_whitespace, | ||
| 7115 | }); | ||
| 7116 | } | ||
| 7117 | |||
| 7118 | test "recovery: missing semicolon after if, for, while stmt" { | 7078 | test "recovery: missing semicolon after if, for, while stmt" { |
| 7119 | try testError( | 7079 | try testError( |
| 7120 | \\test "" { | 7080 | \\test "" { |
lib/std/zig/tokenizer.zig+4-43| ... | @@ -64,7 +64,6 @@ pub const Token = struct { | ... | @@ -64,7 +64,6 @@ pub const Token = struct { |
| 64 | 64 | ||
| 65 | pub const Tag = enum { | 65 | pub const Tag = enum { |
| 66 | invalid, | 66 | invalid, |
| 67 | invalid_periodasterisks, | ||
| 68 | identifier, | 67 | identifier, |
| 69 | string_literal, | 68 | string_literal, |
| 70 | multiline_string_literal_line, | 69 | multiline_string_literal_line, |
| ... | @@ -109,7 +108,6 @@ pub const Token = struct { | ... | @@ -109,7 +108,6 @@ pub const Token = struct { |
| 109 | minus_pipe_equal, | 108 | minus_pipe_equal, |
| 110 | asterisk, | 109 | asterisk, |
| 111 | asterisk_equal, | 110 | asterisk_equal, |
| 112 | asterisk_asterisk, | ||
| 113 | asterisk_percent, | 111 | asterisk_percent, |
| 114 | asterisk_percent_equal, | 112 | asterisk_percent_equal, |
| 115 | asterisk_pipe, | 113 | asterisk_pipe, |
| ... | @@ -197,7 +195,6 @@ pub const Token = struct { | ... | @@ -197,7 +195,6 @@ pub const Token = struct { |
| 197 | .container_doc_comment, | 195 | .container_doc_comment, |
| 198 | => null, | 196 | => null, |
| 199 | 197 | ||
| 200 | .invalid_periodasterisks => ".**", | ||
| 201 | .bang => "!", | 198 | .bang => "!", |
| 202 | .pipe => "|", | 199 | .pipe => "|", |
| 203 | .pipe_pipe => "||", | 200 | .pipe_pipe => "||", |
| ... | @@ -236,7 +233,6 @@ pub const Token = struct { | ... | @@ -236,7 +233,6 @@ pub const Token = struct { |
| 236 | .minus_pipe_equal => "-|=", | 233 | .minus_pipe_equal => "-|=", |
| 237 | .asterisk => "*", | 234 | .asterisk => "*", |
| 238 | .asterisk_equal => "*=", | 235 | .asterisk_equal => "*=", |
| 239 | .asterisk_asterisk => "**", | ||
| 240 | .asterisk_percent => "*%", | 236 | .asterisk_percent => "*%", |
| 241 | .asterisk_percent_equal => "*%=", | 237 | .asterisk_percent_equal => "*%=", |
| 242 | .asterisk_pipe => "*|", | 238 | .asterisk_pipe => "*|", |
| ... | @@ -386,7 +382,6 @@ pub const Tokenizer = struct { | ... | @@ -386,7 +382,6 @@ pub const Tokenizer = struct { |
| 386 | angle_bracket_angle_bracket_right, | 382 | angle_bracket_angle_bracket_right, |
| 387 | period, | 383 | period, |
| 388 | period_2, | 384 | period_2, |
| 389 | period_asterisk, | ||
| 390 | saw_at_sign, | 385 | saw_at_sign, |
| 391 | invalid, | 386 | invalid, |
| 392 | }; | 387 | }; |
| ... | @@ -569,10 +564,6 @@ pub const Tokenizer = struct { | ... | @@ -569,10 +564,6 @@ pub const Tokenizer = struct { |
| 569 | result.tag = .asterisk_equal; | 564 | result.tag = .asterisk_equal; |
| 570 | self.index += 1; | 565 | self.index += 1; |
| 571 | }, | 566 | }, |
| 572 | '*' => { | ||
| 573 | result.tag = .asterisk_asterisk; | ||
| 574 | self.index += 1; | ||
| 575 | }, | ||
| 576 | '%' => continue :state .asterisk_percent, | 567 | '%' => continue :state .asterisk_percent, |
| 577 | '|' => continue :state .asterisk_pipe, | 568 | '|' => continue :state .asterisk_pipe, |
| 578 | else => result.tag = .asterisk, | 569 | else => result.tag = .asterisk, |
| ... | @@ -915,7 +906,10 @@ pub const Tokenizer = struct { | ... | @@ -915,7 +906,10 @@ pub const Tokenizer = struct { |
| 915 | self.index += 1; | 906 | self.index += 1; |
| 916 | switch (self.buffer[self.index]) { | 907 | switch (self.buffer[self.index]) { |
| 917 | '.' => continue :state .period_2, | 908 | '.' => continue :state .period_2, |
| 918 | '*' => continue :state .period_asterisk, | 909 | '*' => { |
| 910 | result.tag = .period_asterisk; | ||
| 911 | self.index += 1; | ||
| 912 | }, | ||
| 919 | else => result.tag = .period, | 913 | else => result.tag = .period, |
| 920 | } | 914 | } |
| 921 | }, | 915 | }, |
| ... | @@ -931,14 +925,6 @@ pub const Tokenizer = struct { | ... | @@ -931,14 +925,6 @@ pub const Tokenizer = struct { |
| 931 | } | 925 | } |
| 932 | }, | 926 | }, |
| 933 | 927 | ||
| 934 | .period_asterisk => { | ||
| 935 | self.index += 1; | ||
| 936 | switch (self.buffer[self.index]) { | ||
| 937 | '*' => result.tag = .invalid_periodasterisks, | ||
| 938 | else => result.tag = .period_asterisk, | ||
| 939 | } | ||
| 940 | }, | ||
| 941 | |||
| 942 | .slash => { | 928 | .slash => { |
| 943 | self.index += 1; | 929 | self.index += 1; |
| 944 | switch (self.buffer[self.index]) { | 930 | switch (self.buffer[self.index]) { |
| ... | @@ -1343,31 +1329,6 @@ test "correctly parse pointer assignment" { | ... | @@ -1343,31 +1329,6 @@ test "correctly parse pointer assignment" { |
| 1343 | }); | 1329 | }); |
| 1344 | } | 1330 | } |
| 1345 | 1331 | ||
| 1346 | test "correctly parse pointer dereference followed by asterisk" { | ||
| 1347 | try testTokenize("\"b\".* ** 10", &.{ | ||
| 1348 | .string_literal, | ||
| 1349 | .period_asterisk, | ||
| 1350 | .asterisk_asterisk, | ||
| 1351 | .number_literal, | ||
| 1352 | }); | ||
| 1353 | |||
| 1354 | try testTokenize("(\"b\".*)** 10", &.{ | ||
| 1355 | .l_paren, | ||
| 1356 | .string_literal, | ||
| 1357 | .period_asterisk, | ||
| 1358 | .r_paren, | ||
| 1359 | .asterisk_asterisk, | ||
| 1360 | .number_literal, | ||
| 1361 | }); | ||
| 1362 | |||
| 1363 | try testTokenize("\"b\".*** 10", &.{ | ||
| 1364 | .string_literal, | ||
| 1365 | .invalid_periodasterisks, | ||
| 1366 | .asterisk_asterisk, | ||
| 1367 | .number_literal, | ||
| 1368 | }); | ||
| 1369 | } | ||
| 1370 | |||
| 1371 | test "range literals" { | 1332 | test "range literals" { |
| 1372 | try testTokenize("0...9", &.{ .number_literal, .ellipsis3, .number_literal }); | 1333 | try testTokenize("0...9", &.{ .number_literal, .ellipsis3, .number_literal }); |
| 1373 | try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal }); | 1334 | try testTokenize("'0'...'9'", &.{ .char_literal, .ellipsis3, .char_literal }); |
src/Air.zig-1| ... | @@ -1032,7 +1032,6 @@ pub const Inst = struct { | ... | @@ -1032,7 +1032,6 @@ pub const Inst = struct { |
| 1032 | /// The ref `none` is an exception: it has the tag bit set but refers to the InternPool. | 1032 | /// The ref `none` is an exception: it has the tag bit set but refers to the InternPool. |
| 1033 | pub const Ref = enum(u32) { | 1033 | pub const Ref = enum(u32) { |
| 1034 | u0_type = @intFromEnum(InternPool.Index.u0_type), | 1034 | u0_type = @intFromEnum(InternPool.Index.u0_type), |
| 1035 | i0_type = @intFromEnum(InternPool.Index.i0_type), | ||
| 1036 | u1_type = @intFromEnum(InternPool.Index.u1_type), | 1035 | u1_type = @intFromEnum(InternPool.Index.u1_type), |
| 1037 | u8_type = @intFromEnum(InternPool.Index.u8_type), | 1036 | u8_type = @intFromEnum(InternPool.Index.u8_type), |
| 1038 | i8_type = @intFromEnum(InternPool.Index.i8_type), | 1037 | i8_type = @intFromEnum(InternPool.Index.i8_type), |
src/Air/Liveness.zig+4-4| ... | @@ -611,7 +611,7 @@ fn analyzeInst( | ... | @@ -611,7 +611,7 @@ fn analyzeInst( |
| 611 | const call = a.air.unwrapCall(inst); | 611 | const call = a.air.unwrapCall(inst); |
| 612 | const args = call.args; | 612 | const args = call.args; |
| 613 | if (args.len + 1 <= bpi - 1) { | 613 | if (args.len + 1 <= bpi - 1) { |
| 614 | var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1); | 614 | var buf: [bpi - 1]Air.Inst.Ref = @splat(.none); |
| 615 | buf[0] = call.callee; | 615 | buf[0] = call.callee; |
| 616 | @memcpy(buf[1..][0..args.len], args); | 616 | @memcpy(buf[1..][0..args.len], args); |
| 617 | return analyzeOperands(a, pass, data, inst, buf); | 617 | return analyzeOperands(a, pass, data, inst, buf); |
| ... | @@ -655,7 +655,7 @@ fn analyzeInst( | ... | @@ -655,7 +655,7 @@ fn analyzeInst( |
| 655 | const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra.items[ty_pl.payload..][0..len])); | 655 | const elements = @as([]const Air.Inst.Ref, @ptrCast(a.air.extra.items[ty_pl.payload..][0..len])); |
| 656 | 656 | ||
| 657 | if (elements.len <= bpi - 1) { | 657 | if (elements.len <= bpi - 1) { |
| 658 | var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1); | 658 | var buf: [bpi - 1]Air.Inst.Ref = @splat(.none); |
| 659 | @memcpy(buf[0..elements.len], elements); | 659 | @memcpy(buf[0..elements.len], elements); |
| 660 | return analyzeOperands(a, pass, data, inst, buf); | 660 | return analyzeOperands(a, pass, data, inst, buf); |
| 661 | } | 661 | } |
| ... | @@ -711,7 +711,7 @@ fn analyzeInst( | ... | @@ -711,7 +711,7 @@ fn analyzeInst( |
| 711 | const inputs = unwrapped_asm.inputs; | 711 | const inputs = unwrapped_asm.inputs; |
| 712 | 712 | ||
| 713 | const num_operands = simple: { | 713 | const num_operands = simple: { |
| 714 | var buf = [1]Air.Inst.Ref{.none} ** (bpi - 1); | 714 | var buf: [bpi - 1]Air.Inst.Ref = @splat(.none); |
| 715 | var buf_index: usize = 0; | 715 | var buf_index: usize = 0; |
| 716 | for (unwrapped_asm.outputs) |output| { | 716 | for (unwrapped_asm.outputs) |output| { |
| 717 | if (output != .none) { | 717 | if (output != .none) { |
| ... | @@ -1421,7 +1421,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type { | ... | @@ -1421,7 +1421,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type { |
| 1421 | inst: Air.Inst.Index, | 1421 | inst: Air.Inst.Index, |
| 1422 | 1422 | ||
| 1423 | operands_remaining: u32, | 1423 | operands_remaining: u32, |
| 1424 | small: [bpi - 1]Air.Inst.Ref = .{.none} ** (bpi - 1), | 1424 | small: [bpi - 1]Air.Inst.Ref = @splat(.none), |
| 1425 | extra_tombs: []u32, | 1425 | extra_tombs: []u32, |
| 1426 | 1426 | ||
| 1427 | // Only used in `LivenessPass.main_analysis` | 1427 | // Only used in `LivenessPass.main_analysis` |
src/InternPool.zig+1-8| ... | @@ -3902,7 +3902,6 @@ pub const Index = enum(u32) { | ... | @@ -3902,7 +3902,6 @@ pub const Index = enum(u32) { |
| 3902 | pub const last_value: Index = .empty_tuple; | 3902 | pub const last_value: Index = .empty_tuple; |
| 3903 | 3903 | ||
| 3904 | u0_type, | 3904 | u0_type, |
| 3905 | i0_type, | ||
| 3906 | u1_type, | 3905 | u1_type, |
| 3907 | u8_type, | 3906 | u8_type, |
| 3908 | i8_type, | 3907 | i8_type, |
| ... | @@ -4350,11 +4349,6 @@ pub const static_keys: [static_len]Key = .{ | ... | @@ -4350,11 +4349,6 @@ pub const static_keys: [static_len]Key = .{ |
| 4350 | .bits = 0, | 4349 | .bits = 0, |
| 4351 | } }, | 4350 | } }, |
| 4352 | 4351 | ||
| 4353 | .{ .int_type = .{ | ||
| 4354 | .signedness = .signed, | ||
| 4355 | .bits = 0, | ||
| 4356 | } }, | ||
| 4357 | |||
| 4358 | .{ .int_type = .{ | 4352 | .{ .int_type = .{ |
| 4359 | .signedness = .unsigned, | 4353 | .signedness = .unsigned, |
| 4360 | .bits = 1, | 4354 | .bits = 1, |
| ... | @@ -7207,6 +7201,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key: | ... | @@ -7207,6 +7201,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key: |
| 7207 | try items.ensureUnusedCapacity(1); | 7201 | try items.ensureUnusedCapacity(1); |
| 7208 | switch (key) { | 7202 | switch (key) { |
| 7209 | .int_type => |int_type| { | 7203 | .int_type => |int_type| { |
| 7204 | if (int_type.signedness == .signed) assert(int_type.bits > 0); | ||
| 7210 | const t: Tag = switch (int_type.signedness) { | 7205 | const t: Tag = switch (int_type.signedness) { |
| 7211 | .signed => .type_int_signed, | 7206 | .signed => .type_int_signed, |
| 7212 | .unsigned => .type_int_unsigned, | 7207 | .unsigned => .type_int_unsigned, |
| ... | @@ -11447,7 +11442,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { | ... | @@ -11447,7 +11442,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 11447 | // mean that the range of type indices would not be dense. | 11442 | // mean that the range of type indices would not be dense. |
| 11448 | return switch (index) { | 11443 | return switch (index) { |
| 11449 | .u0_type, | 11444 | .u0_type, |
| 11450 | .i0_type, | ||
| 11451 | .u1_type, | 11445 | .u1_type, |
| 11452 | .u8_type, | 11446 | .u8_type, |
| 11453 | .i8_type, | 11447 | .i8_type, |
| ... | @@ -11772,7 +11766,6 @@ pub fn getBackingAddrTag(ip: *const InternPool, val: Index) ?Key.Ptr.BaseAddr.Ta | ... | @@ -11772,7 +11766,6 @@ pub fn getBackingAddrTag(ip: *const InternPool, val: Index) ?Key.Ptr.BaseAddr.Ta |
| 11772 | pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId { | 11766 | pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId { |
| 11773 | return switch (index) { | 11767 | return switch (index) { |
| 11774 | .u0_type, | 11768 | .u0_type, |
| 11775 | .i0_type, | ||
| 11776 | .u1_type, | 11769 | .u1_type, |
| 11777 | .u8_type, | 11770 | .u8_type, |
| 11778 | .i8_type, | 11771 | .i8_type, |
src/Sema.zig+5-215| ... | @@ -1171,7 +1171,6 @@ fn analyzeBodyInner( | ... | @@ -1171,7 +1171,6 @@ fn analyzeBodyInner( |
| 1171 | .make_ptr_const => try sema.zirMakePtrConst(block, inst), | 1171 | .make_ptr_const => try sema.zirMakePtrConst(block, inst), |
| 1172 | .anyframe_type => try sema.zirAnyframeType(block, inst), | 1172 | .anyframe_type => try sema.zirAnyframeType(block, inst), |
| 1173 | .array_cat => try sema.zirArrayCat(block, inst), | 1173 | .array_cat => try sema.zirArrayCat(block, inst), |
| 1174 | .array_mul => try sema.zirArrayMul(block, inst), | ||
| 1175 | .array_type => try sema.zirArrayType(block, inst), | 1174 | .array_type => try sema.zirArrayType(block, inst), |
| 1176 | .array_type_sentinel => try sema.zirArrayTypeSentinel(block, inst), | 1175 | .array_type_sentinel => try sema.zirArrayTypeSentinel(block, inst), |
| 1177 | .reify_int => try sema.zirReifyInt(block, inst), | 1176 | .reify_int => try sema.zirReifyInt(block, inst), |
| ... | @@ -1245,7 +1244,6 @@ fn analyzeBodyInner( | ... | @@ -1245,7 +1244,6 @@ fn analyzeBodyInner( |
| 1245 | .optional_type => try sema.zirOptionalType(block, inst), | 1244 | .optional_type => try sema.zirOptionalType(block, inst), |
| 1246 | .ptr_type => try sema.zirPtrType(block, inst), | 1245 | .ptr_type => try sema.zirPtrType(block, inst), |
| 1247 | .ref => try sema.zirRef(block, inst), | 1246 | .ref => try sema.zirRef(block, inst), |
| 1248 | .ret_err_value_code => try sema.zirRetErrValueCode(inst), | ||
| 1249 | .shr => try sema.zirShr(block, inst, .shr), | 1247 | .shr => try sema.zirShr(block, inst, .shr), |
| 1250 | .shr_exact => try sema.zirShr(block, inst, .shr_exact), | 1248 | .shr_exact => try sema.zirShr(block, inst, .shr_exact), |
| 1251 | .slice_end => try sema.zirSliceEnd(block, inst), | 1249 | .slice_end => try sema.zirSliceEnd(block, inst), |
| ... | @@ -1969,25 +1967,6 @@ fn analyzeBodyInner( | ... | @@ -1969,25 +1967,6 @@ fn analyzeBodyInner( |
| 1969 | } | 1967 | } |
| 1970 | break :blk .void_value; | 1968 | break :blk .void_value; |
| 1971 | }, | 1969 | }, |
| 1972 | .defer_err_code => blk: { | ||
| 1973 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code; | ||
| 1974 | const extra = sema.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; | ||
| 1975 | const defer_body = sema.code.bodySlice(extra.index, extra.len); | ||
| 1976 | const err_code = sema.resolveInst(inst_data.err_code); | ||
| 1977 | try map.ensureSpaceForInstructions(sema.gpa, defer_body); | ||
| 1978 | map.putAssumeCapacity(extra.remapped_err_code, err_code); | ||
| 1979 | if (sema.analyzeBodyInner(block, defer_body)) { | ||
| 1980 | // The defer terminated noreturn - no more analysis needed. | ||
| 1981 | break; | ||
| 1982 | } else |err| switch (err) { | ||
| 1983 | error.ComptimeBreak => {}, | ||
| 1984 | else => |e| return e, | ||
| 1985 | } | ||
| 1986 | if (sema.comptime_break_inst != defer_body[defer_body.len - 1]) { | ||
| 1987 | return error.ComptimeBreak; | ||
| 1988 | } | ||
| 1989 | break :blk .void_value; | ||
| 1990 | }, | ||
| 1991 | }; | 1970 | }; |
| 1992 | 1971 | ||
| 1993 | const is_inferred_alloc = if (air_ref.toIndex()) |air_inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(air_inst)]) { | 1972 | const is_inferred_alloc = if (air_ref.toIndex()) |air_inst| switch (sema.air_instructions.items(.tag)[@intFromEnum(air_inst)]) { |
| ... | @@ -12938,29 +12917,6 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -12938,29 +12917,6 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12938 | return Air.internedToRef(result.val); | 12917 | return Air.internedToRef(result.val); |
| 12939 | } | 12918 | } |
| 12940 | 12919 | ||
| 12941 | fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | ||
| 12942 | const pt = sema.pt; | ||
| 12943 | const zcu = pt.zcu; | ||
| 12944 | const comp = zcu.comp; | ||
| 12945 | const gpa = comp.gpa; | ||
| 12946 | const io = comp.io; | ||
| 12947 | |||
| 12948 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | ||
| 12949 | const name = try zcu.intern_pool.getOrPutString( | ||
| 12950 | gpa, | ||
| 12951 | io, | ||
| 12952 | pt.tid, | ||
| 12953 | inst_data.get(sema.code), | ||
| 12954 | .no_embedded_nulls, | ||
| 12955 | ); | ||
| 12956 | _ = try pt.getErrorValue(name); | ||
| 12957 | const error_set_type = try pt.singleErrorSetType(name); | ||
| 12958 | return Air.internedToRef((try pt.intern(.{ .err = .{ | ||
| 12959 | .ty = error_set_type.toIntern(), | ||
| 12960 | .name = name, | ||
| 12961 | } }))); | ||
| 12962 | } | ||
| 12963 | |||
| 12964 | fn zirShl( | 12920 | fn zirShl( |
| 12965 | sema: *Sema, | 12921 | sema: *Sema, |
| 12966 | block: *Block, | 12922 | block: *Block, |
| ... | @@ -13904,174 +13860,6 @@ fn analyzeTupleMul( | ... | @@ -13904,174 +13860,6 @@ fn analyzeTupleMul( |
| 13904 | return block.addAggregateInit(tuple_ty, element_refs); | 13860 | return block.addAggregateInit(tuple_ty, element_refs); |
| 13905 | } | 13861 | } |
| 13906 | 13862 | ||
| 13907 | fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | ||
| 13908 | const tracy = trace(@src()); | ||
| 13909 | defer tracy.end(); | ||
| 13910 | |||
| 13911 | const pt = sema.pt; | ||
| 13912 | const zcu = pt.zcu; | ||
| 13913 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | ||
| 13914 | const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; | ||
| 13915 | const uncoerced_lhs = sema.resolveInst(extra.lhs); | ||
| 13916 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); | ||
| 13917 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); | ||
| 13918 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); | ||
| 13919 | const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node }); | ||
| 13920 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); | ||
| 13921 | |||
| 13922 | const lhs, const lhs_ty = coerced_lhs: { | ||
| 13923 | // If we have a result type, we might be able to do this more efficiently | ||
| 13924 | // by coercing the LHS first. Specifically, if we want an array or vector | ||
| 13925 | // and have a tuple, coerce the tuple immediately. | ||
| 13926 | no_coerce: { | ||
| 13927 | if (extra.res_ty == .none) break :no_coerce; | ||
| 13928 | const res_ty = try sema.resolveTypeOrPoison(block, src, extra.res_ty) orelse break :no_coerce; | ||
| 13929 | if (!uncoerced_lhs_ty.isTuple(zcu)) break :no_coerce; | ||
| 13930 | const lhs_len = uncoerced_lhs_ty.structFieldCount(zcu); | ||
| 13931 | const lhs_dest_ty = switch (res_ty.zigTypeTag(zcu)) { | ||
| 13932 | else => break :no_coerce, | ||
| 13933 | .array => try pt.arrayType(.{ | ||
| 13934 | .child = res_ty.childType(zcu).toIntern(), | ||
| 13935 | .len = lhs_len, | ||
| 13936 | .sentinel = if (res_ty.sentinel(zcu)) |s| s.toIntern() else .none, | ||
| 13937 | }), | ||
| 13938 | .vector => try pt.vectorType(.{ | ||
| 13939 | .child = res_ty.childType(zcu).toIntern(), | ||
| 13940 | .len = lhs_len, | ||
| 13941 | }), | ||
| 13942 | }; | ||
| 13943 | // Attempt to coerce to this type, but don't emit an error if it fails. Instead, | ||
| 13944 | // just exit out of this path and let the usual error happen later, so that error | ||
| 13945 | // messages are consistent. | ||
| 13946 | const coerced = sema.coerceExtra(block, lhs_dest_ty, uncoerced_lhs, lhs_src, .{ .report_err = false }) catch |err| switch (err) { | ||
| 13947 | error.NotCoercible => break :no_coerce, | ||
| 13948 | else => |e| return e, | ||
| 13949 | }; | ||
| 13950 | break :coerced_lhs .{ coerced, lhs_dest_ty }; | ||
| 13951 | } | ||
| 13952 | break :coerced_lhs .{ uncoerced_lhs, uncoerced_lhs_ty }; | ||
| 13953 | }; | ||
| 13954 | |||
| 13955 | if (lhs_ty.isTuple(zcu)) { | ||
| 13956 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | ||
| 13957 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, .usize, .{ .simple = .array_mul_factor }); | ||
| 13958 | const factor_casted = try sema.usizeCast(block, rhs_src, factor); | ||
| 13959 | return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted); | ||
| 13960 | } | ||
| 13961 | |||
| 13962 | // Analyze the lhs first, to catch the case that someone tried to do exponentiation | ||
| 13963 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse { | ||
| 13964 | const msg = msg: { | ||
| 13965 | const msg = try sema.errMsg(lhs_src, "expected indexable; found '{f}'", .{lhs_ty.fmt(pt)}); | ||
| 13966 | errdefer msg.destroy(sema.gpa); | ||
| 13967 | switch (lhs_ty.zigTypeTag(zcu)) { | ||
| 13968 | .int, .float, .comptime_float, .comptime_int, .vector => { | ||
| 13969 | try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{}); | ||
| 13970 | }, | ||
| 13971 | else => {}, | ||
| 13972 | } | ||
| 13973 | break :msg msg; | ||
| 13974 | }; | ||
| 13975 | return sema.failWithOwnedErrorMsg(block, msg); | ||
| 13976 | }; | ||
| 13977 | |||
| 13978 | // In `**` rhs must be comptime-known, but lhs can be runtime-known | ||
| 13979 | const factor = try sema.resolveInt(block, rhs_src, extra.rhs, .usize, .{ .simple = .array_mul_factor }); | ||
| 13980 | |||
| 13981 | const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch | ||
| 13982 | return sema.fail(block, rhs_src, "operation results in overflow", .{}); | ||
| 13983 | const result_len = try sema.usizeCast(block, src, result_len_u64); | ||
| 13984 | |||
| 13985 | const result_ty = try pt.arrayType(.{ | ||
| 13986 | .len = result_len, | ||
| 13987 | .sentinel = if (lhs_info.sentinel) |s| s.toIntern() else .none, | ||
| 13988 | .child = lhs_info.elem_type.toIntern(), | ||
| 13989 | }); | ||
| 13990 | |||
| 13991 | const ptr_addrspace = if (lhs_ty.zigTypeTag(zcu) == .pointer) lhs_ty.ptrAddressSpace(zcu) else null; | ||
| 13992 | const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len); | ||
| 13993 | |||
| 13994 | if (sema.resolveValue(lhs)) |lhs_val| ct: { | ||
| 13995 | const lhs_sub_val = if (lhs_ty.isSinglePointer(zcu)) | ||
| 13996 | try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty) orelse break :ct | ||
| 13997 | else if (lhs_ty.isSlice(zcu)) | ||
| 13998 | try sema.maybeDerefSliceAsArray(block, lhs_src, lhs_val) orelse break :ct | ||
| 13999 | else | ||
| 14000 | lhs_val; | ||
| 14001 | |||
| 14002 | const val = v: { | ||
| 14003 | // Optimization for the common pattern of a single element repeated N times, such | ||
| 14004 | // as zero-filling a byte array. | ||
| 14005 | if (lhs_len == 1 and lhs_info.sentinel == null) { | ||
| 14006 | const elem_val = try lhs_sub_val.elemValue(pt, 0); | ||
| 14007 | break :v try pt.aggregateSplatValue(result_ty, elem_val); | ||
| 14008 | } | ||
| 14009 | |||
| 14010 | const element_vals = try sema.arena.alloc(InternPool.Index, result_len); | ||
| 14011 | var elem_i: usize = 0; | ||
| 14012 | while (elem_i < result_len) { | ||
| 14013 | var lhs_i: usize = 0; | ||
| 14014 | while (lhs_i < lhs_len) : (lhs_i += 1) { | ||
| 14015 | const elem_val = try lhs_sub_val.elemValue(pt, lhs_i); | ||
| 14016 | element_vals[elem_i] = elem_val.toIntern(); | ||
| 14017 | elem_i += 1; | ||
| 14018 | } | ||
| 14019 | } | ||
| 14020 | break :v try pt.aggregateValue(result_ty, element_vals); | ||
| 14021 | }; | ||
| 14022 | return sema.addConstantMaybeRef(val, ptr_addrspace != null); | ||
| 14023 | } | ||
| 14024 | |||
| 14025 | try sema.requireRuntimeBlock(block, src, lhs_src); | ||
| 14026 | |||
| 14027 | // Grab all the LHS values ahead of time, rather than repeatedly emitting instructions | ||
| 14028 | // to get the same elem values. | ||
| 14029 | const lhs_vals = try sema.arena.alloc(Air.Inst.Ref, lhs_len); | ||
| 14030 | for (lhs_vals, 0..) |*lhs_val, idx| { | ||
| 14031 | const idx_ref = try pt.intRef(.usize, idx); | ||
| 14032 | lhs_val.* = try sema.elemVal(block, lhs_src, lhs, idx_ref, src, false); | ||
| 14033 | } | ||
| 14034 | |||
| 14035 | if (ptr_addrspace) |ptr_as| { | ||
| 14036 | const alloc_ty = try pt.ptrType(.{ | ||
| 14037 | .child = result_ty.toIntern(), | ||
| 14038 | .flags = .{ | ||
| 14039 | .address_space = ptr_as, | ||
| 14040 | .is_const = true, | ||
| 14041 | }, | ||
| 14042 | }); | ||
| 14043 | const alloc = try block.addTy(.alloc, alloc_ty); | ||
| 14044 | const elem_ptr_ty = try pt.ptrType(.{ | ||
| 14045 | .child = lhs_info.elem_type.toIntern(), | ||
| 14046 | .flags = .{ .address_space = ptr_as }, | ||
| 14047 | }); | ||
| 14048 | |||
| 14049 | var elem_i: usize = 0; | ||
| 14050 | while (elem_i < result_len) { | ||
| 14051 | for (lhs_vals) |lhs_val| { | ||
| 14052 | const elem_index = try pt.intRef(.usize, elem_i); | ||
| 14053 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | ||
| 14054 | try sema.storePtr2(block, src, elem_ptr, src, lhs_val, lhs_src, .store); | ||
| 14055 | elem_i += 1; | ||
| 14056 | } | ||
| 14057 | } | ||
| 14058 | if (lhs_info.sentinel) |sent_val| { | ||
| 14059 | const elem_index = try pt.intRef(.usize, result_len); | ||
| 14060 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | ||
| 14061 | const init = Air.internedToRef(sent_val.toIntern()); | ||
| 14062 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); | ||
| 14063 | } | ||
| 14064 | |||
| 14065 | return alloc; | ||
| 14066 | } | ||
| 14067 | |||
| 14068 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, result_len); | ||
| 14069 | for (0..try sema.usizeCast(block, rhs_src, factor)) |i| { | ||
| 14070 | @memcpy(element_refs[i * lhs_len ..][0..lhs_len], lhs_vals); | ||
| 14071 | } | ||
| 14072 | return block.addAggregateInit(result_ty, element_refs); | ||
| 14073 | } | ||
| 14074 | |||
| 14075 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 13863 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 14076 | const pt = sema.pt; | 13864 | const pt = sema.pt; |
| 14077 | const zcu = pt.zcu; | 13865 | const zcu = pt.zcu; |
| ... | @@ -18339,7 +18127,6 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -18339,7 +18127,6 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 18339 | switch (obj_ty.zigTypeTag(zcu)) { | 18127 | switch (obj_ty.zigTypeTag(zcu)) { |
| 18340 | .@"struct" => return sema.structInitEmpty(block, obj_ty, src, src), | 18128 | .@"struct" => return sema.structInitEmpty(block, obj_ty, src, src), |
| 18341 | .array, .vector => return sema.arrayInitEmpty(block, src, obj_ty), | 18129 | .array, .vector => return sema.arrayInitEmpty(block, src, obj_ty), |
| 18342 | .void => return Air.internedToRef(Value.void.toIntern()), | ||
| 18343 | .@"union" => return sema.fail(block, src, "union initializer must initialize one field", .{}), | 18130 | .@"union" => return sema.fail(block, src, "union initializer must initialize one field", .{}), |
| 18344 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), | 18131 | else => return sema.failWithArrayInitNotSupported(block, src, obj_ty), |
| 18345 | } | 18132 | } |
| ... | @@ -19661,6 +19448,9 @@ fn zirReifyInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19661,6 +19448,9 @@ fn zirReifyInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19661 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 19448 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 19662 | const signedness = try sema.resolveBuiltinEnum(block, signedness_src, extra.lhs, .Signedness, .{ .simple = .int_signedness }); | 19449 | const signedness = try sema.resolveBuiltinEnum(block, signedness_src, extra.lhs, .Signedness, .{ .simple = .int_signedness }); |
| 19663 | const bits: u16 = @intCast(try sema.resolveInt(block, bits_src, extra.rhs, .u16, .{ .simple = .int_bit_width })); | 19450 | const bits: u16 = @intCast(try sema.resolveInt(block, bits_src, extra.rhs, .u16, .{ .simple = .int_bit_width })); |
| 19451 | if (bits == 0 and signedness == .signed) { | ||
| 19452 | return sema.fail(block, bits_src, "signed integer cannot have bit width 0", .{}); | ||
| 19453 | } | ||
| 19664 | return .fromType(try sema.pt.intType(signedness, bits)); | 19454 | return .fromType(try sema.pt.intType(signedness, bits)); |
| 19665 | } | 19455 | } |
| 19666 | 19456 | ||
| ... | @@ -20752,7 +20542,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -20752,7 +20542,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20752 | } | 20542 | } |
| 20753 | 20543 | ||
| 20754 | try sema.requireRuntimeBlock(block, src, operand_src); | 20544 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 20755 | if (dest_scalar_ty.intInfo(zcu).bits == 0) { | 20545 | if (dest_scalar_ty.toIntern() == .u0_type) { |
| 20756 | if (block.wantSafety()) { | 20546 | if (block.wantSafety()) { |
| 20757 | // Emit an explicit safety check. We can do this one like `abs(x) < 1`. | 20547 | // Emit an explicit safety check. We can do this one like `abs(x) < 1`. |
| 20758 | const abs_ref = try block.addTyOp(.abs, operand_ty, operand); | 20548 | const abs_ref = try block.addTyOp(.abs, operand_ty, operand); |
| ... | @@ -20868,7 +20658,7 @@ fn zirRoundCast( | ... | @@ -20868,7 +20658,7 @@ fn zirRoundCast( |
| 20868 | 20658 | ||
| 20869 | try sema.requireRuntimeBlock(block, src, operand_src); | 20659 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 20870 | 20660 | ||
| 20871 | if (dest_scalar_ty.intInfo(zcu).bits == 0) { | 20661 | if (dest_scalar_ty.toIntern() == .u0_type) { |
| 20872 | if (block.wantSafety()) { | 20662 | if (block.wantSafety()) { |
| 20873 | const abs_ref = try block.addTyOp(.abs, operand_ty, operand); | 20663 | const abs_ref = try block.addTyOp(.abs, operand_ty, operand); |
| 20874 | const is_vector = dest_ty.zigTypeTag(zcu) == .vector; | 20664 | const is_vector = dest_ty.zigTypeTag(zcu) == .vector; |
src/Sema/LowerZon.zig+5-9| ... | @@ -448,16 +448,12 @@ fn lowerInt( | ... | @@ -448,16 +448,12 @@ fn lowerInt( |
| 448 | // If lhs has less than the 32 bits rhs can hold, we need to check the max and | 448 | // If lhs has less than the 32 bits rhs can hold, we need to check the max and |
| 449 | // min values | 449 | // min values |
| 450 | if (std.math.cast(u5, lhs_info.bits)) |bits| { | 450 | if (std.math.cast(u5, lhs_info.bits)) |bits| { |
| 451 | const min_int: i32 = if (lhs_info.signedness == .unsigned or bits == 0) b: { | 451 | const unsigned_bits = bits - @intFromBool(lhs_info.signedness == .signed); |
| 452 | break :b 0; | 452 | const min_int: i32 = switch (lhs_info.signedness) { |
| 453 | } else b: { | 453 | .unsigned => 0, |
| 454 | break :b -(@as(i32, 1) << (bits - 1)); | 454 | .signed => -(@as(i32, 1) << unsigned_bits), |
| 455 | }; | ||
| 456 | const max_int: i32 = if (bits == 0) b: { | ||
| 457 | break :b 0; | ||
| 458 | } else b: { | ||
| 459 | break :b (@as(i32, 1) << (bits - @intFromBool(lhs_info.signedness == .signed))) - 1; | ||
| 460 | }; | 455 | }; |
| 456 | const max_int: i32 = (@as(i32, 1) << unsigned_bits) - 1; | ||
| 461 | if (rhs < min_int or rhs > max_int) { | 457 | if (rhs < min_int or rhs > max_int) { |
| 462 | return self.fail( | 458 | return self.fail( |
| 463 | node, | 459 | node, |
src/Sema/arith.zig+9-5| ... | @@ -20,7 +20,7 @@ pub fn incrementDefinedInt( | ... | @@ -20,7 +20,7 @@ pub fn incrementDefinedInt( |
| 20 | const zcu = pt.zcu; | 20 | const zcu = pt.zcu; |
| 21 | assert(prev_val.typeOf(zcu).toIntern() == ty.toIntern()); | 21 | assert(prev_val.typeOf(zcu).toIntern() == ty.toIntern()); |
| 22 | assert(!prev_val.isUndef(zcu)); | 22 | assert(!prev_val.isUndef(zcu)); |
| 23 | if (ty.intInfo(zcu).bits == 0) { | 23 | if (ty.toIntern() == .u0_type) { |
| 24 | return .{ .overflow = true, .val = try comptimeIntAdd(sema, prev_val, .one_comptime_int) }; | 24 | return .{ .overflow = true, .val = try comptimeIntAdd(sema, prev_val, .one_comptime_int) }; |
| 25 | } | 25 | } |
| 26 | const res = try intAdd(sema, prev_val, try pt.intValue(ty, 1), ty); | 26 | const res = try intAdd(sema, prev_val, try pt.intValue(ty, 1), ty); |
| ... | @@ -1313,7 +1313,7 @@ fn bitwiseBinScalar( | ... | @@ -1313,7 +1313,7 @@ fn bitwiseBinScalar( |
| 1313 | 0b11 => return pt.undefValue(ty), | 1313 | 0b11 => return pt.undefValue(ty), |
| 1314 | }; | 1314 | }; |
| 1315 | }; | 1315 | }; |
| 1316 | if (ty.toIntern() == .u0_type or ty.toIntern() == .i0_type) return pt.intValue(ty, 0); | 1316 | if (ty.toIntern() == .u0_type) return pt.intValue(ty, 0); |
| 1317 | // zig fmt: off | 1317 | // zig fmt: off |
| 1318 | switch (op) { | 1318 | switch (op) { |
| 1319 | .@"and" => return intBitwiseAnd(sema, def_lhs, def_rhs, ty), | 1319 | .@"and" => return intBitwiseAnd(sema, def_lhs, def_rhs, ty), |
| ... | @@ -2209,9 +2209,13 @@ fn intBitwiseNot(sema: *Sema, val: Value, ty: Type) !Value { | ... | @@ -2209,9 +2209,13 @@ fn intBitwiseNot(sema: *Sema, val: Value, ty: Type) !Value { |
| 2209 | const zcu = pt.zcu; | 2209 | const zcu = pt.zcu; |
| 2210 | 2210 | ||
| 2211 | if (val.isUndef(zcu)) return pt.undefValue(ty); | 2211 | if (val.isUndef(zcu)) return pt.undefValue(ty); |
| 2212 | if (ty.toIntern() == .bool_type) return .makeBool(!val.toBool()); | 2212 | switch (ty.toIntern()) { |
| 2213 | .bool_type => return .makeBool(!val.toBool()), | ||
| 2214 | .u0_type => return val, | ||
| 2215 | else => {}, | ||
| 2216 | } | ||
| 2217 | |||
| 2213 | const info = ty.intInfo(zcu); | 2218 | const info = ty.intInfo(zcu); |
| 2214 | if (info.bits == 0) return val; | ||
| 2215 | 2219 | ||
| 2216 | var val_space: Value.BigIntSpace = undefined; | 2220 | var val_space: Value.BigIntSpace = undefined; |
| 2217 | const val_bigint = val.toBigInt(&val_space, zcu); | 2221 | const val_bigint = val.toBigInt(&val_space, zcu); |
| ... | @@ -2231,7 +2235,7 @@ fn intValueAa(sema: *Sema, ty: Type) !Value { | ... | @@ -2231,7 +2235,7 @@ fn intValueAa(sema: *Sema, ty: Type) !Value { |
| 2231 | const zcu = pt.zcu; | 2235 | const zcu = pt.zcu; |
| 2232 | 2236 | ||
| 2233 | if (ty.toIntern() == .bool_type) return .true; | 2237 | if (ty.toIntern() == .bool_type) return .true; |
| 2234 | if (ty.toIntern() == .u0_type or ty.toIntern() == .i0_type) return pt.intValue(ty, 0); | 2238 | if (ty.toIntern() == .u0_type) return pt.intValue(ty, 0); |
| 2235 | const info = ty.intInfo(zcu); | 2239 | const info = ty.intInfo(zcu); |
| 2236 | 2240 | ||
| 2237 | const buf = try sema.arena.alloc(u8, (info.bits + 7) / 8); | 2241 | const buf = try sema.arena.alloc(u8, (info.bits + 7) / 8); |
src/Type.zig+1-1| ... | @@ -2272,7 +2272,7 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { | ... | @@ -2272,7 +2272,7 @@ pub fn minInt(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { |
| 2272 | pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { | 2272 | pub fn minIntScalar(ty: Type, pt: Zcu.PerThread, dest_ty: Type) !Value { |
| 2273 | const zcu = pt.zcu; | 2273 | const zcu = pt.zcu; |
| 2274 | const info = ty.intInfo(zcu); | 2274 | const info = ty.intInfo(zcu); |
| 2275 | if (info.signedness == .unsigned or info.bits == 0) return pt.intValue(dest_ty, 0); | 2275 | if (info.signedness == .unsigned) return pt.intValue(dest_ty, 0); |
| 2276 | 2276 | ||
| 2277 | if (std.math.cast(u6, info.bits - 1)) |shift| { | 2277 | if (std.math.cast(u6, info.bits - 1)) |shift| { |
| 2278 | const n = @as(i64, std.math.minInt(i64)) >> (63 - shift); | 2278 | const n = @as(i64, std.math.minInt(i64)) >> (63 - shift); |
src/Value.zig+1-1| ... | @@ -518,9 +518,9 @@ pub fn readFromPackedMemory( | ... | @@ -518,9 +518,9 @@ pub fn readFromPackedMemory( |
| 518 | }, | 518 | }, |
| 519 | .int => { | 519 | .int => { |
| 520 | if (buffer.len == 0) return pt.intValue(ty, 0); | 520 | if (buffer.len == 0) return pt.intValue(ty, 0); |
| 521 | if (ty.toIntern() == .u0_type) return pt.intValue(ty, 0); | ||
| 521 | const int_info = ty.intInfo(zcu); | 522 | const int_info = ty.intInfo(zcu); |
| 522 | const bits = int_info.bits; | 523 | const bits = int_info.bits; |
| 523 | if (bits == 0) return pt.intValue(ty, 0); | ||
| 524 | 524 | ||
| 525 | // Fast path for integers <= u64 | 525 | // Fast path for integers <= u64 |
| 526 | if (bits <= 64) switch (int_info.signedness) { | 526 | if (bits <= 64) switch (int_info.signedness) { |
src/codegen/aarch64/Select.zig+7-5| ... | @@ -4345,7 +4345,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, | ... | @@ -4345,7 +4345,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, |
| 4345 | try isel.emit(.ldr(neg_zero_ra.q(), .{ | 4345 | try isel.emit(.ldr(neg_zero_ra.q(), .{ |
| 4346 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), | 4346 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), |
| 4347 | })); | 4347 | })); |
| 4348 | try isel.emitLiteral(&(.{0} ** 15 ++ .{0x80})); | 4348 | try isel.emitLiteral(&(@as([15]u8, @splat(0)) ++ .{0x80})); |
| 4349 | try src_mat.finish(isel); | 4349 | try src_mat.finish(isel); |
| 4350 | }, | 4350 | }, |
| 4351 | } | 4351 | } |
| ... | @@ -4425,7 +4425,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, | ... | @@ -4425,7 +4425,7 @@ pub fn body(isel: *Select, air_body: []const Air.Inst.Index) error{ OutOfMemory, |
| 4425 | try isel.emit(.ldr(neg_zero_ra.q(), .{ | 4425 | try isel.emit(.ldr(neg_zero_ra.q(), .{ |
| 4426 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), | 4426 | .literal = @intCast((isel.instructions.items.len + 1 + isel.literals.items.len) << 2), |
| 4427 | })); | 4427 | })); |
| 4428 | try isel.emitLiteral(&(.{0} ** 15 ++ .{0x80})); | 4428 | try isel.emitLiteral(&(@as([15]u8, @splat(0)) ++ .{0x80})); |
| 4429 | try src_mat.finish(isel); | 4429 | try src_mat.finish(isel); |
| 4430 | }, | 4430 | }, |
| 4431 | } | 4431 | } |
| ... | @@ -11222,14 +11222,16 @@ fn initValueAdvanced( | ... | @@ -11222,14 +11222,16 @@ fn initValueAdvanced( |
| 11222 | }; | 11222 | }; |
| 11223 | return @enumFromInt(isel.values.items.len); | 11223 | return @enumFromInt(isel.values.items.len); |
| 11224 | } | 11224 | } |
| 11225 | pub fn dumpValues(isel: *Select, which: enum { only_referenced, all }) void { | 11225 | const WhichValues = enum { only_referenced, all }; |
| 11226 | pub fn dumpValues(isel: *Select, which: WhichValues) void { | ||
| 11227 | dumpValuesInner(isel, which) catch |err| @panic(@errorName(err)); | ||
| 11228 | } | ||
| 11229 | fn dumpValuesInner(isel: *Select, which: WhichValues) !void { | ||
| 11226 | const zcu = isel.pt.zcu; | 11230 | const zcu = isel.pt.zcu; |
| 11227 | const gpa = zcu.gpa; | 11231 | const gpa = zcu.gpa; |
| 11228 | const ip = &zcu.intern_pool; | 11232 | const ip = &zcu.intern_pool; |
| 11229 | const nav = ip.getNav(isel.nav_index); | 11233 | const nav = ip.getNav(isel.nav_index); |
| 11230 | 11234 | ||
| 11231 | errdefer |err| @panic(@errorName(err)); | ||
| 11232 | |||
| 11233 | const locked_stderr = std.debug.lockStderr(&.{}); | 11235 | const locked_stderr = std.debug.lockStderr(&.{}); |
| 11234 | defer std.debug.unlockStderr(); | 11236 | defer std.debug.unlockStderr(); |
| 11235 | const stderr = &locked_stderr.file_writer.interface; | 11237 | const stderr = &locked_stderr.file_writer.interface; |
src/codegen/llvm.zig+7-3| ... | @@ -647,7 +647,11 @@ pub const Object = struct { | ... | @@ -647,7 +647,11 @@ pub const Object = struct { |
| 647 | debug_enums_fwd_ref.toOptional(), | 647 | debug_enums_fwd_ref.toOptional(), |
| 648 | debug_globals_fwd_ref.toOptional(), | 648 | debug_globals_fwd_ref.toOptional(), |
| 649 | }; | 649 | }; |
| 650 | } else .{Builder.Metadata.Optional.none} ** 3; | 650 | } else .{ |
| 651 | Builder.Metadata.Optional.none, | ||
| 652 | Builder.Metadata.Optional.none, | ||
| 653 | Builder.Metadata.Optional.none, | ||
| 654 | }; | ||
| 651 | 655 | ||
| 652 | const obj = try arena.create(Object); | 656 | const obj = try arena.create(Object); |
| 653 | obj.* = .{ | 657 | obj.* = .{ |
| ... | @@ -1439,7 +1443,7 @@ pub const Object = struct { | ... | @@ -1439,7 +1443,7 @@ pub const Object = struct { |
| 1439 | ); | 1443 | ); |
| 1440 | llvm_function.setSubprogram(subprogram, &o.builder); | 1444 | llvm_function.setSubprogram(subprogram, &o.builder); |
| 1441 | break :debug_info .{ file, subprogram }; | 1445 | break :debug_info .{ file, subprogram }; |
| 1442 | } else .{undefined} ** 2; | 1446 | } else .{ undefined, undefined }; |
| 1443 | 1447 | ||
| 1444 | const fuzz: ?FuncGen.Fuzz = f: { | 1448 | const fuzz: ?FuncGen.Fuzz = f: { |
| 1445 | if (!owner_mod.fuzz) break :f null; | 1449 | if (!owner_mod.fuzz) break :f null; |
| ... | @@ -2948,7 +2952,7 @@ pub const Object = struct { | ... | @@ -2948,7 +2952,7 @@ pub const Object = struct { |
| 2948 | const target = zcu.getTarget(); | 2952 | const target = zcu.getTarget(); |
| 2949 | const ip = &zcu.intern_pool; | 2953 | const ip = &zcu.intern_pool; |
| 2950 | return switch (t.toIntern()) { | 2954 | return switch (t.toIntern()) { |
| 2951 | .u0_type, .i0_type => unreachable, // no runtime bits | 2955 | .u0_type => unreachable, // no runtime bits |
| 2952 | inline .u1_type, | 2956 | inline .u1_type, |
| 2953 | .u8_type, | 2957 | .u8_type, |
| 2954 | .i8_type, | 2958 | .i8_type, |
src/codegen/llvm/FuncGen.zig+2-2| ... | @@ -3981,7 +3981,7 @@ fn buildFloatOp( | ... | @@ -3981,7 +3981,7 @@ fn buildFloatOp( |
| 3981 | const scalar_llvm_ty = try o.lowerType(scalar_ty); | 3981 | const scalar_llvm_ty = try o.lowerType(scalar_ty); |
| 3982 | const libc_fn = try o.getLibcFunction( | 3982 | const libc_fn = try o.getLibcFunction( |
| 3983 | fn_name, | 3983 | fn_name, |
| 3984 | ([1]Builder.Type{scalar_llvm_ty} ** 3)[0..params.len], | 3984 | @as([3]Builder.Type, @splat(scalar_llvm_ty))[0..params.len], |
| 3985 | scalar_llvm_ty, | 3985 | scalar_llvm_ty, |
| 3986 | ); | 3986 | ); |
| 3987 | if (ty.zigTypeTag(zcu) == .vector) { | 3987 | if (ty.zigTypeTag(zcu) == .vector) { |
| ... | @@ -7410,7 +7410,7 @@ fn toLlvmAtomicRmwBinOp( | ... | @@ -7410,7 +7410,7 @@ fn toLlvmAtomicRmwBinOp( |
| 7410 | 7410 | ||
| 7411 | fn minIntConst(b: *Builder, min_ty: Type, as_ty: Builder.Type, zcu: *const Zcu) Allocator.Error!Builder.Constant { | 7411 | fn minIntConst(b: *Builder, min_ty: Type, as_ty: Builder.Type, zcu: *const Zcu) Allocator.Error!Builder.Constant { |
| 7412 | const info = min_ty.intInfo(zcu); | 7412 | const info = min_ty.intInfo(zcu); |
| 7413 | if (info.signedness == .unsigned or info.bits == 0) { | 7413 | if (info.signedness == .unsigned) { |
| 7414 | return b.intConst(as_ty, 0); | 7414 | return b.intConst(as_ty, 0); |
| 7415 | } | 7415 | } |
| 7416 | if (std.math.cast(u6, info.bits - 1)) |shift| { | 7416 | if (std.math.cast(u6, info.bits - 1)) |shift| { |
src/codegen/riscv64/CodeGen.zig+5-5| ... | @@ -6230,7 +6230,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { | ... | @@ -6230,7 +6230,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { |
| 6230 | sym: SymbolOffset, | 6230 | sym: SymbolOffset, |
| 6231 | }; | 6231 | }; |
| 6232 | 6232 | ||
| 6233 | var ops: [4]Operand = .{.none} ** 4; | 6233 | var ops: [4]Operand = @splat(.none); |
| 6234 | var last_op = false; | 6234 | var last_op = false; |
| 6235 | var op_it = mem.splitAny(u8, mnem_it.rest(), ",("); | 6235 | var op_it = mem.splitAny(u8, mnem_it.rest(), ",("); |
| 6236 | next_op: for (&ops) |*op| { | 6236 | next_op: for (&ops) |*op| { |
| ... | @@ -6466,7 +6466,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { | ... | @@ -6466,7 +6466,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void { |
| 6466 | } | 6466 | } |
| 6467 | 6467 | ||
| 6468 | simple: { | 6468 | simple: { |
| 6469 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 6469 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 6470 | var buf_index: usize = 0; | 6470 | var buf_index: usize = 0; |
| 6471 | for (outputs) |output| { | 6471 | for (outputs) |output| { |
| 6472 | if (output == .none) continue; | 6472 | if (output == .none) continue; |
| ... | @@ -6581,7 +6581,7 @@ fn genInlineMemcpy( | ... | @@ -6581,7 +6581,7 @@ fn genInlineMemcpy( |
| 6581 | src_ptr: MCValue, | 6581 | src_ptr: MCValue, |
| 6582 | len: MCValue, | 6582 | len: MCValue, |
| 6583 | ) !void { | 6583 | ) !void { |
| 6584 | const regs = try func.register_manager.allocRegs(4, .{null} ** 4, abi.Registers.Integer.temporary); | 6584 | const regs = try func.register_manager.allocRegs(4, @splat(null), abi.Registers.Integer.temporary); |
| 6585 | const locks = func.register_manager.lockRegsAssumeUnused(4, regs); | 6585 | const locks = func.register_manager.lockRegsAssumeUnused(4, regs); |
| 6586 | defer for (locks) |lock| func.register_manager.unlockReg(lock); | 6586 | defer for (locks) |lock| func.register_manager.unlockReg(lock); |
| 6587 | 6587 | ||
| ... | @@ -6691,7 +6691,7 @@ fn genInlineMemset( | ... | @@ -6691,7 +6691,7 @@ fn genInlineMemset( |
| 6691 | src_value: MCValue, | 6691 | src_value: MCValue, |
| 6692 | len: MCValue, | 6692 | len: MCValue, |
| 6693 | ) !void { | 6693 | ) !void { |
| 6694 | const regs = try func.register_manager.allocRegs(3, .{null} ** 3, abi.Registers.Integer.temporary); | 6694 | const regs = try func.register_manager.allocRegs(3, @splat(null), abi.Registers.Integer.temporary); |
| 6695 | const locks = func.register_manager.lockRegsAssumeUnused(3, regs); | 6695 | const locks = func.register_manager.lockRegsAssumeUnused(3, regs); |
| 6696 | defer for (locks) |lock| func.register_manager.unlockReg(lock); | 6696 | defer for (locks) |lock| func.register_manager.unlockReg(lock); |
| 6697 | 6697 | ||
| ... | @@ -8076,7 +8076,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void { | ... | @@ -8076,7 +8076,7 @@ fn airAggregateInit(func: *Func, inst: Air.Inst.Index) !void { |
| 8076 | }; | 8076 | }; |
| 8077 | 8077 | ||
| 8078 | if (elements.len <= Air.Liveness.bpi - 1) { | 8078 | if (elements.len <= Air.Liveness.bpi - 1) { |
| 8079 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 8079 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 8080 | @memcpy(buf[0..elements.len], elements); | 8080 | @memcpy(buf[0..elements.len], elements); |
| 8081 | return func.finishAir(inst, result, buf); | 8081 | return func.finishAir(inst, result, buf); |
| 8082 | } | 8082 | } |
src/codegen/riscv64/abi.zig+1-1| ... | @@ -98,7 +98,7 @@ pub const SystemClass = enum { integer, float, memory, none }; | ... | @@ -98,7 +98,7 @@ pub const SystemClass = enum { integer, float, memory, none }; |
| 98 | /// There are a maximum of 8 possible return slots. Returned values are in | 98 | /// There are a maximum of 8 possible return slots. Returned values are in |
| 99 | /// the beginning of the array; unused slots are filled with .none. | 99 | /// the beginning of the array; unused slots are filled with .none. |
| 100 | pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass { | 100 | pub fn classifySystem(ty: Type, zcu: *Zcu) [8]SystemClass { |
| 101 | var result = [1]SystemClass{.none} ** 8; | 101 | var result: [8]SystemClass = @splat(.none); |
| 102 | const memory_class = [_]SystemClass{ | 102 | const memory_class = [_]SystemClass{ |
| 103 | .memory, .none, .none, .none, | 103 | .memory, .none, .none, .none, |
| 104 | .none, .none, .none, .none, | 104 | .none, .none, .none, .none, |
src/codegen/sparc64/CodeGen.zig+3-3| ... | @@ -833,7 +833,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -833,7 +833,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void { |
| 833 | }; | 833 | }; |
| 834 | 834 | ||
| 835 | if (elements.len <= Air.Liveness.bpi - 1) { | 835 | if (elements.len <= Air.Liveness.bpi - 1) { |
| 836 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 836 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 837 | @memcpy(buf[0..elements.len], elements); | 837 | @memcpy(buf[0..elements.len], elements); |
| 838 | return self.finishAir(inst, result, buf); | 838 | return self.finishAir(inst, result, buf); |
| 839 | } | 839 | } |
| ... | @@ -944,7 +944,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -944,7 +944,7 @@ fn airAsm(self: *Self, inst: Air.Inst.Index) !void { |
| 944 | }; | 944 | }; |
| 945 | 945 | ||
| 946 | simple: { | 946 | simple: { |
| 947 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 947 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 948 | var buf_index: usize = 0; | 948 | var buf_index: usize = 0; |
| 949 | for (outputs) |output| { | 949 | for (outputs) |output| { |
| 950 | if (output == .none) continue; | 950 | if (output == .none) continue; |
| ... | @@ -1344,7 +1344,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier | ... | @@ -1344,7 +1344,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1344 | const result = info.return_value; | 1344 | const result = info.return_value; |
| 1345 | 1345 | ||
| 1346 | if (args.len + 1 <= Air.Liveness.bpi - 1) { | 1346 | if (args.len + 1 <= Air.Liveness.bpi - 1) { |
| 1347 | var buf = [1]Air.Inst.Ref{.none} ** (Air.Liveness.bpi - 1); | 1347 | var buf: [Air.Liveness.bpi - 1]Air.Inst.Ref = @splat(.none); |
| 1348 | buf[0] = call.callee; | 1348 | buf[0] = call.callee; |
| 1349 | @memcpy(buf[1..][0..args.len], args); | 1349 | @memcpy(buf[1..][0..args.len], args); |
| 1350 | return self.finishAir(inst, result, buf); | 1350 | return self.finishAir(inst, result, buf); |
src/codegen/spirv/CodeGen.zig+2-2| ... | @@ -1327,12 +1327,12 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { | ... | @@ -1327,12 +1327,12 @@ fn resolveType(cg: *CodeGen, ty: Type, repr: Repr) Error!Id { |
| 1327 | .indirect => return try cg.resolveType(.u1, .indirect), | 1327 | .indirect => return try cg.resolveType(.u1, .indirect), |
| 1328 | }, | 1328 | }, |
| 1329 | .int => { | 1329 | .int => { |
| 1330 | const int_info = ty.intInfo(zcu); | 1330 | if (ty.toIntern() == .u0_type) { |
| 1331 | if (int_info.bits == 0) { | ||
| 1332 | assert(repr == .indirect); | 1331 | assert(repr == .indirect); |
| 1333 | if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{}); | 1332 | if (target.os.tag != .opencl) return cg.fail("cannot generate opaque type", .{}); |
| 1334 | return try cg.module.opaqueType("u0"); | 1333 | return try cg.module.opaqueType("u0"); |
| 1335 | } | 1334 | } |
| 1335 | const int_info = ty.intInfo(zcu); | ||
| 1336 | return try cg.module.intType(int_info.signedness, int_info.bits); | 1336 | return try cg.module.intType(int_info.signedness, int_info.bits); |
| 1337 | }, | 1337 | }, |
| 1338 | .@"enum" => return try cg.resolveType(ty.intTagType(zcu), repr), | 1338 | .@"enum" => return try cg.resolveType(ty.intTagType(zcu), repr), |
src/codegen/x86_64/CodeGen.zig+6-4| ... | @@ -181601,9 +181601,9 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty | ... | @@ -181601,9 +181601,9 @@ fn splitType(self: *CodeGen, comptime parts_len: usize, ty: Type) ![parts_len]Ty |
| 181601 | const ip = &zcu.intern_pool; | 181601 | const ip = &zcu.intern_pool; |
| 181602 | var parts: [parts_len]Type = undefined; | 181602 | var parts: [parts_len]Type = undefined; |
| 181603 | switch (ip.indexToKey(ty.toIntern())) { | 181603 | switch (ip.indexToKey(ty.toIntern())) { |
| 181604 | .vector_type => |vector_type| if (std.math.divExact(u32, vector_type.len, parts_len)) |vec_len| return .{ | 181604 | .vector_type => |vector_type| if (std.math.divExact(u32, vector_type.len, parts_len)) |vec_len| { |
| 181605 | try pt.vectorType(.{ .len = vec_len, .child = vector_type.child }), | 181605 | return @splat(try pt.vectorType(.{ .len = vec_len, .child = vector_type.child })); |
| 181606 | } ** parts_len else |err| switch (err) { | 181606 | } else |err| switch (err) { |
| 181607 | error.DivisionByZero => unreachable, | 181607 | error.DivisionByZero => unreachable, |
| 181608 | error.UnexpectedRemainder => {}, | 181608 | error.UnexpectedRemainder => {}, |
| 181609 | }, | 181609 | }, |
| ... | @@ -188774,7 +188774,9 @@ const Select = struct { | ... | @@ -188774,7 +188774,9 @@ const Select = struct { |
| 188774 | try pt.aggregateValue(try pt.vectorType(.{ .len = 4, .child = .u32_type }), &(.{ | 188774 | try pt.aggregateValue(try pt.vectorType(.{ .len = 4, .child = .u32_type }), &(.{ |
| 188775 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p52))) >> 32)).toIntern(), | 188775 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p52))) >> 32)).toIntern(), |
| 188776 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p84))) >> 32)).toIntern(), | 188776 | (try pt.intValue(.u32, @as(u64, @bitCast(@as(f64, 0x1p84))) >> 32)).toIntern(), |
| 188777 | } ++ .{(try pt.intValue(.u32, 0)).toIntern()} ** 2)), | 188777 | (try pt.intValue(.u32, 0)).toIntern(), |
| 188778 | (try pt.intValue(.u32, 0)).toIntern(), | ||
| 188779 | })), | ||
| 188778 | ), true }, | 188780 | ), true }, |
| 188779 | .f32_0_0x1p64_mem => .{ try cg.tempMemFromValue( | 188781 | .f32_0_0x1p64_mem => .{ try cg.tempMemFromValue( |
| 188780 | try pt.aggregateValue(try pt.vectorType(.{ .len = 2, .child = .f32_type }), &.{ | 188782 | try pt.aggregateValue(try pt.vectorType(.{ .len = 2, .child = .f32_type }), &.{ |
src/codegen/x86_64/Encoding.zig+10-2| ... | @@ -1044,9 +1044,17 @@ const mnemonic_to_encodings_map = init: { | ... | @@ -1044,9 +1044,17 @@ const mnemonic_to_encodings_map = init: { |
| 1044 | const index = &mnemonic_index[@intFromEnum(entry[0])]; | 1044 | const index = &mnemonic_index[@intFromEnum(entry[0])]; |
| 1045 | mnemonic_map[@intFromEnum(entry[0])][index.*] = .{ | 1045 | mnemonic_map[@intFromEnum(entry[0])][index.*] = .{ |
| 1046 | .op_en = entry[1], | 1046 | .op_en = entry[1], |
| 1047 | .ops = (entry[2] ++ .{.none} ** (ops_len - entry[2].len)).*, | 1047 | .ops = ops: { |
| 1048 | var ops: [ops_len]Op = @splat(.none); | ||
| 1049 | @memcpy(ops[0..entry[2].len], entry[2]); | ||
| 1050 | break :ops ops; | ||
| 1051 | }, | ||
| 1048 | .opc_len = entry[3].len, | 1052 | .opc_len = entry[3].len, |
| 1049 | .opc = (entry[3] ++ .{undefined} ** (opc_len - entry[3].len)).*, | 1053 | .opc = opc: { |
| 1054 | var opc: [opc_len]u8 = @splat(undefined); | ||
| 1055 | @memcpy(opc[0..entry[3].len], entry[3]); | ||
| 1056 | break :opc opc; | ||
| 1057 | }, | ||
| 1050 | .modrm_ext = entry[4], | 1058 | .modrm_ext = entry[4], |
| 1051 | .mode = entry[5], | 1059 | .mode = entry[5], |
| 1052 | .feature = entry[6], | 1060 | .feature = entry[6], |
src/codegen/x86_64/encoder.zig+2-2| ... | @@ -14,7 +14,7 @@ const Symbol = bits.Symbol; | ... | @@ -14,7 +14,7 @@ const Symbol = bits.Symbol; |
| 14 | pub const Instruction = struct { | 14 | pub const Instruction = struct { |
| 15 | prefix: Prefix = .none, | 15 | prefix: Prefix = .none, |
| 16 | encoding: Encoding, | 16 | encoding: Encoding, |
| 17 | ops: [4]Operand = .{.none} ** 4, | 17 | ops: [4]Operand = @splat(.none), |
| 18 | 18 | ||
| 19 | pub const Mnemonic = Encoding.Mnemonic; | 19 | pub const Mnemonic = Encoding.Mnemonic; |
| 20 | 20 | ||
| ... | @@ -335,7 +335,7 @@ pub const Instruction = struct { | ... | @@ -335,7 +335,7 @@ pub const Instruction = struct { |
| 335 | var inst: Instruction = .{ | 335 | var inst: Instruction = .{ |
| 336 | .prefix = prefix, | 336 | .prefix = prefix, |
| 337 | .encoding = encoding, | 337 | .encoding = encoding, |
| 338 | .ops = [1]Operand{.none} ** 4, | 338 | .ops = @splat(.none), |
| 339 | }; | 339 | }; |
| 340 | @memcpy(inst.ops[0..ops.len], ops); | 340 | @memcpy(inst.ops[0..ops.len], ops); |
| 341 | return inst; | 341 | return inst; |
src/libs/mingw/implib.zig+1-1| ... | @@ -387,7 +387,7 @@ const first_string_table_entry = getNameBytesForStringTableOffset(first_string_t | ... | @@ -387,7 +387,7 @@ const first_string_table_entry = getNameBytesForStringTableOffset(first_string_t |
| 387 | const byte_size_of_relocation = 10; | 387 | const byte_size_of_relocation = 10; |
| 388 | 388 | ||
| 389 | fn getNameBytesForStringTableOffset(offset: u32) [8]u8 { | 389 | fn getNameBytesForStringTableOffset(offset: u32) [8]u8 { |
| 390 | var bytes = [_]u8{0} ** 8; | 390 | var bytes: [8]u8 = @splat(0); |
| 391 | std.mem.writeInt(u32, bytes[4..8], offset, .little); | 391 | std.mem.writeInt(u32, bytes[4..8], offset, .little); |
| 392 | return bytes; | 392 | return bytes; |
| 393 | } | 393 | } |
src/link/Coff.zig+20-4| ... | @@ -81,15 +81,31 @@ pub const msdos_stub: [120]u8 = .{ | ... | @@ -81,15 +81,31 @@ pub const msdos_stub: [120]u8 = .{ |
| 81 | 0x00, 0x00, // Overlay number. Zero means this is the main executable. | 81 | 0x00, 0x00, // Overlay number. Zero means this is the main executable. |
| 82 | } | 82 | } |
| 83 | // Reserved words. | 83 | // Reserved words. |
| 84 | ++ .{ 0x00, 0x00 } ** 4 | 84 | ++ .{ |
| 85 | // OEM-related fields. | 85 | 0x00, 0x00, |
| 86 | 0x00, 0x00, | ||
| 87 | 0x00, 0x00, | ||
| 88 | 0x00, 0x00, | ||
| 89 | } | ||
| 90 | // OEM-related fields. | ||
| 86 | ++ .{ | 91 | ++ .{ |
| 87 | 0x00, 0x00, // OEM identifier. | 92 | 0x00, 0x00, // OEM identifier. |
| 88 | 0x00, 0x00, // OEM information. | 93 | 0x00, 0x00, // OEM information. |
| 89 | } | 94 | } |
| 90 | // Reserved words. | 95 | // Reserved words. |
| 91 | ++ .{ 0x00, 0x00 } ** 10 | 96 | ++ .{ |
| 92 | // Address of the PE header (a long). This matches the size of this entire MS-DOS stub, so that's the address of what's after this MS-DOS stub. | 97 | 0x00, 0x00, |
| 98 | 0x00, 0x00, | ||
| 99 | 0x00, 0x00, | ||
| 100 | 0x00, 0x00, | ||
| 101 | 0x00, 0x00, | ||
| 102 | 0x00, 0x00, | ||
| 103 | 0x00, 0x00, | ||
| 104 | 0x00, 0x00, | ||
| 105 | 0x00, 0x00, | ||
| 106 | 0x00, 0x00, | ||
| 107 | } | ||
| 108 | // Address of the PE header (a long). This matches the size of this entire MS-DOS stub, so that's the address of what's after this MS-DOS stub. | ||
| 93 | ++ .{ 0x78, 0x00, 0x00, 0x00 } | 109 | ++ .{ 0x78, 0x00, 0x00, 0x00 } |
| 94 | // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits. | 110 | // What follows is a 16-bit x86 MS-DOS program of 7 instructions that prints the bytes after these instructions and then exits. |
| 95 | ++ .{ | 111 | ++ .{ |
src/link/Dwarf.zig+1-1| ... | @@ -2975,7 +2975,7 @@ fn finishWipNavFuncWriterError( | ... | @@ -2975,7 +2975,7 @@ fn finishWipNavFuncWriterError( |
| 2975 | wip_nav.unit, | 2975 | wip_nav.unit, |
| 2976 | wip_nav.entry, | 2976 | wip_nav.entry, |
| 2977 | dwarf, | 2977 | dwarf, |
| 2978 | ([1]u8{DW.RLE.start_end} ++ [1]u8{0} ** (8 + 8))[0 .. 1 + @intFromEnum(dwarf.address_size) + @intFromEnum(dwarf.address_size)], | 2978 | ([1]u8{DW.RLE.start_end} ++ @as([8 + 8]u8, @splat(0)))[0 .. 1 + @intFromEnum(dwarf.address_size) + @intFromEnum(dwarf.address_size)], |
| 2979 | ); | 2979 | ); |
| 2980 | } | 2980 | } |
| 2981 | 2981 |
src/link/Elf.zig+1-1| ... | @@ -3943,7 +3943,7 @@ fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void | ... | @@ -3943,7 +3943,7 @@ fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void |
| 3943 | const write = phdr.p_flags & elf.PF_W != 0; | 3943 | const write = phdr.p_flags & elf.PF_W != 0; |
| 3944 | const read = phdr.p_flags & elf.PF_R != 0; | 3944 | const read = phdr.p_flags & elf.PF_R != 0; |
| 3945 | const exec = phdr.p_flags & elf.PF_X != 0; | 3945 | const exec = phdr.p_flags & elf.PF_X != 0; |
| 3946 | var flags: [3]u8 = [_]u8{'_'} ** 3; | 3946 | var flags: [3]u8 = @splat('_'); |
| 3947 | if (exec) flags[0] = 'X'; | 3947 | if (exec) flags[0] = 'X'; |
| 3948 | if (write) flags[1] = 'W'; | 3948 | if (write) flags[1] = 'W'; |
| 3949 | if (read) flags[2] = 'R'; | 3949 | if (read) flags[2] = 'R'; |
src/link/Elf/Symbol.zig+1-1| ... | @@ -363,7 +363,7 @@ const Format = struct { | ... | @@ -363,7 +363,7 @@ const Format = struct { |
| 363 | if (symbol.atom(elf_file)) |atom_ptr| { | 363 | if (symbol.atom(elf_file)) |atom_ptr| { |
| 364 | try writer.print(" : atom({d})", .{atom_ptr.atom_index}); | 364 | try writer.print(" : atom({d})", .{atom_ptr.atom_index}); |
| 365 | } | 365 | } |
| 366 | var buf: [2]u8 = .{'_'} ** 2; | 366 | var buf: [2]u8 = @splat('_'); |
| 367 | if (symbol.flags.@"export") buf[0] = 'E'; | 367 | if (symbol.flags.@"export") buf[0] = 'E'; |
| 368 | if (symbol.flags.import) buf[1] = 'I'; | 368 | if (symbol.flags.import) buf[1] = 'I'; |
| 369 | try writer.print(" : {s}", .{&buf}); | 369 | try writer.print(" : {s}", .{&buf}); |
src/link/MachO.zig+2-2| ... | @@ -38,7 +38,7 @@ symtab_cmd: macho.symtab_command = .{}, | ... | @@ -38,7 +38,7 @@ symtab_cmd: macho.symtab_command = .{}, |
| 38 | dysymtab_cmd: macho.dysymtab_command = .{}, | 38 | dysymtab_cmd: macho.dysymtab_command = .{}, |
| 39 | function_starts_cmd: macho.linkedit_data_command = .{ .cmd = .FUNCTION_STARTS }, | 39 | function_starts_cmd: macho.linkedit_data_command = .{ .cmd = .FUNCTION_STARTS }, |
| 40 | data_in_code_cmd: macho.linkedit_data_command = .{ .cmd = .DATA_IN_CODE }, | 40 | data_in_code_cmd: macho.linkedit_data_command = .{ .cmd = .DATA_IN_CODE }, |
| 41 | uuid_cmd: macho.uuid_command = .{ .uuid = [_]u8{0} ** 16 }, | 41 | uuid_cmd: macho.uuid_command = .{ .uuid = @splat(0) }, |
| 42 | codesig_cmd: macho.linkedit_data_command = .{ .cmd = .CODE_SIGNATURE }, | 42 | codesig_cmd: macho.linkedit_data_command = .{ .cmd = .CODE_SIGNATURE }, |
| 43 | 43 | ||
| 44 | pagezero_seg_index: ?u8 = null, | 44 | pagezero_seg_index: ?u8 = null, |
| ... | @@ -3763,7 +3763,7 @@ pub fn addSection( | ... | @@ -3763,7 +3763,7 @@ pub fn addSection( |
| 3763 | } | 3763 | } |
| 3764 | 3764 | ||
| 3765 | pub fn makeStaticString(bytes: []const u8) [16]u8 { | 3765 | pub fn makeStaticString(bytes: []const u8) [16]u8 { |
| 3766 | var buf = [_]u8{0} ** 16; | 3766 | var buf: [16]u8 = @splat(0); |
| 3767 | @memcpy(buf[0..bytes.len], bytes); | 3767 | @memcpy(buf[0..bytes.len], bytes); |
| 3768 | return buf; | 3768 | return buf; |
| 3769 | } | 3769 | } |
src/link/MachO/CodeSignature.zig+1-1| ... | @@ -95,7 +95,7 @@ const CodeDirectory = struct { | ... | @@ -95,7 +95,7 @@ const CodeDirectory = struct { |
| 95 | }; | 95 | }; |
| 96 | comptime var i = 0; | 96 | comptime var i = 0; |
| 97 | inline while (i < n_special_slots) : (i += 1) { | 97 | inline while (i < n_special_slots) : (i += 1) { |
| 98 | cdir.special_slots[i] = [_]u8{0} ** hash_size; | 98 | cdir.special_slots[i] = @splat(0); |
| 99 | } | 99 | } |
| 100 | return cdir; | 100 | return cdir; |
| 101 | } | 101 | } |
src/link/MachO/DebugSymbols.zig+1-1| ... | @@ -25,7 +25,7 @@ allocator: Allocator, | ... | @@ -25,7 +25,7 @@ allocator: Allocator, |
| 25 | file: ?Io.File, | 25 | file: ?Io.File, |
| 26 | 26 | ||
| 27 | symtab_cmd: macho.symtab_command = .{}, | 27 | symtab_cmd: macho.symtab_command = .{}, |
| 28 | uuid_cmd: macho.uuid_command = .{ .uuid = [_]u8{0} ** 16 }, | 28 | uuid_cmd: macho.uuid_command = .{ .uuid = @splat(0) }, |
| 29 | 29 | ||
| 30 | segments: std.ArrayList(macho.segment_command_64) = .empty, | 30 | segments: std.ArrayList(macho.segment_command_64) = .empty, |
| 31 | sections: std.ArrayList(macho.section_64) = .empty, | 31 | sections: std.ArrayList(macho.section_64) = .empty, |
src/link/MachO/InternalObject.zig+1-1| ... | @@ -11,7 +11,7 @@ symbols_extra: std.ArrayList(u32) = .empty, | ... | @@ -11,7 +11,7 @@ symbols_extra: std.ArrayList(u32) = .empty, |
| 11 | globals: std.ArrayList(MachO.SymbolResolver.Index) = .empty, | 11 | globals: std.ArrayList(MachO.SymbolResolver.Index) = .empty, |
| 12 | 12 | ||
| 13 | objc_methnames: std.ArrayList(u8) = .empty, | 13 | objc_methnames: std.ArrayList(u8) = .empty, |
| 14 | objc_selrefs: [@sizeOf(u64)]u8 = [_]u8{0} ** @sizeOf(u64), | 14 | objc_selrefs: [@sizeOf(u64)]u8 = @splat(0), |
| 15 | 15 | ||
| 16 | force_undefined: std.ArrayList(Symbol.Index) = .empty, | 16 | force_undefined: std.ArrayList(Symbol.Index) = .empty, |
| 17 | entry_index: ?Symbol.Index = null, | 17 | entry_index: ?Symbol.Index = null, |
src/link/MachO/Symbol.zig+1-1| ... | @@ -325,7 +325,7 @@ const Format = struct { | ... | @@ -325,7 +325,7 @@ const Format = struct { |
| 325 | if (symbol.getAtom(f.macho_file)) |atom| { | 325 | if (symbol.getAtom(f.macho_file)) |atom| { |
| 326 | try w.print(" : atom({d})", .{atom.atom_index}); | 326 | try w.print(" : atom({d})", .{atom.atom_index}); |
| 327 | } | 327 | } |
| 328 | var buf: [3]u8 = .{'_'} ** 3; | 328 | var buf: [3]u8 = @splat('_'); |
| 329 | if (symbol.flags.@"export") buf[0] = 'E'; | 329 | if (symbol.flags.@"export") buf[0] = 'E'; |
| 330 | if (symbol.flags.import) buf[1] = 'I'; | 330 | if (symbol.flags.import) buf[1] = 'I'; |
| 331 | switch (symbol.visibility) { | 331 | switch (symbol.visibility) { |
src/print_zir.zig-29| ... | @@ -416,8 +416,6 @@ const Writer = struct { | ... | @@ -416,8 +416,6 @@ const Writer = struct { |
| 416 | 416 | ||
| 417 | .for_len => try self.writePlNodeMultiOp(stream, inst), | 417 | .for_len => try self.writePlNodeMultiOp(stream, inst), |
| 418 | 418 | ||
| 419 | .array_mul => try self.writeArrayMul(stream, inst), | ||
| 420 | |||
| 421 | .elem_val_imm => try self.writeElemValImm(stream, inst), | 419 | .elem_val_imm => try self.writeElemValImm(stream, inst), |
| 422 | 420 | ||
| 423 | .@"export" => try self.writePlNodeExport(stream, inst), | 421 | .@"export" => try self.writePlNodeExport(stream, inst), |
| ... | @@ -477,7 +475,6 @@ const Writer = struct { | ... | @@ -477,7 +475,6 @@ const Writer = struct { |
| 477 | .decl_ref, | 475 | .decl_ref, |
| 478 | .decl_val, | 476 | .decl_val, |
| 479 | .ret_err_value, | 477 | .ret_err_value, |
| 480 | .ret_err_value_code, | ||
| 481 | .param_anytype, | 478 | .param_anytype, |
| 482 | .param_anytype_comptime, | 479 | .param_anytype_comptime, |
| 483 | => try self.writeStrTok(stream, inst), | 480 | => try self.writeStrTok(stream, inst), |
| ... | @@ -497,7 +494,6 @@ const Writer = struct { | ... | @@ -497,7 +494,6 @@ const Writer = struct { |
| 497 | .dbg_stmt => try self.writeDbgStmt(stream, inst), | 494 | .dbg_stmt => try self.writeDbgStmt(stream, inst), |
| 498 | 495 | ||
| 499 | .@"defer" => try self.writeDefer(stream, inst), | 496 | .@"defer" => try self.writeDefer(stream, inst), |
| 500 | .defer_err_code => try self.writeDeferErrCode(stream, inst), | ||
| 501 | 497 | ||
| 502 | .declaration => try self.writeDeclaration(stream, inst), | 498 | .declaration => try self.writeDeclaration(stream, inst), |
| 503 | 499 | ||
| ... | @@ -1048,18 +1044,6 @@ const Writer = struct { | ... | @@ -1048,18 +1044,6 @@ const Writer = struct { |
| 1048 | try self.writeSrcNode(stream, inst_data.src_node); | 1044 | try self.writeSrcNode(stream, inst_data.src_node); |
| 1049 | } | 1045 | } |
| 1050 | 1046 | ||
| 1051 | fn writeArrayMul(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void { | ||
| 1052 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | ||
| 1053 | const extra = self.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; | ||
| 1054 | try self.writeInstRef(stream, extra.res_ty); | ||
| 1055 | try stream.writeAll(", "); | ||
| 1056 | try self.writeInstRef(stream, extra.lhs); | ||
| 1057 | try stream.writeAll(", "); | ||
| 1058 | try self.writeInstRef(stream, extra.rhs); | ||
| 1059 | try stream.writeAll(") "); | ||
| 1060 | try self.writeSrcNode(stream, inst_data.src_node); | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | fn writeElemValImm(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void { | 1047 | fn writeElemValImm(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void { |
| 1064 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; | 1048 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; |
| 1065 | try self.writeInstRef(stream, inst_data.operand); | 1049 | try self.writeInstRef(stream, inst_data.operand); |
| ... | @@ -2186,19 +2170,6 @@ const Writer = struct { | ... | @@ -2186,19 +2170,6 @@ const Writer = struct { |
| 2186 | try stream.writeByte(')'); | 2170 | try stream.writeByte(')'); |
| 2187 | } | 2171 | } |
| 2188 | 2172 | ||
| 2189 | fn writeDeferErrCode(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void { | ||
| 2190 | const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code; | ||
| 2191 | const extra = self.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; | ||
| 2192 | |||
| 2193 | try self.writeInstRef(stream, extra.remapped_err_code.toRef()); | ||
| 2194 | try stream.writeAll(" = "); | ||
| 2195 | try self.writeInstRef(stream, inst_data.err_code); | ||
| 2196 | try stream.writeAll(", "); | ||
| 2197 | const body = self.code.bodySlice(extra.index, extra.len); | ||
| 2198 | try self.writeBracedBody(stream, body); | ||
| 2199 | try stream.writeByte(')'); | ||
| 2200 | } | ||
| 2201 | |||
| 2202 | fn writeDeclaration(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void { | 2173 | fn writeDeclaration(self: *Writer, stream: *std.Io.Writer, inst: Zir.Inst.Index) !void { |
| 2203 | const decl = self.code.getDeclaration(inst); | 2174 | const decl = self.code.getDeclaration(inst); |
| 2204 | 2175 |
test/behavior/array.zig+5-17| ... | @@ -104,18 +104,6 @@ test "array init with concat" { | ... | @@ -104,18 +104,6 @@ test "array init with concat" { |
| 104 | try expect(std.mem.eql(u8, &i, "abcd")); | 104 | try expect(std.mem.eql(u8, &i, "abcd")); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | test "array init with mult" { | ||
| 108 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 109 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 110 | |||
| 111 | const a = 'a'; | ||
| 112 | var i: [8]u8 = [2]u8{ a, 'b' } ** 4; | ||
| 113 | try expect(std.mem.eql(u8, &i, "abababab")); | ||
| 114 | |||
| 115 | var j: [4]u8 = [1]u8{'a'} ** 4; | ||
| 116 | try expect(std.mem.eql(u8, &j, "aaaa")); | ||
| 117 | } | ||
| 118 | |||
| 119 | test "array literal with explicit type" { | 107 | test "array literal with explicit type" { |
| 120 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 108 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 121 | 109 | ||
| ... | @@ -196,7 +184,7 @@ test "array with sentinels" { | ... | @@ -196,7 +184,7 @@ test "array with sentinels" { |
| 196 | 184 | ||
| 197 | test "void arrays" { | 185 | test "void arrays" { |
| 198 | var array: [4]void = undefined; | 186 | var array: [4]void = undefined; |
| 199 | array[0] = void{}; | 187 | array[0] = {}; |
| 200 | array[1] = array[2]; | 188 | array[1] = array[2]; |
| 201 | try expect(@sizeOf(@TypeOf(array)) == 0); | 189 | try expect(@sizeOf(@TypeOf(array)) == 0); |
| 202 | try expect(array.len == 4); | 190 | try expect(array.len == 4); |
| ... | @@ -320,7 +308,7 @@ test "set global var array via slice embedded in struct" { | ... | @@ -320,7 +308,7 @@ test "set global var array via slice embedded in struct" { |
| 320 | try expect(s_array[2].b == 3); | 308 | try expect(s_array[2].b == 3); |
| 321 | } | 309 | } |
| 322 | 310 | ||
| 323 | test "read/write through global variable array of struct fields initialized via array mult" { | 311 | test "read/write through global variable array of struct fields initialized via splat" { |
| 324 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 312 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 325 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 313 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 326 | 314 | ||
| ... | @@ -335,7 +323,7 @@ test "read/write through global variable array of struct fields initialized via | ... | @@ -335,7 +323,7 @@ test "read/write through global variable array of struct fields initialized via |
| 335 | term: usize, | 323 | term: usize, |
| 336 | }; | 324 | }; |
| 337 | 325 | ||
| 338 | var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1; | 326 | var storage: [1]MyStruct = @splat(.{ .term = 1 }); |
| 339 | }; | 327 | }; |
| 340 | try S.doTheTest(); | 328 | try S.doTheTest(); |
| 341 | } | 329 | } |
| ... | @@ -641,8 +629,8 @@ test "array of array agregate init" { | ... | @@ -641,8 +629,8 @@ test "array of array agregate init" { |
| 641 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 629 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 642 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 630 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 643 | 631 | ||
| 644 | var a = [1]u32{11} ** 10; | 632 | var a: [10]u32 = @splat(11); |
| 645 | var b = [1][10]u32{a} ** 2; | 633 | var b: [2][10]u32 = @splat(a); |
| 646 | _ = .{ &a, &b }; | 634 | _ = .{ &a, &b }; |
| 647 | try std.testing.expect(b[1][1] == 11); | 635 | try std.testing.expect(b[1][1] == 11); |
| 648 | } | 636 | } |
test/behavior/atomics.zig-1| ... | @@ -369,7 +369,6 @@ test "atomics with different types" { | ... | @@ -369,7 +369,6 @@ test "atomics with different types" { |
| 369 | try testAtomicsWithType(u24, 2, 1); | 369 | try testAtomicsWithType(u24, 2, 1); |
| 370 | 370 | ||
| 371 | try testAtomicsWithType(u0, 0, 0); | 371 | try testAtomicsWithType(u0, 0, 0); |
| 372 | try testAtomicsWithType(i0, 0, 0); | ||
| 373 | 372 | ||
| 374 | try testAtomicsWithType(enum(u32) { x = 1234, y = 5678 }, .x, .y); | 373 | try testAtomicsWithType(enum(u32) { x = 1234, y = 5678 }, .x, .y); |
| 375 | try testAtomicsWithType(enum(u19) { x = 1234, y = 5678 }, .x, .y); | 374 | try testAtomicsWithType(enum(u19) { x = 1234, y = 5678 }, .x, .y); |
test/behavior/basic.zig+2-9| ... | @@ -294,13 +294,6 @@ test "string concatenation simple" { | ... | @@ -294,13 +294,6 @@ test "string concatenation simple" { |
| 294 | try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); | 294 | try expect(mem.eql(u8, "OK" ++ " IT " ++ "WORKED", "OK IT WORKED")); |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | test "array mult operator" { | ||
| 298 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 299 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 300 | |||
| 301 | try expect(mem.eql(u8, "ab" ** 5, "ababababab")); | ||
| 302 | } | ||
| 303 | |||
| 304 | const global_a: i32 = 1234; | 297 | const global_a: i32 = 1234; |
| 305 | const global_b: *const i32 = &global_a; | 298 | const global_b: *const i32 = &global_a; |
| 306 | const global_c: *const f32 = @as(*const f32, @ptrCast(global_b)); | 299 | const global_c: *const f32 = @as(*const f32, @ptrCast(global_b)); |
| ... | @@ -465,7 +458,7 @@ fn testPointerToVoidReturnType() anyerror!void { | ... | @@ -465,7 +458,7 @@ fn testPointerToVoidReturnType() anyerror!void { |
| 465 | const a = testPointerToVoidReturnType2(); | 458 | const a = testPointerToVoidReturnType2(); |
| 466 | return a.*; | 459 | return a.*; |
| 467 | } | 460 | } |
| 468 | const test_pointer_to_void_return_type_x = void{}; | 461 | const test_pointer_to_void_return_type_x = {}; |
| 469 | fn testPointerToVoidReturnType2() *const void { | 462 | fn testPointerToVoidReturnType2() *const void { |
| 470 | return &test_pointer_to_void_return_type_x; | 463 | return &test_pointer_to_void_return_type_x; |
| 471 | } | 464 | } |
| ... | @@ -1041,7 +1034,7 @@ test "const alloc with comptime-known initializer is made comptime-known" { | ... | @@ -1041,7 +1034,7 @@ test "const alloc with comptime-known initializer is made comptime-known" { |
| 1041 | positive: bool, | 1034 | positive: bool, |
| 1042 | }; | 1035 | }; |
| 1043 | const biggest: Const = .{ | 1036 | const biggest: Const = .{ |
| 1044 | .limbs = &([1]usize{comptime std.math.maxInt(usize)} ** 128), | 1037 | .limbs = &@as([128]usize, @splat(comptime std.math.maxInt(usize))), |
| 1045 | .positive = false, | 1038 | .positive = false, |
| 1046 | }; | 1039 | }; |
| 1047 | if (biggest.positive) @compileError("bad"); | 1040 | if (biggest.positive) @compileError("bad"); |
test/behavior/bit_shifting.zig+1-1| ... | @@ -15,7 +15,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt | ... | @@ -15,7 +15,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt |
| 15 | shards: [1 << shard_key_bits]?*Node, | 15 | shards: [1 << shard_key_bits]?*Node, |
| 16 | 16 | ||
| 17 | pub fn create() Self { | 17 | pub fn create() Self { |
| 18 | return Self{ .shards = [_]?*Node{null} ** (1 << shard_key_bits) }; | 18 | return .{ .shards = @splat(null) }; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn getShardKey(key: Key) ShardKey { | 21 | fn getShardKey(key: Key) ShardKey { |
test/behavior/cast.zig+1-4| ... | @@ -3036,7 +3036,7 @@ test "bitcast vector" { | ... | @@ -3036,7 +3036,7 @@ test "bitcast vector" { |
| 3036 | const u8x32 = @Vector(32, u8); | 3036 | const u8x32 = @Vector(32, u8); |
| 3037 | const u32x8 = @Vector(8, u32); | 3037 | const u32x8 = @Vector(8, u32); |
| 3038 | 3038 | ||
| 3039 | const zerox32: u8x32 = [_]u8{0} ** 32; | 3039 | const zerox32: u8x32 = @splat(0); |
| 3040 | const bigsum: u32x8 = @bitCast(zerox32); | 3040 | const bigsum: u32x8 = @bitCast(zerox32); |
| 3041 | try std.testing.expectEqual(0, @reduce(.Add, bigsum)); | 3041 | try std.testing.expectEqual(0, @reduce(.Add, bigsum)); |
| 3042 | } | 3042 | } |
| ... | @@ -3079,8 +3079,6 @@ test "@intFromFloat boundary cases" { | ... | @@ -3079,8 +3079,6 @@ test "@intFromFloat boundary cases" { |
| 3079 | 3079 | ||
| 3080 | try case(u0, 1.0, .down, 0); | 3080 | try case(u0, 1.0, .down, 0); |
| 3081 | try case(u0, -1.0, .up, 0); | 3081 | try case(u0, -1.0, .up, 0); |
| 3082 | try case(i0, 1.0, .down, 0); | ||
| 3083 | try case(i0, -1.0, .up, 0); | ||
| 3084 | 3082 | ||
| 3085 | try case(u10, 1024.0, .down, 1023); | 3083 | try case(u10, 1024.0, .down, 1023); |
| 3086 | try case(u10, -1.0, .up, 0); | 3084 | try case(u10, -1.0, .up, 0); |
| ... | @@ -3111,7 +3109,6 @@ test "@intFromFloat vector boundary cases" { | ... | @@ -3111,7 +3109,6 @@ test "@intFromFloat vector boundary cases" { |
| 3111 | try case(i8, .{ -129.0, 128.0 }, .{ -128, 127 }); | 3109 | try case(i8, .{ -129.0, 128.0 }, .{ -128, 127 }); |
| 3112 | 3110 | ||
| 3113 | try case(u0, .{ -1.0, 1.0 }, .{ 0, 0 }); | 3111 | try case(u0, .{ -1.0, 1.0 }, .{ 0, 0 }); |
| 3114 | try case(i0, .{ -1.0, 1.0 }, .{ 0, 0 }); | ||
| 3115 | 3112 | ||
| 3116 | try case(u10, .{ -1.0, 1024.0 }, .{ 0, 1023 }); | 3113 | try case(u10, .{ -1.0, 1024.0 }, .{ 0, 1023 }); |
| 3117 | try case(i10, .{ -513.0, 512.0 }, .{ -512, 511 }); | 3114 | try case(i10, .{ -513.0, 512.0 }, .{ -512, 511 }); |
test/behavior/defer.zig+1-85| ... | @@ -106,51 +106,6 @@ test "mixing normal and error defers" { | ... | @@ -106,51 +106,6 @@ test "mixing normal and error defers" { |
| 106 | try expect(result[2] == 'a'); | 106 | try expect(result[2] == 'a'); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | test "errdefer with payload" { | ||
| 110 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 111 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 112 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 113 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | ||
| 114 | |||
| 115 | const S = struct { | ||
| 116 | fn foo() !i32 { | ||
| 117 | errdefer |a| { | ||
| 118 | expectEqual(error.One, a) catch @panic("test failure"); | ||
| 119 | } | ||
| 120 | return error.One; | ||
| 121 | } | ||
| 122 | fn doTheTest() !void { | ||
| 123 | try expectError(error.One, foo()); | ||
| 124 | } | ||
| 125 | }; | ||
| 126 | try S.doTheTest(); | ||
| 127 | try comptime S.doTheTest(); | ||
| 128 | } | ||
| 129 | |||
| 130 | test "reference to errdefer payload" { | ||
| 131 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 132 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 133 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; // TODO | ||
| 134 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | ||
| 135 | |||
| 136 | const S = struct { | ||
| 137 | fn foo() !i32 { | ||
| 138 | errdefer |a| { | ||
| 139 | const ptr = &a; | ||
| 140 | const ptr2 = &ptr; | ||
| 141 | expectEqual(error.One, ptr2.*.*) catch @panic("test failure"); | ||
| 142 | expectEqual(error.One, ptr.*) catch @panic("test failure"); | ||
| 143 | } | ||
| 144 | return error.One; | ||
| 145 | } | ||
| 146 | fn doTheTest() !void { | ||
| 147 | try expectError(error.One, foo()); | ||
| 148 | } | ||
| 149 | }; | ||
| 150 | try S.doTheTest(); | ||
| 151 | try comptime S.doTheTest(); | ||
| 152 | } | ||
| 153 | |||
| 154 | test "simple else prong doesn't emit an error for unreachable else prong" { | 109 | test "simple else prong doesn't emit an error for unreachable else prong" { |
| 155 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 110 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 156 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 111 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| ... | @@ -192,47 +147,8 @@ comptime { | ... | @@ -192,47 +147,8 @@ comptime { |
| 192 | if (defer_assign != 0) @compileError("defer_assign failed!"); | 147 | if (defer_assign != 0) @compileError("defer_assign failed!"); |
| 193 | } | 148 | } |
| 194 | 149 | ||
| 195 | test "errdefer capture" { | ||
| 196 | const S = struct { | ||
| 197 | fail: bool = undefined, | ||
| 198 | fn bar0(self: *@This()) error{a}!void { | ||
| 199 | self.fail = false; | ||
| 200 | errdefer |err| if (@TypeOf(err) != error{a}) { | ||
| 201 | self.fail = true; | ||
| 202 | }; | ||
| 203 | return error.a; | ||
| 204 | } | ||
| 205 | fn bar1(self: *@This()) error{a}!void { | ||
| 206 | self.fail = false; | ||
| 207 | errdefer |err| if (@TypeOf(err) != error{a}) { | ||
| 208 | self.fail = true; | ||
| 209 | }; | ||
| 210 | const rv: error{a}!void = @errorCast(@as(error{a}!void, error.a)); | ||
| 211 | return rv; | ||
| 212 | } | ||
| 213 | // https://github.com/ziglang/zig/issues/20371 | ||
| 214 | fn bar2(self: *@This()) error{a}!void { | ||
| 215 | self.fail = false; | ||
| 216 | errdefer |err| if (@TypeOf(err) != error{a}) { | ||
| 217 | self.fail = true; | ||
| 218 | }; | ||
| 219 | return @errorCast(@as(error{a}!void, error.a)); | ||
| 220 | } | ||
| 221 | }; | ||
| 222 | |||
| 223 | var s: S = .{}; | ||
| 224 | s.bar0() catch {}; | ||
| 225 | if (s.fail) return error.TestExpectedError; | ||
| 226 | s.bar1() catch {}; | ||
| 227 | if (s.fail) return error.TestExpectedError; | ||
| 228 | s.bar2() catch {}; | ||
| 229 | if (s.fail) return error.TestExpectedError; | ||
| 230 | } | ||
| 231 | |||
| 232 | test "errdefer in test block" { | 150 | test "errdefer in test block" { |
| 233 | errdefer |err| { | 151 | errdefer {} |
| 234 | _ = &err; | ||
| 235 | } | ||
| 236 | var x: bool = false; | 152 | var x: bool = false; |
| 237 | _ = &x; | 153 | _ = &x; |
| 238 | if (x) return error.Something; | 154 | if (x) return error.Something; |
test/behavior/eval.zig+1-45| ... | @@ -727,15 +727,6 @@ test "array concatenation of function calls" { | ... | @@ -727,15 +727,6 @@ test "array concatenation of function calls" { |
| 727 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); | 727 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); |
| 728 | } | 728 | } |
| 729 | 729 | ||
| 730 | test "array multiplication of function calls" { | ||
| 731 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 732 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 733 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 734 | |||
| 735 | var a = oneItem(3) ** scalar(2); | ||
| 736 | try expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 })); | ||
| 737 | } | ||
| 738 | |||
| 739 | fn oneItem(x: i32) [1]i32 { | 730 | fn oneItem(x: i32) [1]i32 { |
| 740 | return [_]i32{x}; | 731 | return [_]i32{x}; |
| 741 | } | 732 | } |
| ... | @@ -814,41 +805,6 @@ test "array concatenation sets the sentinel - pointer" { | ... | @@ -814,41 +805,6 @@ test "array concatenation sets the sentinel - pointer" { |
| 814 | try expect(ptr[5] == 69); | 805 | try expect(ptr[5] == 69); |
| 815 | } | 806 | } |
| 816 | 807 | ||
| 817 | test "array multiplication sets the sentinel - value" { | ||
| 818 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 819 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 820 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | ||
| 821 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 822 | |||
| 823 | var a = [2:7]u3{ 1, 6 }; | ||
| 824 | _ = &a; | ||
| 825 | const b = a ** 2; | ||
| 826 | comptime assert(@TypeOf(b) == [4:7]u3); | ||
| 827 | try expect(b[0] == 1); | ||
| 828 | try expect(b[1] == 6); | ||
| 829 | try expect(b[2] == 1); | ||
| 830 | try expect(b[3] == 6); | ||
| 831 | const ptr: [*]const u3 = &b; | ||
| 832 | try expect(ptr[4] == 7); | ||
| 833 | } | ||
| 834 | |||
| 835 | test "array multiplication sets the sentinel - pointer" { | ||
| 836 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | ||
| 837 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | ||
| 838 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | ||
| 839 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | ||
| 840 | |||
| 841 | var a = [2:7]u3{ 1, 6 }; | ||
| 842 | const b = &a ** 2; | ||
| 843 | comptime assert(@TypeOf(b) == *const [4:7]u3); | ||
| 844 | try expect(b[0] == 1); | ||
| 845 | try expect(b[1] == 6); | ||
| 846 | try expect(b[2] == 1); | ||
| 847 | try expect(b[3] == 6); | ||
| 848 | const ptr: [*]const u3 = b; | ||
| 849 | try expect(ptr[4] == 7); | ||
| 850 | } | ||
| 851 | |||
| 852 | test "comptime assign int to optional int" { | 808 | test "comptime assign int to optional int" { |
| 853 | comptime { | 809 | comptime { |
| 854 | var x: ?i32 = null; | 810 | var x: ?i32 = null; |
| ... | @@ -1094,7 +1050,7 @@ test "storing an array of type in a field" { | ... | @@ -1094,7 +1050,7 @@ test "storing an array of type in a field" { |
| 1094 | 1050 | ||
| 1095 | fn foo() @This() { | 1051 | fn foo() @This() { |
| 1096 | comptime var foobar: Foobar = undefined; | 1052 | comptime var foobar: Foobar = undefined; |
| 1097 | foobar.str = [_]u8{'a'} ** 1024; | 1053 | foobar.str = @splat('a'); |
| 1098 | return foobar; | 1054 | return foobar; |
| 1099 | } | 1055 | } |
| 1100 | }; | 1056 | }; |
test/behavior/extern_struct_zero_size_fields.zig+2-2| ... | @@ -10,9 +10,9 @@ const T = extern struct { | ... | @@ -10,9 +10,9 @@ const T = extern struct { |
| 10 | baz: struct {} = .{}, | 10 | baz: struct {} = .{}, |
| 11 | ayy: E = .the_only_possible_value, | 11 | ayy: E = .the_only_possible_value, |
| 12 | arr: [0]u0 = .{}, | 12 | arr: [0]u0 = .{}, |
| 13 | matey: [128]void = [_]void{{}} ** 128, | 13 | matey: [128]void = @splat({}), |
| 14 | running_out_of_ideas: packed struct {} = .{}, | 14 | running_out_of_ideas: packed struct {} = .{}, |
| 15 | one_more: [256]S = [_]S{.{}} ** 256, | 15 | one_more: [256]S = @splat(.{}), |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | test { | 18 | test { |
test/behavior/field_parent_ptr.zig+5-5| ... | @@ -1903,7 +1903,7 @@ test "@fieldParentPtr tagged union all zero-bit fields" { | ... | @@ -1903,7 +1903,7 @@ test "@fieldParentPtr tagged union all zero-bit fields" { |
| 1903 | 1903 | ||
| 1904 | const C = union(enum) { | 1904 | const C = union(enum) { |
| 1905 | a: u0, | 1905 | a: u0, |
| 1906 | b: i0, | 1906 | b: void, |
| 1907 | }; | 1907 | }; |
| 1908 | 1908 | ||
| 1909 | { | 1909 | { |
| ... | @@ -1938,20 +1938,20 @@ test "@fieldParentPtr tagged union all zero-bit fields" { | ... | @@ -1938,20 +1938,20 @@ test "@fieldParentPtr tagged union all zero-bit fields" { |
| 1938 | } | 1938 | } |
| 1939 | 1939 | ||
| 1940 | { | 1940 | { |
| 1941 | const c: C = .{ .b = 0 }; | 1941 | const c: C = .{ .b = {} }; |
| 1942 | const pcf = &c.b; | 1942 | const pcf = &c.b; |
| 1943 | const pc: *const C = @alignCast(@fieldParentPtr("b", pcf)); | 1943 | const pc: *const C = @alignCast(@fieldParentPtr("b", pcf)); |
| 1944 | try expect(pc == &c); | 1944 | try expect(pc == &c); |
| 1945 | } | 1945 | } |
| 1946 | { | 1946 | { |
| 1947 | const c: C = .{ .b = 0 }; | 1947 | const c: C = .{ .b = {} }; |
| 1948 | const pcf = &c.b; | 1948 | const pcf = &c.b; |
| 1949 | var pc: *const C = undefined; | 1949 | var pc: *const C = undefined; |
| 1950 | pc = @alignCast(@fieldParentPtr("b", pcf)); | 1950 | pc = @alignCast(@fieldParentPtr("b", pcf)); |
| 1951 | try expect(pc == &c); | 1951 | try expect(pc == &c); |
| 1952 | } | 1952 | } |
| 1953 | { | 1953 | { |
| 1954 | const c: C = .{ .b = 0 }; | 1954 | const c: C = .{ .b = {} }; |
| 1955 | var pcf: @TypeOf(&c.b) = undefined; | 1955 | var pcf: @TypeOf(&c.b) = undefined; |
| 1956 | pcf = &c.b; | 1956 | pcf = &c.b; |
| 1957 | var pc: *const C = undefined; | 1957 | var pc: *const C = undefined; |
| ... | @@ -1960,7 +1960,7 @@ test "@fieldParentPtr tagged union all zero-bit fields" { | ... | @@ -1960,7 +1960,7 @@ test "@fieldParentPtr tagged union all zero-bit fields" { |
| 1960 | } | 1960 | } |
| 1961 | { | 1961 | { |
| 1962 | var c: C = undefined; | 1962 | var c: C = undefined; |
| 1963 | c = .{ .b = 0 }; | 1963 | c = .{ .b = {} }; |
| 1964 | var pcf: @TypeOf(&c.b) = undefined; | 1964 | var pcf: @TypeOf(&c.b) = undefined; |
| 1965 | pcf = &c.b; | 1965 | pcf = &c.b; |
| 1966 | var pc: *C = undefined; | 1966 | var pc: *C = undefined; |
test/behavior/fn.zig+1-1| ... | @@ -280,7 +280,7 @@ test "implicit cast fn call result to optional in field result" { | ... | @@ -280,7 +280,7 @@ test "implicit cast fn call result to optional in field result" { |
| 280 | test "void parameters" { | 280 | test "void parameters" { |
| 281 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; | 281 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| 282 | 282 | ||
| 283 | try voidFun(1, void{}, 2, {}); | 283 | try voidFun(1, {}, 2, {}); |
| 284 | } | 284 | } |
| 285 | fn voidFun(a: i32, b: void, c: i32, d: void) !void { | 285 | fn voidFun(a: i32, b: void, c: i32, d: void) !void { |
| 286 | _ = d; | 286 | _ = d; |
test/behavior/for.zig+5-1| ... | @@ -69,7 +69,11 @@ test "basic for loop" { | ... | @@ -69,7 +69,11 @@ test "basic for loop" { |
| 69 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 69 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 70 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 70 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 71 | 71 | ||
| 72 | const expected_result = [_]u8{ 9, 8, 7, 6, 0, 1, 2, 3 } ** 3; | 72 | const expected_result: [24]u8 = .{ |
| 73 | 9, 8, 7, 6, 0, 1, 2, 3, | ||
| 74 | 9, 8, 7, 6, 0, 1, 2, 3, | ||
| 75 | 9, 8, 7, 6, 0, 1, 2, 3, | ||
| 76 | }; | ||
| 73 | 77 | ||
| 74 | var buffer: [expected_result.len]u8 = undefined; | 78 | var buffer: [expected_result.len]u8 = undefined; |
| 75 | var buf_index: usize = 0; | 79 | var buf_index: usize = 0; |
test/behavior/int_comparison_elision.zig-1| ... | @@ -7,7 +7,6 @@ test "int comparison elision" { | ... | @@ -7,7 +7,6 @@ test "int comparison elision" { |
| 7 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | 7 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 8 | 8 | ||
| 9 | testIntEdges(u0); | 9 | testIntEdges(u0); |
| 10 | testIntEdges(i0); | ||
| 11 | testIntEdges(u1); | 10 | testIntEdges(u1); |
| 12 | testIntEdges(i1); | 11 | testIntEdges(i1); |
| 13 | testIntEdges(u4); | 12 | testIntEdges(u4); |
test/behavior/math.zig-1| ... | @@ -401,7 +401,6 @@ test "binary not" { | ... | @@ -401,7 +401,6 @@ test "binary not" { |
| 401 | try expect(not(u64, 0x0123_4567_89AB_CDEF) == 0xFEDC_BA98_7654_3210); | 401 | try expect(not(u64, 0x0123_4567_89AB_CDEF) == 0xFEDC_BA98_7654_3210); |
| 402 | try expect(not(u64, 0xFEDC_BA98_7654_3210) == 0x0123_4567_89AB_CDEF); | 402 | try expect(not(u64, 0xFEDC_BA98_7654_3210) == 0x0123_4567_89AB_CDEF); |
| 403 | 403 | ||
| 404 | try expect(not(i0, 0) == 0); | ||
| 405 | try expect(not(i1, 0) == -1); | 404 | try expect(not(i1, 0) == -1); |
| 406 | try expect(not(i1, -1) == 0); | 405 | try expect(not(i1, -1) == 0); |
| 407 | try expect(not(i5, -2) == 1); | 406 | try expect(not(i5, -2) == 1); |
test/behavior/memset.zig+2-2| ... | @@ -109,7 +109,7 @@ test "memset with large array element, runtime known" { | ... | @@ -109,7 +109,7 @@ test "memset with large array element, runtime known" { |
| 109 | 109 | ||
| 110 | const A = [128]u64; | 110 | const A = [128]u64; |
| 111 | var buf: [5]A = undefined; | 111 | var buf: [5]A = undefined; |
| 112 | var runtime_known_element = [_]u64{0} ** 128; | 112 | var runtime_known_element: A = @splat(0); |
| 113 | _ = &runtime_known_element; | 113 | _ = &runtime_known_element; |
| 114 | @memset(&buf, runtime_known_element); | 114 | @memset(&buf, runtime_known_element); |
| 115 | for (buf[0]) |elem| try expect(elem == 0); | 115 | for (buf[0]) |elem| try expect(elem == 0); |
| ... | @@ -127,7 +127,7 @@ test "memset with large array element, comptime known" { | ... | @@ -127,7 +127,7 @@ test "memset with large array element, comptime known" { |
| 127 | 127 | ||
| 128 | const A = [128]u64; | 128 | const A = [128]u64; |
| 129 | var buf: [5]A = undefined; | 129 | var buf: [5]A = undefined; |
| 130 | const comptime_known_element = [_]u64{0} ** 128; | 130 | const comptime_known_element: A = @splat(0); |
| 131 | @memset(&buf, comptime_known_element); | 131 | @memset(&buf, comptime_known_element); |
| 132 | for (buf[0]) |elem| try expect(elem == 0); | 132 | for (buf[0]) |elem| try expect(elem == 0); |
| 133 | for (buf[1]) |elem| try expect(elem == 0); | 133 | for (buf[1]) |elem| try expect(elem == 0); |
test/behavior/optional.zig+1-1| ... | @@ -621,7 +621,7 @@ test "copied optional doesn't alias source" { | ... | @@ -621,7 +621,7 @@ test "copied optional doesn't alias source" { |
| 621 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 621 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 622 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | 622 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 623 | 623 | ||
| 624 | var opt_x: ?[3]f32 = [_]f32{0.0} ** 3; | 624 | var opt_x: ?[3]f32 = @splat(0.0); |
| 625 | 625 | ||
| 626 | const x = opt_x.?; | 626 | const x = opt_x.?; |
| 627 | opt_x.?[0] = 15.0; | 627 | opt_x.?[0] = 15.0; |
test/behavior/packed-struct.zig+1-1| ... | @@ -883,7 +883,7 @@ test "pointer to container level packed struct field" { | ... | @@ -883,7 +883,7 @@ test "pointer to container level packed struct field" { |
| 883 | enable_5: bool, | 883 | enable_5: bool, |
| 884 | enable_6: bool, | 884 | enable_6: bool, |
| 885 | }, | 885 | }, |
| 886 | var arr = [_]u32{0} ** 2; | 886 | var arr: [2]u32 = @splat(0); |
| 887 | }; | 887 | }; |
| 888 | @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true; | 888 | @as(*S, @ptrCast(&S.arr[0])).other_bits.enable_3 = true; |
| 889 | try expect(S.arr[0] == 0x10000000); | 889 | try expect(S.arr[0] == 0x10000000); |
test/behavior/pointers.zig+1-1| ... | @@ -627,7 +627,7 @@ test "pointer to array has explicit alignment" { | ... | @@ -627,7 +627,7 @@ test "pointer to array has explicit alignment" { |
| 627 | return @alignCast(@as(*[4]Base2, @ptrCast(ptr))); | 627 | return @alignCast(@as(*[4]Base2, @ptrCast(ptr))); |
| 628 | } | 628 | } |
| 629 | }; | 629 | }; |
| 630 | var bases = [_]S.Base{.{ .a = 2 }} ** 4; | 630 | var bases: [4]S.Base = @splat(.{ .a = 2 }); |
| 631 | const casted = S.func(&bases); | 631 | const casted = S.func(&bases); |
| 632 | try expect(casted[0].a == 2); | 632 | try expect(casted[0].a == 2); |
| 633 | } | 633 | } |
test/behavior/popcount.zig+4-4| ... | @@ -88,16 +88,16 @@ test "@popCount vectors" { | ... | @@ -88,16 +88,16 @@ test "@popCount vectors" { |
| 88 | 88 | ||
| 89 | fn testPopCountVectors() !void { | 89 | fn testPopCountVectors() !void { |
| 90 | { | 90 | { |
| 91 | var x: @Vector(8, u32) = [1]u32{0xffffffff} ** 8; | 91 | var x: @Vector(8, u32) = @splat(0xffffffff); |
| 92 | _ = &x; | 92 | _ = &x; |
| 93 | const expected = [1]u6{32} ** 8; | 93 | const expected: [8]u6 = @splat(32); |
| 94 | const result: [8]u6 = @popCount(x); | 94 | const result: [8]u6 = @popCount(x); |
| 95 | try expect(std.mem.eql(u6, &expected, &result)); | 95 | try expect(std.mem.eql(u6, &expected, &result)); |
| 96 | } | 96 | } |
| 97 | { | 97 | { |
| 98 | var x: @Vector(8, i16) = [1]i16{-1} ** 8; | 98 | var x: @Vector(8, i16) = @splat(-1); |
| 99 | _ = &x; | 99 | _ = &x; |
| 100 | const expected = [1]u5{16} ** 8; | 100 | const expected: [8]u5 = @splat(16); |
| 101 | const result: [8]u5 = @popCount(x); | 101 | const result: [8]u5 = @popCount(x); |
| 102 | try expect(std.mem.eql(u5, &expected, &result)); | 102 | try expect(std.mem.eql(u5, &expected, &result)); |
| 103 | } | 103 | } |
test/behavior/reflection.zig+1-1| ... | @@ -31,7 +31,7 @@ test "reflection: @field" { | ... | @@ -31,7 +31,7 @@ test "reflection: @field" { |
| 31 | var f = Foo{ | 31 | var f = Foo{ |
| 32 | .one = 42, | 32 | .one = 42, |
| 33 | .two = true, | 33 | .two = true, |
| 34 | .three = void{}, | 34 | .three = {}, |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | try expect(f.one == f.one); | 37 | try expect(f.one == f.one); |
test/behavior/slice.zig+1-11| ... | @@ -314,7 +314,7 @@ test "C pointer slice access" { | ... | @@ -314,7 +314,7 @@ test "C pointer slice access" { |
| 314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 314 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 315 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 315 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 316 | 316 | ||
| 317 | var buf: [10]u32 = [1]u32{42} ** 10; | 317 | var buf: [10]u32 = @splat(42); |
| 318 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); | 318 | const c_ptr = @as([*c]const u32, @ptrCast(&buf)); |
| 319 | 319 | ||
| 320 | var runtime_zero: usize = 0; | 320 | var runtime_zero: usize = 0; |
| ... | @@ -768,16 +768,6 @@ test "array concat of slices gives ptr to array" { | ... | @@ -768,16 +768,6 @@ test "array concat of slices gives ptr to array" { |
| 768 | } | 768 | } |
| 769 | } | 769 | } |
| 770 | 770 | ||
| 771 | test "array mult of slice gives ptr to array" { | ||
| 772 | comptime { | ||
| 773 | var a: []const u8 = "aoeu"; | ||
| 774 | _ = &a; | ||
| 775 | const c = a ** 2; | ||
| 776 | try expect(std.mem.eql(u8, c, "aoeuaoeu")); | ||
| 777 | try expect(@TypeOf(c) == *const [8]u8); | ||
| 778 | } | ||
| 779 | } | ||
| 780 | |||
| 781 | test "slice bounds in comptime concatenation" { | 771 | test "slice bounds in comptime concatenation" { |
| 782 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 772 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 783 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 773 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
test/behavior/slice_sentinel_comptime.zig+31-28| ... | @@ -1,16 +1,19 @@ | ... | @@ -1,16 +1,19 @@ |
| 1 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 2 | 2 | ||
| 3 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 4 | const ff_10_u8: [10]u8 = @splat(0xFF); | ||
| 5 | |||
| 3 | test "comptime slice-sentinel in bounds (unterminated)" { | 6 | test "comptime slice-sentinel in bounds (unterminated)" { |
| 4 | // array | 7 | // array |
| 5 | comptime { | 8 | comptime { |
| 6 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 9 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 7 | const slice = target[0..3 :'d']; | 10 | const slice = target[0..3 :'d']; |
| 8 | _ = slice; | 11 | _ = slice; |
| 9 | } | 12 | } |
| 10 | 13 | ||
| 11 | // ptr_array | 14 | // ptr_array |
| 12 | comptime { | 15 | comptime { |
| 13 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 16 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 14 | var target = &buf; | 17 | var target = &buf; |
| 15 | const slice = target[0..3 :'d']; | 18 | const slice = target[0..3 :'d']; |
| 16 | _ = slice; | 19 | _ = slice; |
| ... | @@ -18,7 +21,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -18,7 +21,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 18 | 21 | ||
| 19 | // vector_ConstPtrSpecialBaseArray | 22 | // vector_ConstPtrSpecialBaseArray |
| 20 | comptime { | 23 | comptime { |
| 21 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 24 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 22 | var target: [*]u8 = &buf; | 25 | var target: [*]u8 = &buf; |
| 23 | const slice = target[0..3 :'d']; | 26 | const slice = target[0..3 :'d']; |
| 24 | _ = slice; | 27 | _ = slice; |
| ... | @@ -26,7 +29,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -26,7 +29,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 26 | 29 | ||
| 27 | // vector_ConstPtrSpecialRef | 30 | // vector_ConstPtrSpecialRef |
| 28 | comptime { | 31 | comptime { |
| 29 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 32 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 30 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 33 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 31 | const slice = target[0..3 :'d']; | 34 | const slice = target[0..3 :'d']; |
| 32 | _ = slice; | 35 | _ = slice; |
| ... | @@ -34,7 +37,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -34,7 +37,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 34 | 37 | ||
| 35 | // cvector_ConstPtrSpecialBaseArray | 38 | // cvector_ConstPtrSpecialBaseArray |
| 36 | comptime { | 39 | comptime { |
| 37 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 40 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 38 | var target: [*c]u8 = &buf; | 41 | var target: [*c]u8 = &buf; |
| 39 | const slice = target[0..3 :'d']; | 42 | const slice = target[0..3 :'d']; |
| 40 | _ = slice; | 43 | _ = slice; |
| ... | @@ -42,7 +45,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -42,7 +45,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 42 | 45 | ||
| 43 | // cvector_ConstPtrSpecialRef | 46 | // cvector_ConstPtrSpecialRef |
| 44 | comptime { | 47 | comptime { |
| 45 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 48 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 46 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 49 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 47 | const slice = target[0..3 :'d']; | 50 | const slice = target[0..3 :'d']; |
| 48 | _ = slice; | 51 | _ = slice; |
| ... | @@ -50,7 +53,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -50,7 +53,7 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 50 | 53 | ||
| 51 | // slice | 54 | // slice |
| 52 | comptime { | 55 | comptime { |
| 53 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 56 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 54 | var target: []u8 = &buf; | 57 | var target: []u8 = &buf; |
| 55 | const slice = target[0..3 :'d']; | 58 | const slice = target[0..3 :'d']; |
| 56 | _ = slice; | 59 | _ = slice; |
| ... | @@ -60,14 +63,14 @@ test "comptime slice-sentinel in bounds (unterminated)" { | ... | @@ -60,14 +63,14 @@ test "comptime slice-sentinel in bounds (unterminated)" { |
| 60 | test "comptime slice-sentinel in bounds (end,unterminated)" { | 63 | test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 61 | // array | 64 | // array |
| 62 | comptime { | 65 | comptime { |
| 63 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 66 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 64 | const slice = target[0..13 :0xff]; | 67 | const slice = target[0..13 :0xff]; |
| 65 | _ = slice; | 68 | _ = slice; |
| 66 | } | 69 | } |
| 67 | 70 | ||
| 68 | // ptr_array | 71 | // ptr_array |
| 69 | comptime { | 72 | comptime { |
| 70 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 73 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 71 | var target = &buf; | 74 | var target = &buf; |
| 72 | const slice = target[0..13 :0xff]; | 75 | const slice = target[0..13 :0xff]; |
| 73 | _ = slice; | 76 | _ = slice; |
| ... | @@ -75,7 +78,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -75,7 +78,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 75 | 78 | ||
| 76 | // vector_ConstPtrSpecialBaseArray | 79 | // vector_ConstPtrSpecialBaseArray |
| 77 | comptime { | 80 | comptime { |
| 78 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 81 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 79 | var target: [*]u8 = &buf; | 82 | var target: [*]u8 = &buf; |
| 80 | const slice = target[0..13 :0xff]; | 83 | const slice = target[0..13 :0xff]; |
| 81 | _ = slice; | 84 | _ = slice; |
| ... | @@ -83,7 +86,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -83,7 +86,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 83 | 86 | ||
| 84 | // vector_ConstPtrSpecialRef | 87 | // vector_ConstPtrSpecialRef |
| 85 | comptime { | 88 | comptime { |
| 86 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 89 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 87 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 90 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 88 | const slice = target[0..13 :0xff]; | 91 | const slice = target[0..13 :0xff]; |
| 89 | _ = slice; | 92 | _ = slice; |
| ... | @@ -91,7 +94,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -91,7 +94,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 91 | 94 | ||
| 92 | // cvector_ConstPtrSpecialBaseArray | 95 | // cvector_ConstPtrSpecialBaseArray |
| 93 | comptime { | 96 | comptime { |
| 94 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 97 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 95 | var target: [*c]u8 = &buf; | 98 | var target: [*c]u8 = &buf; |
| 96 | const slice = target[0..13 :0xff]; | 99 | const slice = target[0..13 :0xff]; |
| 97 | _ = slice; | 100 | _ = slice; |
| ... | @@ -99,7 +102,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -99,7 +102,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 99 | 102 | ||
| 100 | // cvector_ConstPtrSpecialRef | 103 | // cvector_ConstPtrSpecialRef |
| 101 | comptime { | 104 | comptime { |
| 102 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 105 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 103 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 106 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 104 | const slice = target[0..13 :0xff]; | 107 | const slice = target[0..13 :0xff]; |
| 105 | _ = slice; | 108 | _ = slice; |
| ... | @@ -107,7 +110,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -107,7 +110,7 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 107 | 110 | ||
| 108 | // slice | 111 | // slice |
| 109 | comptime { | 112 | comptime { |
| 110 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{0xff} ** 10; | 113 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ ff_10_u8; |
| 111 | var target: []u8 = &buf; | 114 | var target: []u8 = &buf; |
| 112 | const slice = target[0..13 :0xff]; | 115 | const slice = target[0..13 :0xff]; |
| 113 | _ = slice; | 116 | _ = slice; |
| ... | @@ -117,14 +120,14 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { | ... | @@ -117,14 +120,14 @@ test "comptime slice-sentinel in bounds (end,unterminated)" { |
| 117 | test "comptime slice-sentinel in bounds (terminated)" { | 120 | test "comptime slice-sentinel in bounds (terminated)" { |
| 118 | // array | 121 | // array |
| 119 | comptime { | 122 | comptime { |
| 120 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 123 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 121 | const slice = target[0..3 :'d']; | 124 | const slice = target[0..3 :'d']; |
| 122 | _ = slice; | 125 | _ = slice; |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | // ptr_array | 128 | // ptr_array |
| 126 | comptime { | 129 | comptime { |
| 127 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 130 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 128 | var target = &buf; | 131 | var target = &buf; |
| 129 | const slice = target[0..3 :'d']; | 132 | const slice = target[0..3 :'d']; |
| 130 | _ = slice; | 133 | _ = slice; |
| ... | @@ -132,7 +135,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -132,7 +135,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 132 | 135 | ||
| 133 | // vector_ConstPtrSpecialBaseArray | 136 | // vector_ConstPtrSpecialBaseArray |
| 134 | comptime { | 137 | comptime { |
| 135 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 138 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 136 | var target: [*]u8 = &buf; | 139 | var target: [*]u8 = &buf; |
| 137 | const slice = target[0..3 :'d']; | 140 | const slice = target[0..3 :'d']; |
| 138 | _ = slice; | 141 | _ = slice; |
| ... | @@ -140,7 +143,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -140,7 +143,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 140 | 143 | ||
| 141 | // vector_ConstPtrSpecialRef | 144 | // vector_ConstPtrSpecialRef |
| 142 | comptime { | 145 | comptime { |
| 143 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 146 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 144 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 147 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 145 | const slice = target[0..3 :'d']; | 148 | const slice = target[0..3 :'d']; |
| 146 | _ = slice; | 149 | _ = slice; |
| ... | @@ -148,7 +151,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -148,7 +151,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 148 | 151 | ||
| 149 | // cvector_ConstPtrSpecialBaseArray | 152 | // cvector_ConstPtrSpecialBaseArray |
| 150 | comptime { | 153 | comptime { |
| 151 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 154 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 152 | var target: [*c]u8 = &buf; | 155 | var target: [*c]u8 = &buf; |
| 153 | const slice = target[0..3 :'d']; | 156 | const slice = target[0..3 :'d']; |
| 154 | _ = slice; | 157 | _ = slice; |
| ... | @@ -156,7 +159,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -156,7 +159,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 156 | 159 | ||
| 157 | // cvector_ConstPtrSpecialRef | 160 | // cvector_ConstPtrSpecialRef |
| 158 | comptime { | 161 | comptime { |
| 159 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 162 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 160 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 163 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 161 | const slice = target[0..3 :'d']; | 164 | const slice = target[0..3 :'d']; |
| 162 | _ = slice; | 165 | _ = slice; |
| ... | @@ -164,7 +167,7 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -164,7 +167,7 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 164 | 167 | ||
| 165 | // slice | 168 | // slice |
| 166 | comptime { | 169 | comptime { |
| 167 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 170 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 168 | var target: []u8 = &buf; | 171 | var target: []u8 = &buf; |
| 169 | const slice = target[0..3 :'d']; | 172 | const slice = target[0..3 :'d']; |
| 170 | _ = slice; | 173 | _ = slice; |
| ... | @@ -174,14 +177,14 @@ test "comptime slice-sentinel in bounds (terminated)" { | ... | @@ -174,14 +177,14 @@ test "comptime slice-sentinel in bounds (terminated)" { |
| 174 | test "comptime slice-sentinel in bounds (on target sentinel)" { | 177 | test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 175 | // array | 178 | // array |
| 176 | comptime { | 179 | comptime { |
| 177 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 180 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 178 | const slice = target[0..14 :0]; | 181 | const slice = target[0..14 :0]; |
| 179 | _ = slice; | 182 | _ = slice; |
| 180 | } | 183 | } |
| 181 | 184 | ||
| 182 | // ptr_array | 185 | // ptr_array |
| 183 | comptime { | 186 | comptime { |
| 184 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 187 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 185 | var target = &buf; | 188 | var target = &buf; |
| 186 | const slice = target[0..14 :0]; | 189 | const slice = target[0..14 :0]; |
| 187 | _ = slice; | 190 | _ = slice; |
| ... | @@ -189,7 +192,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -189,7 +192,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 189 | 192 | ||
| 190 | // vector_ConstPtrSpecialBaseArray | 193 | // vector_ConstPtrSpecialBaseArray |
| 191 | comptime { | 194 | comptime { |
| 192 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 195 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 193 | var target: [*]u8 = &buf; | 196 | var target: [*]u8 = &buf; |
| 194 | const slice = target[0..14 :0]; | 197 | const slice = target[0..14 :0]; |
| 195 | _ = slice; | 198 | _ = slice; |
| ... | @@ -197,7 +200,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -197,7 +200,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 197 | 200 | ||
| 198 | // vector_ConstPtrSpecialRef | 201 | // vector_ConstPtrSpecialRef |
| 199 | comptime { | 202 | comptime { |
| 200 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 203 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 201 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); | 204 | var target: [*]u8 = @as([*]u8, @ptrCast(&buf)); |
| 202 | const slice = target[0..14 :0]; | 205 | const slice = target[0..14 :0]; |
| 203 | _ = slice; | 206 | _ = slice; |
| ... | @@ -205,7 +208,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -205,7 +208,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 205 | 208 | ||
| 206 | // cvector_ConstPtrSpecialBaseArray | 209 | // cvector_ConstPtrSpecialBaseArray |
| 207 | comptime { | 210 | comptime { |
| 208 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 211 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 209 | var target: [*c]u8 = &buf; | 212 | var target: [*c]u8 = &buf; |
| 210 | const slice = target[0..14 :0]; | 213 | const slice = target[0..14 :0]; |
| 211 | _ = slice; | 214 | _ = slice; |
| ... | @@ -213,7 +216,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -213,7 +216,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 213 | 216 | ||
| 214 | // cvector_ConstPtrSpecialRef | 217 | // cvector_ConstPtrSpecialRef |
| 215 | comptime { | 218 | comptime { |
| 216 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 219 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 217 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); | 220 | var target: [*c]u8 = @as([*c]u8, @ptrCast(&buf)); |
| 218 | const slice = target[0..14 :0]; | 221 | const slice = target[0..14 :0]; |
| 219 | _ = slice; | 222 | _ = slice; |
| ... | @@ -221,7 +224,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { | ... | @@ -221,7 +224,7 @@ test "comptime slice-sentinel in bounds (on target sentinel)" { |
| 221 | 224 | ||
| 222 | // slice | 225 | // slice |
| 223 | comptime { | 226 | comptime { |
| 224 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 227 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 225 | var target: []u8 = &buf; | 228 | var target: []u8 = &buf; |
| 226 | const slice = target[0..14 :0]; | 229 | const slice = target[0..14 :0]; |
| 227 | _ = slice; | 230 | _ = slice; |
test/behavior/struct.zig+3-3| ... | @@ -295,9 +295,9 @@ test "void struct fields" { | ... | @@ -295,9 +295,9 @@ test "void struct fields" { |
| 295 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 295 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 296 | 296 | ||
| 297 | const foo = VoidStructFieldsFoo{ | 297 | const foo = VoidStructFieldsFoo{ |
| 298 | .a = void{}, | 298 | .a = {}, |
| 299 | .b = 1, | 299 | .b = 1, |
| 300 | .c = void{}, | 300 | .c = {}, |
| 301 | }; | 301 | }; |
| 302 | try expect(foo.b == 1); | 302 | try expect(foo.b == 1); |
| 303 | try expect(@sizeOf(VoidStructFieldsFoo) == 4); | 303 | try expect(@sizeOf(VoidStructFieldsFoo) == 4); |
| ... | @@ -634,7 +634,7 @@ test "packed array 24bits" { | ... | @@ -634,7 +634,7 @@ test "packed array 24bits" { |
| 634 | try expect(@sizeOf(FooArray24Bits) == @sizeOf(u96)); | 634 | try expect(@sizeOf(FooArray24Bits) == @sizeOf(u96)); |
| 635 | } | 635 | } |
| 636 | 636 | ||
| 637 | var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1); | 637 | var bytes: [@sizeOf(FooArray24Bits) + 1]u8 = @splat(0); |
| 638 | bytes[bytes.len - 1] = 0xbb; | 638 | bytes[bytes.len - 1] = 0xbb; |
| 639 | const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0]; | 639 | const ptr = &std.mem.bytesAsSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0]; |
| 640 | try expect(ptr.a == 0); | 640 | try expect(ptr.a == 0); |
test/behavior/switch_loop.zig+2-2| ... | @@ -547,12 +547,12 @@ test "switch loop with packed unions" { | ... | @@ -547,12 +547,12 @@ test "switch loop with packed unions" { |
| 547 | test "switch loop with packed unions with OPV" { | 547 | test "switch loop with packed unions with OPV" { |
| 548 | const P = packed union { | 548 | const P = packed union { |
| 549 | a: u0, | 549 | a: u0, |
| 550 | b: i0, | 550 | b: void, |
| 551 | 551 | ||
| 552 | fn doTheTest(p: @This()) !void { | 552 | fn doTheTest(p: @This()) !void { |
| 553 | var looped = false; | 553 | var looped = false; |
| 554 | s: switch (p) { | 554 | s: switch (p) { |
| 555 | .{ .b = 0 } => |x| { | 555 | .{ .b = {} } => |x| { |
| 556 | comptime assert(x.a == 0); | 556 | comptime assert(x.a == 0); |
| 557 | if (looped) break :s; | 557 | if (looped) break :s; |
| 558 | looped = true; | 558 | looped = true; |
test/behavior/truncate.zig-25| ... | @@ -31,31 +31,6 @@ test "truncate.u0.var" { | ... | @@ -31,31 +31,6 @@ test "truncate.u0.var" { |
| 31 | try expect(z == 0); | 31 | try expect(z == 0); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | test "truncate i0 to larger integer allowed and has comptime-known result" { | ||
| 35 | var x: i0 = 0; | ||
| 36 | _ = &x; | ||
| 37 | const y: i8 = @truncate(x); | ||
| 38 | comptime assert(y == 0); | ||
| 39 | } | ||
| 40 | |||
| 41 | test "truncate.i0.literal" { | ||
| 42 | const z: i0 = @truncate(0); | ||
| 43 | try expect(z == 0); | ||
| 44 | } | ||
| 45 | |||
| 46 | test "truncate.i0.const" { | ||
| 47 | const c0: isize = 0; | ||
| 48 | const z: i0 = @truncate(c0); | ||
| 49 | try expect(z == 0); | ||
| 50 | } | ||
| 51 | |||
| 52 | test "truncate.i0.var" { | ||
| 53 | var d: i8 = 2; | ||
| 54 | _ = &d; | ||
| 55 | const z: i0 = @truncate(d); | ||
| 56 | try expect(z == 0); | ||
| 57 | } | ||
| 58 | |||
| 59 | test "truncate on comptime integer" { | 34 | test "truncate on comptime integer" { |
| 60 | const x: u16 = @truncate(9999); | 35 | const x: u16 = @truncate(9999); |
| 61 | try expect(x == 9999); | 36 | try expect(x == 9999); |
test/behavior/tuple.zig+1-24| ... | @@ -26,29 +26,6 @@ test "tuple concatenation" { | ... | @@ -26,29 +26,6 @@ test "tuple concatenation" { |
| 26 | try comptime S.doTheTest(); | 26 | try comptime S.doTheTest(); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | test "tuple multiplication" { | ||
| 30 | const S = struct { | ||
| 31 | fn doTheTest() !void { | ||
| 32 | { | ||
| 33 | const t = .{} ** 4; | ||
| 34 | try expect(@typeInfo(@TypeOf(t)).@"struct".fields.len == 0); | ||
| 35 | } | ||
| 36 | { | ||
| 37 | const t = .{'a'} ** 4; | ||
| 38 | try expect(@typeInfo(@TypeOf(t)).@"struct".fields.len == 4); | ||
| 39 | inline for (t) |x| try expect(x == 'a'); | ||
| 40 | } | ||
| 41 | { | ||
| 42 | const t = .{ 1, 2, 3 } ** 4; | ||
| 43 | try expect(@typeInfo(@TypeOf(t)).@"struct".fields.len == 12); | ||
| 44 | inline for (t, 0..) |x, i| try expect(x == 1 + i % 3); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | }; | ||
| 48 | try S.doTheTest(); | ||
| 49 | try comptime S.doTheTest(); | ||
| 50 | } | ||
| 51 | |||
| 52 | test "more tuple concatenation" { | 29 | test "more tuple concatenation" { |
| 53 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 30 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 54 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 31 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| ... | @@ -357,7 +334,7 @@ test "tuple of struct concatenation and coercion to array" { | ... | @@ -357,7 +334,7 @@ test "tuple of struct concatenation and coercion to array" { |
| 357 | const StructWithDefault = struct { value: f32 = 42 }; | 334 | const StructWithDefault = struct { value: f32 = 42 }; |
| 358 | const SomeStruct = struct { array: [4]StructWithDefault }; | 335 | const SomeStruct = struct { array: [4]StructWithDefault }; |
| 359 | 336 | ||
| 360 | const value1 = SomeStruct{ .array = .{StructWithDefault{}} ++ [_]StructWithDefault{.{}} ** 3 }; | 337 | const value1 = SomeStruct{ .array = .{StructWithDefault{}} ++ @as([3]StructWithDefault, @splat(.{})) }; |
| 361 | const value2 = SomeStruct{ .array = .{ .{}, .{}, .{}, .{} } }; | 338 | const value2 = SomeStruct{ .array = .{ .{}, .{}, .{}, .{} } }; |
| 362 | 339 | ||
| 363 | try expectEqual(value1, value2); | 340 | try expectEqual(value1, value2); |
test/behavior/tuple_declarations.zig-6| ... | @@ -42,12 +42,6 @@ test "tuple declaration usage" { | ... | @@ -42,12 +42,6 @@ test "tuple declaration usage" { |
| 42 | try expect(t[0] == 1); | 42 | try expect(t[0] == 1); |
| 43 | try expectEqualStrings(t[1], "foo"); | 43 | try expectEqualStrings(t[1], "foo"); |
| 44 | 44 | ||
| 45 | const mul = t ** 3; | ||
| 46 | try expect(@TypeOf(mul) != T); | ||
| 47 | try expect(mul.len == 6); | ||
| 48 | try expect(mul[2] == 1); | ||
| 49 | try expectEqualStrings(mul[3], "foo"); | ||
| 50 | |||
| 51 | var t2: T = .{ 2, "bar" }; | 45 | var t2: T = .{ 2, "bar" }; |
| 52 | _ = &t2; | 46 | _ = &t2; |
| 53 | const cat = t ++ t2; | 47 | const cat = t ++ t2; |
test/behavior/undefined.zig+1-1| ... | @@ -90,7 +90,7 @@ test "reslice of undefined global var slice" { | ... | @@ -90,7 +90,7 @@ test "reslice of undefined global var slice" { |
| 90 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 90 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 91 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 91 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 92 | 92 | ||
| 93 | var stack_buf: [100]u8 = [_]u8{0} ** 100; | 93 | var stack_buf: [100]u8 = @splat(0); |
| 94 | buf = &stack_buf; | 94 | buf = &stack_buf; |
| 95 | const x = buf[0..1]; | 95 | const x = buf[0..1]; |
| 96 | try @import("std").testing.expect(x.len == 1 and x[0] == 0); | 96 | try @import("std").testing.expect(x.len == 1 and x[0] == 0); |
test/behavior/union.zig+2-2| ... | @@ -138,7 +138,7 @@ const Agg = struct { | ... | @@ -138,7 +138,7 @@ const Agg = struct { |
| 138 | }; | 138 | }; |
| 139 | 139 | ||
| 140 | const v1 = Value{ .Int = 1234 }; | 140 | const v1 = Value{ .Int = 1234 }; |
| 141 | const v2 = Value{ .Array = [_]u8{3} ** 9 }; | 141 | const v2 = Value{ .Array = @splat(3) }; |
| 142 | 142 | ||
| 143 | const err = @as(anyerror!Agg, Agg{ | 143 | const err = @as(anyerror!Agg, Agg{ |
| 144 | .val1 = v1, | 144 | .val1 = v1, |
| ... | @@ -1156,7 +1156,7 @@ test "extern union most-aligned field is smaller" { | ... | @@ -1156,7 +1156,7 @@ test "extern union most-aligned field is smaller" { |
| 1156 | }, | 1156 | }, |
| 1157 | un: [110]u8, | 1157 | un: [110]u8, |
| 1158 | }; | 1158 | }; |
| 1159 | var a: ?U = .{ .un = [_]u8{0} ** 110 }; | 1159 | var a: ?U = .{ .un = @splat(0) }; |
| 1160 | _ = &a; | 1160 | _ = &a; |
| 1161 | try expect(a != null); | 1161 | try expect(a != null); |
| 1162 | } | 1162 | } |
test/behavior/void.zig+1-1| ... | @@ -44,7 +44,7 @@ test "void optional" { | ... | @@ -44,7 +44,7 @@ test "void optional" { |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | test "void array as a local variable initializer" { | 46 | test "void array as a local variable initializer" { |
| 47 | var x = [_]void{{}} ** 1004; | 47 | var x: [1004]void = @splat({}); |
| 48 | _ = &x[0]; | 48 | _ = &x[0]; |
| 49 | _ = x[0]; | 49 | _ = x[0]; |
| 50 | } | 50 | } |
test/c/unistd.zig+3-3| ... | @@ -22,14 +22,14 @@ test "swab" { | ... | @@ -22,14 +22,14 @@ test "swab" { |
| 22 | // n < 1 | 22 | // n < 1 |
| 23 | @memset(a[0..], '\x00'); | 23 | @memset(a[0..], '\x00'); |
| 24 | c.swab("abcd", &a, 0); | 24 | c.swab("abcd", &a, 0); |
| 25 | try testing.expectEqualSlices(u8, "\x00" ** 4, &a); | 25 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a); |
| 26 | c.swab("abcd", &a, -1); | 26 | c.swab("abcd", &a, -1); |
| 27 | try testing.expectEqualSlices(u8, "\x00" ** 4, &a); | 27 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a); |
| 28 | 28 | ||
| 29 | // Odd n | 29 | // Odd n |
| 30 | @memset(a[0..], '\x00'); | 30 | @memset(a[0..], '\x00'); |
| 31 | c.swab("abcd", &a, 1); | 31 | c.swab("abcd", &a, 1); |
| 32 | try testing.expectEqualSlices(u8, "\x00" ** 4, &a); | 32 | try testing.expectEqualSlices(u8, &.{ 0, 0, 0, 0 }, &a); |
| 33 | c.swab("abcd", &a, 3); | 33 | c.swab("abcd", &a, 3); |
| 34 | try testing.expectEqualSlices(u8, "ba\x00\x00", &a); | 34 | try testing.expectEqualSlices(u8, "ba\x00\x00", &a); |
| 35 | } | 35 | } |
test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | fn foo() void { | ||
| 2 | var sequence = "repeat".*** 10; | ||
| 3 | _ = sequence; | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // | ||
| 8 | // :2:28: error: '.*' cannot be followed by '*'; are you missing a space? | ||
test/cases/compile_errors/array_mult_with_number_type.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | const exponent: f32 = 1.0; | ||
| 2 | export fn entry(base: f32) f32 { | ||
| 3 | return base ** exponent; | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // | ||
| 8 | // :3:12: error: expected indexable; found 'f32' | ||
| 9 | // :3:17: note: this operator multiplies arrays; use std.math.pow for exponentiation | ||
test/cases/compile_errors/bad_void_initializer.zig created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | comptime { | ||
| 2 | _ = void{}; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // | ||
| 7 | // :2:13: error: type 'void' does not support array initialization syntax | ||
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..3 :0]; | 4 | const slice = target[0..3 :0]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..3 :0]; | 12 | const slice = target[0..3 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..3 :0]; | 20 | const slice = target[0..3 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..3 :0]; | 28 | const slice = target[0..3 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..3 :0]; | 36 | const slice = target[0..3 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..3 :0]; | 44 | const slice = target[0..3 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..3 :0]; | 52 | const slice = target[0..3 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..3 :0]; | 4 | const slice = target[0..3 :0]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..3 :0]; | 12 | const slice = target[0..3 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..3 :0]; | 20 | const slice = target[0..3 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..3 :0]; | 28 | const slice = target[0..3 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..3 :0]; | 36 | const slice = target[0..3 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..3 :0]; | 44 | const slice = target[0..3 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..3 :0]; | 52 | const slice = target[0..3 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/comptime_slice-sentinel_does_not_match_target-sentinel.zig+14-13| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..14 :255]; | 4 | const slice = target[0..14 :255]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..14 :255]; | 12 | const slice = target[0..14 :255]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..14 :255]; | 20 | const slice = target[0..14 :255]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..14 :255]; | 28 | const slice = target[0..14 :255]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..14 :255]; | 36 | const slice = target[0..14 :255]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..14 :255]; | 44 | const slice = target[0..14 :255]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..14 :255]; | 52 | const slice = target[0..14 :255]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | export fn undefined_slice() void { | 57 | export fn undefined_slice() void { |
| 57 | const arr: [100]u16 = undefined; | 58 | const arr: [100]u16 = undefined; |
| 58 | const slice = arr[0..12 :0]; | 59 | const slice = arr[0..12 :0]; |
| ... | @@ -85,9 +86,9 @@ export fn typeName_slice() void { | ... | @@ -85,9 +86,9 @@ export fn typeName_slice() void { |
| 85 | // :44:29: note: expected '255', found '0' | 86 | // :44:29: note: expected '255', found '0' |
| 86 | // :52:29: error: value in memory does not match slice sentinel | 87 | // :52:29: error: value in memory does not match slice sentinel |
| 87 | // :52:29: note: expected '255', found '0' | 88 | // :52:29: note: expected '255', found '0' |
| 88 | // :58:22: error: value in memory does not match slice sentinel | 89 | // :59:22: error: value in memory does not match slice sentinel |
| 89 | // :58:22: note: expected '0', found 'undefined' | 90 | // :59:22: note: expected '0', found 'undefined' |
| 90 | // :63:22: error: value in memory does not match slice sentinel | 91 | // :64:22: error: value in memory does not match slice sentinel |
| 91 | // :63:22: note: expected '12', found '98' | 92 | // :64:22: note: expected '12', found '98' |
| 92 | // :68:22: error: value in memory does not match slice sentinel | 93 | // :69:22: error: value in memory does not match slice sentinel |
| 93 | // :68:22: note: expected '0', found '105' | 94 | // :69:22: note: expected '0', found '105' |
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_terminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..15 :1]; | 4 | const slice = target[0..15 :1]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..15 :0]; | 12 | const slice = target[0..15 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..15 :0]; | 20 | const slice = target[0..15 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..15 :0]; | 28 | const slice = target[0..15 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..15 :0]; | 36 | const slice = target[0..15 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..15 :0]; | 44 | const slice = target[0..15 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..15 :0]; | 52 | const slice = target[0..15 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig+8-7| ... | @@ -1,13 +1,13 @@ | ... | @@ -1,13 +1,13 @@ |
| 1 | export fn foo_array() void { | 1 | export fn foo_array() void { |
| 2 | comptime { | 2 | comptime { |
| 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 3 | var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 4 | const slice = target[0..14 :0]; | 4 | const slice = target[0..14 :0]; |
| 5 | _ = slice; | 5 | _ = slice; |
| 6 | } | 6 | } |
| 7 | } | 7 | } |
| 8 | export fn foo_ptr_array() void { | 8 | export fn foo_ptr_array() void { |
| 9 | comptime { | 9 | comptime { |
| 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 10 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 11 | var target = &buf; | 11 | var target = &buf; |
| 12 | const slice = target[0..14 :0]; | 12 | const slice = target[0..14 :0]; |
| 13 | _ = slice; | 13 | _ = slice; |
| ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { | ... | @@ -15,7 +15,7 @@ export fn foo_ptr_array() void { |
| 15 | } | 15 | } |
| 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { | 16 | export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 17 | comptime { | 17 | comptime { |
| 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 18 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 19 | var target: [*]u8 = &buf; | 19 | var target: [*]u8 = &buf; |
| 20 | const slice = target[0..14 :0]; | 20 | const slice = target[0..14 :0]; |
| 21 | _ = slice; | 21 | _ = slice; |
| ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { | ... | @@ -23,7 +23,7 @@ export fn foo_vector_ConstPtrSpecialBaseArray() void { |
| 23 | } | 23 | } |
| 24 | export fn foo_vector_ConstPtrSpecialRef() void { | 24 | export fn foo_vector_ConstPtrSpecialRef() void { |
| 25 | comptime { | 25 | comptime { |
| 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 26 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 27 | var target: [*]u8 = @ptrCast(&buf); | 27 | var target: [*]u8 = @ptrCast(&buf); |
| 28 | const slice = target[0..14 :0]; | 28 | const slice = target[0..14 :0]; |
| 29 | _ = slice; | 29 | _ = slice; |
| ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { | ... | @@ -31,7 +31,7 @@ export fn foo_vector_ConstPtrSpecialRef() void { |
| 31 | } | 31 | } |
| 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { | 32 | export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 33 | comptime { | 33 | comptime { |
| 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 34 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 35 | var target: [*c]u8 = &buf; | 35 | var target: [*c]u8 = &buf; |
| 36 | const slice = target[0..14 :0]; | 36 | const slice = target[0..14 :0]; |
| 37 | _ = slice; | 37 | _ = slice; |
| ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { | ... | @@ -39,7 +39,7 @@ export fn foo_cvector_ConstPtrSpecialBaseArray() void { |
| 39 | } | 39 | } |
| 40 | export fn foo_cvector_ConstPtrSpecialRef() void { | 40 | export fn foo_cvector_ConstPtrSpecialRef() void { |
| 41 | comptime { | 41 | comptime { |
| 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 42 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 43 | var target: [*c]u8 = @ptrCast(&buf); | 43 | var target: [*c]u8 = @ptrCast(&buf); |
| 44 | const slice = target[0..14 :0]; | 44 | const slice = target[0..14 :0]; |
| 45 | _ = slice; | 45 | _ = slice; |
| ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { | ... | @@ -47,12 +47,13 @@ export fn foo_cvector_ConstPtrSpecialRef() void { |
| 47 | } | 47 | } |
| 48 | export fn foo_slice() void { | 48 | export fn foo_slice() void { |
| 49 | comptime { | 49 | comptime { |
| 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; | 50 | var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ undef_10_u8; |
| 51 | var target: []u8 = &buf; | 51 | var target: []u8 = &buf; |
| 52 | const slice = target[0..14 :0]; | 52 | const slice = target[0..14 :0]; |
| 53 | _ = slice; | 53 | _ = slice; |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | const undef_10_u8: [10]u8 = @splat(undefined); | ||
| 56 | 57 | ||
| 57 | // error | 58 | // error |
| 58 | // | 59 | // |
test/cases/compile_errors/dereference_bad_pointer_via_array_mul.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | const A = struct {}; | ||
| 2 | const B = struct {}; | ||
| 3 | comptime { | ||
| 4 | const val: [1]A = .{.{}}; | ||
| 5 | const ptr: *const [1]B = @ptrCast(&val); | ||
| 6 | _ = ptr ** 2; | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // | ||
| 11 | // :6:9: error: comptime dereference requires '[1]tmp.B' to have a well-defined layout | ||
test/cases/compile_errors/function_call_assigned_to_incorrect_type.zig+1-1| ... | @@ -3,7 +3,7 @@ export fn entry() void { | ... | @@ -3,7 +3,7 @@ export fn entry() void { |
| 3 | arr = concat(); | 3 | arr = concat(); |
| 4 | } | 4 | } |
| 5 | fn concat() [16]f32 { | 5 | fn concat() [16]f32 { |
| 6 | return [1]f32{0} ** 16; | 6 | return @splat(0.0); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | // error | 9 | // error |
test/cases/compile_errors/invalid_error_capture_discard.zig+6-13| ... | @@ -1,28 +1,21 @@ | ... | @@ -1,28 +1,21 @@ |
| 1 | export fn a() void { | 1 | export fn a() void { |
| 2 | errdefer |_| { | ||
| 3 | @"_"; | ||
| 4 | } | ||
| 5 | } | ||
| 6 | export fn b() void { | ||
| 7 | const x: error{}!void = {}; | 2 | const x: error{}!void = {}; |
| 8 | x catch |_| { | 3 | x catch |_| { |
| 9 | @"_"; | 4 | @"_"; |
| 10 | }; | 5 | }; |
| 11 | } | 6 | } |
| 12 | export fn c() void { | 7 | export fn b() void { |
| 13 | const x: error{}!void = {}; | 8 | const x: error{}!void = {}; |
| 14 | x catch |_| switch (_) {}; | 9 | x catch |_| switch (_) {}; |
| 15 | } | 10 | } |
| 16 | export fn d() void { | 11 | export fn c() void { |
| 17 | const x: error{}!u32 = 0; | 12 | const x: error{}!u32 = 0; |
| 18 | if (x) |v| v else |_| switch (_) {} | 13 | if (x) |v| v else |_| switch (_) {} |
| 19 | } | 14 | } |
| 20 | 15 | ||
| 21 | // error | 16 | // error |
| 22 | // | 17 | // |
| 23 | // :2:15: error: discard of error capture; omit it instead | 18 | // :3:14: error: discard of error capture; omit it instead |
| 24 | // :3:9: error: use of undeclared identifier '_' | 19 | // :4:9: error: use of undeclared identifier '_' |
| 25 | // :8:14: error: discard of error capture; omit it instead | 20 | // :9:14: error: discard of error capture; omit it instead |
| 26 | // :9:9: error: use of undeclared identifier '_' | 21 | // :13:24: error: discard of error capture; omit it instead |
| 27 | // :14:14: error: discard of error capture; omit it instead | ||
| 28 | // :18:24: error: discard of error capture; omit it instead |
test/cases/compile_errors/leading_zero_in_integer.zig+5-6| ... | @@ -3,7 +3,6 @@ export fn entry1() void { | ... | @@ -3,7 +3,6 @@ export fn entry1() void { |
| 3 | _ = T; | 3 | _ = T; |
| 4 | } | 4 | } |
| 5 | export fn entry2() void { | 5 | export fn entry2() void { |
| 6 | _ = i0; | ||
| 7 | _ = u0; | 6 | _ = u0; |
| 8 | var x: i01 = 1; | 7 | var x: i01 = 1; |
| 9 | _ = x; | 8 | _ = x; |
| ... | @@ -18,8 +17,8 @@ export fn entry4() void { | ... | @@ -18,8 +17,8 @@ export fn entry4() void { |
| 18 | // error | 17 | // error |
| 19 | // | 18 | // |
| 20 | // :2:15: error: primitive integer type 'u000123' has leading zero | 19 | // :2:15: error: primitive integer type 'u000123' has leading zero |
| 21 | // :8:12: error: primitive integer type 'i01' has leading zero | 20 | // :7:12: error: primitive integer type 'i01' has leading zero |
| 22 | // :12:9: error: number '000123' has leading zero | 21 | // :11:9: error: number '000123' has leading zero |
| 23 | // :12:9: note: use '0o' prefix for octal literals | 22 | // :11:9: note: use '0o' prefix for octal literals |
| 24 | // :15:9: error: number '01' has leading zero | 23 | // :14:9: error: number '01' has leading zero |
| 25 | // :15:9: note: use '0o' prefix for octal literals | 24 | // :14:9: note: use '0o' prefix for octal literals |
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | export fn foo() void { | 1 | export fn foo() void { |
| 2 | const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16; | 2 | const bytes: [16]u8 align(@alignOf([]const u8)) = @splat(0xFA); |
| 3 | _ = @as(*const []const u8, @ptrCast(&bytes)).*; | 3 | _ = @as(*const []const u8, @ptrCast(&bytes)).*; |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/unused_variable_error_on_errdefer.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | fn foo() !void { | ||
| 2 | errdefer |a| unreachable; | ||
| 3 | return error.A; | ||
| 4 | } | ||
| 5 | export fn entry() void { | ||
| 6 | foo() catch unreachable; | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // | ||
| 11 | // :2:15: error: unused capture | ||
test/cases/compile_errors/zero_width_nonexhaustive_enum.zig+1-7| ... | @@ -1,8 +1,3 @@ | ... | @@ -1,8 +1,3 @@ |
| 1 | comptime { | ||
| 2 | const E = enum(i0) { a, _ }; | ||
| 3 | _ = @as(E, undefined); | ||
| 4 | } | ||
| 5 | |||
| 6 | comptime { | 1 | comptime { |
| 7 | const E = enum(u0) { a, _ }; | 2 | const E = enum(u0) { a, _ }; |
| 8 | _ = @as(E, undefined); | 3 | _ = @as(E, undefined); |
| ... | @@ -16,5 +11,4 @@ comptime { | ... | @@ -16,5 +11,4 @@ comptime { |
| 16 | // error | 11 | // error |
| 17 | // | 12 | // |
| 18 | // :2:15: error: non-exhaustive enum specifies every value | 13 | // :2:15: error: non-exhaustive enum specifies every value |
| 19 | // :7:15: error: non-exhaustive enum specifies every value | 14 | // :7:29: error: enum tag value '1' too large for type 'u0' |
| 20 | // :12:29: error: enum tag value '1' too large for type 'u0' |
test/cases/safety/@intFromFloat cannot fit - boundary case - i0 max.zig	 deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
| 3 | _ = stack_trace; | ||
| 4 | if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) { | ||
| 5 | std.process.exit(0); | ||
| 6 | } | ||
| 7 | std.process.exit(1); | ||
| 8 | } | ||
| 9 | var x: f32 = 1.0; | ||
| 10 | pub fn main() !void { | ||
| 11 | _ = @as(i0, @intFromFloat(x)); | ||
| 12 | return error.TestFailed; | ||
| 13 | } | ||
| 14 | // run | ||
| 15 | // backend=selfhosted,llvm | ||
| 16 | // target=x86_64-linux,aarch64-linux | ||
test/cases/safety/@intFromFloat cannot fit - boundary case - i0 min.zig	 deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
| 3 | _ = stack_trace; | ||
| 4 | if (std.mem.eql(u8, message, "integer part of floating point value out of bounds")) { | ||
| 5 | std.process.exit(0); | ||
| 6 | } | ||
| 7 | std.process.exit(1); | ||
| 8 | } | ||
| 9 | var x: f32 = -1.0; | ||
| 10 | pub fn main() !void { | ||
| 11 | _ = @as(i0, @intFromFloat(x)); | ||
| 12 | return error.TestFailed; | ||
| 13 | } | ||
| 14 | // run | ||
| 15 | // backend=selfhosted,llvm | ||
| 16 | // target=x86_64-linux,aarch64-linux | ||
test/cases/safety/memcpy_alias.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer: [10]u8 = .{ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | 13 | _ = &len; |
| 14 | @memcpy(buffer[0..len], buffer[4 .. 4 + len]); | 14 | @memcpy(buffer[0..len], buffer[4 .. 4 + len]); |
test/cases/safety/memcpy_len_mismatch.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer: [10]u8 = .{ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | 13 | _ = &len; |
| 14 | @memcpy(buffer[0..len], buffer[len .. len + 4]); | 14 | @memcpy(buffer[0..len], buffer[len .. len + 4]); |
test/cases/safety/memmove_len_mismatch.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi | ... | @@ -8,7 +8,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi |
| 8 | std.process.exit(1); | 8 | std.process.exit(1); |
| 9 | } | 9 | } |
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var buffer = [2]u8{ 1, 2 } ** 5; | 11 | var buffer: [10]u8 = .{ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 }; |
| 12 | var len: usize = 5; | 12 | var len: usize = 5; |
| 13 | _ = &len; | 13 | _ = &len; |
| 14 | @memmove(buffer[0..len], buffer[len .. len + 4]); | 14 | @memmove(buffer[0..len], buffer[len .. len + 4]); |
test/src/Debugger.zig-2| ... | @@ -56,7 +56,6 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void { | ... | @@ -56,7 +56,6 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void { |
| 56 | \\ u24_16777215: u24 = 16777215, | 56 | \\ u24_16777215: u24 = 16777215, |
| 57 | \\ u32_0: u32 = 0, | 57 | \\ u32_0: u32 = 0, |
| 58 | \\ u32_4294967295: u32 = 4294967295, | 58 | \\ u32_4294967295: u32 = 4294967295, |
| 59 | \\ i0_0: i0 = 0, | ||
| 60 | \\ @"i1_-1": i1 = -1, | 59 | \\ @"i1_-1": i1 = -1, |
| 61 | \\ i1_0: i1 = 0, | 60 | \\ i1_0: i1 = 0, |
| 62 | \\ @"i2_-2": i2 = -2, | 61 | \\ @"i2_-2": i2 = -2, |
| ... | @@ -139,7 +138,6 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void { | ... | @@ -139,7 +138,6 @@ pub fn addTestsForTarget(db: *Debugger, target: *const Target) void { |
| 139 | \\ (u24) .u24_16777215 = 16777215 | 138 | \\ (u24) .u24_16777215 = 16777215 |
| 140 | \\ (u32) .u32_0 = 0 | 139 | \\ (u32) .u32_0 = 0 |
| 141 | \\ (u32) .u32_4294967295 = 4294967295 | 140 | \\ (u32) .u32_4294967295 = 4294967295 |
| 142 | \\ (i0) .i0_0 = 0 | ||
| 143 | \\ (i1) .@"i1_-1" = -1 | 141 | \\ (i1) .@"i1_-1" = -1 |
| 144 | \\ (i1) .i1_0 = 0 | 142 | \\ (i1) .i1_0 = 0 |
| 145 | \\ (i2) .@"i2_-2" = -2 | 143 | \\ (i2) .@"i2_-2" = -2 |
test/standalone/cmakedefine/build.zig+1-1| ... | @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { |
| 16 | .tenval = 10, | 16 | .tenval = 10, |
| 17 | .stringval = "test", | 17 | .stringval = "test", |
| 18 | 18 | ||
| 19 | .boolnoval = void{}, | 19 | .boolnoval = {}, |
| 20 | .booltrueval = true, | 20 | .booltrueval = true, |
| 21 | .boolfalseval = false, | 21 | .boolfalseval = false, |
| 22 | .boolzeroval = 0, | 22 | .boolzeroval = 0, |
test/tests.zig+3-1| ... | @@ -2465,7 +2465,9 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -2465,7 +2465,9 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 2465 | 2465 | ||
| 2466 | if (options.test_only) |test_only| { | 2466 | if (options.test_only) |test_only| { |
| 2467 | const test_target: ModuleTestTarget = switch (test_only) { | 2467 | const test_target: ModuleTestTarget = switch (test_only) { |
| 2468 | .default => module_test_targets[0], | 2468 | .default => .{ |
| 2469 | .link_libc = if (std.mem.eql(u8, options.name, "libc")) true else null, | ||
| 2470 | }, | ||
| 2469 | .fuzz => |optimize| .{ | 2471 | .fuzz => |optimize| .{ |
| 2470 | .optimize_mode = optimize, | 2472 | .optimize_mode = optimize, |
| 2471 | .use_llvm = true, | 2473 | .use_llvm = true, |
tools/docgen.zig+1-2| ... | @@ -871,7 +871,6 @@ fn tokenizeAndPrintRaw( | ... | @@ -871,7 +871,6 @@ fn tokenizeAndPrintRaw( |
| 871 | .minus_pipe_equal, | 871 | .minus_pipe_equal, |
| 872 | .asterisk, | 872 | .asterisk, |
| 873 | .asterisk_equal, | 873 | .asterisk_equal, |
| 874 | .asterisk_asterisk, | ||
| 875 | .asterisk_percent, | 874 | .asterisk_percent, |
| 876 | .asterisk_percent_equal, | 875 | .asterisk_percent_equal, |
| 877 | .asterisk_pipe, | 876 | .asterisk_pipe, |
| ... | @@ -897,7 +896,7 @@ fn tokenizeAndPrintRaw( | ... | @@ -897,7 +896,7 @@ fn tokenizeAndPrintRaw( |
| 897 | .tilde, | 896 | .tilde, |
| 898 | => try writeEscaped(out, src[token.loc.start..token.loc.end]), | 897 | => try writeEscaped(out, src[token.loc.start..token.loc.end]), |
| 899 | 898 | ||
| 900 | .invalid, .invalid_periodasterisks => return parseError( | 899 | .invalid => return parseError( |
| 901 | docgen_tokenizer, | 900 | docgen_tokenizer, |
| 902 | source_token, | 901 | source_token, |
| 903 | "syntax error", | 902 | "syntax error", |
tools/doctest.zig+1-2| ... | @@ -800,7 +800,6 @@ fn tokenizeAndPrint(arena: Allocator, out: *Writer, raw_src: []const u8) !void { | ... | @@ -800,7 +800,6 @@ fn tokenizeAndPrint(arena: Allocator, out: *Writer, raw_src: []const u8) !void { |
| 800 | .minus_pipe_equal, | 800 | .minus_pipe_equal, |
| 801 | .asterisk, | 801 | .asterisk, |
| 802 | .asterisk_equal, | 802 | .asterisk_equal, |
| 803 | .asterisk_asterisk, | ||
| 804 | .asterisk_percent, | 803 | .asterisk_percent, |
| 805 | .asterisk_percent_equal, | 804 | .asterisk_percent_equal, |
| 806 | .asterisk_pipe, | 805 | .asterisk_pipe, |
| ... | @@ -826,7 +825,7 @@ fn tokenizeAndPrint(arena: Allocator, out: *Writer, raw_src: []const u8) !void { | ... | @@ -826,7 +825,7 @@ fn tokenizeAndPrint(arena: Allocator, out: *Writer, raw_src: []const u8) !void { |
| 826 | .tilde, | 825 | .tilde, |
| 827 | => try writeEscaped(out, src[token.loc.start..token.loc.end]), | 826 | => try writeEscaped(out, src[token.loc.start..token.loc.end]), |
| 828 | 827 | ||
| 829 | .invalid, .invalid_periodasterisks => fatal("syntax error", .{}), | 828 | .invalid => fatal("syntax error", .{}), |
| 830 | } | 829 | } |
| 831 | index = token.loc.end; | 830 | index = token.loc.end; |
| 832 | } | 831 | } |
tools/fetch_them_macos_headers.zig+1-1| ... | @@ -237,7 +237,7 @@ const Version = struct { | ... | @@ -237,7 +237,7 @@ const Version = struct { |
| 237 | patch: u8, | 237 | patch: u8, |
| 238 | 238 | ||
| 239 | fn parse(raw: []const u8) ?Version { | 239 | fn parse(raw: []const u8) ?Version { |
| 240 | var parsed: [3]u16 = [_]u16{0} ** 3; | 240 | var parsed: [3]u16 = @splat(0); |
| 241 | var count: usize = 0; | 241 | var count: usize = 0; |
| 242 | var it = std.mem.splitAny(u8, raw, "."); | 242 | var it = std.mem.splitAny(u8, raw, "."); |
| 243 | while (it.next()) |comp| { | 243 | while (it.next()) |comp| { |
tools/gen_spirv_spec.zig+1-1| ... | @@ -732,7 +732,7 @@ fn renderBitEnum( | ... | @@ -732,7 +732,7 @@ fn renderBitEnum( |
| 732 | ) !void { | 732 | ) !void { |
| 733 | try writer.print("pub const {f} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)}); | 733 | try writer.print("pub const {f} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)}); |
| 734 | 734 | ||
| 735 | var flags_by_bitpos = [_]?usize{null} ** 32; | 735 | var flags_by_bitpos: [32]?usize = @splat(null); |
| 736 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; | 736 | const enumerants = enumeration.enumerants orelse return error.InvalidRegistry; |
| 737 | 737 | ||
| 738 | var aliases = std.array_list.Managed(struct { flag: usize, alias: u5 }).init(arena); | 738 | var aliases = std.array_list.Managed(struct { flag: usize, alias: u5 }).init(arena); |
tools/gen_stubs.zig+3-3| ... | @@ -702,12 +702,12 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: std.builtin.End | ... | @@ -702,12 +702,12 @@ fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: std.builtin.End |
| 702 | } | 702 | } |
| 703 | } else { | 703 | } else { |
| 704 | gop.value_ptr.* = .{ | 704 | gop.value_ptr.* = .{ |
| 705 | .present = [1]bool{false} ** arches.len, | 705 | .present = @splat(false), |
| 706 | .section = section_index_map[this_section], | 706 | .section = section_index_map[this_section], |
| 707 | .ty = ty, | 707 | .ty = ty, |
| 708 | .binding = [1]u4{0} ** arches.len, | 708 | .binding = @splat(0), |
| 709 | .visib = visib, | 709 | .visib = visib, |
| 710 | .size = [1]u64{0} ** arches.len, | 710 | .size = @splat(0), |
| 711 | }; | 711 | }; |
| 712 | } | 712 | } |
| 713 | gop.value_ptr.present[archIndex(parse.arch)] = true; | 713 | gop.value_ptr.present[archIndex(parse.arch)] = true; |
tools/generate_JSONTestSuite.zig+24-11| ... | @@ -4,15 +4,15 @@ const std = @import("std"); | ... | @@ -4,15 +4,15 @@ const std = @import("std"); |
| 4 | const Io = std.Io; | 4 | const Io = std.Io; |
| 5 | 5 | ||
| 6 | pub fn main(init: std.process.Init) !void { | 6 | pub fn main(init: std.process.Init) !void { |
| 7 | const allocator = init.gpa; | 7 | const allocator = init.arena.allocator(); |
| 8 | const io = init.io; | 8 | const io = init.io; |
| 9 | 9 | ||
| 10 | var stdout_buffer: [2000]u8 = undefined; | 10 | var stdout_buffer: [2000]u8 = undefined; |
| 11 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); | 11 | var stdout_writer = Io.File.stdout().writerStreaming(io, &stdout_buffer); |
| 12 | const output = &stdout_writer.interface; | 12 | const output = &stdout_writer.interface; |
| 13 | try output.writeAll( | 13 | try output.writeAll( |
| 14 | \\// This file was generated by _generate_JSONTestSuite.zig | 14 | \\//! This file was generated by _generate_JSONTestSuite.zig |
| 15 | \\// These test cases are sourced from: https://github.com/nst/JSONTestSuite | 15 | \\//! These test cases are sourced from: https://github.com/nst/JSONTestSuite |
| 16 | \\const ok = @import("./test.zig").ok; | 16 | \\const ok = @import("./test.zig").ok; |
| 17 | \\const err = @import("./test.zig").err; | 17 | \\const err = @import("./test.zig").err; |
| 18 | \\const any = @import("./test.zig").any; | 18 | \\const any = @import("./test.zig").any; |
| ... | @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -33,7 +33,7 @@ pub fn main(init: std.process.Init) !void { |
| 33 | }).lessThan); | 33 | }).lessThan); |
| 34 | 34 | ||
| 35 | for (names.items) |name| { | 35 | for (names.items) |name| { |
| 36 | const contents = try Io.Dir.cwd().readFileAlloc(io, name, allocator, .limited(250001)); | 36 | const contents = try Io.Dir.cwd().readFileAlloc(io, name, allocator, .limited(300000)); |
| 37 | try output.writeAll("test "); | 37 | try output.writeAll("test "); |
| 38 | try writeString(output, name); | 38 | try writeString(output, name); |
| 39 | try output.writeAll(" {\n try "); | 39 | try output.writeAll(" {\n try "); |
| ... | @@ -51,21 +51,34 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -51,21 +51,34 @@ pub fn main(init: std.process.Init) !void { |
| 51 | try output.flush(); | 51 | try output.flush(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500; | 54 | const i_structure_500_nested_arrays = &(@as([500]u8, @splat('[')) ++ @as([500]u8, @splat(']'))); |
| 55 | const n_structure_100000_opening_arrays = "[" ** 100000; | 55 | const n_structure_100000_opening_arrays: *const [100000]u8 = &@splat('['); |
| 56 | const n_structure_open_array_object = "[{\"\":" ** 50000 ++ "\n"; | 56 | const n_structure_open_array_object = str: { |
| 57 | const part = "[{\"\":"; | ||
| 58 | const buf: [50000][part.len]u8 = @splat(part.*); | ||
| 59 | const s: []const u8 = @ptrCast(&buf); | ||
| 60 | break :str s ++ "\n"; | ||
| 61 | }; | ||
| 57 | 62 | ||
| 58 | fn writeString(writer: anytype, s: []const u8) !void { | 63 | fn writeString(writer: anytype, s: []const u8) !void { |
| 59 | if (s.len > 200) { | 64 | if (s.len > 200) { |
| 60 | // There are a few of these we can compress with Zig expressions. | 65 | // There are a few of these we can compress with Zig expressions. |
| 61 | if (std.mem.eql(u8, s, i_structure_500_nested_arrays)) { | 66 | if (std.mem.eql(u8, s, i_structure_500_nested_arrays)) { |
| 62 | return writer.writeAll("\"[\" ** 500 ++ \"]\" ** 500"); | 67 | return writer.writeAll("&@as([500]u8, @splat('[')) ++ &@as([500]u8, @splat(']'))"); |
| 63 | } else if (std.mem.eql(u8, s, n_structure_100000_opening_arrays)) { | 68 | } else if (std.mem.eql(u8, s, n_structure_100000_opening_arrays)) { |
| 64 | return writer.writeAll("\"[\" ** 100000"); | 69 | return writer.writeAll("&@as([100000]u8, @splat('['))"); |
| 65 | } else if (std.mem.eql(u8, s, n_structure_open_array_object)) { | 70 | } else if (std.mem.eql(u8, s, n_structure_open_array_object)) { |
| 66 | return writer.writeAll("\"[{\\\"\\\":\" ** 50000 ++ \"\\n\""); | 71 | return writer.writeAll( |
| 72 | \\str: { | ||
| 73 | \\ const part = "[{\"\":"; | ||
| 74 | \\ const buf: [50000][part.len]u8 = @splat(part.*); | ||
| 75 | \\ const s: []const u8 = @ptrCast(&buf); | ||
| 76 | \\ break :str s ++ "\n"; | ||
| 77 | \\ } | ||
| 78 | ); | ||
| 79 | } else { | ||
| 80 | @panic("unhandled long string literal"); | ||
| 67 | } | 81 | } |
| 68 | unreachable; | ||
| 69 | } | 82 | } |
| 70 | try writer.writeByte('"'); | 83 | try writer.writeByte('"'); |
| 71 | for (s) |b| { | 84 | for (s) |b| { |
tools/update_cpu_features.zig+3-1| ... | @@ -2010,7 +2010,9 @@ const Job = struct { | ... | @@ -2010,7 +2010,9 @@ const Job = struct { |
| 2010 | }; | 2010 | }; |
| 2011 | 2011 | ||
| 2012 | fn processOneTarget(io: Io, job: Job) void { | 2012 | fn processOneTarget(io: Io, job: Job) void { |
| 2013 | errdefer |err| std.debug.panic("panic: {s}", .{@errorName(err)}); | 2013 | processOneTargetInner(io, job) catch |err| std.debug.panic("panic: {s}", .{@errorName(err)}); |
| 2014 | } | ||
| 2015 | fn processOneTargetInner(io: Io, job: Job) !void { | ||
| 2014 | const target = job.target; | 2016 | const target = job.target; |
| 2015 | 2017 | ||
| 2016 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); | 2018 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); |