Merge branch 'Snektron-typeOf-to-TypeOf'

closes #3875
closes #1348
This commit is contained in:
Andrew Kelley 2019-12-10 11:13:39 -05:00
commit 9561e7c6b9
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
134 changed files with 604 additions and 585 deletions

View File

@ -307,7 +307,7 @@ pub fn main() void {
assert(optional_value == null);
warn("\noptional 1\ntype: {}\nvalue: {}\n", .{
@typeName(@typeOf(optional_value)),
@typeName(@TypeOf(optional_value)),
optional_value,
});
@ -315,7 +315,7 @@ pub fn main() void {
assert(optional_value != null);
warn("\noptional 2\ntype: {}\nvalue: {}\n", .{
@typeName(@typeOf(optional_value)),
@typeName(@TypeOf(optional_value)),
optional_value,
});
@ -323,14 +323,14 @@ pub fn main() void {
var number_or_error: anyerror!i32 = error.ArgNotFound;
warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{
@typeName(@typeOf(number_or_error)),
@typeName(@TypeOf(number_or_error)),
number_or_error,
});
number_or_error = 1234;
warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{
@typeName(@typeOf(number_or_error)),
@typeName(@TypeOf(number_or_error)),
number_or_error,
});
}
@ -572,7 +572,7 @@ const mem = @import("std").mem;
test "string literals" {
const bytes = "hello";
assert(@typeOf(bytes) == *const [5:0]u8);
assert(@TypeOf(bytes) == *const [5:0]u8);
assert(bytes.len == 5);
assert(bytes[1] == 'e');
assert(bytes[5] == 0);
@ -1802,7 +1802,7 @@ const assert = std.debug.assert;
test "null terminated array" {
const array = [_:0]u8 {1, 2, 3, 4};
assert(@typeOf(array) == [4:0]u8);
assert(@TypeOf(array) == [4:0]u8);
assert(array.len == 4);
assert(array[4] == 0);
}
@ -1885,12 +1885,12 @@ test "address of syntax" {
assert(x_ptr.* == 1234);
// When you get the address of a const variable, you get a const pointer to a single item.
assert(@typeOf(x_ptr) == *const i32);
assert(@TypeOf(x_ptr) == *const i32);
// If you want to mutate the value, you'd need an address of a mutable variable:
var y: i32 = 5678;
const y_ptr = &y;
assert(@typeOf(y_ptr) == *i32);
assert(@TypeOf(y_ptr) == *i32);
y_ptr.* += 1;
assert(y_ptr.* == 5679);
}
@ -1901,7 +1901,7 @@ test "pointer array access" {
// does not support pointer arithmetic.
var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const ptr = &array[2];
assert(@typeOf(ptr) == *u8);
assert(@TypeOf(ptr) == *u8);
assert(array[2] == 3);
ptr.* += 1;
@ -1953,7 +1953,7 @@ const assert = @import("std").debug.assert;
test "@ptrToInt and @intToPtr" {
const ptr = @intToPtr(*i32, 0xdeadbeef);
const addr = @ptrToInt(ptr);
assert(@typeOf(addr) == usize);
assert(@TypeOf(addr) == usize);
assert(addr == 0xdeadbeef);
}
{#code_end#}
@ -1968,7 +1968,7 @@ test "comptime @intToPtr" {
// ptr is never dereferenced.
const ptr = @intToPtr(*i32, 0xdeadbeef);
const addr = @ptrToInt(ptr);
assert(@typeOf(addr) == usize);
assert(@TypeOf(addr) == usize);
assert(addr == 0xdeadbeef);
}
}
@ -1984,7 +1984,7 @@ const assert = @import("std").debug.assert;
test "volatile" {
const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
assert(@typeOf(mmio_ptr) == *volatile u8);
assert(@TypeOf(mmio_ptr) == *volatile u8);
}
{#code_end#}
<p>
@ -2041,8 +2041,8 @@ const builtin = @import("builtin");
test "variable alignment" {
var x: i32 = 1234;
const align_of_i32 = @alignOf(@typeOf(x));
assert(@typeOf(&x) == *i32);
const align_of_i32 = @alignOf(@TypeOf(x));
assert(@TypeOf(&x) == *i32);
assert(*i32 == *align(align_of_i32) i32);
if (builtin.arch == builtin.Arch.x86_64) {
assert((*i32).alignment == 4);
@ -2063,10 +2063,10 @@ const assert = @import("std").debug.assert;
var foo: u8 align(4) = 100;
test "global variable alignment" {
assert(@typeOf(&foo).alignment == 4);
assert(@typeOf(&foo) == *align(4) u8);
assert(@TypeOf(&foo).alignment == 4);
assert(@TypeOf(&foo) == *align(4) u8);
const slice = @as(*[1]u8, &foo)[0..];
assert(@typeOf(slice) == []align(4) u8);
assert(@TypeOf(slice) == []align(4) u8);
}
fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
@ -2075,8 +2075,8 @@ fn noop4() align(4) void {}
test "function alignment" {
assert(derp() == 1234);
assert(@typeOf(noop1) == fn() align(1) void);
assert(@typeOf(noop4) == fn() align(4) void);
assert(@TypeOf(noop1) == fn() align(1) void);
assert(@TypeOf(noop4) == fn() align(4) void);
noop1();
noop4();
}
@ -2162,8 +2162,8 @@ test "basic slices" {
// Using the address-of operator on a slice gives a pointer to a single
// item, while using the `ptr` field gives an unknown length pointer.
assert(@typeOf(slice.ptr) == [*]i32);
assert(@typeOf(&slice[0]) == *i32);
assert(@TypeOf(slice.ptr) == [*]i32);
assert(@TypeOf(&slice[0]) == *i32);
assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
// Slices have array bounds checking. If you try to access something out
@ -2208,7 +2208,7 @@ test "slice pointer" {
slice[2] = 3;
assert(slice[2] == 3);
// The slice is mutable because we sliced a mutable pointer.
assert(@typeOf(slice) == []u8);
assert(@TypeOf(slice) == []u8);
// You can also slice a slice:
const slice2 = slice[2..3];
@ -3566,7 +3566,7 @@ test "for basics" {
// This is zero-indexed.
var sum2: i32 = 0;
for (items) |value, i| {
assert(@typeOf(i) == usize);
assert(@TypeOf(i) == usize);
sum2 += @intCast(i32, i);
}
assert(sum2 == 10);
@ -3909,7 +3909,7 @@ test "type of unreachable" {
// However this assertion will still fail because
// evaluating unreachable at compile-time is a compile error.
assert(@typeOf(unreachable) == noreturn);
assert(@TypeOf(unreachable) == noreturn);
}
}
{#code_end#}
@ -4018,7 +4018,7 @@ test "function" {
const assert = @import("std").debug.assert;
comptime {
assert(@typeOf(foo) == fn()void);
assert(@TypeOf(foo) == fn()void);
assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
}
@ -4062,35 +4062,35 @@ test "pass struct to function" {
</p>
{#header_close#}
{#header_open|Function Parameter Type Inference#}
<p>
Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type.
<p>
Function parameters can be declared with {#syntax#}var{#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.
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: var) @TypeOf(x) {
return x + 42;
}
test "fn type inference" {
assert(addFortyTwo(1) == 43);
assert(@typeOf(addFortyTwo(1)) == comptime_int);
assert(@TypeOf(addFortyTwo(1)) == comptime_int);
var y: i64 = 2;
assert(addFortyTwo(y) == 44);
assert(@typeOf(addFortyTwo(y)) == i64);
assert(@TypeOf(addFortyTwo(y)) == i64);
}
{#code_end#}
{#header_close#}
{#header_open|Function Reflection#}
{#code_begin|test#}
const assert = @import("std").debug.assert;
test "fn reflection" {
assert(@typeOf(assert).ReturnType == void);
assert(@typeOf(assert).is_var_args == false);
assert(@TypeOf(assert).ReturnType == void);
assert(@TypeOf(assert).is_var_args == false);
}
{#code_end#}
{#header_close#}
@ -4390,10 +4390,10 @@ test "error union" {
foo = error.SomeError;
// Use compile-time reflection to access the payload type of an error union:
comptime assert(@typeOf(foo).Payload == i32);
comptime assert(@TypeOf(foo).Payload == i32);
// Use compile-time reflection to access the error set type of an error union:
comptime assert(@typeOf(foo).ErrorSet == anyerror);
comptime assert(@TypeOf(foo).ErrorSet == anyerror);
}
{#code_end#}
{#header_open|Merging Error Sets#}
@ -4770,7 +4770,7 @@ test "optional type" {
foo = 1234;
// Use compile-time reflection to access the child type of the optional:
comptime assert(@typeOf(foo).Child == i32);
comptime assert(@TypeOf(foo).Child == i32);
}
{#code_end#}
{#header_close#}
@ -5154,7 +5154,7 @@ test "peer resolve int widening" {
var b: i16 = 34;
var c = a + b;
assert(c == 46);
assert(@typeOf(c) == i16);
assert(@TypeOf(c) == i16);
}
test "peer resolve arrays of different size to const slice" {
@ -5949,7 +5949,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {
</p>
{#code_begin|syntax#}
pub fn printValue(self: *OutStream, value: var) !void {
const T = @typeOf(value);
const T = @TypeOf(value);
if (@isInteger(T)) {
return self.printInt(T, value);
} else if (@isFloat(T)) {
@ -6265,7 +6265,7 @@ test "async function suspend with block" {
fn testSuspendBlock() void {
suspend {
comptime assert(@typeOf(@frame()) == *@Frame(testSuspendBlock));
comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
the_frame = @frame();
}
result = true;
@ -6332,7 +6332,7 @@ test "async and await" {
fn amain() void {
var frame = async func();
comptime assert(@typeOf(frame) == @Frame(func));
comptime assert(@TypeOf(frame) == @Frame(func));
const ptr: anyframe->void = &frame;
const any_ptr: anyframe = ptr;
@ -6740,7 +6740,7 @@ async fn func(y: *i32) void {
Converts a value of one type to another type.
</p>
<p>
Asserts that {#syntax#}@sizeOf(@typeOf(value)) == @sizeOf(DestType){#endsyntax#}.
Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
</p>
<p>
Asserts that {#syntax#}@typeId(DestType) != @import("builtin").TypeId.Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.
@ -7045,7 +7045,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v
<p>
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
</p>
<p>{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
{#see_also|Compile Variables|cmpxchgWeak#}
{#header_close#}
{#header_open|@cmpxchgWeak#}
@ -7073,7 +7073,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
<p>
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
</p>
<p>{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
<p>{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
{#see_also|Compile Variables|cmpxchgStrong#}
{#header_close#}
@ -8020,7 +8020,7 @@ test "@setRuntimeSafety" {
{#header_close#}
{#header_open|@splat#}
<pre>{#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @typeOf(scalar)){#endsyntax#}</pre>
<pre>{#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @TypeOf(scalar)){#endsyntax#}</pre>
<p>
Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value
{#syntax#}scalar{#endsyntax#}:
@ -8032,7 +8032,7 @@ const assert = std.debug.assert;
test "vector @splat" {
const scalar: u32 = 5;
const result = @splat(4, scalar);
comptime assert(@typeOf(result) == @Vector(4, u32));
comptime assert(@TypeOf(result) == @Vector(4, u32));
assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}
{#code_end#}
@ -8250,8 +8250,8 @@ test "integer truncation" {
<li>{#link|Pointers#}</li>
<li>{#syntax#}comptime_int{#endsyntax#}</li>
<li>{#syntax#}comptime_float{#endsyntax#}</li>
<li>{#syntax#}@typeOf(undefined){#endsyntax#}</li>
<li>{#syntax#}@typeOf(null){#endsyntax#}</li>
<li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li>
<li>{#syntax#}@TypeOf(null){#endsyntax#}</li>
</ul>
<p>
For these types it is a
@ -8516,20 +8516,20 @@ pub const TypeInfo = union(TypeId) {
{#header_close#}
{#header_open|@typeOf#}
<pre>{#syntax#}@typeOf(expression) type{#endsyntax#}</pre>
{#header_open|@TypeOf#}
<pre>{#syntax#}@TypeOf(expression) type{#endsyntax#}</pre>
<p>
This function returns a compile-time constant, which is the type of the
expression passed as an argument. The expression is evaluated.
</p>
<p>{#syntax#}@typeOf{#endsyntax#} guarantees no run-time side-effects within the expression:</p>
<p>{#syntax#}@TypeOf{#endsyntax#} guarantees no run-time side-effects within the expression:</p>
{#code_begin|test#}
const std = @import("std");
const assert = std.debug.assert;
test "no runtime side effects" {
var data: i32 = 0;
const T = @typeOf(foo(i32, &data));
const T = @TypeOf(foo(i32, &data));
comptime assert(T == i32);
assert(data == 0);
}

View File

@ -40,7 +40,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
.allocator = allocator,
};
}
/// Initialize with capacity to hold at least num elements.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn initCapacity(allocator: *Allocator, num: usize) !Self {

View File

@ -106,7 +106,7 @@ pub fn Queue(comptime T: type) type {
pub fn dump(self: *Self) void {
var stderr_file = std.io.getStdErr() catch return;
const stderr = &stderr_file.outStream().stream;
const Error = @typeInfo(@typeOf(stderr)).Pointer.child.Error;
const Error = @typeInfo(@TypeOf(stderr)).Pointer.child.Error;
self.dumpToStream(Error, stderr) catch return;
}

View File

@ -9,7 +9,7 @@ const expect = std.testing.expect;
pub fn Stack(comptime T: type) type {
return struct {
root: ?*Node,
lock: @typeOf(lock_init),
lock: @TypeOf(lock_init),
const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);

View File

@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct {
try di.dwarf_seekable_stream.seekTo(this_unit_offset);
var is_64: bool = undefined;
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
if (unit_length == 0) return;
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
@ -1392,7 +1392,7 @@ pub const DwarfInfo = struct {
try di.dwarf_seekable_stream.seekTo(this_unit_offset);
var is_64: bool = undefined;
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
if (unit_length == 0) return;
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
@ -1551,7 +1551,7 @@ pub const DwarfInfo = struct {
try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset);
var is_64: bool = undefined;
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
if (unit_length == 0) {
return error.MissingDebugInfo;
}
@ -2080,7 +2080,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },
DW.FORM_indirect => {
const child_form_id = try noasync leb.readULEB128(u64, in_stream);
const F = @typeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64));
const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64));
var frame = try allocator.create(F);
defer allocator.destroy(frame);
return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64);

View File

@ -61,7 +61,7 @@ pub fn Group(comptime ReturnType: type) type {
/// `func` must be async and have return type `ReturnType`.
/// Thread-safe.
pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void {
var frame = try self.allocator.create(@typeOf(@call(.{ .modifier = .async_kw }, func, args)));
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);
errdefer self.allocator.destroy(node);

View File

@ -42,7 +42,7 @@ pub const Loop = struct {
},
else => {},
};
pub const Overlapped = @typeOf(overlapped_init);
pub const Overlapped = @TypeOf(overlapped_init);
pub const Id = enum {
Basic,

View File

@ -80,7 +80,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
///
/// If a formatted user type contains a function of the type
/// ```
/// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void
/// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, output: fn (@TypeOf(context), []const u8) Errors!void) Errors!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.
@ -89,7 +89,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
pub fn format(
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
comptime fmt: []const u8,
args: var,
) Errors!void {
@ -320,17 +320,17 @@ pub fn formatType(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
max_depth: usize,
) Errors!void {
if (comptime std.mem.eql(u8, fmt, "*")) {
try output(context, @typeName(@typeOf(value).Child));
try output(context, @typeName(@TypeOf(value).Child));
try output(context, "@");
try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output);
return;
}
const T = @typeOf(value);
const T = @TypeOf(value);
switch (@typeInfo(T)) {
.ComptimeInt, .Int, .Float => {
return formatValue(value, fmt, options, context, Errors, output);
@ -478,7 +478,7 @@ fn formatValue(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (comptime std.mem.eql(u8, fmt, "B")) {
return formatBytes(value, options, 1000, context, Errors, output);
@ -486,7 +486,7 @@ fn formatValue(
return formatBytes(value, options, 1024, context, Errors, output);
}
const T = @typeOf(value);
const T = @TypeOf(value);
switch (@typeId(T)) {
.Float => return formatFloatValue(value, fmt, options, context, Errors, output),
.Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
@ -500,12 +500,12 @@ pub fn formatIntValue(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
comptime var radix = 10;
comptime var uppercase = false;
const int_value = if (@typeOf(value) == comptime_int) blk: {
const int_value = if (@TypeOf(value) == comptime_int) blk: {
const Int = math.IntFittingRange(value, value);
break :blk @as(Int, value);
} else
@ -515,7 +515,7 @@ pub fn formatIntValue(
radix = 10;
uppercase = false;
} else if (comptime std.mem.eql(u8, fmt, "c")) {
if (@typeOf(int_value).bit_count <= 8) {
if (@TypeOf(int_value).bit_count <= 8) {
return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
} else {
@compileError("Cannot print integer that is larger than 8 bits as a ascii");
@ -542,7 +542,7 @@ fn formatFloatValue(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {
return formatFloatScientific(value, options, context, Errors, output);
@ -559,7 +559,7 @@ pub fn formatText(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (fmt.len == 0) {
return output(context, bytes);
@ -580,7 +580,7 @@ pub fn formatAsciiChar(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
return output(context, @as(*const [1]u8, &c)[0..]);
}
@ -590,7 +590,7 @@ pub fn formatBuf(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
try output(context, buf);
@ -610,7 +610,7 @@ pub fn formatFloatScientific(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
var x = @floatCast(f64, value);
@ -672,7 +672,7 @@ pub fn formatFloatScientific(
try output(context, float_decimal.digits[0..1]);
try output(context, ".");
if (float_decimal.digits.len > 1) {
const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
const num_digits = if (@TypeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
try output(context, float_decimal.digits[1..num_digits]);
} else {
@ -705,7 +705,7 @@ pub fn formatFloatDecimal(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
var x = @as(f64, value);
@ -851,7 +851,7 @@ pub fn formatBytes(
comptime radix: usize,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (value == 0) {
return output(context, "0B");
@ -892,15 +892,15 @@ pub fn formatInt(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
const int_value = if (@typeOf(value) == comptime_int) blk: {
const int_value = if (@TypeOf(value) == comptime_int) blk: {
const Int = math.IntFittingRange(value, value);
break :blk @as(Int, value);
} else
value;
if (@typeOf(int_value).is_signed) {
if (@TypeOf(int_value).is_signed) {
return formatIntSigned(int_value, base, uppercase, options, context, Errors, output);
} else {
return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output);
@ -914,7 +914,7 @@ fn formatIntSigned(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
const new_options = FormatOptions{
.width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null,
@ -922,7 +922,7 @@ fn formatIntSigned(
.fill = options.fill,
};
const uint = @IntType(false, @typeOf(value).bit_count);
const uint = @IntType(false, @TypeOf(value).bit_count);
if (value < 0) {
const minus_sign: u8 = '-';
try output(context, @as(*const [1]u8, &minus_sign)[0..]);
@ -945,12 +945,12 @@ fn formatIntUnsigned(
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
assert(base >= 2);
var buf: [math.max(@typeOf(value).bit_count, 1)]u8 = undefined;
const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count);
const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits);
var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count);
const MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits);
var a: MinInt = value;
var index: usize = buf.len;
@ -1420,7 +1420,7 @@ test "custom" {
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
@ -1610,7 +1610,7 @@ test "formatIntValue with comptime_int" {
const value: comptime_int = 123456789123456789;
var buf = try std.Buffer.init(std.debug.global_allocator, "");
try formatIntValue(value, "", FormatOptions{}, &buf, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);
try formatIntValue(value, "", FormatOptions{}, &buf, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);
std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789"));
}
@ -1626,7 +1626,7 @@ test "formatType max_depth" {
options: FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (fmt.len == 0) {
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
@ -1664,19 +1664,19 @@ test "formatType max_depth" {
inst.tu.ptr = &inst.tu;
var buf0 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf0, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);
try formatType(inst, "", FormatOptions{}, &buf0, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);
std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }"));
var buf1 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf1, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);
try formatType(inst, "", FormatOptions{}, &buf1, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);
std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
var buf2 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf2, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);
try formatType(inst, "", FormatOptions{}, &buf2, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);
std.testing.expect(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
var buf3 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf3, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);
try formatType(inst, "", FormatOptions{}, &buf3, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);
std.testing.expect(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
}

View File

@ -22,7 +22,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 {
const info = @typeInfo(@typeOf(key));
const info = @typeInfo(@TypeOf(key));
switch (info.Pointer.size) {
builtin.TypeInfo.Pointer.Size.One => switch (strat) {
@ -74,7 +74,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 {
const Key = @typeOf(key);
const Key = @TypeOf(key);
switch (@typeInfo(Key)) {
.NoReturn,
.Opaque,
@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
/// 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 {
const Key = @typeOf(key);
const Key = @TypeOf(key);
if (comptime meta.trait.isSlice(Key)) {
comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
const extra_help = if (Key == []const u8)

View File

@ -360,9 +360,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var hashes: [hashbytes * 256]u8 = undefined;
var final: [hashbytes]u8 = undefined;
@memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key)));
@memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes)));
@memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final)));
@memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key)));
@memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes)));
@memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final)));
var i: u32 = 0;
while (i < 256) : (i += 1) {
@ -370,7 +370,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var h = hash_fn(key[0..i], 256 - i);
if (builtin.endian == builtin.Endian.Big)
h = @byteSwap(@typeOf(h), h);
h = @byteSwap(@TypeOf(h), h);
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
}

View File

@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var hashes: [hashbytes * 256]u8 = undefined;
var final: [hashbytes]u8 = undefined;
@memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key)));
@memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes)));
@memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final)));
@memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key)));
@memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes)));
@memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final)));
var i: u32 = 0;
while (i < 256) : (i += 1) {
@ -295,7 +295,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var h = hash_fn(key[0..i], 256 - i);
if (builtin.endian == builtin.Endian.Big)
h = @byteSwap(@typeOf(h), h);
h = @byteSwap(@TypeOf(h), h);
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
}

View File

@ -367,7 +367,7 @@ pub const Headers = struct {
options: std.fmt.FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
var it = self.iterator();
while (it.next()) |entry| {

View File

@ -663,7 +663,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
pub fn writeBits(self: *Self, value: var, bits: usize) Error!void {
if (bits == 0) return;
const U = @typeOf(value);
const U = @TypeOf(value);
comptime assert(trait.isUnsignedInt(U));
//by extending the buffer to a minimum of u8 we can cover a number of edge cases
@ -962,7 +962,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 {
const T = @typeOf(ptr);
const T = @TypeOf(ptr);
comptime assert(trait.is(builtin.TypeId.Pointer)(T));
if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) {
@ -1091,7 +1091,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
}
fn serializeInt(self: *Self, value: var) Error!void {
const T = @typeOf(value);
const T = @TypeOf(value);
comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
const t_bit_count = comptime meta.bitCount(T);
@ -1123,7 +1123,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 {
const T = comptime @typeOf(value);
const T = comptime @TypeOf(value);
if (comptime trait.isIndexable(T)) {
for (value) |v|

View File

@ -1038,7 +1038,7 @@ pub const Value = union(enum) {
}
pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void {
var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream);
var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
w.newline = "";
w.one_indent = "";
w.space = "";
@ -1048,7 +1048,7 @@ pub const Value = union(enum) {
pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void {
var one_indent = " " ** indent;
var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream);
var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
w.one_indent = one_indent;
try w.emitJson(self);
}
@ -1338,7 +1338,7 @@ test "write json then parse it" {
var slice_out_stream = std.io.SliceOutStream.init(&out_buffer);
const out_stream = &slice_out_stream.stream;
var jw = WriteStream(@typeOf(out_stream).Child, 4).init(out_stream);
var jw = WriteStream(@TypeOf(out_stream).Child, 4).init(out_stream);
try jw.beginObject();

View File

@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
value: var,
) !void {
assert(self.state[self.state_index] == State.Value);
switch (@typeInfo(@typeOf(value))) {
switch (@typeInfo(@TypeOf(value))) {
.Int => |info| {
if (info.bits < 53) {
try self.stream.print("{}", .{value});
@ -257,7 +257,7 @@ test "json write stream" {
var mem_buf: [1024 * 10]u8 = undefined;
const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator;
var w = std.json.WriteStream(@typeOf(out).Child, 10).init(out);
var w = std.json.WriteStream(@TypeOf(out).Child, 10).init(out);
try w.emitJson(try getJson(allocator));
const result = slice_stream.getWritten();

View File

@ -95,7 +95,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 {
const T = @typeOf(value);
const T = @TypeOf(value);
switch (T) {
f16 => {
var x: f16 = undefined;
@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type {
},
else => {},
}
return @typeOf(@as(A, 0) + @as(B, 0));
return @TypeOf(@as(A, 0) + @as(B, 0));
}
/// 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)) {
const Result = Min(@typeOf(x), @typeOf(y));
pub fn min(x: var, y: var) 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
// scope it is known to fit in the return type.
@ -269,33 +269,33 @@ test "math.min" {
var a: u16 = 999;
var b: u32 = 10;
var result = min(a, b);
testing.expect(@typeOf(result) == u16);
testing.expect(@TypeOf(result) == u16);
testing.expect(result == 10);
}
{
var a: f64 = 10.34;
var b: f32 = 999.12;
var result = min(a, b);
testing.expect(@typeOf(result) == f64);
testing.expect(@TypeOf(result) == f64);
testing.expect(result == 10.34);
}
{
var a: i8 = -127;
var b: i16 = -200;
var result = min(a, b);
testing.expect(@typeOf(result) == i16);
testing.expect(@TypeOf(result) == i16);
testing.expect(result == -200);
}
{
const a = 10.34;
var b: f32 = 999.12;
var result = min(a, b);
testing.expect(@typeOf(result) == f32);
testing.expect(@TypeOf(result) == f32);
testing.expect(result == 10.34);
}
}
pub fn max(x: var, y: var) @typeOf(x + y) {
pub fn max(x: var, y: var) @TypeOf(x + y) {
return if (x > y) x else y;
}
@ -318,8 +318,8 @@ 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) {
return sub(@typeOf(x), 0, x);
pub fn negate(x: var) !@TypeOf(x) {
return sub(@TypeOf(x), 0, x);
}
pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {
@ -333,7 +333,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) 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);
if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) {
if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
if (shift_amt < 0) {
return a >> casted_shift_amt;
}
@ -359,7 +359,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) 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);
if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) {
if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
if (shift_amt >= 0) {
return a >> casted_shift_amt;
} else {
@ -505,12 +505,12 @@ fn testOverflow() void {
testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
}
pub fn absInt(x: var) !@typeOf(x) {
const T = @typeOf(x);
pub fn absInt(x: var) !@TypeOf(x) {
const T = @TypeOf(x);
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
comptime assert(T.is_signed); // must pass a signed integer to absInt
if (x == minInt(@typeOf(x))) {
if (x == minInt(@TypeOf(x))) {
return error.Overflow;
} else {
@setRuntimeSafety(false);
@ -654,16 +654,16 @@ fn testRem() void {
/// Returns the absolute value of the integer parameter.
/// Result is an unsigned integer.
pub fn absCast(x: var) t: {
if (@typeOf(x) == comptime_int) {
if (@TypeOf(x) == comptime_int) {
break :t comptime_int;
} else {
break :t @IntType(false, @typeOf(x).bit_count);
break :t @IntType(false, @TypeOf(x).bit_count);
}
} {
if (@typeOf(x) == comptime_int) {
if (@TypeOf(x) == comptime_int) {
return if (x < 0) -x else x;
}
const uint = @IntType(false, @typeOf(x).bit_count);
const uint = @IntType(false, @TypeOf(x).bit_count);
if (x >= 0) return @intCast(uint, x);
return @intCast(uint, -(x + 1)) + 1;
@ -671,23 +671,23 @@ pub fn absCast(x: var) t: {
test "math.absCast" {
testing.expect(absCast(@as(i32, -999)) == 999);
testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);
testing.expect(@TypeOf(absCast(@as(i32, -999))) == u32);
testing.expect(absCast(@as(i32, 999)) == 999);
testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);
testing.expect(@TypeOf(absCast(@as(i32, 999))) == u32);
testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);
testing.expect(@TypeOf(absCast(@as(i32, minInt(i32)))) == u32);
testing.expect(absCast(-999) == 999);
}
/// Returns the negation of the integer parameter.
/// Result is a signed integer.
pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
if (@typeOf(x).is_signed) return negate(x);
pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) {
if (@TypeOf(x).is_signed) return negate(x);
const int = @IntType(true, @typeOf(x).bit_count);
const int = @IntType(true, @TypeOf(x).bit_count);
if (x > -minInt(int)) return error.Overflow;
if (x == -minInt(int)) return minInt(int);
@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
test "math.negateCast" {
testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
}
@ -709,10 +709,10 @@ test "math.negateCast" {
/// return an error.
pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer
if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) {
comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer
if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
return error.Overflow;
} else if (minInt(@typeOf(x)) < minInt(T) and x < minInt(T)) {
} else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {
return error.Overflow;
} else {
return @intCast(T, x);
@ -726,13 +726,13 @@ test "math.cast" {
testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);
testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
}
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: var) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) {
const addr = @ptrToInt(ptr);
if (addr % alignment != 0) {
return error.UnalignedMemory;
@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" {
}
pub fn lossyCast(comptime T: type, value: var) T {
switch (@typeInfo(@typeOf(value))) {
switch (@typeInfo(@TypeOf(value))) {
builtin.TypeId.Int => return @intToFloat(T, value),
builtin.TypeId.Float => return @floatCast(T, value),
builtin.TypeId.ComptimeInt => return @as(T, value),

View File

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

View File

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

View File

@ -13,8 +13,8 @@ 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) {
const T = @typeOf(x);
pub fn asin(x: var) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => asin32(x),
f64 => asin64(x),

View File

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

View File

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

View File

@ -15,8 +15,8 @@ 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) {
const T = @typeOf(x);
pub fn atanh(x: var) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => atanh_32(x),
f64 => atanh_64(x),

View File

@ -268,7 +268,7 @@ pub const Int = struct {
/// Sets an Int to value. Value must be an primitive integer type.
pub fn set(self: *Int, value: var) Allocator.Error!void {
self.assertWritable();
const T = @typeOf(value);
const T = @TypeOf(value);
switch (@typeInfo(T)) {
TypeId.Int => |info| {
@ -522,7 +522,7 @@ pub const Int = struct {
options: std.fmt.FormatOptions,
context: var,
comptime FmtError: type,
output: fn (@typeOf(context), []const u8) FmtError!void,
output: fn (@TypeOf(context), []const u8) FmtError!void,
) FmtError!void {
self.assertWritable();
// TODO look at fmt and support other bases

View File

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

View File

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

View File

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

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the arc-cosine of z.
pub fn acos(z: var) Complex(@typeOf(z.re)) {
const T = @typeOf(z.re);
pub fn acos(z: var) 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,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the hyperbolic arc-cosine of z.
pub fn acosh(z: var) Complex(@typeOf(z.re)) {
const T = @typeOf(z.re);
pub fn acosh(z: var) 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,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the angular component (in radians) of z.
pub fn arg(z: var) @typeOf(z.re) {
const T = @typeOf(z.re);
pub fn arg(z: var) @TypeOf(z.re) {
const T = @TypeOf(z.re);
return math.atan2(T, z.im, z.re);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex;
/// Returns the cosine of z.
pub fn cos(z: var) Complex(@typeOf(z.re)) {
const T = @typeOf(z.re);
pub fn cos(z: var) 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,8 +14,8 @@ 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)) {
const T = @typeOf(z.re);
pub fn cosh(z: var) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => cosh32(z),
f64 => cosh64(z),

View File

@ -14,8 +14,8 @@ 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) {
const T = @typeOf(z.re);
pub fn exp(z: var) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => exp32(z),

View File

@ -11,8 +11,8 @@ 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) {
const T = @typeOf(z.re);
pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => ldexp_cexp32(z, expt),

View File

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

View File

@ -5,8 +5,8 @@ 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)) {
const T = @typeOf(z.re);
pub fn proj(z: var) Complex(@TypeOf(z.re)) {
const T = @TypeOf(z.re);
if (math.isInf(z.re) or math.isInf(z.im)) {
return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re));

View File

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

View File

@ -14,8 +14,8 @@ 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) {
const T = @typeOf(z.re);
pub fn sinh(z: var) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => sinh32(z),
f64 => sinh64(z),

View File

@ -12,8 +12,8 @@ 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) {
const T = @typeOf(z.re);
pub fn sqrt(z: var) @TypeOf(z) {
const T = @TypeOf(z.re);
return switch (T) {
f32 => sqrt32(z),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,8 +24,8 @@ 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)) {
const T = @typeOf(x);
pub fn frexp(x: var) frexp_result(@TypeOf(x)) {
const T = @TypeOf(x);
return switch (T) {
f32 => frexp32(x),
f64 => frexp64(x),

View File

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

View File

@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
/// Returns whether x is a finite value.
pub fn isFinite(x: var) bool {
const T = @typeOf(x);
const T = @TypeOf(x);
switch (T) {
f16 => {
const bits = @bitCast(u16, x);

View File

@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
/// Returns whether x is an infinity, ignoring sign.
pub fn isInf(x: var) bool {
const T = @typeOf(x);
const T = @TypeOf(x);
switch (T) {
f16 => {
const bits = @bitCast(u16, x);
@ -31,7 +31,7 @@ pub fn isInf(x: var) bool {
/// Returns whether x is an infinity with a positive sign.
pub fn isPositiveInf(x: var) bool {
const T = @typeOf(x);
const T = @TypeOf(x);
switch (T) {
f16 => {
return @bitCast(u16, x) == 0x7C00;
@ -53,7 +53,7 @@ pub fn isPositiveInf(x: var) bool {
/// Returns whether x is an infinity with a negative sign.
pub fn isNegativeInf(x: var) bool {
const T = @typeOf(x);
const T = @TypeOf(x);
switch (T) {
f16 => {
return @bitCast(u16, x) == 0xFC00;

View File

@ -5,7 +5,7 @@ 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 {
const T = @typeOf(x);
const T = @TypeOf(x);
switch (T) {
f16 => {
const bits = @bitCast(u16, x);

View File

@ -17,11 +17,11 @@ const TypeId = builtin.TypeId;
/// - ln(0) = -inf
/// - ln(x) = nan if x < 0
/// - ln(nan) = nan
pub fn ln(x: var) @typeOf(x) {
const T = @typeOf(x);
pub fn ln(x: var) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @typeOf(1.0)(ln_64(x));
return @TypeOf(1.0)(ln_64(x));
},
TypeId.Float => {
return switch (T) {
@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) {
};
},
TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(ln_64(@as(f64, x))));
return @TypeOf(1)(math.floor(ln_64(@as(f64, x))));
},
TypeId.Int => {
return @as(T, math.floor(ln_64(@as(f64, x))));

View File

@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
const float_base = math.lossyCast(f64, base);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
return @TypeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
},
TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
return @TypeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
},
builtin.TypeId.Int => {
// TODO implement integer log without using float math

View File

@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;
/// - log10(0) = -inf
/// - log10(x) = nan if x < 0
/// - log10(nan) = nan
pub fn log10(x: var) @typeOf(x) {
const T = @typeOf(x);
pub fn log10(x: var) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @typeOf(1.0)(log10_64(x));
return @TypeOf(1.0)(log10_64(x));
},
TypeId.Float => {
return switch (T) {
@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
};
},
TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(log10_64(@as(f64, x))));
return @TypeOf(1)(math.floor(log10_64(@as(f64, x))));
},
TypeId.Int => {
return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));

View File

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

View File

@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;
/// - log2(0) = -inf
/// - log2(x) = nan if x < 0
/// - log2(nan) = nan
pub fn log2(x: var) @typeOf(x) {
const T = @typeOf(x);
pub fn log2(x: var) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => {
return @typeOf(1.0)(log2_64(x));
return @TypeOf(1.0)(log2_64(x));
},
TypeId.Float => {
return switch (T) {

View File

@ -24,8 +24,8 @@ 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)) {
const T = @typeOf(x);
pub fn modf(x: var) modf_result(@TypeOf(x)) {
const T = @TypeOf(x);
return switch (T) {
f32 => modf32(x),
f64 => modf64(x),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,8 +12,8 @@ const maxInt = std.math.maxInt;
/// - sqrt(+-0) = +-0
/// - sqrt(x) = nan if x < 0
/// - sqrt(nan) = nan
pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
const T = @typeOf(x);
pub fn sqrt(x: var) (if (@typeId(@TypeOf(x)) == TypeId.Int) @IntType(false, @TypeOf(x).bit_count / 2) else @TypeOf(x)) {
const T = @TypeOf(x);
switch (@typeId(T)) {
TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
TypeId.Float => return @sqrt(T, x),

View File

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

View File

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

View File

@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
/// - trunc(+-0) = +-0
/// - trunc(+-inf) = +-inf
/// - trunc(nan) = nan
pub fn trunc(x: var) @typeOf(x) {
const T = @typeOf(x);
pub fn trunc(x: var) @TypeOf(x) {
const T = @TypeOf(x);
return switch (T) {
f32 => trunc32(x),
f64 => trunc64(x),

View File

@ -86,7 +86,7 @@ pub const Allocator = struct {
/// `ptr` should be the return value of `create`, or otherwise
/// have the same address and alignment property.
pub fn destroy(self: *Allocator, ptr: var) void {
const T = @typeOf(ptr).Child;
const T = @TypeOf(ptr).Child;
if (@sizeOf(T) == 0) return;
const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
const shrink_result = self.shrinkFn(self, non_const_ptr[0..@sizeOf(T)], @alignOf(T), 0, 1);
@ -147,10 +147,10 @@ pub const Allocator = struct {
/// If you need guaranteed success, call `shrink`.
/// If `new_n` is 0, this is the same as `free` and it always succeeds.
pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer;
const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
break :t Error![]align(Slice.alignment) Slice.child;
} {
const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment;
const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment;
return self.alignedRealloc(old_mem, old_alignment, new_n);
}
@ -162,8 +162,8 @@ pub const Allocator = struct {
old_mem: var,
comptime new_alignment: u29,
new_n: usize,
) Error![]align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer;
) Error![]align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child {
const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
const T = Slice.child;
if (old_mem.len == 0) {
return self.alignedAlloc(T, new_alignment, new_n);
@ -189,10 +189,10 @@ pub const Allocator = struct {
/// Returned slice has same alignment as old_mem.
/// Shrinking to 0 is the same as calling `free`.
pub fn shrink(self: *Allocator, old_mem: var, new_n: usize) t: {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer;
const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
break :t []align(Slice.alignment) Slice.child;
} {
const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment;
const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment;
return self.alignedShrink(old_mem, old_alignment, new_n);
}
@ -204,8 +204,8 @@ pub const Allocator = struct {
old_mem: var,
comptime new_alignment: u29,
new_n: usize,
) []align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer;
) []align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child {
const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
const T = Slice.child;
if (new_n == 0) {
@ -229,7 +229,7 @@ pub const Allocator = struct {
/// Free an array allocated with `alloc`. To free a single item,
/// see `destroy`.
pub fn free(self: *Allocator, memory: var) void {
const Slice = @typeInfo(@typeOf(memory)).Pointer;
const Slice = @typeInfo(@TypeOf(memory)).Pointer;
const bytes = @sliceToBytes(memory);
if (bytes.len == 0) return;
const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));
@ -1323,8 +1323,8 @@ fn AsBytesReturnType(comptime P: type) type {
}
///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness.
pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {
const P = @typeOf(ptr);
pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) {
const P = @TypeOf(ptr);
return @ptrCast(AsBytesReturnType(P), ptr);
}
@ -1363,7 +1363,7 @@ test "asBytes" {
}
///Given any value, returns a copy of its bytes in an array.
pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {
pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 {
return asBytes(&value).*;
}
@ -1397,8 +1397,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
///Given a pointer to an array of bytes, returns a pointer to a value of the specified type
/// backed by those bytes, preserving constness.
pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typeOf(bytes)) {
return @ptrCast(BytesAsValueReturnType(T, @typeOf(bytes)), bytes);
pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @TypeOf(bytes)) {
return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes);
}
test "bytesAsValue" {
@ -1460,11 +1460,11 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
}
///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.
pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) {
pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@TypeOf(ptr), length) {
assert(start + length <= ptr.*.len);
const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length);
const T = meta.Child(meta.Child(@typeOf(ptr)));
const ReturnType = SubArrayPtrReturnType(@TypeOf(ptr), length);
const T = meta.Child(meta.Child(@TypeOf(ptr)));
return @ptrCast(ReturnType, &ptr[start]);
}

View File

@ -11,7 +11,7 @@ const TypeId = builtin.TypeId;
const TypeInfo = builtin.TypeInfo;
pub fn tagName(v: var) []const u8 {
const T = @typeOf(v);
const T = @TypeOf(v);
switch (@typeInfo(T)) {
TypeId.ErrorSet => return @errorName(v),
else => return @tagName(v),
@ -339,8 +339,8 @@ test "std.meta.TagType" {
}
///Returns the active tag of a tagged union
pub fn activeTag(u: var) @TagType(@typeOf(u)) {
const T = @typeOf(u);
pub fn activeTag(u: var) @TagType(@TypeOf(u)) {
const T = @TypeOf(u);
return @as(@TagType(T), u);
}
@ -365,7 +365,7 @@ test "std.meta.activeTag" {
///Given a tagged union type, and an enum, return the type of the union
/// field corresponding to the enum tag.
pub fn TagPayloadType(comptime U: type, tag: var) type {
const Tag = @typeOf(tag);
const Tag = @TypeOf(tag);
testing.expect(trait.is(builtin.TypeId.Union)(U));
testing.expect(trait.is(builtin.TypeId.Enum)(Tag));
@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" {
};
const MovedEvent = TagPayloadType(Event, Event.Moved);
var e: Event = undefined;
testing.expect(MovedEvent == @typeOf(e.Moved));
testing.expect(MovedEvent == @TypeOf(e.Moved));
}
///Compares two of any type for equality. Containers are compared on a field-by-field basis,
/// where possible. Pointers are not followed.
pub fn eql(a: var, b: @typeOf(a)) bool {
const T = @typeOf(a);
pub fn eql(a: var, b: @TypeOf(a)) bool {
const T = @TypeOf(a);
switch (@typeId(T)) {
builtin.TypeId.Struct => {

View File

@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool {
return false;
}
pub const TraitFn = @typeOf(traitFnWorkaround);
pub const TraitFn = @TypeOf(traitFnWorkaround);
///
//////Trait generators
@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
pub fn trait(comptime T: type) bool {
if (!comptime isContainer(T)) return false;
if (!comptime @hasDecl(T, name)) return false;
const DeclType = @typeOf(@field(T, name));
const DeclType = @TypeOf(@field(T, name));
const decl_type_id = @typeId(DeclType);
return decl_type_id == builtin.TypeId.Fn;
}
@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {
test "std.meta.trait.isSingleItemPtr" {
const array = [_]u8{0} ** 10;
testing.expect(isSingleItemPtr(@typeOf(&array[0])));
testing.expect(!isSingleItemPtr(@typeOf(array)));
testing.expect(!isSingleItemPtr(@typeOf(array[0..1])));
testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
testing.expect(!isSingleItemPtr(@TypeOf(array)));
testing.expect(!isSingleItemPtr(@TypeOf(array[0..1])));
}
///
@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
test "std.meta.trait.isManyItemPtr" {
const array = [_]u8{0} ** 10;
const mip = @ptrCast([*]const u8, &array[0]);
testing.expect(isManyItemPtr(@typeOf(mip)));
testing.expect(!isManyItemPtr(@typeOf(array)));
testing.expect(!isManyItemPtr(@typeOf(array[0..1])));
testing.expect(isManyItemPtr(@TypeOf(mip)));
testing.expect(!isManyItemPtr(@TypeOf(array)));
testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
}
///
@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool {
test "std.meta.trait.isSlice" {
const array = [_]u8{0} ** 10;
testing.expect(isSlice(@typeOf(array[0..])));
testing.expect(!isSlice(@typeOf(array)));
testing.expect(!isSlice(@typeOf(&array[0])));
testing.expect(isSlice(@TypeOf(array[0..])));
testing.expect(!isSlice(@TypeOf(array)));
testing.expect(!isSlice(@TypeOf(&array[0])));
}
///
@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" {
const array = [_]u8{0} ** 10;
const slice = array[0..];
testing.expect(isIndexable(@typeOf(array)));
testing.expect(isIndexable(@typeOf(&array)));
testing.expect(isIndexable(@typeOf(slice)));
testing.expect(!isIndexable(meta.Child(@typeOf(slice))));
testing.expect(isIndexable(@TypeOf(array)));
testing.expect(isIndexable(@TypeOf(&array)));
testing.expect(isIndexable(@TypeOf(slice)));
testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
}
///
@ -313,8 +313,8 @@ test "std.meta.trait.isNumber" {
testing.expect(isNumber(u32));
testing.expect(isNumber(f32));
testing.expect(isNumber(u64));
testing.expect(isNumber(@typeOf(102)));
testing.expect(isNumber(@typeOf(102.123)));
testing.expect(isNumber(@TypeOf(102)));
testing.expect(isNumber(@TypeOf(102.123)));
testing.expect(!isNumber([]u8));
testing.expect(!isNumber(NotANumber));
}
@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool {
test "std.meta.trait.isConstPtr" {
var t = @as(u8, 0);
const c = @as(u8, 0);
testing.expect(isConstPtr(*const @typeOf(t)));
testing.expect(isConstPtr(@typeOf(&c)));
testing.expect(!isConstPtr(*@typeOf(t)));
testing.expect(!isConstPtr(@typeOf(6)));
testing.expect(isConstPtr(*const @TypeOf(t)));
testing.expect(isConstPtr(@TypeOf(&c)));
testing.expect(!isConstPtr(*@TypeOf(t)));
testing.expect(!isConstPtr(@TypeOf(6)));
}
pub fn isContainer(comptime T: type) bool {

View File

@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent;
/// no-ops. In single threaded debug mode, there is deadlock detection.
pub const Mutex = if (builtin.single_threaded)
struct {
lock: @typeOf(lock_init),
lock: @TypeOf(lock_init),
const lock_init = if (std.debug.runtime_safety) false else {};

View File

@ -271,7 +271,7 @@ pub const Address = extern union {
options: std.fmt.FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) !void {
switch (self.any.family) {
os.AF_INET => {

View File

@ -2974,7 +2974,7 @@ pub fn res_mkquery(
// Make a reasonably unpredictable id
var ts: timespec = undefined;
clock_gettime(CLOCK_REALTIME, &ts) catch {};
const UInt = @IntType(false, @typeOf(ts.tv_nsec).bit_count);
const UInt = @IntType(false, @TypeOf(ts.tv_nsec).bit_count);
const unsec = @bitCast(UInt, ts.tv_nsec);
const id = @truncate(u32, unsec + unsec / 65536);
q[0] = @truncate(u8, id / 256);

View File

@ -706,7 +706,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
.restorer = @ptrCast(extern fn () void, restorer_fn),
};
var ksa_old: k_sigaction = undefined;
const ksa_mask_size = @sizeOf(@typeOf(ksa_old.mask));
const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask));
@memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size);
const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size);
const err = getErrno(result);
@ -786,7 +786,7 @@ pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
}
pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {
if (@typeInfo(usize).Int.bits > @typeInfo(@typeOf(mmsghdr(undefined).msg_len)).Int.bits) {
if (@typeInfo(usize).Int.bits > @typeInfo(@TypeOf(mmsghdr(undefined).msg_len)).Int.bits) {
// workaround kernel brokenness:
// if adding up all iov_len overflows a i32 then split into multiple calls
// see https://www.openwall.com/lists/musl/2014/06/07/5

View File

@ -32,7 +32,7 @@ pub const Guid = extern struct {
options: fmt.FormatOptions,
context: var,
comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void,
output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void {
if (f.len == 0) {
return fmt.format(context, Errors, output, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", self.time_low, self.time_mid, self.time_high_and_version, self.clock_seq_high_and_reserved, self.clock_seq_low, self.node);

View File

@ -214,12 +214,12 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis
pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD;
pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll:BOOL, dwMilliseconds: DWORD) DWORD;
pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) DWORD;
pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx(
nCount: DWORD,
lpHandle: [*]const HANDLE,
bWaitAll:BOOL,
bWaitAll: BOOL,
dwMilliseconds: DWORD,
bAlertable: BOOL,
) DWORD;

View File

@ -635,7 +635,7 @@ const MsfStream = struct {
/// Implementation of InStream trait for Pdb.MsfStream
stream: Stream = undefined,
pub const Error = @typeOf(read).ReturnType.ErrorSet;
pub const Error = @TypeOf(read).ReturnType.ErrorSet;
pub const Stream = io.InStream(Error);
fn init(block_size: u32, file: File, blocks: []u32) MsfStream {

View File

@ -27,7 +27,7 @@ pub const ResetEvent = struct {
pub fn isSet(self: *ResetEvent) bool {
return self.os_event.isSet();
}
/// Sets the event if not already set and
/// wakes up AT LEAST one thread waiting the event.
/// Returns whether or not a thread was woken up.
@ -62,7 +62,7 @@ const OsEvent = if (builtin.single_threaded) DebugEvent else switch (builtin.os)
};
const DebugEvent = struct {
is_set: @typeOf(set_init),
is_set: @TypeOf(set_init),
const set_init = if (std.debug.runtime_safety) false else {};
@ -283,7 +283,7 @@ const PosixEvent = struct {
pub fn init() PosixEvent {
return PosixEvent{
.state = .0,
.state = 0,
.cond = c.PTHREAD_COND_INITIALIZER,
.mutex = c.PTHREAD_MUTEX_INITIALIZER,
};
@ -345,8 +345,8 @@ const PosixEvent = struct {
timeout_abs += @intCast(u64, ts.tv_sec) * time.second;
timeout_abs += @intCast(u64, ts.tv_nsec);
}
ts.tv_sec = @intCast(@typeOf(ts.tv_sec), @divFloor(timeout_abs, time.second));
ts.tv_nsec = @intCast(@typeOf(ts.tv_nsec), @mod(timeout_abs, time.second));
ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.second));
ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.second));
}
var dummy_value: u32 = undefined;
@ -426,8 +426,8 @@ test "std.ResetEvent" {
.event = event,
.value = 0,
};
var receiver = try std.Thread.spawn(&context, Context.receiver);
defer receiver.wait();
try context.sender();
}
}

View File

@ -122,7 +122,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
self.* = undefined;
}
pub fn at(self: var, i: usize) AtType(@typeOf(self)) {
pub fn at(self: var, i: usize) AtType(@TypeOf(self)) {
assert(i < self.len);
return self.uncheckedAt(i);
}
@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
self.len = new_len;
}
pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) {
pub fn uncheckedAt(self: var, index: usize) AtType(@TypeOf(self)) {
if (index < prealloc_item_count) {
return &self.prealloc_segment[index];
}

View File

@ -125,7 +125,7 @@ pub fn main() !void {
}
fn runBuild(builder: *Builder) anyerror!void {
switch (@typeId(@typeOf(root.build).ReturnType)) {
switch (@typeId(@TypeOf(root.build).ReturnType)) {
.Void => root.build(builder),
.ErrorUnion => try root.build(builder),
else => @compileError("expected return type of build to be 'void' or '!void'"),

View File

@ -384,7 +384,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {
} {
@setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined;
var result: @TypeOf(__aeabi_uidivmod).ReturnType = undefined;
result.q = __udivmodsi4(n, d, &result.r);
return result;
}
@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {
} {
@setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined;
var result: @TypeOf(__aeabi_uldivmod).ReturnType = undefined;
result.q = __udivmoddi4(n, d, &result.r);
return result;
}
@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {
} {
@setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_idivmod).ReturnType = undefined;
var result: @TypeOf(__aeabi_idivmod).ReturnType = undefined;
result.q = __divmodsi4(n, d, &result.r);
return result;
}
@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct {
} {
@setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined;
var result: @TypeOf(__aeabi_ldivmod).ReturnType = undefined;
result.q = __divmoddi4(n, d, &result.r);
return result;
}

View File

@ -25,7 +25,7 @@ comptime {
}
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
if (builtin.link_libc and @hasDecl(root, "main")) {
if (@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) {
if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@export("main", main, .Weak);
}
} else if (builtin.os == .windows) {
@ -69,7 +69,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u
uefi.handle = handle;
uefi.system_table = system_table;
switch (@typeInfo(@typeOf(root.main).ReturnType)) {
switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
.NoReturn => {
root.main();
},
@ -248,7 +248,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 {
// This is not marked inline because it is called with @asyncCall when
// there is an event loop.
fn callMain() u8 {
switch (@typeInfo(@typeOf(root.main).ReturnType)) {
switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
.NoReturn => {
root.main();
},
@ -270,7 +270,7 @@ fn callMain() u8 {
}
return 1;
};
switch (@typeInfo(@typeOf(result))) {
switch (@typeInfo(@TypeOf(result))) {
.Void => return 0,
.Int => |info| {
if (info.bits != 8) {

View File

@ -21,14 +21,14 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
/// equal, prints diagnostics to stderr to show exactly how they are not equal,
/// then aborts.
/// The types must match exactly.
pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
switch (@typeInfo(@typeOf(actual))) {
pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
switch (@typeInfo(@TypeOf(actual))) {
.NoReturn,
.BoundFn,
.Opaque,
.Frame,
.AnyFrame,
=> @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"),
=> @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
.Undefined,
.Null,
@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
@compileError("Unable to compare untagged union values");
}
const TagType = @TagType(@typeOf(expected));
const TagType = @TagType(@TypeOf(expected));
const expectedTag = @as(TagType, expected);
const actualTag = @as(TagType, actual);
@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
expectEqual(expectedTag, actualTag);
// we only reach this loop if the tags are equal
inline for (std.meta.fields(@typeOf(actual))) |fld| {
inline for (std.meta.fields(@TypeOf(actual))) |fld| {
if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {
expectEqual(@field(expected, fld.name), @field(actual, fld.name));
return;

View File

@ -138,7 +138,7 @@ pub const Thread = struct {
};
/// caller must call wait on the returned thread
/// fn startFn(@typeOf(context)) T
/// fn startFn(@TypeOf(context)) T
/// where T is u8, noreturn, void, or !void
/// caller must call wait on the returned thread
pub fn spawn(context: var, comptime startFn: var) SpawnError!*Thread {
@ -147,8 +147,8 @@ pub const Thread = struct {
// https://github.com/ziglang/zig/issues/157
const default_stack_size = 16 * 1024 * 1024;
const Context = @typeOf(context);
comptime assert(@ArgType(@typeOf(startFn), 0) == Context);
const Context = @TypeOf(context);
comptime assert(@ArgType(@TypeOf(startFn), 0) == Context);
if (builtin.os == builtin.Os.windows) {
const WinThread = struct {
@ -158,7 +158,7 @@ pub const Thread = struct {
};
extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD {
const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
switch (@typeId(@typeOf(startFn).ReturnType)) {
switch (@typeId(@TypeOf(startFn).ReturnType)) {
.Int => {
return startFn(arg);
},
@ -201,7 +201,7 @@ pub const Thread = struct {
extern fn linuxThreadMain(ctx_addr: usize) u8 {
const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
switch (@typeId(@typeOf(startFn).ReturnType)) {
switch (@typeId(@TypeOf(startFn).ReturnType)) {
.Int => {
return startFn(arg);
},

View File

@ -1,3 +1,14 @@
// TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348
test "zig fmt: change @typeOf to @TypeOf" {
try testTransform(
\\const a = @typeOf(@as(usize, 10));
\\
,
\\const a = @TypeOf(@as(usize, 10));
\\
);
}
test "zig fmt: comptime struct field" {
try testCanonical(
\\const Foo = struct {
@ -1060,7 +1071,7 @@ test "zig fmt: line comment after doc comment" {
test "zig fmt: float literal with exponent" {
try testCanonical(
\\test "bit field alignment" {
\\ assert(@typeOf(&blah.b) == *align(1:3:6) const u3);
\\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3);
\\}
\\
);
@ -2593,7 +2604,7 @@ test "zig fmt: comments at several places in struct init" {
try testTransform(
\\var bar = Bar{
\\ .x = 10, // test
\\ .y = "test"
\\ .y = "test"
\\ // test
\\};
\\

View File

@ -13,19 +13,19 @@ pub const Error = error{
};
/// Returns whether anything changed
pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(stream).Child.Error || Error)!bool {
comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer);
pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool {
comptime assert(@typeId(@TypeOf(stream)) == builtin.TypeId.Pointer);
var anything_changed: bool = false;
// make a passthrough stream that checks whether something changed
const MyStream = struct {
const MyStream = @This();
const StreamError = @typeOf(stream).Child.Error;
const StreamError = @TypeOf(stream).Child.Error;
const Stream = std.io.OutStream(StreamError);
anything_changed_ptr: *bool,
child_stream: @typeOf(stream),
child_stream: @TypeOf(stream),
stream: Stream,
source_index: usize,
source: []const u8,
@ -70,7 +70,7 @@ fn renderRoot(
allocator: *mem.Allocator,
stream: var,
tree: *ast.Tree,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
var tok_it = tree.tokens.iterator(0);
// render all the line comments at the beginning of the file
@ -190,7 +190,7 @@ fn renderRoot(
}
}
fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @typeOf(stream).Child.Error!void {
fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void {
const first_token = node.firstToken();
var prev_token = first_token;
while (tree.tokens.at(prev_token - 1).id == .DocComment) {
@ -204,7 +204,7 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as
}
}
fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@typeOf(stream).Child.Error || Error)!void {
fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Child.Error || Error)!void {
switch (decl.id) {
.FnProto => {
const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);
@ -325,7 +325,7 @@ fn renderExpression(
start_col: *usize,
base: *ast.Node,
space: Space,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
switch (base.id) {
.Identifier => {
const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base);
@ -1249,7 +1249,13 @@ fn renderExpression(
.BuiltinCall => {
const builtin_call = @fieldParentPtr(ast.Node.BuiltinCall, "base", base);
try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name
// TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348
if (mem.eql(u8, tree.tokenSlicePtr(tree.tokens.at(builtin_call.builtin_token)), "@typeOf")) {
try stream.write("@TypeOf");
} else {
try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name
}
try renderToken(tree, stream, tree.nextToken(builtin_call.builtin_token), indent, start_col, Space.None); // (
var it = builtin_call.params.iterator(0);
@ -1897,7 +1903,7 @@ fn renderVarDecl(
indent: usize,
start_col: *usize,
var_decl: *ast.Node.VarDecl,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
if (var_decl.visib_token) |visib_token| {
try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
}
@ -1970,7 +1976,7 @@ fn renderParamDecl(
start_col: *usize,
base: *ast.Node,
space: Space,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
try renderDocComments(tree, stream, param_decl, indent, start_col);
@ -1999,7 +2005,7 @@ fn renderStatement(
indent: usize,
start_col: *usize,
base: *ast.Node,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
switch (base.id) {
.VarDecl => {
const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base);
@ -2038,7 +2044,7 @@ fn renderTokenOffset(
start_col: *usize,
space: Space,
token_skip_bytes: usize,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
if (space == Space.BlockStart) {
if (start_col.* < indent + indent_delta)
return renderToken(tree, stream, token_index, indent, start_col, Space.Space);
@ -2226,7 +2232,7 @@ fn renderToken(
indent: usize,
start_col: *usize,
space: Space,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0);
}
@ -2236,7 +2242,7 @@ fn renderDocComments(
node: var,
indent: usize,
start_col: *usize,
) (@typeOf(stream).Child.Error || Error)!void {
) (@TypeOf(stream).Child.Error || Error)!void {
const comment = node.doc_comments orelse return;
var it = comment.lines.iterator(0);
const first_token = node.firstToken();
@ -2302,7 +2308,7 @@ const FindByteOutStream = struct {
}
};
fn copyFixingWhitespace(stream: var, slice: []const u8) @typeOf(stream).Child.Error!void {
fn copyFixingWhitespace(stream: var, slice: []const u8) @TypeOf(stream).Child.Error!void {
for (slice) |byte| switch (byte) {
'\t' => try stream.write(" "),
'\r' => {},

View File

@ -1021,8 +1021,8 @@ comptime {
// output: must be a function that takes a `self` idiom parameter
// and a bytes parameter
// context: must be that self
fn makeOutput(output: var, context: var) Output(@typeOf(output)) {
return Output(@typeOf(output)){
fn makeOutput(output: var, context: var) Output(@TypeOf(output)) {
return Output(@TypeOf(output)){
.output = output,
.context = context,
};

View File

@ -1807,7 +1807,7 @@ pub const Builder = struct {
// Look at the params and ref() other instructions
comptime var i = 0;
inline while (i < @memberCount(I.Params)) : (i += 1) {
const FieldType = comptime @typeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));
const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));
switch (FieldType) {
*Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),
*BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self),

View File

@ -72,7 +72,7 @@ pub const LibCInstallation = struct {
inline for (keys) |key, i| {
if (std.mem.eql(u8, name, key)) {
found_keys[i].found = true;
switch (@typeInfo(@typeOf(@field(self, key)))) {
switch (@typeInfo(@TypeOf(@field(self, key)))) {
.Optional => {
if (value.len == 0) {
@field(self, key) = null;

View File

@ -270,11 +270,9 @@ const FmtError = error{
FileBusy,
} || fs.File.OpenError;
fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {
const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref);
defer fmt.allocator.free(file_path);
if (try fmt.seen.put(file_path, {})) |_| return;
fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
if (fmt.seen.exists(file_path)) return;
try fmt.seen.put(file_path);
const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
error.IsDir, error.AccessDenied => {
@ -341,7 +339,7 @@ const Fmt = struct {
color: errmsg.Color,
allocator: *mem.Allocator,
const SeenMap = std.StringHashMap(void);
const SeenMap = std.BufSet;
};
fn printErrMsgToFile(

View File

@ -1147,7 +1147,7 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node {
var big = try std.math.big.Int.initCapacity(c.a(), num_limbs);
defer big.deinit();
const data = ZigClangAPSInt_getRawData(int.?);
var i: @typeOf(num_limbs) = 0;
var i: @TypeOf(num_limbs) = 0;
while (i < num_limbs) : (i += 1) big.limbs[i] = data[i];
const str = big.toString(c.a(), 10) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
@ -1416,7 +1416,7 @@ fn revertAndWarn(
source_loc: ZigClangSourceLocation,
comptime format: []const u8,
args: var,
) (@typeOf(err) || error{OutOfMemory}) {
) (@TypeOf(err) || error{OutOfMemory}) {
rp.activate();
try emitWarning(rp.c, source_loc, format, args);
return err;

View File

@ -1038,14 +1038,14 @@ pub const Type = struct {
};
fn hashAny(x: var, comptime seed: u64) u32 {
switch (@typeInfo(@typeOf(x))) {
switch (@typeInfo(@TypeOf(x))) {
.Int => |info| {
comptime var rng = comptime std.rand.DefaultPrng.init(seed);
const unsigned_x = @bitCast(@IntType(false, info.bits), x);
if (info.bits <= 32) {
return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);
} else {
return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@typeOf(unsigned_x)));
return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@TypeOf(unsigned_x)));
}
},
.Pointer => |info| {
@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 {
return hashAny(@as(u32, 1), seed);
}
},
else => @compileError("implement hash function for " ++ @typeName(@typeOf(x))),
else => @compileError("implement hash function for " ++ @typeName(@TypeOf(x))),
}
}

View File

@ -2393,7 +2393,7 @@ struct ScopeFnDef {
ZigFn *fn_entry;
};
// This scope is created for a @typeOf.
// This scope is created for a @TypeOf.
// All runtime side-effects are elided within it.
// NodeTypeFnCallExpr
struct ScopeTypeOf {

View File

@ -121,7 +121,7 @@ static ScopeExpr *find_expr_scope(Scope *scope) {
}
static void update_progress_display(CodeGen *g) {
stage2_progress_update_node(g->sub_progress_node,
stage2_progress_update_node(g->sub_progress_node,
g->resolve_queue_index + g->fn_defs_index,
g->resolve_queue.length + g->fn_defs.length);
}
@ -1732,7 +1732,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
buf_resize(&err_set_type->name, 0);
buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
buf_appendf(&err_set_type->name, "@TypeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
err_set_type->data.error_set.err_count = 0;
err_set_type->data.error_set.errors = nullptr;
err_set_type->data.error_set.infer_fn = fn_entry;

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