Commit bf3ac66150
Changed files (67)
lib
std
crypto
event
http
meta
os
src-self-hosted
test
lib/std/crypto/aes.zig
@@ -136,7 +136,7 @@ fn AES(comptime keysize: usize) type {
pub fn init(key: [keysize / 8]u8) Self {
var ctx: Self = undefined;
- expandKey(key, ctx.enc[0..], ctx.dec[0..]);
+ expandKey(&key, ctx.enc[0..], ctx.dec[0..]);
return ctx;
}
@@ -157,7 +157,7 @@ fn AES(comptime keysize: usize) type {
var ctr_i = std.mem.readIntSliceBig(u128, ctrbuf[0..]);
std.mem.writeIntSliceBig(u128, ctrbuf[0..], ctr_i +% 1);
- n += xorBytes(dst[n..], src[n..], keystream);
+ n += xorBytes(dst[n..], src[n..], &keystream);
}
}
};
lib/std/crypto/blake2.zig
@@ -256,7 +256,7 @@ test "blake2s256 aligned final" {
var out: [Blake2s256.digest_length]u8 = undefined;
var h = Blake2s256.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
@@ -490,6 +490,6 @@ test "blake2b512 aligned final" {
var out: [Blake2b512.digest_length]u8 = undefined;
var h = Blake2b512.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
lib/std/crypto/chacha20.zig
@@ -218,12 +218,12 @@ test "crypto.chacha20 test vector sunscreen" {
};
chaCha20IETF(result[0..], input[0..], 1, key, nonce);
- testing.expectEqualSlices(u8, expected_result, result);
+ testing.expectEqualSlices(u8, &expected_result, &result);
// Chacha20 is self-reversing.
var plaintext: [114]u8 = undefined;
chaCha20IETF(plaintext[0..], result[0..], 1, key, nonce);
- testing.expect(mem.compare(u8, input, plaintext) == mem.Compare.Equal);
+ testing.expect(mem.compare(u8, input, &plaintext) == mem.Compare.Equal);
}
// https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04#section-7
@@ -258,7 +258,7 @@ test "crypto.chacha20 test vector 1" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, expected_result, result);
+ testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 2" {
@@ -292,7 +292,7 @@ test "crypto.chacha20 test vector 2" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, expected_result, result);
+ testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 3" {
@@ -326,7 +326,7 @@ test "crypto.chacha20 test vector 3" {
const nonce = [_]u8{ 0, 0, 0, 0, 0, 0, 0, 1 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, expected_result, result);
+ testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 4" {
@@ -360,7 +360,7 @@ test "crypto.chacha20 test vector 4" {
const nonce = [_]u8{ 1, 0, 0, 0, 0, 0, 0, 0 };
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, expected_result, result);
+ testing.expectEqualSlices(u8, &expected_result, &result);
}
test "crypto.chacha20 test vector 5" {
@@ -432,5 +432,5 @@ test "crypto.chacha20 test vector 5" {
};
chaCha20With64BitNonce(result[0..], input[0..], 0, key, nonce);
- testing.expectEqualSlices(u8, expected_result, result);
+ testing.expectEqualSlices(u8, &expected_result, &result);
}
lib/std/crypto/gimli.zig
@@ -83,7 +83,7 @@ test "permute" {
while (i < 12) : (i += 1) {
input[i] = i * i * i + i *% 0x9e3779b9;
}
- testing.expectEqualSlices(u32, input, [_]u32{
+ testing.expectEqualSlices(u32, &input, &[_]u32{
0x00000000, 0x9e3779ba, 0x3c6ef37a, 0xdaa66d46,
0x78dde724, 0x1715611a, 0xb54cdb2e, 0x53845566,
0xf1bbcfc8, 0x8ff34a5a, 0x2e2ac522, 0xcc624026,
@@ -92,7 +92,7 @@ test "permute" {
},
};
state.permute();
- testing.expectEqualSlices(u32, state.data, [_]u32{
+ testing.expectEqualSlices(u32, &state.data, &[_]u32{
0xba11c85a, 0x91bad119, 0x380ce880, 0xd24c2c68,
0x3eceffea, 0x277a921c, 0x4f73a0bd, 0xda5a9cd8,
0x84b673f0, 0x34e52ff7, 0x9e2bef49, 0xf41bb8d6,
@@ -163,6 +163,6 @@ test "hash" {
var msg: [58 / 2]u8 = undefined;
try std.fmt.hexToBytes(&msg, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C");
var md: [32]u8 = undefined;
- hash(&md, msg);
- htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", md);
+ hash(&md, &msg);
+ htest.assertEqual("1C9A03DC6A5DDC5444CFC6F4B154CFF5CF081633B2CEA4D7D0AE7CCFED5AAA44", &md);
}
lib/std/crypto/md5.zig
@@ -276,6 +276,6 @@ test "md5 aligned final" {
var out: [Md5.digest_length]u8 = undefined;
var h = Md5.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
lib/std/crypto/poly1305.zig
@@ -230,5 +230,5 @@ test "poly1305 rfc7439 vector1" {
var mac: [16]u8 = undefined;
Poly1305.create(mac[0..], msg, key);
- std.testing.expectEqualSlices(u8, expected_mac, mac);
+ std.testing.expectEqualSlices(u8, expected_mac, &mac);
}
lib/std/crypto/sha1.zig
@@ -297,6 +297,6 @@ test "sha1 aligned final" {
var out: [Sha1.digest_length]u8 = undefined;
var h = Sha1.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
lib/std/crypto/sha2.zig
@@ -343,7 +343,7 @@ test "sha256 aligned final" {
var out: [Sha256.digest_length]u8 = undefined;
var h = Sha256.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
@@ -723,6 +723,6 @@ test "sha512 aligned final" {
var out: [Sha512.digest_length]u8 = undefined;
var h = Sha512.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
lib/std/crypto/sha3.zig
@@ -229,7 +229,7 @@ test "sha3-256 aligned final" {
var out: [Sha3_256.digest_length]u8 = undefined;
var h = Sha3_256.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
@@ -300,6 +300,6 @@ test "sha3-512 aligned final" {
var out: [Sha3_512.digest_length]u8 = undefined;
var h = Sha3_512.init();
- h.update(block);
+ h.update(&block);
h.final(out[0..]);
}
lib/std/crypto/test.zig
@@ -8,7 +8,7 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
var h: [expected.len / 2]u8 = undefined;
Hasher.hash(input, h[0..]);
- assertEqual(expected, h);
+ assertEqual(expected, &h);
}
// Assert `expected` == `input` where `input` is a bytestring.
@@ -18,5 +18,5 @@ pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
}
- testing.expectEqualSlices(u8, expected_bytes, input);
+ testing.expectEqualSlices(u8, &expected_bytes, input);
}
lib/std/crypto/x25519.zig
@@ -63,7 +63,7 @@ pub const X25519 = struct {
var pos: isize = 254;
while (pos >= 0) : (pos -= 1) {
// constant time conditional swap before ladder step
- const b = scalarBit(e, @intCast(usize, pos));
+ const b = scalarBit(&e, @intCast(usize, pos));
swap ^= b; // xor trick avoids swapping at the end of the loop
Fe.cswap(x2, x3, swap);
Fe.cswap(z2, z3, swap);
@@ -117,7 +117,7 @@ pub const X25519 = struct {
pub fn createPublicKey(public_key: []u8, private_key: []const u8) bool {
var base_point = [_]u8{9} ++ [_]u8{0} ** 31;
- return create(public_key, private_key, base_point);
+ return create(public_key, private_key, &base_point);
}
};
@@ -581,8 +581,8 @@ test "x25519 public key calculation from secret key" {
var pk_calculated: [32]u8 = undefined;
try fmt.hexToBytes(sk[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
try fmt.hexToBytes(pk_expected[0..], "f1814f0e8ff1043d8a44d25babff3cedcae6c22c3edaa48f857ae70de2baae50");
- std.testing.expect(X25519.createPublicKey(pk_calculated[0..], sk));
- std.testing.expect(std.mem.eql(u8, pk_calculated, pk_expected));
+ std.testing.expect(X25519.createPublicKey(pk_calculated[0..], &sk));
+ std.testing.expect(std.mem.eql(u8, &pk_calculated, &pk_expected));
}
test "x25519 rfc7748 vector1" {
@@ -594,7 +594,7 @@ test "x25519 rfc7748 vector1" {
var output: [32]u8 = undefined;
std.testing.expect(X25519.create(output[0..], secret_key, public_key));
- std.testing.expect(std.mem.eql(u8, output, expected_output));
+ std.testing.expect(std.mem.eql(u8, &output, expected_output));
}
test "x25519 rfc7748 vector2" {
@@ -606,12 +606,12 @@ test "x25519 rfc7748 vector2" {
var output: [32]u8 = undefined;
std.testing.expect(X25519.create(output[0..], secret_key, public_key));
- std.testing.expect(std.mem.eql(u8, output, expected_output));
+ std.testing.expect(std.mem.eql(u8, &output, expected_output));
}
test "x25519 rfc7748 one iteration" {
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".*;
- 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".*;
+ 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";
var k: [32]u8 = initial_value;
var u: [32]u8 = initial_value;
@@ -619,7 +619,7 @@ test "x25519 rfc7748 one iteration" {
var i: usize = 0;
while (i < 1) : (i += 1) {
var output: [32]u8 = undefined;
- std.testing.expect(X25519.create(output[0..], k, u));
+ std.testing.expect(X25519.create(output[0..], &k, &u));
std.mem.copy(u8, u[0..], k[0..]);
std.mem.copy(u8, k[0..], output[0..]);
@@ -634,16 +634,16 @@ test "x25519 rfc7748 1,000 iterations" {
return error.SkipZigTest;
}
- 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".*;
- 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".*;
+ 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";
+ 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";
- var k: [32]u8 = initial_value;
- var u: [32]u8 = initial_value;
+ var k: [32]u8 = initial_value.*;
+ var u: [32]u8 = initial_value.*;
var i: usize = 0;
while (i < 1000) : (i += 1) {
var output: [32]u8 = undefined;
- std.testing.expect(X25519.create(output[0..], k, u));
+ std.testing.expect(X25519.create(output[0..], &k, &u));
std.mem.copy(u8, u[0..], k[0..]);
std.mem.copy(u8, k[0..], output[0..]);
@@ -657,16 +657,16 @@ test "x25519 rfc7748 1,000,000 iterations" {
return error.SkipZigTest;
}
- 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".*;
- 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".*;
+ 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";
+ 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";
- var k: [32]u8 = initial_value;
- var u: [32]u8 = initial_value;
+ var k: [32]u8 = initial_value.*;
+ var u: [32]u8 = initial_value.*;
var i: usize = 0;
while (i < 1000000) : (i += 1) {
var output: [32]u8 = undefined;
- std.testing.expect(X25519.create(output[0..], k, u));
+ std.testing.expect(X25519.create(output[0..], &k, &u));
std.mem.copy(u8, u[0..], k[0..]);
std.mem.copy(u8, k[0..], output[0..]);
lib/std/event/loop.zig
@@ -237,7 +237,7 @@ pub const Loop = struct {
var extra_thread_index: usize = 0;
errdefer {
// writing 8 bytes to an eventfd cannot fail
- os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
+ os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
while (extra_thread_index != 0) {
extra_thread_index -= 1;
self.extra_threads[extra_thread_index].wait();
@@ -684,7 +684,7 @@ pub const Loop = struct {
.linux => {
self.posixFsRequest(&self.os_data.fs_end_request);
// writing 8 bytes to an eventfd cannot fail
- noasync os.write(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
+ noasync os.write(self.os_data.final_eventfd, &wakeup_bytes) catch unreachable;
return;
},
.macosx, .freebsd, .netbsd, .dragonfly => {
lib/std/fs/get_app_data_dir.zig
@@ -31,7 +31,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
error.OutOfMemory => return error.OutOfMemory,
};
defer allocator.free(global_dir);
- return fs.path.join(allocator, [_][]const u8{ global_dir, appname });
+ return fs.path.join(allocator, &[_][]const u8{ global_dir, appname });
},
os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
else => return error.AppDataDirUnavailable,
@@ -42,14 +42,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;
};
- return fs.path.join(allocator, [_][]const u8{ home_dir, "Library", "Application Support", appname });
+ return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname });
},
.linux, .freebsd, .netbsd, .dragonfly => {
const home_dir = os.getenv("HOME") orelse {
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;
};
- return fs.path.join(allocator, [_][]const u8{ home_dir, ".local", "share", appname });
+ return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
},
else => @compileError("Unsupported OS"),
}
lib/std/fs/path.zig
@@ -15,7 +15,9 @@ pub const sep_windows = '\\';
pub const sep_posix = '/';
pub const sep = if (builtin.os == .windows) sep_windows else sep_posix;
-pub const sep_str = [1]u8{sep};
+pub const sep_str_windows = "\\";
+pub const sep_str_posix = "/";
+pub const sep_str = if (builtin.os == .windows) sep_str_windows else sep_str_posix;
pub const delimiter_windows = ';';
pub const delimiter_posix = ':';
@@ -101,31 +103,31 @@ fn testJoinPosix(paths: []const []const u8, expected: []const u8) void {
}
test "join" {
- testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
- testJoinWindows([_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
- testJoinWindows([_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
+ testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
+ testJoinWindows(&[_][]const u8{ "c:\\a\\b", "c" }, "c:\\a\\b\\c");
+ testJoinWindows(&[_][]const u8{ "c:\\a\\b\\", "c" }, "c:\\a\\b\\c");
- testJoinWindows([_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
- testJoinWindows([_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
+ testJoinWindows(&[_][]const u8{ "c:\\", "a", "b\\", "c" }, "c:\\a\\b\\c");
+ testJoinWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c");
testJoinWindows(
- [_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
+ &[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
);
- testJoinPosix([_][]const u8{ "/a/b", "c" }, "/a/b/c");
- testJoinPosix([_][]const u8{ "/a/b/", "c" }, "/a/b/c");
+ testJoinPosix(&[_][]const u8{ "/a/b", "c" }, "/a/b/c");
+ testJoinPosix(&[_][]const u8{ "/a/b/", "c" }, "/a/b/c");
- testJoinPosix([_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
- testJoinPosix([_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
+ testJoinPosix(&[_][]const u8{ "/", "a", "b/", "c" }, "/a/b/c");
+ testJoinPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c");
testJoinPosix(
- [_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
+ &[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
"/home/andy/dev/zig/build/lib/zig/std/io.zig",
);
- testJoinPosix([_][]const u8{ "a", "/c" }, "a/c");
- testJoinPosix([_][]const u8{ "a/", "/c" }, "a/c");
+ testJoinPosix(&[_][]const u8{ "a", "/c" }, "a/c");
+ testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
}
pub fn isAbsolute(path: []const u8) bool {
@@ -246,7 +248,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
}
const relative_path = WindowsPath{
.kind = WindowsPath.Kind.None,
- .disk_designator = [_]u8{},
+ .disk_designator = &[_]u8{},
.is_abs = false,
};
if (path.len < "//a/b".len) {
@@ -255,12 +257,12 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
inline for ("/\\") |this_sep| {
const two_sep = [_]u8{ this_sep, this_sep };
- if (mem.startsWith(u8, path, two_sep)) {
+ if (mem.startsWith(u8, path, &two_sep)) {
if (path[2] == this_sep) {
return relative_path;
}
- var it = mem.tokenize(path, [_]u8{this_sep});
+ var it = mem.tokenize(path, &[_]u8{this_sep});
_ = (it.next() orelse return relative_path);
_ = (it.next() orelse return relative_path);
return WindowsPath{
@@ -322,8 +324,8 @@ fn networkShareServersEql(ns1: []const u8, ns2: []const u8) bool {
const sep1 = ns1[0];
const sep2 = ns2[0];
- var it1 = mem.tokenize(ns1, [_]u8{sep1});
- var it2 = mem.tokenize(ns2, [_]u8{sep2});
+ var it1 = mem.tokenize(ns1, &[_]u8{sep1});
+ var it2 = mem.tokenize(ns2, &[_]u8{sep2});
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return asciiEqlIgnoreCase(it1.next().?, it2.next().?);
@@ -343,8 +345,8 @@ fn compareDiskDesignators(kind: WindowsPath.Kind, p1: []const u8, p2: []const u8
const sep1 = p1[0];
const sep2 = p2[0];
- var it1 = mem.tokenize(p1, [_]u8{sep1});
- var it2 = mem.tokenize(p2, [_]u8{sep2});
+ var it1 = mem.tokenize(p1, &[_]u8{sep1});
+ var it2 = mem.tokenize(p2, &[_]u8{sep2});
// TODO ASCII is wrong, we actually need full unicode support to compare paths.
return asciiEqlIgnoreCase(it1.next().?, it2.next().?) and asciiEqlIgnoreCase(it1.next().?, it2.next().?);
@@ -637,10 +639,10 @@ test "resolve" {
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
cwd[0] = asciiUpper(cwd[0]);
}
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{"."}), cwd));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{"."}), cwd));
} else {
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "a/b/c/", "../../.." }), cwd));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"."}), cwd));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "a/b/c/", "../../.." }), cwd));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"."}), cwd));
}
}
@@ -653,8 +655,8 @@ test "resolveWindows" {
const cwd = try process.getCwdAlloc(debug.global_allocator);
const parsed_cwd = windowsParsePath(cwd);
{
- const result = testResolveWindows([_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
- const expected = try join(debug.global_allocator, [_][]const u8{
+ const result = testResolveWindows(&[_][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
+ const expected = try join(debug.global_allocator, &[_][]const u8{
parsed_cwd.disk_designator,
"usr\\local\\lib\\zig\\std\\array_list.zig",
});
@@ -664,8 +666,8 @@ test "resolveWindows" {
testing.expect(mem.eql(u8, result, expected));
}
{
- const result = testResolveWindows([_][]const u8{ "usr/local", "lib\\zig" });
- const expected = try join(debug.global_allocator, [_][]const u8{
+ const result = testResolveWindows(&[_][]const u8{ "usr/local", "lib\\zig" });
+ const expected = try join(debug.global_allocator, &[_][]const u8{
cwd,
"usr\\local\\lib\\zig",
});
@@ -676,32 +678,32 @@ test "resolveWindows" {
}
}
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//" }), "C:\\"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
- testing.expect(mem.eql(u8, testResolveWindows([_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:\\a\\b\\c", "/hi", "ok" }), "C:\\hi\\ok"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "c:../a" }), "C:\\blah\\a"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/blah\\blah", "d:/games", "C:../a" }), "C:\\blah\\a"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "d:\\a/b\\c/d", "\\e.exe" }), "D:\\e.exe"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/ignore", "c:/some/file" }), "C:\\some\\file"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }), "D:\\ignore\\some\\dir"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "//server/share", "..", "relative\\" }), "\\\\server\\share\\relative"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//" }), "C:\\"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//dir" }), "C:\\dir"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server/share" }), "\\\\server\\share\\"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "//server//share" }), "\\\\server\\share\\"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "c:/", "///some//dir" }), "C:\\some\\dir"));
+ testing.expect(mem.eql(u8, testResolveWindows(&[_][]const u8{ "C:\\foo\\tmp.3\\", "..\\tmp.3\\cycles\\root.js" }), "C:\\foo\\tmp.3\\cycles\\root.js"));
}
test "resolvePosix" {
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c" }), "/a/b/c"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/", "..", ".." }), "/"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{"/a/b/c/"}), "/a/b/c"));
-
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
- testing.expect(mem.eql(u8, testResolvePosix([_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c" }), "/a/b/c"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b", "c", "//d", "e///" }), "/d/e"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/a/b/c", "..", "../" }), "/a"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/", "..", ".." }), "/"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{"/a/b/c/"}), "/a/b/c"));
+
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "../", "file/" }), "/var/file"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/var/lib", "/../", "file/" }), "/file"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/some/dir", ".", "/absolute/" }), "/absolute"));
+ testing.expect(mem.eql(u8, testResolvePosix(&[_][]const u8{ "/foo/tmp.3/", "../tmp.3/cycles/root.js" }), "/foo/tmp.3/cycles/root.js"));
}
fn testResolveWindows(paths: []const []const u8) []u8 {
@@ -856,12 +858,12 @@ pub fn basename(path: []const u8) []const u8 {
pub fn basenamePosix(path: []const u8) []const u8 {
if (path.len == 0)
- return [_]u8{};
+ return &[_]u8{};
var end_index: usize = path.len - 1;
while (path[end_index] == '/') {
if (end_index == 0)
- return [_]u8{};
+ return &[_]u8{};
end_index -= 1;
}
var start_index: usize = end_index;
@@ -877,19 +879,19 @@ pub fn basenamePosix(path: []const u8) []const u8 {
pub fn basenameWindows(path: []const u8) []const u8 {
if (path.len == 0)
- return [_]u8{};
+ return &[_]u8{};
var end_index: usize = path.len - 1;
while (true) {
const byte = path[end_index];
if (byte == '/' or byte == '\\') {
if (end_index == 0)
- return [_]u8{};
+ return &[_]u8{};
end_index -= 1;
continue;
}
if (byte == ':' and end_index == 1) {
- return [_]u8{};
+ return &[_]u8{};
}
break;
}
@@ -971,11 +973,11 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
}
pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
- const resolved_from = try resolveWindows(allocator, [_][]const u8{from});
+ const resolved_from = try resolveWindows(allocator, &[_][]const u8{from});
defer allocator.free(resolved_from);
var clean_up_resolved_to = true;
- const resolved_to = try resolveWindows(allocator, [_][]const u8{to});
+ const resolved_to = try resolveWindows(allocator, &[_][]const u8{to});
defer if (clean_up_resolved_to) allocator.free(resolved_to);
const parsed_from = windowsParsePath(resolved_from);
@@ -1044,10 +1046,10 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8)
}
pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 {
- const resolved_from = try resolvePosix(allocator, [_][]const u8{from});
+ const resolved_from = try resolvePosix(allocator, &[_][]const u8{from});
defer allocator.free(resolved_from);
- const resolved_to = try resolvePosix(allocator, [_][]const u8{to});
+ const resolved_to = try resolvePosix(allocator, &[_][]const u8{to});
defer allocator.free(resolved_to);
var from_it = mem.tokenize(resolved_from, "/");
lib/std/hash/cityhash.zig
@@ -367,7 +367,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
}
- return @truncate(u32, hash_fn(hashes, 0));
+ return @truncate(u32, hash_fn(&hashes, 0));
}
fn CityHash32hashIgnoreSeed(str: []const u8, seed: u32) u32 {
lib/std/hash/murmur.zig
@@ -299,7 +299,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
}
- return @truncate(u32, hash_fn(hashes, 0));
+ return @truncate(u32, hash_fn(&hashes, 0));
}
test "murmur2_32" {
lib/std/http/headers.zig
@@ -514,8 +514,8 @@ test "Headers.getIndices" {
try h.append("set-cookie", "y=2", null);
testing.expect(null == h.getIndices("not-present"));
- testing.expectEqualSlices(usize, [_]usize{0}, h.getIndices("foo").?.toSliceConst());
- testing.expectEqualSlices(usize, [_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
+ testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
+ testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
}
test "Headers.get" {
lib/std/io/out_stream.zig
@@ -56,32 +56,32 @@ pub fn OutStream(comptime WriteError: type) type {
pub fn writeIntNative(self: *Self, comptime T: type, value: T) Error!void {
var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntNative(T, &bytes, value);
- return self.writeFn(self, bytes);
+ return self.writeFn(self, &bytes);
}
/// Write a foreign-endian integer.
pub fn writeIntForeign(self: *Self, comptime T: type, value: T) Error!void {
var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntForeign(T, &bytes, value);
- return self.writeFn(self, bytes);
+ return self.writeFn(self, &bytes);
}
pub fn writeIntLittle(self: *Self, comptime T: type, value: T) Error!void {
var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntLittle(T, &bytes, value);
- return self.writeFn(self, bytes);
+ return self.writeFn(self, &bytes);
}
pub fn writeIntBig(self: *Self, comptime T: type, value: T) Error!void {
var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeIntBig(T, &bytes, value);
- return self.writeFn(self, bytes);
+ return self.writeFn(self, &bytes);
}
pub fn writeInt(self: *Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
mem.writeInt(T, &bytes, value, endian);
- return self.writeFn(self, bytes);
+ return self.writeFn(self, &bytes);
}
};
}
lib/std/io/test.zig
@@ -55,7 +55,7 @@ test "write a file, read it, then delete it" {
defer allocator.free(contents);
expect(mem.eql(u8, contents[0.."begin".len], "begin"));
- expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], data));
+ expect(mem.eql(u8, contents["begin".len .. contents.len - "end".len], &data));
expect(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
}
try fs.deleteFile(tmp_file_name);
@@ -77,7 +77,7 @@ test "BufferOutStream" {
test "SliceInStream" {
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7 };
- var ss = io.SliceInStream.init(bytes);
+ var ss = io.SliceInStream.init(&bytes);
var dest: [4]u8 = undefined;
@@ -95,7 +95,7 @@ test "SliceInStream" {
test "PeekStream" {
const bytes = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8 };
- var ss = io.SliceInStream.init(bytes);
+ var ss = io.SliceInStream.init(&bytes);
var ps = io.PeekStream(2, io.SliceInStream.Error).init(&ss.stream);
var dest: [4]u8 = undefined;
@@ -614,7 +614,7 @@ test "File seek ops" {
fs.deleteFile(tmp_file_name) catch {};
}
- try file.write([_]u8{0x55} ** 8192);
+ try file.write(&([_]u8{0x55} ** 8192));
// Seek to the end
try file.seekFromEnd(0);
lib/std/meta/trait.zig
@@ -46,7 +46,7 @@ test "std.meta.trait.multiTrait" {
}
};
- const isVector = multiTrait([_]TraitFn{
+ const isVector = multiTrait(&[_]TraitFn{
hasFn("add"),
hasField("x"),
hasField("y"),
lib/std/os/test.zig
@@ -137,7 +137,7 @@ test "getrandom" {
try os.getrandom(&buf_b);
// If this test fails the chance is significantly higher that there is a bug than
// that two sets of 50 bytes were equal.
- expect(!mem.eql(u8, buf_a, buf_b));
+ expect(!mem.eql(u8, &buf_a, &buf_b));
}
test "getcwd" {
lib/std/zig/tokenizer.zig
@@ -1313,14 +1313,14 @@ pub const Tokenizer = struct {
};
test "tokenizer" {
- testTokenize("test", [_]Token.Id{Token.Id.Keyword_test});
+ testTokenize("test", &[_]Token.Id{Token.Id.Keyword_test});
}
test "tokenizer - unknown length pointer and then c pointer" {
testTokenize(
\\[*]u8
\\[*c]u8
- , [_]Token.Id{
+ , &[_]Token.Id{
Token.Id.LBracket,
Token.Id.Asterisk,
Token.Id.RBracket,
@@ -1336,70 +1336,70 @@ test "tokenizer - unknown length pointer and then c pointer" {
test "tokenizer - char literal with hex escape" {
testTokenize(
\\'\x1b'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
testTokenize(
\\'\x1'
- , [_]Token.Id{ .Invalid, .Invalid });
+ , &[_]Token.Id{ .Invalid, .Invalid });
}
test "tokenizer - char literal with unicode escapes" {
// Valid unicode escapes
testTokenize(
\\'\u{3}'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
testTokenize(
\\'\u{01}'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
testTokenize(
\\'\u{2a}'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
testTokenize(
\\'\u{3f9}'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
testTokenize(
\\'\u{6E09aBc1523}'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
testTokenize(
\\"\u{440}"
- , [_]Token.Id{.StringLiteral});
+ , &[_]Token.Id{.StringLiteral});
// Invalid unicode escapes
testTokenize(
\\'\u'
- , [_]Token.Id{.Invalid});
+ , &[_]Token.Id{.Invalid});
testTokenize(
\\'\u{{'
- , [_]Token.Id{ .Invalid, .Invalid });
+ , &[_]Token.Id{ .Invalid, .Invalid });
testTokenize(
\\'\u{}'
- , [_]Token.Id{ .Invalid, .Invalid });
+ , &[_]Token.Id{ .Invalid, .Invalid });
testTokenize(
\\'\u{s}'
- , [_]Token.Id{ .Invalid, .Invalid });
+ , &[_]Token.Id{ .Invalid, .Invalid });
testTokenize(
\\'\u{2z}'
- , [_]Token.Id{ .Invalid, .Invalid });
+ , &[_]Token.Id{ .Invalid, .Invalid });
testTokenize(
\\'\u{4a'
- , [_]Token.Id{.Invalid});
+ , &[_]Token.Id{.Invalid});
// Test old-style unicode literals
testTokenize(
\\'\u0333'
- , [_]Token.Id{ .Invalid, .Invalid });
+ , &[_]Token.Id{ .Invalid, .Invalid });
testTokenize(
\\'\U0333'
- , [_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
+ , &[_]Token.Id{ .Invalid, .IntegerLiteral, .Invalid });
}
test "tokenizer - char literal with unicode code point" {
testTokenize(
\\'๐ฉ'
- , [_]Token.Id{.CharLiteral});
+ , &[_]Token.Id{.CharLiteral});
}
test "tokenizer - float literal e exponent" {
- testTokenize("a = 4.94065645841246544177e-324;\n", [_]Token.Id{
+ testTokenize("a = 4.94065645841246544177e-324;\n", &[_]Token.Id{
Token.Id.Identifier,
Token.Id.Equal,
Token.Id.FloatLiteral,
@@ -1408,7 +1408,7 @@ test "tokenizer - float literal e exponent" {
}
test "tokenizer - float literal p exponent" {
- testTokenize("a = 0x1.a827999fcef32p+1022;\n", [_]Token.Id{
+ testTokenize("a = 0x1.a827999fcef32p+1022;\n", &[_]Token.Id{
Token.Id.Identifier,
Token.Id.Equal,
Token.Id.FloatLiteral,
@@ -1417,71 +1417,71 @@ test "tokenizer - float literal p exponent" {
}
test "tokenizer - chars" {
- testTokenize("'c'", [_]Token.Id{Token.Id.CharLiteral});
+ testTokenize("'c'", &[_]Token.Id{Token.Id.CharLiteral});
}
test "tokenizer - invalid token characters" {
- testTokenize("#", [_]Token.Id{Token.Id.Invalid});
- testTokenize("`", [_]Token.Id{Token.Id.Invalid});
- testTokenize("'c", [_]Token.Id{Token.Id.Invalid});
- testTokenize("'", [_]Token.Id{Token.Id.Invalid});
- testTokenize("''", [_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
+ testTokenize("#", &[_]Token.Id{Token.Id.Invalid});
+ testTokenize("`", &[_]Token.Id{Token.Id.Invalid});
+ testTokenize("'c", &[_]Token.Id{Token.Id.Invalid});
+ testTokenize("'", &[_]Token.Id{Token.Id.Invalid});
+ testTokenize("''", &[_]Token.Id{ Token.Id.Invalid, Token.Id.Invalid });
}
test "tokenizer - invalid literal/comment characters" {
- testTokenize("\"\x00\"", [_]Token.Id{
+ testTokenize("\"\x00\"", &[_]Token.Id{
Token.Id.StringLiteral,
Token.Id.Invalid,
});
- testTokenize("//\x00", [_]Token.Id{
+ testTokenize("//\x00", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\x1f", [_]Token.Id{
+ testTokenize("//\x1f", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\x7f", [_]Token.Id{
+ testTokenize("//\x7f", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
}
test "tokenizer - utf8" {
- testTokenize("//\xc2\x80", [_]Token.Id{Token.Id.LineComment});
- testTokenize("//\xf4\x8f\xbf\xbf", [_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xc2\x80", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xf4\x8f\xbf\xbf", &[_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - invalid utf8" {
- testTokenize("//\x80", [_]Token.Id{
+ testTokenize("//\x80", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xbf", [_]Token.Id{
+ testTokenize("//\xbf", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xf8", [_]Token.Id{
+ testTokenize("//\xf8", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xff", [_]Token.Id{
+ testTokenize("//\xff", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xc2\xc0", [_]Token.Id{
+ testTokenize("//\xc2\xc0", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xe0", [_]Token.Id{
+ testTokenize("//\xe0", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xf0", [_]Token.Id{
+ testTokenize("//\xf0", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xf0\x90\x80\xc0", [_]Token.Id{
+ testTokenize("//\xf0\x90\x80\xc0", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
@@ -1489,28 +1489,28 @@ test "tokenizer - invalid utf8" {
test "tokenizer - illegal unicode codepoints" {
// unicode newline characters.U+0085, U+2028, U+2029
- testTokenize("//\xc2\x84", [_]Token.Id{Token.Id.LineComment});
- testTokenize("//\xc2\x85", [_]Token.Id{
+ testTokenize("//\xc2\x84", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xc2\x85", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xc2\x86", [_]Token.Id{Token.Id.LineComment});
- testTokenize("//\xe2\x80\xa7", [_]Token.Id{Token.Id.LineComment});
- testTokenize("//\xe2\x80\xa8", [_]Token.Id{
+ testTokenize("//\xc2\x86", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xe2\x80\xa7", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xe2\x80\xa8", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xe2\x80\xa9", [_]Token.Id{
+ testTokenize("//\xe2\x80\xa9", &[_]Token.Id{
Token.Id.LineComment,
Token.Id.Invalid,
});
- testTokenize("//\xe2\x80\xaa", [_]Token.Id{Token.Id.LineComment});
+ testTokenize("//\xe2\x80\xaa", &[_]Token.Id{Token.Id.LineComment});
}
test "tokenizer - string identifier and builtin fns" {
testTokenize(
\\const @"if" = @import("std");
- , [_]Token.Id{
+ , &[_]Token.Id{
Token.Id.Keyword_const,
Token.Id.Identifier,
Token.Id.Equal,
@@ -1523,21 +1523,21 @@ test "tokenizer - string identifier and builtin fns" {
}
test "tokenizer - pipe and then invalid" {
- testTokenize("||=", [_]Token.Id{
+ testTokenize("||=", &[_]Token.Id{
Token.Id.PipePipe,
Token.Id.Equal,
});
}
test "tokenizer - line comment and doc comment" {
- testTokenize("//", [_]Token.Id{Token.Id.LineComment});
- testTokenize("// a / b", [_]Token.Id{Token.Id.LineComment});
- testTokenize("// /", [_]Token.Id{Token.Id.LineComment});
- testTokenize("/// a", [_]Token.Id{Token.Id.DocComment});
- testTokenize("///", [_]Token.Id{Token.Id.DocComment});
- testTokenize("////", [_]Token.Id{Token.Id.LineComment});
- testTokenize("//!", [_]Token.Id{Token.Id.ContainerDocComment});
- testTokenize("//!!", [_]Token.Id{Token.Id.ContainerDocComment});
+ testTokenize("//", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("// a / b", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("// /", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("/// a", &[_]Token.Id{Token.Id.DocComment});
+ testTokenize("///", &[_]Token.Id{Token.Id.DocComment});
+ testTokenize("////", &[_]Token.Id{Token.Id.LineComment});
+ testTokenize("//!", &[_]Token.Id{Token.Id.ContainerDocComment});
+ testTokenize("//!!", &[_]Token.Id{Token.Id.ContainerDocComment});
}
test "tokenizer - line comment followed by identifier" {
@@ -1545,7 +1545,7 @@ test "tokenizer - line comment followed by identifier" {
\\ Unexpected,
\\ // another
\\ Another,
- , [_]Token.Id{
+ , &[_]Token.Id{
Token.Id.Identifier,
Token.Id.Comma,
Token.Id.LineComment,
@@ -1555,14 +1555,14 @@ test "tokenizer - line comment followed by identifier" {
}
test "tokenizer - UTF-8 BOM is recognized and skipped" {
- testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{
+ testTokenize("\xEF\xBB\xBFa;\n", &[_]Token.Id{
Token.Id.Identifier,
Token.Id.Semicolon,
});
}
test "correctly parse pointer assignment" {
- testTokenize("b.*=3;\n", [_]Token.Id{
+ testTokenize("b.*=3;\n", &[_]Token.Id{
Token.Id.Identifier,
Token.Id.PeriodAsterisk,
Token.Id.Equal,
lib/std/array_list.zig
@@ -35,7 +35,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn init(allocator: *Allocator) Self {
return Self{
- .items = [_]T{},
+ .items = &[_]T{},
.len = 0,
.allocator = allocator,
};
@@ -306,18 +306,14 @@ test "std.ArrayList.basic" {
testing.expect(list.pop() == 10);
testing.expect(list.len == 9);
- list.appendSlice([_]i32{
- 1,
- 2,
- 3,
- }) catch unreachable;
+ list.appendSlice(&[_]i32{ 1, 2, 3 }) catch unreachable;
testing.expect(list.len == 12);
testing.expect(list.pop() == 3);
testing.expect(list.pop() == 2);
testing.expect(list.pop() == 1);
testing.expect(list.len == 9);
- list.appendSlice([_]i32{}) catch unreachable;
+ list.appendSlice(&[_]i32{}) catch unreachable;
testing.expect(list.len == 9);
// can only set on indices < self.len
@@ -464,10 +460,7 @@ test "std.ArrayList.insertSlice" {
try list.append(2);
try list.append(3);
try list.append(4);
- try list.insertSlice(1, [_]i32{
- 9,
- 8,
- });
+ try list.insertSlice(1, &[_]i32{ 9, 8 });
testing.expect(list.items[0] == 1);
testing.expect(list.items[1] == 9);
testing.expect(list.items[2] == 8);
lib/std/bloom_filter.zig
@@ -62,7 +62,7 @@ pub fn BloomFilter(
}
pub fn getCell(self: Self, cell: Index) Cell {
- return Io.get(self.data, cell, 0);
+ return Io.get(&self.data, cell, 0);
}
pub fn incrementCell(self: *Self, cell: Index) void {
@@ -70,7 +70,7 @@ pub fn BloomFilter(
// skip the 'get' operation
Io.set(&self.data, cell, 0, cellMax);
} else {
- const old = Io.get(self.data, cell, 0);
+ const old = Io.get(&self.data, cell, 0);
if (old != cellMax) {
Io.set(&self.data, cell, 0, old + 1);
}
@@ -120,7 +120,7 @@ pub fn BloomFilter(
} else if (newsize > n_items) {
var copied: usize = 0;
while (copied < r.data.len) : (copied += self.data.len) {
- std.mem.copy(u8, r.data[copied .. copied + self.data.len], self.data);
+ std.mem.copy(u8, r.data[copied .. copied + self.data.len], &self.data);
}
}
return r;
lib/std/build.zig
@@ -186,7 +186,7 @@ pub const Builder = struct {
pub fn resolveInstallPrefix(self: *Builder) void {
if (self.dest_dir) |dest_dir| {
const install_prefix = self.install_prefix orelse "/usr";
- self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
+ self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, install_prefix }) catch unreachable;
} else {
const install_prefix = self.install_prefix orelse blk: {
const p = self.cache_root;
@@ -195,8 +195,8 @@ pub const Builder = struct {
};
self.install_path = install_prefix;
}
- self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;
- self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;
+ self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
+ self.exe_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "bin" }) catch unreachable;
}
pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
@@ -803,7 +803,7 @@ pub const Builder = struct {
}
fn pathFromRoot(self: *Builder, rel_path: []const u8) []u8 {
- return fs.path.resolve(self.allocator, [_][]const u8{ self.build_root, rel_path }) catch unreachable;
+ return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable;
}
pub fn fmt(self: *Builder, comptime format: []const u8, args: ...) []u8 {
@@ -818,7 +818,7 @@ pub const Builder = struct {
if (fs.path.isAbsolute(name)) {
return name;
}
- const full_path = try fs.path.join(self.allocator, [_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
+ const full_path = try fs.path.join(self.allocator, &[_][]const u8{ search_prefix, "bin", self.fmt("{}{}", name, exe_extension) });
return fs.realpathAlloc(self.allocator, full_path) catch continue;
}
}
@@ -827,9 +827,9 @@ pub const Builder = struct {
if (fs.path.isAbsolute(name)) {
return name;
}
- var it = mem.tokenize(PATH, [_]u8{fs.path.delimiter});
+ var it = mem.tokenize(PATH, &[_]u8{fs.path.delimiter});
while (it.next()) |path| {
- const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
+ const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
return fs.realpathAlloc(self.allocator, full_path) catch continue;
}
}
@@ -839,7 +839,7 @@ pub const Builder = struct {
return name;
}
for (paths) |path| {
- const full_path = try fs.path.join(self.allocator, [_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
+ const full_path = try fs.path.join(self.allocator, &[_][]const u8{ path, self.fmt("{}{}", name, exe_extension) });
return fs.realpathAlloc(self.allocator, full_path) catch continue;
}
}
@@ -926,12 +926,12 @@ pub const Builder = struct {
};
return fs.path.resolve(
self.allocator,
- [_][]const u8{ base_dir, dest_rel_path },
+ &[_][]const u8{ base_dir, dest_rel_path },
) catch unreachable;
}
fn execPkgConfigList(self: *Builder, out_code: *u8) ![]const PkgConfigPkg {
- const stdout = try self.execAllowFail([_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
+ const stdout = try self.execAllowFail(&[_][]const u8{ "pkg-config", "--list-all" }, out_code, .Ignore);
var list = ArrayList(PkgConfigPkg).init(self.allocator);
var line_it = mem.tokenize(stdout, "\r\n");
while (line_it.next()) |line| {
@@ -970,7 +970,7 @@ pub const Builder = struct {
test "builder.findProgram compiles" {
const builder = try Builder.create(std.heap.page_allocator, "zig", "zig-cache", "zig-cache");
- _ = builder.findProgram([_][]const u8{}, [_][]const u8{}) catch null;
+ _ = builder.findProgram(&[_][]const u8{}, &[_][]const u8{}) catch null;
}
/// Deprecated. Use `builtin.Version`.
@@ -1384,7 +1384,7 @@ pub const LibExeObjStep = struct {
};
var code: u8 = undefined;
- const stdout = if (self.builder.execAllowFail([_][]const u8{
+ const stdout = if (self.builder.execAllowFail(&[_][]const u8{
"pkg-config",
pkg_name,
"--cflags",
@@ -1504,7 +1504,7 @@ pub const LibExeObjStep = struct {
pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
return fs.path.join(
self.builder.allocator,
- [_][]const u8{ self.output_dir.?, self.out_filename },
+ &[_][]const u8{ self.output_dir.?, self.out_filename },
) catch unreachable;
}
@@ -1514,7 +1514,7 @@ pub const LibExeObjStep = struct {
assert(self.kind == Kind.Lib);
return fs.path.join(
self.builder.allocator,
- [_][]const u8{ self.output_dir.?, self.out_lib_filename },
+ &[_][]const u8{ self.output_dir.?, self.out_lib_filename },
) catch unreachable;
}
@@ -1525,7 +1525,7 @@ pub const LibExeObjStep = struct {
assert(!self.disable_gen_h);
return fs.path.join(
self.builder.allocator,
- [_][]const u8{ self.output_dir.?, self.out_h_filename },
+ &[_][]const u8{ self.output_dir.?, self.out_h_filename },
) catch unreachable;
}
@@ -1535,7 +1535,7 @@ pub const LibExeObjStep = struct {
assert(self.target.isWindows() or self.target.isUefi());
return fs.path.join(
self.builder.allocator,
- [_][]const u8{ self.output_dir.?, self.out_pdb_filename },
+ &[_][]const u8{ self.output_dir.?, self.out_pdb_filename },
) catch unreachable;
}
@@ -1605,14 +1605,14 @@ pub const LibExeObjStep = struct {
const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage);
defer self.builder.allocator.free(triplet);
- const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" });
+ const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
errdefer allocator.free(include_path);
try self.include_dirs.append(IncludeDir{ .RawPath = include_path });
- const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" });
+ const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" });
try self.lib_paths.append(lib_path);
- self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" });
+ self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" });
},
}
}
@@ -1725,7 +1725,7 @@ pub const LibExeObjStep = struct {
if (self.build_options_contents.len() > 0) {
const build_options_file = try fs.path.join(
builder.allocator,
- [_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
+ &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", self.name) },
);
try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
try zig_args.append("--pkg-begin");
@@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {
try zig_args.append("--test-cmd");
try zig_args.append(bin_name);
if (glibc_dir_arg) |dir| {
- const full_dir = try fs.path.join(builder.allocator, [_][]const u8{
+ const full_dir = try fs.path.join(builder.allocator, &[_][]const u8{
dir,
try self.target.linuxTriple(builder.allocator),
});
@@ -1994,7 +1994,7 @@ pub const LibExeObjStep = struct {
const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
if (self.output_dir) |output_dir| {
- const full_dest = try fs.path.join(builder.allocator, [_][]const u8{
+ const full_dest = try fs.path.join(builder.allocator, &[_][]const u8{
output_dir,
fs.path.basename(output_path),
});
@@ -2068,7 +2068,7 @@ pub const RunStep = struct {
env_map.set(PATH, search_path) catch unreachable;
return;
};
- const new_path = self.builder.fmt("{}" ++ [1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path);
+ const new_path = self.builder.fmt("{}" ++ &[1]u8{fs.path.delimiter} ++ "{}", prev_path, search_path);
env_map.set(PATH, new_path) catch unreachable;
}
@@ -2162,6 +2162,9 @@ const InstallArtifactStep = struct {
if (self.artifact.isDynamicLibrary()) {
builder.pushInstalledFile(.Lib, artifact.major_only_filename);
builder.pushInstalledFile(.Lib, artifact.name_only_filename);
+ if (self.artifact.target.isWindows()) {
+ builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
+ }
}
if (self.pdb_dir) |pdb_dir| {
builder.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
@@ -2254,7 +2257,7 @@ pub const InstallDirStep = struct {
};
const rel_path = entry.path[full_src_dir.len + 1 ..];
- const dest_path = try fs.path.join(self.builder.allocator, [_][]const u8{ dest_prefix, rel_path });
+ const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ dest_prefix, rel_path });
switch (entry.kind) {
.Directory => try fs.makePath(self.builder.allocator, dest_path),
.File => try self.builder.updateFile(entry.path, dest_path),
@@ -2377,7 +2380,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
// sym link for libfoo.so.1 to libfoo.so.1.2.3
const major_only_path = fs.path.join(
allocator,
- [_][]const u8{ out_dir, filename_major_only },
+ &[_][]const u8{ out_dir, filename_major_only },
) catch unreachable;
fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
@@ -2386,7 +2389,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
// sym link for libfoo.so to libfoo.so.1
const name_only_path = fs.path.join(
allocator,
- [_][]const u8{ out_dir, filename_name_only },
+ &[_][]const u8{ out_dir, filename_name_only },
) catch unreachable;
fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
@@ -2399,7 +2402,7 @@ fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 {
const appdata_path = try fs.getAppDataDir(allocator, "vcpkg");
defer allocator.free(appdata_path);
- const path_file = try fs.path.join(allocator, [_][]const u8{ appdata_path, "vcpkg.path.txt" });
+ const path_file = try fs.path.join(allocator, &[_][]const u8{ appdata_path, "vcpkg.path.txt" });
defer allocator.free(path_file);
const file = fs.File.openRead(path_file) catch return null;
lib/std/debug.zig
@@ -1916,7 +1916,7 @@ const LineNumberProgram = struct {
return error.InvalidDebugInfo;
} else
self.include_dirs[file_entry.dir_index];
- const file_name = try fs.path.join(self.file_entries.allocator, [_][]const u8{ dir_name, file_entry.file_name });
+ const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name });
errdefer self.file_entries.allocator.free(file_name);
return LineInfo{
.line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,
lib/std/elf.zig
@@ -381,7 +381,7 @@ pub const Elf = struct {
var magic: [4]u8 = undefined;
try in.readNoEof(magic[0..]);
- if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat;
+ if (!mem.eql(u8, &magic, "\x7fELF")) return error.InvalidFormat;
elf.is_64 = switch (try in.readByte()) {
1 => false,
lib/std/fifo.zig
@@ -70,7 +70,7 @@ pub fn LinearFifo(
pub fn init(allocator: *Allocator) Self {
return .{
.allocator = allocator,
- .buf = [_]T{},
+ .buf = &[_]T{},
.head = 0,
.count = 0,
};
@@ -143,7 +143,7 @@ pub fn LinearFifo(
/// Returns a writable slice from the 'read' end of the fifo
fn readableSliceMut(self: SliceSelfArg, offset: usize) []T {
- if (offset > self.count) return [_]T{};
+ if (offset > self.count) return &[_]T{};
var start = self.head + offset;
if (start >= self.buf.len) {
@@ -223,7 +223,7 @@ pub fn LinearFifo(
/// Returns the first section of writable buffer
/// Note that this may be of length 0
pub fn writableSlice(self: SliceSelfArg, offset: usize) []T {
- if (offset > self.buf.len) return [_]T{};
+ if (offset > self.buf.len) return &[_]T{};
const tail = self.head + offset + self.count;
if (tail < self.buf.len) {
@@ -357,7 +357,7 @@ test "LinearFifo(u8, .Dynamic)" {
{
var i: usize = 0;
while (i < 5) : (i += 1) {
- try fifo.write([_]u8{try fifo.peekItem(i)});
+ try fifo.write(&[_]u8{try fifo.peekItem(i)});
}
testing.expectEqual(@as(usize, 10), fifo.readableLength());
testing.expectEqualSlices(u8, "HELLOHELLO", fifo.readableSlice(0));
@@ -426,7 +426,7 @@ test "LinearFifo" {
};
defer fifo.deinit();
- try fifo.write([_]T{ 0, 1, 1, 0, 1 });
+ try fifo.write(&[_]T{ 0, 1, 1, 0, 1 });
testing.expectEqual(@as(usize, 5), fifo.readableLength());
{
lib/std/fmt.zig
@@ -451,13 +451,18 @@ pub fn formatType(
},
},
.Array => |info| {
- if (info.child == u8) {
- return formatText(value, fmt, options, context, Errors, output);
- }
- if (value.len == 0) {
- return format(context, Errors, output, "[0]{}", @typeName(T.Child));
- }
- return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(&value));
+ const Slice = @Type(builtin.TypeInfo{
+ .Pointer = .{
+ .size = .Slice,
+ .is_const = true,
+ .is_volatile = false,
+ .is_allowzero = false,
+ .alignment = @alignOf(info.child),
+ .child = info.child,
+ .sentinel = null,
+ },
+ });
+ return formatType(@as(Slice, &value), fmt, options, context, Errors, output, max_depth);
},
.Fn => {
return format(context, Errors, output, "{}@{x}", @typeName(T), @ptrToInt(value));
@@ -872,8 +877,8 @@ pub fn formatBytes(
}
const buf = switch (radix) {
- 1000 => [_]u8{ suffix, 'B' },
- 1024 => [_]u8{ suffix, 'i', 'B' },
+ 1000 => &[_]u8{ suffix, 'B' },
+ 1024 => &[_]u8{ suffix, 'i', 'B' },
else => unreachable,
};
return output(context, buf);
@@ -969,7 +974,7 @@ fn formatIntUnsigned(
if (leftover_padding == 0) break;
}
mem.set(u8, buf[0..index], options.fill);
- return output(context, buf);
+ return output(context, &buf);
} else {
const padded_buf = buf[index - padding ..];
mem.set(u8, padded_buf[0..padding], options.fill);
lib/std/fs.zig
@@ -60,7 +60,7 @@ pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path:
tmp_path[dirname.len] = path.sep;
while (true) {
try crypto.randomBytes(rand_buf[0..]);
- b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], rand_buf);
+ b64_fs_encoder.encode(tmp_path[dirname.len + 1 ..], &rand_buf);
if (symLink(existing_path, tmp_path)) {
return rename(tmp_path, new_path);
@@ -226,7 +226,7 @@ pub const AtomicFile = struct {
while (true) {
try crypto.randomBytes(rand_buf[0..]);
- b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], rand_buf);
+ b64_fs_encoder.encode(tmp_path_buf[dirname_component_len..tmp_path_len], &rand_buf);
const file = File.openWriteNoClobberC(@ptrCast([*:0]u8, &tmp_path_buf), mode) catch |err| switch (err) {
error.PathAlreadyExists => continue,
@@ -290,7 +290,7 @@ pub fn makeDirW(dir_path: [*:0]const u16) !void {
/// have been modified regardless.
/// TODO determine if we can remove the allocator requirement from this function
pub fn makePath(allocator: *Allocator, full_path: []const u8) !void {
- const resolved_path = try path.resolve(allocator, [_][]const u8{full_path});
+ const resolved_path = try path.resolve(allocator, &[_][]const u8{full_path});
defer allocator.free(resolved_path);
var end_index: usize = resolved_path.len;
lib/std/hash_map.zig
@@ -94,7 +94,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3
pub fn init(allocator: *Allocator) Self {
return Self{
- .entries = [_]Entry{},
+ .entries = &[_]Entry{},
.allocator = allocator,
.size = 0,
.max_distance_from_start_index = 0,
lib/std/io.zig
@@ -1107,7 +1107,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
byte.* = if (t_bit_count < u8_bit_count) v else @truncate(u8, v);
}
- try self.out_stream.write(buffer);
+ try self.out_stream.write(&buffer);
}
/// Serializes the passed value into the stream
lib/std/mem.zig
@@ -624,23 +624,23 @@ test "comptime read/write int" {
}
test "readIntBig and readIntLittle" {
- testing.expect(readIntSliceBig(u0, [_]u8{}) == 0x0);
- testing.expect(readIntSliceLittle(u0, [_]u8{}) == 0x0);
+ testing.expect(readIntSliceBig(u0, &[_]u8{}) == 0x0);
+ testing.expect(readIntSliceLittle(u0, &[_]u8{}) == 0x0);
- testing.expect(readIntSliceBig(u8, [_]u8{0x32}) == 0x32);
- testing.expect(readIntSliceLittle(u8, [_]u8{0x12}) == 0x12);
+ testing.expect(readIntSliceBig(u8, &[_]u8{0x32}) == 0x32);
+ testing.expect(readIntSliceLittle(u8, &[_]u8{0x12}) == 0x12);
- testing.expect(readIntSliceBig(u16, [_]u8{ 0x12, 0x34 }) == 0x1234);
- testing.expect(readIntSliceLittle(u16, [_]u8{ 0x12, 0x34 }) == 0x3412);
+ testing.expect(readIntSliceBig(u16, &[_]u8{ 0x12, 0x34 }) == 0x1234);
+ testing.expect(readIntSliceLittle(u16, &[_]u8{ 0x12, 0x34 }) == 0x3412);
- testing.expect(readIntSliceBig(u72, [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
- testing.expect(readIntSliceLittle(u72, [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
+ testing.expect(readIntSliceBig(u72, &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024);
+ testing.expect(readIntSliceLittle(u72, &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec);
- testing.expect(readIntSliceBig(i8, [_]u8{0xff}) == -1);
- testing.expect(readIntSliceLittle(i8, [_]u8{0xfe}) == -2);
+ testing.expect(readIntSliceBig(i8, &[_]u8{0xff}) == -1);
+ testing.expect(readIntSliceLittle(i8, &[_]u8{0xfe}) == -2);
- testing.expect(readIntSliceBig(i16, [_]u8{ 0xff, 0xfd }) == -3);
- testing.expect(readIntSliceLittle(i16, [_]u8{ 0xfc, 0xff }) == -4);
+ testing.expect(readIntSliceBig(i16, &[_]u8{ 0xff, 0xfd }) == -3);
+ testing.expect(readIntSliceLittle(i16, &[_]u8{ 0xfc, 0xff }) == -4);
}
/// Writes an integer to memory, storing it in twos-complement.
@@ -749,34 +749,34 @@ test "writeIntBig and writeIntLittle" {
var buf9: [9]u8 = undefined;
writeIntBig(u0, &buf0, 0x0);
- testing.expect(eql(u8, buf0[0..], [_]u8{}));
+ testing.expect(eql(u8, buf0[0..], &[_]u8{}));
writeIntLittle(u0, &buf0, 0x0);
- testing.expect(eql(u8, buf0[0..], [_]u8{}));
+ testing.expect(eql(u8, buf0[0..], &[_]u8{}));
writeIntBig(u8, &buf1, 0x12);
- testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));
+ testing.expect(eql(u8, buf1[0..], &[_]u8{0x12}));
writeIntLittle(u8, &buf1, 0x34);
- testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));
+ testing.expect(eql(u8, buf1[0..], &[_]u8{0x34}));
writeIntBig(u16, &buf2, 0x1234);
- testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));
+ testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x12, 0x34 }));
writeIntLittle(u16, &buf2, 0x5678);
- testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));
+ testing.expect(eql(u8, buf2[0..], &[_]u8{ 0x78, 0x56 }));
writeIntBig(u72, &buf9, 0x123456789abcdef024);
- testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
+ testing.expect(eql(u8, buf9[0..], &[_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
- testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
+ testing.expect(eql(u8, buf9[0..], &[_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
writeIntBig(i8, &buf1, -1);
- testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));
+ testing.expect(eql(u8, buf1[0..], &[_]u8{0xff}));
writeIntLittle(i8, &buf1, -2);
- testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));
+ testing.expect(eql(u8, buf1[0..], &[_]u8{0xfe}));
writeIntBig(i16, &buf2, -3);
- testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));
+ testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xff, 0xfd }));
writeIntLittle(i16, &buf2, -4);
- testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));
+ testing.expect(eql(u8, buf2[0..], &[_]u8{ 0xfc, 0xff }));
}
/// 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
test "mem.join" {
var buf: [1024]u8 = undefined;
const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
- testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "b", "c" }), "a,b,c"));
- testing.expect(eql(u8, try join(a, ",", [_][]const u8{"a"}), "a"));
- testing.expect(eql(u8, try join(a, ",", [_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
+ testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "b", "c" }), "a,b,c"));
+ testing.expect(eql(u8, try join(a, ",", &[_][]const u8{"a"}), "a"));
+ testing.expect(eql(u8, try join(a, ",", &[_][]const u8{ "a", "", "b", "", "c" }), "a,,b,,c"));
}
/// 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
test "concat" {
var buf: [1024]u8 = undefined;
const a = &std.heap.FixedBufferAllocator.init(&buf).allocator;
- testing.expect(eql(u8, try concat(a, u8, [_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
- testing.expect(eql(u32, try concat(a, u32, [_][]const u32{
- [_]u32{ 0, 1 },
- [_]u32{ 2, 3, 4 },
- [_]u32{},
- [_]u32{5},
- }), [_]u32{ 0, 1, 2, 3, 4, 5 }));
+ testing.expect(eql(u8, try concat(a, u8, &[_][]const u8{ "abc", "def", "ghi" }), "abcdefghi"));
+ testing.expect(eql(u32, try concat(a, u32, &[_][]const u32{
+ &[_]u32{ 0, 1 },
+ &[_]u32{ 2, 3, 4 },
+ &[_]u32{},
+ &[_]u32{5},
+ }), &[_]u32{ 0, 1, 2, 3, 4, 5 }));
}
test "testStringEquality" {
@@ -1111,19 +1111,19 @@ fn testWriteIntImpl() void {
var bytes: [8]u8 = undefined;
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Big);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u0, bytes[0..], 0, builtin.Endian.Little);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
}));
writeIntSlice(u64, bytes[0..], 0x12345678CAFEBABE, builtin.Endian.Big);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1135,7 +1135,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u64, bytes[0..], 0xBEBAFECA78563412, builtin.Endian.Little);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1147,7 +1147,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x12345678, builtin.Endian.Big);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x00,
0x00,
0x00,
@@ -1159,7 +1159,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u32, bytes[0..], 0x78563412, builtin.Endian.Little);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x12,
0x34,
0x56,
@@ -1171,7 +1171,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Big);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x00,
0x00,
0x00,
@@ -1183,7 +1183,7 @@ fn testWriteIntImpl() void {
}));
writeIntSlice(u16, bytes[0..], 0x1234, builtin.Endian.Little);
- testing.expect(eql(u8, bytes, [_]u8{
+ testing.expect(eql(u8, &bytes, &[_]u8{
0x34,
0x12,
0x00,
@@ -1235,22 +1235,10 @@ pub fn reverse(comptime T: type, items: []T) void {
}
test "reverse" {
- var arr = [_]i32{
- 5,
- 3,
- 1,
- 2,
- 4,
- };
+ var arr = [_]i32{ 5, 3, 1, 2, 4 };
reverse(i32, arr[0..]);
- testing.expect(eql(i32, arr, [_]i32{
- 4,
- 2,
- 1,
- 3,
- 5,
- }));
+ testing.expect(eql(i32, &arr, &[_]i32{ 4, 2, 1, 3, 5 }));
}
/// 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 {
}
test "rotate" {
- var arr = [_]i32{
- 5,
- 3,
- 1,
- 2,
- 4,
- };
+ var arr = [_]i32{ 5, 3, 1, 2, 4 };
rotate(i32, arr[0..], 2);
- testing.expect(eql(i32, arr, [_]i32{
- 1,
- 2,
- 4,
- 5,
- 3,
- }));
+ testing.expect(eql(i32, &arr, &[_]i32{ 1, 2, 4, 5, 3 }));
}
/// Converts a little-endian integer to host endianness.
@@ -1394,14 +1370,14 @@ pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
test "toBytes" {
var my_bytes = toBytes(@as(u32, 0x12345678));
switch (builtin.endian) {
- builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x12\x34\x56\x78")),
- builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x78\x56\x34\x12")),
+ builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x12\x34\x56\x78")),
+ builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x78\x56\x34\x12")),
}
my_bytes[0] = '\x99';
switch (builtin.endian) {
- builtin.Endian.Big => testing.expect(eql(u8, my_bytes, "\x99\x34\x56\x78")),
- builtin.Endian.Little => testing.expect(eql(u8, my_bytes, "\x99\x56\x34\x12")),
+ builtin.Endian.Big => testing.expect(eql(u8, &my_bytes, "\x99\x34\x56\x78")),
+ builtin.Endian.Little => testing.expect(eql(u8, &my_bytes, "\x99\x56\x34\x12")),
}
}
@@ -1495,14 +1471,14 @@ pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubA
test "subArrayPtr" {
const a1: [6]u8 = "abcdef".*;
const sub1 = subArrayPtr(&a1, 2, 3);
- testing.expect(eql(u8, sub1.*, "cde"));
+ testing.expect(eql(u8, sub1, "cde"));
var a2: [6]u8 = "abcdef".*;
var sub2 = subArrayPtr(&a2, 2, 3);
testing.expect(eql(u8, sub2, "cde"));
sub2[1] = 'X';
- testing.expect(eql(u8, a2, "abcXef"));
+ testing.expect(eql(u8, &a2, "abcXef"));
}
/// Round an address up to the nearest aligned address
lib/std/net.zig
@@ -291,7 +291,7 @@ pub const Address = extern union {
},
os.AF_INET6 => {
const port = mem.bigToNative(u16, self.in6.port);
- if (mem.eql(u8, self.in6.addr[0..12], [_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
+ if (mem.eql(u8, self.in6.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
try std.fmt.format(
context,
Errors,
@@ -339,7 +339,7 @@ pub const Address = extern union {
unreachable;
}
- try std.fmt.format(context, Errors, output, "{}", self.un.path);
+ try std.fmt.format(context, Errors, output, "{}", &self.un.path);
},
else => unreachable,
}
@@ -894,7 +894,7 @@ fn linuxLookupNameFromDnsSearch(
}
const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
- [_]u8{}
+ &[_]u8{}
else
rc.search.toSliceConst();
@@ -959,7 +959,7 @@ fn linuxLookupNameFromDns(
for (afrrs) |afrr| {
if (family != afrr.af) {
- const len = os.res_mkquery(0, name, 1, afrr.rr, [_]u8{}, null, &qbuf[nq]);
+ const len = os.res_mkquery(0, name, 1, afrr.rr, &[_]u8{}, null, &qbuf[nq]);
qp[nq] = qbuf[nq][0..len];
nq += 1;
}
lib/std/packed_int_array.zig
@@ -201,7 +201,7 @@ pub fn PackedIntArrayEndian(comptime Int: type, comptime endian: builtin.Endian,
///Return the Int stored at index
pub fn get(self: Self, index: usize) Int {
debug.assert(index < int_count);
- return Io.get(self.bytes, index, 0);
+ return Io.get(&self.bytes, index, 0);
}
///Copy int into the array at index
@@ -528,16 +528,7 @@ test "PackedInt(Array/Slice) sliceCast" {
test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u4, .Big, 8);
- var packed_array_be = PackedArrayBe.init([_]u4{
- 0,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- });
+ var packed_array_be = PackedArrayBe.init([_]u4{ 0, 1, 2, 3, 4, 5, 6, 7 });
testing.expect(packed_array_be.bytes[0] == 0b00000001);
testing.expect(packed_array_be.bytes[1] == 0b00100011);
@@ -563,16 +554,7 @@ test "PackedInt(Array/Slice)Endian" {
{
const PackedArrayBe = PackedIntArrayEndian(u11, .Big, 8);
- var packed_array_be = PackedArrayBe.init([_]u11{
- 0,
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- });
+ var packed_array_be = PackedArrayBe.init([_]u11{ 0, 1, 2, 3, 4, 5, 6, 7 });
testing.expect(packed_array_be.bytes[0] == 0b00000000);
testing.expect(packed_array_be.bytes[1] == 0b00000000);
testing.expect(packed_array_be.bytes[2] == 0b00000100);
lib/std/priority_queue.zig
@@ -22,7 +22,7 @@ pub fn PriorityQueue(comptime T: type) type {
/// `fn lessThan(a: T, b: T) bool { return a < b; }`
pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
return Self{
- .items = [_]T{},
+ .items = &[_]T{},
.len = 0,
.allocator = allocator,
.compareFn = compareFn,
lib/std/process.zig
@@ -473,14 +473,14 @@ pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const []u8) void {
}
test "windows arg parsing" {
- testWindowsCmdLine("a b\tc d", [_][]const u8{ "a", "b", "c", "d" });
- testWindowsCmdLine("\"abc\" d e", [_][]const u8{ "abc", "d", "e" });
- testWindowsCmdLine("a\\\\\\b d\"e f\"g h", [_][]const u8{ "a\\\\\\b", "de fg", "h" });
- testWindowsCmdLine("a\\\\\\\"b c d", [_][]const u8{ "a\\\"b", "c", "d" });
- testWindowsCmdLine("a\\\\\\\\\"b c\" d e", [_][]const u8{ "a\\\\b c", "d", "e" });
- testWindowsCmdLine("a b\tc \"d f", [_][]const u8{ "a", "b", "c", "\"d", "f" });
-
- testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [_][]const u8{
+ testWindowsCmdLine("a b\tc d", &[_][]const u8{ "a", "b", "c", "d" });
+ testWindowsCmdLine("\"abc\" d e", &[_][]const u8{ "abc", "d", "e" });
+ testWindowsCmdLine("a\\\\\\b d\"e f\"g h", &[_][]const u8{ "a\\\\\\b", "de fg", "h" });
+ testWindowsCmdLine("a\\\\\\\"b c d", &[_][]const u8{ "a\\\"b", "c", "d" });
+ testWindowsCmdLine("a\\\\\\\\\"b c\" d e", &[_][]const u8{ "a\\\\b c", "d", "e" });
+ testWindowsCmdLine("a b\tc \"d f", &[_][]const u8{ "a", "b", "c", "\"d", "f" });
+
+ testWindowsCmdLine("\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", &[_][]const u8{
".\\..\\zig-cache\\build",
"bin\\zig.exe",
".\\..",
lib/std/rand.zig
@@ -54,7 +54,7 @@ pub const Random = struct {
// use LE instead of native endian for better portability maybe?
// TODO: endian portability is pointless if the underlying prng isn't endian portable.
// TODO: document the endian portability of this library.
- const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, rand_bytes);
+ const byte_aligned_result = mem.readIntSliceLittle(ByteAlignedT, &rand_bytes);
const unsigned_result = @truncate(UnsignedT, byte_aligned_result);
return @bitCast(T, unsigned_result);
}
lib/std/segmented_list.zig
@@ -112,7 +112,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
.allocator = allocator,
.len = 0,
.prealloc_segment = undefined,
- .dynamic_segments = [_][*]T{},
+ .dynamic_segments = &[_][*]T{},
};
}
@@ -192,7 +192,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
const len = @intCast(ShelfIndex, self.dynamic_segments.len);
self.freeShelves(len, 0);
self.allocator.free(self.dynamic_segments);
- self.dynamic_segments = [_][*]T{};
+ self.dynamic_segments = &[_][*]T{};
return;
}
@@ -385,18 +385,14 @@ fn testSegmentedList(comptime prealloc: usize, allocator: *Allocator) !void {
testing.expect(list.pop().? == 100);
testing.expect(list.len == 99);
- try list.pushMany([_]i32{
- 1,
- 2,
- 3,
- });
+ try list.pushMany(&[_]i32{ 1, 2, 3 });
testing.expect(list.len == 102);
testing.expect(list.pop().? == 3);
testing.expect(list.pop().? == 2);
testing.expect(list.pop().? == 1);
testing.expect(list.len == 99);
- try list.pushMany([_]i32{});
+ try list.pushMany(&[_]i32{});
testing.expect(list.len == 99);
var i: i32 = 99;
lib/std/sort.zig
@@ -1043,27 +1043,27 @@ fn cmpByValue(a: IdAndValue, b: IdAndValue) bool {
test "std.sort" {
const u8cases = [_][]const []const u8{
- [_][]const u8{
+ &[_][]const u8{
"",
"",
},
- [_][]const u8{
+ &[_][]const u8{
"a",
"a",
},
- [_][]const u8{
+ &[_][]const u8{
"az",
"az",
},
- [_][]const u8{
+ &[_][]const u8{
"za",
"az",
},
- [_][]const u8{
+ &[_][]const u8{
"asdf",
"adfs",
},
- [_][]const u8{
+ &[_][]const u8{
"one",
"eno",
},
@@ -1078,29 +1078,29 @@ test "std.sort" {
}
const i32cases = [_][]const []const i32{
- [_][]const i32{
- [_]i32{},
- [_]i32{},
+ &[_][]const i32{
+ &[_]i32{},
+ &[_]i32{},
},
- [_][]const i32{
- [_]i32{1},
- [_]i32{1},
+ &[_][]const i32{
+ &[_]i32{1},
+ &[_]i32{1},
},
- [_][]const i32{
- [_]i32{ 0, 1 },
- [_]i32{ 0, 1 },
+ &[_][]const i32{
+ &[_]i32{ 0, 1 },
+ &[_]i32{ 0, 1 },
},
- [_][]const i32{
- [_]i32{ 1, 0 },
- [_]i32{ 0, 1 },
+ &[_][]const i32{
+ &[_]i32{ 1, 0 },
+ &[_]i32{ 0, 1 },
},
- [_][]const i32{
- [_]i32{ 1, -1, 0 },
- [_]i32{ -1, 0, 1 },
+ &[_][]const i32{
+ &[_]i32{ 1, -1, 0 },
+ &[_]i32{ -1, 0, 1 },
},
- [_][]const i32{
- [_]i32{ 2, 1, 3 },
- [_]i32{ 1, 2, 3 },
+ &[_][]const i32{
+ &[_]i32{ 2, 1, 3 },
+ &[_]i32{ 1, 2, 3 },
},
};
@@ -1115,29 +1115,29 @@ test "std.sort" {
test "std.sort descending" {
const rev_cases = [_][]const []const i32{
- [_][]const i32{
- [_]i32{},
- [_]i32{},
+ &[_][]const i32{
+ &[_]i32{},
+ &[_]i32{},
},
- [_][]const i32{
- [_]i32{1},
- [_]i32{1},
+ &[_][]const i32{
+ &[_]i32{1},
+ &[_]i32{1},
},
- [_][]const i32{
- [_]i32{ 0, 1 },
- [_]i32{ 1, 0 },
+ &[_][]const i32{
+ &[_]i32{ 0, 1 },
+ &[_]i32{ 1, 0 },
},
- [_][]const i32{
- [_]i32{ 1, 0 },
- [_]i32{ 1, 0 },
+ &[_][]const i32{
+ &[_]i32{ 1, 0 },
+ &[_]i32{ 1, 0 },
},
- [_][]const i32{
- [_]i32{ 1, -1, 0 },
- [_]i32{ 1, 0, -1 },
+ &[_][]const i32{
+ &[_]i32{ 1, -1, 0 },
+ &[_]i32{ 1, 0, -1 },
},
- [_][]const i32{
- [_]i32{ 2, 1, 3 },
- [_]i32{ 3, 2, 1 },
+ &[_][]const i32{
+ &[_]i32{ 2, 1, 3 },
+ &[_]i32{ 3, 2, 1 },
},
};
@@ -1154,7 +1154,7 @@ test "another sort case" {
var arr = [_]i32{ 5, 3, 1, 2, 4 };
sort(i32, arr[0..], asc(i32));
- testing.expect(mem.eql(i32, arr, [_]i32{ 1, 2, 3, 4, 5 }));
+ testing.expect(mem.eql(i32, &arr, &[_]i32{ 1, 2, 3, 4, 5 }));
}
test "sort fuzz testing" {
lib/std/unicode.zig
@@ -499,14 +499,14 @@ test "utf16leToUtf8" {
{
mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 'A');
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 'a');
- const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
+ const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
testing.expect(mem.eql(u8, utf8, "Aa"));
}
{
mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0x80);
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xffff);
- const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
+ const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
testing.expect(mem.eql(u8, utf8, "\xc2\x80" ++ "\xef\xbf\xbf"));
}
@@ -514,7 +514,7 @@ test "utf16leToUtf8" {
// the values just outside the surrogate half range
mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd7ff);
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xe000);
- const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
+ const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
testing.expect(mem.eql(u8, utf8, "\xed\x9f\xbf" ++ "\xee\x80\x80"));
}
@@ -522,7 +522,7 @@ test "utf16leToUtf8" {
// smallest surrogate pair
mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xd800);
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
- const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
+ const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
testing.expect(mem.eql(u8, utf8, "\xf0\x90\x80\x80"));
}
@@ -530,14 +530,14 @@ test "utf16leToUtf8" {
// largest surrogate pair
mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdfff);
- const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
+ const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xbf\xbf"));
}
{
mem.writeIntSliceLittle(u16, utf16le_as_bytes[0..], 0xdbff);
mem.writeIntSliceLittle(u16, utf16le_as_bytes[2..], 0xdc00);
- const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, utf16le);
+ const utf8 = try utf16leToUtf8Alloc(std.debug.global_allocator, &utf16le);
testing.expect(mem.eql(u8, utf8, "\xf4\x8f\xb0\x80"));
}
}
src/all_types.hpp
@@ -2650,6 +2650,9 @@ struct IrInstruction {
IrInstructionId id;
// true if this instruction was generated by zig and not from user code
bool is_gen;
+
+ // for debugging purposes, this is useful to call to inspect the instruction
+ void dump();
};
struct IrInstructionDeclVarSrc {
src/ir.cpp
@@ -218,7 +218,8 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
ZigType *dest_type);
static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
- ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime);
+ ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
+ bool non_null_comptime, bool allow_discard);
static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
bool non_null_comptime, bool allow_discard);
@@ -10417,9 +10418,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
}
if (cur_type->id == ZigTypeIdErrorSet) {
- if (prev_type->id == ZigTypeIdArray) {
- convert_to_const_slice = true;
- }
if (!resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {
return ira->codegen->builtin_types.entry_invalid;
}
@@ -10754,25 +10752,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
}
}
- if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
- cur_type->data.array.len != prev_type->data.array.len &&
- types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type,
- source_node, false).id == ConstCastResultIdOk)
- {
- convert_to_const_slice = true;
- prev_inst = cur_inst;
- continue;
- }
-
- if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray &&
- cur_type->data.array.len != prev_type->data.array.len &&
- types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type,
- source_node, false).id == ConstCastResultIdOk)
- {
- convert_to_const_slice = true;
- continue;
- }
-
// *[N]T to []T
// *[N]T to E![]T
if (cur_type->id == ZigTypeIdPointer &&
@@ -10820,19 +10799,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
}
}
- // [N]T to []T
- if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) &&
- (prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
- cur_type->data.array.len == 0) &&
- types_match_const_cast_only(ira,
- prev_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
- cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
- {
- convert_to_const_slice = false;
- continue;
- }
-
-
// *[N]T and *[M]T
if (cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
@@ -10876,19 +10842,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
continue;
}
- // [N]T to []T
- if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) &&
- (cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const ||
- prev_type->data.array.len == 0) &&
- types_match_const_cast_only(ira,
- cur_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.child_type,
- prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
- {
- prev_inst = cur_inst;
- convert_to_const_slice = false;
- continue;
- }
-
if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion &&
(cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr))
{
@@ -10924,18 +10877,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
free(errors);
if (convert_to_const_slice) {
- if (prev_inst->value->type->id == ZigTypeIdArray) {
- ZigType *ptr_type = get_pointer_to_type_extra(
- ira->codegen, prev_inst->value->type->data.array.child_type,
- true, false, PtrLenUnknown,
- 0, 0, 0, false);
- ZigType *slice_type = get_slice_type(ira->codegen, ptr_type);
- if (err_set_type != nullptr) {
- return get_error_union_type(ira->codegen, err_set_type, slice_type);
- } else {
- return slice_type;
- }
- } else if (prev_inst->value->type->id == ZigTypeIdPointer) {
+ if (prev_inst->value->type->id == ZigTypeIdPointer) {
ZigType *array_type = prev_inst->value->type->data.pointer.child_type;
src_assert(array_type->id == ZigTypeIdArray, source_node);
ZigType *ptr_type = get_pointer_to_type_extra2(
@@ -12021,52 +11963,6 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
return new_instruction;
}
-static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,
- IrInstruction *array_arg, ZigType *wanted_type, ResultLoc *result_loc)
-{
- assert(is_slice(wanted_type));
- // In this function we honor the const-ness of wanted_type, because
- // we may be casting [0]T to []const T which is perfectly valid.
-
- IrInstruction *array_ptr = nullptr;
- IrInstruction *array;
- if (array_arg->value->type->id == ZigTypeIdPointer) {
- array = ir_get_deref(ira, source_instr, array_arg, nullptr);
- array_ptr = array_arg;
- } else {
- array = array_arg;
- }
- ZigType *array_type = array->value->type;
- assert(array_type->id == ZigTypeIdArray);
-
- if (instr_is_comptime(array) || array_type->data.array.len == 0) {
- IrInstruction *result = ir_const(ira, source_instr, wanted_type);
- init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true);
- result->value->type = wanted_type;
- return result;
- }
-
- IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
- init_const_usize(ira->codegen, start->value, 0);
-
- IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize);
- init_const_usize(ira->codegen, end->value, array_type->data.array.len);
-
- if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
-
- if (result_loc == nullptr) result_loc = no_result_loc();
- IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr,
- true, false, true);
- if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
- return result_loc_inst;
- }
- IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst);
- result->value->data.rh_slice.id = RuntimeHintSliceIdLen;
- result->value->data.rh_slice.len = array_type->data.array.len;
-
- return result;
-}
-
static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {
assert(union_type->id == ZigTypeIdUnion);
@@ -13101,44 +12997,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type);
}
- // cast from [N]T to []const T
- // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
- if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) {
- ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index]->type_entry;
- assert(ptr_type->id == ZigTypeIdPointer);
- if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
- types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
- source_node, false).id == ConstCastResultIdOk)
- {
- return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type, nullptr);
- }
- }
-
- // cast from [N]T to ?[]const T
- // TODO: once https://github.com/ziglang/zig/issues/265 lands, remove this
- if (wanted_type->id == ZigTypeIdOptional &&
- is_slice(wanted_type->data.maybe.child_type) &&
- actual_type->id == ZigTypeIdArray)
- {
- ZigType *ptr_type =
- wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index]->type_entry;
- assert(ptr_type->id == ZigTypeIdPointer);
- if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
- types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
- source_node, false).id == ConstCastResultIdOk)
- {
- IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
- if (type_is_invalid(cast1->value->type))
- return ira->codegen->invalid_instruction;
-
- IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
- if (type_is_invalid(cast2->value->type))
- return ira->codegen->invalid_instruction;
-
- return cast2;
- }
- }
-
// *[N]T to ?[]const T
if (wanted_type->id == ZigTypeIdOptional &&
is_slice(wanted_type->data.maybe.child_type) &&
@@ -13284,20 +13142,41 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// *@Frame(func) to anyframe->T or anyframe
+ // *@Frame(func) to ?anyframe->T or ?anyframe
+ // *@Frame(func) to E!anyframe->T or E!anyframe
if (actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle &&
!actual_type->data.pointer.is_const &&
- actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame && wanted_type->id == ZigTypeIdAnyFrame)
+ actual_type->data.pointer.child_type->id == ZigTypeIdFnFrame)
{
- bool ok = true;
- if (wanted_type->data.any_frame.result_type != nullptr) {
- ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;
- ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;
- if (wanted_type->data.any_frame.result_type != fn_return_type) {
- ok = false;
+ ZigType *anyframe_type;
+ if (wanted_type->id == ZigTypeIdAnyFrame) {
+ anyframe_type = wanted_type;
+ } else if (wanted_type->id == ZigTypeIdOptional &&
+ wanted_type->data.maybe.child_type->id == ZigTypeIdAnyFrame)
+ {
+ anyframe_type = wanted_type->data.maybe.child_type;
+ } else if (wanted_type->id == ZigTypeIdErrorUnion &&
+ wanted_type->data.error_union.payload_type->id == ZigTypeIdAnyFrame)
+ {
+ anyframe_type = wanted_type->data.error_union.payload_type;
+ } else {
+ anyframe_type = nullptr;
+ }
+ if (anyframe_type != nullptr) {
+ bool ok = true;
+ if (anyframe_type->data.any_frame.result_type != nullptr) {
+ ZigFn *fn = actual_type->data.pointer.child_type->data.frame.fn;
+ ZigType *fn_return_type = fn->type_entry->data.fn.fn_type_id.return_type;
+ if (anyframe_type->data.any_frame.result_type != fn_return_type) {
+ ok = false;
+ }
+ }
+ if (ok) {
+ IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
+ if (anyframe_type == wanted_type)
+ return cast1;
+ return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
}
- }
- if (ok) {
- return ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, wanted_type);
}
}
@@ -13322,30 +13201,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return ir_analyze_null_to_c_pointer(ira, source_instr, value, wanted_type);
}
- // cast from [N]T to E![]const T
- if (wanted_type->id == ZigTypeIdErrorUnion &&
- is_slice(wanted_type->data.error_union.payload_type) &&
- actual_type->id == ZigTypeIdArray)
- {
- ZigType *ptr_type =
- wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index]->type_entry;
- assert(ptr_type->id == ZigTypeIdPointer);
- if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
- types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type,
- source_node, false).id == ConstCastResultIdOk)
- {
- IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
- if (type_is_invalid(cast1->value->type))
- return ira->codegen->invalid_instruction;
-
- IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
- if (type_is_invalid(cast2->value->type))
- return ira->codegen->invalid_instruction;
-
- return cast2;
- }
- }
-
// cast from E to E!T
if (wanted_type->id == ZigTypeIdErrorUnion &&
actual_type->id == ZigTypeIdErrorSet)
@@ -13541,6 +13396,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
}
+ // T to ?E!T
+ if (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdErrorUnion &&
+ actual_type->id != ZigTypeIdOptional)
+ {
+ IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
+ if (type_is_invalid(cast1->value->type))
+ return ira->codegen->invalid_instruction;
+ return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
+ }
+
ErrorMsg *parent_msg = ir_add_error_node(ira, source_instr->source_node,
buf_sprintf("expected type '%s', found '%s'",
buf_ptr(&wanted_type->name),
@@ -15283,10 +15148,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
ZigValue *out_array_val;
size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
- if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
- result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
- out_array_val = out_val;
- } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
+ if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
out_array_val = create_const_vals(1);
out_array_val->special = ConstValSpecialStatic;
out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
@@ -15314,6 +15176,9 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
out_val->data.x_struct.fields[slice_len_index]->type = ira->codegen->builtin_types.entry_usize;
out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic;
bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len);
+ } else if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) {
+ result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
+ out_array_val = out_val;
} else {
result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
@@ -16142,7 +16007,8 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
// when calling this function, at the callsite must check for result type noreturn and propagate it up
static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
- ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
+ ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,
+ bool non_null_comptime, bool allow_discard)
{
Error err;
if (result_loc->resolved_loc != nullptr) {
@@ -16275,8 +16141,12 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
ira->src_implicit_return_type_list.append(value);
}
peer_parent->skipped = true;
- return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
+ IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
value_type, value, force_runtime || !is_comptime, true, true);
+ if (parent_result_loc != nullptr) {
+ peer_parent->parent->written = true;
+ }
+ return parent_result_loc;
}
if (peer_parent->resolved_type == nullptr) {
@@ -16317,30 +16187,16 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
force_runtime, non_null_comptime);
}
- ConstCastOnly const_cast_result = types_match_const_cast_only(ira, dest_type, value_type,
- result_cast->base.source_instruction->source_node, false);
- if (const_cast_result.id == ConstCastResultIdInvalid)
- return ira->codegen->invalid_instruction;
- if (const_cast_result.id != ConstCastResultIdOk) {
- // We will not be able to provide a result location for this value. Create
- // a new result location.
- return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
- force_runtime, non_null_comptime);
- }
-
- // In this case we can pointer cast the result location.
IrInstruction *casted_value;
if (value != nullptr) {
casted_value = ir_implicit_cast(ira, value, dest_type);
+ if (type_is_invalid(casted_value->value->type))
+ return ira->codegen->invalid_instruction;
+ dest_type = casted_value->value->type;
} else {
casted_value = nullptr;
}
- if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) {
- return casted_value;
- }
-
- bool old_parent_result_loc_written = result_cast->parent->written;
IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
dest_type, casted_value, force_runtime, non_null_comptime, true);
if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
@@ -16378,26 +16234,24 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
- {
- // we also need to check that this cast is OK.
- ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
- parent_result_loc->value->type, ptr_type,
- result_cast->base.source_instruction->source_node, false);
- if (const_cast_result.id == ConstCastResultIdInvalid)
- return ira->codegen->invalid_instruction;
- if (const_cast_result.id != ConstCastResultIdOk) {
- // We will not be able to provide a result location for this value. Create
- // a new result location.
- result_cast->parent->written = old_parent_result_loc_written;
- return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
- force_runtime, non_null_comptime);
+ ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
+ parent_result_loc->value->type, ptr_type,
+ result_cast->base.source_instruction->source_node, false);
+ if (const_cast_result.id == ConstCastResultIdInvalid)
+ return ira->codegen->invalid_instruction;
+ if (const_cast_result.id != ConstCastResultIdOk) {
+ if (allow_discard) {
+ return parent_result_loc;
}
+ // We will not be able to provide a result location for this value. Create
+ // a new result location.
+ result_cast->parent->written = false;
+ return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,
+ force_runtime, non_null_comptime);
}
- result_loc->written = true;
- result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
+ return ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
ptr_type, result_cast->base.source_instruction, false);
- return result_loc->resolved_loc;
}
case ResultLocIdBitCast: {
ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
@@ -16483,7 +16337,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
result_loc_pass1 = no_result_loc();
}
IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
- value, force_runtime, non_null_comptime);
+ value, force_runtime, non_null_comptime, allow_discard);
if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))
return result_loc;
@@ -16496,7 +16350,7 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
- value_type->id != ZigTypeIdNull)
+ value_type->id != ZigTypeIdNull && value == nullptr)
{
result_loc_pass1->written = false;
return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
@@ -16514,9 +16368,6 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
return unwrapped_err_ptr;
}
}
- } else if (is_slice(actual_elem_type) && value_type->id == ZigTypeIdArray) {
- // need to allow EndExpr to do the implicit cast from array to slice
- result_loc_pass1->written = false;
}
return result_loc;
}
@@ -17520,11 +17371,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
ir_reset_result(call_instruction->result_loc);
result_loc = nullptr;
- } else {
- call_instruction->base.value.type = impl_fn_type_id->return_type;
- IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type);
- if (type_is_invalid(casted_value->value.type))
- return casted_value;
}
}
} else if (call_instruction->is_async_call_builtin) {
@@ -17687,11 +17533,6 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) {
ir_reset_result(call_instruction->result_loc);
result_loc = nullptr;
- } else {
- call_instruction->base.value.type = return_type;
- IrInstruction *casted_value = ir_implicit_cast(ira, &call_instruction->base, result_loc->value.type->data.pointer.child_type);
- if (type_is_invalid(casted_value->value.type))
- return casted_value;
}
}
} else if (call_instruction->is_async_call_builtin) {
@@ -21041,6 +20882,8 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
{
// We're now done inferring the type.
container_type->data.structure.resolve_status = ResolveStatusUnstarted;
+ } else if (container_type->id == ZigTypeIdVector) {
+ // OK
} else {
ir_add_error_node(ira, instruction->base.source_node,
buf_sprintf("type '%s' does not support array initialization",
@@ -22434,17 +22277,23 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
return result;
}
-static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
+static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
+ const char *name, size_t field_index)
{
+ Error err;
ensure_field_index(struct_value->type, name, field_index);
- assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic);
- return struct_value->data.x_struct.fields[field_index];
+ ZigValue *val = struct_value->data.x_struct.fields[field_index];
+ if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, source_node, val, UndefBad)))
+ return nullptr;
+ return val;
}
static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,
const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
{
- ZigValue *field_val = get_const_field(ira, struct_value, name, field_index);
+ ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
+ if (field_val == nullptr)
+ return ErrorSemanticAnalyzeFail;
IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
get_optional_type(ira->codegen, elem_type));
@@ -22455,23 +22304,31 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
return ErrorNone;
}
-static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
+static Error get_const_field_bool(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value,
+ const char *name, size_t field_index, bool *out)
{
- ZigValue *value = get_const_field(ira, struct_value, name, field_index);
+ ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
+ if (value == nullptr)
+ return ErrorSemanticAnalyzeFail;
assert(value->type == ira->codegen->builtin_types.entry_bool);
- return value->data.x_bool;
+ *out = value->data.x_bool;
+ return ErrorNone;
}
-static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
+static BigInt *get_const_field_lit_int(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
{
- ZigValue *value = get_const_field(ira, struct_value, name, field_index);
+ ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
+ if (value == nullptr)
+ return nullptr;
assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
return &value->data.x_bigint;
}
-static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index)
+static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node, ZigValue *struct_value, const char *name, size_t field_index)
{
- ZigValue *value = get_const_field(ira, struct_value, name, field_index);
+ ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
+ if (value == nullptr)
+ return ira->codegen->invalid_instruction->value->type;
assert(value->type == ira->codegen->builtin_types.entry_type);
return value->data.x_type;
}
@@ -22489,17 +22346,25 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
return ira->codegen->builtin_types.entry_bool;
case ZigTypeIdUnreachable:
return ira->codegen->builtin_types.entry_unreachable;
- case ZigTypeIdInt:
+ case ZigTypeIdInt: {
assert(payload->special == ConstValSpecialStatic);
assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
- return get_int_type(ira->codegen,
- get_const_field_bool(ira, payload, "is_signed", 0),
- bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1)));
+ BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);
+ if (bi == nullptr)
+ return ira->codegen->invalid_instruction->value->type;
+ bool is_signed;
+ if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))
+ return ira->codegen->invalid_instruction->value->type;
+ return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
+ }
case ZigTypeIdFloat:
{
assert(payload->special == ConstValSpecialStatic);
assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
- uint32_t bits = bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 0));
+ BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0);
+ if (bi == nullptr)
+ return ira->codegen->invalid_instruction->value->type;
+ uint32_t bits = bigint_as_u32(bi);
switch (bits) {
case 16: return ira->codegen->builtin_types.entry_f16;
case 32: return ira->codegen->builtin_types.entry_f32;
@@ -22515,27 +22380,51 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
assert(payload->special == ConstValSpecialStatic);
assert(payload->type == type_info_pointer_type);
- ZigValue *size_value = get_const_field(ira, payload, "size", 0);
+ ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0);
assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
- ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4);
+ ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4);
+ if (type_is_invalid(elem_type))
+ return ira->codegen->invalid_instruction->value->type;
ZigValue *sentinel;
if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,
elem_type, &sentinel)))
{
- return nullptr;
+ return ira->codegen->invalid_instruction->value->type;
+ }
+ BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3);
+ if (bi == nullptr)
+ return ira->codegen->invalid_instruction->value->type;
+
+ bool is_const;
+ if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))
+ return ira->codegen->invalid_instruction->value->type;
+
+ bool is_volatile;
+ if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2,
+ &is_volatile)))
+ {
+ return ira->codegen->invalid_instruction->value->type;
+ }
+
+ bool is_allowzero;
+ if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5,
+ &is_allowzero)))
+ {
+ return ira->codegen->invalid_instruction->value->type;
}
+
ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
elem_type,
- get_const_field_bool(ira, payload, "is_const", 1),
- get_const_field_bool(ira, payload, "is_volatile", 2),
+ is_const,
+ is_volatile,
ptr_len,
- bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)),
+ bigint_as_u32(bi),
0, // bit_offset_in_host
0, // host_int_bytes
- get_const_field_bool(ira, payload, "is_allowzero", 5),
+ is_allowzero,
VECTOR_INDEX_NONE, nullptr, sentinel);
if (size_enum_index != 2)
return ptr_type;
@@ -22544,17 +22433,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
case ZigTypeIdArray: {
assert(payload->special == ConstValSpecialStatic);
assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
- ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1);
+ ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1);
+ if (type_is_invalid(elem_type))
+ return ira->codegen->invalid_instruction->value->type;
ZigValue *sentinel;
if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,
elem_type, &sentinel)))
{
- return nullptr;
+ return ira->codegen->invalid_instruction->value->type;
}
- return get_array_type(ira->codegen,
- elem_type,
- bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0)),
- sentinel);
+ BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);
+ if (bi == nullptr)
+ return ira->codegen->invalid_instruction->value->type;
+ return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
}
case ZigTypeIdComptimeFloat:
return ira->codegen->builtin_types.entry_num_lit_float;
@@ -22575,7 +22466,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
case ZigTypeIdEnumLiteral:
ir_add_error(ira, instruction, buf_sprintf(
"TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
- return nullptr;
+ return ira->codegen->invalid_instruction->value->type;
case ZigTypeIdUnion:
case ZigTypeIdFn:
case ZigTypeIdBoundFn:
@@ -22583,7 +22474,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
case ZigTypeIdStruct:
ir_add_error(ira, instruction, buf_sprintf(
"@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
- return nullptr;
+ return ira->codegen->invalid_instruction->value->type;
}
zig_unreachable();
}
@@ -22602,7 +22493,7 @@ static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionT
return ira->codegen->invalid_instruction;
ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);
- if (!type)
+ if (type_is_invalid(type))
return ira->codegen->invalid_instruction;
return ir_const_type(ira, &instruction->base, type);
}
@@ -28332,3 +28223,18 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
}
return ErrorNone;
}
+
+void IrInstruction::dump() {
+ IrInstruction *inst = this;
+ if (inst->source_node != nullptr) {
+ inst->source_node->src();
+ } else {
+ fprintf(stderr, "(null source node)\n");
+ }
+ IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;
+ ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);
+ if (pass == IrPassSrc) {
+ fprintf(stderr, "-> ");
+ ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);
+ }
+}
src-self-hosted/dep_tokenizer.zig
@@ -992,7 +992,7 @@ fn printHexValue(out: var, value: u64, width: u8) !void {
fn printCharValues(out: var, bytes: []const u8) !void {
for (bytes) |b| {
- try out.write([_]u8{printable_char_tab[b]});
+ try out.write(&[_]u8{printable_char_tab[b]});
}
}
@@ -1001,7 +1001,7 @@ fn printUnderstandableChar(out: var, char: u8) !void {
std.fmt.format(out.context, anyerror, out.output, "\\x{X:2}", char) catch {};
} else {
try out.write("'");
- try out.write([_]u8{printable_char_tab[char]});
+ try out.write(&[_]u8{printable_char_tab[char]});
try out.write("'");
}
}
src-self-hosted/main.zig
@@ -521,7 +521,7 @@ pub const usage_fmt =
pub const args_fmt_spec = [_]Flag{
Flag.Bool("--help"),
Flag.Bool("--check"),
- Flag.Option("--color", [_][]const u8{
+ Flag.Option("--color", &[_][]const u8{
"auto",
"off",
"on",
src-self-hosted/stage1.zig
@@ -170,7 +170,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
stderr = &stderr_file.outStream().stream;
const args = args_list.toSliceConst();
- var flags = try Args.parse(allocator, self_hosted_main.args_fmt_spec, args[2..]);
+ var flags = try Args.parse(allocator, &self_hosted_main.args_fmt_spec, args[2..]);
defer flags.deinit();
if (flags.present("help")) {
@@ -286,7 +286,7 @@ fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void
while (try dir_it.next()) |entry| {
if (entry.kind == .Directory or mem.endsWith(u8, entry.name, ".zig")) {
- const full_path = try fs.path.join(fmt.allocator, [_][]const u8{ file_path, entry.name });
+ const full_path = try fs.path.join(fmt.allocator, &[_][]const u8{ file_path, entry.name });
try fmtPath(fmt, full_path, check_mode);
}
}
test/stage1/behavior/bugs/1607.zig
@@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void {
}
test "slices pointing at the same address as global array." {
- checkAddress(a);
- comptime checkAddress(a);
+ checkAddress(&a);
+ comptime checkAddress(&a);
}
test/stage1/behavior/bugs/1914.zig
@@ -7,7 +7,7 @@ const B = struct {
a_pointer: *const A,
};
-const b_list: []B = [_]B{};
+const b_list: []B = &[_]B{};
const a = A{ .b_list_pointer = &b_list };
test "segfault bug" {
@@ -24,7 +24,7 @@ pub const B2 = struct {
pointer_array: []*A2,
};
-var b_value = B2{ .pointer_array = [_]*A2{} };
+var b_value = B2{ .pointer_array = &[_]*A2{} };
test "basic stuff" {
std.debug.assert(&b_value == &b_value);
test/stage1/behavior/array.zig
@@ -20,7 +20,7 @@ test "arrays" {
}
expect(accumulator == 15);
- expect(getArrayLen(array) == 5);
+ expect(getArrayLen(&array) == 5);
}
fn getArrayLen(a: []const u32) usize {
return a.len;
@@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 {
test "runtime initialize array elem and then implicit cast to slice" {
var two: i32 = 2;
- const x: []const i32 = [_]i32{two};
+ const x: []const i32 = &[_]i32{two};
expect(x[0] == 2);
}
test "array literal as argument to function" {
const S = struct {
fn entry(two: i32) void {
- foo([_]i32{
+ foo(&[_]i32{
1,
2,
3,
});
- foo([_]i32{
+ foo(&[_]i32{
1,
two,
3,
});
- foo2(true, [_]i32{
+ foo2(true, &[_]i32{
1,
2,
3,
});
- foo2(true, [_]i32{
+ foo2(true, &[_]i32{
1,
two,
3,
@@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" {
const S = struct {
fn entry(two: i32) void {
const cases = [_][]const []const i32{
- [_][]const i32{[_]i32{1}},
- [_][]const i32{[_]i32{ 2, 3 }},
- [_][]const i32{
- [_]i32{4},
- [_]i32{ 5, 6, 7 },
+ &[_][]const i32{&[_]i32{1}},
+ &[_][]const i32{&[_]i32{ 2, 3 }},
+ &[_][]const i32{
+ &[_]i32{4},
+ &[_]i32{ 5, 6, 7 },
},
};
- check(cases);
+ check(&cases);
const cases2 = [_][]const i32{
- [_]i32{1},
+ &[_]i32{1},
&[_]i32{ two, 3 },
};
expect(cases2.len == 2);
@@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" {
expect(cases2[1][1] == 3);
const cases3 = [_][]const []const i32{
- [_][]const i32{[_]i32{1}},
+ &[_][]const i32{&[_]i32{1}},
&[_][]const i32{&[_]i32{ two, 3 }},
- [_][]const i32{
- [_]i32{4},
- [_]i32{ 5, 6, 7 },
+ &[_][]const i32{
+ &[_]i32{4},
+ &[_]i32{ 5, 6, 7 },
},
};
- check(cases3);
+ check(&cases3);
}
fn check(cases: []const []const []const i32) void {
@@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" {
test "anonymous list literal syntax" {
const S = struct {
fn doTheTest() void {
- var array: [4]u8 = .{1, 2, 3, 4};
+ var array: [4]u8 = .{ 1, 2, 3, 4 };
expect(array[0] == 1);
expect(array[1] == 2);
expect(array[2] == 3);
@@ -335,8 +335,8 @@ test "anonymous literal in array" {
};
fn doTheTest() void {
var array: [2]Foo = .{
- .{.a = 3},
- .{.b = 3},
+ .{ .a = 3 },
+ .{ .b = 3 },
};
expect(array[0].a == 3);
expect(array[0].b == 4);
@@ -351,7 +351,7 @@ test "anonymous literal in array" {
test "access the null element of a null terminated array" {
const S = struct {
fn doTheTest() void {
- var array: [4:0]u8 = .{'a', 'o', 'e', 'u'};
+ var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
comptime expect(array[4] == 0);
var len: usize = 4;
expect(array[len] == 0);
test/stage1/behavior/async_fn.zig
@@ -143,7 +143,7 @@ test "coroutine suspend, resume" {
resume frame;
seq('h');
- expect(std.mem.eql(u8, points, "abcdefgh"));
+ expect(std.mem.eql(u8, &points, "abcdefgh"));
}
fn amain() void {
@@ -206,7 +206,7 @@ test "coroutine await" {
resume await_a_promise;
await_seq('i');
expect(await_final_result == 1234);
- expect(std.mem.eql(u8, await_points, "abcdefghi"));
+ expect(std.mem.eql(u8, &await_points, "abcdefghi"));
}
async fn await_amain() void {
await_seq('b');
@@ -240,7 +240,7 @@ test "coroutine await early return" {
var p = async early_amain();
early_seq('f');
expect(early_final_result == 1234);
- expect(std.mem.eql(u8, early_points, "abcdef"));
+ expect(std.mem.eql(u8, &early_points, "abcdef"));
}
async fn early_amain() void {
early_seq('b');
@@ -1166,7 +1166,7 @@ test "suspend in for loop" {
}
fn atest() void {
- expect(func([_]u8{ 1, 2, 3 }) == 6);
+ expect(func(&[_]u8{ 1, 2, 3 }) == 6);
}
fn func(stuff: []const u8) u32 {
global_frame = @frame();
@@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" {
fn doTheTest() void {
var foo = Foo{
- .slice = [_]i32{ 1, 2 },
+ .slice = &[_]i32{ 1, 2 },
};
expect(atest(&foo) == 3);
}
@@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" {
fn doTheTest() void {
var foo = Foo{
- .slice = [_]i32{ 1, 2 },
+ .slice = &[_]i32{ 1, 2 },
};
expect(atest(&foo) == 3);
}
test/stage1/behavior/await_struct.zig
@@ -16,7 +16,7 @@ test "coroutine await struct" {
resume await_a_promise;
await_seq('i');
expect(await_final_result.x == 1234);
- expect(std.mem.eql(u8, await_points, "abcdefghi"));
+ expect(std.mem.eql(u8, &await_points, "abcdefghi"));
}
async fn await_amain() void {
await_seq('b');
test/stage1/behavior/cast.zig
@@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" {
}
fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 {
if (a) {
- return [_]u8{};
+ return &[_]u8{};
}
return slice[0..1];
@@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void {
}
fn gimmeErrOrSlice() anyerror![]u8 {
- return [_]u8{};
+ return &[_]u8{};
}
test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
@@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
}
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
if (a) {
- return [_]u8{};
+ return &[_]u8{};
}
return slice[0..1];
@@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void {
test "implicit cast from [*]T to ?*c_void" {
var a = [_]u8{ 3, 2, 1 };
incrementVoidPtrArray(a[0..].ptr, 3);
- expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 }));
+ expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 }));
}
fn incrementVoidPtrArray(array: ?*c_void, len: usize) void {
@@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" {
test "peer resolution of string literals" {
const S = struct {
- const E = extern enum { a, b, c, d};
+ const E = extern enum {
+ a,
+ b,
+ c,
+ d,
+ };
fn doTheTest(e: E) void {
const cmd = switch (e) {
@@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" {
fn doTheTest() void {
// [:x]T to []T
{
- var array = [4:0]i32{1,2,3,4};
+ var array = [4:0]i32{ 1, 2, 3, 4 };
var slice: [:0]i32 = &array;
var dest: []i32 = slice;
- expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
+ expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
}
// [*:x]T to [*]T
{
- var array = [4:99]i32{1,2,3,4};
+ var array = [4:99]i32{ 1, 2, 3, 4 };
var dest: [*]i32 = &array;
expect(dest[0] == 1);
expect(dest[1] == 2);
@@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" {
// [N:x]T to [N]T
{
- var array = [4:0]i32{1,2,3,4};
+ var array = [4:0]i32{ 1, 2, 3, 4 };
var dest: [4]i32 = array;
- expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
+ expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 }));
}
// *[N:x]T to *[N]T
{
- var array = [4:0]i32{1,2,3,4};
+ var array = [4:0]i32{ 1, 2, 3, 4 };
var dest: *[4]i32 = &array;
- expect(mem.eql(i32, dest, &[_]i32{1,2,3,4}));
+ expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 }));
}
// [:x]T to [*:x]T
{
- var array = [4:0]i32{1,2,3,4};
+ var array = [4:0]i32{ 1, 2, 3, 4 };
var slice: [:0]i32 = &array;
var dest: [*:0]i32 = slice;
expect(dest[0] == 1);
@@ -674,3 +679,21 @@ test "type coercion related to sentinel-termination" {
S.doTheTest();
comptime S.doTheTest();
}
+
+test "cast i8 fn call peers to i32 result" {
+ const S = struct {
+ fn doTheTest() void {
+ var cond = true;
+ const value: i32 = if (cond) smallBoi() else bigBoi();
+ expect(value == 123);
+ }
+ fn smallBoi() i8 {
+ return 123;
+ }
+ fn bigBoi() i16 {
+ return 1234;
+ }
+ };
+ S.doTheTest();
+ comptime S.doTheTest();
+}
test/stage1/behavior/eval.zig
@@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" {
};
var b = [1]u8{9};
- var f = @bytesToSlice(F, b);
+ var f = @bytesToSlice(F, &b);
expect(f[0].a == 9);
}
@@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" {
test "array concatenation forces comptime" {
var a = oneItem(3) ++ oneItem(4);
- expect(std.mem.eql(i32, a, [_]i32{ 3, 4 }));
+ expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 }));
}
test "array multiplication forces comptime" {
var a = oneItem(3) ** scalar(2);
- expect(std.mem.eql(i32, a, [_]i32{ 3, 3 }));
+ expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 }));
}
fn oneItem(x: i32) [1]i32 {
test/stage1/behavior/for.zig
@@ -26,7 +26,7 @@ test "for loop with pointer elem var" {
var target: [source.len]u8 = undefined;
mem.copy(u8, target[0..], source);
mangleString(target[0..]);
- expect(mem.eql(u8, target, "bcdefgh"));
+ expect(mem.eql(u8, &target, "bcdefgh"));
for (source) |*c, i|
expect(@typeOf(c) == *const u8);
@@ -64,7 +64,7 @@ test "basic for loop" {
buffer[buf_index] = @intCast(u8, index);
buf_index += 1;
}
- const unknown_size: []const u8 = array;
+ const unknown_size: []const u8 = &array;
for (unknown_size) |item| {
buffer[buf_index] = item;
buf_index += 1;
@@ -74,7 +74,7 @@ test "basic for loop" {
buf_index += 1;
}
- expect(mem.eql(u8, buffer[0..buf_index], expected_result));
+ expect(mem.eql(u8, buffer[0..buf_index], &expected_result));
}
test "break from outer for loop" {
@@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" {
}
}
};
- S.doTheTest([_]u8{ 1, 2 });
- comptime S.doTheTest([_]u8{ 1, 2 });
+ S.doTheTest(&[_]u8{ 1, 2 });
+ comptime S.doTheTest(&[_]u8{ 1, 2 });
}
test/stage1/behavior/generics.zig
@@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T {
}
test "generic fn with implicit cast" {
- expect(getFirstByte(u8, [_]u8{13}) == 13);
- expect(getFirstByte(u16, [_]u16{
+ expect(getFirstByte(u8, &[_]u8{13}) == 13);
+ expect(getFirstByte(u16, &[_]u16{
0,
13,
}) == 0);
test/stage1/behavior/misc.zig
@@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {}
test "cast undefined" {
const array: [100]u8 = undefined;
- const slice = @as([]const u8, array);
+ const slice = @as([]const u8, &array);
testCastUndefined(slice);
}
fn testCastUndefined(x: []const u8) void {}
@@ -614,7 +614,7 @@ test "slicing zero length array" {
expect(s1.len == 0);
expect(s2.len == 0);
expect(mem.eql(u8, s1, ""));
- expect(mem.eql(u32, s2, [_]u32{}));
+ expect(mem.eql(u32, s2, &[_]u32{}));
}
const addr1 = @ptrCast(*const u8, emptyFn);
@@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic
const E = struct {
entries: []u32,
};
- var foo = E{ .entries = [_]u32{} };
+ var foo = E{ .entries = &[_]u32{} };
expect(foo.entries.len == 0);
}
test/stage1/behavior/ptrcast.zig
@@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void {
test "reinterpret struct field at comptime" {
const numLittle = comptime Bytes.init(0x12345678);
- expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes));
+ expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes));
}
const Bytes = struct {
test/stage1/behavior/shuffle.zig
@@ -9,28 +9,28 @@ test "@shuffle" {
var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) };
var res = @shuffle(i32, v, x, mask);
- expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
+ expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
// Implicit cast from array (of mask)
res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) });
- expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 }));
+ expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 }));
// Undefined
const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 };
res = @shuffle(i32, v, undefined, mask2);
- expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 }));
+ expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 }));
// Upcasting of b
var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined };
const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 };
res = @shuffle(i32, x, v2, mask3);
- expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 }));
+ expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 }));
// Upcasting of a
var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 };
const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) };
res = @shuffle(i32, v3, x, mask4);
- expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 }));
+ expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 }));
// bool
// Disabled because of #3317
@@ -39,7 +39,7 @@ test "@shuffle" {
var v4: @Vector(2, bool) = [2]bool{ true, false };
const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
var res2 = @shuffle(bool, x2, v4, mask5);
- expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
+ expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
}
// TODO re-enable when LLVM codegen is fixed
@@ -49,7 +49,7 @@ test "@shuffle" {
var v4: @Vector(2, bool) = [2]bool{ true, false };
const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 };
var res2 = @shuffle(bool, x2, v4, mask5);
- expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false }));
+ expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false }));
}
}
};
test/stage1/behavior/slice.zig
@@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 {
test "implicitly cast array of size 0 to slice" {
var msg = [_]u8{};
- assertLenIsZero(msg);
+ assertLenIsZero(&msg);
}
fn assertLenIsZero(msg: []const u8) void {
@@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 {
}
test "comptime slices are disambiguated" {
- expect(sliceSum([_]u8{ 1, 2 }) == 3);
- expect(sliceSum([_]u8{ 3, 4 }) == 7);
+ expect(sliceSum(&[_]u8{ 1, 2 }) == 3);
+ expect(sliceSum(&[_]u8{ 3, 4 }) == 7);
}
test "slice type with custom alignment" {
test/stage1/behavior/struct.zig
@@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 {
}
test "pass slice of empty struct to fn" {
- expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1);
+ expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1);
}
fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize {
return slice.len;
@@ -432,7 +432,7 @@ const Expr = union(enum) {
};
fn alloc(comptime T: type) []T {
- return [_]T{};
+ return &[_]T{};
}
test "call method with mutable reference to struct with no fields" {
@@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" {
.a = true,
.b = "abcdefghijklmnopqurstu".*,
};
- bar(foo.b);
+ const value = foo.b;
+ bar(&value);
}
};
S.doTheTest();
@@ -783,7 +784,7 @@ test "struct with var field" {
x: var,
y: var,
};
- const pt = Point {
+ const pt = Point{
.x = 1,
.y = 2,
};
test/stage1/behavior/struct_contains_slice_of_itself.zig
@@ -14,21 +14,21 @@ test "struct contains slice of itself" {
var other_nodes = [_]Node{
Node{
.payload = 31,
- .children = [_]Node{},
+ .children = &[_]Node{},
},
Node{
.payload = 32,
- .children = [_]Node{},
+ .children = &[_]Node{},
},
};
var nodes = [_]Node{
Node{
.payload = 1,
- .children = [_]Node{},
+ .children = &[_]Node{},
},
Node{
.payload = 2,
- .children = [_]Node{},
+ .children = &[_]Node{},
},
Node{
.payload = 3,
@@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" {
var other_nodes = [_]NodeAligned{
NodeAligned{
.payload = 31,
- .children = [_]NodeAligned{},
+ .children = &[_]NodeAligned{},
},
NodeAligned{
.payload = 32,
- .children = [_]NodeAligned{},
+ .children = &[_]NodeAligned{},
},
};
var nodes = [_]NodeAligned{
NodeAligned{
.payload = 1,
- .children = [_]NodeAligned{},
+ .children = &[_]NodeAligned{},
},
NodeAligned{
.payload = 2,
- .children = [_]NodeAligned{},
+ .children = &[_]NodeAligned{},
},
NodeAligned{
.payload = 3,
test/stage1/behavior/type.zig
@@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void {
test "Type.MetaType" {
testing.expect(type == @Type(TypeInfo{ .Type = undefined }));
- testTypes([_]type{type});
+ testTypes(&[_]type{type});
}
test "Type.Void" {
testing.expect(void == @Type(TypeInfo{ .Void = undefined }));
- testTypes([_]type{void});
+ testTypes(&[_]type{void});
}
test "Type.Bool" {
testing.expect(bool == @Type(TypeInfo{ .Bool = undefined }));
- testTypes([_]type{bool});
+ testTypes(&[_]type{bool});
}
test "Type.NoReturn" {
testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined }));
- testTypes([_]type{noreturn});
+ testTypes(&[_]type{noreturn});
}
test "Type.Int" {
@@ -37,7 +37,7 @@ test "Type.Int" {
testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));
testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));
testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));
- testTypes([_]type{ u8, u32, i64 });
+ testTypes(&[_]type{ u8, u32, i64 });
}
test "Type.Float" {
@@ -45,11 +45,11 @@ test "Type.Float" {
testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } }));
testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } }));
testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } }));
- testTypes([_]type{ f16, f32, f64, f128 });
+ testTypes(&[_]type{ f16, f32, f64, f128 });
}
test "Type.Pointer" {
- testTypes([_]type{
+ testTypes(&[_]type{
// One Value Pointer Types
*u8, *const u8,
*volatile u8, *const volatile u8,
@@ -115,18 +115,18 @@ test "Type.Array" {
.sentinel = 0,
},
}));
- testTypes([_]type{ [1]u8, [30]usize, [7]bool });
+ testTypes(&[_]type{ [1]u8, [30]usize, [7]bool });
}
test "Type.ComptimeFloat" {
- testTypes([_]type{comptime_float});
+ testTypes(&[_]type{comptime_float});
}
test "Type.ComptimeInt" {
- testTypes([_]type{comptime_int});
+ testTypes(&[_]type{comptime_int});
}
test "Type.Undefined" {
- testTypes([_]type{@typeOf(undefined)});
+ testTypes(&[_]type{@typeOf(undefined)});
}
test "Type.Null" {
- testTypes([_]type{@typeOf(null)});
+ testTypes(&[_]type{@typeOf(null)});
}
test/stage1/behavior/union.zig
@@ -241,7 +241,7 @@ pub const PackThis = union(enum) {
};
test "constant packed union" {
- testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }});
+ testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }});
}
fn testConstPackedUnion(expected_tokens: []const PackThis) void {
test/stage1/behavior/vector.zig
@@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" {
fn doTheTest() void {
const a: @Vector(4, bool) = [_]bool{ true, false, true, false };
const result_array: [4]bool = a;
- expect(mem.eql(bool, result_array, [4]bool{ true, false, true, false }));
+ expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false }));
}
};
S.doTheTest();
@@ -20,11 +20,11 @@ test "vector wrap operators" {
fn doTheTest() void {
var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 };
- expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 }));
- expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 }));
- expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 }));
+ expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 }));
+ expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 }));
+ expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 }));
var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 };
- expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 }));
+ expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 }));
}
};
S.doTheTest();
@@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" {
fn doTheTest() void {
var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 };
var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 };
- expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false }));
- expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true }));
- expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false }));
- expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true }));
- expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false }));
- expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true }));
+ expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false }));
+ expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true }));
+ expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false }));
+ expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true }));
+ expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false }));
+ expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true }));
}
};
S.doTheTest();
@@ -53,10 +53,10 @@ test "vector int operators" {
fn doTheTest() void {
var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 };
var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 };
- expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 }));
- expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 }));
- expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 }));
- expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 }));
+ expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 }));
+ expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 }));
+ expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 }));
+ expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 }));
}
};
S.doTheTest();
@@ -68,10 +68,10 @@ test "vector float operators" {
fn doTheTest() void {
var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 };
var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 };
- expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 }));
- expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 }));
- expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 }));
- expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 }));
+ expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 }));
+ expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 }));
+ expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 }));
+ expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 }));
}
};
S.doTheTest();
@@ -83,9 +83,9 @@ test "vector bit operators" {
fn doTheTest() void {
var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 };
var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 };
- expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
- expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
- expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
+ expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 }));
+ expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 }));
+ expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 }));
}
};
S.doTheTest();
@@ -98,7 +98,7 @@ test "implicit cast vector to array" {
var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
var result_array: [4]i32 = a;
result_array = a;
- expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 }));
+ expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 }));
}
};
S.doTheTest();
@@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" {
{
var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 };
var x: [4]u3 = v;
- expect(mem.eql(u3, x, @as([4]u3, v)));
+ expect(mem.eql(u3, &x, &@as([4]u3, v)));
}
{
var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 };
var x: [4]u2 = v;
- expect(mem.eql(u2, x, @as([4]u2, v)));
+ expect(mem.eql(u2, &x, &@as([4]u2, v)));
}
{
var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 };
var x: [4]u1 = v;
- expect(mem.eql(u1, x, @as([4]u1, v)));
+ expect(mem.eql(u1, &x, &@as([4]u1, v)));
}
{
var v: @Vector(4, bool) = [4]bool{ false, false, true, false };
var x: [4]bool = v;
- expect(mem.eql(bool, x, @as([4]bool, v)));
+ expect(mem.eql(bool, &x, &@as([4]bool, v)));
}
}
};
test/compare_output.zig
@@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\
);
- tc.setCommandLineArgs([_][]const u8{
+ tc.setCommandLineArgs(&[_][]const u8{
"first arg",
"'a' 'b' \\",
"bare",
@@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\
);
- tc.setCommandLineArgs([_][]const u8{
+ tc.setCommandLineArgs(&[_][]const u8{
"first arg",
"'a' 'b' \\",
"bare",
test/tests.zig
@@ -325,7 +325,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M
const exe = b.addExecutable("test-cli", "test/cli.zig");
const run_cmd = exe.run();
- run_cmd.addArgs([_][]const u8{
+ run_cmd.addArgs(&[_][]const u8{
fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable,
b.pathFromRoot(b.cache_root),
});
@@ -411,7 +411,7 @@ pub fn addPkgTests(
const ArchTag = @TagType(builtin.Arch);
if (test_target.disable_native and
test_target.target.getOs() == builtin.os and
- @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch))
+ @as(ArchTag, test_target.target.getArch()) == @as(ArchTag, builtin.arch))
{
continue;
}
@@ -429,7 +429,7 @@ pub fn addPkgTests(
"bare";
const triple_prefix = if (test_target.target == .Native)
- @as([]const u8,"native")
+ @as([]const u8, "native")
else
test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable;
@@ -626,7 +626,7 @@ pub const CompareOutputContext = struct {
warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
- const child = std.ChildProcess.init([_][]const u8{full_exe_path}, b.allocator) catch unreachable;
+ const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable;
defer child.deinit();
child.env_map = b.env_map;
@@ -667,7 +667,7 @@ pub const CompareOutputContext = struct {
.expected_output = expected_output,
.link_libc = false,
.special = special,
- .cli_args = [_][]const u8{},
+ .cli_args = &[_][]const u8{},
};
const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
tc.addSourceFile(root_src_name, source);
@@ -704,7 +704,7 @@ pub const CompareOutputContext = struct {
const root_src = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, case.sources.items[0].filename },
+ &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
) catch unreachable;
switch (case.special) {
@@ -720,7 +720,7 @@ pub const CompareOutputContext = struct {
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, src_file.filename },
+ &[_][]const u8{ b.cache_root, src_file.filename },
) catch unreachable;
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
exe.step.dependOn(&write_src.step);
@@ -752,7 +752,7 @@ pub const CompareOutputContext = struct {
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, src_file.filename },
+ &[_][]const u8{ b.cache_root, src_file.filename },
) catch unreachable;
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
exe.step.dependOn(&write_src.step);
@@ -783,7 +783,7 @@ pub const CompareOutputContext = struct {
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, src_file.filename },
+ &[_][]const u8{ b.cache_root, src_file.filename },
) catch unreachable;
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
exe.step.dependOn(&write_src.step);
@@ -816,7 +816,7 @@ pub const StackTracesContext = struct {
const source_pathname = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, "source.zig" },
+ &[_][]const u8{ b.cache_root, "source.zig" },
) catch unreachable;
for (self.modes) |mode| {
@@ -1073,7 +1073,7 @@ pub const CompileErrorContext = struct {
const root_src = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
+ &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
) catch unreachable;
var zig_args = ArrayList([]const u8).init(b.allocator);
@@ -1270,7 +1270,7 @@ pub const CompileErrorContext = struct {
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, src_file.filename },
+ &[_][]const u8{ b.cache_root, src_file.filename },
) catch unreachable;
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
compile_and_cmp_errors.step.dependOn(&write_src.step);
@@ -1404,7 +1404,7 @@ pub const TranslateCContext = struct {
const root_src = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
+ &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename },
) catch unreachable;
var zig_args = ArrayList([]const u8).init(b.allocator);
@@ -1577,7 +1577,7 @@ pub const TranslateCContext = struct {
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, src_file.filename },
+ &[_][]const u8{ b.cache_root, src_file.filename },
) catch unreachable;
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
translate_c_and_cmp.step.dependOn(&write_src.step);
@@ -1700,7 +1700,7 @@ pub const GenHContext = struct {
const b = self.b;
const root_src = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, case.sources.items[0].filename },
+ &[_][]const u8{ b.cache_root, case.sources.items[0].filename },
) catch unreachable;
const mode = builtin.Mode.Debug;
@@ -1715,7 +1715,7 @@ pub const GenHContext = struct {
for (case.sources.toSliceConst()) |src_file| {
const expanded_src_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, src_file.filename },
+ &[_][]const u8{ b.cache_root, src_file.filename },
) catch unreachable;
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
obj.step.dependOn(&write_src.step);
build.zig
@@ -20,10 +20,10 @@ pub fn build(b: *Builder) !void {
const rel_zig_exe = try fs.path.relative(b.allocator, b.build_root, b.zig_exe);
const langref_out_path = fs.path.join(
b.allocator,
- [_][]const u8{ b.cache_root, "langref.html" },
+ &[_][]const u8{ b.cache_root, "langref.html" },
) catch unreachable;
var docgen_cmd = docgen_exe.run();
- docgen_cmd.addArgs([_][]const u8{
+ docgen_cmd.addArgs(&[_][]const u8{
rel_zig_exe,
"doc" ++ fs.path.sep_str ++ "langref.html.in",
langref_out_path,
@@ -36,7 +36,7 @@ pub fn build(b: *Builder) !void {
const test_step = b.step("test", "Run all the tests");
// find the stage0 build artifacts because we're going to re-use config.h and zig_cpp library
- const build_info = try b.exec([_][]const u8{
+ const build_info = try b.exec(&[_][]const u8{
b.zig_exe,
"BUILD_INFO",
});
@@ -56,7 +56,7 @@ pub fn build(b: *Builder) !void {
test_stage2.setBuildMode(builtin.Mode.Debug);
test_stage2.addPackagePath("stage2_tests", "test/stage2/test.zig");
- const fmt_build_zig = b.addFmt([_][]const u8{"build.zig"});
+ const fmt_build_zig = b.addFmt(&[_][]const u8{"build.zig"});
var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
exe.setBuildMode(mode);
@@ -88,7 +88,7 @@ pub fn build(b: *Builder) !void {
.source_dir = "lib",
.install_dir = .Lib,
.install_subdir = "zig",
- .exclude_extensions = [_][]const u8{ "test.zig", "README.md" },
+ .exclude_extensions = &[_][]const u8{ "test.zig", "README.md" },
});
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 {
}
const lib_dir = fs.path.join(
b.allocator,
- [_][]const u8{ dep.prefix, "lib" },
+ &[_][]const u8{ dep.prefix, "lib" },
) catch unreachable;
for (dep.system_libs.toSliceConst()) |lib| {
const static_bare_name = if (mem.eql(u8, lib, "curses"))
@@ -157,7 +157,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
b.fmt("lib{}.a", lib);
const static_lib_name = fs.path.join(
b.allocator,
- [_][]const u8{ lib_dir, static_bare_name },
+ &[_][]const u8{ lib_dir, static_bare_name },
) catch unreachable;
const have_static = fileExists(static_lib_name) catch unreachable;
if (have_static) {
@@ -183,7 +183,7 @@ fn fileExists(filename: []const u8) !bool {
}
fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
- lib_exe_obj.addObjectFile(fs.path.join(b.allocator, [_][]const u8{
+ lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cmake_binary_dir,
"zig_cpp",
b.fmt("{}{}{}", lib_exe_obj.target.libPrefix(), lib_name, lib_exe_obj.target.staticLibSuffix()),
@@ -199,22 +199,22 @@ const LibraryDep = struct {
};
fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
- const shared_mode = try b.exec([_][]const u8{ llvm_config_exe, "--shared-mode" });
+ const shared_mode = try b.exec(&[_][]const u8{ llvm_config_exe, "--shared-mode" });
const is_static = mem.startsWith(u8, shared_mode, "static");
const libs_output = if (is_static)
- try b.exec([_][]const u8{
+ try b.exec(&[_][]const u8{
llvm_config_exe,
"--libfiles",
"--system-libs",
})
else
- try b.exec([_][]const u8{
+ try b.exec(&[_][]const u8{
llvm_config_exe,
"--libs",
});
- const includes_output = try b.exec([_][]const u8{ llvm_config_exe, "--includedir" });
- const libdir_output = try b.exec([_][]const u8{ llvm_config_exe, "--libdir" });
- const prefix_output = try b.exec([_][]const u8{ llvm_config_exe, "--prefix" });
+ const includes_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--includedir" });
+ const libdir_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--libdir" });
+ const prefix_output = try b.exec(&[_][]const u8{ llvm_config_exe, "--prefix" });
var result = LibraryDep{
.prefix = mem.tokenize(prefix_output, " \r\n").next().?,
@@ -341,7 +341,7 @@ fn addCxxKnownPath(
objname: []const u8,
errtxt: ?[]const u8,
) !void {
- const path_padded = try b.exec([_][]const u8{
+ const path_padded = try b.exec(&[_][]const u8{
ctx.cxx_compiler,
b.fmt("-print-file-name={}", objname),
});