different array literal syntax when inferring the size

old syntax:  []i32{1, 2, 3}
new syntax: [_]i32{1, 2, 3}

closes #1797
This commit is contained in:
Andrew Kelley 2019-06-09 19:24:24 -04:00
parent 10e33b3536
commit b735764898
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
106 changed files with 87054 additions and 86934 deletions

View File

@ -18,10 +18,10 @@ pub fn build(b: *Builder) !void {
const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
const langref_out_path = fs.path.join(
b.allocator,
[][]const u8{ b.cache_root, "langref.html" },
[_][]const u8{ b.cache_root, "langref.html" },
) catch unreachable;
var docgen_cmd = docgen_exe.run();
docgen_cmd.addArgs([][]const u8{
docgen_cmd.addArgs([_][]const u8{
rel_zig_exe,
"doc" ++ fs.path.sep_str ++ "langref.html.in",
langref_out_path,
@ -34,7 +34,7 @@ pub fn build(b: *Builder) !void {
const test_step = b.step("test", "Run all the tests");
// find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
const build_info = try b.exec([][]const u8{
const build_info = try b.exec([_][]const u8{
b.zig_exe,
"BUILD_INFO",
});
@ -55,7 +55,7 @@ pub fn build(b: *Builder) !void {
var test_stage2 = b.addTest("src-self-hosted/test.zig");
test_stage2.setBuildMode(builtin.Mode.Debug);
const fmt_build_zig = b.addFmt([][]const u8{"build.zig"});
const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"});
var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
exe.setBuildMode(mode);
@ -139,7 +139,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
}
const lib_dir = fs.path.join(
b.allocator,
[][]const u8{ dep.prefix, "lib" },
[_][]const u8{ dep.prefix, "lib" },
) catch unreachable;
for (dep.system_libs.toSliceConst()) |lib| {
const static_bare_name = if (mem.eql(u8, lib, "curses"))
@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
b.fmt("lib{}.a", lib);
const static_lib_name = fs.path.join(
b.allocator,
[][]const u8{ lib_dir, static_bare_name },
[_][]const u8{ lib_dir, static_bare_name },
) catch unreachable;
const have_static = fileExists(static_lib_name) catch unreachable;
if (have_static) {
@ -175,7 +175,7 @@ fn fileExists(filename: []const u8) !bool {
fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [][]const u8{
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{
cmake_binary_dir,
"zig_cpp",
b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()),
@ -191,22 +191,22 @@ const LibraryDep = struct {
};
fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
const shared_mode = try b.exec([][]const u8{ llvm_config_exe, "--shared-mode" });
const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" });
const is_static = mem.startsWith(u8, shared_mode, "static");
const libs_output = if (is_static)
try b.exec([][]const u8{
try b.exec([_][]const u8{
llvm_config_exe,
"--libfiles",
"--system-libs",
})
else
try b.exec([][]const u8{
try b.exec([_][]const u8{
llvm_config_exe,
"--libs",
});
const includes_output = try b.exec([][]const u8{ llvm_config_exe, "--includedir" });
const libdir_output = try b.exec([][]const u8{ llvm_config_exe, "--libdir" });
const prefix_output = try b.exec([][]const u8{ llvm_config_exe, "--prefix" });
const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });
const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" });
const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" });
var result = LibraryDep{
.prefix = mem.tokenize(prefix_output, " \r\n").next().?,
@ -255,10 +255,10 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
var it = mem.tokenize(stdlib_files, ";");
while (it.next()) |stdlib_file| {
const src_path = fs.path.join(b.allocator, [][]const u8{ "std", stdlib_file }) catch unreachable;
const src_path = fs.path.join(b.allocator, [_][]const u8{ "std", stdlib_file }) catch unreachable;
const dest_path = fs.path.join(
b.allocator,
[][]const u8{ "lib", "zig", "std", stdlib_file },
[_][]const u8{ "lib", "zig", "std", stdlib_file },
) catch unreachable;
b.installFile(src_path, dest_path);
}
@ -267,10 +267,10 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
var it = mem.tokenize(c_header_files, ";");
while (it.next()) |c_header_file| {
const src_path = fs.path.join(b.allocator, [][]const u8{ "c_headers", c_header_file }) catch unreachable;
const src_path = fs.path.join(b.allocator, [_][]const u8{ "c_headers", c_header_file }) catch unreachable;
const dest_path = fs.path.join(
b.allocator,
[][]const u8{ "lib", "zig", "include", c_header_file },
[_][]const u8{ "lib", "zig", "include", c_header_file },
) catch unreachable;
b.installFile(src_path, dest_path);
}
@ -354,7 +354,7 @@ fn addCxxKnownPath(
objname: []const u8,
errtxt: ?[]const u8,
) !void {
const path_padded = try b.exec([][]const u8{
const path_padded = try b.exec([_][]const u8{
ctx.cxx_compiler,
b.fmt("-print-file-name={}", objname),
});

View File

@ -717,7 +717,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
return buf.toOwnedSlice();
}
const builtin_types = [][]const u8{
const builtin_types = [_][]const u8{
"f16", "f32", "f64", "f128", "c_longdouble", "c_short",
"c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong",
"c_ulonglong", "c_char", "c_void", "void", "bool", "isize",
@ -1016,7 +1016,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
const tmp_source_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_ext },
[_][]const u8{ tmp_dir_name, name_plus_ext },
);
try io.writeFile(tmp_source_file_name, trimmed_raw_source);
@ -1025,11 +1025,11 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
const tmp_bin_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_bin_ext },
[_][]const u8{ tmp_dir_name, name_plus_bin_ext },
);
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
try build_args.appendSlice([][]const u8{
try build_args.appendSlice([_][]const u8{
zig_exe,
"build-exe",
tmp_source_file_name,
@ -1060,7 +1060,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
const full_path_object = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_with_ext },
[_][]const u8{ tmp_dir_name, name_with_ext },
);
try build_args.append("--object");
try build_args.append(full_path_object);
@ -1072,7 +1072,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
try out.print(" --library c");
}
if (code.target_str) |triple| {
try build_args.appendSlice([][]const u8{ "-target", triple });
try build_args.appendSlice([_][]const u8{ "-target", triple });
if (!code.is_inline) {
try out.print(" -target {}", triple);
}
@ -1123,7 +1123,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
}
const run_args = [][]const u8{tmp_bin_file_name};
const run_args = [_][]const u8{tmp_bin_file_name};
const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {
const result = try ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
@ -1157,7 +1157,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"test",
tmp_source_file_name,
@ -1181,7 +1181,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
},
}
if (code.target_str) |triple| {
try test_args.appendSlice([][]const u8{ "-target", triple });
try test_args.appendSlice([_][]const u8{ "-target", triple });
try out.print(" -target {}", triple);
}
const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
@ -1193,7 +1193,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"test",
"--color",
@ -1252,7 +1252,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"test",
tmp_source_file_name,
@ -1314,7 +1314,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
const tmp_obj_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_obj_ext },
[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
);
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
@ -1322,10 +1322,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
const output_h_file_name = try fs.path.join(
allocator,
[][]const u8{ tmp_dir_name, name_plus_h_ext },
[_][]const u8{ tmp_dir_name, name_plus_h_ext },
);
try build_args.appendSlice([][]const u8{
try build_args.appendSlice([_][]const u8{
zig_exe,
"build-obj",
tmp_source_file_name,
@ -1364,7 +1364,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
if (code.target_str) |triple| {
try build_args.appendSlice([][]const u8{ "-target", triple });
try build_args.appendSlice([_][]const u8{ "-target", triple });
try out.print(" -target {}", triple);
}
@ -1411,7 +1411,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
var test_args = std.ArrayList([]const u8).init(allocator);
defer test_args.deinit();
try test_args.appendSlice([][]const u8{
try test_args.appendSlice([_][]const u8{
zig_exe,
"build-lib",
tmp_source_file_name,
@ -1435,7 +1435,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
},
}
if (code.target_str) |triple| {
try test_args.appendSlice([][]const u8{ "-target", triple });
try test_args.appendSlice([_][]const u8{ "-target", triple });
try out.print(" -target {}", triple);
}
const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
@ -1476,7 +1476,7 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
}
fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
const result = try exec(allocator, env_map, []const []const u8{
const result = try exec(allocator, env_map, [_][]const u8{
zig_exe,
"builtin",
});

View File

@ -1530,10 +1530,10 @@ value == null{#endsyntax#}</pre>
</td>
<td>
<pre>{#syntax#}const mem = @import("std").mem;
const array1 = []u32{1,2};
const array2 = []u32{3,4};
const array1 = [_]u32{1,2};
const array2 = [_]u32{3,4};
const together = array1 ++ array2;
mem.eql(u32, together, []u32{1,2,3,4}){#endsyntax#}</pre>
mem.eql(u32, together, [_]u32{1,2,3,4}){#endsyntax#}</pre>
</td>
</tr>
<tr>
@ -1628,7 +1628,7 @@ const assert = @import("std").debug.assert;
const mem = @import("std").mem;
// array literal
const message = []u8{ 'h', 'e', 'l', 'l', 'o' };
const message = [_]u8{ 'h', 'e', 'l', 'l', 'o' };
// get the size of an array
comptime {
@ -1664,11 +1664,11 @@ test "modify an array" {
// array concatenation works if the values are known
// at compile time
const part_one = []i32{ 1, 2, 3, 4 };
const part_two = []i32{ 5, 6, 7, 8 };
const part_one = [_]i32{ 1, 2, 3, 4 };
const part_two = [_]i32{ 5, 6, 7, 8 };
const all_of_it = part_one ++ part_two;
comptime {
assert(mem.eql(i32, all_of_it, []i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
assert(mem.eql(i32, all_of_it, [_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
}
// remember that string literals are arrays
@ -1686,7 +1686,7 @@ comptime {
}
// initialize an array to zero
const all_zero = []u16{0} ** 10;
const all_zero = [_]u16{0} ** 10;
comptime {
assert(all_zero.len == 10);
@ -1715,7 +1715,7 @@ test "compile-time array initalization" {
}
// call a function to initialize an array
var more_points = []Point{makePoint(3)} ** 10;
var more_points = [_]Point{makePoint(3)} ** 10;
fn makePoint(x: i32) Point {
return Point{
.x = x,
@ -1819,7 +1819,7 @@ test "pointer array access" {
// Taking an address of an individual element gives a
// pointer to a single item. This kind of pointer
// does not support pointer arithmetic.
var array = []u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const ptr = &array[2];
assert(@typeOf(ptr) == *u8);
@ -1841,7 +1841,7 @@ test "pointer array access" {
const assert = @import("std").debug.assert;
test "pointer slicing" {
var array = []u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const slice = array[2..4];
assert(slice.len == 2);
@ -1922,7 +1922,7 @@ test "volatile" {
const assert = @import("std").debug.assert;
test "pointer casting" {
const bytes align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12 };
const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 };
const u32_ptr = @ptrCast(*const u32, &bytes);
assert(u32_ptr.* == 0x12121212);
@ -2011,7 +2011,7 @@ test "function alignment" {
const assert = @import("std").debug.assert;
test "pointer alignment safety" {
var array align(4) = []u32{ 0x11111111, 0x11111111 };
var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
const bytes = @sliceToBytes(array[0..]);
assert(foo(bytes) == 0x11111111);
}
@ -2048,7 +2048,7 @@ test "allowzero" {
const assert = @import("std").debug.assert;
test "basic slices" {
var array = []i32{ 1, 2, 3, 4 };
var array = [_]i32{ 1, 2, 3, 4 };
// A slice is a pointer and a length. The difference between an array and
// a slice is that the array's length is part of the type and known at
// compile-time, whereas the slice's length is known at runtime.
@ -2116,7 +2116,7 @@ test "slice pointer" {
test "slice widening" {
// Zig supports slice widening and slice narrowing. Cast a slice of u8
// to a slice of anything else, and Zig will perform the length conversion.
const array align(@alignOf(u32)) = []u8{ 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13 };
const array align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13 };
const slice = @bytesToSlice(u32, array[0..]);
assert(slice.len == 2);
assert(slice[0] == 0x12121212);
@ -3245,7 +3245,7 @@ fn typeNameLength(comptime T: type) usize {
const assert = @import("std").debug.assert;
test "for basics" {
const items = []i32 { 4, 5, 3, 4, 0 };
const items = [_]i32 { 4, 5, 3, 4, 0 };
var sum: i32 = 0;
// For loops iterate over slices and arrays.
@ -3275,7 +3275,7 @@ test "for basics" {
}
test "for reference" {
var items = []i32 { 3, 4, 2 };
var items = [_]i32 { 3, 4, 2 };
// Iterate over the slice by reference by
// specifying that the capture value is a pointer.
@ -3290,7 +3290,7 @@ test "for reference" {
test "for else" {
// For allows an else attached to it, the same as a while loop.
var items = []?i32 { 3, 4, null, 5 };
var items = [_]?i32 { 3, 4, null, 5 };
// For loops can also be used as expressions.
// Similar to while loops, when you break from a for loop, the else branch is not evaluated.
@ -3315,8 +3315,8 @@ const assert = std.debug.assert;
test "nested break" {
var count: usize = 0;
outer: for ([]i32{ 1, 2, 3, 4, 5 }) |_| {
for ([]i32{ 1, 2, 3, 4, 5 }) |_| {
outer: for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
count += 1;
break :outer;
}
@ -3326,8 +3326,8 @@ test "nested break" {
test "nested continue" {
var count: usize = 0;
outer: for ([]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }) |_| {
for ([]i32{ 1, 2, 3, 4, 5 }) |_| {
outer: for ([_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }) |_| {
for ([_]i32{ 1, 2, 3, 4, 5 }) |_| {
count += 1;
continue :outer;
}
@ -3349,7 +3349,7 @@ test "nested continue" {
const assert = @import("std").debug.assert;
test "inline for loop" {
const nums = []i32{2, 4, 6};
const nums = [_]i32{2, 4, 6};
var sum: usize = 0;
inline for (nums) |i| {
const T = switch (i) {
@ -4883,7 +4883,7 @@ test "peer type resolution: [0]u8 and []const u8" {
}
fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
if (a) {
return []const u8{};
return [_]u8{};
}
return slice[0..1];
@ -4904,7 +4904,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
}
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
if (a) {
return []u8{};
return [_]u8{};
}
return slice[0..1];
@ -5192,7 +5192,7 @@ const CmdFn = struct {
func: fn(i32) i32,
};
const cmd_fns = []CmdFn{
const cmd_fns = [_]CmdFn{
CmdFn {.name = "one", .func = one},
CmdFn {.name = "two", .func = two},
CmdFn {.name = "three", .func = three},
@ -5933,7 +5933,7 @@ async fn testAsyncSeq() void {
suspend;
seq('d');
}
var points = []u8{0} ** "abcdefg".len;
var points = [_]u8{0} ** "abcdefg".len;
var index: usize = 0;
fn seq(c: u8) void {
@ -6071,7 +6071,7 @@ async fn another() i32 {
return 1234;
}
var seq_points = []u8{0} ** "abcdefghi".len;
var seq_points = [_]u8{0} ** "abcdefghi".len;
var seq_index: usize = 0;
fn seq(c: u8) void {
@ -6225,7 +6225,7 @@ comptime {
{#header_close#}
{#header_open|@bitOffsetOf#}
<pre>{#syntax#}@bitOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}</pre>
<pre>{#syntax#}@bitOffsetOf(comptime T: type, comptime field_name: []const u8) comptime_int{#endsyntax#}</pre>
<p>
Returns the bit offset of a field relative to its containing struct.
</p>
@ -6283,7 +6283,7 @@ comptime {
{#header_close#}
{#header_open|@byteOffsetOf#}
<pre>{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: [] const u8) comptime_int{#endsyntax#}</pre>
<pre>{#syntax#}@byteOffsetOf(comptime T: type, comptime field_name: []const u8) comptime_int{#endsyntax#}</pre>
<p>
Returns the byte offset of a field relative to its containing struct.
</p>
@ -7391,7 +7391,7 @@ const std = @import("std");
const assert = std.debug.assert;
test "@This()" {
var items = []i32{ 1, 2, 3, 4 };
var items = [_]i32{ 1, 2, 3, 4 };
const list = List(i32){ .items = items[0..] };
assert(list.length() == 4);
}
@ -8305,7 +8305,7 @@ comptime {
<p>At runtime:</p>
{#code_begin|exe_err#}
pub fn main() !void {
var array align(4) = []u32{ 0x11111111, 0x11111111 };
var array align(4) = [_]u32{ 0x11111111, 0x11111111 };
const bytes = @sliceToBytes(array[0..]);
if (foo(bytes) != 0x11111111) return error.Wrong;
}
@ -8937,7 +8937,7 @@ pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");
@ -9002,7 +9002,7 @@ pub fn build(b: *Builder) void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addCExecutable("test");
exe.addCompileFlags([][]const u8 {
exe.addCompileFlags([_][]const u8 {
"-std=c99",
});
exe.addSourceFile("test.c");

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.addObject(obj);
exe.linkSystemLibrary("c");

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");

View File

@ -178,7 +178,7 @@ pub const Args = struct {
else => @panic("attempted to retrieve flag with wrong type"),
}
} else {
return []const []const u8{};
return [_][]const u8{};
}
}
};
@ -238,11 +238,11 @@ pub const Flag = struct {
};
test "parse arguments" {
const spec1 = comptime []const Flag{
const spec1 = comptime [_]Flag{
Flag.Bool("--help"),
Flag.Bool("--init"),
Flag.Arg1("--build-file"),
Flag.Option("--color", []const []const u8{
Flag.Option("--color", [_][]const u8{
"on",
"off",
"auto",
@ -252,7 +252,7 @@ test "parse arguments" {
Flag.ArgN("--library", 1),
};
const cliargs = []const []const u8{
const cliargs = [_][]const u8{
"build",
"--help",
"pos1",

View File

@ -15,7 +15,7 @@ pub const CInt = struct {
ULongLong,
};
pub const list = []CInt{
pub const list = [_]CInt{
CInt{
.id = Id.Short,
.zig_name = "c_short",

View File

@ -102,8 +102,8 @@ pub const ZigCompiler = struct {
/// Must be called only once, ever. Sets global state.
pub fn setLlvmArgv(allocator: *Allocator, llvm_argv: []const []const u8) !void {
if (llvm_argv.len != 0) {
var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [][]const []const u8{
[][]const u8{"zig (LLVM option parsing)"},
var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [_][]const []const u8{
[_][]const u8{"zig (LLVM option parsing)"},
llvm_argv,
});
defer c_compatible_args.deinit();
@ -421,20 +421,20 @@ pub const Compilation = struct {
.strip = false,
.is_static = is_static,
.linker_rdynamic = false,
.clang_argv = [][]const u8{},
.lib_dirs = [][]const u8{},
.rpath_list = [][]const u8{},
.assembly_files = [][]const u8{},
.link_objects = [][]const u8{},
.clang_argv = [_][]const u8{},
.lib_dirs = [_][]const u8{},
.rpath_list = [_][]const u8{},
.assembly_files = [_][]const u8{},
.link_objects = [_][]const u8{},
.fn_link_set = event.Locked(FnLinkSet).init(loop, FnLinkSet.init()),
.windows_subsystem_windows = false,
.windows_subsystem_console = false,
.link_libs_list = undefined,
.libc_link_lib = null,
.err_color = errmsg.Color.Auto,
.darwin_frameworks = [][]const u8{},
.darwin_frameworks = [_][]const u8{},
.darwin_version_min = DarwinVersionMin.None,
.test_filters = [][]const u8{},
.test_filters = [_][]const u8{},
.test_name_prefix = null,
.emit_file_type = Emit.Binary,
.link_out_file = null,
@ -487,7 +487,7 @@ pub const Compilation = struct {
comp.name = try Buffer.init(comp.arena(), name);
comp.llvm_triple = try target.getTriple(comp.arena());
comp.llvm_target = try Target.llvmTargetFromTriple(comp.llvm_triple);
comp.zig_std_dir = try std.fs.path.join(comp.arena(), [][]const u8{ zig_lib_dir, "std" });
comp.zig_std_dir = try std.fs.path.join(comp.arena(), [_][]const u8{ zig_lib_dir, "std" });
const opt_level = switch (build_mode) {
builtin.Mode.Debug => llvm.CodeGenLevelNone,
@ -1196,7 +1196,7 @@ pub const Compilation = struct {
const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
defer self.gpa().free(file_name);
const full_path = try std.fs.path.join(self.gpa(), [][]const u8{ tmp_dir, file_name[0..] });
const full_path = try std.fs.path.join(self.gpa(), [_][]const u8{ tmp_dir, file_name[0..] });
errdefer self.gpa().free(full_path);
return Buffer.fromOwnedSlice(self.gpa(), full_path);
@ -1217,7 +1217,7 @@ pub const Compilation = struct {
const zig_dir_path = try getZigDir(self.gpa());
defer self.gpa().free(zig_dir_path);
const tmp_dir = try std.fs.path.join(self.arena(), [][]const u8{ zig_dir_path, comp_dir_name[0..] });
const tmp_dir = try std.fs.path.join(self.arena(), [_][]const u8{ zig_dir_path, comp_dir_name[0..] });
try std.fs.makePath(self.gpa(), tmp_dir);
return tmp_dir;
}

View File

@ -900,7 +900,7 @@ fn printLabel(out: var, label: []const u8, bytes: []const u8) !void {
var i: usize = text.len;
const end = 79;
while (i < 79) : (i += 1) {
try out.write([]const u8{label[0]});
try out.write([_]u8{label[0]});
}
try out.write("\n");
}
@ -993,7 +993,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
fn printCharValues(out: var, bytes: []const u8) !void {
for (bytes) |b| {
try out.write([]const u8{printable_char_tab[b]});
try out.write([_]u8{printable_char_tab[b]});
}
}
@ -1002,7 +1002,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
std.fmt.format(out.context, anyerror, out.output, "\\x{X2}", char) catch {};
} else {
try out.write("'");
try out.write([]const u8{printable_char_tab[char]});
try out.write([_]u8{printable_char_tab[char]});
try out.write("'");
}
}

View File

@ -8,10 +8,10 @@ const warn = std.debug.warn;
/// Caller must free result
pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
const test_zig_dir = try fs.path.join(allocator, [][]const u8{ test_path, "lib", "zig" });
const test_zig_dir = try fs.path.join(allocator, [_][]const u8{ test_path, "lib", "zig" });
errdefer allocator.free(test_zig_dir);
const test_index_file = try fs.path.join(allocator, [][]const u8{ test_zig_dir, "std", "std.zig" });
const test_index_file = try fs.path.join(allocator, [_][]const u8{ test_zig_dir, "std", "std.zig" });
defer allocator.free(test_index_file);
var file = try fs.File.openRead(test_index_file);

View File

@ -35,7 +35,7 @@ pub const LibCInstallation = struct {
) !void {
self.initEmpty();
const keys = []const []const u8{
const keys = [_][]const u8{
"include_dir",
"lib_dir",
"static_lib_dir",
@ -183,7 +183,7 @@ pub const LibCInstallation = struct {
async fn findNativeIncludeDirLinux(self: *LibCInstallation, loop: *event.Loop) !void {
const cc_exe = std.os.getenv("CC") orelse "cc";
const argv = []const []const u8{
const argv = [_][]const u8{
cc_exe,
"-E",
"-Wp,-v",
@ -231,7 +231,7 @@ pub const LibCInstallation = struct {
while (path_i < search_paths.len) : (path_i += 1) {
const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
const stdlib_path = try fs.path.join(loop.allocator, [][]const u8{ search_path, "stdlib.h" });
const stdlib_path = try fs.path.join(loop.allocator, [_][]const u8{ search_path, "stdlib.h" });
defer loop.allocator.free(stdlib_path);
if (try fileExists(stdlib_path)) {
@ -257,7 +257,7 @@ pub const LibCInstallation = struct {
const stdlib_path = try fs.path.join(
loop.allocator,
[][]const u8{ result_buf.toSliceConst(), "stdlib.h" },
[_][]const u8{ result_buf.toSliceConst(), "stdlib.h" },
);
defer loop.allocator.free(stdlib_path);
@ -289,7 +289,7 @@ pub const LibCInstallation = struct {
}
const ucrt_lib_path = try fs.path.join(
loop.allocator,
[][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },
[_][]const u8{ result_buf.toSliceConst(), "ucrt.lib" },
);
defer loop.allocator.free(ucrt_lib_path);
if (try fileExists(ucrt_lib_path)) {
@ -309,7 +309,7 @@ pub const LibCInstallation = struct {
}
async fn findNativeDynamicLinker(self: *LibCInstallation, loop: *event.Loop) FindError!void {
var dyn_tests = []DynTest{
var dyn_tests = [_]DynTest{
DynTest{
.name = "ld-linux-x86-64.so.2",
.result = null,
@ -367,7 +367,7 @@ pub const LibCInstallation = struct {
}
const kernel32_path = try fs.path.join(
loop.allocator,
[][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },
[_][]const u8{ result_buf.toSliceConst(), "kernel32.lib" },
);
defer loop.allocator.free(kernel32_path);
if (try fileExists(kernel32_path)) {
@ -395,7 +395,7 @@ async fn ccPrintFileName(loop: *event.Loop, o_file: []const u8, want_dirname: bo
const cc_exe = std.os.getenv("CC") orelse "cc";
const arg1 = try std.fmt.allocPrint(loop.allocator, "-print-file-name={}", o_file);
defer loop.allocator.free(arg1);
const argv = []const []const u8{ cc_exe, arg1 };
const argv = [_][]const u8{ cc_exe, arg1 };
// TODO This simulates evented I/O for the child process exec
await (async loop.yield() catch unreachable);

View File

@ -311,7 +311,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
}
fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
const full_path = try std.fs.path.join(&ctx.arena.allocator, [][]const u8{ dirname, basename });
const full_path = try std.fs.path.join(&ctx.arena.allocator, [_][]const u8{ dirname, basename });
const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
try ctx.args.append(full_path_with_null.ptr);
}
@ -722,7 +722,7 @@ fn darwinGetReleaseVersion(str: []const u8, major: *u32, minor: *u32, micro: *u3
return error.InvalidDarwinVersionString;
var start_pos: usize = 0;
for ([]*u32{ major, minor, micro }) |v| {
for ([_]*u32{ major, minor, micro }) |v| {
const dot_pos = mem.indexOfScalarPos(u8, str, start_pos, '.');
const end_pos = dot_pos orelse str.len;
v.* = std.fmt.parseUnsigned(u32, str[start_pos..end_pos], 10) catch return error.InvalidDarwinVersionString;

View File

@ -74,7 +74,7 @@ pub fn main() !void {
process.exit(1);
}
const commands = []Command{
const commands = [_]Command{
Command{
.name = "build-exe",
.exec = cmdBuildExe,
@ -190,14 +190,14 @@ const usage_build_generic =
\\
;
const args_build_generic = []Flag{
const args_build_generic = [_]Flag{
Flag.Bool("--help"),
Flag.Option("--color", []const []const u8{
Flag.Option("--color", [_][]const u8{
"auto",
"off",
"on",
}),
Flag.Option("--mode", []const []const u8{
Flag.Option("--mode", [_][]const u8{
"debug",
"release-fast",
"release-safe",
@ -205,7 +205,7 @@ const args_build_generic = []Flag{
}),
Flag.ArgMergeN("--assembly", 1),
Flag.Option("--emit", []const []const u8{
Flag.Option("--emit", [_][]const u8{
"asm",
"bin",
"llvm-ir",
@ -525,10 +525,10 @@ pub const usage_fmt =
\\
;
pub const args_fmt_spec = []Flag{
pub const args_fmt_spec = [_]Flag{
Flag.Bool("--help"),
Flag.Bool("--check"),
Flag.Option("--color", []const []const u8{
Flag.Option("--color", [_][]const u8{
"auto",
"off",
"on",
@ -756,7 +756,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
var group = event.Group(FmtError!void).init(fmt.loop);
while (try dir.next()) |entry| {
if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
const full_path = try fs.path.join(fmt.loop.allocator, [][]const u8{ file_path, entry.name });
const full_path = try fs.path.join(fmt.loop.allocator, [_][]const u8{ file_path, entry.name });
try group.call(fmtPath, fmt, full_path, check_mode);
}
}
@ -855,7 +855,7 @@ fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
try stdout.print("{}\n", std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING));
}
const args_test_spec = []Flag{Flag.Bool("--help")};
const args_test_spec = [_]Flag{Flag.Bool("--help")};
fn cmdHelp(allocator: *Allocator, args: []const []const u8) !void {
try stdout.write(usage);
@ -897,7 +897,7 @@ fn cmdInternal(allocator: *Allocator, args: []const []const u8) !void {
process.exit(1);
}
const sub_commands = []Command{Command{
const sub_commands = [_]Command{Command{
.name = "build-info",
.exec = cmdInternalBuildInfo,
}};

View File

@ -287,7 +287,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
while (try dir.next()) |entry| {
if (entry.kind == fs.Dir.Entry.Kind.Directory or mem.endsWith(u8, entry.name, ".zig")) {
const full_path = try fs.path.join(fmt.allocator, [][]const u8{ file_path, entry.name });
const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
try fmtPath(fmt, full_path, check_mode);
}
}

View File

@ -391,7 +391,7 @@ pub const Value = struct {
const array_llvm_value = (try base_array.val.getLlvmConst(ofile)).?;
const ptr_bit_count = ofile.comp.target_ptr_bits;
const usize_llvm_type = llvm.IntTypeInContext(ofile.context, ptr_bit_count) orelse return error.OutOfMemory;
const indices = []*llvm.Value{
const indices = [_]*llvm.Value{
llvm.ConstNull(usize_llvm_type) orelse return error.OutOfMemory,
llvm.ConstInt(usize_llvm_type, base_array.elem_index, 0) orelse return error.OutOfMemory,
};

View File

@ -460,6 +460,7 @@ enum NodeType {
NodeTypeContainerInitExpr,
NodeTypeStructValueField,
NodeTypeArrayType,
NodeTypeInferredArrayType,
NodeTypeErrorType,
NodeTypeIfErrorExpr,
NodeTypeIfOptional,
@ -685,6 +686,10 @@ struct AstNodePointerType {
bool is_volatile;
};
struct AstNodeInferredArrayType {
AstNode *child_type;
};
struct AstNodeArrayType {
AstNode *size;
AstNode *child_type;
@ -989,6 +994,7 @@ struct AstNode {
AstNodeContinueExpr continue_expr;
AstNodeUnreachableExpr unreachable_expr;
AstNodeArrayType array_type;
AstNodeInferredArrayType inferred_array_type;
AstNodeErrorType error_type;
AstNodeErrorSetDecl err_set_decl;
AstNodeCancelExpr cancel_expr;
@ -2590,6 +2596,7 @@ struct IrInstructionContainerInitList {
IrInstruction base;
IrInstruction *container_type;
IrInstruction *elem_type;
size_t item_count;
IrInstruction **items;
LLVMValueRef tmp_ptr;

View File

@ -3024,6 +3024,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
case NodeTypeContainerInitExpr:
case NodeTypeStructValueField:
case NodeTypeArrayType:
case NodeTypeInferredArrayType:
case NodeTypeErrorType:
case NodeTypeIfErrorExpr:
case NodeTypeIfOptional:

View File

@ -239,6 +239,8 @@ static const char *node_type_str(NodeType node_type) {
return "ContainerInitExpr";
case NodeTypeArrayType:
return "ArrayType";
case NodeTypeInferredArrayType:
return "InferredArrayType";
case NodeTypeErrorType:
return "ErrorType";
case NodeTypeIfErrorExpr:
@ -848,6 +850,12 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
render_node_ungrouped(ar, node->data.array_type.child_type);
break;
}
case NodeTypeInferredArrayType:
{
fprintf(ar->f, "[_]");
render_node_ungrouped(ar, node->data.inferred_array_type.child_type);
break;
}
case NodeTypePromiseType:
{
fprintf(ar->f, "promise");

View File

@ -1427,15 +1427,17 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour
}
static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,
IrInstruction *container_type, size_t item_count, IrInstruction **items)
IrInstruction *container_type, IrInstruction *elem_type, size_t item_count, IrInstruction **items)
{
IrInstructionContainerInitList *container_init_list_instruction =
ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);
container_init_list_instruction->container_type = container_type;
container_init_list_instruction->elem_type = elem_type;
container_init_list_instruction->item_count = item_count;
container_init_list_instruction->items = items;
if (container_type != nullptr) ir_ref_instruction(container_type, irb->current_basic_block);
if (elem_type != nullptr) ir_ref_instruction(elem_type, irb->current_basic_block);
for (size_t i = 0; i < item_count; i += 1) {
ir_ref_instruction(items[i], irb->current_basic_block);
}
@ -5396,11 +5398,25 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;
ContainerInitKind kind = container_init_expr->kind;
IrInstruction *container_type = ir_gen_node(irb, container_init_expr->type, scope);
if (container_type == irb->codegen->invalid_instruction)
return container_type;
IrInstruction *container_type = nullptr;
IrInstruction *elem_type = nullptr;
if (container_init_expr->type->type == NodeTypeInferredArrayType) {
elem_type = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.child_type, scope);
if (elem_type == irb->codegen->invalid_instruction)
return elem_type;
} else {
container_type = ir_gen_node(irb, container_init_expr->type, scope);
if (container_type == irb->codegen->invalid_instruction)
return container_type;
}
if (kind == ContainerInitKindStruct) {
if (elem_type != nullptr) {
add_node_error(irb->codegen, container_init_expr->type,
buf_sprintf("initializing array with struct syntax"));
return irb->codegen->invalid_instruction;
}
size_t field_count = container_init_expr->entries.length;
IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);
for (size_t i = 0; i < field_count; i += 1) {
@ -5429,7 +5445,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
values[i] = expr_value;
}
return ir_build_container_init_list(irb, scope, node, container_type, item_count, values);
return ir_build_container_init_list(irb, scope, node, container_type, elem_type, item_count, values);
} else {
zig_unreachable();
}
@ -7693,6 +7709,10 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
return ir_lval_wrap(irb, scope, ir_gen_suspend(irb, scope, node), lval);
case NodeTypeEnumLiteral:
return ir_lval_wrap(irb, scope, ir_gen_enum_literal(irb, scope, node), lval);
case NodeTypeInferredArrayType:
add_node_error(irb->codegen, node,
buf_sprintf("inferred array size invalid here"));
return irb->codegen->invalid_instruction;
}
zig_unreachable();
}
@ -17961,16 +17981,31 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
{
Error err;
ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
size_t elem_count = instruction->item_count;
if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
ZigType *container_type;
if (instruction->container_type != nullptr) {
container_type = ir_resolve_type(ira, instruction->container_type->child);
if (type_is_invalid(container_type))
return ira->codegen->invalid_instruction;
} else {
ZigType *elem_type = ir_resolve_type(ira, instruction->elem_type->child);
if (type_is_invalid(elem_type))
return ira->codegen->invalid_instruction;
if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown))) {
return ira->codegen->invalid_instruction;
}
container_type = get_array_type(ira->codegen, elem_type, elem_count);
}
if (is_slice(container_type)) {
ir_add_error(ira, &instruction->base,
buf_sprintf("expected array type or [_], found slice"));
return ira->codegen->invalid_instruction;
} else if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) {
return ir_analyze_container_init_fields(ira, &instruction->base, container_type,
0, nullptr);
} else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) {
} else if (container_type->id == ZigTypeIdArray) {
// array is same as slice init but we make a compile error if the length is wrong
ZigType *child_type;
if (container_type->id == ZigTypeIdArray) {
@ -18057,7 +18092,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
IrInstruction *new_instruction = ir_build_container_init_list(&ira->new_irb,
instruction->base.scope, instruction->base.source_node,
nullptr, elem_count, new_items);
nullptr, nullptr, elem_count, new_items);
new_instruction->value.type = fixed_size_array_type;
ir_add_alloca(ira, new_instruction, fixed_size_array_type);
return new_instruction;

View File

@ -288,6 +288,9 @@ static AstNode *ast_parse_prefix_op_expr(
case NodeTypeArrayType:
right = &prefix->data.array_type.child_type;
break;
case NodeTypeInferredArrayType:
right = &prefix->data.inferred_array_type.child_type;
break;
case NodeTypePointerType: {
// We might get two pointers from *_ptr_type_start
AstNode *child = prefix->data.pointer_type.op_expr;
@ -1852,11 +1855,15 @@ static AstNode *ast_parse_asm_output(ParseContext *pc) {
// AsmOutputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN (MINUSRARROW TypeExpr / IDENTIFIER) RPAREN
static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr)
return nullptr;
Token *sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
Token *sym_name = eat_token_if(pc, TokenIdBracketUnderscoreBracket);
if (sym_name == nullptr) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr) {
return nullptr;
} else {
sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
}
}
Token *str = expect_token(pc, TokenIdStringLiteral);
expect_token(pc, TokenIdLParen);
@ -1871,7 +1878,7 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
expect_token(pc, TokenIdRParen);
AsmOutput *res = allocate<AsmOutput>(1);
res->asm_symbolic_name = token_buf(sym_name);
res->asm_symbolic_name = (sym_name->id == TokenIdBracketUnderscoreBracket) ? buf_create_from_str("_") : token_buf(sym_name);
res->constraint = token_buf(str);
res->variable_name = token_buf(var_name);
res->return_type = return_type;
@ -1894,18 +1901,23 @@ static AstNode *ast_parse_asm_input(ParseContext *pc) {
// AsmInputItem <- LBRACKET IDENTIFIER RBRACKET STRINGLITERAL LPAREN Expr RPAREN
static AsmInput *ast_parse_asm_input_item(ParseContext *pc) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr)
return nullptr;
Token *sym_name = eat_token_if(pc, TokenIdBracketUnderscoreBracket);
if (sym_name == nullptr) {
if (eat_token_if(pc, TokenIdLBracket) == nullptr) {
return nullptr;
} else {
sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
}
}
Token *sym_name = expect_token(pc, TokenIdSymbol);
expect_token(pc, TokenIdRBracket);
Token *constraint = expect_token(pc, TokenIdStringLiteral);
expect_token(pc, TokenIdLParen);
AstNode *expr = ast_expect(pc, ast_parse_expr);
expect_token(pc, TokenIdRParen);
AsmInput *res = allocate<AsmInput>(1);
res->asm_symbolic_name = token_buf(sym_name);
res->asm_symbolic_name = (sym_name->id == TokenIdBracketUnderscoreBracket) ? buf_create_from_str("_") : token_buf(sym_name);
res->constraint = token_buf(constraint);
res->expr = expr;
return res;
@ -2597,6 +2609,12 @@ static AstNode *ast_parse_prefix_type_op(ParseContext *pc) {
return ptr;
}
Token *arr_init = eat_token_if(pc, TokenIdBracketUnderscoreBracket);
if (arr_init != nullptr) {
return ast_create_node(pc, NodeTypeInferredArrayType, arr_init);
}
return nullptr;
}
@ -3003,6 +3021,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
visit_field(&node->data.array_type.child_type, visit, context);
visit_field(&node->data.array_type.align_expr, visit, context);
break;
case NodeTypeInferredArrayType:
visit_field(&node->data.array_type.child_type, visit, context);
break;
case NodeTypePromiseType:
visit_field(&node->data.promise_type.payload_type, visit, context);
break;

View File

@ -224,6 +224,7 @@ enum TokenizeState {
TokenizeStateLBracket,
TokenizeStateLBracketStar,
TokenizeStateLBracketStarC,
TokenizeStateLBracketUnderscore,
};
@ -774,6 +775,9 @@ void tokenize(Buf *buf, Tokenization *out) {
case '*':
t.state = TokenizeStateLBracketStar;
break;
case '_':
t.state = TokenizeStateLBracketUnderscore;
break;
default:
// reinterpret as just an lbracket
t.pos -= 1;
@ -782,6 +786,21 @@ void tokenize(Buf *buf, Tokenization *out) {
continue;
}
break;
case TokenizeStateLBracketUnderscore:
switch (c) {
case ']':
set_token_id(&t, t.cur_tok, TokenIdBracketUnderscoreBracket);
end_token(&t);
t.state = TokenizeStateStart;
break;
default:
// reinterpret as just an lbracket
t.pos -= 2;
end_token(&t);
t.state = TokenizeStateStart;
continue;
}
break;
case TokenizeStateLBracketStar:
switch (c) {
case 'c':
@ -1443,6 +1462,7 @@ void tokenize(Buf *buf, Tokenization *out) {
case TokenizeStateLineStringContinueC:
case TokenizeStateLBracketStar:
case TokenizeStateLBracketStarC:
case TokenizeStateLBracketUnderscore:
tokenize_error(&t, "unexpected EOF");
break;
case TokenizeStateLineComment:
@ -1581,6 +1601,7 @@ const char * token_name(TokenId id) {
case TokenIdTimesPercent: return "*%";
case TokenIdTimesPercentEq: return "*%=";
case TokenIdBarBarEq: return "||=";
case TokenIdBracketUnderscoreBracket: return "[_]";
case TokenIdCount:
zig_unreachable();
}

View File

@ -30,6 +30,7 @@ enum TokenId {
TokenIdBitXorEq,
TokenIdBracketStarBracket,
TokenIdBracketStarCBracket,
TokenIdBracketUnderscoreBracket,
TokenIdCharLiteral,
TokenIdCmpEq,
TokenIdCmpGreaterOrEq,

View File

@ -23,7 +23,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn init(allocator: *Allocator) Self {
return Self{
.items = []align(A) T{},
.items = [_]T{},
.len = 0,
.allocator = allocator,
};
@ -265,7 +265,7 @@ test "std.ArrayList.basic" {
testing.expect(list.pop() == 10);
testing.expect(list.len == 9);
list.appendSlice([]const i32{
list.appendSlice([_]i32{
1,
2,
3,
@ -276,7 +276,7 @@ test "std.ArrayList.basic" {
testing.expect(list.pop() == 1);
testing.expect(list.len == 9);
list.appendSlice([]const i32{}) catch unreachable;
list.appendSlice([_]i32{}) catch unreachable;
testing.expect(list.len == 9);
// can only set on indices < self.len
@ -423,7 +423,7 @@ test "std.ArrayList.insertSlice" {
try list.append(2);
try list.append(3);
try list.append(4);
try list.insertSlice(1, []const i32{
try list.insertSlice(1, [_]i32{
9,
8,
});
@ -434,7 +434,7 @@ test "std.ArrayList.insertSlice" {
testing.expect(list.items[4] == 3);
testing.expect(list.items[5] == 4);
const items = []const i32{1};
const items = [_]i32{1};
try list.insertSlice(0, items[0..0]);
testing.expect(list.len == 6);
testing.expect(list.items[0] == 1);

View File

@ -28,7 +28,7 @@ const combinedTable = init: {
const std = @import("std");
const mem = std.mem;
const alpha = []u1{
const alpha = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -40,7 +40,7 @@ const combinedTable = init: {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
};
const lower = []u1{
const lower = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -52,7 +52,7 @@ const combinedTable = init: {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
};
const upper = []u1{
const upper = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -64,7 +64,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const digit = []u1{
const digit = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -76,7 +76,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const hex = []u1{
const hex = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -88,7 +88,7 @@ const combinedTable = init: {
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const space = []u1{
const space = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -100,7 +100,7 @@ const combinedTable = init: {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const punct = []u1{
const punct = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -112,7 +112,7 @@ const combinedTable = init: {
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
};
const graph = []u1{
const graph = [_]u1{
// 0, 1, 2, 3, 4, 5, 6, 7 ,8, 9,10,11,12,13,14,15
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

View File

@ -14,7 +14,7 @@ pub const Base64Encoder = struct {
/// a bunch of assertions, then simply pass the data right through.
pub fn init(alphabet_chars: []const u8, pad_char: u8) Base64Encoder {
assert(alphabet_chars.len == 64);
var char_in_alphabet = []bool{false} ** 256;
var char_in_alphabet = [_]bool{false} ** 256;
for (alphabet_chars) |c| {
assert(!char_in_alphabet[c]);
assert(c != pad_char);
@ -92,7 +92,7 @@ pub const Base64Decoder = struct {
var result = Base64Decoder{
.char_to_index = undefined,
.char_in_alphabet = []bool{false} ** 256,
.char_in_alphabet = [_]bool{false} ** 256,
.pad_char = pad_char,
};
@ -160,7 +160,7 @@ pub const Base64DecoderWithIgnore = struct {
pub fn init(alphabet_chars: []const u8, pad_char: u8, ignore_chars: []const u8) Base64DecoderWithIgnore {
var result = Base64DecoderWithIgnore{
.decoder = Base64Decoder.init(alphabet_chars, pad_char),
.char_is_ignored = []bool{false} ** 256,
.char_is_ignored = [_]bool{false} ** 256,
};
for (ignore_chars) |c| {

View File

@ -153,8 +153,8 @@ pub const Builder = struct {
pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default
self.lib_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [][]const u8{ self.prefix, "bin" }) catch unreachable;
self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.prefix, "lib" }) catch unreachable;
self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.prefix, "bin" }) catch unreachable;
}
pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
@ -653,7 +653,7 @@ pub const Builder = struct {
pub fn addInstallFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
const full_dest_path = fs.path.resolve(
self.allocator,
[][]const u8{ self.prefix, dest_rel_path },
[_][]const u8{ self.prefix, dest_rel_path },
) catch unreachable;
self.pushInstalledFile(full_dest_path);
@ -689,7 +689,7 @@ pub const Builder = struct {
}
fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
return fs.path.resolve(self.allocator, [][]const u8{ self.build_root, rel_path }) catch unreachable;
return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable;
}
pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
@ -704,7 +704,7 @@ pub const Builder = struct {
if (fs.path.isAbsolute(name)) {
return name;
}
const full_path = try fs.path.join(self.allocator, [][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
if (fs.path.real(self.allocator, full_path)) |real_path| {
return real_path;
} else |_| {
@ -719,7 +719,7 @@ pub const Builder = struct {
}
var it = mem.tokenize(PATH, []u8{fs.path.delimiter});
while (it.next()) |path| {
const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
if (fs.path.real(self.allocator, full_path)) |real_path| {
return real_path;
} else |_| {
@ -733,7 +733,7 @@ pub const Builder = struct {
return name;
}
for (paths) |path| {
const full_path = try fs.path.join(self.allocator, [][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
if (fs.path.real(self.allocator, full_path)) |real_path| {
return real_path;
} else |_| {
@ -928,7 +928,7 @@ const CSourceFile = struct {
};
fn isLibCLibrary(name: []const u8) bool {
const libc_libraries = [][]const u8{ "c", "m", "dl", "rt", "pthread" };
const libc_libraries = [_][]const u8{ "c", "m", "dl", "rt", "pthread" };
for (libc_libraries) |libc_lib_name| {
if (mem.eql(u8, name, libc_lib_name))
return true;
@ -1247,7 +1247,7 @@ pub const LibExeObjStep = struct {
pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
return fs.path.join(
self.builder.allocator,
[][]const u8{ self.output_dir.?, self.out_filename },
[_][]const u8{ self.output_dir.?, self.out_filename },
) catch unreachable;
}
@ -1257,7 +1257,7 @@ pub const LibExeObjStep = struct {
assert(self.kind == Kind.Lib);
return fs.path.join(
self.builder.allocator,
[][]const u8{ self.output_dir.?, self.out_lib_filename },
[_][]const u8{ self.output_dir.?, self.out_lib_filename },
) catch unreachable;
}
@ -1268,7 +1268,7 @@ pub const LibExeObjStep = struct {
assert(!self.disable_gen_h);
return fs.path.join(
self.builder.allocator,
[][]const u8{ self.output_dir.?, self.out_h_filename },
[_][]const u8{ self.output_dir.?, self.out_h_filename },
) catch unreachable;
}
@ -1410,7 +1410,7 @@ pub const LibExeObjStep = struct {
if (self.build_options_contents.len() > 0) {
const build_options_file = try fs.path.join(
builder.allocator,
[][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
);
try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
try zig_args.append("--pkg-begin");
@ -1737,7 +1737,7 @@ const InstallArtifactStep = struct {
.artifact = artifact,
.dest_file = fs.path.join(
builder.allocator,
[][]const u8{ dest_dir, artifact.out_filename },
[_][]const u8{ dest_dir, artifact.out_filename },
) catch unreachable,
};
self.step.dependOn(&artifact.step);
@ -1745,11 +1745,11 @@ const InstallArtifactStep = struct {
if (self.artifact.kind == LibExeObjStep.Kind.Lib and self.artifact.is_dynamic) {
builder.pushInstalledFile(fs.path.join(
builder.allocator,
[][]const u8{ builder.lib_dir, artifact.major_only_filename },
[_][]const u8{ builder.lib_dir, artifact.major_only_filename },
) catch unreachable);
builder.pushInstalledFile(fs.path.join(
builder.allocator,
[][]const u8{ builder.lib_dir, artifact.name_only_filename },
[_][]const u8{ builder.lib_dir, artifact.name_only_filename },
) catch unreachable);
}
return self;
@ -1909,7 +1909,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
// sym link for libfoo.so.1 to libfoo.so.1.2.3
const major_only_path = fs.path.join(
allocator,
[][]const u8{ out_dir, filename_major_only },
[_][]const u8{ out_dir, filename_major_only },
) catch unreachable;
fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
@ -1918,7 +1918,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
// sym link for libfoo.so to libfoo.so.1
const name_only_path = fs.path.join(
allocator,
[][]const u8{ out_dir, filename_name_only },
[_][]const u8{ out_dir, filename_name_only },
) catch unreachable;
fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);

View File

@ -523,7 +523,7 @@ pub const ChildProcess = struct {
// to match posix semantics
const app_name = x: {
if (self.cwd) |cwd| {
const resolved = try fs.path.resolve(self.allocator, [][]const u8{ cwd, self.argv[0] });
const resolved = try fs.path.resolve(self.allocator, [_][]const u8{ cwd, self.argv[0] });
defer self.allocator.free(resolved);
break :x try cstr.addNullByte(self.allocator, resolved);
} else {
@ -546,7 +546,7 @@ pub const ChildProcess = struct {
var it = mem.tokenize(PATH, ";");
while (it.next()) |search_path| {
const joined_path = try fs.path.join(self.allocator, [][]const u8{ search_path, app_name });
const joined_path = try fs.path.join(self.allocator, [_][]const u8{ search_path, app_name });
defer self.allocator.free(joined_path);
const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);

View File

@ -57,7 +57,7 @@ pub const Coff = struct {
var pe_header_magic: [4]u8 = undefined;
try in.readNoEof(pe_header_magic[0..]);
if (!mem.eql(u8, pe_header_magic, []u8{ 'P', 'E', 0, 0 }))
if (!mem.eql(u8, pe_header_magic, [_]u8{ 'P', 'E', 0, 0 }))
return error.InvalidPEHeader;
self.coff_header = CoffHeader{

View File

@ -49,16 +49,16 @@ fn Blake2s(comptime out_len: usize) type {
};
const sigma = [10][16]u8{
[]const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[]const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[]const u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[]const u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[]const u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[]const u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[]const u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[]const u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[]const u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[]const u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
[_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[_]u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[_]u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[_]u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[_]u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[_]u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[_]u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[_]u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[_]u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[_]u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
};
h: [8]u32,
@ -149,7 +149,7 @@ fn Blake2s(comptime out_len: usize) type {
v[13] ^= @intCast(u32, d.t >> 32);
if (last) v[14] = ~v[14];
const rounds = comptime []RoundParam{
const rounds = comptime [_]RoundParam{
Rp(0, 4, 8, 12, 0, 1),
Rp(1, 5, 9, 13, 2, 3),
Rp(2, 6, 10, 14, 4, 5),
@ -252,7 +252,7 @@ test "blake2s256 streaming" {
}
test "blake2s256 aligned final" {
var block = []u8{0} ** Blake2s256.block_length;
var block = [_]u8{0} ** Blake2s256.block_length;
var out: [Blake2s256.digest_length]u8 = undefined;
var h = Blake2s256.init();
@ -284,18 +284,18 @@ fn Blake2b(comptime out_len: usize) type {
};
const sigma = [12][16]u8{
[]const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[]const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[]const u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[]const u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[]const u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[]const u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[]const u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[]const u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[]const u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[]const u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
[]const u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[]const u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[_]u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
[_]u8{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
[_]u8{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
[_]u8{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
[_]u8{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
[_]u8{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
[_]u8{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
[_]u8{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
[_]u8{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
[_]u8{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
[_]u8{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
};
h: [8]u64,
@ -383,7 +383,7 @@ fn Blake2b(comptime out_len: usize) type {
v[13] ^= @intCast(u64, d.t >> 64);
if (last) v[14] = ~v[14];
const rounds = comptime []RoundParam{
const rounds = comptime [_]RoundParam{
Rp(0, 4, 8, 12, 0, 1),
Rp(1, 5, 9, 13, 2, 3),
Rp(2, 6, 10, 14, 4, 5),
@ -486,7 +486,7 @@ test "blake2b512 streaming" {
}
test "blake2b512 aligned final" {
var block = []u8{0} ** Blake2b512.block_length;
var block = [_]u8{0} ** Blake2b512.block_length;
var out: [Blake2b512.digest_length]u8 = undefined;
var h = Blake2b512.init();

View File

@ -33,7 +33,7 @@ fn salsa20_wordtobyte(out: []u8, input: [16]u32) void {
for (x) |_, i|
x[i] = input[i];
const rounds = comptime []QuarterRound{
const rounds = comptime [_]QuarterRound{
Rp(0, 4, 8, 12),
Rp(1, 5, 9, 13),
Rp(2, 6, 10, 14),
@ -71,7 +71,7 @@ fn chaCha20_internal(out: []u8, in: []const u8, key: [8]u32, counter: [4]u32) vo
var cursor: usize = 0;
const c = "expand 32-byte k";
const constant_le = []u32{
const constant_le = [_]u32{
mem.readIntSliceLittle(u32, c[0..4]),
mem.readIntSliceLittle(u32, c[4..8]),
mem.readIntSliceLittle(u32, c[8..12]),
@ -186,7 +186,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
// https://tools.ietf.org/html/rfc7539#section-2.4.2
test "crypto.chacha20 test vector sunscreen" {
const expected_result = []u8{
const expected_result = [_]u8{
0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80,
0x41, 0xba, 0x07, 0x28, 0xdd, 0x0d, 0x69, 0x81,
0xe9, 0x7e, 0x7a, 0xec, 0x1d, 0x43, 0x60, 0xc2,
@ -205,13 +205,13 @@ test "crypto.chacha20 test vector sunscreen" {
};
const input = "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.";
var result: [114]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,
};
const nonce = []u8{
const nonce = [_]u8{
0, 0, 0, 0,
0, 0, 0, 0x4a,
0, 0, 0, 0,
@ -228,7 +228,7 @@ test "crypto.chacha20 test vector sunscreen" {
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
test "crypto.chacha20 test vector 1" {
const expected_result = []u8{
const expected_result = [_]u8{
0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90,
0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28,
0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a,
@ -238,7 +238,7 @@ test "crypto.chacha20 test vector 1" {
0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c,
0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -249,20 +249,20 @@ test "crypto.chacha20 test vector 1" {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
var result: [64]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 2" {
const expected_result = []u8{
const expected_result = [_]u8{
0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96,
0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96,
0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60,
@ -272,7 +272,7 @@ test "crypto.chacha20 test vector 2" {
0x53, 0xd7, 0x92, 0xb1, 0xc4, 0x3f, 0xea, 0x81,
0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -283,20 +283,20 @@ test "crypto.chacha20 test vector 2" {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
var result: [64]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1,
};
const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 3" {
const expected_result = []u8{
const expected_result = [_]u8{
0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5,
0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a,
0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13,
@ -306,7 +306,7 @@ test "crypto.chacha20 test vector 3" {
0x52, 0x77, 0x06, 0x2e, 0xb7, 0xa0, 0x43, 0x3e,
0x44, 0x5f, 0x41, 0xe3,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -317,20 +317,20 @@ test "crypto.chacha20 test vector 3" {
0x00, 0x00, 0x00, 0x00,
};
var result: [60]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
const nonce = []u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 4" {
const expected_result = []u8{
const expected_result = [_]u8{
0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb,
0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80,
0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac,
@ -340,7 +340,7 @@ test "crypto.chacha20 test vector 4" {
0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d,
0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b,
};
const input = []u8{
const input = [_]u8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -351,20 +351,20 @@ test "crypto.chacha20 test vector 4" {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
var result: [64]u8 = undefined;
const key = []u8{
const key = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
const nonce = []u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
testing.expectEqualSlices(u8, expected_result, result);
}
test "crypto.chacha20 test vector 5" {
const expected_result = []u8{
const expected_result = [_]u8{
0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69,
0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75,
0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93,
@ -401,7 +401,7 @@ test "crypto.chacha20 test vector 5" {
0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, 0x7a,
0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9,
};
const input = []u8{
const input = [_]u8{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -421,13 +421,13 @@ test "crypto.chacha20 test vector 5" {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
var result: [256]u8 = undefined;
const key = []u8{
const key = [_]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,
};
const nonce = []u8{
const nonce = [_]u8{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
};

View File

@ -132,14 +132,14 @@ pub const Md5 = struct {
s[i] |= u32(b[i * 4 + 3]) << 24;
}
var v: [4]u32 = []u32{
var v: [4]u32 = [_]u32{
d.s[0],
d.s[1],
d.s[2],
d.s[3],
};
const round0 = comptime []RoundParam{
const round0 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 0, 7, 0xD76AA478),
Rp(3, 0, 1, 2, 1, 12, 0xE8C7B756),
Rp(2, 3, 0, 1, 2, 17, 0x242070DB),
@ -162,7 +162,7 @@ pub const Md5 = struct {
v[r.a] = v[r.b] +% math.rotl(u32, v[r.a], r.s);
}
const round1 = comptime []RoundParam{
const round1 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 1, 5, 0xF61E2562),
Rp(3, 0, 1, 2, 6, 9, 0xC040B340),
Rp(2, 3, 0, 1, 11, 14, 0x265E5A51),
@ -185,7 +185,7 @@ pub const Md5 = struct {
v[r.a] = v[r.b] +% math.rotl(u32, v[r.a], r.s);
}
const round2 = comptime []RoundParam{
const round2 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 5, 4, 0xFFFA3942),
Rp(3, 0, 1, 2, 8, 11, 0x8771F681),
Rp(2, 3, 0, 1, 11, 16, 0x6D9D6122),
@ -208,7 +208,7 @@ pub const Md5 = struct {
v[r.a] = v[r.b] +% math.rotl(u32, v[r.a], r.s);
}
const round3 = comptime []RoundParam{
const round3 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 0, 6, 0xF4292244),
Rp(3, 0, 1, 2, 7, 10, 0x432AFF97),
Rp(2, 3, 0, 1, 14, 15, 0xAB9423A7),
@ -272,7 +272,7 @@ test "md5 streaming" {
}
test "md5 aligned final" {
var block = []u8{0} ** Md5.block_length;
var block = [_]u8{0} ** Md5.block_length;
var out: [Md5.digest_length]u8 = undefined;
var h = Md5.init();

View File

@ -119,7 +119,7 @@ pub const Sha1 = struct {
var s: [16]u32 = undefined;
var v: [5]u32 = []u32{
var v: [5]u32 = [_]u32{
d.s[0],
d.s[1],
d.s[2],
@ -127,7 +127,7 @@ pub const Sha1 = struct {
d.s[4],
};
const round0a = comptime []RoundParam{
const round0a = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 0),
Rp(4, 0, 1, 2, 3, 1),
Rp(3, 4, 0, 1, 2, 2),
@ -152,7 +152,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round0b = comptime []RoundParam{
const round0b = comptime [_]RoundParam{
Rp(4, 0, 1, 2, 3, 16),
Rp(3, 4, 0, 1, 2, 17),
Rp(2, 3, 4, 0, 1, 18),
@ -166,7 +166,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round1 = comptime []RoundParam{
const round1 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 20),
Rp(4, 0, 1, 2, 3, 21),
Rp(3, 4, 0, 1, 2, 22),
@ -196,7 +196,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round2 = comptime []RoundParam{
const round2 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 40),
Rp(4, 0, 1, 2, 3, 41),
Rp(3, 4, 0, 1, 2, 42),
@ -226,7 +226,7 @@ pub const Sha1 = struct {
v[r.b] = math.rotl(u32, v[r.b], u32(30));
}
const round3 = comptime []RoundParam{
const round3 = comptime [_]RoundParam{
Rp(0, 1, 2, 3, 4, 60),
Rp(4, 0, 1, 2, 3, 61),
Rp(3, 4, 0, 1, 2, 62),
@ -293,7 +293,7 @@ test "sha1 streaming" {
}
test "sha1 aligned final" {
var block = []u8{0} ** Sha1.block_length;
var block = [_]u8{0} ** Sha1.block_length;
var out: [Sha1.digest_length]u8 = undefined;
var h = Sha1.init();

View File

@ -189,7 +189,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u32, s[i - 15], u32(7)) ^ math.rotr(u32, s[i - 15], u32(18)) ^ (s[i - 15] >> 3)) +% (math.rotr(u32, s[i - 2], u32(17)) ^ math.rotr(u32, s[i - 2], u32(19)) ^ (s[i - 2] >> 10));
}
var v: [8]u32 = []u32{
var v: [8]u32 = [_]u32{
d.s[0],
d.s[1],
d.s[2],
@ -200,7 +200,7 @@ fn Sha2_32(comptime params: Sha2Params32) type {
d.s[7],
};
const round0 = comptime []RoundParam256{
const round0 = comptime [_]RoundParam256{
Rp256(0, 1, 2, 3, 4, 5, 6, 7, 0, 0x428A2F98),
Rp256(7, 0, 1, 2, 3, 4, 5, 6, 1, 0x71374491),
Rp256(6, 7, 0, 1, 2, 3, 4, 5, 2, 0xB5C0FBCF),
@ -339,7 +339,7 @@ test "sha256 streaming" {
}
test "sha256 aligned final" {
var block = []u8{0} ** Sha256.block_length;
var block = [_]u8{0} ** Sha256.block_length;
var out: [Sha256.digest_length]u8 = undefined;
var h = Sha256.init();
@ -535,7 +535,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
s[i] = s[i - 16] +% s[i - 7] +% (math.rotr(u64, s[i - 15], u64(1)) ^ math.rotr(u64, s[i - 15], u64(8)) ^ (s[i - 15] >> 7)) +% (math.rotr(u64, s[i - 2], u64(19)) ^ math.rotr(u64, s[i - 2], u64(61)) ^ (s[i - 2] >> 6));
}
var v: [8]u64 = []u64{
var v: [8]u64 = [_]u64{
d.s[0],
d.s[1],
d.s[2],
@ -546,7 +546,7 @@ fn Sha2_64(comptime params: Sha2Params64) type {
d.s[7],
};
const round0 = comptime []RoundParam512{
const round0 = comptime [_]RoundParam512{
Rp512(0, 1, 2, 3, 4, 5, 6, 7, 0, 0x428A2F98D728AE22),
Rp512(7, 0, 1, 2, 3, 4, 5, 6, 1, 0x7137449123EF65CD),
Rp512(6, 7, 0, 1, 2, 3, 4, 5, 2, 0xB5C0FBCFEC4D3B2F),
@ -717,7 +717,7 @@ test "sha512 streaming" {
}
test "sha512 aligned final" {
var block = []u8{0} ** Sha512.block_length;
var block = [_]u8{0} ** Sha512.block_length;
var out: [Sha512.digest_length]u8 = undefined;
var h = Sha512.init();

View File

@ -86,7 +86,7 @@ fn Keccak(comptime bits: usize, comptime delim: u8) type {
};
}
const RC = []const u64{
const RC = [_]u64{
0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000,
0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,
0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
@ -95,15 +95,15 @@ const RC = []const u64{
0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
};
const ROTC = []const usize{
const ROTC = [_]usize{
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
};
const PIL = []const usize{
const PIL = [_]usize{
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
};
const M5 = []const usize{
const M5 = [_]usize{
0, 1, 2, 3, 4, 0, 1, 2, 3, 4,
};
@ -115,9 +115,9 @@ fn keccak_f(comptime F: usize, d: []u8) void {
break :x 12 + 2 * math.log2(B);
};
var s = []const u64{0} ** 25;
var t = []const u64{0} ** 1;
var c = []const u64{0} ** 5;
var s = [_]u64{0} ** 25;
var t = [_]u64{0} ** 1;
var c = [_]u64{0} ** 5;
for (s) |*r, i| {
r.* = mem.readIntSliceLittle(u64, d[8 * i .. 8 * i + 8]);
@ -225,7 +225,7 @@ test "sha3-256 streaming" {
}
test "sha3-256 aligned final" {
var block = []u8{0} ** Sha3_256.block_length;
var block = [_]u8{0} ** Sha3_256.block_length;
var out: [Sha3_256.digest_length]u8 = undefined;
var h = Sha3_256.init();
@ -296,7 +296,7 @@ test "sha3-512 streaming" {
}
test "sha3-512 aligned final" {
var block = []u8{0} ** Sha3_512.block_length;
var block = [_]u8{0} ** Sha3_512.block_length;
var out: [Sha3_512.digest_length]u8 = undefined;
var h = Sha3_512.init();

View File

@ -116,7 +116,7 @@ pub const X25519 = struct {
}
pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
var base_point = []u8{9} ++ []u8{0} ** 31;
var base_point = [_]u8{9} ++ [_]u8{0} ** 31;
return create(public_key, private_key, base_point);
}
};

View File

@ -820,7 +820,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
const len = try di.coff.getPdbPath(path_buf[0..]);
const raw_path = path_buf[0..len];
const path = try fs.path.resolve(allocator, [][]const u8{raw_path});
const path = try fs.path.resolve(allocator, [_][]const u8{raw_path});
try di.pdb.openFile(di.coff, path);
@ -1418,7 +1418,7 @@ const LineNumberProgram = struct {
return error.InvalidDebugInfo;
} else
self.include_dirs[file_entry.dir_index];
const file_name = try fs.path.join(self.file_entries.allocator, [][]const u8{ dir_name, file_entry.file_name });
const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name });
errdefer self.file_entries.allocator.free(file_name);
return LineInfo{
.line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,

View File

@ -698,7 +698,7 @@ pub async fn readFile(loop: *Loop, file_path: []const u8, max_size: usize) ![]u8
while (true) {
try list.ensureCapacity(list.len + mem.page_size);
const buf = list.items[list.len..];
const buf_array = [][]u8{buf};
const buf_array = [_][]u8{buf};
const amt = try await (async preadv(loop, fd, buf_array, list.len) catch unreachable);
list.len += amt;
if (list.len > max_size) {

View File

@ -143,7 +143,7 @@ pub const Loop = struct {
Thread.SpawnError || os.EpollCtlError || os.KEventError ||
windows.CreateIoCompletionPortError;
const wakeup_bytes = []u8{0x1} ** 8;
const wakeup_bytes = [_]u8{0x1} ** 8;
fn initOsData(self: *Loop, extra_thread_count: usize) InitOsDataError!void {
switch (builtin.os) {

View File

@ -293,7 +293,7 @@ pub fn formatIntValue(
'c' => {
if (@typeOf(int_value).bit_count <= 8) {
if (fmt.len > 1)
@compileError("Unknown format character: " ++ []u8{fmt[1]});
@compileError("Unknown format character: " ++ [_]u8{fmt[1]});
return formatAsciiChar(u8(int_value), context, Errors, output);
}
},
@ -317,7 +317,7 @@ pub fn formatIntValue(
uppercase = true;
width = 0;
},
else => @compileError("Unknown format character: " ++ []u8{fmt[0]}),
else => @compileError("Unknown format character: " ++ [_]u8{fmt[0]}),
}
if (fmt.len > 1) width = comptime (parseUnsigned(usize, fmt[1..], 10) catch unreachable);
}
@ -341,7 +341,7 @@ fn formatFloatValue(
switch (float_fmt) {
'e' => try formatFloatScientific(value, width, context, Errors, output),
'.' => try formatFloatDecimal(value, width, context, Errors, output),
else => @compileError("Unknown format character: " ++ []u8{float_fmt}),
else => @compileError("Unknown format character: " ++ [_]u8{float_fmt}),
}
}
@ -362,7 +362,7 @@ pub fn formatText(
try formatInt(c, 16, fmt[0] == 'X', 2, context, Errors, output);
}
return;
} else @compileError("Unknown format character: " ++ []u8{fmt[0]});
} else @compileError("Unknown format character: " ++ [_]u8{fmt[0]});
}
return output(context, bytes);
}
@ -668,8 +668,8 @@ pub fn formatBytes(
}
const buf = switch (radix) {
1000 => []u8{ suffix, 'B' },
1024 => []u8{ suffix, 'i', 'B' },
1000 => [_]u8{ suffix, 'B' },
1024 => [_]u8{ suffix, 'i', 'B' },
else => unreachable,
};
return output(context, buf);

View File

@ -415,7 +415,7 @@ fn fpprev(val: f64) f64 {
return @bitCast(f64, @bitCast(u64, val) -% 1);
}
pub const c_digits_lut = []u8{
pub const c_digits_lut = [_]u8{
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6',
'0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3',
'1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0',

View File

@ -1,4 +1,4 @@
pub const enum3 = []u64{
pub const enum3 = [_]u64{
0x4e2e2785c3a2a20b,
0x240a28877a09a4e1,
0x728fca36c06cf106,
@ -445,7 +445,7 @@ fn slab(str: []const u8, exp: i32) Slab {
};
}
pub const enum3_data = []Slab{
pub const enum3_data = [_]Slab{
slab("40648030339495312", 69),
slab("4498645355592131", -134),
slab("678321594594593", 244),

View File

@ -2,7 +2,7 @@ pub const HP = struct {
val: f64,
off: f64,
};
pub const lookup_table = []HP{
pub const lookup_table = [_]HP{
HP{ .val = 1.000000e+308, .off = -1.097906362944045488e+291 },
HP{ .val = 1.000000e+307, .off = 1.396894023974354241e+290 },
HP{ .val = 1.000000e+306, .off = -1.721606459673645508e+289 },

View File

@ -390,7 +390,7 @@ test "fmt.parseFloat" {
const approxEq = std.math.approxEq;
const epsilon = 1e-7;
inline for ([]type{ f16, f32, f64, f128 }) |T| {
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
const Z = @IntType(false, T.bit_count);
testing.expectError(error.InvalidCharacter, parseFloat(T, ""));

View File

@ -209,7 +209,7 @@ pub fn makeDirW(dir_path: [*]const u16) !void {
/// have been modified regardless.
/// TODO determine if we can remove the allocator requirement from this function
pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
const resolved_path = try path.resolve(allocator, [][]const u8{full_path});
const resolved_path = try path.resolve(allocator, [_][]const u8{full_path});
defer allocator.free(resolved_path);
var end_index: usize = resolved_path.len;
@ -447,13 +447,13 @@ pub const Dir = struct {
.seek = 0,
.index = 0,
.end_index = 0,
.buf = []u8{},
.buf = [_]u8{},
},
.linux => Handle{
.fd = try os.open(dir_path, os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC, 0),
.index = 0,
.end_index = 0,
.buf = []u8{},
.buf = [_]u8{},
},
else => @compileError("unimplemented"),
},
@ -550,7 +550,7 @@ pub const Dir = struct {
return null;
}
const name_utf16le = mem.toSlice(u16, self.handle.find_file_data.cFileName[0..].ptr);
if (mem.eql(u16, name_utf16le, []u16{'.'}) or mem.eql(u16, name_utf16le, []u16{ '.', '.' }))
if (mem.eql(u16, name_utf16le, [_]u16{'.'}) or mem.eql(u16, name_utf16le, [_]u16{ '.', '.' }))
continue;
// Trust that Windows gives us valid UTF-16LE
const name_utf8_len = std.unicode.utf16leToUtf8(self.handle.name_data[0..], name_utf16le) catch unreachable;

View File

@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
error.OutOfMemory => return error.OutOfMemory,
};
defer allocator.free(global_dir);
return fs.path.join(allocator, [][]const u8{ global_dir, appname });
return fs.path.join(allocator, [_][]const u8{ global_dir, appname });
},
os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
else => return error.AppDataDirUnavailable,
@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;
};
return fs.path.join(allocator, [][]const u8{ home_dir, "Library", "Application Support", appname });
return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });
},
.linux, .freebsd, .netbsd => {
const home_dir = os.getenv("HOME") orelse {
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;
};
return fs.path.join(allocator, [][]const u8{ home_dir, ".local", "share", appname });
return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname });
},
else => @compileError("Unsupported OS"),
}

View File

@ -101,31 +101,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
}
test "join" {
testJoinWindows([][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows(
[][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
);
testJoinPosix([][]const u8{ "/a/b", "c" }, "/a/b/c");
testJoinPosix([][]const u8{ "/a/b/", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c");
testJoinPosix([][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
testJoinPosix([][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
testJoinPosix(
[][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
"/home/andy/dev/zig/build/lib/zig/std/io.zig",
);
testJoinPosix([][]const u8{ "a", "/c" }, "a/c");
testJoinPosix([][]const u8{ "a/", "/c" }, "a/c");
testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");
testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");
}
pub fn isAbsolute(path: []const u8) bool {
@ -227,7 +227,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
}
const relative_path = WindowsPath{
.kind = WindowsPath.Kind.None,
.disk_designator = []u8{},
.disk_designator = [_]u8{},
.is_abs = false,
};
if (path.len < "//a/b".len) {
@ -237,13 +237,13 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
// TODO when I combined these together with `inline for` the compiler crashed
{
const this_sep = '/';
const two_sep = []u8{ this_sep, this_sep };
const two_sep = [_]u8{ this_sep, this_sep };
if (mem.startsWith(u8, path, two_sep)) {
if (path[2] == this_sep) {
return relative_path;
}
var it = mem.tokenize(path, []u8{this_sep});
var it = mem.tokenize(path, [_]u8{this_sep});
_ = (it.next() orelse return relative_path);
_ = (it.next() orelse return relative_path);
return WindowsPath{
@ -255,13 +255,13 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
}
{
const this_sep = '\\';
const two_sep = []u8{ this_sep, this_sep };
const two_sep = [_]u8{ this_sep, this_sep };
if (mem.startsWith(u8, path, two_sep)) {
if (path[2] == this_sep) {
return relative_path;
}
var it = mem.tokenize(path, []u8{this_sep});
var it = mem.tokenize(path, [_]u8{this_sep});
_ = (it.next() orelse return relative_path);
_ = (it.next() orelse return relative_path);
return WindowsPath{
@ -323,8 +323,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
const sep1 = ns1[0];
const sep2 = ns2[0];
var it1 = mem.tokenize(ns1, []u8{sep1});
var it2 = mem.tokenize(ns2, []u8{sep2});
var it1 = mem.tokenize(ns1, [_]u8{sep1});
var it2 = mem.tokenize(ns2, [_]u8{sep2});
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
@ -344,8 +344,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
const sep1 = p1[0];
const sep2 = p2[0];
var it1 = mem.tokenize(p1, []u8{sep1});
var it2 = mem.tokenize(p2, []u8{sep2});
var it1 = mem.tokenize(p1, [_]u8{sep1});
var it2 = mem.tokenize(p2, [_]u8{sep2});
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
@ -638,10 +638,10 @@ test "resolve" {
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
cwd[0] = asciiUpper(cwd[0]);
}
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{"."}), cwd));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));
} else {
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "a/b/c/", "../../.." }), cwd));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"."}), cwd));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));
}
}
@ -650,8 +650,8 @@ test "resolveWindows" {
const cwd = try process.getCwdAlloc(debug.global_allocator);
const parsed_cwd = windowsParsePath(cwd);
{
const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
const expected = try join(debug.global_allocator, [][]const u8{
const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
const expected = try join(debug.global_allocator, [_][]const u8{
parsed_cwd.disk_designator,
"usr\\local\\lib\\zig\\std\\array_list.zig",
});
@ -661,8 +661,8 @@ test "resolveWindows" {
testing.expect(mem.eql(u8, result, expected));
}
{
const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
const expected = try join(debug.global_allocator, [][]const u8{
const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });
const expected = try join(debug.global_allocator, [_][]const u8{
cwd,
"usr\\local\\lib\\zig",
});
@ -673,32 +673,32 @@ test "resolveWindows" {
}
}
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//" }), "C:\\"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//dir" }), "C:\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//" }), "C:\\"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
}
test "resolvePosix" {
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c" }), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/a/b/c", "..", "../" }), "/a"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/", "..", ".." }), "/"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{"/a/b/c/"}), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
testing.expect(mem.eql(u8, testResolvePosix([][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
}
fn testResolveWindows(paths: []const []const u8) []u8 {
@ -853,12 +853,12 @@ pub fn basename(path: []const u8) []const u8 {
pub fn basenamePosix(path: []const u8) []const u8 {
if (path.len == 0)
return []u8{};
return [_]u8{};
var end_index: usize = path.len - 1;
while (path[end_index] == '/') {
if (end_index == 0)
return []u8{};
return [_]u8{};
end_index -= 1;
}
var start_index: usize = end_index;
@ -874,19 +874,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
pub fn basenameWindows(path: []const u8) []const u8 {
if (path.len == 0)
return []u8{};
return [_]u8{};
var end_index: usize = path.len - 1;
while (true) {
const byte = path[end_index];
if (byte == '/' or byte == '\\') {
if (end_index == 0)
return []u8{};
return [_]u8{};
end_index -= 1;
continue;
}
if (byte == ':' and end_index == 1) {
return []u8{};
return [_]u8{};
}
break;
}
@ -968,11 +968,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
}
pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
const resolved_from = try resolveWindows(allocator, [][]const u8{from});
const resolved_from = try resolveWindows(allocator, [_][]const u8{from});
defer allocator.free(resolved_from);
var clean_up_resolved_to = true;
const resolved_to = try resolveWindows(allocator, [][]const u8{to});
const resolved_to = try resolveWindows(allocator, [_][]const u8{to});
defer if (clean_up_resolved_to) allocator.free(resolved_to);
const parsed_from = windowsParsePath(resolved_from);
@ -1037,14 +1037,14 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
return result[0..result_index];
}
return []u8{};
return [_]u8{};
}
pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
const resolved_from = try resolvePosix(allocator, [][]const u8{from});
const resolved_from = try resolvePosix(allocator, [_][]const u8{from});
defer allocator.free(resolved_from);
const resolved_to = try resolvePosix(allocator, [][]const u8{to});
const resolved_to = try resolvePosix(allocator, [_][]const u8{to});
defer allocator.free(resolved_to);
var from_it = mem.tokenize(resolved_from, "/");
@ -1082,7 +1082,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![
return result;
}
return []u8{};
return [_]u8{};
}
test "relative" {

View File

@ -94,14 +94,14 @@ test "adler32 sanity" {
}
test "adler32 long" {
const long1 = []u8{1} ** 1024;
const long1 = [_]u8{1} ** 1024;
testing.expect(Adler32.hash(long1[0..]) == 0x06780401);
const long2 = []u8{1} ** 1025;
const long2 = [_]u8{1} ** 1025;
testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402);
}
test "adler32 very long" {
const long = []u8{1} ** 5553;
const long = [_]u8{1} ** 5553;
testing.expect(Adler32.hash(long[0..]) == 0x707f15b2);
}

View File

@ -163,7 +163,7 @@ fn SipHash(comptime T: type, comptime c_rounds: usize, comptime d_rounds: usize)
const test_key = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f";
test "siphash64-2-4 sanity" {
const vectors = [][8]u8{
const vectors = [_][8]u8{
"\x31\x0e\x0e\xdd\x47\xdb\x6f\x72", // ""
"\xfd\x67\xdc\x93\xc5\x39\xf8\x74", // "\x00"
"\x5a\x4f\xa9\xd9\x09\x80\x6c\x0d", // "\x00\x01" ... etc
@ -242,7 +242,7 @@ test "siphash64-2-4 sanity" {
}
test "siphash128-2-4 sanity" {
const vectors = [][16]u8{
const vectors = [_][16]u8{
"\xa3\x81\x7f\x04\xba\x25\xa8\xe6\x6d\xf6\x72\x14\xc7\x55\x02\x93",
"\xda\x87\xc1\xd8\x6b\x99\xaf\x44\x34\x76\x59\x11\x9b\x22\xfc\x45",
"\x81\x77\x22\x8d\xa4\xa4\x5d\xc7\xfc\xa3\x8b\xde\xf6\x0a\xff\xe4",

View File

@ -77,7 +77,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
pub fn init(allocator: *Allocator) Self {
return Self{
.entries = []Entry{},
.entries = [_]Entry{},
.allocator = allocator,
.size = 0,
.max_distance_from_start_index = 0,
@ -436,12 +436,12 @@ test "iterator hash map" {
testing.expect((try reset_map.put(2, 22)) == null);
testing.expect((try reset_map.put(3, 33)) == null);
var keys = []i32{
var keys = [_]i32{
3,
2,
1,
};
var values = []i32{
var values = [_]i32{
33,
22,
11,

View File

@ -76,7 +76,7 @@ test "BufferOutStream" {
}
test "SliceInStream" {
const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7 };
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
var ss = io.SliceInStream.init(bytes);
var dest: [4]u8 = undefined;
@ -94,7 +94,7 @@ test "SliceInStream" {
}
test "PeekStream" {
const bytes = []const u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
var ss = io.SliceInStream.init(bytes);
var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
@ -147,8 +147,8 @@ test "SliceOutStream" {
}
test "BitInStream" {
const mem_be = []u8{ 0b11001101, 0b00001011 };
const mem_le = []u8{ 0b00011101, 0b10010101 };
const mem_be = [_]u8{ 0b11001101, 0b00001011 };
const mem_le = [_]u8{ 0b00011101, 0b10010101 };
var mem_in_be = io.SliceInStream.init(mem_be[0..]);
const InError = io.SliceInStream.Error;
@ -219,8 +219,8 @@ test "BitInStream" {
}
test "BitOutStream" {
var mem_be = []u8{0} ** 2;
var mem_le = []u8{0} ** 2;
var mem_be = [_]u8{0} ** 2;
var mem_le = [_]u8{0} ** 2;
var mem_out_be = io.SliceOutStream.init(mem_be[0..]);
const OutError = io.SliceOutStream.Error;

View File

@ -23,21 +23,21 @@ pub fn atan(x: var) @typeOf(x) {
}
fn atan32(x_: f32) f32 {
const atanhi = []const f32{
const atanhi = [_]f32{
4.6364760399e-01, // atan(0.5)hi
7.8539812565e-01, // atan(1.0)hi
9.8279368877e-01, // atan(1.5)hi
1.5707962513e+00, // atan(inf)hi
};
const atanlo = []const f32{
const atanlo = [_]f32{
5.0121582440e-09, // atan(0.5)lo
3.7748947079e-08, // atan(1.0)lo
3.4473217170e-08, // atan(1.5)lo
7.5497894159e-08, // atan(inf)lo
};
const aT = []const f32{
const aT = [_]f32{
3.3333328366e-01,
-1.9999158382e-01,
1.4253635705e-01,
@ -114,21 +114,21 @@ fn atan32(x_: f32) f32 {
}
fn atan64(x_: f64) f64 {
const atanhi = []const f64{
const atanhi = [_]f64{
4.63647609000806093515e-01, // atan(0.5)hi
7.85398163397448278999e-01, // atan(1.0)hi
9.82793723247329054082e-01, // atan(1.5)hi
1.57079632679489655800e+00, // atan(inf)hi
};
const atanlo = []const f64{
const atanlo = [_]f64{
2.26987774529616870924e-17, // atan(0.5)lo
3.06161699786838301793e-17, // atan(1.0)lo
1.39033110312309984516e-17, // atan(1.5)lo
6.12323399573676603587e-17, // atan(inf)lo
};
const aT = []const f64{
const aT = [_]f64{
3.33333333333329318027e-01,
-1.99999999998764832476e-01,
1.42857142725034663711e-01,

View File

@ -415,13 +415,13 @@ pub const Int = struct {
i += 1;
}
const ap_base = Int.initFixed(([]Limb{base})[0..]);
const ap_base = Int.initFixed(([_]Limb{base})[0..]);
try self.set(0);
for (value[i..]) |ch| {
const d = try charToDigit(ch, base);
const ap_d = Int.initFixed(([]Limb{d})[0..]);
const ap_d = Int.initFixed(([_]Limb{d})[0..]);
try self.mul(self.*, ap_base);
try self.add(self.*, ap_d);
@ -828,7 +828,7 @@ pub const Int = struct {
// Trunc -> Floor.
if (!q.isPositive()) {
const one = Int.initFixed(([]Limb{1})[0..]);
const one = Int.initFixed(([_]Limb{1})[0..]);
try q.sub(q.*, one);
try r.add(q.*, one);
}

View File

@ -102,7 +102,7 @@ pub const Rational = struct {
if (point) |i| {
try self.p.setString(10, str[0..i]);
const base = Int.initFixed(([]Limb{10})[0..]);
const base = Int.initFixed(([_]Limb{10})[0..]);
var j: usize = start;
while (j < str.len - i - 1) : (j += 1) {
@ -452,7 +452,7 @@ pub const Rational = struct {
try gcd(&a, r.p, r.q);
r.p.setSign(sign);
const one = Int.initFixed(([]Limb{1})[0..]);
const one = Int.initFixed(([_]Limb{1})[0..]);
if (a.cmp(one) != 0) {
var unused = try Int.init(r.p.allocator.?);
defer unused.deinit();

View File

@ -24,7 +24,7 @@ pub fn exp(x: var) @typeOf(x) {
}
fn exp32(x_: f32) f32 {
const half = []f32{ 0.5, -0.5 };
const half = [_]f32{ 0.5, -0.5 };
const ln2hi = 6.9314575195e-1;
const ln2lo = 1.4286067653e-6;
const invln2 = 1.4426950216e+0;
@ -99,7 +99,7 @@ fn exp32(x_: f32) f32 {
}
fn exp64(x_: f64) f64 {
const half = []const f64{ 0.5, -0.5 };
const half = [_]f64{ 0.5, -0.5 };
const ln2hi: f64 = 6.93147180369123816490e-01;
const ln2lo: f64 = 1.90821492927058770002e-10;
const invln2: f64 = 1.44269504088896338700e+00;

View File

@ -22,7 +22,7 @@ pub fn exp2(x: var) @typeOf(x) {
};
}
const exp2ft = []const f64{
const exp2ft = [_]f64{
0x1.6a09e667f3bcdp-1,
0x1.7a11473eb0187p-1,
0x1.8ace5422aa0dbp-1,
@ -96,7 +96,7 @@ fn exp2_32(x: f32) f32 {
return @floatCast(f32, r * uk);
}
const exp2dt = []f64{
const exp2dt = [_]f64{
// exp2(z + eps) eps
0x1.6a09e667f3d5dp-1, 0x1.9880p-44,
0x1.6b052fa751744p-1, 0x1.8000p-50,

View File

@ -262,8 +262,8 @@ pub fn secureZero(comptime T: type, s: []T) void {
}
test "mem.secureZero" {
var a = []u8{0xfe} ** 8;
var b = []u8{0xfe} ** 8;
var a = [_]u8{0xfe} ** 8;
var b = [_]u8{0xfe} ** 8;
set(u8, a[0..], 0);
secureZero(u8, b[0..]);
@ -598,23 +598,23 @@ test "comptime read/write int" {
}
test "readIntBig and readIntLittle" {
testing.expect(readIntSliceBig(u0, []u8{}) == 0x0);
testing.expect(readIntSliceLittle(u0, []u8{}) == 0x0);
testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);
testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);
testing.expect(readIntSliceBig(u8, []u8{0x32}) == 0x32);
testing.expect(readIntSliceLittle(u8, []u8{0x12}) == 0x12);
testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);
testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);
testing.expect(readIntSliceBig(u16, []u8{ 0x12, 0x34 }) == 0x1234);
testing.expect(readIntSliceLittle(u16, []u8{ 0x12, 0x34 }) == 0x3412);
testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);
testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);
testing.expect(readIntSliceBig(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
testing.expect(readIntSliceLittle(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
testing.expect(readIntSliceBig(i8, []u8{0xff}) == -1);
testing.expect(readIntSliceLittle(i8, []u8{0xfe}) == -2);
testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1);
testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);
testing.expect(readIntSliceBig(i16, []u8{ 0xff, 0xfd }) == -3);
testing.expect(readIntSliceLittle(i16, []u8{ 0xfc, 0xff }) == -4);
testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);
testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);
}
/// Writes an integer to memory, storing it in twos-complement.
@ -723,34 +723,34 @@ test "writeIntBig and writeIntLittle" {
var buf9: [9]u8 = undefined;
writeIntBig(u0, &buf0, 0x0);
testing.expect(eql_slice_u8(buf0[0..], []u8{}));
testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
writeIntLittle(u0, &buf0, 0x0);
testing.expect(eql_slice_u8(buf0[0..], []u8{}));
testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
writeIntBig(u8, &buf1, 0x12);
testing.expect(eql_slice_u8(buf1[0..], []u8{0x12}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x12}));
writeIntLittle(u8, &buf1, 0x34);
testing.expect(eql_slice_u8(buf1[0..], []u8{0x34}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x34}));
writeIntBig(u16, &buf2, 0x1234);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x12, 0x34 }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x12, 0x34 }));
writeIntLittle(u16, &buf2, 0x5678);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0x78, 0x56 }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x78, 0x56 }));
writeIntBig(u72, &buf9, 0x123456789abcdef024);
testing.expect(eql_slice_u8(buf9[0..], []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
testing.expect(eql_slice_u8(buf9[0..], []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
writeIntBig(i8, &buf1, -1);
testing.expect(eql_slice_u8(buf1[0..], []u8{0xff}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xff}));
writeIntLittle(i8, &buf1, -2);
testing.expect(eql_slice_u8(buf1[0..], []u8{0xfe}));
testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xfe}));
writeIntBig(i16, &buf2, -3);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xff, 0xfd }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xff, 0xfd }));
writeIntLittle(i16, &buf2, -4);
testing.expect(eql_slice_u8(buf2[0..], []u8{ 0xfc, 0xff }));
testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xfc, 0xff }));
}
pub fn hash_slice_u8(k: []const u8) u32 {
@ -991,9 +991,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
test "mem.join" {
var buf: [1024]u8 = undefined;
const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "b", "c" }), "a,b,c"));
testing.expect(eql(u8, try join(a, ",", [][]const u8{"a"}), "a"));
testing.expect(eql(u8, try join(a, ",", [][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c"));
testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a"));
testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
}
test "testStringEquality" {
@ -1008,7 +1008,7 @@ test "testReadInt" {
}
fn testReadIntImpl() void {
{
const bytes = []u8{
const bytes = [_]u8{
0x12,
0x34,
0x56,
@ -1022,7 +1022,7 @@ fn testReadIntImpl() void {
testing.expect(readIntLittle(i32, &bytes) == 0x78563412);
}
{
const buf = []u8{
const buf = [_]u8{
0x00,
0x00,
0x12,
@ -1032,7 +1032,7 @@ fn testReadIntImpl() void {
testing.expect(answer == 0x00001234);
}
{
const buf = []u8{
const buf = [_]u8{
0x12,
0x34,
0x00,
@ -1042,7 +1042,7 @@ fn testReadIntImpl() void {
testing.expect(answer == 0x00003412);
}
{
const bytes = []u8{
const bytes = [_]u8{
0xff,
0xfe,
};
@ -1061,19 +1061,19 @@ fn testWriteIntImpl() void {
var bytes: [8]u8 = undefined;
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x12,
0x34,
0x56,
@ -1085,7 +1085,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x12,
0x34,
0x56,
@ -1097,7 +1097,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00,
0x00,
0x00,
@ -1109,7 +1109,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x12,
0x34,
0x56,
@ -1121,7 +1121,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x00,
0x00,
0x00,
@ -1133,7 +1133,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
testing.expect(eql(u8, bytes, []u8{
testing.expect(eql(u8, bytes, [_]u8{
0x34,
0x12,
0x00,
@ -1185,7 +1185,7 @@ pub fn reverse(comptime T: type, items: []T) void {
}
test "reverse" {
var arr = []i32{
var arr = [_]i32{
5,
3,
1,
@ -1194,7 +1194,7 @@ test "reverse" {
};
reverse(i32, arr[0..]);
testing.expect(eql(i32, arr, []i32{
testing.expect(eql(i32, arr, [_]i32{
4,
2,
1,
@ -1212,7 +1212,7 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
}
test "rotate" {
var arr = []i32{
var arr = [_]i32{
5,
3,
1,
@ -1221,7 +1221,7 @@ test "rotate" {
};
rotate(i32, arr[0..], 2);
testing.expect(eql(i32, arr, []i32{
testing.expect(eql(i32, arr, [_]i32{
1,
2,
4,

View File

@ -184,7 +184,7 @@ test "std.meta.declarations" {
fn a() void {}
};
const decls = comptime [][]TypeInfo.Declaration{
const decls = comptime [_][]TypeInfo.Declaration{
declarations(E1),
declarations(S1),
declarations(U1),
@ -220,7 +220,7 @@ test "std.meta.declarationInfo" {
fn a() void {}
};
const infos = comptime []TypeInfo.Declaration{
const infos = comptime [_]TypeInfo.Declaration{
declarationInfo(E1, "a"),
declarationInfo(S1, "a"),
declarationInfo(U1, "a"),

View File

@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
}
};
const isVector = multiTrait(TraitList{
const isVector = multiTrait([_]TraitFn{
hasFn("add"),
hasField("x"),
hasField("y"),
@ -235,7 +235,7 @@ pub fn isSingleItemPtr(comptime T: type) bool {
}
test "std.meta.trait.isSingleItemPtr" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
testing.expect(isSingleItemPtr(@typeOf(&array[0])));
testing.expect(!isSingleItemPtr(@typeOf(array)));
testing.expect(!isSingleItemPtr(@typeOf(array[0..1])));
@ -251,7 +251,7 @@ pub fn isManyItemPtr(comptime T: type) bool {
}
test "std.meta.trait.isManyItemPtr" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
const mip = @ptrCast([*]const u8, &array[0]);
testing.expect(isManyItemPtr(@typeOf(mip)));
testing.expect(!isManyItemPtr(@typeOf(array)));
@ -268,7 +268,7 @@ pub fn isSlice(comptime T: type) bool {
}
test "std.meta.trait.isSlice" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
testing.expect(isSlice(@typeOf(array[0..])));
testing.expect(!isSlice(@typeOf(array)));
testing.expect(!isSlice(@typeOf(&array[0])));
@ -288,7 +288,7 @@ pub fn isIndexable(comptime T: type) bool {
}
test "std.meta.trait.isIndexable" {
const array = []u8{0} ** 10;
const array = [_]u8{0} ** 10;
const slice = array[0..];
testing.expect(isIndexable(@typeOf(array)));

View File

@ -25,7 +25,7 @@ pub const Address = struct {
.family = os.AF_INET,
.port = mem.nativeToBig(u16, _port),
.addr = ip4,
.zero = []u8{0} ** 8,
.zero = [_]u8{0} ** 8,
},
},
};

View File

@ -1223,7 +1223,7 @@ pub fn isCygwinPty(handle: fd_t) bool {
if (!windows.is_the_target) return false;
const size = @sizeOf(windows.FILE_NAME_INFO);
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = [_]u8{0} ** (size + windows.MAX_PATH);
if (windows.kernel32.GetFileInformationByHandleEx(
handle,
@ -1237,8 +1237,8 @@ pub fn isCygwinPty(handle: fd_t) bool {
const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
const name_bytes = name_info_bytes[size .. size + usize(name_info.FileNameLength)];
const name_wide = @bytesToSlice(u16, name_bytes);
return mem.indexOf(u16, name_wide, []u16{ 'm', 's', 'y', 's', '-' }) != null or
mem.indexOf(u16, name_wide, []u16{ '-', 'p', 't', 'y' }) != null;
return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
}
pub const SocketError = error{
@ -2335,7 +2335,7 @@ pub fn realpathW(pathname: [*]const u16, out_buffer: *[MAX_PATH_BYTES]u8) RealPa
// Windows returns \\?\ prepended to the path.
// We strip it to make this function consistent across platforms.
const prefix = []u16{ '\\', '\\', '?', '\\' };
const prefix = [_]u16{ '\\', '\\', '?', '\\' };
const start_index = if (mem.startsWith(u16, wide_slice, prefix)) prefix.len else 0;
// Trust that Windows gives us valid UTF-16LE.

View File

@ -691,8 +691,8 @@ pub const winsize = extern struct {
pub const NSIG = 65;
pub const sigset_t = [128 / @sizeOf(usize)]usize;
pub const all_mask = []u32{ 0xffffffff, 0xffffffff };
pub const app_mask = []u32{ 0xfffffffc, 0x7fffffff };
pub const all_mask = [_]u32{ 0xffffffff, 0xffffffff };
pub const app_mask = [_]u32{ 0xfffffffc, 0x7fffffff };
pub const k_sigaction = extern struct {
handler: extern fn (i32) void,
@ -711,7 +711,7 @@ pub const Sigaction = struct {
pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
pub const empty_sigset = []usize{0} ** sigset_t.len;
pub const empty_sigset = [_]usize{0} ** sigset_t.len;
pub const in_port_t = u16;
pub const sa_family_t = u16;

View File

@ -39,7 +39,7 @@ test "timer" {
expect(err == 0);
const events_one: linux.epoll_event = undefined;
var events = []linux.epoll_event{events_one} ** 8;
var events = [_]linux.epoll_event{events_one} ** 8;
// TODO implicit cast from *[N]T to [*]T
err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);

View File

@ -145,7 +145,7 @@ pub const FindFirstFileError = error{
};
pub fn FindFirstFile(dir_path: []const u8, find_file_data: *WIN32_FIND_DATAW) FindFirstFileError!HANDLE {
const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, []u16{ '\\', '*', 0 });
const dir_path_w = try sliceToPrefixedSuffixedFileW(dir_path, [_]u16{ '\\', '*', 0 });
const handle = kernel32.FindFirstFileW(&dir_path_w, find_file_data);
if (handle == INVALID_HANDLE_VALUE) {
@ -725,7 +725,7 @@ pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
}
pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE + 1]u16 {
return sliceToPrefixedSuffixedFileW(s, []u16{0});
return sliceToPrefixedSuffixedFileW(s, [_]u16{0});
}
pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) ![PATH_MAX_WIDE + suffix.len]u16 {
@ -745,7 +745,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
}
}
const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {
const prefix = []u16{ '\\', '\\', '?', '\\' };
const prefix = [_]u16{ '\\', '\\', '?', '\\' };
mem.copy(u16, result[0..], prefix);
break :blk prefix.len;
};
@ -767,10 +767,7 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError {
// 614 is the length of the longest windows error desciption
var buf_u16: [614]u16 = undefined;
var buf_u8: [614]u8 = undefined;
var len = kernel32.FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT),
buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);
var len = kernel32.FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG.NEUTRAL, SUBLANG.DEFAULT), buf_u16[0..].ptr, buf_u16.len / @sizeOf(TCHAR), null);
_ = std.unicode.utf16leToUtf8(&buf_u8, buf_u16[0..len]) catch unreachable;
std.debug.warn("error.Unexpected: GetLastError({}): {}\n", err, buf_u8[0..len]);
std.debug.dumpCurrentStackTrace(null);

View File

@ -351,7 +351,7 @@ test "PackedIntArray" {
test "PackedIntArray init" {
const PackedArray = PackedIntArray(u3, 8);
var packed_array = PackedArray.init([]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
var packed_array = PackedArray.init([_]u3{ 0, 1, 2, 3, 4, 5, 6, 7 });
var i = usize(0);
while (i < packed_array.len()) : (i += 1) testing.expect(packed_array.get(i) == i);
}
@ -487,7 +487,7 @@ test "PackedIntSlice accumulating bit offsets" {
// big endian values were not tested
test "PackedInt(Array/Slice) sliceCast" {
const PackedArray = PackedIntArray(u1, 16);
var packed_array = PackedArray.init([]u1{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
var packed_array = PackedArray.init([_]u1{ 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
const packed_slice_cast_2 = packed_array.sliceCast(u2);
const packed_slice_cast_4 = packed_slice_cast_2.sliceCast(u4);
var packed_slice_cast_9 = packed_array.slice(0, (packed_array.len() / 9) * 9).sliceCast(u9);
@ -528,7 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
var packed_array_be = PackedArrayBe.init([]u4{
var packed_array_be = PackedArrayBe.init([_]u4{
0,
1,
2,
@ -563,7 +563,7 @@ test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
var packed_array_be = PackedArrayBe.init([]u11{
var packed_array_be = PackedArrayBe.init([_]u11{
0,
1,
2,

View File

@ -15,7 +15,7 @@ pub fn PriorityQueue(comptime T: type) type {
pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
return Self{
.items = []T{},
.items = [_]T{},
.len = 0,
.allocator = allocator,
.compareFn = compareFn,
@ -276,12 +276,12 @@ test "std.PriorityQueue: peek" {
test "std.PriorityQueue: sift up with odd indices" {
var queue = PQ.init(debug.global_allocator, lessThan);
defer queue.deinit();
const items = []u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
for (items) |e| {
try queue.add(e);
}
const sorted_items = []u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
expectEqual(e, queue.remove());
}
@ -290,22 +290,22 @@ test "std.PriorityQueue: sift up with odd indices" {
test "std.PriorityQueue: addSlice" {
var queue = PQ.init(debug.global_allocator, lessThan);
defer queue.deinit();
const items = []u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
try queue.addSlice(items[0..]);
const sorted_items = []u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
expectEqual(e, queue.remove());
}
}
test "std.PriorityQueue: fromOwnedSlice" {
const items = []u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const items = [_]u32{ 15, 7, 21, 14, 13, 22, 12, 6, 7, 25, 5, 24, 11, 16, 15, 24, 2, 1 };
const heap_items = try std.mem.dupe(debug.global_allocator, u32, items[0..]);
var queue = PQ.fromOwnedSlice(debug.global_allocator, lessThan, heap_items[0..]);
defer queue.deinit();
const sorted_items = []u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
const sorted_items = [_]u32{ 1, 2, 5, 6, 7, 7, 11, 12, 13, 14, 15, 15, 16, 21, 22, 24, 24, 25 };
for (sorted_items) |e| {
expectEqual(e, queue.remove());
}
@ -355,7 +355,7 @@ test "std.PriorityQueue: iterator" {
map.deinit();
}
const items = []u32{ 54, 12, 7, 23, 25, 13 };
const items = [_]u32{ 54, 12, 7, 23, 25, 13 };
for (items) |e| {
_ = try queue.add(e);
_ = try map.put(e, {});

View File

@ -474,14 +474,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
}
test "windows arg parsing" {
testWindowsCmdLine(c"a b\tc d", [][]const u8{ "a", "b", "c", "d" });
testWindowsCmdLine(c"\"abc\" d e", [][]const u8{ "abc", "d", "e" });
testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{ "a\\\\\\b", "de fg", "h" });
testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{ "a\\\"b", "c", "d" });
testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{ "a\\\\b c", "d", "e" });
testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{ "a", "b", "c", "\"d", "f" });
testWindowsCmdLine(c"a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
testWindowsCmdLine(c"\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
testWindowsCmdLine(c"a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
testWindowsCmdLine(c"a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
".\\..\\zig-cache\\build",
"bin\\zig.exe",
".\\..",

View File

@ -501,7 +501,7 @@ const SplitMix64 = struct {
test "splitmix64 sequence" {
var r = SplitMix64.init(0xaeecf86f7878dd75);
const seq = []const u64{
const seq = [_]u64{
0x5dbd39db0178eb44,
0xa9900fb66b397da3,
0x5c1a28b1aeebcf5c,
@ -594,7 +594,7 @@ test "pcg sequence" {
const s1: u64 = 0x84e9c579ef59bbf7;
r.seedTwo(s0, s1);
const seq = []const u32{
const seq = [_]u32{
2881561918,
3063928540,
1199791034,
@ -643,7 +643,7 @@ pub const Xoroshiro128 = struct {
var s0: u64 = 0;
var s1: u64 = 0;
const table = []const u64{
const table = [_]u64{
0xbeac0467eba5facb,
0xd86b048b86aa9922,
};
@ -703,7 +703,7 @@ test "xoroshiro sequence" {
r.s[0] = 0xaeecf86f7878dd75;
r.s[1] = 0x01cd153642e72622;
const seq1 = []const u64{
const seq1 = [_]u64{
0xb0ba0da5bb600397,
0x18a08afde614dccc,
0xa2635b956a31b929,
@ -718,7 +718,7 @@ test "xoroshiro sequence" {
r.jump();
const seq2 = []const u64{
const seq2 = [_]u64{
0x95344a13556d3e22,
0xb4fb32dafa4d00df,
0xb2011d9ccdcfe2dd,
@ -821,7 +821,7 @@ pub const Isaac64 = struct {
self.m[0] = init_s;
// prescrambled golden ratio constants
var a = []const u64{
var a = [_]u64{
0x647c4677a2884b7c,
0xb9f8b322c73ac862,
0x8c0ea5053d4712a0,
@ -911,7 +911,7 @@ test "isaac64 sequence" {
var r = Isaac64.init(0);
// from reference implementation
const seq = []const u64{
const seq = [_]u64{
0xf67dfba498e4937c,
0x84a5066a9204f380,
0xfee34bd5f5514dbb,
@ -954,8 +954,8 @@ test "Random float" {
test "Random shuffle" {
var prng = DefaultPrng.init(0);
var seq = []const u8{ 0, 1, 2, 3, 4 };
var seen = []bool{false} ** 5;
var seq = [_]u8{ 0, 1, 2, 3, 4 };
var seen = [_]bool{false} ** 5;
var i: usize = 0;
while (i < 1000) : (i += 1) {
@ -991,7 +991,7 @@ fn testRange(r: *Random, start: i8, end: i8) void {
}
fn testRangeBias(r: *Random, start: i8, end: i8, biased: bool) void {
const count = @intCast(usize, i32(end) - i32(start));
var values_buffer = []bool{false} ** 0x100;
var values_buffer = [_]bool{false} ** 0x100;
const values = values_buffer[0..count];
var i: usize = 0;
while (i < count) {

View File

@ -108,7 +108,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
.allocator = allocator,
.len = 0,
.prealloc_segment = undefined,
.dynamic_segments = [][*]T{},
.dynamic_segments = [_][*]T{},
};
}
@ -187,7 +187,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
const len = @intCast(ShelfIndex, self.dynamic_segments.len);
self.freeShelves(len, 0);
self.allocator.free(self.dynamic_segments);
self.dynamic_segments = [][*]T{};
self.dynamic_segments = [_][*]T{};
return;
}
@ -382,7 +382,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
testing.expect(list.pop().? == 100);
testing.expect(list.len == 99);
try list.pushMany([]i32{
try list.pushMany([_]i32{
1,
2,
3,
@ -393,7 +393,7 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
testing.expect(list.pop().? == 1);
testing.expect(list.len == 99);
try list.pushMany([]const i32{});
try list.pushMany([_]i32{});
testing.expect(list.len == 99);
var i: i32 = 99;

View File

@ -132,7 +132,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: T, rhs: T) bool) vo
// http://pages.ripco.net/~jgamble/nw.html
var iterator = Iterator.init(items.len, 4);
while (!iterator.finished()) {
var order = []u8{ 0, 1, 2, 3, 4, 5, 6, 7 };
var order = [_]u8{ 0, 1, 2, 3, 4, 5, 6, 7 };
const range = iterator.nextRange();
const sliced_items = items[range.start..];
@ -322,7 +322,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn (lhs: T, rhs: T) bool) vo
var find: usize = 0;
var start: usize = 0;
var pull_index: usize = 0;
var pull = []Pull{
var pull = [_]Pull{
Pull{
.from = 0,
.to = 0,
@ -994,7 +994,7 @@ test "stable sort" {
comptime testStableSort();
}
fn testStableSort() void {
var expected = []IdAndValue{
var expected = [_]IdAndValue{
IdAndValue{ .id = 0, .value = 0 },
IdAndValue{ .id = 1, .value = 0 },
IdAndValue{ .id = 2, .value = 0 },
@ -1005,8 +1005,8 @@ fn testStableSort() void {
IdAndValue{ .id = 1, .value = 2 },
IdAndValue{ .id = 2, .value = 2 },
};
var cases = [][9]IdAndValue{
[]IdAndValue{
var cases = [_][9]IdAndValue{
[_]IdAndValue{
IdAndValue{ .id = 0, .value = 0 },
IdAndValue{ .id = 0, .value = 1 },
IdAndValue{ .id = 0, .value = 2 },
@ -1017,7 +1017,7 @@ fn testStableSort() void {
IdAndValue{ .id = 2, .value = 1 },
IdAndValue{ .id = 2, .value = 2 },
},
[]IdAndValue{
[_]IdAndValue{
IdAndValue{ .id = 0, .value = 2 },
IdAndValue{ .id = 0, .value = 1 },
IdAndValue{ .id = 0, .value = 0 },
@ -1046,28 +1046,28 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
}
test "std.sort" {
const u8cases = [][]const []const u8{
[][]const u8{
const u8cases = [_][]const []const u8{
[_][]const u8{
"",
"",
},
[][]const u8{
[_][]const u8{
"a",
"a",
},
[][]const u8{
[_][]const u8{
"az",
"az",
},
[][]const u8{
[_][]const u8{
"za",
"az",
},
[][]const u8{
[_][]const u8{
"asdf",
"adfs",
},
[][]const u8{
[_][]const u8{
"one",
"eno",
},
@ -1081,30 +1081,30 @@ test "std.sort" {
testing.expect(mem.eql(u8, slice, case[1]));
}
const i32cases = [][]const []const i32{
[][]const i32{
[]i32{},
[]i32{},
const i32cases = [_][]const []const i32{
[_][]const i32{
[_]i32{},
[_]i32{},
},
[][]const i32{
[]i32{1},
[]i32{1},
[_][]const i32{
[_]i32{1},
[_]i32{1},
},
[][]const i32{
[]i32{ 0, 1 },
[]i32{ 0, 1 },
[_][]const i32{
[_]i32{ 0, 1 },
[_]i32{ 0, 1 },
},
[][]const i32{
[]i32{ 1, 0 },
[]i32{ 0, 1 },
[_][]const i32{
[_]i32{ 1, 0 },
[_]i32{ 0, 1 },
},
[][]const i32{
[]i32{ 1, -1, 0 },
[]i32{ -1, 0, 1 },
[_][]const i32{
[_]i32{ 1, -1, 0 },
[_]i32{ -1, 0, 1 },
},
[][]const i32{
[]i32{ 2, 1, 3 },
[]i32{ 1, 2, 3 },
[_][]const i32{
[_]i32{ 2, 1, 3 },
[_]i32{ 1, 2, 3 },
},
};
@ -1118,30 +1118,30 @@ test "std.sort" {
}
test "std.sort descending" {
const rev_cases = [][]const []const i32{
[][]const i32{
[]i32{},
[]i32{},
const rev_cases = [_][]const []const i32{
[_][]const i32{
[_]i32{},
[_]i32{},
},
[][]const i32{
[]i32{1},
[]i32{1},
[_][]const i32{
[_]i32{1},
[_]i32{1},
},
[][]const i32{
[]i32{ 0, 1 },
[]i32{ 1, 0 },
[_][]const i32{
[_]i32{ 0, 1 },
[_]i32{ 1, 0 },
},
[][]const i32{
[]i32{ 1, 0 },
[]i32{ 1, 0 },
[_][]const i32{
[_]i32{ 1, 0 },
[_]i32{ 1, 0 },
},
[][]const i32{
[]i32{ 1, -1, 0 },
[]i32{ 1, 0, -1 },
[_][]const i32{
[_]i32{ 1, -1, 0 },
[_]i32{ 1, 0, -1 },
},
[][]const i32{
[]i32{ 2, 1, 3 },
[]i32{ 3, 2, 1 },
[_][]const i32{
[_]i32{ 2, 1, 3 },
[_]i32{ 3, 2, 1 },
},
};
@ -1155,10 +1155,10 @@ test "std.sort descending" {
}
test "another sort case" {
var arr = []i32{ 5, 3, 1, 2, 4 };
var arr = [_]i32{ 5, 3, 1, 2, 4 };
sort(i32, arr[0..], asc(i32));
testing.expect(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 }));
testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 }));
}
test "sort fuzz testing" {

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,7 @@ fn test__cmpdf2(vector: TestVector) bool {
return true;
}
const arguments = []f64{
const arguments = [_]f64{
std.math.nan(f64),
-std.math.inf(f64),
-0x1.fffffffffffffp1023,

View File

@ -45,7 +45,7 @@ fn test__cmpsf2(vector: TestVector) bool {
return true;
}
const arguments = []f32{
const arguments = [_]f32{
std.math.nan(f32),
-std.math.inf(f32),
-0x1.fffffep127,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ pub const Token = struct {
id: Id,
};
pub const keywords = []Keyword{
pub const keywords = [_]Keyword{
Keyword{ .bytes = "align", .id = Id.Keyword_align },
Keyword{ .bytes = "allowzero", .id = Id.Keyword_allowzero },
Keyword{ .bytes = "and", .id = Id.Keyword_and },
@ -1190,14 +1190,14 @@ pub const Tokenizer = struct {
};
test "tokenizer" {
testTokenize("test", []Token.Id{Token.Id.Keyword_test});
testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});
}
test "tokenizer - unknown length pointer and then c pointer" {
testTokenize(
\\[*]u8
\\[*c]u8
, []Token.Id{
, [_]Token.Id{
Token.Id.BracketStarBracket,
Token.Id.Identifier,
Token.Id.BracketStarCBracket,
@ -1208,11 +1208,11 @@ test "tokenizer - unknown length pointer and then c pointer" {
test "tokenizer - char literal with hex escape" {
testTokenize(
\\'\x1b'
, []Token.Id{Token.Id.CharLiteral});
, [_]Token.Id{Token.Id.CharLiteral});
}
test "tokenizer - float literal e exponent" {
testTokenize("a = 4.94065645841246544177e-324;\n", []Token.Id{
testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{
Token.Id.Identifier,
Token.Id.Equal,
Token.Id.FloatLiteral,
@ -1221,7 +1221,7 @@ test "tokenizer - float literal e exponent" {
}
test "tokenizer - float literal p exponent" {
testTokenize("a = 0x1.a827999fcef32p+1022;\n", []Token.Id{
testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{
Token.Id.Identifier,
Token.Id.Equal,
Token.Id.FloatLiteral,
@ -1230,71 +1230,71 @@ test "tokenizer - float literal p exponent" {
}
test "tokenizer - chars" {
testTokenize("'c'", []Token.Id{Token.Id.CharLiteral});
testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});
}
test "tokenizer - invalid token characters" {
testTokenize("#", []Token.Id{Token.Id.Invalid});
testTokenize("`", []Token.Id{Token.Id.Invalid});
testTokenize("'c", []Token.Id{Token.Id.Invalid});
testTokenize("'", []Token.Id{Token.Id.Invalid});
testTokenize("''", []Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
testTokenize("#", [_]Token.Id{Token.Id.Invalid});
testTokenize("`", [_]Token.Id{Token.Id.Invalid});
testTokenize("'c", [_]Token.Id{Token.Id.Invalid});
testTokenize("'", [_]Token.Id{Token.Id.Invalid});
testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
}
test "tokenizer - invalid literal/comment characters" {
testTokenize("\"\x00\"", []Token.Id{
testTokenize("\"\x00\"", [_]Token.Id{
Token.Id.StringLiteral,
Token.Id.Invalid,
});
testTokenize("//\x00", []Token.Id{
testTokenize("//\x00", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\x1f", []Token.Id{
testTokenize("//\x1f", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\x7f", []Token.Id{
testTokenize("//\x7f", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
}
test "tokenizer - utf8" {
testTokenize("//\xc2\x80", []Token.Id{Token.Id.LineComment});
testTokenize("//\xf4\x8f\xbf\xbf", []Token.Id{Token.Id.LineComment});
testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - invalid utf8" {
testTokenize("//\x80", []Token.Id{
testTokenize("//\x80", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xbf", []Token.Id{
testTokenize("//\xbf", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xf8", []Token.Id{
testTokenize("//\xf8", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xff", []Token.Id{
testTokenize("//\xff", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xc2\xc0", []Token.Id{
testTokenize("//\xc2\xc0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xe0", []Token.Id{
testTokenize("//\xe0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xf0", []Token.Id{
testTokenize("//\xf0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xf0\x90\x80\xc0", []Token.Id{
testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
@ -1302,28 +1302,28 @@ test "tokenizer - invalid utf8" {
test "tokenizer - illegal unicode codepoints" {
// unicode newline characters.U+0085, U+2028, U+2029
testTokenize("//\xc2\x84", []Token.Id{Token.Id.LineComment});
testTokenize("//\xc2\x85", []Token.Id{
testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xc2\x85", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xc2\x86", []Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa7", []Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa8", []Token.Id{
testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xa8", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xe2\x80\xa9", []Token.Id{
testTokenize("//\xe2\x80\xa9", [_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
testTokenize("//\xe2\x80\xaa", []Token.Id{Token.Id.LineComment});
testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - string identifier and builtin fns" {
testTokenize(
\\const @"if" = @import("std");
, []Token.Id{
, [_]Token.Id{
Token.Id.Keyword_const,
Token.Id.Identifier,
Token.Id.Equal,
@ -1336,19 +1336,19 @@ test "tokenizer - string identifier and builtin fns" {
}
test "tokenizer - pipe and then invalid" {
testTokenize("||=", []Token.Id{
testTokenize("||=", [_]Token.Id{
Token.Id.PipePipe,
Token.Id.Equal,
});
}
test "tokenizer - line comment and doc comment" {
testTokenize("//", []Token.Id{Token.Id.LineComment});
testTokenize("// a / b", []Token.Id{Token.Id.LineComment});
testTokenize("// /", []Token.Id{Token.Id.LineComment});
testTokenize("/// a", []Token.Id{Token.Id.DocComment});
testTokenize("///", []Token.Id{Token.Id.DocComment});
testTokenize("////", []Token.Id{Token.Id.LineComment});
testTokenize("//", [_]Token.Id{Token.Id.LineComment});
testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});
testTokenize("// /", [_]Token.Id{Token.Id.LineComment});
testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});
testTokenize("///", [_]Token.Id{Token.Id.DocComment});
testTokenize("////", [_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - line comment followed by identifier" {
@ -1356,7 +1356,7 @@ test "tokenizer - line comment followed by identifier" {
\\ Unexpected,
\\ // another
\\ Another,
, []Token.Id{
, [_]Token.Id{
Token.Id.Identifier,
Token.Id.Comma,
Token.Id.LineComment,

View File

@ -29,11 +29,11 @@ pub fn main() !void {
std.debug.warn("Expected second argument to be cache root directory path\n");
return error.InvalidArgs;
});
const zig_exe = try fs.path.resolve(a, [][]const u8{zig_exe_rel});
const zig_exe = try fs.path.resolve(a, [_][]const u8{zig_exe_rel});
const dir_path = try fs.path.join(a, [][]const u8{ cache_root, "clitest" });
const dir_path = try fs.path.join(a, [_][]const u8{ cache_root, "clitest" });
const TestFn = fn ([]const u8, []const u8) anyerror!void;
const test_fns = []TestFn{
const test_fns = [_]TestFn{
testZigInitLib,
testZigInitExe,
testGodboltApi,
@ -87,22 +87,22 @@ fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
}
fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
_ = try exec(dir_path, [][]const u8{ zig_exe, "init-lib" });
const test_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "test" });
_ = try exec(dir_path, [_][]const u8{ zig_exe, "init-lib" });
const test_result = try exec(dir_path, [_][]const u8{ zig_exe, "build", "test" });
testing.expect(std.mem.endsWith(u8, test_result.stderr, "All tests passed.\n"));
}
fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
_ = try exec(dir_path, [][]const u8{ zig_exe, "init-exe" });
const run_result = try exec(dir_path, [][]const u8{ zig_exe, "build", "run" });
_ = try exec(dir_path, [_][]const u8{ zig_exe, "init-exe" });
const run_result = try exec(dir_path, [_][]const u8{ zig_exe, "build", "run" });
testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));
}
fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
if (builtin.os != .linux or builtin.arch != .x86_64) return;
const example_zig_path = try fs.path.join(a, [][]const u8{ dir_path, "example.zig" });
const example_s_path = try fs.path.join(a, [][]const u8{ dir_path, "example.s" });
const example_zig_path = try fs.path.join(a, [_][]const u8{ dir_path, "example.zig" });
const example_s_path = try fs.path.join(a, [_][]const u8{ dir_path, "example.s" });
try std.io.writeFile(example_zig_path,
\\// Type your code here, or load an example.
@ -115,7 +115,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
\\}
);
const args = [][]const u8{
const args = [_][]const u8{
zig_exe, "build-obj",
"--cache-dir", dir_path,
"--name", "example",

View File

@ -287,7 +287,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\}
\\
\\export fn main() c_int {
\\ var array = []u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
\\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 };
\\
\\ c.qsort(@ptrCast(?*c_void, array[0..].ptr), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn);
\\
@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\
);
tc.setCommandLineArgs([][]const u8{
tc.setCommandLineArgs([_][]const u8{
"first arg",
"'a' 'b' \\",
"bare",
@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\
);
tc.setCommandLineArgs([][]const u8{
tc.setCommandLineArgs([_][]const u8{
"first arg",
"'a' 'b' \\",
"bare",

View File

@ -2,6 +2,33 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"slice passed as array init type",
\\export fn entry() void {
\\ const x = []u8{};
\\}
,
"tmp.zig:2:19: error: expected array type or [_], found slice",
);
cases.add(
"inferred array size invalid here",
\\export fn entry() void {
\\ const x = [_]u8;
\\}
,
"tmp.zig:2:15: error: inferred array size invalid here",
);
cases.add(
"initializing array with struct syntax",
\\export fn entry() void {
\\ const x = [_]u8{ .y = 2 };
\\}
,
"tmp.zig:2:15: error: initializing array with struct syntax",
);
cases.add(
"compile error in struct init expression",
\\const Foo = struct {
@ -375,8 +402,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest(
"comptime vector overflow shows the index",
\\comptime {
\\ var a: @Vector(4, u8) = []u8{ 1, 2, 255, 4 };
\\ var b: @Vector(4, u8) = []u8{ 5, 6, 1, 8 };
\\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
\\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
\\ var x = a + b;
\\}
,
@ -902,7 +929,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"implicit cast const array to mutable slice",
\\export fn entry() void {
\\ const buffer: [1]u8 = []u8{8};
\\ const buffer: [1]u8 = [_]u8{8};
\\ const sliceA: []u8 = &buffer;
\\}
,
@ -1239,8 +1266,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"`_` should not be usable inside for",
\\export fn returns() void {
\\ for ([]void{}) |_, i| {
\\ for ([]void{}) |_, j| {
\\ for ([_]void{}) |_, i| {
\\ for ([_]void{}) |_, j| {
\\ return _;
\\ }
\\ }
@ -2861,10 +2888,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"struct init syntax for array",
\\const foo = []u16{.x = 1024,};
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
\\const foo = [3]u16{ .x = 1024 };
\\comptime {
\\ _ = foo;
\\}
,
"tmp.zig:1:18: error: type '[]u16' does not support struct initialization syntax",
"tmp.zig:1:19: error: type '[3]u16' does not support struct initialization syntax",
);
cases.add(
@ -3116,7 +3145,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\};
\\
\\const member_fn_type = @typeOf(Foo.member_a);
\\const members = []member_fn_type {
\\const members = [_]member_fn_type {
\\ Foo.member_a,
\\ Foo.member_b,
\\};
@ -3142,25 +3171,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"wrong function type",
\\const fns = []fn() void { a, b, c };
\\const fns = [_]fn() void { a, b, c };
\\fn a() i32 {return 0;}
\\fn b() i32 {return 1;}
\\fn c() i32 {return 2;}
\\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
,
"tmp.zig:1:27: error: expected type 'fn() void', found 'fn() i32'",
"tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",
);
cases.add(
"extern function pointer mismatch",
\\const fns = [](fn(i32)i32) { a, b, c };
\\const fns = [_](fn(i32)i32) { a, b, c };
\\pub fn a(x: i32) i32 {return x + 0;}
\\pub fn b(x: i32) i32 {return x + 1;}
\\export fn c(x: i32) i32 {return x + 2;}
\\
\\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
,
"tmp.zig:1:36: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",
"tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",
);
cases.add(
@ -3261,7 +3290,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"indexing an array of size zero",
\\const array = []u8{};
\\const array = [_]u8{};
\\export fn foo() void {
\\ const pointer = &array[0];
\\}
@ -4854,7 +4883,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"calling a var args function only known at runtime",
\\var foos = []fn(...) void { foo1, foo2 };
\\var foos = [_]fn(...) void { foo1, foo2 };
\\
\\fn foo1(args: ...) void {}
\\fn foo2(args: ...) void {}
@ -4868,7 +4897,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"calling a generic function only known at runtime",
\\var foos = []fn(var) void { foo1, foo2 };
\\var foos = [_]fn(var) void { foo1, foo2 };
\\
\\fn foo1(arg: var) void {}
\\fn foo2(arg: var) void {}
@ -5022,7 +5051,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"increase pointer alignment in @ptrCast",
\\export fn entry() u32 {
\\ var bytes: [4]u8 = []u8{0x01, 0x02, 0x03, 0x04};
\\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
\\ const ptr = @ptrCast(*u32, &bytes[0]);
\\ return ptr.*;
\\}
@ -5249,7 +5278,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\};
\\
\\export fn entry() void {
\\ const tests = []TestCase {
\\ const tests = [_]TestCase {
\\ Free("001"),
\\ Free("002"),
\\ LibC("078"),
@ -5257,7 +5286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ Free("117"),
\\ };
\\
\\ for ([]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
\\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
\\ inline for (tests) |test_case| {
\\ const foo = test_case.filename ++ ".zig";
\\ }

View File

@ -112,7 +112,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() void {
\\ const a = []i32{1, 2, 3, 4};
\\ const a = [_]i32{1, 2, 3, 4};
\\ baz(bar(a));
\\}
\\fn bar(a: []const i32) i32 {
@ -139,8 +139,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @Vector(4, i32) = []i32{ 1, 2, 2147483643, 4 };
\\ var b: @Vector(4, i32) = []i32{ 5, 6, 7, 8 };
\\ var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
\\ var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
\\ const x = add(a, b);
\\}
\\fn add(a: @Vector(4, i32), b: @Vector(4, i32)) @Vector(4, i32) {
@ -153,8 +153,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @Vector(4, u32) = []u32{ 1, 2, 8, 4 };
\\ var b: @Vector(4, u32) = []u32{ 5, 6, 7, 8 };
\\ var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
\\ var b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
\\ const x = sub(b, a);
\\}
\\fn sub(a: @Vector(4, u32), b: @Vector(4, u32)) @Vector(4, u32) {
@ -167,8 +167,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @Vector(4, u8) = []u8{ 1, 2, 200, 4 };
\\ var b: @Vector(4, u8) = []u8{ 5, 6, 2, 8 };
\\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
\\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
\\ const x = mul(b, a);
\\}
\\fn mul(a: @Vector(4, u8), b: @Vector(4, u8)) @Vector(4, u8) {
@ -181,7 +181,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @Vector(4, i16) = []i16{ 1, -32768, 200, 4 };
\\ var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
\\ const x = neg(a);
\\}
\\fn neg(a: @Vector(4, i16)) @Vector(4, i16) {
@ -323,7 +323,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
\\ const x = widenSlice([_]u8{1, 2, 3, 4, 5});
\\ if (x.len == 0) return error.Whatever;
\\}
\\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 {
@ -426,7 +426,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() !void {
\\ var array align(4) = []u32{0x11111111, 0x11111111};
\\ var array align(4) = [_]u32{0x11111111, 0x11111111};
\\ const bytes = @sliceToBytes(array[0..]);
\\ if (foo(bytes) != 0x11111111) return error.Wrong;
\\}

View File

@ -70,7 +70,7 @@ test "specifying alignment allows pointer cast" {
testBytesAlign(0x33);
}
fn testBytesAlign(b: u8) void {
var bytes align(4) = []u8{
var bytes align(4) = [_]u8{
b,
b,
b,
@ -84,7 +84,7 @@ test "specifying alignment allows slice cast" {
testBytesAlignSlice(0x33);
}
fn testBytesAlignSlice(b: u8) void {
var bytes align(4) = []u8{
var bytes align(4) = [_]u8{
b,
b,
b,
@ -107,7 +107,7 @@ fn expects4(x: *align(4) u32) void {
}
test "@alignCast slices" {
var array align(4) = []u32{
var array align(4) = [_]u32{
1,
1,
};
@ -169,21 +169,21 @@ test "@ptrCast preserves alignment of bigger source" {
test "runtime known array index has best alignment possible" {
// take full advantage of over-alignment
var array align(4) = []u8{ 1, 2, 3, 4 };
var array align(4) = [_]u8{ 1, 2, 3, 4 };
expect(@typeOf(&array[0]) == *align(4) u8);
expect(@typeOf(&array[1]) == *u8);
expect(@typeOf(&array[2]) == *align(2) u8);
expect(@typeOf(&array[3]) == *u8);
// because align is too small but we still figure out to use 2
var bigger align(2) = []u64{ 1, 2, 3, 4 };
var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
expect(@typeOf(&bigger[0]) == *align(2) u64);
expect(@typeOf(&bigger[1]) == *align(2) u64);
expect(@typeOf(&bigger[2]) == *align(2) u64);
expect(@typeOf(&bigger[3]) == *align(2) u64);
// because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
var smaller align(2) = []u32{ 1, 2, 3, 4 };
var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
comptime expect(@typeOf(smaller[0..]) == []align(2) u32);
comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32);
testIndex(smaller[0..].ptr, 0, *align(2) u32);

View File

@ -34,7 +34,7 @@ test "void arrays" {
}
test "array literal" {
const hex_mult = []u16{
const hex_mult = [_]u16{
4096,
256,
16,
@ -54,7 +54,7 @@ test "array dot len const expr" {
const ArrayDotLenConstExpr = struct {
y: [some_array.len]u8,
};
const some_array = []u8{
const some_array = [_]u8{
0,
1,
2,
@ -62,7 +62,7 @@ const some_array = []u8{
};
test "nested arrays" {
const array_of_strings = [][]const u8{
const array_of_strings = [_][]const u8{
"hello",
"this",
"is",
@ -158,7 +158,7 @@ fn testArrayByValAtComptime(b: [2]u8) u8 {
}
test "comptime evalutating function that takes array by value" {
const arr = []u8{ 0, 1 };
const arr = [_]u8{ 0, 1 };
_ = comptime testArrayByValAtComptime(arr);
_ = comptime testArrayByValAtComptime(arr);
}
@ -175,22 +175,22 @@ fn plusOne(x: u32) u32 {
test "array literal as argument to function" {
const S = struct {
fn entry(two: i32) void {
foo([]i32{
foo([_]i32{
1,
2,
3,
});
foo([]i32{
foo([_]i32{
1,
two,
3,
});
foo2(true, []i32{
foo2(true, [_]i32{
1,
2,
3,
});
foo2(true, []i32{
foo2(true, [_]i32{
1,
two,
3,
@ -215,19 +215,19 @@ test "array literal as argument to function" {
test "double nested array to const slice cast in array literal" {
const S = struct {
fn entry(two: i32) void {
const cases = [][]const []const i32{
[][]const i32{[]i32{1}},
[][]const i32{[]i32{ 2, 3 }},
[][]const i32{
[]i32{4},
[]i32{ 5, 6, 7 },
const cases = [_][]const []const i32{
[_][]const i32{[_]i32{1}},
[_][]const i32{[_]i32{ 2, 3 }},
[_][]const i32{
[_]i32{4},
[_]i32{ 5, 6, 7 },
},
};
check(cases);
const cases2 = [][]const i32{
[]i32{1},
[]i32{ two, 3 },
const cases2 = [_][]const i32{
[_]i32{1},
[_]i32{ two, 3 },
};
expect(cases2.len == 2);
expect(cases2[0].len == 1);
@ -236,12 +236,12 @@ test "double nested array to const slice cast in array literal" {
expect(cases2[1][0] == 2);
expect(cases2[1][1] == 3);
const cases3 = [][]const []const i32{
[][]const i32{[]i32{1}},
[][]const i32{[]i32{ two, 3 }},
[][]const i32{
[]i32{4},
[]i32{ 5, 6, 7 },
const cases3 = [_][]const []const i32{
[_][]const i32{[_]i32{1}},
[_][]const i32{[_]i32{ two, 3 }},
[_][]const i32{
[_]i32{4},
[_]i32{ 5, 6, 7 },
},
};
check(cases3);

View File

@ -11,7 +11,7 @@ fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, compt
shards: [1 << ShardKey.bit_count]?*Node,
pub fn create() Self {
return Self{ .shards = []?*Node{null} ** (1 << ShardKey.bit_count) };
return Self{ .shards = [_]?*Node{null} ** (1 << ShardKey.bit_count) };
}
fn getShardKey(key: Key) ShardKey {

View File

@ -11,7 +11,7 @@ const A = union(enum) {
};
test "union that needs padding bytes inside an array" {
var as = []A{
var as = [_]A{
A{ .B = B{ .D = 1 } },
A{ .B = B{ .D = 1 } },
};

View File

@ -1,7 +1,7 @@
const std = @import("std");
const testing = std.testing;
const a = []u8{ 1, 2, 3 };
const a = [_]u8{ 1, 2, 3 };
fn checkAddress(s: []const u8) void {
for (s) |*i, j| {

View File

@ -7,7 +7,7 @@ const B = struct {
a_pointer: *const A,
};
const b_list: []B = []B{};
const b_list: []B = [_]B{};
const a = A{ .b_list_pointer = &b_list };
test "segfault bug" {
@ -24,7 +24,7 @@ pub const B2 = struct {
pointer_array: []*A2,
};
var b_value = B2{ .pointer_array = []*A2{} };
var b_value = B2{ .pointer_array = [_]*A2{} };
test "basic stuff" {
std.debug.assert(&b_value == &b_value);

View File

@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {
}
fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
if (a) {
return []const u8{};
return [_]u8{};
}
return slice[0..1];
@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {
}
fn gimmeErrOrSlice() anyerror![]u8 {
return []u8{};
return [_]u8{};
}
test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
@ -194,7 +194,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
}
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
if (a) {
return []u8{};
return [_]u8{};
}
return slice[0..1];
@ -287,7 +287,7 @@ fn cast128Float(x: u128) f128 {
}
test "const slice widen cast" {
const bytes align(4) = []u8{
const bytes align(4) = [_]u8{
0x12,
0x12,
0x12,
@ -364,7 +364,7 @@ test "comptime_int @intToFloat" {
}
test "@bytesToSlice keeps pointer alignment" {
var bytes = []u8{ 0x01, 0x02, 0x03, 0x04 };
var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
const numbers = @bytesToSlice(u32, bytes[0..]);
comptime expect(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32);
}
@ -415,9 +415,9 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
}
test "implicit cast from [*]T to ?*c_void" {
var a = []u8{ 3, 2, 1 };
var a = [_]u8{ 3, 2, 1 };
incrementVoidPtrArray(a[0..].ptr, 3);
expect(std.mem.eql(u8, a, []u8{ 4, 3, 2 }));
expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 }));
}
fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {

View File

@ -5,7 +5,7 @@ const expect = std.testing.expect;
var argv: [*]const [*]const u8 = undefined;
test "const slice child" {
const strs = ([][*]const u8){
const strs = [_][*]const u8{
c"one",
c"two",
c"three",

View File

@ -38,7 +38,7 @@ async fn await_another() Foo {
return Foo{ .x = 1234 };
}
var await_points = []u8{0} ** "abcdefghi".len;
var await_points = [_]u8{0} ** "abcdefghi".len;
var await_seq_index: usize = 0;
fn await_seq(c: u8) void {

View File

@ -40,7 +40,7 @@ async fn testAsyncSeq() void {
suspend;
seq('d');
}
var points = []u8{0} ** "abcdefg".len;
var points = [_]u8{0} ** "abcdefg".len;
var index: usize = 0;
fn seq(c: u8) void {
@ -106,7 +106,7 @@ async fn await_another() i32 {
return 1234;
}
var await_points = []u8{0} ** "abcdefghi".len;
var await_points = [_]u8{0} ** "abcdefghi".len;
var await_seq_index: usize = 0;
fn await_seq(c: u8) void {
@ -138,7 +138,7 @@ async fn early_another() i32 {
return 1234;
}
var early_points = []u8{0} ** "abcdef".len;
var early_points = [_]u8{0} ** "abcdef".len;
var early_seq_index: usize = 0;
fn early_seq(c: u8) void {

View File

@ -930,7 +930,7 @@ test "enum literal in array literal" {
two,
};
const array = []Items{
const array = [_]Items{
.one,
.two,
};

View File

@ -73,7 +73,7 @@ const Point = struct {
x: i32,
y: i32,
};
const static_point_list = []Point{
const static_point_list = [_]Point{
makePoint(1, 2),
makePoint(3, 4),
};
@ -94,7 +94,7 @@ pub const Vec3 = struct {
};
pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
return Vec3{
.data = []f32{
.data = [_]f32{
x,
y,
z,
@ -118,7 +118,7 @@ const Vertex = struct {
g: f32,
b: f32,
};
const vertices = []Vertex{
const vertices = [_]Vertex{
Vertex{
.x = -0.6,
.y = -0.4,
@ -159,7 +159,7 @@ test "statically initalized array literal" {
const y: [4]u8 = st_init_arr_lit_x;
expect(y[3] == 4);
}
const st_init_arr_lit_x = []u8{
const st_init_arr_lit_x = [_]u8{
1,
2,
3,
@ -221,7 +221,7 @@ const CmdFn = struct {
func: fn (i32) i32,
};
const cmd_fns = []CmdFn{
const cmd_fns = [_]CmdFn{
CmdFn{
.name = "one",
.func = one,
@ -595,7 +595,7 @@ test "pointer to type" {
test "slice of type" {
comptime {
var types_array = []type{ i32, f64, type };
var types_array = [_]type{ i32, f64, type };
for (types_array) |T, i| {
switch (i) {
0 => expect(T == i32),
@ -672,7 +672,7 @@ fn testVarInsideInlineLoop(args: ...) void {
test "inline for with same type but different values" {
var res: usize = 0;
inline for ([]type{ [2]u8, [1]u8, [2]u8 }) |T| {
inline for ([_]type{ [2]u8, [1]u8, [2]u8 }) |T| {
var a: T = undefined;
res += a.len;
}
@ -710,7 +710,7 @@ test "@bytesToslice on a packed struct" {
}
test "comptime pointer cast array and then slice" {
const array = []u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
const array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
const ptrA: [*]const u8 = @ptrCast([*]const u8, &array);
const sliceA: []const u8 = ptrA[0..2];
@ -763,16 +763,16 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {
test "array concatenation forces comptime" {
var a = oneItem(3) ++ oneItem(4);
expect(std.mem.eql(i32, a, []i32{ 3, 4 }));
expect(std.mem.eql(i32, a, [_]i32{ 3, 4 }));
}
test "array multiplication forces comptime" {
var a = oneItem(3) ** scalar(2);
expect(std.mem.eql(i32, a, []i32{ 3, 3 }));
expect(std.mem.eql(i32, a, [_]i32{ 3, 3 }));
}
fn oneItem(x: i32) [1]i32 {
return []i32{x};
return [_]i32{x};
}
fn scalar(x: u32) u32 {

View File

@ -73,7 +73,7 @@ fn fnWithUnreachable() noreturn {
}
test "function pointers" {
const fns = []@typeOf(fn1){
const fns = [_]@typeOf(fn1){
fn1,
fn2,
fn3,

View File

@ -3,7 +3,7 @@ const expect = std.testing.expect;
const mem = std.mem;
test "continue in for loop" {
const array = []i32{
const array = [_]i32{
1,
2,
3,
@ -41,12 +41,12 @@ fn mangleString(s: []u8) void {
}
test "basic for loop" {
const expected_result = []u8{ 9, 8, 7, 6, 0, 1, 2, 3 } ** 3;
const expected_result = [_]u8{ 9, 8, 7, 6, 0, 1, 2, 3 } ** 3;
var buffer: [expected_result.len]u8 = undefined;
var buf_index: usize = 0;
const array = []u8{ 9, 8, 7, 6 };
const array = [_]u8{ 9, 8, 7, 6 };
for (array) |item| {
buffer[buf_index] = item;
buf_index += 1;

View File

@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
}
test "generic fn with implicit cast" {
expect(getFirstByte(u8, []u8{13}) == 13);
expect(getFirstByte(u16, []u16{
expect(getFirstByte(u8, [_]u8{13}) == 13);
expect(getFirstByte(u16, [_]u16{
0,
13,
}) == 0);
@ -133,7 +133,7 @@ fn getFirstByte(comptime T: type, mem: []const T) u8 {
return getByte(@ptrCast(*const u8, &mem[0]));
}
const foos = []fn (var) bool{
const foos = [_]fn (var) bool{
foo1,
foo2,
};

View File

@ -345,7 +345,7 @@ test "quad hex float literal parsing accurate" {
var f: f128 = 0x1.ed8764648369535adf4be3214567fp-9;
expect(@bitCast(u128, f) == 0x3ff6ed8764648369535adf4be3214568);
}
const exp2ft = []f64{
const exp2ft = [_]f64{
0x1.6a09e667f3bcdp-1,
0x1.7a11473eb0187p-1,
0x1.8ace5422aa0dbp-1,
@ -371,7 +371,7 @@ test "quad hex float literal parsing accurate" {
-0x1.0p-149,
};
const answers = []u64{
const answers = [_]u64{
0x3fe6a09e667f3bcd,
0x3fe7a11473eb0187,
0x3fe8ace5422aa0db,
@ -601,11 +601,11 @@ fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int
test "vector integer addition" {
const S = struct {
fn doTheTest() void {
var a: @Vector(4, i32) = []i32{ 1, 2, 3, 4 };
var b: @Vector(4, i32) = []i32{ 5, 6, 7, 8 };
var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
var result = a + b;
var result_array: [4]i32 = result;
const expected = []i32{ 6, 8, 10, 12 };
const expected = [_]i32{ 6, 8, 10, 12 };
expectEqualSlices(i32, &expected, &result_array);
}
};

View File

@ -376,7 +376,7 @@ test "C string concatenation" {
test "cast slice to u8 slice" {
expect(@sizeOf(i32) == 4);
var big_thing_array = []i32{ 1, 2, 3, 4 };
var big_thing_array = [_]i32{ 1, 2, 3, 4 };
const big_thing_slice: []i32 = big_thing_array[0..];
const bytes = @sliceToBytes(big_thing_slice);
expect(bytes.len == 4 * 4);
@ -412,9 +412,9 @@ test "non const ptr to aliased type" {
}
test "array 2D const double ptr" {
const rect_2d_vertexes = [][1]f32{
[]f32{1.0},
[]f32{2.0},
const rect_2d_vertexes = [_][1]f32{
[_]f32{1.0},
[_]f32{2.0},
};
testArray2DConstDoublePtr(&rect_2d_vertexes[0][0]);
}
@ -513,7 +513,7 @@ test "global variable initialized to global variable array element" {
const GDTEntry = struct {
field: i32,
};
var gdt = []GDTEntry{
var gdt = [_]GDTEntry{
GDTEntry{ .field = 1 },
GDTEntry{ .field = 2 },
};
@ -607,11 +607,11 @@ export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion, c: Pack
test "slicing zero length array" {
const s1 = ""[0..];
const s2 = ([]u32{})[0..];
const s2 = ([_]u32{})[0..];
expect(s1.len == 0);
expect(s2.len == 0);
expect(mem.eql(u8, s1, ""));
expect(mem.eql(u32, s2, []u32{}));
expect(mem.eql(u32, s2, [_]u32{}));
}
const addr1 = @ptrCast(*const u8, emptyFn);
@ -650,7 +650,7 @@ test "volatile load and store" {
test "slice string literal has type []const u8" {
comptime {
expect(@typeOf("aoeu"[0..]) == []const u8);
const array = []i32{ 1, 2, 3, 4 };
const array = [_]i32{ 1, 2, 3, 4 };
expect(@typeOf(array[0..]) == []const i32);
}
}

View File

@ -22,7 +22,7 @@ test "reinterpret bytes of an array into an extern struct" {
}
fn testReinterpretBytesAsExternStruct() void {
var bytes align(2) = []u8{ 1, 2, 3, 4, 5, 6 };
var bytes align(2) = [_]u8{ 1, 2, 3, 4, 5, 6 };
const S = extern struct {
a: u8,
@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {
test "reinterpret struct field at comptime" {
const numLittle = comptime Bytes.init(0x12345678);
expect(std.mem.eql(u8, []u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
}
const Bytes = struct {

View File

@ -14,7 +14,7 @@ test "compile time slice of pointer to hard coded address" {
}
test "runtime safety lets us slice from len..len" {
var an_array = []u8{
var an_array = [_]u8{
1,
2,
3,
@ -27,7 +27,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
}
test "implicitly cast array of size 0 to slice" {
var msg = []u8{};
var msg = [_]u8{};
assertLenIsZero(msg);
}
@ -51,6 +51,6 @@ fn sliceSum(comptime q: []const u8) i32 {
}
test "comptime slices are disambiguated" {
expect(sliceSum([]u8{ 1, 2 }) == 3);
expect(sliceSum([]u8{ 3, 4 }) == 7);
expect(sliceSum([_]u8{ 1, 2 }) == 3);
expect(sliceSum([_]u8{ 3, 4 }) == 7);
}

View File

@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
}
test "pass slice of empty struct to fn" {
expect(testPassSliceOfEmptyStructToFn([]EmptyStruct2{EmptyStruct2{}}) == 1);
expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1);
}
fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
return slice.len;
@ -313,7 +313,7 @@ test "packed array 24bits" {
expect(@sizeOf(FooArray24Bits) == 2 + 2 * 4 + 2);
}
var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);
var bytes = [_]u8{0} ** (@sizeOf(FooArray24Bits) + 1);
bytes[bytes.len - 1] = 0xaa;
const ptr = &@bytesToSlice(FooArray24Bits, bytes[0 .. bytes.len - 1])[0];
expect(ptr.a == 0);
@ -363,7 +363,7 @@ test "aligned array of packed struct" {
expect(@sizeOf(FooArrayOfAligned) == 2 * 2);
}
var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);
var bytes = [_]u8{0xbb} ** @sizeOf(FooArrayOfAligned);
const ptr = &@bytesToSlice(FooArrayOfAligned, bytes[0..bytes.len])[0];
expect(ptr.a[0].a == 0xbb);
@ -432,7 +432,7 @@ const Expr = union(enum) {
};
fn alloc(comptime T: type) []T {
return []T{};
return [_]T{};
}
test "call method with mutable reference to struct with no fields" {

View File

@ -11,24 +11,24 @@ const NodeAligned = struct {
};
test "struct contains slice of itself" {
var other_nodes = []Node{
var other_nodes = [_]Node{
Node{
.payload = 31,
.children = []Node{},
.children = [_]Node{},
},
Node{
.payload = 32,
.children = []Node{},
.children = [_]Node{},
},
};
var nodes = []Node{
var nodes = [_]Node{
Node{
.payload = 1,
.children = []Node{},
.children = [_]Node{},
},
Node{
.payload = 2,
.children = []Node{},
.children = [_]Node{},
},
Node{
.payload = 3,
@ -48,24 +48,24 @@ test "struct contains slice of itself" {
}
test "struct contains aligned slice of itself" {
var other_nodes = []NodeAligned{
var other_nodes = [_]NodeAligned{
NodeAligned{
.payload = 31,
.children = []NodeAligned{},
.children = [_]NodeAligned{},
},
NodeAligned{
.payload = 32,
.children = []NodeAligned{},
.children = [_]NodeAligned{},
},
};
var nodes = []NodeAligned{
var nodes = [_]NodeAligned{
NodeAligned{
.payload = 1,
.children = []NodeAligned{},
.children = [_]NodeAligned{},
},
NodeAligned{
.payload = 2,
.children = []NodeAligned{},
.children = [_]NodeAligned{},
},
NodeAligned{
.payload = 3,

Some files were not shown because too many files have changed in this diff Show More