authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-30 23:13:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-30 23:13:17-07:00
logdc28f5c3ec61a525d45d9f07a666e62f6598ed0a
tree45daf6a6a98bc0828412fd807eebd2e84e34511a
parent351b57497b1cf2ea6ee72a3c7cfdb84b924bb368
parent557eb414eee96201d1ae01b15ebf8955eca1da6d

Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen

Conflicts: lib/std/crypto/25519/field.zig lib/std/crypto/poly1305.zig I had resolved those by removing `comptime` but master branch decided to make the parameters `comptime`. This also pulls in the updated default `zig build` install directory.

10 files changed, 66 insertions(+), 13 deletions(-)

.gitignore+1
...@@ -10,6 +10,7 @@...@@ -10,6 +10,7 @@
10# -andrewrk10# -andrewrk
1111
12zig-cache/12zig-cache/
13zig-out/
13/release/14/release/
14/debug/15/debug/
15/build/16/build/
BRANCH_TODO+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1 * decouple AstGen from Module, Compilation
2 * modify dbg_stmt ZIR instructions to have line/column rather than node indexes1 * modify dbg_stmt ZIR instructions to have line/column rather than node indexes
2 * decouple AstGen from Module, Compilation
3 * AstGen threadlocal3 * AstGen threadlocal
4 * extern "foo" for vars and for functions4 * extern "foo" for vars and for functions
5 * namespace decls table can't reference ZIR memory because it can get modified on updates5 * namespace decls table can't reference ZIR memory because it can get modified on updates
doc/langref.html.in+32-1
...@@ -2861,6 +2861,37 @@ fn dump(args: anytype) void {...@@ -2861,6 +2861,37 @@ fn dump(args: anytype) void {
2861 expect(args.b);2861 expect(args.b);
2862 expect(args.s[0] == 'h');2862 expect(args.s[0] == 'h');
2863 expect(args.s[1] == 'i');2863 expect(args.s[1] == 'i');
2864}
2865 {#code_end#}
2866 <p>
2867 Anonymous structs can be created without specifying field names, and are referred to as "tuples".
2868 </p>
2869 <p>
2870 The fields are implicitly named using numbers starting from 0. Because their names are integers,
2871 the {#syntax#}@"0"{#endsyntax#} syntax must be used to access them. Names inside {#syntax#}@""{#endsyntax#} are always recognised as identifiers.
2872 </p>
2873 <p>
2874 Like arrays, tuples have a .len field, can be indexed and work with the ++ and ** operators. They can also be iterated over with {#link|inline for#}.
2875 </p>
2876 {#code_begin|test|tuple#}
2877const std = @import("std");
2878const expect = std.testing.expect;
2879
2880test "tuple" {
2881 const values = .{
2882 @as(u32, 1234),
2883 @as(f64, 12.34),
2884 true,
2885 "hi",
2886 } ++ .{false} ** 2;
2887 expect(values[0] == 1234);
2888 expect(values[4] == false);
2889 inline for (values) |v, i| {
2890 if (i != 2) continue;
2891 expect(v);
2892 }
2893 expect(values.len == 6);
2894 expect(values.@"3"[0] == 'h');
2864}2895}
2865 {#code_end#}2896 {#code_end#}
2866 {#header_close#}2897 {#header_close#}
...@@ -9997,7 +10028,7 @@ pub fn build(b: *Builder) void {...@@ -9997,7 +10028,7 @@ pub fn build(b: *Builder) void {
9997 {#code_end#}10028 {#code_end#}
9998 <p class="file">terminal</p>10029 <p class="file">terminal</p>
9999 <pre><code class="shell">$ zig build10030 <pre><code class="shell">$ zig build
10000$ ./zig-cache/bin/test10031$ ./zig-out/bin/test
10001all your base are belong to us</code></pre>10032all your base are belong to us</code></pre>
10002 {#see_also|Targets|Zig Build System#}10033 {#see_also|Targets|Zig Build System#}
10003 {#header_close#}10034 {#header_close#}
lib/std/build.zig+2-1
...@@ -195,7 +195,8 @@ pub const Builder = struct {...@@ -195,7 +195,8 @@ pub const Builder = struct {
195 self.install_prefix = install_prefix orelse "/usr";195 self.install_prefix = install_prefix orelse "/usr";
196 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;196 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;
197 } else {197 } else {
198 self.install_prefix = install_prefix orelse self.cache_root;198 self.install_prefix = install_prefix orelse
199 (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
199 self.install_path = self.install_prefix;200 self.install_path = self.install_prefix;
200 }201 }
201 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;202 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
lib/std/compress/deflate.zig+18
...@@ -384,6 +384,8 @@ pub fn InflateStream(comptime ReaderType: type) type {...@@ -384,6 +384,8 @@ pub fn InflateStream(comptime ReaderType: type) type {
384 const last_length = lengths[i - 1];384 const last_length = lengths[i - 1];
385 const repeat = 3 + (try self.readBits(2));385 const repeat = 3 + (try self.readBits(2));
386 const last_index = i + repeat;386 const last_index = i + repeat;
387 if (last_index > lengths.len)
388 return error.InvalidLength;
387 while (i < last_index) : (i += 1) {389 while (i < last_index) : (i += 1) {
388 lengths[i] = last_length;390 lengths[i] = last_length;
389 }391 }
...@@ -655,3 +657,19 @@ pub fn InflateStream(comptime ReaderType: type) type {...@@ -655,3 +657,19 @@ pub fn InflateStream(comptime ReaderType: type) type {
655pub fn inflateStream(reader: anytype, window_slice: []u8) InflateStream(@TypeOf(reader)) {657pub fn inflateStream(reader: anytype, window_slice: []u8) InflateStream(@TypeOf(reader)) {
656 return InflateStream(@TypeOf(reader)).init(reader, window_slice);658 return InflateStream(@TypeOf(reader)).init(reader, window_slice);
657}659}
660
661test "lengths overflow" {
662 // malformed final dynamic block, tries to write 321 code lengths (MAXCODES is 316)
663 // f dy hlit hdist hclen 16 17 18 0 (18) x138 (18) x138 (18) x39 (16) x6
664 // 1 10 11101 11101 0000 010 010 010 010 (11) 1111111 (11) 1111111 (11) 0011100 (01) 11
665 const stream = [_]u8{
666 0b11101101, 0b00011101, 0b00100100, 0b11101001, 0b11111111, 0b11111111, 0b00111001, 0b00001110
667 };
668
669 const reader = std.io.fixedBufferStream(&stream).reader();
670 var window: [0x8000]u8 = undefined;
671 var inflate = inflateStream(reader, &window);
672
673 var buf: [1]u8 = undefined;
674 std.testing.expectError(error.InvalidLength, inflate.read(&buf));
675}
lib/std/crypto/25519/field.zig+1-1
...@@ -292,7 +292,7 @@ pub const Fe = struct {...@@ -292,7 +292,7 @@ pub const Fe = struct {
292 return _carry128(&r);292 return _carry128(&r);
293 }293 }
294294
295 fn _sq(a: Fe, double: bool) callconv(.Inline) Fe {295 fn _sq(a: Fe, comptime double: bool) callconv(.Inline) Fe {
296 var ax: [5]u128 = undefined;296 var ax: [5]u128 = undefined;
297 var r: [5]u128 = undefined;297 var r: [5]u128 = undefined;
298 comptime var i = 0;298 comptime var i = 0;
lib/std/crypto/poly1305.zig+1-1
...@@ -39,7 +39,7 @@ pub const Poly1305 = struct {...@@ -39,7 +39,7 @@ pub const Poly1305 = struct {
39 };39 };
40 }40 }
4141
42 fn blocks(st: *Poly1305, m: []const u8, last: bool) void {42 fn blocks(st: *Poly1305, m: []const u8, comptime last: bool) void {
43 const hibit: u64 = if (last) 0 else 1 << 40;43 const hibit: u64 = if (last) 0 else 1 << 40;
44 const r0 = st.r[0];44 const r0 = st.r[0];
45 const r1 = st.r[1];45 const r1 = st.r[1];
lib/std/os.zig+6-4
...@@ -1049,7 +1049,7 @@ pub const OpenError = error{...@@ -1049,7 +1049,7 @@ pub const OpenError = error{
1049} || UnexpectedError;1049} || UnexpectedError;
10501050
1051/// Open and possibly create a file. Keeps trying if it gets interrupted.1051/// Open and possibly create a file. Keeps trying if it gets interrupted.
1052/// See also `openC`.1052/// See also `openZ`.
1053pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {1053pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {
1054 if (std.Target.current.os.tag == .windows) {1054 if (std.Target.current.os.tag == .windows) {
1055 const file_path_w = try windows.sliceToPrefixedFileW(file_path);1055 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
...@@ -1147,7 +1147,7 @@ pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t...@@ -1147,7 +1147,7 @@ pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t
11471147
1148/// Open and possibly create a file. Keeps trying if it gets interrupted.1148/// Open and possibly create a file. Keeps trying if it gets interrupted.
1149/// `file_path` is relative to the open directory handle `dir_fd`.1149/// `file_path` is relative to the open directory handle `dir_fd`.
1150/// See also `openatC`.1150/// See also `openatZ`.
1151pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t {1151pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t {
1152 if (builtin.os.tag == .wasi) {1152 if (builtin.os.tag == .wasi) {
1153 @compileError("use openatWasi instead");1153 @compileError("use openatWasi instead");
...@@ -1754,7 +1754,7 @@ pub const UnlinkError = error{...@@ -1754,7 +1754,7 @@ pub const UnlinkError = error{
1754} || UnexpectedError;1754} || UnexpectedError;
17551755
1756/// Delete a name and possibly the file it refers to.1756/// Delete a name and possibly the file it refers to.
1757/// See also `unlinkC`.1757/// See also `unlinkZ`.
1758pub fn unlink(file_path: []const u8) UnlinkError!void {1758pub fn unlink(file_path: []const u8) UnlinkError!void {
1759 if (builtin.os.tag == .wasi) {1759 if (builtin.os.tag == .wasi) {
1760 @compileError("unlink is not supported in WASI; use unlinkat instead");1760 @compileError("unlink is not supported in WASI; use unlinkat instead");
...@@ -3419,7 +3419,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {...@@ -3419,7 +3419,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
3419 }3419 }
3420}3420}
34213421
3422pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound };3422pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound, SymLinkLoop };
34233423
3424/// Similar to `fstat`, but returns stat of a resource pointed to by `pathname`3424/// Similar to `fstat`, but returns stat of a resource pointed to by `pathname`
3425/// which is relative to `dirfd` handle.3425/// which is relative to `dirfd` handle.
...@@ -3466,8 +3466,10 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S...@@ -3466,8 +3466,10 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
3466 EBADF => unreachable, // Always a race condition.3466 EBADF => unreachable, // Always a race condition.
3467 ENOMEM => return error.SystemResources,3467 ENOMEM => return error.SystemResources,
3468 EACCES => return error.AccessDenied,3468 EACCES => return error.AccessDenied,
3469 EPERM => return error.AccessDenied,
3469 EFAULT => unreachable,3470 EFAULT => unreachable,
3470 ENAMETOOLONG => return error.NameTooLong,3471 ENAMETOOLONG => return error.NameTooLong,
3472 ELOOP => return error.SymLinkLoop,
3471 ENOENT => return error.FileNotFound,3473 ENOENT => return error.FileNotFound,
3472 ENOTDIR => return error.FileNotFound,3474 ENOTDIR => return error.FileNotFound,
3473 else => |err| return unexpectedErrno(err),3475 else => |err| return unexpectedErrno(err),
lib/std/special/build_runner.zig+3-3
...@@ -82,9 +82,9 @@ pub fn main() !void {...@@ -82,9 +82,9 @@ pub fn main() !void {
82 builder.verbose = true;82 builder.verbose = true;
83 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {83 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
84 return usage(builder, false, stdout_stream);84 return usage(builder, false, stdout_stream);
85 } else if (mem.eql(u8, arg, "--prefix")) {85 } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
86 install_prefix = nextArg(args, &arg_idx) orelse {86 install_prefix = nextArg(args, &arg_idx) orelse {
87 warn("Expected argument after --prefix\n\n", .{});87 warn("Expected argument after {s}\n\n", .{arg});
88 return usageAndErr(builder, false, stderr_stream);88 return usageAndErr(builder, false, stderr_stream);
89 };89 };
90 } else if (mem.eql(u8, arg, "--search-prefix")) {90 } else if (mem.eql(u8, arg, "--search-prefix")) {
...@@ -188,7 +188,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void...@@ -188,7 +188,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
188 \\General Options:188 \\General Options:
189 \\ -h, --help Print this help and exit189 \\ -h, --help Print this help and exit
190 \\ --verbose Print commands before executing them190 \\ --verbose Print commands before executing them
191 \\ --prefix [path] Override default install prefix191 \\ -p, --prefix [path] Override default install prefix
192 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers192 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
193 \\ --color [auto|off|on] Enable or disable colored error messages193 \\ --color [auto|off|on] Enable or disable colored error messages
194 \\194 \\
src/main.zig+1-1
...@@ -687,7 +687,7 @@ fn buildOutputType(...@@ -687,7 +687,7 @@ fn buildOutputType(
687 extra_cflags.shrinkRetainingCapacity(0);687 extra_cflags.shrinkRetainingCapacity(0);
688 while (true) {688 while (true) {
689 i += 1;689 i += 1;
690 if (i + 1 >= args.len) fatal("expected -- after -cflags", .{});690 if (i >= args.len) fatal("expected -- after -cflags", .{});
691 if (mem.eql(u8, args[i], "--")) break;691 if (mem.eql(u8, args[i], "--")) break;
692 try extra_cflags.append(args[i]);692 try extra_cflags.append(args[i]);
693 }693 }