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 {...@@ -20,10 +20,10 @@ pub fn build(b: *Builder) !void {
20 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);20 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
21 const langref_out_path = fs.path.join(21 const langref_out_path = fs.path.join(
22 b.allocator,22 b.allocator,
23 [_][]const u8{ b.cache_root, "langref.html" },23 &[_][]const u8{ b.cache_root, "langref.html" },
24 ) catch unreachable;24 ) catch unreachable;
25 var docgen_cmd = docgen_exe.run();25 var docgen_cmd = docgen_exe.run();
26 docgen_cmd.addArgs([_][]const u8{26 docgen_cmd.addArgs(&[_][]const u8{
27 rel_zig_exe,27 rel_zig_exe,
28 "doc" ++ fs.path.sep_str ++ "langref.html.in",28 "doc" ++ fs.path.sep_str ++ "langref.html.in",
29 langref_out_path,29 langref_out_path,
...@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {...@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {
36 const test_step = b.step("test", "Run all the tests");36 const test_step = b.step("test", "Run all the tests");
3737
38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library38 // 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{
40 b.zig_exe,40 b.zig_exe,
41 "BUILD_INFO",41 "BUILD_INFO",
42 });42 });
...@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {...@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {
56 test_stage2.setBuildMode(builtin.Mode.Debug);56 test_stage2.setBuildMode(builtin.Mode.Debug);
57 test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");57 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
61 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");61 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
62 exe.setBuildMode(mode);62 exe.setBuildMode(mode);
...@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {...@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {
88 .source_dir = "lib",88 .source_dir = "lib",
89 .install_dir = .Lib,89 .install_dir = .Lib,
90 .install_subdir = "zig",90 .install_subdir = "zig",
91 .exclude_extensions = [_][]const u8{ "test.zig", "README.md" },91 .exclude_extensions = &[_][]const u8{ "test.zig", "README.md" },
92 });92 });
9393
94 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");94 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 {...@@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
148 }148 }
149 const lib_dir = fs.path.join(149 const lib_dir = fs.path.join(
150 b.allocator,150 b.allocator,
151 [_][]const u8{ dep.prefix, "lib" },151 &[_][]const u8{ dep.prefix, "lib" },
152 ) catch unreachable;152 ) catch unreachable;
153 for (dep.system_libs.toSliceConst()) |lib| {153 for (dep.system_libs.toSliceConst()) |lib| {
154 const static_bare_name = if (mem.eql(u8, lib, "curses"))154 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 {...@@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
157 b.fmt("lib{}.a", lib);157 b.fmt("lib{}.a", lib);
158 const static_lib_name = fs.path.join(158 const static_lib_name = fs.path.join(
159 b.allocator,159 b.allocator,
160 [_][]const u8{ lib_dir, static_bare_name },160 &[_][]const u8{ lib_dir, static_bare_name },
161 ) catch unreachable;161 ) catch unreachable;
162 const have_static = fileExists(static_lib_name) catch unreachable;162 const have_static = fileExists(static_lib_name) catch unreachable;
163 if (have_static) {163 if (have_static) {
...@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {...@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {
183}183}
184184
185fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {185fn 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{
187 cmake_binary_dir,187 cmake_binary_dir,
188 "zig_cpp",188 "zig_cpp",
189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
...@@ -199,22 +199,22 @@ const LibraryDep = struct {...@@ -199,22 +199,22 @@ const LibraryDep = struct {
199};199};
200200
201fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {201fn 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" });
203 const is_static = mem.startsWith(u8, shared_mode, "static");203 const is_static = mem.startsWith(u8, shared_mode, "static");
204 const libs_output = if (is_static)204 const libs_output = if (is_static)
205 try b.exec([_][]const u8{205 try b.exec(&[_][]const u8{
206 llvm_config_exe,206 llvm_config_exe,
207 "--libfiles",207 "--libfiles",
208 "--system-libs",208 "--system-libs",
209 })209 })
210 else210 else
211 try b.exec([_][]const u8{211 try b.exec(&[_][]const u8{
212 llvm_config_exe,212 llvm_config_exe,
213 "--libs",213 "--libs",
214 });214 });
215 const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });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" });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" });217 const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
218218
219 var result = LibraryDep{219 var result = LibraryDep{
220 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,220 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,
...@@ -341,7 +341,7 @@ fn addCxxKnownPath(...@@ -341,7 +341,7 @@ fn addCxxKnownPath(
341 objname: []const u8,341 objname: []const u8,
342 errtxt: ?[]const u8,342 errtxt: ?[]const u8,
343) !void {343) !void {
344 const path_padded = try b.exec([_][]const u8{344 const path_padded = try b.exec(&[_][]const u8{
345 ctx.cxx_compiler,345 ctx.cxx_compiler,
346 b.fmt("-print-file-name={}", objname),346 b.fmt("-print-file-name={}", objname),
347 });347 });
lib/std/array_list.zig+4-11
...@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {...@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
35 /// Deinitialize with `deinit` or use `toOwnedSlice`.35 /// Deinitialize with `deinit` or use `toOwnedSlice`.
36 pub fn init(allocator: *Allocator) Self {36 pub fn init(allocator: *Allocator) Self {
37 return Self{37 return Self{
38 .items = [_]T{},38 .items = &[_]T{},
39 .len = 0,39 .len = 0,
40 .allocator = allocator,40 .allocator = allocator,
41 };41 };
...@@ -306,18 +306,14 @@ test "std.ArrayList.basic" {...@@ -306,18 +306,14 @@ test "std.ArrayList.basic" {
306 testing.expect(list.pop() == 10);306 testing.expect(list.pop() == 10);
307 testing.expect(list.len == 9);307 testing.expect(list.len == 9);
308308
309 list.appendSlice([_]i32{309 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
310 1,
311 2,
312 3,
313 }) catch unreachable;
314 testing.expect(list.len == 12);310 testing.expect(list.len == 12);
315 testing.expect(list.pop() == 3);311 testing.expect(list.pop() == 3);
316 testing.expect(list.pop() == 2);312 testing.expect(list.pop() == 2);
317 testing.expect(list.pop() == 1);313 testing.expect(list.pop() == 1);
318 testing.expect(list.len == 9);314 testing.expect(list.len == 9);
319315
320 list.appendSlice([_]i32{}) catch unreachable;316 list.appendSlice(&[_]i32{}) catch unreachable;
321 testing.expect(list.len == 9);317 testing.expect(list.len == 9);
322318
323 // can only set on indices < self.len319 // can only set on indices < self.len
...@@ -464,10 +460,7 @@ test "std.ArrayList.insertSlice" {...@@ -464,10 +460,7 @@ test "std.ArrayList.insertSlice" {
464 try list.append(2);460 try list.append(2);
465 try list.append(3);461 try list.append(3);
466 try list.append(4);462 try list.append(4);
467 try list.insertSlice(1, [_]i32{463 try list.insertSlice(1, &[_]i32{ 9, 8 });
468 9,
469 8,
470 });
471 testing.expect(list.items[0] == 1);464 testing.expect(list.items[0] == 1);
472 testing.expect(list.items[1] == 9);465 testing.expect(list.items[1] == 9);
473 testing.expect(list.items[2] == 8);466 testing.expect(list.items[2] == 8);
lib/std/bloom_filter.zig+3-3
...@@ -62,7 +62,7 @@ pub fn BloomFilter(...@@ -62,7 +62,7 @@ pub fn BloomFilter(
62 }62 }
6363
64 pub fn getCell(self: Self, cell: Index) Cell {64 pub fn getCell(self: Self, cell: Index) Cell {
65 return Io.get(self.data, cell, 0);65 return Io.get(&self.data, cell, 0);
66 }66 }
6767
68 pub fn incrementCell(self: *Self, cell: Index) void {68 pub fn incrementCell(self: *Self, cell: Index) void {
...@@ -70,7 +70,7 @@ pub fn BloomFilter(...@@ -70,7 +70,7 @@ pub fn BloomFilter(
70 // skip the 'get' operation70 // skip the 'get' operation
71 Io.set(&self.data, cell, 0, cellMax);71 Io.set(&self.data, cell, 0, cellMax);
72 } else {72 } else {
73 const old = Io.get(self.data, cell, 0);73 const old = Io.get(&self.data, cell, 0);
74 if (old != cellMax) {74 if (old != cellMax) {
75 Io.set(&self.data, cell, 0, old + 1);75 Io.set(&self.data, cell, 0, old + 1);
76 }76 }
...@@ -120,7 +120,7 @@ pub fn BloomFilter(...@@ -120,7 +120,7 @@ pub fn BloomFilter(
120 } else if (newsize > n_items) {120 } else if (newsize > n_items) {
121 var copied: usize = 0;121 var copied: usize = 0;
122 while (copied < r.data.len) : (copied += self.data.len) {122 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);
124 }124 }
125 }125 }
126 return r;126 return r;
lib/std/build.zig+30-27
...@@ -186,7 +186,7 @@ pub const Builder = struct {...@@ -186,7 +186,7 @@ pub const Builder = struct {
186 pub fn resolveInstallPrefix(self: *Builder) void {186 pub fn resolveInstallPrefix(self: *Builder) void {
187 if (self.dest_dir) |dest_dir| {187 if (self.dest_dir) |dest_dir| {
188 const install_prefix = self.install_prefix orelse "/usr";188 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;
190 } else {190 } else {
191 const install_prefix = self.install_prefix orelse blk: {191 const install_prefix = self.install_prefix orelse blk: {
192 const p = self.cache_root;192 const p = self.cache_root;
...@@ -195,8 +195,8 @@ pub const Builder = struct {...@@ -195,8 +195,8 @@ pub const Builder = struct {
195 };195 };
196 self.install_path = install_prefix;196 self.install_path = install_prefix;
197 }197 }
198 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) 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;199 self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
200 }200 }
201201
202 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {202 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
...@@ -803,7 +803,7 @@ pub const Builder = struct {...@@ -803,7 +803,7 @@ pub const Builder = struct {
803 }803 }
804804
805 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {805 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;
807 }807 }
808808
809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
...@@ -818,7 +818,7 @@ pub const Builder = struct {...@@ -818,7 +818,7 @@ pub const Builder = struct {
818 if (fs.path.isAbsolute(name)) {818 if (fs.path.isAbsolute(name)) {
819 return name;819 return name;
820 }820 }
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) });
822 return fs.realpathAlloc(self.allocator, full_path) catch continue;822 return fs.realpathAlloc(self.allocator, full_path) catch continue;
823 }823 }
824 }824 }
...@@ -827,9 +827,9 @@ pub const Builder = struct {...@@ -827,9 +827,9 @@ pub const Builder = struct {
827 if (fs.path.isAbsolute(name)) {827 if (fs.path.isAbsolute(name)) {
828 return name;828 return name;
829 }829 }
830 var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter});830 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
831 while (it.next()) |path| {831 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) });
833 return fs.realpathAlloc(self.allocator, full_path) catch continue;833 return fs.realpathAlloc(self.allocator, full_path) catch continue;
834 }834 }
835 }835 }
...@@ -839,7 +839,7 @@ pub const Builder = struct {...@@ -839,7 +839,7 @@ pub const Builder = struct {
839 return name;839 return name;
840 }840 }
841 for (paths) |path| {841 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) });
843 return fs.realpathAlloc(self.allocator, full_path) catch continue;843 return fs.realpathAlloc(self.allocator, full_path) catch continue;
844 }844 }
845 }845 }
...@@ -926,12 +926,12 @@ pub const Builder = struct {...@@ -926,12 +926,12 @@ pub const Builder = struct {
926 };926 };
927 return fs.path.resolve(927 return fs.path.resolve(
928 self.allocator,928 self.allocator,
929 [_][]const u8{ base_dir, dest_rel_path },929 &[_][]const u8{ base_dir, dest_rel_path },
930 ) catch unreachable;930 ) catch unreachable;
931 }931 }
932932
933 fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {933 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);
935 var list = ArrayList(PkgConfigPkg).init(self.allocator);935 var list = ArrayList(PkgConfigPkg).init(self.allocator);
936 var line_it = mem.tokenize(stdout, "\r\n");936 var line_it = mem.tokenize(stdout, "\r\n");
937 while (line_it.next()) |line| {937 while (line_it.next()) |line| {
...@@ -970,7 +970,7 @@ pub const Builder = struct {...@@ -970,7 +970,7 @@ pub const Builder = struct {
970970
971test "builder.findProgram compiles" {971test "builder.findProgram compiles" {
972 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");972 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;
974}974}
975975
976/// Deprecated. Use `builtin.Version`.976/// Deprecated. Use `builtin.Version`.
...@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {...@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {
1384 };1384 };
13851385
1386 var code: u8 = undefined;1386 var code: u8 = undefined;
1387 const stdout = if (self.builder.execAllowFail([_][]const u8{1387 const stdout = if (self.builder.execAllowFail(&[_][]const u8{
1388 "pkg-config",1388 "pkg-config",
1389 pkg_name,1389 pkg_name,
1390 "--cflags",1390 "--cflags",
...@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {...@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {
1504 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {1504 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1505 return fs.path.join(1505 return fs.path.join(
1506 self.builder.allocator,1506 self.builder.allocator,
1507 [_][]const u8{ self.output_dir.?, self.out_filename },1507 &[_][]const u8{ self.output_dir.?, self.out_filename },
1508 ) catch unreachable;1508 ) catch unreachable;
1509 }1509 }
15101510
...@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {...@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {
1514 assert(self.kind == Kind.Lib);1514 assert(self.kind == Kind.Lib);
1515 return fs.path.join(1515 return fs.path.join(
1516 self.builder.allocator,1516 self.builder.allocator,
1517 [_][]const u8{ self.output_dir.?, self.out_lib_filename },1517 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
1518 ) catch unreachable;1518 ) catch unreachable;
1519 }1519 }
15201520
...@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {...@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {
1525 assert(!self.disable_gen_h);1525 assert(!self.disable_gen_h);
1526 return fs.path.join(1526 return fs.path.join(
1527 self.builder.allocator,1527 self.builder.allocator,
1528 [_][]const u8{ self.output_dir.?, self.out_h_filename },1528 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
1529 ) catch unreachable;1529 ) catch unreachable;
1530 }1530 }
15311531
...@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {...@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {
1535 assert(self.target.isWindows() or self.target.isUefi());1535 assert(self.target.isWindows() or self.target.isUefi());
1536 return fs.path.join(1536 return fs.path.join(
1537 self.builder.allocator,1537 self.builder.allocator,
1538 [_][]const u8{ self.output_dir.?, self.out_pdb_filename },1538 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
1539 ) catch unreachable;1539 ) catch unreachable;
1540 }1540 }
15411541
...@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {...@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {
1605 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);1605 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
1606 defer self.builder.allocator.free(triplet);1606 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" });
1609 errdefer allocator.free(include_path);1609 errdefer allocator.free(include_path);
1610 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });1610 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" });
1613 try self.lib_paths.append(lib_path);1613 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" });
1616 },1616 },
1617 }1617 }
1618 }1618 }
...@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {...@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {
1725 if (self.build_options_contents.len() > 0) {1725 if (self.build_options_contents.len() > 0) {
1726 const build_options_file = try fs.path.join(1726 const build_options_file = try fs.path.join(
1727 builder.allocator,1727 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) },
1729 );1729 );
1730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());1730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
1731 try zig_args.append("--pkg-begin");1731 try zig_args.append("--pkg-begin");
...@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {...@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {
1849 try zig_args.append("--test-cmd");1849 try zig_args.append("--test-cmd");
1850 try zig_args.append(bin_name);1850 try zig_args.append(bin_name);
1851 if (glibc_dir_arg) |dir| {1851 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{
1853 dir,1853 dir,
1854 try self.target.linuxTriple(builder.allocator),1854 try self.target.linuxTriple(builder.allocator),
1855 });1855 });
...@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {...@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {
1994 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");1994 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
19951995
1996 if (self.output_dir) |output_dir| {1996 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{
1998 output_dir,1998 output_dir,
1999 fs.path.basename(output_path),1999 fs.path.basename(output_path),
2000 });2000 });
...@@ -2068,7 +2068,7 @@ pub const RunStep = struct {...@@ -2068,7 +2068,7 @@ pub const RunStep = struct {
2068 env_map.set(PATH, search_path) catch unreachable;2068 env_map.set(PATH, search_path) catch unreachable;
2069 return;2069 return;
2070 };2070 };
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);
2072 env_map.set(PATH, new_path) catch unreachable;2072 env_map.set(PATH, new_path) catch unreachable;
2073 }2073 }
20742074
...@@ -2162,6 +2162,9 @@ const InstallArtifactStep = struct {...@@ -2162,6 +2162,9 @@ const InstallArtifactStep = struct {
2162 if (self.artifact.isDynamicLibrary()) {2162 if (self.artifact.isDynamicLibrary()) {
2163 builder.pushInstalledFile(.Lib, artifact.major_only_filename);2163 builder.pushInstalledFile(.Lib, artifact.major_only_filename);
2164 builder.pushInstalledFile(.Lib, artifact.name_only_filename);2164 builder.pushInstalledFile(.Lib, artifact.name_only_filename);
2165 if (self.artifact.target.isWindows()) {
2166 builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
2167 }
2165 }2168 }
2166 if (self.pdb_dir) |pdb_dir| {2169 if (self.pdb_dir) |pdb_dir| {
2167 builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);2170 builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
...@@ -2254,7 +2257,7 @@ pub const InstallDirStep = struct {...@@ -2254,7 +2257,7 @@ pub const InstallDirStep = struct {
2254 };2257 };
22552258
2256 const rel_path = entry.path[full_src_dir.len + 1 ..];2259 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 });
2258 switch (entry.kind) {2261 switch (entry.kind) {
2259 .Directory => try fs.makePath(self.builder.allocator, dest_path),2262 .Directory => try fs.makePath(self.builder.allocator, dest_path),
2260 .File => try self.builder.updateFile(entry.path, dest_path),2263 .File => try self.builder.updateFile(entry.path, dest_path),
...@@ -2377,7 +2380,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj...@@ -2377,7 +2380,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
2377 // sym link for libfoo.so.1 to libfoo.so.1.2.32380 // sym link for libfoo.so.1 to libfoo.so.1.2.3
2378 const major_only_path = fs.path.join(2381 const major_only_path = fs.path.join(
2379 allocator,2382 allocator,
2380 [_][]const u8{ out_dir, filename_major_only },2383 &[_][]const u8{ out_dir, filename_major_only },
2381 ) catch unreachable;2384 ) catch unreachable;
2382 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {2385 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
2383 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);2386 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
...@@ -2386,7 +2389,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj...@@ -2386,7 +2389,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
2386 // sym link for libfoo.so to libfoo.so.12389 // sym link for libfoo.so to libfoo.so.1
2387 const name_only_path = fs.path.join(2390 const name_only_path = fs.path.join(
2388 allocator,2391 allocator,
2389 [_][]const u8{ out_dir, filename_name_only },2392 &[_][]const u8{ out_dir, filename_name_only },
2390 ) catch unreachable;2393 ) catch unreachable;
2391 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {2394 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2392 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);2395 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
...@@ -2399,7 +2402,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {...@@ -2399,7 +2402,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
2399 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");2402 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
2400 defer allocator.free(appdata_path);2403 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" });
2403 defer allocator.free(path_file);2406 defer allocator.free(path_file);
24042407
2405 const file = fs.File.openRead(path_file) catch return null;2408 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 {...@@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type {
136136
137 pub fn init(key: [keysize / 8]u8) Self {137 pub fn init(key: [keysize / 8]u8) Self {
138 var ctx: Self = undefined;138 var ctx: Self = undefined;
139 expandKey(key, ctx.enc[0..], ctx.dec[0..]);139 expandKey(&key, ctx.enc[0..], ctx.dec[0..]);
140 return ctx;140 return ctx;
141 }141 }
142142
...@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {...@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {
157 var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);157 var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);
158 std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1);158 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);
161 }161 }
162 }162 }
163 };163 };
lib/std/crypto/blake2.zig+2-2
...@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {...@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {
256 var out: [Blake2s256.digest_length]u8 = undefined;256 var out: [Blake2s256.digest_length]u8 = undefined;
257257
258 var h = Blake2s256.init();258 var h = Blake2s256.init();
259 h.update(block);259 h.update(&block);
260 h.final(out[0..]);260 h.final(out[0..]);
261}261}
262262
...@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {...@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {
490 var out: [Blake2b512.digest_length]u8 = undefined;490 var out: [Blake2b512.digest_length]u8 = undefined;
491491
492 var h = Blake2b512.init();492 var h = Blake2b512.init();
493 h.update(block);493 h.update(&block);
494 h.final(out[0..]);494 h.final(out[0..]);
495}495}
lib/std/crypto/chacha20.zig+7-7
...@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {...@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {
218 };218 };
219219
220 chaCha20IETF(result[0..], input[0..], 1, key, nonce);220 chaCha20IETF(result[0..], input[0..], 1, key, nonce);
221 testing.expectEqualSlices(u8, expected_result, result);221 testing.expectEqualSlices(u8, &expected_result, &result);
222222
223 // Chacha20 is self-reversing.223 // Chacha20 is self-reversing.
224 var plaintext: [114]u8 = undefined;224 var plaintext: [114]u8 = undefined;
225 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);225 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);
227}227}
228228
229// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7229// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
...@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {...@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {
258 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };258 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
259259
260 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);260 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
261 testing.expectEqualSlices(u8, expected_result, result);261 testing.expectEqualSlices(u8, &expected_result, &result);
262}262}
263263
264test "crypto.chacha20 test vector 2" {264test "crypto.chacha20 test vector 2" {
...@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {...@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {
292 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };292 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
293293
294 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);294 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
295 testing.expectEqualSlices(u8, expected_result, result);295 testing.expectEqualSlices(u8, &expected_result, &result);
296}296}
297297
298test "crypto.chacha20 test vector 3" {298test "crypto.chacha20 test vector 3" {
...@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {...@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {
326 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };326 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
327327
328 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);328 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
329 testing.expectEqualSlices(u8, expected_result, result);329 testing.expectEqualSlices(u8, &expected_result, &result);
330}330}
331331
332test "crypto.chacha20 test vector 4" {332test "crypto.chacha20 test vector 4" {
...@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {...@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {
360 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };360 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
361361
362 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);362 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
363 testing.expectEqualSlices(u8, expected_result, result);363 testing.expectEqualSlices(u8, &expected_result, &result);
364}364}
365365
366test "crypto.chacha20 test vector 5" {366test "crypto.chacha20 test vector 5" {
...@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {...@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {
432 };432 };
433433
434 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);434 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
435 testing.expectEqualSlices(u8, expected_result, result);435 testing.expectEqualSlices(u8, &expected_result, &result);
436}436}
lib/std/crypto/gimli.zig+4-4
...@@ -83,7 +83,7 @@ test "permute" {...@@ -83,7 +83,7 @@ test "permute" {
83 while (i < 12) : (i += 1) {83 while (i < 12) : (i += 1) {
84 input[i] = i * i * i + i *% 0x9e3779b9;84 input[i] = i * i * i + i *% 0x9e3779b9;
85 }85 }
86 testing.expectEqualSlices(u32, input, [_]u32{86 testing.expectEqualSlices(u32, &input, &[_]u32{
87 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,87 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,
88 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,88 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,
89 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,89 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,
...@@ -92,7 +92,7 @@ test "permute" {...@@ -92,7 +92,7 @@ test "permute" {
92 },92 },
93 };93 };
94 state.permute();94 state.permute();
95 testing.expectEqualSlices(u32, state.data, [_]u32{95 testing.expectEqualSlices(u32, &state.data, &[_]u32{
96 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,96 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,
97 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,97 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,
98 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,98 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,
...@@ -163,6 +163,6 @@ test "hash" {...@@ -163,6 +163,6 @@ test "hash" {
163 var msg: [58 / 2]u8 = undefined;163 var msg: [58 / 2]u8 = undefined;
164 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");164 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
165 var md: [32]u8 = undefined;165 var md: [32]u8 = undefined;
166 hash(&md, msg);166 hash(&md, &msg);
167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", md);167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
168}168}
lib/std/crypto/md5.zig+1-1
...@@ -276,6 +276,6 @@ test "md5 aligned final" {...@@ -276,6 +276,6 @@ test "md5 aligned final" {
276 var out: [Md5.digest_length]u8 = undefined;276 var out: [Md5.digest_length]u8 = undefined;
277277
278 var h = Md5.init();278 var h = Md5.init();
279 h.update(block);279 h.update(&block);
280 h.final(out[0..]);280 h.final(out[0..]);
281}281}
lib/std/crypto/poly1305.zig+1-1
...@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {...@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
230 var mac: [16]u8 = undefined;230 var mac: [16]u8 = undefined;
231 Poly1305.create(mac[0..], msg, key);231 Poly1305.create(mac[0..], msg, key);
232232
233 std.testing.expectEqualSlices(u8, expected_mac, mac);233 std.testing.expectEqualSlices(u8, expected_mac, &mac);
234}234}
lib/std/crypto/sha1.zig+1-1
...@@ -297,6 +297,6 @@ test "sha1 aligned final" {...@@ -297,6 +297,6 @@ test "sha1 aligned final" {
297 var out: [Sha1.digest_length]u8 = undefined;297 var out: [Sha1.digest_length]u8 = undefined;
298298
299 var h = Sha1.init();299 var h = Sha1.init();
300 h.update(block);300 h.update(&block);
301 h.final(out[0..]);301 h.final(out[0..]);
302}302}
lib/std/crypto/sha2.zig+2-2
...@@ -343,7 +343,7 @@ test "sha256 aligned final" {...@@ -343,7 +343,7 @@ test "sha256 aligned final" {
343 var out: [Sha256.digest_length]u8 = undefined;343 var out: [Sha256.digest_length]u8 = undefined;
344344
345 var h = Sha256.init();345 var h = Sha256.init();
346 h.update(block);346 h.update(&block);
347 h.final(out[0..]);347 h.final(out[0..]);
348}348}
349349
...@@ -723,6 +723,6 @@ test "sha512 aligned final" {...@@ -723,6 +723,6 @@ test "sha512 aligned final" {
723 var out: [Sha512.digest_length]u8 = undefined;723 var out: [Sha512.digest_length]u8 = undefined;
724724
725 var h = Sha512.init();725 var h = Sha512.init();
726 h.update(block);726 h.update(&block);
727 h.final(out[0..]);727 h.final(out[0..]);
728}728}
lib/std/crypto/sha3.zig+2-2
...@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {...@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {
229 var out: [Sha3_256.digest_length]u8 = undefined;229 var out: [Sha3_256.digest_length]u8 = undefined;
230230
231 var h = Sha3_256.init();231 var h = Sha3_256.init();
232 h.update(block);232 h.update(&block);
233 h.final(out[0..]);233 h.final(out[0..]);
234}234}
235235
...@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {...@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {
300 var out: [Sha3_512.digest_length]u8 = undefined;300 var out: [Sha3_512.digest_length]u8 = undefined;
301301
302 var h = Sha3_512.init();302 var h = Sha3_512.init();
303 h.update(block);303 h.update(&block);
304 h.final(out[0..]);304 h.final(out[0..]);
305}305}
lib/std/crypto/test.zig+2-2
...@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu...@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
8 var h: [expected.len / 2]u8 = undefined;8 var h: [expected.len / 2]u8 = undefined;
9 Hasher.hash(input, h[0..]);9 Hasher.hash(input, h[0..]);
1010
11 assertEqual(expected, h);11 assertEqual(expected, &h);
12}12}
1313
14// Assert `expected` == `input` where `input` is a bytestring.14// Assert `expected` == `input` where `input` is a bytestring.
...@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {...@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
18 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;18 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
19 }19 }
2020
21 testing.expectEqualSlices(u8, expected_bytes, input);21 testing.expectEqualSlices(u8, &expected_bytes, input);
22}22}
lib/std/crypto/x25519.zig+18-18
...@@ -63,7 +63,7 @@ pub const X25519 = struct {...@@ -63,7 +63,7 @@ pub const X25519 = struct {
63 var pos: isize = 254;63 var pos: isize = 254;
64 while (pos >= 0) : (pos -= 1) {64 while (pos >= 0) : (pos -= 1) {
65 // constant time conditional swap before ladder step65 // constant time conditional swap before ladder step
66 const b = scalarBit(e, @intCast(usize, pos));66 const b = scalarBit(&e, @intCast(usize, pos));
67 swap ^= b; // xor trick avoids swapping at the end of the loop67 swap ^= b; // xor trick avoids swapping at the end of the loop
68 Fe.cswap(x2, x3, swap);68 Fe.cswap(x2, x3, swap);
69 Fe.cswap(z2, z3, swap);69 Fe.cswap(z2, z3, swap);
...@@ -117,7 +117,7 @@ pub const X25519 = struct {...@@ -117,7 +117,7 @@ pub const X25519 = struct {
117117
118 pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {118 pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
119 var base_point = [_]u8{9} ++ [_]u8{0} ** 31;119 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);
121 }121 }
122};122};
123123
...@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {...@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
581 var pk_calculated: [32]u8 = undefined;581 var pk_calculated: [32]u8 = undefined;
582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], &sk));
585 std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));585 std.testing.expect(std.mem.eql(u8, &pk_calculated, &pk_expected));
586}586}
587587
588test "x25519 rfc7748 vector1" {588test "x25519 rfc7748 vector1" {
...@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {...@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {
594 var output: [32]u8 = undefined;594 var output: [32]u8 = undefined;
595595
596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));596 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));
598}598}
599599
600test "x25519 rfc7748 vector2" {600test "x25519 rfc7748 vector2" {
...@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {...@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {
606 var output: [32]u8 = undefined;606 var output: [32]u8 = undefined;
607607
608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));608 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));
610}610}
611611
612test "x25519 rfc7748 one iteration" {612test "x25519 rfc7748 one iteration" {
613 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".*;613 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
616 var k: [32]u8 = initial_value;616 var k: [32]u8 = initial_value;
617 var u: [32]u8 = initial_value;617 var u: [32]u8 = initial_value;
...@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {...@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {
619 var i: usize = 0;619 var i: usize = 0;
620 while (i < 1) : (i += 1) {620 while (i < 1) : (i += 1) {
621 var output: [32]u8 = undefined;621 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
624 std.mem.copy(u8, u[0..], k[0..]);624 std.mem.copy(u8, u[0..], k[0..]);
625 std.mem.copy(u8, k[0..], output[0..]);625 std.mem.copy(u8, k[0..], output[0..]);
...@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {
634 return error.SkipZigTest;634 return error.SkipZigTest;
635 }635 }
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".*;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".*;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;640 var k: [32]u8 = initial_value.*;
641 var u: [32]u8 = initial_value;641 var u: [32]u8 = initial_value.*;
642642
643 var i: usize = 0;643 var i: usize = 0;
644 while (i < 1000) : (i += 1) {644 while (i < 1000) : (i += 1) {
645 var output: [32]u8 = undefined;645 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
648 std.mem.copy(u8, u[0..], k[0..]);648 std.mem.copy(u8, u[0..], k[0..]);
649 std.mem.copy(u8, k[0..], output[0..]);649 std.mem.copy(u8, k[0..], output[0..]);
...@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {
657 return error.SkipZigTest;657 return error.SkipZigTest;
658 }658 }
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".*;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".*;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;663 var k: [32]u8 = initial_value.*;
664 var u: [32]u8 = initial_value;664 var u: [32]u8 = initial_value.*;
665665
666 var i: usize = 0;666 var i: usize = 0;
667 while (i < 1000000) : (i += 1) {667 while (i < 1000000) : (i += 1) {
668 var output: [32]u8 = undefined;668 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
671 std.mem.copy(u8, u[0..], k[0..]);671 std.mem.copy(u8, u[0..], k[0..]);
672 std.mem.copy(u8, k[0..], output[0..]);672 std.mem.copy(u8, k[0..], output[0..]);
lib/std/debug.zig+1-1
...@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {...@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {
1916 return error.InvalidDebugInfo;1916 return error.InvalidDebugInfo;
1917 } else1917 } else
1918 self.include_dirs[file_entry.dir_index];1918 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 });
1920 errdefer self.file_entries.allocator.free(file_name);1920 errdefer self.file_entries.allocator.free(file_name);
1921 return LineInfo{1921 return LineInfo{
1922 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,1922 .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 {...@@ -381,7 +381,7 @@ pub const Elf = struct {
381381
382 var magic: [4]u8 = undefined;382 var magic: [4]u8 = undefined;
383 try in.readNoEof(magic[0..]);383 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
386 elf.is_64 = switch (try in.readByte()) {386 elf.is_64 = switch (try in.readByte()) {
387 1 => false,387 1 => false,
lib/std/event/loop.zig+2-2
...@@ -237,7 +237,7 @@ pub const Loop = struct {...@@ -237,7 +237,7 @@ pub const Loop = struct {
237 var extra_thread_index: usize = 0;237 var extra_thread_index: usize = 0;
238 errdefer {238 errdefer {
239 // writing 8 bytes to an eventfd cannot fail239 // 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;
241 while (extra_thread_index != 0) {241 while (extra_thread_index != 0) {
242 extra_thread_index -= 1;242 extra_thread_index -= 1;
243 self.extra_threads[extra_thread_index].wait();243 self.extra_threads[extra_thread_index].wait();
...@@ -684,7 +684,7 @@ pub const Loop = struct {...@@ -684,7 +684,7 @@ pub const Loop = struct {
684 .linux => {684 .linux => {
685 self.posixFsRequest(&self.os_data.fs_end_request);685 self.posixFsRequest(&self.os_data.fs_end_request);
686 // writing 8 bytes to an eventfd cannot fail686 // 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;
688 return;688 return;
689 },689 },
690 .macosx, .freebsd, .netbsd, .dragonfly => {690 .macosx, .freebsd, .netbsd, .dragonfly => {
lib/std/fifo.zig+5-5
...@@ -70,7 +70,7 @@ pub fn LinearFifo(...@@ -70,7 +70,7 @@ pub fn LinearFifo(
70 pub fn init(allocator: *Allocator) Self {70 pub fn init(allocator: *Allocator) Self {
71 return .{71 return .{
72 .allocator = allocator,72 .allocator = allocator,
73 .buf = [_]T{},73 .buf = &[_]T{},
74 .head = 0,74 .head = 0,
75 .count = 0,75 .count = 0,
76 };76 };
...@@ -143,7 +143,7 @@ pub fn LinearFifo(...@@ -143,7 +143,7 @@ pub fn LinearFifo(
143143
144 /// Returns a writable slice from the 'read' end of the fifo144 /// Returns a writable slice from the 'read' end of the fifo
145 fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {145 fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {
146 if (offset > self.count) return [_]T{};146 if (offset > self.count) return &[_]T{};
147147
148 var start = self.head + offset;148 var start = self.head + offset;
149 if (start >= self.buf.len) {149 if (start >= self.buf.len) {
...@@ -223,7 +223,7 @@ pub fn LinearFifo(...@@ -223,7 +223,7 @@ pub fn LinearFifo(
223 /// Returns the first section of writable buffer223 /// Returns the first section of writable buffer
224 /// Note that this may be of length 0224 /// Note that this may be of length 0
225 pub fn writableSlice(self: SliceSelfArg, offset: usize) []T {225 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
228 const tail = self.head + offset + self.count;228 const tail = self.head + offset + self.count;
229 if (tail < self.buf.len) {229 if (tail < self.buf.len) {
...@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {
357 {357 {
358 var i: usize = 0;358 var i: usize = 0;
359 while (i < 5) : (i += 1) {359 while (i < 5) : (i += 1) {
360 try fifo.write([_]u8{try fifo.peekItem(i)});360 try fifo.write(&[_]u8{try fifo.peekItem(i)});
361 }361 }
362 testing.expectEqual(@as(usize, 10), fifo.readableLength());362 testing.expectEqual(@as(usize, 10), fifo.readableLength());
363 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));363 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
...@@ -426,7 +426,7 @@ test "LinearFifo" {...@@ -426,7 +426,7 @@ test "LinearFifo" {
426 };426 };
427 defer fifo.deinit();427 defer fifo.deinit();
428428
429 try fifo.write([_]T{ 0, 1, 1, 0, 1 });429 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
430 testing.expectEqual(@as(usize, 5), fifo.readableLength());430 testing.expectEqual(@as(usize, 5), fifo.readableLength());
431431
432 {432 {
lib/std/fmt.zig+15-10
...@@ -451,13 +451,18 @@ pub fn formatType(...@@ -451,13 +451,18 @@ pub fn formatType(
451 },451 },
452 },452 },
453 .Array => |info| {453 .Array => |info| {
454 if (info.child == u8) {454 const Slice = @Type(builtin.TypeInfo{
455 return formatText(value, fmt, options, context, Errors, output);455 .Pointer = .{
456 }456 .size = .Slice,
457 if (value.len == 0) {457 .is_const = true,
458 return format(context, Errors, output, "[0]{}", @typeName(T.Child));458 .is_volatile = false,
459 }459 .is_allowzero = false,
460 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));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);
461 },466 },
462 .Fn => {467 .Fn => {
463 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));468 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
...@@ -872,8 +877,8 @@ pub fn formatBytes(...@@ -872,8 +877,8 @@ pub fn formatBytes(
872 }877 }
873878
874 const buf = switch (radix) {879 const buf = switch (radix) {
875 1000 => [_]u8{ suffix, 'B' },880 1000 => &[_]u8{ suffix, 'B' },
876 1024 => [_]u8{ suffix, 'i', 'B' },881 1024 => &[_]u8{ suffix, 'i', 'B' },
877 else => unreachable,882 else => unreachable,
878 };883 };
879 return output(context, buf);884 return output(context, buf);
...@@ -969,7 +974,7 @@ fn formatIntUnsigned(...@@ -969,7 +974,7 @@ fn formatIntUnsigned(
969 if (leftover_padding == 0) break;974 if (leftover_padding == 0) break;
970 }975 }
971 mem.set(u8, buf[0..index], options.fill);976 mem.set(u8, buf[0..index], options.fill);
972 return output(context, buf);977 return output(context, &buf);
973 } else {978 } else {
974 const padded_buf = buf[index - padding ..];979 const padded_buf = buf[index - padding ..];
975 mem.set(u8, padded_buf[0..padding], options.fill);980 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:...@@ -60,7 +60,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
60 tmp_path[dirname.len] = path.sep;60 tmp_path[dirname.len] = path.sep;
61 while (true) {61 while (true) {
62 try crypto.randomBytes(rand_buf[0..]);62 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
65 if (symLink(existing_path, tmp_path)) {65 if (symLink(existing_path, tmp_path)) {
66 return rename(tmp_path, new_path);66 return rename(tmp_path, new_path);
...@@ -226,7 +226,7 @@ pub const AtomicFile = struct {...@@ -226,7 +226,7 @@ pub const AtomicFile = struct {
226226
227 while (true) {227 while (true) {
228 try crypto.randomBytes(rand_buf[0..]);228 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
231 const file = File.openWriteNoClobberC(@ptrCast([*:0]u8, &tmp_path_buf), mode) catch |err| switch (err) {231 const file = File.openWriteNoClobberC(@ptrCast([*:0]u8, &tmp_path_buf), mode) catch |err| switch (err) {
232 error.PathAlreadyExists => continue,232 error.PathAlreadyExists => continue,
...@@ -290,7 +290,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {...@@ -290,7 +290,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {
290/// have been modified regardless.290/// have been modified regardless.
291/// TODO determine if we can remove the allocator requirement from this function291/// TODO determine if we can remove the allocator requirement from this function
292pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {292pub 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});
294 defer allocator.free(resolved_path);294 defer allocator.free(resolved_path);
295295
296 var end_index: usize = resolved_path.len;296 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...@@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
31 error.OutOfMemory => return error.OutOfMemory,31 error.OutOfMemory => return error.OutOfMemory,
32 };32 };
33 defer allocator.free(global_dir);33 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 });
35 },35 },
36 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,36 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
37 else => return error.AppDataDirUnavailable,37 else => return error.AppDataDirUnavailable,
...@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
42 // TODO look in /etc/passwd42 // TODO look in /etc/passwd
43 return error.AppDataDirUnavailable;43 return error.AppDataDirUnavailable;
44 };44 };
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 });
46 },46 },
47 .linux, .freebsd, .netbsd, .dragonfly => {47 .linux, .freebsd, .netbsd, .dragonfly => {
48 const home_dir = os.getenv("HOME") orelse {48 const home_dir = os.getenv("HOME") orelse {
49 // TODO look in /etc/passwd49 // TODO look in /etc/passwd
50 return error.AppDataDirUnavailable;50 return error.AppDataDirUnavailable;
51 };51 };
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 });
53 },53 },
54 else => @compileError("Unsupported OS"),54 else => @compileError("Unsupported OS"),
55 }55 }
lib/std/fs/path.zig+62-60
...@@ -15,7 +15,9 @@ pub const sep_windows = '\\';...@@ -15,7 +15,9 @@ pub const sep_windows = '\\';
15pub const sep_posix = '/';15pub const sep_posix = '/';
16pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;16pub 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
20pub const delimiter_windows = ';';22pub const delimiter_windows = ';';
21pub const delimiter_posix = ':';23pub const delimiter_posix = ':';
...@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {...@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
101}103}
102104
103test "join" {105test "join" {
104 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");106 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
105 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");107 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
106 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");110 testJoinWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
109 testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");111 testJoinWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
110112
111 testJoinWindows(113 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" },
113 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",115 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
114 );116 );
115117
116 testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");118 testJoinPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
117 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");121 testJoinPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
120 testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");122 testJoinPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
121123
122 testJoinPosix(124 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" },
124 "/home/andy/dev/zig/build/lib/zig/std/io.zig",126 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
125 );127 );
126128
127 testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");129 testJoinPosix(&[_][]const u8{ "a", "/c" }, "a/c");
128 testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");130 testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
129}131}
130132
131pub fn isAbsolute(path: []const u8) bool {133pub fn isAbsolute(path: []const u8) bool {
...@@ -246,7 +248,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -246,7 +248,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
246 }248 }
247 const relative_path = WindowsPath{249 const relative_path = WindowsPath{
248 .kind = WindowsPath.Kind.None,250 .kind = WindowsPath.Kind.None,
249 .disk_designator = [_]u8{},251 .disk_designator = &[_]u8{},
250 .is_abs = false,252 .is_abs = false,
251 };253 };
252 if (path.len < "//a/b".len) {254 if (path.len < "//a/b".len) {
...@@ -255,12 +257,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -255,12 +257,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
255257
256 inline for ("/\\") |this_sep| {258 inline for ("/\\") |this_sep| {
257 const two_sep = [_]u8{ this_sep, this_sep };259 const two_sep = [_]u8{ this_sep, this_sep };
258 if (mem.startsWith(u8, path, two_sep)) {260 if (mem.startsWith(u8, path, &two_sep)) {
259 if (path[2] == this_sep) {261 if (path[2] == this_sep) {
260 return relative_path;262 return relative_path;
261 }263 }
262264
263 var it = mem.tokenize(path, [_]u8{this_sep});265 var it = mem.tokenize(path, &[_]u8{this_sep});
264 _ = (it.next() orelse return relative_path);266 _ = (it.next() orelse return relative_path);
265 _ = (it.next() orelse return relative_path);267 _ = (it.next() orelse return relative_path);
266 return WindowsPath{268 return WindowsPath{
...@@ -322,8 +324,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {...@@ -322,8 +324,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
322 const sep1 = ns1[0];324 const sep1 = ns1[0];
323 const sep2 = ns2[0];325 const sep2 = ns2[0];
324326
325 var it1 = mem.tokenize(ns1, [_]u8{sep1});327 var it1 = mem.tokenize(ns1, &[_]u8{sep1});
326 var it2 = mem.tokenize(ns2, [_]u8{sep2});328 var it2 = mem.tokenize(ns2, &[_]u8{sep2});
327329
328 // TODO ASCII is wrong, we actually need full unicode support to compare paths.330 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
329 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);331 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
...@@ -343,8 +345,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8...@@ -343,8 +345,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
343 const sep1 = p1[0];345 const sep1 = p1[0];
344 const sep2 = p2[0];346 const sep2 = p2[0];
345347
346 var it1 = mem.tokenize(p1, [_]u8{sep1});348 var it1 = mem.tokenize(p1, &[_]u8{sep1});
347 var it2 = mem.tokenize(p2, [_]u8{sep2});349 var it2 = mem.tokenize(p2, &[_]u8{sep2});
348350
349 // TODO ASCII is wrong, we actually need full unicode support to compare paths.351 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
350 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);352 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
...@@ -637,10 +639,10 @@ test "resolve" {...@@ -637,10 +639,10 @@ test "resolve" {
637 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {639 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
638 cwd[0] = asciiUpper(cwd[0]);640 cwd[0] = asciiUpper(cwd[0]);
639 }641 }
640 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));642 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{"."}), cwd));
641 } else {643 } else {
642 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));644 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "a/b/c/", "../../.." }), cwd));
643 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));645 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"."}), cwd));
644 }646 }
645}647}
646648
...@@ -653,8 +655,8 @@ test "resolveWindows" {...@@ -653,8 +655,8 @@ test "resolveWindows" {
653 const cwd = try process.getCwdAlloc(debug.global_allocator);655 const cwd = try process.getCwdAlloc(debug.global_allocator);
654 const parsed_cwd = windowsParsePath(cwd);656 const parsed_cwd = windowsParsePath(cwd);
655 {657 {
656 const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });658 const result = testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
657 const expected = try join(debug.global_allocator, [_][]const u8{659 const expected = try join(debug.global_allocator, &[_][]const u8{
658 parsed_cwd.disk_designator,660 parsed_cwd.disk_designator,
659 "usr\\local\\lib\\zig\\std\\array_list.zig",661 "usr\\local\\lib\\zig\\std\\array_list.zig",
660 });662 });
...@@ -664,8 +666,8 @@ test "resolveWindows" {...@@ -664,8 +666,8 @@ test "resolveWindows" {
664 testing.expect(mem.eql(u8, result, expected));666 testing.expect(mem.eql(u8, result, expected));
665 }667 }
666 {668 {
667 const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });669 const result = testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" });
668 const expected = try join(debug.global_allocator, [_][]const u8{670 const expected = try join(debug.global_allocator, &[_][]const u8{
669 cwd,671 cwd,
670 "usr\\local\\lib\\zig",672 "usr\\local\\lib\\zig",
671 });673 });
...@@ -676,32 +678,32 @@ test "resolveWindows" {...@@ -676,32 +678,32 @@ test "resolveWindows" {
676 }678 }
677 }679 }
678680
679 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));681 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"));682 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"));683 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"));684 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"));685 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"));686 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"));687 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:\\"));688 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//" }), "C:\\"));
687 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));689 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\\"));690 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\\"));691 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"));692 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"));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"));
692}694}
693695
694test "resolvePosix" {696test "resolvePosix" {
695 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));697 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"));698 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"));699 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
698 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));700 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/", "..", ".." }), "/"));
699 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));701 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"/a/b/c/"}), "/a/b/c"));
700702
701 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));703 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"));704 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"));705 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"));706 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
705}707}
706708
707fn testResolveWindows(paths: []const []const u8) []u8 {709fn testResolveWindows(paths: []const []const u8) []u8 {
...@@ -856,12 +858,12 @@ pub fn basename(path: []const u8) []const u8 {...@@ -856,12 +858,12 @@ pub fn basename(path: []const u8) []const u8 {
856858
857pub fn basenamePosix(path: []const u8) []const u8 {859pub fn basenamePosix(path: []const u8) []const u8 {
858 if (path.len == 0)860 if (path.len == 0)
859 return [_]u8{};861 return &[_]u8{};
860862
861 var end_index: usize = path.len - 1;863 var end_index: usize = path.len - 1;
862 while (path[end_index] == '/') {864 while (path[end_index] == '/') {
863 if (end_index == 0)865 if (end_index == 0)
864 return [_]u8{};866 return &[_]u8{};
865 end_index -= 1;867 end_index -= 1;
866 }868 }
867 var start_index: usize = end_index;869 var start_index: usize = end_index;
...@@ -877,19 +879,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {...@@ -877,19 +879,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
877879
878pub fn basenameWindows(path: []const u8) []const u8 {880pub fn basenameWindows(path: []const u8) []const u8 {
879 if (path.len == 0)881 if (path.len == 0)
880 return [_]u8{};882 return &[_]u8{};
881883
882 var end_index: usize = path.len - 1;884 var end_index: usize = path.len - 1;
883 while (true) {885 while (true) {
884 const byte = path[end_index];886 const byte = path[end_index];
885 if (byte == '/' or byte == '\\') {887 if (byte == '/' or byte == '\\') {
886 if (end_index == 0)888 if (end_index == 0)
887 return [_]u8{};889 return &[_]u8{};
888 end_index -= 1;890 end_index -= 1;
889 continue;891 continue;
890 }892 }
891 if (byte == ':' and end_index == 1) {893 if (byte == ':' and end_index == 1) {
892 return [_]u8{};894 return &[_]u8{};
893 }895 }
894 break;896 break;
895 }897 }
...@@ -971,11 +973,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {...@@ -971,11 +973,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
971}973}
972974
973pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {975pub 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});
975 defer allocator.free(resolved_from);977 defer allocator.free(resolved_from);
976978
977 var clean_up_resolved_to = true;979 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});
979 defer if (clean_up_resolved_to) allocator.free(resolved_to);981 defer if (clean_up_resolved_to) allocator.free(resolved_to);
980982
981 const parsed_from = windowsParsePath(resolved_from);983 const parsed_from = windowsParsePath(resolved_from);
...@@ -1044,10 +1046,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)...@@ -1044,10 +1046,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
1044}1046}
10451047
1046pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {1048pub 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});
1048 defer allocator.free(resolved_from);1050 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});
1051 defer allocator.free(resolved_to);1053 defer allocator.free(resolved_to);
10521054
1053 var from_it = mem.tokenize(resolved_from, "/");1055 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 {...@@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
367 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);367 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
368 }368 }
369369
370 return @truncate(u32, hash_fn(hashes, 0));370 return @truncate(u32, hash_fn(&hashes, 0));
371}371}
372372
373fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {373fn 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 {...@@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300 }300 }
301301
302 return @truncate(u32, hash_fn(hashes, 0));302 return @truncate(u32, hash_fn(&hashes, 0));
303}303}
304304
305test "murmur2_32" {305test "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...@@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
9494
95 pub fn init(allocator: *Allocator) Self {95 pub fn init(allocator: *Allocator) Self {
96 return Self{96 return Self{
97 .entries = [_]Entry{},97 .entries = &[_]Entry{},
98 .allocator = allocator,98 .allocator = allocator,
99 .size = 0,99 .size = 0,
100 .max_distance_from_start_index = 0,100 .max_distance_from_start_index = 0,
lib/std/http/headers.zig+2-2
...@@ -514,8 +514,8 @@ test "Headers.getIndices" {...@@ -514,8 +514,8 @@ test "Headers.getIndices" {
514 try h.append("set-cookie", "y=2", null);514 try h.append("set-cookie", "y=2", null);
515515
516 testing.expect(null == h.getIndices("not-present"));516 testing.expect(null == h.getIndices("not-present"));
517 testing.expectEqualSlices(usize, [_]usize{0}, h.getIndices("foo").?.toSliceConst());517 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
518 testing.expectEqualSlices(usize, [_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());518 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
519}519}
520520
521test "Headers.get" {521test "Headers.get" {
lib/std/io.zig+1-1
...@@ -1107,7 +1107,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1107,7 +1107,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1107 byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);1107 byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);
1108 }1108 }
11091109
1110 try self.out_stream.write(buffer);1110 try self.out_stream.write(&buffer);
1111 }1111 }
11121112
1113 /// Serializes the passed value into the stream1113 /// 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 {...@@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type {
56 pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {56 pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {
57 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;57 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
58 mem.writeIntNative(T, &bytes, value);58 mem.writeIntNative(T, &bytes, value);
59 return self.writeFn(self, bytes);59 return self.writeFn(self, &bytes);
60 }60 }
6161
62 /// Write a foreign-endian integer.62 /// Write a foreign-endian integer.
63 pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {63 pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {
64 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;64 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
65 mem.writeIntForeign(T, &bytes, value);65 mem.writeIntForeign(T, &bytes, value);
66 return self.writeFn(self, bytes);66 return self.writeFn(self, &bytes);
67 }67 }
6868
69 pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {69 pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {
70 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;70 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
71 mem.writeIntLittle(T, &bytes, value);71 mem.writeIntLittle(T, &bytes, value);
72 return self.writeFn(self, bytes);72 return self.writeFn(self, &bytes);
73 }73 }
7474
75 pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {75 pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {
76 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;76 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
77 mem.writeIntBig(T, &bytes, value);77 mem.writeIntBig(T, &bytes, value);
78 return self.writeFn(self, bytes);78 return self.writeFn(self, &bytes);
79 }79 }
8080
81 pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {81 pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
82 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;82 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
83 mem.writeInt(T, &bytes, value, endian);83 mem.writeInt(T, &bytes, value, endian);
84 return self.writeFn(self, bytes);84 return self.writeFn(self, &bytes);
85 }85 }
86 };86 };
87}87}
lib/std/io/test.zig+4-4
...@@ -55,7 +55,7 @@ test "write a file, read it, then delete it" {...@@ -55,7 +55,7 @@ test "write a file, read it, then delete it" {
55 defer allocator.free(contents);55 defer allocator.free(contents);
5656
57 expect(mem.eql(u8, contents[0.."begin".len], "begin"));57 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));
59 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));59 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
60 }60 }
61 try fs.deleteFile(tmp_file_name);61 try fs.deleteFile(tmp_file_name);
...@@ -77,7 +77,7 @@ test "BufferOutStream" {...@@ -77,7 +77,7 @@ test "BufferOutStream" {
7777
78test "SliceInStream" {78test "SliceInStream" {
79 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };79 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
82 var dest: [4]u8 = undefined;82 var dest: [4]u8 = undefined;
8383
...@@ -95,7 +95,7 @@ test "SliceInStream" {...@@ -95,7 +95,7 @@ test "SliceInStream" {
9595
96test "PeekStream" {96test "PeekStream" {
97 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };97 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);
99 var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);99 var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
100100
101 var dest: [4]u8 = undefined;101 var dest: [4]u8 = undefined;
...@@ -614,7 +614,7 @@ test "File seek ops" {...@@ -614,7 +614,7 @@ test "File seek ops" {
614 fs.deleteFile(tmp_file_name) catch {};614 fs.deleteFile(tmp_file_name) catch {};
615 }615 }
616616
617 try file.write([_]u8{0x55} ** 8192);617 try file.write(&([_]u8{0x55} ** 8192));
618618
619 // Seek to the end619 // Seek to the end
620 try file.seekFromEnd(0);620 try file.seekFromEnd(0);
lib/std/mem.zig+52-76
...@@ -624,23 +624,23 @@ test "comptime read/write int" {...@@ -624,23 +624,23 @@ test "comptime read/write int" {
624}624}
625625
626test "readIntBig and readIntLittle" {626test "readIntBig and readIntLittle" {
627 testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);627 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
628 testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);628 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
629629
630 testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);630 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
631 testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);631 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
632632
633 testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);633 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
634 testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);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);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);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);639 testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
640 testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);640 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
641641
642 testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);642 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
643 testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);643 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
644}644}
645645
646/// Writes an integer to memory, storing it in twos-complement.646/// Writes an integer to memory, storing it in twos-complement.
...@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {...@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {
749 var buf9: [9]u8 = undefined;749 var buf9: [9]u8 = undefined;
750750
751 writeIntBig(u0, &buf0, 0x0);751 writeIntBig(u0, &buf0, 0x0);
752 testing.expect(eql(u8, buf0[0..], [_]u8{}));752 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
753 writeIntLittle(u0, &buf0, 0x0);753 writeIntLittle(u0, &buf0, 0x0);
754 testing.expect(eql(u8, buf0[0..], [_]u8{}));754 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
755755
756 writeIntBig(u8, &buf1, 0x12);756 writeIntBig(u8, &buf1, 0x12);
757 testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));757 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
758 writeIntLittle(u8, &buf1, 0x34);758 writeIntLittle(u8, &buf1, 0x34);
759 testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));759 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
760760
761 writeIntBig(u16, &buf2, 0x1234);761 writeIntBig(u16, &buf2, 0x1234);
762 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));762 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
763 writeIntLittle(u16, &buf2, 0x5678);763 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
766 writeIntBig(u72, &buf9, 0x123456789abcdef024);766 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 }));
768 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);768 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
771 writeIntBig(i8, &buf1, -1);771 writeIntBig(i8, &buf1, -1);
772 testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));772 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
773 writeIntLittle(i8, &buf1, -2);773 writeIntLittle(i8, &buf1, -2);
774 testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));774 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
775775
776 writeIntBig(i16, &buf2, -3);776 writeIntBig(i16, &buf2, -3);
777 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));777 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
778 writeIntLittle(i16, &buf2, -4);778 writeIntLittle(i16, &buf2, -4);
779 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));779 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
780}780}
781781
782/// Returns an iterator that iterates over the slices of `buffer` that are not782/// 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...@@ -1004,9 +1004,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
1004test "mem.join" {1004test "mem.join" {
1005 var buf: [1024]u8 = undefined;1005 var buf: [1024]u8 = undefined;
1006 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;1006 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1007 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"));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"));1009 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
1010}1010}
10111011
1012/// Copies each T from slices into a new slice that exactly holds all the elements.1012/// 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...@@ -1037,13 +1037,13 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T
1037test "concat" {1037test "concat" {
1038 var buf: [1024]u8 = undefined;1038 var buf: [1024]u8 = undefined;
1039 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;1039 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1040 testing.expect(eql(u8, try concat(a, u8, [_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));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{1041 testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{
1042 [_]u32{ 0, 1 },1042 &[_]u32{ 0, 1 },
1043 [_]u32{ 2, 3, 4 },1043 &[_]u32{ 2, 3, 4 },
1044 [_]u32{},1044 &[_]u32{},
1045 [_]u32{5},1045 &[_]u32{5},
1046 }), [_]u32{ 0, 1, 2, 3, 4, 5 }));1046 }), &[_]u32{ 0, 1, 2, 3, 4, 5 }));
1047}1047}
10481048
1049test "testStringEquality" {1049test "testStringEquality" {
...@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {...@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {
1111 var bytes: [8]u8 = undefined;1111 var bytes: [8]u8 = undefined;
11121112
1113 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);1113 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1114 testing.expect(eql(u8, bytes, [_]u8{1114 testing.expect(eql(u8, &bytes, &[_]u8{
1115 0x00, 0x00, 0x00, 0x00,1115 0x00, 0x00, 0x00, 0x00,
1116 0x00, 0x00, 0x00, 0x00,1116 0x00, 0x00, 0x00, 0x00,
1117 }));1117 }));
11181118
1119 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);1119 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1120 testing.expect(eql(u8, bytes, [_]u8{1120 testing.expect(eql(u8, &bytes, &[_]u8{
1121 0x00, 0x00, 0x00, 0x00,1121 0x00, 0x00, 0x00, 0x00,
1122 0x00, 0x00, 0x00, 0x00,1122 0x00, 0x00, 0x00, 0x00,
1123 }));1123 }));
11241124
1125 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);1125 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1126 testing.expect(eql(u8, bytes, [_]u8{1126 testing.expect(eql(u8, &bytes, &[_]u8{
1127 0x12,1127 0x12,
1128 0x34,1128 0x34,
1129 0x56,1129 0x56,
...@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {...@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {
1135 }));1135 }));
11361136
1137 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);1137 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1138 testing.expect(eql(u8, bytes, [_]u8{1138 testing.expect(eql(u8, &bytes, &[_]u8{
1139 0x12,1139 0x12,
1140 0x34,1140 0x34,
1141 0x56,1141 0x56,
...@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {...@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {
1147 }));1147 }));
11481148
1149 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);1149 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1150 testing.expect(eql(u8, bytes, [_]u8{1150 testing.expect(eql(u8, &bytes, &[_]u8{
1151 0x00,1151 0x00,
1152 0x00,1152 0x00,
1153 0x00,1153 0x00,
...@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {...@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {
1159 }));1159 }));
11601160
1161 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);1161 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1162 testing.expect(eql(u8, bytes, [_]u8{1162 testing.expect(eql(u8, &bytes, &[_]u8{
1163 0x12,1163 0x12,
1164 0x34,1164 0x34,
1165 0x56,1165 0x56,
...@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {...@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {
1171 }));1171 }));
11721172
1173 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);1173 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1174 testing.expect(eql(u8, bytes, [_]u8{1174 testing.expect(eql(u8, &bytes, &[_]u8{
1175 0x00,1175 0x00,
1176 0x00,1176 0x00,
1177 0x00,1177 0x00,
...@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {...@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {
1183 }));1183 }));
11841184
1185 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);1185 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1186 testing.expect(eql(u8, bytes, [_]u8{1186 testing.expect(eql(u8, &bytes, &[_]u8{
1187 0x34,1187 0x34,
1188 0x12,1188 0x12,
1189 0x00,1189 0x00,
...@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {...@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {
1235}1235}
12361236
1237test "reverse" {1237test "reverse" {
1238 var arr = [_]i32{1238 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1239 5,
1240 3,
1241 1,
1242 2,
1243 4,
1244 };
1245 reverse(i32, arr[0..]);1239 reverse(i32, arr[0..]);
12461240
1247 testing.expect(eql(i32, arr, [_]i32{1241 testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
1248 4,
1249 2,
1250 1,
1251 3,
1252 5,
1253 }));
1254}1242}
12551243
1256/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)1244/// 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 {...@@ -1262,22 +1250,10 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
1262}1250}
12631251
1264test "rotate" {1252test "rotate" {
1265 var arr = [_]i32{1253 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1266 5,
1267 3,
1268 1,
1269 2,
1270 4,
1271 };
1272 rotate(i32, arr[0..], 2);1254 rotate(i32, arr[0..], 2);
12731255
1274 testing.expect(eql(i32, arr, [_]i32{1256 testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
1275 1,
1276 2,
1277 4,
1278 5,
1279 3,
1280 }));
1281}1257}
12821258
1283/// Converts a little-endian integer to host endianness.1259/// Converts a little-endian integer to host endianness.
...@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {...@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
1394test "toBytes" {1370test "toBytes" {
1395 var my_bytes = toBytes(@as(u32, 0x12345678));1371 var my_bytes = toBytes(@as(u32, 0x12345678));
1396 switch (builtin.endian) {1372 switch (builtin.endian) {
1397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),1373 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")),1374 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
1399 }1375 }
14001376
1401 my_bytes[0] = '\x99';1377 my_bytes[0] = '\x99';
1402 switch (builtin.endian) {1378 switch (builtin.endian) {
1403 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x99\x34\x56\x78")),1379 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")),1380 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
1405 }1381 }
1406}1382}
14071383
...@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA...@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
1495test "subArrayPtr" {1471test "subArrayPtr" {
1496 const a1: [6]u8 = "abcdef".*;1472 const a1: [6]u8 = "abcdef".*;
1497 const sub1 = subArrayPtr(&a1, 2, 3);1473 const sub1 = subArrayPtr(&a1, 2, 3);
1498 testing.expect(eql(u8, sub1.*, "cde"));1474 testing.expect(eql(u8, sub1, "cde"));
14991475
1500 var a2: [6]u8 = "abcdef".*;1476 var a2: [6]u8 = "abcdef".*;
1501 var sub2 = subArrayPtr(&a2, 2, 3);1477 var sub2 = subArrayPtr(&a2, 2, 3);
15021478
1503 testing.expect(eql(u8, sub2, "cde"));1479 testing.expect(eql(u8, sub2, "cde"));
1504 sub2[1] = 'X';1480 sub2[1] = 'X';
1505 testing.expect(eql(u8, a2, "abcXef"));1481 testing.expect(eql(u8, &a2, "abcXef"));
1506}1482}
15071483
1508/// Round an address up to the nearest aligned address1484/// 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" {...@@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
46 }46 }
47 };47 };
4848
49 const isVector = multiTrait([_]TraitFn{49 const isVector = multiTrait(&[_]TraitFn{
50 hasFn("add"),50 hasFn("add"),
51 hasField("x"),51 hasField("x"),
52 hasField("y"),52 hasField("y"),
lib/std/net.zig+4-4
...@@ -291,7 +291,7 @@ pub const Address = extern union {...@@ -291,7 +291,7 @@ pub const Address = extern union {
291 },291 },
292 os.AF_INET6 => {292 os.AF_INET6 => {
293 const port = mem.bigToNative(u16, self.in6.port);293 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 })) {
295 try std.fmt.format(295 try std.fmt.format(
296 context,296 context,
297 Errors,297 Errors,
...@@ -339,7 +339,7 @@ pub const Address = extern union {...@@ -339,7 +339,7 @@ pub const Address = extern union {
339 unreachable;339 unreachable;
340 }340 }
341341
342 try std.fmt.format(context, Errors, output, "{}", self.un.path);342 try std.fmt.format(context, Errors, output, "{}", &self.un.path);
343 },343 },
344 else => unreachable,344 else => unreachable,
345 }345 }
...@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(...@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(
894 }894 }
895895
896 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))896 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
897 [_]u8{}897 &[_]u8{}
898 else898 else
899 rc.search.toSliceConst();899 rc.search.toSliceConst();
900900
...@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(...@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(
959959
960 for (afrrs) |afrr| {960 for (afrrs) |afrr| {
961 if (family != afrr.af) {961 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]);
963 qp[nq] = qbuf[nq][0..len];963 qp[nq] = qbuf[nq][0..len];
964 nq += 1;964 nq += 1;
965 }965 }
lib/std/os/test.zig+1-1
...@@ -137,7 +137,7 @@ test "getrandom" {...@@ -137,7 +137,7 @@ test "getrandom" {
137 try os.getrandom(&buf_b);137 try os.getrandom(&buf_b);
138 // If this test fails the chance is significantly higher that there is a bug than138 // If this test fails the chance is significantly higher that there is a bug than
139 // that two sets of 50 bytes were equal.139 // 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));
141}141}
142142
143test "getcwd" {143test "getcwd" {
lib/std/packed_int_array.zig+3-21
...@@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,...@@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
201 ///Return the Int stored at index201 ///Return the Int stored at index
202 pub fn get(self: Self, index: usize) Int {202 pub fn get(self: Self, index: usize) Int {
203 debug.assert(index < int_count);203 debug.assert(index < int_count);
204 return Io.get(self.bytes, index, 0);204 return Io.get(&self.bytes, index, 0);
205 }205 }
206206
207 ///Copy int into the array at index207 ///Copy int into the array at index
...@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
528test "PackedInt(Array/Slice)Endian" {528test "PackedInt(Array/Slice)Endian" {
529 {529 {
530 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);530 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
531 var packed_array_be = PackedArrayBe.init([_]u4{531 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
532 0,
533 1,
534 2,
535 3,
536 4,
537 5,
538 6,
539 7,
540 });
541 testing.expect(packed_array_be.bytes[0] == 0b00000001);532 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542 testing.expect(packed_array_be.bytes[1] == 0b00100011);533 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543534
...@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {...@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {
563554
564 {555 {
565 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);556 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
566 var packed_array_be = PackedArrayBe.init([_]u11{557 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
567 0,
568 1,
569 2,
570 3,
571 4,
572 5,
573 6,
574 7,
575 });
576 testing.expect(packed_array_be.bytes[0] == 0b00000000);558 testing.expect(packed_array_be.bytes[0] == 0b00000000);
577 testing.expect(packed_array_be.bytes[1] == 0b00000000);559 testing.expect(packed_array_be.bytes[1] == 0b00000000);
578 testing.expect(packed_array_be.bytes[2] == 0b00000100);560 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 {...@@ -22,7 +22,7 @@ pub fn PriorityQueue(comptime T: type) type {
22 /// `fn lessThan(a: T, b: T) bool { return a < b; }`22 /// `fn lessThan(a: T, b: T) bool { return a < b; }`
23 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {23 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
24 return Self{24 return Self{
25 .items = [_]T{},25 .items = &[_]T{},
26 .len = 0,26 .len = 0,
27 .allocator = allocator,27 .allocator = allocator,
28 .compareFn = compareFn,28 .compareFn = compareFn,
lib/std/process.zig+8-8
...@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {...@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
473}473}
474474
475test "windows arg parsing" {475test "windows arg parsing" {
476 testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });476 testWindowsCmdLine("a b\tc d", &[_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" });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" });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" });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" });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" });481 testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" });
482482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{
484 ".\\..\\zig-cache\\build",484 ".\\..\\zig-cache\\build",
485 "bin\\zig.exe",485 "bin\\zig.exe",
486 ".\\..",486 ".\\..",
lib/std/rand.zig+1-1
...@@ -54,7 +54,7 @@ pub const Random = struct {...@@ -54,7 +54,7 @@ pub const Random = struct {
54 // use LE instead of native endian for better portability maybe?54 // use LE instead of native endian for better portability maybe?
55 // TODO: endian portability is pointless if the underlying prng isn't endian portable.55 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
56 // TODO: document the endian portability of this library.56 // 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);
58 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);58 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);
59 return @bitCast(T, unsigned_result);59 return @bitCast(T, unsigned_result);
60 }60 }
lib/std/segmented_list.zig+4-8
...@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
112 .allocator = allocator,112 .allocator = allocator,
113 .len = 0,113 .len = 0,
114 .prealloc_segment = undefined,114 .prealloc_segment = undefined,
115 .dynamic_segments = [_][*]T{},115 .dynamic_segments = &[_][*]T{},
116 };116 };
117 }117 }
118118
...@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
192 const len = @intCast(ShelfIndex, self.dynamic_segments.len);192 const len = @intCast(ShelfIndex, self.dynamic_segments.len);
193 self.freeShelves(len, 0);193 self.freeShelves(len, 0);
194 self.allocator.free(self.dynamic_segments);194 self.allocator.free(self.dynamic_segments);
195 self.dynamic_segments = [_][*]T{};195 self.dynamic_segments = &[_][*]T{};
196 return;196 return;
197 }197 }
198198
...@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
385 testing.expect(list.pop().? == 100);385 testing.expect(list.pop().? == 100);
386 testing.expect(list.len == 99);386 testing.expect(list.len == 99);
387387
388 try list.pushMany([_]i32{388 try list.pushMany(&[_]i32{ 1, 2, 3 });
389 1,
390 2,
391 3,
392 });
393 testing.expect(list.len == 102);389 testing.expect(list.len == 102);
394 testing.expect(list.pop().? == 3);390 testing.expect(list.pop().? == 3);
395 testing.expect(list.pop().? == 2);391 testing.expect(list.pop().? == 2);
396 testing.expect(list.pop().? == 1);392 testing.expect(list.pop().? == 1);
397 testing.expect(list.len == 99);393 testing.expect(list.len == 99);
398394
399 try list.pushMany([_]i32{});395 try list.pushMany(&[_]i32{});
400 testing.expect(list.len == 99);396 testing.expect(list.len == 99);
401397
402 var i: i32 = 99;398 var i: i32 = 99;
lib/std/sort.zig+43-43
...@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {...@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
10431043
1044test "std.sort" {1044test "std.sort" {
1045 const u8cases = [_][]const []const u8{1045 const u8cases = [_][]const []const u8{
1046 [_][]const u8{1046 &[_][]const u8{
1047 "",1047 "",
1048 "",1048 "",
1049 },1049 },
1050 [_][]const u8{1050 &[_][]const u8{
1051 "a",1051 "a",
1052 "a",1052 "a",
1053 },1053 },
1054 [_][]const u8{1054 &[_][]const u8{
1055 "az",1055 "az",
1056 "az",1056 "az",
1057 },1057 },
1058 [_][]const u8{1058 &[_][]const u8{
1059 "za",1059 "za",
1060 "az",1060 "az",
1061 },1061 },
1062 [_][]const u8{1062 &[_][]const u8{
1063 "asdf",1063 "asdf",
1064 "adfs",1064 "adfs",
1065 },1065 },
1066 [_][]const u8{1066 &[_][]const u8{
1067 "one",1067 "one",
1068 "eno",1068 "eno",
1069 },1069 },
...@@ -1078,29 +1078,29 @@ test "std.sort" {...@@ -1078,29 +1078,29 @@ test "std.sort" {
1078 }1078 }
10791079
1080 const i32cases = [_][]const []const i32{1080 const i32cases = [_][]const []const i32{
1081 [_][]const i32{1081 &[_][]const i32{
1082 [_]i32{},1082 &[_]i32{},
1083 [_]i32{},1083 &[_]i32{},
1084 },1084 },
1085 [_][]const i32{1085 &[_][]const i32{
1086 [_]i32{1},1086 &[_]i32{1},
1087 [_]i32{1},1087 &[_]i32{1},
1088 },1088 },
1089 [_][]const i32{1089 &[_][]const i32{
1090 [_]i32{ 0, 1 },1090 &[_]i32{ 0, 1 },
1091 [_]i32{ 0, 1 },1091 &[_]i32{ 0, 1 },
1092 },1092 },
1093 [_][]const i32{1093 &[_][]const i32{
1094 [_]i32{ 1, 0 },1094 &[_]i32{ 1, 0 },
1095 [_]i32{ 0, 1 },1095 &[_]i32{ 0, 1 },
1096 },1096 },
1097 [_][]const i32{1097 &[_][]const i32{
1098 [_]i32{ 1, -1, 0 },1098 &[_]i32{ 1, -1, 0 },
1099 [_]i32{ -1, 0, 1 },1099 &[_]i32{ -1, 0, 1 },
1100 },1100 },
1101 [_][]const i32{1101 &[_][]const i32{
1102 [_]i32{ 2, 1, 3 },1102 &[_]i32{ 2, 1, 3 },
1103 [_]i32{ 1, 2, 3 },1103 &[_]i32{ 1, 2, 3 },
1104 },1104 },
1105 };1105 };
11061106
...@@ -1115,29 +1115,29 @@ test "std.sort" {...@@ -1115,29 +1115,29 @@ test "std.sort" {
11151115
1116test "std.sort descending" {1116test "std.sort descending" {
1117 const rev_cases = [_][]const []const i32{1117 const rev_cases = [_][]const []const i32{
1118 [_][]const i32{1118 &[_][]const i32{
1119 [_]i32{},1119 &[_]i32{},
1120 [_]i32{},1120 &[_]i32{},
1121 },1121 },
1122 [_][]const i32{1122 &[_][]const i32{
1123 [_]i32{1},1123 &[_]i32{1},
1124 [_]i32{1},1124 &[_]i32{1},
1125 },1125 },
1126 [_][]const i32{1126 &[_][]const i32{
1127 [_]i32{ 0, 1 },1127 &[_]i32{ 0, 1 },
1128 [_]i32{ 1, 0 },1128 &[_]i32{ 1, 0 },
1129 },1129 },
1130 [_][]const i32{1130 &[_][]const i32{
1131 [_]i32{ 1, 0 },1131 &[_]i32{ 1, 0 },
1132 [_]i32{ 1, 0 },1132 &[_]i32{ 1, 0 },
1133 },1133 },
1134 [_][]const i32{1134 &[_][]const i32{
1135 [_]i32{ 1, -1, 0 },1135 &[_]i32{ 1, -1, 0 },
1136 [_]i32{ 1, 0, -1 },1136 &[_]i32{ 1, 0, -1 },
1137 },1137 },
1138 [_][]const i32{1138 &[_][]const i32{
1139 [_]i32{ 2, 1, 3 },1139 &[_]i32{ 2, 1, 3 },
1140 [_]i32{ 3, 2, 1 },1140 &[_]i32{ 3, 2, 1 },
1141 },1141 },
1142 };1142 };
11431143
...@@ -1154,7 +1154,7 @@ test "another sort case" {...@@ -1154,7 +1154,7 @@ test "another sort case" {
1154 var arr = [_]i32{ 5, 3, 1, 2, 4 };1154 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1155 sort(i32, arr[0..], asc(i32));1155 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 }));
1158}1158}
11591159
1160test "sort fuzz testing" {1160test "sort fuzz testing" {
lib/std/unicode.zig+6-6
...@@ -499,14 +499,14 @@ test "utf16leToUtf8" {...@@ -499,14 +499,14 @@ test "utf16leToUtf8" {
499 {499 {
500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');501 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);
503 testing.expect(mem.eql(u8, utf8, "Aa"));503 testing.expect(mem.eql(u8, utf8, "Aa"));
504 }504 }
505505
506 {506 {
507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);508 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);
510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
511 }511 }
512512
...@@ -514,7 +514,7 @@ test "utf16leToUtf8" {...@@ -514,7 +514,7 @@ test "utf16leToUtf8" {
514 // the values just outside the surrogate half range514 // the values just outside the surrogate half range
515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);516 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);
518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
519 }519 }
520520
...@@ -522,7 +522,7 @@ test "utf16leToUtf8" {...@@ -522,7 +522,7 @@ test "utf16leToUtf8" {
522 // smallest surrogate pair522 // smallest surrogate pair
523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);524 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);
526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
527 }527 }
528528
...@@ -530,14 +530,14 @@ test "utf16leToUtf8" {...@@ -530,14 +530,14 @@ test "utf16leToUtf8" {
530 // largest surrogate pair530 // largest surrogate pair
531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);532 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);
534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
535 }535 }
536536
537 {537 {
538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);539 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);
541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
542 }542 }
543}543}
lib/std/zig/tokenizer.zig+61-61
...@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {...@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {
1313};1313};
13141314
1315test "tokenizer" {1315test "tokenizer" {
1316 testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});1316 testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test});
1317}1317}
13181318
1319test "tokenizer - unknown length pointer and then c pointer" {1319test "tokenizer - unknown length pointer and then c pointer" {
1320 testTokenize(1320 testTokenize(
1321 \\[*]u81321 \\[*]u8
1322 \\[*c]u81322 \\[*c]u8
1323 , [_]Token.Id{1323 , &[_]Token.Id{
1324 Token.Id.LBracket,1324 Token.Id.LBracket,
1325 Token.Id.Asterisk,1325 Token.Id.Asterisk,
1326 Token.Id.RBracket,1326 Token.Id.RBracket,
...@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {...@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {
1336test "tokenizer - char literal with hex escape" {1336test "tokenizer - char literal with hex escape" {
1337 testTokenize(1337 testTokenize(
1338 \\'\x1b'1338 \\'\x1b'
1339 , [_]Token.Id{.CharLiteral});1339 , &[_]Token.Id{.CharLiteral});
1340 testTokenize(1340 testTokenize(
1341 \\'\x1'1341 \\'\x1'
1342 , [_]Token.Id{ .Invalid, .Invalid });1342 , &[_]Token.Id{ .Invalid, .Invalid });
1343}1343}
13441344
1345test "tokenizer - char literal with unicode escapes" {1345test "tokenizer - char literal with unicode escapes" {
1346 // Valid unicode escapes1346 // Valid unicode escapes
1347 testTokenize(1347 testTokenize(
1348 \\'\u{3}'1348 \\'\u{3}'
1349 , [_]Token.Id{.CharLiteral});1349 , &[_]Token.Id{.CharLiteral});
1350 testTokenize(1350 testTokenize(
1351 \\'\u{01}'1351 \\'\u{01}'
1352 , [_]Token.Id{.CharLiteral});1352 , &[_]Token.Id{.CharLiteral});
1353 testTokenize(1353 testTokenize(
1354 \\'\u{2a}'1354 \\'\u{2a}'
1355 , [_]Token.Id{.CharLiteral});1355 , &[_]Token.Id{.CharLiteral});
1356 testTokenize(1356 testTokenize(
1357 \\'\u{3f9}'1357 \\'\u{3f9}'
1358 , [_]Token.Id{.CharLiteral});1358 , &[_]Token.Id{.CharLiteral});
1359 testTokenize(1359 testTokenize(
1360 \\'\u{6E09aBc1523}'1360 \\'\u{6E09aBc1523}'
1361 , [_]Token.Id{.CharLiteral});1361 , &[_]Token.Id{.CharLiteral});
1362 testTokenize(1362 testTokenize(
1363 \\"\u{440}"1363 \\"\u{440}"
1364 , [_]Token.Id{.StringLiteral});1364 , &[_]Token.Id{.StringLiteral});
13651365
1366 // Invalid unicode escapes1366 // Invalid unicode escapes
1367 testTokenize(1367 testTokenize(
1368 \\'\u'1368 \\'\u'
1369 , [_]Token.Id{.Invalid});1369 , &[_]Token.Id{.Invalid});
1370 testTokenize(1370 testTokenize(
1371 \\'\u{{'1371 \\'\u{{'
1372 , [_]Token.Id{ .Invalid, .Invalid });1372 , &[_]Token.Id{ .Invalid, .Invalid });
1373 testTokenize(1373 testTokenize(
1374 \\'\u{}'1374 \\'\u{}'
1375 , [_]Token.Id{ .Invalid, .Invalid });1375 , &[_]Token.Id{ .Invalid, .Invalid });
1376 testTokenize(1376 testTokenize(
1377 \\'\u{s}'1377 \\'\u{s}'
1378 , [_]Token.Id{ .Invalid, .Invalid });1378 , &[_]Token.Id{ .Invalid, .Invalid });
1379 testTokenize(1379 testTokenize(
1380 \\'\u{2z}'1380 \\'\u{2z}'
1381 , [_]Token.Id{ .Invalid, .Invalid });1381 , &[_]Token.Id{ .Invalid, .Invalid });
1382 testTokenize(1382 testTokenize(
1383 \\'\u{4a'1383 \\'\u{4a'
1384 , [_]Token.Id{.Invalid});1384 , &[_]Token.Id{.Invalid});
13851385
1386 // Test old-style unicode literals1386 // Test old-style unicode literals
1387 testTokenize(1387 testTokenize(
1388 \\'\u0333'1388 \\'\u0333'
1389 , [_]Token.Id{ .Invalid, .Invalid });1389 , &[_]Token.Id{ .Invalid, .Invalid });
1390 testTokenize(1390 testTokenize(
1391 \\'\U0333'1391 \\'\U0333'
1392 , [_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });1392 , &[_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
1393}1393}
13941394
1395test "tokenizer - char literal with unicode code point" {1395test "tokenizer - char literal with unicode code point" {
1396 testTokenize(1396 testTokenize(
1397 \\'💩'1397 \\'💩'
1398 , [_]Token.Id{.CharLiteral});1398 , &[_]Token.Id{.CharLiteral});
1399}1399}
14001400
1401test "tokenizer - float literal e exponent" {1401test "tokenizer - float literal e exponent" {
1402 testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{1402 testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{
1403 Token.Id.Identifier,1403 Token.Id.Identifier,
1404 Token.Id.Equal,1404 Token.Id.Equal,
1405 Token.Id.FloatLiteral,1405 Token.Id.FloatLiteral,
...@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {...@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {
1408}1408}
14091409
1410test "tokenizer - float literal p exponent" {1410test "tokenizer - float literal p exponent" {
1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{
1412 Token.Id.Identifier,1412 Token.Id.Identifier,
1413 Token.Id.Equal,1413 Token.Id.Equal,
1414 Token.Id.FloatLiteral,1414 Token.Id.FloatLiteral,
...@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {...@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {
1417}1417}
14181418
1419test "tokenizer - chars" {1419test "tokenizer - chars" {
1420 testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});1420 testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral});
1421}1421}
14221422
1423test "tokenizer - invalid token characters" {1423test "tokenizer - invalid token characters" {
1424 testTokenize("#", [_]Token.Id{Token.Id.Invalid});1424 testTokenize("#", &[_]Token.Id{Token.Id.Invalid});
1425 testTokenize("`", [_]Token.Id{Token.Id.Invalid});1425 testTokenize("`", &[_]Token.Id{Token.Id.Invalid});
1426 testTokenize("'c", [_]Token.Id{Token.Id.Invalid});1426 testTokenize("'c", &[_]Token.Id{Token.Id.Invalid});
1427 testTokenize("'", [_]Token.Id{Token.Id.Invalid});1427 testTokenize("'", &[_]Token.Id{Token.Id.Invalid});
1428 testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });1428 testTokenize("''", &[_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
1429}1429}
14301430
1431test "tokenizer - invalid literal/comment characters" {1431test "tokenizer - invalid literal/comment characters" {
1432 testTokenize("\"\x00\"", [_]Token.Id{1432 testTokenize("\"\x00\"", &[_]Token.Id{
1433 Token.Id.StringLiteral,1433 Token.Id.StringLiteral,
1434 Token.Id.Invalid,1434 Token.Id.Invalid,
1435 });1435 });
1436 testTokenize("//\x00", [_]Token.Id{1436 testTokenize("//\x00", &[_]Token.Id{
1437 Token.Id.LineComment,1437 Token.Id.LineComment,
1438 Token.Id.Invalid,1438 Token.Id.Invalid,
1439 });1439 });
1440 testTokenize("//\x1f", [_]Token.Id{1440 testTokenize("//\x1f", &[_]Token.Id{
1441 Token.Id.LineComment,1441 Token.Id.LineComment,
1442 Token.Id.Invalid,1442 Token.Id.Invalid,
1443 });1443 });
1444 testTokenize("//\x7f", [_]Token.Id{1444 testTokenize("//\x7f", &[_]Token.Id{
1445 Token.Id.LineComment,1445 Token.Id.LineComment,
1446 Token.Id.Invalid,1446 Token.Id.Invalid,
1447 });1447 });
1448}1448}
14491449
1450test "tokenizer - utf8" {1450test "tokenizer - utf8" {
1451 testTokenize("//\xc2\x80", [_]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});1452 testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{Token.Id.LineComment});
1453}1453}
14541454
1455test "tokenizer - invalid utf8" {1455test "tokenizer - invalid utf8" {
1456 testTokenize("//\x80", [_]Token.Id{1456 testTokenize("//\x80", &[_]Token.Id{
1457 Token.Id.LineComment,1457 Token.Id.LineComment,
1458 Token.Id.Invalid,1458 Token.Id.Invalid,
1459 });1459 });
1460 testTokenize("//\xbf", [_]Token.Id{1460 testTokenize("//\xbf", &[_]Token.Id{
1461 Token.Id.LineComment,1461 Token.Id.LineComment,
1462 Token.Id.Invalid,1462 Token.Id.Invalid,
1463 });1463 });
1464 testTokenize("//\xf8", [_]Token.Id{1464 testTokenize("//\xf8", &[_]Token.Id{
1465 Token.Id.LineComment,1465 Token.Id.LineComment,
1466 Token.Id.Invalid,1466 Token.Id.Invalid,
1467 });1467 });
1468 testTokenize("//\xff", [_]Token.Id{1468 testTokenize("//\xff", &[_]Token.Id{
1469 Token.Id.LineComment,1469 Token.Id.LineComment,
1470 Token.Id.Invalid,1470 Token.Id.Invalid,
1471 });1471 });
1472 testTokenize("//\xc2\xc0", [_]Token.Id{1472 testTokenize("//\xc2\xc0", &[_]Token.Id{
1473 Token.Id.LineComment,1473 Token.Id.LineComment,
1474 Token.Id.Invalid,1474 Token.Id.Invalid,
1475 });1475 });
1476 testTokenize("//\xe0", [_]Token.Id{1476 testTokenize("//\xe0", &[_]Token.Id{
1477 Token.Id.LineComment,1477 Token.Id.LineComment,
1478 Token.Id.Invalid,1478 Token.Id.Invalid,
1479 });1479 });
1480 testTokenize("//\xf0", [_]Token.Id{1480 testTokenize("//\xf0", &[_]Token.Id{
1481 Token.Id.LineComment,1481 Token.Id.LineComment,
1482 Token.Id.Invalid,1482 Token.Id.Invalid,
1483 });1483 });
1484 testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{1484 testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{
1485 Token.Id.LineComment,1485 Token.Id.LineComment,
1486 Token.Id.Invalid,1486 Token.Id.Invalid,
1487 });1487 });
...@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {...@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {
14891489
1490test "tokenizer - illegal unicode codepoints" {1490test "tokenizer - illegal unicode codepoints" {
1491 // unicode newline characters.U+0085, U+2028, U+20291491 // unicode newline characters.U+0085, U+2028, U+2029
1492 testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});1492 testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment});
1493 testTokenize("//\xc2\x85", [_]Token.Id{1493 testTokenize("//\xc2\x85", &[_]Token.Id{
1494 Token.Id.LineComment,1494 Token.Id.LineComment,
1495 Token.Id.Invalid,1495 Token.Id.Invalid,
1496 });1496 });
1497 testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});1497 testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment});
1498 testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});1498 testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment});
1499 testTokenize("//\xe2\x80\xa8", [_]Token.Id{1499 testTokenize("//\xe2\x80\xa8", &[_]Token.Id{
1500 Token.Id.LineComment,1500 Token.Id.LineComment,
1501 Token.Id.Invalid,1501 Token.Id.Invalid,
1502 });1502 });
1503 testTokenize("//\xe2\x80\xa9", [_]Token.Id{1503 testTokenize("//\xe2\x80\xa9", &[_]Token.Id{
1504 Token.Id.LineComment,1504 Token.Id.LineComment,
1505 Token.Id.Invalid,1505 Token.Id.Invalid,
1506 });1506 });
1507 testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});1507 testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment});
1508}1508}
15091509
1510test "tokenizer - string identifier and builtin fns" {1510test "tokenizer - string identifier and builtin fns" {
1511 testTokenize(1511 testTokenize(
1512 \\const @"if" = @import("std");1512 \\const @"if" = @import("std");
1513 , [_]Token.Id{1513 , &[_]Token.Id{
1514 Token.Id.Keyword_const,1514 Token.Id.Keyword_const,
1515 Token.Id.Identifier,1515 Token.Id.Identifier,
1516 Token.Id.Equal,1516 Token.Id.Equal,
...@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {...@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {
1523}1523}
15241524
1525test "tokenizer - pipe and then invalid" {1525test "tokenizer - pipe and then invalid" {
1526 testTokenize("||=", [_]Token.Id{1526 testTokenize("||=", &[_]Token.Id{
1527 Token.Id.PipePipe,1527 Token.Id.PipePipe,
1528 Token.Id.Equal,1528 Token.Id.Equal,
1529 });1529 });
1530}1530}
15311531
1532test "tokenizer - line comment and doc comment" {1532test "tokenizer - line comment and doc comment" {
1533 testTokenize("//", [_]Token.Id{Token.Id.LineComment});1533 testTokenize("//", &[_]Token.Id{Token.Id.LineComment});
1534 testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});1534 testTokenize("// a / b", &[_]Token.Id{Token.Id.LineComment});
1535 testTokenize("// /", [_]Token.Id{Token.Id.LineComment});1535 testTokenize("// /", &[_]Token.Id{Token.Id.LineComment});
1536 testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});1536 testTokenize("/// a", &[_]Token.Id{Token.Id.DocComment});
1537 testTokenize("///", [_]Token.Id{Token.Id.DocComment});1537 testTokenize("///", &[_]Token.Id{Token.Id.DocComment});
1538 testTokenize("////", [_]Token.Id{Token.Id.LineComment});1538 testTokenize("////", &[_]Token.Id{Token.Id.LineComment});
1539 testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment});1539 testTokenize("//!", &[_]Token.Id{Token.Id.ContainerDocComment});
1540 testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment});1540 testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment});
1541}1541}
15421542
1543test "tokenizer - line comment followed by identifier" {1543test "tokenizer - line comment followed by identifier" {
...@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {...@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {
1545 \\ Unexpected,1545 \\ Unexpected,
1546 \\ // another1546 \\ // another
1547 \\ Another,1547 \\ Another,
1548 , [_]Token.Id{1548 , &[_]Token.Id{
1549 Token.Id.Identifier,1549 Token.Id.Identifier,
1550 Token.Id.Comma,1550 Token.Id.Comma,
1551 Token.Id.LineComment,1551 Token.Id.LineComment,
...@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {...@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {
1555}1555}
15561556
1557test "tokenizer - UTF-8 BOM is recognized and skipped" {1557test "tokenizer - UTF-8 BOM is recognized and skipped" {
1558 testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{1558 testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{
1559 Token.Id.Identifier,1559 Token.Id.Identifier,
1560 Token.Id.Semicolon,1560 Token.Id.Semicolon,
1561 });1561 });
1562}1562}
15631563
1564test "correctly parse pointer assignment" {1564test "correctly parse pointer assignment" {
1565 testTokenize("b.*=3;\n", [_]Token.Id{1565 testTokenize("b.*=3;\n", &[_]Token.Id{
1566 Token.Id.Identifier,1566 Token.Id.Identifier,
1567 Token.Id.PeriodAsterisk,1567 Token.Id.PeriodAsterisk,
1568 Token.Id.Equal,1568 Token.Id.Equal,
src-self-hosted/dep_tokenizer.zig+2-2
...@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {...@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
992992
993fn printCharValues(out: var, bytes: []const u8) !void {993fn printCharValues(out: var, bytes: []const u8) !void {
994 for (bytes) |b| {994 for (bytes) |b| {
995 try out.write([_]u8{printable_char_tab[b]});995 try out.write(&[_]u8{printable_char_tab[b]});
996 }996 }
997}997}
998998
...@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {...@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
1002 } else {1002 } else {
1003 try out.write("'");1003 try out.write("'");
1004 try out.write([_]u8{printable_char_tab[char]});1004 try out.write(&[_]u8{printable_char_tab[char]});
1005 try out.write("'");1005 try out.write("'");
1006 }1006 }
1007}1007}
src-self-hosted/main.zig+1-1
...@@ -521,7 +521,7 @@ pub const usage_fmt =...@@ -521,7 +521,7 @@ pub const usage_fmt =
521pub const args_fmt_spec = [_]Flag{521pub const args_fmt_spec = [_]Flag{
522 Flag.Bool("--help"),522 Flag.Bool("--help"),
523 Flag.Bool("--check"),523 Flag.Bool("--check"),
524 Flag.Option("--color", [_][]const u8{524 Flag.Option("--color", &[_][]const u8{
525 "auto",525 "auto",
526 "off",526 "off",
527 "on",527 "on",
src-self-hosted/stage1.zig+2-2
...@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {...@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
170 stderr = &stderr_file.outStream().stream;170 stderr = &stderr_file.outStream().stream;
171171
172 const args = args_list.toSliceConst();172 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..]);
174 defer flags.deinit();174 defer flags.deinit();
175175
176 if (flags.present("help")) {176 if (flags.present("help")) {
...@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
286286
287 while (try dir_it.next()) |entry| {287 while (try dir_it.next()) |entry| {
288 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {288 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 });
290 try fmtPath(fmt, full_path, check_mode);290 try fmtPath(fmt, full_path, check_mode);
291 }291 }
292 }292 }
src/all_types.hpp+3
...@@ -2650,6 +2650,9 @@ struct IrInstruction {...@@ -2650,6 +2650,9 @@ struct IrInstruction {
2650 IrInstructionId id;2650 IrInstructionId id;
2651 // true if this instruction was generated by zig and not from user code2651 // true if this instruction was generated by zig and not from user code
2652 bool is_gen;2652 bool is_gen;
2653
2654 // for debugging purposes, this is useful to call to inspect the instruction
2655 void dump();
2653};2656};
26542657
2655struct IrInstructionDeclVarSrc {2658struct IrInstructionDeclVarSrc {
src/ir.cpp+171-265
...@@ -218,7 +218,8 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -218,7 +218,8 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
218static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,218static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
219 ZigType *dest_type);219 ZigType *dest_type);
220static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,220static 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);
222static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,223static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
223 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,224 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
224 bool non_null_comptime, bool allow_discard);225 bool non_null_comptime, bool allow_discard);
...@@ -10417,9 +10418,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10417,9 +10418,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10417 }10418 }
1041810419
10419 if (cur_type->id == ZigTypeIdErrorSet) {10420 if (cur_type->id == ZigTypeIdErrorSet) {
10420 if (prev_type->id == ZigTypeIdArray) {
10421 convert_to_const_slice = true;
10422 }
10423 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {10421 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
10424 return ira->codegen->builtin_types.entry_invalid;10422 return ira->codegen->builtin_types.entry_invalid;
10425 }10423 }
...@@ -10754,25 +10752,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10754,25 +10752,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10754 }10752 }
10755 }10753 }
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
10776 // *[N]T to []T10755 // *[N]T to []T
10777 // *[N]T to E![]T10756 // *[N]T to E![]T
10778 if (cur_type->id == ZigTypeIdPointer &&10757 if (cur_type->id == ZigTypeIdPointer &&
...@@ -10820,19 +10799,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10820,19 +10799,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10820 }10799 }
10821 }10800 }
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
10836 // *[N]T and *[M]T10802 // *[N]T and *[M]T
10837 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&10803 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
10838 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&10804 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
...@@ -10876,19 +10842,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10876,19 +10842,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10876 continue;10842 continue;
10877 }10843 }
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
10892 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&10845 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
10893 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))10846 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
10894 {10847 {
...@@ -10924,18 +10877,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10924,18 +10877,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10924 free(errors);10877 free(errors);
1092510878
10926 if (convert_to_const_slice) {10879 if (convert_to_const_slice) {
10927 if (prev_inst->value->type->id == ZigTypeIdArray) {10880 if (prev_inst->value->type->id == ZigTypeIdPointer) {
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) {
10939 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;10881 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
10940 src_assert(array_type->id == ZigTypeIdArray, source_node);10882 src_assert(array_type->id == ZigTypeIdArray, source_node);
10941 ZigType *ptr_type = get_pointer_to_type_extra2(10883 ZigType *ptr_type = get_pointer_to_type_extra2(
...@@ -12021,52 +11963,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -12021,52 +11963,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
12021 return new_instruction;11963 return new_instruction;
12022}11964}
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
12070static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {11966static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
12071 assert(union_type->id == ZigTypeIdUnion);11967 assert(union_type->id == ZigTypeIdUnion);
1207211968
...@@ -13101,44 +12997,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13101,44 +12997,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13101 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);12997 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
13102 }12998 }
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
13142 // *[N]T to ?[]const T13000 // *[N]T to ?[]const T
13143 if (wanted_type->id == ZigTypeIdOptional &&13001 if (wanted_type->id == ZigTypeIdOptional &&
13144 is_slice(wanted_type->data.maybe.child_type) &&13002 is_slice(wanted_type->data.maybe.child_type) &&
...@@ -13284,20 +13142,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13284,20 +13142,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13284 }13142 }
1328513143
13286 // *@Frame(func) to anyframe->T or anyframe13144 // *@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
13287 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&13147 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&
13288 !actual_type->data.pointer.is_const &&13148 !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)
13290 {13150 {
13291 bool ok = true;13151 ZigType *anyframe_type;
13292 if (wanted_type->data.any_frame.result_type != nullptr) {13152 if (wanted_type->id == ZigTypeIdAnyFrame) {
13293 ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;13153 anyframe_type = wanted_type;
13294 ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;13154 } else if (wanted_type->id == ZigTypeIdOptional &&
13295 if (wanted_type->data.any_frame.result_type != fn_return_type) {13155 wanted_type->data.maybe.child_type->id == ZigTypeIdAnyFrame)
13296 ok = false;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);
13297 }13179 }
13298 }
13299 if (ok) {
13300 return ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, wanted_type);
13301 }13180 }
13302 }13181 }
1330313182
...@@ -13322,30 +13201,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13322,30 +13201,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13322 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);13201 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);
13323 }13202 }
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
13349 // cast from E to E!T13204 // cast from E to E!T
13350 if (wanted_type->id == ZigTypeIdErrorUnion &&13205 if (wanted_type->id == ZigTypeIdErrorUnion &&
13351 actual_type->id == ZigTypeIdErrorSet)13206 actual_type->id == ZigTypeIdErrorSet)
...@@ -13541,6 +13396,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13541,6 +13396,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13541 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);13396 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
13542 }13397 }
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
13544 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,13409 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
13545 buf_sprintf("expected type '%s', found '%s'",13410 buf_sprintf("expected type '%s', found '%s'",
13546 buf_ptr(&wanted_type->name),13411 buf_ptr(&wanted_type->name),
...@@ -15283,10 +15148,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15283,10 +15148,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1528315148
15284 ZigValue *out_array_val;15149 ZigValue *out_array_val;
15285 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);15150 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) {15151 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
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) {
15290 out_array_val = create_const_vals(1);15152 out_array_val = create_const_vals(1);
15291 out_array_val->special = ConstValSpecialStatic;15153 out_array_val->special = ConstValSpecialStatic;
15292 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);15154 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...@@ -15314,6 +15176,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15314 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;15176 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
15315 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;15177 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
15316 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);15178 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;
15317 } else {15182 } else {
15318 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,15183 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
15319 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);15184 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
...@@ -16142,7 +16007,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su...@@ -16142,7 +16007,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
1614216007
16143// when calling this function, at the callsite must check for result type noreturn and propagate it up16008// when calling this function, at the callsite must check for result type noreturn and propagate it up
16144static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,16009static 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)
16146{16012{
16147 Error err;16013 Error err;
16148 if (result_loc->resolved_loc != nullptr) {16014 if (result_loc->resolved_loc != nullptr) {
...@@ -16275,8 +16141,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16275,8 +16141,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16275 ira->src_implicit_return_type_list.append(value);16141 ira->src_implicit_return_type_list.append(value);
16276 }16142 }
16277 peer_parent->skipped = true;16143 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,
16279 value_type, value, force_runtime || !is_comptime, true, true);16145 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;
16280 }16150 }
1628116151
16282 if (peer_parent->resolved_type == nullptr) {16152 if (peer_parent->resolved_type == nullptr) {
...@@ -16317,30 +16187,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16317,30 +16187,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16317 force_runtime, non_null_comptime);16187 force_runtime, non_null_comptime);
16318 }16188 }
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.
16332 IrInstruction *casted_value;16190 IrInstruction *casted_value;
16333 if (value != nullptr) {16191 if (value != nullptr) {
16334 casted_value = ir_implicit_cast(ira, value, dest_type);16192 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;
16335 } else {16196 } else {
16336 casted_value = nullptr;16197 casted_value = nullptr;
16337 }16198 }
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;
16344 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,16200 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
16345 dest_type, casted_value, force_runtime, non_null_comptime, true);16201 dest_type, casted_value, force_runtime, non_null_comptime, true);
16346 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||16202 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...@@ -16378,26 +16234,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16378 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,16234 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
16379 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);16235 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1638016236
16381 {16237 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16382 // we also need to check that this cast is OK.16238 parent_result_loc->value->type, ptr_type,
16383 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,16239 result_cast->base.source_instruction->source_node, false);
16384 parent_result_loc->value->type, ptr_type,16240 if (const_cast_result.id == ConstCastResultIdInvalid)
16385 result_cast->base.source_instruction->source_node, false);16241 return ira->codegen->invalid_instruction;
16386 if (const_cast_result.id == ConstCastResultIdInvalid)16242 if (const_cast_result.id != ConstCastResultIdOk) {
16387 return ira->codegen->invalid_instruction;16243 if (allow_discard) {
16388 if (const_cast_result.id != ConstCastResultIdOk) {16244 return parent_result_loc;
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);
16394 }16245 }
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);
16395 }16251 }
1639616252
16397 result_loc->written = true;16253 return ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
16398 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
16399 ptr_type, result_cast->base.source_instruction, false);16254 ptr_type, result_cast->base.source_instruction, false);
16400 return result_loc->resolved_loc;
16401 }16255 }
16402 case ResultLocIdBitCast: {16256 case ResultLocIdBitCast: {
16403 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);16257 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
...@@ -16483,7 +16337,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -16483,7 +16337,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16483 result_loc_pass1 = no_result_loc();16337 result_loc_pass1 = no_result_loc();
16484 }16338 }
16485 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,16339 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);
16487 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))16341 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
16488 return result_loc;16342 return result_loc;
1648916343
...@@ -16496,7 +16350,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -16496,7 +16350,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16496 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);16350 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
16497 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;16351 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
16498 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&16352 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
16499 value_type->id != ZigTypeIdNull)16353 value_type->id != ZigTypeIdNull && value == nullptr)
16500 {16354 {
16501 result_loc_pass1->written = false;16355 result_loc_pass1->written = false;
16502 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);16356 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...@@ -16514,9 +16368,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16514 return unwrapped_err_ptr;16368 return unwrapped_err_ptr;
16515 }16369 }
16516 }16370 }
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;
16520 }16371 }
16521 return result_loc;16372 return result_loc;
16522}16373}
...@@ -17520,11 +17371,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17520,11 +17371,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17520 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {17371 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
17521 ir_reset_result(call_instruction->result_loc);17372 ir_reset_result(call_instruction->result_loc);
17522 result_loc = nullptr;17373 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;
17528 }17374 }
17529 }17375 }
17530 } else if (call_instruction->is_async_call_builtin) {17376 } else if (call_instruction->is_async_call_builtin) {
...@@ -17687,11 +17533,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17687,11 +17533,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17687 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {17533 if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
17688 ir_reset_result(call_instruction->result_loc);17534 ir_reset_result(call_instruction->result_loc);
17689 result_loc = nullptr;17535 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;
17695 }17536 }
17696 }17537 }
17697 } else if (call_instruction->is_async_call_builtin) {17538 } else if (call_instruction->is_async_call_builtin) {
...@@ -21041,6 +20882,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21041,6 +20882,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
21041 {20882 {
21042 // We're now done inferring the type.20883 // We're now done inferring the type.
21043 container_type->data.structure.resolve_status = ResolveStatusUnstarted;20884 container_type->data.structure.resolve_status = ResolveStatusUnstarted;
20885 } else if (container_type->id == ZigTypeIdVector) {
20886 // OK
21044 } else {20887 } else {
21045 ir_add_error_node(ira, instruction->base.source_node,20888 ir_add_error_node(ira, instruction->base.source_node,
21046 buf_sprintf("type '%s' does not support array initialization",20889 buf_sprintf("type '%s' does not support array initialization",
...@@ -22434,17 +22277,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -22434,17 +22277,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
22434 return result;22277 return result;
22435}22278}
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)
22438{22282{
22283 Error err;
22439 ensure_field_index(struct_value->type, name, field_index);22284 ensure_field_index(struct_value->type, name, field_index);
22440 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);22285 ZigValue *val = struct_value->data.x_struct.fields[field_index];
22441 return 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;
22442}22289}
2244322290
22444static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,22291static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
22445 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)22292 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
22446{22293{
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;
22448 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);22297 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
22449 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,22298 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
22450 get_optional_type(ira->codegen, elem_type));22299 get_optional_type(ira->codegen, elem_type));
...@@ -22455,23 +22304,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst...@@ -22455,23 +22304,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
22455 return ErrorNone;22304 return ErrorNone;
22456}22305}
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)
22459{22309{
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;
22461 assert(value->type == ira->codegen->builtin_types.entry_bool);22313 assert(value->type == ira->codegen->builtin_types.entry_bool);
22462 return value->data.x_bool;22314 *out = value->data.x_bool;
22315 return ErrorNone;
22463}22316}
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)
22466{22319{
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;
22468 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);22323 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
22469 return &value->data.x_bigint;22324 return &value->data.x_bigint;
22470}22325}
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)
22473{22328{
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;
22475 assert(value->type == ira->codegen->builtin_types.entry_type);22332 assert(value->type == ira->codegen->builtin_types.entry_type);
22476 return value->data.x_type;22333 return value->data.x_type;
22477}22334}
...@@ -22489,17 +22346,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22489,17 +22346,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22489 return ira->codegen->builtin_types.entry_bool;22346 return ira->codegen->builtin_types.entry_bool;
22490 case ZigTypeIdUnreachable:22347 case ZigTypeIdUnreachable:
22491 return ira->codegen->builtin_types.entry_unreachable;22348 return ira->codegen->builtin_types.entry_unreachable;
22492 case ZigTypeIdInt:22349 case ZigTypeIdInt: {
22493 assert(payload->special == ConstValSpecialStatic);22350 assert(payload->special == ConstValSpecialStatic);
22494 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));22351 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
22495 return get_int_type(ira->codegen,22352 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
22496 get_const_field_bool(ira, payload, "is_signed", 0),22353 if (bi == nullptr)
22497 bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1)));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 }
22498 case ZigTypeIdFloat:22360 case ZigTypeIdFloat:
22499 {22361 {
22500 assert(payload->special == ConstValSpecialStatic);22362 assert(payload->special == ConstValSpecialStatic);
22501 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));22363 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);
22503 switch (bits) {22368 switch (bits) {
22504 case 16: return ira->codegen->builtin_types.entry_f16;22369 case 16: return ira->codegen->builtin_types.entry_f16;
22505 case 32: return ira->codegen->builtin_types.entry_f32;22370 case 32: return ira->codegen->builtin_types.entry_f32;
...@@ -22515,27 +22380,51 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22515,27 +22380,51 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22515 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);22380 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
22516 assert(payload->special == ConstValSpecialStatic);22381 assert(payload->special == ConstValSpecialStatic);
22517 assert(payload->type == type_info_pointer_type);22382 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);
22519 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));22384 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
22520 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);22385 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
22521 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);22386 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;
22523 ZigValue *sentinel;22390 ZigValue *sentinel;
22524 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,22391 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
22525 elem_type, &sentinel)))22392 elem_type, &sentinel)))
22526 {22393 {
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;
22528 }22416 }
2252922417
22418
22530 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,22419 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
22531 elem_type,22420 elem_type,
22532 get_const_field_bool(ira, payload, "is_const", 1),22421 is_const,
22533 get_const_field_bool(ira, payload, "is_volatile", 2),22422 is_volatile,
22534 ptr_len,22423 ptr_len,
22535 bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)),22424 bigint_as_u32(bi),
22536 0, // bit_offset_in_host22425 0, // bit_offset_in_host
22537 0, // host_int_bytes22426 0, // host_int_bytes
22538 get_const_field_bool(ira, payload, "is_allowzero", 5),22427 is_allowzero,
22539 VECTOR_INDEX_NONE, nullptr, sentinel);22428 VECTOR_INDEX_NONE, nullptr, sentinel);
22540 if (size_enum_index != 2)22429 if (size_enum_index != 2)
22541 return ptr_type;22430 return ptr_type;
...@@ -22544,17 +22433,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22544,17 +22433,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22544 case ZigTypeIdArray: {22433 case ZigTypeIdArray: {
22545 assert(payload->special == ConstValSpecialStatic);22434 assert(payload->special == ConstValSpecialStatic);
22546 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));22435 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;
22548 ZigValue *sentinel;22439 ZigValue *sentinel;
22549 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,22440 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
22550 elem_type, &sentinel)))22441 elem_type, &sentinel)))
22551 {22442 {
22552 return nullptr;22443 return ira->codegen->invalid_instruction->value->type;
22553 }22444 }
22554 return get_array_type(ira->codegen,22445 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
22555 elem_type,22446 if (bi == nullptr)
22556 bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)),22447 return ira->codegen->invalid_instruction->value->type;
22557 sentinel);22448 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
22558 }22449 }
22559 case ZigTypeIdComptimeFloat:22450 case ZigTypeIdComptimeFloat:
22560 return ira->codegen->builtin_types.entry_num_lit_float;22451 return ira->codegen->builtin_types.entry_num_lit_float;
...@@ -22575,7 +22466,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22575,7 +22466,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22575 case ZigTypeIdEnumLiteral:22466 case ZigTypeIdEnumLiteral:
22576 ir_add_error(ira, instruction, buf_sprintf(22467 ir_add_error(ira, instruction, buf_sprintf(
22577 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));22468 "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;
22579 case ZigTypeIdUnion:22470 case ZigTypeIdUnion:
22580 case ZigTypeIdFn:22471 case ZigTypeIdFn:
22581 case ZigTypeIdBoundFn:22472 case ZigTypeIdBoundFn:
...@@ -22583,7 +22474,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22583,7 +22474,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22583 case ZigTypeIdStruct:22474 case ZigTypeIdStruct:
22584 ir_add_error(ira, instruction, buf_sprintf(22475 ir_add_error(ira, instruction, buf_sprintf(
22585 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));22476 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
22586 return nullptr;22477 return ira->codegen->invalid_instruction->value->type;
22587 }22478 }
22588 zig_unreachable();22479 zig_unreachable();
22589}22480}
...@@ -22602,7 +22493,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT...@@ -22602,7 +22493,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
22602 return ira->codegen->invalid_instruction;22493 return ira->codegen->invalid_instruction;
22603 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));22494 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
22604 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);22495 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))
22606 return ira->codegen->invalid_instruction;22497 return ira->codegen->invalid_instruction;
22607 return ir_const_type(ira, &instruction->base, type);22498 return ir_const_type(ira, &instruction->base, type);
22608}22499}
...@@ -28332,3 +28223,18 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {...@@ -28332,3 +28223,18 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
28332 }28223 }
28333 return ErrorNone;28224 return ErrorNone;
28334}28225}
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 {...@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
465 \\465 \\
466 );466 );
467467
468 tc.setCommandLineArgs([_][]const u8{468 tc.setCommandLineArgs(&[_][]const u8{
469 "first arg",469 "first arg",
470 "'a' 'b' \\",470 "'a' 'b' \\",
471 "bare",471 "bare",
...@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
506 \\506 \\
507 );507 );
508508
509 tc.setCommandLineArgs([_][]const u8{509 tc.setCommandLineArgs(&[_][]const u8{
510 "first arg",510 "first arg",
511 "'a' 'b' \\",511 "'a' 'b' \\",
512 "bare",512 "bare",
test/stage1/behavior/array.zig+22-22
...@@ -20,7 +20,7 @@ test "arrays" {...@@ -20,7 +20,7 @@ test "arrays" {
20 }20 }
2121
22 expect(accumulator == 15);22 expect(accumulator == 15);
23 expect(getArrayLen(array) == 5);23 expect(getArrayLen(&array) == 5);
24}24}
25fn getArrayLen(a: []const u32) usize {25fn getArrayLen(a: []const u32) usize {
26 return a.len;26 return a.len;
...@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {...@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {
182182
183test "runtime initialize array elem and then implicit cast to slice" {183test "runtime initialize array elem and then implicit cast to slice" {
184 var two: i32 = 2;184 var two: i32 = 2;
185 const x: []const i32 = [_]i32{two};185 const x: []const i32 = &[_]i32{two};
186 expect(x[0] == 2);186 expect(x[0] == 2);
187}187}
188188
189test "array literal as argument to function" {189test "array literal as argument to function" {
190 const S = struct {190 const S = struct {
191 fn entry(two: i32) void {191 fn entry(two: i32) void {
192 foo([_]i32{192 foo(&[_]i32{
193 1,193 1,
194 2,194 2,
195 3,195 3,
196 });196 });
197 foo([_]i32{197 foo(&[_]i32{
198 1,198 1,
199 two,199 two,
200 3,200 3,
201 });201 });
202 foo2(true, [_]i32{202 foo2(true, &[_]i32{
203 1,203 1,
204 2,204 2,
205 3,205 3,
206 });206 });
207 foo2(true, [_]i32{207 foo2(true, &[_]i32{
208 1,208 1,
209 two,209 two,
210 3,210 3,
...@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {...@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {
230 const S = struct {230 const S = struct {
231 fn entry(two: i32) void {231 fn entry(two: i32) void {
232 const cases = [_][]const []const i32{232 const cases = [_][]const []const i32{
233 [_][]const i32{[_]i32{1}},233 &[_][]const i32{&[_]i32{1}},
234 [_][]const i32{[_]i32{ 2, 3 }},234 &[_][]const i32{&[_]i32{ 2, 3 }},
235 [_][]const i32{235 &[_][]const i32{
236 [_]i32{4},236 &[_]i32{4},
237 [_]i32{ 5, 6, 7 },237 &[_]i32{ 5, 6, 7 },
238 },238 },
239 };239 };
240 check(cases);240 check(&cases);
241241
242 const cases2 = [_][]const i32{242 const cases2 = [_][]const i32{
243 [_]i32{1},243 &[_]i32{1},
244 &[_]i32{ two, 3 },244 &[_]i32{ two, 3 },
245 };245 };
246 expect(cases2.len == 2);246 expect(cases2.len == 2);
...@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {...@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {
251 expect(cases2[1][1] == 3);251 expect(cases2[1][1] == 3);
252252
253 const cases3 = [_][]const []const i32{253 const cases3 = [_][]const []const i32{
254 [_][]const i32{[_]i32{1}},254 &[_][]const i32{&[_]i32{1}},
255 &[_][]const i32{&[_]i32{ two, 3 }},255 &[_][]const i32{&[_]i32{ two, 3 }},
256 [_][]const i32{256 &[_][]const i32{
257 [_]i32{4},257 &[_]i32{4},
258 [_]i32{ 5, 6, 7 },258 &[_]i32{ 5, 6, 7 },
259 },259 },
260 };260 };
261 check(cases3);261 check(&cases3);
262 }262 }
263263
264 fn check(cases: []const []const []const i32) void {264 fn check(cases: []const []const []const i32) void {
...@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {...@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {
316test "anonymous list literal syntax" {316test "anonymous list literal syntax" {
317 const S = struct {317 const S = struct {
318 fn doTheTest() void {318 fn doTheTest() void {
319 var array: [4]u8 = .{1, 2, 3, 4};319 var array: [4]u8 = .{ 1, 2, 3, 4 };
320 expect(array[0] == 1);320 expect(array[0] == 1);
321 expect(array[1] == 2);321 expect(array[1] == 2);
322 expect(array[2] == 3);322 expect(array[2] == 3);
...@@ -335,8 +335,8 @@ test "anonymous literal in array" {...@@ -335,8 +335,8 @@ test "anonymous literal in array" {
335 };335 };
336 fn doTheTest() void {336 fn doTheTest() void {
337 var array: [2]Foo = .{337 var array: [2]Foo = .{
338 .{.a = 3},338 .{ .a = 3 },
339 .{.b = 3},339 .{ .b = 3 },
340 };340 };
341 expect(array[0].a == 3);341 expect(array[0].a == 3);
342 expect(array[0].b == 4);342 expect(array[0].b == 4);
...@@ -351,7 +351,7 @@ test "anonymous literal in array" {...@@ -351,7 +351,7 @@ test "anonymous literal in array" {
351test "access the null element of a null terminated array" {351test "access the null element of a null terminated array" {
352 const S = struct {352 const S = struct {
353 fn doTheTest() void {353 fn doTheTest() void {
354 var array: [4:0]u8 = .{'a', 'o', 'e', 'u'};354 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
355 comptime expect(array[4] == 0);355 comptime expect(array[4] == 0);
356 var len: usize = 4;356 var len: usize = 4;
357 expect(array[len] == 0);357 expect(array[len] == 0);
test/stage1/behavior/async_fn.zig+6-6
...@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {...@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {
143 resume frame;143 resume frame;
144 seq('h');144 seq('h');
145145
146 expect(std.mem.eql(u8, points, "abcdefgh"));146 expect(std.mem.eql(u8, &points, "abcdefgh"));
147 }147 }
148148
149 fn amain() void {149 fn amain() void {
...@@ -206,7 +206,7 @@ test "coroutine await" {...@@ -206,7 +206,7 @@ test "coroutine await" {
206 resume await_a_promise;206 resume await_a_promise;
207 await_seq('i');207 await_seq('i');
208 expect(await_final_result == 1234);208 expect(await_final_result == 1234);
209 expect(std.mem.eql(u8, await_points, "abcdefghi"));209 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
210}210}
211async fn await_amain() void {211async fn await_amain() void {
212 await_seq('b');212 await_seq('b');
...@@ -240,7 +240,7 @@ test "coroutine await early return" {...@@ -240,7 +240,7 @@ test "coroutine await early return" {
240 var p = async early_amain();240 var p = async early_amain();
241 early_seq('f');241 early_seq('f');
242 expect(early_final_result == 1234);242 expect(early_final_result == 1234);
243 expect(std.mem.eql(u8, early_points, "abcdef"));243 expect(std.mem.eql(u8, &early_points, "abcdef"));
244}244}
245async fn early_amain() void {245async fn early_amain() void {
246 early_seq('b');246 early_seq('b');
...@@ -1166,7 +1166,7 @@ test "suspend in for loop" {...@@ -1166,7 +1166,7 @@ test "suspend in for loop" {
1166 }1166 }
11671167
1168 fn atest() void {1168 fn atest() void {
1169 expect(func([_]u8{ 1, 2, 3 }) == 6);1169 expect(func(&[_]u8{ 1, 2, 3 }) == 6);
1170 }1170 }
1171 fn func(stuff: []const u8) u32 {1171 fn func(stuff: []const u8) u32 {
1172 global_frame = @frame();1172 global_frame = @frame();
...@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {...@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {
12111211
1212 fn doTheTest() void {1212 fn doTheTest() void {
1213 var foo = Foo{1213 var foo = Foo{
1214 .slice = [_]i32{ 1, 2 },1214 .slice = &[_]i32{ 1, 2 },
1215 };1215 };
1216 expect(atest(&foo) == 3);1216 expect(atest(&foo) == 3);
1217 }1217 }
...@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {...@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
12421242
1243 fn doTheTest() void {1243 fn doTheTest() void {
1244 var foo = Foo{1244 var foo = Foo{
1245 .slice = [_]i32{ 1, 2 },1245 .slice = &[_]i32{ 1, 2 },
1246 };1246 };
1247 expect(atest(&foo) == 3);1247 expect(atest(&foo) == 3);
1248 }1248 }
test/stage1/behavior/await_struct.zig+1-1
...@@ -16,7 +16,7 @@ test "coroutine await struct" {...@@ -16,7 +16,7 @@ test "coroutine await struct" {
16 resume await_a_promise;16 resume await_a_promise;
17 await_seq('i');17 await_seq('i');
18 expect(await_final_result.x == 1234);18 expect(await_final_result.x == 1234);
19 expect(std.mem.eql(u8, await_points, "abcdefghi"));19 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
20}20}
21async fn await_amain() void {21async fn await_amain() void {
22 await_seq('b');22 await_seq('b');
test/stage1/behavior/bugs/1607.zig+2-2
...@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {...@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {
10}10}
1111
12test "slices pointing at the same address as global array." {12test "slices pointing at the same address as global array." {
13 checkAddress(a);13 checkAddress(&a);
14 comptime checkAddress(a);14 comptime checkAddress(&a);
15}15}
test/stage1/behavior/bugs/1914.zig+2-2
...@@ -7,7 +7,7 @@ const B = struct {...@@ -7,7 +7,7 @@ const B = struct {
7 a_pointer: *const A,7 a_pointer: *const A,
8};8};
99
10const b_list: []B = [_]B{};10const b_list: []B = &[_]B{};
11const a = A{ .b_list_pointer = &b_list };11const a = A{ .b_list_pointer = &b_list };
1212
13test "segfault bug" {13test "segfault bug" {
...@@ -24,7 +24,7 @@ pub const B2 = struct {...@@ -24,7 +24,7 @@ pub const B2 = struct {
24 pointer_array: []*A2,24 pointer_array: []*A2,
25};25};
2626
27var b_value = B2{ .pointer_array = [_]*A2{} };27var b_value = B2{ .pointer_array = &[_]*A2{} };
2828
29test "basic stuff" {29test "basic stuff" {
30 std.debug.assert(&b_value == &b_value);30 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" {...@@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {
150}150}
151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
152 if (a) {152 if (a) {
153 return [_]u8{};153 return &[_]u8{};
154 }154 }
155155
156 return slice[0..1];156 return slice[0..1];
...@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {...@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {
175}175}
176176
177fn gimmeErrOrSlice() anyerror![]u8 {177fn gimmeErrOrSlice() anyerror![]u8 {
178 return [_]u8{};178 return &[_]u8{};
179}179}
180180
181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {181test "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" {...@@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
200}200}
201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
202 if (a) {202 if (a) {
203 return [_]u8{};203 return &[_]u8{};
204 }204 }
205205
206 return slice[0..1];206 return slice[0..1];
...@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {...@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
457test "implicit cast from [*]T to ?*c_void" {457test "implicit cast from [*]T to ?*c_void" {
458 var a = [_]u8{ 3, 2, 1 };458 var a = [_]u8{ 3, 2, 1 };
459 incrementVoidPtrArray(a[0..].ptr, 3);459 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 }));
461}461}
462462
463fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {463fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
...@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {...@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {
606606
607test "peer resolution of string literals" {607test "peer resolution of string literals" {
608 const S = struct {608 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
611 fn doTheTest(e: E) void {616 fn doTheTest(e: E) void {
612 const cmd = switch (e) {617 const cmd = switch (e) {
...@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {...@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {
627 fn doTheTest() void {632 fn doTheTest() void {
628 // [:x]T to []T633 // [:x]T to []T
629 {634 {
630 var array = [4:0]i32{1,2,3,4};635 var array = [4:0]i32{ 1, 2, 3, 4 };
631 var slice: [:0]i32 = &array;636 var slice: [:0]i32 = &array;
632 var dest: []i32 = slice;637 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 }));
634 }639 }
635640
636 // [*:x]T to [*]T641 // [*:x]T to [*]T
637 {642 {
638 var array = [4:99]i32{1,2,3,4};643 var array = [4:99]i32{ 1, 2, 3, 4 };
639 var dest: [*]i32 = &array;644 var dest: [*]i32 = &array;
640 expect(dest[0] == 1);645 expect(dest[0] == 1);
641 expect(dest[1] == 2);646 expect(dest[1] == 2);
...@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {...@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {
646651
647 // [N:x]T to [N]T652 // [N:x]T to [N]T
648 {653 {
649 var array = [4:0]i32{1,2,3,4};654 var array = [4:0]i32{ 1, 2, 3, 4 };
650 var dest: [4]i32 = array;655 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 }));
652 }657 }
653658
654 // *[N:x]T to *[N]T659 // *[N:x]T to *[N]T
655 {660 {
656 var array = [4:0]i32{1,2,3,4};661 var array = [4:0]i32{ 1, 2, 3, 4 };
657 var dest: *[4]i32 = &array;662 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 }));
659 }664 }
660665
661 // [:x]T to [*:x]T666 // [:x]T to [*:x]T
662 {667 {
663 var array = [4:0]i32{1,2,3,4};668 var array = [4:0]i32{ 1, 2, 3, 4 };
664 var slice: [:0]i32 = &array;669 var slice: [:0]i32 = &array;
665 var dest: [*:0]i32 = slice;670 var dest: [*:0]i32 = slice;
666 expect(dest[0] == 1);671 expect(dest[0] == 1);
...@@ -674,3 +679,21 @@ test "type coercion related to sentinel-termination" {...@@ -674,3 +679,21 @@ test "type coercion related to sentinel-termination" {
674 S.doTheTest();679 S.doTheTest();
675 comptime S.doTheTest();680 comptime S.doTheTest();
676}681}
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" {...@@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" {
717 };717 };
718718
719 var b = [1]u8{9};719 var b = [1]u8{9};
720 var f = @bytesToSlice(F, b);720 var f = @bytesToSlice(F, &b);
721 expect(f[0].a == 9);721 expect(f[0].a == 9);
722}722}
723723
...@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {...@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {
774774
775test "array concatenation forces comptime" {775test "array concatenation forces comptime" {
776 var a = oneItem(3) ++ oneItem(4);776 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 }));
778}778}
779779
780test "array multiplication forces comptime" {780test "array multiplication forces comptime" {
781 var a = oneItem(3) ** scalar(2);781 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 }));
783}783}
784784
785fn oneItem(x: i32) [1]i32 {785fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/for.zig+5-5
...@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {...@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
26 var target: [source.len]u8 = undefined;26 var target: [source.len]u8 = undefined;
27 mem.copy(u8, target[0..], source);27 mem.copy(u8, target[0..], source);
28 mangleString(target[0..]);28 mangleString(target[0..]);
29 expect(mem.eql(u8, target, "bcdefgh"));29 expect(mem.eql(u8, &target, "bcdefgh"));
3030
31 for (source) |*c, i|31 for (source) |*c, i|
32 expect(@typeOf(c) == *const u8);32 expect(@typeOf(c) == *const u8);
...@@ -64,7 +64,7 @@ test "basic for loop" {...@@ -64,7 +64,7 @@ test "basic for loop" {
64 buffer[buf_index] = @intCast(u8, index);64 buffer[buf_index] = @intCast(u8, index);
65 buf_index += 1;65 buf_index += 1;
66 }66 }
67 const unknown_size: []const u8 = array;67 const unknown_size: []const u8 = &array;
68 for (unknown_size) |item| {68 for (unknown_size) |item| {
69 buffer[buf_index] = item;69 buffer[buf_index] = item;
70 buf_index += 1;70 buf_index += 1;
...@@ -74,7 +74,7 @@ test "basic for loop" {...@@ -74,7 +74,7 @@ test "basic for loop" {
74 buf_index += 1;74 buf_index += 1;
75 }75 }
7676
77 expect(mem.eql(u8, buffer[0..buf_index], expected_result));77 expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
78}78}
7979
80test "break from outer for loop" {80test "break from outer for loop" {
...@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {...@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {
139 }139 }
140 }140 }
141 };141 };
142 S.doTheTest([_]u8{ 1, 2 });142 S.doTheTest(&[_]u8{ 1, 2 });
143 comptime S.doTheTest([_]u8{ 1, 2 });143 comptime S.doTheTest(&[_]u8{ 1, 2 });
144}144}
test/stage1/behavior/generics.zig+2-2
...@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {...@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
120}120}
121121
122test "generic fn with implicit cast" {122test "generic fn with implicit cast" {
123 expect(getFirstByte(u8, [_]u8{13}) == 13);123 expect(getFirstByte(u8, &[_]u8{13}) == 13);
124 expect(getFirstByte(u16, [_]u16{124 expect(getFirstByte(u16, &[_]u16{
125 0,125 0,
126 13,126 13,
127 }) == 0);127 }) == 0);
test/stage1/behavior/misc.zig+3-3
...@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}...@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}
241241
242test "cast undefined" {242test "cast undefined" {
243 const array: [100]u8 = undefined;243 const array: [100]u8 = undefined;
244 const slice = @as([]const u8, array);244 const slice = @as([]const u8, &array);
245 testCastUndefined(slice);245 testCastUndefined(slice);
246}246}
247fn testCastUndefined(x: []const u8) void {}247fn testCastUndefined(x: []const u8) void {}
...@@ -614,7 +614,7 @@ test "slicing zero length array" {...@@ -614,7 +614,7 @@ test "slicing zero length array" {
614 expect(s1.len == 0);614 expect(s1.len == 0);
615 expect(s2.len == 0);615 expect(s2.len == 0);
616 expect(mem.eql(u8, s1, ""));616 expect(mem.eql(u8, s1, ""));
617 expect(mem.eql(u32, s2, [_]u32{}));617 expect(mem.eql(u32, s2, &[_]u32{}));
618}618}
619619
620const addr1 = @ptrCast(*const u8, emptyFn);620const addr1 = @ptrCast(*const u8, emptyFn);
...@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic...@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic
710 const E = struct {710 const E = struct {
711 entries: []u32,711 entries: []u32,
712 };712 };
713 var foo = E{ .entries = [_]u32{} };713 var foo = E{ .entries = &[_]u32{} };
714 expect(foo.entries.len == 0);714 expect(foo.entries.len == 0);
715}715}
716716
test/stage1/behavior/ptrcast.zig+1-1
...@@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {...@@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {
3737
38test "reinterpret struct field at comptime" {38test "reinterpret struct field at comptime" {
39 const numLittle = comptime Bytes.init(0x12345678);39 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));
41}41}
4242
43const Bytes = struct {43const Bytes = struct {
test/stage1/behavior/shuffle.zig+7-7
...@@ -9,28 +9,28 @@ test "@shuffle" {...@@ -9,28 +9,28 @@ test "@shuffle" {
9 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };9 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
10 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };10 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
11 var res = @shuffle(i32, v, x, mask);11 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
14 // Implicit cast from array (of mask)14 // Implicit cast from array (of mask)
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));16 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1717
18 // Undefined18 // Undefined
19 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };19 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
20 res = @shuffle(i32, v, undefined, mask2);20 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
23 // Upcasting of b23 // Upcasting of b
24 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };24 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
25 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };25 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
26 res = @shuffle(i32, x, v2, mask3);26 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
29 // Upcasting of a29 // Upcasting of a
30 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };30 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
32 res = @shuffle(i32, v3, x, mask4);32 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
35 // bool35 // bool
36 // Disabled because of #331736 // Disabled because of #3317
...@@ -39,7 +39,7 @@ test "@shuffle" {...@@ -39,7 +39,7 @@ test "@shuffle" {
39 var v4: @Vector(2, bool) = [2]bool{ true, false };39 var v4: @Vector(2, bool) = [2]bool{ true, false };
40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
41 var res2 = @shuffle(bool, x2, v4, mask5);41 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 }));
43 }43 }
4444
45 // TODO re-enable when LLVM codegen is fixed45 // TODO re-enable when LLVM codegen is fixed
...@@ -49,7 +49,7 @@ test "@shuffle" {...@@ -49,7 +49,7 @@ test "@shuffle" {
49 var v4: @Vector(2, bool) = [2]bool{ true, false };49 var v4: @Vector(2, bool) = [2]bool{ true, false };
50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
51 var res2 = @shuffle(bool, x2, v4, mask5);51 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 }));
53 }53 }
54 }54 }
55 };55 };
test/stage1/behavior/slice.zig+3-3
...@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {...@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
2828
29test "implicitly cast array of size 0 to slice" {29test "implicitly cast array of size 0 to slice" {
30 var msg = [_]u8{};30 var msg = [_]u8{};
31 assertLenIsZero(msg);31 assertLenIsZero(&msg);
32}32}
3333
34fn assertLenIsZero(msg: []const u8) void {34fn assertLenIsZero(msg: []const u8) void {
...@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {...@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {
51}51}
5252
53test "comptime slices are disambiguated" {53test "comptime slices are disambiguated" {
54 expect(sliceSum([_]u8{ 1, 2 }) == 3);54 expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
55 expect(sliceSum([_]u8{ 3, 4 }) == 7);55 expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
56}56}
5757
58test "slice type with custom alignment" {58test "slice type with custom alignment" {
test/stage1/behavior/struct.zig+5-4
...@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {...@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
184}184}
185185
186test "pass slice of empty struct to fn" {186test "pass slice of empty struct to fn" {
187 expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1);187 expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
188}188}
189fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {189fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
190 return slice.len;190 return slice.len;
...@@ -432,7 +432,7 @@ const Expr = union(enum) {...@@ -432,7 +432,7 @@ const Expr = union(enum) {
432};432};
433433
434fn alloc(comptime T: type) []T {434fn alloc(comptime T: type) []T {
435 return [_]T{};435 return &[_]T{};
436}436}
437437
438test "call method with mutable reference to struct with no fields" {438test "call method with mutable reference to struct with no fields" {
...@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {...@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {
495 .a = true,495 .a = true,
496 .b = "abcdefghijklmnopqurstu".*,496 .b = "abcdefghijklmnopqurstu".*,
497 };497 };
498 bar(foo.b);498 const value = foo.b;
499 bar(&value);
499 }500 }
500 };501 };
501 S.doTheTest();502 S.doTheTest();
...@@ -783,7 +784,7 @@ test "struct with var field" {...@@ -783,7 +784,7 @@ test "struct with var field" {
783 x: var,784 x: var,
784 y: var,785 y: var,
785 };786 };
786 const pt = Point {787 const pt = Point{
787 .x = 1,788 .x = 1,
788 .y = 2,789 .y = 2,
789 };790 };
test/stage1/behavior/struct_contains_slice_of_itself.zig+8-8
...@@ -14,21 +14,21 @@ test "struct contains slice of itself" {...@@ -14,21 +14,21 @@ test "struct contains slice of itself" {
14 var other_nodes = [_]Node{14 var other_nodes = [_]Node{
15 Node{15 Node{
16 .payload = 31,16 .payload = 31,
17 .children = [_]Node{},17 .children = &[_]Node{},
18 },18 },
19 Node{19 Node{
20 .payload = 32,20 .payload = 32,
21 .children = [_]Node{},21 .children = &[_]Node{},
22 },22 },
23 };23 };
24 var nodes = [_]Node{24 var nodes = [_]Node{
25 Node{25 Node{
26 .payload = 1,26 .payload = 1,
27 .children = [_]Node{},27 .children = &[_]Node{},
28 },28 },
29 Node{29 Node{
30 .payload = 2,30 .payload = 2,
31 .children = [_]Node{},31 .children = &[_]Node{},
32 },32 },
33 Node{33 Node{
34 .payload = 3,34 .payload = 3,
...@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {...@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {
51 var other_nodes = [_]NodeAligned{51 var other_nodes = [_]NodeAligned{
52 NodeAligned{52 NodeAligned{
53 .payload = 31,53 .payload = 31,
54 .children = [_]NodeAligned{},54 .children = &[_]NodeAligned{},
55 },55 },
56 NodeAligned{56 NodeAligned{
57 .payload = 32,57 .payload = 32,
58 .children = [_]NodeAligned{},58 .children = &[_]NodeAligned{},
59 },59 },
60 };60 };
61 var nodes = [_]NodeAligned{61 var nodes = [_]NodeAligned{
62 NodeAligned{62 NodeAligned{
63 .payload = 1,63 .payload = 1,
64 .children = [_]NodeAligned{},64 .children = &[_]NodeAligned{},
65 },65 },
66 NodeAligned{66 NodeAligned{
67 .payload = 2,67 .payload = 2,
68 .children = [_]NodeAligned{},68 .children = &[_]NodeAligned{},
69 },69 },
70 NodeAligned{70 NodeAligned{
71 .payload = 3,71 .payload = 3,
test/stage1/behavior/type.zig+12-12
...@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {...@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {
1212
13test "Type.MetaType" {13test "Type.MetaType" {
14 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));14 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
15 testTypes([_]type{type});15 testTypes(&[_]type{type});
16}16}
1717
18test "Type.Void" {18test "Type.Void" {
19 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));19 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
20 testTypes([_]type{void});20 testTypes(&[_]type{void});
21}21}
2222
23test "Type.Bool" {23test "Type.Bool" {
24 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));24 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
25 testTypes([_]type{bool});25 testTypes(&[_]type{bool});
26}26}
2727
28test "Type.NoReturn" {28test "Type.NoReturn" {
29 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));29 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
30 testTypes([_]type{noreturn});30 testTypes(&[_]type{noreturn});
31}31}
3232
33test "Type.Int" {33test "Type.Int" {
...@@ -37,7 +37,7 @@ test "Type.Int" {...@@ -37,7 +37,7 @@ test "Type.Int" {
37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));
38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));
39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));39 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 });
41}41}
4242
43test "Type.Float" {43test "Type.Float" {
...@@ -45,11 +45,11 @@ test "Type.Float" {...@@ -45,11 +45,11 @@ test "Type.Float" {
45 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));45 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
46 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));46 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
47 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));47 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
48 testTypes([_]type{ f16, f32, f64, f128 });48 testTypes(&[_]type{ f16, f32, f64, f128 });
49}49}
5050
51test "Type.Pointer" {51test "Type.Pointer" {
52 testTypes([_]type{52 testTypes(&[_]type{
53 // One Value Pointer Types53 // One Value Pointer Types
54 *u8, *const u8,54 *u8, *const u8,
55 *volatile u8, *const volatile u8,55 *volatile u8, *const volatile u8,
...@@ -115,18 +115,18 @@ test "Type.Array" {...@@ -115,18 +115,18 @@ test "Type.Array" {
115 .sentinel = 0,115 .sentinel = 0,
116 },116 },
117 }));117 }));
118 testTypes([_]type{ [1]u8, [30]usize, [7]bool });118 testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
119}119}
120120
121test "Type.ComptimeFloat" {121test "Type.ComptimeFloat" {
122 testTypes([_]type{comptime_float});122 testTypes(&[_]type{comptime_float});
123}123}
124test "Type.ComptimeInt" {124test "Type.ComptimeInt" {
125 testTypes([_]type{comptime_int});125 testTypes(&[_]type{comptime_int});
126}126}
127test "Type.Undefined" {127test "Type.Undefined" {
128 testTypes([_]type{@typeOf(undefined)});128 testTypes(&[_]type{@typeOf(undefined)});
129}129}
130test "Type.Null" {130test "Type.Null" {
131 testTypes([_]type{@typeOf(null)});131 testTypes(&[_]type{@typeOf(null)});
132}132}
test/stage1/behavior/union.zig+1-1
...@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {...@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {
241};241};
242242
243test "constant packed union" {243test "constant packed union" {
244 testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }});244 testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
245}245}
246246
247fn testConstPackedUnion(expected_tokens: []const PackThis) void {247fn testConstPackedUnion(expected_tokens: []const PackThis) void {
test/stage1/behavior/vector.zig+27-27
...@@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" {...@@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" {
8 fn doTheTest() void {8 fn doTheTest() void {
9 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };9 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };
10 const result_array: [4]bool = a;10 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 }));
12 }12 }
13 };13 };
14 S.doTheTest();14 S.doTheTest();
...@@ -20,11 +20,11 @@ test "vector wrap operators" {...@@ -20,11 +20,11 @@ test "vector wrap operators" {
20 fn doTheTest() void {20 fn doTheTest() void {
21 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };21 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
22 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };22 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 }));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 }));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 }));25 expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
26 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };26 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 }));
28 }28 }
29 };29 };
30 S.doTheTest();30 S.doTheTest();
...@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {...@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
36 fn doTheTest() void {36 fn doTheTest() void {
37 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };37 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
38 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };38 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 }));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 }));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 }));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 }));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 }));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 }));44 expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
45 }45 }
46 };46 };
47 S.doTheTest();47 S.doTheTest();
...@@ -53,10 +53,10 @@ test "vector int operators" {...@@ -53,10 +53,10 @@ test "vector int operators" {
53 fn doTheTest() void {53 fn doTheTest() void {
54 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };54 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
55 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };55 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 }));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 }));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 }));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 }));59 expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
60 }60 }
61 };61 };
62 S.doTheTest();62 S.doTheTest();
...@@ -68,10 +68,10 @@ test "vector float operators" {...@@ -68,10 +68,10 @@ test "vector float operators" {
68 fn doTheTest() void {68 fn doTheTest() void {
69 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };69 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
70 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };70 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 }));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 }));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 }));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 }));74 expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
75 }75 }
76 };76 };
77 S.doTheTest();77 S.doTheTest();
...@@ -83,9 +83,9 @@ test "vector bit operators" {...@@ -83,9 +83,9 @@ test "vector bit operators" {
83 fn doTheTest() void {83 fn doTheTest() void {
84 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };84 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
85 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };85 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 }));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 }));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 }));88 expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
89 }89 }
90 };90 };
91 S.doTheTest();91 S.doTheTest();
...@@ -98,7 +98,7 @@ test "implicit cast vector to array" {...@@ -98,7 +98,7 @@ test "implicit cast vector to array" {
98 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };98 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
99 var result_array: [4]i32 = a;99 var result_array: [4]i32 = a;
100 result_array = a;100 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 }));
102 }102 }
103 };103 };
104 S.doTheTest();104 S.doTheTest();
...@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {...@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120 {120 {
121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122 var x: [4]u3 = v;122 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)));
124 }124 }
125 {125 {
126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127 var x: [4]u2 = v;127 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)));
129 }129 }
130 {130 {
131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132 var x: [4]u1 = v;132 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)));
134 }134 }
135 {135 {
136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137 var x: [4]bool = v;137 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)));
139 }139 }
140 }140 }
141 };141 };
test/tests.zig+16-16
...@@ -325,7 +325,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M...@@ -325,7 +325,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
325325
326 const exe = b.addExecutable("test-cli", "test/cli.zig");326 const exe = b.addExecutable("test-cli", "test/cli.zig");
327 const run_cmd = exe.run();327 const run_cmd = exe.run();
328 run_cmd.addArgs([_][]const u8{328 run_cmd.addArgs(&[_][]const u8{
329 fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,329 fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
330 b.pathFromRoot(b.cache_root),330 b.pathFromRoot(b.cache_root),
331 });331 });
...@@ -411,7 +411,7 @@ pub fn addPkgTests(...@@ -411,7 +411,7 @@ pub fn addPkgTests(
411 const ArchTag = @TagType(builtin.Arch);411 const ArchTag = @TagType(builtin.Arch);
412 if (test_target.disable_native and412 if (test_target.disable_native and
413 test_target.target.getOs() == builtin.os and413 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))
415 {415 {
416 continue;416 continue;
417 }417 }
...@@ -429,7 +429,7 @@ pub fn addPkgTests(...@@ -429,7 +429,7 @@ pub fn addPkgTests(
429 "bare";429 "bare";
430430
431 const triple_prefix = if (test_target.target == .Native)431 const triple_prefix = if (test_target.target == .Native)
432 @as([]const u8,"native")432 @as([]const u8, "native")
433 else433 else
434 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;434 test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
435435
...@@ -626,7 +626,7 @@ pub const CompareOutputContext = struct {...@@ -626,7 +626,7 @@ pub const CompareOutputContext = struct {
626626
627 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);627 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;
630 defer child.deinit();630 defer child.deinit();
631631
632 child.env_map = b.env_map;632 child.env_map = b.env_map;
...@@ -667,7 +667,7 @@ pub const CompareOutputContext = struct {...@@ -667,7 +667,7 @@ pub const CompareOutputContext = struct {
667 .expected_output = expected_output,667 .expected_output = expected_output,
668 .link_libc = false,668 .link_libc = false,
669 .special = special,669 .special = special,
670 .cli_args = [_][]const u8{},670 .cli_args = &[_][]const u8{},
671 };671 };
672 const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";672 const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
673 tc.addSourceFile(root_src_name, source);673 tc.addSourceFile(root_src_name, source);
...@@ -704,7 +704,7 @@ pub const CompareOutputContext = struct {...@@ -704,7 +704,7 @@ pub const CompareOutputContext = struct {
704704
705 const root_src = fs.path.join(705 const root_src = fs.path.join(
706 b.allocator,706 b.allocator,
707 [_][]const u8{ b.cache_root, case.sources.items[0].filename },707 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
708 ) catch unreachable;708 ) catch unreachable;
709709
710 switch (case.special) {710 switch (case.special) {
...@@ -720,7 +720,7 @@ pub const CompareOutputContext = struct {...@@ -720,7 +720,7 @@ pub const CompareOutputContext = struct {
720 for (case.sources.toSliceConst()) |src_file| {720 for (case.sources.toSliceConst()) |src_file| {
721 const expanded_src_path = fs.path.join(721 const expanded_src_path = fs.path.join(
722 b.allocator,722 b.allocator,
723 [_][]const u8{ b.cache_root, src_file.filename },723 &[_][]const u8{ b.cache_root, src_file.filename },
724 ) catch unreachable;724 ) catch unreachable;
725 const write_src = b.addWriteFile(expanded_src_path, src_file.source);725 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
726 exe.step.dependOn(&write_src.step);726 exe.step.dependOn(&write_src.step);
...@@ -752,7 +752,7 @@ pub const CompareOutputContext = struct {...@@ -752,7 +752,7 @@ pub const CompareOutputContext = struct {
752 for (case.sources.toSliceConst()) |src_file| {752 for (case.sources.toSliceConst()) |src_file| {
753 const expanded_src_path = fs.path.join(753 const expanded_src_path = fs.path.join(
754 b.allocator,754 b.allocator,
755 [_][]const u8{ b.cache_root, src_file.filename },755 &[_][]const u8{ b.cache_root, src_file.filename },
756 ) catch unreachable;756 ) catch unreachable;
757 const write_src = b.addWriteFile(expanded_src_path, src_file.source);757 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
758 exe.step.dependOn(&write_src.step);758 exe.step.dependOn(&write_src.step);
...@@ -783,7 +783,7 @@ pub const CompareOutputContext = struct {...@@ -783,7 +783,7 @@ pub const CompareOutputContext = struct {
783 for (case.sources.toSliceConst()) |src_file| {783 for (case.sources.toSliceConst()) |src_file| {
784 const expanded_src_path = fs.path.join(784 const expanded_src_path = fs.path.join(
785 b.allocator,785 b.allocator,
786 [_][]const u8{ b.cache_root, src_file.filename },786 &[_][]const u8{ b.cache_root, src_file.filename },
787 ) catch unreachable;787 ) catch unreachable;
788 const write_src = b.addWriteFile(expanded_src_path, src_file.source);788 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
789 exe.step.dependOn(&write_src.step);789 exe.step.dependOn(&write_src.step);
...@@ -816,7 +816,7 @@ pub const StackTracesContext = struct {...@@ -816,7 +816,7 @@ pub const StackTracesContext = struct {
816816
817 const source_pathname = fs.path.join(817 const source_pathname = fs.path.join(
818 b.allocator,818 b.allocator,
819 [_][]const u8{ b.cache_root, "source.zig" },819 &[_][]const u8{ b.cache_root, "source.zig" },
820 ) catch unreachable;820 ) catch unreachable;
821821
822 for (self.modes) |mode| {822 for (self.modes) |mode| {
...@@ -1073,7 +1073,7 @@ pub const CompileErrorContext = struct {...@@ -1073,7 +1073,7 @@ pub const CompileErrorContext = struct {
10731073
1074 const root_src = fs.path.join(1074 const root_src = fs.path.join(
1075 b.allocator,1075 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 },
1077 ) catch unreachable;1077 ) catch unreachable;
10781078
1079 var zig_args = ArrayList([]const u8).init(b.allocator);1079 var zig_args = ArrayList([]const u8).init(b.allocator);
...@@ -1270,7 +1270,7 @@ pub const CompileErrorContext = struct {...@@ -1270,7 +1270,7 @@ pub const CompileErrorContext = struct {
1270 for (case.sources.toSliceConst()) |src_file| {1270 for (case.sources.toSliceConst()) |src_file| {
1271 const expanded_src_path = fs.path.join(1271 const expanded_src_path = fs.path.join(
1272 b.allocator,1272 b.allocator,
1273 [_][]const u8{ b.cache_root, src_file.filename },1273 &[_][]const u8{ b.cache_root, src_file.filename },
1274 ) catch unreachable;1274 ) catch unreachable;
1275 const write_src = b.addWriteFile(expanded_src_path, src_file.source);1275 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
1276 compile_and_cmp_errors.step.dependOn(&write_src.step);1276 compile_and_cmp_errors.step.dependOn(&write_src.step);
...@@ -1404,7 +1404,7 @@ pub const TranslateCContext = struct {...@@ -1404,7 +1404,7 @@ pub const TranslateCContext = struct {
14041404
1405 const root_src = fs.path.join(1405 const root_src = fs.path.join(
1406 b.allocator,1406 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 },
1408 ) catch unreachable;1408 ) catch unreachable;
14091409
1410 var zig_args = ArrayList([]const u8).init(b.allocator);1410 var zig_args = ArrayList([]const u8).init(b.allocator);
...@@ -1577,7 +1577,7 @@ pub const TranslateCContext = struct {...@@ -1577,7 +1577,7 @@ pub const TranslateCContext = struct {
1577 for (case.sources.toSliceConst()) |src_file| {1577 for (case.sources.toSliceConst()) |src_file| {
1578 const expanded_src_path = fs.path.join(1578 const expanded_src_path = fs.path.join(
1579 b.allocator,1579 b.allocator,
1580 [_][]const u8{ b.cache_root, src_file.filename },1580 &[_][]const u8{ b.cache_root, src_file.filename },
1581 ) catch unreachable;1581 ) catch unreachable;
1582 const write_src = b.addWriteFile(expanded_src_path, src_file.source);1582 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
1583 translate_c_and_cmp.step.dependOn(&write_src.step);1583 translate_c_and_cmp.step.dependOn(&write_src.step);
...@@ -1700,7 +1700,7 @@ pub const GenHContext = struct {...@@ -1700,7 +1700,7 @@ pub const GenHContext = struct {
1700 const b = self.b;1700 const b = self.b;
1701 const root_src = fs.path.join(1701 const root_src = fs.path.join(
1702 b.allocator,1702 b.allocator,
1703 [_][]const u8{ b.cache_root, case.sources.items[0].filename },1703 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
1704 ) catch unreachable;1704 ) catch unreachable;
17051705
1706 const mode = builtin.Mode.Debug;1706 const mode = builtin.Mode.Debug;
...@@ -1715,7 +1715,7 @@ pub const GenHContext = struct {...@@ -1715,7 +1715,7 @@ pub const GenHContext = struct {
1715 for (case.sources.toSliceConst()) |src_file| {1715 for (case.sources.toSliceConst()) |src_file| {
1716 const expanded_src_path = fs.path.join(1716 const expanded_src_path = fs.path.join(
1717 b.allocator,1717 b.allocator,
1718 [_][]const u8{ b.cache_root, src_file.filename },1718 &[_][]const u8{ b.cache_root, src_file.filename },
1719 ) catch unreachable;1719 ) catch unreachable;
1720 const write_src = b.addWriteFile(expanded_src_path, src_file.source);1720 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
1721 obj.step.dependOn(&write_src.step);1721 obj.step.dependOn(&write_src.step);