| author | |
| committer | |
| log | be1507a7afe4c8869abdbab67a32ede6afe3d938 |
| tree | 88be868d2b791d3bd7ab5cbd479b11066ece55d2 |
| parent | 3e095d8ef32fc93f5050cead708849846d626d1d |
| signature |
8 files changed, 56 insertions(+), 51 deletions(-)
doc/docgen.zig+6-5| ... | ... | @@ -212,7 +212,7 @@ const Tokenizer = struct { |
| 212 | 212 | } |
| 213 | 213 | }; |
| 214 | 214 | |
| 215 | fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: var) anyerror { | |
| 215 | fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: anytype) anyerror { | |
| 216 | 216 | const loc = tokenizer.getTokenLocation(token); |
| 217 | 217 | const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 }; |
| 218 | 218 | warn("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args); |
| ... | ... | @@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 634 | 634 | return buf.toOwnedSlice(); |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | fn writeEscaped(out: var, input: []const u8) !void { | |
| 637 | fn writeEscaped(out: anytype, input: []const u8) !void { | |
| 638 | 638 | for (input) |c| { |
| 639 | 639 | try switch (c) { |
| 640 | 640 | '&' => out.writeAll("&"), |
| ... | ... | @@ -765,7 +765,7 @@ fn isType(name: []const u8) bool { |
| 765 | 765 | return false; |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Token, raw_src: []const u8) !void { | |
| 768 | fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token, raw_src: []const u8) !void { | |
| 769 | 769 | const src = mem.trim(u8, raw_src, " \n"); |
| 770 | 770 | try out.writeAll("<code class=\"zig\">"); |
| 771 | 771 | var tokenizer = std.zig.Tokenizer.init(src); |
| ... | ... | @@ -825,6 +825,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok |
| 825 | 825 | .Keyword_volatile, |
| 826 | 826 | .Keyword_allowzero, |
| 827 | 827 | .Keyword_while, |
| 828 | .Keyword_anytype, | |
| 828 | 829 | => { |
| 829 | 830 | try out.writeAll("<span class=\"tok-kw\">"); |
| 830 | 831 | try writeEscaped(out, src[token.loc.start..token.loc.end]); |
| ... | ... | @@ -977,12 +978,12 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok |
| 977 | 978 | try out.writeAll("</code>"); |
| 978 | 979 | } |
| 979 | 980 | |
| 980 | fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token) !void { | |
| 981 | fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token) !void { | |
| 981 | 982 | const raw_src = docgen_tokenizer.buffer[source_token.start..source_token.end]; |
| 982 | 983 | return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src); |
| 983 | 984 | } |
| 984 | 985 | |
| 985 | fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void { | |
| 986 | fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8) !void { | |
| 986 | 987 | var code_progress_index: usize = 0; |
| 987 | 988 | |
| 988 | 989 | var env_map = try process.getEnvMap(allocator); |
lib/std/fmt.zig+1-1| ... | ... | @@ -69,7 +69,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool { |
| 69 | 69 | /// |
| 70 | 70 | /// If a formatted user type contains a function of the type |
| 71 | 71 | /// ``` |
| 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 | |
| 73 | 73 | /// ``` |
| 74 | 74 | /// with `?` being the type formatted, this function will be called instead of the default implementation. |
| 75 | 75 | /// 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 { |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | /// 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. | |
| 27 | 29 | pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime ReaderType: type) type { |
| 28 | 30 | return struct { |
| 29 | 31 | 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, |
| 108 | 110 | const C = comptime meta.Child(T); |
| 109 | 111 | const child_type_id = @typeInfo(C); |
| 110 | 112 | |
| 111 | //custom deserializer: fn(self: *Self, deserializer: var) !void | |
| 113 | //custom deserializer: fn(self: *Self, deserializer: anytype) !void | |
| 112 | 114 | if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self); |
| 113 | 115 | |
| 114 | 116 | if (comptime trait.isPacked(C) and packing != .Bit) { |
| ... | ... | @@ -196,18 +198,20 @@ pub fn deserializer( |
| 196 | 198 | } |
| 197 | 199 | |
| 198 | 200 | /// 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. | |
| 211 | 215 | pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime OutStreamType: type) type { |
| 212 | 216 | return struct { |
| 213 | 217 | 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 |
| 270 | 274 | return; |
| 271 | 275 | } |
| 272 | 276 | |
| 273 | //custom serializer: fn(self: Self, serializer: var) !void | |
| 277 | //custom serializer: fn(self: Self, serializer: anytype) !void | |
| 274 | 278 | if (comptime trait.hasFn("serialize")(T)) return T.serialize(value, self); |
| 275 | 279 | |
| 276 | 280 | if (comptime trait.isPacked(T) and packing != .Bit) { |
lib/std/log.zig+1-1| ... | ... | @@ -22,7 +22,7 @@ const root = @import("root"); |
| 22 | 22 | //! comptime level: std.log.Level, |
| 23 | 23 | //! comptime scope: @TypeOf(.EnumLiteral), |
| 24 | 24 | //! comptime format: []const u8, |
| 25 | //! args: var, | |
| 25 | //! args: anytype, | |
| 26 | 26 | //! ) void { |
| 27 | 27 | //! // Ignore all non-critical logging from sources other than |
| 28 | 28 | //! // .my_project and .nice_library |
lib/std/zig/ast.zig+2-2| ... | ... | @@ -1052,12 +1052,12 @@ pub const Node = struct { |
| 1052 | 1052 | const params_len: usize = if (self.params_len == 0) |
| 1053 | 1053 | 0 |
| 1054 | 1054 | 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, | |
| 1056 | 1056 | .var_args => self.params_len - 1, |
| 1057 | 1057 | }; |
| 1058 | 1058 | if (i < params_len) { |
| 1059 | 1059 | switch (self.paramsConst()[i].param_type) { |
| 1060 | .var_type => |n| return n, | |
| 1060 | .any_type => |n| return n, | |
| 1061 | 1061 | .var_args => unreachable, |
| 1062 | 1062 | .type_expr => |n| return n, |
| 1063 | 1063 | } |
src-self-hosted/Module.zig+1-1| ... | ... | @@ -1132,7 +1132,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1132 | 1132 | const param_types = try fn_type_scope.arena.alloc(*zir.Inst, param_decls.len); |
| 1133 | 1133 | for (param_decls) |param_decl, i| { |
| 1134 | 1134 | 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", .{}), | |
| 1136 | 1136 | .var_args => |tok| return self.failTok(&fn_type_scope.base, tok, "TODO implement var args", .{}), |
| 1137 | 1137 | .type_expr => |node| node, |
| 1138 | 1138 | }; |
src/analyze.cpp+2-2| ... | ... | @@ -1511,13 +1511,13 @@ ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1511 | 1511 | } |
| 1512 | 1512 | for (; i < fn_type_id->param_count; i += 1) { |
| 1513 | 1513 | const char *comma_str = (i == 0) ? "" : ","; |
| 1514 | buf_appendf(&fn_type->name, "%svar", comma_str); | |
| 1514 | buf_appendf(&fn_type->name, "%sanytype", comma_str); | |
| 1515 | 1515 | } |
| 1516 | 1516 | buf_append_str(&fn_type->name, ")"); |
| 1517 | 1517 | if (fn_type_id->cc != CallingConventionUnspecified) { |
| 1518 | 1518 | buf_appendf(&fn_type->name, " callconv(.%s)", calling_convention_name(fn_type_id->cc)); |
| 1519 | 1519 | } |
| 1520 | buf_append_str(&fn_type->name, " var"); | |
| 1520 | buf_append_str(&fn_type->name, " anytype"); | |
| 1521 | 1521 | |
| 1522 | 1522 | fn_type->data.fn.fn_type_id = *fn_type_id; |
| 1523 | 1523 | fn_type->data.fn.is_generic = true; |
test/compile_errors.zig+17-17| ... | ... | @@ -42,7 +42,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 42 | 42 | \\fn foo() Foo { |
| 43 | 43 | \\ return .{ .x = 42 }; |
| 44 | 44 | \\} |
| 45 | \\fn bar(val: var) Foo { | |
| 45 | \\fn bar(val: anytype) Foo { | |
| 46 | 46 | \\ return .{ .x = val }; |
| 47 | 47 | \\} |
| 48 | 48 | \\export fn entry() void { |
| ... | ... | @@ -1034,7 +1034,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1034 | 1034 | \\ storev(&v[i], 42); |
| 1035 | 1035 | \\} |
| 1036 | 1036 | \\ |
| 1037 | \\fn storev(ptr: var, val: i32) void { | |
| 1037 | \\fn storev(ptr: anytype, val: i32) void { | |
| 1038 | 1038 | \\ ptr.* = val; |
| 1039 | 1039 | \\} |
| 1040 | 1040 | , &[_][]const u8{ |
| ... | ... | @@ -1049,7 +1049,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1049 | 1049 | \\ var x = loadv(&v[i]); |
| 1050 | 1050 | \\} |
| 1051 | 1051 | \\ |
| 1052 | \\fn loadv(ptr: var) i32 { | |
| 1052 | \\fn loadv(ptr: anytype) i32 { | |
| 1053 | 1053 | \\ return ptr.*; |
| 1054 | 1054 | \\} |
| 1055 | 1055 | , &[_][]const u8{ |
| ... | ... | @@ -1832,7 +1832,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1832 | 1832 | \\ while (true) {} |
| 1833 | 1833 | \\} |
| 1834 | 1834 | , &[_][]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'", | |
| 1836 | 1836 | "note: only one of the functions is generic", |
| 1837 | 1837 | }); |
| 1838 | 1838 | |
| ... | ... | @@ -2032,11 +2032,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2032 | 2032 | }); |
| 2033 | 2033 | |
| 2034 | 2034 | cases.add("export generic function", |
| 2035 | \\export fn foo(num: var) i32 { | |
| 2035 | \\export fn foo(num: anytype) i32 { | |
| 2036 | 2036 | \\ return 0; |
| 2037 | 2037 | \\} |
| 2038 | 2038 | , &[_][]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'", | |
| 2040 | 2040 | }); |
| 2041 | 2041 | |
| 2042 | 2042 | cases.add("C pointer to c_void", |
| ... | ... | @@ -2836,7 +2836,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2836 | 2836 | }); |
| 2837 | 2837 | |
| 2838 | 2838 | cases.add("missing parameter name of generic function", |
| 2839 | \\fn dump(var) void {} | |
| 2839 | \\fn dump(anytype) void {} | |
| 2840 | 2840 | \\export fn entry() void { |
| 2841 | 2841 | \\ var a: u8 = 9; |
| 2842 | 2842 | \\ dump(a); |
| ... | ... | @@ -2859,13 +2859,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2859 | 2859 | }); |
| 2860 | 2860 | |
| 2861 | 2861 | 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 {} | |
| 2864 | 2864 | \\export fn entry() void { |
| 2865 | 2865 | \\ f(g); |
| 2866 | 2866 | \\} |
| 2867 | 2867 | , &[_][]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", | |
| 2869 | 2869 | }); |
| 2870 | 2870 | |
| 2871 | 2871 | cases.add("optional pointer to void in extern struct", |
| ... | ... | @@ -3165,7 +3165,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3165 | 3165 | |
| 3166 | 3166 | cases.add("var makes structs required to be comptime known", |
| 3167 | 3167 | \\export fn entry() void { |
| 3168 | \\ const S = struct{v: var}; | |
| 3168 | \\ const S = struct{v: anytype}; | |
| 3169 | 3169 | \\ var s = S{.v=@as(i32, 10)}; |
| 3170 | 3170 | \\} |
| 3171 | 3171 | , &[_][]const u8{ |
| ... | ... | @@ -6072,10 +6072,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6072 | 6072 | }); |
| 6073 | 6073 | |
| 6074 | 6074 | 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 }; | |
| 6076 | 6076 | \\ |
| 6077 | \\fn foo1(arg: var) void {} | |
| 6078 | \\fn foo2(arg: var) void {} | |
| 6077 | \\fn foo1(arg: anytype) void {} | |
| 6078 | \\fn foo2(arg: anytype) void {} | |
| 6079 | 6079 | \\ |
| 6080 | 6080 | \\pub fn main() !void { |
| 6081 | 6081 | \\ foos[0](true); |
| ... | ... | @@ -6920,12 +6920,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6920 | 6920 | }); |
| 6921 | 6921 | |
| 6922 | 6922 | cases.add("getting return type of generic function", |
| 6923 | \\fn generic(a: var) void {} | |
| 6923 | \\fn generic(a: anytype) void {} | |
| 6924 | 6924 | \\comptime { |
| 6925 | 6925 | \\ _ = @TypeOf(generic).ReturnType; |
| 6926 | 6926 | \\} |
| 6927 | 6927 | , &[_][]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", | |
| 6929 | 6929 | }); |
| 6930 | 6930 | |
| 6931 | 6931 | cases.add("unsupported modifier at start of asm output constraint", |
| ... | ... | @@ -7493,7 +7493,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 7493 | 7493 | }); |
| 7494 | 7494 | |
| 7495 | 7495 | 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 {} | |
| 7497 | 7497 | \\ |
| 7498 | 7498 | \\export fn foo() void { |
| 7499 | 7499 | \\ const MyStruct = struct { |