authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-02 00:03:41-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-12-02 00:03:41-05:00
logfecd540826b14275784f10fe429ed147543377b6
treecb2e096bd1b4ec17f7badc7ac73e706d66c99df1
parent4b6740e19d57454f3c4eac0c2e9a92ce08e7ec04
parente7ee6647a16738d344173d0482028dc5578cc6c2
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #3787 from ziglang/remove-array-type-coercion

Remove array type coercion and fix result location bugs

96 files changed, 1230 insertions(+), 1148 deletions(-)

build.zig+15-15
......@@ -20,10 +20,10 @@ pub fn build(b: *Builder) !void {
2020 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
2121 const langref_out_path = fs.path.join(
2222 b.allocator,
23 [_][]const u8{ b.cache_root, "langref.html" },
23 &[_][]const u8{ b.cache_root, "langref.html" },
2424 ) catch unreachable;
2525 var docgen_cmd = docgen_exe.run();
26 docgen_cmd.addArgs([_][]const u8{
26 docgen_cmd.addArgs(&[_][]const u8{
2727 rel_zig_exe,
2828 "doc" ++ fs.path.sep_str ++ "langref.html.in",
2929 langref_out_path,
......@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {
3636 const test_step = b.step("test", "Run all the tests");
3737
3838 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 const build_info = try b.exec([_][]const u8{
39 const build_info = try b.exec(&[_][]const u8{
4040 b.zig_exe,
4141 "BUILD_INFO",
4242 });
......@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {
5656 test_stage2.setBuildMode(builtin.Mode.Debug);
5757 test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");
5858
59 const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"});
59 const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
6060
6161 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
6262 exe.setBuildMode(mode);
......@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {
8888 .source_dir = "lib",
8989 .install_dir = .Lib,
9090 .install_subdir = "zig",
91 .exclude_extensions = [_][]const u8{ "test.zig", "README.md" },
91 .exclude_extensions = &[_][]const u8{ "test.zig", "README.md" },
9292 });
9393
9494 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
......@@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
148148 }
149149 const lib_dir = fs.path.join(
150150 b.allocator,
151 [_][]const u8{ dep.prefix, "lib" },
151 &[_][]const u8{ dep.prefix, "lib" },
152152 ) catch unreachable;
153153 for (dep.system_libs.toSliceConst()) |lib| {
154154 const static_bare_name = if (mem.eql(u8, lib, "curses"))
......@@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
157157 b.fmt("lib{}.a", lib);
158158 const static_lib_name = fs.path.join(
159159 b.allocator,
160 [_][]const u8{ lib_dir, static_bare_name },
160 &[_][]const u8{ lib_dir, static_bare_name },
161161 ) catch unreachable;
162162 const have_static = fileExists(static_lib_name) catch unreachable;
163163 if (have_static) {
......@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {
183183}
184184
185185fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{
186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
187187 cmake_binary_dir,
188188 "zig_cpp",
189189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
......@@ -199,22 +199,22 @@ const LibraryDep = struct {
199199};
200200
201201fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
202 const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" });
202 const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" });
203203 const is_static = mem.startsWith(u8, shared_mode, "static");
204204 const libs_output = if (is_static)
205 try b.exec([_][]const u8{
205 try b.exec(&[_][]const u8{
206206 llvm_config_exe,
207207 "--libfiles",
208208 "--system-libs",
209209 })
210210 else
211 try b.exec([_][]const u8{
211 try b.exec(&[_][]const u8{
212212 llvm_config_exe,
213213 "--libs",
214214 });
215 const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });
216 const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" });
217 const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" });
215 const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" });
216 const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" });
217 const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
218218
219219 var result = LibraryDep{
220220 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,
......@@ -341,7 +341,7 @@ fn addCxxKnownPath(
341341 objname: []const u8,
342342 errtxt: ?[]const u8,
343343) !void {
344 const path_padded = try b.exec([_][]const u8{
344 const path_padded = try b.exec(&[_][]const u8{
345345 ctx.cxx_compiler,
346346 b.fmt("-print-file-name={}", objname),
347347 });
doc/docgen.zig+16-16
......@@ -1039,7 +1039,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10391039 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
10401040 const tmp_source_file_name = try fs.path.join(
10411041 allocator,
1042 [_][]const u8{ tmp_dir_name, name_plus_ext },
1042 &[_][]const u8{ tmp_dir_name, name_plus_ext },
10431043 );
10441044 try io.writeFile(tmp_source_file_name, trimmed_raw_source);
10451045
......@@ -1048,7 +1048,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10481048 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
10491049 var build_args = std.ArrayList([]const u8).init(allocator);
10501050 defer build_args.deinit();
1051 try build_args.appendSlice([_][]const u8{
1051 try build_args.appendSlice(&[_][]const u8{
10521052 zig_exe,
10531053 "build-exe",
10541054 tmp_source_file_name,
......@@ -1079,7 +1079,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10791079 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
10801080 const full_path_object = try fs.path.join(
10811081 allocator,
1082 [_][]const u8{ tmp_dir_name, name_with_ext },
1082 &[_][]const u8{ tmp_dir_name, name_with_ext },
10831083 );
10841084 try build_args.append("--object");
10851085 try build_args.append(full_path_object);
......@@ -1090,7 +1090,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10901090 try out.print(" -lc");
10911091 }
10921092 if (code.target_str) |triple| {
1093 try build_args.appendSlice([_][]const u8{ "-target", triple });
1093 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
10941094 if (!code.is_inline) {
10951095 try out.print(" -target {}", triple);
10961096 }
......@@ -1143,7 +1143,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11431143 }
11441144
11451145 const path_to_exe = mem.trim(u8, exec_result.stdout, " \r\n");
1146 const run_args = [_][]const u8{path_to_exe};
1146 const run_args = &[_][]const u8{path_to_exe};
11471147
11481148 var exited_with_signal = false;
11491149
......@@ -1184,7 +1184,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11841184 var test_args = std.ArrayList([]const u8).init(allocator);
11851185 defer test_args.deinit();
11861186
1187 try test_args.appendSlice([_][]const u8{
1187 try test_args.appendSlice(&[_][]const u8{
11881188 zig_exe,
11891189 "test",
11901190 tmp_source_file_name,
......@@ -1212,7 +1212,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12121212 try out.print(" -lc");
12131213 }
12141214 if (code.target_str) |triple| {
1215 try test_args.appendSlice([_][]const u8{ "-target", triple });
1215 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
12161216 try out.print(" -target {}", triple);
12171217 }
12181218 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
......@@ -1224,7 +1224,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12241224 var test_args = std.ArrayList([]const u8).init(allocator);
12251225 defer test_args.deinit();
12261226
1227 try test_args.appendSlice([_][]const u8{
1227 try test_args.appendSlice(&[_][]const u8{
12281228 zig_exe,
12291229 "test",
12301230 "--color",
......@@ -1283,7 +1283,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12831283 var test_args = std.ArrayList([]const u8).init(allocator);
12841284 defer test_args.deinit();
12851285
1286 try test_args.appendSlice([_][]const u8{
1286 try test_args.appendSlice(&[_][]const u8{
12871287 zig_exe,
12881288 "test",
12891289 tmp_source_file_name,
......@@ -1345,7 +1345,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13451345 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
13461346 const tmp_obj_file_name = try fs.path.join(
13471347 allocator,
1348 [_][]const u8{ tmp_dir_name, name_plus_obj_ext },
1348 &[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
13491349 );
13501350 var build_args = std.ArrayList([]const u8).init(allocator);
13511351 defer build_args.deinit();
......@@ -1353,10 +1353,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13531353 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
13541354 const output_h_file_name = try fs.path.join(
13551355 allocator,
1356 [_][]const u8{ tmp_dir_name, name_plus_h_ext },
1356 &[_][]const u8{ tmp_dir_name, name_plus_h_ext },
13571357 );
13581358
1359 try build_args.appendSlice([_][]const u8{
1359 try build_args.appendSlice(&[_][]const u8{
13601360 zig_exe,
13611361 "build-obj",
13621362 tmp_source_file_name,
......@@ -1395,7 +1395,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13951395 }
13961396
13971397 if (code.target_str) |triple| {
1398 try build_args.appendSlice([_][]const u8{ "-target", triple });
1398 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
13991399 try out.print(" -target {}", triple);
14001400 }
14011401
......@@ -1442,7 +1442,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14421442 var test_args = std.ArrayList([]const u8).init(allocator);
14431443 defer test_args.deinit();
14441444
1445 try test_args.appendSlice([_][]const u8{
1445 try test_args.appendSlice(&[_][]const u8{
14461446 zig_exe,
14471447 "build-lib",
14481448 tmp_source_file_name,
......@@ -1466,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14661466 },
14671467 }
14681468 if (code.target_str) |triple| {
1469 try test_args.appendSlice([_][]const u8{ "-target", triple });
1469 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
14701470 try out.print(" -target {}", triple);
14711471 }
14721472 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");
......@@ -1507,7 +1507,7 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
15071507}
15081508
15091509fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {
1510 const result = try exec(allocator, env_map, [_][]const u8{
1510 const result = try exec(allocator, env_map, &[_][]const u8{
15111511 zig_exe,
15121512 "builtin",
15131513 });
doc/langref.html.in+21-21
......@@ -1518,7 +1518,7 @@ value == null{#endsyntax#}</pre>
15181518const array1 = [_]u32{1,2};
15191519const array2 = [_]u32{3,4};
15201520const together = array1 ++ array2;
1521mem.eql(u32, together, [_]u32{1,2,3,4}){#endsyntax#}</pre>
1521mem.eql(u32, together, &[_]u32{1,2,3,4}){#endsyntax#}</pre>
15221522 </td>
15231523 </tr>
15241524 <tr>
......@@ -1621,10 +1621,10 @@ comptime {
16211621}
16221622
16231623// A string literal is a pointer to an array literal.
1624const same_message = "hello".*;
1624const same_message = "hello";
16251625
16261626comptime {
1627 assert(mem.eql(u8, message, same_message));
1627 assert(mem.eql(u8, &message, same_message));
16281628}
16291629
16301630test "iterate over an array" {
......@@ -1652,7 +1652,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };
16521652const part_two = [_]i32{ 5, 6, 7, 8 };
16531653const all_of_it = part_one ++ part_two;
16541654comptime {
1655 assert(mem.eql(i32, all_of_it, [_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
1655 assert(mem.eql(i32, &all_of_it, &[_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 }));
16561656}
16571657
16581658// remember that string literals are arrays
......@@ -4915,30 +4915,30 @@ const assert = std.debug.assert;
49154915// https://github.com/ziglang/zig/issues/265 is implemented.
49164916test "[N]T to []const T" {
49174917 var x1: []const u8 = "hello";
4918 var x2: []const u8 = [5]u8{ 'h', 'e', 'l', 'l', 111 };
4918 var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
49194919 assert(std.mem.eql(u8, x1, x2));
49204920
4921 var y: []const f32 = [2]f32{ 1.2, 3.4 };
4921 var y: []const f32 = &[2]f32{ 1.2, 3.4 };
49224922 assert(y[0] == 1.2);
49234923}
49244924
49254925// Likewise, it works when the destination type is an error union.
49264926test "[N]T to E![]const T" {
49274927 var x1: anyerror![]const u8 = "hello";
4928 var x2: anyerror![]const u8 = [5]u8{ 'h', 'e', 'l', 'l', 111 };
4928 var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
49294929 assert(std.mem.eql(u8, try x1, try x2));
49304930
4931 var y: anyerror![]const f32 = [2]f32{ 1.2, 3.4 };
4931 var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
49324932 assert((try y)[0] == 1.2);
49334933}
49344934
49354935// Likewise, it works when the destination type is an optional.
49364936test "[N]T to ?[]const T" {
49374937 var x1: ?[]const u8 = "hello";
4938 var x2: ?[]const u8 = [5]u8{ 'h', 'e', 'l', 'l', 111 };
4938 var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
49394939 assert(std.mem.eql(u8, x1.?, x2.?));
49404940
4941 var y: ?[]const f32 = [2]f32{ 1.2, 3.4 };
4941 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
49424942 assert(y.?[0] == 1.2);
49434943}
49444944
......@@ -4950,7 +4950,7 @@ test "*[N]T to []T" {
49504950
49514951 const buf2 = [2]f32{ 1.2, 3.4 };
49524952 const x2: []const f32 = &buf2;
4953 assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 }));
4953 assert(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 }));
49544954}
49554955
49564956// Single-item pointers to arrays can be coerced to
......@@ -5185,7 +5185,7 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
51855185 return @as(usize, 3);
51865186}
51875187
5188test "peer type resolution: [0]u8 and []const u8" {
5188test "peer type resolution: *[0]u8 and []const u8" {
51895189 assert(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
51905190 assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
51915191 comptime {
......@@ -5195,12 +5195,12 @@ test "peer type resolution: [0]u8 and []const u8" {
51955195}
51965196fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
51975197 if (a) {
5198 return [_]u8{};
5198 return &[_]u8{};
51995199 }
52005200
52015201 return slice[0..1];
52025202}
5203test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
5203test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
52045204 {
52055205 var data = "hi".*;
52065206 const slice = data[0..];
......@@ -5216,7 +5216,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
52165216}
52175217fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
52185218 if (a) {
5219 return [_]u8{};
5219 return &[_]u8{};
52205220 }
52215221
52225222 return slice[0..1];
......@@ -5746,7 +5746,7 @@ test "fibonacci" {
57465746 </p>
57475747 {#code_begin|test#}
57485748const first_25_primes = firstNPrimes(25);
5749const sum_of_first_25_primes = sum(first_25_primes);
5749const sum_of_first_25_primes = sum(&first_25_primes);
57505750
57515751fn firstNPrimes(comptime n: usize) [n]i32 {
57525752 var prime_list: [n]i32 = undefined;
......@@ -6364,7 +6364,7 @@ test "async function await" {
63646364 resume the_frame;
63656365 seq('i');
63666366 assert(final_result == 1234);
6367 assert(std.mem.eql(u8, seq_points, "abcdefghi"));
6367 assert(std.mem.eql(u8, &seq_points, "abcdefghi"));
63686368}
63696369fn amain() void {
63706370 seq('b');
......@@ -8014,7 +8014,7 @@ test "vector @splat" {
80148014 const scalar: u32 = 5;
80158015 const result = @splat(4, scalar);
80168016 comptime assert(@typeOf(result) == @Vector(4, u32));
8017 assert(std.mem.eql(u32, @as([4]u32, result), [_]u32{ 5, 5, 5, 5 }));
8017 assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
80188018}
80198019 {#code_end#}
80208020 <p>
......@@ -8948,7 +8948,7 @@ pub fn main() void {
89488948 {#code_begin|test_err|unable to convert#}
89498949comptime {
89508950 var bytes = [5]u8{ 1, 2, 3, 4, 5 };
8951 var slice = @bytesToSlice(u32, bytes);
8951 var slice = @bytesToSlice(u32, bytes[0..]);
89528952}
89538953 {#code_end#}
89548954 <p>At runtime:</p>
......@@ -9760,7 +9760,7 @@ pub fn build(b: *Builder) void {
97609760 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
97619761
97629762 const exe = b.addExecutable("test", null);
9763 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
9763 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
97649764 exe.linkLibrary(lib);
97659765 exe.linkSystemLibrary("c");
97669766
......@@ -9825,7 +9825,7 @@ pub fn build(b: *Builder) void {
98259825 const obj = b.addObject("base64", "base64.zig");
98269826
98279827 const exe = b.addExecutable("test", null);
9828 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
9828 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
98299829 exe.addObject(obj);
98309830 exe.linkSystemLibrary("c");
98319831 exe.install();
lib/std/array_list.zig+4-11
......@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
3535 /// Deinitialize with `deinit` or use `toOwnedSlice`.
3636 pub fn init(allocator: *Allocator) Self {
3737 return Self{
38 .items = [_]T{},
38 .items = &[_]T{},
3939 .len = 0,
4040 .allocator = allocator,
4141 };
......@@ -323,18 +323,14 @@ test "std.ArrayList.basic" {
323323 testing.expect(list.pop() == 10);
324324 testing.expect(list.len == 9);
325325
326 list.appendSlice([_]i32{
327 1,
328 2,
329 3,
330 }) catch unreachable;
326 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
331327 testing.expect(list.len == 12);
332328 testing.expect(list.pop() == 3);
333329 testing.expect(list.pop() == 2);
334330 testing.expect(list.pop() == 1);
335331 testing.expect(list.len == 9);
336332
337 list.appendSlice([_]i32{}) catch unreachable;
333 list.appendSlice(&[_]i32{}) catch unreachable;
338334 testing.expect(list.len == 9);
339335
340336 // can only set on indices < self.len
......@@ -481,10 +477,7 @@ test "std.ArrayList.insertSlice" {
481477 try list.append(2);
482478 try list.append(3);
483479 try list.append(4);
484 try list.insertSlice(1, [_]i32{
485 9,
486 8,
487 });
480 try list.insertSlice(1, &[_]i32{ 9, 8 });
488481 testing.expect(list.items[0] == 1);
489482 testing.expect(list.items[1] == 9);
490483 testing.expect(list.items[2] == 8);
lib/std/bloom_filter.zig+3-3
......@@ -62,7 +62,7 @@ pub fn BloomFilter(
6262 }
6363
6464 pub fn getCell(self: Self, cell: Index) Cell {
65 return Io.get(self.data, cell, 0);
65 return Io.get(&self.data, cell, 0);
6666 }
6767
6868 pub fn incrementCell(self: *Self, cell: Index) void {
......@@ -70,7 +70,7 @@ pub fn BloomFilter(
7070 // skip the 'get' operation
7171 Io.set(&self.data, cell, 0, cellMax);
7272 } else {
73 const old = Io.get(self.data, cell, 0);
73 const old = Io.get(&self.data, cell, 0);
7474 if (old != cellMax) {
7575 Io.set(&self.data, cell, 0, old + 1);
7676 }
......@@ -120,7 +120,7 @@ pub fn BloomFilter(
120120 } else if (newsize > n_items) {
121121 var copied: usize = 0;
122122 while (copied < r.data.len) : (copied += self.data.len) {
123 std.mem.copy(u8, r.data[copied .. copied + self.data.len], self.data);
123 std.mem.copy(u8, r.data[copied .. copied + self.data.len], &self.data);
124124 }
125125 }
126126 return r;
lib/std/build.zig+29-26
......@@ -186,7 +186,7 @@ pub const Builder = struct {
186186 pub fn resolveInstallPrefix(self: *Builder) void {
187187 if (self.dest_dir) |dest_dir| {
188188 const install_prefix = self.install_prefix orelse "/usr";
189 self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
189 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable;
190190 } else {
191191 const install_prefix = self.install_prefix orelse blk: {
192192 const p = self.cache_root;
......@@ -195,8 +195,8 @@ pub const Builder = struct {
195195 };
196196 self.install_path = install_prefix;
197197 }
198 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;
199 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;
198 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
199 self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
200200 }
201201
202202 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -803,7 +803,7 @@ pub const Builder = struct {
803803 }
804804
805805 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
806 return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable;
806 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
807807 }
808808
809809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
......@@ -818,7 +818,7 @@ pub const Builder = struct {
818818 if (fs.path.isAbsolute(name)) {
819819 return name;
820820 }
821 const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
822822 return fs.realpathAlloc(self.allocator, full_path) catch continue;
823823 }
824824 }
......@@ -827,9 +827,9 @@ pub const Builder = struct {
827827 if (fs.path.isAbsolute(name)) {
828828 return name;
829829 }
830 var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter});
830 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
831831 while (it.next()) |path| {
832 const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
832 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
833833 return fs.realpathAlloc(self.allocator, full_path) catch continue;
834834 }
835835 }
......@@ -839,7 +839,7 @@ pub const Builder = struct {
839839 return name;
840840 }
841841 for (paths) |path| {
842 const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
842 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
843843 return fs.realpathAlloc(self.allocator, full_path) catch continue;
844844 }
845845 }
......@@ -926,12 +926,12 @@ pub const Builder = struct {
926926 };
927927 return fs.path.resolve(
928928 self.allocator,
929 [_][]const u8{ base_dir, dest_rel_path },
929 &[_][]const u8{ base_dir, dest_rel_path },
930930 ) catch unreachable;
931931 }
932932
933933 fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {
934 const stdout = try self.execAllowFail([_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
934 const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
935935 var list = ArrayList(PkgConfigPkg).init(self.allocator);
936936 var line_it = mem.tokenize(stdout, "\r\n");
937937 while (line_it.next()) |line| {
......@@ -970,7 +970,7 @@ pub const Builder = struct {
970970
971971test "builder.findProgram compiles" {
972972 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");
973 _ = builder.findProgram([_][]const u8{}, [_][]const u8{}) catch null;
973 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
974974}
975975
976976/// Deprecated. Use `builtin.Version`.
......@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {
13841384 };
13851385
13861386 var code: u8 = undefined;
1387 const stdout = if (self.builder.execAllowFail([_][]const u8{
1387 const stdout = if (self.builder.execAllowFail(&[_][]const u8{
13881388 "pkg-config",
13891389 pkg_name,
13901390 "--cflags",
......@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {
15041504 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
15051505 return fs.path.join(
15061506 self.builder.allocator,
1507 [_][]const u8{ self.output_dir.?, self.out_filename },
1507 &[_][]const u8{ self.output_dir.?, self.out_filename },
15081508 ) catch unreachable;
15091509 }
15101510
......@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {
15141514 assert(self.kind == Kind.Lib);
15151515 return fs.path.join(
15161516 self.builder.allocator,
1517 [_][]const u8{ self.output_dir.?, self.out_lib_filename },
1517 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
15181518 ) catch unreachable;
15191519 }
15201520
......@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {
15251525 assert(!self.disable_gen_h);
15261526 return fs.path.join(
15271527 self.builder.allocator,
1528 [_][]const u8{ self.output_dir.?, self.out_h_filename },
1528 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
15291529 ) catch unreachable;
15301530 }
15311531
......@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {
15351535 assert(self.target.isWindows() or self.target.isUefi());
15361536 return fs.path.join(
15371537 self.builder.allocator,
1538 [_][]const u8{ self.output_dir.?, self.out_pdb_filename },
1538 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
15391539 ) catch unreachable;
15401540 }
15411541
......@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {
16051605 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
16061606 defer self.builder.allocator.free(triplet);
16071607
1608 const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" });
1608 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
16091609 errdefer allocator.free(include_path);
16101610 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });
16111611
1612 const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" });
1612 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
16131613 try self.lib_paths.append(lib_path);
16141614
1615 self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" });
1615 self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
16161616 },
16171617 }
16181618 }
......@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {
17251725 if (self.build_options_contents.len() > 0) {
17261726 const build_options_file = try fs.path.join(
17271727 builder.allocator,
1728 [_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
1728 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
17291729 );
17301730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
17311731 try zig_args.append("--pkg-begin");
......@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {
18491849 try zig_args.append("--test-cmd");
18501850 try zig_args.append(bin_name);
18511851 if (glibc_dir_arg) |dir| {
1852 const full_dir = try fs.path.join(builder.allocator, [_][]const u8{
1852 const full_dir = try fs.path.join(builder.allocator, &[_][]const u8{
18531853 dir,
18541854 try self.target.linuxTriple(builder.allocator),
18551855 });
......@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {
19941994 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
19951995
19961996 if (self.output_dir) |output_dir| {
1997 const full_dest = try fs.path.join(builder.allocator, [_][]const u8{
1997 const full_dest = try fs.path.join(builder.allocator, &[_][]const u8{
19981998 output_dir,
19991999 fs.path.basename(output_path),
20002000 });
......@@ -2176,6 +2176,9 @@ const InstallArtifactStep = struct {
21762176 if (self.artifact.isDynamicLibrary()) {
21772177 builder.pushInstalledFile(.Lib, artifact.major_only_filename);
21782178 builder.pushInstalledFile(.Lib, artifact.name_only_filename);
2179 if (self.artifact.target.isWindows()) {
2180 builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
2181 }
21792182 }
21802183 if (self.pdb_dir) |pdb_dir| {
21812184 builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
......@@ -2268,7 +2271,7 @@ pub const InstallDirStep = struct {
22682271 };
22692272
22702273 const rel_path = entry.path[full_src_dir.len + 1 ..];
2271 const dest_path = try fs.path.join(self.builder.allocator, [_][]const u8{ dest_prefix, rel_path });
2274 const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ dest_prefix, rel_path });
22722275 switch (entry.kind) {
22732276 .Directory => try fs.makePath(self.builder.allocator, dest_path),
22742277 .File => try self.builder.updateFile(entry.path, dest_path),
......@@ -2391,7 +2394,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
23912394 // sym link for libfoo.so.1 to libfoo.so.1.2.3
23922395 const major_only_path = fs.path.join(
23932396 allocator,
2394 [_][]const u8{ out_dir, filename_major_only },
2397 &[_][]const u8{ out_dir, filename_major_only },
23952398 ) catch unreachable;
23962399 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
23972400 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
......@@ -2400,7 +2403,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
24002403 // sym link for libfoo.so to libfoo.so.1
24012404 const name_only_path = fs.path.join(
24022405 allocator,
2403 [_][]const u8{ out_dir, filename_name_only },
2406 &[_][]const u8{ out_dir, filename_name_only },
24042407 ) catch unreachable;
24052408 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
24062409 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
......@@ -2413,7 +2416,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
24132416 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
24142417 defer allocator.free(appdata_path);
24152418
2416 const path_file = try fs.path.join(allocator, [_][]const u8{ appdata_path, "vcpkg.path.txt" });
2419 const path_file = try fs.path.join(allocator, &[_][]const u8{ appdata_path, "vcpkg.path.txt" });
24172420 defer allocator.free(path_file);
24182421
24192422 const file = fs.cwd().openFile(path_file, .{}) catch return null;
lib/std/child_process.zig+3-3
......@@ -571,7 +571,7 @@ pub const ChildProcess = struct {
571571 // to match posix semantics
572572 const app_name = x: {
573573 if (self.cwd) |cwd| {
574 const resolved = try fs.path.resolve(self.allocator, [_][]const u8{ cwd, self.argv[0] });
574 const resolved = try fs.path.resolve(self.allocator, &[_][]const u8{ cwd, self.argv[0] });
575575 defer self.allocator.free(resolved);
576576 break :x try cstr.addNullByte(self.allocator, resolved);
577577 } else {
......@@ -613,10 +613,10 @@ pub const ChildProcess = struct {
613613 retry: while (it.next()) |search_path| {
614614 var ext_it = mem.tokenize(PATHEXT, ";");
615615 while (ext_it.next()) |app_ext| {
616 const app_basename = try mem.concat(self.allocator, u8, [_][]const u8{ app_name[0 .. app_name.len - 1], app_ext });
616 const app_basename = try mem.concat(self.allocator, u8, &[_][]const u8{ app_name[0 .. app_name.len - 1], app_ext });
617617 defer self.allocator.free(app_basename);
618618
619 const joined_path = try fs.path.join(self.allocator, [_][]const u8{ search_path, app_basename });
619 const joined_path = try fs.path.join(self.allocator, &[_][]const u8{ search_path, app_basename });
620620 defer self.allocator.free(joined_path);
621621
622622 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);
lib/std/coff.zig+3-3
......@@ -61,7 +61,7 @@ pub const Coff = struct {
6161
6262 var magic: [2]u8 = undefined;
6363 try in.readNoEof(magic[0..]);
64 if (!mem.eql(u8, magic, "MZ"))
64 if (!mem.eql(u8, &magic, "MZ"))
6565 return error.InvalidPEMagic;
6666
6767 // Seek to PE File Header (coff header)
......@@ -71,7 +71,7 @@ pub const Coff = struct {
7171
7272 var pe_header_magic: [4]u8 = undefined;
7373 try in.readNoEof(pe_header_magic[0..]);
74 if (!mem.eql(u8, pe_header_magic, [_]u8{ 'P', 'E', 0, 0 }))
74 if (!mem.eql(u8, &pe_header_magic, &[_]u8{ 'P', 'E', 0, 0 }))
7575 return error.InvalidPEHeader;
7676
7777 self.coff_header = CoffHeader{
......@@ -163,7 +163,7 @@ pub const Coff = struct {
163163 var cv_signature: [4]u8 = undefined; // CodeView signature
164164 try in.readNoEof(cv_signature[0..]);
165165 // 'RSDS' indicates PDB70 format, used by lld.
166 if (!mem.eql(u8, cv_signature, "RSDS"))
166 if (!mem.eql(u8, &cv_signature, "RSDS"))
167167 return error.InvalidPEMagic;
168168 try in.readNoEof(self.guid[0..]);
169169 self.age = try in.readIntLittle(u32);
lib/std/crypto/aes.zig+2-2
......@@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type {
136136
137137 pub fn init(key: [keysize / 8]u8) Self {
138138 var ctx: Self = undefined;
139 expandKey(key, ctx.enc[0..], ctx.dec[0..]);
139 expandKey(&key, ctx.enc[0..], ctx.dec[0..]);
140140 return ctx;
141141 }
142142
......@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {
157157 var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);
158158 std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1);
159159
160 n += xorBytes(dst[n..], src[n..], keystream);
160 n += xorBytes(dst[n..], src[n..], &keystream);
161161 }
162162 }
163163 };
lib/std/crypto/blake2.zig+2-2
......@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {
256256 var out: [Blake2s256.digest_length]u8 = undefined;
257257
258258 var h = Blake2s256.init();
259 h.update(block);
259 h.update(&block);
260260 h.final(out[0..]);
261261}
262262
......@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {
490490 var out: [Blake2b512.digest_length]u8 = undefined;
491491
492492 var h = Blake2b512.init();
493 h.update(block);
493 h.update(&block);
494494 h.final(out[0..]);
495495}
lib/std/crypto/chacha20.zig+7-7
......@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {
218218 };
219219
220220 chaCha20IETF(result[0..], input[0..], 1, key, nonce);
221 testing.expectEqualSlices(u8, expected_result, result);
221 testing.expectEqualSlices(u8, &expected_result, &result);
222222
223223 // Chacha20 is self-reversing.
224224 var plaintext: [114]u8 = undefined;
225225 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);
226 testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal);
226 testing.expect(mem.compare(u8, input, &plaintext) == mem.Compare.Equal);
227227}
228228
229229// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
......@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {
258258 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
259259
260260 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
261 testing.expectEqualSlices(u8, expected_result, result);
261 testing.expectEqualSlices(u8, &expected_result, &result);
262262}
263263
264264test "crypto.chacha20 test vector 2" {
......@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {
292292 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
293293
294294 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
295 testing.expectEqualSlices(u8, expected_result, result);
295 testing.expectEqualSlices(u8, &expected_result, &result);
296296}
297297
298298test "crypto.chacha20 test vector 3" {
......@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {
326326 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
327327
328328 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
329 testing.expectEqualSlices(u8, expected_result, result);
329 testing.expectEqualSlices(u8, &expected_result, &result);
330330}
331331
332332test "crypto.chacha20 test vector 4" {
......@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {
360360 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
361361
362362 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
363 testing.expectEqualSlices(u8, expected_result, result);
363 testing.expectEqualSlices(u8, &expected_result, &result);
364364}
365365
366366test "crypto.chacha20 test vector 5" {
......@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {
432432 };
433433
434434 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
435 testing.expectEqualSlices(u8, expected_result, result);
435 testing.expectEqualSlices(u8, &expected_result, &result);
436436}
lib/std/crypto/gimli.zig+4-4
......@@ -83,7 +83,7 @@ test "permute" {
8383 while (i < 12) : (i += 1) {
8484 input[i] = i * i * i + i *% 0x9e3779b9;
8585 }
86 testing.expectEqualSlices(u32, input, [_]u32{
86 testing.expectEqualSlices(u32, &input, &[_]u32{
8787 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,
8888 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,
8989 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,
......@@ -92,7 +92,7 @@ test "permute" {
9292 },
9393 };
9494 state.permute();
95 testing.expectEqualSlices(u32, state.data, [_]u32{
95 testing.expectEqualSlices(u32, &state.data, &[_]u32{
9696 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,
9797 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,
9898 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,
......@@ -163,6 +163,6 @@ test "hash" {
163163 var msg: [58 / 2]u8 = undefined;
164164 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
165165 var md: [32]u8 = undefined;
166 hash(&md, msg);
167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", md);
166 hash(&md, &msg);
167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
168168}
lib/std/crypto/md5.zig+1-1
......@@ -276,6 +276,6 @@ test "md5 aligned final" {
276276 var out: [Md5.digest_length]u8 = undefined;
277277
278278 var h = Md5.init();
279 h.update(block);
279 h.update(&block);
280280 h.final(out[0..]);
281281}
lib/std/crypto/poly1305.zig+1-1
......@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
230230 var mac: [16]u8 = undefined;
231231 Poly1305.create(mac[0..], msg, key);
232232
233 std.testing.expectEqualSlices(u8, expected_mac, mac);
233 std.testing.expectEqualSlices(u8, expected_mac, &mac);
234234}
lib/std/crypto/sha1.zig+1-1
......@@ -297,6 +297,6 @@ test "sha1 aligned final" {
297297 var out: [Sha1.digest_length]u8 = undefined;
298298
299299 var h = Sha1.init();
300 h.update(block);
300 h.update(&block);
301301 h.final(out[0..]);
302302}
lib/std/crypto/sha2.zig+2-2
......@@ -343,7 +343,7 @@ test "sha256 aligned final" {
343343 var out: [Sha256.digest_length]u8 = undefined;
344344
345345 var h = Sha256.init();
346 h.update(block);
346 h.update(&block);
347347 h.final(out[0..]);
348348}
349349
......@@ -723,6 +723,6 @@ test "sha512 aligned final" {
723723 var out: [Sha512.digest_length]u8 = undefined;
724724
725725 var h = Sha512.init();
726 h.update(block);
726 h.update(&block);
727727 h.final(out[0..]);
728728}
lib/std/crypto/sha3.zig+2-2
......@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {
229229 var out: [Sha3_256.digest_length]u8 = undefined;
230230
231231 var h = Sha3_256.init();
232 h.update(block);
232 h.update(&block);
233233 h.final(out[0..]);
234234}
235235
......@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {
300300 var out: [Sha3_512.digest_length]u8 = undefined;
301301
302302 var h = Sha3_512.init();
303 h.update(block);
303 h.update(&block);
304304 h.final(out[0..]);
305305}
lib/std/crypto/test.zig+2-2
......@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
88 var h: [expected.len / 2]u8 = undefined;
99 Hasher.hash(input, h[0..]);
1010
11 assertEqual(expected, h);
11 assertEqual(expected, &h);
1212}
1313
1414// Assert `expected` == `input` where `input` is a bytestring.
......@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
1818 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
1919 }
2020
21 testing.expectEqualSlices(u8, expected_bytes, input);
21 testing.expectEqualSlices(u8, &expected_bytes, input);
2222}
lib/std/crypto/x25519.zig+18-18
......@@ -63,7 +63,7 @@ pub const X25519 = struct {
6363 var pos: isize = 254;
6464 while (pos >= 0) : (pos -= 1) {
6565 // constant time conditional swap before ladder step
66 const b = scalarBit(e, @intCast(usize, pos));
66 const b = scalarBit(&e, @intCast(usize, pos));
6767 swap ^= b; // xor trick avoids swapping at the end of the loop
6868 Fe.cswap(x2, x3, swap);
6969 Fe.cswap(z2, z3, swap);
......@@ -117,7 +117,7 @@ pub const X25519 = struct {
117117
118118 pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
119119 var base_point = [_]u8{9} ++ [_]u8{0} ** 31;
120 return create(public_key, private_key, base_point);
120 return create(public_key, private_key, &base_point);
121121 }
122122};
123123
......@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
581581 var pk_calculated: [32]u8 = undefined;
582582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
583583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));
585 std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], &sk));
585 std.testing.expect(std.mem.eql(u8, &pk_calculated, &pk_expected));
586586}
587587
588588test "x25519 rfc7748 vector1" {
......@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {
594594 var output: [32]u8 = undefined;
595595
596596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
597 std.testing.expect(std.mem.eql(u8, output, expected_output));
597 std.testing.expect(std.mem.eql(u8, &output, expected_output));
598598}
599599
600600test "x25519 rfc7748 vector2" {
......@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {
606606 var output: [32]u8 = undefined;
607607
608608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
609 std.testing.expect(std.mem.eql(u8, output, expected_output));
609 std.testing.expect(std.mem.eql(u8, &output, expected_output));
610610}
611611
612612test "x25519 rfc7748 one iteration" {
613613 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79".*;
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79";
615615
616616 var k: [32]u8 = initial_value;
617617 var u: [32]u8 = initial_value;
......@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {
619619 var i: usize = 0;
620620 while (i < 1) : (i += 1) {
621621 var output: [32]u8 = undefined;
622 std.testing.expect(X25519.create(output[0..], k, u));
622 std.testing.expect(X25519.create(output[0..], &k, &u));
623623
624624 std.mem.copy(u8, u[0..], k[0..]);
625625 std.mem.copy(u8, k[0..], output[0..]);
......@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {
634634 return error.SkipZigTest;
635635 }
636636
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51".*;
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51";
639639
640 var k: [32]u8 = initial_value;
641 var u: [32]u8 = initial_value;
640 var k: [32]u8 = initial_value.*;
641 var u: [32]u8 = initial_value.*;
642642
643643 var i: usize = 0;
644644 while (i < 1000) : (i += 1) {
645645 var output: [32]u8 = undefined;
646 std.testing.expect(X25519.create(output[0..], k, u));
646 std.testing.expect(X25519.create(output[0..], &k, &u));
647647
648648 std.mem.copy(u8, u[0..], k[0..]);
649649 std.mem.copy(u8, k[0..], output[0..]);
......@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {
657657 return error.SkipZigTest;
658658 }
659659
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24".*;
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24";
662662
663 var k: [32]u8 = initial_value;
664 var u: [32]u8 = initial_value;
663 var k: [32]u8 = initial_value.*;
664 var u: [32]u8 = initial_value.*;
665665
666666 var i: usize = 0;
667667 while (i < 1000000) : (i += 1) {
668668 var output: [32]u8 = undefined;
669 std.testing.expect(X25519.create(output[0..], k, u));
669 std.testing.expect(X25519.create(output[0..], &k, &u));
670670
671671 std.mem.copy(u8, u[0..], k[0..]);
672672 std.mem.copy(u8, k[0..], output[0..]);
lib/std/debug.zig+4-4
......@@ -825,7 +825,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
825825 const len = try di.coff.getPdbPath(path_buf[0..]);
826826 const raw_path = path_buf[0..len];
827827
828 const path = try fs.path.resolve(allocator, [_][]const u8{raw_path});
828 const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
829829
830830 try di.pdb.openFile(di.coff, path);
831831
......@@ -834,10 +834,10 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
834834 const signature = try pdb_stream.stream.readIntLittle(u32);
835835 const age = try pdb_stream.stream.readIntLittle(u32);
836836 var guid: [16]u8 = undefined;
837 try pdb_stream.stream.readNoEof(guid[0..]);
837 try pdb_stream.stream.readNoEof(&guid);
838838 if (version != 20000404) // VC70, only value observed by LLVM team
839839 return error.UnknownPDBVersion;
840 if (!mem.eql(u8, di.coff.guid, guid) or di.coff.age != age)
840 if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age)
841841 return error.PDBMismatch;
842842 // We validated the executable and pdb match.
843843
......@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {
19161916 return error.InvalidDebugInfo;
19171917 } else
19181918 self.include_dirs[file_entry.dir_index];
1919 const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name });
1919 const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name });
19201920 errdefer self.file_entries.allocator.free(file_name);
19211921 return LineInfo{
19221922 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,
lib/std/elf.zig+1-1
......@@ -381,7 +381,7 @@ pub const Elf = struct {
381381
382382 var magic: [4]u8 = undefined;
383383 try in.readNoEof(magic[0..]);
384 if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat;
384 if (!mem.eql(u8, &magic, "\x7fELF")) return error.InvalidFormat;
385385
386386 elf.is_64 = switch (try in.readByte()) {
387387 1 => false,
lib/std/event/fs.zig+1-1
......@@ -695,7 +695,7 @@ pub fn readFile(allocator: *Allocator, file_path: []const u8, max_size: usize) !
695695 try list.ensureCapacity(list.len + mem.page_size);
696696 const buf = list.items[list.len..];
697697 const buf_array = [_][]u8{buf};
698 const amt = try preadv(allocator, fd, buf_array, list.len);
698 const amt = try preadv(allocator, fd, &buf_array, list.len);
699699 list.len += amt;
700700 if (list.len > max_size) {
701701 return error.FileTooBig;
lib/std/event/loop.zig+2-2
......@@ -237,7 +237,7 @@ pub const Loop = struct {
237237 var extra_thread_index: usize = 0;
238238 errdefer {
239239 // writing 8 bytes to an eventfd cannot fail
240 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
240 os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
241241 while (extra_thread_index != 0) {
242242 extra_thread_index -= 1;
243243 self.extra_threads[extra_thread_index].wait();
......@@ -684,7 +684,7 @@ pub const Loop = struct {
684684 .linux => {
685685 self.posixFsRequest(&self.os_data.fs_end_request);
686686 // writing 8 bytes to an eventfd cannot fail
687 noasync os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
687 noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
688688 return;
689689 },
690690 .macosx, .freebsd, .netbsd, .dragonfly => {
lib/std/fifo.zig+5-5
......@@ -70,7 +70,7 @@ pub fn LinearFifo(
7070 pub fn init(allocator: *Allocator) Self {
7171 return .{
7272 .allocator = allocator,
73 .buf = [_]T{},
73 .buf = &[_]T{},
7474 .head = 0,
7575 .count = 0,
7676 };
......@@ -143,7 +143,7 @@ pub fn LinearFifo(
143143
144144 /// Returns a writable slice from the 'read' end of the fifo
145145 fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {
146 if (offset > self.count) return [_]T{};
146 if (offset > self.count) return &[_]T{};
147147
148148 var start = self.head + offset;
149149 if (start >= self.buf.len) {
......@@ -223,7 +223,7 @@ pub fn LinearFifo(
223223 /// Returns the first section of writable buffer
224224 /// Note that this may be of length 0
225225 pub fn writableSlice(self: SliceSelfArg, offset: usize) []T {
226 if (offset > self.buf.len) return [_]T{};
226 if (offset > self.buf.len) return &[_]T{};
227227
228228 const tail = self.head + offset + self.count;
229229 if (tail < self.buf.len) {
......@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {
357357 {
358358 var i: usize = 0;
359359 while (i < 5) : (i += 1) {
360 try fifo.write([_]u8{try fifo.peekItem(i)});
360 try fifo.write(&[_]u8{try fifo.peekItem(i)});
361361 }
362362 testing.expectEqual(@as(usize, 10), fifo.readableLength());
363363 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
......@@ -426,7 +426,7 @@ test "LinearFifo" {
426426 };
427427 defer fifo.deinit();
428428
429 try fifo.write([_]T{ 0, 1, 1, 0, 1 });
429 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
430430 testing.expectEqual(@as(usize, 5), fifo.readableLength());
431431
432432 {
lib/std/fmt.zig+15-10
......@@ -451,13 +451,18 @@ pub fn formatType(
451451 },
452452 },
453453 .Array => |info| {
454 if (info.child == u8) {
455 return formatText(value, fmt, options, context, Errors, output);
456 }
457 if (value.len == 0) {
458 return format(context, Errors, output, "[0]{}", @typeName(T.Child));
459 }
460 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
454 const Slice = @Type(builtin.TypeInfo{
455 .Pointer = .{
456 .size = .Slice,
457 .is_const = true,
458 .is_volatile = false,
459 .is_allowzero = false,
460 .alignment = @alignOf(info.child),
461 .child = info.child,
462 .sentinel = null,
463 },
464 });
465 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
461466 },
462467 .Fn => {
463468 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
......@@ -872,8 +877,8 @@ pub fn formatBytes(
872877 }
873878
874879 const buf = switch (radix) {
875 1000 => [_]u8{ suffix, 'B' },
876 1024 => [_]u8{ suffix, 'i', 'B' },
880 1000 => &[_]u8{ suffix, 'B' },
881 1024 => &[_]u8{ suffix, 'i', 'B' },
877882 else => unreachable,
878883 };
879884 return output(context, buf);
......@@ -969,7 +974,7 @@ fn formatIntUnsigned(
969974 if (leftover_padding == 0) break;
970975 }
971976 mem.set(u8, buf[0..index], options.fill);
972 return output(context, buf);
977 return output(context, &buf);
973978 } else {
974979 const padded_buf = buf[index - padding ..];
975980 mem.set(u8, padded_buf[0..padding], options.fill);
lib/std/fs.zig+4-4
......@@ -58,7 +58,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
5858 tmp_path[dirname.len] = path.sep;
5959 while (true) {
6060 try crypto.randomBytes(rand_buf[0..]);
61 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
61 b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf);
6262
6363 if (symLink(existing_path, tmp_path)) {
6464 return rename(tmp_path, new_path);
......@@ -226,7 +226,7 @@ pub const AtomicFile = struct {
226226
227227 while (true) {
228228 try crypto.randomBytes(rand_buf[0..]);
229 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf);
229 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], &rand_buf);
230230
231231 // TODO https://github.com/ziglang/zig/issues/3770 to clean up this @ptrCast
232232 const file = my_cwd.createFileC(
......@@ -292,7 +292,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {
292292/// have been modified regardless.
293293/// TODO determine if we can remove the allocator requirement from this function
294294pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
295 const resolved_path = try path.resolve(allocator, [_][]const u8{full_path});
295 const resolved_path = try path.resolve(allocator, &[_][]const u8{full_path});
296296 defer allocator.free(resolved_path);
297297
298298 var end_index: usize = resolved_path.len;
......@@ -611,7 +611,7 @@ pub const Dir = struct {
611611
612612 const name_utf16le = @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2];
613613
614 if (mem.eql(u16, name_utf16le, [_]u16{'.'}) or mem.eql(u16, name_utf16le, [_]u16{ '.', '.' }))
614 if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' }))
615615 continue;
616616 // Trust that Windows gives us valid UTF-16LE
617617 const name_utf8_len = std.unicode.utf16leToUtf8(self.name_data[0..], name_utf16le) catch unreachable;
lib/std/fs/get_app_data_dir.zig+3-3
......@@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
3131 error.OutOfMemory => return error.OutOfMemory,
3232 };
3333 defer allocator.free(global_dir);
34 return fs.path.join(allocator, [_][]const u8{ global_dir, appname });
34 return fs.path.join(allocator, &[_][]const u8{ global_dir, appname });
3535 },
3636 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
3737 else => return error.AppDataDirUnavailable,
......@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
4242 // TODO look in /etc/passwd
4343 return error.AppDataDirUnavailable;
4444 };
45 return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });
45 return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname });
4646 },
4747 .linux, .freebsd, .netbsd, .dragonfly => {
4848 const home_dir = os.getenv("HOME") orelse {
4949 // TODO look in /etc/passwd
5050 return error.AppDataDirUnavailable;
5151 };
52 return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname });
52 return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
5353 },
5454 else => @compileError("Unsupported OS"),
5555 }
lib/std/fs/path.zig+62-60
......@@ -15,7 +15,9 @@ pub const sep_windows = '\\';
1515pub const sep_posix = '/';
1616pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;
1717
18pub const sep_str = [1]u8{sep};
18pub const sep_str_windows = "\\";
19pub const sep_str_posix = "/";
20pub const sep_str = if (builtin.os == .windows) sep_str_windows else sep_str_posix;
1921
2022pub const delimiter_windows = ';';
2123pub const delimiter_posix = ':';
......@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
101103}
102104
103105test "join" {
104 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
105 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
106 testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
106 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
107 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
108 testJoinWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
107109
108 testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
109 testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
110 testJoinWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
111 testJoinWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
110112
111113 testJoinWindows(
112 [_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
114 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
113115 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
114116 );
115117
116 testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");
117 testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c");
118 testJoinPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
119 testJoinPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c");
118120
119 testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
120 testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
121 testJoinPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
122 testJoinPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
121123
122124 testJoinPosix(
123 [_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
125 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
124126 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
125127 );
126128
127 testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");
128 testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");
129 testJoinPosix(&[_][]const u8{ "a", "/c" }, "a/c");
130 testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
129131}
130132
131133pub fn isAbsoluteC(path_c: [*:0]const u8) bool {
......@@ -277,7 +279,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
277279 }
278280 const relative_path = WindowsPath{
279281 .kind = WindowsPath.Kind.None,
280 .disk_designator = [_]u8{},
282 .disk_designator = &[_]u8{},
281283 .is_abs = false,
282284 };
283285 if (path.len < "//a/b".len) {
......@@ -286,12 +288,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
286288
287289 inline for ("/\\") |this_sep| {
288290 const two_sep = [_]u8{ this_sep, this_sep };
289 if (mem.startsWith(u8, path, two_sep)) {
291 if (mem.startsWith(u8, path, &two_sep)) {
290292 if (path[2] == this_sep) {
291293 return relative_path;
292294 }
293295
294 var it = mem.tokenize(path, [_]u8{this_sep});
296 var it = mem.tokenize(path, &[_]u8{this_sep});
295297 _ = (it.next() orelse return relative_path);
296298 _ = (it.next() orelse return relative_path);
297299 return WindowsPath{
......@@ -353,8 +355,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
353355 const sep1 = ns1[0];
354356 const sep2 = ns2[0];
355357
356 var it1 = mem.tokenize(ns1, [_]u8{sep1});
357 var it2 = mem.tokenize(ns2, [_]u8{sep2});
358 var it1 = mem.tokenize(ns1, &[_]u8{sep1});
359 var it2 = mem.tokenize(ns2, &[_]u8{sep2});
358360
359361 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
360362 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -374,8 +376,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
374376 const sep1 = p1[0];
375377 const sep2 = p2[0];
376378
377 var it1 = mem.tokenize(p1, [_]u8{sep1});
378 var it2 = mem.tokenize(p2, [_]u8{sep2});
379 var it1 = mem.tokenize(p1, &[_]u8{sep1});
380 var it2 = mem.tokenize(p2, &[_]u8{sep2});
379381
380382 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
381383 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
......@@ -668,10 +670,10 @@ test "resolve" {
668670 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
669671 cwd[0] = asciiUpper(cwd[0]);
670672 }
671 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));
673 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{"."}), cwd));
672674 } else {
673 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));
674 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));
675 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "a/b/c/", "../../.." }), cwd));
676 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"."}), cwd));
675677 }
676678}
677679
......@@ -684,8 +686,8 @@ test "resolveWindows" {
684686 const cwd = try process.getCwdAlloc(debug.global_allocator);
685687 const parsed_cwd = windowsParsePath(cwd);
686688 {
687 const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
688 const expected = try join(debug.global_allocator, [_][]const u8{
689 const result = testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
690 const expected = try join(debug.global_allocator, &[_][]const u8{
689691 parsed_cwd.disk_designator,
690692 "usr\\local\\lib\\zig\\std\\array_list.zig",
691693 });
......@@ -695,8 +697,8 @@ test "resolveWindows" {
695697 testing.expect(mem.eql(u8, result, expected));
696698 }
697699 {
698 const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });
699 const expected = try join(debug.global_allocator, [_][]const u8{
700 const result = testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" });
701 const expected = try join(debug.global_allocator, &[_][]const u8{
700702 cwd,
701703 "usr\\local\\lib\\zig",
702704 });
......@@ -707,32 +709,32 @@ test "resolveWindows" {
707709 }
708710 }
709711
710 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
711 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
712 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
713 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
714 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
715 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
716 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
717 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//" }), "C:\\"));
718 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
719 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
720 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
721 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
722 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
712 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
713 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
714 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
715 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
716 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
717 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
718 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
719 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//" }), "C:\\"));
720 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
721 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
722 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
723 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
724 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
723725}
724726
725727test "resolvePosix" {
726 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));
727 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
728 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
729 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));
730 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));
731
732 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
733 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
734 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
735 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
728 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c" }), "/a/b/c"));
729 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
730 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
731 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/", "..", ".." }), "/"));
732 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"/a/b/c/"}), "/a/b/c"));
733
734 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
735 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
736 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
737 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
736738}
737739
738740fn testResolveWindows(paths: []const []const u8) []u8 {
......@@ -887,12 +889,12 @@ pub fn basename(path: []const u8) []const u8 {
887889
888890pub fn basenamePosix(path: []const u8) []const u8 {
889891 if (path.len == 0)
890 return [_]u8{};
892 return &[_]u8{};
891893
892894 var end_index: usize = path.len - 1;
893895 while (path[end_index] == '/') {
894896 if (end_index == 0)
895 return [_]u8{};
897 return &[_]u8{};
896898 end_index -= 1;
897899 }
898900 var start_index: usize = end_index;
......@@ -908,19 +910,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
908910
909911pub fn basenameWindows(path: []const u8) []const u8 {
910912 if (path.len == 0)
911 return [_]u8{};
913 return &[_]u8{};
912914
913915 var end_index: usize = path.len - 1;
914916 while (true) {
915917 const byte = path[end_index];
916918 if (byte == '/' or byte == '\\') {
917919 if (end_index == 0)
918 return [_]u8{};
920 return &[_]u8{};
919921 end_index -= 1;
920922 continue;
921923 }
922924 if (byte == ':' and end_index == 1) {
923 return [_]u8{};
925 return &[_]u8{};
924926 }
925927 break;
926928 }
......@@ -1002,11 +1004,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
10021004}
10031005
10041006pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
1005 const resolved_from = try resolveWindows(allocator, [_][]const u8{from});
1007 const resolved_from = try resolveWindows(allocator, &[_][]const u8{from});
10061008 defer allocator.free(resolved_from);
10071009
10081010 var clean_up_resolved_to = true;
1009 const resolved_to = try resolveWindows(allocator, [_][]const u8{to});
1011 const resolved_to = try resolveWindows(allocator, &[_][]const u8{to});
10101012 defer if (clean_up_resolved_to) allocator.free(resolved_to);
10111013
10121014 const parsed_from = windowsParsePath(resolved_from);
......@@ -1075,10 +1077,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
10751077}
10761078
10771079pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
1078 const resolved_from = try resolvePosix(allocator, [_][]const u8{from});
1080 const resolved_from = try resolvePosix(allocator, &[_][]const u8{from});
10791081 defer allocator.free(resolved_from);
10801082
1081 const resolved_to = try resolvePosix(allocator, [_][]const u8{to});
1083 const resolved_to = try resolvePosix(allocator, &[_][]const u8{to});
10821084 defer allocator.free(resolved_to);
10831085
10841086 var from_it = mem.tokenize(resolved_from, "/");
lib/std/hash/cityhash.zig+1-1
......@@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
367367 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
368368 }
369369
370 return @truncate(u32, hash_fn(hashes, 0));
370 return @truncate(u32, hash_fn(&hashes, 0));
371371}
372372
373373fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
lib/std/hash/murmur.zig+1-1
......@@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
299299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300300 }
301301
302 return @truncate(u32, hash_fn(hashes, 0));
302 return @truncate(u32, hash_fn(&hashes, 0));
303303}
304304
305305test "murmur2_32" {
lib/std/hash_map.zig+1-1
......@@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
9494
9595 pub fn init(allocator: *Allocator) Self {
9696 return Self{
97 .entries = [_]Entry{},
97 .entries = &[_]Entry{},
9898 .allocator = allocator,
9999 .size = 0,
100100 .max_distance_from_start_index = 0,
lib/std/http/headers.zig+2-2
......@@ -514,8 +514,8 @@ test "Headers.getIndices" {
514514 try h.append("set-cookie", "y=2", null);
515515
516516 testing.expect(null == h.getIndices("not-present"));
517 testing.expectEqualSlices(usize, [_]usize{0}, h.getIndices("foo").?.toSliceConst());
518 testing.expectEqualSlices(usize, [_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
517 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
518 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
519519}
520520
521521test "Headers.get" {
lib/std/io.zig+1-1
......@@ -1104,7 +1104,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11041104 byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);
11051105 }
11061106
1107 try self.out_stream.write(buffer);
1107 try self.out_stream.write(&buffer);
11081108 }
11091109
11101110 /// Serializes the passed value into the stream
lib/std/io/out_stream.zig+5-5
......@@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type {
5656 pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {
5757 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
5858 mem.writeIntNative(T, &bytes, value);
59 return self.writeFn(self, bytes);
59 return self.writeFn(self, &bytes);
6060 }
6161
6262 /// Write a foreign-endian integer.
6363 pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {
6464 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
6565 mem.writeIntForeign(T, &bytes, value);
66 return self.writeFn(self, bytes);
66 return self.writeFn(self, &bytes);
6767 }
6868
6969 pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {
7070 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
7171 mem.writeIntLittle(T, &bytes, value);
72 return self.writeFn(self, bytes);
72 return self.writeFn(self, &bytes);
7373 }
7474
7575 pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {
7676 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
7777 mem.writeIntBig(T, &bytes, value);
78 return self.writeFn(self, bytes);
78 return self.writeFn(self, &bytes);
7979 }
8080
8181 pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
8282 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
8383 mem.writeInt(T, &bytes, value, endian);
84 return self.writeFn(self, bytes);
84 return self.writeFn(self, &bytes);
8585 }
8686 };
8787}
lib/std/io/test.zig+4-4
......@@ -57,7 +57,7 @@ test "write a file, read it, then delete it" {
5757 defer allocator.free(contents);
5858
5959 expect(mem.eql(u8, contents[0.."begin".len], "begin"));
60 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
60 expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
6161 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
6262 }
6363 try cwd.deleteFile(tmp_file_name);
......@@ -79,7 +79,7 @@ test "BufferOutStream" {
7979
8080test "SliceInStream" {
8181 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
82 var ss = io.SliceInStream.init(bytes);
82 var ss = io.SliceInStream.init(&bytes);
8383
8484 var dest: [4]u8 = undefined;
8585
......@@ -97,7 +97,7 @@ test "SliceInStream" {
9797
9898test "PeekStream" {
9999 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
100 var ss = io.SliceInStream.init(bytes);
100 var ss = io.SliceInStream.init(&bytes);
101101 var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
102102
103103 var dest: [4]u8 = undefined;
......@@ -616,7 +616,7 @@ test "File seek ops" {
616616 fs.cwd().deleteFile(tmp_file_name) catch {};
617617 }
618618
619 try file.write([_]u8{0x55} ** 8192);
619 try file.write(&([_]u8{0x55} ** 8192));
620620
621621 // Seek to the end
622622 try file.seekFromEnd(0);
lib/std/mem.zig+52-76
......@@ -624,23 +624,23 @@ test "comptime read/write int" {
624624}
625625
626626test "readIntBig and readIntLittle" {
627 testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);
628 testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);
627 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
628 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
629629
630 testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);
631 testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);
630 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
631 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
632632
633 testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);
634 testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);
633 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
634 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
635635
636 testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
637 testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
636 testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
637 testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
638638
639 testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1);
640 testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);
639 testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
640 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
641641
642 testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);
643 testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);
642 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
643 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
644644}
645645
646646/// Writes an integer to memory, storing it in twos-complement.
......@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {
749749 var buf9: [9]u8 = undefined;
750750
751751 writeIntBig(u0, &buf0, 0x0);
752 testing.expect(eql(u8, buf0[0..], [_]u8{}));
752 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
753753 writeIntLittle(u0, &buf0, 0x0);
754 testing.expect(eql(u8, buf0[0..], [_]u8{}));
754 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
755755
756756 writeIntBig(u8, &buf1, 0x12);
757 testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));
757 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
758758 writeIntLittle(u8, &buf1, 0x34);
759 testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));
759 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
760760
761761 writeIntBig(u16, &buf2, 0x1234);
762 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));
762 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
763763 writeIntLittle(u16, &buf2, 0x5678);
764 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));
764 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
765765
766766 writeIntBig(u72, &buf9, 0x123456789abcdef024);
767 testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
767 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
768768 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
769 testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
769 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
770770
771771 writeIntBig(i8, &buf1, -1);
772 testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));
772 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
773773 writeIntLittle(i8, &buf1, -2);
774 testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));
774 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
775775
776776 writeIntBig(i16, &buf2, -3);
777 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));
777 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
778778 writeIntLittle(i16, &buf2, -4);
779 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));
779 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
780780}
781781
782782/// Returns an iterator that iterates over the slices of `buffer` that are not
......@@ -1004,9 +1004,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
10041004test "mem.join" {
10051005 var buf: [1024]u8 = undefined;
10061006 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1007 testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c"));
1008 testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a"));
1009 testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
1007 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c"));
1008 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a"));
1009 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
10101010}
10111011
10121012/// Copies each T from slices into a new slice that exactly holds all the elements.
......@@ -1037,13 +1037,13 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T
10371037test "concat" {
10381038 var buf: [1024]u8 = undefined;
10391039 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1040 testing.expect(eql(u8, try concat(a, u8, [_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
1041 testing.expect(eql(u32, try concat(a, u32, [_][]const u32{
1042 [_]u32{ 0, 1 },
1043 [_]u32{ 2, 3, 4 },
1044 [_]u32{},
1045 [_]u32{5},
1046 }), [_]u32{ 0, 1, 2, 3, 4, 5 }));
1040 testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
1041 testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{
1042 &[_]u32{ 0, 1 },
1043 &[_]u32{ 2, 3, 4 },
1044 &[_]u32{},
1045 &[_]u32{5},
1046 }), &[_]u32{ 0, 1, 2, 3, 4, 5 }));
10471047}
10481048
10491049test "testStringEquality" {
......@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {
11111111 var bytes: [8]u8 = undefined;
11121112
11131113 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1114 testing.expect(eql(u8, bytes, [_]u8{
1114 testing.expect(eql(u8, &bytes, &[_]u8{
11151115 0x00, 0x00, 0x00, 0x00,
11161116 0x00, 0x00, 0x00, 0x00,
11171117 }));
11181118
11191119 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1120 testing.expect(eql(u8, bytes, [_]u8{
1120 testing.expect(eql(u8, &bytes, &[_]u8{
11211121 0x00, 0x00, 0x00, 0x00,
11221122 0x00, 0x00, 0x00, 0x00,
11231123 }));
11241124
11251125 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1126 testing.expect(eql(u8, bytes, [_]u8{
1126 testing.expect(eql(u8, &bytes, &[_]u8{
11271127 0x12,
11281128 0x34,
11291129 0x56,
......@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {
11351135 }));
11361136
11371137 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1138 testing.expect(eql(u8, bytes, [_]u8{
1138 testing.expect(eql(u8, &bytes, &[_]u8{
11391139 0x12,
11401140 0x34,
11411141 0x56,
......@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {
11471147 }));
11481148
11491149 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1150 testing.expect(eql(u8, bytes, [_]u8{
1150 testing.expect(eql(u8, &bytes, &[_]u8{
11511151 0x00,
11521152 0x00,
11531153 0x00,
......@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {
11591159 }));
11601160
11611161 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1162 testing.expect(eql(u8, bytes, [_]u8{
1162 testing.expect(eql(u8, &bytes, &[_]u8{
11631163 0x12,
11641164 0x34,
11651165 0x56,
......@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {
11711171 }));
11721172
11731173 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1174 testing.expect(eql(u8, bytes, [_]u8{
1174 testing.expect(eql(u8, &bytes, &[_]u8{
11751175 0x00,
11761176 0x00,
11771177 0x00,
......@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {
11831183 }));
11841184
11851185 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1186 testing.expect(eql(u8, bytes, [_]u8{
1186 testing.expect(eql(u8, &bytes, &[_]u8{
11871187 0x34,
11881188 0x12,
11891189 0x00,
......@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {
12351235}
12361236
12371237test "reverse" {
1238 var arr = [_]i32{
1239 5,
1240 3,
1241 1,
1242 2,
1243 4,
1244 };
1238 var arr = [_]i32{ 5, 3, 1, 2, 4 };
12451239 reverse(i32, arr[0..]);
12461240
1247 testing.expect(eql(i32, arr, [_]i32{
1248 4,
1249 2,
1250 1,
1251 3,
1252 5,
1253 }));
1241 testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
12541242}
12551243
12561244/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
......@@ -1262,22 +1250,10 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
12621250}
12631251
12641252test "rotate" {
1265 var arr = [_]i32{
1266 5,
1267 3,
1268 1,
1269 2,
1270 4,
1271 };
1253 var arr = [_]i32{ 5, 3, 1, 2, 4 };
12721254 rotate(i32, arr[0..], 2);
12731255
1274 testing.expect(eql(i32, arr, [_]i32{
1275 1,
1276 2,
1277 4,
1278 5,
1279 3,
1280 }));
1256 testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
12811257}
12821258
12831259/// Converts a little-endian integer to host endianness.
......@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
13941370test "toBytes" {
13951371 var my_bytes = toBytes(@as(u32, 0x12345678));
13961372 switch (builtin.endian) {
1397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
1398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
1373 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
1374 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
13991375 }
14001376
14011377 my_bytes[0] = '\x99';
14021378 switch (builtin.endian) {
1403 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x99\x34\x56\x78")),
1404 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x99\x56\x34\x12")),
1379 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
1380 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
14051381 }
14061382}
14071383
......@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
14951471test "subArrayPtr" {
14961472 const a1: [6]u8 = "abcdef".*;
14971473 const sub1 = subArrayPtr(&a1, 2, 3);
1498 testing.expect(eql(u8, sub1.*, "cde"));
1474 testing.expect(eql(u8, sub1, "cde"));
14991475
15001476 var a2: [6]u8 = "abcdef".*;
15011477 var sub2 = subArrayPtr(&a2, 2, 3);
15021478
15031479 testing.expect(eql(u8, sub2, "cde"));
15041480 sub2[1] = 'X';
1505 testing.expect(eql(u8, a2, "abcXef"));
1481 testing.expect(eql(u8, &a2, "abcXef"));
15061482}
15071483
15081484/// Round an address up to the nearest aligned address
lib/std/meta/trait.zig+1-1
......@@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
4646 }
4747 };
4848
49 const isVector = multiTrait([_]TraitFn{
49 const isVector = multiTrait(&[_]TraitFn{
5050 hasFn("add"),
5151 hasField("x"),
5252 hasField("y"),
lib/std/net.zig+4-4
......@@ -291,7 +291,7 @@ pub const Address = extern union {
291291 },
292292 os.AF_INET6 => {
293293 const port = mem.bigToNative(u16, self.in6.port);
294 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
294 if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
295295 try std.fmt.format(
296296 context,
297297 Errors,
......@@ -339,7 +339,7 @@ pub const Address = extern union {
339339 unreachable;
340340 }
341341
342 try std.fmt.format(context, Errors, output, "{}", self.un.path);
342 try std.fmt.format(context, Errors, output, "{}", &self.un.path);
343343 },
344344 else => unreachable,
345345 }
......@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(
894894 }
895895
896896 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
897 [_]u8{}
897 &[_]u8{}
898898 else
899899 rc.search.toSliceConst();
900900
......@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(
959959
960960 for (afrrs) |afrr| {
961961 if (family != afrr.af) {
962 const len = os.res_mkquery(0, name, 1, afrr.rr, [_]u8{}, null, &qbuf[nq]);
962 const len = os.res_mkquery(0, name, 1, afrr.rr, &[_]u8{}, null, &qbuf[nq]);
963963 qp[nq] = qbuf[nq][0..len];
964964 nq += 1;
965965 }
lib/std/os.zig+3-3
......@@ -1571,8 +1571,8 @@ pub fn isCygwinPty(handle: fd_t) bool {
15711571 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
15721572 const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];
15731573 const name_wide = @bytesToSlice(u16, name_bytes);
1574 return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or
1575 mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;
1574 return mem.indexOf(u16, name_wide, &[_]u16{ 'm', 's', 'y', 's', '-' }) != null or
1575 mem.indexOf(u16, name_wide, &[_]u16{ '-', 'p', 't', 'y' }) != null;
15761576}
15771577
15781578pub const SocketError = error{
......@@ -2640,7 +2640,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real
26402640 // Windows returns \\?\ prepended to the path.
26412641 // We strip it to make this function consistent across platforms.
26422642 const prefix = [_]u16{ '\\', '\\', '?', '\\' };
2643 const start_index = if (mem.startsWith(u16, wide_slice, prefix)) prefix.len else 0;
2643 const start_index = if (mem.startsWith(u16, wide_slice, &prefix)) prefix.len else 0;
26442644
26452645 // Trust that Windows gives us valid UTF-16LE.
26462646 const end_index = std.unicode.utf16leToUtf8(out_buffer, wide_slice[start_index..]) catch unreachable;
lib/std/os/test.zig+1-1
......@@ -137,7 +137,7 @@ test "getrandom" {
137137 try os.getrandom(&buf_b);
138138 // If this test fails the chance is significantly higher that there is a bug than
139139 // that two sets of 50 bytes were equal.
140 expect(!mem.eql(u8, buf_a, buf_b));
140 expect(!mem.eql(u8, &buf_a, &buf_b));
141141}
142142
143143test "getcwd" {
lib/std/os/windows.zig+3-3
......@@ -932,9 +932,9 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 {
932932 // TODO https://github.com/ziglang/zig/issues/2765
933933 var result: [PATH_MAX_WIDE:0]u16 = undefined;
934934
935 const start_index = if (mem.startsWith(u16, s, [_]u16{ '\\', '?' })) 0 else blk: {
935 const start_index = if (mem.startsWith(u16, s, &[_]u16{ '\\', '?' })) 0 else blk: {
936936 const prefix = [_]u16{ '\\', '?', '?', '\\' };
937 mem.copy(u16, result[0..], prefix);
937 mem.copy(u16, result[0..], &prefix);
938938 break :blk prefix.len;
939939 };
940940 const end_index = start_index + s.len;
......@@ -961,7 +961,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
961961 }
962962 const start_index = if (mem.startsWith(u8, s, "\\?") or !std.fs.path.isAbsolute(s)) 0 else blk: {
963963 const prefix = [_]u16{ '\\', '?', '?', '\\' };
964 mem.copy(u16, result[0..], prefix);
964 mem.copy(u16, result[0..], &prefix);
965965 break :blk prefix.len;
966966 };
967967 const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s);
lib/std/packed_int_array.zig+3-21
......@@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
201201 ///Return the Int stored at index
202202 pub fn get(self: Self, index: usize) Int {
203203 debug.assert(index < int_count);
204 return Io.get(self.bytes, index, 0);
204 return Io.get(&self.bytes, index, 0);
205205 }
206206
207207 ///Copy int into the array at index
......@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
528528test "PackedInt(Array/Slice)Endian" {
529529 {
530530 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
531 var packed_array_be = PackedArrayBe.init([_]u4{
532 0,
533 1,
534 2,
535 3,
536 4,
537 5,
538 6,
539 7,
540 });
531 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
541532 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542533 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543534
......@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {
563554
564555 {
565556 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
566 var packed_array_be = PackedArrayBe.init([_]u11{
567 0,
568 1,
569 2,
570 3,
571 4,
572 5,
573 6,
574 7,
575 });
557 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
576558 testing.expect(packed_array_be.bytes[0] == 0b00000000);
577559 testing.expect(packed_array_be.bytes[1] == 0b00000000);
578560 testing.expect(packed_array_be.bytes[2] == 0b00000100);
lib/std/pdb.zig+2-2
......@@ -501,7 +501,7 @@ const Msf = struct {
501501 const superblock = try in.readStruct(SuperBlock);
502502
503503 // Sanity checks
504 if (!mem.eql(u8, superblock.FileMagic, SuperBlock.file_magic))
504 if (!mem.eql(u8, &superblock.FileMagic, SuperBlock.file_magic))
505505 return error.InvalidDebugInfo;
506506 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)
507507 return error.InvalidDebugInfo;
......@@ -547,7 +547,7 @@ const Msf = struct {
547547 const size = stream_sizes[i];
548548 if (size == 0) {
549549 stream.* = MsfStream{
550 .blocks = [_]u32{},
550 .blocks = &[_]u32{},
551551 };
552552 } else {
553553 var blocks = try allocator.alloc(u32, size);
lib/std/priority_queue.zig+1-1
......@@ -22,7 +22,7 @@ pub fn PriorityQueue(comptime T: type) type {
2222 /// `fn lessThan(a: T, b: T) bool { return a < b; }`
2323 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
2424 return Self{
25 .items = [_]T{},
25 .items = &[_]T{},
2626 .len = 0,
2727 .allocator = allocator,
2828 .compareFn = compareFn,
lib/std/process.zig+8-8
......@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
473473}
474474
475475test "windows arg parsing" {
476 testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine("a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
476 testWindowsCmdLine("a b\tc d", &[_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", &[_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" });
482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{
484484 ".\\..\\zig-cache\\build",
485485 "bin\\zig.exe",
486486 ".\\..",
lib/std/rand.zig+1-1
......@@ -54,7 +54,7 @@ pub const Random = struct {
5454 // use LE instead of native endian for better portability maybe?
5555 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
5656 // TODO: document the endian portability of this library.
57 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, rand_bytes);
57 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
5858 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);
5959 return @bitCast(T, unsigned_result);
6060 }
lib/std/segmented_list.zig+4-8
......@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
112112 .allocator = allocator,
113113 .len = 0,
114114 .prealloc_segment = undefined,
115 .dynamic_segments = [_][*]T{},
115 .dynamic_segments = &[_][*]T{},
116116 };
117117 }
118118
......@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
192192 const len = @intCast(ShelfIndex, self.dynamic_segments.len);
193193 self.freeShelves(len, 0);
194194 self.allocator.free(self.dynamic_segments);
195 self.dynamic_segments = [_][*]T{};
195 self.dynamic_segments = &[_][*]T{};
196196 return;
197197 }
198198
......@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
385385 testing.expect(list.pop().? == 100);
386386 testing.expect(list.len == 99);
387387
388 try list.pushMany([_]i32{
389 1,
390 2,
391 3,
392 });
388 try list.pushMany(&[_]i32{ 1, 2, 3 });
393389 testing.expect(list.len == 102);
394390 testing.expect(list.pop().? == 3);
395391 testing.expect(list.pop().? == 2);
396392 testing.expect(list.pop().? == 1);
397393 testing.expect(list.len == 99);
398394
399 try list.pushMany([_]i32{});
395 try list.pushMany(&[_]i32{});
400396 testing.expect(list.len == 99);
401397
402398 var i: i32 = 99;
lib/std/sort.zig+43-43
......@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
10431043
10441044test "std.sort" {
10451045 const u8cases = [_][]const []const u8{
1046 [_][]const u8{
1046 &[_][]const u8{
10471047 "",
10481048 "",
10491049 },
1050 [_][]const u8{
1050 &[_][]const u8{
10511051 "a",
10521052 "a",
10531053 },
1054 [_][]const u8{
1054 &[_][]const u8{
10551055 "az",
10561056 "az",
10571057 },
1058 [_][]const u8{
1058 &[_][]const u8{
10591059 "za",
10601060 "az",
10611061 },
1062 [_][]const u8{
1062 &[_][]const u8{
10631063 "asdf",
10641064 "adfs",
10651065 },
1066 [_][]const u8{
1066 &[_][]const u8{
10671067 "one",
10681068 "eno",
10691069 },
......@@ -1078,29 +1078,29 @@ test "std.sort" {
10781078 }
10791079
10801080 const i32cases = [_][]const []const i32{
1081 [_][]const i32{
1082 [_]i32{},
1083 [_]i32{},
1081 &[_][]const i32{
1082 &[_]i32{},
1083 &[_]i32{},
10841084 },
1085 [_][]const i32{
1086 [_]i32{1},
1087 [_]i32{1},
1085 &[_][]const i32{
1086 &[_]i32{1},
1087 &[_]i32{1},
10881088 },
1089 [_][]const i32{
1090 [_]i32{ 0, 1 },
1091 [_]i32{ 0, 1 },
1089 &[_][]const i32{
1090 &[_]i32{ 0, 1 },
1091 &[_]i32{ 0, 1 },
10921092 },
1093 [_][]const i32{
1094 [_]i32{ 1, 0 },
1095 [_]i32{ 0, 1 },
1093 &[_][]const i32{
1094 &[_]i32{ 1, 0 },
1095 &[_]i32{ 0, 1 },
10961096 },
1097 [_][]const i32{
1098 [_]i32{ 1, -1, 0 },
1099 [_]i32{ -1, 0, 1 },
1097 &[_][]const i32{
1098 &[_]i32{ 1, -1, 0 },
1099 &[_]i32{ -1, 0, 1 },
11001100 },
1101 [_][]const i32{
1102 [_]i32{ 2, 1, 3 },
1103 [_]i32{ 1, 2, 3 },
1101 &[_][]const i32{
1102 &[_]i32{ 2, 1, 3 },
1103 &[_]i32{ 1, 2, 3 },
11041104 },
11051105 };
11061106
......@@ -1115,29 +1115,29 @@ test "std.sort" {
11151115
11161116test "std.sort descending" {
11171117 const rev_cases = [_][]const []const i32{
1118 [_][]const i32{
1119 [_]i32{},
1120 [_]i32{},
1118 &[_][]const i32{
1119 &[_]i32{},
1120 &[_]i32{},
11211121 },
1122 [_][]const i32{
1123 [_]i32{1},
1124 [_]i32{1},
1122 &[_][]const i32{
1123 &[_]i32{1},
1124 &[_]i32{1},
11251125 },
1126 [_][]const i32{
1127 [_]i32{ 0, 1 },
1128 [_]i32{ 1, 0 },
1126 &[_][]const i32{
1127 &[_]i32{ 0, 1 },
1128 &[_]i32{ 1, 0 },
11291129 },
1130 [_][]const i32{
1131 [_]i32{ 1, 0 },
1132 [_]i32{ 1, 0 },
1130 &[_][]const i32{
1131 &[_]i32{ 1, 0 },
1132 &[_]i32{ 1, 0 },
11331133 },
1134 [_][]const i32{
1135 [_]i32{ 1, -1, 0 },
1136 [_]i32{ 1, 0, -1 },
1134 &[_][]const i32{
1135 &[_]i32{ 1, -1, 0 },
1136 &[_]i32{ 1, 0, -1 },
11371137 },
1138 [_][]const i32{
1139 [_]i32{ 2, 1, 3 },
1140 [_]i32{ 3, 2, 1 },
1138 &[_][]const i32{
1139 &[_]i32{ 2, 1, 3 },
1140 &[_]i32{ 3, 2, 1 },
11411141 },
11421142 };
11431143
......@@ -1154,7 +1154,7 @@ test "another sort case" {
11541154 var arr = [_]i32{ 5, 3, 1, 2, 4 };
11551155 sort(i32, arr[0..], asc(i32));
11561156
1157 testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 }));
1157 testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
11581158}
11591159
11601160test "sort fuzz testing" {
lib/std/unicode.zig+6-6
......@@ -499,14 +499,14 @@ test "utf16leToUtf8" {
499499 {
500500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
501501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
503503 testing.expect(mem.eql(u8, utf8, "Aa"));
504504 }
505505
506506 {
507507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
508508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
510510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
511511 }
512512
......@@ -514,7 +514,7 @@ test "utf16leToUtf8" {
514514 // the values just outside the surrogate half range
515515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
516516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
518518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
519519 }
520520
......@@ -522,7 +522,7 @@ test "utf16leToUtf8" {
522522 // smallest surrogate pair
523523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
524524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
526526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
527527 }
528528
......@@ -530,14 +530,14 @@ test "utf16leToUtf8" {
530530 // largest surrogate pair
531531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
532532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
534534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
535535 }
536536
537537 {
538538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
539539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
541541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
542542 }
543543}
lib/std/zig/tokenizer.zig+61-61
......@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {
13131313};
13141314
13151315test "tokenizer" {
1316 testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});
1316 testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test});
13171317}
13181318
13191319test "tokenizer - unknown length pointer and then c pointer" {
13201320 testTokenize(
13211321 \\[*]u8
13221322 \\[*c]u8
1323 , [_]Token.Id{
1323 , &[_]Token.Id{
13241324 Token.Id.LBracket,
13251325 Token.Id.Asterisk,
13261326 Token.Id.RBracket,
......@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {
13361336test "tokenizer - char literal with hex escape" {
13371337 testTokenize(
13381338 \\'\x1b'
1339 , [_]Token.Id{.CharLiteral});
1339 , &[_]Token.Id{.CharLiteral});
13401340 testTokenize(
13411341 \\'\x1'
1342 , [_]Token.Id{ .Invalid, .Invalid });
1342 , &[_]Token.Id{ .Invalid, .Invalid });
13431343}
13441344
13451345test "tokenizer - char literal with unicode escapes" {
13461346 // Valid unicode escapes
13471347 testTokenize(
13481348 \\'\u{3}'
1349 , [_]Token.Id{.CharLiteral});
1349 , &[_]Token.Id{.CharLiteral});
13501350 testTokenize(
13511351 \\'\u{01}'
1352 , [_]Token.Id{.CharLiteral});
1352 , &[_]Token.Id{.CharLiteral});
13531353 testTokenize(
13541354 \\'\u{2a}'
1355 , [_]Token.Id{.CharLiteral});
1355 , &[_]Token.Id{.CharLiteral});
13561356 testTokenize(
13571357 \\'\u{3f9}'
1358 , [_]Token.Id{.CharLiteral});
1358 , &[_]Token.Id{.CharLiteral});
13591359 testTokenize(
13601360 \\'\u{6E09aBc1523}'
1361 , [_]Token.Id{.CharLiteral});
1361 , &[_]Token.Id{.CharLiteral});
13621362 testTokenize(
13631363 \\"\u{440}"
1364 , [_]Token.Id{.StringLiteral});
1364 , &[_]Token.Id{.StringLiteral});
13651365
13661366 // Invalid unicode escapes
13671367 testTokenize(
13681368 \\'\u'
1369 , [_]Token.Id{.Invalid});
1369 , &[_]Token.Id{.Invalid});
13701370 testTokenize(
13711371 \\'\u{{'
1372 , [_]Token.Id{ .Invalid, .Invalid });
1372 , &[_]Token.Id{ .Invalid, .Invalid });
13731373 testTokenize(
13741374 \\'\u{}'
1375 , [_]Token.Id{ .Invalid, .Invalid });
1375 , &[_]Token.Id{ .Invalid, .Invalid });
13761376 testTokenize(
13771377 \\'\u{s}'
1378 , [_]Token.Id{ .Invalid, .Invalid });
1378 , &[_]Token.Id{ .Invalid, .Invalid });
13791379 testTokenize(
13801380 \\'\u{2z}'
1381 , [_]Token.Id{ .Invalid, .Invalid });
1381 , &[_]Token.Id{ .Invalid, .Invalid });
13821382 testTokenize(
13831383 \\'\u{4a'
1384 , [_]Token.Id{.Invalid});
1384 , &[_]Token.Id{.Invalid});
13851385
13861386 // Test old-style unicode literals
13871387 testTokenize(
13881388 \\'\u0333'
1389 , [_]Token.Id{ .Invalid, .Invalid });
1389 , &[_]Token.Id{ .Invalid, .Invalid });
13901390 testTokenize(
13911391 \\'\U0333'
1392 , [_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
1392 , &[_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
13931393}
13941394
13951395test "tokenizer - char literal with unicode code point" {
13961396 testTokenize(
13971397 \\'💩'
1398 , [_]Token.Id{.CharLiteral});
1398 , &[_]Token.Id{.CharLiteral});
13991399}
14001400
14011401test "tokenizer - float literal e exponent" {
1402 testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{
1402 testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{
14031403 Token.Id.Identifier,
14041404 Token.Id.Equal,
14051405 Token.Id.FloatLiteral,
......@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {
14081408}
14091409
14101410test "tokenizer - float literal p exponent" {
1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{
1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{
14121412 Token.Id.Identifier,
14131413 Token.Id.Equal,
14141414 Token.Id.FloatLiteral,
......@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {
14171417}
14181418
14191419test "tokenizer - chars" {
1420 testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});
1420 testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral});
14211421}
14221422
14231423test "tokenizer - invalid token characters" {
1424 testTokenize("#", [_]Token.Id{Token.Id.Invalid});
1425 testTokenize("`", [_]Token.Id{Token.Id.Invalid});
1426 testTokenize("'c", [_]Token.Id{Token.Id.Invalid});
1427 testTokenize("'", [_]Token.Id{Token.Id.Invalid});
1428 testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
1424 testTokenize("#", &[_]Token.Id{Token.Id.Invalid});
1425 testTokenize("`", &[_]Token.Id{Token.Id.Invalid});
1426 testTokenize("'c", &[_]Token.Id{Token.Id.Invalid});
1427 testTokenize("'", &[_]Token.Id{Token.Id.Invalid});
1428 testTokenize("''", &[_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
14291429}
14301430
14311431test "tokenizer - invalid literal/comment characters" {
1432 testTokenize("\"\x00\"", [_]Token.Id{
1432 testTokenize("\"\x00\"", &[_]Token.Id{
14331433 Token.Id.StringLiteral,
14341434 Token.Id.Invalid,
14351435 });
1436 testTokenize("//\x00", [_]Token.Id{
1436 testTokenize("//\x00", &[_]Token.Id{
14371437 Token.Id.LineComment,
14381438 Token.Id.Invalid,
14391439 });
1440 testTokenize("//\x1f", [_]Token.Id{
1440 testTokenize("//\x1f", &[_]Token.Id{
14411441 Token.Id.LineComment,
14421442 Token.Id.Invalid,
14431443 });
1444 testTokenize("//\x7f", [_]Token.Id{
1444 testTokenize("//\x7f", &[_]Token.Id{
14451445 Token.Id.LineComment,
14461446 Token.Id.Invalid,
14471447 });
14481448}
14491449
14501450test "tokenizer - utf8" {
1451 testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment});
1452 testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment});
1451 testTokenize("//\xc2\x80", &[_]Token.Id{Token.Id.LineComment});
1452 testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{Token.Id.LineComment});
14531453}
14541454
14551455test "tokenizer - invalid utf8" {
1456 testTokenize("//\x80", [_]Token.Id{
1456 testTokenize("//\x80", &[_]Token.Id{
14571457 Token.Id.LineComment,
14581458 Token.Id.Invalid,
14591459 });
1460 testTokenize("//\xbf", [_]Token.Id{
1460 testTokenize("//\xbf", &[_]Token.Id{
14611461 Token.Id.LineComment,
14621462 Token.Id.Invalid,
14631463 });
1464 testTokenize("//\xf8", [_]Token.Id{
1464 testTokenize("//\xf8", &[_]Token.Id{
14651465 Token.Id.LineComment,
14661466 Token.Id.Invalid,
14671467 });
1468 testTokenize("//\xff", [_]Token.Id{
1468 testTokenize("//\xff", &[_]Token.Id{
14691469 Token.Id.LineComment,
14701470 Token.Id.Invalid,
14711471 });
1472 testTokenize("//\xc2\xc0", [_]Token.Id{
1472 testTokenize("//\xc2\xc0", &[_]Token.Id{
14731473 Token.Id.LineComment,
14741474 Token.Id.Invalid,
14751475 });
1476 testTokenize("//\xe0", [_]Token.Id{
1476 testTokenize("//\xe0", &[_]Token.Id{
14771477 Token.Id.LineComment,
14781478 Token.Id.Invalid,
14791479 });
1480 testTokenize("//\xf0", [_]Token.Id{
1480 testTokenize("//\xf0", &[_]Token.Id{
14811481 Token.Id.LineComment,
14821482 Token.Id.Invalid,
14831483 });
1484 testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{
1484 testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{
14851485 Token.Id.LineComment,
14861486 Token.Id.Invalid,
14871487 });
......@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {
14891489
14901490test "tokenizer - illegal unicode codepoints" {
14911491 // unicode newline characters.U+0085, U+2028, U+2029
1492 testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});
1493 testTokenize("//\xc2\x85", [_]Token.Id{
1492 testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment});
1493 testTokenize("//\xc2\x85", &[_]Token.Id{
14941494 Token.Id.LineComment,
14951495 Token.Id.Invalid,
14961496 });
1497 testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});
1498 testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});
1499 testTokenize("//\xe2\x80\xa8", [_]Token.Id{
1497 testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment});
1498 testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment});
1499 testTokenize("//\xe2\x80\xa8", &[_]Token.Id{
15001500 Token.Id.LineComment,
15011501 Token.Id.Invalid,
15021502 });
1503 testTokenize("//\xe2\x80\xa9", [_]Token.Id{
1503 testTokenize("//\xe2\x80\xa9", &[_]Token.Id{
15041504 Token.Id.LineComment,
15051505 Token.Id.Invalid,
15061506 });
1507 testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});
1507 testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment});
15081508}
15091509
15101510test "tokenizer - string identifier and builtin fns" {
15111511 testTokenize(
15121512 \\const @"if" = @import("std");
1513 , [_]Token.Id{
1513 , &[_]Token.Id{
15141514 Token.Id.Keyword_const,
15151515 Token.Id.Identifier,
15161516 Token.Id.Equal,
......@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {
15231523}
15241524
15251525test "tokenizer - pipe and then invalid" {
1526 testTokenize("||=", [_]Token.Id{
1526 testTokenize("||=", &[_]Token.Id{
15271527 Token.Id.PipePipe,
15281528 Token.Id.Equal,
15291529 });
15301530}
15311531
15321532test "tokenizer - line comment and doc comment" {
1533 testTokenize("//", [_]Token.Id{Token.Id.LineComment});
1534 testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});
1535 testTokenize("// /", [_]Token.Id{Token.Id.LineComment});
1536 testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});
1537 testTokenize("///", [_]Token.Id{Token.Id.DocComment});
1538 testTokenize("////", [_]Token.Id{Token.Id.LineComment});
1539 testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment});
1540 testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment});
1533 testTokenize("//", &[_]Token.Id{Token.Id.LineComment});
1534 testTokenize("// a / b", &[_]Token.Id{Token.Id.LineComment});
1535 testTokenize("// /", &[_]Token.Id{Token.Id.LineComment});
1536 testTokenize("/// a", &[_]Token.Id{Token.Id.DocComment});
1537 testTokenize("///", &[_]Token.Id{Token.Id.DocComment});
1538 testTokenize("////", &[_]Token.Id{Token.Id.LineComment});
1539 testTokenize("//!", &[_]Token.Id{Token.Id.ContainerDocComment});
1540 testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment});
15411541}
15421542
15431543test "tokenizer - line comment followed by identifier" {
......@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {
15451545 \\ Unexpected,
15461546 \\ // another
15471547 \\ Another,
1548 , [_]Token.Id{
1548 , &[_]Token.Id{
15491549 Token.Id.Identifier,
15501550 Token.Id.Comma,
15511551 Token.Id.LineComment,
......@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {
15551555}
15561556
15571557test "tokenizer - UTF-8 BOM is recognized and skipped" {
1558 testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{
1558 testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{
15591559 Token.Id.Identifier,
15601560 Token.Id.Semicolon,
15611561 });
15621562}
15631563
15641564test "correctly parse pointer assignment" {
1565 testTokenize("b.*=3;\n", [_]Token.Id{
1565 testTokenize("b.*=3;\n", &[_]Token.Id{
15661566 Token.Id.Identifier,
15671567 Token.Id.PeriodAsterisk,
15681568 Token.Id.Equal,
src-self-hosted/arg.zig+1-1
......@@ -178,7 +178,7 @@ pub const Args = struct {
178178 else => @panic("attempted to retrieve flag with wrong type"),
179179 }
180180 } else {
181 return [_][]const u8{};
181 return &[_][]const u8{};
182182 }
183183 }
184184};
src-self-hosted/compilation.zig+14-15
......@@ -103,8 +103,8 @@ pub const ZigCompiler = struct {
103103 /// Must be called only once, ever. Sets global state.
104104 pub fn setLlvmArgv(allocator: *Allocator, llvm_argv: []const []const u8) !void {
105105 if (llvm_argv.len != 0) {
106 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [_][]const []const u8{
107 [_][]const u8{"zig (LLVM option parsing)"},
106 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, &[_][]const []const u8{
107 &[_][]const u8{"zig (LLVM option parsing)"},
108108 llvm_argv,
109109 });
110110 defer c_compatible_args.deinit();
......@@ -148,13 +148,13 @@ pub const Compilation = struct {
148148 is_static: bool,
149149 linker_rdynamic: bool = false,
150150
151 clang_argv: []const []const u8 = [_][]const u8{},
152 lib_dirs: []const []const u8 = [_][]const u8{},
153 rpath_list: []const []const u8 = [_][]const u8{},
154 assembly_files: []const []const u8 = [_][]const u8{},
151 clang_argv: []const []const u8 = &[_][]const u8{},
152 lib_dirs: []const []const u8 = &[_][]const u8{},
153 rpath_list: []const []const u8 = &[_][]const u8{},
154 assembly_files: []const []const u8 = &[_][]const u8{},
155155
156156 /// paths that are explicitly provided by the user to link against
157 link_objects: []const []const u8 = [_][]const u8{},
157 link_objects: []const []const u8 = &[_][]const u8{},
158158
159159 /// functions that have their own objects that we need to link
160160 /// it uses an optional pointer so that tombstone removals are possible
......@@ -178,10 +178,10 @@ pub const Compilation = struct {
178178 verbose_llvm_ir: bool = false,
179179 verbose_link: bool = false,
180180
181 darwin_frameworks: []const []const u8 = [_][]const u8{},
181 darwin_frameworks: []const []const u8 = &[_][]const u8{},
182182 darwin_version_min: DarwinVersionMin = .None,
183183
184 test_filters: []const []const u8 = [_][]const u8{},
184 test_filters: []const []const u8 = &[_][]const u8{},
185185 test_name_prefix: ?[]const u8 = null,
186186
187187 emit_file_type: Emit = .Binary,
......@@ -400,7 +400,6 @@ pub const Compilation = struct {
400400 .llvm_triple = undefined,
401401 .is_static = is_static,
402402 .link_libs_list = undefined,
403
404403 .exported_symbol_names = event.Locked(Decl.Table).init(Decl.Table.init(allocator)),
405404 .prelink_group = event.Group(BuildError!void).init(allocator),
406405 .deinit_group = event.Group(void).init(allocator),
......@@ -448,7 +447,7 @@ pub const Compilation = struct {
448447 comp.name = try Buffer.init(comp.arena(), name);
449448 comp.llvm_triple = try util.getTriple(comp.arena(), target);
450449 comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple);
451 comp.zig_std_dir = try std.fs.path.join(comp.arena(), [_][]const u8{ zig_lib_dir, "std" });
450 comp.zig_std_dir = try std.fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" });
452451
453452 const opt_level = switch (build_mode) {
454453 .Debug => llvm.CodeGenLevelNone,
......@@ -490,7 +489,7 @@ pub const Compilation = struct {
490489 comp.events = try allocator.create(event.Channel(Event));
491490 defer allocator.destroy(comp.events);
492491
493 comp.events.init([0]Event{});
492 comp.events.init(&[0]Event{});
494493 defer comp.events.deinit();
495494
496495 if (root_src_path) |root_src| {
......@@ -1166,7 +1165,7 @@ pub const Compilation = struct {
11661165 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
11671166 defer self.gpa().free(file_name);
11681167
1169 const full_path = try std.fs.path.join(self.gpa(), [_][]const u8{ tmp_dir, file_name[0..] });
1168 const full_path = try std.fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
11701169 errdefer self.gpa().free(full_path);
11711170
11721171 return Buffer.fromOwnedSlice(self.gpa(), full_path);
......@@ -1187,7 +1186,7 @@ pub const Compilation = struct {
11871186 const zig_dir_path = try getZigDir(self.gpa());
11881187 defer self.gpa().free(zig_dir_path);
11891188
1190 const tmp_dir = try std.fs.path.join(self.arena(), [_][]const u8{ zig_dir_path, comp_dir_name[0..] });
1189 const tmp_dir = try std.fs.path.join(self.arena(), &[_][]const u8{ zig_dir_path, comp_dir_name[0..] });
11911190 try std.fs.makePath(self.gpa(), tmp_dir);
11921191 return tmp_dir;
11931192 }
......@@ -1209,7 +1208,7 @@ pub const Compilation = struct {
12091208 }
12101209
12111210 var result: [12]u8 = undefined;
1212 b64_fs_encoder.encode(result[0..], rand_bytes);
1211 b64_fs_encoder.encode(result[0..], &rand_bytes);
12131212 return result;
12141213 }
12151214
src-self-hosted/dep_tokenizer.zig+2-2
......@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
992992
993993fn printCharValues(out: var, bytes: []const u8) !void {
994994 for (bytes) |b| {
995 try out.write([_]u8{printable_char_tab[b]});
995 try out.write(&[_]u8{printable_char_tab[b]});
996996 }
997997}
998998
......@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
10011001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
10021002 } else {
10031003 try out.write("'");
1004 try out.write([_]u8{printable_char_tab[char]});
1004 try out.write(&[_]u8{printable_char_tab[char]});
10051005 try out.write("'");
10061006 }
10071007}
src-self-hosted/introspect.zig+2-2
......@@ -8,10 +8,10 @@ const warn = std.debug.warn;
88
99/// Caller must free result
1010pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {
11 const test_zig_dir = try fs.path.join(allocator, [_][]const u8{ test_path, "lib", "zig" });
11 const test_zig_dir = try fs.path.join(allocator, &[_][]const u8{ test_path, "lib", "zig" });
1212 errdefer allocator.free(test_zig_dir);
1313
14 const test_index_file = try fs.path.join(allocator, [_][]const u8{ test_zig_dir, "std", "std.zig" });
14 const test_index_file = try fs.path.join(allocator, &[_][]const u8{ test_zig_dir, "std", "std.zig" });
1515 defer allocator.free(test_index_file);
1616
1717 var file = try fs.File.openRead(test_index_file);
src-self-hosted/libc_installation.zig+3-3
......@@ -193,7 +193,7 @@ pub const LibCInstallation = struct {
193193 "/dev/null",
194194 };
195195 // TODO make this use event loop
196 const errorable_result = std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024);
196 const errorable_result = std.ChildProcess.exec(allocator, &argv, null, null, 1024 * 1024);
197197 const exec_result = if (std.debug.runtime_safety) blk: {
198198 break :blk errorable_result catch unreachable;
199199 } else blk: {
......@@ -233,7 +233,7 @@ pub const LibCInstallation = struct {
233233 while (path_i < search_paths.len) : (path_i += 1) {
234234 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
235235 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");
236 const stdlib_path = try fs.path.join(allocator, [_][]const u8{ search_path, "stdlib.h" });
236 const stdlib_path = try fs.path.join(allocator, &[_][]const u8{ search_path, "stdlib.h" });
237237 defer allocator.free(stdlib_path);
238238
239239 if (try fileExists(stdlib_path)) {
......@@ -401,7 +401,7 @@ fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool
401401
402402 // TODO This simulates evented I/O for the child process exec
403403 event.Loop.startCpuBoundOperation();
404 const errorable_result = std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024);
404 const errorable_result = std.ChildProcess.exec(allocator, &argv, null, null, 1024 * 1024);
405405 const exec_result = if (std.debug.runtime_safety) blk: {
406406 break :blk errorable_result catch unreachable;
407407 } else blk: {
src-self-hosted/link.zig+1-1
......@@ -314,7 +314,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
314314}
315315
316316fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {
317 const full_path = try std.fs.path.join(&ctx.arena.allocator, [_][]const u8{ dirname, basename });
317 const full_path = try std.fs.path.join(&ctx.arena.allocator, &[_][]const u8{ dirname, basename });
318318 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
319319 try ctx.args.append(@ptrCast([*:0]const u8, full_path_with_null.ptr));
320320}
src-self-hosted/main.zig+7-7
......@@ -196,12 +196,12 @@ const usage_build_generic =
196196
197197const args_build_generic = [_]Flag{
198198 Flag.Bool("--help"),
199 Flag.Option("--color", [_][]const u8{
199 Flag.Option("--color", &[_][]const u8{
200200 "auto",
201201 "off",
202202 "on",
203203 }),
204 Flag.Option("--mode", [_][]const u8{
204 Flag.Option("--mode", &[_][]const u8{
205205 "debug",
206206 "release-fast",
207207 "release-safe",
......@@ -209,7 +209,7 @@ const args_build_generic = [_]Flag{
209209 }),
210210
211211 Flag.ArgMergeN("--assembly", 1),
212 Flag.Option("--emit", [_][]const u8{
212 Flag.Option("--emit", &[_][]const u8{
213213 "asm",
214214 "bin",
215215 "llvm-ir",
......@@ -257,7 +257,7 @@ const args_build_generic = [_]Flag{
257257};
258258
259259fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Compilation.Kind) !void {
260 var flags = try Args.parse(allocator, args_build_generic, args);
260 var flags = try Args.parse(allocator, &args_build_generic, args);
261261 defer flags.deinit();
262262
263263 if (flags.present("help")) {
......@@ -525,7 +525,7 @@ pub const usage_fmt =
525525pub const args_fmt_spec = [_]Flag{
526526 Flag.Bool("--help"),
527527 Flag.Bool("--check"),
528 Flag.Option("--color", [_][]const u8{
528 Flag.Option("--color", &[_][]const u8{
529529 "auto",
530530 "off",
531531 "on",
......@@ -579,7 +579,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
579579}
580580
581581fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
582 var flags = try Args.parse(allocator, args_fmt_spec, args);
582 var flags = try Args.parse(allocator, &args_fmt_spec, args);
583583 defer flags.deinit();
584584
585585 if (flags.present("help")) {
......@@ -709,7 +709,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
709709 var it = dir.iterate();
710710 while (try it.next()) |entry| {
711711 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {
712 const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
712 const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name });
713713 @panic("TODO https://github.com/ziglang/zig/issues/3777");
714714 // try group.call(fmtPath, fmt, full_path, check_mode);
715715 }
src-self-hosted/stage1.zig+2-2
......@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
170170 stderr = &stderr_file.outStream().stream;
171171
172172 const args = args_list.toSliceConst();
173 var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]);
173 var flags = try Args.parse(allocator, &self_hosted_main.args_fmt_spec, args[2..]);
174174 defer flags.deinit();
175175
176176 if (flags.present("help")) {
......@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
286286
287287 while (try dir_it.next()) |entry| {
288288 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {
289 const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
289 const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name });
290290 try fmtPath(fmt, full_path, check_mode);
291291 }
292292 }
src/all_types.hpp+7-7
......@@ -313,12 +313,6 @@ struct RuntimeHintSlice {
313313 uint64_t len;
314314};
315315
316struct ConstGlobalRefs {
317 LLVMValueRef llvm_value;
318 LLVMValueRef llvm_global;
319 uint32_t align;
320};
321
322316enum LazyValueId {
323317 LazyValueIdInvalid,
324318 LazyValueIdAlignOf,
......@@ -409,8 +403,10 @@ struct LazyValueErrUnionType {
409403struct ZigValue {
410404 ZigType *type;
411405 ConstValSpecial special;
406 uint32_t llvm_align;
412407 ConstParent parent;
413 ConstGlobalRefs *global_refs;
408 LLVMValueRef llvm_value;
409 LLVMValueRef llvm_global;
414410
415411 union {
416412 // populated if special == ConstValSpecialStatic
......@@ -2652,6 +2648,10 @@ struct IrInstruction {
26522648 IrInstructionId id;
26532649 // true if this instruction was generated by zig and not from user code
26542650 bool is_gen;
2651
2652 // for debugging purposes, these are useful to call to inspect the instruction
2653 void dump();
2654 void src();
26552655};
26562656
26572657struct IrInstructionDeclVarSrc {
src/analyze.cpp+6-23
......@@ -5909,12 +5909,7 @@ ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_
59095909
59105910
59115911ZigValue *create_const_vals(size_t count) {
5912 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
5913 ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
5914 for (size_t i = 0; i < count; i += 1) {
5915 vals[i].global_refs = &global_refs[i];
5916 }
5917 return vals;
5912 return allocate<ZigValue>(count, "ZigValue");
59185913}
59195914
59205915ZigValue **alloc_const_vals_ptrs(size_t count) {
......@@ -6492,20 +6487,14 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
64926487 return false;
64936488 return true;
64946489 case ConstPtrSpecialBaseArray:
6495 if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val &&
6496 a->data.x_ptr.data.base_array.array_val->global_refs !=
6497 b->data.x_ptr.data.base_array.array_val->global_refs)
6498 {
6490 if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val) {
64996491 return false;
65006492 }
65016493 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
65026494 return false;
65036495 return true;
65046496 case ConstPtrSpecialBaseStruct:
6505 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&
6506 a->data.x_ptr.data.base_struct.struct_val->global_refs !=
6507 b->data.x_ptr.data.base_struct.struct_val->global_refs)
6508 {
6497 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val) {
65096498 return false;
65106499 }
65116500 if (a->data.x_ptr.data.base_struct.field_index != b->data.x_ptr.data.base_struct.field_index)
......@@ -6513,27 +6502,21 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
65136502 return true;
65146503 case ConstPtrSpecialBaseErrorUnionCode:
65156504 if (a->data.x_ptr.data.base_err_union_code.err_union_val !=
6516 b->data.x_ptr.data.base_err_union_code.err_union_val &&
6517 a->data.x_ptr.data.base_err_union_code.err_union_val->global_refs !=
6518 b->data.x_ptr.data.base_err_union_code.err_union_val->global_refs)
6505 b->data.x_ptr.data.base_err_union_code.err_union_val)
65196506 {
65206507 return false;
65216508 }
65226509 return true;
65236510 case ConstPtrSpecialBaseErrorUnionPayload:
65246511 if (a->data.x_ptr.data.base_err_union_payload.err_union_val !=
6525 b->data.x_ptr.data.base_err_union_payload.err_union_val &&
6526 a->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs !=
6527 b->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs)
6512 b->data.x_ptr.data.base_err_union_payload.err_union_val)
65286513 {
65296514 return false;
65306515 }
65316516 return true;
65326517 case ConstPtrSpecialBaseOptionalPayload:
65336518 if (a->data.x_ptr.data.base_optional_payload.optional_val !=
6534 b->data.x_ptr.data.base_optional_payload.optional_val &&
6535 a->data.x_ptr.data.base_optional_payload.optional_val->global_refs !=
6536 b->data.x_ptr.data.base_optional_payload.optional_val->global_refs)
6519 b->data.x_ptr.data.base_optional_payload.optional_val)
65376520 {
65386521 return false;
65396522 }
src/codegen.cpp+42-68
......@@ -946,7 +946,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
946946
947947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
948948 ZigValue *val = &g->panic_msg_vals[msg_id];
949 if (!val->global_refs->llvm_global) {
949 if (!val->llvm_global) {
950950
951951 Buf *buf_msg = panic_msg_buf(msg_id);
952952 ZigValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;
......@@ -955,13 +955,13 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
955955 render_const_val(g, val, "");
956956 render_const_val_global(g, val, "");
957957
958 assert(val->global_refs->llvm_global);
958 assert(val->llvm_global);
959959 }
960960
961961 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
962962 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
963963 ZigType *str_type = get_slice_type(g, u8_ptr_type);
964 return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(get_llvm_type(g, str_type), 0));
964 return LLVMConstBitCast(val->llvm_global, LLVMPointerType(get_llvm_type(g, str_type), 0));
965965}
966966
967967static ZigType *ptr_to_stack_trace_type(CodeGen *g) {
......@@ -1727,9 +1727,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
17271727 if (handle_is_ptr(instruction->value->type)) {
17281728 render_const_val_global(g, instruction->value, "");
17291729 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);
1730 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_global, get_llvm_type(g, ptr_type), "");
1730 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->llvm_global, get_llvm_type(g, ptr_type), "");
17311731 } else {
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->global_refs->llvm_value,
1732 instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value->llvm_value,
17331733 get_llvm_type(g, instruction->value->type), "");
17341734 }
17351735 assert(instruction->llvm_value);
......@@ -6374,7 +6374,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren
63746374 case ConstParentIdNone:
63756375 render_const_val(g, val, "");
63766376 render_const_val_global(g, val, "");
6377 return val->global_refs->llvm_global;
6377 return val->llvm_global;
63786378 case ConstParentIdStruct:
63796379 return gen_const_ptr_struct_recursive(g, parent->data.p_struct.struct_val,
63806380 parent->data.p_struct.field_index);
......@@ -6392,7 +6392,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren
63926392 case ConstParentIdScalar:
63936393 render_const_val(g, parent->data.p_scalar.scalar_val, "");
63946394 render_const_val_global(g, parent->data.p_scalar.scalar_val, "");
6395 return parent->data.p_scalar.scalar_val->global_refs->llvm_global;
6395 return parent->data.p_scalar.scalar_val->llvm_global;
63966396 }
63976397 zig_unreachable();
63986398}
......@@ -6623,17 +6623,15 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
66236623 zig_unreachable();
66246624 case ConstPtrSpecialRef:
66256625 {
6626 assert(const_val->global_refs != nullptr);
66276626 ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee;
66286627 render_const_val(g, pointee, "");
66296628 render_const_val_global(g, pointee, "");
6630 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
6629 const_val->llvm_value = LLVMConstBitCast(pointee->llvm_global,
66316630 get_llvm_type(g, const_val->type));
6632 return const_val->global_refs->llvm_value;
6631 return const_val->llvm_value;
66336632 }
66346633 case ConstPtrSpecialBaseArray:
66356634 {
6636 assert(const_val->global_refs != nullptr);
66376635 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
66386636 assert(array_const_val->type->id == ZigTypeIdArray);
66396637 if (!type_has_bits(array_const_val->type)) {
......@@ -6641,102 +6639,97 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
66416639 ZigValue *pointee = array_const_val->type->data.array.sentinel;
66426640 render_const_val(g, pointee, "");
66436641 render_const_val_global(g, pointee, "");
6644 const_val->global_refs->llvm_value = LLVMConstBitCast(pointee->global_refs->llvm_global,
6642 const_val->llvm_value = LLVMConstBitCast(pointee->llvm_global,
66456643 get_llvm_type(g, const_val->type));
6646 return const_val->global_refs->llvm_value;
6644 return const_val->llvm_value;
66476645 } else {
66486646 // make this a null pointer
66496647 ZigType *usize = g->builtin_types.entry_usize;
6650 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6648 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
66516649 get_llvm_type(g, const_val->type));
6652 return const_val->global_refs->llvm_value;
6650 return const_val->llvm_value;
66536651 }
66546652 }
66556653 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
66566654 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);
66576655 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6658 const_val->global_refs->llvm_value = ptr_val;
6656 const_val->llvm_value = ptr_val;
66596657 return ptr_val;
66606658 }
66616659 case ConstPtrSpecialBaseStruct:
66626660 {
6663 assert(const_val->global_refs != nullptr);
66646661 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
66656662 assert(struct_const_val->type->id == ZigTypeIdStruct);
66666663 if (!type_has_bits(struct_const_val->type)) {
66676664 // make this a null pointer
66686665 ZigType *usize = g->builtin_types.entry_usize;
6669 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6666 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
66706667 get_llvm_type(g, const_val->type));
6671 return const_val->global_refs->llvm_value;
6668 return const_val->llvm_value;
66726669 }
66736670 size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index;
66746671 size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index]->gen_index;
66756672 LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val,
66766673 gen_field_index);
66776674 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6678 const_val->global_refs->llvm_value = ptr_val;
6675 const_val->llvm_value = ptr_val;
66796676 return ptr_val;
66806677 }
66816678 case ConstPtrSpecialBaseErrorUnionCode:
66826679 {
6683 assert(const_val->global_refs != nullptr);
66846680 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
66856681 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
66866682 if (!type_has_bits(err_union_const_val->type)) {
66876683 // make this a null pointer
66886684 ZigType *usize = g->builtin_types.entry_usize;
6689 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6685 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
66906686 get_llvm_type(g, const_val->type));
6691 return const_val->global_refs->llvm_value;
6687 return const_val->llvm_value;
66926688 }
66936689 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_code_recursive(g, err_union_const_val);
66946690 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6695 const_val->global_refs->llvm_value = ptr_val;
6691 const_val->llvm_value = ptr_val;
66966692 return ptr_val;
66976693 }
66986694 case ConstPtrSpecialBaseErrorUnionPayload:
66996695 {
6700 assert(const_val->global_refs != nullptr);
67016696 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
67026697 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
67036698 if (!type_has_bits(err_union_const_val->type)) {
67046699 // make this a null pointer
67056700 ZigType *usize = g->builtin_types.entry_usize;
6706 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6701 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
67076702 get_llvm_type(g, const_val->type));
6708 return const_val->global_refs->llvm_value;
6703 return const_val->llvm_value;
67096704 }
67106705 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_payload_recursive(g, err_union_const_val);
67116706 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6712 const_val->global_refs->llvm_value = ptr_val;
6707 const_val->llvm_value = ptr_val;
67136708 return ptr_val;
67146709 }
67156710 case ConstPtrSpecialBaseOptionalPayload:
67166711 {
6717 assert(const_val->global_refs != nullptr);
67186712 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
67196713 assert(optional_const_val->type->id == ZigTypeIdOptional);
67206714 if (!type_has_bits(optional_const_val->type)) {
67216715 // make this a null pointer
67226716 ZigType *usize = g->builtin_types.entry_usize;
6723 const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
6717 const_val->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->llvm_type),
67246718 get_llvm_type(g, const_val->type));
6725 return const_val->global_refs->llvm_value;
6719 return const_val->llvm_value;
67266720 }
67276721 LLVMValueRef uncasted_ptr_val = gen_const_ptr_optional_payload_recursive(g, optional_const_val);
67286722 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));
6729 const_val->global_refs->llvm_value = ptr_val;
6723 const_val->llvm_value = ptr_val;
67306724 return ptr_val;
67316725 }
67326726 case ConstPtrSpecialHardCodedAddr:
67336727 {
6734 assert(const_val->global_refs != nullptr);
67356728 uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;
67366729 ZigType *usize = g->builtin_types.entry_usize;
6737 const_val->global_refs->llvm_value = LLVMConstIntToPtr(
6730 const_val->llvm_value = LLVMConstIntToPtr(
67386731 LLVMConstInt(usize->llvm_type, addr_value, false), get_llvm_type(g, const_val->type));
6739 return const_val->global_refs->llvm_value;
6732 return const_val->llvm_value;
67406733 }
67416734 case ConstPtrSpecialFunction:
67426735 return LLVMConstBitCast(fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry),
......@@ -7175,34 +7168,29 @@ check: switch (const_val->special) {
71757168}
71767169
71777170static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
7178 if (!const_val->global_refs)
7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);
7180 if (!const_val->global_refs->llvm_value)
7181 const_val->global_refs->llvm_value = gen_const_val(g, const_val, name);
7171 if (!const_val->llvm_value)
7172 const_val->llvm_value = gen_const_val(g, const_val, name);
71827173
7183 if (const_val->global_refs->llvm_global)
7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
7174 if (const_val->llvm_global)
7175 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
71857176}
71867177
71877178static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) {
7188 if (!const_val->global_refs)
7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);
7190
7191 if (!const_val->global_refs->llvm_global) {
7192 LLVMTypeRef type_ref = const_val->global_refs->llvm_value ?
7193 LLVMTypeOf(const_val->global_refs->llvm_value) : get_llvm_type(g, const_val->type);
7179 if (!const_val->llvm_global) {
7180 LLVMTypeRef type_ref = const_val->llvm_value ?
7181 LLVMTypeOf(const_val->llvm_value) : get_llvm_type(g, const_val->type);
71947182 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, name);
71957183 LLVMSetLinkage(global_value, LLVMInternalLinkage);
71967184 LLVMSetGlobalConstant(global_value, true);
71977185 LLVMSetUnnamedAddr(global_value, true);
7198 LLVMSetAlignment(global_value, (const_val->global_refs->align == 0) ?
7199 get_abi_alignment(g, const_val->type) : const_val->global_refs->align);
7186 LLVMSetAlignment(global_value, (const_val->llvm_align == 0) ?
7187 get_abi_alignment(g, const_val->type) : const_val->llvm_align);
72007188
7201 const_val->global_refs->llvm_global = global_value;
7189 const_val->llvm_global = global_value;
72027190 }
72037191
7204 if (const_val->global_refs->llvm_value)
7205 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);
7192 if (const_val->llvm_value)
7193 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
72067194}
72077195
72087196static void generate_error_name_table(CodeGen *g) {
......@@ -7403,7 +7391,7 @@ static void do_code_gen(CodeGen *g) {
74037391 bool exported = (linkage != GlobalLinkageIdInternal);
74047392 render_const_val(g, var->const_value, symbol_name);
74057393 render_const_val_global(g, var->const_value, symbol_name);
7406 global_value = var->const_value->global_refs->llvm_global;
7394 global_value = var->const_value->llvm_global;
74077395
74087396 if (exported) {
74097397 LLVMSetLinkage(global_value, to_llvm_linkage(linkage));
......@@ -7418,7 +7406,7 @@ static void do_code_gen(CodeGen *g) {
74187406 // Here we use const_value->type because that's the type of the llvm global,
74197407 // which we const ptr cast upon use to whatever it needs to be.
74207408 if (var->gen_is_const && var->const_value->type->id != ZigTypeIdFn) {
7421 gen_global_var(g, var, var->const_value->global_refs->llvm_value, var->const_value->type);
7409 gen_global_var(g, var, var->const_value->llvm_value, var->const_value->type);
74227410 }
74237411
74247412 LLVMSetGlobalConstant(global_value, var->gen_is_const);
......@@ -8012,31 +8000,26 @@ static void define_intern_values(CodeGen *g) {
80128000 {
80138001 auto& value = g->intern.x_undefined;
80148002 value.type = g->builtin_types.entry_undef;
8015 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined");
80168003 value.special = ConstValSpecialStatic;
80178004 }
80188005 {
80198006 auto& value = g->intern.x_void;
80208007 value.type = g->builtin_types.entry_void;
8021 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void");
80228008 value.special = ConstValSpecialStatic;
80238009 }
80248010 {
80258011 auto& value = g->intern.x_null;
80268012 value.type = g->builtin_types.entry_null;
8027 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null");
80288013 value.special = ConstValSpecialStatic;
80298014 }
80308015 {
80318016 auto& value = g->intern.x_unreachable;
80328017 value.type = g->builtin_types.entry_unreachable;
8033 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable");
80348018 value.special = ConstValSpecialStatic;
80358019 }
80368020 {
80378021 auto& value = g->intern.zero_byte;
80388022 value.type = g->builtin_types.entry_u8;
8039 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.zero_byte");
80408023 value.special = ConstValSpecialStatic;
80418024 bigint_init_unsigned(&value.data.x_bigint, 0);
80428025 }
......@@ -8669,19 +8652,10 @@ static void init(CodeGen *g) {
86698652 g->invalid_instruction = &sentinel_instructions[0];
86708653 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
86718654 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8672 g->invalid_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86738655
86748656 g->unreach_instruction = &sentinel_instructions[1];
86758657 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
86768658 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
8677 g->unreach_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
8678
8679 {
8680 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(PanicMsgIdCount);
8681 for (size_t i = 0; i < PanicMsgIdCount; i += 1) {
8682 g->panic_msg_vals[i].global_refs = &global_refs[i];
8683 }
8684 }
86858659
86868660 define_builtin_fns(g);
86878661 Error err;
src/ir.cpp+381-346
......@@ -42,6 +42,10 @@ struct IrAnalyze {
4242 ZigList<IrSuspendPosition> resume_stack;
4343 IrBasicBlock *const_predecessor_bb;
4444 size_t ref_count;
45 size_t break_debug_id; // for debugging purposes
46
47 // For the purpose of using in a debugger
48 void dump();
4549};
4650
4751enum ConstCastResultId {
......@@ -195,6 +199,14 @@ struct ConstCastIntShorten {
195199 ZigType *actual_type;
196200};
197201
202// for debugging purposes
203struct DbgIrBreakPoint {
204 const char *src_file;
205 uint32_t line;
206};
207DbgIrBreakPoint dbg_ir_breakpoints_buf[20];
208size_t dbg_ir_breakpoints_count = 0;
209
198210static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
199211static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
200212 ResultLoc *result_loc);
......@@ -220,14 +232,15 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
220232static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
221233 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
222234static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);
223static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs);
235static void copy_const_val(ZigValue *dest, ZigValue *src);
224236static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
225237static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
226238 ZigType *ptr_type);
227239static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
228240 ZigType *dest_type);
229241static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
230 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime);
242 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
243 bool non_null_comptime, bool allow_discard);
231244static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
232245 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
233246 bool non_null_comptime, bool allow_discard);
......@@ -733,6 +746,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
733746 case ZigTypeIdErrorSet:
734747 case ZigTypeIdOpaque:
735748 case ZigTypeIdAnyFrame:
749 case ZigTypeIdFn:
736750 return true;
737751 case ZigTypeIdFloat:
738752 return expected->data.floating.bit_count == actual->data.floating.bit_count;
......@@ -744,7 +758,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
744758 case ZigTypeIdErrorUnion:
745759 case ZigTypeIdEnum:
746760 case ZigTypeIdUnion:
747 case ZigTypeIdFn:
748761 case ZigTypeIdArgTuple:
749762 case ZigTypeIdVector:
750763 case ZigTypeIdFnFrame:
......@@ -1541,7 +1554,6 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no
15411554 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
15421555 special_instruction->base.owner_bb = irb->current_basic_block;
15431556 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1544 special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs");
15451557 return special_instruction;
15461558}
15471559
......@@ -4324,6 +4336,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
43244336 scope_block->peer_parent = allocate<ResultLocPeerParent>(1, "ResultLocPeerParent");
43254337 scope_block->peer_parent->base.id = ResultLocIdPeerParent;
43264338 scope_block->peer_parent->base.source_instruction = scope_block->is_comptime;
4339 scope_block->peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
43274340 scope_block->peer_parent->end_bb = scope_block->end_block;
43284341 scope_block->peer_parent->is_comptime = scope_block->is_comptime;
43294342 scope_block->peer_parent->parent = result_loc;
......@@ -4578,6 +4591,7 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction
45784591 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
45794592 peer_parent->base.id = ResultLocIdPeerParent;
45804593 peer_parent->base.source_instruction = cond_br_inst;
4594 peer_parent->base.allow_write_through_const = parent->allow_write_through_const;
45814595 peer_parent->end_bb = end_block;
45824596 peer_parent->is_comptime = is_comptime;
45834597 peer_parent->parent = parent;
......@@ -6349,7 +6363,9 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
63496363
63506364 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
63516365 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, fn_type, arg_index, true);
6352 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result_loc());
6366 ResultLoc *no_result = no_result_loc();
6367 ir_build_reset_result(irb, scope, node, no_result);
6368 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);
63536369
63546370 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
63556371 if (arg == irb->codegen->invalid_instruction)
......@@ -6771,6 +6787,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo
67716787 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
67726788 result_loc_var->base.id = ResultLocIdVar;
67736789 result_loc_var->base.source_instruction = alloca;
6790 result_loc_var->base.allow_write_through_const = true;
67746791 result_loc_var->var = var;
67756792
67766793 ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base);
......@@ -6784,6 +6801,7 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de
67846801 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
67856802 result_loc_cast->base.id = ResultLocIdCast;
67866803 result_loc_cast->base.source_instruction = dest_type;
6804 result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const;
67876805 ir_ref_instruction(dest_type, irb->current_basic_block);
67886806 result_loc_cast->parent = parent_result_loc;
67896807
......@@ -7964,6 +7982,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
79647982
79657983 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
79667984 peer_parent->base.id = ResultLocIdPeerParent;
7985 peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
79677986 peer_parent->end_bb = end_block;
79687987 peer_parent->is_comptime = is_comptime;
79697988 peer_parent->parent = result_loc;
......@@ -9111,7 +9130,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast
91119130 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
91129131 return err;
91139132 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
9114 copy_const_val(child_val, &tmp, false);
9133 copy_const_val(child_val, &tmp);
91159134 return ErrorNone;
91169135}
91179136
......@@ -10756,10 +10775,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1075610775 continue;
1075710776 }
1075810777 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
10759 if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
10778 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
10779 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10780 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {
1076010781 return ira->codegen->builtin_types.entry_invalid;
1076110782 }
10762 if (type_is_global_error_set(cur_err_set_type)) {
10783 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
1076310784 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
1076410785 prev_inst = cur_inst;
1076510786 continue;
......@@ -10809,9 +10830,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1080910830 }
1081010831
1081110832 if (cur_type->id == ZigTypeIdErrorSet) {
10812 if (prev_type->id == ZigTypeIdArray) {
10813 convert_to_const_slice = true;
10814 }
1081510833 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
1081610834 return ira->codegen->builtin_types.entry_invalid;
1081710835 }
......@@ -11146,25 +11164,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1114611164 }
1114711165 }
1114811166
11149 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
11150 cur_type->data.array.len != prev_type->data.array.len &&
11151 types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
11152 source_node, false).id == ConstCastResultIdOk)
11153 {
11154 convert_to_const_slice = true;
11155 prev_inst = cur_inst;
11156 continue;
11157 }
11158
11159 if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
11160 cur_type->data.array.len != prev_type->data.array.len &&
11161 types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
11162 source_node, false).id == ConstCastResultIdOk)
11163 {
11164 convert_to_const_slice = true;
11165 continue;
11166 }
11167
1116811167 // *[N]T to []T
1116911168 // *[N]T to E![]T
1117011169 if (cur_type->id == ZigTypeIdPointer &&
......@@ -11212,19 +11211,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1121211211 }
1121311212 }
1121411213
11215 // [N]T to []T
11216 if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
11217 (prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
11218 cur_type->data.array.len == 0) &&
11219 types_match_const_cast_only(ira,
11220 prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
11221 cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
11222 {
11223 convert_to_const_slice = false;
11224 continue;
11225 }
11226
11227
1122811214 // *[N]T and *[M]T
1122911215 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
1123011216 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
......@@ -11268,19 +11254,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1126811254 continue;
1126911255 }
1127011256
11271 // [N]T to []T
11272 if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
11273 (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
11274 prev_type->data.array.len == 0) &&
11275 types_match_const_cast_only(ira,
11276 cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
11277 prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
11278 {
11279 prev_inst = cur_inst;
11280 convert_to_const_slice = false;
11281 continue;
11282 }
11283
1128411257 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
1128511258 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
1128611259 {
......@@ -11316,18 +11289,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1131611289 free(errors);
1131711290
1131811291 if (convert_to_const_slice) {
11319 if (prev_inst->value->type->id == ZigTypeIdArray) {
11320 ZigType *ptr_type = get_pointer_to_type_extra(
11321 ira->codegen, prev_inst->value->type->data.array.child_type,
11322 true, false, PtrLenUnknown,
11323 0, 0, 0, false);
11324 ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
11325 if (err_set_type != nullptr) {
11326 return get_error_union_type(ira->codegen, err_set_type, slice_type);
11327 } else {
11328 return slice_type;
11329 }
11330 } else if (prev_inst->value->type->id == ZigTypeIdPointer) {
11292 if (prev_inst->value->type->id == ZigTypeIdPointer) {
1133111293 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
1133211294 src_assert(array_type->id == ZigTypeIdArray, source_node);
1133311295 ZigType *ptr_type = get_pointer_to_type_extra2(
......@@ -11394,19 +11356,37 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1139411356 }
1139511357}
1139611358
11397static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) {
11398 ConstGlobalRefs *global_refs = dest->global_refs;
11359// Returns whether the x_optional field of ZigValue is active.
11360static bool type_has_optional_repr(ZigType *ty) {
11361 if (ty->id != ZigTypeIdOptional) {
11362 return false;
11363 } else if (get_codegen_ptr_type(ty) != nullptr) {
11364 return false;
11365 } else if (is_opt_err_set(ty)) {
11366 return false;
11367 } else {
11368 return true;
11369 }
11370}
11371
11372static void copy_const_val(ZigValue *dest, ZigValue *src) {
1139911373 memcpy(dest, src, sizeof(ZigValue));
11400 if (!same_global_refs) {
11401 dest->global_refs = global_refs;
11402 if (src->special != ConstValSpecialStatic)
11403 return;
11404 if (dest->type->id == ZigTypeIdStruct) {
11405 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
11406 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
11407 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i], false);
11408 }
11374 if (src->special != ConstValSpecialStatic)
11375 return;
11376 dest->parent.id = ConstParentIdNone;
11377 if (dest->type->id == ZigTypeIdStruct) {
11378 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
11379 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
11380 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
11381 dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;
11382 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;
11383 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;
1140911384 }
11385 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
11386 dest->data.x_optional = create_const_vals(1);
11387 copy_const_val(dest->data.x_optional, src->data.x_optional);
11388 dest->data.x_optional->parent.id = ConstParentIdOptionalPayload;
11389 dest->data.x_optional->parent.data.p_optional_payload.optional_val = dest;
1141011390 }
1141111391}
1141211392
......@@ -11424,13 +11404,11 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
1142411404 case CastOpErrSet:
1142511405 case CastOpBitCast:
1142611406 zig_panic("TODO");
11427 case CastOpNoop:
11428 {
11429 bool same_global_refs = other_val->special == ConstValSpecialStatic;
11430 copy_const_val(const_val, other_val, same_global_refs);
11431 const_val->type = new_type;
11432 break;
11433 }
11407 case CastOpNoop: {
11408 copy_const_val(const_val, other_val);
11409 const_val->type = new_type;
11410 break;
11411 }
1143411412 case CastOpNumLitToConcrete:
1143511413 if (other_val->type->id == ZigTypeIdComptimeFloat) {
1143611414 assert(new_type->id == ZigTypeIdFloat);
......@@ -11527,6 +11505,14 @@ static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruct
1152711505 return &const_instruction->base;
1152811506}
1152911507
11508// This function initializes the new IrInstruction with the provided ZigValue,
11509// rather than creating a new one.
11510static IrInstruction *ir_const_move(IrAnalyze *ira, IrInstruction *old_instruction, ZigValue *val) {
11511 IrInstruction *result = ir_const_noval(ira, old_instruction);
11512 result->value = val;
11513 return result;
11514}
11515
1153011516static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
1153111517 ZigType *wanted_type, CastOp cast_op)
1153211518{
......@@ -12151,7 +12137,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1215112137 source_instr->scope, source_instr->source_node);
1215212138 const_instruction->base.value->special = ConstValSpecialStatic;
1215312139 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
12154 copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst);
12140 copy_const_val(const_instruction->base.value, val);
1215512141 } else {
1215612142 const_instruction->base.value->data.x_optional = val;
1215712143 }
......@@ -12413,52 +12399,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1241312399 return new_instruction;
1241412400}
1241512401
12416static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
12417 IrInstruction *array_arg, ZigType *wanted_type, ResultLoc *result_loc)
12418{
12419 assert(is_slice(wanted_type));
12420 // In this function we honor the const-ness of wanted_type, because
12421 // we may be casting [0]T to []const T which is perfectly valid.
12422
12423 IrInstruction *array_ptr = nullptr;
12424 IrInstruction *array;
12425 if (array_arg->value->type->id == ZigTypeIdPointer) {
12426 array = ir_get_deref(ira, source_instr, array_arg, nullptr);
12427 array_ptr = array_arg;
12428 } else {
12429 array = array_arg;
12430 }
12431 ZigType *array_type = array->value->type;
12432 assert(array_type->id == ZigTypeIdArray);
12433
12434 if (instr_is_comptime(array) || array_type->data.array.len == 0) {
12435 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12436 init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true);
12437 result->value->type = wanted_type;
12438 return result;
12439 }
12440
12441 IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
12442 init_const_usize(ira->codegen, start->value, 0);
12443
12444 IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
12445 init_const_usize(ira->codegen, end->value, array_type->data.array.len);
12446
12447 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
12448
12449 if (result_loc == nullptr) result_loc = no_result_loc();
12450 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr,
12451 true, false, true);
12452 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
12453 return result_loc_inst;
12454 }
12455 IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst);
12456 result->value->data.rh_slice.id = RuntimeHintSliceIdLen;
12457 result->value->data.rh_slice.len = array_type->data.array.len;
12458
12459 return result;
12460}
12461
1246212402static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
1246312403 assert(union_type->id == ZigTypeIdUnion);
1246412404
......@@ -13155,7 +13095,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
1315513095 if (instr_is_comptime(array)) {
1315613096 // arrays and vectors have the same ZigValue representation
1315713097 IrInstruction *result = ir_const(ira, source_instr, vector_type);
13158 copy_const_val(result->value, array->value, false);
13098 copy_const_val(result->value, array->value);
1315913099 result->value->type = vector_type;
1316013100 return result;
1316113101 }
......@@ -13168,7 +13108,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1316813108 if (instr_is_comptime(vector)) {
1316913109 // arrays and vectors have the same ZigValue representation
1317013110 IrInstruction *result = ir_const(ira, source_instr, array_type);
13171 copy_const_val(result->value, vector->value, false);
13111 copy_const_val(result->value, vector->value);
1317213112 result->value->type = array_type;
1317313113 return result;
1317413114 }
......@@ -13456,7 +13396,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1345613396 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
1345713397 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
1345813398 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13459 copy_const_val(result->value, value->value, false);
13399 copy_const_val(result->value, value->value);
1346013400 result->value->type = wanted_type;
1346113401 } else {
1346213402 float_init_bigint(&result->value->data.x_bigint, value->value);
......@@ -13504,44 +13444,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1350413444 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
1350513445 }
1350613446
13507 // cast from [N]T to []const T
13508 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
13509 if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
13510 ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
13511 assert(ptr_type->id == ZigTypeIdPointer);
13512 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
13513 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13514 source_node, false).id == ConstCastResultIdOk)
13515 {
13516 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type, nullptr);
13517 }
13518 }
13519
13520 // cast from [N]T to ?[]const T
13521 // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
13522 if (wanted_type->id == ZigTypeIdOptional &&
13523 is_slice(wanted_type->data.maybe.child_type) &&
13524 actual_type->id == ZigTypeIdArray)
13525 {
13526 ZigType *ptr_type =
13527 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index]->type_entry;
13528 assert(ptr_type->id == ZigTypeIdPointer);
13529 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
13530 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13531 source_node, false).id == ConstCastResultIdOk)
13532 {
13533 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13534 if (type_is_invalid(cast1->value->type))
13535 return ira->codegen->invalid_instruction;
13536
13537 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13538 if (type_is_invalid(cast2->value->type))
13539 return ira->codegen->invalid_instruction;
13540
13541 return cast2;
13542 }
13543 }
13544
1354513447 // *[N]T to ?[]const T
1354613448 if (wanted_type->id == ZigTypeIdOptional &&
1354713449 is_slice(wanted_type->data.maybe.child_type) &&
......@@ -13687,20 +13589,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1368713589 }
1368813590
1368913591 // *@Frame(func) to anyframe->T or anyframe
13592 // *@Frame(func) to ?anyframe->T or ?anyframe
13593 // *@Frame(func) to E!anyframe->T or E!anyframe
1369013594 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&
1369113595 !actual_type->data.pointer.is_const &&
13692 actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame && wanted_type->id == ZigTypeIdAnyFrame)
13596 actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame)
1369313597 {
13694 bool ok = true;
13695 if (wanted_type->data.any_frame.result_type != nullptr) {
13696 ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;
13697 ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;
13698 if (wanted_type->data.any_frame.result_type != fn_return_type) {
13699 ok = false;
13598 ZigType *anyframe_type;
13599 if (wanted_type->id == ZigTypeIdAnyFrame) {
13600 anyframe_type = wanted_type;
13601 } else if (wanted_type->id == ZigTypeIdOptional &&
13602 wanted_type->data.maybe.child_type->id == ZigTypeIdAnyFrame)
13603 {
13604 anyframe_type = wanted_type->data.maybe.child_type;
13605 } else if (wanted_type->id == ZigTypeIdErrorUnion &&
13606 wanted_type->data.error_union.payload_type->id == ZigTypeIdAnyFrame)
13607 {
13608 anyframe_type = wanted_type->data.error_union.payload_type;
13609 } else {
13610 anyframe_type = nullptr;
13611 }
13612 if (anyframe_type != nullptr) {
13613 bool ok = true;
13614 if (anyframe_type->data.any_frame.result_type != nullptr) {
13615 ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;
13616 ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;
13617 if (anyframe_type->data.any_frame.result_type != fn_return_type) {
13618 ok = false;
13619 }
13620 }
13621 if (ok) {
13622 IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
13623 if (anyframe_type == wanted_type)
13624 return cast1;
13625 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
1370013626 }
13701 }
13702 if (ok) {
13703 return ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, wanted_type);
1370413627 }
1370513628 }
1370613629
......@@ -13725,30 +13648,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1372513648 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);
1372613649 }
1372713650
13728 // cast from [N]T to E![]const T
13729 if (wanted_type->id == ZigTypeIdErrorUnion &&
13730 is_slice(wanted_type->data.error_union.payload_type) &&
13731 actual_type->id == ZigTypeIdArray)
13732 {
13733 ZigType *ptr_type =
13734 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index]->type_entry;
13735 assert(ptr_type->id == ZigTypeIdPointer);
13736 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
13737 types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
13738 source_node, false).id == ConstCastResultIdOk)
13739 {
13740 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
13741 if (type_is_invalid(cast1->value->type))
13742 return ira->codegen->invalid_instruction;
13743
13744 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13745 if (type_is_invalid(cast2->value->type))
13746 return ira->codegen->invalid_instruction;
13747
13748 return cast2;
13749 }
13750 }
13751
1375213651 // cast from E to E!T
1375313652 if (wanted_type->id == ZigTypeIdErrorUnion &&
1375413653 actual_type->id == ZigTypeIdErrorSet)
......@@ -13944,6 +13843,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1394413843 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
1394513844 }
1394613845
13846 // T to ?U, where T implicitly casts to U
13847 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {
13848 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
13849 if (type_is_invalid(cast1->value->type))
13850 return ira->codegen->invalid_instruction;
13851 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
13852 }
13853
13854 // T to E!U, where T implicitly casts to U
13855 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
13856 actual_type->id != ZigTypeIdErrorSet)
13857 {
13858 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
13859 if (type_is_invalid(cast1->value->type))
13860 return ira->codegen->invalid_instruction;
13861 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
13862 }
13863
1394713864 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
1394813865 buf_sprintf("expected type '%s', found '%s'",
1394913866 buf_ptr(&wanted_type->name),
......@@ -14338,9 +14255,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
1433814255}
1433914256
1434014257static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
14341 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
14342 copy_const_val(result->value, instruction->base.value, true);
14343 return result;
14258 return ir_const_move(ira, &instruction->base, instruction->base.value);
1434414259}
1434514260
1434614261static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
......@@ -14878,7 +14793,7 @@ never_mind_just_calculate_it_normally:
1487814793 &op1_val->data.x_array.data.s_none.elements[i],
1487914794 &op2_val->data.x_array.data.s_none.elements[i],
1488014795 bin_op_instruction, op_id, one_possible_value);
14881 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false);
14796 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value);
1488214797 }
1488314798 return result;
1488414799 }
......@@ -15686,10 +15601,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1568615601
1568715602 ZigValue *out_array_val;
1568815603 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
15689 if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15690 result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
15691 out_array_val = out_val;
15692 } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
15604 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
1569315605 out_array_val = create_const_vals(1);
1569415606 out_array_val->special = ConstValSpecialStatic;
1569515607 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
......@@ -15717,6 +15629,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1571715629 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
1571815630 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
1571915631 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
15632 } else if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
15633 result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
15634 out_array_val = out_val;
1572015635 } else {
1572115636 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
1572215637 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
......@@ -15744,21 +15659,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1574415659 size_t next_index = 0;
1574515660 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
1574615661 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15747 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false);
15662 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]);
1574815663 elem_dest_val->parent.id = ConstParentIdArray;
1574915664 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1575015665 elem_dest_val->parent.data.p_array.elem_index = next_index;
1575115666 }
1575215667 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
1575315668 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15754 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false);
15669 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]);
1575515670 elem_dest_val->parent.id = ConstParentIdArray;
1575615671 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1575715672 elem_dest_val->parent.data.p_array.elem_index = next_index;
1575815673 }
1575915674 if (next_index < full_len) {
1576015675 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
15761 copy_const_val(elem_dest_val, sentinel, false);
15676 copy_const_val(elem_dest_val, sentinel);
1576215677 elem_dest_val->parent.id = ConstParentIdArray;
1576315678 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1576415679 elem_dest_val->parent.data.p_array.elem_index = next_index;
......@@ -15843,7 +15758,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1584315758 for (uint64_t x = 0; x < mult_amt; x += 1) {
1584415759 for (uint64_t y = 0; y < old_array_len; y += 1) {
1584515760 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15846 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false);
15761 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]);
1584715762 elem_dest_val->parent.id = ConstParentIdArray;
1584815763 elem_dest_val->parent.data.p_array.array_val = out_val;
1584915764 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -15854,7 +15769,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1585415769
1585515770 if (array_type->data.array.sentinel != nullptr) {
1585615771 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
15857 copy_const_val(elem_dest_val, array_type->data.array.sentinel, false);
15772 copy_const_val(elem_dest_val, array_type->data.array.sentinel);
1585815773 elem_dest_val->parent.id = ConstParentIdArray;
1585915774 elem_dest_val->parent.data.p_array.array_val = out_val;
1586015775 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -16004,7 +15919,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1600415919 var->const_value = init_val;
1600515920 } else {
1600615921 var->const_value = create_const_vals(1);
16007 copy_const_val(var->const_value, init_val, false);
15922 copy_const_val(var->const_value, init_val);
1600815923 }
1600915924 }
1601015925 }
......@@ -16030,7 +15945,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1603015945 result_type = ira->codegen->builtin_types.entry_invalid;
1603115946 } else if (init_val->type->id == ZigTypeIdFn &&
1603215947 init_val->special != ConstValSpecialUndef &&
16033 init_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
15948 init_val->data.x_ptr.special == ConstPtrSpecialFunction &&
1603415949 init_val->data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
1603515950 {
1603615951 var_class_requires_const = true;
......@@ -16114,7 +16029,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1611416029 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
1611516030 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
1611616031 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
16117 copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const);
16032 copy_const_val(mem_slot, init_val);
1611816033 ira_ref(var->owner_exec->analysis);
1611916034
1612016035 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
......@@ -16546,7 +16461,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
1654616461
1654716462// when calling this function, at the callsite must check for result type noreturn and propagate it up
1654816463static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
16549 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
16464 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
16465 bool non_null_comptime, bool allow_discard)
1655016466{
1655116467 Error err;
1655216468 if (result_loc->resolved_loc != nullptr) {
......@@ -16584,7 +16500,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1658416500 bool force_comptime;
1658516501 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
1658616502 return ira->codegen->invalid_instruction;
16587 bool is_comptime = force_comptime || (value != nullptr &&
16503 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&
1658816504 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
1658916505
1659016506 if (alloca_src->base.child == nullptr || is_comptime) {
......@@ -16594,15 +16510,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1659416510 }
1659516511 IrInstruction *alloca_gen;
1659616512 if (is_comptime && value != nullptr) {
16597 if (align > value->value->global_refs->align) {
16598 value->value->global_refs->align = align;
16513 if (align > value->value->llvm_align) {
16514 value->value->llvm_align = align;
1659916515 }
1660016516 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
1660116517 } else {
1660216518 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
1660316519 alloca_src->name_hint, force_comptime);
16520 if (force_runtime) {
16521 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
16522 alloca_gen->value->special = ConstValSpecialRuntime;
16523 }
1660416524 }
16605 if (alloca_src->base.child != nullptr) {
16525 if (alloca_src->base.child != nullptr && !result_loc->written) {
1660616526 alloca_src->base.child->ref_count = 0;
1660716527 }
1660816528 alloca_src->base.child = alloca_gen;
......@@ -16617,6 +16537,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1661716537 return result_loc->resolved_loc;
1661816538 }
1661916539 case ResultLocIdReturn: {
16540 if (value != nullptr) {
16541 reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true;
16542 ira->src_implicit_return_type_list.append(value);
16543 }
1662016544 if (!non_null_comptime) {
1662116545 bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime;
1662216546 if (is_comptime)
......@@ -16659,10 +16583,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1665916583 return result_loc->resolved_loc;
1666016584 }
1666116585
16662 bool is_comptime;
16663 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_comptime))
16586 bool is_condition_comptime;
16587 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))
1666416588 return ira->codegen->invalid_instruction;
16665 if (is_comptime) {
16589 if (is_condition_comptime) {
1666616590 peer_parent->skipped = true;
1666716591 if (non_null_comptime) {
1666816592 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
......@@ -16674,13 +16598,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1667416598 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
1667516599 return ira->codegen->invalid_instruction;
1667616600 if (peer_parent_has_type) {
16677 if (peer_parent->parent->id == ResultLocIdReturn && value != nullptr) {
16678 reinterpret_cast<ResultLocReturn *>(peer_parent->parent)->implicit_return_type_done = true;
16679 ira->src_implicit_return_type_list.append(value);
16680 }
1668116601 peer_parent->skipped = true;
16682 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
16683 value_type, value, force_runtime || !is_comptime, true, true);
16602 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
16603 value_type, value, force_runtime || !is_condition_comptime, true, true);
16604 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
16605 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
16606 {
16607 return parent_result_loc;
16608 }
16609 peer_parent->parent->written = true;
16610 result_loc->written = true;
16611 result_loc->resolved_loc = parent_result_loc;
16612 return result_loc->resolved_loc;
1668416613 }
1668516614
1668616615 if (peer_parent->resolved_type == nullptr) {
......@@ -16702,14 +16631,14 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1670216631 {
1670316632 return parent_result_loc;
1670416633 }
16705 // because is_comptime is false, we mark this a runtime pointer
16634 // because is_condition_comptime is false, we mark this a runtime pointer
1670616635 parent_result_loc->value->special = ConstValSpecialRuntime;
1670716636 result_loc->written = true;
1670816637 result_loc->resolved_loc = parent_result_loc;
1670916638 return result_loc->resolved_loc;
1671016639 }
1671116640 case ResultLocIdCast: {
16712 if (value != nullptr && value->value->special != ConstValSpecialRuntime)
16641 if (value != nullptr && value->value->special != ConstValSpecialRuntime && !non_null_comptime)
1671316642 return nullptr;
1671416643 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
1671516644 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
......@@ -16721,30 +16650,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1672116650 force_runtime, non_null_comptime);
1672216651 }
1672316652
16724 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type,
16725 result_cast->base.source_instruction->source_node, false);
16726 if (const_cast_result.id == ConstCastResultIdInvalid)
16727 return ira->codegen->invalid_instruction;
16728 if (const_cast_result.id != ConstCastResultIdOk) {
16729 // We will not be able to provide a result location for this value. Create
16730 // a new result location.
16731 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
16732 force_runtime, non_null_comptime);
16733 }
16734
16735 // In this case we can pointer cast the result location.
1673616653 IrInstruction *casted_value;
1673716654 if (value != nullptr) {
1673816655 casted_value = ir_implicit_cast(ira, value, dest_type);
16656 if (type_is_invalid(casted_value->value->type))
16657 return ira->codegen->invalid_instruction;
16658 dest_type = casted_value->value->type;
1673916659 } else {
1674016660 casted_value = nullptr;
1674116661 }
1674216662
16743 if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) {
16744 return casted_value;
16745 }
16746
16747 bool old_parent_result_loc_written = result_cast->parent->written;
1674816663 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
1674916664 dest_type, casted_value, force_runtime, non_null_comptime, true);
1675016665 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
......@@ -16752,8 +16667,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1675216667 {
1675316668 return parent_result_loc;
1675416669 }
16670
1675516671 ZigType *parent_ptr_type = parent_result_loc->value->type;
1675616672 assert(parent_ptr_type->id == ZigTypeIdPointer);
16673
1675716674 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
1675816675 ResolveStatusAlignmentKnown)))
1675916676 {
......@@ -16782,20 +16699,20 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1678216699 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
1678316700 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1678416701
16785 {
16786 // we also need to check that this cast is OK.
16787 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16788 parent_result_loc->value->type, ptr_type,
16789 result_cast->base.source_instruction->source_node, false);
16790 if (const_cast_result.id == ConstCastResultIdInvalid)
16791 return ira->codegen->invalid_instruction;
16792 if (const_cast_result.id != ConstCastResultIdOk) {
16793 // We will not be able to provide a result location for this value. Create
16794 // a new result location.
16795 result_cast->parent->written = old_parent_result_loc_written;
16796 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
16797 force_runtime, non_null_comptime);
16702 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16703 parent_result_loc->value->type, ptr_type,
16704 result_cast->base.source_instruction->source_node, false);
16705 if (const_cast_result.id == ConstCastResultIdInvalid)
16706 return ira->codegen->invalid_instruction;
16707 if (const_cast_result.id != ConstCastResultIdOk) {
16708 if (allow_discard) {
16709 return parent_result_loc;
1679816710 }
16711 // We will not be able to provide a result location for this value. Create
16712 // a new result location.
16713 result_cast->parent->written = false;
16714 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
16715 force_runtime, non_null_comptime);
1679916716 }
1680016717
1680116718 result_loc->written = true;
......@@ -16836,6 +16753,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1683616753 IrInstruction *bitcasted_value;
1683716754 if (value != nullptr) {
1683816755 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type);
16756 dest_type = bitcasted_value->value->type;
1683916757 } else {
1684016758 bitcasted_value = nullptr;
1684116759 }
......@@ -16887,7 +16805,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1688716805 result_loc_pass1 = no_result_loc();
1688816806 }
1688916807 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
16890 value, force_runtime, non_null_comptime);
16808 value, force_runtime, non_null_comptime, allow_discard);
1689116809 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
1689216810 return result_loc;
1689316811
......@@ -16900,11 +16818,13 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1690016818 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
1690116819 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
1690216820 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
16903 value_type->id != ZigTypeIdNull)
16821 value_type->id != ZigTypeIdNull && type_has_bits(value_type))
1690416822 {
1690516823 result_loc_pass1->written = false;
1690616824 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
16907 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {
16825 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion &&
16826 type_has_bits(value_type))
16827 {
1690816828 if (value_type->id == ZigTypeIdErrorSet) {
1690916829 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
1691016830 } else {
......@@ -16918,9 +16838,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
1691816838 return unwrapped_err_ptr;
1691916839 }
1692016840 }
16921 } else if (is_slice(actual_elem_type) && value_type->id == ZigTypeIdArray) {
16922 // need to allow EndExpr to do the implicit cast from array to slice
16923 result_loc_pass1->written = false;
1692416841 }
1692516842 return result_loc;
1692616843}
......@@ -17159,7 +17076,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1715917076 arg_val = create_const_runtime(casted_arg->value->type);
1716017077 }
1716117078 if (arg_part_of_generic_id) {
17162 copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true);
17079 copy_const_val(&generic_id->params[generic_id->param_count], arg_val);
1716317080 generic_id->param_count += 1;
1716417081 }
1716517082
......@@ -17340,7 +17257,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1734017257 IrInstruction *casted_ptr;
1734117258 if (instr_is_comptime(ptr)) {
1734217259 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);
17343 copy_const_val(casted_ptr->value, ptr->value, false);
17260 copy_const_val(casted_ptr->value, ptr->value);
1734417261 casted_ptr->value->type = struct_ptr_type;
1734517262 } else {
1734617263 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,
......@@ -17403,14 +17320,8 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1740317320 if (dest_val == nullptr)
1740417321 return ira->codegen->invalid_instruction;
1740517322 if (dest_val->special != ConstValSpecialRuntime) {
17406 // TODO this allows a value stored to have the original value modified and then
17407 // have that affect what should be a copy. We need some kind of advanced copy-on-write
17408 // system to make these two tests pass at the same time:
17409 // * "string literal used as comptime slice is memoized"
17410 // * "comptime modification of const struct field" - except modified to avoid
17411 // ConstPtrMutComptimeVar, thus defeating the logic below.
17412 bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar;
17413 copy_const_val(dest_val, value->value, same_global_refs);
17323 copy_const_val(dest_val, value->value);
17324
1741417325 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
1741517326 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
1741617327 {
......@@ -17684,9 +17595,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1768417595 }
1768517596 }
1768617597
17687 IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type);
17688 copy_const_val(new_instruction->value, result, true);
17689 new_instruction->value->type = return_type;
17598 IrInstruction *new_instruction = ir_const_move(ira, &call_instruction->base, result);
1769017599 return ir_finish_anal(ira, new_instruction);
1769117600 }
1769217601
......@@ -17842,7 +17751,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1784217751 nullptr, UndefBad);
1784317752 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
1784417753 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
17845 copy_const_val(const_instruction->base.value, align_result, true);
17754 copy_const_val(const_instruction->base.value, align_result);
1784617755
1784717756 uint32_t align_bytes = 0;
1784817757 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
......@@ -18172,7 +18081,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1817218081
1817318082 if (dst_size <= src_size) {
1817418083 if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) {
18175 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut != ConstPtrMutComptimeVar);
18084 copy_const_val(out_val, pointee);
1817618085 return ErrorNone;
1817718086 }
1817818087 Buf buf = BUF_INIT;
......@@ -18535,7 +18444,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1853518444
1853618445 if (value->value->special != ConstValSpecialRuntime) {
1853718446 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);
18538 copy_const_val(result->value, value->value, true);
18447 copy_const_val(result->value, value->value);
1853918448 return result;
1854018449 } else {
1854118450 return value;
......@@ -18928,7 +18837,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1892818837 if (index == array_len && array_type->data.array.sentinel != nullptr) {
1892918838 ZigType *elem_type = array_type->data.array.child_type;
1893018839 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);
18931 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false);
18840 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
1893218841 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
1893318842 }
1893418843 if (index >= array_len) {
......@@ -19007,7 +18916,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1900718916 return ira->codegen->invalid_instruction;
1900818917 if (actual_array_type->id != ZigTypeIdArray) {
1900918918 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
19010 buf_sprintf("expected array type or [_], found slice"));
18919 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
18920 buf_ptr(&actual_array_type->name)));
1901118921 return ira->codegen->invalid_instruction;
1901218922 }
1901318923
......@@ -19419,7 +19329,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
1941919329
1942019330 if (instr_is_comptime(container_ptr)) {
1942119331 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);
19422 copy_const_val(result->value, container_ptr->value, false);
19332 copy_const_val(result->value, container_ptr->value);
1942319333 result->value->type = field_ptr_type;
1942419334 return result;
1942519335 }
......@@ -20851,7 +20761,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2085120761 case ZigTypeIdErrorSet: {
2085220762 if (pointee_val) {
2085320763 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);
20854 copy_const_val(result->value, pointee_val, true);
20764 copy_const_val(result->value, pointee_val);
2085520765 result->value->type = target_type;
2085620766 return result;
2085720767 }
......@@ -21347,7 +21257,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
2134721257 return ira->codegen->invalid_instruction;
2134821258
2134921259 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);
21350 copy_const_val(runtime_inst->value, field->init_val, true);
21260 copy_const_val(runtime_inst->value, field->init_val);
2135121261
2135221262 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
2135321263 container_type, true);
......@@ -21399,7 +21309,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2139921309
2140021310 if (is_slice(container_type)) {
2140121311 ir_add_error_node(ira, instruction->init_array_type_source_node,
21402 buf_sprintf("expected array type or [_], found slice"));
21312 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
21313 buf_ptr(&container_type->name)));
2140321314 return ira->codegen->invalid_instruction;
2140421315 }
2140521316
......@@ -21435,6 +21346,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2143521346 {
2143621347 // We're now done inferring the type.
2143721348 container_type->data.structure.resolve_status = ResolveStatusUnstarted;
21349 } else if (container_type->id == ZigTypeIdVector) {
21350 // OK
2143821351 } else {
2143921352 ir_add_error_node(ira, instruction->base.source_node,
2144021353 buf_sprintf("type '%s' does not support array initialization",
......@@ -21605,7 +21518,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2160521518 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2160621519 }
2160721520 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
21608 copy_const_val(result->value, err->cached_error_name_val, true);
21521 copy_const_val(result->value, err->cached_error_name_val);
2160921522 result->value->type = str_type;
2161021523 return result;
2161121524 }
......@@ -22828,17 +22741,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2282822741 return result;
2282922742}
2283022743
22831static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22744static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
22745 const char *name, size_t field_index)
2283222746{
22747 Error err;
2283322748 ensure_field_index(struct_value->type, name, field_index);
22834 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
22835 return struct_value->data.x_struct.fields[field_index];
22749 ZigValue *val = struct_value->data.x_struct.fields[field_index];
22750 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, val, UndefBad)))
22751 return nullptr;
22752 return val;
2283622753}
2283722754
2283822755static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
2283922756 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
2284022757{
22841 ZigValue *field_val = get_const_field(ira, struct_value, name, field_index);
22758 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
22759 if (field_val == nullptr)
22760 return ErrorSemanticAnalyzeFail;
2284222761 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
2284322762 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
2284422763 get_optional_type(ira->codegen, elem_type));
......@@ -22849,23 +22768,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
2284922768 return ErrorNone;
2285022769}
2285122770
22852static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22771static Error get_const_field_bool(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
22772 const char *name, size_t field_index, bool *out)
2285322773{
22854 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22774 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
22775 if (value == nullptr)
22776 return ErrorSemanticAnalyzeFail;
2285522777 assert(value->type == ira->codegen->builtin_types.entry_bool);
22856 return value->data.x_bool;
22778 *out = value->data.x_bool;
22779 return ErrorNone;
2285722780}
2285822781
22859static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22782static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
2286022783{
22861 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22784 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
22785 if (value == nullptr)
22786 return nullptr;
2286222787 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
2286322788 return &value->data.x_bigint;
2286422789}
2286522790
22866static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
22791static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
2286722792{
22868 ZigValue *value = get_const_field(ira, struct_value, name, field_index);
22793 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
22794 if (value == nullptr)
22795 return ira->codegen->invalid_instruction->value->type;
2286922796 assert(value->type == ira->codegen->builtin_types.entry_type);
2287022797 return value->data.x_type;
2287122798}
......@@ -22883,17 +22810,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2288322810 return ira->codegen->builtin_types.entry_bool;
2288422811 case ZigTypeIdUnreachable:
2288522812 return ira->codegen->builtin_types.entry_unreachable;
22886 case ZigTypeIdInt:
22813 case ZigTypeIdInt: {
2288722814 assert(payload->special == ConstValSpecialStatic);
2288822815 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
22889 return get_int_type(ira->codegen,
22890 get_const_field_bool(ira, payload, "is_signed", 0),
22891 bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1)));
22816 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
22817 if (bi == nullptr)
22818 return ira->codegen->invalid_instruction->value->type;
22819 bool is_signed;
22820 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))
22821 return ira->codegen->invalid_instruction->value->type;
22822 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
22823 }
2289222824 case ZigTypeIdFloat:
2289322825 {
2289422826 assert(payload->special == ConstValSpecialStatic);
2289522827 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
22896 uint32_t bits = bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 0));
22828 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0);
22829 if (bi == nullptr)
22830 return ira->codegen->invalid_instruction->value->type;
22831 uint32_t bits = bigint_as_u32(bi);
2289722832 switch (bits) {
2289822833 case 16: return ira->codegen->builtin_types.entry_f16;
2289922834 case 32: return ira->codegen->builtin_types.entry_f32;
......@@ -22902,34 +22837,58 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2290222837 }
2290322838 ir_add_error(ira, instruction,
2290422839 buf_sprintf("%d-bit float unsupported", bits));
22905 return nullptr;
22840 return ira->codegen->invalid_instruction->value->type;
2290622841 }
2290722842 case ZigTypeIdPointer:
2290822843 {
2290922844 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2291022845 assert(payload->special == ConstValSpecialStatic);
2291122846 assert(payload->type == type_info_pointer_type);
22912 ZigValue *size_value = get_const_field(ira, payload, "size", 0);
22847 ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0);
2291322848 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
2291422849 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
2291522850 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
22916 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);
22851 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4);
22852 if (type_is_invalid(elem_type))
22853 return ira->codegen->invalid_instruction->value->type;
2291722854 ZigValue *sentinel;
2291822855 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
2291922856 elem_type, &sentinel)))
2292022857 {
22921 return nullptr;
22858 return ira->codegen->invalid_instruction->value->type;
22859 }
22860 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3);
22861 if (bi == nullptr)
22862 return ira->codegen->invalid_instruction->value->type;
22863
22864 bool is_const;
22865 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))
22866 return ira->codegen->invalid_instruction->value->type;
22867
22868 bool is_volatile;
22869 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2,
22870 &is_volatile)))
22871 {
22872 return ira->codegen->invalid_instruction->value->type;
2292222873 }
2292322874
22875 bool is_allowzero;
22876 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5,
22877 &is_allowzero)))
22878 {
22879 return ira->codegen->invalid_instruction->value->type;
22880 }
22881
22882
2292422883 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
2292522884 elem_type,
22926 get_const_field_bool(ira, payload, "is_const", 1),
22927 get_const_field_bool(ira, payload, "is_volatile", 2),
22885 is_const,
22886 is_volatile,
2292822887 ptr_len,
22929 bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)),
22888 bigint_as_u32(bi),
2293022889 0, // bit_offset_in_host
2293122890 0, // host_int_bytes
22932 get_const_field_bool(ira, payload, "is_allowzero", 5),
22891 is_allowzero,
2293322892 VECTOR_INDEX_NONE, nullptr, sentinel);
2293422893 if (size_enum_index != 2)
2293522894 return ptr_type;
......@@ -22938,17 +22897,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2293822897 case ZigTypeIdArray: {
2293922898 assert(payload->special == ConstValSpecialStatic);
2294022899 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
22941 ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);
22900 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1);
22901 if (type_is_invalid(elem_type))
22902 return ira->codegen->invalid_instruction->value->type;
2294222903 ZigValue *sentinel;
2294322904 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
2294422905 elem_type, &sentinel)))
2294522906 {
22946 return nullptr;
22907 return ira->codegen->invalid_instruction->value->type;
2294722908 }
22948 return get_array_type(ira->codegen,
22949 elem_type,
22950 bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)),
22951 sentinel);
22909 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
22910 if (bi == nullptr)
22911 return ira->codegen->invalid_instruction->value->type;
22912 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
2295222913 }
2295322914 case ZigTypeIdComptimeFloat:
2295422915 return ira->codegen->builtin_types.entry_num_lit_float;
......@@ -22969,7 +22930,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2296922930 case ZigTypeIdEnumLiteral:
2297022931 ir_add_error(ira, instruction, buf_sprintf(
2297122932 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
22972 return nullptr;
22933 return ira->codegen->invalid_instruction->value->type;
2297322934 case ZigTypeIdUnion:
2297422935 case ZigTypeIdFn:
2297522936 case ZigTypeIdBoundFn:
......@@ -22977,7 +22938,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2297722938 case ZigTypeIdStruct:
2297822939 ir_add_error(ira, instruction, buf_sprintf(
2297922940 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
22980 return nullptr;
22941 return ira->codegen->invalid_instruction->value->type;
2298122942 }
2298222943 zig_unreachable();
2298322944}
......@@ -22996,7 +22957,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
2299622957 return ira->codegen->invalid_instruction;
2299722958 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
2299822959 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);
22999 if (!type)
22960 if (type_is_invalid(type))
2300022961 return ira->codegen->invalid_instruction;
2300122962 return ir_const_type(ira, &instruction->base, type);
2300222963}
......@@ -23042,7 +23003,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
2304223003 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2304323004 }
2304423005 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);
23045 copy_const_val(result->value, type_entry->cached_const_name_val, true);
23006 copy_const_val(result->value, type_entry->cached_const_name_val);
2304623007 return result;
2304723008}
2304823009
......@@ -23684,7 +23645,13 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2368423645 return result_loc;
2368523646 }
2368623647
23687 if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
23648 if (target->value->type->id == ZigTypeIdPointer &&
23649 target->value->type->data.pointer.ptr_len == PtrLenSingle &&
23650 target->value->type->data.pointer.child_type->id == ZigTypeIdArray)
23651 {
23652 known_len = target->value->type->data.pointer.child_type->data.array.len;
23653 have_known_len = true;
23654 } else if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) {
2368823655 known_len = casted_value->value->data.rh_slice.len;
2368923656 have_known_len = true;
2369023657 }
......@@ -23742,7 +23709,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2374223709
2374323710 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
2374423711 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
23745 copy_const_val(ptr_val, target_ptr_val, false);
23712 copy_const_val(ptr_val, target_ptr_val);
2374623713 ptr_val->type = dest_ptr_type;
2374723714
2374823715 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
......@@ -24035,7 +24002,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
2403524002 ZigValue *src_elem_val = (v >= 0) ?
2403624003 &a->value->data.x_array.data.s_none.elements[v] :
2403724004 &b->value->data.x_array.data.s_none.elements[~v];
24038 copy_const_val(result_elem_val, src_elem_val, false);
24005 copy_const_val(result_elem_val, src_elem_val);
2403924006
2404024007 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
2404124008 }
......@@ -24130,7 +24097,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
2413024097 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
2413124098 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
2413224099 for (uint32_t i = 0; i < len_int; i += 1) {
24133 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false);
24100 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
2413424101 }
2413524102 return result;
2413624103 }
......@@ -24271,7 +24238,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
2427124238 }
2427224239
2427324240 for (size_t i = start; i < end; i += 1) {
24274 copy_const_val(&dest_elements[i], byte_val, true);
24241 copy_const_val(&dest_elements[i], byte_val);
2427524242 }
2427624243
2427724244 return ir_const_void(ira, &instruction->base);
......@@ -24450,7 +24417,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
2445024417 // TODO check for noalias violations - this should be generalized to work for any function
2445124418
2445224419 for (size_t i = 0; i < count; i += 1) {
24453 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i], true);
24420 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
2445424421 }
2445524422
2445624423 return ir_const_void(ira, &instruction->base);
......@@ -25892,7 +25859,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
2589225859 }
2589325860
2589425861 IrInstruction *result = ir_const(ira, target, result_type);
25895 copy_const_val(result->value, val, true);
25862 copy_const_val(result->value, val);
2589625863 result->value->type = result_type;
2589725864 return result;
2589825865 }
......@@ -25974,7 +25941,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2597425941 } else {
2597525942 result = ir_const(ira, source_instr, dest_type);
2597625943 }
25977 copy_const_val(result->value, val, true);
25944 copy_const_val(result->value, val);
2597825945 result->value->type = dest_type;
2597925946
2598025947 // Keep the bigger alignment, it can only help-
......@@ -27474,10 +27441,6 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns
2747427441 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
2747527442 return result_loc;
2747627443
27477 if (instruction->result_loc_cast->parent->gen_instruction != nullptr) {
27478 return instruction->result_loc_cast->parent->gen_instruction;
27479 }
27480
2748127444 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
2748227445 if (type_is_invalid(dest_type))
2748327446 return ira->codegen->invalid_instruction;
......@@ -28060,7 +28023,24 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2806028023 }
2806128024
2806228025 if (ira->codegen->verbose_ir) {
28063 fprintf(stderr, "analyze #%" PRIu32 "\n", old_instruction->debug_id);
28026 fprintf(stderr, "~ ");
28027 old_instruction->src();
28028 fprintf(stderr, "~ ");
28029 ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc);
28030 bool want_break = false;
28031 if (ira->break_debug_id == old_instruction->debug_id) {
28032 want_break = true;
28033 } else if (old_instruction->source_node != nullptr) {
28034 for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) {
28035 if (dbg_ir_breakpoints_buf[i].line == old_instruction->source_node->line + 1 &&
28036 buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path,
28037 dbg_ir_breakpoints_buf[i].src_file))
28038 {
28039 want_break = true;
28040 }
28041 }
28042 }
28043 if (want_break) BREAKPOINT;
2806428044 }
2806528045 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
2806628046 if (new_instruction != nullptr) {
......@@ -28068,6 +28048,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2806828048 old_instruction->child = new_instruction;
2806928049
2807028050 if (type_is_invalid(new_instruction->value->type)) {
28051 if (ira->codegen->verbose_ir) {
28052 fprintf(stderr, "-> (invalid)");
28053 }
28054
2807128055 if (new_exec->first_err_trace_msg != nullptr) {
2807228056 ira->codegen->trace_err = new_exec->first_err_trace_msg;
2807328057 } else {
......@@ -28081,11 +28065,22 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
2808128065 old_instruction->source_node, buf_create_from_str("referenced here"));
2808228066 }
2808328067 return ira->codegen->builtin_types.entry_invalid;
28068 } else if (ira->codegen->verbose_ir) {
28069 fprintf(stderr, "-> ");
28070 if (instr_is_unreachable(new_instruction)) {
28071 fprintf(stderr, "(noreturn)\n");
28072 } else {
28073 ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen);
28074 }
2808428075 }
2808528076
2808628077 // unreachable instructions do their own control flow.
2808728078 if (new_instruction->value->type->id == ZigTypeIdUnreachable)
2808828079 continue;
28080 } else {
28081 if (ira->codegen->verbose_ir) {
28082 fprintf(stderr, "-> (null");
28083 }
2808928084 }
2809028085
2809128086 ira->instruction_index += 1;
......@@ -28748,3 +28743,43 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
2874828743 }
2874928744 return ErrorNone;
2875028745}
28746
28747void IrInstruction::src() {
28748 IrInstruction *inst = this;
28749 if (inst->source_node != nullptr) {
28750 inst->source_node->src();
28751 } else {
28752 fprintf(stderr, "(null source node)\n");
28753 }
28754}
28755
28756void IrInstruction::dump() {
28757 IrInstruction *inst = this;
28758 inst->src();
28759 IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;
28760 if (inst->scope == nullptr) {
28761 fprintf(stderr, "(null scope)\n");
28762 } else {
28763 ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);
28764 if (pass == IrPassSrc) {
28765 fprintf(stderr, "-> ");
28766 ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);
28767 }
28768 }
28769}
28770
28771void IrAnalyze::dump() {
28772 ir_print(this->codegen, stderr, this->new_irb.exec, 0, IrPassGen);
28773 if (this->new_irb.current_basic_block != nullptr) {
28774 fprintf(stderr, "Current basic block:\n");
28775 ir_print_basic_block(this->codegen, stderr, this->new_irb.current_basic_block, 1, IrPassGen);
28776 }
28777}
28778
28779void dbg_ir_break(const char *src_file, uint32_t line) {
28780 dbg_ir_breakpoints_buf[dbg_ir_breakpoints_count] = {src_file, line};
28781 dbg_ir_breakpoints_count += 1;
28782}
28783void dbg_ir_clear(void) {
28784 dbg_ir_breakpoints_count = 0;
28785}
src/ir.hpp+4
......@@ -35,4 +35,8 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
3535 AstNode *source_node);
3636const char *float_op_to_name(BuiltinFnId op, bool llvm_name);
3737
38// for debugging purposes
39void dbg_ir_break(const char *src_file, uint32_t line);
40void dbg_ir_clear(void);
41
3842#endif
src/ir_print.cpp+32-12
......@@ -2530,6 +2530,37 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
25302530 fprintf(irp->f, "\n");
25312531}
25322532
2533static void irp_print_basic_block(IrPrint *irp, IrBasicBlock *current_block) {
2534 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
2535 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
2536 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2537 if (irp->pass != IrPassSrc) {
2538 irp->printed.put(instruction, 0);
2539 irp->pending.clear();
2540 }
2541 ir_print_instruction(irp, instruction, false);
2542 for (size_t j = 0; j < irp->pending.length; ++j)
2543 ir_print_instruction(irp, irp->pending.at(j), true);
2544 }
2545}
2546
2547void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass) {
2548 IrPrint ir_print = {};
2549 ir_print.pass = pass;
2550 ir_print.codegen = codegen;
2551 ir_print.f = f;
2552 ir_print.indent = indent_size;
2553 ir_print.indent_size = indent_size;
2554 ir_print.printed = {};
2555 ir_print.printed.init(64);
2556 ir_print.pending = {};
2557
2558 irp_print_basic_block(&ir_print, bb);
2559
2560 ir_print.pending.deinit();
2561 ir_print.printed.deinit();
2562}
2563
25332564void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {
25342565 IrPrint ir_print = {};
25352566 IrPrint *irp = &ir_print;
......@@ -2543,18 +2574,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
25432574 irp->pending = {};
25442575
25452576 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
2546 IrBasicBlock *current_block = executable->basic_block_list.at(bb_i);
2547 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
2548 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
2549 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2550 if (irp->pass != IrPassSrc) {
2551 irp->printed.put(instruction, 0);
2552 irp->pending.clear();
2553 }
2554 ir_print_instruction(irp, instruction, false);
2555 for (size_t j = 0; j < irp->pending.length; ++j)
2556 ir_print_instruction(irp, irp->pending.at(j), true);
2557 }
2577 irp_print_basic_block(irp, executable->basic_block_list.at(bb_i));
25582578 }
25592579
25602580 irp->pending.deinit();
src/ir_print.hpp+1
......@@ -15,6 +15,7 @@
1515void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
1616void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
1717void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);
18void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass);
1819
1920const char* ir_instruction_type_str(IrInstructionId id);
2021
src/util.hpp+6-2
......@@ -26,20 +26,24 @@
2626#define ATTRIBUTE_NORETURN __declspec(noreturn)
2727#define ATTRIBUTE_MUST_USE
2828
29#define BREAKPOINT __debugbreak()
30
2931#else
3032
33#include <signal.h>
34
3135#define ATTRIBUTE_COLD __attribute__((cold))
3236#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
3337#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
3438#define ATTRIBUTE_NORETURN __attribute__((noreturn))
3539#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
3640
41#define BREAKPOINT raise(SIGTRAP)
42
3743#endif
3844
3945#include "softfloat.hpp"
4046
41#define BREAKPOINT __asm("int $0x03")
42
4347ATTRIBUTE_COLD
4448ATTRIBUTE_NORETURN
4549ATTRIBUTE_PRINTF(1, 2)
test/cli.zig+13-13
......@@ -26,9 +26,9 @@ pub fn main() !void {
2626 std.debug.warn("Expected second argument to be cache root directory path\n");
2727 return error.InvalidArgs;
2828 });
29 const zig_exe = try fs.path.resolve(a, [_][]const u8{zig_exe_rel});
29 const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
3030
31 const dir_path = try fs.path.join(a, [_][]const u8{ cache_root, "clitest" });
31 const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" });
3232 const TestFn = fn ([]const u8, []const u8) anyerror!void;
3333 const test_fns = [_]TestFn{
3434 testZigInitLib,
......@@ -85,22 +85,22 @@ fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
8585}
8686
8787fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
88 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-lib" });
89 const test_result = try exec(dir_path, [_][]const u8{ zig_exe, "build", "test" });
88 _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-lib" });
89 const test_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "test" });
9090 testing.expect(std.mem.endsWith(u8, test_result.stderr, "All 1 tests passed.\n"));
9191}
9292
9393fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
94 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-exe" });
95 const run_result = try exec(dir_path, [_][]const u8{ zig_exe, "build", "run" });
94 _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" });
95 const run_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "run" });
9696 testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));
9797}
9898
9999fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
100100 if (builtin.os != .linux or builtin.arch != .x86_64) return;
101101
102 const example_zig_path = try fs.path.join(a, [_][]const u8{ dir_path, "example.zig" });
103 const example_s_path = try fs.path.join(a, [_][]const u8{ dir_path, "example.s" });
102 const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" });
103 const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });
104104
105105 try std.io.writeFile(example_zig_path,
106106 \\// Type your code here, or load an example.
......@@ -123,7 +123,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
123123 "--strip", "--release-fast",
124124 example_zig_path, "--disable-gen-h",
125125 };
126 _ = try exec(dir_path, args);
126 _ = try exec(dir_path, &args);
127127
128128 const out_asm = try std.io.readFileAlloc(a, example_s_path);
129129 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
......@@ -132,10 +132,10 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
132132}
133133
134134fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
135 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-exe" });
136 const output_path = try fs.path.join(a, [_][]const u8{ "does", "not", "exist" });
137 const source_path = try fs.path.join(a, [_][]const u8{ "src", "main.zig" });
138 _ = try exec(dir_path, [_][]const u8{
135 _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" });
136 const output_path = try fs.path.join(a, &[_][]const u8{ "does", "not", "exist" });
137 const source_path = try fs.path.join(a, &[_][]const u8{ "src", "main.zig" });
138 _ = try exec(dir_path, &[_][]const u8{
139139 zig_exe, "build-exe", source_path, "--output-dir", output_path,
140140 });
141141}
test/compare_output.zig+2-2
......@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
465465 \\
466466 );
467467
468 tc.setCommandLineArgs([_][]const u8{
468 tc.setCommandLineArgs(&[_][]const u8{
469469 "first arg",
470470 "'a' 'b' \\",
471471 "bare",
......@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
506506 \\
507507 );
508508
509 tc.setCommandLineArgs([_][]const u8{
509 tc.setCommandLineArgs(&[_][]const u8{
510510 "first arg",
511511 "'a' 'b' \\",
512512 "bare",
test/compile_errors.zig+16-15
......@@ -20,6 +20,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2020 break :x tc;
2121 });
2222
23 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
24 // going to stop me from merging this branch which fixes a bunch of other stuff.
2325 cases.add(
2426 "incompatible sentinels",
2527 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
......@@ -40,8 +42,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4042 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
4143 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",
4244
43 "tmp.zig:8:35: error: expected type '[2:0]u8', found '[2:255]u8'",
44 "tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel",
45 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
46 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
4547 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
4648 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
4749 );
......@@ -179,7 +181,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
179181 \\ var geo_data = getGeo3DTex2D();
180182 \\}
181183 ,
182 "tmp.zig:4:30: error: expected type '[][2]f32', found '[1][2]f32'",
184 "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'",
183185 );
184186
185187 cases.add(
......@@ -776,7 +778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
776778 \\ const x = []u8{1, 2};
777779 \\}
778780 ,
779 "tmp.zig:2:15: error: expected array type or [_], found slice",
781 "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'",
780782 );
781783
782784 cases.add(
......@@ -785,7 +787,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
785787 \\ const x = []u8{};
786788 \\}
787789 ,
788 "tmp.zig:2:15: error: expected array type or [_], found slice",
790 "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'",
789791 );
790792
791793 cases.add(
......@@ -2284,8 +2286,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22842286 \\
22852287 \\fn bar(x: *b.Foo) void {}
22862288 ,
2287 "tmp.zig:6:9: error: expected type '*b.Foo', found '*a.Foo'",
2288 "tmp.zig:6:9: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
2289 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
2290 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
22892291 "a.zig:1:17: note: a.Foo declared here",
22902292 "b.zig:1:17: note: b.Foo declared here",
22912293 );
......@@ -4810,10 +4812,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48104812 "convert fixed size array to slice with invalid size",
48114813 \\export fn f() void {
48124814 \\ var array: [5]u8 = undefined;
4813 \\ var foo = @bytesToSlice(u32, array)[0];
4815 \\ var foo = @bytesToSlice(u32, &array)[0];
48144816 \\}
48154817 ,
4816 "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) const u32: size mismatch",
4818 "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch",
48174819 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",
48184820 );
48194821
......@@ -5150,7 +5152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
51505152 \\
51515153 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
51525154 ,
5153 "tmp.zig:8:16: error: expected type '*const u3', found '*align(:3:1) const u3'",
5155 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
51545156 );
51555157
51565158 cases.add(
......@@ -5847,7 +5849,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58475849 \\ x.* += 1;
58485850 \\}
58495851 ,
5850 "tmp.zig:8:9: error: expected type '*u32', found '*align(1) u32'",
5852 "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
58515853 );
58525854
58535855 cases.add(
......@@ -5867,9 +5869,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58675869 \\ x[0] += 1;
58685870 \\}
58695871 ,
5870 "tmp.zig:9:9: error: cast increases pointer alignment",
5872 "tmp.zig:9:26: error: cast increases pointer alignment",
58715873 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
5872 "tmp.zig:9:9: note: '*[1]u32' has alignment 4",
5874 "tmp.zig:9:26: note: '*[1]u32' has alignment 4",
58735875 );
58745876
58755877 cases.add(
......@@ -6917,7 +6919,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69176919 \\ var foo: u32 = @This(){};
69186920 \\}
69196921 ,
6920 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",
6921 "tmp.zig:1:1: note: (root) declared here",
6922 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
69226923 );
69236924}
test/runtime_safety.zig+2-2
......@@ -261,7 +261,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
261261 \\}
262262 \\pub fn main() void {
263263 \\ const a = [_]i32{1, 2, 3, 4};
264 \\ baz(bar(a));
264 \\ baz(bar(&a));
265265 \\}
266266 \\fn bar(a: []const i32) i32 {
267267 \\ return a[4];
......@@ -471,7 +471,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
471471 \\ @import("std").os.exit(126);
472472 \\}
473473 \\pub fn main() !void {
474 \\ const x = widenSlice([_]u8{1, 2, 3, 4, 5});
474 \\ const x = widenSlice(&[_]u8{1, 2, 3, 4, 5});
475475 \\ if (x.len == 0) return error.Whatever;
476476 \\}
477477 \\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 {
test/stage1/behavior/array.zig+22-22
......@@ -20,7 +20,7 @@ test "arrays" {
2020 }
2121
2222 expect(accumulator == 15);
23 expect(getArrayLen(array) == 5);
23 expect(getArrayLen(&array) == 5);
2424}
2525fn getArrayLen(a: []const u32) usize {
2626 return a.len;
......@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {
182182
183183test "runtime initialize array elem and then implicit cast to slice" {
184184 var two: i32 = 2;
185 const x: []const i32 = [_]i32{two};
185 const x: []const i32 = &[_]i32{two};
186186 expect(x[0] == 2);
187187}
188188
189189test "array literal as argument to function" {
190190 const S = struct {
191191 fn entry(two: i32) void {
192 foo([_]i32{
192 foo(&[_]i32{
193193 1,
194194 2,
195195 3,
196196 });
197 foo([_]i32{
197 foo(&[_]i32{
198198 1,
199199 two,
200200 3,
201201 });
202 foo2(true, [_]i32{
202 foo2(true, &[_]i32{
203203 1,
204204 2,
205205 3,
206206 });
207 foo2(true, [_]i32{
207 foo2(true, &[_]i32{
208208 1,
209209 two,
210210 3,
......@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {
230230 const S = struct {
231231 fn entry(two: i32) void {
232232 const cases = [_][]const []const i32{
233 [_][]const i32{[_]i32{1}},
234 [_][]const i32{[_]i32{ 2, 3 }},
235 [_][]const i32{
236 [_]i32{4},
237 [_]i32{ 5, 6, 7 },
233 &[_][]const i32{&[_]i32{1}},
234 &[_][]const i32{&[_]i32{ 2, 3 }},
235 &[_][]const i32{
236 &[_]i32{4},
237 &[_]i32{ 5, 6, 7 },
238238 },
239239 };
240 check(cases);
240 check(&cases);
241241
242242 const cases2 = [_][]const i32{
243 [_]i32{1},
243 &[_]i32{1},
244244 &[_]i32{ two, 3 },
245245 };
246246 expect(cases2.len == 2);
......@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {
251251 expect(cases2[1][1] == 3);
252252
253253 const cases3 = [_][]const []const i32{
254 [_][]const i32{[_]i32{1}},
254 &[_][]const i32{&[_]i32{1}},
255255 &[_][]const i32{&[_]i32{ two, 3 }},
256 [_][]const i32{
257 [_]i32{4},
258 [_]i32{ 5, 6, 7 },
256 &[_][]const i32{
257 &[_]i32{4},
258 &[_]i32{ 5, 6, 7 },
259259 },
260260 };
261 check(cases3);
261 check(&cases3);
262262 }
263263
264264 fn check(cases: []const []const []const i32) void {
......@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {
316316test "anonymous list literal syntax" {
317317 const S = struct {
318318 fn doTheTest() void {
319 var array: [4]u8 = .{1, 2, 3, 4};
319 var array: [4]u8 = .{ 1, 2, 3, 4 };
320320 expect(array[0] == 1);
321321 expect(array[1] == 2);
322322 expect(array[2] == 3);
......@@ -335,8 +335,8 @@ test "anonymous literal in array" {
335335 };
336336 fn doTheTest() void {
337337 var array: [2]Foo = .{
338 .{.a = 3},
339 .{.b = 3},
338 .{ .a = 3 },
339 .{ .b = 3 },
340340 };
341341 expect(array[0].a == 3);
342342 expect(array[0].b == 4);
......@@ -351,7 +351,7 @@ test "anonymous literal in array" {
351351test "access the null element of a null terminated array" {
352352 const S = struct {
353353 fn doTheTest() void {
354 var array: [4:0]u8 = .{'a', 'o', 'e', 'u'};
354 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
355355 comptime expect(array[4] == 0);
356356 var len: usize = 4;
357357 expect(array[len] == 0);
test/stage1/behavior/async_fn.zig+6-6
......@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {
143143 resume frame;
144144 seq('h');
145145
146 expect(std.mem.eql(u8, points, "abcdefgh"));
146 expect(std.mem.eql(u8, &points, "abcdefgh"));
147147 }
148148
149149 fn amain() void {
......@@ -206,7 +206,7 @@ test "coroutine await" {
206206 resume await_a_promise;
207207 await_seq('i');
208208 expect(await_final_result == 1234);
209 expect(std.mem.eql(u8, await_points, "abcdefghi"));
209 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
210210}
211211async fn await_amain() void {
212212 await_seq('b');
......@@ -240,7 +240,7 @@ test "coroutine await early return" {
240240 var p = async early_amain();
241241 early_seq('f');
242242 expect(early_final_result == 1234);
243 expect(std.mem.eql(u8, early_points, "abcdef"));
243 expect(std.mem.eql(u8, &early_points, "abcdef"));
244244}
245245async fn early_amain() void {
246246 early_seq('b');
......@@ -1166,7 +1166,7 @@ test "suspend in for loop" {
11661166 }
11671167
11681168 fn atest() void {
1169 expect(func([_]u8{ 1, 2, 3 }) == 6);
1169 expect(func(&[_]u8{ 1, 2, 3 }) == 6);
11701170 }
11711171 fn func(stuff: []const u8) u32 {
11721172 global_frame = @frame();
......@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {
12111211
12121212 fn doTheTest() void {
12131213 var foo = Foo{
1214 .slice = [_]i32{ 1, 2 },
1214 .slice = &[_]i32{ 1, 2 },
12151215 };
12161216 expect(atest(&foo) == 3);
12171217 }
......@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
12421242
12431243 fn doTheTest() void {
12441244 var foo = Foo{
1245 .slice = [_]i32{ 1, 2 },
1245 .slice = &[_]i32{ 1, 2 },
12461246 };
12471247 expect(atest(&foo) == 3);
12481248 }
test/stage1/behavior/await_struct.zig+1-1
......@@ -16,7 +16,7 @@ test "coroutine await struct" {
1616 resume await_a_promise;
1717 await_seq('i');
1818 expect(await_final_result.x == 1234);
19 expect(std.mem.eql(u8, await_points, "abcdefghi"));
19 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
2020}
2121async fn await_amain() void {
2222 await_seq('b');
test/stage1/behavior/bugs/1607.zig+2-2
......@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {
1010}
1111
1212test "slices pointing at the same address as global array." {
13 checkAddress(a);
14 comptime checkAddress(a);
13 checkAddress(&a);
14 comptime checkAddress(&a);
1515}
test/stage1/behavior/bugs/1914.zig+2-2
......@@ -7,7 +7,7 @@ const B = struct {
77 a_pointer: *const A,
88};
99
10const b_list: []B = [_]B{};
10const b_list: []B = &[_]B{};
1111const a = A{ .b_list_pointer = &b_list };
1212
1313test "segfault bug" {
......@@ -24,7 +24,7 @@ pub const B2 = struct {
2424 pointer_array: []*A2,
2525};
2626
27var b_value = B2{ .pointer_array = [_]*A2{} };
27var b_value = B2{ .pointer_array = &[_]*A2{} };
2828
2929test "basic stuff" {
3030 std.debug.assert(&b_value == &b_value);
test/stage1/behavior/cast.zig+49-13
......@@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {
150150}
151151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
152152 if (a) {
153 return [_]u8{};
153 return &[_]u8{};
154154 }
155155
156156 return slice[0..1];
......@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {
175175}
176176
177177fn gimmeErrOrSlice() anyerror![]u8 {
178 return [_]u8{};
178 return &[_]u8{};
179179}
180180
181181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
......@@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
200200}
201201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
202202 if (a) {
203 return [_]u8{};
203 return &[_]u8{};
204204 }
205205
206206 return slice[0..1];
......@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
457457test "implicit cast from [*]T to ?*c_void" {
458458 var a = [_]u8{ 3, 2, 1 };
459459 incrementVoidPtrArray(a[0..].ptr, 3);
460 expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 }));
460 expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
461461}
462462
463463fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
......@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {
606606
607607test "peer resolution of string literals" {
608608 const S = struct {
609 const E = extern enum { a, b, c, d};
609 const E = extern enum {
610 a,
611 b,
612 c,
613 d,
614 };
610615
611616 fn doTheTest(e: E) void {
612617 const cmd = switch (e) {
......@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {
627632 fn doTheTest() void {
628633 // [:x]T to []T
629634 {
630 var array = [4:0]i32{1,2,3,4};
635 var array = [4:0]i32{ 1, 2, 3, 4 };
631636 var slice: [:0]i32 = &array;
632637 var dest: []i32 = slice;
633 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
638 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
634639 }
635640
636641 // [*:x]T to [*]T
637642 {
638 var array = [4:99]i32{1,2,3,4};
643 var array = [4:99]i32{ 1, 2, 3, 4 };
639644 var dest: [*]i32 = &array;
640645 expect(dest[0] == 1);
641646 expect(dest[1] == 2);
......@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {
646651
647652 // [N:x]T to [N]T
648653 {
649 var array = [4:0]i32{1,2,3,4};
654 var array = [4:0]i32{ 1, 2, 3, 4 };
650655 var dest: [4]i32 = array;
651 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
656 expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
652657 }
653658
654659 // *[N:x]T to *[N]T
655660 {
656 var array = [4:0]i32{1,2,3,4};
661 var array = [4:0]i32{ 1, 2, 3, 4 };
657662 var dest: *[4]i32 = &array;
658 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
663 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
659664 }
660665
661666 // [:x]T to [*:x]T
662667 {
663 var array = [4:0]i32{1,2,3,4};
668 var array = [4:0]i32{ 1, 2, 3, 4 };
664669 var slice: [:0]i32 = &array;
665670 var dest: [*:0]i32 = slice;
666671 expect(dest[0] == 1);
......@@ -674,3 +679,34 @@ test "type coercion related to sentinel-termination" {
674679 S.doTheTest();
675680 comptime S.doTheTest();
676681}
682
683test "cast i8 fn call peers to i32 result" {
684 const S = struct {
685 fn doTheTest() void {
686 var cond = true;
687 const value: i32 = if (cond) smallBoi() else bigBoi();
688 expect(value == 123);
689 }
690 fn smallBoi() i8 {
691 return 123;
692 }
693 fn bigBoi() i16 {
694 return 1234;
695 }
696 };
697 S.doTheTest();
698 comptime S.doTheTest();
699}
700
701test "return u8 coercing into ?u32 return type" {
702 const S = struct {
703 fn doTheTest() void {
704 expect(foo(123).? == 123);
705 }
706 fn foo(arg: u8) ?u32 {
707 return arg;
708 }
709 };
710 S.doTheTest();
711 comptime S.doTheTest();
712}
test/stage1/behavior/error.zig+27
......@@ -400,3 +400,30 @@ test "function pointer with return type that is error union with payload which i
400400 };
401401 S.doTheTest();
402402}
403
404test "return result loc as peer result loc in inferred error set function" {
405 const S = struct {
406 fn doTheTest() void {
407 if (foo(2)) |x| {
408 expect(x.Two);
409 } else |e| switch (e) {
410 error.Whatever => @panic("fail"),
411 }
412 expectError(error.Whatever, foo(99));
413 }
414 const FormValue = union(enum) {
415 One: void,
416 Two: bool,
417 };
418
419 fn foo(id: u64) !FormValue {
420 return switch (id) {
421 2 => FormValue{ .Two = true },
422 1 => FormValue{ .One = {} },
423 else => return error.Whatever,
424 };
425 }
426 };
427 S.doTheTest();
428 comptime S.doTheTest();
429}
test/stage1/behavior/eval.zig+3-3
......@@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" {
717717 };
718718
719719 var b = [1]u8{9};
720 var f = @bytesToSlice(F, b);
720 var f = @bytesToSlice(F, &b);
721721 expect(f[0].a == 9);
722722}
723723
......@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {
774774
775775test "array concatenation forces comptime" {
776776 var a = oneItem(3) ++ oneItem(4);
777 expect(std.mem.eql(i32, a, [_]i32{ 3, 4 }));
777 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
778778}
779779
780780test "array multiplication forces comptime" {
781781 var a = oneItem(3) ** scalar(2);
782 expect(std.mem.eql(i32, a, [_]i32{ 3, 3 }));
782 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
783783}
784784
785785fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/for.zig+5-5
......@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
2626 var target: [source.len]u8 = undefined;
2727 mem.copy(u8, target[0..], source);
2828 mangleString(target[0..]);
29 expect(mem.eql(u8, target, "bcdefgh"));
29 expect(mem.eql(u8, &target, "bcdefgh"));
3030
3131 for (source) |*c, i|
3232 expect(@typeOf(c) == *const u8);
......@@ -64,7 +64,7 @@ test "basic for loop" {
6464 buffer[buf_index] = @intCast(u8, index);
6565 buf_index += 1;
6666 }
67 const unknown_size: []const u8 = array;
67 const unknown_size: []const u8 = &array;
6868 for (unknown_size) |item| {
6969 buffer[buf_index] = item;
7070 buf_index += 1;
......@@ -74,7 +74,7 @@ test "basic for loop" {
7474 buf_index += 1;
7575 }
7676
77 expect(mem.eql(u8, buffer[0..buf_index], expected_result));
77 expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
7878}
7979
8080test "break from outer for loop" {
......@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {
139139 }
140140 }
141141 };
142 S.doTheTest([_]u8{ 1, 2 });
143 comptime S.doTheTest([_]u8{ 1, 2 });
142 S.doTheTest(&[_]u8{ 1, 2 });
143 comptime S.doTheTest(&[_]u8{ 1, 2 });
144144}
test/stage1/behavior/generics.zig+2-2
......@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
120120}
121121
122122test "generic fn with implicit cast" {
123 expect(getFirstByte(u8, [_]u8{13}) == 13);
124 expect(getFirstByte(u16, [_]u16{
123 expect(getFirstByte(u8, &[_]u8{13}) == 13);
124 expect(getFirstByte(u16, &[_]u16{
125125 0,
126126 13,
127127 }) == 0);
test/stage1/behavior/misc.zig+3-3
......@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}
241241
242242test "cast undefined" {
243243 const array: [100]u8 = undefined;
244 const slice = @as([]const u8, array);
244 const slice = @as([]const u8, &array);
245245 testCastUndefined(slice);
246246}
247247fn testCastUndefined(x: []const u8) void {}
......@@ -614,7 +614,7 @@ test "slicing zero length array" {
614614 expect(s1.len == 0);
615615 expect(s2.len == 0);
616616 expect(mem.eql(u8, s1, ""));
617 expect(mem.eql(u32, s2, [_]u32{}));
617 expect(mem.eql(u32, s2, &[_]u32{}));
618618}
619619
620620const addr1 = @ptrCast(*const u8, emptyFn);
......@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic
710710 const E = struct {
711711 entries: []u32,
712712 };
713 var foo = E{ .entries = [_]u32{} };
713 var foo = E{ .entries = &[_]u32{} };
714714 expect(foo.entries.len == 0);
715715}
716716
test/stage1/behavior/optional.zig+11
......@@ -119,3 +119,14 @@ test "self-referential struct through a slice of optional" {
119119 var n = S.Node.new();
120120 expect(n.data == null);
121121}
122
123test "assigning to an unwrapped optional field in an inline loop" {
124 comptime var maybe_pos_arg: ?comptime_int = null;
125 inline for ("ab") |x| {
126 maybe_pos_arg = 0;
127 if (maybe_pos_arg.? != 0) {
128 @compileError("bad");
129 }
130 maybe_pos_arg.? = 10;
131 }
132}
test/stage1/behavior/ptrcast.zig+1-1
......@@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {
3737
3838test "reinterpret struct field at comptime" {
3939 const numLittle = comptime Bytes.init(0x12345678);
40 expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
40 expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes));
4141}
4242
4343const Bytes = struct {
test/stage1/behavior/shuffle.zig+7-7
......@@ -9,28 +9,28 @@ test "@shuffle" {
99 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
1010 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
1111 var res = @shuffle(i32, v, x, mask);
12 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
12 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1313
1414 // Implicit cast from array (of mask)
1515 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
16 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1717
1818 // Undefined
1919 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
2020 res = @shuffle(i32, v, undefined, mask2);
21 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 }));
21 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
2222
2323 // Upcasting of b
2424 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
2525 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
2626 res = @shuffle(i32, x, v2, mask3);
27 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 }));
27 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
2828
2929 // Upcasting of a
3030 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
3131 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
3232 res = @shuffle(i32, v3, x, mask4);
33 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 }));
33 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
3434
3535 // bool
3636 // Disabled because of #3317
......@@ -39,7 +39,7 @@ test "@shuffle" {
3939 var v4: @Vector(2, bool) = [2]bool{ true, false };
4040 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
4141 var res2 = @shuffle(bool, x2, v4, mask5);
42 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
42 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
4343 }
4444
4545 // TODO re-enable when LLVM codegen is fixed
......@@ -49,7 +49,7 @@ test "@shuffle" {
4949 var v4: @Vector(2, bool) = [2]bool{ true, false };
5050 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
5151 var res2 = @shuffle(bool, x2, v4, mask5);
52 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
52 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
5353 }
5454 }
5555 };
test/stage1/behavior/slice.zig+3-3
......@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
2828
2929test "implicitly cast array of size 0 to slice" {
3030 var msg = [_]u8{};
31 assertLenIsZero(msg);
31 assertLenIsZero(&msg);
3232}
3333
3434fn assertLenIsZero(msg: []const u8) void {
......@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {
5151}
5252
5353test "comptime slices are disambiguated" {
54 expect(sliceSum([_]u8{ 1, 2 }) == 3);
55 expect(sliceSum([_]u8{ 3, 4 }) == 7);
54 expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
55 expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
5656}
5757
5858test "slice type with custom alignment" {
test/stage1/behavior/struct.zig+5-4
......@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
184184}
185185
186186test "pass slice of empty struct to fn" {
187 expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1);
187 expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
188188}
189189fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
190190 return slice.len;
......@@ -432,7 +432,7 @@ const Expr = union(enum) {
432432};
433433
434434fn alloc(comptime T: type) []T {
435 return [_]T{};
435 return &[_]T{};
436436}
437437
438438test "call method with mutable reference to struct with no fields" {
......@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {
495495 .a = true,
496496 .b = "abcdefghijklmnopqurstu".*,
497497 };
498 bar(foo.b);
498 const value = foo.b;
499 bar(&value);
499500 }
500501 };
501502 S.doTheTest();
......@@ -783,7 +784,7 @@ test "struct with var field" {
783784 x: var,
784785 y: var,
785786 };
786 const pt = Point {
787 const pt = Point{
787788 .x = 1,
788789 .y = 2,
789790 };
test/stage1/behavior/struct_contains_slice_of_itself.zig+8-8
......@@ -14,21 +14,21 @@ test "struct contains slice of itself" {
1414 var other_nodes = [_]Node{
1515 Node{
1616 .payload = 31,
17 .children = [_]Node{},
17 .children = &[_]Node{},
1818 },
1919 Node{
2020 .payload = 32,
21 .children = [_]Node{},
21 .children = &[_]Node{},
2222 },
2323 };
2424 var nodes = [_]Node{
2525 Node{
2626 .payload = 1,
27 .children = [_]Node{},
27 .children = &[_]Node{},
2828 },
2929 Node{
3030 .payload = 2,
31 .children = [_]Node{},
31 .children = &[_]Node{},
3232 },
3333 Node{
3434 .payload = 3,
......@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {
5151 var other_nodes = [_]NodeAligned{
5252 NodeAligned{
5353 .payload = 31,
54 .children = [_]NodeAligned{},
54 .children = &[_]NodeAligned{},
5555 },
5656 NodeAligned{
5757 .payload = 32,
58 .children = [_]NodeAligned{},
58 .children = &[_]NodeAligned{},
5959 },
6060 };
6161 var nodes = [_]NodeAligned{
6262 NodeAligned{
6363 .payload = 1,
64 .children = [_]NodeAligned{},
64 .children = &[_]NodeAligned{},
6565 },
6666 NodeAligned{
6767 .payload = 2,
68 .children = [_]NodeAligned{},
68 .children = &[_]NodeAligned{},
6969 },
7070 NodeAligned{
7171 .payload = 3,
test/stage1/behavior/type.zig+12-12
......@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {
1212
1313test "Type.MetaType" {
1414 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
15 testTypes([_]type{type});
15 testTypes(&[_]type{type});
1616}
1717
1818test "Type.Void" {
1919 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
20 testTypes([_]type{void});
20 testTypes(&[_]type{void});
2121}
2222
2323test "Type.Bool" {
2424 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
25 testTypes([_]type{bool});
25 testTypes(&[_]type{bool});
2626}
2727
2828test "Type.NoReturn" {
2929 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
30 testTypes([_]type{noreturn});
30 testTypes(&[_]type{noreturn});
3131}
3232
3333test "Type.Int" {
......@@ -37,7 +37,7 @@ test "Type.Int" {
3737 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));
3838 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));
3939 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));
40 testTypes([_]type{ u8, u32, i64 });
40 testTypes(&[_]type{ u8, u32, i64 });
4141}
4242
4343test "Type.Float" {
......@@ -45,11 +45,11 @@ test "Type.Float" {
4545 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
4646 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
4747 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
48 testTypes([_]type{ f16, f32, f64, f128 });
48 testTypes(&[_]type{ f16, f32, f64, f128 });
4949}
5050
5151test "Type.Pointer" {
52 testTypes([_]type{
52 testTypes(&[_]type{
5353 // One Value Pointer Types
5454 *u8, *const u8,
5555 *volatile u8, *const volatile u8,
......@@ -115,18 +115,18 @@ test "Type.Array" {
115115 .sentinel = 0,
116116 },
117117 }));
118 testTypes([_]type{ [1]u8, [30]usize, [7]bool });
118 testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
119119}
120120
121121test "Type.ComptimeFloat" {
122 testTypes([_]type{comptime_float});
122 testTypes(&[_]type{comptime_float});
123123}
124124test "Type.ComptimeInt" {
125 testTypes([_]type{comptime_int});
125 testTypes(&[_]type{comptime_int});
126126}
127127test "Type.Undefined" {
128 testTypes([_]type{@typeOf(undefined)});
128 testTypes(&[_]type{@typeOf(undefined)});
129129}
130130test "Type.Null" {
131 testTypes([_]type{@typeOf(null)});
131 testTypes(&[_]type{@typeOf(null)});
132132}
test/stage1/behavior/union.zig+30-1
......@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {
241241};
242242
243243test "constant packed union" {
244 testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }});
244 testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
245245}
246246
247247fn testConstPackedUnion(expected_tokens: []const PackThis) void {
......@@ -582,3 +582,32 @@ test "update the tag value for zero-sized unions" {
582582 x = S{ .U1 = {} };
583583 expect(x == .U1);
584584}
585
586test "function call result coerces from tagged union to the tag" {
587 const S = struct {
588 const Arch = union(enum) {
589 One,
590 Two: usize,
591 };
592
593 const ArchTag = @TagType(Arch);
594
595 fn doTheTest() void {
596 var x: ArchTag = getArch1();
597 expect(x == .One);
598
599 var y: ArchTag = getArch2();
600 expect(y == .Two);
601 }
602
603 pub fn getArch1() Arch {
604 return .One;
605 }
606
607 pub fn getArch2() Arch {
608 return .{ .Two = 99 };
609 }
610 };
611 S.doTheTest();
612 comptime S.doTheTest();
613}
test/stage1/behavior/vector.zig+27-27
......@@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" {
88 fn doTheTest() void {
99 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };
1010 const result_array: [4]bool = a;
11 expect(mem.eql(bool, result_array, [4]bool{ true, false, true, false }));
11 expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
1212 }
1313 };
1414 S.doTheTest();
......@@ -20,11 +20,11 @@ test "vector wrap operators" {
2020 fn doTheTest() void {
2121 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
2222 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
23 expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
23 expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
2626 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
27 expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 }));
27 expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
2828 }
2929 };
3030 S.doTheTest();
......@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
3636 fn doTheTest() void {
3737 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
3838 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
39 expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));
39 expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
4545 }
4646 };
4747 S.doTheTest();
......@@ -53,10 +53,10 @@ test "vector int operators" {
5353 fn doTheTest() void {
5454 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
5555 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
56 expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));
56 expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
6060 }
6161 };
6262 S.doTheTest();
......@@ -68,10 +68,10 @@ test "vector float operators" {
6868 fn doTheTest() void {
6969 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
7070 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
71 expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));
71 expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
7575 }
7676 };
7777 S.doTheTest();
......@@ -83,9 +83,9 @@ test "vector bit operators" {
8383 fn doTheTest() void {
8484 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
8585 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
86 expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
86 expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
8989 }
9090 };
9191 S.doTheTest();
......@@ -98,7 +98,7 @@ test "implicit cast vector to array" {
9898 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
9999 var result_array: [4]i32 = a;
100100 result_array = a;
101 expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 }));
101 expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
102102 }
103103 };
104104 S.doTheTest();
......@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120120 {
121121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122122 var x: [4]u3 = v;
123 expect(mem.eql(u3, x, @as([4]u3, v)));
123 expect(mem.eql(u3, &x, &@as([4]u3, v)));
124124 }
125125 {
126126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127127 var x: [4]u2 = v;
128 expect(mem.eql(u2, x, @as([4]u2, v)));
128 expect(mem.eql(u2, &x, &@as([4]u2, v)));
129129 }
130130 {
131131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132132 var x: [4]u1 = v;
133 expect(mem.eql(u1, x, @as([4]u1, v)));
133 expect(mem.eql(u1, &x, &@as([4]u1, v)));
134134 }
135135 {
136136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137137 var x: [4]bool = v;
138 expect(mem.eql(bool, x, @as([4]bool, v)));
138 expect(mem.eql(bool, &x, &@as([4]bool, v)));
139139 }
140140 }
141141 };
test/stage1/c_abi/build.zig+1-1
......@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
44 const rel_opts = b.standardReleaseOptions();
55
66 const c_obj = b.addObject("cfuncs", null);
7 c_obj.addCSourceFile("cfuncs.c", [_][]const u8{"-std=c99"});
7 c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
88 c_obj.setBuildMode(rel_opts);
99 c_obj.linkSystemLibrary("c");
1010
test/stage1/c_abi/main.zig+1-1
......@@ -124,7 +124,7 @@ test "C ABI array" {
124124}
125125
126126export fn zig_array(x: [10]u8) void {
127 expect(std.mem.eql(u8, x, "1234567890"));
127 expect(std.mem.eql(u8, &x, "1234567890"));
128128}
129129
130130const BigStruct = extern struct {
test/standalone/mix_o_files/build.zig+1-1
......@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
44 const obj = b.addObject("base64", "base64.zig");
55
66 const exe = b.addExecutable("test", null);
7 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
7 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
88 exe.addObject(obj);
99 exe.linkSystemLibrary("c");
1010
test/standalone/shared_library/build.zig+1-1
......@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
44 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
55
66 const exe = b.addExecutable("test", null);
7 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
7 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
88 exe.linkLibrary(lib);
99 exe.linkSystemLibrary("c");
1010
test/standalone/static_c_lib/build.zig+1-1
......@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
44 const mode = b.standardReleaseOptions();
55
66 const foo = b.addStaticLibrary("foo", null);
7 foo.addCSourceFile("foo.c", [_][]const u8{});
7 foo.addCSourceFile("foo.c", &[_][]const u8{});
88 foo.setBuildMode(mode);
99 foo.addIncludeDir(".");
1010
test/tests.zig+14-14
......@@ -345,7 +345,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
345345
346346 const exe = b.addExecutable("test-cli", "test/cli.zig");
347347 const run_cmd = exe.run();
348 run_cmd.addArgs([_][]const u8{
348 run_cmd.addArgs(&[_][]const u8{
349349 fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
350350 b.pathFromRoot(b.cache_root),
351351 });
......@@ -646,7 +646,7 @@ pub const CompareOutputContext = struct {
646646
647647 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
648648
649 const child = std.ChildProcess.init([_][]const u8{full_exe_path}, b.allocator) catch unreachable;
649 const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
650650 defer child.deinit();
651651
652652 child.env_map = b.env_map;
......@@ -687,7 +687,7 @@ pub const CompareOutputContext = struct {
687687 .expected_output = expected_output,
688688 .link_libc = false,
689689 .special = special,
690 .cli_args = [_][]const u8{},
690 .cli_args = &[_][]const u8{},
691691 };
692692 const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
693693 tc.addSourceFile(root_src_name, source);
......@@ -724,7 +724,7 @@ pub const CompareOutputContext = struct {
724724
725725 const root_src = fs.path.join(
726726 b.allocator,
727 [_][]const u8{ b.cache_root, case.sources.items[0].filename },
727 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
728728 ) catch unreachable;
729729
730730 switch (case.special) {
......@@ -740,7 +740,7 @@ pub const CompareOutputContext = struct {
740740 for (case.sources.toSliceConst()) |src_file| {
741741 const expanded_src_path = fs.path.join(
742742 b.allocator,
743 [_][]const u8{ b.cache_root, src_file.filename },
743 &[_][]const u8{ b.cache_root, src_file.filename },
744744 ) catch unreachable;
745745 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
746746 exe.step.dependOn(&write_src.step);
......@@ -772,7 +772,7 @@ pub const CompareOutputContext = struct {
772772 for (case.sources.toSliceConst()) |src_file| {
773773 const expanded_src_path = fs.path.join(
774774 b.allocator,
775 [_][]const u8{ b.cache_root, src_file.filename },
775 &[_][]const u8{ b.cache_root, src_file.filename },
776776 ) catch unreachable;
777777 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
778778 exe.step.dependOn(&write_src.step);
......@@ -803,7 +803,7 @@ pub const CompareOutputContext = struct {
803803 for (case.sources.toSliceConst()) |src_file| {
804804 const expanded_src_path = fs.path.join(
805805 b.allocator,
806 [_][]const u8{ b.cache_root, src_file.filename },
806 &[_][]const u8{ b.cache_root, src_file.filename },
807807 ) catch unreachable;
808808 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
809809 exe.step.dependOn(&write_src.step);
......@@ -836,7 +836,7 @@ pub const StackTracesContext = struct {
836836
837837 const source_pathname = fs.path.join(
838838 b.allocator,
839 [_][]const u8{ b.cache_root, "source.zig" },
839 &[_][]const u8{ b.cache_root, "source.zig" },
840840 ) catch unreachable;
841841
842842 for (self.modes) |mode| {
......@@ -1093,7 +1093,7 @@ pub const CompileErrorContext = struct {
10931093
10941094 const root_src = fs.path.join(
10951095 b.allocator,
1096 [_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
1096 &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
10971097 ) catch unreachable;
10981098
10991099 var zig_args = ArrayList([]const u8).init(b.allocator);
......@@ -1290,7 +1290,7 @@ pub const CompileErrorContext = struct {
12901290 for (case.sources.toSliceConst()) |src_file| {
12911291 const expanded_src_path = fs.path.join(
12921292 b.allocator,
1293 [_][]const u8{ b.cache_root, src_file.filename },
1293 &[_][]const u8{ b.cache_root, src_file.filename },
12941294 ) catch unreachable;
12951295 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
12961296 compile_and_cmp_errors.step.dependOn(&write_src.step);
......@@ -1424,7 +1424,7 @@ pub const TranslateCContext = struct {
14241424
14251425 const root_src = fs.path.join(
14261426 b.allocator,
1427 [_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
1427 &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
14281428 ) catch unreachable;
14291429
14301430 var zig_args = ArrayList([]const u8).init(b.allocator);
......@@ -1597,7 +1597,7 @@ pub const TranslateCContext = struct {
15971597 for (case.sources.toSliceConst()) |src_file| {
15981598 const expanded_src_path = fs.path.join(
15991599 b.allocator,
1600 [_][]const u8{ b.cache_root, src_file.filename },
1600 &[_][]const u8{ b.cache_root, src_file.filename },
16011601 ) catch unreachable;
16021602 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
16031603 translate_c_and_cmp.step.dependOn(&write_src.step);
......@@ -1720,7 +1720,7 @@ pub const GenHContext = struct {
17201720 const b = self.b;
17211721 const root_src = fs.path.join(
17221722 b.allocator,
1723 [_][]const u8{ b.cache_root, case.sources.items[0].filename },
1723 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
17241724 ) catch unreachable;
17251725
17261726 const mode = builtin.Mode.Debug;
......@@ -1735,7 +1735,7 @@ pub const GenHContext = struct {
17351735 for (case.sources.toSliceConst()) |src_file| {
17361736 const expanded_src_path = fs.path.join(
17371737 b.allocator,
1738 [_][]const u8{ b.cache_root, src_file.filename },
1738 &[_][]const u8{ b.cache_root, src_file.filename },
17391739 ) catch unreachable;
17401740 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
17411741 obj.step.dependOn(&write_src.step);