authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-27 03:30:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-27 03:37:50-05:00
logbf3ac6615051143a9ef41180cd74e88de5dd573d
tree94571f5e6d408287928091c4dad6451d946d6434
parent379d547603badb2667089c85454a2e3f5ede3342
signaturelock-open Commit is signed but in an unrecognized format.

remove type coercion from array values to references

* Implements #3768. This is a sweeping breaking change that requires many (trivial) edits to Zig source code. Array values no longer coerced to slices; however one may use `&` to obtain a reference to an array value, which may then be coerced to a slice. * Adds `IrInstruction::dump`, for debugging purposes. It's useful to call to inspect the instruction when debugging Zig IR. * Fixes bugs with result location semantics. See the new behavior test cases, and compile error test cases. * Fixes bugs with `@typeInfo` not properly resolving const values. * Behavior tests are passing but std lib tests are not yet. There is more work to do before merging this branch.

67 files changed, 729 insertions(+), 839 deletions(-)

build.zig+15-15
......@@ -20,10 +20,10 @@ pub fn build(b: *Builder) !void {
2020 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
2121 const langref_out_path = fs.path.join(
2222 b.allocator,
23 [_][]const u8{ b.cache_root, "langref.html" },
23 &[_][]const u8{ b.cache_root, "langref.html" },
2424 ) catch unreachable;
2525 var docgen_cmd = docgen_exe.run();
26 docgen_cmd.addArgs([_][]const u8{
26 docgen_cmd.addArgs(&[_][]const u8{
2727 rel_zig_exe,
2828 "doc" ++ fs.path.sep_str ++ "langref.html.in",
2929 langref_out_path,
......@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {
3636 const test_step = b.step("test", "Run all the tests");
3737
3838 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 const build_info = try b.exec([_][]const u8{
39 const build_info = try b.exec(&[_][]const u8{
4040 b.zig_exe,
4141 "BUILD_INFO",
4242 });
......@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {
5656 test_stage2.setBuildMode(builtin.Mode.Debug);
5757 test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");
5858
59 const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"});
59 const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
6060
6161 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
6262 exe.setBuildMode(mode);
......@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {
8888 .source_dir = "lib",
8989 .install_dir = .Lib,
9090 .install_subdir = "zig",
91 .exclude_extensions = [_][]const u8{ "test.zig", "README.md" },
91 .exclude_extensions = &[_][]const u8{ "test.zig", "README.md" },
9292 });
9393
9494 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
......@@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
148148 }
149149 const lib_dir = fs.path.join(
150150 b.allocator,
151 [_][]const u8{ dep.prefix, "lib" },
151 &[_][]const u8{ dep.prefix, "lib" },
152152 ) catch unreachable;
153153 for (dep.system_libs.toSliceConst()) |lib| {
154154 const static_bare_name = if (mem.eql(u8, lib, "curses"))
......@@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
157157 b.fmt("lib{}.a", lib);
158158 const static_lib_name = fs.path.join(
159159 b.allocator,
160 [_][]const u8{ lib_dir, static_bare_name },
160 &[_][]const u8{ lib_dir, static_bare_name },
161161 ) catch unreachable;
162162 const have_static = fileExists(static_lib_name) catch unreachable;
163163 if (have_static) {
......@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {
183183}
184184
185185fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{
186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
187187 cmake_binary_dir,
188188 "zig_cpp",
189189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
......@@ -199,22 +199,22 @@ const LibraryDep = struct {
199199};
200200
201201fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
202 const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" });
202 const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" });
203203 const is_static = mem.startsWith(u8, shared_mode, "static");
204204 const libs_output = if (is_static)
205 try b.exec([_][]const u8{
205 try b.exec(&[_][]const u8{
206206 llvm_config_exe,
207207 "--libfiles",
208208 "--system-libs",
209209 })
210210 else
211 try b.exec([_][]const u8{
211 try b.exec(&[_][]const u8{
212212 llvm_config_exe,
213213 "--libs",
214214 });
215 const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });
216 const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" });
217 const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" });
215 const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" });
216 const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" });
217 const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
218218
219219 var result = LibraryDep{
220220 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,
......@@ -341,7 +341,7 @@ fn addCxxKnownPath(
341341 objname: []const u8,
342342 errtxt: ?[]const u8,
343343) !void {
344 const path_padded = try b.exec([_][]const u8{
344 const path_padded = try b.exec(&[_][]const u8{
345345 ctx.cxx_compiler,
346346 b.fmt("-print-file-name={}", objname),
347347 });
lib/std/array_list.zig+4-11
......@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
3535 /// Deinitialize with `deinit` or use `toOwnedSlice`.
3636 pub fn init(allocator: *Allocator) Self {
3737 return Self{
38 .items = [_]T{},
38 .items = &[_]T{},
3939 .len = 0,
4040 .allocator = allocator,
4141 };
......@@ -306,18 +306,14 @@ test "std.ArrayList.basic" {
306306 testing.expect(list.pop() == 10);
307307 testing.expect(list.len == 9);
308308
309 list.appendSlice([_]i32{
310 1,
311 2,
312 3,
313 }) catch unreachable;
309 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
314310 testing.expect(list.len == 12);
315311 testing.expect(list.pop() == 3);
316312 testing.expect(list.pop() == 2);
317313 testing.expect(list.pop() == 1);
318314 testing.expect(list.len == 9);
319315
320 list.appendSlice([_]i32{}) catch unreachable;
316 list.appendSlice(&[_]i32{}) catch unreachable;
321317 testing.expect(list.len == 9);
322318
323319 // can only set on indices < self.len
......@@ -464,10 +460,7 @@ test "std.ArrayList.insertSlice" {
464460 try list.append(2);
465461 try list.append(3);
466462 try list.append(4);
467 try list.insertSlice(1, [_]i32{
468 9,
469 8,
470 });
463 try list.insertSlice(1, &[_]i32{ 9, 8 });
471464 testing.expect(list.items[0] == 1);
472465 testing.expect(list.items[1] == 9);
473466 testing.expect(list.items[2] == 8);
lib/std/bloom_filter.zig+3-3
......@@ -62,7 +62,7 @@ pub fn BloomFilter(
6262 }
6363
6464 pub fn getCell(self: Self, cell: Index) Cell {
65 return Io.get(self.data, cell, 0);
65 return Io.get(&self.data, cell, 0);
6666 }
6767
6868 pub fn incrementCell(self: *Self, cell: Index) void {
......@@ -70,7 +70,7 @@ pub fn BloomFilter(
7070 // skip the 'get' operation
7171 Io.set(&self.data, cell, 0, cellMax);
7272 } else {
73 const old = Io.get(self.data, cell, 0);
73 const old = Io.get(&self.data, cell, 0);
7474 if (old != cellMax) {
7575 Io.set(&self.data, cell, 0, old + 1);
7676 }
......@@ -120,7 +120,7 @@ pub fn BloomFilter(
120120 } else if (newsize > n_items) {
121121 var copied: usize = 0;
122122 while (copied < r.data.len) : (copied += self.data.len) {
123 std.mem.copy(u8, r.data[copied .. copied + self.data.len], self.data);
123 std.mem.copy(u8, r.data[copied .. copied + self.data.len], &self.data);
124124 }
125125 }
126126 return r;
lib/std/build.zig+30-27
......@@ -186,7 +186,7 @@ pub const Builder = struct {
186186 pub fn resolveInstallPrefix(self: *Builder) void {
187187 if (self.dest_dir) |dest_dir| {
188188 const install_prefix = self.install_prefix orelse "/usr";
189 self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
189 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable;
190190 } else {
191191 const install_prefix = self.install_prefix orelse blk: {
192192 const p = self.cache_root;
......@@ -195,8 +195,8 @@ pub const Builder = struct {
195195 };
196196 self.install_path = install_prefix;
197197 }
198 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;
199 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;
198 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
199 self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
200200 }
201201
202202 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -803,7 +803,7 @@ pub const Builder = struct {
803803 }
804804
805805 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
806 return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable;
806 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
807807 }
808808
809809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
......@@ -818,7 +818,7 @@ pub const Builder = struct {
818818 if (fs.path.isAbsolute(name)) {
819819 return name;
820820 }
821 const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
822822 return fs.realpathAlloc(self.allocator, full_path) catch continue;
823823 }
824824 }
......@@ -827,9 +827,9 @@ pub const Builder = struct {
827827 if (fs.path.isAbsolute(name)) {
828828 return name;
829829 }
830 var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter});
830 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
831831 while (it.next()) |path| {
832 const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
832 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
833833 return fs.realpathAlloc(self.allocator, full_path) catch continue;
834834 }
835835 }
......@@ -839,7 +839,7 @@ pub const Builder = struct {
839839 return name;
840840 }
841841 for (paths) |path| {
842 const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
842 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
843843 return fs.realpathAlloc(self.allocator, full_path) catch continue;
844844 }
845845 }
......@@ -926,12 +926,12 @@ pub const Builder = struct {
926926 };
927927 return fs.path.resolve(
928928 self.allocator,
929 [_][]const u8{ base_dir, dest_rel_path },
929 &[_][]const u8{ base_dir, dest_rel_path },
930930 ) catch unreachable;
931931 }
932932
933933 fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {
934 const stdout = try self.execAllowFail([_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
934 const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
935935 var list = ArrayList(PkgConfigPkg).init(self.allocator);
936936 var line_it = mem.tokenize(stdout, "\r\n");
937937 while (line_it.next()) |line| {
......@@ -970,7 +970,7 @@ pub const Builder = struct {
970970
971971test "builder.findProgram compiles" {
972972 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");
973 _ = builder.findProgram([_][]const u8{}, [_][]const u8{}) catch null;
973 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
974974}
975975
976976/// Deprecated. Use `builtin.Version`.
......@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {
13841384 };
13851385
13861386 var code: u8 = undefined;
1387 const stdout = if (self.builder.execAllowFail([_][]const u8{
1387 const stdout = if (self.builder.execAllowFail(&[_][]const u8{
13881388 "pkg-config",
13891389 pkg_name,
13901390 "--cflags",
......@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {
15041504 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
15051505 return fs.path.join(
15061506 self.builder.allocator,
1507 [_][]const u8{ self.output_dir.?, self.out_filename },
1507 &[_][]const u8{ self.output_dir.?, self.out_filename },
15081508 ) catch unreachable;
15091509 }
15101510
......@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {
15141514 assert(self.kind == Kind.Lib);
15151515 return fs.path.join(
15161516 self.builder.allocator,
1517 [_][]const u8{ self.output_dir.?, self.out_lib_filename },
1517 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
15181518 ) catch unreachable;
15191519 }
15201520
......@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {
15251525 assert(!self.disable_gen_h);
15261526 return fs.path.join(
15271527 self.builder.allocator,
1528 [_][]const u8{ self.output_dir.?, self.out_h_filename },
1528 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
15291529 ) catch unreachable;
15301530 }
15311531
......@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {
15351535 assert(self.target.isWindows() or self.target.isUefi());
15361536 return fs.path.join(
15371537 self.builder.allocator,
1538 [_][]const u8{ self.output_dir.?, self.out_pdb_filename },
1538 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
15391539 ) catch unreachable;
15401540 }
15411541
......@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {
16051605 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
16061606 defer self.builder.allocator.free(triplet);
16071607
1608 const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" });
1608 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
16091609 errdefer allocator.free(include_path);
16101610 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });
16111611
1612 const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" });
1612 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
16131613 try self.lib_paths.append(lib_path);
16141614
1615 self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" });
1615 self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
16161616 },
16171617 }
16181618 }
......@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {
17251725 if (self.build_options_contents.len() > 0) {
17261726 const build_options_file = try fs.path.join(
17271727 builder.allocator,
1728 [_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
1728 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
17291729 );
17301730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
17311731 try zig_args.append("--pkg-begin");
......@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {
18491849 try zig_args.append("--test-cmd");
18501850 try zig_args.append(bin_name);
18511851 if (glibc_dir_arg) |dir| {
1852 const full_dir = try fs.path.join(builder.allocator, [_][]const u8{
1852 const full_dir = try fs.path.join(builder.allocator, &[_][]const u8{
18531853 dir,
18541854 try self.target.linuxTriple(builder.allocator),
18551855 });
......@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {
19941994 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
19951995
19961996 if (self.output_dir) |output_dir| {
1997 const full_dest = try fs.path.join(builder.allocator, [_][]const u8{
1997 const full_dest = try fs.path.join(builder.allocator, &[_][]const u8{
19981998 output_dir,
19991999 fs.path.basename(output_path),
20002000 });
......@@ -2068,7 +2068,7 @@ pub const RunStep = struct {
20682068 env_map.set(PATH, search_path) catch unreachable;
20692069 return;
20702070 };
2071 const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path);
2071 const new_path = self.builder.fmt("{}" ++ &[1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path);
20722072 env_map.set(PATH, new_path) catch unreachable;
20732073 }
20742074
......@@ -2162,6 +2162,9 @@ const InstallArtifactStep = struct {
21622162 if (self.artifact.isDynamicLibrary()) {
21632163 builder.pushInstalledFile(.Lib, artifact.major_only_filename);
21642164 builder.pushInstalledFile(.Lib, artifact.name_only_filename);
2165 if (self.artifact.target.isWindows()) {
2166 builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
2167 }
21652168 }
21662169 if (self.pdb_dir) |pdb_dir| {
21672170 builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
......@@ -2254,7 +2257,7 @@ pub const InstallDirStep = struct {
22542257 };
22552258
22562259 const rel_path = entry.path[full_src_dir.len + 1 ..];
2257 const dest_path = try fs.path.join(self.builder.allocator, [_][]const u8{ dest_prefix, rel_path });
2260 const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ dest_prefix, rel_path });
22582261 switch (entry.kind) {
22592262 .Directory => try fs.makePath(self.builder.allocator, dest_path),
22602263 .File => try self.builder.updateFile(entry.path, dest_path),
......@@ -2377,7 +2380,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
23772380 // sym link for libfoo.so.1 to libfoo.so.1.2.3
23782381 const major_only_path = fs.path.join(
23792382 allocator,
2380 [_][]const u8{ out_dir, filename_major_only },
2383 &[_][]const u8{ out_dir, filename_major_only },
23812384 ) catch unreachable;
23822385 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
23832386 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
......@@ -2386,7 +2389,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
23862389 // sym link for libfoo.so to libfoo.so.1
23872390 const name_only_path = fs.path.join(
23882391 allocator,
2389 [_][]const u8{ out_dir, filename_name_only },
2392 &[_][]const u8{ out_dir, filename_name_only },
23902393 ) catch unreachable;
23912394 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
23922395 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
......@@ -2399,7 +2402,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
23992402 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
24002403 defer allocator.free(appdata_path);
24012404
2402 const path_file = try fs.path.join(allocator, [_][]const u8{ appdata_path, "vcpkg.path.txt" });
2405 const path_file = try fs.path.join(allocator, &[_][]const u8{ appdata_path, "vcpkg.path.txt" });
24032406 defer allocator.free(path_file);
24042407
24052408 const file = fs.File.openRead(path_file) catch return null;
lib/std/crypto/aes.zig+2-2
......@@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type {
136136
137137 pub fn init(key: [keysize / 8]u8) Self {
138138 var ctx: Self = undefined;
139 expandKey(key, ctx.enc[0..], ctx.dec[0..]);
139 expandKey(&key, ctx.enc[0..], ctx.dec[0..]);
140140 return ctx;
141141 }
142142
......@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {
157157 var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);
158158 std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1);
159159
160 n += xorBytes(dst[n..], src[n..], keystream);
160 n += xorBytes(dst[n..], src[n..], &keystream);
161161 }
162162 }
163163 };
lib/std/crypto/blake2.zig+2-2
......@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {
256256 var out: [Blake2s256.digest_length]u8 = undefined;
257257
258258 var h = Blake2s256.init();
259 h.update(block);
259 h.update(&block);
260260 h.final(out[0..]);
261261}
262262
......@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {
490490 var out: [Blake2b512.digest_length]u8 = undefined;
491491
492492 var h = Blake2b512.init();
493 h.update(block);
493 h.update(&block);
494494 h.final(out[0..]);
495495}
lib/std/crypto/chacha20.zig+7-7
......@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {
218218 };
219219
220220 chaCha20IETF(result[0..], input[0..], 1, key, nonce);
221 testing.expectEqualSlices(u8, expected_result, result);
221 testing.expectEqualSlices(u8, &expected_result, &result);
222222
223223 // Chacha20 is self-reversing.
224224 var plaintext: [114]u8 = undefined;
225225 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);
226 testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal);
226 testing.expect(mem.compare(u8, input, &plaintext) == mem.Compare.Equal);
227227}
228228
229229// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
......@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {
258258 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
259259
260260 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
261 testing.expectEqualSlices(u8, expected_result, result);
261 testing.expectEqualSlices(u8, &expected_result, &result);
262262}
263263
264264test "crypto.chacha20 test vector 2" {
......@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {
292292 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
293293
294294 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
295 testing.expectEqualSlices(u8, expected_result, result);
295 testing.expectEqualSlices(u8, &expected_result, &result);
296296}
297297
298298test "crypto.chacha20 test vector 3" {
......@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {
326326 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
327327
328328 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
329 testing.expectEqualSlices(u8, expected_result, result);
329 testing.expectEqualSlices(u8, &expected_result, &result);
330330}
331331
332332test "crypto.chacha20 test vector 4" {
......@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {
360360 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
361361
362362 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
363 testing.expectEqualSlices(u8, expected_result, result);
363 testing.expectEqualSlices(u8, &expected_result, &result);
364364}
365365
366366test "crypto.chacha20 test vector 5" {
......@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {
432432 };
433433
434434 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
435 testing.expectEqualSlices(u8, expected_result, result);
435 testing.expectEqualSlices(u8, &expected_result, &result);
436436}
lib/std/crypto/gimli.zig+4-4
......@@ -83,7 +83,7 @@ test "permute" {
8383 while (i < 12) : (i += 1) {
8484 input[i] = i * i * i + i *% 0x9e3779b9;
8585 }
86 testing.expectEqualSlices(u32, input, [_]u32{
86 testing.expectEqualSlices(u32, &input, &[_]u32{
8787 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,
8888 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,
8989 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,
......@@ -92,7 +92,7 @@ test "permute" {
9292 },
9393 };
9494 state.permute();
95 testing.expectEqualSlices(u32, state.data, [_]u32{
95 testing.expectEqualSlices(u32, &state.data, &[_]u32{
9696 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,
9797 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,
9898 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,
......@@ -163,6 +163,6 @@ test "hash" {
163163 var msg: [58 / 2]u8 = undefined;
164164 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
165165 var md: [32]u8 = undefined;
166 hash(&md, msg);
167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", md);
166 hash(&md, &msg);
167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
168168}
lib/std/crypto/md5.zig+1-1
......@@ -276,6 +276,6 @@ test "md5 aligned final" {
276276 var out: [Md5.digest_length]u8 = undefined;
277277
278278 var h = Md5.init();
279 h.update(block);
279 h.update(&block);
280280 h.final(out[0..]);
281281}
lib/std/crypto/poly1305.zig+1-1
......@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
230230 var mac: [16]u8 = undefined;
231231 Poly1305.create(mac[0..], msg, key);
232232
233 std.testing.expectEqualSlices(u8, expected_mac, mac);
233 std.testing.expectEqualSlices(u8, expected_mac, &mac);
234234}
lib/std/crypto/sha1.zig+1-1
......@@ -297,6 +297,6 @@ test "sha1 aligned final" {
297297 var out: [Sha1.digest_length]u8 = undefined;
298298
299299 var h = Sha1.init();
300 h.update(block);
300 h.update(&block);
301301 h.final(out[0..]);
302302}
lib/std/crypto/sha2.zig+2-2
......@@ -343,7 +343,7 @@ test "sha256 aligned final" {
343343 var out: [Sha256.digest_length]u8 = undefined;
344344
345345 var h = Sha256.init();
346 h.update(block);
346 h.update(&block);
347347 h.final(out[0..]);
348348}
349349
......@@ -723,6 +723,6 @@ test "sha512 aligned final" {
723723 var out: [Sha512.digest_length]u8 = undefined;
724724
725725 var h = Sha512.init();
726 h.update(block);
726 h.update(&block);
727727 h.final(out[0..]);
728728}
lib/std/crypto/sha3.zig+2-2
......@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {
229229 var out: [Sha3_256.digest_length]u8 = undefined;
230230
231231 var h = Sha3_256.init();
232 h.update(block);
232 h.update(&block);
233233 h.final(out[0..]);
234234}
235235
......@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {
300300 var out: [Sha3_512.digest_length]u8 = undefined;
301301
302302 var h = Sha3_512.init();
303 h.update(block);
303 h.update(&block);
304304 h.final(out[0..]);
305305}
lib/std/crypto/test.zig+2-2
......@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
88 var h: [expected.len / 2]u8 = undefined;
99 Hasher.hash(input, h[0..]);
1010
11 assertEqual(expected, h);
11 assertEqual(expected, &h);
1212}
1313
1414// Assert `expected` == `input` where `input` is a bytestring.
......@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
1818 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
1919 }
2020
21 testing.expectEqualSlices(u8, expected_bytes, input);
21 testing.expectEqualSlices(u8, &expected_bytes, input);
2222}
lib/std/crypto/x25519.zig+18-18
......@@ -63,7 +63,7 @@ pub const X25519 = struct {
6363 var pos: isize = 254;
6464 while (pos >= 0) : (pos -= 1) {
6565 // constant time conditional swap before ladder step
66 const b = scalarBit(e, @intCast(usize, pos));
66 const b = scalarBit(&e, @intCast(usize, pos));
6767 swap ^= b; // xor trick avoids swapping at the end of the loop
6868 Fe.cswap(x2, x3, swap);
6969 Fe.cswap(z2, z3, swap);
......@@ -117,7 +117,7 @@ pub const X25519 = struct {
117117
118118 pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
119119 var base_point = [_]u8{9} ++ [_]u8{0} ** 31;
120 return create(public_key, private_key, base_point);
120 return create(public_key, private_key, &base_point);
121121 }
122122};
123123
......@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
581581 var pk_calculated: [32]u8 = undefined;
582582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
583583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));
585 std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], &sk));
585 std.testing.expect(std.mem.eql(u8, &pk_calculated, &pk_expected));
586586}
587587
588588test "x25519 rfc7748 vector1" {
......@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {
594594 var output: [32]u8 = undefined;
595595
596596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
597 std.testing.expect(std.mem.eql(u8, output, expected_output));
597 std.testing.expect(std.mem.eql(u8, &output, expected_output));
598598}
599599
600600test "x25519 rfc7748 vector2" {
......@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {
606606 var output: [32]u8 = undefined;
607607
608608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
609 std.testing.expect(std.mem.eql(u8, output, expected_output));
609 std.testing.expect(std.mem.eql(u8, &output, expected_output));
610610}
611611
612612test "x25519 rfc7748 one iteration" {
613613 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79".*;
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79";
615615
616616 var k: [32]u8 = initial_value;
617617 var u: [32]u8 = initial_value;
......@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {
619619 var i: usize = 0;
620620 while (i < 1) : (i += 1) {
621621 var output: [32]u8 = undefined;
622 std.testing.expect(X25519.create(output[0..], k, u));
622 std.testing.expect(X25519.create(output[0..], &k, &u));
623623
624624 std.mem.copy(u8, u[0..], k[0..]);
625625 std.mem.copy(u8, k[0..], output[0..]);
......@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {
634634 return error.SkipZigTest;
635635 }
636636
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51".*;
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51";
639639
640 var k: [32]u8 = initial_value;
641 var u: [32]u8 = initial_value;
640 var k: [32]u8 = initial_value.*;
641 var u: [32]u8 = initial_value.*;
642642
643643 var i: usize = 0;
644644 while (i < 1000) : (i += 1) {
645645 var output: [32]u8 = undefined;
646 std.testing.expect(X25519.create(output[0..], k, u));
646 std.testing.expect(X25519.create(output[0..], &k, &u));
647647
648648 std.mem.copy(u8, u[0..], k[0..]);
649649 std.mem.copy(u8, k[0..], output[0..]);
......@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {
657657 return error.SkipZigTest;
658658 }
659659
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24".*;
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24";
662662
663 var k: [32]u8 = initial_value;
664 var u: [32]u8 = initial_value;
663 var k: [32]u8 = initial_value.*;
664 var u: [32]u8 = initial_value.*;
665665
666666 var i: usize = 0;
667667 while (i < 1000000) : (i += 1) {
668668 var output: [32]u8 = undefined;
669 std.testing.expect(X25519.create(output[0..], k, u));
669 std.testing.expect(X25519.create(output[0..], &k, &u));
670670
671671 std.mem.copy(u8, u[0..], k[0..]);
672672 std.mem.copy(u8, k[0..], output[0..]);
lib/std/debug.zig+1-1
......@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {
19161916 return error.InvalidDebugInfo;
19171917 } else
19181918 self.include_dirs[file_entry.dir_index];
1919 const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name });
1919 const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name });
19201920 errdefer self.file_entries.allocator.free(file_name);
19211921 return LineInfo{
19221922 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,
lib/std/elf.zig+1-1
......@@ -381,7 +381,7 @@ pub const Elf = struct {
381381
382382 var magic: [4]u8 = undefined;
383383 try in.readNoEof(magic[0..]);
384 if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat;
384 if (!mem.eql(u8, &magic, "\x7fELF")) return error.InvalidFormat;
385385
386386 elf.is_64 = switch (try in.readByte()) {
387387 1 => false,
lib/std/event/loop.zig+2-2
......@@ -237,7 +237,7 @@ pub const Loop = struct {
237237 var extra_thread_index: usize = 0;
238238 errdefer {
239239 // writing 8 bytes to an eventfd cannot fail
240 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
240 os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
241241 while (extra_thread_index != 0) {
242242 extra_thread_index -= 1;
243243 self.extra_threads[extra_thread_index].wait();
......@@ -684,7 +684,7 @@ pub const Loop = struct {
684684 .linux => {
685685 self.posixFsRequest(&self.os_data.fs_end_request);
686686 // writing 8 bytes to an eventfd cannot fail
687 noasync os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
687 noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
688688 return;
689689 },
690690 .macosx, .freebsd, .netbsd, .dragonfly => {
lib/std/fifo.zig+5-5
......@@ -70,7 +70,7 @@ pub fn LinearFifo(
7070 pub fn init(allocator: *Allocator) Self {
7171 return .{
7272 .allocator = allocator,
73 .buf = [_]T{},
73 .buf = &[_]T{},
7474 .head = 0,
7575 .count = 0,
7676 };
......@@ -143,7 +143,7 @@ pub fn LinearFifo(
143143
144144 /// Returns a writable slice from the 'read' end of the fifo
145145 fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {
146 if (offset > self.count) return [_]T{};
146 if (offset > self.count) return &[_]T{};
147147
148148 var start = self.head + offset;
149149 if (start >= self.buf.len) {
......@@ -223,7 +223,7 @@ pub fn LinearFifo(
223223 /// Returns the first section of writable buffer
224224 /// Note that this may be of length 0
225225 pub fn writableSlice(self: SliceSelfArg, offset: usize) []T {
226 if (offset > self.buf.len) return [_]T{};
226 if (offset > self.buf.len) return &[_]T{};
227227
228228 const tail = self.head + offset + self.count;
229229 if (tail < self.buf.len) {
......@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {
357357 {
358358 var i: usize = 0;
359359 while (i < 5) : (i += 1) {
360 try fifo.write([_]u8{try fifo.peekItem(i)});
360 try fifo.write(&[_]u8{try fifo.peekItem(i)});
361361 }
362362 testing.expectEqual(@as(usize, 10), fifo.readableLength());
363363 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
......@@ -426,7 +426,7 @@ test "LinearFifo" {
426426 };
427427 defer fifo.deinit();
428428
429 try fifo.write([_]T{ 0, 1, 1, 0, 1 });
429 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
430430 testing.expectEqual(@as(usize, 5), fifo.readableLength());
431431
432432 {
lib/std/fmt.zig+15-10
......@@ -451,13 +451,18 @@ pub fn formatType(
451451 },
452452 },
453453 .Array => |info| {
454 if (info.child == u8) {
455 return formatText(value, fmt, options, context, Errors, output);
456 }
457 if (value.len == 0) {
458 return format(context, Errors, output, "[0]{}", @typeName(T.Child));
459 }
460 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
454 const Slice = @Type(builtin.TypeInfo{
455 .Pointer = .{
456 .size = .Slice,
457 .is_const = true,
458 .is_volatile = false,
459 .is_allowzero = false,
460 .alignment = @alignOf(info.child),
461 .child = info.child,
462 .sentinel = null,
463 },
464 });
465 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
461466 },
462467 .Fn => {
463468 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
......@@ -872,8 +877,8 @@ pub fn formatBytes(
872877 }
873878
874879 const buf = switch (radix) {
875 1000 => [_]u8{ suffix, 'B' },
876 1024 => [_]u8{ suffix, 'i', 'B' },
880 1000 => &[_]u8{ suffix, 'B' },
881 1024 => &[_]u8{ suffix, 'i', 'B' },
877882 else => unreachable,
878883 };
879884 return output(context, buf);
......@@ -969,7 +974,7 @@ fn formatIntUnsigned(
969974 if (leftover_padding == 0) break;
970975 }
971976 mem.set(u8, buf[0..index], options.fill);
972 return output(context, buf);
977 return output(context, &buf);
973978 } else {
974979 const padded_buf = buf[index - padding ..];
975980 mem.set(u8, padded_buf[0..padding], options.fill);
lib/std/fs.zig+3-3
......@@ -60,7 +60,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
6060 tmp_path[dirname.len] = path.sep;
6161 while (true) {
6262 try crypto.randomBytes(rand_buf[0..]);
63 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
63 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf);
6464
6565 if (symLink(existing_path, tmp_path)) {
6666 return rename(tmp_path, new_path);
......@@ -226,7 +226,7 @@ pub const AtomicFile = struct {
226226
227227 while (true) {
228228 try crypto.randomBytes(rand_buf[0..]);
229 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf);
229 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], &rand_buf);
230230
231231 const file = File.openWriteNoClobberC(@ptrCast([*:0]u8, &tmp_path_buf), mode) catch |err| switch (err) {
232232 error.PathAlreadyExists => continue,
......@@ -290,7 +290,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {
290290/// have been modified regardless.
291291/// TODO determine if we can remove the allocator requirement from this function
292292pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
293 const resolved_path = try path.resolve(allocator, [_][]const u8{full_path});
293 const resolved_path = try path.resolve(allocator, &[_][]const u8{full_path});
294294 defer allocator.free(resolved_path);
295295
296296 var end_index: usize = resolved_path.len;
lib/std/fs/get_app_data_dir.zig+3-3
......@@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
3131 error.OutOfMemory => return error.OutOfMemory,
3232 };
3333 defer allocator.free(global_dir);
34 return fs.path.join(allocator, [_][]const u8{ global_dir, appname });
34 return fs.path.join(allocator, &[_][]const u8{ global_dir, appname });
3535 },
3636 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
3737 else => return error.AppDataDirUnavailable,
......@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
4242 // TODO look in /etc/passwd
4343 return error.AppDataDirUnavailable;
4444 };
45 return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });
45 return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname });
4646 },
4747 .linux, .freebsd, .netbsd, .dragonfly => {
4848 const home_dir = os.getenv("HOME") orelse {
4949 // TODO look in /etc/passwd
5050 return error.AppDataDirUnavailable;
5151 };
52 return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname });
52 return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
5353 },
5454 else => @compileError("Unsupported OS"),
5555 }
lib/std/fs/path.zig+62-60
......@@ -15,7 +15,9 @@ pub const sep_windows = '\\';
1515pub const sep_posix = '/';
1616pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;
1717
18pub const sep_str = [1]u8{sep};
18pub const sep_str_windows = "\\";
19pub const sep_str_posix = "/";
20pub const sep_str = if (builtin.os == .windows) sep_str_windows else sep_str_posix;
1921
2022pub const delimiter_windows = ';';
2123pub const delimiter_posix = ':';
......@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
101103}
102104
103105test "join" {
104 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
105 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
106 testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
106 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
107 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
108 testJoinWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
107109
108 testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
109 testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
110 testJoinWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
111 testJoinWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
110112
111113 testJoinWindows(
112 [_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
114 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
113115 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
114116 );
115117
116 testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");
117 testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c");
118 testJoinPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
119 testJoinPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c");
118120
119 testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
120 testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
121 testJoinPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
122 testJoinPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
121123
122124 testJoinPosix(
123 [_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
125 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
124126 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
125127 );
126128
127 testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");
128 testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");
129 testJoinPosix(&[_][]const u8{ "a", "/c" }, "a/c");
130 testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
129131}
130132
131133pub fn isAbsolute(path: []const u8) bool {
......@@ -246,7 +248,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
246248 }
247249 const relative_path = WindowsPath{
248250 .kind = WindowsPath.Kind.None,
249 .disk_designator = [_]u8{},
251 .disk_designator = &[_]u8{},
250252 .is_abs = false,
251253 };
252254 if (path.len < "//a/b".len) {
......@@ -255,12 +257,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
255257
256258 inline for ("/\\") |this_sep| {
257259 const two_sep = [_]u8{ this_sep, this_sep };
258 if (mem.startsWith(u8, path, two_sep)) {
260 if (mem.startsWith(u8, path, &two_sep)) {
259261 if (path[2] == this_sep) {
260262 return relative_path;
261263 }
262264
263 var it = mem.tokenize(path, [_]u8{this_sep});
265 var it = mem.tokenize(path, &[_]u8{this_sep});
264266 _ = (it.next() orelse return relative_path);
265267 _ = (it.next() orelse return relative_path);
266268 return WindowsPath{
......@@ -322,8 +324,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
322324 const sep1 = ns1[0];
323325 const sep2 = ns2[0];
324326
325 var it1 = mem.tokenize(ns1, [_]u8{sep1});
326 var it2 = mem.tokenize(ns2, [_]u8{sep2});
327 var it1 = mem.tokenize(ns1, &[_]u8{sep1});
328 var it2 = mem.tokenize(ns2, &[_]u8{sep2});
327329
328330 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
329331 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -343,8 +345,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
343345 const sep1 = p1[0];
344346 const sep2 = p2[0];
345347
346 var it1 = mem.tokenize(p1, [_]u8{sep1});
347 var it2 = mem.tokenize(p2, [_]u8{sep2});
348 var it1 = mem.tokenize(p1, &[_]u8{sep1});
349 var it2 = mem.tokenize(p2, &[_]u8{sep2});
348350
349351 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
350352 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -637,10 +639,10 @@ test "resolve" {
637639 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
638640 cwd[0] = asciiUpper(cwd[0]);
639641 }
640 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));
642 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{"."}), cwd));
641643 } else {
642 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));
643 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));
644 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "a/b/c/", "../../.." }), cwd));
645 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"."}), cwd));
644646 }
645647}
646648
......@@ -653,8 +655,8 @@ test "resolveWindows" {
653655 const cwd = try process.getCwdAlloc(debug.global_allocator);
654656 const parsed_cwd = windowsParsePath(cwd);
655657 {
656 const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
657 const expected = try join(debug.global_allocator, [_][]const u8{
658 const result = testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
659 const expected = try join(debug.global_allocator, &[_][]const u8{
658660 parsed_cwd.disk_designator,
659661 "usr\\local\\lib\\zig\\std\\array_list.zig",
660662 });
......@@ -664,8 +666,8 @@ test "resolveWindows" {
664666 testing.expect(mem.eql(u8, result, expected));
665667 }
666668 {
667 const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });
668 const expected = try join(debug.global_allocator, [_][]const u8{
669 const result = testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" });
670 const expected = try join(debug.global_allocator, &[_][]const u8{
669671 cwd,
670672 "usr\\local\\lib\\zig",
671673 });
......@@ -676,32 +678,32 @@ test "resolveWindows" {
676678 }
677679 }
678680
679 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
680 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
681 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
682 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
683 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
684 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
685 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
686 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//" }), "C:\\"));
687 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
688 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
689 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
690 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
691 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
681 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
682 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
683 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
684 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
685 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
686 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
687 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
688 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//" }), "C:\\"));
689 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
690 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
691 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
692 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
693 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
692694}
693695
694696test "resolvePosix" {
695 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));
696 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
697 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
698 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));
699 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));
700
701 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
702 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
703 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
704 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
697 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c" }), "/a/b/c"));
698 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
699 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
700 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/", "..", ".." }), "/"));
701 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"/a/b/c/"}), "/a/b/c"));
702
703 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
704 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
705 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
706 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
705707}
706708
707709fn testResolveWindows(paths: []const []const u8) []u8 {
......@@ -856,12 +858,12 @@ pub fn basename(path: []const u8) []const u8 {
856858
857859pub fn basenamePosix(path: []const u8) []const u8 {
858860 if (path.len == 0)
859 return [_]u8{};
861 return &[_]u8{};
860862
861863 var end_index: usize = path.len - 1;
862864 while (path[end_index] == '/') {
863865 if (end_index == 0)
864 return [_]u8{};
866 return &[_]u8{};
865867 end_index -= 1;
866868 }
867869 var start_index: usize = end_index;
......@@ -877,19 +879,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
877879
878880pub fn basenameWindows(path: []const u8) []const u8 {
879881 if (path.len == 0)
880 return [_]u8{};
882 return &[_]u8{};
881883
882884 var end_index: usize = path.len - 1;
883885 while (true) {
884886 const byte = path[end_index];
885887 if (byte == '/' or byte == '\\') {
886888 if (end_index == 0)
887 return [_]u8{};
889 return &[_]u8{};
888890 end_index -= 1;
889891 continue;
890892 }
891893 if (byte == ':' and end_index == 1) {
892 return [_]u8{};
894 return &[_]u8{};
893895 }
894896 break;
895897 }
......@@ -971,11 +973,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
971973}
972974
973975pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
974 const resolved_from = try resolveWindows(allocator, [_][]const u8{from});
976 const resolved_from = try resolveWindows(allocator, &[_][]const u8{from});
975977 defer allocator.free(resolved_from);
976978
977979 var clean_up_resolved_to = true;
978 const resolved_to = try resolveWindows(allocator, [_][]const u8{to});
980 const resolved_to = try resolveWindows(allocator, &[_][]const u8{to});
979981 defer if (clean_up_resolved_to) allocator.free(resolved_to);
980982
981983 const parsed_from = windowsParsePath(resolved_from);
......@@ -1044,10 +1046,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
10441046}
10451047
10461048pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
1047 const resolved_from = try resolvePosix(allocator, [_][]const u8{from});
1049 const resolved_from = try resolvePosix(allocator, &[_][]const u8{from});
10481050 defer allocator.free(resolved_from);
10491051
1050 const resolved_to = try resolvePosix(allocator, [_][]const u8{to});
1052 const resolved_to = try resolvePosix(allocator, &[_][]const u8{to});
10511053 defer allocator.free(resolved_to);
10521054
10531055 var from_it = mem.tokenize(resolved_from, "/");
lib/std/hash/cityhash.zig+1-1
......@@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
367367 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
368368 }
369369
370 return @truncate(u32, hash_fn(hashes, 0));
370 return @truncate(u32, hash_fn(&hashes, 0));
371371}
372372
373373fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
lib/std/hash/murmur.zig+1-1
......@@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
299299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300300 }
301301
302 return @truncate(u32, hash_fn(hashes, 0));
302 return @truncate(u32, hash_fn(&hashes, 0));
303303}
304304
305305test "murmur2_32" {
lib/std/hash_map.zig+1-1
......@@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
9494
9595 pub fn init(allocator: *Allocator) Self {
9696 return Self{
97 .entries = [_]Entry{},
97 .entries = &[_]Entry{},
9898 .allocator = allocator,
9999 .size = 0,
100100 .max_distance_from_start_index = 0,
lib/std/http/headers.zig+2-2
......@@ -514,8 +514,8 @@ test "Headers.getIndices" {
514514 try h.append("set-cookie", "y=2", null);
515515
516516 testing.expect(null == h.getIndices("not-present"));
517 testing.expectEqualSlices(usize, [_]usize{0}, h.getIndices("foo").?.toSliceConst());
518 testing.expectEqualSlices(usize, [_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
517 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
518 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
519519}
520520
521521test "Headers.get" {
lib/std/io.zig+1-1
......@@ -1107,7 +1107,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11071107 byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);
11081108 }
11091109
1110 try self.out_stream.write(buffer);
1110 try self.out_stream.write(&buffer);
11111111 }
11121112
11131113 /// Serializes the passed value into the stream
lib/std/io/out_stream.zig+5-5
......@@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type {
5656 pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {
5757 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
5858 mem.writeIntNative(T, &bytes, value);
59 return self.writeFn(self, bytes);
59 return self.writeFn(self, &bytes);
6060 }
6161
6262 /// Write a foreign-endian integer.
6363 pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {
6464 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
6565 mem.writeIntForeign(T, &bytes, value);
66 return self.writeFn(self, bytes);
66 return self.writeFn(self, &bytes);
6767 }
6868
6969 pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {
7070 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
7171 mem.writeIntLittle(T, &bytes, value);
72 return self.writeFn(self, bytes);
72 return self.writeFn(self, &bytes);
7373 }
7474
7575 pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {
7676 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
7777 mem.writeIntBig(T, &bytes, value);
78 return self.writeFn(self, bytes);
78 return self.writeFn(self, &bytes);
7979 }
8080
8181 pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
8282 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
8383 mem.writeInt(T, &bytes, value, endian);
84 return self.writeFn(self, bytes);
84 return self.writeFn(self, &bytes);
8585 }
8686 };
8787}
lib/std/io/test.zig+4-4
......@@ -55,7 +55,7 @@ test "write a file, read it, then delete it" {
5555 defer allocator.free(contents);
5656
5757 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
58 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
58 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
5959 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
6060 }
6161 try fs.deleteFile(tmp_file_name);
......@@ -77,7 +77,7 @@ test "BufferOutStream" {
7777
7878test "SliceInStream" {
7979 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
80 var ss = io.SliceInStream.init(bytes);
80 var ss = io.SliceInStream.init(&bytes);
8181
8282 var dest: [4]u8 = undefined;
8383
......@@ -95,7 +95,7 @@ test "SliceInStream" {
9595
9696test "PeekStream" {
9797 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
98 var ss = io.SliceInStream.init(bytes);
98 var ss = io.SliceInStream.init(&bytes);
9999 var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
100100
101101 var dest: [4]u8 = undefined;
......@@ -614,7 +614,7 @@ test "File seek ops" {
614614 fs.deleteFile(tmp_file_name) catch {};
615615 }
616616
617 try file.write([_]u8{0x55} ** 8192);
617 try file.write(&([_]u8{0x55} ** 8192));
618618
619619 // Seek to the end
620620 try file.seekFromEnd(0);
lib/std/mem.zig+52-76
......@@ -624,23 +624,23 @@ test "comptime read/write int" {
624624}
625625
626626test "readIntBig and readIntLittle" {
627 testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);
628 testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);
627 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
628 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
629629
630 testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);
631 testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);
630 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
631 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
632632
633 testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);
634 testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);
633 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
634 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
635635
636 testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
637 testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
636 testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
637 testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
638638
639 testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1);
640 testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);
639 testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
640 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
641641
642 testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);
643 testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);
642 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
643 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
644644}
645645
646646/// Writes an integer to memory, storing it in twos-complement.
......@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {
749749 var buf9: [9]u8 = undefined;
750750
751751 writeIntBig(u0, &buf0, 0x0);
752 testing.expect(eql(u8, buf0[0..], [_]u8{}));
752 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
753753 writeIntLittle(u0, &buf0, 0x0);
754 testing.expect(eql(u8, buf0[0..], [_]u8{}));
754 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
755755
756756 writeIntBig(u8, &buf1, 0x12);
757 testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));
757 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
758758 writeIntLittle(u8, &buf1, 0x34);
759 testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));
759 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
760760
761761 writeIntBig(u16, &buf2, 0x1234);
762 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));
762 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
763763 writeIntLittle(u16, &buf2, 0x5678);
764 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));
764 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
765765
766766 writeIntBig(u72, &buf9, 0x123456789abcdef024);
767 testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
767 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
768768 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
769 testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
769 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
770770
771771 writeIntBig(i8, &buf1, -1);
772 testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));
772 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
773773 writeIntLittle(i8, &buf1, -2);
774 testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));
774 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
775775
776776 writeIntBig(i16, &buf2, -3);
777 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));
777 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
778778 writeIntLittle(i16, &buf2, -4);
779 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));
779 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
780780}
781781
782782/// Returns an iterator that iterates over the slices of `buffer` that are not
......@@ -1004,9 +1004,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
10041004test "mem.join" {
10051005 var buf: [1024]u8 = undefined;
10061006 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1007 testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c"));
1008 testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a"));
1009 testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
1007 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c"));
1008 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a"));
1009 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
10101010}
10111011
10121012/// Copies each T from slices into a new slice that exactly holds all the elements.
......@@ -1037,13 +1037,13 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T
10371037test "concat" {
10381038 var buf: [1024]u8 = undefined;
10391039 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1040 testing.expect(eql(u8, try concat(a, u8, [_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
1041 testing.expect(eql(u32, try concat(a, u32, [_][]const u32{
1042 [_]u32{ 0, 1 },
1043 [_]u32{ 2, 3, 4 },
1044 [_]u32{},
1045 [_]u32{5},
1046 }), [_]u32{ 0, 1, 2, 3, 4, 5 }));
1040 testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
1041 testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{
1042 &[_]u32{ 0, 1 },
1043 &[_]u32{ 2, 3, 4 },
1044 &[_]u32{},
1045 &[_]u32{5},
1046 }), &[_]u32{ 0, 1, 2, 3, 4, 5 }));
10471047}
10481048
10491049test "testStringEquality" {
......@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {
11111111 var bytes: [8]u8 = undefined;
11121112
11131113 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1114 testing.expect(eql(u8, bytes, [_]u8{
1114 testing.expect(eql(u8, &bytes, &[_]u8{
11151115 0x00, 0x00, 0x00, 0x00,
11161116 0x00, 0x00, 0x00, 0x00,
11171117 }));
11181118
11191119 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1120 testing.expect(eql(u8, bytes, [_]u8{
1120 testing.expect(eql(u8, &bytes, &[_]u8{
11211121 0x00, 0x00, 0x00, 0x00,
11221122 0x00, 0x00, 0x00, 0x00,
11231123 }));
11241124
11251125 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1126 testing.expect(eql(u8, bytes, [_]u8{
1126 testing.expect(eql(u8, &bytes, &[_]u8{
11271127 0x12,
11281128 0x34,
11291129 0x56,
......@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {
11351135 }));
11361136
11371137 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1138 testing.expect(eql(u8, bytes, [_]u8{
1138 testing.expect(eql(u8, &bytes, &[_]u8{
11391139 0x12,
11401140 0x34,
11411141 0x56,
......@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {
11471147 }));
11481148
11491149 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1150 testing.expect(eql(u8, bytes, [_]u8{
1150 testing.expect(eql(u8, &bytes, &[_]u8{
11511151 0x00,
11521152 0x00,
11531153 0x00,
......@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {
11591159 }));
11601160
11611161 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1162 testing.expect(eql(u8, bytes, [_]u8{
1162 testing.expect(eql(u8, &bytes, &[_]u8{
11631163 0x12,
11641164 0x34,
11651165 0x56,
......@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {
11711171 }));
11721172
11731173 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1174 testing.expect(eql(u8, bytes, [_]u8{
1174 testing.expect(eql(u8, &bytes, &[_]u8{
11751175 0x00,
11761176 0x00,
11771177 0x00,
......@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {
11831183 }));
11841184
11851185 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1186 testing.expect(eql(u8, bytes, [_]u8{
1186 testing.expect(eql(u8, &bytes, &[_]u8{
11871187 0x34,
11881188 0x12,
11891189 0x00,
......@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {
12351235}
12361236
12371237test "reverse" {
1238 var arr = [_]i32{
1239 5,
1240 3,
1241 1,
1242 2,
1243 4,
1244 };
1238 var arr = [_]i32{ 5, 3, 1, 2, 4 };
12451239 reverse(i32, arr[0..]);
12461240
1247 testing.expect(eql(i32, arr, [_]i32{
1248 4,
1249 2,
1250 1,
1251 3,
1252 5,
1253 }));
1241 testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
12541242}
12551243
12561244/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
......@@ -1262,22 +1250,10 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
12621250}
12631251
12641252test "rotate" {
1265 var arr = [_]i32{
1266 5,
1267 3,
1268 1,
1269 2,
1270 4,
1271 };
1253 var arr = [_]i32{ 5, 3, 1, 2, 4 };
12721254 rotate(i32, arr[0..], 2);
12731255
1274 testing.expect(eql(i32, arr, [_]i32{
1275 1,
1276 2,
1277 4,
1278 5,
1279 3,
1280 }));
1256 testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
12811257}
12821258
12831259/// Converts a little-endian integer to host endianness.
......@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
13941370test "toBytes" {
13951371 var my_bytes = toBytes(@as(u32, 0x12345678));
13961372 switch (builtin.endian) {
1397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
1398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
1373 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
1374 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
13991375 }
14001376
14011377 my_bytes[0] = '\x99';
14021378 switch (builtin.endian) {
1403 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x99\x34\x56\x78")),
1404 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x99\x56\x34\x12")),
1379 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
1380 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
14051381 }
14061382}
14071383
......@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
14951471test "subArrayPtr" {
14961472 const a1: [6]u8 = "abcdef".*;
14971473 const sub1 = subArrayPtr(&a1, 2, 3);
1498 testing.expect(eql(u8, sub1.*, "cde"));
1474 testing.expect(eql(u8, sub1, "cde"));
14991475
15001476 var a2: [6]u8 = "abcdef".*;
15011477 var sub2 = subArrayPtr(&a2, 2, 3);
15021478
15031479 testing.expect(eql(u8, sub2, "cde"));
15041480 sub2[1] = 'X';
1505 testing.expect(eql(u8, a2, "abcXef"));
1481 testing.expect(eql(u8, &a2, "abcXef"));
15061482}
15071483
15081484/// Round an address up to the nearest aligned address
lib/std/meta/trait.zig+1-1
......@@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
4646 }
4747 };
4848
49 const isVector = multiTrait([_]TraitFn{
49 const isVector = multiTrait(&[_]TraitFn{
5050 hasFn("add"),
5151 hasField("x"),
5252 hasField("y"),
lib/std/net.zig+4-4
......@@ -291,7 +291,7 @@ pub const Address = extern union {
291291 },
292292 os.AF_INET6 => {
293293 const port = mem.bigToNative(u16, self.in6.port);
294 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
294 if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
295295 try std.fmt.format(
296296 context,
297297 Errors,
......@@ -339,7 +339,7 @@ pub const Address = extern union {
339339 unreachable;
340340 }
341341
342 try std.fmt.format(context, Errors, output, "{}", self.un.path);
342 try std.fmt.format(context, Errors, output, "{}", &self.un.path);
343343 },
344344 else => unreachable,
345345 }
......@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(
894894 }
895895
896896 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
897 [_]u8{}
897 &[_]u8{}
898898 else
899899 rc.search.toSliceConst();
900900
......@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(
959959
960960 for (afrrs) |afrr| {
961961 if (family != afrr.af) {
962 const len = os.res_mkquery(0, name, 1, afrr.rr, [_]u8{}, null, &qbuf[nq]);
962 const len = os.res_mkquery(0, name, 1, afrr.rr, &[_]u8{}, null, &qbuf[nq]);
963963 qp[nq] = qbuf[nq][0..len];
964964 nq += 1;
965965 }
lib/std/os/test.zig+1-1
......@@ -137,7 +137,7 @@ test "getrandom" {
137137 try os.getrandom(&buf_b);
138138 // If this test fails the chance is significantly higher that there is a bug than
139139 // that two sets of 50 bytes were equal.
140 expect(!mem.eql(u8, buf_a, buf_b));
140 expect(!mem.eql(u8, &buf_a, &buf_b));
141141}
142142
143143test "getcwd" {
lib/std/packed_int_array.zig+3-21
......@@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
201201 ///Return the Int stored at index
202202 pub fn get(self: Self, index: usize) Int {
203203 debug.assert(index < int_count);
204 return Io.get(self.bytes, index, 0);
204 return Io.get(&self.bytes, index, 0);
205205 }
206206
207207 ///Copy int into the array at index
......@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
528528test "PackedInt(Array/Slice)Endian" {
529529 {
530530 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
531 var packed_array_be = PackedArrayBe.init([_]u4{
532 0,
533 1,
534 2,
535 3,
536 4,
537 5,
538 6,
539 7,
540 });
531 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
541532 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542533 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543534
......@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {
563554
564555 {
565556 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
566 var packed_array_be = PackedArrayBe.init([_]u11{
567 0,
568 1,
569 2,
570 3,
571 4,
572 5,
573 6,
574 7,
575 });
557 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
576558 testing.expect(packed_array_be.bytes[0] == 0b00000000);
577559 testing.expect(packed_array_be.bytes[1] == 0b00000000);
578560 testing.expect(packed_array_be.bytes[2] == 0b00000100);
lib/std/priority_queue.zig+1-1
......@@ -22,7 +22,7 @@ pub fn PriorityQueue(comptime T: type) type {
2222 /// `fn lessThan(a: T, b: T) bool { return a < b; }`
2323 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
2424 return Self{
25 .items = [_]T{},
25 .items = &[_]T{},
2626 .len = 0,
2727 .allocator = allocator,
2828 .compareFn = compareFn,
lib/std/process.zig+8-8
......@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
473473}
474474
475475test "windows arg parsing" {
476 testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine("a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
476 testWindowsCmdLine("a b\tc d", &[_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", &[_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" });
482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{
484484 ".\\..\\zig-cache\\build",
485485 "bin\\zig.exe",
486486 ".\\..",
lib/std/rand.zig+1-1
......@@ -54,7 +54,7 @@ pub const Random = struct {
5454 // use LE instead of native endian for better portability maybe?
5555 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
5656 // TODO: document the endian portability of this library.
57 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, rand_bytes);
57 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
5858 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);
5959 return @bitCast(T, unsigned_result);
6060 }
lib/std/segmented_list.zig+4-8
......@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
112112 .allocator = allocator,
113113 .len = 0,
114114 .prealloc_segment = undefined,
115 .dynamic_segments = [_][*]T{},
115 .dynamic_segments = &[_][*]T{},
116116 };
117117 }
118118
......@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
192192 const len = @intCast(ShelfIndex, self.dynamic_segments.len);
193193 self.freeShelves(len, 0);
194194 self.allocator.free(self.dynamic_segments);
195 self.dynamic_segments = [_][*]T{};
195 self.dynamic_segments = &[_][*]T{};
196196 return;
197197 }
198198
......@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
385385 testing.expect(list.pop().? == 100);
386386 testing.expect(list.len == 99);
387387
388 try list.pushMany([_]i32{
389 1,
390 2,
391 3,
392 });
388 try list.pushMany(&[_]i32{ 1, 2, 3 });
393389 testing.expect(list.len == 102);
394390 testing.expect(list.pop().? == 3);
395391 testing.expect(list.pop().? == 2);
396392 testing.expect(list.pop().? == 1);
397393 testing.expect(list.len == 99);
398394
399 try list.pushMany([_]i32{});
395 try list.pushMany(&[_]i32{});
400396 testing.expect(list.len == 99);
401397
402398 var i: i32 = 99;
lib/std/sort.zig+43-43
......@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
10431043
10441044test "std.sort" {
10451045 const u8cases = [_][]const []const u8{
1046 [_][]const u8{
1046 &[_][]const u8{
10471047 "",
10481048 "",
10491049 },
1050 [_][]const u8{
1050 &[_][]const u8{
10511051 "a",
10521052 "a",
10531053 },
1054 [_][]const u8{
1054 &[_][]const u8{
10551055 "az",
10561056 "az",
10571057 },
1058 [_][]const u8{
1058 &[_][]const u8{
10591059 "za",
10601060 "az",
10611061 },
1062 [_][]const u8{
1062 &[_][]const u8{
10631063 "asdf",
10641064 "adfs",
10651065 },
1066 [_][]const u8{
1066 &[_][]const u8{
10671067 "one",
10681068 "eno",
10691069 },
......@@ -1078,29 +1078,29 @@ test "std.sort" {
10781078 }
10791079
10801080 const i32cases = [_][]const []const i32{
1081 [_][]const i32{
1082 [_]i32{},
1083 [_]i32{},
1081 &[_][]const i32{
1082 &[_]i32{},
1083 &[_]i32{},
10841084 },
1085 [_][]const i32{
1086 [_]i32{1},
1087 [_]i32{1},
1085 &[_][]const i32{
1086 &[_]i32{1},
1087 &[_]i32{1},
10881088 },
1089 [_][]const i32{
1090 [_]i32{ 0, 1 },
1091 [_]i32{ 0, 1 },
1089 &[_][]const i32{
1090 &[_]i32{ 0, 1 },
1091 &[_]i32{ 0, 1 },
10921092 },
1093 [_][]const i32{
1094 [_]i32{ 1, 0 },
1095 [_]i32{ 0, 1 },
1093 &[_][]const i32{
1094 &[_]i32{ 1, 0 },
1095 &[_]i32{ 0, 1 },
10961096 },
1097 [_][]const i32{
1098 [_]i32{ 1, -1, 0 },
1099 [_]i32{ -1, 0, 1 },
1097 &[_][]const i32{
1098 &[_]i32{ 1, -1, 0 },
1099 &[_]i32{ -1, 0, 1 },
11001100 },
1101 [_][]const i32{
1102 [_]i32{ 2, 1, 3 },
1103 [_]i32{ 1, 2, 3 },
1101 &[_][]const i32{
1102 &[_]i32{ 2, 1, 3 },
1103 &[_]i32{ 1, 2, 3 },
11041104 },
11051105 };
11061106
......@@ -1115,29 +1115,29 @@ test "std.sort" {
11151115
11161116test "std.sort descending" {
11171117 const rev_cases = [_][]const []const i32{
1118 [_][]const i32{
1119 [_]i32{},
1120 [_]i32{},
1118 &[_][]const i32{
1119 &[_]i32{},
1120 &[_]i32{},
11211121 },
1122 [_][]const i32{
1123 [_]i32{1},
1124 [_]i32{1},
1122 &[_][]const i32{
1123 &[_]i32{1},
1124 &[_]i32{1},
11251125 },
1126 [_][]const i32{
1127 [_]i32{ 0, 1 },
1128 [_]i32{ 1, 0 },
1126 &[_][]const i32{
1127 &[_]i32{ 0, 1 },
1128 &[_]i32{ 1, 0 },
11291129 },
1130 [_][]const i32{
1131 [_]i32{ 1, 0 },
1132 [_]i32{ 1, 0 },
1130 &[_][]const i32{
1131 &[_]i32{ 1, 0 },
1132 &[_]i32{ 1, 0 },
11331133 },
1134 [_][]const i32{
1135 [_]i32{ 1, -1, 0 },
1136 [_]i32{ 1, 0, -1 },
1134 &[_][]const i32{
1135 &[_]i32{ 1, -1, 0 },
1136 &[_]i32{ 1, 0, -1 },
11371137 },
1138 [_][]const i32{
1139 [_]i32{ 2, 1, 3 },
1140 [_]i32{ 3, 2, 1 },
1138 &[_][]const i32{
1139 &[_]i32{ 2, 1, 3 },
1140 &[_]i32{ 3, 2, 1 },
11411141 },
11421142 };
11431143
......@@ -1154,7 +1154,7 @@ test "another sort case" {
11541154 var arr = [_]i32{ 5, 3, 1, 2, 4 };
11551155 sort(i32, arr[0..], asc(i32));
11561156
1157 testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 }));
1157 testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
11581158}
11591159
11601160test "sort fuzz testing" {
lib/std/unicode.zig+6-6
......@@ -499,14 +499,14 @@ test "utf16leToUtf8" {
499499 {
500500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
501501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
503503 testing.expect(mem.eql(u8, utf8, "Aa"));
504504 }
505505
506506 {
507507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
508508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
510510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
511511 }
512512
......@@ -514,7 +514,7 @@ test "utf16leToUtf8" {
514514 // the values just outside the surrogate half range
515515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
516516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
518518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
519519 }
520520
......@@ -522,7 +522,7 @@ test "utf16leToUtf8" {
522522 // smallest surrogate pair
523523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
524524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
526526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
527527 }
528528
......@@ -530,14 +530,14 @@ test "utf16leToUtf8" {
530530 // largest surrogate pair
531531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
532532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
534534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
535535 }
536536
537537 {
538538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
539539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
541541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
542542 }
543543}
lib/std/zig/tokenizer.zig+61-61
......@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {
13131313};
13141314
13151315test "tokenizer" {
1316 testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});
1316 testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test});
13171317}
13181318
13191319test "tokenizer - unknown length pointer and then c pointer" {
13201320 testTokenize(
13211321 \\[*]u8
13221322 \\[*c]u8
1323 , [_]Token.Id{
1323 , &[_]Token.Id{
13241324 Token.Id.LBracket,
13251325 Token.Id.Asterisk,
13261326 Token.Id.RBracket,
......@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {
13361336test "tokenizer - char literal with hex escape" {
13371337 testTokenize(
13381338 \\'\x1b'
1339 , [_]Token.Id{.CharLiteral});
1339 , &[_]Token.Id{.CharLiteral});
13401340 testTokenize(
13411341 \\'\x1'
1342 , [_]Token.Id{ .Invalid, .Invalid });
1342 , &[_]Token.Id{ .Invalid, .Invalid });
13431343}
13441344
13451345test "tokenizer - char literal with unicode escapes" {
13461346 // Valid unicode escapes
13471347 testTokenize(
13481348 \\'\u{3}'
1349 , [_]Token.Id{.CharLiteral});
1349 , &[_]Token.Id{.CharLiteral});
13501350 testTokenize(
13511351 \\'\u{01}'
1352 , [_]Token.Id{.CharLiteral});
1352 , &[_]Token.Id{.CharLiteral});
13531353 testTokenize(
13541354 \\'\u{2a}'
1355 , [_]Token.Id{.CharLiteral});
1355 , &[_]Token.Id{.CharLiteral});
13561356 testTokenize(
13571357 \\'\u{3f9}'
1358 , [_]Token.Id{.CharLiteral});
1358 , &[_]Token.Id{.CharLiteral});
13591359 testTokenize(
13601360 \\'\u{6E09aBc1523}'
1361 , [_]Token.Id{.CharLiteral});
1361 , &[_]Token.Id{.CharLiteral});
13621362 testTokenize(
13631363 \\"\u{440}"
1364 , [_]Token.Id{.StringLiteral});
1364 , &[_]Token.Id{.StringLiteral});
13651365
13661366 // Invalid unicode escapes
13671367 testTokenize(
13681368 \\'\u'
1369 , [_]Token.Id{.Invalid});
1369 , &[_]Token.Id{.Invalid});
13701370 testTokenize(
13711371 \\'\u{{'
1372 , [_]Token.Id{ .Invalid, .Invalid });
1372 , &[_]Token.Id{ .Invalid, .Invalid });
13731373 testTokenize(
13741374 \\'\u{}'
1375 , [_]Token.Id{ .Invalid, .Invalid });
1375 , &[_]Token.Id{ .Invalid, .Invalid });
13761376 testTokenize(
13771377 \\'\u{s}'
1378 , [_]Token.Id{ .Invalid, .Invalid });
1378 , &[_]Token.Id{ .Invalid, .Invalid });
13791379 testTokenize(
13801380 \\'\u{2z}'
1381 , [_]Token.Id{ .Invalid, .Invalid });
1381 , &[_]Token.Id{ .Invalid, .Invalid });
13821382 testTokenize(
13831383 \\'\u{4a'
1384 , [_]Token.Id{.Invalid});
1384 , &[_]Token.Id{.Invalid});
13851385
13861386 // Test old-style unicode literals
13871387 testTokenize(
13881388 \\'\u0333'
1389 , [_]Token.Id{ .Invalid, .Invalid });
1389 , &[_]Token.Id{ .Invalid, .Invalid });
13901390 testTokenize(
13911391 \\'\U0333'
1392 , [_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
1392 , &[_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
13931393}
13941394
13951395test "tokenizer - char literal with unicode code point" {
13961396 testTokenize(
13971397 \\'💩'
1398 , [_]Token.Id{.CharLiteral});
1398 , &[_]Token.Id{.CharLiteral});
13991399}
14001400
14011401test "tokenizer - float literal e exponent" {
1402 testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{
1402 testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{
14031403 Token.Id.Identifier,
14041404 Token.Id.Equal,
14051405 Token.Id.FloatLiteral,
......@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {
14081408}
14091409
14101410test "tokenizer - float literal p exponent" {
1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{
1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{
14121412 Token.Id.Identifier,
14131413 Token.Id.Equal,
14141414 Token.Id.FloatLiteral,
......@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {
14171417}
14181418
14191419test "tokenizer - chars" {
1420 testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});
1420 testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral});
14211421}
14221422
14231423test "tokenizer - invalid token characters" {
1424 testTokenize("#", [_]Token.Id{Token.Id.Invalid});
1425 testTokenize("`", [_]Token.Id{Token.Id.Invalid});
1426 testTokenize("'c", [_]Token.Id{Token.Id.Invalid});
1427 testTokenize("'", [_]Token.Id{Token.Id.Invalid});
1428 testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
1424 testTokenize("#", &[_]Token.Id{Token.Id.Invalid});
1425 testTokenize("`", &[_]Token.Id{Token.Id.Invalid});
1426 testTokenize("'c", &[_]Token.Id{Token.Id.Invalid});
1427 testTokenize("'", &[_]Token.Id{Token.Id.Invalid});
1428 testTokenize("''", &[_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
14291429}
14301430
14311431test "tokenizer - invalid literal/comment characters" {
1432 testTokenize("\"\x00\"", [_]Token.Id{
1432 testTokenize("\"\x00\"", &[_]Token.Id{
14331433 Token.Id.StringLiteral,
14341434 Token.Id.Invalid,
14351435 });
1436 testTokenize("//\x00", [_]Token.Id{
1436 testTokenize("//\x00", &[_]Token.Id{
14371437 Token.Id.LineComment,
14381438 Token.Id.Invalid,
14391439 });
1440 testTokenize("//\x1f", [_]Token.Id{
1440 testTokenize("//\x1f", &[_]Token.Id{
14411441 Token.Id.LineComment,
14421442 Token.Id.Invalid,
14431443 });
1444 testTokenize("//\x7f", [_]Token.Id{
1444 testTokenize("//\x7f", &[_]Token.Id{
14451445 Token.Id.LineComment,
14461446 Token.Id.Invalid,
14471447 });
14481448}
14491449
14501450test "tokenizer - utf8" {
1451 testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment});
1452 testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment});
1451 testTokenize("//\xc2\x80", &[_]Token.Id{Token.Id.LineComment});
1452 testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{Token.Id.LineComment});
14531453}
14541454
14551455test "tokenizer - invalid utf8" {
1456 testTokenize("//\x80", [_]Token.Id{
1456 testTokenize("//\x80", &[_]Token.Id{
14571457 Token.Id.LineComment,
14581458 Token.Id.Invalid,
14591459 });
1460 testTokenize("//\xbf", [_]Token.Id{
1460 testTokenize("//\xbf", &[_]Token.Id{
14611461 Token.Id.LineComment,
14621462 Token.Id.Invalid,
14631463 });
1464 testTokenize("//\xf8", [_]Token.Id{
1464 testTokenize("//\xf8", &[_]Token.Id{
14651465 Token.Id.LineComment,
14661466 Token.Id.Invalid,
14671467 });
1468 testTokenize("//\xff", [_]Token.Id{
1468 testTokenize("//\xff", &[_]Token.Id{
14691469 Token.Id.LineComment,
14701470 Token.Id.Invalid,
14711471 });
1472 testTokenize("//\xc2\xc0", [_]Token.Id{
1472 testTokenize("//\xc2\xc0", &[_]Token.Id{
14731473 Token.Id.LineComment,
14741474 Token.Id.Invalid,
14751475 });
1476 testTokenize("//\xe0", [_]Token.Id{
1476 testTokenize("//\xe0", &[_]Token.Id{
14771477 Token.Id.LineComment,
14781478 Token.Id.Invalid,
14791479 });
1480 testTokenize("//\xf0", [_]Token.Id{
1480 testTokenize("//\xf0", &[_]Token.Id{
14811481 Token.Id.LineComment,
14821482 Token.Id.Invalid,
14831483 });
1484 testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{
1484 testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{
14851485 Token.Id.LineComment,
14861486 Token.Id.Invalid,
14871487 });
......@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {
14891489
14901490test "tokenizer - illegal unicode codepoints" {
14911491 // unicode newline characters.U+0085, U+2028, U+2029
1492 testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});
1493 testTokenize("//\xc2\x85", [_]Token.Id{
1492 testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment});
1493 testTokenize("//\xc2\x85", &[_]Token.Id{
14941494 Token.Id.LineComment,
14951495 Token.Id.Invalid,
14961496 });
1497 testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});
1498 testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});
1499 testTokenize("//\xe2\x80\xa8", [_]Token.Id{
1497 testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment});
1498 testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment});
1499 testTokenize("//\xe2\x80\xa8", &[_]Token.Id{
15001500 Token.Id.LineComment,
15011501 Token.Id.Invalid,
15021502 });
1503 testTokenize("//\xe2\x80\xa9", [_]Token.Id{
1503 testTokenize("//\xe2\x80\xa9", &[_]Token.Id{
15041504 Token.Id.LineComment,
15051505 Token.Id.Invalid,
15061506 });
1507 testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});
1507 testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment});
15081508}
15091509
15101510test "tokenizer - string identifier and builtin fns" {
15111511 testTokenize(
15121512 \\const @"if" = @import("std");
1513 , [_]Token.Id{
1513 , &[_]Token.Id{
15141514 Token.Id.Keyword_const,
15151515 Token.Id.Identifier,
15161516 Token.Id.Equal,
......@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {
15231523}
15241524
15251525test "tokenizer - pipe and then invalid" {
1526 testTokenize("||=", [_]Token.Id{
1526 testTokenize("||=", &[_]Token.Id{
15271527 Token.Id.PipePipe,
15281528 Token.Id.Equal,
15291529 });
15301530}
15311531
15321532test "tokenizer - line comment and doc comment" {
1533 testTokenize("//", [_]Token.Id{Token.Id.LineComment});
1534 testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});
1535 testTokenize("// /", [_]Token.Id{Token.Id.LineComment});
1536 testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});
1537 testTokenize("///", [_]Token.Id{Token.Id.DocComment});
1538 testTokenize("////", [_]Token.Id{Token.Id.LineComment});
1539 testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment});
1540 testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment});
1533 testTokenize("//", &[_]Token.Id{Token.Id.LineComment});
1534 testTokenize("// a / b", &[_]Token.Id{Token.Id.LineComment});
1535 testTokenize("// /", &[_]Token.Id{Token.Id.LineComment});
1536 testTokenize("/// a", &[_]Token.Id{Token.Id.DocComment});
1537 testTokenize("///", &[_]Token.Id{Token.Id.DocComment});
1538 testTokenize("////", &[_]Token.Id{Token.Id.LineComment});
1539 testTokenize("//!", &[_]Token.Id{Token.Id.ContainerDocComment});
1540 testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment});
15411541}
15421542
15431543test "tokenizer - line comment followed by identifier" {
......@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {
15451545 \\ Unexpected,
15461546 \\ // another
15471547 \\ Another,
1548 , [_]Token.Id{
1548 , &[_]Token.Id{
15491549 Token.Id.Identifier,
15501550 Token.Id.Comma,
15511551 Token.Id.LineComment,
......@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {
15551555}
15561556
15571557test "tokenizer - UTF-8 BOM is recognized and skipped" {
1558 testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{
1558 testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{
15591559 Token.Id.Identifier,
15601560 Token.Id.Semicolon,
15611561 });
15621562}
15631563
15641564test "correctly parse pointer assignment" {
1565 testTokenize("b.*=3;\n", [_]Token.Id{
1565 testTokenize("b.*=3;\n", &[_]Token.Id{
15661566 Token.Id.Identifier,
15671567 Token.Id.PeriodAsterisk,
15681568 Token.Id.Equal,
src-self-hosted/dep_tokenizer.zig+2-2
......@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
992992
993993fn printCharValues(out: var, bytes: []const u8) !void {
994994 for (bytes) |b| {
995 try out.write([_]u8{printable_char_tab[b]});
995 try out.write(&[_]u8{printable_char_tab[b]});
996996 }
997997}
998998
......@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
10011001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
10021002 } else {
10031003 try out.write("'");
1004 try out.write([_]u8{printable_char_tab[char]});
1004 try out.write(&[_]u8{printable_char_tab[char]});
10051005 try out.write("'");
10061006 }
10071007}
src-self-hosted/main.zig+1-1
......@@ -521,7 +521,7 @@ pub const usage_fmt =
521521pub const args_fmt_spec = [_]Flag{
522522 Flag.Bool("--help"),
523523 Flag.Bool("--check"),
524 Flag.Option("--color", [_][]const u8{
524 Flag.Option("--color", &[_][]const u8{
525525 "auto",
526526 "off",
527527 "on",
src-self-hosted/stage1.zig+2-2
......@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
170170 stderr = &stderr_file.outStream().stream;
171171
172172 const args = args_list.toSliceConst();
173 var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]);
173 var flags = try Args.parse(allocator, &self_hosted_main.args_fmt_spec, args[2..]);
174174 defer flags.deinit();
175175
176176 if (flags.present("help")) {
......@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
286286
287287 while (try dir_it.next()) |entry| {
288288 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {
289 const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
289 const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name });
290290 try fmtPath(fmt, full_path, check_mode);
291291 }
292292 }
src/all_types.hpp+3
......@@ -2650,6 +2650,9 @@ struct IrInstruction {
26502650 IrInstructionId id;
26512651 // true if this instruction was generated by zig and not from user code
26522652 bool is_gen;
2653
2654 // for debugging purposes, this is useful to call to inspect the instruction
2655 void dump();
26532656};
26542657
26552658struct IrInstructionDeclVarSrc {
src/ir.cpp+171-265
......@@ -218,7 +218,8 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
218218static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
219219 ZigType *dest_type);
220220static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
221 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime);
221 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
222 bool non_null_comptime, bool allow_discard);
222223static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
223224 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
224225 bool non_null_comptime, bool allow_discard);
......@@ -10417,9 +10418,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1041710418 }
1041810419
1041910420 if (cur_type->id == ZigTypeIdErrorSet) {
10420 if (prev_type->id == ZigTypeIdArray) {
10421 convert_to_const_slice = true;
10422 }
1042310421 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
1042410422 return ira->codegen->builtin_types.entry_invalid;
1042510423 }
......@@ -10754,25 +10752,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1075410752 }
1075510753 }
1075610754
10757 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
10758 cur_type->data.array.len != prev_type->data.array.len &&
10759 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
10760 source_node, false).id == ConstCastResultIdOk)
10761 {
10762 convert_to_const_slice = true;
10763 prev_inst = cur_inst;
10764 continue;
10765 }
10766
10767 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
10768 cur_type->data.array.len != prev_type->data.array.len &&
10769 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
10770 source_node, false).id == ConstCastResultIdOk)
10771 {
10772 convert_to_const_slice = true;
10773 continue;
10774 }
10775
1077610755 // *[N]T to []T
1077710756 // *[N]T to E![]T
1077810757 if (cur_type->id == ZigTypeIdPointer &&
......@@ -10820,19 +10799,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1082010799 }
1082110800 }
1082210801
10823 // [N]T to []T
10824 if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
10825 (prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
10826 cur_type->data.array.len == 0) &&
10827 types_match_const_cast_only(ira,
10828 prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
10829 cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
10830 {
10831 convert_to_const_slice = false;
10832 continue;
10833 }
10834
10835
1083610802 // *[N]T and *[M]T
1083710803 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
1083810804 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
......@@ -10876,19 +10842,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1087610842 continue;
1087710843 }
1087810844
10879 // [N]T to []T
10880 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
10881 (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
10882 prev_type->data.array.len == 0) &&
10883 types_match_const_cast_only(ira,
10884 cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
10885 prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
10886 {
10887 prev_inst = cur_inst;
10888 convert_to_const_slice = false;
10889 continue;
10890 }
10891
1089210845 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
1089310846 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
1089410847 {
......@@ -10924,18 +10877,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1092410877 free(errors);
1092510878
1092610879 if (convert_to_const_slice) {
10927 if (prev_inst->value->type->id == ZigTypeIdArray) {
10928 ZigType *ptr_type = get_pointer_to_type_extra(
10929 ira->codegen, prev_inst->value->type->data.array.child_type,
10930 true, false, PtrLenUnknown,
10931 0, 0, 0, false);
10932 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
10933 if (err_set_type != nullptr) {
10934 return get_error_union_type(ira->codegen, err_set_type, slice_type);
10935 } else {
10936 return slice_type;
10937 }
10938 } else if (prev_inst->value->type->id == ZigTypeIdPointer) {
10880 if (prev_inst->value->type->id == ZigTypeIdPointer) {
1093910881 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
1094010882 src_assert(array_type->id == ZigTypeIdArray, source_node);
1094110883 ZigType *ptr_type = get_pointer_to_type_extra2(
......@@ -12021,52 +11963,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1202111963 return new_instruction;
1202211964}
1202311965
12024static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
12025 IrInstruction *array_arg, ZigType *wanted_type, ResultLoc *result_loc)
12026{
12027 assert(is_slice(wanted_type));
12028 // In this function we honor the const-ness of wanted_type, because
12029 // we may be casting [0]T to []const T which is perfectly valid.
12030
12031 IrInstruction *array_ptr = nullptr;
12032 IrInstruction *array;
12033 if (array_arg->value->type->id == ZigTypeIdPointer) {
12034 array = ir_get_deref(ira, source_instr, array_arg, nullptr);
12035 array_ptr = array_arg;
12036 } else {
12037 array = array_arg;
12038 }
12039 ZigType *array_type = array->value->type;
12040 assert(array_type->id == ZigTypeIdArray);
12041
12042 if (instr_is_comptime(array) || array_type->data.array.len == 0) {
12043 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12044 init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true);
12045 result->value->type = wanted_type;
12046 return result;
12047 }
12048
12049 IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
12050 init_const_usize(ira->codegen, start->value, 0);
12051
12052 IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
12053 init_const_usize(ira->codegen, end->value, array_type->data.array.len);
12054
12055 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
12056
12057 if (result_loc == nullptr) result_loc = no_result_loc();
12058 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr,
12059 true, false, true);
12060 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
12061 return result_loc_inst;
12062 }
12063 IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst);
12064 result->value->data.rh_slice.id = RuntimeHintSliceIdLen;
12065 result->value->data.rh_slice.len = array_type->data.array.len;
12066
12067 return result;
12068}
12069
1207011966static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
1207111967 assert(union_type->id == ZigTypeIdUnion);
1207211968
......@@ -13101,44 +12997,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1310112997 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
1310212998 }
1310312999
13104 // cast from [N]T to []const T
13105 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
13106 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
13107 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
13108 assert(ptr_type->id == ZigTypeIdPointer);
13109 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
13110 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13111 source_node, false).id == ConstCastResultIdOk)
13112 {
13113 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type, nullptr);
13114 }
13115 }
13116
13117 // cast from [N]T to ?[]const T
13118 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
13119 if (wanted_type->id == ZigTypeIdOptional &&
13120 is_slice(wanted_type->data.maybe.child_type) &&
13121 actual_type->id == ZigTypeIdArray)
13122 {
13123 ZigType *ptr_type =
13124 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index]->type_entry;
13125 assert(ptr_type->id == ZigTypeIdPointer);
13126 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
13127 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13128 source_node, false).id == ConstCastResultIdOk)
13129 {
13130 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13131 if (type_is_invalid(cast1->value->type))
13132 return ira->codegen->invalid_instruction;
13133
13134 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13135 if (type_is_invalid(cast2->value->type))
13136 return ira->codegen->invalid_instruction;
13137
13138 return cast2;
13139 }
13140 }
13141
1314213000 // *[N]T to ?[]const T
1314313001 if (wanted_type->id == ZigTypeIdOptional &&
1314413002 is_slice(wanted_type->data.maybe.child_type) &&
......@@ -13284,20 +13142,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1328413142 }
1328513143
1328613144 // *@Frame(func) to anyframe->T or anyframe
13145 // *@Frame(func) to ?anyframe->T or ?anyframe
13146 // *@Frame(func) to E!anyframe->T or E!anyframe
1328713147 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&
1328813148 !actual_type->data.pointer.is_const &&
13289 actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame && wanted_type->id == ZigTypeIdAnyFrame)
13149 actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame)
1329013150 {
13291 bool ok = true;
13292 if (wanted_type->data.any_frame.result_type != nullptr) {
13293 ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;
13294 ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;
13295 if (wanted_type->data.any_frame.result_type != fn_return_type) {
13296 ok = false;
13151 ZigType *anyframe_type;
13152 if (wanted_type->id == ZigTypeIdAnyFrame) {
13153 anyframe_type = wanted_type;
13154 } else if (wanted_type->id == ZigTypeIdOptional &&
13155 wanted_type->data.maybe.child_type->id == ZigTypeIdAnyFrame)
13156 {
13157 anyframe_type = wanted_type->data.maybe.child_type;
13158 } else if (wanted_type->id == ZigTypeIdErrorUnion &&
13159 wanted_type->data.error_union.payload_type->id == ZigTypeIdAnyFrame)
13160 {
13161 anyframe_type = wanted_type->data.error_union.payload_type;
13162 } else {
13163 anyframe_type = nullptr;
13164 }
13165 if (anyframe_type != nullptr) {
13166 bool ok = true;
13167 if (anyframe_type->data.any_frame.result_type != nullptr) {
13168 ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;
13169 ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;
13170 if (anyframe_type->data.any_frame.result_type != fn_return_type) {
13171 ok = false;
13172 }
13173 }
13174 if (ok) {
13175 IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
13176 if (anyframe_type == wanted_type)
13177 return cast1;
13178 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1329713179 }
13298 }
13299 if (ok) {
13300 return ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, wanted_type);
1330113180 }
1330213181 }
1330313182
......@@ -13322,30 +13201,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1332213201 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);
1332313202 }
1332413203
13325 // cast from [N]T to E![]const T
13326 if (wanted_type->id == ZigTypeIdErrorUnion &&
13327 is_slice(wanted_type->data.error_union.payload_type) &&
13328 actual_type->id == ZigTypeIdArray)
13329 {
13330 ZigType *ptr_type =
13331 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index]->type_entry;
13332 assert(ptr_type->id == ZigTypeIdPointer);
13333 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
13334 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13335 source_node, false).id == ConstCastResultIdOk)
13336 {
13337 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
13338 if (type_is_invalid(cast1->value->type))
13339 return ira->codegen->invalid_instruction;
13340
13341 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13342 if (type_is_invalid(cast2->value->type))
13343 return ira->codegen->invalid_instruction;
13344
13345 return cast2;
13346 }
13347 }
13348
1334913204 // cast from E to E!T
1335013205 if (wanted_type->id == ZigTypeIdErrorUnion &&
1335113206 actual_type->id == ZigTypeIdErrorSet)
......@@ -13541,6 +13396,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1354113396 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
1354213397 }
1354313398
13399 // T to ?E!T
13400 if (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdErrorUnion &&
13401 actual_type->id != ZigTypeIdOptional)
13402 {
13403 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
13404 if (type_is_invalid(cast1->value->type))
13405 return ira->codegen->invalid_instruction;
13406 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
13407 }
13408
1354413409 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
1354513410 buf_sprintf("expected type '%s', found '%s'",
1354613411 buf_ptr(&wanted_type->name),
......@@ -15283,10 +15148,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1528315148
1528415149 ZigValue *out_array_val;
1528515150 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
15286 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15287 result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
15288 out_array_val = out_val;
15289 } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
15151 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
1529015152 out_array_val = create_const_vals(1);
1529115153 out_array_val->special = ConstValSpecialStatic;
1529215154 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
......@@ -15314,6 +15176,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1531415176 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
1531515177 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
1531615178 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
15179 } else if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15180 result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
15181 out_array_val = out_val;
1531715182 } else {
1531815183 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
1531915184 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
......@@ -16142,7 +16007,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
1614216007
1614316008// when calling this function, at the callsite must check for result type noreturn and propagate it up
1614416009static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
16145 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
16010 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
16011 bool non_null_comptime, bool allow_discard)
1614616012{
1614716013 Error err;
1614816014 if (result_loc->resolved_loc != nullptr) {
......@@ -16275,8 +16141,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1627516141 ira->src_implicit_return_type_list.append(value);
1627616142 }
1627716143 peer_parent->skipped = true;
16278 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
16144 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1627916145 value_type, value, force_runtime || !is_comptime, true, true);
16146 if (parent_result_loc != nullptr) {
16147 peer_parent->parent->written = true;
16148 }
16149 return parent_result_loc;
1628016150 }
1628116151
1628216152 if (peer_parent->resolved_type == nullptr) {
......@@ -16317,30 +16187,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1631716187 force_runtime, non_null_comptime);
1631816188 }
1631916189
16320 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type,
16321 result_cast->base.source_instruction->source_node, false);
16322 if (const_cast_result.id == ConstCastResultIdInvalid)
16323 return ira->codegen->invalid_instruction;
16324 if (const_cast_result.id != ConstCastResultIdOk) {
16325 // We will not be able to provide a result location for this value. Create
16326 // a new result location.
16327 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
16328 force_runtime, non_null_comptime);
16329 }
16330
16331 // In this case we can pointer cast the result location.
1633216190 IrInstruction *casted_value;
1633316191 if (value != nullptr) {
1633416192 casted_value = ir_implicit_cast(ira, value, dest_type);
16193 if (type_is_invalid(casted_value->value->type))
16194 return ira->codegen->invalid_instruction;
16195 dest_type = casted_value->value->type;
1633516196 } else {
1633616197 casted_value = nullptr;
1633716198 }
1633816199
16339 if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) {
16340 return casted_value;
16341 }
16342
16343 bool old_parent_result_loc_written = result_cast->parent->written;
1634416200 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
1634516201 dest_type, casted_value, force_runtime, non_null_comptime, true);
1634616202 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
......@@ -16378,26 +16234,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1637816234 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
1637916235 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1638016236
16381 {
16382 // we also need to check that this cast is OK.
16383 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16384 parent_result_loc->value->type, ptr_type,
16385 result_cast->base.source_instruction->source_node, false);
16386 if (const_cast_result.id == ConstCastResultIdInvalid)
16387 return ira->codegen->invalid_instruction;
16388 if (const_cast_result.id != ConstCastResultIdOk) {
16389 // We will not be able to provide a result location for this value. Create
16390 // a new result location.
16391 result_cast->parent->written = old_parent_result_loc_written;
16392 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
16393 force_runtime, non_null_comptime);
16237 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16238 parent_result_loc->value->type, ptr_type,
16239 result_cast->base.source_instruction->source_node, false);
16240 if (const_cast_result.id == ConstCastResultIdInvalid)
16241 return ira->codegen->invalid_instruction;
16242 if (const_cast_result.id != ConstCastResultIdOk) {
16243 if (allow_discard) {
16244 return parent_result_loc;
1639416245 }
16246 // We will not be able to provide a result location for this value. Create
16247 // a new result location.
16248 result_cast->parent->written = false;
16249 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
16250 force_runtime, non_null_comptime);
1639516251 }
1639616252
16397 result_loc->written = true;
16398 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
16253 return ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
1639916254 ptr_type, result_cast->base.source_instruction, false);
16400 return result_loc->resolved_loc;
1640116255 }
1640216256 case ResultLocIdBitCast: {
1640316257 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
......@@ -16483,7 +16337,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1648316337 result_loc_pass1 = no_result_loc();
1648416338 }
1648516339 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
16486 value, force_runtime, non_null_comptime);
16340 value, force_runtime, non_null_comptime, allow_discard);
1648716341 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
1648816342 return result_loc;
1648916343
......@@ -16496,7 +16350,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1649616350 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
1649716351 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
1649816352 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
16499 value_type->id != ZigTypeIdNull)
16353 value_type->id != ZigTypeIdNull && value == nullptr)
1650016354 {
1650116355 result_loc_pass1->written = false;
1650216356 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
......@@ -16514,9 +16368,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1651416368 return unwrapped_err_ptr;
1651516369 }
1651616370 }
16517 } else if (is_slice(actual_elem_type) && value_type->id == ZigTypeIdArray) {
16518 // need to allow EndExpr to do the implicit cast from array to slice
16519 result_loc_pass1->written = false;
1652016371 }
1652116372 return result_loc;
1652216373}
......@@ -17520,11 +17371,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1752017371 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
1752117372 ir_reset_result(call_instruction->result_loc);
1752217373 result_loc = nullptr;
17523 } else {
17524 call_instruction->base.value.type = impl_fn_type_id->return_type;
17525 IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type);
17526 if (type_is_invalid(casted_value->value.type))
17527 return casted_value;
1752817374 }
1752917375 }
1753017376 } else if (call_instruction->is_async_call_builtin) {
......@@ -17687,11 +17533,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1768717533 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
1768817534 ir_reset_result(call_instruction->result_loc);
1768917535 result_loc = nullptr;
17690 } else {
17691 call_instruction->base.value.type = return_type;
17692 IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type);
17693 if (type_is_invalid(casted_value->value.type))
17694 return casted_value;
1769517536 }
1769617537 }
1769717538 } else if (call_instruction->is_async_call_builtin) {
......@@ -21041,6 +20882,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2104120882 {
2104220883 // We're now done inferring the type.
2104320884 container_type->data.structure.resolve_status = ResolveStatusUnstarted;
20885 } else if (container_type->id == ZigTypeIdVector) {
20886 // OK
2104420887 } else {
2104520888 ir_add_error_node(ira, instruction->base.source_node,
2104620889 buf_sprintf("type '%s' does not support array initialization",
......@@ -22434,17 +22277,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2243422277 return result;
2243522278}
2243622279
22437static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22280static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
22281 const char *name, size_t field_index)
2243822282{
22283 Error err;
2243922284 ensure_field_index(struct_value->type, name, field_index);
22440 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
22441 return struct_value->data.x_struct.fields[field_index];
22285 ZigValue *val = struct_value->data.x_struct.fields[field_index];
22286 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, val, UndefBad)))
22287 return nullptr;
22288 return val;
2244222289}
2244322290
2244422291static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
2244522292 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
2244622293{
22447 ZigValue *field_val = get_const_field(ira, struct_value, name, field_index);
22294 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
22295 if (field_val == nullptr)
22296 return ErrorSemanticAnalyzeFail;
2244822297 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
2244922298 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
2245022299 get_optional_type(ira->codegen, elem_type));
......@@ -22455,23 +22304,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
2245522304 return ErrorNone;
2245622305}
2245722306
22458static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22307static Error get_const_field_bool(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
22308 const char *name, size_t field_index, bool *out)
2245922309{
22460 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22310 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
22311 if (value == nullptr)
22312 return ErrorSemanticAnalyzeFail;
2246122313 assert(value->type == ira->codegen->builtin_types.entry_bool);
22462 return value->data.x_bool;
22314 *out = value->data.x_bool;
22315 return ErrorNone;
2246322316}
2246422317
22465static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22318static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
2246622319{
22467 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22320 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
22321 if (value == nullptr)
22322 return nullptr;
2246822323 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
2246922324 return &value->data.x_bigint;
2247022325}
2247122326
22472static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22327static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
2247322328{
22474 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22329 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
22330 if (value == nullptr)
22331 return ira->codegen->invalid_instruction->value->type;
2247522332 assert(value->type == ira->codegen->builtin_types.entry_type);
2247622333 return value->data.x_type;
2247722334}
......@@ -22489,17 +22346,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2248922346 return ira->codegen->builtin_types.entry_bool;
2249022347 case ZigTypeIdUnreachable:
2249122348 return ira->codegen->builtin_types.entry_unreachable;
22492 case ZigTypeIdInt:
22349 case ZigTypeIdInt: {
2249322350 assert(payload->special == ConstValSpecialStatic);
2249422351 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
22495 return get_int_type(ira->codegen,
22496 get_const_field_bool(ira, payload, "is_signed", 0),
22497 bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1)));
22352 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
22353 if (bi == nullptr)
22354 return ira->codegen->invalid_instruction->value->type;
22355 bool is_signed;
22356 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))
22357 return ira->codegen->invalid_instruction->value->type;
22358 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
22359 }
2249822360 case ZigTypeIdFloat:
2249922361 {
2250022362 assert(payload->special == ConstValSpecialStatic);
2250122363 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
22502 uint32_t bits = bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 0));
22364 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0);
22365 if (bi == nullptr)
22366 return ira->codegen->invalid_instruction->value->type;
22367 uint32_t bits = bigint_as_u32(bi);
2250322368 switch (bits) {
2250422369 case 16: return ira->codegen->builtin_types.entry_f16;
2250522370 case 32: return ira->codegen->builtin_types.entry_f32;
......@@ -22515,27 +22380,51 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2251522380 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2251622381 assert(payload->special == ConstValSpecialStatic);
2251722382 assert(payload->type == type_info_pointer_type);
22518 ZigValue *size_value = get_const_field(ira, payload, "size", 0);
22383 ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0);
2251922384 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
2252022385 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
2252122386 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
22522 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);
22387 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4);
22388 if (type_is_invalid(elem_type))
22389 return ira->codegen->invalid_instruction->value->type;
2252322390 ZigValue *sentinel;
2252422391 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
2252522392 elem_type, &sentinel)))
2252622393 {
22527 return nullptr;
22394 return ira->codegen->invalid_instruction->value->type;
22395 }
22396 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3);
22397 if (bi == nullptr)
22398 return ira->codegen->invalid_instruction->value->type;
22399
22400 bool is_const;
22401 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))
22402 return ira->codegen->invalid_instruction->value->type;
22403
22404 bool is_volatile;
22405 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2,
22406 &is_volatile)))
22407 {
22408 return ira->codegen->invalid_instruction->value->type;
22409 }
22410
22411 bool is_allowzero;
22412 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5,
22413 &is_allowzero)))
22414 {
22415 return ira->codegen->invalid_instruction->value->type;
2252822416 }
2252922417
22418
2253022419 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
2253122420 elem_type,
22532 get_const_field_bool(ira, payload, "is_const", 1),
22533 get_const_field_bool(ira, payload, "is_volatile", 2),
22421 is_const,
22422 is_volatile,
2253422423 ptr_len,
22535 bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)),
22424 bigint_as_u32(bi),
2253622425 0, // bit_offset_in_host
2253722426 0, // host_int_bytes
22538 get_const_field_bool(ira, payload, "is_allowzero", 5),
22427 is_allowzero,
2253922428 VECTOR_INDEX_NONE, nullptr, sentinel);
2254022429 if (size_enum_index != 2)
2254122430 return ptr_type;
......@@ -22544,17 +22433,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2254422433 case ZigTypeIdArray: {
2254522434 assert(payload->special == ConstValSpecialStatic);
2254622435 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
22547 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);
22436 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1);
22437 if (type_is_invalid(elem_type))
22438 return ira->codegen->invalid_instruction->value->type;
2254822439 ZigValue *sentinel;
2254922440 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
2255022441 elem_type, &sentinel)))
2255122442 {
22552 return nullptr;
22443 return ira->codegen->invalid_instruction->value->type;
2255322444 }
22554 return get_array_type(ira->codegen,
22555 elem_type,
22556 bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)),
22557 sentinel);
22445 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
22446 if (bi == nullptr)
22447 return ira->codegen->invalid_instruction->value->type;
22448 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
2255822449 }
2255922450 case ZigTypeIdComptimeFloat:
2256022451 return ira->codegen->builtin_types.entry_num_lit_float;
......@@ -22575,7 +22466,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2257522466 case ZigTypeIdEnumLiteral:
2257622467 ir_add_error(ira, instruction, buf_sprintf(
2257722468 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
22578 return nullptr;
22469 return ira->codegen->invalid_instruction->value->type;
2257922470 case ZigTypeIdUnion:
2258022471 case ZigTypeIdFn:
2258122472 case ZigTypeIdBoundFn:
......@@ -22583,7 +22474,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2258322474 case ZigTypeIdStruct:
2258422475 ir_add_error(ira, instruction, buf_sprintf(
2258522476 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
22586 return nullptr;
22477 return ira->codegen->invalid_instruction->value->type;
2258722478 }
2258822479 zig_unreachable();
2258922480}
......@@ -22602,7 +22493,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
2260222493 return ira->codegen->invalid_instruction;
2260322494 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
2260422495 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);
22605 if (!type)
22496 if (type_is_invalid(type))
2260622497 return ira->codegen->invalid_instruction;
2260722498 return ir_const_type(ira, &instruction->base, type);
2260822499}
......@@ -28332,3 +28223,18 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
2833228223 }
2833328224 return ErrorNone;
2833428225}
28226
28227void IrInstruction::dump() {
28228 IrInstruction *inst = this;
28229 if (inst->source_node != nullptr) {
28230 inst->source_node->src();
28231 } else {
28232 fprintf(stderr, "(null source node)\n");
28233 }
28234 IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;
28235 ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);
28236 if (pass == IrPassSrc) {
28237 fprintf(stderr, "-> ");
28238 ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);
28239 }
28240}
test/compare_output.zig+2-2
......@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
465465 \\
466466 );
467467
468 tc.setCommandLineArgs([_][]const u8{
468 tc.setCommandLineArgs(&[_][]const u8{
469469 "first arg",
470470 "'a' 'b' \\",
471471 "bare",
......@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
506506 \\
507507 );
508508
509 tc.setCommandLineArgs([_][]const u8{
509 tc.setCommandLineArgs(&[_][]const u8{
510510 "first arg",
511511 "'a' 'b' \\",
512512 "bare",
test/stage1/behavior/array.zig+22-22
......@@ -20,7 +20,7 @@ test "arrays" {
2020 }
2121
2222 expect(accumulator == 15);
23 expect(getArrayLen(array) == 5);
23 expect(getArrayLen(&array) == 5);
2424}
2525fn getArrayLen(a: []const u32) usize {
2626 return a.len;
......@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {
182182
183183test "runtime initialize array elem and then implicit cast to slice" {
184184 var two: i32 = 2;
185 const x: []const i32 = [_]i32{two};
185 const x: []const i32 = &[_]i32{two};
186186 expect(x[0] == 2);
187187}
188188
189189test "array literal as argument to function" {
190190 const S = struct {
191191 fn entry(two: i32) void {
192 foo([_]i32{
192 foo(&[_]i32{
193193 1,
194194 2,
195195 3,
196196 });
197 foo([_]i32{
197 foo(&[_]i32{
198198 1,
199199 two,
200200 3,
201201 });
202 foo2(true, [_]i32{
202 foo2(true, &[_]i32{
203203 1,
204204 2,
205205 3,
206206 });
207 foo2(true, [_]i32{
207 foo2(true, &[_]i32{
208208 1,
209209 two,
210210 3,
......@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {
230230 const S = struct {
231231 fn entry(two: i32) void {
232232 const cases = [_][]const []const i32{
233 [_][]const i32{[_]i32{1}},
234 [_][]const i32{[_]i32{ 2, 3 }},
235 [_][]const i32{
236 [_]i32{4},
237 [_]i32{ 5, 6, 7 },
233 &[_][]const i32{&[_]i32{1}},
234 &[_][]const i32{&[_]i32{ 2, 3 }},
235 &[_][]const i32{
236 &[_]i32{4},
237 &[_]i32{ 5, 6, 7 },
238238 },
239239 };
240 check(cases);
240 check(&cases);
241241
242242 const cases2 = [_][]const i32{
243 [_]i32{1},
243 &[_]i32{1},
244244 &[_]i32{ two, 3 },
245245 };
246246 expect(cases2.len == 2);
......@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {
251251 expect(cases2[1][1] == 3);
252252
253253 const cases3 = [_][]const []const i32{
254 [_][]const i32{[_]i32{1}},
254 &[_][]const i32{&[_]i32{1}},
255255 &[_][]const i32{&[_]i32{ two, 3 }},
256 [_][]const i32{
257 [_]i32{4},
258 [_]i32{ 5, 6, 7 },
256 &[_][]const i32{
257 &[_]i32{4},
258 &[_]i32{ 5, 6, 7 },
259259 },
260260 };
261 check(cases3);
261 check(&cases3);
262262 }
263263
264264 fn check(cases: []const []const []const i32) void {
......@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {
316316test "anonymous list literal syntax" {
317317 const S = struct {
318318 fn doTheTest() void {
319 var array: [4]u8 = .{1, 2, 3, 4};
319 var array: [4]u8 = .{ 1, 2, 3, 4 };
320320 expect(array[0] == 1);
321321 expect(array[1] == 2);
322322 expect(array[2] == 3);
......@@ -335,8 +335,8 @@ test "anonymous literal in array" {
335335 };
336336 fn doTheTest() void {
337337 var array: [2]Foo = .{
338 .{.a = 3},
339 .{.b = 3},
338 .{ .a = 3 },
339 .{ .b = 3 },
340340 };
341341 expect(array[0].a == 3);
342342 expect(array[0].b == 4);
......@@ -351,7 +351,7 @@ test "anonymous literal in array" {
351351test "access the null element of a null terminated array" {
352352 const S = struct {
353353 fn doTheTest() void {
354 var array: [4:0]u8 = .{'a', 'o', 'e', 'u'};
354 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
355355 comptime expect(array[4] == 0);
356356 var len: usize = 4;
357357 expect(array[len] == 0);
test/stage1/behavior/async_fn.zig+6-6
......@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {
143143 resume frame;
144144 seq('h');
145145
146 expect(std.mem.eql(u8, points, "abcdefgh"));
146 expect(std.mem.eql(u8, &points, "abcdefgh"));
147147 }
148148
149149 fn amain() void {
......@@ -206,7 +206,7 @@ test "coroutine await" {
206206 resume await_a_promise;
207207 await_seq('i');
208208 expect(await_final_result == 1234);
209 expect(std.mem.eql(u8, await_points, "abcdefghi"));
209 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
210210}
211211async fn await_amain() void {
212212 await_seq('b');
......@@ -240,7 +240,7 @@ test "coroutine await early return" {
240240 var p = async early_amain();
241241 early_seq('f');
242242 expect(early_final_result == 1234);
243 expect(std.mem.eql(u8, early_points, "abcdef"));
243 expect(std.mem.eql(u8, &early_points, "abcdef"));
244244}
245245async fn early_amain() void {
246246 early_seq('b');
......@@ -1166,7 +1166,7 @@ test "suspend in for loop" {
11661166 }
11671167
11681168 fn atest() void {
1169 expect(func([_]u8{ 1, 2, 3 }) == 6);
1169 expect(func(&[_]u8{ 1, 2, 3 }) == 6);
11701170 }
11711171 fn func(stuff: []const u8) u32 {
11721172 global_frame = @frame();
......@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {
12111211
12121212 fn doTheTest() void {
12131213 var foo = Foo{
1214 .slice = [_]i32{ 1, 2 },
1214 .slice = &[_]i32{ 1, 2 },
12151215 };
12161216 expect(atest(&foo) == 3);
12171217 }
......@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
12421242
12431243 fn doTheTest() void {
12441244 var foo = Foo{
1245 .slice = [_]i32{ 1, 2 },
1245 .slice = &[_]i32{ 1, 2 },
12461246 };
12471247 expect(atest(&foo) == 3);
12481248 }
test/stage1/behavior/await_struct.zig+1-1
......@@ -16,7 +16,7 @@ test "coroutine await struct" {
1616 resume await_a_promise;
1717 await_seq('i');
1818 expect(await_final_result.x == 1234);
19 expect(std.mem.eql(u8, await_points, "abcdefghi"));
19 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
2020}
2121async fn await_amain() void {
2222 await_seq('b');
test/stage1/behavior/bugs/1607.zig+2-2
......@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {
1010}
1111
1212test "slices pointing at the same address as global array." {
13 checkAddress(a);
14 comptime checkAddress(a);
13 checkAddress(&a);
14 comptime checkAddress(&a);
1515}
test/stage1/behavior/bugs/1914.zig+2-2
......@@ -7,7 +7,7 @@ const B = struct {
77 a_pointer: *const A,
88};
99
10const b_list: []B = [_]B{};
10const b_list: []B = &[_]B{};
1111const a = A{ .b_list_pointer = &b_list };
1212
1313test "segfault bug" {
......@@ -24,7 +24,7 @@ pub const B2 = struct {
2424 pointer_array: []*A2,
2525};
2626
27var b_value = B2{ .pointer_array = [_]*A2{} };
27var b_value = B2{ .pointer_array = &[_]*A2{} };
2828
2929test "basic stuff" {
3030 std.debug.assert(&b_value == &b_value);
test/stage1/behavior/cast.zig+36-13
......@@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {
150150}
151151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
152152 if (a) {
153 return [_]u8{};
153 return &[_]u8{};
154154 }
155155
156156 return slice[0..1];
......@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {
175175}
176176
177177fn gimmeErrOrSlice() anyerror![]u8 {
178 return [_]u8{};
178 return &[_]u8{};
179179}
180180
181181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
......@@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
200200}
201201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
202202 if (a) {
203 return [_]u8{};
203 return &[_]u8{};
204204 }
205205
206206 return slice[0..1];
......@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
457457test "implicit cast from [*]T to ?*c_void" {
458458 var a = [_]u8{ 3, 2, 1 };
459459 incrementVoidPtrArray(a[0..].ptr, 3);
460 expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 }));
460 expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
461461}
462462
463463fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
......@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {
606606
607607test "peer resolution of string literals" {
608608 const S = struct {
609 const E = extern enum { a, b, c, d};
609 const E = extern enum {
610 a,
611 b,
612 c,
613 d,
614 };
610615
611616 fn doTheTest(e: E) void {
612617 const cmd = switch (e) {
......@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {
627632 fn doTheTest() void {
628633 // [:x]T to []T
629634 {
630 var array = [4:0]i32{1,2,3,4};
635 var array = [4:0]i32{ 1, 2, 3, 4 };
631636 var slice: [:0]i32 = &array;
632637 var dest: []i32 = slice;
633 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
638 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
634639 }
635640
636641 // [*:x]T to [*]T
637642 {
638 var array = [4:99]i32{1,2,3,4};
643 var array = [4:99]i32{ 1, 2, 3, 4 };
639644 var dest: [*]i32 = &array;
640645 expect(dest[0] == 1);
641646 expect(dest[1] == 2);
......@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {
646651
647652 // [N:x]T to [N]T
648653 {
649 var array = [4:0]i32{1,2,3,4};
654 var array = [4:0]i32{ 1, 2, 3, 4 };
650655 var dest: [4]i32 = array;
651 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
656 expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
652657 }
653658
654659 // *[N:x]T to *[N]T
655660 {
656 var array = [4:0]i32{1,2,3,4};
661 var array = [4:0]i32{ 1, 2, 3, 4 };
657662 var dest: *[4]i32 = &array;
658 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
663 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
659664 }
660665
661666 // [:x]T to [*:x]T
662667 {
663 var array = [4:0]i32{1,2,3,4};
668 var array = [4:0]i32{ 1, 2, 3, 4 };
664669 var slice: [:0]i32 = &array;
665670 var dest: [*:0]i32 = slice;
666671 expect(dest[0] == 1);
......@@ -674,3 +679,21 @@ test "type coercion related to sentinel-termination" {
674679 S.doTheTest();
675680 comptime S.doTheTest();
676681}
682
683test "cast i8 fn call peers to i32 result" {
684 const S = struct {
685 fn doTheTest() void {
686 var cond = true;
687 const value: i32 = if (cond) smallBoi() else bigBoi();
688 expect(value == 123);
689 }
690 fn smallBoi() i8 {
691 return 123;
692 }
693 fn bigBoi() i16 {
694 return 1234;
695 }
696 };
697 S.doTheTest();
698 comptime S.doTheTest();
699}
test/stage1/behavior/eval.zig+3-3
......@@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" {
717717 };
718718
719719 var b = [1]u8{9};
720 var f = @bytesToSlice(F, b);
720 var f = @bytesToSlice(F, &b);
721721 expect(f[0].a == 9);
722722}
723723
......@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {
774774
775775test "array concatenation forces comptime" {
776776 var a = oneItem(3) ++ oneItem(4);
777 expect(std.mem.eql(i32, a, [_]i32{ 3, 4 }));
777 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
778778}
779779
780780test "array multiplication forces comptime" {
781781 var a = oneItem(3) ** scalar(2);
782 expect(std.mem.eql(i32, a, [_]i32{ 3, 3 }));
782 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
783783}
784784
785785fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/for.zig+5-5
......@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
2626 var target: [source.len]u8 = undefined;
2727 mem.copy(u8, target[0..], source);
2828 mangleString(target[0..]);
29 expect(mem.eql(u8, target, "bcdefgh"));
29 expect(mem.eql(u8, &target, "bcdefgh"));
3030
3131 for (source) |*c, i|
3232 expect(@typeOf(c) == *const u8);
......@@ -64,7 +64,7 @@ test "basic for loop" {
6464 buffer[buf_index] = @intCast(u8, index);
6565 buf_index += 1;
6666 }
67 const unknown_size: []const u8 = array;
67 const unknown_size: []const u8 = &array;
6868 for (unknown_size) |item| {
6969 buffer[buf_index] = item;
7070 buf_index += 1;
......@@ -74,7 +74,7 @@ test "basic for loop" {
7474 buf_index += 1;
7575 }
7676
77 expect(mem.eql(u8, buffer[0..buf_index], expected_result));
77 expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
7878}
7979
8080test "break from outer for loop" {
......@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {
139139 }
140140 }
141141 };
142 S.doTheTest([_]u8{ 1, 2 });
143 comptime S.doTheTest([_]u8{ 1, 2 });
142 S.doTheTest(&[_]u8{ 1, 2 });
143 comptime S.doTheTest(&[_]u8{ 1, 2 });
144144}
test/stage1/behavior/generics.zig+2-2
......@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
120120}
121121
122122test "generic fn with implicit cast" {
123 expect(getFirstByte(u8, [_]u8{13}) == 13);
124 expect(getFirstByte(u16, [_]u16{
123 expect(getFirstByte(u8, &[_]u8{13}) == 13);
124 expect(getFirstByte(u16, &[_]u16{
125125 0,
126126 13,
127127 }) == 0);
test/stage1/behavior/misc.zig+3-3
......@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}
241241
242242test "cast undefined" {
243243 const array: [100]u8 = undefined;
244 const slice = @as([]const u8, array);
244 const slice = @as([]const u8, &array);
245245 testCastUndefined(slice);
246246}
247247fn testCastUndefined(x: []const u8) void {}
......@@ -614,7 +614,7 @@ test "slicing zero length array" {
614614 expect(s1.len == 0);
615615 expect(s2.len == 0);
616616 expect(mem.eql(u8, s1, ""));
617 expect(mem.eql(u32, s2, [_]u32{}));
617 expect(mem.eql(u32, s2, &[_]u32{}));
618618}
619619
620620const addr1 = @ptrCast(*const u8, emptyFn);
......@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic
710710 const E = struct {
711711 entries: []u32,
712712 };
713 var foo = E{ .entries = [_]u32{} };
713 var foo = E{ .entries = &[_]u32{} };
714714 expect(foo.entries.len == 0);
715715}
716716
test/stage1/behavior/ptrcast.zig+1-1
......@@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {
3737
3838test "reinterpret struct field at comptime" {
3939 const numLittle = comptime Bytes.init(0x12345678);
40 expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
40 expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes));
4141}
4242
4343const Bytes = struct {
test/stage1/behavior/shuffle.zig+7-7
......@@ -9,28 +9,28 @@ test "@shuffle" {
99 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
1010 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
1111 var res = @shuffle(i32, v, x, mask);
12 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
12 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1313
1414 // Implicit cast from array (of mask)
1515 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
16 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1717
1818 // Undefined
1919 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
2020 res = @shuffle(i32, v, undefined, mask2);
21 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 }));
21 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
2222
2323 // Upcasting of b
2424 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
2525 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
2626 res = @shuffle(i32, x, v2, mask3);
27 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 }));
27 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
2828
2929 // Upcasting of a
3030 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
3131 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
3232 res = @shuffle(i32, v3, x, mask4);
33 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 }));
33 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
3434
3535 // bool
3636 // Disabled because of #3317
......@@ -39,7 +39,7 @@ test "@shuffle" {
3939 var v4: @Vector(2, bool) = [2]bool{ true, false };
4040 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
4141 var res2 = @shuffle(bool, x2, v4, mask5);
42 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
42 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
4343 }
4444
4545 // TODO re-enable when LLVM codegen is fixed
......@@ -49,7 +49,7 @@ test "@shuffle" {
4949 var v4: @Vector(2, bool) = [2]bool{ true, false };
5050 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
5151 var res2 = @shuffle(bool, x2, v4, mask5);
52 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
52 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
5353 }
5454 }
5555 };
test/stage1/behavior/slice.zig+3-3
......@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
2828
2929test "implicitly cast array of size 0 to slice" {
3030 var msg = [_]u8{};
31 assertLenIsZero(msg);
31 assertLenIsZero(&msg);
3232}
3333
3434fn assertLenIsZero(msg: []const u8) void {
......@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {
5151}
5252
5353test "comptime slices are disambiguated" {
54 expect(sliceSum([_]u8{ 1, 2 }) == 3);
55 expect(sliceSum([_]u8{ 3, 4 }) == 7);
54 expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
55 expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
5656}
5757
5858test "slice type with custom alignment" {
test/stage1/behavior/struct.zig+5-4
......@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
184184}
185185
186186test "pass slice of empty struct to fn" {
187 expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1);
187 expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
188188}
189189fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
190190 return slice.len;
......@@ -432,7 +432,7 @@ const Expr = union(enum) {
432432};
433433
434434fn alloc(comptime T: type) []T {
435 return [_]T{};
435 return &[_]T{};
436436}
437437
438438test "call method with mutable reference to struct with no fields" {
......@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {
495495 .a = true,
496496 .b = "abcdefghijklmnopqurstu".*,
497497 };
498 bar(foo.b);
498 const value = foo.b;
499 bar(&value);
499500 }
500501 };
501502 S.doTheTest();
......@@ -783,7 +784,7 @@ test "struct with var field" {
783784 x: var,
784785 y: var,
785786 };
786 const pt = Point {
787 const pt = Point{
787788 .x = 1,
788789 .y = 2,
789790 };
test/stage1/behavior/struct_contains_slice_of_itself.zig+8-8
......@@ -14,21 +14,21 @@ test "struct contains slice of itself" {
1414 var other_nodes = [_]Node{
1515 Node{
1616 .payload = 31,
17 .children = [_]Node{},
17 .children = &[_]Node{},
1818 },
1919 Node{
2020 .payload = 32,
21 .children = [_]Node{},
21 .children = &[_]Node{},
2222 },
2323 };
2424 var nodes = [_]Node{
2525 Node{
2626 .payload = 1,
27 .children = [_]Node{},
27 .children = &[_]Node{},
2828 },
2929 Node{
3030 .payload = 2,
31 .children = [_]Node{},
31 .children = &[_]Node{},
3232 },
3333 Node{
3434 .payload = 3,
......@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {
5151 var other_nodes = [_]NodeAligned{
5252 NodeAligned{
5353 .payload = 31,
54 .children = [_]NodeAligned{},
54 .children = &[_]NodeAligned{},
5555 },
5656 NodeAligned{
5757 .payload = 32,
58 .children = [_]NodeAligned{},
58 .children = &[_]NodeAligned{},
5959 },
6060 };
6161 var nodes = [_]NodeAligned{
6262 NodeAligned{
6363 .payload = 1,
64 .children = [_]NodeAligned{},
64 .children = &[_]NodeAligned{},
6565 },
6666 NodeAligned{
6767 .payload = 2,
68 .children = [_]NodeAligned{},
68 .children = &[_]NodeAligned{},
6969 },
7070 NodeAligned{
7171 .payload = 3,
test/stage1/behavior/type.zig+12-12
......@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {
1212
1313test "Type.MetaType" {
1414 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
15 testTypes([_]type{type});
15 testTypes(&[_]type{type});
1616}
1717
1818test "Type.Void" {
1919 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
20 testTypes([_]type{void});
20 testTypes(&[_]type{void});
2121}
2222
2323test "Type.Bool" {
2424 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
25 testTypes([_]type{bool});
25 testTypes(&[_]type{bool});
2626}
2727
2828test "Type.NoReturn" {
2929 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
30 testTypes([_]type{noreturn});
30 testTypes(&[_]type{noreturn});
3131}
3232
3333test "Type.Int" {
......@@ -37,7 +37,7 @@ test "Type.Int" {
3737 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));
3838 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));
3939 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));
40 testTypes([_]type{ u8, u32, i64 });
40 testTypes(&[_]type{ u8, u32, i64 });
4141}
4242
4343test "Type.Float" {
......@@ -45,11 +45,11 @@ test "Type.Float" {
4545 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
4646 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
4747 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
48 testTypes([_]type{ f16, f32, f64, f128 });
48 testTypes(&[_]type{ f16, f32, f64, f128 });
4949}
5050
5151test "Type.Pointer" {
52 testTypes([_]type{
52 testTypes(&[_]type{
5353 // One Value Pointer Types
5454 *u8, *const u8,
5555 *volatile u8, *const volatile u8,
......@@ -115,18 +115,18 @@ test "Type.Array" {
115115 .sentinel = 0,
116116 },
117117 }));
118 testTypes([_]type{ [1]u8, [30]usize, [7]bool });
118 testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
119119}
120120
121121test "Type.ComptimeFloat" {
122 testTypes([_]type{comptime_float});
122 testTypes(&[_]type{comptime_float});
123123}
124124test "Type.ComptimeInt" {
125 testTypes([_]type{comptime_int});
125 testTypes(&[_]type{comptime_int});
126126}
127127test "Type.Undefined" {
128 testTypes([_]type{@typeOf(undefined)});
128 testTypes(&[_]type{@typeOf(undefined)});
129129}
130130test "Type.Null" {
131 testTypes([_]type{@typeOf(null)});
131 testTypes(&[_]type{@typeOf(null)});
132132}
test/stage1/behavior/union.zig+1-1
......@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {
241241};
242242
243243test "constant packed union" {
244 testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }});
244 testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
245245}
246246
247247fn testConstPackedUnion(expected_tokens: []const PackThis) void {
test/stage1/behavior/vector.zig+27-27
......@@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" {
88 fn doTheTest() void {
99 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };
1010 const result_array: [4]bool = a;
11 expect(mem.eql(bool, result_array, [4]bool{ true, false, true, false }));
11 expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
1212 }
1313 };
1414 S.doTheTest();
......@@ -20,11 +20,11 @@ test "vector wrap operators" {
2020 fn doTheTest() void {
2121 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
2222 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
23 expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
23 expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
2626 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
27 expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 }));
27 expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
2828 }
2929 };
3030 S.doTheTest();
......@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
3636 fn doTheTest() void {
3737 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
3838 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
39 expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));
39 expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
4545 }
4646 };
4747 S.doTheTest();
......@@ -53,10 +53,10 @@ test "vector int operators" {
5353 fn doTheTest() void {
5454 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
5555 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
56 expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));
56 expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
6060 }
6161 };
6262 S.doTheTest();
......@@ -68,10 +68,10 @@ test "vector float operators" {
6868 fn doTheTest() void {
6969 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
7070 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
71 expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));
71 expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
7575 }
7676 };
7777 S.doTheTest();
......@@ -83,9 +83,9 @@ test "vector bit operators" {
8383 fn doTheTest() void {
8484 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
8585 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
86 expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
86 expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
8989 }
9090 };
9191 S.doTheTest();
......@@ -98,7 +98,7 @@ test "implicit cast vector to array" {
9898 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
9999 var result_array: [4]i32 = a;
100100 result_array = a;
101 expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 }));
101 expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
102102 }
103103 };
104104 S.doTheTest();
......@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120120 {
121121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122122 var x: [4]u3 = v;
123 expect(mem.eql(u3, x, @as([4]u3, v)));
123 expect(mem.eql(u3, &x, &@as([4]u3, v)));
124124 }
125125 {
126126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127127 var x: [4]u2 = v;
128 expect(mem.eql(u2, x, @as([4]u2, v)));
128 expect(mem.eql(u2, &x, &@as([4]u2, v)));
129129 }
130130 {
131131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132132 var x: [4]u1 = v;
133 expect(mem.eql(u1, x, @as([4]u1, v)));
133 expect(mem.eql(u1, &x, &@as([4]u1, v)));
134134 }
135135 {
136136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137137 var x: [4]bool = v;
138 expect(mem.eql(bool, x, @as([4]bool, v)));
138 expect(mem.eql(bool, &x, &@as([4]bool, v)));
139139 }
140140 }
141141 };
test/tests.zig+16-16
......@@ -325,7 +325,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
325325
326326 const exe = b.addExecutable("test-cli", "test/cli.zig");
327327 const run_cmd = exe.run();
328 run_cmd.addArgs([_][]const u8{
328 run_cmd.addArgs(&[_][]const u8{
329329 fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
330330 b.pathFromRoot(b.cache_root),
331331 });
......@@ -411,7 +411,7 @@ pub fn addPkgTests(
411411 const ArchTag = @TagType(builtin.Arch);
412412 if (test_target.disable_native and
413413 test_target.target.getOs() == builtin.os and
414 @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch))
414 @as(ArchTag, test_target.target.getArch()) == @as(ArchTag, builtin.arch))
415415 {
416416 continue;
417417 }
......@@ -429,7 +429,7 @@ pub fn addPkgTests(
429429 "bare";
430430
431431 const triple_prefix = if (test_target.target == .Native)
432 @as([]const u8,"native")
432 @as([]const u8, "native")
433433 else
434434 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
435435
......@@ -626,7 +626,7 @@ pub const CompareOutputContext = struct {
626626
627627 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
628628
629 const child = std.ChildProcess.init([_][]const u8{full_exe_path}, b.allocator) catch unreachable;
629 const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
630630 defer child.deinit();
631631
632632 child.env_map = b.env_map;
......@@ -667,7 +667,7 @@ pub const CompareOutputContext = struct {
667667 .expected_output = expected_output,
668668 .link_libc = false,
669669 .special = special,
670 .cli_args = [_][]const u8{},
670 .cli_args = &[_][]const u8{},
671671 };
672672 const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
673673 tc.addSourceFile(root_src_name, source);
......@@ -704,7 +704,7 @@ pub const CompareOutputContext = struct {
704704
705705 const root_src = fs.path.join(
706706 b.allocator,
707 [_][]const u8{ b.cache_root, case.sources.items[0].filename },
707 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
708708 ) catch unreachable;
709709
710710 switch (case.special) {
......@@ -720,7 +720,7 @@ pub const CompareOutputContext = struct {
720720 for (case.sources.toSliceConst()) |src_file| {
721721 const expanded_src_path = fs.path.join(
722722 b.allocator,
723 [_][]const u8{ b.cache_root, src_file.filename },
723 &[_][]const u8{ b.cache_root, src_file.filename },
724724 ) catch unreachable;
725725 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
726726 exe.step.dependOn(&write_src.step);
......@@ -752,7 +752,7 @@ pub const CompareOutputContext = struct {
752752 for (case.sources.toSliceConst()) |src_file| {
753753 const expanded_src_path = fs.path.join(
754754 b.allocator,
755 [_][]const u8{ b.cache_root, src_file.filename },
755 &[_][]const u8{ b.cache_root, src_file.filename },
756756 ) catch unreachable;
757757 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
758758 exe.step.dependOn(&write_src.step);
......@@ -783,7 +783,7 @@ pub const CompareOutputContext = struct {
783783 for (case.sources.toSliceConst()) |src_file| {
784784 const expanded_src_path = fs.path.join(
785785 b.allocator,
786 [_][]const u8{ b.cache_root, src_file.filename },
786 &[_][]const u8{ b.cache_root, src_file.filename },
787787 ) catch unreachable;
788788 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
789789 exe.step.dependOn(&write_src.step);
......@@ -816,7 +816,7 @@ pub const StackTracesContext = struct {
816816
817817 const source_pathname = fs.path.join(
818818 b.allocator,
819 [_][]const u8{ b.cache_root, "source.zig" },
819 &[_][]const u8{ b.cache_root, "source.zig" },
820820 ) catch unreachable;
821821
822822 for (self.modes) |mode| {
......@@ -1073,7 +1073,7 @@ pub const CompileErrorContext = struct {
10731073
10741074 const root_src = fs.path.join(
10751075 b.allocator,
1076 [_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
1076 &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
10771077 ) catch unreachable;
10781078
10791079 var zig_args = ArrayList([]const u8).init(b.allocator);
......@@ -1270,7 +1270,7 @@ pub const CompileErrorContext = struct {
12701270 for (case.sources.toSliceConst()) |src_file| {
12711271 const expanded_src_path = fs.path.join(
12721272 b.allocator,
1273 [_][]const u8{ b.cache_root, src_file.filename },
1273 &[_][]const u8{ b.cache_root, src_file.filename },
12741274 ) catch unreachable;
12751275 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
12761276 compile_and_cmp_errors.step.dependOn(&write_src.step);
......@@ -1404,7 +1404,7 @@ pub const TranslateCContext = struct {
14041404
14051405 const root_src = fs.path.join(
14061406 b.allocator,
1407 [_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
1407 &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
14081408 ) catch unreachable;
14091409
14101410 var zig_args = ArrayList([]const u8).init(b.allocator);
......@@ -1577,7 +1577,7 @@ pub const TranslateCContext = struct {
15771577 for (case.sources.toSliceConst()) |src_file| {
15781578 const expanded_src_path = fs.path.join(
15791579 b.allocator,
1580 [_][]const u8{ b.cache_root, src_file.filename },
1580 &[_][]const u8{ b.cache_root, src_file.filename },
15811581 ) catch unreachable;
15821582 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
15831583 translate_c_and_cmp.step.dependOn(&write_src.step);
......@@ -1700,7 +1700,7 @@ pub const GenHContext = struct {
17001700 const b = self.b;
17011701 const root_src = fs.path.join(
17021702 b.allocator,
1703 [_][]const u8{ b.cache_root, case.sources.items[0].filename },
1703 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
17041704 ) catch unreachable;
17051705
17061706 const mode = builtin.Mode.Debug;
......@@ -1715,7 +1715,7 @@ pub const GenHContext = struct {
17151715 for (case.sources.toSliceConst()) |src_file| {
17161716 const expanded_src_path = fs.path.join(
17171717 b.allocator,
1718 [_][]const u8{ b.cache_root, src_file.filename },
1718 &[_][]const u8{ b.cache_root, src_file.filename },
17191719 ) catch unreachable;
17201720 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
17211721 obj.step.dependOn(&write_src.step);