Merge pull request #5846 from Vexu/anytype

Rename 'var' type to 'anytype'
master
Andrew Kelley 2020-07-12 07:35:01 +00:00 committed by GitHub
commit fe08a4d065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
166 changed files with 795 additions and 749 deletions

View File

@ -153,7 +153,7 @@ pub fn build(b: *Builder) !void {
test_step.dependOn(docs_step);
}
fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
fn dependOnLib(b: *Builder, lib_exe_obj: anytype, dep: LibraryDep) void {
for (dep.libdirs.items) |lib_dir| {
lib_exe_obj.addLibPath(lib_dir);
}
@ -193,7 +193,7 @@ fn fileExists(filename: []const u8) !bool {
return true;
}
fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
fn addCppLib(b: *Builder, lib_exe_obj: anytype, cmake_binary_dir: []const u8, lib_name: []const u8) void {
lib_exe_obj.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
cmake_binary_dir,
"zig_cpp",
@ -275,7 +275,7 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
return result;
}
fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
fn configureStage2(b: *Builder, exe: anytype, ctx: Context) !void {
exe.addIncludeDir("src");
exe.addIncludeDir(ctx.cmake_binary_dir);
addCppLib(b, exe, ctx.cmake_binary_dir, "zig_cpp");
@ -340,7 +340,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void {
fn addCxxKnownPath(
b: *Builder,
ctx: Context,
exe: var,
exe: anytype,
objname: []const u8,
errtxt: ?[]const u8,
) !void {

View File

@ -212,7 +212,7 @@ const Tokenizer = struct {
}
};
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: var) anyerror {
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: anytype) anyerror {
const loc = tokenizer.getTokenLocation(token);
const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 };
warn("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args);
@ -634,7 +634,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
return buf.toOwnedSlice();
}
fn writeEscaped(out: var, input: []const u8) !void {
fn writeEscaped(out: anytype, input: []const u8) !void {
for (input) |c| {
try switch (c) {
'&' => out.writeAll("&"),
@ -765,7 +765,7 @@ fn isType(name: []const u8) bool {
return false;
}
fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Token, raw_src: []const u8) !void {
fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token, raw_src: []const u8) !void {
const src = mem.trim(u8, raw_src, " \n");
try out.writeAll("<code class=\"zig\">");
var tokenizer = std.zig.Tokenizer.init(src);
@ -825,6 +825,7 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
.Keyword_volatile,
.Keyword_allowzero,
.Keyword_while,
.Keyword_anytype,
=> {
try out.writeAll("<span class=\"tok-kw\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
@ -977,12 +978,12 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
try out.writeAll("</code>");
}
fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: var, source_token: Token) !void {
fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: Token) !void {
const raw_src = docgen_tokenizer.buffer[source_token.start..source_token.end];
return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src);
}
fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8) !void {
var code_progress_index: usize = 0;
var env_map = try process.getEnvMap(allocator);

View File

@ -1785,7 +1785,7 @@ test "fully anonymous list literal" {
dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"});
}
fn dump(args: var) void {
fn dump(args: anytype) void {
assert(args.@"0" == 1234);
assert(args.@"1" == 12.34);
assert(args.@"2");
@ -2717,7 +2717,7 @@ test "fully anonymous struct" {
});
}
fn dump(args: var) void {
fn dump(args: anytype) void {
assert(args.int == 1234);
assert(args.float == 12.34);
assert(args.b);
@ -4181,14 +4181,14 @@ test "pass struct to function" {
{#header_close#}
{#header_open|Function Parameter Type Inference#}
<p>
Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type.
Function parameters can be declared with {#syntax#}anytype{#endsyntax#} in place of the type.
In this case the parameter types will be inferred when the function is called.
Use {#link|@TypeOf#} and {#link|@typeInfo#} to get information about the inferred type.
</p>
{#code_begin|test#}
const assert = @import("std").debug.assert;
fn addFortyTwo(x: var) @TypeOf(x) {
fn addFortyTwo(x: anytype) @TypeOf(x) {
return x + 42;
}
@ -5974,7 +5974,7 @@ pub fn main() void {
{#code_begin|syntax#}
/// Calls print and then flushes the buffer.
pub fn printf(self: *OutStream, comptime format: []const u8, args: var) anyerror!void {
pub fn printf(self: *OutStream, comptime format: []const u8, args: anytype) anyerror!void {
const State = enum {
Start,
OpenBrace,
@ -6060,7 +6060,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {
on the type:
</p>
{#code_begin|syntax#}
pub fn printValue(self: *OutStream, value: var) !void {
pub fn printValue(self: *OutStream, value: anytype) !void {
switch (@typeInfo(@TypeOf(value))) {
.Int => {
return self.printInt(T, value);
@ -6686,7 +6686,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
</p>
{#header_close#}
{#header_open|@alignCast#}
<pre>{#syntax#}@alignCast(comptime alignment: u29, ptr: var) var{#endsyntax#}</pre>
<pre>{#syntax#}@alignCast(comptime alignment: u29, ptr: anytype) anytype{#endsyntax#}</pre>
<p>
{#syntax#}ptr{#endsyntax#} can be {#syntax#}*T{#endsyntax#}, {#syntax#}fn(){#endsyntax#}, {#syntax#}?*T{#endsyntax#},
{#syntax#}?fn(){#endsyntax#}, or {#syntax#}[]T{#endsyntax#}. It returns the same type as {#syntax#}ptr{#endsyntax#}
@ -6723,7 +6723,7 @@ comptime {
{#header_close#}
{#header_open|@asyncCall#}
<pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: var) anyframe->T{#endsyntax#}</pre>
<pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: anytype) anyframe->T{#endsyntax#}</pre>
<p>
{#syntax#}@asyncCall{#endsyntax#} performs an {#syntax#}async{#endsyntax#} call on a function pointer,
which may or may not be an {#link|async function|Async Functions#}.
@ -6811,7 +6811,7 @@ fn func(y: *i32) void {
</p>
{#header_close#}
{#header_open|@bitCast#}
<pre>{#syntax#}@bitCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@bitCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre>
<p>
Converts a value of one type to another type.
</p>
@ -6932,7 +6932,7 @@ fn func(y: *i32) void {
{#header_close#}
{#header_open|@call#}
<pre>{#syntax#}@call(options: std.builtin.CallOptions, function: var, args: var) var{#endsyntax#}</pre>
<pre>{#syntax#}@call(options: std.builtin.CallOptions, function: anytype, args: anytype) anytype{#endsyntax#}</pre>
<p>
Calls a function, in the same way that invoking an expression with parentheses does:
</p>
@ -7279,7 +7279,7 @@ test "main" {
{#header_close#}
{#header_open|@enumToInt#}
<pre>{#syntax#}@enumToInt(enum_or_tagged_union: var) var{#endsyntax#}</pre>
<pre>{#syntax#}@enumToInt(enum_or_tagged_union: anytype) anytype{#endsyntax#}</pre>
<p>
Converts an enumeration value into its integer tag type. When a tagged union is passed,
the tag value is used as the enumeration value.
@ -7314,7 +7314,7 @@ test "main" {
{#header_close#}
{#header_open|@errorToInt#}
<pre>{#syntax#}@errorToInt(err: var) std.meta.IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre>
<pre>{#syntax#}@errorToInt(err: anytype) std.meta.IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre>
<p>
Supports the following types:
</p>
@ -7334,7 +7334,7 @@ test "main" {
{#header_close#}
{#header_open|@errSetCast#}
<pre>{#syntax#}@errSetCast(comptime T: DestType, value: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@errSetCast(comptime T: DestType, value: anytype) DestType{#endsyntax#}</pre>
<p>
Converts an error value from one error set to another error set. Attempting to convert an error
which is not in the destination error set results in safety-protected {#link|Undefined Behavior#}.
@ -7342,7 +7342,7 @@ test "main" {
{#header_close#}
{#header_open|@export#}
<pre>{#syntax#}@export(target: var, comptime options: std.builtin.ExportOptions) void{#endsyntax#}</pre>
<pre>{#syntax#}@export(target: anytype, comptime options: std.builtin.ExportOptions) void{#endsyntax#}</pre>
<p>
Creates a symbol in the output object file.
</p>
@ -7387,7 +7387,7 @@ export fn @"A function name that is a complete sentence."() void {}
{#header_close#}
{#header_open|@field#}
<pre>{#syntax#}@field(lhs: var, comptime field_name: []const u8) (field){#endsyntax#}</pre>
<pre>{#syntax#}@field(lhs: anytype, comptime field_name: []const u8) (field){#endsyntax#}</pre>
<p>Performs field access by a compile-time string.
</p>
{#code_begin|test#}
@ -7421,7 +7421,7 @@ test "field access by string" {
{#header_close#}
{#header_open|@floatCast#}
<pre>{#syntax#}@floatCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@floatCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre>
<p>
Convert from one float type to another. This cast is safe, but may cause the
numeric value to lose precision.
@ -7429,7 +7429,7 @@ test "field access by string" {
{#header_close#}
{#header_open|@floatToInt#}
<pre>{#syntax#}@floatToInt(comptime DestType: type, float: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@floatToInt(comptime DestType: type, float: anytype) DestType{#endsyntax#}</pre>
<p>
Converts the integer part of a floating point number to the destination type.
</p>
@ -7455,7 +7455,7 @@ test "field access by string" {
{#header_close#}
{#header_open|@Frame#}
<pre>{#syntax#}@Frame(func: var) type{#endsyntax#}</pre>
<pre>{#syntax#}@Frame(func: anytype) type{#endsyntax#}</pre>
<p>
This function returns the frame type of a function. This works for {#link|Async Functions#}
as well as any function without a specific calling convention.
@ -7581,7 +7581,7 @@ test "@hasDecl" {
{#header_close#}
{#header_open|@intCast#}
<pre>{#syntax#}@intCast(comptime DestType: type, int: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@intCast(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
<p>
Converts an integer to another integer while keeping the same numerical value.
Attempting to convert a number which is out of range of the destination type results in
@ -7622,7 +7622,7 @@ test "@hasDecl" {
{#header_close#}
{#header_open|@intToFloat#}
<pre>{#syntax#}@intToFloat(comptime DestType: type, int: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@intToFloat(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
<p>
Converts an integer to the closest floating point representation. To convert the other way, use {#link|@floatToInt#}. This cast is always safe.
</p>
@ -7773,7 +7773,7 @@ test "@wasmMemoryGrow" {
{#header_close#}
{#header_open|@ptrCast#}
<pre>{#syntax#}@ptrCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre>
<pre>{#syntax#}@ptrCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre>
<p>
Converts a pointer of one type to a pointer of another type.
</p>
@ -7784,7 +7784,7 @@ test "@wasmMemoryGrow" {
{#header_close#}
{#header_open|@ptrToInt#}
<pre>{#syntax#}@ptrToInt(value: var) usize{#endsyntax#}</pre>
<pre>{#syntax#}@ptrToInt(value: anytype) usize{#endsyntax#}</pre>
<p>
Converts {#syntax#}value{#endsyntax#} to a {#syntax#}usize{#endsyntax#} which is the address of the pointer. {#syntax#}value{#endsyntax#} can be one of these types:
</p>
@ -8042,7 +8042,7 @@ test "@setRuntimeSafety" {
{#header_close#}
{#header_open|@splat#}
<pre>{#syntax#}@splat(comptime len: u32, scalar: var) std.meta.Vector(len, @TypeOf(scalar)){#endsyntax#}</pre>
<pre>{#syntax#}@splat(comptime len: u32, scalar: anytype) std.meta.Vector(len, @TypeOf(scalar)){#endsyntax#}</pre>
<p>
Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value
{#syntax#}scalar{#endsyntax#}:
@ -8088,7 +8088,7 @@ fn doTheTest() void {
{#code_end#}
{#header_close#}
{#header_open|@sqrt#}
<pre>{#syntax#}@sqrt(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@sqrt(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Performs the square root of a floating point number. Uses a dedicated hardware instruction
when available.
@ -8099,7 +8099,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@sin#}
<pre>{#syntax#}@sin(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@sin(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Sine trigometric function on a floating point number. Uses a dedicated hardware instruction
when available.
@ -8110,7 +8110,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@cos#}
<pre>{#syntax#}@cos(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@cos(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Cosine trigometric function on a floating point number. Uses a dedicated hardware instruction
when available.
@ -8121,7 +8121,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@exp#}
<pre>{#syntax#}@exp(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@exp(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Base-e exponential function on a floating point number. Uses a dedicated hardware instruction
when available.
@ -8132,7 +8132,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@exp2#}
<pre>{#syntax#}@exp2(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@exp2(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Base-2 exponential function on a floating point number. Uses a dedicated hardware instruction
when available.
@ -8143,7 +8143,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@log#}
<pre>{#syntax#}@log(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@log(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Returns the natural logarithm of a floating point number. Uses a dedicated hardware instruction
when available.
@ -8154,7 +8154,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@log2#}
<pre>{#syntax#}@log2(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@log2(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Returns the logarithm to the base 2 of a floating point number. Uses a dedicated hardware instruction
when available.
@ -8165,7 +8165,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@log10#}
<pre>{#syntax#}@log10(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@log10(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Returns the logarithm to the base 10 of a floating point number. Uses a dedicated hardware instruction
when available.
@ -8176,7 +8176,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@fabs#}
<pre>{#syntax#}@fabs(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@fabs(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Returns the absolute value of a floating point number. Uses a dedicated hardware instruction
when available.
@ -8187,7 +8187,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@floor#}
<pre>{#syntax#}@floor(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@floor(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Returns the largest integral value not greater than the given floating point number.
Uses a dedicated hardware instruction when available.
@ -8198,7 +8198,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@ceil#}
<pre>{#syntax#}@ceil(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@ceil(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Returns the largest integral value not less than the given floating point number.
Uses a dedicated hardware instruction when available.
@ -8209,7 +8209,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@trunc#}
<pre>{#syntax#}@trunc(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@trunc(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Rounds the given floating point number to an integer, towards zero.
Uses a dedicated hardware instruction when available.
@ -8220,7 +8220,7 @@ fn doTheTest() void {
</p>
{#header_close#}
{#header_open|@round#}
<pre>{#syntax#}@round(value: var) @TypeOf(value){#endsyntax#}</pre>
<pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre>
<p>
Rounds the given floating point number to an integer, away from zero. Uses a dedicated hardware instruction
when available.
@ -8241,7 +8241,7 @@ fn doTheTest() void {
{#header_close#}
{#header_open|@tagName#}
<pre>{#syntax#}@tagName(value: var) []const u8{#endsyntax#}</pre>
<pre>{#syntax#}@tagName(value: anytype) []const u8{#endsyntax#}</pre>
<p>
Converts an enum value or union value to a slice of bytes representing the name.</p><p>If the enum is non-exhaustive and the tag value does not map to a name, it invokes safety-checked {#link|Undefined Behavior#}.
</p>
@ -8292,7 +8292,7 @@ fn List(comptime T: type) type {
{#header_close#}
{#header_open|@truncate#}
<pre>{#syntax#}@truncate(comptime T: type, integer: var) T{#endsyntax#}</pre>
<pre>{#syntax#}@truncate(comptime T: type, integer: anytype) T{#endsyntax#}</pre>
<p>
This function truncates bits from an integer type, resulting in a smaller
or same-sized integer type.
@ -10214,7 +10214,7 @@ TopLevelDecl
/ (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl
/ KEYWORD_usingnamespace Expr SEMICOLON
FnProto &lt;- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr)
FnProto &lt;- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_anytype / TypeExpr)
VarDecl &lt;- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? LinkSection? (EQUAL Expr)? SEMICOLON
@ -10386,7 +10386,7 @@ LinkSection &lt;- KEYWORD_linksection LPAREN Expr RPAREN
ParamDecl &lt;- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType
ParamType
&lt;- KEYWORD_var
&lt;- KEYWORD_anytype
/ DOT3
/ TypeExpr
@ -10624,6 +10624,7 @@ KEYWORD_align &lt;- 'align' end_of_word
KEYWORD_allowzero &lt;- 'allowzero' end_of_word
KEYWORD_and &lt;- 'and' end_of_word
KEYWORD_anyframe &lt;- 'anyframe' end_of_word
KEYWORD_anytype &lt;- 'anytype' end_of_word
KEYWORD_asm &lt;- 'asm' end_of_word
KEYWORD_async &lt;- 'async' end_of_word
KEYWORD_await &lt;- 'await' end_of_word
@ -10669,14 +10670,14 @@ KEYWORD_var &lt;- 'var' end_of_word
KEYWORD_volatile &lt;- 'volatile' end_of_word
KEYWORD_while &lt;- 'while' end_of_word
keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_asm
/ KEYWORD_async / KEYWORD_await / KEYWORD_break
keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_anyframe / KEYWORD_anytype
/ KEYWORD_allowzero / KEYWORD_asm / KEYWORD_async / KEYWORD_await / KEYWORD_break
/ KEYWORD_catch / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue
/ KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer
/ KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false
/ KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline
/ KEYWORD_noalias / KEYWORD_null / KEYWORD_or
/ KEYWORD_orelse / KEYWORD_packed / KEYWORD_anyframe / KEYWORD_pub
/ KEYWORD_orelse / KEYWORD_packed / KEYWORD_pub
/ KEYWORD_resume / KEYWORD_return / KEYWORD_linksection
/ KEYWORD_struct / KEYWORD_suspend
/ KEYWORD_switch / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try

View File

@ -53,7 +53,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
/// Deprecated: use `items` field directly.
/// Return contents as a slice. Only valid while the list
/// doesn't change size.
pub fn span(self: var) @TypeOf(self.items) {
pub fn span(self: anytype) @TypeOf(self.items) {
return self.items;
}

View File

@ -69,7 +69,7 @@ pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type {
}
/// Only works when `T` is `u8`.
pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Self {
pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: anytype) !Self {
const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) {
error.Overflow => return error.OutOfMemory,
};
@ -82,7 +82,7 @@ pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type {
self.list.deinit();
}
pub fn span(self: var) @TypeOf(self.list.items[0..:sentinel]) {
pub fn span(self: anytype) @TypeOf(self.list.items[0..:sentinel]) {
return self.list.items[0..self.len() :sentinel];
}

View File

@ -123,10 +123,10 @@ pub fn Queue(comptime T: type) type {
/// Dumps the contents of the queue to `stream`.
/// Up to 4 elements from the head are dumped and the tail of the queue is
/// dumped as well.
pub fn dumpToStream(self: *Self, stream: var) !void {
pub fn dumpToStream(self: *Self, stream: anytype) !void {
const S = struct {
fn dumpRecursive(
s: var,
s: anytype,
optional_node: ?*Node,
indent: usize,
comptime depth: comptime_int,

View File

@ -312,7 +312,7 @@ pub const Builder = struct {
return write_file_step;
}
pub fn addLog(self: *Builder, comptime format: []const u8, args: var) *LogStep {
pub fn addLog(self: *Builder, comptime format: []const u8, args: anytype) *LogStep {
const data = self.fmt(format, args);
const log_step = self.allocator.create(LogStep) catch unreachable;
log_step.* = LogStep.init(self, data);
@ -883,7 +883,7 @@ pub const Builder = struct {
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: var) []u8 {
pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 {
return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable;
}

View File

@ -126,7 +126,7 @@ const BinaryElfOutput = struct {
return segment.p_offset <= section.elfOffset and (segment.p_offset + segment.p_filesz) >= (section.elfOffset + section.fileSize);
}
fn sectionValidForOutput(shdr: var) bool {
fn sectionValidForOutput(shdr: anytype) bool {
return shdr.sh_size > 0 and shdr.sh_type != elf.SHT_NOBITS and
((shdr.sh_flags & elf.SHF_ALLOC) == elf.SHF_ALLOC);
}

View File

@ -198,7 +198,7 @@ pub const TypeInfo = union(enum) {
/// The type of the sentinel is the element type of the pointer, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use `var`.
sentinel: var,
sentinel: anytype,
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
@ -220,7 +220,7 @@ pub const TypeInfo = union(enum) {
/// The type of the sentinel is the element type of the array, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use `var`.
sentinel: var,
sentinel: anytype,
};
/// This data structure is used by the Zig language code generation and
@ -237,7 +237,7 @@ pub const TypeInfo = union(enum) {
name: []const u8,
offset: ?comptime_int,
field_type: type,
default_value: var,
default_value: anytype,
};
/// This data structure is used by the Zig language code generation and
@ -328,7 +328,7 @@ pub const TypeInfo = union(enum) {
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Frame = struct {
function: var,
function: anytype,
};
/// This data structure is used by the Zig language code generation and
@ -452,7 +452,7 @@ pub const Version = struct {
self: Version,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
out_stream: var,
out_stream: anytype,
) !void {
if (fmt.len == 0) {
if (self.patch == 0) {

View File

@ -27,7 +27,7 @@ pub usingnamespace switch (std.Target.current.os.tag) {
else => struct {},
};
pub fn getErrno(rc: var) u16 {
pub fn getErrno(rc: anytype) u16 {
if (rc == -1) {
return @intCast(u16, _errno().*);
} else {

View File

@ -64,7 +64,7 @@ pub const Error = union(enum) {
NothingDeclared: SimpleError("declaration doesn't declare anything"),
QualifierIgnored: SingleTokenError("qualifier '{}' ignored"),
pub fn render(self: *const Error, tree: *Tree, stream: var) !void {
pub fn render(self: *const Error, tree: *Tree, stream: anytype) !void {
switch (self.*) {
.InvalidToken => |*x| return x.render(tree, stream),
.ExpectedToken => |*x| return x.render(tree, stream),
@ -114,7 +114,7 @@ pub const Error = union(enum) {
token: TokenIndex,
expected_id: @TagType(Token.Id),
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
const found_token = tree.tokens.at(self.token);
if (found_token.id == .Invalid) {
return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
@ -129,7 +129,7 @@ pub const Error = union(enum) {
token: TokenIndex,
type_spec: *Node.TypeSpec,
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
try stream.write("invalid type specifier '");
try type_spec.spec.print(tree, stream);
const token_name = tree.tokens.at(self.token).id.symbol();
@ -141,7 +141,7 @@ pub const Error = union(enum) {
kw: TokenIndex,
name: TokenIndex,
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
pub fn render(self: *const ExpectedToken, tree: *Tree, stream: anytype) !void {
return stream.print("must use '{}' tag to refer to type '{}'", .{ tree.slice(kw), tree.slice(name) });
}
};
@ -150,7 +150,7 @@ pub const Error = union(enum) {
return struct {
token: TokenIndex,
pub fn render(self: *const @This(), tree: *Tree, stream: var) !void {
pub fn render(self: *const @This(), tree: *Tree, stream: anytype) !void {
const actual_token = tree.tokens.at(self.token);
return stream.print(msg, .{actual_token.id.symbol()});
}
@ -163,7 +163,7 @@ pub const Error = union(enum) {
token: TokenIndex,
pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: anytype) !void {
return stream.write(msg);
}
};
@ -317,7 +317,7 @@ pub const Node = struct {
sym_type: *Type,
},
pub fn print(self: *@This(), self: *const @This(), tree: *Tree, stream: var) !void {
pub fn print(self: *@This(), self: *const @This(), tree: *Tree, stream: anytype) !void {
switch (self.spec) {
.None => unreachable,
.Void => |index| try stream.write(tree.slice(index)),

View File

@ -70,7 +70,7 @@ pub const CacheHash = struct {
/// Convert the input value into bytes and record it as a dependency of the
/// process being cached
pub fn add(self: *CacheHash, val: var) void {
pub fn add(self: *CacheHash, val: anytype) void {
assert(self.manifest_file == null);
const valPtr = switch (@typeInfo(@TypeOf(val))) {

View File

@ -8,7 +8,7 @@ const mem = std.mem;
/// `kvs` expects a list literal containing list literals or an array/slice of structs
/// where `.@"0"` is the `[]const u8` key and `.@"1"` is the associated value of type `V`.
/// TODO: https://github.com/ziglang/zig/issues/4335
pub fn ComptimeStringMap(comptime V: type, comptime kvs: var) type {
pub fn ComptimeStringMap(comptime V: type, comptime kvs: anytype) type {
const precomputed = comptime blk: {
@setEvalBranchQuota(2000);
const KV = struct {
@ -126,7 +126,7 @@ test "ComptimeStringMap slice of structs" {
testMap(map);
}
fn testMap(comptime map: var) void {
fn testMap(comptime map: anytype) void {
std.testing.expectEqual(TestEnum.A, map.get("have").?);
std.testing.expectEqual(TestEnum.B, map.get("nothing").?);
std.testing.expect(null == map.get("missing"));
@ -165,7 +165,7 @@ test "ComptimeStringMap void value type, list literal of list literals" {
testSet(map);
}
fn testSet(comptime map: var) void {
fn testSet(comptime map: anytype) void {
std.testing.expectEqual({}, map.get("have").?);
std.testing.expectEqual({}, map.get("nothing").?);
std.testing.expect(null == map.get("missing"));

View File

@ -29,7 +29,7 @@ const hashes = [_]Crypto{
Crypto{ .ty = crypto.Blake3, .name = "blake3" },
};
pub fn benchmarkHash(comptime Hash: var, comptime bytes: comptime_int) !u64 {
pub fn benchmarkHash(comptime Hash: anytype, comptime bytes: comptime_int) !u64 {
var h = Hash.init();
var block: [Hash.digest_length]u8 = undefined;
@ -56,7 +56,7 @@ const macs = [_]Crypto{
Crypto{ .ty = crypto.HmacSha256, .name = "hmac-sha256" },
};
pub fn benchmarkMac(comptime Mac: var, comptime bytes: comptime_int) !u64 {
pub fn benchmarkMac(comptime Mac: anytype, comptime bytes: comptime_int) !u64 {
std.debug.assert(32 >= Mac.mac_length and 32 >= Mac.minimum_key_length);
var in: [1 * MiB]u8 = undefined;
@ -81,7 +81,7 @@ pub fn benchmarkMac(comptime Mac: var, comptime bytes: comptime_int) !u64 {
const exchanges = [_]Crypto{Crypto{ .ty = crypto.X25519, .name = "x25519" }};
pub fn benchmarkKeyExchange(comptime DhKeyExchange: var, comptime exchange_count: comptime_int) !u64 {
pub fn benchmarkKeyExchange(comptime DhKeyExchange: anytype, comptime exchange_count: comptime_int) !u64 {
std.debug.assert(DhKeyExchange.minimum_key_length >= DhKeyExchange.secret_length);
var in: [DhKeyExchange.minimum_key_length]u8 = undefined;
@ -166,21 +166,21 @@ pub fn main() !void {
inline for (hashes) |H| {
if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
const throughput = try benchmarkHash(H.ty, mode(32 * MiB));
try stdout.print("{:>11}: {:5} MiB/s\n", .{H.name, throughput / (1 * MiB)});
try stdout.print("{:>11}: {:5} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
}
}
inline for (macs) |M| {
if (filter == null or std.mem.indexOf(u8, M.name, filter.?) != null) {
const throughput = try benchmarkMac(M.ty, mode(128 * MiB));
try stdout.print("{:>11}: {:5} MiB/s\n", .{M.name, throughput / (1 * MiB)});
try stdout.print("{:>11}: {:5} MiB/s\n", .{ M.name, throughput / (1 * MiB) });
}
}
inline for (exchanges) |E| {
if (filter == null or std.mem.indexOf(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKeyExchange(E.ty, mode(1000));
try stdout.print("{:>11}: {:5} exchanges/s\n", .{E.name, throughput});
try stdout.print("{:>11}: {:5} exchanges/s\n", .{ E.name, throughput });
}
}
}

View File

@ -4,7 +4,7 @@ const mem = std.mem;
const fmt = std.fmt;
// Hash using the specified hasher `H` asserting `expected == H(input)`.
pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, input: []const u8) void {
pub fn assertEqualHash(comptime Hasher: anytype, comptime expected: []const u8, input: []const u8) void {
var h: [expected.len / 2]u8 = undefined;
Hasher.hash(input, h[0..]);

View File

@ -58,7 +58,7 @@ pub const warn = print;
/// Print to stderr, unbuffered, and silently returning on failure. Intended
/// for use in "printf debugging." Use `std.log` functions for proper logging.
pub fn print(comptime fmt: []const u8, args: var) void {
pub fn print(comptime fmt: []const u8, args: anytype) void {
const held = stderr_mutex.acquire();
defer held.release();
const stderr = io.getStdErr().writer();
@ -223,7 +223,7 @@ pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
pub fn panic(comptime format: []const u8, args: var) noreturn {
pub fn panic(comptime format: []const u8, args: anytype) noreturn {
@setCold(true);
// TODO: remove conditional once wasi / LLVM defines __builtin_return_address
const first_trace_addr = if (builtin.os.tag == .wasi) null else @returnAddress();
@ -241,7 +241,7 @@ var panic_mutex = std.Mutex.init();
/// This is used to catch and handle panics triggered by the panic handler.
threadlocal var panic_stage: usize = 0;
pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: anytype) noreturn {
@setCold(true);
if (enable_segfault_handler) {
@ -306,7 +306,7 @@ const RESET = "\x1b[0m";
pub fn writeStackTrace(
stack_trace: builtin.StackTrace,
out_stream: var,
out_stream: anytype,
allocator: *mem.Allocator,
debug_info: *DebugInfo,
tty_config: TTY.Config,
@ -384,7 +384,7 @@ pub const StackIterator = struct {
};
pub fn writeCurrentStackTrace(
out_stream: var,
out_stream: anytype,
debug_info: *DebugInfo,
tty_config: TTY.Config,
start_addr: ?usize,
@ -399,7 +399,7 @@ pub fn writeCurrentStackTrace(
}
pub fn writeCurrentStackTraceWindows(
out_stream: var,
out_stream: anytype,
debug_info: *DebugInfo,
tty_config: TTY.Config,
start_addr: ?usize,
@ -435,7 +435,7 @@ pub const TTY = struct {
// TODO give this a payload of file handle
windows_api,
fn setColor(conf: Config, out_stream: var, color: Color) void {
fn setColor(conf: Config, out_stream: anytype, color: Color) void {
nosuspend switch (conf) {
.no_color => return,
.escape_codes => switch (color) {
@ -555,7 +555,7 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach
}
/// TODO resources https://github.com/ziglang/zig/issues/4353
pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {
pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: anytype, address: usize, tty_config: TTY.Config) !void {
const module = debug_info.getModuleForAddress(address) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => {
return printLineInfo(
@ -586,13 +586,13 @@ pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: us
}
fn printLineInfo(
out_stream: var,
out_stream: anytype,
line_info: ?LineInfo,
address: usize,
symbol_name: []const u8,
compile_unit_name: []const u8,
tty_config: TTY.Config,
comptime printLineFromFile: var,
comptime printLineFromFile: anytype,
) !void {
nosuspend {
tty_config.setColor(out_stream, .White);
@ -820,7 +820,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
}
}
fn readSparseBitVector(stream: var, allocator: *mem.Allocator) ![]usize {
fn readSparseBitVector(stream: anytype, allocator: *mem.Allocator) ![]usize {
const num_words = try stream.readIntLittle(u32);
var word_i: usize = 0;
var list = ArrayList(usize).init(allocator);
@ -1004,7 +1004,7 @@ fn readMachODebugInfo(allocator: *mem.Allocator, macho_file: File) !ModuleDebugI
};
}
fn printLineFromFileAnyOs(out_stream: var, line_info: LineInfo) !void {
fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
// Need this to always block even in async I/O mode, because this could potentially
// be called from e.g. the event loop code crashing.
var f = try fs.cwd().openFile(line_info.file_name, .{ .intended_io_mode = .blocking });

View File

@ -3,7 +3,7 @@ const testing = std.testing;
/// Read a single unsigned LEB128 value from the given reader as type T,
/// or error.Overflow if the value cannot fit.
pub fn readULEB128(comptime T: type, reader: var) !T {
pub fn readULEB128(comptime T: type, reader: anytype) !T {
const U = if (T.bit_count < 8) u8 else T;
const ShiftT = std.math.Log2Int(U);
@ -33,7 +33,7 @@ pub fn readULEB128(comptime T: type, reader: var) !T {
}
/// Write a single unsigned integer as unsigned LEB128 to the given writer.
pub fn writeULEB128(writer: var, uint_value: var) !void {
pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
const T = @TypeOf(uint_value);
const U = if (T.bit_count < 8) u8 else T;
var value = @intCast(U, uint_value);
@ -61,7 +61,7 @@ pub fn readULEB128Mem(comptime T: type, ptr: *[]const u8) !T {
/// Write a single unsigned LEB128 integer to the given memory as unsigned LEB128,
/// returning the number of bytes written.
pub fn writeULEB128Mem(ptr: []u8, uint_value: var) !usize {
pub fn writeULEB128Mem(ptr: []u8, uint_value: anytype) !usize {
const T = @TypeOf(uint_value);
const max_group = (T.bit_count + 6) / 7;
var buf = std.io.fixedBufferStream(ptr);
@ -71,7 +71,7 @@ pub fn writeULEB128Mem(ptr: []u8, uint_value: var) !usize {
/// Read a single signed LEB128 value from the given reader as type T,
/// or error.Overflow if the value cannot fit.
pub fn readILEB128(comptime T: type, reader: var) !T {
pub fn readILEB128(comptime T: type, reader: anytype) !T {
const S = if (T.bit_count < 8) i8 else T;
const U = std.meta.Int(false, S.bit_count);
const ShiftU = std.math.Log2Int(U);
@ -120,7 +120,7 @@ pub fn readILEB128(comptime T: type, reader: var) !T {
}
/// Write a single signed integer as signed LEB128 to the given writer.
pub fn writeILEB128(writer: var, int_value: var) !void {
pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
const T = @TypeOf(int_value);
const S = if (T.bit_count < 8) i8 else T;
const U = std.meta.Int(false, S.bit_count);
@ -152,7 +152,7 @@ pub fn readILEB128Mem(comptime T: type, ptr: *[]const u8) !T {
/// Write a single signed LEB128 integer to the given memory as unsigned LEB128,
/// returning the number of bytes written.
pub fn writeILEB128Mem(ptr: []u8, int_value: var) !usize {
pub fn writeILEB128Mem(ptr: []u8, int_value: anytype) !usize {
const T = @TypeOf(int_value);
var buf = std.io.fixedBufferStream(ptr);
try writeILEB128(buf.writer(), int_value);
@ -295,7 +295,7 @@ test "deserialize unsigned LEB128" {
try test_read_uleb128_seq(u64, 4, "\x81\x01\x3f\x80\x7f\x80\x80\x80\x00");
}
fn test_write_leb128(value: var) !void {
fn test_write_leb128(value: anytype) !void {
const T = @TypeOf(value);
const writeStream = if (T.is_signed) writeILEB128 else writeULEB128;

View File

@ -236,7 +236,7 @@ const LineNumberProgram = struct {
}
};
fn readUnitLength(in_stream: var, endian: builtin.Endian, is_64: *bool) !u64 {
fn readUnitLength(in_stream: anytype, endian: builtin.Endian, is_64: *bool) !u64 {
const first_32_bits = try in_stream.readInt(u32, endian);
is_64.* = (first_32_bits == 0xffffffff);
if (is_64.*) {
@ -249,7 +249,7 @@ fn readUnitLength(in_stream: var, endian: builtin.Endian, is_64: *bool) !u64 {
}
// TODO the nosuspends here are workarounds
fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 {
fn readAllocBytes(allocator: *mem.Allocator, in_stream: anytype, size: usize) ![]u8 {
const buf = try allocator.alloc(u8, size);
errdefer allocator.free(buf);
if ((try nosuspend in_stream.read(buf)) < size) return error.EndOfFile;
@ -257,25 +257,25 @@ fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8
}
// TODO the nosuspends here are workarounds
fn readAddress(in_stream: var, endian: builtin.Endian, is_64: bool) !u64 {
fn readAddress(in_stream: anytype, endian: builtin.Endian, is_64: bool) !u64 {
return nosuspend if (is_64)
try in_stream.readInt(u64, endian)
else
@as(u64, try in_stream.readInt(u32, endian));
}
fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue {
fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: anytype, size: usize) !FormValue {
const buf = try readAllocBytes(allocator, in_stream, size);
return FormValue{ .Block = buf };
}
// TODO the nosuspends here are workarounds
fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: usize) !FormValue {
fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: usize) !FormValue {
const block_len = try nosuspend in_stream.readVarInt(usize, endian, size);
return parseFormValueBlockLen(allocator, in_stream, block_len);
}
fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {
fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: builtin.Endian, comptime size: i32) !FormValue {
// TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.
// `nosuspend` should be removed from all the function calls once it is fixed.
return FormValue{
@ -302,7 +302,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo
}
// TODO the nosuspends here are workarounds
fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, endian: builtin.Endian, size: i32) !FormValue {
fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: builtin.Endian, size: i32) !FormValue {
return FormValue{
.Ref = switch (size) {
1 => try nosuspend in_stream.readInt(u8, endian),
@ -316,7 +316,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, endian: builtin.
}
// TODO the nosuspends here are workarounds
fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue {
fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue {
return switch (form_id) {
FORM_addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) },
FORM_block1 => parseFormValueBlock(allocator, in_stream, endian, 1),
@ -670,7 +670,7 @@ pub const DwarfInfo = struct {
}
}
fn parseDie(di: *DwarfInfo, in_stream: var, abbrev_table: *const AbbrevTable, is_64: bool) !?Die {
fn parseDie(di: *DwarfInfo, in_stream: anytype, abbrev_table: *const AbbrevTable, is_64: bool) !?Die {
const abbrev_code = try leb.readULEB128(u64, in_stream);
if (abbrev_code == 0) return null;
const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo;

View File

@ -517,7 +517,7 @@ pub fn readAllHeaders(allocator: *mem.Allocator, file: File) !AllHeaders {
return hdrs;
}
pub fn int(is_64: bool, need_bswap: bool, int_32: var, int_64: var) @TypeOf(int_64) {
pub fn int(is_64: bool, need_bswap: bool, int_32: anytype, int_64: anytype) @TypeOf(int_64) {
if (is_64) {
if (need_bswap) {
return @byteSwap(@TypeOf(int_64), int_64);
@ -529,7 +529,7 @@ pub fn int(is_64: bool, need_bswap: bool, int_32: var, int_64: var) @TypeOf(int_
}
}
pub fn int32(need_bswap: bool, int_32: var, comptime Int64: var) Int64 {
pub fn int32(need_bswap: bool, int_32: anytype, comptime Int64: anytype) Int64 {
if (need_bswap) {
return @byteSwap(@TypeOf(int_32), int_32);
} else {

View File

@ -65,7 +65,7 @@ pub fn Group(comptime ReturnType: type) type {
/// allocated by the group and freed by `wait`.
/// `func` must be async and have return type `ReturnType`.
/// Thread-safe.
pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void {
pub fn call(self: *Self, comptime func: anytype, args: anytype) error{OutOfMemory}!void {
var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
errdefer self.allocator.destroy(frame);
const node = try self.allocator.create(AllocStack.Node);

View File

@ -69,16 +69,16 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
///
/// If a formatted user type contains a function of the type
/// ```
/// pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: var) !void
/// pub fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void
/// ```
/// with `?` being the type formatted, this function will be called instead of the default implementation.
/// This allows user types to be formatted in a logical manner instead of dumping all fields of the type.
///
/// A user type may be a `struct`, `vector`, `union` or `enum` type.
pub fn format(
writer: var,
writer: anytype,
comptime fmt: []const u8,
args: var,
args: anytype,
) !void {
const ArgSetType = u32;
if (@typeInfo(@TypeOf(args)) != .Struct) {
@ -311,10 +311,10 @@ pub fn format(
}
pub fn formatType(
value: var,
value: anytype,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
max_depth: usize,
) @TypeOf(writer).Error!void {
if (comptime std.mem.eql(u8, fmt, "*")) {
@ -490,10 +490,10 @@ pub fn formatType(
}
fn formatValue(
value: var,
value: anytype,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
if (comptime std.mem.eql(u8, fmt, "B")) {
return formatBytes(value, options, 1000, writer);
@ -511,10 +511,10 @@ fn formatValue(
}
pub fn formatIntValue(
value: var,
value: anytype,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
comptime var radix = 10;
comptime var uppercase = false;
@ -551,10 +551,10 @@ pub fn formatIntValue(
}
fn formatFloatValue(
value: var,
value: anytype,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {
return formatFloatScientific(value, options, writer);
@ -569,7 +569,7 @@ pub fn formatText(
bytes: []const u8,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
if (comptime std.mem.eql(u8, fmt, "s") or (fmt.len == 0)) {
return formatBuf(bytes, options, writer);
@ -586,7 +586,7 @@ pub fn formatText(
pub fn formatAsciiChar(
c: u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
return writer.writeAll(@as(*const [1]u8, &c));
}
@ -594,7 +594,7 @@ pub fn formatAsciiChar(
pub fn formatBuf(
buf: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
const width = options.width orelse buf.len;
var padding = if (width > buf.len) (width - buf.len) else 0;
@ -626,9 +626,9 @@ pub fn formatBuf(
// It should be the case that every full precision, printed value can be re-parsed back to the
// same type unambiguously.
pub fn formatFloatScientific(
value: var,
value: anytype,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
var x = @floatCast(f64, value);
@ -719,9 +719,9 @@ pub fn formatFloatScientific(
// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
// By default floats are printed at full precision (no rounding).
pub fn formatFloatDecimal(
value: var,
value: anytype,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
var x = @as(f64, value);
@ -860,10 +860,10 @@ pub fn formatFloatDecimal(
}
pub fn formatBytes(
value: var,
value: anytype,
options: FormatOptions,
comptime radix: usize,
writer: var,
writer: anytype,
) !void {
if (value == 0) {
return writer.writeAll("0B");
@ -901,11 +901,11 @@ pub fn formatBytes(
}
pub fn formatInt(
value: var,
value: anytype,
base: u8,
uppercase: bool,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
const int_value = if (@TypeOf(value) == comptime_int) blk: {
const Int = math.IntFittingRange(value, value);
@ -921,11 +921,11 @@ pub fn formatInt(
}
fn formatIntSigned(
value: var,
value: anytype,
base: u8,
uppercase: bool,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
const new_options = FormatOptions{
.width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null,
@ -948,11 +948,11 @@ fn formatIntSigned(
}
fn formatIntUnsigned(
value: var,
value: anytype,
base: u8,
uppercase: bool,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
assert(base >= 2);
var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
@ -990,7 +990,7 @@ fn formatIntUnsigned(
}
}
pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) usize {
pub fn formatIntBuf(out_buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) usize {
var fbs = std.io.fixedBufferStream(out_buf);
formatInt(value, base, uppercase, options, fbs.writer()) catch unreachable;
return fbs.pos;
@ -1050,7 +1050,7 @@ fn parseWithSign(
.Pos => math.add,
.Neg => math.sub,
};
var x: T = 0;
for (buf) |c| {
@ -1132,14 +1132,14 @@ pub const BufPrintError = error{
/// As much as possible was written to the buffer, but it was too small to fit all the printed bytes.
NoSpaceLeft,
};
pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: var) BufPrintError![]u8 {
pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: anytype) BufPrintError![]u8 {
var fbs = std.io.fixedBufferStream(buf);
try format(fbs.writer(), fmt, args);
return fbs.getWritten();
}
// Count the characters needed for format. Useful for preallocating memory
pub fn count(comptime fmt: []const u8, args: var) u64 {
pub fn count(comptime fmt: []const u8, args: anytype) u64 {
var counting_writer = std.io.countingWriter(std.io.null_writer);
format(counting_writer.writer(), fmt, args) catch |err| switch (err) {};
return counting_writer.bytes_written;
@ -1147,7 +1147,7 @@ pub fn count(comptime fmt: []const u8, args: var) u64 {
pub const AllocPrintError = error{OutOfMemory};
pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![]u8 {
pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![]u8 {
const size = math.cast(usize, count(fmt, args)) catch |err| switch (err) {
// Output too long. Can't possibly allocate enough memory to display it.
error.Overflow => return error.OutOfMemory,
@ -1158,7 +1158,7 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: var
};
}
pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![:0]u8 {
pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 {
const result = try allocPrint(allocator, fmt ++ "\x00", args);
return result[0 .. result.len - 1 :0];
}
@ -1184,7 +1184,7 @@ test "bufPrintInt" {
std.testing.expectEqualSlices(u8, "-42", bufPrintIntToSlice(buf, @as(i32, -42), 10, false, FormatOptions{ .width = 3 }));
}
fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, options: FormatOptions) []u8 {
fn bufPrintIntToSlice(buf: []u8, value: anytype, base: u8, uppercase: bool, options: FormatOptions) []u8 {
return buf[0..formatIntBuf(buf, value, base, uppercase, options)];
}
@ -1452,7 +1452,7 @@ test "custom" {
self: SelfType,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });
@ -1573,7 +1573,7 @@ test "bytes.hex" {
try testFmt("lowercase: 000ebabe\n", "lowercase: {x}\n", .{bytes_with_zeros});
}
fn testFmt(expected: []const u8, comptime template: []const u8, args: var) !void {
fn testFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void {
var buf: [100]u8 = undefined;
const result = try bufPrint(buf[0..], template, args);
if (mem.eql(u8, result, expected)) return;
@ -1669,7 +1669,7 @@ test "formatType max_depth" {
self: SelfType,
comptime fmt: []const u8,
options: FormatOptions,
writer: var,
writer: anytype,
) !void {
if (fmt.len == 0) {
return std.fmt.format(writer, "({d:.3},{d:.3})", .{ self.x, self.y });

View File

@ -29,7 +29,7 @@ pub const PreopenType = union(PreopenTypeTag) {
}
}
pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: var) !void {
pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
try out_stream.print("PreopenType{{ ", .{});
switch (self) {
PreopenType.Dir => |path| try out_stream.print(".Dir = '{}'", .{path}),

View File

@ -21,7 +21,7 @@ pub const HashStrategy = enum {
};
/// Helper function to hash a pointer and mutate the strategy if needed.
pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
const info = @typeInfo(@TypeOf(key));
switch (info.Pointer.size) {
@ -53,7 +53,7 @@ pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
}
/// Helper function to hash a set of contiguous objects, from an array or slice.
pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void {
pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
switch (strat) {
.Shallow => {
// TODO detect via a trait when Key has no padding bits to
@ -73,7 +73,7 @@ pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void {
/// Provides generic hashing for any eligible type.
/// Strategy is provided to determine if pointers should be followed or not.
pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
const Key = @TypeOf(key);
switch (@typeInfo(Key)) {
.NoReturn,
@ -161,7 +161,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
/// Provides generic hashing for any eligible type.
/// Only hashes `key` itself, pointers are not followed.
/// Slices are rejected to avoid ambiguity on the user's intention.
pub fn autoHash(hasher: var, key: var) void {
pub fn autoHash(hasher: anytype, key: anytype) void {
const Key = @TypeOf(key);
if (comptime meta.trait.isSlice(Key)) {
comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
@ -181,28 +181,28 @@ pub fn autoHash(hasher: var, key: var) void {
const testing = std.testing;
const Wyhash = std.hash.Wyhash;
fn testHash(key: var) u64 {
fn testHash(key: anytype) u64 {
// Any hash could be used here, for testing autoHash.
var hasher = Wyhash.init(0);
hash(&hasher, key, .Shallow);
return hasher.final();
}
fn testHashShallow(key: var) u64 {
fn testHashShallow(key: anytype) u64 {
// Any hash could be used here, for testing autoHash.
var hasher = Wyhash.init(0);
hash(&hasher, key, .Shallow);
return hasher.final();
}
fn testHashDeep(key: var) u64 {
fn testHashDeep(key: anytype) u64 {
// Any hash could be used here, for testing autoHash.
var hasher = Wyhash.init(0);
hash(&hasher, key, .Deep);
return hasher.final();
}
fn testHashDeepRecursive(key: var) u64 {
fn testHashDeepRecursive(key: anytype) u64 {
// Any hash could be used here, for testing autoHash.
var hasher = Wyhash.init(0);
hash(&hasher, key, .DeepRecursive);

View File

@ -88,7 +88,7 @@ const Result = struct {
const block_size: usize = 8 * 8192;
pub fn benchmarkHash(comptime H: var, bytes: usize) !Result {
pub fn benchmarkHash(comptime H: anytype, bytes: usize) !Result {
var h = blk: {
if (H.init_u8s) |init| {
break :blk H.ty.init(init);
@ -119,7 +119,7 @@ pub fn benchmarkHash(comptime H: var, bytes: usize) !Result {
};
}
pub fn benchmarkHashSmallKeys(comptime H: var, key_size: usize, bytes: usize) !Result {
pub fn benchmarkHashSmallKeys(comptime H: anytype, key_size: usize, bytes: usize) !Result {
const key_count = bytes / key_size;
var block: [block_size]u8 = undefined;
prng.random.bytes(block[0..]);

View File

@ -354,7 +354,7 @@ pub const CityHash64 = struct {
}
};
fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
const hashbytes = hashbits / 8;
var key: [256]u8 = undefined;
var hashes: [hashbytes * 256]u8 = undefined;

View File

@ -279,7 +279,7 @@ pub const Murmur3_32 = struct {
}
};
fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
fn SMHasherTest(comptime hash_fn: anytype, comptime hashbits: u32) u32 {
const hashbytes = hashbits / 8;
var key: [256]u8 = undefined;
var hashes: [hashbytes * 256]u8 = undefined;

View File

@ -15,15 +15,20 @@ pub const ArenaAllocator = @import("heap/arena_allocator.zig").ArenaAllocator;
const Allocator = mem.Allocator;
usingnamespace if (comptime @hasDecl(c, "malloc_size")) struct {
pub const supports_malloc_size = true;
pub const malloc_size = c.malloc_size;
} else if (comptime @hasDecl(c, "malloc_usable_size")) struct {
pub const supports_malloc_size = true;
pub const malloc_size = c.malloc_usable_size;
} else struct {
pub const supports_malloc_size = false;
};
usingnamespace if (comptime @hasDecl(c, "malloc_size"))
struct {
pub const supports_malloc_size = true;
pub const malloc_size = c.malloc_size;
}
else if (comptime @hasDecl(c, "malloc_usable_size"))
struct {
pub const supports_malloc_size = true;
pub const malloc_size = c.malloc_usable_size;
}
else
struct {
pub const supports_malloc_size = false;
};
pub const c_allocator = &c_allocator_state;
var c_allocator_state = Allocator{
@ -151,8 +156,7 @@ const PageAllocator = struct {
}
const maxDropLen = alignment - std.math.min(alignment, mem.page_size);
const allocLen = if (maxDropLen <= alignedLen - n) alignedLen
else mem.alignForward(alignedLen + maxDropLen, mem.page_size);
const allocLen = if (maxDropLen <= alignedLen - n) alignedLen else mem.alignForward(alignedLen + maxDropLen, mem.page_size);
const slice = os.mmap(
null,
allocLen,
@ -331,8 +335,7 @@ const WasmPageAllocator = struct {
fn alloc(allocator: *Allocator, len: usize, alignment: u29, len_align: u29) error{OutOfMemory}![]u8 {
const page_count = nPages(len);
const page_idx = try allocPages(page_count, alignment);
return @intToPtr([*]u8, page_idx * mem.page_size)
[0..alignPageAllocLen(page_count * mem.page_size, len, len_align)];
return @intToPtr([*]u8, page_idx * mem.page_size)[0..alignPageAllocLen(page_count * mem.page_size, len, len_align)];
}
fn allocPages(page_count: usize, alignment: u29) !usize {
{
@ -452,7 +455,7 @@ pub const HeapAllocator = switch (builtin.os.tag) {
fn resize(allocator: *Allocator, buf: []u8, new_size: usize, len_align: u29) error{OutOfMemory}!usize {
const self = @fieldParentPtr(HeapAllocator, "allocator", allocator);
if (new_size == 0) {
os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void ,getRecordPtr(buf).*));
os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void, getRecordPtr(buf).*));
return 0;
}

View File

@ -40,7 +40,7 @@ pub fn LoggingAllocator(comptime OutStreamType: type) type {
if (new_len == 0) {
self.out_stream.print("free : {}\n", .{buf.len}) catch {};
} else if (new_len <= buf.len) {
self.out_stream.print("shrink: {} to {}\n", .{buf.len, new_len}) catch {};
self.out_stream.print("shrink: {} to {}\n", .{ buf.len, new_len }) catch {};
} else {
self.out_stream.print("expand: {} to {}", .{ buf.len, new_len }) catch {};
}
@ -60,7 +60,7 @@ pub fn LoggingAllocator(comptime OutStreamType: type) type {
pub fn loggingAllocator(
parent_allocator: *Allocator,
out_stream: var,
out_stream: anytype,
) LoggingAllocator(@TypeOf(out_stream)) {
return LoggingAllocator(@TypeOf(out_stream)).init(parent_allocator, out_stream);
}

View File

@ -348,7 +348,7 @@ pub const Headers = struct {
self: Self,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
out_stream: var,
out_stream: anytype,
) !void {
for (self.toSlice()) |entry| {
try out_stream.writeAll(entry.name);

View File

@ -170,7 +170,7 @@ pub fn BitReader(endian: builtin.Endian, comptime ReaderType: type) type {
pub fn bitReader(
comptime endian: builtin.Endian,
underlying_stream: var,
underlying_stream: anytype,
) BitReader(endian, @TypeOf(underlying_stream)) {
return BitReader(endian, @TypeOf(underlying_stream)).init(underlying_stream);
}

View File

@ -34,7 +34,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {
/// Write the specified number of bits to the stream from the least significant bits of
/// the specified unsigned int value. Bits will only be written to the stream when there
/// are enough to fill a byte.
pub fn writeBits(self: *Self, value: var, bits: usize) Error!void {
pub fn writeBits(self: *Self, value: anytype, bits: usize) Error!void {
if (bits == 0) return;
const U = @TypeOf(value);
@ -145,7 +145,7 @@ pub fn BitWriter(endian: builtin.Endian, comptime WriterType: type) type {
pub fn bitWriter(
comptime endian: builtin.Endian,
underlying_stream: var,
underlying_stream: anytype,
) BitWriter(endian, @TypeOf(underlying_stream)) {
return BitWriter(endian, @TypeOf(underlying_stream)).init(underlying_stream);
}

View File

@ -48,7 +48,7 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
};
}
pub fn bufferedReader(underlying_stream: var) BufferedReader(4096, @TypeOf(underlying_stream)) {
pub fn bufferedReader(underlying_stream: anytype) BufferedReader(4096, @TypeOf(underlying_stream)) {
return .{ .unbuffered_reader = underlying_stream };
}

View File

@ -43,6 +43,6 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty
};
}
pub fn bufferedWriter(underlying_stream: var) BufferedWriter(4096, @TypeOf(underlying_stream)) {
pub fn bufferedWriter(underlying_stream: anytype) BufferedWriter(4096, @TypeOf(underlying_stream)) {
return .{ .unbuffered_writer = underlying_stream };
}

View File

@ -32,7 +32,7 @@ pub fn CountingWriter(comptime WriterType: type) type {
};
}
pub fn countingWriter(child_stream: var) CountingWriter(@TypeOf(child_stream)) {
pub fn countingWriter(child_stream: anytype) CountingWriter(@TypeOf(child_stream)) {
return .{ .bytes_written = 0, .child_stream = child_stream };
}

View File

@ -127,7 +127,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
};
}
pub fn fixedBufferStream(buffer: var) FixedBufferStream(NonSentinelSpan(@TypeOf(buffer))) {
pub fn fixedBufferStream(buffer: anytype) FixedBufferStream(NonSentinelSpan(@TypeOf(buffer))) {
return .{ .buffer = mem.span(buffer), .pos = 0 };
}

View File

@ -43,7 +43,7 @@ pub fn MultiWriter(comptime Writers: type) type {
};
}
pub fn multiWriter(streams: var) MultiWriter(@TypeOf(streams)) {
pub fn multiWriter(streams: anytype) MultiWriter(@TypeOf(streams)) {
return .{ .streams = streams };
}

View File

@ -80,7 +80,7 @@ pub fn PeekStream(
pub fn peekStream(
comptime lookahead: comptime_int,
underlying_stream: var,
underlying_stream: anytype,
) PeekStream(.{ .Static = lookahead }, @TypeOf(underlying_stream)) {
return PeekStream(.{ .Static = lookahead }, @TypeOf(underlying_stream)).init(underlying_stream);
}

View File

@ -16,14 +16,16 @@ pub const Packing = enum {
};
/// Creates a deserializer that deserializes types from any stream.
/// If `is_packed` is true, the data stream is treated as bit-packed,
/// otherwise data is expected to be packed to the smallest byte.
/// Types may implement a custom deserialization routine with a
/// function named `deserialize` in the form of:
/// pub fn deserialize(self: *Self, deserializer: var) !void
/// which will be called when the deserializer is used to deserialize
/// that type. It will pass a pointer to the type instance to deserialize
/// into and a pointer to the deserializer struct.
/// If `is_packed` is true, the data stream is treated as bit-packed,
/// otherwise data is expected to be packed to the smallest byte.
/// Types may implement a custom deserialization routine with a
/// function named `deserialize` in the form of:
/// ```
/// pub fn deserialize(self: *Self, deserializer: anytype) !void
/// ```
/// which will be called when the deserializer is used to deserialize
/// that type. It will pass a pointer to the type instance to deserialize
/// into and a pointer to the deserializer struct.
pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime ReaderType: type) type {
return struct {
in_stream: if (packing == .Bit) io.BitReader(endian, ReaderType) else ReaderType,
@ -93,7 +95,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
}
/// Deserializes data into the type pointed to by `ptr`
pub fn deserializeInto(self: *Self, ptr: var) !void {
pub fn deserializeInto(self: *Self, ptr: anytype) !void {
const T = @TypeOf(ptr);
comptime assert(trait.is(.Pointer)(T));
@ -108,7 +110,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
const C = comptime meta.Child(T);
const child_type_id = @typeInfo(C);
//custom deserializer: fn(self: *Self, deserializer: var) !void
//custom deserializer: fn(self: *Self, deserializer: anytype) !void
if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self);
if (comptime trait.isPacked(C) and packing != .Bit) {
@ -190,24 +192,26 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
pub fn deserializer(
comptime endian: builtin.Endian,
comptime packing: Packing,
in_stream: var,
in_stream: anytype,
) Deserializer(endian, packing, @TypeOf(in_stream)) {
return Deserializer(endian, packing, @TypeOf(in_stream)).init(in_stream);
}
/// Creates a serializer that serializes types to any stream.
/// If `is_packed` is true, the data will be bit-packed into the stream.
/// Note that the you must call `serializer.flush()` when you are done
/// writing bit-packed data in order ensure any unwritten bits are committed.
/// If `is_packed` is false, data is packed to the smallest byte. In the case
/// of packed structs, the struct will written bit-packed and with the specified
/// endianess, after which data will resume being written at the next byte boundary.
/// Types may implement a custom serialization routine with a
/// function named `serialize` in the form of:
/// pub fn serialize(self: Self, serializer: var) !void
/// which will be called when the serializer is used to serialize that type. It will
/// pass a const pointer to the type instance to be serialized and a pointer
/// to the serializer struct.
/// If `is_packed` is true, the data will be bit-packed into the stream.
/// Note that the you must call `serializer.flush()` when you are done
/// writing bit-packed data in order ensure any unwritten bits are committed.
/// If `is_packed` is false, data is packed to the smallest byte. In the case
/// of packed structs, the struct will written bit-packed and with the specified
/// endianess, after which data will resume being written at the next byte boundary.
/// Types may implement a custom serialization routine with a
/// function named `serialize` in the form of:
/// ```
/// pub fn serialize(self: Self, serializer: anytype) !void
/// ```
/// which will be called when the serializer is used to serialize that type. It will
/// pass a const pointer to the type instance to be serialized and a pointer
/// to the serializer struct.
pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, comptime OutStreamType: type) type {
return struct {
out_stream: if (packing == .Bit) io.BitOutStream(endian, OutStreamType) else OutStreamType,
@ -229,7 +233,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
if (packing == .Bit) return self.out_stream.flushBits();
}
fn serializeInt(self: *Self, value: var) Error!void {
fn serializeInt(self: *Self, value: anytype) Error!void {
const T = @TypeOf(value);
comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T));
@ -261,7 +265,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
}
/// Serializes the passed value into the stream
pub fn serialize(self: *Self, value: var) Error!void {
pub fn serialize(self: *Self, value: anytype) Error!void {
const T = comptime @TypeOf(value);
if (comptime trait.isIndexable(T)) {
@ -270,7 +274,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
return;
}
//custom serializer: fn(self: Self, serializer: var) !void
//custom serializer: fn(self: Self, serializer: anytype) !void
if (comptime trait.hasFn("serialize")(T)) return T.serialize(value, self);
if (comptime trait.isPacked(T) and packing != .Bit) {
@ -346,7 +350,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
pub fn serializer(
comptime endian: builtin.Endian,
comptime packing: Packing,
out_stream: var,
out_stream: anytype,
) Serializer(endian, packing, @TypeOf(out_stream)) {
return Serializer(endian, packing, @TypeOf(out_stream)).init(out_stream);
}
@ -462,7 +466,7 @@ test "Serializer/Deserializer Int: Inf/NaN" {
try testIntSerializerDeserializerInfNaN(.Little, .Bit);
}
fn testAlternateSerializer(self: var, _serializer: var) !void {
fn testAlternateSerializer(self: anytype, _serializer: anytype) !void {
try _serializer.serialize(self.f_f16);
}
@ -503,7 +507,7 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:
f_f16: f16,
f_unused_u32: u32,
pub fn deserialize(self: *@This(), _deserializer: var) !void {
pub fn deserialize(self: *@This(), _deserializer: anytype) !void {
try _deserializer.deserializeInto(&self.f_f16);
self.f_unused_u32 = 47;
}

View File

@ -24,7 +24,7 @@ pub fn Writer(
}
}
pub fn print(self: Self, comptime format: []const u8, args: var) Error!void {
pub fn print(self: Self, comptime format: []const u8, args: anytype) Error!void {
return std.fmt.format(self, format, args);
}

View File

@ -239,7 +239,7 @@ pub const StreamingParser = struct {
NullLiteral3,
// Only call this function to generate array/object final state.
pub fn fromInt(x: var) State {
pub fn fromInt(x: anytype) State {
debug.assert(x == 0 or x == 1);
const T = @TagType(State);
return @intToEnum(State, @intCast(T, x));
@ -1236,7 +1236,7 @@ pub const Value = union(enum) {
pub fn jsonStringify(
value: @This(),
options: StringifyOptions,
out_stream: var,
out_stream: anytype,
) @TypeOf(out_stream).Error!void {
switch (value) {
.Null => try stringify(null, options, out_stream),
@ -2338,7 +2338,7 @@ pub const StringifyOptions = struct {
pub fn outputIndent(
whitespace: @This(),
out_stream: var,
out_stream: anytype,
) @TypeOf(out_stream).Error!void {
var char: u8 = undefined;
var n_chars: usize = undefined;
@ -2380,7 +2380,7 @@ pub const StringifyOptions = struct {
fn outputUnicodeEscape(
codepoint: u21,
out_stream: var,
out_stream: anytype,
) !void {
if (codepoint <= 0xFFFF) {
// If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF),
@ -2402,9 +2402,9 @@ fn outputUnicodeEscape(
}
pub fn stringify(
value: var,
value: anytype,
options: StringifyOptions,
out_stream: var,
out_stream: anytype,
) @TypeOf(out_stream).Error!void {
const T = @TypeOf(value);
switch (@typeInfo(T)) {
@ -2584,7 +2584,7 @@ pub fn stringify(
unreachable;
}
fn teststringify(expected: []const u8, value: var, options: StringifyOptions) !void {
fn teststringify(expected: []const u8, value: anytype, options: StringifyOptions) !void {
const ValidationOutStream = struct {
const Self = @This();
pub const OutStream = std.io.OutStream(*Self, Error, write);
@ -2758,7 +2758,7 @@ test "stringify struct with custom stringifier" {
pub fn jsonStringify(
value: Self,
options: StringifyOptions,
out_stream: var,
out_stream: anytype,
) !void {
try out_stream.writeAll("[\"something special\",");
try stringify(42, options, out_stream);

View File

@ -152,7 +152,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
self: *Self,
/// An integer, float, or `std.math.BigInt`. Emitted as a bare number if it fits losslessly
/// in a IEEE 754 double float, otherwise emitted as a string to the full precision.
value: var,
value: anytype,
) !void {
assert(self.state[self.state_index] == State.Value);
switch (@typeInfo(@TypeOf(value))) {
@ -215,7 +215,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
self.state_index -= 1;
}
fn stringify(self: *Self, value: var) !void {
fn stringify(self: *Self, value: anytype) !void {
try std.json.stringify(value, std.json.StringifyOptions{
.whitespace = self.whitespace,
}, self.stream);
@ -224,7 +224,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
}
pub fn writeStream(
out_stream: var,
out_stream: anytype,
comptime max_depth: usize,
) WriteStream(@TypeOf(out_stream), max_depth) {
return WriteStream(@TypeOf(out_stream), max_depth).init(out_stream);

View File

@ -22,7 +22,7 @@ const root = @import("root");
//! comptime level: std.log.Level,
//! comptime scope: @TypeOf(.EnumLiteral),
//! comptime format: []const u8,
//! args: var,
//! args: anytype,
//! ) void {
//! // Ignore all non-critical logging from sources other than
//! // .my_project and .nice_library
@ -101,7 +101,7 @@ fn log(
comptime message_level: Level,
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
if (@enumToInt(message_level) <= @enumToInt(level)) {
if (@hasDecl(root, "log")) {
@ -120,7 +120,7 @@ fn log(
pub fn emerg(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
@setCold(true);
log(.emerg, scope, format, args);
@ -131,7 +131,7 @@ pub fn emerg(
pub fn alert(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
@setCold(true);
log(.alert, scope, format, args);
@ -143,7 +143,7 @@ pub fn alert(
pub fn crit(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
@setCold(true);
log(.crit, scope, format, args);
@ -154,7 +154,7 @@ pub fn crit(
pub fn err(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
@setCold(true);
log(.err, scope, format, args);
@ -166,7 +166,7 @@ pub fn err(
pub fn warn(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
log(.warn, scope, format, args);
}
@ -176,7 +176,7 @@ pub fn warn(
pub fn notice(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
log(.notice, scope, format, args);
}
@ -186,7 +186,7 @@ pub fn notice(
pub fn info(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
log(.info, scope, format, args);
}
@ -196,7 +196,7 @@ pub fn info(
pub fn debug(
comptime scope: @Type(.EnumLiteral),
comptime format: []const u8,
args: var,
args: anytype,
) void {
log(.debug, scope, format, args);
}

View File

@ -104,7 +104,7 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
}
// TODO: Hide the following in an internal module.
pub fn forceEval(value: var) void {
pub fn forceEval(value: anytype) void {
const T = @TypeOf(value);
switch (T) {
f16 => {
@ -259,7 +259,7 @@ pub fn Min(comptime A: type, comptime B: type) type {
/// Returns the smaller number. When one of the parameter's type's full range fits in the other,
/// the return type is the smaller type.
pub fn min(x: var, y: var) Min(@TypeOf(x), @TypeOf(y)) {
pub fn min(x: anytype, y: anytype) Min(@TypeOf(x), @TypeOf(y)) {
const Result = Min(@TypeOf(x), @TypeOf(y));
if (x < y) {
// TODO Zig should allow this as an implicit cast because x is immutable and in this
@ -310,7 +310,7 @@ test "math.min" {
}
}
pub fn max(x: var, y: var) @TypeOf(x, y) {
pub fn max(x: anytype, y: anytype) @TypeOf(x, y) {
return if (x > y) x else y;
}
@ -318,7 +318,7 @@ test "math.max" {
testing.expect(max(@as(i32, -1), @as(i32, 2)) == 2);
}
pub fn clamp(val: var, lower: var, upper: var) @TypeOf(val, lower, upper) {
pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
assert(lower <= upper);
return max(lower, min(val, upper));
}
@ -354,7 +354,7 @@ pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) {
return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
}
pub fn negate(x: var) !@TypeOf(x) {
pub fn negate(x: anytype) !@TypeOf(x) {
return sub(@TypeOf(x), 0, x);
}
@ -365,7 +365,7 @@ pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {
/// Shifts left. Overflowed bits are truncated.
/// A negative shift amount results in a right shift.
pub fn shl(comptime T: type, a: T, shift_amt: var) T {
pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
const abs_shift_amt = absCast(shift_amt);
const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
@ -391,7 +391,7 @@ test "math.shl" {
/// Shifts right. Overflowed bits are truncated.
/// A negative shift amount results in a left shift.
pub fn shr(comptime T: type, a: T, shift_amt: var) T {
pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
const abs_shift_amt = absCast(shift_amt);
const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
@ -419,7 +419,7 @@ test "math.shr" {
/// Rotates right. Only unsigned values can be rotated.
/// Negative shift values results in shift modulo the bit count.
pub fn rotr(comptime T: type, x: T, r: var) T {
pub fn rotr(comptime T: type, x: T, r: anytype) T {
if (T.is_signed) {
@compileError("cannot rotate signed integer");
} else {
@ -438,7 +438,7 @@ test "math.rotr" {
/// Rotates left. Only unsigned values can be rotated.
/// Negative shift values results in shift modulo the bit count.
pub fn rotl(comptime T: type, x: T, r: var) T {
pub fn rotl(comptime T: type, x: T, r: anytype) T {
if (T.is_signed) {
@compileError("cannot rotate signed integer");
} else {
@ -541,7 +541,7 @@ fn testOverflow() void {
testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
}
pub fn absInt(x: var) !@TypeOf(x) {
pub fn absInt(x: anytype) !@TypeOf(x) {
const T = @TypeOf(x);
comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
comptime assert(T.is_signed); // must pass a signed integer to absInt
@ -689,7 +689,7 @@ fn testRem() void {
/// Returns the absolute value of the integer parameter.
/// Result is an unsigned integer.
pub fn absCast(x: var) switch (@typeInfo(@TypeOf(x))) {
pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
.ComptimeInt => comptime_int,
.Int => |intInfo| std.meta.Int(false, intInfo.bits),
else => @compileError("absCast only accepts integers"),
@ -724,7 +724,7 @@ test "math.absCast" {
/// Returns the negation of the integer parameter.
/// Result is a signed integer.
pub fn negateCast(x: var) !std.meta.Int(true, @TypeOf(x).bit_count) {
pub fn negateCast(x: anytype) !std.meta.Int(true, @TypeOf(x).bit_count) {
if (@TypeOf(x).is_signed) return negate(x);
const int = std.meta.Int(true, @TypeOf(x).bit_count);
@ -747,7 +747,7 @@ test "math.negateCast" {
/// Cast an integer to a different integer type. If the value doesn't fit,
/// return an error.
pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
pub fn cast(comptime T: type, x: anytype) (error{Overflow}!T) {
comptime assert(@typeInfo(T) == .Int); // must pass an integer
comptime assert(@typeInfo(@TypeOf(x)) == .Int); // must pass an integer
if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
@ -772,7 +772,7 @@ test "math.cast" {
pub const AlignCastError = error{UnalignedMemory};
/// Align cast a pointer but return an error if it's the wrong alignment
pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) {
pub fn alignCast(comptime alignment: u29, ptr: anytype) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) {
const addr = @ptrToInt(ptr);
if (addr % alignment != 0) {
return error.UnalignedMemory;
@ -780,7 +780,7 @@ pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@TypeOf(@alig
return @alignCast(alignment, ptr);
}
pub fn isPowerOfTwo(v: var) bool {
pub fn isPowerOfTwo(v: anytype) bool {
assert(v != 0);
return (v & (v - 1)) == 0;
}
@ -897,7 +897,7 @@ test "std.math.log2_int_ceil" {
testing.expect(log2_int_ceil(u32, 10) == 4);
}
pub fn lossyCast(comptime T: type, value: var) T {
pub fn lossyCast(comptime T: type, value: anytype) T {
switch (@typeInfo(@TypeOf(value))) {
.Int => return @intToFloat(T, value),
.Float => return @floatCast(T, value),
@ -1031,7 +1031,7 @@ pub const Order = enum {
};
/// Given two numbers, this function returns the order they are with respect to each other.
pub fn order(a: var, b: var) Order {
pub fn order(a: anytype, b: anytype) Order {
if (a == b) {
return .eq;
} else if (a < b) {
@ -1062,7 +1062,7 @@ pub const CompareOperator = enum {
/// This function does the same thing as comparison operators, however the
/// operator is a runtime-known enum value. Works on any operands that
/// support comparison operators.
pub fn compare(a: var, op: CompareOperator, b: var) bool {
pub fn compare(a: anytype, op: CompareOperator, b: anytype) bool {
return switch (op) {
.lt => a < b,
.lte => a <= b,

View File

@ -12,7 +12,7 @@ const expect = std.testing.expect;
///
/// Special cases:
/// - acos(x) = nan if x < -1 or x > 1
pub fn acos(x: var) @TypeOf(x) {
pub fn acos(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => acos32(x),

View File

@ -14,7 +14,7 @@ const expect = std.testing.expect;
/// Special cases:
/// - acosh(x) = snan if x < 1
/// - acosh(nan) = nan
pub fn acosh(x: var) @TypeOf(x) {
pub fn acosh(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => acosh32(x),

View File

@ -13,7 +13,7 @@ const expect = std.testing.expect;
/// Special Cases:
/// - asin(+-0) = +-0
/// - asin(x) = nan if x < -1 or x > 1
pub fn asin(x: var) @TypeOf(x) {
pub fn asin(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => asin32(x),

View File

@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;
/// - asinh(+-0) = +-0
/// - asinh(+-inf) = +-inf
/// - asinh(nan) = nan
pub fn asinh(x: var) @TypeOf(x) {
pub fn asinh(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => asinh32(x),

View File

@ -13,7 +13,7 @@ const expect = std.testing.expect;
/// Special Cases:
/// - atan(+-0) = +-0
/// - atan(+-inf) = +-pi/2
pub fn atan(x: var) @TypeOf(x) {
pub fn atan(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => atan32(x),

View File

@ -15,7 +15,7 @@ const maxInt = std.math.maxInt;
/// - atanh(+-1) = +-inf with signal
/// - atanh(x) = nan if |x| > 1 with signal
/// - atanh(nan) = nan
pub fn atanh(x: var) @TypeOf(x) {
pub fn atanh(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => atanh_32(x),

View File

@ -12,7 +12,7 @@ const assert = std.debug.assert;
/// Returns the number of limbs needed to store `scalar`, which must be a
/// primitive integer value.
pub fn calcLimbLen(scalar: var) usize {
pub fn calcLimbLen(scalar: anytype) usize {
const T = @TypeOf(scalar);
switch (@typeInfo(T)) {
.Int => |info| {
@ -110,7 +110,7 @@ pub const Mutable = struct {
/// `value` is a primitive integer type.
/// Asserts the value fits within the provided `limbs_buffer`.
/// Note: `calcLimbLen` can be used to figure out how big an array to allocate for `limbs_buffer`.
pub fn init(limbs_buffer: []Limb, value: var) Mutable {
pub fn init(limbs_buffer: []Limb, value: anytype) Mutable {
limbs_buffer[0] = 0;
var self: Mutable = .{
.limbs = limbs_buffer,
@ -169,7 +169,7 @@ pub const Mutable = struct {
/// Asserts the value fits within the limbs buffer.
/// Note: `calcLimbLen` can be used to figure out how big the limbs buffer
/// needs to be to store a specific value.
pub fn set(self: *Mutable, value: var) void {
pub fn set(self: *Mutable, value: anytype) void {
const T = @TypeOf(value);
switch (@typeInfo(T)) {
@ -281,7 +281,7 @@ pub const Mutable = struct {
///
/// Asserts the result fits in `r`. An upper bound on the number of limbs needed by
/// r is `math.max(a.limbs.len, calcLimbLen(scalar)) + 1`.
pub fn addScalar(r: *Mutable, a: Const, scalar: var) void {
pub fn addScalar(r: *Mutable, a: Const, scalar: anytype) void {
var limbs: [calcLimbLen(scalar)]Limb = undefined;
const operand = init(&limbs, scalar).toConst();
return add(r, a, operand);
@ -1058,7 +1058,7 @@ pub const Const = struct {
self: Const,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
out_stream: var,
out_stream: anytype,
) !void {
comptime var radix = 10;
comptime var uppercase = false;
@ -1261,7 +1261,7 @@ pub const Const = struct {
}
/// Same as `order` but the right-hand operand is a primitive integer.
pub fn orderAgainstScalar(lhs: Const, scalar: var) math.Order {
pub fn orderAgainstScalar(lhs: Const, scalar: anytype) math.Order {
var limbs: [calcLimbLen(scalar)]Limb = undefined;
const rhs = Mutable.init(&limbs, scalar);
return order(lhs, rhs.toConst());
@ -1333,7 +1333,7 @@ pub const Managed = struct {
/// Creates a new `Managed` with value `value`.
///
/// This is identical to an `init`, followed by a `set`.
pub fn initSet(allocator: *Allocator, value: var) !Managed {
pub fn initSet(allocator: *Allocator, value: anytype) !Managed {
var s = try Managed.init(allocator);
try s.set(value);
return s;
@ -1496,7 +1496,7 @@ pub const Managed = struct {
}
/// Sets an Managed to value. Value must be an primitive integer type.
pub fn set(self: *Managed, value: var) Allocator.Error!void {
pub fn set(self: *Managed, value: anytype) Allocator.Error!void {
try self.ensureCapacity(calcLimbLen(value));
var m = self.toMutable();
m.set(value);
@ -1549,7 +1549,7 @@ pub const Managed = struct {
self: Managed,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
out_stream: var,
out_stream: anytype,
) !void {
return self.toConst().format(fmt, options, out_stream);
}
@ -1607,7 +1607,7 @@ pub const Managed = struct {
/// scalar is a primitive integer type.
///
/// Returns an error if memory could not be allocated.
pub fn addScalar(r: *Managed, a: Const, scalar: var) Allocator.Error!void {
pub fn addScalar(r: *Managed, a: Const, scalar: anytype) Allocator.Error!void {
try r.ensureCapacity(math.max(a.limbs.len, calcLimbLen(scalar)) + 1);
var m = r.toMutable();
m.addScalar(a, scalar);

View File

@ -43,7 +43,7 @@ pub const Rational = struct {
}
/// Set a Rational from a primitive integer type.
pub fn setInt(self: *Rational, a: var) !void {
pub fn setInt(self: *Rational, a: anytype) !void {
try self.p.set(a);
try self.q.set(1);
}
@ -280,7 +280,7 @@ pub const Rational = struct {
}
/// Set a rational from an integer ratio.
pub fn setRatio(self: *Rational, p: var, q: var) !void {
pub fn setRatio(self: *Rational, p: anytype, q: anytype) !void {
try self.p.set(p);
try self.q.set(q);

View File

@ -14,7 +14,7 @@ const expect = std.testing.expect;
/// - cbrt(+-0) = +-0
/// - cbrt(+-inf) = +-inf
/// - cbrt(nan) = nan
pub fn cbrt(x: var) @TypeOf(x) {
pub fn cbrt(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => cbrt32(x),

View File

@ -15,7 +15,7 @@ const expect = std.testing.expect;
/// - ceil(+-0) = +-0
/// - ceil(+-inf) = +-inf
/// - ceil(nan) = nan
pub fn ceil(x: var) @TypeOf(x) {
pub fn ceil(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => ceil32(x),

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the absolute value (modulus) of z.
pub fn abs(z: var) @TypeOf(z.re) {
pub fn abs(z: anytype) @TypeOf(z.re) {
const T = @TypeOf(z.re);
return math.hypot(T, z.re, z.im);
}

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the arc-cosine of z.
pub fn acos(z: var) Complex(@TypeOf(z.re)) {
pub fn acos(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const q = cmath.asin(z);
return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the hyperbolic arc-cosine of z.
pub fn acosh(z: var) Complex(@TypeOf(z.re)) {
pub fn acosh(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const q = cmath.acos(z);
return Complex(T).new(-q.im, q.re);

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the angular component (in radians) of z.
pub fn arg(z: var) @TypeOf(z.re) {
pub fn arg(z: anytype) @TypeOf(z.re) {
const T = @TypeOf(z.re);
return math.atan2(T, z.im, z.re);
}

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
// Returns the arc-sine of z.
pub fn asin(z: var) Complex(@TypeOf(z.re)) {
pub fn asin(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const x = z.re;
const y = z.im;

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the hyperbolic arc-sine of z.
pub fn asinh(z: var) Complex(@TypeOf(z.re)) {
pub fn asinh(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const q = Complex(T).new(-z.im, z.re);
const r = cmath.asin(q);

View File

@ -12,7 +12,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the arc-tangent of z.
pub fn atan(z: var) @TypeOf(z) {
pub fn atan(z: anytype) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => atan32(z),

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the hyperbolic arc-tangent of z.
pub fn atanh(z: var) Complex(@TypeOf(z.re)) {
pub fn atanh(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const q = Complex(T).new(-z.im, z.re);
const r = cmath.atan(q);

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the complex conjugate of z.
pub fn conj(z: var) Complex(@TypeOf(z.re)) {
pub fn conj(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
return Complex(T).new(z.re, -z.im);
}

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the cosine of z.
pub fn cos(z: var) Complex(@TypeOf(z.re)) {
pub fn cos(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const p = Complex(T).new(-z.im, z.re);
return cmath.cosh(p);

View File

@ -14,7 +14,7 @@ const Complex = cmath.Complex;
const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
/// Returns the hyperbolic arc-cosine of z.
pub fn cosh(z: var) Complex(@TypeOf(z.re)) {
pub fn cosh(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => cosh32(z),

View File

@ -14,7 +14,7 @@ const Complex = cmath.Complex;
const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
/// Returns e raised to the power of z (e^z).
pub fn exp(z: var) @TypeOf(z) {
pub fn exp(z: anytype) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {

View File

@ -11,7 +11,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns exp(z) scaled to avoid overflow.
pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) {
pub fn ldexp_cexp(z: anytype, expt: i32) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the natural logarithm of z.
pub fn log(z: var) Complex(@TypeOf(z.re)) {
pub fn log(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const r = cmath.abs(z);
const phi = cmath.arg(z);

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the projection of z onto the riemann sphere.
pub fn proj(z: var) Complex(@TypeOf(z.re)) {
pub fn proj(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
if (math.isInf(z.re) or math.isInf(z.im)) {

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the sine of z.
pub fn sin(z: var) Complex(@TypeOf(z.re)) {
pub fn sin(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const p = Complex(T).new(-z.im, z.re);
const q = cmath.sinh(p);

View File

@ -14,7 +14,7 @@ const Complex = cmath.Complex;
const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
/// Returns the hyperbolic sine of z.
pub fn sinh(z: var) @TypeOf(z) {
pub fn sinh(z: anytype) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => sinh32(z),

View File

@ -12,7 +12,7 @@ const Complex = cmath.Complex;
/// Returns the square root of z. The real and imaginary parts of the result have the same sign
/// as the imaginary part of z.
pub fn sqrt(z: var) @TypeOf(z) {
pub fn sqrt(z: anytype) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {

View File

@ -5,7 +5,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the tanget of z.
pub fn tan(z: var) Complex(@TypeOf(z.re)) {
pub fn tan(z: anytype) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
const q = Complex(T).new(-z.im, z.re);
const r = cmath.tanh(q);

View File

@ -12,7 +12,7 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the hyperbolic tangent of z.
pub fn tanh(z: var) @TypeOf(z) {
pub fn tanh(z: anytype) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => tanh32(z),

View File

@ -13,7 +13,7 @@ const expect = std.testing.expect;
/// Special Cases:
/// - cos(+-inf) = nan
/// - cos(nan) = nan
pub fn cos(x: var) @TypeOf(x) {
pub fn cos(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => cos_(f32, x),

View File

@ -17,7 +17,7 @@ const maxInt = std.math.maxInt;
/// - cosh(+-0) = 1
/// - cosh(+-inf) = +inf
/// - cosh(nan) = nan
pub fn cosh(x: var) @TypeOf(x) {
pub fn cosh(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => cosh32(x),

View File

@ -14,7 +14,7 @@ const builtin = @import("builtin");
/// Special Cases:
/// - exp(+inf) = +inf
/// - exp(nan) = nan
pub fn exp(x: var) @TypeOf(x) {
pub fn exp(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => exp32(x),

View File

@ -13,7 +13,7 @@ const expect = std.testing.expect;
/// Special Cases:
/// - exp2(+inf) = +inf
/// - exp2(nan) = nan
pub fn exp2(x: var) @TypeOf(x) {
pub fn exp2(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => exp2_32(x),

View File

@ -18,7 +18,7 @@ const expect = std.testing.expect;
/// - expm1(+inf) = +inf
/// - expm1(-inf) = -1
/// - expm1(nan) = nan
pub fn expm1(x: var) @TypeOf(x) {
pub fn expm1(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => expm1_32(x),

View File

@ -7,7 +7,7 @@
const math = @import("../math.zig");
/// Returns exp(x) / 2 for x >= log(maxFloat(T)).
pub fn expo2(x: var) @TypeOf(x) {
pub fn expo2(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => expo2f(x),

View File

@ -14,7 +14,7 @@ const maxInt = std.math.maxInt;
/// Special Cases:
/// - fabs(+-inf) = +inf
/// - fabs(nan) = nan
pub fn fabs(x: var) @TypeOf(x) {
pub fn fabs(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f16 => fabs16(x),

View File

@ -15,7 +15,7 @@ const math = std.math;
/// - floor(+-0) = +-0
/// - floor(+-inf) = +-inf
/// - floor(nan) = nan
pub fn floor(x: var) @TypeOf(x) {
pub fn floor(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f16 => floor16(x),

View File

@ -24,7 +24,7 @@ pub const frexp64_result = frexp_result(f64);
/// - frexp(+-0) = +-0, 0
/// - frexp(+-inf) = +-inf, 0
/// - frexp(nan) = nan, undefined
pub fn frexp(x: var) frexp_result(@TypeOf(x)) {
pub fn frexp(x: anytype) frexp_result(@TypeOf(x)) {
const T = @TypeOf(x);
return switch (T) {
f32 => frexp32(x),

View File

@ -16,7 +16,7 @@ const minInt = std.math.minInt;
/// - ilogb(+-inf) = maxInt(i32)
/// - ilogb(0) = maxInt(i32)
/// - ilogb(nan) = maxInt(i32)
pub fn ilogb(x: var) i32 {
pub fn ilogb(x: anytype) i32 {
const T = @TypeOf(x);
return switch (T) {
f32 => ilogb32(x),

View File

@ -4,7 +4,7 @@ const expect = std.testing.expect;
const maxInt = std.math.maxInt;
/// Returns whether x is a finite value.
pub fn isFinite(x: var) bool {
pub fn isFinite(x: anytype) bool {
const T = @TypeOf(x);
switch (T) {
f16 => {

View File

@ -4,7 +4,7 @@ const expect = std.testing.expect;
const maxInt = std.math.maxInt;
/// Returns whether x is an infinity, ignoring sign.
pub fn isInf(x: var) bool {
pub fn isInf(x: anytype) bool {
const T = @TypeOf(x);
switch (T) {
f16 => {
@ -30,7 +30,7 @@ pub fn isInf(x: var) bool {
}
/// Returns whether x is an infinity with a positive sign.
pub fn isPositiveInf(x: var) bool {
pub fn isPositiveInf(x: anytype) bool {
const T = @TypeOf(x);
switch (T) {
f16 => {
@ -52,7 +52,7 @@ pub fn isPositiveInf(x: var) bool {
}
/// Returns whether x is an infinity with a negative sign.
pub fn isNegativeInf(x: var) bool {
pub fn isNegativeInf(x: anytype) bool {
const T = @TypeOf(x);
switch (T) {
f16 => {

View File

@ -4,12 +4,12 @@ const expect = std.testing.expect;
const maxInt = std.math.maxInt;
/// Returns whether x is a nan.
pub fn isNan(x: var) bool {
pub fn isNan(x: anytype) bool {
return x != x;
}
/// Returns whether x is a signalling nan.
pub fn isSignalNan(x: var) bool {
pub fn isSignalNan(x: anytype) bool {
// Note: A signalling nan is identical to a standard nan right now but may have a different bit
// representation in the future when required.
return isNan(x);

View File

@ -4,7 +4,7 @@ const expect = std.testing.expect;
const maxInt = std.math.maxInt;
// Returns whether x has a normalized representation (i.e. integer part of mantissa is 1).
pub fn isNormal(x: var) bool {
pub fn isNormal(x: anytype) bool {
const T = @TypeOf(x);
switch (T) {
f16 => {

View File

@ -15,7 +15,7 @@ const expect = std.testing.expect;
/// - ln(0) = -inf
/// - ln(x) = nan if x < 0
/// - ln(nan) = nan
pub fn ln(x: var) @TypeOf(x) {
pub fn ln(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeInfo(T)) {
.ComptimeFloat => {

View File

@ -16,7 +16,7 @@ const maxInt = std.math.maxInt;
/// - log10(0) = -inf
/// - log10(x) = nan if x < 0
/// - log10(nan) = nan
pub fn log10(x: var) @TypeOf(x) {
pub fn log10(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeInfo(T)) {
.ComptimeFloat => {

View File

@ -17,7 +17,7 @@ const expect = std.testing.expect;
/// - log1p(-1) = -inf
/// - log1p(x) = nan if x < -1
/// - log1p(nan) = nan
pub fn log1p(x: var) @TypeOf(x) {
pub fn log1p(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => log1p_32(x),

View File

@ -16,7 +16,7 @@ const maxInt = std.math.maxInt;
/// - log2(0) = -inf
/// - log2(x) = nan if x < 0
/// - log2(nan) = nan
pub fn log2(x: var) @TypeOf(x) {
pub fn log2(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeInfo(T)) {
.ComptimeFloat => {

View File

@ -24,7 +24,7 @@ pub const modf64_result = modf_result(f64);
/// Special Cases:
/// - modf(+-inf) = +-inf, nan
/// - modf(nan) = nan, nan
pub fn modf(x: var) modf_result(@TypeOf(x)) {
pub fn modf(x: anytype) modf_result(@TypeOf(x)) {
const T = @TypeOf(x);
return switch (T) {
f32 => modf32(x),

View File

@ -15,7 +15,7 @@ const math = std.math;
/// - round(+-0) = +-0
/// - round(+-inf) = +-inf
/// - round(nan) = nan
pub fn round(x: var) @TypeOf(x) {
pub fn round(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => round32(x),

View File

@ -9,7 +9,7 @@ const math = std.math;
const expect = std.testing.expect;
/// Returns x * 2^n.
pub fn scalbn(x: var, n: i32) @TypeOf(x) {
pub fn scalbn(x: anytype, n: i32) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => scalbn32(x, n),

View File

@ -3,7 +3,7 @@ const math = std.math;
const expect = std.testing.expect;
/// Returns whether x is negative or negative 0.
pub fn signbit(x: var) bool {
pub fn signbit(x: anytype) bool {
const T = @TypeOf(x);
return switch (T) {
f16 => signbit16(x),

View File

@ -14,7 +14,7 @@ const expect = std.testing.expect;
/// - sin(+-0) = +-0
/// - sin(+-inf) = nan
/// - sin(nan) = nan
pub fn sin(x: var) @TypeOf(x) {
pub fn sin(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => sin_(T, x),

View File

@ -17,7 +17,7 @@ const maxInt = std.math.maxInt;
/// - sinh(+-0) = +-0
/// - sinh(+-inf) = +-inf
/// - sinh(nan) = nan
pub fn sinh(x: var) @TypeOf(x) {
pub fn sinh(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => sinh32(x),

View File

@ -13,7 +13,7 @@ const maxInt = std.math.maxInt;
/// - sqrt(x) = nan if x < 0
/// - sqrt(nan) = nan
/// TODO Decide if all this logic should be implemented directly in the @sqrt bultin function.
pub fn sqrt(x: var) Sqrt(@TypeOf(x)) {
pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) {
const T = @TypeOf(x);
switch (@typeInfo(T)) {
.Float, .ComptimeFloat => return @sqrt(x),

View File

@ -14,7 +14,7 @@ const expect = std.testing.expect;
/// - tan(+-0) = +-0
/// - tan(+-inf) = nan
/// - tan(nan) = nan
pub fn tan(x: var) @TypeOf(x) {
pub fn tan(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => tan_(f32, x),

View File

@ -17,7 +17,7 @@ const maxInt = std.math.maxInt;
/// - sinh(+-0) = +-0
/// - sinh(+-inf) = +-1
/// - sinh(nan) = nan
pub fn tanh(x: var) @TypeOf(x) {
pub fn tanh(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => tanh32(x),

Some files were not shown because too many files have changed in this diff Show More