authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-11 22:04:38+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-12 00:54:07+03:00
logbe1507a7afe4c8869abdbab67a32ede6afe3d938
tree88be868d2b791d3bd7ab5cbd479b11066ece55d2
parent3e095d8ef32fc93f5050cead708849846d626d1d
signaturelock-open Commit is signed but in an unrecognized format.

update compile error tests and some doc comments


8 files changed, 56 insertions(+), 51 deletions(-)

doc/docgen.zig+6-5
......@@ -212,7 +212,7 @@ const Tokenizer = struct {
212212 }
213213};
214214
215fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: var) anyerror {
215fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: anytype) anyerror {
216216 const loc = tokenizer.getTokenLocation(token);
217217 const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 };
218218 warn("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args);
......@@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
634634 return buf.toOwnedSlice();
635635}
636636
637fn writeEscaped(out: var, input: []const u8) !void {
637fn writeEscaped(out: anytype, input: []const u8) !void {
638638 for (input) |c| {
639639 try switch (c) {
640640 '&' => out.writeAll("&amp;"),
......@@ -765,7 +765,7 @@ fn isType(name: []const u8) bool {
765765 return false;
766766}
767767
768fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Token, raw_src: []const u8) !void {
768fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token, raw_src: []const u8) !void {
769769 const src = mem.trim(u8, raw_src, " \n");
770770 try out.writeAll("<code class=\"zig\">");
771771 var tokenizer = std.zig.Tokenizer.init(src);
......@@ -825,6 +825,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
825825 .Keyword_volatile,
826826 .Keyword_allowzero,
827827 .Keyword_while,
828 .Keyword_anytype,
828829 => {
829830 try out.writeAll("<span class=\"tok-kw\">");
830831 try writeEscaped(out, src[token.loc.start..token.loc.end]);
......@@ -977,12 +978,12 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
977978 try out.writeAll("</code>");
978979}
979980
980fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token) !void {
981fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token) !void {
981982 const raw_src = docgen_tokenizer.buffer[source_token.start..source_token.end];
982983 return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src);
983984}
984985
985fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
986fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8) !void {
986987 var code_progress_index: usize = 0;
987988
988989 var env_map = try process.getEnvMap(allocator);
lib/std/fmt.zig+1-1
......@@ -69,7 +69,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
6969///
7070/// If a formatted user type contains a function of the type
7171/// ```
72/// pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: var) !void
72/// pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void
7373/// ```
7474/// with `?` being the type formatted, this function will be called instead of the default implementation.
7575/// This allows user types to be formatted in a logical manner instead of dumping all fields of the type.
lib/std/io/serialization.zig+26-22
......@@ -16,14 +16,16 @@ pub const Packing = enum {
1616};
1717
1818/// Creates a deserializer that deserializes types from any stream.
19/// If `is_packed` is true, the data stream is treated as bit-packed,
20/// otherwise data is expected to be packed to the smallest byte.
21/// Types may implement a custom deserialization routine with a
22/// function named `deserialize` in the form of:
23/// pub fn deserialize(self: *Self, deserializer: var) !void
24/// which will be called when the deserializer is used to deserialize
25/// that type. It will pass a pointer to the type instance to deserialize
26/// into and a pointer to the deserializer struct.
19/// If `is_packed` is true, the data stream is treated as bit-packed,
20/// otherwise data is expected to be packed to the smallest byte.
21/// Types may implement a custom deserialization routine with a
22/// function named `deserialize` in the form of:
23/// ```
24/// pub fn deserialize(self: *Self, deserializer: anytype) !void
25/// ```
26/// which will be called when the deserializer is used to deserialize
27/// that type. It will pass a pointer to the type instance to deserialize
28/// into and a pointer to the deserializer struct.
2729pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime ReaderType: type) type {
2830 return struct {
2931 in_stream: if (packing == .Bit) io.BitReader(endian, ReaderType) else ReaderType,
......@@ -108,7 +110,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
108110 const C = comptime meta.Child(T);
109111 const child_type_id = @typeInfo(C);
110112
111 //custom deserializer: fn(self: *Self, deserializer: var) !void
113 //custom deserializer: fn(self: *Self, deserializer: anytype) !void
112114 if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self);
113115
114116 if (comptime trait.isPacked(C) and packing != .Bit) {
......@@ -196,18 +198,20 @@ pub fn deserializer(
196198}
197199
198200/// Creates a serializer that serializes types to any stream.
199/// If `is_packed` is true, the data will be bit-packed into the stream.
200/// Note that the you must call `serializer.flush()` when you are done
201/// writing bit-packed data in order ensure any unwritten bits are committed.
202/// If `is_packed` is false, data is packed to the smallest byte. In the case
203/// of packed structs, the struct will written bit-packed and with the specified
204/// endianess, after which data will resume being written at the next byte boundary.
205/// Types may implement a custom serialization routine with a
206/// function named `serialize` in the form of:
207/// pub fn serialize(self: Self, serializer: var) !void
208/// which will be called when the serializer is used to serialize that type. It will
209/// pass a const pointer to the type instance to be serialized and a pointer
210/// to the serializer struct.
201/// If `is_packed` is true, the data will be bit-packed into the stream.
202/// Note that the you must call `serializer.flush()` when you are done
203/// writing bit-packed data in order ensure any unwritten bits are committed.
204/// If `is_packed` is false, data is packed to the smallest byte. In the case
205/// of packed structs, the struct will written bit-packed and with the specified
206/// endianess, after which data will resume being written at the next byte boundary.
207/// Types may implement a custom serialization routine with a
208/// function named `serialize` in the form of:
209/// ```
210/// pub fn serialize(self: Self, serializer: anytype) !void
211/// ```
212/// which will be called when the serializer is used to serialize that type. It will
213/// pass a const pointer to the type instance to be serialized and a pointer
214/// to the serializer struct.
211215pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime OutStreamType: type) type {
212216 return struct {
213217 out_stream: if (packing == .Bit) io.BitOutStream(endian, OutStreamType) else OutStreamType,
......@@ -270,7 +274,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
270274 return;
271275 }
272276
273 //custom serializer: fn(self: Self, serializer: var) !void
277 //custom serializer: fn(self: Self, serializer: anytype) !void
274278 if (comptime trait.hasFn("serialize")(T)) return T.serialize(value, self);
275279
276280 if (comptime trait.isPacked(T) and packing != .Bit) {
lib/std/log.zig+1-1
......@@ -22,7 +22,7 @@ const root = @import("root");
2222//! comptime level: std.log.Level,
2323//! comptime scope: @TypeOf(.EnumLiteral),
2424//! comptime format: []const u8,
25//! args: var,
25//! args: anytype,
2626//! ) void {
2727//! // Ignore all non-critical logging from sources other than
2828//! // .my_project and .nice_library
lib/std/zig/ast.zig+2-2
......@@ -1052,12 +1052,12 @@ pub const Node = struct {
10521052 const params_len: usize = if (self.params_len == 0)
10531053 0
10541054 else switch (self.paramsConst()[self.params_len - 1].param_type) {
1055 .var_type, .type_expr => self.params_len,
1055 .any_type, .type_expr => self.params_len,
10561056 .var_args => self.params_len - 1,
10571057 };
10581058 if (i < params_len) {
10591059 switch (self.paramsConst()[i].param_type) {
1060 .var_type => |n| return n,
1060 .any_type => |n| return n,
10611061 .var_args => unreachable,
10621062 .type_expr => |n| return n,
10631063 }
src-self-hosted/Module.zig+1-1
......@@ -1132,7 +1132,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool {
11321132 const param_types = try fn_type_scope.arena.alloc(*zir.Inst, param_decls.len);
11331133 for (param_decls) |param_decl, i| {
11341134 const param_type_node = switch (param_decl.param_type) {
1135 .var_type => |node| return self.failNode(&fn_type_scope.base, node, "TODO implement anytype parameter", .{}),
1135 .any_type => |node| return self.failNode(&fn_type_scope.base, node, "TODO implement anytype parameter", .{}),
11361136 .var_args => |tok| return self.failTok(&fn_type_scope.base, tok, "TODO implement var args", .{}),
11371137 .type_expr => |node| node,
11381138 };
src/analyze.cpp+2-2
......@@ -1511,13 +1511,13 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
15111511 }
15121512 for (; i < fn_type_id->param_count; i += 1) {
15131513 const char *comma_str = (i == 0) ? "" : ",";
1514 buf_appendf(&fn_type->name, "%svar", comma_str);
1514 buf_appendf(&fn_type->name, "%sanytype", comma_str);
15151515 }
15161516 buf_append_str(&fn_type->name, ")");
15171517 if (fn_type_id->cc != CallingConventionUnspecified) {
15181518 buf_appendf(&fn_type->name, " callconv(.%s)", calling_convention_name(fn_type_id->cc));
15191519 }
1520 buf_append_str(&fn_type->name, " var");
1520 buf_append_str(&fn_type->name, " anytype");
15211521
15221522 fn_type->data.fn.fn_type_id = *fn_type_id;
15231523 fn_type->data.fn.is_generic = true;
test/compile_errors.zig+17-17
......@@ -42,7 +42,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4242 \\fn foo() Foo {
4343 \\ return .{ .x = 42 };
4444 \\}
45 \\fn bar(val: var) Foo {
45 \\fn bar(val: anytype) Foo {
4646 \\ return .{ .x = val };
4747 \\}
4848 \\export fn entry() void {
......@@ -1034,7 +1034,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
10341034 \\ storev(&v[i], 42);
10351035 \\}
10361036 \\
1037 \\fn storev(ptr: var, val: i32) void {
1037 \\fn storev(ptr: anytype, val: i32) void {
10381038 \\ ptr.* = val;
10391039 \\}
10401040 , &[_][]const u8{
......@@ -1049,7 +1049,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
10491049 \\ var x = loadv(&v[i]);
10501050 \\}
10511051 \\
1052 \\fn loadv(ptr: var) i32 {
1052 \\fn loadv(ptr: anytype) i32 {
10531053 \\ return ptr.*;
10541054 \\}
10551055 , &[_][]const u8{
......@@ -1832,7 +1832,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
18321832 \\ while (true) {}
18331833 \\}
18341834 , &[_][]const u8{
1835 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var) var'",
1835 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'",
18361836 "note: only one of the functions is generic",
18371837 });
18381838
......@@ -2032,11 +2032,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20322032 });
20332033
20342034 cases.add("export generic function",
2035 \\export fn foo(num: var) i32 {
2035 \\export fn foo(num: anytype) i32 {
20362036 \\ return 0;
20372037 \\}
20382038 , &[_][]const u8{
2039 "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'C'",
2039 "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'",
20402040 });
20412041
20422042 cases.add("C pointer to c_void",
......@@ -2836,7 +2836,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28362836 });
28372837
28382838 cases.add("missing parameter name of generic function",
2839 \\fn dump(var) void {}
2839 \\fn dump(anytype) void {}
28402840 \\export fn entry() void {
28412841 \\ var a: u8 = 9;
28422842 \\ dump(a);
......@@ -2859,13 +2859,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28592859 });
28602860
28612861 cases.add("generic fn as parameter without comptime keyword",
2862 \\fn f(_: fn (var) void) void {}
2863 \\fn g(_: var) void {}
2862 \\fn f(_: fn (anytype) void) void {}
2863 \\fn g(_: anytype) void {}
28642864 \\export fn entry() void {
28652865 \\ f(g);
28662866 \\}
28672867 , &[_][]const u8{
2868 "tmp.zig:1:9: error: parameter of type 'fn(var) var' must be declared comptime",
2868 "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime",
28692869 });
28702870
28712871 cases.add("optional pointer to void in extern struct",
......@@ -3165,7 +3165,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
31653165
31663166 cases.add("var makes structs required to be comptime known",
31673167 \\export fn entry() void {
3168 \\ const S = struct{v: var};
3168 \\ const S = struct{v: anytype};
31693169 \\ var s = S{.v=@as(i32, 10)};
31703170 \\}
31713171 , &[_][]const u8{
......@@ -6072,10 +6072,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
60726072 });
60736073
60746074 cases.add("calling a generic function only known at runtime",
6075 \\var foos = [_]fn(var) void { foo1, foo2 };
6075 \\var foos = [_]fn(anytype) void { foo1, foo2 };
60766076 \\
6077 \\fn foo1(arg: var) void {}
6078 \\fn foo2(arg: var) void {}
6077 \\fn foo1(arg: anytype) void {}
6078 \\fn foo2(arg: anytype) void {}
60796079 \\
60806080 \\pub fn main() !void {
60816081 \\ foos[0](true);
......@@ -6920,12 +6920,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69206920 });
69216921
69226922 cases.add("getting return type of generic function",
6923 \\fn generic(a: var) void {}
6923 \\fn generic(a: anytype) void {}
69246924 \\comptime {
69256925 \\ _ = @TypeOf(generic).ReturnType;
69266926 \\}
69276927 , &[_][]const u8{
6928 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",
6928 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(anytype) anytype' is generic",
69296929 });
69306930
69316931 cases.add("unsupported modifier at start of asm output constraint",
......@@ -7493,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
74937493 });
74947494
74957495 cases.add("issue #5221: invalid struct init type referenced by @typeInfo and passed into function",
7496 \\fn ignore(comptime param: var) void {}
7496 \\fn ignore(comptime param: anytype) void {}
74977497 \\
74987498 \\export fn foo() void {
74997499 \\ const MyStruct = struct {