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 {...@@ -20,10 +20,10 @@ pub fn build(b: *Builder) !void {
20 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);20 const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
21 const langref_out_path = fs.path.join(21 const langref_out_path = fs.path.join(
22 b.allocator,22 b.allocator,
23 [_][]const u8{ b.cache_root, "langref.html" },23 &[_][]const u8{ b.cache_root, "langref.html" },
24 ) catch unreachable;24 ) catch unreachable;
25 var docgen_cmd = docgen_exe.run();25 var docgen_cmd = docgen_exe.run();
26 docgen_cmd.addArgs([_][]const u8{26 docgen_cmd.addArgs(&[_][]const u8{
27 rel_zig_exe,27 rel_zig_exe,
28 "doc" ++ fs.path.sep_str ++ "langref.html.in",28 "doc" ++ fs.path.sep_str ++ "langref.html.in",
29 langref_out_path,29 langref_out_path,
...@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {...@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {
36 const test_step = b.step("test", "Run all the tests");36 const test_step = b.step("test", "Run all the tests");
3737
38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library38 // find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
39 const build_info = try b.exec([_][]const u8{39 const build_info = try b.exec(&[_][]const u8{
40 b.zig_exe,40 b.zig_exe,
41 "BUILD_INFO",41 "BUILD_INFO",
42 });42 });
...@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {...@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {
56 test_stage2.setBuildMode(builtin.Mode.Debug);56 test_stage2.setBuildMode(builtin.Mode.Debug);
57 test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");57 test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");
5858
59 const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"});59 const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
6060
61 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");61 var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
62 exe.setBuildMode(mode);62 exe.setBuildMode(mode);
...@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {...@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {
88 .source_dir = "lib",88 .source_dir = "lib",
89 .install_dir = .Lib,89 .install_dir = .Lib,
90 .install_subdir = "zig",90 .install_subdir = "zig",
91 .exclude_extensions = [_][]const u8{ "test.zig", "README.md" },91 .exclude_extensions = &[_][]const u8{ "test.zig", "README.md" },
92 });92 });
9393
94 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");94 const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
...@@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -148,7 +148,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
148 }148 }
149 const lib_dir = fs.path.join(149 const lib_dir = fs.path.join(
150 b.allocator,150 b.allocator,
151 [_][]const u8{ dep.prefix, "lib" },151 &[_][]const u8{ dep.prefix, "lib" },
152 ) catch unreachable;152 ) catch unreachable;
153 for (dep.system_libs.toSliceConst()) |lib| {153 for (dep.system_libs.toSliceConst()) |lib| {
154 const static_bare_name = if (mem.eql(u8, lib, "curses"))154 const static_bare_name = if (mem.eql(u8, lib, "curses"))
...@@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {...@@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
157 b.fmt("lib{}.a", lib);157 b.fmt("lib{}.a", lib);
158 const static_lib_name = fs.path.join(158 const static_lib_name = fs.path.join(
159 b.allocator,159 b.allocator,
160 [_][]const u8{ lib_dir, static_bare_name },160 &[_][]const u8{ lib_dir, static_bare_name },
161 ) catch unreachable;161 ) catch unreachable;
162 const have_static = fileExists(static_lib_name) catch unreachable;162 const have_static = fileExists(static_lib_name) catch unreachable;
163 if (have_static) {163 if (have_static) {
...@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {...@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {
183}183}
184184
185fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {185fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{186 lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
187 cmake_binary_dir,187 cmake_binary_dir,
188 "zig_cpp",188 "zig_cpp",
189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),189 b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
...@@ -199,22 +199,22 @@ const LibraryDep = struct {...@@ -199,22 +199,22 @@ const LibraryDep = struct {
199};199};
200200
201fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {201fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
202 const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" });202 const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" });
203 const is_static = mem.startsWith(u8, shared_mode, "static");203 const is_static = mem.startsWith(u8, shared_mode, "static");
204 const libs_output = if (is_static)204 const libs_output = if (is_static)
205 try b.exec([_][]const u8{205 try b.exec(&[_][]const u8{
206 llvm_config_exe,206 llvm_config_exe,
207 "--libfiles",207 "--libfiles",
208 "--system-libs",208 "--system-libs",
209 })209 })
210 else210 else
211 try b.exec([_][]const u8{211 try b.exec(&[_][]const u8{
212 llvm_config_exe,212 llvm_config_exe,
213 "--libs",213 "--libs",
214 });214 });
215 const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });215 const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" });
216 const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" });216 const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" });
217 const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" });217 const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
218218
219 var result = LibraryDep{219 var result = LibraryDep{
220 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,220 .prefix = mem.tokenize(prefix_output, " \r\n").next().?,
...@@ -341,7 +341,7 @@ fn addCxxKnownPath(...@@ -341,7 +341,7 @@ fn addCxxKnownPath(
341 objname: []const u8,341 objname: []const u8,
342 errtxt: ?[]const u8,342 errtxt: ?[]const u8,
343) !void {343) !void {
344 const path_padded = try b.exec([_][]const u8{344 const path_padded = try b.exec(&[_][]const u8{
345 ctx.cxx_compiler,345 ctx.cxx_compiler,
346 b.fmt("-print-file-name={}", objname),346 b.fmt("-print-file-name={}", objname),
347 });347 });
doc/docgen.zig+16-16
...@@ -1039,7 +1039,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1039,7 +1039,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1039 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);1039 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
1040 const tmp_source_file_name = try fs.path.join(1040 const tmp_source_file_name = try fs.path.join(
1041 allocator,1041 allocator,
1042 [_][]const u8{ tmp_dir_name, name_plus_ext },1042 &[_][]const u8{ tmp_dir_name, name_plus_ext },
1043 );1043 );
1044 try io.writeFile(tmp_source_file_name, trimmed_raw_source);1044 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...@@ -1048,7 +1048,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1048 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);1048 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
1049 var build_args = std.ArrayList([]const u8).init(allocator);1049 var build_args = std.ArrayList([]const u8).init(allocator);
1050 defer build_args.deinit();1050 defer build_args.deinit();
1051 try build_args.appendSlice([_][]const u8{1051 try build_args.appendSlice(&[_][]const u8{
1052 zig_exe,1052 zig_exe,
1053 "build-exe",1053 "build-exe",
1054 tmp_source_file_name,1054 tmp_source_file_name,
...@@ -1079,7 +1079,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1079,7 +1079,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1079 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);1079 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
1080 const full_path_object = try fs.path.join(1080 const full_path_object = try fs.path.join(
1081 allocator,1081 allocator,
1082 [_][]const u8{ tmp_dir_name, name_with_ext },1082 &[_][]const u8{ tmp_dir_name, name_with_ext },
1083 );1083 );
1084 try build_args.append("--object");1084 try build_args.append("--object");
1085 try build_args.append(full_path_object);1085 try build_args.append(full_path_object);
...@@ -1090,7 +1090,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1090,7 +1090,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1090 try out.print(" -lc");1090 try out.print(" -lc");
1091 }1091 }
1092 if (code.target_str) |triple| {1092 if (code.target_str) |triple| {
1093 try build_args.appendSlice([_][]const u8{ "-target", triple });1093 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
1094 if (!code.is_inline) {1094 if (!code.is_inline) {
1095 try out.print(" -target {}", triple);1095 try out.print(" -target {}", triple);
1096 }1096 }
...@@ -1143,7 +1143,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1143,7 +1143,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1143 }1143 }
11441144
1145 const path_to_exe = mem.trim(u8, exec_result.stdout, " \r\n");1145 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
1148 var exited_with_signal = false;1148 var exited_with_signal = false;
11491149
...@@ -1184,7 +1184,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1184,7 +1184,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1184 var test_args = std.ArrayList([]const u8).init(allocator);1184 var test_args = std.ArrayList([]const u8).init(allocator);
1185 defer test_args.deinit();1185 defer test_args.deinit();
11861186
1187 try test_args.appendSlice([_][]const u8{1187 try test_args.appendSlice(&[_][]const u8{
1188 zig_exe,1188 zig_exe,
1189 "test",1189 "test",
1190 tmp_source_file_name,1190 tmp_source_file_name,
...@@ -1212,7 +1212,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1212,7 +1212,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1212 try out.print(" -lc");1212 try out.print(" -lc");
1213 }1213 }
1214 if (code.target_str) |triple| {1214 if (code.target_str) |triple| {
1215 try test_args.appendSlice([_][]const u8{ "-target", triple });1215 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
1216 try out.print(" -target {}", triple);1216 try out.print(" -target {}", triple);
1217 }1217 }
1218 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");1218 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...@@ -1224,7 +1224,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1224 var test_args = std.ArrayList([]const u8).init(allocator);1224 var test_args = std.ArrayList([]const u8).init(allocator);
1225 defer test_args.deinit();1225 defer test_args.deinit();
12261226
1227 try test_args.appendSlice([_][]const u8{1227 try test_args.appendSlice(&[_][]const u8{
1228 zig_exe,1228 zig_exe,
1229 "test",1229 "test",
1230 "--color",1230 "--color",
...@@ -1283,7 +1283,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1283,7 +1283,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1283 var test_args = std.ArrayList([]const u8).init(allocator);1283 var test_args = std.ArrayList([]const u8).init(allocator);
1284 defer test_args.deinit();1284 defer test_args.deinit();
12851285
1286 try test_args.appendSlice([_][]const u8{1286 try test_args.appendSlice(&[_][]const u8{
1287 zig_exe,1287 zig_exe,
1288 "test",1288 "test",
1289 tmp_source_file_name,1289 tmp_source_file_name,
...@@ -1345,7 +1345,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1345,7 +1345,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1345 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);1345 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
1346 const tmp_obj_file_name = try fs.path.join(1346 const tmp_obj_file_name = try fs.path.join(
1347 allocator,1347 allocator,
1348 [_][]const u8{ tmp_dir_name, name_plus_obj_ext },1348 &[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
1349 );1349 );
1350 var build_args = std.ArrayList([]const u8).init(allocator);1350 var build_args = std.ArrayList([]const u8).init(allocator);
1351 defer build_args.deinit();1351 defer build_args.deinit();
...@@ -1353,10 +1353,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1353,10 +1353,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1353 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);1353 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
1354 const output_h_file_name = try fs.path.join(1354 const output_h_file_name = try fs.path.join(
1355 allocator,1355 allocator,
1356 [_][]const u8{ tmp_dir_name, name_plus_h_ext },1356 &[_][]const u8{ tmp_dir_name, name_plus_h_ext },
1357 );1357 );
13581358
1359 try build_args.appendSlice([_][]const u8{1359 try build_args.appendSlice(&[_][]const u8{
1360 zig_exe,1360 zig_exe,
1361 "build-obj",1361 "build-obj",
1362 tmp_source_file_name,1362 tmp_source_file_name,
...@@ -1395,7 +1395,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1395,7 +1395,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1395 }1395 }
13961396
1397 if (code.target_str) |triple| {1397 if (code.target_str) |triple| {
1398 try build_args.appendSlice([_][]const u8{ "-target", triple });1398 try build_args.appendSlice(&[_][]const u8{ "-target", triple });
1399 try out.print(" -target {}", triple);1399 try out.print(" -target {}", triple);
1400 }1400 }
14011401
...@@ -1442,7 +1442,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1442,7 +1442,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1442 var test_args = std.ArrayList([]const u8).init(allocator);1442 var test_args = std.ArrayList([]const u8).init(allocator);
1443 defer test_args.deinit();1443 defer test_args.deinit();
14441444
1445 try test_args.appendSlice([_][]const u8{1445 try test_args.appendSlice(&[_][]const u8{
1446 zig_exe,1446 zig_exe,
1447 "build-lib",1447 "build-lib",
1448 tmp_source_file_name,1448 tmp_source_file_name,
...@@ -1466,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var...@@ -1466,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
1466 },1466 },
1467 }1467 }
1468 if (code.target_str) |triple| {1468 if (code.target_str) |triple| {
1469 try test_args.appendSlice([_][]const u8{ "-target", triple });1469 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
1470 try out.print(" -target {}", triple);1470 try out.print(" -target {}", triple);
1471 }1471 }
1472 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed");1472 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...@@ -1507,7 +1507,7 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
1507}1507}
15081508
1509fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 {1509fn 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{
1511 zig_exe,1511 zig_exe,
1512 "builtin",1512 "builtin",
1513 });1513 });
doc/langref.html.in+21-21
...@@ -1518,7 +1518,7 @@ value == null{#endsyntax#}</pre>...@@ -1518,7 +1518,7 @@ value == null{#endsyntax#}</pre>
1518const array1 = [_]u32{1,2};1518const array1 = [_]u32{1,2};
1519const array2 = [_]u32{3,4};1519const array2 = [_]u32{3,4};
1520const together = array1 ++ array2;1520const 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>
1522 </td>1522 </td>
1523 </tr>1523 </tr>
1524 <tr>1524 <tr>
...@@ -1621,10 +1621,10 @@ comptime {...@@ -1621,10 +1621,10 @@ comptime {
1621}1621}
16221622
1623// A string literal is a pointer to an array literal.1623// A string literal is a pointer to an array literal.
1624const same_message = "hello".*;1624const same_message = "hello";
16251625
1626comptime {1626comptime {
1627 assert(mem.eql(u8, message, same_message));1627 assert(mem.eql(u8, &message, same_message));
1628}1628}
16291629
1630test "iterate over an array" {1630test "iterate over an array" {
...@@ -1652,7 +1652,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };...@@ -1652,7 +1652,7 @@ const part_one = [_]i32{ 1, 2, 3, 4 };
1652const part_two = [_]i32{ 5, 6, 7, 8 };1652const part_two = [_]i32{ 5, 6, 7, 8 };
1653const all_of_it = part_one ++ part_two;1653const all_of_it = part_one ++ part_two;
1654comptime {1654comptime {
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 }));
1656}1656}
16571657
1658// remember that string literals are arrays1658// remember that string literals are arrays
...@@ -4915,30 +4915,30 @@ const assert = std.debug.assert;...@@ -4915,30 +4915,30 @@ const assert = std.debug.assert;
4915// https://github.com/ziglang/zig/issues/265 is implemented.4915// https://github.com/ziglang/zig/issues/265 is implemented.
4916test "[N]T to []const T" {4916test "[N]T to []const T" {
4917 var x1: []const u8 = "hello";4917 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 };
4919 assert(std.mem.eql(u8, x1, x2));4919 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 };
4922 assert(y[0] == 1.2);4922 assert(y[0] == 1.2);
4923}4923}
49244924
4925// Likewise, it works when the destination type is an error union.4925// Likewise, it works when the destination type is an error union.
4926test "[N]T to E![]const T" {4926test "[N]T to E![]const T" {
4927 var x1: anyerror![]const u8 = "hello";4927 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 };
4929 assert(std.mem.eql(u8, try x1, try x2));4929 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 };
4932 assert((try y)[0] == 1.2);4932 assert((try y)[0] == 1.2);
4933}4933}
49344934
4935// Likewise, it works when the destination type is an optional.4935// Likewise, it works when the destination type is an optional.
4936test "[N]T to ?[]const T" {4936test "[N]T to ?[]const T" {
4937 var x1: ?[]const u8 = "hello";4937 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 };
4939 assert(std.mem.eql(u8, x1.?, x2.?));4939 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 };
4942 assert(y.?[0] == 1.2);4942 assert(y.?[0] == 1.2);
4943}4943}
49444944
...@@ -4950,7 +4950,7 @@ test "*[N]T to []T" {...@@ -4950,7 +4950,7 @@ test "*[N]T to []T" {
49504950
4951 const buf2 = [2]f32{ 1.2, 3.4 };4951 const buf2 = [2]f32{ 1.2, 3.4 };
4952 const x2: []const f32 = &buf2;4952 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 }));
4954}4954}
49554955
4956// Single-item pointers to arrays can be coerced to4956// Single-item pointers to arrays can be coerced to
...@@ -5185,7 +5185,7 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {...@@ -5185,7 +5185,7 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
5185 return @as(usize, 3);5185 return @as(usize, 3);
5186}5186}
51875187
5188test "peer type resolution: [0]u8 and []const u8" {5188test "peer type resolution: *[0]u8 and []const u8" {
5189 assert(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);5189 assert(peerTypeEmptyArrayAndSlice(true, "hi").len == 0);
5190 assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);5190 assert(peerTypeEmptyArrayAndSlice(false, "hi").len == 1);
5191 comptime {5191 comptime {
...@@ -5195,12 +5195,12 @@ test "peer type resolution: [0]u8 and []const u8" {...@@ -5195,12 +5195,12 @@ test "peer type resolution: [0]u8 and []const u8" {
5195}5195}
5196fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {5196fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
5197 if (a) {5197 if (a) {
5198 return [_]u8{};5198 return &[_]u8{};
5199 }5199 }
52005200
5201 return slice[0..1];5201 return slice[0..1];
5202}5202}
5203test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {5203test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" {
5204 {5204 {
5205 var data = "hi".*;5205 var data = "hi".*;
5206 const slice = data[0..];5206 const slice = data[0..];
...@@ -5216,7 +5216,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {...@@ -5216,7 +5216,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
5216}5216}
5217fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {5217fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
5218 if (a) {5218 if (a) {
5219 return [_]u8{};5219 return &[_]u8{};
5220 }5220 }
52215221
5222 return slice[0..1];5222 return slice[0..1];
...@@ -5746,7 +5746,7 @@ test "fibonacci" {...@@ -5746,7 +5746,7 @@ test "fibonacci" {
5746 </p>5746 </p>
5747 {#code_begin|test#}5747 {#code_begin|test#}
5748const first_25_primes = firstNPrimes(25);5748const 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
5751fn firstNPrimes(comptime n: usize) [n]i32 {5751fn firstNPrimes(comptime n: usize) [n]i32 {
5752 var prime_list: [n]i32 = undefined;5752 var prime_list: [n]i32 = undefined;
...@@ -6364,7 +6364,7 @@ test "async function await" {...@@ -6364,7 +6364,7 @@ test "async function await" {
6364 resume the_frame;6364 resume the_frame;
6365 seq('i');6365 seq('i');
6366 assert(final_result == 1234);6366 assert(final_result == 1234);
6367 assert(std.mem.eql(u8, seq_points, "abcdefghi"));6367 assert(std.mem.eql(u8, &seq_points, "abcdefghi"));
6368}6368}
6369fn amain() void {6369fn amain() void {
6370 seq('b');6370 seq('b');
...@@ -8014,7 +8014,7 @@ test "vector @splat" {...@@ -8014,7 +8014,7 @@ test "vector @splat" {
8014 const scalar: u32 = 5;8014 const scalar: u32 = 5;
8015 const result = @splat(4, scalar);8015 const result = @splat(4, scalar);
8016 comptime assert(@typeOf(result) == @Vector(4, u32));8016 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 }));
8018}8018}
8019 {#code_end#}8019 {#code_end#}
8020 <p>8020 <p>
...@@ -8948,7 +8948,7 @@ pub fn main() void {...@@ -8948,7 +8948,7 @@ pub fn main() void {
8948 {#code_begin|test_err|unable to convert#}8948 {#code_begin|test_err|unable to convert#}
8949comptime {8949comptime {
8950 var bytes = [5]u8{ 1, 2, 3, 4, 5 };8950 var bytes = [5]u8{ 1, 2, 3, 4, 5 };
8951 var slice = @bytesToSlice(u32, bytes);8951 var slice = @bytesToSlice(u32, bytes[0..]);
8952}8952}
8953 {#code_end#}8953 {#code_end#}
8954 <p>At runtime:</p>8954 <p>At runtime:</p>
...@@ -9760,7 +9760,7 @@ pub fn build(b: *Builder) void {...@@ -9760,7 +9760,7 @@ pub fn build(b: *Builder) void {
9760 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));9760 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
97619761
9762 const exe = b.addExecutable("test", null);9762 const exe = b.addExecutable("test", null);
9763 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});9763 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
9764 exe.linkLibrary(lib);9764 exe.linkLibrary(lib);
9765 exe.linkSystemLibrary("c");9765 exe.linkSystemLibrary("c");
97669766
...@@ -9825,7 +9825,7 @@ pub fn build(b: *Builder) void {...@@ -9825,7 +9825,7 @@ pub fn build(b: *Builder) void {
9825 const obj = b.addObject("base64", "base64.zig");9825 const obj = b.addObject("base64", "base64.zig");
98269826
9827 const exe = b.addExecutable("test", null);9827 const exe = b.addExecutable("test", null);
9828 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});9828 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
9829 exe.addObject(obj);9829 exe.addObject(obj);
9830 exe.linkSystemLibrary("c");9830 exe.linkSystemLibrary("c");
9831 exe.install();9831 exe.install();
lib/std/array_list.zig+4-11
...@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {...@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
35 /// Deinitialize with `deinit` or use `toOwnedSlice`.35 /// Deinitialize with `deinit` or use `toOwnedSlice`.
36 pub fn init(allocator: *Allocator) Self {36 pub fn init(allocator: *Allocator) Self {
37 return Self{37 return Self{
38 .items = [_]T{},38 .items = &[_]T{},
39 .len = 0,39 .len = 0,
40 .allocator = allocator,40 .allocator = allocator,
41 };41 };
...@@ -323,18 +323,14 @@ test "std.ArrayList.basic" {...@@ -323,18 +323,14 @@ test "std.ArrayList.basic" {
323 testing.expect(list.pop() == 10);323 testing.expect(list.pop() == 10);
324 testing.expect(list.len == 9);324 testing.expect(list.len == 9);
325325
326 list.appendSlice([_]i32{326 list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
327 1,
328 2,
329 3,
330 }) catch unreachable;
331 testing.expect(list.len == 12);327 testing.expect(list.len == 12);
332 testing.expect(list.pop() == 3);328 testing.expect(list.pop() == 3);
333 testing.expect(list.pop() == 2);329 testing.expect(list.pop() == 2);
334 testing.expect(list.pop() == 1);330 testing.expect(list.pop() == 1);
335 testing.expect(list.len == 9);331 testing.expect(list.len == 9);
336332
337 list.appendSlice([_]i32{}) catch unreachable;333 list.appendSlice(&[_]i32{}) catch unreachable;
338 testing.expect(list.len == 9);334 testing.expect(list.len == 9);
339335
340 // can only set on indices < self.len336 // can only set on indices < self.len
...@@ -481,10 +477,7 @@ test "std.ArrayList.insertSlice" {...@@ -481,10 +477,7 @@ test "std.ArrayList.insertSlice" {
481 try list.append(2);477 try list.append(2);
482 try list.append(3);478 try list.append(3);
483 try list.append(4);479 try list.append(4);
484 try list.insertSlice(1, [_]i32{480 try list.insertSlice(1, &[_]i32{ 9, 8 });
485 9,
486 8,
487 });
488 testing.expect(list.items[0] == 1);481 testing.expect(list.items[0] == 1);
489 testing.expect(list.items[1] == 9);482 testing.expect(list.items[1] == 9);
490 testing.expect(list.items[2] == 8);483 testing.expect(list.items[2] == 8);
lib/std/bloom_filter.zig+3-3
...@@ -62,7 +62,7 @@ pub fn BloomFilter(...@@ -62,7 +62,7 @@ pub fn BloomFilter(
62 }62 }
6363
64 pub fn getCell(self: Self, cell: Index) Cell {64 pub fn getCell(self: Self, cell: Index) Cell {
65 return Io.get(self.data, cell, 0);65 return Io.get(&self.data, cell, 0);
66 }66 }
6767
68 pub fn incrementCell(self: *Self, cell: Index) void {68 pub fn incrementCell(self: *Self, cell: Index) void {
...@@ -70,7 +70,7 @@ pub fn BloomFilter(...@@ -70,7 +70,7 @@ pub fn BloomFilter(
70 // skip the 'get' operation70 // skip the 'get' operation
71 Io.set(&self.data, cell, 0, cellMax);71 Io.set(&self.data, cell, 0, cellMax);
72 } else {72 } else {
73 const old = Io.get(self.data, cell, 0);73 const old = Io.get(&self.data, cell, 0);
74 if (old != cellMax) {74 if (old != cellMax) {
75 Io.set(&self.data, cell, 0, old + 1);75 Io.set(&self.data, cell, 0, old + 1);
76 }76 }
...@@ -120,7 +120,7 @@ pub fn BloomFilter(...@@ -120,7 +120,7 @@ pub fn BloomFilter(
120 } else if (newsize > n_items) {120 } else if (newsize > n_items) {
121 var copied: usize = 0;121 var copied: usize = 0;
122 while (copied < r.data.len) : (copied += self.data.len) {122 while (copied < r.data.len) : (copied += self.data.len) {
123 std.mem.copy(u8, r.data[copied .. copied + self.data.len], self.data);123 std.mem.copy(u8, r.data[copied .. copied + self.data.len], &self.data);
124 }124 }
125 }125 }
126 return r;126 return r;
lib/std/build.zig+29-26
...@@ -186,7 +186,7 @@ pub const Builder = struct {...@@ -186,7 +186,7 @@ pub const Builder = struct {
186 pub fn resolveInstallPrefix(self: *Builder) void {186 pub fn resolveInstallPrefix(self: *Builder) void {
187 if (self.dest_dir) |dest_dir| {187 if (self.dest_dir) |dest_dir| {
188 const install_prefix = self.install_prefix orelse "/usr";188 const install_prefix = self.install_prefix orelse "/usr";
189 self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;189 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable;
190 } else {190 } else {
191 const install_prefix = self.install_prefix orelse blk: {191 const install_prefix = self.install_prefix orelse blk: {
192 const p = self.cache_root;192 const p = self.cache_root;
...@@ -195,8 +195,8 @@ pub const Builder = struct {...@@ -195,8 +195,8 @@ pub const Builder = struct {
195 };195 };
196 self.install_path = install_prefix;196 self.install_path = install_prefix;
197 }197 }
198 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;198 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
199 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;199 self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
200 }200 }
201201
202 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {202 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
...@@ -803,7 +803,7 @@ pub const Builder = struct {...@@ -803,7 +803,7 @@ pub const Builder = struct {
803 }803 }
804804
805 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {805 fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
806 return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable;806 return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
807 }807 }
808808
809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {809 pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
...@@ -818,7 +818,7 @@ pub const Builder = struct {...@@ -818,7 +818,7 @@ pub const Builder = struct {
818 if (fs.path.isAbsolute(name)) {818 if (fs.path.isAbsolute(name)) {
819 return name;819 return name;
820 }820 }
821 const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });821 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
822 return fs.realpathAlloc(self.allocator, full_path) catch continue;822 return fs.realpathAlloc(self.allocator, full_path) catch continue;
823 }823 }
824 }824 }
...@@ -827,9 +827,9 @@ pub const Builder = struct {...@@ -827,9 +827,9 @@ pub const Builder = struct {
827 if (fs.path.isAbsolute(name)) {827 if (fs.path.isAbsolute(name)) {
828 return name;828 return name;
829 }829 }
830 var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter});830 var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
831 while (it.next()) |path| {831 while (it.next()) |path| {
832 const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });832 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
833 return fs.realpathAlloc(self.allocator, full_path) catch continue;833 return fs.realpathAlloc(self.allocator, full_path) catch continue;
834 }834 }
835 }835 }
...@@ -839,7 +839,7 @@ pub const Builder = struct {...@@ -839,7 +839,7 @@ pub const Builder = struct {
839 return name;839 return name;
840 }840 }
841 for (paths) |path| {841 for (paths) |path| {
842 const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });842 const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
843 return fs.realpathAlloc(self.allocator, full_path) catch continue;843 return fs.realpathAlloc(self.allocator, full_path) catch continue;
844 }844 }
845 }845 }
...@@ -926,12 +926,12 @@ pub const Builder = struct {...@@ -926,12 +926,12 @@ pub const Builder = struct {
926 };926 };
927 return fs.path.resolve(927 return fs.path.resolve(
928 self.allocator,928 self.allocator,
929 [_][]const u8{ base_dir, dest_rel_path },929 &[_][]const u8{ base_dir, dest_rel_path },
930 ) catch unreachable;930 ) catch unreachable;
931 }931 }
932932
933 fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {933 fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {
934 const stdout = try self.execAllowFail([_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);934 const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
935 var list = ArrayList(PkgConfigPkg).init(self.allocator);935 var list = ArrayList(PkgConfigPkg).init(self.allocator);
936 var line_it = mem.tokenize(stdout, "\r\n");936 var line_it = mem.tokenize(stdout, "\r\n");
937 while (line_it.next()) |line| {937 while (line_it.next()) |line| {
...@@ -970,7 +970,7 @@ pub const Builder = struct {...@@ -970,7 +970,7 @@ pub const Builder = struct {
970970
971test "builder.findProgram compiles" {971test "builder.findProgram compiles" {
972 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");972 const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");
973 _ = builder.findProgram([_][]const u8{}, [_][]const u8{}) catch null;973 _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
974}974}
975975
976/// Deprecated. Use `builtin.Version`.976/// Deprecated. Use `builtin.Version`.
...@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {...@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {
1384 };1384 };
13851385
1386 var code: u8 = undefined;1386 var code: u8 = undefined;
1387 const stdout = if (self.builder.execAllowFail([_][]const u8{1387 const stdout = if (self.builder.execAllowFail(&[_][]const u8{
1388 "pkg-config",1388 "pkg-config",
1389 pkg_name,1389 pkg_name,
1390 "--cflags",1390 "--cflags",
...@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {...@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {
1504 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {1504 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1505 return fs.path.join(1505 return fs.path.join(
1506 self.builder.allocator,1506 self.builder.allocator,
1507 [_][]const u8{ self.output_dir.?, self.out_filename },1507 &[_][]const u8{ self.output_dir.?, self.out_filename },
1508 ) catch unreachable;1508 ) catch unreachable;
1509 }1509 }
15101510
...@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {...@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {
1514 assert(self.kind == Kind.Lib);1514 assert(self.kind == Kind.Lib);
1515 return fs.path.join(1515 return fs.path.join(
1516 self.builder.allocator,1516 self.builder.allocator,
1517 [_][]const u8{ self.output_dir.?, self.out_lib_filename },1517 &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
1518 ) catch unreachable;1518 ) catch unreachable;
1519 }1519 }
15201520
...@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {...@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {
1525 assert(!self.disable_gen_h);1525 assert(!self.disable_gen_h);
1526 return fs.path.join(1526 return fs.path.join(
1527 self.builder.allocator,1527 self.builder.allocator,
1528 [_][]const u8{ self.output_dir.?, self.out_h_filename },1528 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
1529 ) catch unreachable;1529 ) catch unreachable;
1530 }1530 }
15311531
...@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {...@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {
1535 assert(self.target.isWindows() or self.target.isUefi());1535 assert(self.target.isWindows() or self.target.isUefi());
1536 return fs.path.join(1536 return fs.path.join(
1537 self.builder.allocator,1537 self.builder.allocator,
1538 [_][]const u8{ self.output_dir.?, self.out_pdb_filename },1538 &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
1539 ) catch unreachable;1539 ) catch unreachable;
1540 }1540 }
15411541
...@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {...@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {
1605 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);1605 const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
1606 defer self.builder.allocator.free(triplet);1606 defer self.builder.allocator.free(triplet);
16071607
1608 const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" });1608 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
1609 errdefer allocator.free(include_path);1609 errdefer allocator.free(include_path);
1610 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });1610 try self.include_dirs.append(IncludeDir{ .RawPath = include_path });
16111611
1612 const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" });1612 const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
1613 try self.lib_paths.append(lib_path);1613 try self.lib_paths.append(lib_path);
16141614
1615 self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" });1615 self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
1616 },1616 },
1617 }1617 }
1618 }1618 }
...@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {...@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {
1725 if (self.build_options_contents.len() > 0) {1725 if (self.build_options_contents.len() > 0) {
1726 const build_options_file = try fs.path.join(1726 const build_options_file = try fs.path.join(
1727 builder.allocator,1727 builder.allocator,
1728 [_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },1728 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
1729 );1729 );
1730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());1730 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
1731 try zig_args.append("--pkg-begin");1731 try zig_args.append("--pkg-begin");
...@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {...@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {
1849 try zig_args.append("--test-cmd");1849 try zig_args.append("--test-cmd");
1850 try zig_args.append(bin_name);1850 try zig_args.append(bin_name);
1851 if (glibc_dir_arg) |dir| {1851 if (glibc_dir_arg) |dir| {
1852 const full_dir = try fs.path.join(builder.allocator, [_][]const u8{1852 const full_dir = try fs.path.join(builder.allocator, &[_][]const u8{
1853 dir,1853 dir,
1854 try self.target.linuxTriple(builder.allocator),1854 try self.target.linuxTriple(builder.allocator),
1855 });1855 });
...@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {...@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {
1994 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");1994 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
19951995
1996 if (self.output_dir) |output_dir| {1996 if (self.output_dir) |output_dir| {
1997 const full_dest = try fs.path.join(builder.allocator, [_][]const u8{1997 const full_dest = try fs.path.join(builder.allocator, &[_][]const u8{
1998 output_dir,1998 output_dir,
1999 fs.path.basename(output_path),1999 fs.path.basename(output_path),
2000 });2000 });
...@@ -2176,6 +2176,9 @@ const InstallArtifactStep = struct {...@@ -2176,6 +2176,9 @@ const InstallArtifactStep = struct {
2176 if (self.artifact.isDynamicLibrary()) {2176 if (self.artifact.isDynamicLibrary()) {
2177 builder.pushInstalledFile(.Lib, artifact.major_only_filename);2177 builder.pushInstalledFile(.Lib, artifact.major_only_filename);
2178 builder.pushInstalledFile(.Lib, artifact.name_only_filename);2178 builder.pushInstalledFile(.Lib, artifact.name_only_filename);
2179 if (self.artifact.target.isWindows()) {
2180 builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
2181 }
2179 }2182 }
2180 if (self.pdb_dir) |pdb_dir| {2183 if (self.pdb_dir) |pdb_dir| {
2181 builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);2184 builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
...@@ -2268,7 +2271,7 @@ pub const InstallDirStep = struct {...@@ -2268,7 +2271,7 @@ pub const InstallDirStep = struct {
2268 };2271 };
22692272
2270 const rel_path = entry.path[full_src_dir.len + 1 ..];2273 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 });
2272 switch (entry.kind) {2275 switch (entry.kind) {
2273 .Directory => try fs.makePath(self.builder.allocator, dest_path),2276 .Directory => try fs.makePath(self.builder.allocator, dest_path),
2274 .File => try self.builder.updateFile(entry.path, dest_path),2277 .File => try self.builder.updateFile(entry.path, dest_path),
...@@ -2391,7 +2394,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj...@@ -2391,7 +2394,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
2391 // sym link for libfoo.so.1 to libfoo.so.1.2.32394 // sym link for libfoo.so.1 to libfoo.so.1.2.3
2392 const major_only_path = fs.path.join(2395 const major_only_path = fs.path.join(
2393 allocator,2396 allocator,
2394 [_][]const u8{ out_dir, filename_major_only },2397 &[_][]const u8{ out_dir, filename_major_only },
2395 ) catch unreachable;2398 ) catch unreachable;
2396 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {2399 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
2397 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);2400 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
...@@ -2400,7 +2403,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj...@@ -2400,7 +2403,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
2400 // sym link for libfoo.so to libfoo.so.12403 // sym link for libfoo.so to libfoo.so.1
2401 const name_only_path = fs.path.join(2404 const name_only_path = fs.path.join(
2402 allocator,2405 allocator,
2403 [_][]const u8{ out_dir, filename_name_only },2406 &[_][]const u8{ out_dir, filename_name_only },
2404 ) catch unreachable;2407 ) catch unreachable;
2405 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {2408 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2406 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);2409 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
...@@ -2413,7 +2416,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {...@@ -2413,7 +2416,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
2413 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");2416 const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
2414 defer allocator.free(appdata_path);2417 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" });
2417 defer allocator.free(path_file);2420 defer allocator.free(path_file);
24182421
2419 const file = fs.cwd().openFile(path_file, .{}) catch return null;2422 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 {...@@ -571,7 +571,7 @@ pub const ChildProcess = struct {
571 // to match posix semantics571 // to match posix semantics
572 const app_name = x: {572 const app_name = x: {
573 if (self.cwd) |cwd| {573 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] });
575 defer self.allocator.free(resolved);575 defer self.allocator.free(resolved);
576 break :x try cstr.addNullByte(self.allocator, resolved);576 break :x try cstr.addNullByte(self.allocator, resolved);
577 } else {577 } else {
...@@ -613,10 +613,10 @@ pub const ChildProcess = struct {...@@ -613,10 +613,10 @@ pub const ChildProcess = struct {
613 retry: while (it.next()) |search_path| {613 retry: while (it.next()) |search_path| {
614 var ext_it = mem.tokenize(PATHEXT, ";");614 var ext_it = mem.tokenize(PATHEXT, ";");
615 while (ext_it.next()) |app_ext| {615 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 });
617 defer self.allocator.free(app_basename);617 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 });
620 defer self.allocator.free(joined_path);620 defer self.allocator.free(joined_path);
621621
622 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, joined_path);622 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 {...@@ -61,7 +61,7 @@ pub const Coff = struct {
6161
62 var magic: [2]u8 = undefined;62 var magic: [2]u8 = undefined;
63 try in.readNoEof(magic[0..]);63 try in.readNoEof(magic[0..]);
64 if (!mem.eql(u8, magic, "MZ"))64 if (!mem.eql(u8, &magic, "MZ"))
65 return error.InvalidPEMagic;65 return error.InvalidPEMagic;
6666
67 // Seek to PE File Header (coff header)67 // Seek to PE File Header (coff header)
...@@ -71,7 +71,7 @@ pub const Coff = struct {...@@ -71,7 +71,7 @@ pub const Coff = struct {
7171
72 var pe_header_magic: [4]u8 = undefined;72 var pe_header_magic: [4]u8 = undefined;
73 try in.readNoEof(pe_header_magic[0..]);73 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 }))
75 return error.InvalidPEHeader;75 return error.InvalidPEHeader;
7676
77 self.coff_header = CoffHeader{77 self.coff_header = CoffHeader{
...@@ -163,7 +163,7 @@ pub const Coff = struct {...@@ -163,7 +163,7 @@ pub const Coff = struct {
163 var cv_signature: [4]u8 = undefined; // CodeView signature163 var cv_signature: [4]u8 = undefined; // CodeView signature
164 try in.readNoEof(cv_signature[0..]);164 try in.readNoEof(cv_signature[0..]);
165 // 'RSDS' indicates PDB70 format, used by lld.165 // 'RSDS' indicates PDB70 format, used by lld.
166 if (!mem.eql(u8, cv_signature, "RSDS"))166 if (!mem.eql(u8, &cv_signature, "RSDS"))
167 return error.InvalidPEMagic;167 return error.InvalidPEMagic;
168 try in.readNoEof(self.guid[0..]);168 try in.readNoEof(self.guid[0..]);
169 self.age = try in.readIntLittle(u32);169 self.age = try in.readIntLittle(u32);
lib/std/crypto/aes.zig+2-2
...@@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type {...@@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type {
136136
137 pub fn init(key: [keysize / 8]u8) Self {137 pub fn init(key: [keysize / 8]u8) Self {
138 var ctx: Self = undefined;138 var ctx: Self = undefined;
139 expandKey(key, ctx.enc[0..], ctx.dec[0..]);139 expandKey(&key, ctx.enc[0..], ctx.dec[0..]);
140 return ctx;140 return ctx;
141 }141 }
142142
...@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {...@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {
157 var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);157 var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);
158 std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1);158 std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1);
159159
160 n += xorBytes(dst[n..], src[n..], keystream);160 n += xorBytes(dst[n..], src[n..], &keystream);
161 }161 }
162 }162 }
163 };163 };
lib/std/crypto/blake2.zig+2-2
...@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {...@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {
256 var out: [Blake2s256.digest_length]u8 = undefined;256 var out: [Blake2s256.digest_length]u8 = undefined;
257257
258 var h = Blake2s256.init();258 var h = Blake2s256.init();
259 h.update(block);259 h.update(&block);
260 h.final(out[0..]);260 h.final(out[0..]);
261}261}
262262
...@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {...@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {
490 var out: [Blake2b512.digest_length]u8 = undefined;490 var out: [Blake2b512.digest_length]u8 = undefined;
491491
492 var h = Blake2b512.init();492 var h = Blake2b512.init();
493 h.update(block);493 h.update(&block);
494 h.final(out[0..]);494 h.final(out[0..]);
495}495}
lib/std/crypto/chacha20.zig+7-7
...@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {...@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {
218 };218 };
219219
220 chaCha20IETF(result[0..], input[0..], 1, key, nonce);220 chaCha20IETF(result[0..], input[0..], 1, key, nonce);
221 testing.expectEqualSlices(u8, expected_result, result);221 testing.expectEqualSlices(u8, &expected_result, &result);
222222
223 // Chacha20 is self-reversing.223 // Chacha20 is self-reversing.
224 var plaintext: [114]u8 = undefined;224 var plaintext: [114]u8 = undefined;
225 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);225 chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);
226 testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal);226 testing.expect(mem.compare(u8, input, &plaintext) == mem.Compare.Equal);
227}227}
228228
229// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7229// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
...@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {...@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {
258 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };258 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
259259
260 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);260 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
261 testing.expectEqualSlices(u8, expected_result, result);261 testing.expectEqualSlices(u8, &expected_result, &result);
262}262}
263263
264test "crypto.chacha20 test vector 2" {264test "crypto.chacha20 test vector 2" {
...@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {...@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {
292 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };292 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
293293
294 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);294 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
295 testing.expectEqualSlices(u8, expected_result, result);295 testing.expectEqualSlices(u8, &expected_result, &result);
296}296}
297297
298test "crypto.chacha20 test vector 3" {298test "crypto.chacha20 test vector 3" {
...@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {...@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {
326 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };326 const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
327327
328 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);328 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
329 testing.expectEqualSlices(u8, expected_result, result);329 testing.expectEqualSlices(u8, &expected_result, &result);
330}330}
331331
332test "crypto.chacha20 test vector 4" {332test "crypto.chacha20 test vector 4" {
...@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {...@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {
360 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };360 const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
361361
362 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);362 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
363 testing.expectEqualSlices(u8, expected_result, result);363 testing.expectEqualSlices(u8, &expected_result, &result);
364}364}
365365
366test "crypto.chacha20 test vector 5" {366test "crypto.chacha20 test vector 5" {
...@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {...@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {
432 };432 };
433433
434 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);434 chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
435 testing.expectEqualSlices(u8, expected_result, result);435 testing.expectEqualSlices(u8, &expected_result, &result);
436}436}
lib/std/crypto/gimli.zig+4-4
...@@ -83,7 +83,7 @@ test "permute" {...@@ -83,7 +83,7 @@ test "permute" {
83 while (i < 12) : (i += 1) {83 while (i < 12) : (i += 1) {
84 input[i] = i * i * i + i *% 0x9e3779b9;84 input[i] = i * i * i + i *% 0x9e3779b9;
85 }85 }
86 testing.expectEqualSlices(u32, input, [_]u32{86 testing.expectEqualSlices(u32, &input, &[_]u32{
87 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,87 0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,
88 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,88 0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,
89 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,89 0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,
...@@ -92,7 +92,7 @@ test "permute" {...@@ -92,7 +92,7 @@ test "permute" {
92 },92 },
93 };93 };
94 state.permute();94 state.permute();
95 testing.expectEqualSlices(u32, state.data, [_]u32{95 testing.expectEqualSlices(u32, &state.data, &[_]u32{
96 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,96 0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,
97 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,97 0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,
98 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,98 0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,
...@@ -163,6 +163,6 @@ test "hash" {...@@ -163,6 +163,6 @@ test "hash" {
163 var msg: [58 / 2]u8 = undefined;163 var msg: [58 / 2]u8 = undefined;
164 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");164 try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
165 var md: [32]u8 = undefined;165 var md: [32]u8 = undefined;
166 hash(&md, msg);166 hash(&md, &msg);
167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", md);167 htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
168}168}
lib/std/crypto/md5.zig+1-1
...@@ -276,6 +276,6 @@ test "md5 aligned final" {...@@ -276,6 +276,6 @@ test "md5 aligned final" {
276 var out: [Md5.digest_length]u8 = undefined;276 var out: [Md5.digest_length]u8 = undefined;
277277
278 var h = Md5.init();278 var h = Md5.init();
279 h.update(block);279 h.update(&block);
280 h.final(out[0..]);280 h.final(out[0..]);
281}281}
lib/std/crypto/poly1305.zig+1-1
...@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {...@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
230 var mac: [16]u8 = undefined;230 var mac: [16]u8 = undefined;
231 Poly1305.create(mac[0..], msg, key);231 Poly1305.create(mac[0..], msg, key);
232232
233 std.testing.expectEqualSlices(u8, expected_mac, mac);233 std.testing.expectEqualSlices(u8, expected_mac, &mac);
234}234}
lib/std/crypto/sha1.zig+1-1
...@@ -297,6 +297,6 @@ test "sha1 aligned final" {...@@ -297,6 +297,6 @@ test "sha1 aligned final" {
297 var out: [Sha1.digest_length]u8 = undefined;297 var out: [Sha1.digest_length]u8 = undefined;
298298
299 var h = Sha1.init();299 var h = Sha1.init();
300 h.update(block);300 h.update(&block);
301 h.final(out[0..]);301 h.final(out[0..]);
302}302}
lib/std/crypto/sha2.zig+2-2
...@@ -343,7 +343,7 @@ test "sha256 aligned final" {...@@ -343,7 +343,7 @@ test "sha256 aligned final" {
343 var out: [Sha256.digest_length]u8 = undefined;343 var out: [Sha256.digest_length]u8 = undefined;
344344
345 var h = Sha256.init();345 var h = Sha256.init();
346 h.update(block);346 h.update(&block);
347 h.final(out[0..]);347 h.final(out[0..]);
348}348}
349349
...@@ -723,6 +723,6 @@ test "sha512 aligned final" {...@@ -723,6 +723,6 @@ test "sha512 aligned final" {
723 var out: [Sha512.digest_length]u8 = undefined;723 var out: [Sha512.digest_length]u8 = undefined;
724724
725 var h = Sha512.init();725 var h = Sha512.init();
726 h.update(block);726 h.update(&block);
727 h.final(out[0..]);727 h.final(out[0..]);
728}728}
lib/std/crypto/sha3.zig+2-2
...@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {...@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {
229 var out: [Sha3_256.digest_length]u8 = undefined;229 var out: [Sha3_256.digest_length]u8 = undefined;
230230
231 var h = Sha3_256.init();231 var h = Sha3_256.init();
232 h.update(block);232 h.update(&block);
233 h.final(out[0..]);233 h.final(out[0..]);
234}234}
235235
...@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {...@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {
300 var out: [Sha3_512.digest_length]u8 = undefined;300 var out: [Sha3_512.digest_length]u8 = undefined;
301301
302 var h = Sha3_512.init();302 var h = Sha3_512.init();
303 h.update(block);303 h.update(&block);
304 h.final(out[0..]);304 h.final(out[0..]);
305}305}
lib/std/crypto/test.zig+2-2
...@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu...@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
8 var h: [expected.len / 2]u8 = undefined;8 var h: [expected.len / 2]u8 = undefined;
9 Hasher.hash(input, h[0..]);9 Hasher.hash(input, h[0..]);
1010
11 assertEqual(expected, h);11 assertEqual(expected, &h);
12}12}
1313
14// Assert `expected` == `input` where `input` is a bytestring.14// Assert `expected` == `input` where `input` is a bytestring.
...@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {...@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
18 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;18 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
19 }19 }
2020
21 testing.expectEqualSlices(u8, expected_bytes, input);21 testing.expectEqualSlices(u8, &expected_bytes, input);
22}22}
lib/std/crypto/x25519.zig+18-18
...@@ -63,7 +63,7 @@ pub const X25519 = struct {...@@ -63,7 +63,7 @@ pub const X25519 = struct {
63 var pos: isize = 254;63 var pos: isize = 254;
64 while (pos >= 0) : (pos -= 1) {64 while (pos >= 0) : (pos -= 1) {
65 // constant time conditional swap before ladder step65 // constant time conditional swap before ladder step
66 const b = scalarBit(e, @intCast(usize, pos));66 const b = scalarBit(&e, @intCast(usize, pos));
67 swap ^= b; // xor trick avoids swapping at the end of the loop67 swap ^= b; // xor trick avoids swapping at the end of the loop
68 Fe.cswap(x2, x3, swap);68 Fe.cswap(x2, x3, swap);
69 Fe.cswap(z2, z3, swap);69 Fe.cswap(z2, z3, swap);
...@@ -117,7 +117,7 @@ pub const X25519 = struct {...@@ -117,7 +117,7 @@ pub const X25519 = struct {
117117
118 pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {118 pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
119 var base_point = [_]u8{9} ++ [_]u8{0} ** 31;119 var base_point = [_]u8{9} ++ [_]u8{0} ** 31;
120 return create(public_key, private_key, base_point);120 return create(public_key, private_key, &base_point);
121 }121 }
122};122};
123123
...@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {...@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
581 var pk_calculated: [32]u8 = undefined;581 var pk_calculated: [32]u8 = undefined;
582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");582 try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");583 try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));584 std.testing.expect(X25519.createPublicKey(pk_calculated[0..], &sk));
585 std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));585 std.testing.expect(std.mem.eql(u8, &pk_calculated, &pk_expected));
586}586}
587587
588test "x25519 rfc7748 vector1" {588test "x25519 rfc7748 vector1" {
...@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {...@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {
594 var output: [32]u8 = undefined;594 var output: [32]u8 = undefined;
595595
596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));596 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
597 std.testing.expect(std.mem.eql(u8, output, expected_output));597 std.testing.expect(std.mem.eql(u8, &output, expected_output));
598}598}
599599
600test "x25519 rfc7748 vector2" {600test "x25519 rfc7748 vector2" {
...@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {...@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {
606 var output: [32]u8 = undefined;606 var output: [32]u8 = undefined;
607607
608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));608 std.testing.expect(X25519.create(output[0..], secret_key, public_key));
609 std.testing.expect(std.mem.eql(u8, output, expected_output));609 std.testing.expect(std.mem.eql(u8, &output, expected_output));
610}610}
611611
612test "x25519 rfc7748 one iteration" {612test "x25519 rfc7748 one iteration" {
613 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;613 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;
614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79".*;614 const expected_output = "\x42\x2c\x8e\x7a\x62\x27\xd7\xbc\xa1\x35\x0b\x3e\x2b\xb7\x27\x9f\x78\x97\xb8\x7b\xb6\x85\x4b\x78\x3c\x60\xe8\x03\x11\xae\x30\x79";
615615
616 var k: [32]u8 = initial_value;616 var k: [32]u8 = initial_value;
617 var u: [32]u8 = initial_value;617 var u: [32]u8 = initial_value;
...@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {...@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {
619 var i: usize = 0;619 var i: usize = 0;
620 while (i < 1) : (i += 1) {620 while (i < 1) : (i += 1) {
621 var output: [32]u8 = undefined;621 var output: [32]u8 = undefined;
622 std.testing.expect(X25519.create(output[0..], k, u));622 std.testing.expect(X25519.create(output[0..], &k, &u));
623623
624 std.mem.copy(u8, u[0..], k[0..]);624 std.mem.copy(u8, u[0..], k[0..]);
625 std.mem.copy(u8, k[0..], output[0..]);625 std.mem.copy(u8, k[0..], output[0..]);
...@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {...@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {
634 return error.SkipZigTest;634 return error.SkipZigTest;
635 }635 }
636636
637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;637 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51".*;638 const expected_output = "\x68\x4c\xf5\x9b\xa8\x33\x09\x55\x28\x00\xef\x56\x6f\x2f\x4d\x3c\x1c\x38\x87\xc4\x93\x60\xe3\x87\x5f\x2e\xb9\x4d\x99\x53\x2c\x51";
639639
640 var k: [32]u8 = initial_value;640 var k: [32]u8 = initial_value.*;
641 var u: [32]u8 = initial_value;641 var u: [32]u8 = initial_value.*;
642642
643 var i: usize = 0;643 var i: usize = 0;
644 while (i < 1000) : (i += 1) {644 while (i < 1000) : (i += 1) {
645 var output: [32]u8 = undefined;645 var output: [32]u8 = undefined;
646 std.testing.expect(X25519.create(output[0..], k, u));646 std.testing.expect(X25519.create(output[0..], &k, &u));
647647
648 std.mem.copy(u8, u[0..], k[0..]);648 std.mem.copy(u8, u[0..], k[0..]);
649 std.mem.copy(u8, k[0..], output[0..]);649 std.mem.copy(u8, k[0..], output[0..]);
...@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {...@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {
657 return error.SkipZigTest;657 return error.SkipZigTest;
658 }658 }
659659
660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00".*;660 const initial_value = "\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24".*;661 const expected_output = "\x7c\x39\x11\xe0\xab\x25\x86\xfd\x86\x44\x97\x29\x7e\x57\x5e\x6f\x3b\xc6\x01\xc0\x88\x3c\x30\xdf\x5f\x4d\xd2\xd2\x4f\x66\x54\x24";
662662
663 var k: [32]u8 = initial_value;663 var k: [32]u8 = initial_value.*;
664 var u: [32]u8 = initial_value;664 var u: [32]u8 = initial_value.*;
665665
666 var i: usize = 0;666 var i: usize = 0;
667 while (i < 1000000) : (i += 1) {667 while (i < 1000000) : (i += 1) {
668 var output: [32]u8 = undefined;668 var output: [32]u8 = undefined;
669 std.testing.expect(X25519.create(output[0..], k, u));669 std.testing.expect(X25519.create(output[0..], &k, &u));
670670
671 std.mem.copy(u8, u[0..], k[0..]);671 std.mem.copy(u8, u[0..], k[0..]);
672 std.mem.copy(u8, k[0..], output[0..]);672 std.mem.copy(u8, k[0..], output[0..]);
lib/std/debug.zig+4-4
...@@ -825,7 +825,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {...@@ -825,7 +825,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
825 const len = try di.coff.getPdbPath(path_buf[0..]);825 const len = try di.coff.getPdbPath(path_buf[0..]);
826 const raw_path = path_buf[0..len];826 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
830 try di.pdb.openFile(di.coff, path);830 try di.pdb.openFile(di.coff, path);
831831
...@@ -834,10 +834,10 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {...@@ -834,10 +834,10 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
834 const signature = try pdb_stream.stream.readIntLittle(u32);834 const signature = try pdb_stream.stream.readIntLittle(u32);
835 const age = try pdb_stream.stream.readIntLittle(u32);835 const age = try pdb_stream.stream.readIntLittle(u32);
836 var guid: [16]u8 = undefined;836 var guid: [16]u8 = undefined;
837 try pdb_stream.stream.readNoEof(guid[0..]);837 try pdb_stream.stream.readNoEof(&guid);
838 if (version != 20000404) // VC70, only value observed by LLVM team838 if (version != 20000404) // VC70, only value observed by LLVM team
839 return error.UnknownPDBVersion;839 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)
841 return error.PDBMismatch;841 return error.PDBMismatch;
842 // We validated the executable and pdb match.842 // We validated the executable and pdb match.
843843
...@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {...@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {
1916 return error.InvalidDebugInfo;1916 return error.InvalidDebugInfo;
1917 } else1917 } else
1918 self.include_dirs[file_entry.dir_index];1918 self.include_dirs[file_entry.dir_index];
1919 const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name });1919 const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name });
1920 errdefer self.file_entries.allocator.free(file_name);1920 errdefer self.file_entries.allocator.free(file_name);
1921 return LineInfo{1921 return LineInfo{
1922 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,1922 .line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,
lib/std/elf.zig+1-1
...@@ -381,7 +381,7 @@ pub const Elf = struct {...@@ -381,7 +381,7 @@ pub const Elf = struct {
381381
382 var magic: [4]u8 = undefined;382 var magic: [4]u8 = undefined;
383 try in.readNoEof(magic[0..]);383 try in.readNoEof(magic[0..]);
384 if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat;384 if (!mem.eql(u8, &magic, "\x7fELF")) return error.InvalidFormat;
385385
386 elf.is_64 = switch (try in.readByte()) {386 elf.is_64 = switch (try in.readByte()) {
387 1 => false,387 1 => false,
lib/std/event/fs.zig+1-1
...@@ -695,7 +695,7 @@ pub fn readFile(allocator: *Allocator, file_path: []const u8, max_size: usize) !...@@ -695,7 +695,7 @@ pub fn readFile(allocator: *Allocator, file_path: []const u8, max_size: usize) !
695 try list.ensureCapacity(list.len + mem.page_size);695 try list.ensureCapacity(list.len + mem.page_size);
696 const buf = list.items[list.len..];696 const buf = list.items[list.len..];
697 const buf_array = [_][]u8{buf};697 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);
699 list.len += amt;699 list.len += amt;
700 if (list.len > max_size) {700 if (list.len > max_size) {
701 return error.FileTooBig;701 return error.FileTooBig;
lib/std/event/loop.zig+2-2
...@@ -237,7 +237,7 @@ pub const Loop = struct {...@@ -237,7 +237,7 @@ pub const Loop = struct {
237 var extra_thread_index: usize = 0;237 var extra_thread_index: usize = 0;
238 errdefer {238 errdefer {
239 // writing 8 bytes to an eventfd cannot fail239 // writing 8 bytes to an eventfd cannot fail
240 os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;240 os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
241 while (extra_thread_index != 0) {241 while (extra_thread_index != 0) {
242 extra_thread_index -= 1;242 extra_thread_index -= 1;
243 self.extra_threads[extra_thread_index].wait();243 self.extra_threads[extra_thread_index].wait();
...@@ -684,7 +684,7 @@ pub const Loop = struct {...@@ -684,7 +684,7 @@ pub const Loop = struct {
684 .linux => {684 .linux => {
685 self.posixFsRequest(&self.os_data.fs_end_request);685 self.posixFsRequest(&self.os_data.fs_end_request);
686 // writing 8 bytes to an eventfd cannot fail686 // writing 8 bytes to an eventfd cannot fail
687 noasync os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;687 noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
688 return;688 return;
689 },689 },
690 .macosx, .freebsd, .netbsd, .dragonfly => {690 .macosx, .freebsd, .netbsd, .dragonfly => {
lib/std/fifo.zig+5-5
...@@ -70,7 +70,7 @@ pub fn LinearFifo(...@@ -70,7 +70,7 @@ pub fn LinearFifo(
70 pub fn init(allocator: *Allocator) Self {70 pub fn init(allocator: *Allocator) Self {
71 return .{71 return .{
72 .allocator = allocator,72 .allocator = allocator,
73 .buf = [_]T{},73 .buf = &[_]T{},
74 .head = 0,74 .head = 0,
75 .count = 0,75 .count = 0,
76 };76 };
...@@ -143,7 +143,7 @@ pub fn LinearFifo(...@@ -143,7 +143,7 @@ pub fn LinearFifo(
143143
144 /// Returns a writable slice from the 'read' end of the fifo144 /// Returns a writable slice from the 'read' end of the fifo
145 fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {145 fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {
146 if (offset > self.count) return [_]T{};146 if (offset > self.count) return &[_]T{};
147147
148 var start = self.head + offset;148 var start = self.head + offset;
149 if (start >= self.buf.len) {149 if (start >= self.buf.len) {
...@@ -223,7 +223,7 @@ pub fn LinearFifo(...@@ -223,7 +223,7 @@ pub fn LinearFifo(
223 /// Returns the first section of writable buffer223 /// Returns the first section of writable buffer
224 /// Note that this may be of length 0224 /// Note that this may be of length 0
225 pub fn writableSlice(self: SliceSelfArg, offset: usize) []T {225 pub fn writableSlice(self: SliceSelfArg, offset: usize) []T {
226 if (offset > self.buf.len) return [_]T{};226 if (offset > self.buf.len) return &[_]T{};
227227
228 const tail = self.head + offset + self.count;228 const tail = self.head + offset + self.count;
229 if (tail < self.buf.len) {229 if (tail < self.buf.len) {
...@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {...@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {
357 {357 {
358 var i: usize = 0;358 var i: usize = 0;
359 while (i < 5) : (i += 1) {359 while (i < 5) : (i += 1) {
360 try fifo.write([_]u8{try fifo.peekItem(i)});360 try fifo.write(&[_]u8{try fifo.peekItem(i)});
361 }361 }
362 testing.expectEqual(@as(usize, 10), fifo.readableLength());362 testing.expectEqual(@as(usize, 10), fifo.readableLength());
363 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));363 testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
...@@ -426,7 +426,7 @@ test "LinearFifo" {...@@ -426,7 +426,7 @@ test "LinearFifo" {
426 };426 };
427 defer fifo.deinit();427 defer fifo.deinit();
428428
429 try fifo.write([_]T{ 0, 1, 1, 0, 1 });429 try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
430 testing.expectEqual(@as(usize, 5), fifo.readableLength());430 testing.expectEqual(@as(usize, 5), fifo.readableLength());
431431
432 {432 {
lib/std/fmt.zig+15-10
...@@ -451,13 +451,18 @@ pub fn formatType(...@@ -451,13 +451,18 @@ pub fn formatType(
451 },451 },
452 },452 },
453 .Array => |info| {453 .Array => |info| {
454 if (info.child == u8) {454 const Slice = @Type(builtin.TypeInfo{
455 return formatText(value, fmt, options, context, Errors, output);455 .Pointer = .{
456 }456 .size = .Slice,
457 if (value.len == 0) {457 .is_const = true,
458 return format(context, Errors, output, "[0]{}", @typeName(T.Child));458 .is_volatile = false,
459 }459 .is_allowzero = false,
460 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));460 .alignment = @alignOf(info.child),
461 .child = info.child,
462 .sentinel = null,
463 },
464 });
465 return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
461 },466 },
462 .Fn => {467 .Fn => {
463 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));468 return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
...@@ -872,8 +877,8 @@ pub fn formatBytes(...@@ -872,8 +877,8 @@ pub fn formatBytes(
872 }877 }
873878
874 const buf = switch (radix) {879 const buf = switch (radix) {
875 1000 => [_]u8{ suffix, 'B' },880 1000 => &[_]u8{ suffix, 'B' },
876 1024 => [_]u8{ suffix, 'i', 'B' },881 1024 => &[_]u8{ suffix, 'i', 'B' },
877 else => unreachable,882 else => unreachable,
878 };883 };
879 return output(context, buf);884 return output(context, buf);
...@@ -969,7 +974,7 @@ fn formatIntUnsigned(...@@ -969,7 +974,7 @@ fn formatIntUnsigned(
969 if (leftover_padding == 0) break;974 if (leftover_padding == 0) break;
970 }975 }
971 mem.set(u8, buf[0..index], options.fill);976 mem.set(u8, buf[0..index], options.fill);
972 return output(context, buf);977 return output(context, &buf);
973 } else {978 } else {
974 const padded_buf = buf[index - padding ..];979 const padded_buf = buf[index - padding ..];
975 mem.set(u8, padded_buf[0..padding], options.fill);980 mem.set(u8, padded_buf[0..padding], options.fill);
lib/std/fs.zig+4-4
...@@ -58,7 +58,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:...@@ -58,7 +58,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
58 tmp_path[dirname.len] = path.sep;58 tmp_path[dirname.len] = path.sep;
59 while (true) {59 while (true) {
60 try crypto.randomBytes(rand_buf[0..]);60 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
63 if (symLink(existing_path, tmp_path)) {63 if (symLink(existing_path, tmp_path)) {
64 return rename(tmp_path, new_path);64 return rename(tmp_path, new_path);
...@@ -226,7 +226,7 @@ pub const AtomicFile = struct {...@@ -226,7 +226,7 @@ pub const AtomicFile = struct {
226226
227 while (true) {227 while (true) {
228 try crypto.randomBytes(rand_buf[0..]);228 try crypto.randomBytes(rand_buf[0..]);
229 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf);229 b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], &rand_buf);
230230
231 // TODO https://github.com/ziglang/zig/issues/3770 to clean up this @ptrCast231 // TODO https://github.com/ziglang/zig/issues/3770 to clean up this @ptrCast
232 const file = my_cwd.createFileC(232 const file = my_cwd.createFileC(
...@@ -292,7 +292,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {...@@ -292,7 +292,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {
292/// have been modified regardless.292/// have been modified regardless.
293/// TODO determine if we can remove the allocator requirement from this function293/// TODO determine if we can remove the allocator requirement from this function
294pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {294pub 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});
296 defer allocator.free(resolved_path);296 defer allocator.free(resolved_path);
297297
298 var end_index: usize = resolved_path.len;298 var end_index: usize = resolved_path.len;
...@@ -611,7 +611,7 @@ pub const Dir = struct {...@@ -611,7 +611,7 @@ pub const Dir = struct {
611611
612 const name_utf16le = @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2];612 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{ '.', '.' }))
615 continue;615 continue;
616 // Trust that Windows gives us valid UTF-16LE616 // Trust that Windows gives us valid UTF-16LE
617 const name_utf8_len = std.unicode.utf16leToUtf8(self.name_data[0..], name_utf16le) catch unreachable;617 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...@@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
31 error.OutOfMemory => return error.OutOfMemory,31 error.OutOfMemory => return error.OutOfMemory,
32 };32 };
33 defer allocator.free(global_dir);33 defer allocator.free(global_dir);
34 return fs.path.join(allocator, [_][]const u8{ global_dir, appname });34 return fs.path.join(allocator, &[_][]const u8{ global_dir, appname });
35 },35 },
36 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,36 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
37 else => return error.AppDataDirUnavailable,37 else => return error.AppDataDirUnavailable,
...@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD...@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
42 // TODO look in /etc/passwd42 // TODO look in /etc/passwd
43 return error.AppDataDirUnavailable;43 return error.AppDataDirUnavailable;
44 };44 };
45 return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });45 return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname });
46 },46 },
47 .linux, .freebsd, .netbsd, .dragonfly => {47 .linux, .freebsd, .netbsd, .dragonfly => {
48 const home_dir = os.getenv("HOME") orelse {48 const home_dir = os.getenv("HOME") orelse {
49 // TODO look in /etc/passwd49 // TODO look in /etc/passwd
50 return error.AppDataDirUnavailable;50 return error.AppDataDirUnavailable;
51 };51 };
52 return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname });52 return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
53 },53 },
54 else => @compileError("Unsupported OS"),54 else => @compileError("Unsupported OS"),
55 }55 }
lib/std/fs/path.zig+62-60
...@@ -15,7 +15,9 @@ pub const sep_windows = '\\';...@@ -15,7 +15,9 @@ pub const sep_windows = '\\';
15pub const sep_posix = '/';15pub const sep_posix = '/';
16pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;16pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;
1717
18pub const sep_str = [1]u8{sep};18pub const sep_str_windows = "\\";
19pub const sep_str_posix = "/";
20pub const sep_str = if (builtin.os == .windows) sep_str_windows else sep_str_posix;
1921
20pub const delimiter_windows = ';';22pub const delimiter_windows = ';';
21pub const delimiter_posix = ':';23pub const delimiter_posix = ':';
...@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {...@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
101}103}
102104
103test "join" {105test "join" {
104 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");106 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
105 testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");107 testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
106 testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");108 testJoinWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
107109
108 testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");110 testJoinWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
109 testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");111 testJoinWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
110112
111 testJoinWindows(113 testJoinWindows(
112 [_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },114 &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
113 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",115 "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
114 );116 );
115117
116 testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");118 testJoinPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
117 testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c");119 testJoinPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c");
118120
119 testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");121 testJoinPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
120 testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");122 testJoinPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
121123
122 testJoinPosix(124 testJoinPosix(
123 [_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },125 &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
124 "/home/andy/dev/zig/build/lib/zig/std/io.zig",126 "/home/andy/dev/zig/build/lib/zig/std/io.zig",
125 );127 );
126128
127 testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");129 testJoinPosix(&[_][]const u8{ "a", "/c" }, "a/c");
128 testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");130 testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
129}131}
130132
131pub fn isAbsoluteC(path_c: [*:0]const u8) bool {133pub fn isAbsoluteC(path_c: [*:0]const u8) bool {
...@@ -277,7 +279,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -277,7 +279,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
277 }279 }
278 const relative_path = WindowsPath{280 const relative_path = WindowsPath{
279 .kind = WindowsPath.Kind.None,281 .kind = WindowsPath.Kind.None,
280 .disk_designator = [_]u8{},282 .disk_designator = &[_]u8{},
281 .is_abs = false,283 .is_abs = false,
282 };284 };
283 if (path.len < "//a/b".len) {285 if (path.len < "//a/b".len) {
...@@ -286,12 +288,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {...@@ -286,12 +288,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
286288
287 inline for ("/\\") |this_sep| {289 inline for ("/\\") |this_sep| {
288 const two_sep = [_]u8{ this_sep, this_sep };290 const two_sep = [_]u8{ this_sep, this_sep };
289 if (mem.startsWith(u8, path, two_sep)) {291 if (mem.startsWith(u8, path, &two_sep)) {
290 if (path[2] == this_sep) {292 if (path[2] == this_sep) {
291 return relative_path;293 return relative_path;
292 }294 }
293295
294 var it = mem.tokenize(path, [_]u8{this_sep});296 var it = mem.tokenize(path, &[_]u8{this_sep});
295 _ = (it.next() orelse return relative_path);297 _ = (it.next() orelse return relative_path);
296 _ = (it.next() orelse return relative_path);298 _ = (it.next() orelse return relative_path);
297 return WindowsPath{299 return WindowsPath{
...@@ -353,8 +355,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {...@@ -353,8 +355,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
353 const sep1 = ns1[0];355 const sep1 = ns1[0];
354 const sep2 = ns2[0];356 const sep2 = ns2[0];
355357
356 var it1 = mem.tokenize(ns1, [_]u8{sep1});358 var it1 = mem.tokenize(ns1, &[_]u8{sep1});
357 var it2 = mem.tokenize(ns2, [_]u8{sep2});359 var it2 = mem.tokenize(ns2, &[_]u8{sep2});
358360
359 // TODO ASCII is wrong, we actually need full unicode support to compare paths.361 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
360 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);362 return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
...@@ -374,8 +376,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8...@@ -374,8 +376,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
374 const sep1 = p1[0];376 const sep1 = p1[0];
375 const sep2 = p2[0];377 const sep2 = p2[0];
376378
377 var it1 = mem.tokenize(p1, [_]u8{sep1});379 var it1 = mem.tokenize(p1, &[_]u8{sep1});
378 var it2 = mem.tokenize(p2, [_]u8{sep2});380 var it2 = mem.tokenize(p2, &[_]u8{sep2});
379381
380 // TODO ASCII is wrong, we actually need full unicode support to compare paths.382 // TODO ASCII is wrong, we actually need full unicode support to compare paths.
381 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);383 return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
...@@ -668,10 +670,10 @@ test "resolve" {...@@ -668,10 +670,10 @@ test "resolve" {
668 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {670 if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
669 cwd[0] = asciiUpper(cwd[0]);671 cwd[0] = asciiUpper(cwd[0]);
670 }672 }
671 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));673 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{"."}), cwd));
672 } else {674 } else {
673 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));675 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "a/b/c/", "../../.." }), cwd));
674 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));676 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"."}), cwd));
675 }677 }
676}678}
677679
...@@ -684,8 +686,8 @@ test "resolveWindows" {...@@ -684,8 +686,8 @@ test "resolveWindows" {
684 const cwd = try process.getCwdAlloc(debug.global_allocator);686 const cwd = try process.getCwdAlloc(debug.global_allocator);
685 const parsed_cwd = windowsParsePath(cwd);687 const parsed_cwd = windowsParsePath(cwd);
686 {688 {
687 const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });689 const result = testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
688 const expected = try join(debug.global_allocator, [_][]const u8{690 const expected = try join(debug.global_allocator, &[_][]const u8{
689 parsed_cwd.disk_designator,691 parsed_cwd.disk_designator,
690 "usr\\local\\lib\\zig\\std\\array_list.zig",692 "usr\\local\\lib\\zig\\std\\array_list.zig",
691 });693 });
...@@ -695,8 +697,8 @@ test "resolveWindows" {...@@ -695,8 +697,8 @@ test "resolveWindows" {
695 testing.expect(mem.eql(u8, result, expected));697 testing.expect(mem.eql(u8, result, expected));
696 }698 }
697 {699 {
698 const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });700 const result = testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" });
699 const expected = try join(debug.global_allocator, [_][]const u8{701 const expected = try join(debug.global_allocator, &[_][]const u8{
700 cwd,702 cwd,
701 "usr\\local\\lib\\zig",703 "usr\\local\\lib\\zig",
702 });704 });
...@@ -707,32 +709,32 @@ test "resolveWindows" {...@@ -707,32 +709,32 @@ test "resolveWindows" {
707 }709 }
708 }710 }
709711
710 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));712 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"));713 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"));714 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"));715 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"));716 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"));717 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"));718 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:\\"));719 testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//" }), "C:\\"));
718 testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));720 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\\"));721 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\\"));722 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"));723 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"));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"));
723}725}
724726
725test "resolvePosix" {727test "resolvePosix" {
726 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));728 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"));729 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"));730 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
729 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));731 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/", "..", ".." }), "/"));
730 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));732 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"/a/b/c/"}), "/a/b/c"));
731733
732 testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));734 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"));735 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"));736 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"));737 testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
736}738}
737739
738fn testResolveWindows(paths: []const []const u8) []u8 {740fn testResolveWindows(paths: []const []const u8) []u8 {
...@@ -887,12 +889,12 @@ pub fn basename(path: []const u8) []const u8 {...@@ -887,12 +889,12 @@ pub fn basename(path: []const u8) []const u8 {
887889
888pub fn basenamePosix(path: []const u8) []const u8 {890pub fn basenamePosix(path: []const u8) []const u8 {
889 if (path.len == 0)891 if (path.len == 0)
890 return [_]u8{};892 return &[_]u8{};
891893
892 var end_index: usize = path.len - 1;894 var end_index: usize = path.len - 1;
893 while (path[end_index] == '/') {895 while (path[end_index] == '/') {
894 if (end_index == 0)896 if (end_index == 0)
895 return [_]u8{};897 return &[_]u8{};
896 end_index -= 1;898 end_index -= 1;
897 }899 }
898 var start_index: usize = end_index;900 var start_index: usize = end_index;
...@@ -908,19 +910,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {...@@ -908,19 +910,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
908910
909pub fn basenameWindows(path: []const u8) []const u8 {911pub fn basenameWindows(path: []const u8) []const u8 {
910 if (path.len == 0)912 if (path.len == 0)
911 return [_]u8{};913 return &[_]u8{};
912914
913 var end_index: usize = path.len - 1;915 var end_index: usize = path.len - 1;
914 while (true) {916 while (true) {
915 const byte = path[end_index];917 const byte = path[end_index];
916 if (byte == '/' or byte == '\\') {918 if (byte == '/' or byte == '\\') {
917 if (end_index == 0)919 if (end_index == 0)
918 return [_]u8{};920 return &[_]u8{};
919 end_index -= 1;921 end_index -= 1;
920 continue;922 continue;
921 }923 }
922 if (byte == ':' and end_index == 1) {924 if (byte == ':' and end_index == 1) {
923 return [_]u8{};925 return &[_]u8{};
924 }926 }
925 break;927 break;
926 }928 }
...@@ -1002,11 +1004,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {...@@ -1002,11 +1004,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
1002}1004}
10031005
1004pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {1006pub 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});
1006 defer allocator.free(resolved_from);1008 defer allocator.free(resolved_from);
10071009
1008 var clean_up_resolved_to = true;1010 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});
1010 defer if (clean_up_resolved_to) allocator.free(resolved_to);1012 defer if (clean_up_resolved_to) allocator.free(resolved_to);
10111013
1012 const parsed_from = windowsParsePath(resolved_from);1014 const parsed_from = windowsParsePath(resolved_from);
...@@ -1075,10 +1077,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)...@@ -1075,10 +1077,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
1075}1077}
10761078
1077pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {1079pub 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});
1079 defer allocator.free(resolved_from);1081 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});
1082 defer allocator.free(resolved_to);1084 defer allocator.free(resolved_to);
10831085
1084 var from_it = mem.tokenize(resolved_from, "/");1086 var from_it = mem.tokenize(resolved_from, "/");
lib/std/hash/cityhash.zig+1-1
...@@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
367 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);367 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
368 }368 }
369369
370 return @truncate(u32, hash_fn(hashes, 0));370 return @truncate(u32, hash_fn(&hashes, 0));
371}371}
372372
373fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {373fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
lib/std/hash/murmur.zig+1-1
...@@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300 }300 }
301301
302 return @truncate(u32, hash_fn(hashes, 0));302 return @truncate(u32, hash_fn(&hashes, 0));
303}303}
304304
305test "murmur2_32" {305test "murmur2_32" {
lib/std/hash_map.zig+1-1
...@@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3...@@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
9494
95 pub fn init(allocator: *Allocator) Self {95 pub fn init(allocator: *Allocator) Self {
96 return Self{96 return Self{
97 .entries = [_]Entry{},97 .entries = &[_]Entry{},
98 .allocator = allocator,98 .allocator = allocator,
99 .size = 0,99 .size = 0,
100 .max_distance_from_start_index = 0,100 .max_distance_from_start_index = 0,
lib/std/http/headers.zig+2-2
...@@ -514,8 +514,8 @@ test "Headers.getIndices" {...@@ -514,8 +514,8 @@ test "Headers.getIndices" {
514 try h.append("set-cookie", "y=2", null);514 try h.append("set-cookie", "y=2", null);
515515
516 testing.expect(null == h.getIndices("not-present"));516 testing.expect(null == h.getIndices("not-present"));
517 testing.expectEqualSlices(usize, [_]usize{0}, h.getIndices("foo").?.toSliceConst());517 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
518 testing.expectEqualSlices(usize, [_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());518 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
519}519}
520520
521test "Headers.get" {521test "Headers.get" {
lib/std/io.zig+1-1
...@@ -1104,7 +1104,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1104,7 +1104,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1104 byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);1104 byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);
1105 }1105 }
11061106
1107 try self.out_stream.write(buffer);1107 try self.out_stream.write(&buffer);
1108 }1108 }
11091109
1110 /// Serializes the passed value into the stream1110 /// Serializes the passed value into the stream
lib/std/io/out_stream.zig+5-5
...@@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type {
56 pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {56 pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {
57 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;57 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
58 mem.writeIntNative(T, &bytes, value);58 mem.writeIntNative(T, &bytes, value);
59 return self.writeFn(self, bytes);59 return self.writeFn(self, &bytes);
60 }60 }
6161
62 /// Write a foreign-endian integer.62 /// Write a foreign-endian integer.
63 pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {63 pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {
64 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;64 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
65 mem.writeIntForeign(T, &bytes, value);65 mem.writeIntForeign(T, &bytes, value);
66 return self.writeFn(self, bytes);66 return self.writeFn(self, &bytes);
67 }67 }
6868
69 pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {69 pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {
70 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;70 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
71 mem.writeIntLittle(T, &bytes, value);71 mem.writeIntLittle(T, &bytes, value);
72 return self.writeFn(self, bytes);72 return self.writeFn(self, &bytes);
73 }73 }
7474
75 pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {75 pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {
76 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;76 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
77 mem.writeIntBig(T, &bytes, value);77 mem.writeIntBig(T, &bytes, value);
78 return self.writeFn(self, bytes);78 return self.writeFn(self, &bytes);
79 }79 }
8080
81 pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {81 pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
82 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;82 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
83 mem.writeInt(T, &bytes, value, endian);83 mem.writeInt(T, &bytes, value, endian);
84 return self.writeFn(self, bytes);84 return self.writeFn(self, &bytes);
85 }85 }
86 };86 };
87}87}
lib/std/io/test.zig+4-4
...@@ -57,7 +57,7 @@ test "write a file, read it, then delete it" {...@@ -57,7 +57,7 @@ test "write a file, read it, then delete it" {
57 defer allocator.free(contents);57 defer allocator.free(contents);
5858
59 expect(mem.eql(u8, contents[0.."begin".len], "begin"));59 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));
61 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));61 expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
62 }62 }
63 try cwd.deleteFile(tmp_file_name);63 try cwd.deleteFile(tmp_file_name);
...@@ -79,7 +79,7 @@ test "BufferOutStream" {...@@ -79,7 +79,7 @@ test "BufferOutStream" {
7979
80test "SliceInStream" {80test "SliceInStream" {
81 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };81 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
84 var dest: [4]u8 = undefined;84 var dest: [4]u8 = undefined;
8585
...@@ -97,7 +97,7 @@ test "SliceInStream" {...@@ -97,7 +97,7 @@ test "SliceInStream" {
9797
98test "PeekStream" {98test "PeekStream" {
99 const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };99 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);
101 var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);101 var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
102102
103 var dest: [4]u8 = undefined;103 var dest: [4]u8 = undefined;
...@@ -616,7 +616,7 @@ test "File seek ops" {...@@ -616,7 +616,7 @@ test "File seek ops" {
616 fs.cwd().deleteFile(tmp_file_name) catch {};616 fs.cwd().deleteFile(tmp_file_name) catch {};
617 }617 }
618618
619 try file.write([_]u8{0x55} ** 8192);619 try file.write(&([_]u8{0x55} ** 8192));
620620
621 // Seek to the end621 // Seek to the end
622 try file.seekFromEnd(0);622 try file.seekFromEnd(0);
lib/std/mem.zig+52-76
...@@ -624,23 +624,23 @@ test "comptime read/write int" {...@@ -624,23 +624,23 @@ test "comptime read/write int" {
624}624}
625625
626test "readIntBig and readIntLittle" {626test "readIntBig and readIntLittle" {
627 testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);627 testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
628 testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);628 testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
629629
630 testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);630 testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
631 testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);631 testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
632632
633 testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);633 testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
634 testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);634 testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
635635
636 testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);636 testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
637 testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);637 testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
638638
639 testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1);639 testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
640 testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);640 testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
641641
642 testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);642 testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
643 testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);643 testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
644}644}
645645
646/// Writes an integer to memory, storing it in twos-complement.646/// Writes an integer to memory, storing it in twos-complement.
...@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {...@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {
749 var buf9: [9]u8 = undefined;749 var buf9: [9]u8 = undefined;
750750
751 writeIntBig(u0, &buf0, 0x0);751 writeIntBig(u0, &buf0, 0x0);
752 testing.expect(eql(u8, buf0[0..], [_]u8{}));752 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
753 writeIntLittle(u0, &buf0, 0x0);753 writeIntLittle(u0, &buf0, 0x0);
754 testing.expect(eql(u8, buf0[0..], [_]u8{}));754 testing.expect(eql(u8, buf0[0..], &[_]u8{}));
755755
756 writeIntBig(u8, &buf1, 0x12);756 writeIntBig(u8, &buf1, 0x12);
757 testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));757 testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
758 writeIntLittle(u8, &buf1, 0x34);758 writeIntLittle(u8, &buf1, 0x34);
759 testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));759 testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
760760
761 writeIntBig(u16, &buf2, 0x1234);761 writeIntBig(u16, &buf2, 0x1234);
762 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));762 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
763 writeIntLittle(u16, &buf2, 0x5678);763 writeIntLittle(u16, &buf2, 0x5678);
764 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));764 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
765765
766 writeIntBig(u72, &buf9, 0x123456789abcdef024);766 writeIntBig(u72, &buf9, 0x123456789abcdef024);
767 testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));767 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
768 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);768 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
769 testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));769 testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
770770
771 writeIntBig(i8, &buf1, -1);771 writeIntBig(i8, &buf1, -1);
772 testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));772 testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
773 writeIntLittle(i8, &buf1, -2);773 writeIntLittle(i8, &buf1, -2);
774 testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));774 testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
775775
776 writeIntBig(i16, &buf2, -3);776 writeIntBig(i16, &buf2, -3);
777 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));777 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
778 writeIntLittle(i16, &buf2, -4);778 writeIntLittle(i16, &buf2, -4);
779 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));779 testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
780}780}
781781
782/// Returns an iterator that iterates over the slices of `buffer` that are not782/// Returns an iterator that iterates over the slices of `buffer` that are not
...@@ -1004,9 +1004,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons...@@ -1004,9 +1004,9 @@ pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []cons
1004test "mem.join" {1004test "mem.join" {
1005 var buf: [1024]u8 = undefined;1005 var buf: [1024]u8 = undefined;
1006 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;1006 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1007 testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c"));1007 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c"));
1008 testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a"));1008 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a"));
1009 testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));1009 testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
1010}1010}
10111011
1012/// Copies each T from slices into a new slice that exactly holds all the elements.1012/// Copies each T from slices into a new slice that exactly holds all the elements.
...@@ -1037,13 +1037,13 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T...@@ -1037,13 +1037,13 @@ pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T
1037test "concat" {1037test "concat" {
1038 var buf: [1024]u8 = undefined;1038 var buf: [1024]u8 = undefined;
1039 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;1039 const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
1040 testing.expect(eql(u8, try concat(a, u8, [_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));1040 testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
1041 testing.expect(eql(u32, try concat(a, u32, [_][]const u32{1041 testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{
1042 [_]u32{ 0, 1 },1042 &[_]u32{ 0, 1 },
1043 [_]u32{ 2, 3, 4 },1043 &[_]u32{ 2, 3, 4 },
1044 [_]u32{},1044 &[_]u32{},
1045 [_]u32{5},1045 &[_]u32{5},
1046 }), [_]u32{ 0, 1, 2, 3, 4, 5 }));1046 }), &[_]u32{ 0, 1, 2, 3, 4, 5 }));
1047}1047}
10481048
1049test "testStringEquality" {1049test "testStringEquality" {
...@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {...@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {
1111 var bytes: [8]u8 = undefined;1111 var bytes: [8]u8 = undefined;
11121112
1113 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);1113 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
1114 testing.expect(eql(u8, bytes, [_]u8{1114 testing.expect(eql(u8, &bytes, &[_]u8{
1115 0x00, 0x00, 0x00, 0x00,1115 0x00, 0x00, 0x00, 0x00,
1116 0x00, 0x00, 0x00, 0x00,1116 0x00, 0x00, 0x00, 0x00,
1117 }));1117 }));
11181118
1119 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);1119 writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
1120 testing.expect(eql(u8, bytes, [_]u8{1120 testing.expect(eql(u8, &bytes, &[_]u8{
1121 0x00, 0x00, 0x00, 0x00,1121 0x00, 0x00, 0x00, 0x00,
1122 0x00, 0x00, 0x00, 0x00,1122 0x00, 0x00, 0x00, 0x00,
1123 }));1123 }));
11241124
1125 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);1125 writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
1126 testing.expect(eql(u8, bytes, [_]u8{1126 testing.expect(eql(u8, &bytes, &[_]u8{
1127 0x12,1127 0x12,
1128 0x34,1128 0x34,
1129 0x56,1129 0x56,
...@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {...@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {
1135 }));1135 }));
11361136
1137 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);1137 writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
1138 testing.expect(eql(u8, bytes, [_]u8{1138 testing.expect(eql(u8, &bytes, &[_]u8{
1139 0x12,1139 0x12,
1140 0x34,1140 0x34,
1141 0x56,1141 0x56,
...@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {...@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {
1147 }));1147 }));
11481148
1149 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);1149 writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
1150 testing.expect(eql(u8, bytes, [_]u8{1150 testing.expect(eql(u8, &bytes, &[_]u8{
1151 0x00,1151 0x00,
1152 0x00,1152 0x00,
1153 0x00,1153 0x00,
...@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {...@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {
1159 }));1159 }));
11601160
1161 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);1161 writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
1162 testing.expect(eql(u8, bytes, [_]u8{1162 testing.expect(eql(u8, &bytes, &[_]u8{
1163 0x12,1163 0x12,
1164 0x34,1164 0x34,
1165 0x56,1165 0x56,
...@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {...@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {
1171 }));1171 }));
11721172
1173 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);1173 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
1174 testing.expect(eql(u8, bytes, [_]u8{1174 testing.expect(eql(u8, &bytes, &[_]u8{
1175 0x00,1175 0x00,
1176 0x00,1176 0x00,
1177 0x00,1177 0x00,
...@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {...@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {
1183 }));1183 }));
11841184
1185 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);1185 writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
1186 testing.expect(eql(u8, bytes, [_]u8{1186 testing.expect(eql(u8, &bytes, &[_]u8{
1187 0x34,1187 0x34,
1188 0x12,1188 0x12,
1189 0x00,1189 0x00,
...@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {...@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {
1235}1235}
12361236
1237test "reverse" {1237test "reverse" {
1238 var arr = [_]i32{1238 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1239 5,
1240 3,
1241 1,
1242 2,
1243 4,
1244 };
1245 reverse(i32, arr[0..]);1239 reverse(i32, arr[0..]);
12461240
1247 testing.expect(eql(i32, arr, [_]i32{1241 testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
1248 4,
1249 2,
1250 1,
1251 3,
1252 5,
1253 }));
1254}1242}
12551243
1256/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)1244/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
...@@ -1262,22 +1250,10 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {...@@ -1262,22 +1250,10 @@ pub fn rotate(comptime T: type, items: []T, amount: usize) void {
1262}1250}
12631251
1264test "rotate" {1252test "rotate" {
1265 var arr = [_]i32{1253 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1266 5,
1267 3,
1268 1,
1269 2,
1270 4,
1271 };
1272 rotate(i32, arr[0..], 2);1254 rotate(i32, arr[0..], 2);
12731255
1274 testing.expect(eql(i32, arr, [_]i32{1256 testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
1275 1,
1276 2,
1277 4,
1278 5,
1279 3,
1280 }));
1281}1257}
12821258
1283/// Converts a little-endian integer to host endianness.1259/// Converts a little-endian integer to host endianness.
...@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {...@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
1394test "toBytes" {1370test "toBytes" {
1395 var my_bytes = toBytes(@as(u32, 0x12345678));1371 var my_bytes = toBytes(@as(u32, 0x12345678));
1396 switch (builtin.endian) {1372 switch (builtin.endian) {
1397 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),1373 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
1398 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),1374 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
1399 }1375 }
14001376
1401 my_bytes[0] = '\x99';1377 my_bytes[0] = '\x99';
1402 switch (builtin.endian) {1378 switch (builtin.endian) {
1403 builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x99\x34\x56\x78")),1379 builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
1404 builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x99\x56\x34\x12")),1380 builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
1405 }1381 }
1406}1382}
14071383
...@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA...@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
1495test "subArrayPtr" {1471test "subArrayPtr" {
1496 const a1: [6]u8 = "abcdef".*;1472 const a1: [6]u8 = "abcdef".*;
1497 const sub1 = subArrayPtr(&a1, 2, 3);1473 const sub1 = subArrayPtr(&a1, 2, 3);
1498 testing.expect(eql(u8, sub1.*, "cde"));1474 testing.expect(eql(u8, sub1, "cde"));
14991475
1500 var a2: [6]u8 = "abcdef".*;1476 var a2: [6]u8 = "abcdef".*;
1501 var sub2 = subArrayPtr(&a2, 2, 3);1477 var sub2 = subArrayPtr(&a2, 2, 3);
15021478
1503 testing.expect(eql(u8, sub2, "cde"));1479 testing.expect(eql(u8, sub2, "cde"));
1504 sub2[1] = 'X';1480 sub2[1] = 'X';
1505 testing.expect(eql(u8, a2, "abcXef"));1481 testing.expect(eql(u8, &a2, "abcXef"));
1506}1482}
15071483
1508/// Round an address up to the nearest aligned address1484/// Round an address up to the nearest aligned address
lib/std/meta/trait.zig+1-1
...@@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {...@@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
46 }46 }
47 };47 };
4848
49 const isVector = multiTrait([_]TraitFn{49 const isVector = multiTrait(&[_]TraitFn{
50 hasFn("add"),50 hasFn("add"),
51 hasField("x"),51 hasField("x"),
52 hasField("y"),52 hasField("y"),
lib/std/net.zig+4-4
...@@ -291,7 +291,7 @@ pub const Address = extern union {...@@ -291,7 +291,7 @@ pub const Address = extern union {
291 },291 },
292 os.AF_INET6 => {292 os.AF_INET6 => {
293 const port = mem.bigToNative(u16, self.in6.port);293 const port = mem.bigToNative(u16, self.in6.port);
294 if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {294 if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
295 try std.fmt.format(295 try std.fmt.format(
296 context,296 context,
297 Errors,297 Errors,
...@@ -339,7 +339,7 @@ pub const Address = extern union {...@@ -339,7 +339,7 @@ pub const Address = extern union {
339 unreachable;339 unreachable;
340 }340 }
341341
342 try std.fmt.format(context, Errors, output, "{}", self.un.path);342 try std.fmt.format(context, Errors, output, "{}", &self.un.path);
343 },343 },
344 else => unreachable,344 else => unreachable,
345 }345 }
...@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(...@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(
894 }894 }
895895
896 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))896 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
897 [_]u8{}897 &[_]u8{}
898 else898 else
899 rc.search.toSliceConst();899 rc.search.toSliceConst();
900900
...@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(...@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(
959959
960 for (afrrs) |afrr| {960 for (afrrs) |afrr| {
961 if (family != afrr.af) {961 if (family != afrr.af) {
962 const len = os.res_mkquery(0, name, 1, afrr.rr, [_]u8{}, null, &qbuf[nq]);962 const len = os.res_mkquery(0, name, 1, afrr.rr, &[_]u8{}, null, &qbuf[nq]);
963 qp[nq] = qbuf[nq][0..len];963 qp[nq] = qbuf[nq][0..len];
964 nq += 1;964 nq += 1;
965 }965 }
lib/std/os.zig+3-3
...@@ -1571,8 +1571,8 @@ pub fn isCygwinPty(handle: fd_t) bool {...@@ -1571,8 +1571,8 @@ pub fn isCygwinPty(handle: fd_t) bool {
1571 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);1571 const name_info = @ptrCast(*const windows.FILE_NAME_INFO, &name_info_bytes[0]);
1572 const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];1572 const name_bytes = name_info_bytes[size .. size + @as(usize, name_info.FileNameLength)];
1573 const name_wide = @bytesToSlice(u16, name_bytes);1573 const name_wide = @bytesToSlice(u16, name_bytes);
1574 return mem.indexOf(u16, name_wide, [_]u16{ 'm', 's', 'y', 's', '-' }) != null or1574 return mem.indexOf(u16, name_wide, &[_]u16{ 'm', 's', 'y', 's', '-' }) != null or
1575 mem.indexOf(u16, name_wide, [_]u16{ '-', 'p', 't', 'y' }) != null;1575 mem.indexOf(u16, name_wide, &[_]u16{ '-', 'p', 't', 'y' }) != null;
1576}1576}
15771577
1578pub const SocketError = error{1578pub const SocketError = error{
...@@ -2640,7 +2640,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real...@@ -2640,7 +2640,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real
2640 // Windows returns \\?\ prepended to the path.2640 // Windows returns \\?\ prepended to the path.
2641 // We strip it to make this function consistent across platforms.2641 // We strip it to make this function consistent across platforms.
2642 const prefix = [_]u16{ '\\', '\\', '?', '\\' };2642 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
2645 // Trust that Windows gives us valid UTF-16LE.2645 // Trust that Windows gives us valid UTF-16LE.
2646 const end_index = std.unicode.utf16leToUtf8(out_buffer, wide_slice[start_index..]) catch unreachable;2646 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" {...@@ -137,7 +137,7 @@ test "getrandom" {
137 try os.getrandom(&buf_b);137 try os.getrandom(&buf_b);
138 // If this test fails the chance is significantly higher that there is a bug than138 // If this test fails the chance is significantly higher that there is a bug than
139 // that two sets of 50 bytes were equal.139 // that two sets of 50 bytes were equal.
140 expect(!mem.eql(u8, buf_a, buf_b));140 expect(!mem.eql(u8, &buf_a, &buf_b));
141}141}
142142
143test "getcwd" {143test "getcwd" {
lib/std/os/windows.zig+3-3
...@@ -932,9 +932,9 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 {...@@ -932,9 +932,9 @@ pub fn wToPrefixedFileW(s: []const u16) ![PATH_MAX_WIDE:0]u16 {
932 // TODO https://github.com/ziglang/zig/issues/2765932 // TODO https://github.com/ziglang/zig/issues/2765
933 var result: [PATH_MAX_WIDE:0]u16 = undefined;933 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: {
936 const prefix = [_]u16{ '\\', '?', '?', '\\' };936 const prefix = [_]u16{ '\\', '?', '?', '\\' };
937 mem.copy(u16, result[0..], prefix);937 mem.copy(u16, result[0..], &prefix);
938 break :blk prefix.len;938 break :blk prefix.len;
939 };939 };
940 const end_index = start_index + s.len;940 const end_index = start_index + s.len;
...@@ -961,7 +961,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)...@@ -961,7 +961,7 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
961 }961 }
962 const start_index = if (mem.startsWith(u8, s, "\\?") or !std.fs.path.isAbsolute(s)) 0 else blk: {962 const start_index = if (mem.startsWith(u8, s, "\\?") or !std.fs.path.isAbsolute(s)) 0 else blk: {
963 const prefix = [_]u16{ '\\', '?', '?', '\\' };963 const prefix = [_]u16{ '\\', '?', '?', '\\' };
964 mem.copy(u16, result[0..], prefix);964 mem.copy(u16, result[0..], &prefix);
965 break :blk prefix.len;965 break :blk prefix.len;
966 };966 };
967 const end_index = start_index + try std.unicode.utf8ToUtf16Le(result[start_index..], s);967 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,...@@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
201 ///Return the Int stored at index201 ///Return the Int stored at index
202 pub fn get(self: Self, index: usize) Int {202 pub fn get(self: Self, index: usize) Int {
203 debug.assert(index < int_count);203 debug.assert(index < int_count);
204 return Io.get(self.bytes, index, 0);204 return Io.get(&self.bytes, index, 0);
205 }205 }
206206
207 ///Copy int into the array at index207 ///Copy int into the array at index
...@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {...@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
528test "PackedInt(Array/Slice)Endian" {528test "PackedInt(Array/Slice)Endian" {
529 {529 {
530 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);530 const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
531 var packed_array_be = PackedArrayBe.init([_]u4{531 var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
532 0,
533 1,
534 2,
535 3,
536 4,
537 5,
538 6,
539 7,
540 });
541 testing.expect(packed_array_be.bytes[0] == 0b00000001);532 testing.expect(packed_array_be.bytes[0] == 0b00000001);
542 testing.expect(packed_array_be.bytes[1] == 0b00100011);533 testing.expect(packed_array_be.bytes[1] == 0b00100011);
543534
...@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {...@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {
563554
564 {555 {
565 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);556 const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
566 var packed_array_be = PackedArrayBe.init([_]u11{557 var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
567 0,
568 1,
569 2,
570 3,
571 4,
572 5,
573 6,
574 7,
575 });
576 testing.expect(packed_array_be.bytes[0] == 0b00000000);558 testing.expect(packed_array_be.bytes[0] == 0b00000000);
577 testing.expect(packed_array_be.bytes[1] == 0b00000000);559 testing.expect(packed_array_be.bytes[1] == 0b00000000);
578 testing.expect(packed_array_be.bytes[2] == 0b00000100);560 testing.expect(packed_array_be.bytes[2] == 0b00000100);
lib/std/pdb.zig+2-2
...@@ -501,7 +501,7 @@ const Msf = struct {...@@ -501,7 +501,7 @@ const Msf = struct {
501 const superblock = try in.readStruct(SuperBlock);501 const superblock = try in.readStruct(SuperBlock);
502502
503 // Sanity checks503 // Sanity checks
504 if (!mem.eql(u8, superblock.FileMagic, SuperBlock.file_magic))504 if (!mem.eql(u8, &superblock.FileMagic, SuperBlock.file_magic))
505 return error.InvalidDebugInfo;505 return error.InvalidDebugInfo;
506 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)506 if (superblock.FreeBlockMapBlock != 1 and superblock.FreeBlockMapBlock != 2)
507 return error.InvalidDebugInfo;507 return error.InvalidDebugInfo;
...@@ -547,7 +547,7 @@ const Msf = struct {...@@ -547,7 +547,7 @@ const Msf = struct {
547 const size = stream_sizes[i];547 const size = stream_sizes[i];
548 if (size == 0) {548 if (size == 0) {
549 stream.* = MsfStream{549 stream.* = MsfStream{
550 .blocks = [_]u32{},550 .blocks = &[_]u32{},
551 };551 };
552 } else {552 } else {
553 var blocks = try allocator.alloc(u32, size);553 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 {...@@ -22,7 +22,7 @@ pub fn PriorityQueue(comptime T: type) type {
22 /// `fn lessThan(a: T, b: T) bool { return a < b; }`22 /// `fn lessThan(a: T, b: T) bool { return a < b; }`
23 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {23 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
24 return Self{24 return Self{
25 .items = [_]T{},25 .items = &[_]T{},
26 .len = 0,26 .len = 0,
27 .allocator = allocator,27 .allocator = allocator,
28 .compareFn = compareFn,28 .compareFn = compareFn,
lib/std/process.zig+8-8
...@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {...@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
473}473}
474474
475test "windows arg parsing" {475test "windows arg parsing" {
476 testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });476 testWindowsCmdLine("a b\tc d", &[_][]const u8{ "a", "b", "c", "d" });
477 testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" });477 testWindowsCmdLine("\"abc\" d e", &[_][]const u8{ "abc", "d", "e" });
478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });478 testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
479 testWindowsCmdLine("a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });479 testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" });
480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });480 testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" });
481 testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });481 testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" });
482482
483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{483 testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{
484 ".\\..\\zig-cache\\build",484 ".\\..\\zig-cache\\build",
485 "bin\\zig.exe",485 "bin\\zig.exe",
486 ".\\..",486 ".\\..",
lib/std/rand.zig+1-1
...@@ -54,7 +54,7 @@ pub const Random = struct {...@@ -54,7 +54,7 @@ pub const Random = struct {
54 // use LE instead of native endian for better portability maybe?54 // use LE instead of native endian for better portability maybe?
55 // TODO: endian portability is pointless if the underlying prng isn't endian portable.55 // TODO: endian portability is pointless if the underlying prng isn't endian portable.
56 // TODO: document the endian portability of this library.56 // TODO: document the endian portability of this library.
57 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, rand_bytes);57 const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
58 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);58 const unsigned_result = @truncate(UnsignedT, byte_aligned_result);
59 return @bitCast(T, unsigned_result);59 return @bitCast(T, unsigned_result);
60 }60 }
lib/std/segmented_list.zig+4-8
...@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
112 .allocator = allocator,112 .allocator = allocator,
113 .len = 0,113 .len = 0,
114 .prealloc_segment = undefined,114 .prealloc_segment = undefined,
115 .dynamic_segments = [_][*]T{},115 .dynamic_segments = &[_][*]T{},
116 };116 };
117 }117 }
118118
...@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
192 const len = @intCast(ShelfIndex, self.dynamic_segments.len);192 const len = @intCast(ShelfIndex, self.dynamic_segments.len);
193 self.freeShelves(len, 0);193 self.freeShelves(len, 0);
194 self.allocator.free(self.dynamic_segments);194 self.allocator.free(self.dynamic_segments);
195 self.dynamic_segments = [_][*]T{};195 self.dynamic_segments = &[_][*]T{};
196 return;196 return;
197 }197 }
198198
...@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {...@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
385 testing.expect(list.pop().? == 100);385 testing.expect(list.pop().? == 100);
386 testing.expect(list.len == 99);386 testing.expect(list.len == 99);
387387
388 try list.pushMany([_]i32{388 try list.pushMany(&[_]i32{ 1, 2, 3 });
389 1,
390 2,
391 3,
392 });
393 testing.expect(list.len == 102);389 testing.expect(list.len == 102);
394 testing.expect(list.pop().? == 3);390 testing.expect(list.pop().? == 3);
395 testing.expect(list.pop().? == 2);391 testing.expect(list.pop().? == 2);
396 testing.expect(list.pop().? == 1);392 testing.expect(list.pop().? == 1);
397 testing.expect(list.len == 99);393 testing.expect(list.len == 99);
398394
399 try list.pushMany([_]i32{});395 try list.pushMany(&[_]i32{});
400 testing.expect(list.len == 99);396 testing.expect(list.len == 99);
401397
402 var i: i32 = 99;398 var i: i32 = 99;
lib/std/sort.zig+43-43
...@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {...@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
10431043
1044test "std.sort" {1044test "std.sort" {
1045 const u8cases = [_][]const []const u8{1045 const u8cases = [_][]const []const u8{
1046 [_][]const u8{1046 &[_][]const u8{
1047 "",1047 "",
1048 "",1048 "",
1049 },1049 },
1050 [_][]const u8{1050 &[_][]const u8{
1051 "a",1051 "a",
1052 "a",1052 "a",
1053 },1053 },
1054 [_][]const u8{1054 &[_][]const u8{
1055 "az",1055 "az",
1056 "az",1056 "az",
1057 },1057 },
1058 [_][]const u8{1058 &[_][]const u8{
1059 "za",1059 "za",
1060 "az",1060 "az",
1061 },1061 },
1062 [_][]const u8{1062 &[_][]const u8{
1063 "asdf",1063 "asdf",
1064 "adfs",1064 "adfs",
1065 },1065 },
1066 [_][]const u8{1066 &[_][]const u8{
1067 "one",1067 "one",
1068 "eno",1068 "eno",
1069 },1069 },
...@@ -1078,29 +1078,29 @@ test "std.sort" {...@@ -1078,29 +1078,29 @@ test "std.sort" {
1078 }1078 }
10791079
1080 const i32cases = [_][]const []const i32{1080 const i32cases = [_][]const []const i32{
1081 [_][]const i32{1081 &[_][]const i32{
1082 [_]i32{},1082 &[_]i32{},
1083 [_]i32{},1083 &[_]i32{},
1084 },1084 },
1085 [_][]const i32{1085 &[_][]const i32{
1086 [_]i32{1},1086 &[_]i32{1},
1087 [_]i32{1},1087 &[_]i32{1},
1088 },1088 },
1089 [_][]const i32{1089 &[_][]const i32{
1090 [_]i32{ 0, 1 },1090 &[_]i32{ 0, 1 },
1091 [_]i32{ 0, 1 },1091 &[_]i32{ 0, 1 },
1092 },1092 },
1093 [_][]const i32{1093 &[_][]const i32{
1094 [_]i32{ 1, 0 },1094 &[_]i32{ 1, 0 },
1095 [_]i32{ 0, 1 },1095 &[_]i32{ 0, 1 },
1096 },1096 },
1097 [_][]const i32{1097 &[_][]const i32{
1098 [_]i32{ 1, -1, 0 },1098 &[_]i32{ 1, -1, 0 },
1099 [_]i32{ -1, 0, 1 },1099 &[_]i32{ -1, 0, 1 },
1100 },1100 },
1101 [_][]const i32{1101 &[_][]const i32{
1102 [_]i32{ 2, 1, 3 },1102 &[_]i32{ 2, 1, 3 },
1103 [_]i32{ 1, 2, 3 },1103 &[_]i32{ 1, 2, 3 },
1104 },1104 },
1105 };1105 };
11061106
...@@ -1115,29 +1115,29 @@ test "std.sort" {...@@ -1115,29 +1115,29 @@ test "std.sort" {
11151115
1116test "std.sort descending" {1116test "std.sort descending" {
1117 const rev_cases = [_][]const []const i32{1117 const rev_cases = [_][]const []const i32{
1118 [_][]const i32{1118 &[_][]const i32{
1119 [_]i32{},1119 &[_]i32{},
1120 [_]i32{},1120 &[_]i32{},
1121 },1121 },
1122 [_][]const i32{1122 &[_][]const i32{
1123 [_]i32{1},1123 &[_]i32{1},
1124 [_]i32{1},1124 &[_]i32{1},
1125 },1125 },
1126 [_][]const i32{1126 &[_][]const i32{
1127 [_]i32{ 0, 1 },1127 &[_]i32{ 0, 1 },
1128 [_]i32{ 1, 0 },1128 &[_]i32{ 1, 0 },
1129 },1129 },
1130 [_][]const i32{1130 &[_][]const i32{
1131 [_]i32{ 1, 0 },1131 &[_]i32{ 1, 0 },
1132 [_]i32{ 1, 0 },1132 &[_]i32{ 1, 0 },
1133 },1133 },
1134 [_][]const i32{1134 &[_][]const i32{
1135 [_]i32{ 1, -1, 0 },1135 &[_]i32{ 1, -1, 0 },
1136 [_]i32{ 1, 0, -1 },1136 &[_]i32{ 1, 0, -1 },
1137 },1137 },
1138 [_][]const i32{1138 &[_][]const i32{
1139 [_]i32{ 2, 1, 3 },1139 &[_]i32{ 2, 1, 3 },
1140 [_]i32{ 3, 2, 1 },1140 &[_]i32{ 3, 2, 1 },
1141 },1141 },
1142 };1142 };
11431143
...@@ -1154,7 +1154,7 @@ test "another sort case" {...@@ -1154,7 +1154,7 @@ test "another sort case" {
1154 var arr = [_]i32{ 5, 3, 1, 2, 4 };1154 var arr = [_]i32{ 5, 3, 1, 2, 4 };
1155 sort(i32, arr[0..], asc(i32));1155 sort(i32, arr[0..], asc(i32));
11561156
1157 testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 }));1157 testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
1158}1158}
11591159
1160test "sort fuzz testing" {1160test "sort fuzz testing" {
lib/std/unicode.zig+6-6
...@@ -499,14 +499,14 @@ test "utf16leToUtf8" {...@@ -499,14 +499,14 @@ test "utf16leToUtf8" {
499 {499 {
500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');500 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');501 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);502 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
503 testing.expect(mem.eql(u8, utf8, "Aa"));503 testing.expect(mem.eql(u8, utf8, "Aa"));
504 }504 }
505505
506 {506 {
507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);507 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);508 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);509 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));510 testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
511 }511 }
512512
...@@ -514,7 +514,7 @@ test "utf16leToUtf8" {...@@ -514,7 +514,7 @@ test "utf16leToUtf8" {
514 // the values just outside the surrogate half range514 // the values just outside the surrogate half range
515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);515 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);516 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);517 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));518 testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
519 }519 }
520520
...@@ -522,7 +522,7 @@ test "utf16leToUtf8" {...@@ -522,7 +522,7 @@ test "utf16leToUtf8" {
522 // smallest surrogate pair522 // smallest surrogate pair
523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);523 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);524 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);525 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));526 testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
527 }527 }
528528
...@@ -530,14 +530,14 @@ test "utf16leToUtf8" {...@@ -530,14 +530,14 @@ test "utf16leToUtf8" {
530 // largest surrogate pair530 // largest surrogate pair
531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);531 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);532 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);533 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));534 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
535 }535 }
536536
537 {537 {
538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);538 mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);539 mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);540 const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));541 testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
542 }542 }
543}543}
lib/std/zig/tokenizer.zig+61-61
...@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {...@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {
1313};1313};
13141314
1315test "tokenizer" {1315test "tokenizer" {
1316 testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});1316 testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test});
1317}1317}
13181318
1319test "tokenizer - unknown length pointer and then c pointer" {1319test "tokenizer - unknown length pointer and then c pointer" {
1320 testTokenize(1320 testTokenize(
1321 \\[*]u81321 \\[*]u8
1322 \\[*c]u81322 \\[*c]u8
1323 , [_]Token.Id{1323 , &[_]Token.Id{
1324 Token.Id.LBracket,1324 Token.Id.LBracket,
1325 Token.Id.Asterisk,1325 Token.Id.Asterisk,
1326 Token.Id.RBracket,1326 Token.Id.RBracket,
...@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {...@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {
1336test "tokenizer - char literal with hex escape" {1336test "tokenizer - char literal with hex escape" {
1337 testTokenize(1337 testTokenize(
1338 \\'\x1b'1338 \\'\x1b'
1339 , [_]Token.Id{.CharLiteral});1339 , &[_]Token.Id{.CharLiteral});
1340 testTokenize(1340 testTokenize(
1341 \\'\x1'1341 \\'\x1'
1342 , [_]Token.Id{ .Invalid, .Invalid });1342 , &[_]Token.Id{ .Invalid, .Invalid });
1343}1343}
13441344
1345test "tokenizer - char literal with unicode escapes" {1345test "tokenizer - char literal with unicode escapes" {
1346 // Valid unicode escapes1346 // Valid unicode escapes
1347 testTokenize(1347 testTokenize(
1348 \\'\u{3}'1348 \\'\u{3}'
1349 , [_]Token.Id{.CharLiteral});1349 , &[_]Token.Id{.CharLiteral});
1350 testTokenize(1350 testTokenize(
1351 \\'\u{01}'1351 \\'\u{01}'
1352 , [_]Token.Id{.CharLiteral});1352 , &[_]Token.Id{.CharLiteral});
1353 testTokenize(1353 testTokenize(
1354 \\'\u{2a}'1354 \\'\u{2a}'
1355 , [_]Token.Id{.CharLiteral});1355 , &[_]Token.Id{.CharLiteral});
1356 testTokenize(1356 testTokenize(
1357 \\'\u{3f9}'1357 \\'\u{3f9}'
1358 , [_]Token.Id{.CharLiteral});1358 , &[_]Token.Id{.CharLiteral});
1359 testTokenize(1359 testTokenize(
1360 \\'\u{6E09aBc1523}'1360 \\'\u{6E09aBc1523}'
1361 , [_]Token.Id{.CharLiteral});1361 , &[_]Token.Id{.CharLiteral});
1362 testTokenize(1362 testTokenize(
1363 \\"\u{440}"1363 \\"\u{440}"
1364 , [_]Token.Id{.StringLiteral});1364 , &[_]Token.Id{.StringLiteral});
13651365
1366 // Invalid unicode escapes1366 // Invalid unicode escapes
1367 testTokenize(1367 testTokenize(
1368 \\'\u'1368 \\'\u'
1369 , [_]Token.Id{.Invalid});1369 , &[_]Token.Id{.Invalid});
1370 testTokenize(1370 testTokenize(
1371 \\'\u{{'1371 \\'\u{{'
1372 , [_]Token.Id{ .Invalid, .Invalid });1372 , &[_]Token.Id{ .Invalid, .Invalid });
1373 testTokenize(1373 testTokenize(
1374 \\'\u{}'1374 \\'\u{}'
1375 , [_]Token.Id{ .Invalid, .Invalid });1375 , &[_]Token.Id{ .Invalid, .Invalid });
1376 testTokenize(1376 testTokenize(
1377 \\'\u{s}'1377 \\'\u{s}'
1378 , [_]Token.Id{ .Invalid, .Invalid });1378 , &[_]Token.Id{ .Invalid, .Invalid });
1379 testTokenize(1379 testTokenize(
1380 \\'\u{2z}'1380 \\'\u{2z}'
1381 , [_]Token.Id{ .Invalid, .Invalid });1381 , &[_]Token.Id{ .Invalid, .Invalid });
1382 testTokenize(1382 testTokenize(
1383 \\'\u{4a'1383 \\'\u{4a'
1384 , [_]Token.Id{.Invalid});1384 , &[_]Token.Id{.Invalid});
13851385
1386 // Test old-style unicode literals1386 // Test old-style unicode literals
1387 testTokenize(1387 testTokenize(
1388 \\'\u0333'1388 \\'\u0333'
1389 , [_]Token.Id{ .Invalid, .Invalid });1389 , &[_]Token.Id{ .Invalid, .Invalid });
1390 testTokenize(1390 testTokenize(
1391 \\'\U0333'1391 \\'\U0333'
1392 , [_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });1392 , &[_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
1393}1393}
13941394
1395test "tokenizer - char literal with unicode code point" {1395test "tokenizer - char literal with unicode code point" {
1396 testTokenize(1396 testTokenize(
1397 \\'💩'1397 \\'💩'
1398 , [_]Token.Id{.CharLiteral});1398 , &[_]Token.Id{.CharLiteral});
1399}1399}
14001400
1401test "tokenizer - float literal e exponent" {1401test "tokenizer - float literal e exponent" {
1402 testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{1402 testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{
1403 Token.Id.Identifier,1403 Token.Id.Identifier,
1404 Token.Id.Equal,1404 Token.Id.Equal,
1405 Token.Id.FloatLiteral,1405 Token.Id.FloatLiteral,
...@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {...@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {
1408}1408}
14091409
1410test "tokenizer - float literal p exponent" {1410test "tokenizer - float literal p exponent" {
1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{1411 testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{
1412 Token.Id.Identifier,1412 Token.Id.Identifier,
1413 Token.Id.Equal,1413 Token.Id.Equal,
1414 Token.Id.FloatLiteral,1414 Token.Id.FloatLiteral,
...@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {...@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {
1417}1417}
14181418
1419test "tokenizer - chars" {1419test "tokenizer - chars" {
1420 testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});1420 testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral});
1421}1421}
14221422
1423test "tokenizer - invalid token characters" {1423test "tokenizer - invalid token characters" {
1424 testTokenize("#", [_]Token.Id{Token.Id.Invalid});1424 testTokenize("#", &[_]Token.Id{Token.Id.Invalid});
1425 testTokenize("`", [_]Token.Id{Token.Id.Invalid});1425 testTokenize("`", &[_]Token.Id{Token.Id.Invalid});
1426 testTokenize("'c", [_]Token.Id{Token.Id.Invalid});1426 testTokenize("'c", &[_]Token.Id{Token.Id.Invalid});
1427 testTokenize("'", [_]Token.Id{Token.Id.Invalid});1427 testTokenize("'", &[_]Token.Id{Token.Id.Invalid});
1428 testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });1428 testTokenize("''", &[_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
1429}1429}
14301430
1431test "tokenizer - invalid literal/comment characters" {1431test "tokenizer - invalid literal/comment characters" {
1432 testTokenize("\"\x00\"", [_]Token.Id{1432 testTokenize("\"\x00\"", &[_]Token.Id{
1433 Token.Id.StringLiteral,1433 Token.Id.StringLiteral,
1434 Token.Id.Invalid,1434 Token.Id.Invalid,
1435 });1435 });
1436 testTokenize("//\x00", [_]Token.Id{1436 testTokenize("//\x00", &[_]Token.Id{
1437 Token.Id.LineComment,1437 Token.Id.LineComment,
1438 Token.Id.Invalid,1438 Token.Id.Invalid,
1439 });1439 });
1440 testTokenize("//\x1f", [_]Token.Id{1440 testTokenize("//\x1f", &[_]Token.Id{
1441 Token.Id.LineComment,1441 Token.Id.LineComment,
1442 Token.Id.Invalid,1442 Token.Id.Invalid,
1443 });1443 });
1444 testTokenize("//\x7f", [_]Token.Id{1444 testTokenize("//\x7f", &[_]Token.Id{
1445 Token.Id.LineComment,1445 Token.Id.LineComment,
1446 Token.Id.Invalid,1446 Token.Id.Invalid,
1447 });1447 });
1448}1448}
14491449
1450test "tokenizer - utf8" {1450test "tokenizer - utf8" {
1451 testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment});1451 testTokenize("//\xc2\x80", &[_]Token.Id{Token.Id.LineComment});
1452 testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment});1452 testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{Token.Id.LineComment});
1453}1453}
14541454
1455test "tokenizer - invalid utf8" {1455test "tokenizer - invalid utf8" {
1456 testTokenize("//\x80", [_]Token.Id{1456 testTokenize("//\x80", &[_]Token.Id{
1457 Token.Id.LineComment,1457 Token.Id.LineComment,
1458 Token.Id.Invalid,1458 Token.Id.Invalid,
1459 });1459 });
1460 testTokenize("//\xbf", [_]Token.Id{1460 testTokenize("//\xbf", &[_]Token.Id{
1461 Token.Id.LineComment,1461 Token.Id.LineComment,
1462 Token.Id.Invalid,1462 Token.Id.Invalid,
1463 });1463 });
1464 testTokenize("//\xf8", [_]Token.Id{1464 testTokenize("//\xf8", &[_]Token.Id{
1465 Token.Id.LineComment,1465 Token.Id.LineComment,
1466 Token.Id.Invalid,1466 Token.Id.Invalid,
1467 });1467 });
1468 testTokenize("//\xff", [_]Token.Id{1468 testTokenize("//\xff", &[_]Token.Id{
1469 Token.Id.LineComment,1469 Token.Id.LineComment,
1470 Token.Id.Invalid,1470 Token.Id.Invalid,
1471 });1471 });
1472 testTokenize("//\xc2\xc0", [_]Token.Id{1472 testTokenize("//\xc2\xc0", &[_]Token.Id{
1473 Token.Id.LineComment,1473 Token.Id.LineComment,
1474 Token.Id.Invalid,1474 Token.Id.Invalid,
1475 });1475 });
1476 testTokenize("//\xe0", [_]Token.Id{1476 testTokenize("//\xe0", &[_]Token.Id{
1477 Token.Id.LineComment,1477 Token.Id.LineComment,
1478 Token.Id.Invalid,1478 Token.Id.Invalid,
1479 });1479 });
1480 testTokenize("//\xf0", [_]Token.Id{1480 testTokenize("//\xf0", &[_]Token.Id{
1481 Token.Id.LineComment,1481 Token.Id.LineComment,
1482 Token.Id.Invalid,1482 Token.Id.Invalid,
1483 });1483 });
1484 testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{1484 testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{
1485 Token.Id.LineComment,1485 Token.Id.LineComment,
1486 Token.Id.Invalid,1486 Token.Id.Invalid,
1487 });1487 });
...@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {...@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {
14891489
1490test "tokenizer - illegal unicode codepoints" {1490test "tokenizer - illegal unicode codepoints" {
1491 // unicode newline characters.U+0085, U+2028, U+20291491 // unicode newline characters.U+0085, U+2028, U+2029
1492 testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});1492 testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment});
1493 testTokenize("//\xc2\x85", [_]Token.Id{1493 testTokenize("//\xc2\x85", &[_]Token.Id{
1494 Token.Id.LineComment,1494 Token.Id.LineComment,
1495 Token.Id.Invalid,1495 Token.Id.Invalid,
1496 });1496 });
1497 testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});1497 testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment});
1498 testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});1498 testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment});
1499 testTokenize("//\xe2\x80\xa8", [_]Token.Id{1499 testTokenize("//\xe2\x80\xa8", &[_]Token.Id{
1500 Token.Id.LineComment,1500 Token.Id.LineComment,
1501 Token.Id.Invalid,1501 Token.Id.Invalid,
1502 });1502 });
1503 testTokenize("//\xe2\x80\xa9", [_]Token.Id{1503 testTokenize("//\xe2\x80\xa9", &[_]Token.Id{
1504 Token.Id.LineComment,1504 Token.Id.LineComment,
1505 Token.Id.Invalid,1505 Token.Id.Invalid,
1506 });1506 });
1507 testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});1507 testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment});
1508}1508}
15091509
1510test "tokenizer - string identifier and builtin fns" {1510test "tokenizer - string identifier and builtin fns" {
1511 testTokenize(1511 testTokenize(
1512 \\const @"if" = @import("std");1512 \\const @"if" = @import("std");
1513 , [_]Token.Id{1513 , &[_]Token.Id{
1514 Token.Id.Keyword_const,1514 Token.Id.Keyword_const,
1515 Token.Id.Identifier,1515 Token.Id.Identifier,
1516 Token.Id.Equal,1516 Token.Id.Equal,
...@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {...@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {
1523}1523}
15241524
1525test "tokenizer - pipe and then invalid" {1525test "tokenizer - pipe and then invalid" {
1526 testTokenize("||=", [_]Token.Id{1526 testTokenize("||=", &[_]Token.Id{
1527 Token.Id.PipePipe,1527 Token.Id.PipePipe,
1528 Token.Id.Equal,1528 Token.Id.Equal,
1529 });1529 });
1530}1530}
15311531
1532test "tokenizer - line comment and doc comment" {1532test "tokenizer - line comment and doc comment" {
1533 testTokenize("//", [_]Token.Id{Token.Id.LineComment});1533 testTokenize("//", &[_]Token.Id{Token.Id.LineComment});
1534 testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});1534 testTokenize("// a / b", &[_]Token.Id{Token.Id.LineComment});
1535 testTokenize("// /", [_]Token.Id{Token.Id.LineComment});1535 testTokenize("// /", &[_]Token.Id{Token.Id.LineComment});
1536 testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});1536 testTokenize("/// a", &[_]Token.Id{Token.Id.DocComment});
1537 testTokenize("///", [_]Token.Id{Token.Id.DocComment});1537 testTokenize("///", &[_]Token.Id{Token.Id.DocComment});
1538 testTokenize("////", [_]Token.Id{Token.Id.LineComment});1538 testTokenize("////", &[_]Token.Id{Token.Id.LineComment});
1539 testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment});1539 testTokenize("//!", &[_]Token.Id{Token.Id.ContainerDocComment});
1540 testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment});1540 testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment});
1541}1541}
15421542
1543test "tokenizer - line comment followed by identifier" {1543test "tokenizer - line comment followed by identifier" {
...@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {...@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {
1545 \\ Unexpected,1545 \\ Unexpected,
1546 \\ // another1546 \\ // another
1547 \\ Another,1547 \\ Another,
1548 , [_]Token.Id{1548 , &[_]Token.Id{
1549 Token.Id.Identifier,1549 Token.Id.Identifier,
1550 Token.Id.Comma,1550 Token.Id.Comma,
1551 Token.Id.LineComment,1551 Token.Id.LineComment,
...@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {...@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {
1555}1555}
15561556
1557test "tokenizer - UTF-8 BOM is recognized and skipped" {1557test "tokenizer - UTF-8 BOM is recognized and skipped" {
1558 testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{1558 testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{
1559 Token.Id.Identifier,1559 Token.Id.Identifier,
1560 Token.Id.Semicolon,1560 Token.Id.Semicolon,
1561 });1561 });
1562}1562}
15631563
1564test "correctly parse pointer assignment" {1564test "correctly parse pointer assignment" {
1565 testTokenize("b.*=3;\n", [_]Token.Id{1565 testTokenize("b.*=3;\n", &[_]Token.Id{
1566 Token.Id.Identifier,1566 Token.Id.Identifier,
1567 Token.Id.PeriodAsterisk,1567 Token.Id.PeriodAsterisk,
1568 Token.Id.Equal,1568 Token.Id.Equal,
src-self-hosted/arg.zig+1-1
...@@ -178,7 +178,7 @@ pub const Args = struct {...@@ -178,7 +178,7 @@ pub const Args = struct {
178 else => @panic("attempted to retrieve flag with wrong type"),178 else => @panic("attempted to retrieve flag with wrong type"),
179 }179 }
180 } else {180 } else {
181 return [_][]const u8{};181 return &[_][]const u8{};
182 }182 }
183 }183 }
184};184};
src-self-hosted/compilation.zig+14-15
...@@ -103,8 +103,8 @@ pub const ZigCompiler = struct {...@@ -103,8 +103,8 @@ pub const ZigCompiler = struct {
103 /// Must be called only once, ever. Sets global state.103 /// Must be called only once, ever. Sets global state.
104 pub fn setLlvmArgv(allocator: *Allocator, llvm_argv: []const []const u8) !void {104 pub fn setLlvmArgv(allocator: *Allocator, llvm_argv: []const []const u8) !void {
105 if (llvm_argv.len != 0) {105 if (llvm_argv.len != 0) {
106 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, [_][]const []const u8{106 var c_compatible_args = try std.cstr.NullTerminated2DArray.fromSlices(allocator, &[_][]const []const u8{
107 [_][]const u8{"zig (LLVM option parsing)"},107 &[_][]const u8{"zig (LLVM option parsing)"},
108 llvm_argv,108 llvm_argv,
109 });109 });
110 defer c_compatible_args.deinit();110 defer c_compatible_args.deinit();
...@@ -148,13 +148,13 @@ pub const Compilation = struct {...@@ -148,13 +148,13 @@ pub const Compilation = struct {
148 is_static: bool,148 is_static: bool,
149 linker_rdynamic: bool = false,149 linker_rdynamic: bool = false,
150150
151 clang_argv: []const []const u8 = [_][]const u8{},151 clang_argv: []const []const u8 = &[_][]const u8{},
152 lib_dirs: []const []const u8 = [_][]const u8{},152 lib_dirs: []const []const u8 = &[_][]const u8{},
153 rpath_list: []const []const u8 = [_][]const u8{},153 rpath_list: []const []const u8 = &[_][]const u8{},
154 assembly_files: []const []const u8 = [_][]const u8{},154 assembly_files: []const []const u8 = &[_][]const u8{},
155155
156 /// paths that are explicitly provided by the user to link against156 /// 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
159 /// functions that have their own objects that we need to link159 /// functions that have their own objects that we need to link
160 /// it uses an optional pointer so that tombstone removals are possible160 /// it uses an optional pointer so that tombstone removals are possible
...@@ -178,10 +178,10 @@ pub const Compilation = struct {...@@ -178,10 +178,10 @@ pub const Compilation = struct {
178 verbose_llvm_ir: bool = false,178 verbose_llvm_ir: bool = false,
179 verbose_link: bool = false,179 verbose_link: bool = false,
180180
181 darwin_frameworks: []const []const u8 = [_][]const u8{},181 darwin_frameworks: []const []const u8 = &[_][]const u8{},
182 darwin_version_min: DarwinVersionMin = .None,182 darwin_version_min: DarwinVersionMin = .None,
183183
184 test_filters: []const []const u8 = [_][]const u8{},184 test_filters: []const []const u8 = &[_][]const u8{},
185 test_name_prefix: ?[]const u8 = null,185 test_name_prefix: ?[]const u8 = null,
186186
187 emit_file_type: Emit = .Binary,187 emit_file_type: Emit = .Binary,
...@@ -400,7 +400,6 @@ pub const Compilation = struct {...@@ -400,7 +400,6 @@ pub const Compilation = struct {
400 .llvm_triple = undefined,400 .llvm_triple = undefined,
401 .is_static = is_static,401 .is_static = is_static,
402 .link_libs_list = undefined,402 .link_libs_list = undefined,
403
404 .exported_symbol_names = event.Locked(Decl.Table).init(Decl.Table.init(allocator)),403 .exported_symbol_names = event.Locked(Decl.Table).init(Decl.Table.init(allocator)),
405 .prelink_group = event.Group(BuildError!void).init(allocator),404 .prelink_group = event.Group(BuildError!void).init(allocator),
406 .deinit_group = event.Group(void).init(allocator),405 .deinit_group = event.Group(void).init(allocator),
...@@ -448,7 +447,7 @@ pub const Compilation = struct {...@@ -448,7 +447,7 @@ pub const Compilation = struct {
448 comp.name = try Buffer.init(comp.arena(), name);447 comp.name = try Buffer.init(comp.arena(), name);
449 comp.llvm_triple = try util.getTriple(comp.arena(), target);448 comp.llvm_triple = try util.getTriple(comp.arena(), target);
450 comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple);449 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
453 const opt_level = switch (build_mode) {452 const opt_level = switch (build_mode) {
454 .Debug => llvm.CodeGenLevelNone,453 .Debug => llvm.CodeGenLevelNone,
...@@ -490,7 +489,7 @@ pub const Compilation = struct {...@@ -490,7 +489,7 @@ pub const Compilation = struct {
490 comp.events = try allocator.create(event.Channel(Event));489 comp.events = try allocator.create(event.Channel(Event));
491 defer allocator.destroy(comp.events);490 defer allocator.destroy(comp.events);
492491
493 comp.events.init([0]Event{});492 comp.events.init(&[0]Event{});
494 defer comp.events.deinit();493 defer comp.events.deinit();
495494
496 if (root_src_path) |root_src| {495 if (root_src_path) |root_src| {
...@@ -1166,7 +1165,7 @@ pub const Compilation = struct {...@@ -1166,7 +1165,7 @@ pub const Compilation = struct {
1166 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);1165 const file_name = try std.fmt.allocPrint(self.gpa(), "{}{}", file_prefix[0..], suffix);
1167 defer self.gpa().free(file_name);1166 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..] });
1170 errdefer self.gpa().free(full_path);1169 errdefer self.gpa().free(full_path);
11711170
1172 return Buffer.fromOwnedSlice(self.gpa(), full_path);1171 return Buffer.fromOwnedSlice(self.gpa(), full_path);
...@@ -1187,7 +1186,7 @@ pub const Compilation = struct {...@@ -1187,7 +1186,7 @@ pub const Compilation = struct {
1187 const zig_dir_path = try getZigDir(self.gpa());1186 const zig_dir_path = try getZigDir(self.gpa());
1188 defer self.gpa().free(zig_dir_path);1187 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..] });
1191 try std.fs.makePath(self.gpa(), tmp_dir);1190 try std.fs.makePath(self.gpa(), tmp_dir);
1192 return tmp_dir;1191 return tmp_dir;
1193 }1192 }
...@@ -1209,7 +1208,7 @@ pub const Compilation = struct {...@@ -1209,7 +1208,7 @@ pub const Compilation = struct {
1209 }1208 }
12101209
1211 var result: [12]u8 = undefined;1210 var result: [12]u8 = undefined;
1212 b64_fs_encoder.encode(result[0..], rand_bytes);1211 b64_fs_encoder.encode(result[0..], &rand_bytes);
1213 return result;1212 return result;
1214 }1213 }
12151214
src-self-hosted/dep_tokenizer.zig+2-2
...@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {...@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
992992
993fn printCharValues(out: var, bytes: []const u8) !void {993fn printCharValues(out: var, bytes: []const u8) !void {
994 for (bytes) |b| {994 for (bytes) |b| {
995 try out.write([_]u8{printable_char_tab[b]});995 try out.write(&[_]u8{printable_char_tab[b]});
996 }996 }
997}997}
998998
...@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {...@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};1001 std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
1002 } else {1002 } else {
1003 try out.write("'");1003 try out.write("'");
1004 try out.write([_]u8{printable_char_tab[char]});1004 try out.write(&[_]u8{printable_char_tab[char]});
1005 try out.write("'");1005 try out.write("'");
1006 }1006 }
1007}1007}
src-self-hosted/introspect.zig+2-2
...@@ -8,10 +8,10 @@ const warn = std.debug.warn;...@@ -8,10 +8,10 @@ const warn = std.debug.warn;
88
9/// Caller must free result9/// Caller must free result
10pub fn testZigInstallPrefix(allocator: *mem.Allocator, test_path: []const u8) ![]u8 {10pub 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" });
12 errdefer allocator.free(test_zig_dir);12 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" });
15 defer allocator.free(test_index_file);15 defer allocator.free(test_index_file);
1616
17 var file = try fs.File.openRead(test_index_file);17 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 {...@@ -193,7 +193,7 @@ pub const LibCInstallation = struct {
193 "/dev/null",193 "/dev/null",
194 };194 };
195 // TODO make this use event loop195 // 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);
197 const exec_result = if (std.debug.runtime_safety) blk: {197 const exec_result = if (std.debug.runtime_safety) blk: {
198 break :blk errorable_result catch unreachable;198 break :blk errorable_result catch unreachable;
199 } else blk: {199 } else blk: {
...@@ -233,7 +233,7 @@ pub const LibCInstallation = struct {...@@ -233,7 +233,7 @@ pub const LibCInstallation = struct {
233 while (path_i < search_paths.len) : (path_i += 1) {233 while (path_i < search_paths.len) : (path_i += 1) {
234 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);234 const search_path_untrimmed = search_paths.at(search_paths.len - path_i - 1);
235 const search_path = std.mem.trimLeft(u8, search_path_untrimmed, " ");235 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" });
237 defer allocator.free(stdlib_path);237 defer allocator.free(stdlib_path);
238238
239 if (try fileExists(stdlib_path)) {239 if (try fileExists(stdlib_path)) {
...@@ -401,7 +401,7 @@ fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool...@@ -401,7 +401,7 @@ fn ccPrintFileName(allocator: *Allocator, o_file: []const u8, want_dirname: bool
401401
402 // TODO This simulates evented I/O for the child process exec402 // TODO This simulates evented I/O for the child process exec
403 event.Loop.startCpuBoundOperation();403 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);
405 const exec_result = if (std.debug.runtime_safety) blk: {405 const exec_result = if (std.debug.runtime_safety) blk: {
406 break :blk errorable_result catch unreachable;406 break :blk errorable_result catch unreachable;
407 } else blk: {407 } else blk: {
src-self-hosted/link.zig+1-1
...@@ -314,7 +314,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {...@@ -314,7 +314,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
314}314}
315315
316fn addPathJoin(ctx: *Context, dirname: []const u8, basename: []const u8) !void {316fn 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 });
318 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);318 const full_path_with_null = try std.cstr.addNullByte(&ctx.arena.allocator, full_path);
319 try ctx.args.append(@ptrCast([*:0]const u8, full_path_with_null.ptr));319 try ctx.args.append(@ptrCast([*:0]const u8, full_path_with_null.ptr));
320}320}
src-self-hosted/main.zig+7-7
...@@ -196,12 +196,12 @@ const usage_build_generic =...@@ -196,12 +196,12 @@ const usage_build_generic =
196196
197const args_build_generic = [_]Flag{197const args_build_generic = [_]Flag{
198 Flag.Bool("--help"),198 Flag.Bool("--help"),
199 Flag.Option("--color", [_][]const u8{199 Flag.Option("--color", &[_][]const u8{
200 "auto",200 "auto",
201 "off",201 "off",
202 "on",202 "on",
203 }),203 }),
204 Flag.Option("--mode", [_][]const u8{204 Flag.Option("--mode", &[_][]const u8{
205 "debug",205 "debug",
206 "release-fast",206 "release-fast",
207 "release-safe",207 "release-safe",
...@@ -209,7 +209,7 @@ const args_build_generic = [_]Flag{...@@ -209,7 +209,7 @@ const args_build_generic = [_]Flag{
209 }),209 }),
210210
211 Flag.ArgMergeN("--assembly", 1),211 Flag.ArgMergeN("--assembly", 1),
212 Flag.Option("--emit", [_][]const u8{212 Flag.Option("--emit", &[_][]const u8{
213 "asm",213 "asm",
214 "bin",214 "bin",
215 "llvm-ir",215 "llvm-ir",
...@@ -257,7 +257,7 @@ const args_build_generic = [_]Flag{...@@ -257,7 +257,7 @@ const args_build_generic = [_]Flag{
257};257};
258258
259fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Compilation.Kind) !void {259fn 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);
261 defer flags.deinit();261 defer flags.deinit();
262262
263 if (flags.present("help")) {263 if (flags.present("help")) {
...@@ -525,7 +525,7 @@ pub const usage_fmt =...@@ -525,7 +525,7 @@ pub const usage_fmt =
525pub const args_fmt_spec = [_]Flag{525pub const args_fmt_spec = [_]Flag{
526 Flag.Bool("--help"),526 Flag.Bool("--help"),
527 Flag.Bool("--check"),527 Flag.Bool("--check"),
528 Flag.Option("--color", [_][]const u8{528 Flag.Option("--color", &[_][]const u8{
529 "auto",529 "auto",
530 "off",530 "off",
531 "on",531 "on",
...@@ -579,7 +579,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {...@@ -579,7 +579,7 @@ fn cmdLibC(allocator: *Allocator, args: []const []const u8) !void {
579}579}
580580
581fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {581fn 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);
583 defer flags.deinit();583 defer flags.deinit();
584584
585 if (flags.present("help")) {585 if (flags.present("help")) {
...@@ -709,7 +709,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -709,7 +709,7 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
709 var it = dir.iterate();709 var it = dir.iterate();
710 while (try it.next()) |entry| {710 while (try it.next()) |entry| {
711 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {711 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 });
713 @panic("TODO https://github.com/ziglang/zig/issues/3777");713 @panic("TODO https://github.com/ziglang/zig/issues/3777");
714 // try group.call(fmtPath, fmt, full_path, check_mode);714 // try group.call(fmtPath, fmt, full_path, check_mode);
715 }715 }
src-self-hosted/stage1.zig+2-2
...@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {...@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
170 stderr = &stderr_file.outStream().stream;170 stderr = &stderr_file.outStream().stream;
171171
172 const args = args_list.toSliceConst();172 const args = args_list.toSliceConst();
173 var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]);173 var flags = try Args.parse(allocator, &self_hosted_main.args_fmt_spec, args[2..]);
174 defer flags.deinit();174 defer flags.deinit();
175175
176 if (flags.present("help")) {176 if (flags.present("help")) {
...@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void...@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
286286
287 while (try dir_it.next()) |entry| {287 while (try dir_it.next()) |entry| {
288 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {288 if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {
289 const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });289 const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name });
290 try fmtPath(fmt, full_path, check_mode);290 try fmtPath(fmt, full_path, check_mode);
291 }291 }
292 }292 }
src/all_types.hpp+7-7
...@@ -313,12 +313,6 @@ struct RuntimeHintSlice {...@@ -313,12 +313,6 @@ struct RuntimeHintSlice {
313 uint64_t len;313 uint64_t len;
314};314};
315315
316struct ConstGlobalRefs {
317 LLVMValueRef llvm_value;
318 LLVMValueRef llvm_global;
319 uint32_t align;
320};
321
322enum LazyValueId {316enum LazyValueId {
323 LazyValueIdInvalid,317 LazyValueIdInvalid,
324 LazyValueIdAlignOf,318 LazyValueIdAlignOf,
...@@ -409,8 +403,10 @@ struct LazyValueErrUnionType {...@@ -409,8 +403,10 @@ struct LazyValueErrUnionType {
409struct ZigValue {403struct ZigValue {
410 ZigType *type;404 ZigType *type;
411 ConstValSpecial special;405 ConstValSpecial special;
406 uint32_t llvm_align;
412 ConstParent parent;407 ConstParent parent;
413 ConstGlobalRefs *global_refs;408 LLVMValueRef llvm_value;
409 LLVMValueRef llvm_global;
414410
415 union {411 union {
416 // populated if special == ConstValSpecialStatic412 // populated if special == ConstValSpecialStatic
...@@ -2652,6 +2648,10 @@ struct IrInstruction {...@@ -2652,6 +2648,10 @@ struct IrInstruction {
2652 IrInstructionId id;2648 IrInstructionId id;
2653 // true if this instruction was generated by zig and not from user code2649 // true if this instruction was generated by zig and not from user code
2654 bool is_gen;2650 bool is_gen;
2651
2652 // for debugging purposes, these are useful to call to inspect the instruction
2653 void dump();
2654 void src();
2655};2655};
26562656
2657struct IrInstructionDeclVarSrc {2657struct 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_...@@ -5909,12 +5909,7 @@ ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_
59095909
59105910
5911ZigValue *create_const_vals(size_t count) {5911ZigValue *create_const_vals(size_t count) {
5912 ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");5912 return allocate<ZigValue>(count, "ZigValue");
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;
5918}5913}
59195914
5920ZigValue **alloc_const_vals_ptrs(size_t count) {5915ZigValue **alloc_const_vals_ptrs(size_t count) {
...@@ -6492,20 +6487,14 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {...@@ -6492,20 +6487,14 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
6492 return false;6487 return false;
6493 return true;6488 return true;
6494 case ConstPtrSpecialBaseArray:6489 case ConstPtrSpecialBaseArray:
6495 if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val &&6490 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 {
6499 return false;6491 return false;
6500 }6492 }
6501 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)6493 if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
6502 return false;6494 return false;
6503 return true;6495 return true;
6504 case ConstPtrSpecialBaseStruct:6496 case ConstPtrSpecialBaseStruct:
6505 if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&6497 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 {
6509 return false;6498 return false;
6510 }6499 }
6511 if (a->data.x_ptr.data.base_struct.field_index != b->data.x_ptr.data.base_struct.field_index)6500 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) {...@@ -6513,27 +6502,21 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
6513 return true;6502 return true;
6514 case ConstPtrSpecialBaseErrorUnionCode:6503 case ConstPtrSpecialBaseErrorUnionCode:
6515 if (a->data.x_ptr.data.base_err_union_code.err_union_val !=6504 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 &&6505 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)
6519 {6506 {
6520 return false;6507 return false;
6521 }6508 }
6522 return true;6509 return true;
6523 case ConstPtrSpecialBaseErrorUnionPayload:6510 case ConstPtrSpecialBaseErrorUnionPayload:
6524 if (a->data.x_ptr.data.base_err_union_payload.err_union_val !=6511 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 &&6512 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)
6528 {6513 {
6529 return false;6514 return false;
6530 }6515 }
6531 return true;6516 return true;
6532 case ConstPtrSpecialBaseOptionalPayload:6517 case ConstPtrSpecialBaseOptionalPayload:
6533 if (a->data.x_ptr.data.base_optional_payload.optional_val !=6518 if (a->data.x_ptr.data.base_optional_payload.optional_val !=
6534 b->data.x_ptr.data.base_optional_payload.optional_val &&6519 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)
6537 {6520 {
6538 return false;6521 return false;
6539 }6522 }
src/codegen.cpp+42-68
...@@ -946,7 +946,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {...@@ -946,7 +946,7 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
946946
947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {947static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
948 ZigValue *val = &g->panic_msg_vals[msg_id];948 ZigValue *val = &g->panic_msg_vals[msg_id];
949 if (!val->global_refs->llvm_global) {949 if (!val->llvm_global) {
950950
951 Buf *buf_msg = panic_msg_buf(msg_id);951 Buf *buf_msg = panic_msg_buf(msg_id);
952 ZigValue *array_val = create_const_str_lit(g, buf_msg)->data.x_ptr.data.ref.pointee;952 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) {...@@ -955,13 +955,13 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) {
955 render_const_val(g, val, "");955 render_const_val(g, val, "");
956 render_const_val_global(g, val, "");956 render_const_val_global(g, val, "");
957957
958 assert(val->global_refs->llvm_global);958 assert(val->llvm_global);
959 }959 }
960960
961 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,961 ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
962 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);962 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
963 ZigType *str_type = get_slice_type(g, u8_ptr_type);963 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));
965}965}
966966
967static ZigType *ptr_to_stack_trace_type(CodeGen *g) {967static ZigType *ptr_to_stack_trace_type(CodeGen *g) {
...@@ -1727,9 +1727,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {...@@ -1727,9 +1727,9 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1727 if (handle_is_ptr(instruction->value->type)) {1727 if (handle_is_ptr(instruction->value->type)) {
1728 render_const_val_global(g, instruction->value, "");1728 render_const_val_global(g, instruction->value, "");
1729 ZigType *ptr_type = get_pointer_to_type(g, instruction->value->type, true);1729 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), "");
1731 } else {1731 } 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,
1733 get_llvm_type(g, instruction->value->type), "");1733 get_llvm_type(g, instruction->value->type), "");
1734 }1734 }
1735 assert(instruction->llvm_value);1735 assert(instruction->llvm_value);
...@@ -6374,7 +6374,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren...@@ -6374,7 +6374,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren
6374 case ConstParentIdNone:6374 case ConstParentIdNone:
6375 render_const_val(g, val, "");6375 render_const_val(g, val, "");
6376 render_const_val_global(g, val, "");6376 render_const_val_global(g, val, "");
6377 return val->global_refs->llvm_global;6377 return val->llvm_global;
6378 case ConstParentIdStruct:6378 case ConstParentIdStruct:
6379 return gen_const_ptr_struct_recursive(g, parent->data.p_struct.struct_val,6379 return gen_const_ptr_struct_recursive(g, parent->data.p_struct.struct_val,
6380 parent->data.p_struct.field_index);6380 parent->data.p_struct.field_index);
...@@ -6392,7 +6392,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren...@@ -6392,7 +6392,7 @@ static LLVMValueRef gen_parent_ptr(CodeGen *g, ZigValue *val, ConstParent *paren
6392 case ConstParentIdScalar:6392 case ConstParentIdScalar:
6393 render_const_val(g, parent->data.p_scalar.scalar_val, "");6393 render_const_val(g, parent->data.p_scalar.scalar_val, "");
6394 render_const_val_global(g, parent->data.p_scalar.scalar_val, "");6394 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;
6396 }6396 }
6397 zig_unreachable();6397 zig_unreachable();
6398}6398}
...@@ -6623,17 +6623,15 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha...@@ -6623,17 +6623,15 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6623 zig_unreachable();6623 zig_unreachable();
6624 case ConstPtrSpecialRef:6624 case ConstPtrSpecialRef:
6625 {6625 {
6626 assert(const_val->global_refs != nullptr);
6627 ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee;6626 ZigValue *pointee = const_val->data.x_ptr.data.ref.pointee;
6628 render_const_val(g, pointee, "");6627 render_const_val(g, pointee, "");
6629 render_const_val_global(g, pointee, "");6628 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,
6631 get_llvm_type(g, const_val->type));6630 get_llvm_type(g, const_val->type));
6632 return const_val->global_refs->llvm_value;6631 return const_val->llvm_value;
6633 }6632 }
6634 case ConstPtrSpecialBaseArray:6633 case ConstPtrSpecialBaseArray:
6635 {6634 {
6636 assert(const_val->global_refs != nullptr);
6637 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;6635 ZigValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val;
6638 assert(array_const_val->type->id == ZigTypeIdArray);6636 assert(array_const_val->type->id == ZigTypeIdArray);
6639 if (!type_has_bits(array_const_val->type)) {6637 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...@@ -6641,102 +6639,97 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ZigValue *const_val, const cha
6641 ZigValue *pointee = array_const_val->type->data.array.sentinel;6639 ZigValue *pointee = array_const_val->type->data.array.sentinel;
6642 render_const_val(g, pointee, "");6640 render_const_val(g, pointee, "");
6643 render_const_val_global(g, pointee, "");6641 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,
6645 get_llvm_type(g, const_val->type));6643 get_llvm_type(g, const_val->type));
6646 return const_val->global_refs->llvm_value;6644 return const_val->llvm_value;
6647 } else {6645 } else {
6648 // make this a null pointer6646 // make this a null pointer
6649 ZigType *usize = g->builtin_types.entry_usize;6647 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),
6651 get_llvm_type(g, const_val->type));6649 get_llvm_type(g, const_val->type));
6652 return const_val->global_refs->llvm_value;6650 return const_val->llvm_value;
6653 }6651 }
6654 }6652 }
6655 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;6653 size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index;
6656 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);6654 LLVMValueRef uncasted_ptr_val = gen_const_ptr_array_recursive(g, array_const_val, elem_index);
6657 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));6655 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;
6659 return ptr_val;6657 return ptr_val;
6660 }6658 }
6661 case ConstPtrSpecialBaseStruct:6659 case ConstPtrSpecialBaseStruct:
6662 {6660 {
6663 assert(const_val->global_refs != nullptr);
6664 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;6661 ZigValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val;
6665 assert(struct_const_val->type->id == ZigTypeIdStruct);6662 assert(struct_const_val->type->id == ZigTypeIdStruct);
6666 if (!type_has_bits(struct_const_val->type)) {6663 if (!type_has_bits(struct_const_val->type)) {
6667 // make this a null pointer6664 // make this a null pointer
6668 ZigType *usize = g->builtin_types.entry_usize;6665 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),
6670 get_llvm_type(g, const_val->type));6667 get_llvm_type(g, const_val->type));
6671 return const_val->global_refs->llvm_value;6668 return const_val->llvm_value;
6672 }6669 }
6673 size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index;6670 size_t src_field_index = const_val->data.x_ptr.data.base_struct.field_index;
6674 size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index]->gen_index;6671 size_t gen_field_index = struct_const_val->type->data.structure.fields[src_field_index]->gen_index;
6675 LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val,6672 LLVMValueRef uncasted_ptr_val = gen_const_ptr_struct_recursive(g, struct_const_val,
6676 gen_field_index);6673 gen_field_index);
6677 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));6674 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;
6679 return ptr_val;6676 return ptr_val;
6680 }6677 }
6681 case ConstPtrSpecialBaseErrorUnionCode:6678 case ConstPtrSpecialBaseErrorUnionCode:
6682 {6679 {
6683 assert(const_val->global_refs != nullptr);
6684 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;6680 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_code.err_union_val;
6685 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6681 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6686 if (!type_has_bits(err_union_const_val->type)) {6682 if (!type_has_bits(err_union_const_val->type)) {
6687 // make this a null pointer6683 // make this a null pointer
6688 ZigType *usize = g->builtin_types.entry_usize;6684 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),
6690 get_llvm_type(g, const_val->type));6686 get_llvm_type(g, const_val->type));
6691 return const_val->global_refs->llvm_value;6687 return const_val->llvm_value;
6692 }6688 }
6693 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_code_recursive(g, err_union_const_val);6689 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_code_recursive(g, err_union_const_val);
6694 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));6690 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;
6696 return ptr_val;6692 return ptr_val;
6697 }6693 }
6698 case ConstPtrSpecialBaseErrorUnionPayload:6694 case ConstPtrSpecialBaseErrorUnionPayload:
6699 {6695 {
6700 assert(const_val->global_refs != nullptr);
6701 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;6696 ZigValue *err_union_const_val = const_val->data.x_ptr.data.base_err_union_payload.err_union_val;
6702 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);6697 assert(err_union_const_val->type->id == ZigTypeIdErrorUnion);
6703 if (!type_has_bits(err_union_const_val->type)) {6698 if (!type_has_bits(err_union_const_val->type)) {
6704 // make this a null pointer6699 // make this a null pointer
6705 ZigType *usize = g->builtin_types.entry_usize;6700 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),
6707 get_llvm_type(g, const_val->type));6702 get_llvm_type(g, const_val->type));
6708 return const_val->global_refs->llvm_value;6703 return const_val->llvm_value;
6709 }6704 }
6710 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_payload_recursive(g, err_union_const_val);6705 LLVMValueRef uncasted_ptr_val = gen_const_ptr_err_union_payload_recursive(g, err_union_const_val);
6711 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));6706 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;
6713 return ptr_val;6708 return ptr_val;
6714 }6709 }
6715 case ConstPtrSpecialBaseOptionalPayload:6710 case ConstPtrSpecialBaseOptionalPayload:
6716 {6711 {
6717 assert(const_val->global_refs != nullptr);
6718 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;6712 ZigValue *optional_const_val = const_val->data.x_ptr.data.base_optional_payload.optional_val;
6719 assert(optional_const_val->type->id == ZigTypeIdOptional);6713 assert(optional_const_val->type->id == ZigTypeIdOptional);
6720 if (!type_has_bits(optional_const_val->type)) {6714 if (!type_has_bits(optional_const_val->type)) {
6721 // make this a null pointer6715 // make this a null pointer
6722 ZigType *usize = g->builtin_types.entry_usize;6716 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),
6724 get_llvm_type(g, const_val->type));6718 get_llvm_type(g, const_val->type));
6725 return const_val->global_refs->llvm_value;6719 return const_val->llvm_value;
6726 }6720 }
6727 LLVMValueRef uncasted_ptr_val = gen_const_ptr_optional_payload_recursive(g, optional_const_val);6721 LLVMValueRef uncasted_ptr_val = gen_const_ptr_optional_payload_recursive(g, optional_const_val);
6728 LLVMValueRef ptr_val = LLVMConstBitCast(uncasted_ptr_val, get_llvm_type(g, const_val->type));6722 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;
6730 return ptr_val;6724 return ptr_val;
6731 }6725 }
6732 case ConstPtrSpecialHardCodedAddr:6726 case ConstPtrSpecialHardCodedAddr:
6733 {6727 {
6734 assert(const_val->global_refs != nullptr);
6735 uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;6728 uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr;
6736 ZigType *usize = g->builtin_types.entry_usize;6729 ZigType *usize = g->builtin_types.entry_usize;
6737 const_val->global_refs->llvm_value = LLVMConstIntToPtr(6730 const_val->llvm_value = LLVMConstIntToPtr(
6738 LLVMConstInt(usize->llvm_type, addr_value, false), get_llvm_type(g, const_val->type));6731 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;
6740 }6733 }
6741 case ConstPtrSpecialFunction:6734 case ConstPtrSpecialFunction:
6742 return LLVMConstBitCast(fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry),6735 return LLVMConstBitCast(fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry),
...@@ -7175,34 +7168,29 @@ check: switch (const_val->special) {...@@ -7175,34 +7168,29 @@ check: switch (const_val->special) {
7175}7168}
71767169
7177static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) {7170static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name) {
7178 if (!const_val->global_refs)7171 if (!const_val->llvm_value)
7179 const_val->global_refs = allocate<ConstGlobalRefs>(1);7172 const_val->llvm_value = gen_const_val(g, const_val, name);
7180 if (!const_val->global_refs->llvm_value)
7181 const_val->global_refs->llvm_value = gen_const_val(g, const_val, name);
71827173
7183 if (const_val->global_refs->llvm_global)7174 if (const_val->llvm_global)
7184 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);7175 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
7185}7176}
71867177
7187static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) {7178static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name) {
7188 if (!const_val->global_refs)7179 if (!const_val->llvm_global) {
7189 const_val->global_refs = allocate<ConstGlobalRefs>(1);7180 LLVMTypeRef type_ref = const_val->llvm_value ?
71907181 LLVMTypeOf(const_val->llvm_value) : get_llvm_type(g, const_val->type);
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);
7194 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, name);7182 LLVMValueRef global_value = LLVMAddGlobal(g->module, type_ref, name);
7195 LLVMSetLinkage(global_value, LLVMInternalLinkage);7183 LLVMSetLinkage(global_value, LLVMInternalLinkage);
7196 LLVMSetGlobalConstant(global_value, true);7184 LLVMSetGlobalConstant(global_value, true);
7197 LLVMSetUnnamedAddr(global_value, true);7185 LLVMSetUnnamedAddr(global_value, true);
7198 LLVMSetAlignment(global_value, (const_val->global_refs->align == 0) ?7186 LLVMSetAlignment(global_value, (const_val->llvm_align == 0) ?
7199 get_abi_alignment(g, const_val->type) : const_val->global_refs->align);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;
7202 }7190 }
72037191
7204 if (const_val->global_refs->llvm_value)7192 if (const_val->llvm_value)
7205 LLVMSetInitializer(const_val->global_refs->llvm_global, const_val->global_refs->llvm_value);7193 LLVMSetInitializer(const_val->llvm_global, const_val->llvm_value);
7206}7194}
72077195
7208static void generate_error_name_table(CodeGen *g) {7196static void generate_error_name_table(CodeGen *g) {
...@@ -7403,7 +7391,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7403,7 +7391,7 @@ static void do_code_gen(CodeGen *g) {
7403 bool exported = (linkage != GlobalLinkageIdInternal);7391 bool exported = (linkage != GlobalLinkageIdInternal);
7404 render_const_val(g, var->const_value, symbol_name);7392 render_const_val(g, var->const_value, symbol_name);
7405 render_const_val_global(g, var->const_value, symbol_name);7393 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
7408 if (exported) {7396 if (exported) {
7409 LLVMSetLinkage(global_value, to_llvm_linkage(linkage));7397 LLVMSetLinkage(global_value, to_llvm_linkage(linkage));
...@@ -7418,7 +7406,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7418,7 +7406,7 @@ static void do_code_gen(CodeGen *g) {
7418 // Here we use const_value->type because that's the type of the llvm global,7406 // Here we use const_value->type because that's the type of the llvm global,
7419 // which we const ptr cast upon use to whatever it needs to be.7407 // which we const ptr cast upon use to whatever it needs to be.
7420 if (var->gen_is_const && var->const_value->type->id != ZigTypeIdFn) {7408 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);
7422 }7410 }
74237411
7424 LLVMSetGlobalConstant(global_value, var->gen_is_const);7412 LLVMSetGlobalConstant(global_value, var->gen_is_const);
...@@ -8012,31 +8000,26 @@ static void define_intern_values(CodeGen *g) {...@@ -8012,31 +8000,26 @@ static void define_intern_values(CodeGen *g) {
8012 {8000 {
8013 auto& value = g->intern.x_undefined;8001 auto& value = g->intern.x_undefined;
8014 value.type = g->builtin_types.entry_undef;8002 value.type = g->builtin_types.entry_undef;
8015 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.undefined");
8016 value.special = ConstValSpecialStatic;8003 value.special = ConstValSpecialStatic;
8017 }8004 }
8018 {8005 {
8019 auto& value = g->intern.x_void;8006 auto& value = g->intern.x_void;
8020 value.type = g->builtin_types.entry_void;8007 value.type = g->builtin_types.entry_void;
8021 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.void");
8022 value.special = ConstValSpecialStatic;8008 value.special = ConstValSpecialStatic;
8023 }8009 }
8024 {8010 {
8025 auto& value = g->intern.x_null;8011 auto& value = g->intern.x_null;
8026 value.type = g->builtin_types.entry_null;8012 value.type = g->builtin_types.entry_null;
8027 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.null");
8028 value.special = ConstValSpecialStatic;8013 value.special = ConstValSpecialStatic;
8029 }8014 }
8030 {8015 {
8031 auto& value = g->intern.x_unreachable;8016 auto& value = g->intern.x_unreachable;
8032 value.type = g->builtin_types.entry_unreachable;8017 value.type = g->builtin_types.entry_unreachable;
8033 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.unreachable");
8034 value.special = ConstValSpecialStatic;8018 value.special = ConstValSpecialStatic;
8035 }8019 }
8036 {8020 {
8037 auto& value = g->intern.zero_byte;8021 auto& value = g->intern.zero_byte;
8038 value.type = g->builtin_types.entry_u8;8022 value.type = g->builtin_types.entry_u8;
8039 value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs.zero_byte");
8040 value.special = ConstValSpecialStatic;8023 value.special = ConstValSpecialStatic;
8041 bigint_init_unsigned(&value.data.x_bigint, 0);8024 bigint_init_unsigned(&value.data.x_bigint, 0);
8042 }8025 }
...@@ -8669,19 +8652,10 @@ static void init(CodeGen *g) {...@@ -8669,19 +8652,10 @@ static void init(CodeGen *g) {
8669 g->invalid_instruction = &sentinel_instructions[0];8652 g->invalid_instruction = &sentinel_instructions[0];
8670 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");8653 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");
8671 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;8654 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;
8672 g->invalid_instruction->value->global_refs = allocate<ConstGlobalRefs>(1);
86738655
8674 g->unreach_instruction = &sentinel_instructions[1];8656 g->unreach_instruction = &sentinel_instructions[1];
8675 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");8657 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8676 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;8658 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
8686 define_builtin_fns(g);8660 define_builtin_fns(g);
8687 Error err;8661 Error err;
src/ir.cpp+381-346
...@@ -42,6 +42,10 @@ struct IrAnalyze {...@@ -42,6 +42,10 @@ struct IrAnalyze {
42 ZigList<IrSuspendPosition> resume_stack;42 ZigList<IrSuspendPosition> resume_stack;
43 IrBasicBlock *const_predecessor_bb;43 IrBasicBlock *const_predecessor_bb;
44 size_t ref_count;44 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();
45};49};
4650
47enum ConstCastResultId {51enum ConstCastResultId {
...@@ -195,6 +199,14 @@ struct ConstCastIntShorten {...@@ -195,6 +199,14 @@ struct ConstCastIntShorten {
195 ZigType *actual_type;199 ZigType *actual_type;
196};200};
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
198static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);210static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);
199static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,211static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,
200 ResultLoc *result_loc);212 ResultLoc *result_loc);
...@@ -220,14 +232,15 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -220,14 +232,15 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
220static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,232static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
221 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);233 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);
222static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);234static 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);
224static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);236static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
225static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,237static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,
226 ZigType *ptr_type);238 ZigType *ptr_type);
227static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,239static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
228 ZigType *dest_type);240 ZigType *dest_type);
229static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,241static 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);
231static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,244static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
232 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,245 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
233 bool non_null_comptime, bool allow_discard);246 bool non_null_comptime, bool allow_discard);
...@@ -733,6 +746,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte...@@ -733,6 +746,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
733 case ZigTypeIdErrorSet:746 case ZigTypeIdErrorSet:
734 case ZigTypeIdOpaque:747 case ZigTypeIdOpaque:
735 case ZigTypeIdAnyFrame:748 case ZigTypeIdAnyFrame:
749 case ZigTypeIdFn:
736 return true;750 return true;
737 case ZigTypeIdFloat:751 case ZigTypeIdFloat:
738 return expected->data.floating.bit_count == actual->data.floating.bit_count;752 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...@@ -744,7 +758,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
744 case ZigTypeIdErrorUnion:758 case ZigTypeIdErrorUnion:
745 case ZigTypeIdEnum:759 case ZigTypeIdEnum:
746 case ZigTypeIdUnion:760 case ZigTypeIdUnion:
747 case ZigTypeIdFn:
748 case ZigTypeIdArgTuple:761 case ZigTypeIdArgTuple:
749 case ZigTypeIdVector:762 case ZigTypeIdVector:
750 case ZigTypeIdFnFrame:763 case ZigTypeIdFnFrame:
...@@ -1541,7 +1554,6 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no...@@ -1541,7 +1554,6 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no
1541 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);1554 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);
1542 special_instruction->base.owner_bb = irb->current_basic_block;1555 special_instruction->base.owner_bb = irb->current_basic_block;
1543 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");1556 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1544 special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs");
1545 return special_instruction;1557 return special_instruction;
1546}1558}
15471559
...@@ -4324,6 +4336,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4324,6 +4336,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4324 scope_block->peer_parent = allocate<ResultLocPeerParent>(1, "ResultLocPeerParent");4336 scope_block->peer_parent = allocate<ResultLocPeerParent>(1, "ResultLocPeerParent");
4325 scope_block->peer_parent->base.id = ResultLocIdPeerParent;4337 scope_block->peer_parent->base.id = ResultLocIdPeerParent;
4326 scope_block->peer_parent->base.source_instruction = scope_block->is_comptime;4338 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;
4327 scope_block->peer_parent->end_bb = scope_block->end_block;4340 scope_block->peer_parent->end_bb = scope_block->end_block;
4328 scope_block->peer_parent->is_comptime = scope_block->is_comptime;4341 scope_block->peer_parent->is_comptime = scope_block->is_comptime;
4329 scope_block->peer_parent->parent = result_loc;4342 scope_block->peer_parent->parent = result_loc;
...@@ -4578,6 +4591,7 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction...@@ -4578,6 +4591,7 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction
4578 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);4591 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
4579 peer_parent->base.id = ResultLocIdPeerParent;4592 peer_parent->base.id = ResultLocIdPeerParent;
4580 peer_parent->base.source_instruction = cond_br_inst;4593 peer_parent->base.source_instruction = cond_br_inst;
4594 peer_parent->base.allow_write_through_const = parent->allow_write_through_const;
4581 peer_parent->end_bb = end_block;4595 peer_parent->end_bb = end_block;
4582 peer_parent->is_comptime = is_comptime;4596 peer_parent->is_comptime = is_comptime;
4583 peer_parent->parent = parent;4597 peer_parent->parent = parent;
...@@ -6349,7 +6363,9 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node...@@ -6349,7 +6363,9 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
63496363
6350 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);6364 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
6351 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, fn_type, arg_index, true);6365 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
6354 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);6370 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
6355 if (arg == irb->codegen->invalid_instruction)6371 if (arg == irb->codegen->invalid_instruction)
...@@ -6771,6 +6787,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo...@@ -6771,6 +6787,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *allo
6771 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);6787 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
6772 result_loc_var->base.id = ResultLocIdVar;6788 result_loc_var->base.id = ResultLocIdVar;
6773 result_loc_var->base.source_instruction = alloca;6789 result_loc_var->base.source_instruction = alloca;
6790 result_loc_var->base.allow_write_through_const = true;
6774 result_loc_var->var = var;6791 result_loc_var->var = var;
67756792
6776 ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base);6793 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...@@ -6784,6 +6801,7 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de
6784 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);6801 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
6785 result_loc_cast->base.id = ResultLocIdCast;6802 result_loc_cast->base.id = ResultLocIdCast;
6786 result_loc_cast->base.source_instruction = dest_type;6803 result_loc_cast->base.source_instruction = dest_type;
6804 result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const;
6787 ir_ref_instruction(dest_type, irb->current_basic_block);6805 ir_ref_instruction(dest_type, irb->current_basic_block);
6788 result_loc_cast->parent = parent_result_loc;6806 result_loc_cast->parent = parent_result_loc;
67896807
...@@ -7964,6 +7982,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7964,6 +7982,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
79647982
7965 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);7983 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
7966 peer_parent->base.id = ResultLocIdPeerParent;7984 peer_parent->base.id = ResultLocIdPeerParent;
7985 peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
7967 peer_parent->end_bb = end_block;7986 peer_parent->end_bb = end_block;
7968 peer_parent->is_comptime = is_comptime;7987 peer_parent->is_comptime = is_comptime;
7969 peer_parent->parent = result_loc;7988 peer_parent->parent = result_loc;
...@@ -9111,7 +9130,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast...@@ -9111,7 +9130,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast
9111 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))9130 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
9112 return err;9131 return err;
9113 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);9132 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);
9115 return ErrorNone;9134 return ErrorNone;
9116}9135}
91179136
...@@ -10756,10 +10775,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10756,10 +10775,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10756 continue;10775 continue;
10757 }10776 }
10758 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;10777 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)) {
10760 return ira->codegen->builtin_types.entry_invalid;10781 return ira->codegen->builtin_types.entry_invalid;
10761 }10782 }
10762 if (type_is_global_error_set(cur_err_set_type)) {10783 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
10763 err_set_type = ira->codegen->builtin_types.entry_global_error_set;10784 err_set_type = ira->codegen->builtin_types.entry_global_error_set;
10764 prev_inst = cur_inst;10785 prev_inst = cur_inst;
10765 continue;10786 continue;
...@@ -10809,9 +10830,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10809,9 +10830,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10809 }10830 }
1081010831
10811 if (cur_type->id == ZigTypeIdErrorSet) {10832 if (cur_type->id == ZigTypeIdErrorSet) {
10812 if (prev_type->id == ZigTypeIdArray) {
10813 convert_to_const_slice = true;
10814 }
10815 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {10833 if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
10816 return ira->codegen->builtin_types.entry_invalid;10834 return ira->codegen->builtin_types.entry_invalid;
10817 }10835 }
...@@ -11146,25 +11164,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11146,25 +11164,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11146 }11164 }
11147 }11165 }
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
11168 // *[N]T to []T11167 // *[N]T to []T
11169 // *[N]T to E![]T11168 // *[N]T to E![]T
11170 if (cur_type->id == ZigTypeIdPointer &&11169 if (cur_type->id == ZigTypeIdPointer &&
...@@ -11212,19 +11211,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11212,19 +11211,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11212 }11211 }
11213 }11212 }
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
11228 // *[N]T and *[M]T11214 // *[N]T and *[M]T
11229 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&11215 if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
11230 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&11216 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
...@@ -11268,19 +11254,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11268,19 +11254,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11268 continue;11254 continue;
11269 }11255 }
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
11284 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&11257 if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
11285 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))11258 (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
11286 {11259 {
...@@ -11316,18 +11289,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11316,18 +11289,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11316 free(errors);11289 free(errors);
1131711290
11318 if (convert_to_const_slice) {11291 if (convert_to_const_slice) {
11319 if (prev_inst->value->type->id == ZigTypeIdArray) {11292 if (prev_inst->value->type->id == ZigTypeIdPointer) {
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) {
11331 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;11293 ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
11332 src_assert(array_type->id == ZigTypeIdArray, source_node);11294 src_assert(array_type->id == ZigTypeIdArray, source_node);
11333 ZigType *ptr_type = get_pointer_to_type_extra2(11295 ZigType *ptr_type = get_pointer_to_type_extra2(
...@@ -11394,19 +11356,37 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11394,19 +11356,37 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11394 }11356 }
11395}11357}
1139611358
11397static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) {11359// Returns whether the x_optional field of ZigValue is active.
11398 ConstGlobalRefs *global_refs = dest->global_refs;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) {
11399 memcpy(dest, src, sizeof(ZigValue));11373 memcpy(dest, src, sizeof(ZigValue));
11400 if (!same_global_refs) {11374 if (src->special != ConstValSpecialStatic)
11401 dest->global_refs = global_refs;11375 return;
11402 if (src->special != ConstValSpecialStatic)11376 dest->parent.id = ConstParentIdNone;
11403 return;11377 if (dest->type->id == ZigTypeIdStruct) {
11404 if (dest->type->id == ZigTypeIdStruct) {11378 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
11405 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) {
11406 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]);
11407 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i], false);11381 dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;
11408 }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;
11409 }11384 }
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;
11410 }11390 }
11411}11391}
1141211392
...@@ -11424,13 +11404,11 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -11424,13 +11404,11 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
11424 case CastOpErrSet:11404 case CastOpErrSet:
11425 case CastOpBitCast:11405 case CastOpBitCast:
11426 zig_panic("TODO");11406 zig_panic("TODO");
11427 case CastOpNoop:11407 case CastOpNoop: {
11428 {11408 copy_const_val(const_val, other_val);
11429 bool same_global_refs = other_val->special == ConstValSpecialStatic;11409 const_val->type = new_type;
11430 copy_const_val(const_val, other_val, same_global_refs);11410 break;
11431 const_val->type = new_type;11411 }
11432 break;
11433 }
11434 case CastOpNumLitToConcrete:11412 case CastOpNumLitToConcrete:
11435 if (other_val->type->id == ZigTypeIdComptimeFloat) {11413 if (other_val->type->id == ZigTypeIdComptimeFloat) {
11436 assert(new_type->id == ZigTypeIdFloat);11414 assert(new_type->id == ZigTypeIdFloat);
...@@ -11527,6 +11505,14 @@ static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruct...@@ -11527,6 +11505,14 @@ static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruct
11527 return &const_instruction->base;11505 return &const_instruction->base;
11528}11506}
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
11530static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,11516static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
11531 ZigType *wanted_type, CastOp cast_op)11517 ZigType *wanted_type, CastOp cast_op)
11532{11518{
...@@ -12151,7 +12137,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so...@@ -12151,7 +12137,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
12151 source_instr->scope, source_instr->source_node);12137 source_instr->scope, source_instr->source_node);
12152 const_instruction->base.value->special = ConstValSpecialStatic;12138 const_instruction->base.value->special = ConstValSpecialStatic;
12153 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {12139 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);
12155 } else {12141 } else {
12156 const_instruction->base.value->data.x_optional = val;12142 const_instruction->base.value->data.x_optional = val;
12157 }12143 }
...@@ -12413,52 +12399,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi...@@ -12413,52 +12399,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
12413 return new_instruction;12399 return new_instruction;
12414}12400}
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
12462static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {12402static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
12463 assert(union_type->id == ZigTypeIdUnion);12403 assert(union_type->id == ZigTypeIdUnion);
1246412404
...@@ -13155,7 +13095,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *...@@ -13155,7 +13095,7 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
13155 if (instr_is_comptime(array)) {13095 if (instr_is_comptime(array)) {
13156 // arrays and vectors have the same ZigValue representation13096 // arrays and vectors have the same ZigValue representation
13157 IrInstruction *result = ir_const(ira, source_instr, vector_type);13097 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);
13159 result->value->type = vector_type;13099 result->value->type = vector_type;
13160 return result;13100 return result;
13161 }13101 }
...@@ -13168,7 +13108,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *...@@ -13168,7 +13108,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
13168 if (instr_is_comptime(vector)) {13108 if (instr_is_comptime(vector)) {
13169 // arrays and vectors have the same ZigValue representation13109 // arrays and vectors have the same ZigValue representation
13170 IrInstruction *result = ir_const(ira, source_instr, array_type);13110 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);
13172 result->value->type = array_type;13112 result->value->type = array_type;
13173 return result;13113 return result;
13174 }13114 }
...@@ -13456,7 +13396,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13456,7 +13396,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13456 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {13396 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
13457 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13397 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
13458 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {13398 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);
13460 result->value->type = wanted_type;13400 result->value->type = wanted_type;
13461 } else {13401 } else {
13462 float_init_bigint(&result->value->data.x_bigint, value->value);13402 float_init_bigint(&result->value->data.x_bigint, value->value);
...@@ -13504,44 +13444,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13504,44 +13444,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13504 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);13444 return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
13505 }13445 }
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
13545 // *[N]T to ?[]const T13447 // *[N]T to ?[]const T
13546 if (wanted_type->id == ZigTypeIdOptional &&13448 if (wanted_type->id == ZigTypeIdOptional &&
13547 is_slice(wanted_type->data.maybe.child_type) &&13449 is_slice(wanted_type->data.maybe.child_type) &&
...@@ -13687,20 +13589,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13687,20 +13589,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13687 }13589 }
1368813590
13689 // *@Frame(func) to anyframe->T or anyframe13591 // *@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
13690 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&13594 if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&
13691 !actual_type->data.pointer.is_const &&13595 !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)
13693 {13597 {
13694 bool ok = true;13598 ZigType *anyframe_type;
13695 if (wanted_type->data.any_frame.result_type != nullptr) {13599 if (wanted_type->id == ZigTypeIdAnyFrame) {
13696 ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;13600 anyframe_type = wanted_type;
13697 ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;13601 } else if (wanted_type->id == ZigTypeIdOptional &&
13698 if (wanted_type->data.any_frame.result_type != fn_return_type) {13602 wanted_type->data.maybe.child_type->id == ZigTypeIdAnyFrame)
13699 ok = false;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);
13700 }13626 }
13701 }
13702 if (ok) {
13703 return ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, wanted_type);
13704 }13627 }
13705 }13628 }
1370613629
...@@ -13725,30 +13648,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13725,30 +13648,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13725 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);13648 return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);
13726 }13649 }
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
13752 // cast from E to E!T13651 // cast from E to E!T
13753 if (wanted_type->id == ZigTypeIdErrorUnion &&13652 if (wanted_type->id == ZigTypeIdErrorUnion &&
13754 actual_type->id == ZigTypeIdErrorSet)13653 actual_type->id == ZigTypeIdErrorSet)
...@@ -13944,6 +13843,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13944,6 +13843,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13944 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);13843 return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
13945 }13844 }
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
13947 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,13864 ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
13948 buf_sprintf("expected type '%s', found '%s'",13865 buf_sprintf("expected type '%s', found '%s'",
13949 buf_ptr(&wanted_type->name),13866 buf_ptr(&wanted_type->name),
...@@ -14338,9 +14255,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -14338,9 +14255,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
14338}14255}
1433914256
14340static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {14257static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {
14341 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);14258 return ir_const_move(ira, &instruction->base, instruction->base.value);
14342 copy_const_val(result->value, instruction->base.value, true);
14343 return result;
14344}14259}
1434514260
14346static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {14261static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
...@@ -14878,7 +14793,7 @@ never_mind_just_calculate_it_normally:...@@ -14878,7 +14793,7 @@ never_mind_just_calculate_it_normally:
14878 &op1_val->data.x_array.data.s_none.elements[i],14793 &op1_val->data.x_array.data.s_none.elements[i],
14879 &op2_val->data.x_array.data.s_none.elements[i],14794 &op2_val->data.x_array.data.s_none.elements[i],
14880 bin_op_instruction, op_id, one_possible_value);14795 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);
14882 }14797 }
14883 return result;14798 return result;
14884 }14799 }
...@@ -15686,10 +15601,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15686,10 +15601,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
1568615601
15687 ZigValue *out_array_val;15602 ZigValue *out_array_val;
15688 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);15603 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) {15604 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
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) {
15693 out_array_val = create_const_vals(1);15605 out_array_val = create_const_vals(1);
15694 out_array_val->special = ConstValSpecialStatic;15606 out_array_val->special = ConstValSpecialStatic;
15695 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);15607 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...@@ -15717,6 +15629,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15717 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;15629 out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
15718 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;15630 out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
15719 bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);15631 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;
15720 } else {15635 } else {
15721 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,15636 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
15722 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);15637 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
...@@ -15744,21 +15659,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -15744,21 +15659,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
15744 size_t next_index = 0;15659 size_t next_index = 0;
15745 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {15660 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
15746 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15661 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]);
15748 elem_dest_val->parent.id = ConstParentIdArray;15663 elem_dest_val->parent.id = ConstParentIdArray;
15749 elem_dest_val->parent.data.p_array.array_val = out_array_val;15664 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15750 elem_dest_val->parent.data.p_array.elem_index = next_index;15665 elem_dest_val->parent.data.p_array.elem_index = next_index;
15751 }15666 }
15752 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {15667 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
15753 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15668 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]);
15755 elem_dest_val->parent.id = ConstParentIdArray;15670 elem_dest_val->parent.id = ConstParentIdArray;
15756 elem_dest_val->parent.data.p_array.array_val = out_array_val;15671 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15757 elem_dest_val->parent.data.p_array.elem_index = next_index;15672 elem_dest_val->parent.data.p_array.elem_index = next_index;
15758 }15673 }
15759 if (next_index < full_len) {15674 if (next_index < full_len) {
15760 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];15675 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);
15762 elem_dest_val->parent.id = ConstParentIdArray;15677 elem_dest_val->parent.id = ConstParentIdArray;
15763 elem_dest_val->parent.data.p_array.array_val = out_array_val;15678 elem_dest_val->parent.data.p_array.array_val = out_array_val;
15764 elem_dest_val->parent.data.p_array.elem_index = next_index;15679 elem_dest_val->parent.data.p_array.elem_index = next_index;
...@@ -15843,7 +15758,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15843,7 +15758,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
15843 for (uint64_t x = 0; x < mult_amt; x += 1) {15758 for (uint64_t x = 0; x < mult_amt; x += 1) {
15844 for (uint64_t y = 0; y < old_array_len; y += 1) {15759 for (uint64_t y = 0; y < old_array_len; y += 1) {
15845 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];15760 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]);
15847 elem_dest_val->parent.id = ConstParentIdArray;15762 elem_dest_val->parent.id = ConstParentIdArray;
15848 elem_dest_val->parent.data.p_array.array_val = out_val;15763 elem_dest_val->parent.data.p_array.array_val = out_val;
15849 elem_dest_val->parent.data.p_array.elem_index = i;15764 elem_dest_val->parent.data.p_array.elem_index = i;
...@@ -15854,7 +15769,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -15854,7 +15769,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
1585415769
15855 if (array_type->data.array.sentinel != nullptr) {15770 if (array_type->data.array.sentinel != nullptr) {
15856 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];15771 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);
15858 elem_dest_val->parent.id = ConstParentIdArray;15773 elem_dest_val->parent.id = ConstParentIdArray;
15859 elem_dest_val->parent.data.p_array.array_val = out_val;15774 elem_dest_val->parent.data.p_array.array_val = out_val;
15860 elem_dest_val->parent.data.p_array.elem_index = i;15775 elem_dest_val->parent.data.p_array.elem_index = i;
...@@ -16004,7 +15919,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16004,7 +15919,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16004 var->const_value = init_val;15919 var->const_value = init_val;
16005 } else {15920 } else {
16006 var->const_value = create_const_vals(1);15921 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);
16008 }15923 }
16009 }15924 }
16010 }15925 }
...@@ -16030,7 +15945,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16030,7 +15945,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16030 result_type = ira->codegen->builtin_types.entry_invalid;15945 result_type = ira->codegen->builtin_types.entry_invalid;
16031 } else if (init_val->type->id == ZigTypeIdFn &&15946 } else if (init_val->type->id == ZigTypeIdFn &&
16032 init_val->special != ConstValSpecialUndef &&15947 init_val->special != ConstValSpecialUndef &&
16033 init_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&15948 init_val->data.x_ptr.special == ConstPtrSpecialFunction &&
16034 init_val->data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)15949 init_val->data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
16035 {15950 {
16036 var_class_requires_const = true;15951 var_class_requires_const = true;
...@@ -16114,7 +16029,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16114,7 +16029,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16114 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {16029 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {
16115 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);16030 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
16116 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);16031 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);
16118 ira_ref(var->owner_exec->analysis);16033 ira_ref(var->owner_exec->analysis);
1611916034
16120 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {16035 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...@@ -16546,7 +16461,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
1654616461
16547// when calling this function, at the callsite must check for result type noreturn and propagate it up16462// when calling this function, at the callsite must check for result type noreturn and propagate it up
16548static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,16463static 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)
16550{16466{
16551 Error err;16467 Error err;
16552 if (result_loc->resolved_loc != nullptr) {16468 if (result_loc->resolved_loc != nullptr) {
...@@ -16584,7 +16500,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16584,7 +16500,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16584 bool force_comptime;16500 bool force_comptime;
16585 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))16501 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
16586 return ira->codegen->invalid_instruction;16502 return ira->codegen->invalid_instruction;
16587 bool is_comptime = force_comptime || (value != nullptr &&16503 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&
16588 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);16504 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
1658916505
16590 if (alloca_src->base.child == nullptr || is_comptime) {16506 if (alloca_src->base.child == nullptr || is_comptime) {
...@@ -16594,15 +16510,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16594,15 +16510,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16594 }16510 }
16595 IrInstruction *alloca_gen;16511 IrInstruction *alloca_gen;
16596 if (is_comptime && value != nullptr) {16512 if (is_comptime && value != nullptr) {
16597 if (align > value->value->global_refs->align) {16513 if (align > value->value->llvm_align) {
16598 value->value->global_refs->align = align;16514 value->value->llvm_align = align;
16599 }16515 }
16600 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);16516 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
16601 } else {16517 } else {
16602 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,16518 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
16603 alloca_src->name_hint, force_comptime);16519 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 }
16604 }16524 }
16605 if (alloca_src->base.child != nullptr) {16525 if (alloca_src->base.child != nullptr && !result_loc->written) {
16606 alloca_src->base.child->ref_count = 0;16526 alloca_src->base.child->ref_count = 0;
16607 }16527 }
16608 alloca_src->base.child = alloca_gen;16528 alloca_src->base.child = alloca_gen;
...@@ -16617,6 +16537,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16617,6 +16537,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16617 return result_loc->resolved_loc;16537 return result_loc->resolved_loc;
16618 }16538 }
16619 case ResultLocIdReturn: {16539 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 }
16620 if (!non_null_comptime) {16544 if (!non_null_comptime) {
16621 bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime;16545 bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime;
16622 if (is_comptime)16546 if (is_comptime)
...@@ -16659,10 +16583,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16659,10 +16583,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16659 return result_loc->resolved_loc;16583 return result_loc->resolved_loc;
16660 }16584 }
1666116585
16662 bool is_comptime;16586 bool is_condition_comptime;
16663 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_comptime))16587 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))
16664 return ira->codegen->invalid_instruction;16588 return ira->codegen->invalid_instruction;
16665 if (is_comptime) {16589 if (is_condition_comptime) {
16666 peer_parent->skipped = true;16590 peer_parent->skipped = true;
16667 if (non_null_comptime) {16591 if (non_null_comptime) {
16668 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,16592 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...@@ -16674,13 +16598,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16674 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))16598 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
16675 return ira->codegen->invalid_instruction;16599 return ira->codegen->invalid_instruction;
16676 if (peer_parent_has_type) {16600 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 }
16681 peer_parent->skipped = true;16601 peer_parent->skipped = true;
16682 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,16602 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
16683 value_type, value, force_runtime || !is_comptime, true, true);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;
16684 }16613 }
1668516614
16686 if (peer_parent->resolved_type == nullptr) {16615 if (peer_parent->resolved_type == nullptr) {
...@@ -16702,14 +16631,14 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16702,14 +16631,14 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16702 {16631 {
16703 return parent_result_loc;16632 return parent_result_loc;
16704 }16633 }
16705 // because is_comptime is false, we mark this a runtime pointer16634 // because is_condition_comptime is false, we mark this a runtime pointer
16706 parent_result_loc->value->special = ConstValSpecialRuntime;16635 parent_result_loc->value->special = ConstValSpecialRuntime;
16707 result_loc->written = true;16636 result_loc->written = true;
16708 result_loc->resolved_loc = parent_result_loc;16637 result_loc->resolved_loc = parent_result_loc;
16709 return result_loc->resolved_loc;16638 return result_loc->resolved_loc;
16710 }16639 }
16711 case ResultLocIdCast: {16640 case ResultLocIdCast: {
16712 if (value != nullptr && value->value->special != ConstValSpecialRuntime)16641 if (value != nullptr && value->value->special != ConstValSpecialRuntime && !non_null_comptime)
16713 return nullptr;16642 return nullptr;
16714 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);16643 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
16715 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);16644 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...@@ -16721,30 +16650,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16721 force_runtime, non_null_comptime);16650 force_runtime, non_null_comptime);
16722 }16651 }
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.
16736 IrInstruction *casted_value;16653 IrInstruction *casted_value;
16737 if (value != nullptr) {16654 if (value != nullptr) {
16738 casted_value = ir_implicit_cast(ira, value, dest_type);16655 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;
16739 } else {16659 } else {
16740 casted_value = nullptr;16660 casted_value = nullptr;
16741 }16661 }
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;
16748 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,16663 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
16749 dest_type, casted_value, force_runtime, non_null_comptime, true);16664 dest_type, casted_value, force_runtime, non_null_comptime, true);
16750 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||16665 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...@@ -16752,8 +16667,10 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16752 {16667 {
16753 return parent_result_loc;16668 return parent_result_loc;
16754 }16669 }
16670
16755 ZigType *parent_ptr_type = parent_result_loc->value->type;16671 ZigType *parent_ptr_type = parent_result_loc->value->type;
16756 assert(parent_ptr_type->id == ZigTypeIdPointer);16672 assert(parent_ptr_type->id == ZigTypeIdPointer);
16673
16757 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,16674 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
16758 ResolveStatusAlignmentKnown)))16675 ResolveStatusAlignmentKnown)))
16759 {16676 {
...@@ -16782,20 +16699,20 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16782,20 +16699,20 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16782 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,16699 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
16783 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);16700 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1678416701
16785 {16702 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
16786 // we also need to check that this cast is OK.16703 parent_result_loc->value->type, ptr_type,
16787 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,16704 result_cast->base.source_instruction->source_node, false);
16788 parent_result_loc->value->type, ptr_type,16705 if (const_cast_result.id == ConstCastResultIdInvalid)
16789 result_cast->base.source_instruction->source_node, false);16706 return ira->codegen->invalid_instruction;
16790 if (const_cast_result.id == ConstCastResultIdInvalid)16707 if (const_cast_result.id != ConstCastResultIdOk) {
16791 return ira->codegen->invalid_instruction;16708 if (allow_discard) {
16792 if (const_cast_result.id != ConstCastResultIdOk) {16709 return parent_result_loc;
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);
16798 }16710 }
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);
16799 }16716 }
1680016717
16801 result_loc->written = true;16718 result_loc->written = true;
...@@ -16836,6 +16753,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -16836,6 +16753,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
16836 IrInstruction *bitcasted_value;16753 IrInstruction *bitcasted_value;
16837 if (value != nullptr) {16754 if (value != nullptr) {
16838 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type);16755 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type);
16756 dest_type = bitcasted_value->value->type;
16839 } else {16757 } else {
16840 bitcasted_value = nullptr;16758 bitcasted_value = nullptr;
16841 }16759 }
...@@ -16887,7 +16805,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -16887,7 +16805,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16887 result_loc_pass1 = no_result_loc();16805 result_loc_pass1 = no_result_loc();
16888 }16806 }
16889 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,16807 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);
16891 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))16809 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
16892 return result_loc;16810 return result_loc;
1689316811
...@@ -16900,11 +16818,13 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -16900,11 +16818,13 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16900 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);16818 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
16901 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;16819 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
16902 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&16820 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))
16904 {16822 {
16905 result_loc_pass1->written = false;16823 result_loc_pass1->written = false;
16906 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);16824 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 {
16908 if (value_type->id == ZigTypeIdErrorSet) {16828 if (value_type->id == ZigTypeIdErrorSet) {
16909 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);16829 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
16910 } else {16830 } else {
...@@ -16918,9 +16838,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -16918,9 +16838,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
16918 return unwrapped_err_ptr;16838 return unwrapped_err_ptr;
16919 }16839 }
16920 }16840 }
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;
16924 }16841 }
16925 return result_loc;16842 return result_loc;
16926}16843}
...@@ -17159,7 +17076,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -17159,7 +17076,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
17159 arg_val = create_const_runtime(casted_arg->value->type);17076 arg_val = create_const_runtime(casted_arg->value->type);
17160 }17077 }
17161 if (arg_part_of_generic_id) {17078 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);
17163 generic_id->param_count += 1;17080 generic_id->param_count += 1;
17164 }17081 }
1716517082
...@@ -17340,7 +17257,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -17340,7 +17257,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
17340 IrInstruction *casted_ptr;17257 IrInstruction *casted_ptr;
17341 if (instr_is_comptime(ptr)) {17258 if (instr_is_comptime(ptr)) {
17342 casted_ptr = ir_const(ira, source_instr, struct_ptr_type);17259 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);
17344 casted_ptr->value->type = struct_ptr_type;17261 casted_ptr->value->type = struct_ptr_type;
17345 } else {17262 } else {
17346 casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope,17263 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...@@ -17403,14 +17320,8 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
17403 if (dest_val == nullptr)17320 if (dest_val == nullptr)
17404 return ira->codegen->invalid_instruction;17321 return ira->codegen->invalid_instruction;
17405 if (dest_val->special != ConstValSpecialRuntime) {17322 if (dest_val->special != ConstValSpecialRuntime) {
17406 // TODO this allows a value stored to have the original value modified and then17323 copy_const_val(dest_val, value->value);
17407 // have that affect what should be a copy. We need some kind of advanced copy-on-write17324
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);
17414 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&17325 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
17415 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)17326 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
17416 {17327 {
...@@ -17684,9 +17595,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17684,9 +17595,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17684 }17595 }
17685 }17596 }
1768617597
17687 IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type);17598 IrInstruction *new_instruction = ir_const_move(ira, &call_instruction->base, result);
17688 copy_const_val(new_instruction->value, result, true);
17689 new_instruction->value->type = return_type;
17690 return ir_finish_anal(ira, new_instruction);17599 return ir_finish_anal(ira, new_instruction);
17691 }17600 }
1769217601
...@@ -17842,7 +17751,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -17842,7 +17751,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
17842 nullptr, UndefBad);17751 nullptr, UndefBad);
17843 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,17752 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
17844 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);17753 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
17847 uint32_t align_bytes = 0;17756 uint32_t align_bytes = 0;
17848 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);17757 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...@@ -18172,7 +18081,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
1817218081
18173 if (dst_size <= src_size) {18082 if (dst_size <= src_size) {
18174 if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) {18083 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);
18176 return ErrorNone;18085 return ErrorNone;
18177 }18086 }
18178 Buf buf = BUF_INIT;18087 Buf buf = BUF_INIT;
...@@ -18535,7 +18444,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -18535,7 +18444,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1853518444
18536 if (value->value->special != ConstValSpecialRuntime) {18445 if (value->value->special != ConstValSpecialRuntime) {
18537 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);18446 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);
18539 return result;18448 return result;
18540 } else {18449 } else {
18541 return value;18450 return value;
...@@ -18928,7 +18837,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -18928,7 +18837,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
18928 if (index == array_len && array_type->data.array.sentinel != nullptr) {18837 if (index == array_len && array_type->data.array.sentinel != nullptr) {
18929 ZigType *elem_type = array_type->data.array.child_type;18838 ZigType *elem_type = array_type->data.array.child_type;
18930 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);18839 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);
18932 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);18841 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);
18933 }18842 }
18934 if (index >= array_len) {18843 if (index >= array_len) {
...@@ -19007,7 +18916,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19007,7 +18916,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19007 return ira->codegen->invalid_instruction;18916 return ira->codegen->invalid_instruction;
19008 if (actual_array_type->id != ZigTypeIdArray) {18917 if (actual_array_type->id != ZigTypeIdArray) {
19009 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,18918 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)));
19011 return ira->codegen->invalid_instruction;18921 return ira->codegen->invalid_instruction;
19012 }18922 }
1901318923
...@@ -19419,7 +19329,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -19419,7 +19329,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
1941919329
19420 if (instr_is_comptime(container_ptr)) {19330 if (instr_is_comptime(container_ptr)) {
19421 IrInstruction *result = ir_const(ira, source_instr, field_ptr_type);19331 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);
19423 result->value->type = field_ptr_type;19333 result->value->type = field_ptr_type;
19424 return result;19334 return result;
19425 }19335 }
...@@ -20851,7 +20761,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -20851,7 +20761,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
20851 case ZigTypeIdErrorSet: {20761 case ZigTypeIdErrorSet: {
20852 if (pointee_val) {20762 if (pointee_val) {
20853 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);20763 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);
20855 result->value->type = target_type;20765 result->value->type = target_type;
20856 return result;20766 return result;
20857 }20767 }
...@@ -21347,7 +21257,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -21347,7 +21257,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
21347 return ira->codegen->invalid_instruction;21257 return ira->codegen->invalid_instruction;
2134821258
21349 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);21259 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
21352 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,21262 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,
21353 container_type, true);21263 container_type, true);
...@@ -21399,7 +21309,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21399,7 +21309,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
2139921309
21400 if (is_slice(container_type)) {21310 if (is_slice(container_type)) {
21401 ir_add_error_node(ira, instruction->init_array_type_source_node,21311 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)));
21403 return ira->codegen->invalid_instruction;21314 return ira->codegen->invalid_instruction;
21404 }21315 }
2140521316
...@@ -21435,6 +21346,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -21435,6 +21346,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
21435 {21346 {
21436 // We're now done inferring the type.21347 // We're now done inferring the type.
21437 container_type->data.structure.resolve_status = ResolveStatusUnstarted;21348 container_type->data.structure.resolve_status = ResolveStatusUnstarted;
21349 } else if (container_type->id == ZigTypeIdVector) {
21350 // OK
21438 } else {21351 } else {
21439 ir_add_error_node(ira, instruction->base.source_node,21352 ir_add_error_node(ira, instruction->base.source_node,
21440 buf_sprintf("type '%s' does not support array initialization",21353 buf_sprintf("type '%s' does not support array initialization",
...@@ -21605,7 +21518,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -21605,7 +21518,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
21605 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);21518 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
21606 }21519 }
21607 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);21520 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);
21609 result->value->type = str_type;21522 result->value->type = str_type;
21610 return result;21523 return result;
21611 }21524 }
...@@ -22828,17 +22741,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,...@@ -22828,17 +22741,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
22828 return result;22741 return result;
22829}22742}
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)
22832{22746{
22747 Error err;
22833 ensure_field_index(struct_value->type, name, field_index);22748 ensure_field_index(struct_value->type, name, field_index);
22834 assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);22749 ZigValue *val = struct_value->data.x_struct.fields[field_index];
22835 return 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;
22836}22753}
2283722754
22838static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,22755static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
22839 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)22756 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
22840{22757{
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;
22842 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);22761 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
22843 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,22762 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
22844 get_optional_type(ira->codegen, elem_type));22763 get_optional_type(ira->codegen, elem_type));
...@@ -22849,23 +22768,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst...@@ -22849,23 +22768,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
22849 return ErrorNone;22768 return ErrorNone;
22850}22769}
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)
22853{22773{
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;
22855 assert(value->type == ira->codegen->builtin_types.entry_bool);22777 assert(value->type == ira->codegen->builtin_types.entry_bool);
22856 return value->data.x_bool;22778 *out = value->data.x_bool;
22779 return ErrorNone;
22857}22780}
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)
22860{22783{
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;
22862 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);22787 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
22863 return &value->data.x_bigint;22788 return &value->data.x_bigint;
22864}22789}
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)
22867{22792{
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;
22869 assert(value->type == ira->codegen->builtin_types.entry_type);22796 assert(value->type == ira->codegen->builtin_types.entry_type);
22870 return value->data.x_type;22797 return value->data.x_type;
22871}22798}
...@@ -22883,17 +22810,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22883,17 +22810,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22883 return ira->codegen->builtin_types.entry_bool;22810 return ira->codegen->builtin_types.entry_bool;
22884 case ZigTypeIdUnreachable:22811 case ZigTypeIdUnreachable:
22885 return ira->codegen->builtin_types.entry_unreachable;22812 return ira->codegen->builtin_types.entry_unreachable;
22886 case ZigTypeIdInt:22813 case ZigTypeIdInt: {
22887 assert(payload->special == ConstValSpecialStatic);22814 assert(payload->special == ConstValSpecialStatic);
22888 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));22815 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
22889 return get_int_type(ira->codegen,22816 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
22890 get_const_field_bool(ira, payload, "is_signed", 0),22817 if (bi == nullptr)
22891 bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1)));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 }
22892 case ZigTypeIdFloat:22824 case ZigTypeIdFloat:
22893 {22825 {
22894 assert(payload->special == ConstValSpecialStatic);22826 assert(payload->special == ConstValSpecialStatic);
22895 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));22827 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);
22897 switch (bits) {22832 switch (bits) {
22898 case 16: return ira->codegen->builtin_types.entry_f16;22833 case 16: return ira->codegen->builtin_types.entry_f16;
22899 case 32: return ira->codegen->builtin_types.entry_f32;22834 case 32: return ira->codegen->builtin_types.entry_f32;
...@@ -22902,34 +22837,58 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22902,34 +22837,58 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22902 }22837 }
22903 ir_add_error(ira, instruction,22838 ir_add_error(ira, instruction,
22904 buf_sprintf("%d-bit float unsupported", bits));22839 buf_sprintf("%d-bit float unsupported", bits));
22905 return nullptr;22840 return ira->codegen->invalid_instruction->value->type;
22906 }22841 }
22907 case ZigTypeIdPointer:22842 case ZigTypeIdPointer:
22908 {22843 {
22909 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);22844 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
22910 assert(payload->special == ConstValSpecialStatic);22845 assert(payload->special == ConstValSpecialStatic);
22911 assert(payload->type == type_info_pointer_type);22846 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);
22913 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));22848 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
22914 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);22849 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
22915 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);22850 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;
22917 ZigValue *sentinel;22854 ZigValue *sentinel;
22918 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,22855 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
22919 elem_type, &sentinel)))22856 elem_type, &sentinel)))
22920 {22857 {
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;
22922 }22873 }
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
22924 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,22883 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
22925 elem_type,22884 elem_type,
22926 get_const_field_bool(ira, payload, "is_const", 1),22885 is_const,
22927 get_const_field_bool(ira, payload, "is_volatile", 2),22886 is_volatile,
22928 ptr_len,22887 ptr_len,
22929 bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)),22888 bigint_as_u32(bi),
22930 0, // bit_offset_in_host22889 0, // bit_offset_in_host
22931 0, // host_int_bytes22890 0, // host_int_bytes
22932 get_const_field_bool(ira, payload, "is_allowzero", 5),22891 is_allowzero,
22933 VECTOR_INDEX_NONE, nullptr, sentinel);22892 VECTOR_INDEX_NONE, nullptr, sentinel);
22934 if (size_enum_index != 2)22893 if (size_enum_index != 2)
22935 return ptr_type;22894 return ptr_type;
...@@ -22938,17 +22897,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22938,17 +22897,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22938 case ZigTypeIdArray: {22897 case ZigTypeIdArray: {
22939 assert(payload->special == ConstValSpecialStatic);22898 assert(payload->special == ConstValSpecialStatic);
22940 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));22899 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;
22942 ZigValue *sentinel;22903 ZigValue *sentinel;
22943 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,22904 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
22944 elem_type, &sentinel)))22905 elem_type, &sentinel)))
22945 {22906 {
22946 return nullptr;22907 return ira->codegen->invalid_instruction->value->type;
22947 }22908 }
22948 return get_array_type(ira->codegen,22909 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
22949 elem_type,22910 if (bi == nullptr)
22950 bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)),22911 return ira->codegen->invalid_instruction->value->type;
22951 sentinel);22912 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
22952 }22913 }
22953 case ZigTypeIdComptimeFloat:22914 case ZigTypeIdComptimeFloat:
22954 return ira->codegen->builtin_types.entry_num_lit_float;22915 return ira->codegen->builtin_types.entry_num_lit_float;
...@@ -22969,7 +22930,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22969,7 +22930,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22969 case ZigTypeIdEnumLiteral:22930 case ZigTypeIdEnumLiteral:
22970 ir_add_error(ira, instruction, buf_sprintf(22931 ir_add_error(ira, instruction, buf_sprintf(
22971 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));22932 "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;
22973 case ZigTypeIdUnion:22934 case ZigTypeIdUnion:
22974 case ZigTypeIdFn:22935 case ZigTypeIdFn:
22975 case ZigTypeIdBoundFn:22936 case ZigTypeIdBoundFn:
...@@ -22977,7 +22938,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -22977,7 +22938,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
22977 case ZigTypeIdStruct:22938 case ZigTypeIdStruct:
22978 ir_add_error(ira, instruction, buf_sprintf(22939 ir_add_error(ira, instruction, buf_sprintf(
22979 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));22940 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
22980 return nullptr;22941 return ira->codegen->invalid_instruction->value->type;
22981 }22942 }
22982 zig_unreachable();22943 zig_unreachable();
22983}22944}
...@@ -22996,7 +22957,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT...@@ -22996,7 +22957,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
22996 return ira->codegen->invalid_instruction;22957 return ira->codegen->invalid_instruction;
22997 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));22958 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
22998 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);22959 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))
23000 return ira->codegen->invalid_instruction;22961 return ira->codegen->invalid_instruction;
23001 return ir_const_type(ira, &instruction->base, type);22962 return ir_const_type(ira, &instruction->base, type);
23002}22963}
...@@ -23042,7 +23003,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc...@@ -23042,7 +23003,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc
23042 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));23003 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
23043 }23004 }
23044 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);23005 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);
23046 return result;23007 return result;
23047}23008}
2304823009
...@@ -23684,7 +23645,13 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -23684,7 +23645,13 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
23684 return result_loc;23645 return result_loc;
23685 }23646 }
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) {
23688 known_len = casted_value->value->data.rh_slice.len;23655 known_len = casted_value->value->data.rh_slice.len;
23689 have_known_len = true;23656 have_known_len = true;
23690 }23657 }
...@@ -23742,7 +23709,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -23742,7 +23709,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2374223709
23743 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];23710 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
23744 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];23711 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);
23746 ptr_val->type = dest_ptr_type;23713 ptr_val->type = dest_ptr_type;
2374723714
23748 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];23715 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...@@ -24035,7 +24002,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24035 ZigValue *src_elem_val = (v >= 0) ?24002 ZigValue *src_elem_val = (v >= 0) ?
24036 &a->value->data.x_array.data.s_none.elements[v] :24003 &a->value->data.x_array.data.s_none.elements[v] :
24037 &b->value->data.x_array.data.s_none.elements[~v];24004 &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
24040 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);24007 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
24041 }24008 }
...@@ -24130,7 +24097,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction...@@ -24130,7 +24097,7 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
24130 IrInstruction *result = ir_const(ira, &instruction->base, return_type);24097 IrInstruction *result = ir_const(ira, &instruction->base, return_type);
24131 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);24098 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
24132 for (uint32_t i = 0; i < len_int; i += 1) {24099 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);
24134 }24101 }
24135 return result;24102 return result;
24136 }24103 }
...@@ -24271,7 +24238,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -24271,7 +24238,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
24271 }24238 }
2427224239
24273 for (size_t i = start; i < end; i += 1) {24240 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);
24275 }24242 }
2427624243
24277 return ir_const_void(ira, &instruction->base);24244 return ir_const_void(ira, &instruction->base);
...@@ -24450,7 +24417,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -24450,7 +24417,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
24450 // TODO check for noalias violations - this should be generalized to work for any function24417 // TODO check for noalias violations - this should be generalized to work for any function
2445124418
24452 for (size_t i = 0; i < count; i += 1) {24419 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]);
24454 }24421 }
2445524422
24456 return ir_const_void(ira, &instruction->base);24423 return ir_const_void(ira, &instruction->base);
...@@ -25892,7 +25859,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -25892,7 +25859,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
25892 }25859 }
2589325860
25894 IrInstruction *result = ir_const(ira, target, result_type);25861 IrInstruction *result = ir_const(ira, target, result_type);
25895 copy_const_val(result->value, val, true);25862 copy_const_val(result->value, val);
25896 result->value->type = result_type;25863 result->value->type = result_type;
25897 return result;25864 return result;
25898 }25865 }
...@@ -25974,7 +25941,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -25974,7 +25941,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
25974 } else {25941 } else {
25975 result = ir_const(ira, source_instr, dest_type);25942 result = ir_const(ira, source_instr, dest_type);
25976 }25943 }
25977 copy_const_val(result->value, val, true);25944 copy_const_val(result->value, val);
25978 result->value->type = dest_type;25945 result->value->type = dest_type;
2597925946
25980 // Keep the bigger alignment, it can only help-25947 // Keep the bigger alignment, it can only help-
...@@ -27474,10 +27441,6 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns...@@ -27474,10 +27441,6 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns
27474 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))27441 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
27475 return result_loc;27442 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
27481 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);27444 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
27482 if (type_is_invalid(dest_type))27445 if (type_is_invalid(dest_type))
27483 return ira->codegen->invalid_instruction;27446 return ira->codegen->invalid_instruction;
...@@ -28060,7 +28023,24 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -28060,7 +28023,24 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
28060 }28023 }
2806128024
28062 if (ira->codegen->verbose_ir) {28025 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;
28064 }28044 }
28065 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);28045 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
28066 if (new_instruction != nullptr) {28046 if (new_instruction != nullptr) {
...@@ -28068,6 +28048,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -28068,6 +28048,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
28068 old_instruction->child = new_instruction;28048 old_instruction->child = new_instruction;
2806928049
28070 if (type_is_invalid(new_instruction->value->type)) {28050 if (type_is_invalid(new_instruction->value->type)) {
28051 if (ira->codegen->verbose_ir) {
28052 fprintf(stderr, "-> (invalid)");
28053 }
28054
28071 if (new_exec->first_err_trace_msg != nullptr) {28055 if (new_exec->first_err_trace_msg != nullptr) {
28072 ira->codegen->trace_err = new_exec->first_err_trace_msg;28056 ira->codegen->trace_err = new_exec->first_err_trace_msg;
28073 } else {28057 } else {
...@@ -28081,11 +28065,22 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -28081,11 +28065,22 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
28081 old_instruction->source_node, buf_create_from_str("referenced here"));28065 old_instruction->source_node, buf_create_from_str("referenced here"));
28082 }28066 }
28083 return ira->codegen->builtin_types.entry_invalid;28067 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 }
28084 }28075 }
2808528076
28086 // unreachable instructions do their own control flow.28077 // unreachable instructions do their own control flow.
28087 if (new_instruction->value->type->id == ZigTypeIdUnreachable)28078 if (new_instruction->value->type->id == ZigTypeIdUnreachable)
28088 continue;28079 continue;
28080 } else {
28081 if (ira->codegen->verbose_ir) {
28082 fprintf(stderr, "-> (null");
28083 }
28089 }28084 }
2809028085
28091 ira->instruction_index += 1;28086 ira->instruction_index += 1;
...@@ -28748,3 +28743,43 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {...@@ -28748,3 +28743,43 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
28748 }28743 }
28749 return ErrorNone;28744 return ErrorNone;
28750}28745}
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...@@ -35,4 +35,8 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
35 AstNode *source_node);35 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op, bool llvm_name);36const 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
38#endif42#endif
src/ir_print.cpp+32-12
...@@ -2530,6 +2530,37 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool...@@ -2530,6 +2530,37 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
2530 fprintf(irp->f, "\n");2530 fprintf(irp->f, "\n");
2531}2531}
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
2533void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {2564void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {
2534 IrPrint ir_print = {};2565 IrPrint ir_print = {};
2535 IrPrint *irp = &ir_print;2566 IrPrint *irp = &ir_print;
...@@ -2543,18 +2574,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si...@@ -2543,18 +2574,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
2543 irp->pending = {};2574 irp->pending = {};
25442575
2545 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {2576 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);2577 irp_print_basic_block(irp, 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 }
2558 }2578 }
25592579
2560 irp->pending.deinit();2580 irp->pending.deinit();
src/ir_print.hpp+1
...@@ -15,6 +15,7 @@...@@ -15,6 +15,7 @@
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);17void 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
19const char* ir_instruction_type_str(IrInstructionId id);20const char* ir_instruction_type_str(IrInstructionId id);
2021
src/util.hpp+6-2
...@@ -26,20 +26,24 @@...@@ -26,20 +26,24 @@
26#define ATTRIBUTE_NORETURN __declspec(noreturn)26#define ATTRIBUTE_NORETURN __declspec(noreturn)
27#define ATTRIBUTE_MUST_USE27#define ATTRIBUTE_MUST_USE
2828
29#define BREAKPOINT __debugbreak()
30
29#else31#else
3032
33#include <signal.h>
34
31#define ATTRIBUTE_COLD __attribute__((cold))35#define ATTRIBUTE_COLD __attribute__((cold))
32#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))36#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
33#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))37#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
34#define ATTRIBUTE_NORETURN __attribute__((noreturn))38#define ATTRIBUTE_NORETURN __attribute__((noreturn))
35#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))39#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
3640
41#define BREAKPOINT raise(SIGTRAP)
42
37#endif43#endif
3844
39#include "softfloat.hpp"45#include "softfloat.hpp"
4046
41#define BREAKPOINT __asm("int $0x03")
42
43ATTRIBUTE_COLD47ATTRIBUTE_COLD
44ATTRIBUTE_NORETURN48ATTRIBUTE_NORETURN
45ATTRIBUTE_PRINTF(1, 2)49ATTRIBUTE_PRINTF(1, 2)
test/cli.zig+13-13
...@@ -26,9 +26,9 @@ pub fn main() !void {...@@ -26,9 +26,9 @@ pub fn main() !void {
26 std.debug.warn("Expected second argument to be cache root directory path\n");26 std.debug.warn("Expected second argument to be cache root directory path\n");
27 return error.InvalidArgs;27 return error.InvalidArgs;
28 });28 });
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" });
32 const TestFn = fn ([]const u8, []const u8) anyerror!void;32 const TestFn = fn ([]const u8, []const u8) anyerror!void;
33 const test_fns = [_]TestFn{33 const test_fns = [_]TestFn{
34 testZigInitLib,34 testZigInitLib,
...@@ -85,22 +85,22 @@ fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {...@@ -85,22 +85,22 @@ fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
85}85}
8686
87fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {87fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
88 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-lib" });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" });89 const test_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "test" });
90 testing.expect(std.mem.endsWith(u8, test_result.stderr, "All 1 tests passed.\n"));90 testing.expect(std.mem.endsWith(u8, test_result.stderr, "All 1 tests passed.\n"));
91}91}
9292
93fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {93fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
94 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-exe" });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" });95 const run_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "run" });
96 testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));96 testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));
97}97}
9898
99fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {99fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
100 if (builtin.os != .linux or builtin.arch != .x86_64) return;100 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" });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" });103 const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });
104104
105 try std.io.writeFile(example_zig_path,105 try std.io.writeFile(example_zig_path,
106 \\// Type your code here, or load an example.106 \\// Type your code here, or load an example.
...@@ -123,7 +123,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {...@@ -123,7 +123,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
123 "--strip", "--release-fast",123 "--strip", "--release-fast",
124 example_zig_path, "--disable-gen-h",124 example_zig_path, "--disable-gen-h",
125 };125 };
126 _ = try exec(dir_path, args);126 _ = try exec(dir_path, &args);
127127
128 const out_asm = try std.io.readFileAlloc(a, example_s_path);128 const out_asm = try std.io.readFileAlloc(a, example_s_path);
129 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);129 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 {...@@ -132,10 +132,10 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
132}132}
133133
134fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {134fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
135 _ = try exec(dir_path, [_][]const u8{ zig_exe, "init-exe" });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" });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" });137 const source_path = try fs.path.join(a, &[_][]const u8{ "src", "main.zig" });
138 _ = try exec(dir_path, [_][]const u8{138 _ = try exec(dir_path, &[_][]const u8{
139 zig_exe, "build-exe", source_path, "--output-dir", output_path,139 zig_exe, "build-exe", source_path, "--output-dir", output_path,
140 });140 });
141}141}
test/compare_output.zig+2-2
...@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
465 \\465 \\
466 );466 );
467467
468 tc.setCommandLineArgs([_][]const u8{468 tc.setCommandLineArgs(&[_][]const u8{
469 "first arg",469 "first arg",
470 "'a' 'b' \\",470 "'a' 'b' \\",
471 "bare",471 "bare",
...@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
506 \\506 \\
507 );507 );
508508
509 tc.setCommandLineArgs([_][]const u8{509 tc.setCommandLineArgs(&[_][]const u8{
510 "first arg",510 "first arg",
511 "'a' 'b' \\",511 "'a' 'b' \\",
512 "bare",512 "bare",
test/compile_errors.zig+16-15
...@@ -20,6 +20,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -20,6 +20,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20 break :x tc;20 break :x tc;
21 });21 });
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.
23 cases.add(25 cases.add(
24 "incompatible sentinels",26 "incompatible sentinels",
25 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {27 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
...@@ -40,8 +42,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -40,8 +42,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
40 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",42 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
41 "tmp.zig:5:12: note: destination pointer requires a terminating '0' sentinel",43 "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'",45 "tmp.zig:8:35: error: expected type '[2:255]u8', found '[2:0]u8'",
44 "tmp.zig:8:35: note: destination array requires a terminating '0' sentinel, but source array has a terminating '255' sentinel",46 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
45 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",47 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
46 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",48 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
47 );49 );
...@@ -179,7 +181,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -179,7 +181,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
179 \\ var geo_data = getGeo3DTex2D();181 \\ var geo_data = getGeo3DTex2D();
180 \\}182 \\}
181 ,183 ,
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'",
183 );185 );
184186
185 cases.add(187 cases.add(
...@@ -776,7 +778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -776,7 +778,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
776 \\ const x = []u8{1, 2};778 \\ const x = []u8{1, 2};
777 \\}779 \\}
778 ,780 ,
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'",
780 );782 );
781783
782 cases.add(784 cases.add(
...@@ -785,7 +787,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -785,7 +787,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
785 \\ const x = []u8{};787 \\ const x = []u8{};
786 \\}788 \\}
787 ,789 ,
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'",
789 );791 );
790792
791 cases.add(793 cases.add(
...@@ -2284,8 +2286,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2284,8 +2286,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2284 \\2286 \\
2285 \\fn bar(x: *b.Foo) void {}2287 \\fn bar(x: *b.Foo) void {}
2286 ,2288 ,
2287 "tmp.zig:6:9: error: expected type '*b.Foo', found '*a.Foo'",2289 "tmp.zig:6:10: 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'",2290 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
2289 "a.zig:1:17: note: a.Foo declared here",2291 "a.zig:1:17: note: a.Foo declared here",
2290 "b.zig:1:17: note: b.Foo declared here",2292 "b.zig:1:17: note: b.Foo declared here",
2291 );2293 );
...@@ -4810,10 +4812,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4810,10 +4812,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4810 "convert fixed size array to slice with invalid size",4812 "convert fixed size array to slice with invalid size",
4811 \\export fn f() void {4813 \\export fn f() void {
4812 \\ var array: [5]u8 = undefined;4814 \\ var array: [5]u8 = undefined;
4813 \\ var foo = @bytesToSlice(u32, array)[0];4815 \\ var foo = @bytesToSlice(u32, &array)[0];
4814 \\}4816 \\}
4815 ,4817 ,
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",
4817 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",4819 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",
4818 );4820 );
48194821
...@@ -5150,7 +5152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5150,7 +5152,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5150 \\5152 \\
5151 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }5153 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
5152 ,5154 ,
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'",
5154 );5156 );
51555157
5156 cases.add(5158 cases.add(
...@@ -5847,7 +5849,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5847,7 +5849,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5847 \\ x.* += 1;5849 \\ x.* += 1;
5848 \\}5850 \\}
5849 ,5851 ,
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'",
5851 );5853 );
58525854
5853 cases.add(5855 cases.add(
...@@ -5867,9 +5869,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5867,9 +5869,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5867 \\ x[0] += 1;5869 \\ x[0] += 1;
5868 \\}5870 \\}
5869 ,5871 ,
5870 "tmp.zig:9:9: error: cast increases pointer alignment",5872 "tmp.zig:9:26: error: cast increases pointer alignment",
5871 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",5873 "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",
5873 );5875 );
58745876
5875 cases.add(5877 cases.add(
...@@ -6917,7 +6919,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6917,7 +6919,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6917 \\ var foo: u32 = @This(){};6919 \\ var foo: u32 = @This(){};
6918 \\}6920 \\}
6919 ,6921 ,
6920 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",6922 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
6921 "tmp.zig:1:1: note: (root) declared here",
6922 );6923 );
6923}6924}
test/runtime_safety.zig+2-2
...@@ -261,7 +261,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -261,7 +261,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
261 \\}261 \\}
262 \\pub fn main() void {262 \\pub fn main() void {
263 \\ const a = [_]i32{1, 2, 3, 4};263 \\ const a = [_]i32{1, 2, 3, 4};
264 \\ baz(bar(a));264 \\ baz(bar(&a));
265 \\}265 \\}
266 \\fn bar(a: []const i32) i32 {266 \\fn bar(a: []const i32) i32 {
267 \\ return a[4];267 \\ return a[4];
...@@ -471,7 +471,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -471,7 +471,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
471 \\ @import("std").os.exit(126);471 \\ @import("std").os.exit(126);
472 \\}472 \\}
473 \\pub fn main() !void {473 \\pub fn main() !void {
474 \\ const x = widenSlice([_]u8{1, 2, 3, 4, 5});474 \\ const x = widenSlice(&[_]u8{1, 2, 3, 4, 5});
475 \\ if (x.len == 0) return error.Whatever;475 \\ if (x.len == 0) return error.Whatever;
476 \\}476 \\}
477 \\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 {477 \\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 {
test/stage1/behavior/array.zig+22-22
...@@ -20,7 +20,7 @@ test "arrays" {...@@ -20,7 +20,7 @@ test "arrays" {
20 }20 }
2121
22 expect(accumulator == 15);22 expect(accumulator == 15);
23 expect(getArrayLen(array) == 5);23 expect(getArrayLen(&array) == 5);
24}24}
25fn getArrayLen(a: []const u32) usize {25fn getArrayLen(a: []const u32) usize {
26 return a.len;26 return a.len;
...@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {...@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {
182182
183test "runtime initialize array elem and then implicit cast to slice" {183test "runtime initialize array elem and then implicit cast to slice" {
184 var two: i32 = 2;184 var two: i32 = 2;
185 const x: []const i32 = [_]i32{two};185 const x: []const i32 = &[_]i32{two};
186 expect(x[0] == 2);186 expect(x[0] == 2);
187}187}
188188
189test "array literal as argument to function" {189test "array literal as argument to function" {
190 const S = struct {190 const S = struct {
191 fn entry(two: i32) void {191 fn entry(two: i32) void {
192 foo([_]i32{192 foo(&[_]i32{
193 1,193 1,
194 2,194 2,
195 3,195 3,
196 });196 });
197 foo([_]i32{197 foo(&[_]i32{
198 1,198 1,
199 two,199 two,
200 3,200 3,
201 });201 });
202 foo2(true, [_]i32{202 foo2(true, &[_]i32{
203 1,203 1,
204 2,204 2,
205 3,205 3,
206 });206 });
207 foo2(true, [_]i32{207 foo2(true, &[_]i32{
208 1,208 1,
209 two,209 two,
210 3,210 3,
...@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {...@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {
230 const S = struct {230 const S = struct {
231 fn entry(two: i32) void {231 fn entry(two: i32) void {
232 const cases = [_][]const []const i32{232 const cases = [_][]const []const i32{
233 [_][]const i32{[_]i32{1}},233 &[_][]const i32{&[_]i32{1}},
234 [_][]const i32{[_]i32{ 2, 3 }},234 &[_][]const i32{&[_]i32{ 2, 3 }},
235 [_][]const i32{235 &[_][]const i32{
236 [_]i32{4},236 &[_]i32{4},
237 [_]i32{ 5, 6, 7 },237 &[_]i32{ 5, 6, 7 },
238 },238 },
239 };239 };
240 check(cases);240 check(&cases);
241241
242 const cases2 = [_][]const i32{242 const cases2 = [_][]const i32{
243 [_]i32{1},243 &[_]i32{1},
244 &[_]i32{ two, 3 },244 &[_]i32{ two, 3 },
245 };245 };
246 expect(cases2.len == 2);246 expect(cases2.len == 2);
...@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {...@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {
251 expect(cases2[1][1] == 3);251 expect(cases2[1][1] == 3);
252252
253 const cases3 = [_][]const []const i32{253 const cases3 = [_][]const []const i32{
254 [_][]const i32{[_]i32{1}},254 &[_][]const i32{&[_]i32{1}},
255 &[_][]const i32{&[_]i32{ two, 3 }},255 &[_][]const i32{&[_]i32{ two, 3 }},
256 [_][]const i32{256 &[_][]const i32{
257 [_]i32{4},257 &[_]i32{4},
258 [_]i32{ 5, 6, 7 },258 &[_]i32{ 5, 6, 7 },
259 },259 },
260 };260 };
261 check(cases3);261 check(&cases3);
262 }262 }
263263
264 fn check(cases: []const []const []const i32) void {264 fn check(cases: []const []const []const i32) void {
...@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {...@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {
316test "anonymous list literal syntax" {316test "anonymous list literal syntax" {
317 const S = struct {317 const S = struct {
318 fn doTheTest() void {318 fn doTheTest() void {
319 var array: [4]u8 = .{1, 2, 3, 4};319 var array: [4]u8 = .{ 1, 2, 3, 4 };
320 expect(array[0] == 1);320 expect(array[0] == 1);
321 expect(array[1] == 2);321 expect(array[1] == 2);
322 expect(array[2] == 3);322 expect(array[2] == 3);
...@@ -335,8 +335,8 @@ test "anonymous literal in array" {...@@ -335,8 +335,8 @@ test "anonymous literal in array" {
335 };335 };
336 fn doTheTest() void {336 fn doTheTest() void {
337 var array: [2]Foo = .{337 var array: [2]Foo = .{
338 .{.a = 3},338 .{ .a = 3 },
339 .{.b = 3},339 .{ .b = 3 },
340 };340 };
341 expect(array[0].a == 3);341 expect(array[0].a == 3);
342 expect(array[0].b == 4);342 expect(array[0].b == 4);
...@@ -351,7 +351,7 @@ test "anonymous literal in array" {...@@ -351,7 +351,7 @@ test "anonymous literal in array" {
351test "access the null element of a null terminated array" {351test "access the null element of a null terminated array" {
352 const S = struct {352 const S = struct {
353 fn doTheTest() void {353 fn doTheTest() void {
354 var array: [4:0]u8 = .{'a', 'o', 'e', 'u'};354 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
355 comptime expect(array[4] == 0);355 comptime expect(array[4] == 0);
356 var len: usize = 4;356 var len: usize = 4;
357 expect(array[len] == 0);357 expect(array[len] == 0);
test/stage1/behavior/async_fn.zig+6-6
...@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {...@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {
143 resume frame;143 resume frame;
144 seq('h');144 seq('h');
145145
146 expect(std.mem.eql(u8, points, "abcdefgh"));146 expect(std.mem.eql(u8, &points, "abcdefgh"));
147 }147 }
148148
149 fn amain() void {149 fn amain() void {
...@@ -206,7 +206,7 @@ test "coroutine await" {...@@ -206,7 +206,7 @@ test "coroutine await" {
206 resume await_a_promise;206 resume await_a_promise;
207 await_seq('i');207 await_seq('i');
208 expect(await_final_result == 1234);208 expect(await_final_result == 1234);
209 expect(std.mem.eql(u8, await_points, "abcdefghi"));209 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
210}210}
211async fn await_amain() void {211async fn await_amain() void {
212 await_seq('b');212 await_seq('b');
...@@ -240,7 +240,7 @@ test "coroutine await early return" {...@@ -240,7 +240,7 @@ test "coroutine await early return" {
240 var p = async early_amain();240 var p = async early_amain();
241 early_seq('f');241 early_seq('f');
242 expect(early_final_result == 1234);242 expect(early_final_result == 1234);
243 expect(std.mem.eql(u8, early_points, "abcdef"));243 expect(std.mem.eql(u8, &early_points, "abcdef"));
244}244}
245async fn early_amain() void {245async fn early_amain() void {
246 early_seq('b');246 early_seq('b');
...@@ -1166,7 +1166,7 @@ test "suspend in for loop" {...@@ -1166,7 +1166,7 @@ test "suspend in for loop" {
1166 }1166 }
11671167
1168 fn atest() void {1168 fn atest() void {
1169 expect(func([_]u8{ 1, 2, 3 }) == 6);1169 expect(func(&[_]u8{ 1, 2, 3 }) == 6);
1170 }1170 }
1171 fn func(stuff: []const u8) u32 {1171 fn func(stuff: []const u8) u32 {
1172 global_frame = @frame();1172 global_frame = @frame();
...@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {...@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {
12111211
1212 fn doTheTest() void {1212 fn doTheTest() void {
1213 var foo = Foo{1213 var foo = Foo{
1214 .slice = [_]i32{ 1, 2 },1214 .slice = &[_]i32{ 1, 2 },
1215 };1215 };
1216 expect(atest(&foo) == 3);1216 expect(atest(&foo) == 3);
1217 }1217 }
...@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {...@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
12421242
1243 fn doTheTest() void {1243 fn doTheTest() void {
1244 var foo = Foo{1244 var foo = Foo{
1245 .slice = [_]i32{ 1, 2 },1245 .slice = &[_]i32{ 1, 2 },
1246 };1246 };
1247 expect(atest(&foo) == 3);1247 expect(atest(&foo) == 3);
1248 }1248 }
test/stage1/behavior/await_struct.zig+1-1
...@@ -16,7 +16,7 @@ test "coroutine await struct" {...@@ -16,7 +16,7 @@ test "coroutine await struct" {
16 resume await_a_promise;16 resume await_a_promise;
17 await_seq('i');17 await_seq('i');
18 expect(await_final_result.x == 1234);18 expect(await_final_result.x == 1234);
19 expect(std.mem.eql(u8, await_points, "abcdefghi"));19 expect(std.mem.eql(u8, &await_points, "abcdefghi"));
20}20}
21async fn await_amain() void {21async fn await_amain() void {
22 await_seq('b');22 await_seq('b');
test/stage1/behavior/bugs/1607.zig+2-2
...@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {...@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {
10}10}
1111
12test "slices pointing at the same address as global array." {12test "slices pointing at the same address as global array." {
13 checkAddress(a);13 checkAddress(&a);
14 comptime checkAddress(a);14 comptime checkAddress(&a);
15}15}
test/stage1/behavior/bugs/1914.zig+2-2
...@@ -7,7 +7,7 @@ const B = struct {...@@ -7,7 +7,7 @@ const B = struct {
7 a_pointer: *const A,7 a_pointer: *const A,
8};8};
99
10const b_list: []B = [_]B{};10const b_list: []B = &[_]B{};
11const a = A{ .b_list_pointer = &b_list };11const a = A{ .b_list_pointer = &b_list };
1212
13test "segfault bug" {13test "segfault bug" {
...@@ -24,7 +24,7 @@ pub const B2 = struct {...@@ -24,7 +24,7 @@ pub const B2 = struct {
24 pointer_array: []*A2,24 pointer_array: []*A2,
25};25};
2626
27var b_value = B2{ .pointer_array = [_]*A2{} };27var b_value = B2{ .pointer_array = &[_]*A2{} };
2828
29test "basic stuff" {29test "basic stuff" {
30 std.debug.assert(&b_value == &b_value);30 std.debug.assert(&b_value == &b_value);
test/stage1/behavior/cast.zig+49-13
...@@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {...@@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {
150}150}
151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {151fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
152 if (a) {152 if (a) {
153 return [_]u8{};153 return &[_]u8{};
154 }154 }
155155
156 return slice[0..1];156 return slice[0..1];
...@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {...@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {
175}175}
176176
177fn gimmeErrOrSlice() anyerror![]u8 {177fn gimmeErrOrSlice() anyerror![]u8 {
178 return [_]u8{};178 return &[_]u8{};
179}179}
180180
181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {181test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
...@@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {...@@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
200}200}
201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {201fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
202 if (a) {202 if (a) {
203 return [_]u8{};203 return &[_]u8{};
204 }204 }
205205
206 return slice[0..1];206 return slice[0..1];
...@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {...@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
457test "implicit cast from [*]T to ?*c_void" {457test "implicit cast from [*]T to ?*c_void" {
458 var a = [_]u8{ 3, 2, 1 };458 var a = [_]u8{ 3, 2, 1 };
459 incrementVoidPtrArray(a[0..].ptr, 3);459 incrementVoidPtrArray(a[0..].ptr, 3);
460 expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 }));460 expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
461}461}
462462
463fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {463fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
...@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {...@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {
606606
607test "peer resolution of string literals" {607test "peer resolution of string literals" {
608 const S = struct {608 const S = struct {
609 const E = extern enum { a, b, c, d};609 const E = extern enum {
610 a,
611 b,
612 c,
613 d,
614 };
610615
611 fn doTheTest(e: E) void {616 fn doTheTest(e: E) void {
612 const cmd = switch (e) {617 const cmd = switch (e) {
...@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {...@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {
627 fn doTheTest() void {632 fn doTheTest() void {
628 // [:x]T to []T633 // [:x]T to []T
629 {634 {
630 var array = [4:0]i32{1,2,3,4};635 var array = [4:0]i32{ 1, 2, 3, 4 };
631 var slice: [:0]i32 = &array;636 var slice: [:0]i32 = &array;
632 var dest: []i32 = slice;637 var dest: []i32 = slice;
633 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));638 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
634 }639 }
635640
636 // [*:x]T to [*]T641 // [*:x]T to [*]T
637 {642 {
638 var array = [4:99]i32{1,2,3,4};643 var array = [4:99]i32{ 1, 2, 3, 4 };
639 var dest: [*]i32 = &array;644 var dest: [*]i32 = &array;
640 expect(dest[0] == 1);645 expect(dest[0] == 1);
641 expect(dest[1] == 2);646 expect(dest[1] == 2);
...@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {...@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {
646651
647 // [N:x]T to [N]T652 // [N:x]T to [N]T
648 {653 {
649 var array = [4:0]i32{1,2,3,4};654 var array = [4:0]i32{ 1, 2, 3, 4 };
650 var dest: [4]i32 = array;655 var dest: [4]i32 = array;
651 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));656 expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
652 }657 }
653658
654 // *[N:x]T to *[N]T659 // *[N:x]T to *[N]T
655 {660 {
656 var array = [4:0]i32{1,2,3,4};661 var array = [4:0]i32{ 1, 2, 3, 4 };
657 var dest: *[4]i32 = &array;662 var dest: *[4]i32 = &array;
658 expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));663 expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
659 }664 }
660665
661 // [:x]T to [*:x]T666 // [:x]T to [*:x]T
662 {667 {
663 var array = [4:0]i32{1,2,3,4};668 var array = [4:0]i32{ 1, 2, 3, 4 };
664 var slice: [:0]i32 = &array;669 var slice: [:0]i32 = &array;
665 var dest: [*:0]i32 = slice;670 var dest: [*:0]i32 = slice;
666 expect(dest[0] == 1);671 expect(dest[0] == 1);
...@@ -674,3 +679,34 @@ test "type coercion related to sentinel-termination" {...@@ -674,3 +679,34 @@ test "type coercion related to sentinel-termination" {
674 S.doTheTest();679 S.doTheTest();
675 comptime S.doTheTest();680 comptime S.doTheTest();
676}681}
682
683test "cast i8 fn call peers to i32 result" {
684 const S = struct {
685 fn doTheTest() void {
686 var cond = true;
687 const value: i32 = if (cond) smallBoi() else bigBoi();
688 expect(value == 123);
689 }
690 fn smallBoi() i8 {
691 return 123;
692 }
693 fn bigBoi() i16 {
694 return 1234;
695 }
696 };
697 S.doTheTest();
698 comptime S.doTheTest();
699}
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...@@ -400,3 +400,30 @@ test "function pointer with return type that is error union with payload which i
400 };400 };
401 S.doTheTest();401 S.doTheTest();
402}402}
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" {...@@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" {
717 };717 };
718718
719 var b = [1]u8{9};719 var b = [1]u8{9};
720 var f = @bytesToSlice(F, b);720 var f = @bytesToSlice(F, &b);
721 expect(f[0].a == 9);721 expect(f[0].a == 9);
722}722}
723723
...@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {...@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {
774774
775test "array concatenation forces comptime" {775test "array concatenation forces comptime" {
776 var a = oneItem(3) ++ oneItem(4);776 var a = oneItem(3) ++ oneItem(4);
777 expect(std.mem.eql(i32, a, [_]i32{ 3, 4 }));777 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
778}778}
779779
780test "array multiplication forces comptime" {780test "array multiplication forces comptime" {
781 var a = oneItem(3) ** scalar(2);781 var a = oneItem(3) ** scalar(2);
782 expect(std.mem.eql(i32, a, [_]i32{ 3, 3 }));782 expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
783}783}
784784
785fn oneItem(x: i32) [1]i32 {785fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/for.zig+5-5
...@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {...@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
26 var target: [source.len]u8 = undefined;26 var target: [source.len]u8 = undefined;
27 mem.copy(u8, target[0..], source);27 mem.copy(u8, target[0..], source);
28 mangleString(target[0..]);28 mangleString(target[0..]);
29 expect(mem.eql(u8, target, "bcdefgh"));29 expect(mem.eql(u8, &target, "bcdefgh"));
3030
31 for (source) |*c, i|31 for (source) |*c, i|
32 expect(@typeOf(c) == *const u8);32 expect(@typeOf(c) == *const u8);
...@@ -64,7 +64,7 @@ test "basic for loop" {...@@ -64,7 +64,7 @@ test "basic for loop" {
64 buffer[buf_index] = @intCast(u8, index);64 buffer[buf_index] = @intCast(u8, index);
65 buf_index += 1;65 buf_index += 1;
66 }66 }
67 const unknown_size: []const u8 = array;67 const unknown_size: []const u8 = &array;
68 for (unknown_size) |item| {68 for (unknown_size) |item| {
69 buffer[buf_index] = item;69 buffer[buf_index] = item;
70 buf_index += 1;70 buf_index += 1;
...@@ -74,7 +74,7 @@ test "basic for loop" {...@@ -74,7 +74,7 @@ test "basic for loop" {
74 buf_index += 1;74 buf_index += 1;
75 }75 }
7676
77 expect(mem.eql(u8, buffer[0..buf_index], expected_result));77 expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
78}78}
7979
80test "break from outer for loop" {80test "break from outer for loop" {
...@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {...@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {
139 }139 }
140 }140 }
141 };141 };
142 S.doTheTest([_]u8{ 1, 2 });142 S.doTheTest(&[_]u8{ 1, 2 });
143 comptime S.doTheTest([_]u8{ 1, 2 });143 comptime S.doTheTest(&[_]u8{ 1, 2 });
144}144}
test/stage1/behavior/generics.zig+2-2
...@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {...@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
120}120}
121121
122test "generic fn with implicit cast" {122test "generic fn with implicit cast" {
123 expect(getFirstByte(u8, [_]u8{13}) == 13);123 expect(getFirstByte(u8, &[_]u8{13}) == 13);
124 expect(getFirstByte(u16, [_]u16{124 expect(getFirstByte(u16, &[_]u16{
125 0,125 0,
126 13,126 13,
127 }) == 0);127 }) == 0);
test/stage1/behavior/misc.zig+3-3
...@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}...@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}
241241
242test "cast undefined" {242test "cast undefined" {
243 const array: [100]u8 = undefined;243 const array: [100]u8 = undefined;
244 const slice = @as([]const u8, array);244 const slice = @as([]const u8, &array);
245 testCastUndefined(slice);245 testCastUndefined(slice);
246}246}
247fn testCastUndefined(x: []const u8) void {}247fn testCastUndefined(x: []const u8) void {}
...@@ -614,7 +614,7 @@ test "slicing zero length array" {...@@ -614,7 +614,7 @@ test "slicing zero length array" {
614 expect(s1.len == 0);614 expect(s1.len == 0);
615 expect(s2.len == 0);615 expect(s2.len == 0);
616 expect(mem.eql(u8, s1, ""));616 expect(mem.eql(u8, s1, ""));
617 expect(mem.eql(u32, s2, [_]u32{}));617 expect(mem.eql(u32, s2, &[_]u32{}));
618}618}
619619
620const addr1 = @ptrCast(*const u8, emptyFn);620const addr1 = @ptrCast(*const u8, emptyFn);
...@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic...@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic
710 const E = struct {710 const E = struct {
711 entries: []u32,711 entries: []u32,
712 };712 };
713 var foo = E{ .entries = [_]u32{} };713 var foo = E{ .entries = &[_]u32{} };
714 expect(foo.entries.len == 0);714 expect(foo.entries.len == 0);
715}715}
716716
test/stage1/behavior/optional.zig+11
...@@ -119,3 +119,14 @@ test "self-referential struct through a slice of optional" {...@@ -119,3 +119,14 @@ test "self-referential struct through a slice of optional" {
119 var n = S.Node.new();119 var n = S.Node.new();
120 expect(n.data == null);120 expect(n.data == null);
121}121}
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 {...@@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {
3737
38test "reinterpret struct field at comptime" {38test "reinterpret struct field at comptime" {
39 const numLittle = comptime Bytes.init(0x12345678);39 const numLittle = comptime Bytes.init(0x12345678);
40 expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));40 expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes));
41}41}
4242
43const Bytes = struct {43const Bytes = struct {
test/stage1/behavior/shuffle.zig+7-7
...@@ -9,28 +9,28 @@ test "@shuffle" {...@@ -9,28 +9,28 @@ test "@shuffle" {
9 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };9 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
10 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };10 const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
11 var res = @shuffle(i32, v, x, mask);11 var res = @shuffle(i32, v, x, mask);
12 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));12 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1313
14 // Implicit cast from array (of mask)14 // Implicit cast from array (of mask)
15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });15 res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
16 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));16 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
1717
18 // Undefined18 // Undefined
19 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };19 const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
20 res = @shuffle(i32, v, undefined, mask2);20 res = @shuffle(i32, v, undefined, mask2);
21 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 }));21 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
2222
23 // Upcasting of b23 // Upcasting of b
24 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };24 var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
25 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };25 const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
26 res = @shuffle(i32, x, v2, mask3);26 res = @shuffle(i32, x, v2, mask3);
27 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 }));27 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
2828
29 // Upcasting of a29 // Upcasting of a
30 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };30 var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };31 const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
32 res = @shuffle(i32, v3, x, mask4);32 res = @shuffle(i32, v3, x, mask4);
33 expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 }));33 expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
3434
35 // bool35 // bool
36 // Disabled because of #331736 // Disabled because of #3317
...@@ -39,7 +39,7 @@ test "@shuffle" {...@@ -39,7 +39,7 @@ test "@shuffle" {
39 var v4: @Vector(2, bool) = [2]bool{ true, false };39 var v4: @Vector(2, bool) = [2]bool{ true, false };
40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };40 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
41 var res2 = @shuffle(bool, x2, v4, mask5);41 var res2 = @shuffle(bool, x2, v4, mask5);
42 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));42 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
43 }43 }
4444
45 // TODO re-enable when LLVM codegen is fixed45 // TODO re-enable when LLVM codegen is fixed
...@@ -49,7 +49,7 @@ test "@shuffle" {...@@ -49,7 +49,7 @@ test "@shuffle" {
49 var v4: @Vector(2, bool) = [2]bool{ true, false };49 var v4: @Vector(2, bool) = [2]bool{ true, false };
50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };50 const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
51 var res2 = @shuffle(bool, x2, v4, mask5);51 var res2 = @shuffle(bool, x2, v4, mask5);
52 expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));52 expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
53 }53 }
54 }54 }
55 };55 };
test/stage1/behavior/slice.zig+3-3
...@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {...@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
2828
29test "implicitly cast array of size 0 to slice" {29test "implicitly cast array of size 0 to slice" {
30 var msg = [_]u8{};30 var msg = [_]u8{};
31 assertLenIsZero(msg);31 assertLenIsZero(&msg);
32}32}
3333
34fn assertLenIsZero(msg: []const u8) void {34fn assertLenIsZero(msg: []const u8) void {
...@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {...@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {
51}51}
5252
53test "comptime slices are disambiguated" {53test "comptime slices are disambiguated" {
54 expect(sliceSum([_]u8{ 1, 2 }) == 3);54 expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
55 expect(sliceSum([_]u8{ 3, 4 }) == 7);55 expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
56}56}
5757
58test "slice type with custom alignment" {58test "slice type with custom alignment" {
test/stage1/behavior/struct.zig+5-4
...@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {...@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
184}184}
185185
186test "pass slice of empty struct to fn" {186test "pass slice of empty struct to fn" {
187 expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1);187 expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
188}188}
189fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {189fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
190 return slice.len;190 return slice.len;
...@@ -432,7 +432,7 @@ const Expr = union(enum) {...@@ -432,7 +432,7 @@ const Expr = union(enum) {
432};432};
433433
434fn alloc(comptime T: type) []T {434fn alloc(comptime T: type) []T {
435 return [_]T{};435 return &[_]T{};
436}436}
437437
438test "call method with mutable reference to struct with no fields" {438test "call method with mutable reference to struct with no fields" {
...@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {...@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {
495 .a = true,495 .a = true,
496 .b = "abcdefghijklmnopqurstu".*,496 .b = "abcdefghijklmnopqurstu".*,
497 };497 };
498 bar(foo.b);498 const value = foo.b;
499 bar(&value);
499 }500 }
500 };501 };
501 S.doTheTest();502 S.doTheTest();
...@@ -783,7 +784,7 @@ test "struct with var field" {...@@ -783,7 +784,7 @@ test "struct with var field" {
783 x: var,784 x: var,
784 y: var,785 y: var,
785 };786 };
786 const pt = Point {787 const pt = Point{
787 .x = 1,788 .x = 1,
788 .y = 2,789 .y = 2,
789 };790 };
test/stage1/behavior/struct_contains_slice_of_itself.zig+8-8
...@@ -14,21 +14,21 @@ test "struct contains slice of itself" {...@@ -14,21 +14,21 @@ test "struct contains slice of itself" {
14 var other_nodes = [_]Node{14 var other_nodes = [_]Node{
15 Node{15 Node{
16 .payload = 31,16 .payload = 31,
17 .children = [_]Node{},17 .children = &[_]Node{},
18 },18 },
19 Node{19 Node{
20 .payload = 32,20 .payload = 32,
21 .children = [_]Node{},21 .children = &[_]Node{},
22 },22 },
23 };23 };
24 var nodes = [_]Node{24 var nodes = [_]Node{
25 Node{25 Node{
26 .payload = 1,26 .payload = 1,
27 .children = [_]Node{},27 .children = &[_]Node{},
28 },28 },
29 Node{29 Node{
30 .payload = 2,30 .payload = 2,
31 .children = [_]Node{},31 .children = &[_]Node{},
32 },32 },
33 Node{33 Node{
34 .payload = 3,34 .payload = 3,
...@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {...@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {
51 var other_nodes = [_]NodeAligned{51 var other_nodes = [_]NodeAligned{
52 NodeAligned{52 NodeAligned{
53 .payload = 31,53 .payload = 31,
54 .children = [_]NodeAligned{},54 .children = &[_]NodeAligned{},
55 },55 },
56 NodeAligned{56 NodeAligned{
57 .payload = 32,57 .payload = 32,
58 .children = [_]NodeAligned{},58 .children = &[_]NodeAligned{},
59 },59 },
60 };60 };
61 var nodes = [_]NodeAligned{61 var nodes = [_]NodeAligned{
62 NodeAligned{62 NodeAligned{
63 .payload = 1,63 .payload = 1,
64 .children = [_]NodeAligned{},64 .children = &[_]NodeAligned{},
65 },65 },
66 NodeAligned{66 NodeAligned{
67 .payload = 2,67 .payload = 2,
68 .children = [_]NodeAligned{},68 .children = &[_]NodeAligned{},
69 },69 },
70 NodeAligned{70 NodeAligned{
71 .payload = 3,71 .payload = 3,
test/stage1/behavior/type.zig+12-12
...@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {...@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {
1212
13test "Type.MetaType" {13test "Type.MetaType" {
14 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));14 testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
15 testTypes([_]type{type});15 testTypes(&[_]type{type});
16}16}
1717
18test "Type.Void" {18test "Type.Void" {
19 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));19 testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
20 testTypes([_]type{void});20 testTypes(&[_]type{void});
21}21}
2222
23test "Type.Bool" {23test "Type.Bool" {
24 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));24 testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
25 testTypes([_]type{bool});25 testTypes(&[_]type{bool});
26}26}
2727
28test "Type.NoReturn" {28test "Type.NoReturn" {
29 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));29 testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
30 testTypes([_]type{noreturn});30 testTypes(&[_]type{noreturn});
31}31}
3232
33test "Type.Int" {33test "Type.Int" {
...@@ -37,7 +37,7 @@ test "Type.Int" {...@@ -37,7 +37,7 @@ test "Type.Int" {
37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));
38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));
39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));
40 testTypes([_]type{ u8, u32, i64 });40 testTypes(&[_]type{ u8, u32, i64 });
41}41}
4242
43test "Type.Float" {43test "Type.Float" {
...@@ -45,11 +45,11 @@ test "Type.Float" {...@@ -45,11 +45,11 @@ test "Type.Float" {
45 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));45 testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
46 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));46 testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
47 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));47 testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
48 testTypes([_]type{ f16, f32, f64, f128 });48 testTypes(&[_]type{ f16, f32, f64, f128 });
49}49}
5050
51test "Type.Pointer" {51test "Type.Pointer" {
52 testTypes([_]type{52 testTypes(&[_]type{
53 // One Value Pointer Types53 // One Value Pointer Types
54 *u8, *const u8,54 *u8, *const u8,
55 *volatile u8, *const volatile u8,55 *volatile u8, *const volatile u8,
...@@ -115,18 +115,18 @@ test "Type.Array" {...@@ -115,18 +115,18 @@ test "Type.Array" {
115 .sentinel = 0,115 .sentinel = 0,
116 },116 },
117 }));117 }));
118 testTypes([_]type{ [1]u8, [30]usize, [7]bool });118 testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
119}119}
120120
121test "Type.ComptimeFloat" {121test "Type.ComptimeFloat" {
122 testTypes([_]type{comptime_float});122 testTypes(&[_]type{comptime_float});
123}123}
124test "Type.ComptimeInt" {124test "Type.ComptimeInt" {
125 testTypes([_]type{comptime_int});125 testTypes(&[_]type{comptime_int});
126}126}
127test "Type.Undefined" {127test "Type.Undefined" {
128 testTypes([_]type{@typeOf(undefined)});128 testTypes(&[_]type{@typeOf(undefined)});
129}129}
130test "Type.Null" {130test "Type.Null" {
131 testTypes([_]type{@typeOf(null)});131 testTypes(&[_]type{@typeOf(null)});
132}132}
test/stage1/behavior/union.zig+30-1
...@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {...@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {
241};241};
242242
243test "constant packed union" {243test "constant packed union" {
244 testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }});244 testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
245}245}
246246
247fn testConstPackedUnion(expected_tokens: []const PackThis) void {247fn testConstPackedUnion(expected_tokens: []const PackThis) void {
...@@ -582,3 +582,32 @@ test "update the tag value for zero-sized unions" {...@@ -582,3 +582,32 @@ test "update the tag value for zero-sized unions" {
582 x = S{ .U1 = {} };582 x = S{ .U1 = {} };
583 expect(x == .U1);583 expect(x == .U1);
584}584}
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" {...@@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" {
8 fn doTheTest() void {8 fn doTheTest() void {
9 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };9 const a: @Vector(4, bool) = [_]bool{ true, false, true, false };
10 const result_array: [4]bool = a;10 const result_array: [4]bool = a;
11 expect(mem.eql(bool, result_array, [4]bool{ true, false, true, false }));11 expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
12 }12 }
13 };13 };
14 S.doTheTest();14 S.doTheTest();
...@@ -20,11 +20,11 @@ test "vector wrap operators" {...@@ -20,11 +20,11 @@ test "vector wrap operators" {
20 fn doTheTest() void {20 fn doTheTest() void {
21 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };21 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
22 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };22 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
23 expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));23 expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
24 expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));24 expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
25 expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));25 expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
26 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };26 var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
27 expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 }));27 expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
28 }28 }
29 };29 };
30 S.doTheTest();30 S.doTheTest();
...@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {...@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
36 fn doTheTest() void {36 fn doTheTest() void {
37 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };37 var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
38 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };38 var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
39 expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));39 expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
40 expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));40 expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
41 expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));41 expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
42 expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));42 expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
43 expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));43 expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
44 expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));44 expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
45 }45 }
46 };46 };
47 S.doTheTest();47 S.doTheTest();
...@@ -53,10 +53,10 @@ test "vector int operators" {...@@ -53,10 +53,10 @@ test "vector int operators" {
53 fn doTheTest() void {53 fn doTheTest() void {
54 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };54 var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
55 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };55 var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
56 expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));56 expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
57 expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));57 expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
58 expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));58 expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
59 expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));59 expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
60 }60 }
61 };61 };
62 S.doTheTest();62 S.doTheTest();
...@@ -68,10 +68,10 @@ test "vector float operators" {...@@ -68,10 +68,10 @@ test "vector float operators" {
68 fn doTheTest() void {68 fn doTheTest() void {
69 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };69 var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
70 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };70 var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
71 expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));71 expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
72 expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));72 expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
73 expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));73 expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
74 expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));74 expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
75 }75 }
76 };76 };
77 S.doTheTest();77 S.doTheTest();
...@@ -83,9 +83,9 @@ test "vector bit operators" {...@@ -83,9 +83,9 @@ test "vector bit operators" {
83 fn doTheTest() void {83 fn doTheTest() void {
84 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };84 var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
85 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };85 var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
86 expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));86 expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
87 expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));87 expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
88 expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));88 expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
89 }89 }
90 };90 };
91 S.doTheTest();91 S.doTheTest();
...@@ -98,7 +98,7 @@ test "implicit cast vector to array" {...@@ -98,7 +98,7 @@ test "implicit cast vector to array" {
98 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };98 var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
99 var result_array: [4]i32 = a;99 var result_array: [4]i32 = a;
100 result_array = a;100 result_array = a;
101 expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 }));101 expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
102 }102 }
103 };103 };
104 S.doTheTest();104 S.doTheTest();
...@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {...@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
120 {120 {
121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };121 var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
122 var x: [4]u3 = v;122 var x: [4]u3 = v;
123 expect(mem.eql(u3, x, @as([4]u3, v)));123 expect(mem.eql(u3, &x, &@as([4]u3, v)));
124 }124 }
125 {125 {
126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };126 var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
127 var x: [4]u2 = v;127 var x: [4]u2 = v;
128 expect(mem.eql(u2, x, @as([4]u2, v)));128 expect(mem.eql(u2, &x, &@as([4]u2, v)));
129 }129 }
130 {130 {
131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };131 var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
132 var x: [4]u1 = v;132 var x: [4]u1 = v;
133 expect(mem.eql(u1, x, @as([4]u1, v)));133 expect(mem.eql(u1, &x, &@as([4]u1, v)));
134 }134 }
135 {135 {
136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };136 var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
137 var x: [4]bool = v;137 var x: [4]bool = v;
138 expect(mem.eql(bool, x, @as([4]bool, v)));138 expect(mem.eql(bool, &x, &@as([4]bool, v)));
139 }139 }
140 }140 }
141 };141 };
test/stage1/c_abi/build.zig+1-1
...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
4 const rel_opts = b.standardReleaseOptions();4 const rel_opts = b.standardReleaseOptions();
55
6 const c_obj = b.addObject("cfuncs", null);6 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"});
8 c_obj.setBuildMode(rel_opts);8 c_obj.setBuildMode(rel_opts);
9 c_obj.linkSystemLibrary("c");9 c_obj.linkSystemLibrary("c");
1010
test/stage1/c_abi/main.zig+1-1
...@@ -124,7 +124,7 @@ test "C ABI array" {...@@ -124,7 +124,7 @@ test "C ABI array" {
124}124}
125125
126export fn zig_array(x: [10]u8) void {126export fn zig_array(x: [10]u8) void {
127 expect(std.mem.eql(u8, x, "1234567890"));127 expect(std.mem.eql(u8, &x, "1234567890"));
128}128}
129129
130const BigStruct = extern struct {130const BigStruct = extern struct {
test/standalone/mix_o_files/build.zig+1-1
...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
4 const obj = b.addObject("base64", "base64.zig");4 const obj = b.addObject("base64", "base64.zig");
55
6 const exe = b.addExecutable("test", null);6 const exe = b.addExecutable("test", null);
7 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});7 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
8 exe.addObject(obj);8 exe.addObject(obj);
9 exe.linkSystemLibrary("c");9 exe.linkSystemLibrary("c");
1010
test/standalone/shared_library/build.zig+1-1
...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
4 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));4 const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
55
6 const exe = b.addExecutable("test", null);6 const exe = b.addExecutable("test", null);
7 exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});7 exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
8 exe.linkLibrary(lib);8 exe.linkLibrary(lib);
9 exe.linkSystemLibrary("c");9 exe.linkSystemLibrary("c");
1010
test/standalone/static_c_lib/build.zig+1-1
...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {...@@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
4 const mode = b.standardReleaseOptions();4 const mode = b.standardReleaseOptions();
55
6 const foo = b.addStaticLibrary("foo", null);6 const foo = b.addStaticLibrary("foo", null);
7 foo.addCSourceFile("foo.c", [_][]const u8{});7 foo.addCSourceFile("foo.c", &[_][]const u8{});
8 foo.setBuildMode(mode);8 foo.setBuildMode(mode);
9 foo.addIncludeDir(".");9 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...@@ -345,7 +345,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
345345
346 const exe = b.addExecutable("test-cli", "test/cli.zig");346 const exe = b.addExecutable("test-cli", "test/cli.zig");
347 const run_cmd = exe.run();347 const run_cmd = exe.run();
348 run_cmd.addArgs([_][]const u8{348 run_cmd.addArgs(&[_][]const u8{
349 fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,349 fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
350 b.pathFromRoot(b.cache_root),350 b.pathFromRoot(b.cache_root),
351 });351 });
...@@ -646,7 +646,7 @@ pub const CompareOutputContext = struct {...@@ -646,7 +646,7 @@ pub const CompareOutputContext = struct {
646646
647 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);647 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;
650 defer child.deinit();650 defer child.deinit();
651651
652 child.env_map = b.env_map;652 child.env_map = b.env_map;
...@@ -687,7 +687,7 @@ pub const CompareOutputContext = struct {...@@ -687,7 +687,7 @@ pub const CompareOutputContext = struct {
687 .expected_output = expected_output,687 .expected_output = expected_output,
688 .link_libc = false,688 .link_libc = false,
689 .special = special,689 .special = special,
690 .cli_args = [_][]const u8{},690 .cli_args = &[_][]const u8{},
691 };691 };
692 const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";692 const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
693 tc.addSourceFile(root_src_name, source);693 tc.addSourceFile(root_src_name, source);
...@@ -724,7 +724,7 @@ pub const CompareOutputContext = struct {...@@ -724,7 +724,7 @@ pub const CompareOutputContext = struct {
724724
725 const root_src = fs.path.join(725 const root_src = fs.path.join(
726 b.allocator,726 b.allocator,
727 [_][]const u8{ b.cache_root, case.sources.items[0].filename },727 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
728 ) catch unreachable;728 ) catch unreachable;
729729
730 switch (case.special) {730 switch (case.special) {
...@@ -740,7 +740,7 @@ pub const CompareOutputContext = struct {...@@ -740,7 +740,7 @@ pub const CompareOutputContext = struct {
740 for (case.sources.toSliceConst()) |src_file| {740 for (case.sources.toSliceConst()) |src_file| {
741 const expanded_src_path = fs.path.join(741 const expanded_src_path = fs.path.join(
742 b.allocator,742 b.allocator,
743 [_][]const u8{ b.cache_root, src_file.filename },743 &[_][]const u8{ b.cache_root, src_file.filename },
744 ) catch unreachable;744 ) catch unreachable;
745 const write_src = b.addWriteFile(expanded_src_path, src_file.source);745 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
746 exe.step.dependOn(&write_src.step);746 exe.step.dependOn(&write_src.step);
...@@ -772,7 +772,7 @@ pub const CompareOutputContext = struct {...@@ -772,7 +772,7 @@ pub const CompareOutputContext = struct {
772 for (case.sources.toSliceConst()) |src_file| {772 for (case.sources.toSliceConst()) |src_file| {
773 const expanded_src_path = fs.path.join(773 const expanded_src_path = fs.path.join(
774 b.allocator,774 b.allocator,
775 [_][]const u8{ b.cache_root, src_file.filename },775 &[_][]const u8{ b.cache_root, src_file.filename },
776 ) catch unreachable;776 ) catch unreachable;
777 const write_src = b.addWriteFile(expanded_src_path, src_file.source);777 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
778 exe.step.dependOn(&write_src.step);778 exe.step.dependOn(&write_src.step);
...@@ -803,7 +803,7 @@ pub const CompareOutputContext = struct {...@@ -803,7 +803,7 @@ pub const CompareOutputContext = struct {
803 for (case.sources.toSliceConst()) |src_file| {803 for (case.sources.toSliceConst()) |src_file| {
804 const expanded_src_path = fs.path.join(804 const expanded_src_path = fs.path.join(
805 b.allocator,805 b.allocator,
806 [_][]const u8{ b.cache_root, src_file.filename },806 &[_][]const u8{ b.cache_root, src_file.filename },
807 ) catch unreachable;807 ) catch unreachable;
808 const write_src = b.addWriteFile(expanded_src_path, src_file.source);808 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
809 exe.step.dependOn(&write_src.step);809 exe.step.dependOn(&write_src.step);
...@@ -836,7 +836,7 @@ pub const StackTracesContext = struct {...@@ -836,7 +836,7 @@ pub const StackTracesContext = struct {
836836
837 const source_pathname = fs.path.join(837 const source_pathname = fs.path.join(
838 b.allocator,838 b.allocator,
839 [_][]const u8{ b.cache_root, "source.zig" },839 &[_][]const u8{ b.cache_root, "source.zig" },
840 ) catch unreachable;840 ) catch unreachable;
841841
842 for (self.modes) |mode| {842 for (self.modes) |mode| {
...@@ -1093,7 +1093,7 @@ pub const CompileErrorContext = struct {...@@ -1093,7 +1093,7 @@ pub const CompileErrorContext = struct {
10931093
1094 const root_src = fs.path.join(1094 const root_src = fs.path.join(
1095 b.allocator,1095 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 },
1097 ) catch unreachable;1097 ) catch unreachable;
10981098
1099 var zig_args = ArrayList([]const u8).init(b.allocator);1099 var zig_args = ArrayList([]const u8).init(b.allocator);
...@@ -1290,7 +1290,7 @@ pub const CompileErrorContext = struct {...@@ -1290,7 +1290,7 @@ pub const CompileErrorContext = struct {
1290 for (case.sources.toSliceConst()) |src_file| {1290 for (case.sources.toSliceConst()) |src_file| {
1291 const expanded_src_path = fs.path.join(1291 const expanded_src_path = fs.path.join(
1292 b.allocator,1292 b.allocator,
1293 [_][]const u8{ b.cache_root, src_file.filename },1293 &[_][]const u8{ b.cache_root, src_file.filename },
1294 ) catch unreachable;1294 ) catch unreachable;
1295 const write_src = b.addWriteFile(expanded_src_path, src_file.source);1295 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
1296 compile_and_cmp_errors.step.dependOn(&write_src.step);1296 compile_and_cmp_errors.step.dependOn(&write_src.step);
...@@ -1424,7 +1424,7 @@ pub const TranslateCContext = struct {...@@ -1424,7 +1424,7 @@ pub const TranslateCContext = struct {
14241424
1425 const root_src = fs.path.join(1425 const root_src = fs.path.join(
1426 b.allocator,1426 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 },
1428 ) catch unreachable;1428 ) catch unreachable;
14291429
1430 var zig_args = ArrayList([]const u8).init(b.allocator);1430 var zig_args = ArrayList([]const u8).init(b.allocator);
...@@ -1597,7 +1597,7 @@ pub const TranslateCContext = struct {...@@ -1597,7 +1597,7 @@ pub const TranslateCContext = struct {
1597 for (case.sources.toSliceConst()) |src_file| {1597 for (case.sources.toSliceConst()) |src_file| {
1598 const expanded_src_path = fs.path.join(1598 const expanded_src_path = fs.path.join(
1599 b.allocator,1599 b.allocator,
1600 [_][]const u8{ b.cache_root, src_file.filename },1600 &[_][]const u8{ b.cache_root, src_file.filename },
1601 ) catch unreachable;1601 ) catch unreachable;
1602 const write_src = b.addWriteFile(expanded_src_path, src_file.source);1602 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
1603 translate_c_and_cmp.step.dependOn(&write_src.step);1603 translate_c_and_cmp.step.dependOn(&write_src.step);
...@@ -1720,7 +1720,7 @@ pub const GenHContext = struct {...@@ -1720,7 +1720,7 @@ pub const GenHContext = struct {
1720 const b = self.b;1720 const b = self.b;
1721 const root_src = fs.path.join(1721 const root_src = fs.path.join(
1722 b.allocator,1722 b.allocator,
1723 [_][]const u8{ b.cache_root, case.sources.items[0].filename },1723 &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
1724 ) catch unreachable;1724 ) catch unreachable;
17251725
1726 const mode = builtin.Mode.Debug;1726 const mode = builtin.Mode.Debug;
...@@ -1735,7 +1735,7 @@ pub const GenHContext = struct {...@@ -1735,7 +1735,7 @@ pub const GenHContext = struct {
1735 for (case.sources.toSliceConst()) |src_file| {1735 for (case.sources.toSliceConst()) |src_file| {
1736 const expanded_src_path = fs.path.join(1736 const expanded_src_path = fs.path.join(
1737 b.allocator,1737 b.allocator,
1738 [_][]const u8{ b.cache_root, src_file.filename },1738 &[_][]const u8{ b.cache_root, src_file.filename },
1739 ) catch unreachable;1739 ) catch unreachable;
1740 const write_src = b.addWriteFile(expanded_src_path, src_file.source);1740 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
1741 obj.step.dependOn(&write_src.step);1741 obj.step.dependOn(&write_src.step);