mirror of
https://github.com/ziglang/zig.git
synced 2026-02-17 06:49:23 +00:00
Merge pull request #4547 from Vexu/deprecate
Remove deprecated builtins
This commit is contained in:
commit
61a50a23e8
@ -550,7 +550,7 @@ pub fn main() void {
|
||||
{#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an
|
||||
integer type is {#syntax#}65535{#endsyntax#}.
|
||||
</p>
|
||||
{#see_also|Integers|Floats|void|Errors|@IntType#}
|
||||
{#see_also|Integers|Floats|void|Errors|@Type#}
|
||||
{#header_close#}
|
||||
{#header_open|Primitive Values#}
|
||||
<div class="table-wrapper">
|
||||
@ -2810,14 +2810,10 @@ test "@TagType" {
|
||||
assert(@TagType(Small) == u2);
|
||||
}
|
||||
|
||||
// @memberCount tells how many fields an enum has:
|
||||
test "@memberCount" {
|
||||
assert(@memberCount(Small) == 4);
|
||||
}
|
||||
|
||||
// @memberName tells the name of a field in an enum:
|
||||
test "@memberName" {
|
||||
assert(mem.eql(u8, @memberName(Small, 1), "Two"));
|
||||
// @typeInfo tells us the field count and the fields names:
|
||||
test "@typeInfo" {
|
||||
assert(@typeInfo(Small).Enum.fields.len == 4);
|
||||
assert(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "Two"));
|
||||
}
|
||||
|
||||
// @tagName gives a []const u8 representation of an enum value:
|
||||
@ -2825,7 +2821,7 @@ test "@tagName" {
|
||||
assert(mem.eql(u8, @tagName(Small.Three), "Three"));
|
||||
}
|
||||
{#code_end#}
|
||||
{#see_also|@memberName|@memberCount|@tagName|@sizeOf#}
|
||||
{#see_also|@typeInfo|@tagName|@sizeOf#}
|
||||
|
||||
{#header_open|extern enum#}
|
||||
<p>
|
||||
@ -6671,18 +6667,6 @@ comptime {
|
||||
</p>
|
||||
{#see_also|Alignment#}
|
||||
{#header_close#}
|
||||
{#header_open|@ArgType#}
|
||||
<pre>{#syntax#}@ArgType(comptime T: type, comptime n: usize) type{#endsyntax#}</pre>
|
||||
<p>
|
||||
This builtin function takes a function type and returns the type of the parameter at index {#syntax#}n{#endsyntax#}.
|
||||
</p>
|
||||
<p>
|
||||
{#syntax#}T{#endsyntax#} must be a function type.
|
||||
</p>
|
||||
<p>
|
||||
Note: This function is deprecated. Use {#link|@typeInfo#} instead.
|
||||
</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@as#}
|
||||
<pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre>
|
||||
@ -6816,7 +6800,7 @@ async fn func(y: *i32) void {
|
||||
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.
|
||||
Asserts that {#syntax#}@typeInfo(DestType) != .Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.
|
||||
</p>
|
||||
<p>
|
||||
Can be used for these things for example:
|
||||
@ -7269,7 +7253,7 @@ test "main" {
|
||||
<p>
|
||||
Floored division. Rounds toward negative infinity. For unsigned integers it is
|
||||
the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
|
||||
{#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
|
||||
{#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
|
||||
</p>
|
||||
<ul>
|
||||
<li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
|
||||
@ -7283,7 +7267,7 @@ test "main" {
|
||||
<p>
|
||||
Truncated division. Rounds toward zero. For unsigned integers it is
|
||||
the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
|
||||
{#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
|
||||
{#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
|
||||
</p>
|
||||
<ul>
|
||||
<li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
|
||||
@ -7341,7 +7325,7 @@ test "main" {
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@errorToInt#}
|
||||
<pre>{#syntax#}@errorToInt(err: var) @IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@errorToInt(err: var) std.meta.IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre>
|
||||
<p>
|
||||
Supports the following types:
|
||||
</p>
|
||||
@ -7635,7 +7619,7 @@ test "@hasDecl" {
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@intToError#}
|
||||
<pre>{#syntax#}@intToError(value: @IntType(false, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}</pre>
|
||||
<pre>{#syntax#}@intToError(value: std.meta.IntType(false, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}</pre>
|
||||
<p>
|
||||
Converts from the integer representation of an error into {#link|The Global Error Set#} type.
|
||||
</p>
|
||||
@ -7668,44 +7652,6 @@ test "@hasDecl" {
|
||||
</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@IntType#}
|
||||
<pre>{#syntax#}@IntType(comptime is_signed: bool, comptime bit_count: u16) type{#endsyntax#}</pre>
|
||||
<p>
|
||||
This function returns an integer type with the given signness and bit count. The maximum
|
||||
bit count for an integer type is {#syntax#}65535{#endsyntax#}.
|
||||
</p>
|
||||
<p>
|
||||
Deprecated. Use {#link|@Type#}.
|
||||
</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@memberCount#}
|
||||
<pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre>
|
||||
<p>
|
||||
This function returns the number of members in a struct, enum, or union type.
|
||||
</p>
|
||||
<p>
|
||||
The result is a compile time constant.
|
||||
</p>
|
||||
<p>
|
||||
It does not include functions, variables, or constants.
|
||||
</p>
|
||||
{#header_close#}
|
||||
{#header_open|@memberName#}
|
||||
<pre>{#syntax#}@memberName(comptime T: type, comptime index: usize) [N]u8{#endsyntax#}</pre>
|
||||
<p>Returns the field name of a struct, union, or enum.</p>
|
||||
<p>
|
||||
The result is a compile time constant.
|
||||
</p>
|
||||
<p>
|
||||
It does not include functions, variables, or constants.
|
||||
</p>
|
||||
{#header_close#}
|
||||
{#header_open|@memberType#}
|
||||
<pre>{#syntax#}@memberType(comptime T: type, comptime index: usize) type{#endsyntax#}</pre>
|
||||
<p>Returns the field type of a struct or union.</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@memcpy#}
|
||||
<pre>{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize){#endsyntax#}</pre>
|
||||
<p>
|
||||
@ -8401,43 +8347,6 @@ test "integer truncation" {
|
||||
<li>{#link|struct#}</li>
|
||||
</ul>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@typeId#}
|
||||
<pre>{#syntax#}@typeId(comptime T: type) @import("builtin").TypeId{#endsyntax#}</pre>
|
||||
<p>
|
||||
Returns which kind of type something is. Possible values:
|
||||
</p>
|
||||
{#code_begin|syntax#}
|
||||
pub const TypeId = enum {
|
||||
Type,
|
||||
Void,
|
||||
Bool,
|
||||
NoReturn,
|
||||
Int,
|
||||
Float,
|
||||
Pointer,
|
||||
Array,
|
||||
Struct,
|
||||
ComptimeFloat,
|
||||
ComptimeInt,
|
||||
Undefined,
|
||||
Null,
|
||||
Optional,
|
||||
ErrorUnion,
|
||||
ErrorSet,
|
||||
Enum,
|
||||
Union,
|
||||
Fn,
|
||||
BoundFn,
|
||||
Opaque,
|
||||
Frame,
|
||||
AnyFrame,
|
||||
Vector,
|
||||
EnumLiteral,
|
||||
};
|
||||
{#code_end#}
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|@typeInfo#}
|
||||
<pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
|
||||
<p>
|
||||
|
||||
@ -609,13 +609,13 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
fn typeToEnum(comptime T: type) TypeId {
|
||||
return switch (@typeId(T)) {
|
||||
builtin.TypeId.Int => TypeId.Int,
|
||||
builtin.TypeId.Float => TypeId.Float,
|
||||
builtin.TypeId.Bool => TypeId.Bool,
|
||||
return switch (@typeInfo(T)) {
|
||||
.Int => .Int,
|
||||
.Float => .Float,
|
||||
.Bool => .Bool,
|
||||
else => switch (T) {
|
||||
[]const u8 => TypeId.String,
|
||||
[]const []const u8 => TypeId.List,
|
||||
[]const u8 => .String,
|
||||
[]const []const u8 => .List,
|
||||
else => @compileError("Unsupported type: " ++ @typeName(T)),
|
||||
},
|
||||
};
|
||||
@ -627,11 +627,11 @@ pub const Builder = struct {
|
||||
|
||||
pub fn typeIdName(id: TypeId) []const u8 {
|
||||
return switch (id) {
|
||||
TypeId.Bool => "bool",
|
||||
TypeId.Int => "int",
|
||||
TypeId.Float => "float",
|
||||
TypeId.String => "string",
|
||||
TypeId.List => "list",
|
||||
.Bool => "bool",
|
||||
.Int => "int",
|
||||
.Float => "float",
|
||||
.String => "string",
|
||||
.List => "list",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -851,7 +851,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
|
||||
os.exit(1);
|
||||
}
|
||||
|
||||
const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);
|
||||
const ErrInt = std.meta.IntType(false, @sizeOf(anyerror) * 8);
|
||||
|
||||
fn writeIntFd(fd: i32, value: ErrInt) !void {
|
||||
const file = File{
|
||||
|
||||
@ -2,7 +2,7 @@ const std = @import("std");
|
||||
const testing = std.testing;
|
||||
|
||||
pub fn readULEB128(comptime T: type, in_stream: var) !T {
|
||||
const ShiftT = @IntType(false, std.math.log2(T.bit_count));
|
||||
const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
|
||||
|
||||
var result: T = 0;
|
||||
var shift: usize = 0;
|
||||
@ -27,7 +27,7 @@ pub fn readULEB128(comptime T: type, in_stream: var) !T {
|
||||
}
|
||||
|
||||
pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
|
||||
const ShiftT = @IntType(false, std.math.log2(T.bit_count));
|
||||
const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
|
||||
|
||||
var result: T = 0;
|
||||
var shift: usize = 0;
|
||||
@ -55,8 +55,8 @@ pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
|
||||
}
|
||||
|
||||
pub fn readILEB128(comptime T: type, in_stream: var) !T {
|
||||
const UT = @IntType(false, T.bit_count);
|
||||
const ShiftT = @IntType(false, std.math.log2(T.bit_count));
|
||||
const UT = std.meta.IntType(false, T.bit_count);
|
||||
const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
|
||||
|
||||
var result: UT = 0;
|
||||
var shift: usize = 0;
|
||||
@ -87,8 +87,8 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
|
||||
}
|
||||
|
||||
pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
|
||||
const UT = @IntType(false, T.bit_count);
|
||||
const ShiftT = @IntType(false, std.math.log2(T.bit_count));
|
||||
const UT = std.meta.IntType(false, T.bit_count);
|
||||
const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
|
||||
|
||||
var result: UT = 0;
|
||||
var shift: usize = 0;
|
||||
|
||||
@ -82,7 +82,7 @@ pub fn format(
|
||||
comptime fmt: []const u8,
|
||||
args: var,
|
||||
) Errors!void {
|
||||
const ArgSetType = @IntType(false, 32);
|
||||
const ArgSetType = u32;
|
||||
if (@typeInfo(@TypeOf(args)) != .Struct) {
|
||||
@compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args)));
|
||||
}
|
||||
@ -405,7 +405,7 @@ pub fn formatType(
|
||||
try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});
|
||||
}
|
||||
},
|
||||
.Struct => {
|
||||
.Struct => |StructT| {
|
||||
if (comptime std.meta.trait.hasFn("format")(T)) {
|
||||
return value.format(fmt, options, context, Errors, output);
|
||||
}
|
||||
@ -416,27 +416,28 @@ pub fn formatType(
|
||||
}
|
||||
comptime var field_i = 0;
|
||||
try output(context, "{");
|
||||
inline while (field_i < @memberCount(T)) : (field_i += 1) {
|
||||
inline for (StructT.fields) |f| {
|
||||
if (field_i == 0) {
|
||||
try output(context, " .");
|
||||
} else {
|
||||
try output(context, ", .");
|
||||
}
|
||||
try output(context, @memberName(T, field_i));
|
||||
try output(context, f.name);
|
||||
try output(context, " = ");
|
||||
try formatType(@field(value, @memberName(T, field_i)), fmt, options, context, Errors, output, max_depth - 1);
|
||||
try formatType(@field(value, f.name), fmt, options, context, Errors, output, max_depth - 1);
|
||||
field_i += 1;
|
||||
}
|
||||
try output(context, " }");
|
||||
},
|
||||
.Pointer => |ptr_info| switch (ptr_info.size) {
|
||||
.One => switch (@typeInfo(ptr_info.child)) {
|
||||
builtin.TypeId.Array => |info| {
|
||||
.Array => |info| {
|
||||
if (info.child == u8) {
|
||||
return formatText(value, fmt, options, context, Errors, output);
|
||||
}
|
||||
return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
|
||||
},
|
||||
builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {
|
||||
.Enum, .Union, .Struct => {
|
||||
return formatType(value.*, fmt, options, context, Errors, output, max_depth);
|
||||
},
|
||||
else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
|
||||
@ -509,7 +510,7 @@ fn formatValue(
|
||||
}
|
||||
|
||||
const T = @TypeOf(value);
|
||||
switch (@typeId(T)) {
|
||||
switch (@typeInfo(T)) {
|
||||
.Float => return formatFloatValue(value, fmt, options, context, Errors, output),
|
||||
.Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
|
||||
.Bool => return output(context, if (value) "true" else "false"),
|
||||
@ -943,7 +944,7 @@ fn formatIntSigned(
|
||||
.fill = options.fill,
|
||||
};
|
||||
|
||||
const uint = @IntType(false, @TypeOf(value).bit_count);
|
||||
const uint = std.meta.IntType(false, @TypeOf(value).bit_count);
|
||||
if (value < 0) {
|
||||
const minus_sign: u8 = '-';
|
||||
try output(context, @as(*const [1]u8, &minus_sign)[0..]);
|
||||
@ -971,7 +972,7 @@ fn formatIntUnsigned(
|
||||
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);
|
||||
const MinInt = std.meta.IntType(@TypeOf(value).is_signed, min_int_bits);
|
||||
var a: MinInt = value;
|
||||
var index: usize = buf.len;
|
||||
|
||||
|
||||
@ -393,7 +393,7 @@ test "fmt.parseFloat" {
|
||||
const epsilon = 1e-7;
|
||||
|
||||
inline for ([_]type{ f16, f32, f64, f128 }) |T| {
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
|
||||
testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
|
||||
|
||||
@ -93,7 +93,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
|
||||
// TODO Check if the situation is better after #561 is resolved.
|
||||
.Int => @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)}),
|
||||
|
||||
.Float => |info| hash(hasher, @bitCast(@IntType(false, info.bits), key), strat),
|
||||
.Float => |info| hash(hasher, @bitCast(std.meta.IntType(false, info.bits), key), strat),
|
||||
|
||||
.Bool => hash(hasher, @boolToInt(key), strat),
|
||||
.Enum => hash(hasher, @enumToInt(key), strat),
|
||||
|
||||
@ -10,7 +10,7 @@ const primes = [_]u64{
|
||||
};
|
||||
|
||||
fn read_bytes(comptime bytes: u8, data: []const u8) u64 {
|
||||
const T = @IntType(false, 8 * bytes);
|
||||
const T = std.meta.IntType(false, 8 * bytes);
|
||||
return mem.readIntSliceLittle(T, data[0..bytes]);
|
||||
}
|
||||
|
||||
|
||||
@ -1015,7 +1015,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
|
||||
// very near usize?
|
||||
if (mem.page_size << 2 > maxInt(usize)) return;
|
||||
|
||||
const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
|
||||
const USizeShift = std.meta.IntType(false, std.math.log2(usize.bit_count));
|
||||
const large_align = @as(u29, mem.page_size << 2);
|
||||
|
||||
var align_mask: usize = undefined;
|
||||
|
||||
@ -337,7 +337,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
|
||||
assert(u_bit_count >= bits);
|
||||
break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
|
||||
};
|
||||
const Buf = @IntType(false, buf_bit_count);
|
||||
const Buf = std.meta.IntType(false, buf_bit_count);
|
||||
const BufShift = math.Log2Int(Buf);
|
||||
|
||||
out_bits.* = @as(usize, 0);
|
||||
@ -659,7 +659,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
|
||||
assert(u_bit_count >= bits);
|
||||
break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
|
||||
};
|
||||
const Buf = @IntType(false, buf_bit_count);
|
||||
const Buf = std.meta.IntType(false, buf_bit_count);
|
||||
const BufShift = math.Log2Int(Buf);
|
||||
|
||||
const buf_value = @intCast(Buf, value);
|
||||
@ -831,12 +831,12 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
|
||||
//@BUG: inferred error issue. See: #1386
|
||||
fn deserializeInt(self: *Self, comptime T: type) (Error || error{EndOfStream})!T {
|
||||
comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
|
||||
comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T));
|
||||
|
||||
const u8_bit_count = 8;
|
||||
const t_bit_count = comptime meta.bitCount(T);
|
||||
|
||||
const U = @IntType(false, t_bit_count);
|
||||
const U = std.meta.IntType(false, t_bit_count);
|
||||
const Log2U = math.Log2Int(U);
|
||||
const int_size = (U.bit_count + 7) / 8;
|
||||
|
||||
@ -851,7 +851,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
|
||||
if (int_size == 1) {
|
||||
if (t_bit_count == 8) return @bitCast(T, buffer[0]);
|
||||
const PossiblySignedByte = @IntType(T.is_signed, 8);
|
||||
const PossiblySignedByte = std.meta.IntType(T.is_signed, 8);
|
||||
return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
|
||||
}
|
||||
|
||||
@ -880,9 +880,9 @@ 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);
|
||||
comptime assert(trait.is(builtin.TypeId.Pointer)(T));
|
||||
comptime assert(trait.is(.Pointer)(T));
|
||||
|
||||
if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) {
|
||||
if (comptime trait.isSlice(T) or comptime trait.isPtrTo(.Array)(T)) {
|
||||
for (ptr) |*v|
|
||||
try self.deserializeInto(v);
|
||||
return;
|
||||
@ -891,7 +891,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
comptime assert(trait.isSingleItemPtr(T));
|
||||
|
||||
const C = comptime meta.Child(T);
|
||||
const child_type_id = @typeId(C);
|
||||
const child_type_id = @typeInfo(C);
|
||||
|
||||
//custom deserializer: fn(self: *Self, deserializer: var) !void
|
||||
if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self);
|
||||
@ -902,10 +902,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
}
|
||||
|
||||
switch (child_type_id) {
|
||||
builtin.TypeId.Void => return,
|
||||
builtin.TypeId.Bool => ptr.* = (try self.deserializeInt(u1)) > 0,
|
||||
builtin.TypeId.Float, builtin.TypeId.Int => ptr.* = try self.deserializeInt(C),
|
||||
builtin.TypeId.Struct => {
|
||||
.Void => return,
|
||||
.Bool => ptr.* = (try self.deserializeInt(u1)) > 0,
|
||||
.Float, .Int => ptr.* = try self.deserializeInt(C),
|
||||
.Struct => {
|
||||
const info = @typeInfo(C).Struct;
|
||||
|
||||
inline for (info.fields) |*field_info| {
|
||||
@ -915,7 +915,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
if (FieldType == void or FieldType == u0) continue;
|
||||
|
||||
//it doesn't make any sense to read pointers
|
||||
if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) {
|
||||
if (comptime trait.is(.Pointer)(FieldType)) {
|
||||
@compileError("Will not " ++ "read field " ++ name ++ " of struct " ++
|
||||
@typeName(C) ++ " because it " ++ "is of pointer-type " ++
|
||||
@typeName(FieldType) ++ ".");
|
||||
@ -924,7 +924,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
try self.deserializeInto(&@field(ptr, name));
|
||||
}
|
||||
},
|
||||
builtin.TypeId.Union => {
|
||||
.Union => {
|
||||
const info = @typeInfo(C).Union;
|
||||
if (info.tag_type) |TagType| {
|
||||
//we avoid duplicate iteration over the enum tags
|
||||
@ -948,7 +948,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
@compileError("Cannot meaningfully deserialize " ++ @typeName(C) ++
|
||||
" because it is an untagged union. Use a custom deserialize().");
|
||||
},
|
||||
builtin.TypeId.Optional => {
|
||||
.Optional => {
|
||||
const OC = comptime meta.Child(C);
|
||||
const exists = (try self.deserializeInt(u1)) > 0;
|
||||
if (!exists) {
|
||||
@ -960,7 +960,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
|
||||
const val_ptr = &ptr.*.?;
|
||||
try self.deserializeInto(val_ptr);
|
||||
},
|
||||
builtin.TypeId.Enum => {
|
||||
.Enum => {
|
||||
var value = try self.deserializeInt(@TagType(C));
|
||||
ptr.* = try meta.intToEnum(C, value);
|
||||
},
|
||||
@ -1009,12 +1009,12 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
|
||||
|
||||
fn serializeInt(self: *Self, value: var) Error!void {
|
||||
const T = @TypeOf(value);
|
||||
comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
|
||||
comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T));
|
||||
|
||||
const t_bit_count = comptime meta.bitCount(T);
|
||||
const u8_bit_count = comptime meta.bitCount(u8);
|
||||
|
||||
const U = @IntType(false, t_bit_count);
|
||||
const U = std.meta.IntType(false, t_bit_count);
|
||||
const Log2U = math.Log2Int(U);
|
||||
const int_size = (U.bit_count + 7) / 8;
|
||||
|
||||
@ -1058,11 +1058,11 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
|
||||
return;
|
||||
}
|
||||
|
||||
switch (@typeId(T)) {
|
||||
builtin.TypeId.Void => return,
|
||||
builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
|
||||
builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
|
||||
builtin.TypeId.Struct => {
|
||||
switch (@typeInfo(T)) {
|
||||
.Void => return,
|
||||
.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
|
||||
.Float, .Int => try self.serializeInt(value),
|
||||
.Struct => {
|
||||
const info = @typeInfo(T);
|
||||
|
||||
inline for (info.Struct.fields) |*field_info| {
|
||||
@ -1072,7 +1072,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
|
||||
if (FieldType == void or FieldType == u0) continue;
|
||||
|
||||
//It doesn't make sense to write pointers
|
||||
if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) {
|
||||
if (comptime trait.is(.Pointer)(FieldType)) {
|
||||
@compileError("Will not " ++ "serialize field " ++ name ++
|
||||
" of struct " ++ @typeName(T) ++ " because it " ++
|
||||
"is of pointer-type " ++ @typeName(FieldType) ++ ".");
|
||||
@ -1080,7 +1080,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
|
||||
try self.serialize(@field(value, name));
|
||||
}
|
||||
},
|
||||
builtin.TypeId.Union => {
|
||||
.Union => {
|
||||
const info = @typeInfo(T).Union;
|
||||
if (info.tag_type) |TagType| {
|
||||
const active_tag = meta.activeTag(value);
|
||||
@ -1101,7 +1101,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
|
||||
@compileError("Cannot meaningfully serialize " ++ @typeName(T) ++
|
||||
" because it is an untagged union. Use a custom serialize().");
|
||||
},
|
||||
builtin.TypeId.Optional => {
|
||||
.Optional => {
|
||||
if (value == null) {
|
||||
try self.serializeInt(@as(u1, @boolToInt(false)));
|
||||
return;
|
||||
@ -1112,10 +1112,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
|
||||
const val_ptr = &value.?;
|
||||
try self.serialize(val_ptr.*);
|
||||
},
|
||||
builtin.TypeId.Enum => {
|
||||
.Enum => {
|
||||
try self.serializeInt(@enumToInt(value));
|
||||
},
|
||||
else => @compileError("Cannot serialize " ++ @tagName(@typeId(T)) ++ " types (unimplemented)."),
|
||||
else => @compileError("Cannot serialize " ++ @tagName(@typeInfo(T)) ++ " types (unimplemented)."),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -318,6 +318,7 @@ test "BitStreams with File Stream" {
|
||||
}
|
||||
|
||||
fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void {
|
||||
@setEvalBranchQuota(1500);
|
||||
//@NOTE: if this test is taking too long, reduce the maximum tested bitsize
|
||||
const max_test_bitsize = 128;
|
||||
|
||||
@ -341,8 +342,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
|
||||
|
||||
comptime var i = 0;
|
||||
inline while (i <= max_test_bitsize) : (i += 1) {
|
||||
const U = @IntType(false, i);
|
||||
const S = @IntType(true, i);
|
||||
const U = std.meta.IntType(false, i);
|
||||
const S = std.meta.IntType(true, i);
|
||||
try serializer.serializeInt(@as(U, i));
|
||||
if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
|
||||
}
|
||||
@ -350,8 +351,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
|
||||
|
||||
i = 0;
|
||||
inline while (i <= max_test_bitsize) : (i += 1) {
|
||||
const U = @IntType(false, i);
|
||||
const S = @IntType(true, i);
|
||||
const U = std.meta.IntType(false, i);
|
||||
const S = std.meta.IntType(true, i);
|
||||
const x = try deserializer.deserializeInt(U);
|
||||
const y = try deserializer.deserializeInt(S);
|
||||
expect(x == @as(U, i));
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("std.zig");
|
||||
const TypeId = builtin.TypeId;
|
||||
const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
|
||||
@ -89,7 +87,7 @@ pub const snan = @import("math/nan.zig").snan;
|
||||
pub const inf = @import("math/inf.zig").inf;
|
||||
|
||||
pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
|
||||
assert(@typeId(T) == TypeId.Float);
|
||||
assert(@typeInfo(T) == .Float);
|
||||
return fabs(x - y) < epsilon;
|
||||
}
|
||||
|
||||
@ -198,7 +196,7 @@ test "" {
|
||||
}
|
||||
|
||||
pub fn floatMantissaBits(comptime T: type) comptime_int {
|
||||
assert(@typeId(T) == builtin.TypeId.Float);
|
||||
assert(@typeInfo(T) == .Float);
|
||||
|
||||
return switch (T.bit_count) {
|
||||
16 => 10,
|
||||
@ -211,7 +209,7 @@ pub fn floatMantissaBits(comptime T: type) comptime_int {
|
||||
}
|
||||
|
||||
pub fn floatExponentBits(comptime T: type) comptime_int {
|
||||
assert(@typeId(T) == builtin.TypeId.Float);
|
||||
assert(@typeInfo(T) == .Float);
|
||||
|
||||
return switch (T.bit_count) {
|
||||
16 => 5,
|
||||
@ -446,7 +444,7 @@ pub fn Log2Int(comptime T: type) type {
|
||||
count += 1;
|
||||
}
|
||||
|
||||
return @IntType(false, count);
|
||||
return std.meta.IntType(false, count);
|
||||
}
|
||||
|
||||
pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) type {
|
||||
@ -462,7 +460,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
|
||||
if (is_signed) {
|
||||
magnitude_bits += 1;
|
||||
}
|
||||
return @IntType(is_signed, magnitude_bits);
|
||||
return std.meta.IntType(is_signed, magnitude_bits);
|
||||
}
|
||||
|
||||
test "math.IntFittingRange" {
|
||||
@ -526,7 +524,7 @@ fn testOverflow() void {
|
||||
|
||||
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(@typeInfo(T) == .Int); // must pass an integer to absInt
|
||||
comptime assert(T.is_signed); // must pass a signed integer to absInt
|
||||
|
||||
if (x == minInt(@TypeOf(x))) {
|
||||
@ -560,7 +558,7 @@ fn testAbsFloat() void {
|
||||
pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
|
||||
@setRuntimeSafety(false);
|
||||
if (denominator == 0) return error.DivisionByZero;
|
||||
if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
|
||||
if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
|
||||
return @divTrunc(numerator, denominator);
|
||||
}
|
||||
|
||||
@ -581,7 +579,7 @@ fn testDivTrunc() void {
|
||||
pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
|
||||
@setRuntimeSafety(false);
|
||||
if (denominator == 0) return error.DivisionByZero;
|
||||
if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
|
||||
if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
|
||||
return @divFloor(numerator, denominator);
|
||||
}
|
||||
|
||||
@ -602,7 +600,7 @@ fn testDivFloor() void {
|
||||
pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
|
||||
@setRuntimeSafety(false);
|
||||
if (denominator == 0) return error.DivisionByZero;
|
||||
if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
|
||||
if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
|
||||
const result = @divTrunc(numerator, denominator);
|
||||
if (result * denominator != numerator) return error.UnexpectedRemainder;
|
||||
return result;
|
||||
@ -676,13 +674,13 @@ pub fn absCast(x: var) t: {
|
||||
if (@TypeOf(x) == comptime_int) {
|
||||
break :t comptime_int;
|
||||
} else {
|
||||
break :t @IntType(false, @TypeOf(x).bit_count);
|
||||
break :t std.meta.IntType(false, @TypeOf(x).bit_count);
|
||||
}
|
||||
} {
|
||||
if (@TypeOf(x) == comptime_int) {
|
||||
return if (x < 0) -x else x;
|
||||
}
|
||||
const uint = @IntType(false, @TypeOf(x).bit_count);
|
||||
const uint = std.meta.IntType(false, @TypeOf(x).bit_count);
|
||||
if (x >= 0) return @intCast(uint, x);
|
||||
|
||||
return @intCast(uint, -(x + 1)) + 1;
|
||||
@ -703,10 +701,10 @@ test "math.absCast" {
|
||||
|
||||
/// Returns the negation of the integer parameter.
|
||||
/// Result is a signed integer.
|
||||
pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) {
|
||||
pub fn negateCast(x: var) !std.meta.IntType(true, @TypeOf(x).bit_count) {
|
||||
if (@TypeOf(x).is_signed) return negate(x);
|
||||
|
||||
const int = @IntType(true, @TypeOf(x).bit_count);
|
||||
const int = std.meta.IntType(true, @TypeOf(x).bit_count);
|
||||
if (x > -minInt(int)) return error.Overflow;
|
||||
|
||||
if (x == -minInt(int)) return minInt(int);
|
||||
@ -727,8 +725,8 @@ test "math.negateCast" {
|
||||
/// Cast an integer to a different integer type. If the value doesn't fit,
|
||||
/// return an error.
|
||||
pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
|
||||
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
|
||||
comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer
|
||||
comptime assert(@typeInfo(T) == .Int); // must pass an integer
|
||||
comptime assert(@typeInfo(@TypeOf(x)) == .Int); // must pass an integer
|
||||
if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
|
||||
return error.Overflow;
|
||||
} else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {
|
||||
@ -792,11 +790,11 @@ fn testFloorPowerOfTwo() void {
|
||||
/// Returns the next power of two (if the value is not already a power of two).
|
||||
/// Only unsigned integers can be used. Zero is not an allowed input.
|
||||
/// Result is a type with 1 more bit than the input type.
|
||||
pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T.bit_count + 1) {
|
||||
comptime assert(@typeId(T) == builtin.TypeId.Int);
|
||||
pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.IntType(T.is_signed, T.bit_count + 1) {
|
||||
comptime assert(@typeInfo(T) == .Int);
|
||||
comptime assert(!T.is_signed);
|
||||
assert(value != 0);
|
||||
comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
|
||||
comptime const PromotedType = std.meta.IntType(T.is_signed, T.bit_count + 1);
|
||||
comptime const shiftType = std.math.Log2Int(PromotedType);
|
||||
return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
|
||||
}
|
||||
@ -805,9 +803,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
|
||||
/// Only unsigned integers can be used. Zero is not an allowed input.
|
||||
/// If the value doesn't fit, returns an error.
|
||||
pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
|
||||
comptime assert(@typeId(T) == builtin.TypeId.Int);
|
||||
comptime assert(@typeInfo(T) == .Int);
|
||||
comptime assert(!T.is_signed);
|
||||
comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
|
||||
comptime const PromotedType = std.meta.IntType(T.is_signed, T.bit_count + 1);
|
||||
comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
|
||||
var x = ceilPowerOfTwoPromote(T, value);
|
||||
if (overflowBit & x != 0) {
|
||||
@ -878,10 +876,10 @@ test "std.math.log2_int_ceil" {
|
||||
|
||||
pub fn lossyCast(comptime T: type, value: var) T {
|
||||
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),
|
||||
builtin.TypeId.ComptimeFloat => return @as(T, value),
|
||||
.Int => return @intToFloat(T, value),
|
||||
.Float => return @floatCast(T, value),
|
||||
.ComptimeInt => return @as(T, value),
|
||||
.ComptimeFloat => return @as(T, value),
|
||||
else => @compileError("bad type"),
|
||||
}
|
||||
}
|
||||
@ -949,8 +947,8 @@ test "max value type" {
|
||||
testing.expect(x == 2147483647);
|
||||
}
|
||||
|
||||
pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
|
||||
const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
|
||||
pub fn mulWide(comptime T: type, a: T, b: T) std.meta.IntType(T.is_signed, T.bit_count * 2) {
|
||||
const ResultInt = std.meta.IntType(T.is_signed, T.bit_count * 2);
|
||||
return @as(ResultInt, a) * @as(ResultInt, b);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
const std = @import("../../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const debug = std.debug;
|
||||
const testing = std.testing;
|
||||
const math = std.math;
|
||||
@ -9,10 +8,8 @@ const ArrayList = std.ArrayList;
|
||||
const maxInt = std.math.maxInt;
|
||||
const minInt = std.math.minInt;
|
||||
|
||||
const TypeId = builtin.TypeId;
|
||||
|
||||
pub const Limb = usize;
|
||||
pub const DoubleLimb = @IntType(false, 2 * Limb.bit_count);
|
||||
pub const DoubleLimb = std.meta.IntType(false, 2 * Limb.bit_count);
|
||||
pub const Log2Limb = math.Log2Int(Limb);
|
||||
|
||||
comptime {
|
||||
@ -270,8 +267,8 @@ pub const Int = struct {
|
||||
const T = @TypeOf(value);
|
||||
|
||||
switch (@typeInfo(T)) {
|
||||
TypeId.Int => |info| {
|
||||
const UT = if (T.is_signed) @IntType(false, T.bit_count - 1) else T;
|
||||
.Int => |info| {
|
||||
const UT = if (T.is_signed) std.meta.IntType(false, T.bit_count - 1) else T;
|
||||
|
||||
try self.ensureCapacity(@sizeOf(UT) / @sizeOf(Limb));
|
||||
self.metadata = 0;
|
||||
@ -294,7 +291,7 @@ pub const Int = struct {
|
||||
}
|
||||
}
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
.ComptimeInt => {
|
||||
comptime var w_value = if (value < 0) -value else value;
|
||||
|
||||
const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1;
|
||||
@ -332,9 +329,9 @@ pub const Int = struct {
|
||||
///
|
||||
/// Returns an error if self cannot be narrowed into the requested type without truncation.
|
||||
pub fn to(self: Int, comptime T: type) ConvertError!T {
|
||||
switch (@typeId(T)) {
|
||||
TypeId.Int => {
|
||||
const UT = @IntType(false, T.bit_count);
|
||||
switch (@typeInfo(T)) {
|
||||
.Int => {
|
||||
const UT = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
if (self.bitCountTwosComp() > T.bit_count) {
|
||||
return error.TargetTooSmall;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
const std = @import("../../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const debug = std.debug;
|
||||
const math = std.math;
|
||||
const mem = std.mem;
|
||||
@ -7,8 +6,6 @@ const testing = std.testing;
|
||||
const Allocator = mem.Allocator;
|
||||
const ArrayList = std.ArrayList;
|
||||
|
||||
const TypeId = builtin.TypeId;
|
||||
|
||||
const bn = @import("int.zig");
|
||||
const Limb = bn.Limb;
|
||||
const DoubleLimb = bn.DoubleLimb;
|
||||
@ -129,9 +126,9 @@ pub const Rational = struct {
|
||||
/// completely represent the provided float.
|
||||
pub fn setFloat(self: *Rational, comptime T: type, f: T) !void {
|
||||
// Translated from golang.go/src/math/big/rat.go.
|
||||
debug.assert(@typeId(T) == builtin.TypeId.Float);
|
||||
debug.assert(@typeInfo(T) == .Float);
|
||||
|
||||
const UnsignedIntType = @IntType(false, T.bit_count);
|
||||
const UnsignedIntType = std.meta.IntType(false, T.bit_count);
|
||||
const f_bits = @bitCast(UnsignedIntType, f);
|
||||
|
||||
const exponent_bits = math.floatExponentBits(T);
|
||||
@ -187,10 +184,10 @@ pub const Rational = struct {
|
||||
pub fn toFloat(self: Rational, comptime T: type) !T {
|
||||
// Translated from golang.go/src/math/big/rat.go.
|
||||
// TODO: Indicate whether the result is not exact.
|
||||
debug.assert(@typeId(T) == builtin.TypeId.Float);
|
||||
debug.assert(@typeInfo(T) == .Float);
|
||||
|
||||
const fsize = T.bit_count;
|
||||
const BitReprType = @IntType(false, T.bit_count);
|
||||
const BitReprType = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
const msize = math.floatMantissaBits(T);
|
||||
const msize1 = msize + 1;
|
||||
@ -465,7 +462,7 @@ pub const Rational = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const SignedDoubleLimb = @IntType(true, DoubleLimb.bit_count);
|
||||
const SignedDoubleLimb = std.meta.IntType(true, DoubleLimb.bit_count);
|
||||
|
||||
fn gcd(rma: *Int, x: Int, y: Int) !void {
|
||||
rma.assertWritable();
|
||||
@ -653,7 +650,7 @@ test "big.rational gcd one large" {
|
||||
}
|
||||
|
||||
fn extractLowBits(a: Int, comptime T: type) T {
|
||||
testing.expect(@typeId(T) == builtin.TypeId.Int);
|
||||
testing.expect(@typeInfo(T) == .Int);
|
||||
|
||||
if (T.bit_count <= Limb.bit_count) {
|
||||
return @truncate(T, a.limbs[0]);
|
||||
|
||||
@ -44,7 +44,7 @@ const pi4c = 2.69515142907905952645E-15;
|
||||
const m4pi = 1.273239544735162542821171882678754627704620361328125;
|
||||
|
||||
fn cos_(comptime T: type, x_: T) T {
|
||||
const I = @IntType(true, T.bit_count);
|
||||
const I = std.meta.IntType(true, T.bit_count);
|
||||
|
||||
var x = x_;
|
||||
if (math.isNan(x) or math.isInf(x)) {
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
const builtin = @import("builtin");
|
||||
const TypeId = builtin.TypeId;
|
||||
|
||||
/// Returns the natural logarithm of x.
|
||||
///
|
||||
@ -19,21 +17,21 @@ const TypeId = builtin.TypeId;
|
||||
/// - ln(nan) = nan
|
||||
pub fn ln(x: var) @TypeOf(x) {
|
||||
const T = @TypeOf(x);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
switch (@typeInfo(T)) {
|
||||
.ComptimeFloat => {
|
||||
return @as(comptime_float, ln_64(x));
|
||||
},
|
||||
TypeId.Float => {
|
||||
.Float => {
|
||||
return switch (T) {
|
||||
f32 => ln_32(x),
|
||||
f64 => ln_64(x),
|
||||
else => @compileError("ln not implemented for " ++ @typeName(T)),
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
.ComptimeInt => {
|
||||
return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
|
||||
},
|
||||
TypeId.Int => {
|
||||
.Int => {
|
||||
return @as(T, math.floor(ln_64(@as(f64, x))));
|
||||
},
|
||||
else => @compileError("ln not implemented for " ++ @typeName(T)),
|
||||
|
||||
@ -6,8 +6,6 @@
|
||||
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const builtin = @import("builtin");
|
||||
const TypeId = builtin.TypeId;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
/// Returns the logarithm of x for the provided base.
|
||||
@ -16,24 +14,24 @@ pub fn log(comptime T: type, base: T, x: T) T {
|
||||
return math.log2(x);
|
||||
} else if (base == 10) {
|
||||
return math.log10(x);
|
||||
} else if ((@typeId(T) == TypeId.Float or @typeId(T) == TypeId.ComptimeFloat) and base == math.e) {
|
||||
} else if ((@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat) and base == math.e) {
|
||||
return math.ln(x);
|
||||
}
|
||||
|
||||
const float_base = math.lossyCast(f64, base);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
switch (@typeInfo(T)) {
|
||||
.ComptimeFloat => {
|
||||
return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base));
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
.ComptimeInt => {
|
||||
return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
|
||||
},
|
||||
builtin.TypeId.Int => {
|
||||
.Int => {
|
||||
// TODO implement integer log without using float math
|
||||
return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base)));
|
||||
},
|
||||
|
||||
builtin.TypeId.Float => {
|
||||
.Float => {
|
||||
switch (T) {
|
||||
f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),
|
||||
f64 => return math.ln(x) / math.ln(float_base),
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const testing = std.testing;
|
||||
const builtin = @import("builtin");
|
||||
const TypeId = builtin.TypeId;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
/// Returns the base-10 logarithm of x.
|
||||
@ -20,21 +18,21 @@ const maxInt = std.math.maxInt;
|
||||
/// - log10(nan) = nan
|
||||
pub fn log10(x: var) @TypeOf(x) {
|
||||
const T = @TypeOf(x);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
switch (@typeInfo(T)) {
|
||||
.ComptimeFloat => {
|
||||
return @as(comptime_float, log10_64(x));
|
||||
},
|
||||
TypeId.Float => {
|
||||
.Float => {
|
||||
return switch (T) {
|
||||
f32 => log10_32(x),
|
||||
f64 => log10_64(x),
|
||||
else => @compileError("log10 not implemented for " ++ @typeName(T)),
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => {
|
||||
.ComptimeInt => {
|
||||
return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
|
||||
},
|
||||
TypeId.Int => {
|
||||
.Int => {
|
||||
return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
|
||||
},
|
||||
else => @compileError("log10 not implemented for " ++ @typeName(T)),
|
||||
|
||||
@ -7,8 +7,6 @@
|
||||
const std = @import("../std.zig");
|
||||
const math = std.math;
|
||||
const expect = std.testing.expect;
|
||||
const builtin = @import("builtin");
|
||||
const TypeId = builtin.TypeId;
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
/// Returns the base-2 logarithm of x.
|
||||
@ -20,18 +18,18 @@ const maxInt = std.math.maxInt;
|
||||
/// - log2(nan) = nan
|
||||
pub fn log2(x: var) @TypeOf(x) {
|
||||
const T = @TypeOf(x);
|
||||
switch (@typeId(T)) {
|
||||
TypeId.ComptimeFloat => {
|
||||
switch (@typeInfo(T)) {
|
||||
.ComptimeFloat => {
|
||||
return @as(comptime_float, log2_64(x));
|
||||
},
|
||||
TypeId.Float => {
|
||||
.Float => {
|
||||
return switch (T) {
|
||||
f32 => log2_32(x),
|
||||
f64 => log2_64(x),
|
||||
else => @compileError("log2 not implemented for " ++ @typeName(T)),
|
||||
};
|
||||
},
|
||||
TypeId.ComptimeInt => comptime {
|
||||
.ComptimeInt => comptime {
|
||||
var result = 0;
|
||||
var x_shifted = x;
|
||||
while (b: {
|
||||
@ -40,7 +38,7 @@ pub fn log2(x: var) @TypeOf(x) {
|
||||
}) : (result += 1) {}
|
||||
return result;
|
||||
},
|
||||
TypeId.Int => {
|
||||
.Int => {
|
||||
return math.log2_int(T, x);
|
||||
},
|
||||
else => @compileError("log2 not implemented for " ++ @typeName(T)),
|
||||
|
||||
@ -145,7 +145,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
|
||||
var xe = r2.exponent;
|
||||
var x1 = r2.significand;
|
||||
|
||||
var i = @floatToInt(@IntType(true, T.bit_count), yi);
|
||||
var i = @floatToInt(std.meta.IntType(true, T.bit_count), yi);
|
||||
while (i != 0) : (i >>= 1) {
|
||||
const overflow_shift = math.floatExponentBits(T) + 1;
|
||||
if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) {
|
||||
|
||||
@ -45,7 +45,7 @@ const pi4c = 2.69515142907905952645E-15;
|
||||
const m4pi = 1.273239544735162542821171882678754627704620361328125;
|
||||
|
||||
fn sin_(comptime T: type, x_: T) T {
|
||||
const I = @IntType(true, T.bit_count);
|
||||
const I = std.meta.IntType(true, T.bit_count);
|
||||
|
||||
var x = x_;
|
||||
if (x == 0 or math.isNan(x)) {
|
||||
|
||||
@ -31,7 +31,7 @@ pub fn sqrt(x: var) Sqrt(@TypeOf(x)) {
|
||||
}
|
||||
}
|
||||
|
||||
fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
|
||||
fn sqrt_int(comptime T: type, value: T) std.meta.IntType(false, T.bit_count / 2) {
|
||||
var op = value;
|
||||
var res: T = 0;
|
||||
var one: T = 1 << (T.bit_count - 2);
|
||||
@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
|
||||
one >>= 2;
|
||||
}
|
||||
|
||||
const ResultType = @IntType(false, T.bit_count / 2);
|
||||
const ResultType = std.meta.IntType(false, T.bit_count / 2);
|
||||
return @intCast(ResultType, res);
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ test "math.sqrt_int" {
|
||||
/// Returns the return type `sqrt` will return given an operand of type `T`.
|
||||
pub fn Sqrt(comptime T: type) type {
|
||||
return switch (@typeInfo(T)) {
|
||||
.Int => |int| @IntType(false, int.bits / 2),
|
||||
.Int => |int| std.meta.IntType(false, int.bits / 2),
|
||||
else => T,
|
||||
};
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ const pi4c = 2.69515142907905952645E-15;
|
||||
const m4pi = 1.273239544735162542821171882678754627704620361328125;
|
||||
|
||||
fn tan_(comptime T: type, x_: T) T {
|
||||
const I = @IntType(true, T.bit_count);
|
||||
const I = std.meta.IntType(true, T.bit_count);
|
||||
|
||||
var x = x_;
|
||||
if (x == 0 or math.isNan(x)) {
|
||||
|
||||
@ -708,7 +708,7 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
|
||||
assert(buffer.len >= @divExact(T.bit_count, 8));
|
||||
|
||||
// TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough
|
||||
const uint = @IntType(false, T.bit_count);
|
||||
const uint = std.meta.IntType(false, T.bit_count);
|
||||
var bits = @truncate(uint, value);
|
||||
for (buffer) |*b| {
|
||||
b.* = @truncate(u8, bits);
|
||||
@ -725,7 +725,7 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
|
||||
assert(buffer.len >= @divExact(T.bit_count, 8));
|
||||
|
||||
// TODO I want to call writeIntBig here but comptime eval facilities aren't good enough
|
||||
const uint = @IntType(false, T.bit_count);
|
||||
const uint = std.meta.IntType(false, T.bit_count);
|
||||
var bits = @truncate(uint, value);
|
||||
var index: usize = buffer.len;
|
||||
while (index != 0) {
|
||||
|
||||
@ -536,9 +536,8 @@ test "intToEnum with error return" {
|
||||
pub const IntToEnumError = error{InvalidEnumTag};
|
||||
|
||||
pub fn intToEnum(comptime Tag: type, tag_int: var) IntToEnumError!Tag {
|
||||
comptime var i = 0;
|
||||
inline while (i != @memberCount(Tag)) : (i += 1) {
|
||||
const this_tag_value = @field(Tag, @memberName(Tag, i));
|
||||
inline for (@typeInfo(Tag).Enum.fields) |f| {
|
||||
const this_tag_value = @field(Tag, f.name);
|
||||
if (tag_int == @enumToInt(this_tag_value)) {
|
||||
return this_tag_value;
|
||||
}
|
||||
@ -581,3 +580,12 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
|
||||
return &array;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn IntType(comptime is_signed: bool, comptime bit_count: u16) type {
|
||||
return @Type(TypeInfo{
|
||||
.Int = .{
|
||||
.is_signed = is_signed,
|
||||
.bits = bit_count,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const builtin = std.builtin;
|
||||
const mem = std.mem;
|
||||
const debug = std.debug;
|
||||
const testing = std.testing;
|
||||
@ -54,7 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
|
||||
if (!comptime isContainer(T)) return false;
|
||||
if (!comptime @hasDecl(T, name)) return false;
|
||||
const DeclType = @TypeOf(@field(T, name));
|
||||
return @typeId(DeclType) == .Fn;
|
||||
return @typeInfo(DeclType) == .Fn;
|
||||
}
|
||||
};
|
||||
return Closure.trait;
|
||||
@ -105,7 +105,7 @@ test "std.meta.trait.hasField" {
|
||||
pub fn is(comptime id: builtin.TypeId) TraitFn {
|
||||
const Closure = struct {
|
||||
pub fn trait(comptime T: type) bool {
|
||||
return id == @typeId(T);
|
||||
return id == @typeInfo(T);
|
||||
}
|
||||
};
|
||||
return Closure.trait;
|
||||
@ -123,7 +123,7 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
|
||||
const Closure = struct {
|
||||
pub fn trait(comptime T: type) bool {
|
||||
if (!comptime isSingleItemPtr(T)) return false;
|
||||
return id == @typeId(meta.Child(T));
|
||||
return id == @typeInfo(meta.Child(T));
|
||||
}
|
||||
};
|
||||
return Closure.trait;
|
||||
@ -139,7 +139,7 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
|
||||
const Closure = struct {
|
||||
pub fn trait(comptime T: type) bool {
|
||||
if (!comptime isSlice(T)) return false;
|
||||
return id == @typeId(meta.Child(T));
|
||||
return id == @typeInfo(meta.Child(T));
|
||||
}
|
||||
};
|
||||
return Closure.trait;
|
||||
@ -285,7 +285,7 @@ test "std.meta.trait.isIndexable" {
|
||||
}
|
||||
|
||||
pub fn isNumber(comptime T: type) bool {
|
||||
return switch (@typeId(T)) {
|
||||
return switch (@typeInfo(T)) {
|
||||
.Int, .Float, .ComptimeInt, .ComptimeFloat => true,
|
||||
else => false,
|
||||
};
|
||||
@ -320,7 +320,7 @@ test "std.meta.trait.isConstPtr" {
|
||||
}
|
||||
|
||||
pub fn isContainer(comptime T: type) bool {
|
||||
return switch (@typeId(T)) {
|
||||
return switch (@typeInfo(T)) {
|
||||
.Struct, .Union, .Enum => true,
|
||||
else => false,
|
||||
};
|
||||
|
||||
@ -3349,7 +3349,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 = std.meta.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);
|
||||
|
||||
@ -1004,7 +1004,7 @@ pub const dl_phdr_info = extern struct {
|
||||
|
||||
pub const CPU_SETSIZE = 128;
|
||||
pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
|
||||
pub const cpu_count_t = @IntType(false, std.math.log2(CPU_SETSIZE * 8));
|
||||
pub const cpu_count_t = std.meta.IntType(false, std.math.log2(CPU_SETSIZE * 8));
|
||||
|
||||
pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
|
||||
var sum: cpu_count_t = 0;
|
||||
|
||||
@ -34,13 +34,13 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: builtin.Endian) type {
|
||||
|
||||
//we bitcast the desired Int type to an unsigned version of itself
|
||||
// to avoid issues with shifting signed ints.
|
||||
const UnInt = @IntType(false, int_bits);
|
||||
const UnInt = std.meta.IntType(false, int_bits);
|
||||
|
||||
//The maximum container int type
|
||||
const MinIo = @IntType(false, min_io_bits);
|
||||
const MinIo = std.meta.IntType(false, min_io_bits);
|
||||
|
||||
//The minimum container int type
|
||||
const MaxIo = @IntType(false, max_io_bits);
|
||||
const MaxIo = std.meta.IntType(false, max_io_bits);
|
||||
|
||||
return struct {
|
||||
pub fn get(bytes: []const u8, index: usize, bit_offset: u7) Int {
|
||||
@ -322,7 +322,7 @@ test "PackedIntArray" {
|
||||
inline while (bits <= 256) : (bits += 1) {
|
||||
//alternate unsigned and signed
|
||||
const even = bits % 2 == 0;
|
||||
const I = @IntType(even, bits);
|
||||
const I = std.meta.IntType(even, bits);
|
||||
|
||||
const PackedArray = PackedIntArray(I, int_count);
|
||||
const expected_bytes = ((bits * int_count) + 7) / 8;
|
||||
@ -369,7 +369,7 @@ test "PackedIntSlice" {
|
||||
inline while (bits <= 256) : (bits += 1) {
|
||||
//alternate unsigned and signed
|
||||
const even = bits % 2 == 0;
|
||||
const I = @IntType(even, bits);
|
||||
const I = std.meta.IntType(even, bits);
|
||||
const P = PackedIntSlice(I);
|
||||
|
||||
var data = P.init(&buffer, int_count);
|
||||
@ -399,7 +399,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
|
||||
|
||||
comptime var bits = 0;
|
||||
inline while (bits <= max_bits) : (bits += 1) {
|
||||
const Int = @IntType(false, bits);
|
||||
const Int = std.meta.IntType(false, bits);
|
||||
|
||||
const PackedArray = PackedIntArray(Int, int_count);
|
||||
var packed_array = @as(PackedArray, undefined);
|
||||
|
||||
@ -45,8 +45,8 @@ pub const Random = struct {
|
||||
/// Returns a random int `i` such that `0 <= i <= maxInt(T)`.
|
||||
/// `i` is evenly distributed.
|
||||
pub fn int(r: *Random, comptime T: type) T {
|
||||
const UnsignedT = @IntType(false, T.bit_count);
|
||||
const ByteAlignedT = @IntType(false, @divTrunc(T.bit_count + 7, 8) * 8);
|
||||
const UnsignedT = std.meta.IntType(false, T.bit_count);
|
||||
const ByteAlignedT = std.meta.IntType(false, @divTrunc(T.bit_count + 7, 8) * 8);
|
||||
|
||||
var rand_bytes: [@sizeOf(ByteAlignedT)]u8 = undefined;
|
||||
r.bytes(rand_bytes[0..]);
|
||||
@ -85,9 +85,9 @@ pub const Random = struct {
|
||||
comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
|
||||
assert(0 < less_than);
|
||||
// Small is typically u32
|
||||
const Small = @IntType(false, @divTrunc(T.bit_count + 31, 32) * 32);
|
||||
const Small = std.meta.IntType(false, @divTrunc(T.bit_count + 31, 32) * 32);
|
||||
// Large is typically u64
|
||||
const Large = @IntType(false, Small.bit_count * 2);
|
||||
const Large = std.meta.IntType(false, Small.bit_count * 2);
|
||||
|
||||
// adapted from:
|
||||
// http://www.pcg-random.org/posts/bounded-rands.html
|
||||
@ -99,7 +99,7 @@ pub const Random = struct {
|
||||
// TODO: workaround for https://github.com/ziglang/zig/issues/1770
|
||||
// should be:
|
||||
// var t: Small = -%less_than;
|
||||
var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than)));
|
||||
var t: Small = @bitCast(Small, -%@bitCast(std.meta.IntType(true, Small.bit_count), @as(Small, less_than)));
|
||||
|
||||
if (t >= less_than) {
|
||||
t -= less_than;
|
||||
@ -145,7 +145,7 @@ pub const Random = struct {
|
||||
assert(at_least < less_than);
|
||||
if (T.is_signed) {
|
||||
// Two's complement makes this math pretty easy.
|
||||
const UnsignedT = @IntType(false, T.bit_count);
|
||||
const UnsignedT = std.meta.IntType(false, T.bit_count);
|
||||
const lo = @bitCast(UnsignedT, at_least);
|
||||
const hi = @bitCast(UnsignedT, less_than);
|
||||
const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);
|
||||
@ -163,7 +163,7 @@ pub const Random = struct {
|
||||
assert(at_least < less_than);
|
||||
if (T.is_signed) {
|
||||
// Two's complement makes this math pretty easy.
|
||||
const UnsignedT = @IntType(false, T.bit_count);
|
||||
const UnsignedT = std.meta.IntType(false, T.bit_count);
|
||||
const lo = @bitCast(UnsignedT, at_least);
|
||||
const hi = @bitCast(UnsignedT, less_than);
|
||||
const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);
|
||||
@ -180,7 +180,7 @@ pub const Random = struct {
|
||||
assert(at_least <= at_most);
|
||||
if (T.is_signed) {
|
||||
// Two's complement makes this math pretty easy.
|
||||
const UnsignedT = @IntType(false, T.bit_count);
|
||||
const UnsignedT = std.meta.IntType(false, T.bit_count);
|
||||
const lo = @bitCast(UnsignedT, at_least);
|
||||
const hi = @bitCast(UnsignedT, at_most);
|
||||
const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);
|
||||
@ -198,7 +198,7 @@ pub const Random = struct {
|
||||
assert(at_least <= at_most);
|
||||
if (T.is_signed) {
|
||||
// Two's complement makes this math pretty easy.
|
||||
const UnsignedT = @IntType(false, T.bit_count);
|
||||
const UnsignedT = std.meta.IntType(false, T.bit_count);
|
||||
const lo = @bitCast(UnsignedT, at_least);
|
||||
const hi = @bitCast(UnsignedT, at_most);
|
||||
const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);
|
||||
@ -281,7 +281,7 @@ pub const Random = struct {
|
||||
/// This function introduces a minor bias.
|
||||
pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
|
||||
comptime assert(T.is_signed == false);
|
||||
const T2 = @IntType(false, T.bit_count * 2);
|
||||
const T2 = std.meta.IntType(false, T.bit_count * 2);
|
||||
|
||||
// adapted from:
|
||||
// http://www.pcg-random.org/posts/bounded-rands.html
|
||||
|
||||
@ -128,7 +128,7 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
fn runBuild(builder: *Builder) anyerror!void {
|
||||
switch (@typeId(@TypeOf(root.build).ReturnType)) {
|
||||
switch (@typeInfo(@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'"),
|
||||
|
||||
@ -511,7 +511,7 @@ export fn roundf(a: f32) f32 {
|
||||
fn generic_fmod(comptime T: type, x: T, y: T) T {
|
||||
@setRuntimeSafety(false);
|
||||
|
||||
const uint = @IntType(false, T.bit_count);
|
||||
const uint = std.meta.IntType(false, T.bit_count);
|
||||
const log2uint = math.Log2Int(uint);
|
||||
const digits = if (T == f32) 23 else 52;
|
||||
const exp_bits = if (T == f32) 9 else 12;
|
||||
|
||||
@ -54,21 +54,21 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
|
||||
}
|
||||
|
||||
// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
|
||||
fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
|
||||
fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
const implicitBit = @as(Z, 1) << significandBits;
|
||||
|
||||
const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
|
||||
const shift = @clz(std.meta.IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
|
||||
significand.* <<= @intCast(S, shift);
|
||||
return 1 - shift;
|
||||
}
|
||||
|
||||
// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
|
||||
fn addXf3(comptime T: type, a: T, b: T) T {
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
|
||||
|
||||
const typeWidth = T.bit_count;
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
@ -182,7 +182,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
|
||||
// If partial cancellation occured, we need to left-shift the result
|
||||
// and adjust the exponent:
|
||||
if (aSignificand < implicitBit << 3) {
|
||||
const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(@IntType(false, T.bit_count), implicitBit << 3));
|
||||
const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.IntType(false, T.bit_count), implicitBit << 3));
|
||||
aSignificand <<= @intCast(S, shift);
|
||||
aExponent -= shift;
|
||||
}
|
||||
|
||||
@ -22,8 +22,8 @@ const GE = extern enum(i32) {
|
||||
pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
|
||||
const srep_t = @IntType(true, T.bit_count);
|
||||
const rep_t = @IntType(false, T.bit_count);
|
||||
const srep_t = std.meta.IntType(true, T.bit_count);
|
||||
const rep_t = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
const exponentBits = std.math.floatExponentBits(T);
|
||||
@ -68,7 +68,7 @@ pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
|
||||
pub fn unordcmp(comptime T: type, a: T, b: T) i32 {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
|
||||
const rep_t = @IntType(false, T.bit_count);
|
||||
const rep_t = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
const exponentBits = std.math.floatExponentBits(T);
|
||||
|
||||
@ -7,8 +7,8 @@ const builtin = @import("builtin");
|
||||
|
||||
pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
const Z = @IntType(false, f64.bit_count);
|
||||
const SignedZ = @IntType(true, f64.bit_count);
|
||||
const Z = std.meta.IntType(false, f64.bit_count);
|
||||
const SignedZ = std.meta.IntType(true, f64.bit_count);
|
||||
|
||||
const typeWidth = f64.bit_count;
|
||||
const significandBits = std.math.floatMantissaBits(f64);
|
||||
@ -312,9 +312,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
|
||||
fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
const implicitBit = @as(Z, 1) << significandBits;
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ const builtin = @import("builtin");
|
||||
|
||||
pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
const Z = @IntType(false, f32.bit_count);
|
||||
const Z = std.meta.IntType(false, f32.bit_count);
|
||||
|
||||
const typeWidth = f32.bit_count;
|
||||
const significandBits = std.math.floatMantissaBits(f32);
|
||||
@ -185,9 +185,9 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
|
||||
fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
const implicitBit = @as(Z, 1) << significandBits;
|
||||
|
||||
|
||||
@ -30,11 +30,11 @@ pub fn __aeabi_f2d(arg: f32) callconv(.AAPCS) f64 {
|
||||
|
||||
const CHAR_BIT = 8;
|
||||
|
||||
fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @typeInfo(src_t).Float.bits)) dst_t {
|
||||
fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: std.meta.IntType(false, @typeInfo(src_t).Float.bits)) dst_t {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
|
||||
const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits);
|
||||
const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);
|
||||
const src_rep_t = std.meta.IntType(false, @typeInfo(src_t).Float.bits);
|
||||
const dst_rep_t = std.meta.IntType(false, @typeInfo(dst_t).Float.bits);
|
||||
const srcSigBits = std.math.floatMantissaBits(src_t);
|
||||
const dstSigBits = std.math.floatMantissaBits(dst_t);
|
||||
const SrcShift = std.math.Log2Int(src_rep_t);
|
||||
|
||||
@ -45,7 +45,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
|
||||
if (exponent < 0) return 0;
|
||||
|
||||
// The unsigned result needs to be large enough to handle an fixint_t or rep_t
|
||||
const fixuint_t = @IntType(false, fixint_t.bit_count);
|
||||
const fixuint_t = std.meta.IntType(false, fixint_t.bit_count);
|
||||
const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t;
|
||||
var uint_result: UintResultType = undefined;
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
|
||||
f128 => u128,
|
||||
else => unreachable,
|
||||
};
|
||||
const srep_t = @IntType(true, rep_t.bit_count);
|
||||
const srep_t = @import("std").meta.IntType(true, rep_t.bit_count);
|
||||
const significandBits = switch (fp_t) {
|
||||
f32 => 23,
|
||||
f64 => 52,
|
||||
|
||||
@ -5,8 +5,8 @@ const maxInt = std.math.maxInt;
|
||||
fn floatsiXf(comptime T: type, a: i32) T {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
|
||||
|
||||
if (a == 0) {
|
||||
return @as(T, 0.0);
|
||||
|
||||
@ -28,7 +28,7 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {
|
||||
|
||||
fn mulXf3(comptime T: type, a: T, b: T) T {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
const typeWidth = T.bit_count;
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
@ -264,9 +264,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
|
||||
fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
|
||||
@setRuntimeSafety(builtin.is_test);
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
const implicitBit = @as(Z, 1) << significandBits;
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
|
||||
}
|
||||
|
||||
fn negXf2(comptime T: type, a: T) T {
|
||||
const Z = @IntType(false, T.bit_count);
|
||||
const Z = std.meta.IntType(false, T.bit_count);
|
||||
|
||||
const typeWidth = T.bit_count;
|
||||
const significandBits = std.math.floatMantissaBits(T);
|
||||
|
||||
@ -36,8 +36,8 @@ pub fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
|
||||
}
|
||||
|
||||
inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
|
||||
const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits);
|
||||
const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);
|
||||
const src_rep_t = std.meta.IntType(false, @typeInfo(src_t).Float.bits);
|
||||
const dst_rep_t = std.meta.IntType(false, @typeInfo(dst_t).Float.bits);
|
||||
const srcSigBits = std.math.floatMantissaBits(src_t);
|
||||
const dstSigBits = std.math.floatMantissaBits(dst_t);
|
||||
const SrcShift = std.math.Log2Int(src_rep_t);
|
||||
|
||||
@ -10,8 +10,8 @@ const high = 1 - low;
|
||||
pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {
|
||||
@setRuntimeSafety(is_test);
|
||||
|
||||
const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
|
||||
const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
|
||||
const SingleInt = @import("std").meta.IntType(false, @divExact(DoubleInt.bit_count, 2));
|
||||
const SignedDoubleInt = @import("std").meta.IntType(true, DoubleInt.bit_count);
|
||||
const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
|
||||
|
||||
const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
|
||||
|
||||
@ -222,7 +222,7 @@ pub const Target = union(enum) {
|
||||
pub const needed_bit_count = 154;
|
||||
pub const byte_count = (needed_bit_count + 7) / 8;
|
||||
pub const usize_count = (byte_count + (@sizeOf(usize) - 1)) / @sizeOf(usize);
|
||||
pub const Index = std.math.Log2Int(@IntType(false, usize_count * @bitSizeOf(usize)));
|
||||
pub const Index = std.math.Log2Int(std.meta.IntType(false, usize_count * @bitSizeOf(usize)));
|
||||
pub const ShiftInt = std.math.Log2Int(usize);
|
||||
|
||||
pub const empty = Set{ .ints = [1]usize{0} ** usize_count };
|
||||
|
||||
@ -148,7 +148,7 @@ pub const Thread = struct {
|
||||
const default_stack_size = 16 * 1024 * 1024;
|
||||
|
||||
const Context = @TypeOf(context);
|
||||
comptime assert(@ArgType(@TypeOf(startFn), 0) == Context);
|
||||
comptime assert(@typeInfo(@TypeOf(startFn)).Fn.args[0].arg_type.? == Context);
|
||||
|
||||
if (builtin.os == builtin.Os.windows) {
|
||||
const WinThread = struct {
|
||||
@ -158,7 +158,7 @@ pub const Thread = struct {
|
||||
};
|
||||
fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {
|
||||
const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
|
||||
switch (@typeId(@TypeOf(startFn).ReturnType)) {
|
||||
switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
|
||||
.Int => {
|
||||
return startFn(arg);
|
||||
},
|
||||
@ -201,7 +201,7 @@ pub const Thread = struct {
|
||||
fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {
|
||||
const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
|
||||
|
||||
switch (@typeId(@TypeOf(startFn).ReturnType)) {
|
||||
switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
|
||||
.Int => {
|
||||
return startFn(arg);
|
||||
},
|
||||
|
||||
@ -457,10 +457,9 @@ pub const Node = struct {
|
||||
}
|
||||
|
||||
pub fn iterate(base: *Node, index: usize) ?*Node {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (base.id == @field(Id, @memberName(Id, i))) {
|
||||
const T = @field(Node, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (base.id == @field(Id, f.name)) {
|
||||
const T = @field(Node, f.name);
|
||||
return @fieldParentPtr(T, "base", base).iterate(index);
|
||||
}
|
||||
}
|
||||
@ -468,10 +467,9 @@ pub const Node = struct {
|
||||
}
|
||||
|
||||
pub fn firstToken(base: *const Node) TokenIndex {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (base.id == @field(Id, @memberName(Id, i))) {
|
||||
const T = @field(Node, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (base.id == @field(Id, f.name)) {
|
||||
const T = @field(Node, f.name);
|
||||
return @fieldParentPtr(T, "base", base).firstToken();
|
||||
}
|
||||
}
|
||||
@ -479,10 +477,9 @@ pub const Node = struct {
|
||||
}
|
||||
|
||||
pub fn lastToken(base: *const Node) TokenIndex {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (base.id == @field(Id, @memberName(Id, i))) {
|
||||
const T = @field(Node, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (base.id == @field(Id, f.name)) {
|
||||
const T = @field(Node, f.name);
|
||||
return @fieldParentPtr(T, "base", base).lastToken();
|
||||
}
|
||||
}
|
||||
@ -490,10 +487,9 @@ pub const Node = struct {
|
||||
}
|
||||
|
||||
pub fn typeToId(comptime T: type) Id {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (T == @field(Node, @memberName(Id, i))) {
|
||||
return @field(Id, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (T == @field(Node, f.name)) {
|
||||
return @field(Id, f.name);
|
||||
}
|
||||
}
|
||||
unreachable;
|
||||
|
||||
@ -1410,7 +1410,7 @@ test "zig fmt: same-line comment after non-block if expression" {
|
||||
test "zig fmt: same-line comment on comptime expression" {
|
||||
try testCanonical(
|
||||
\\test "" {
|
||||
\\ comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
|
||||
\\ comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const mem = std.mem;
|
||||
const ast = std.zig.ast;
|
||||
@ -14,7 +13,7 @@ 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);
|
||||
comptime assert(@typeInfo(@TypeOf(stream)) == .Pointer);
|
||||
|
||||
var anything_changed: bool = false;
|
||||
|
||||
|
||||
@ -76,20 +76,18 @@ pub const Inst = struct {
|
||||
}
|
||||
|
||||
pub fn typeToId(comptime T: type) Id {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (T == @field(Inst, @memberName(Id, i))) {
|
||||
return @field(Id, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (T == @field(Inst, f.name)) {
|
||||
return @field(Id, f.name);
|
||||
}
|
||||
}
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub fn dump(base: *const Inst) void {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (base.id == @field(Id, @memberName(Id, i))) {
|
||||
const T = @field(Inst, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (base.id == @field(Id, f.name)) {
|
||||
const T = @field(Inst, f.name);
|
||||
std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
|
||||
@fieldParentPtr(T, "base", base).dump();
|
||||
std.debug.warn(")", .{});
|
||||
@ -100,10 +98,9 @@ pub const Inst = struct {
|
||||
}
|
||||
|
||||
pub fn hasSideEffects(base: *const Inst) bool {
|
||||
comptime var i = 0;
|
||||
inline while (i < @memberCount(Id)) : (i += 1) {
|
||||
if (base.id == @field(Id, @memberName(Id, i))) {
|
||||
const T = @field(Inst, @memberName(Id, i));
|
||||
inline for (@typeInfo(Id).Enum.fields) |f| {
|
||||
if (base.id == @field(Id, f.name)) {
|
||||
const T = @field(Inst, f.name);
|
||||
return @fieldParentPtr(T, "base", base).hasSideEffects();
|
||||
}
|
||||
}
|
||||
@ -1805,21 +1802,19 @@ 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)));
|
||||
switch (FieldType) {
|
||||
*Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),
|
||||
*BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self),
|
||||
?*Inst => if (@field(inst.params, @memberName(I.Params, i))) |other| other.ref(self),
|
||||
inline for (@typeInfo(I.Params).Struct.fields) |f| {
|
||||
switch (f.fiedl_type) {
|
||||
*Inst => @field(inst.params, f.name).ref(self),
|
||||
*BasicBlock => @field(inst.params, f.name).ref(self),
|
||||
?*Inst => if (@field(inst.params, f.name)) |other| other.ref(self),
|
||||
[]*Inst => {
|
||||
// TODO https://github.com/ziglang/zig/issues/1269
|
||||
for (@field(inst.params, @memberName(I.Params, i))) |other|
|
||||
for (@field(inst.params, f.name)) |other|
|
||||
other.ref(self);
|
||||
},
|
||||
[]*BasicBlock => {
|
||||
// TODO https://github.com/ziglang/zig/issues/1269
|
||||
for (@field(inst.params, @memberName(I.Params, i))) |other|
|
||||
for (@field(inst.params, f.name)) |other|
|
||||
other.ref(self);
|
||||
},
|
||||
Type.Pointer.Mut,
|
||||
@ -1831,7 +1826,7 @@ pub const Builder = struct {
|
||||
=> {},
|
||||
// it's ok to add more types here, just make sure that
|
||||
// any instructions and basic blocks are ref'd appropriately
|
||||
else => @compileError("unrecognized type in Params: " ++ @typeName(FieldType)),
|
||||
else => @compileError("unrecognized type in Params: " ++ @typeName(f.field_type)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5381,15 +5381,15 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
|
||||
return error.ParseError;
|
||||
}
|
||||
|
||||
//if (@typeId(@TypeOf(x)) == .Pointer)
|
||||
//if (@typeInfo(@TypeOf(x)) == .Pointer)
|
||||
// @ptrCast(dest, x)
|
||||
//else if (@typeId(@TypeOf(x)) == .Integer)
|
||||
//else if (@typeInfo(@TypeOf(x)) == .Integer)
|
||||
// @intToPtr(dest, x)
|
||||
//else
|
||||
// @as(dest, x)
|
||||
|
||||
const if_1 = try transCreateNodeIf(c);
|
||||
const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeId");
|
||||
const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
|
||||
const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
|
||||
try type_id_1.params.push(&type_of_1.base);
|
||||
try type_of_1.params.push(node_to_cast);
|
||||
@ -5416,7 +5416,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
|
||||
if_1.@"else" = else_1;
|
||||
|
||||
const if_2 = try transCreateNodeIf(c);
|
||||
const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeId");
|
||||
const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
|
||||
const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
|
||||
try type_id_2.params.push(&type_of_2.base);
|
||||
try type_of_2.params.push(node_to_cast);
|
||||
|
||||
@ -1042,7 +1042,7 @@ fn hashAny(x: var, comptime seed: u64) u32 {
|
||||
switch (@typeInfo(@TypeOf(x))) {
|
||||
.Int => |info| {
|
||||
comptime var rng = comptime std.rand.DefaultPrng.init(seed);
|
||||
const unsigned_x = @bitCast(@IntType(false, info.bits), x);
|
||||
const unsigned_x = @bitCast(std.meta.IntType(false, info.bits), x);
|
||||
if (info.bits <= 32) {
|
||||
return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);
|
||||
} else {
|
||||
|
||||
@ -1695,9 +1695,6 @@ enum BuiltinFnId {
|
||||
BuiltinFnIdMemset,
|
||||
BuiltinFnIdSizeof,
|
||||
BuiltinFnIdAlignOf,
|
||||
BuiltinFnIdMemberCount,
|
||||
BuiltinFnIdMemberType,
|
||||
BuiltinFnIdMemberName,
|
||||
BuiltinFnIdField,
|
||||
BuiltinFnIdTypeInfo,
|
||||
BuiltinFnIdType,
|
||||
@ -1757,7 +1754,6 @@ enum BuiltinFnId {
|
||||
BuiltinFnIdIntToErr,
|
||||
BuiltinFnIdEnumToInt,
|
||||
BuiltinFnIdIntToEnum,
|
||||
BuiltinFnIdIntType,
|
||||
BuiltinFnIdVectorType,
|
||||
BuiltinFnIdShuffle,
|
||||
BuiltinFnIdSplat,
|
||||
@ -1777,7 +1773,6 @@ enum BuiltinFnId {
|
||||
BuiltinFnIdBitOffsetOf,
|
||||
BuiltinFnIdNewStackCall,
|
||||
BuiltinFnIdAsyncCall,
|
||||
BuiltinFnIdTypeId,
|
||||
BuiltinFnIdShlExact,
|
||||
BuiltinFnIdShrExact,
|
||||
BuiltinFnIdSetEvalBranchQuota,
|
||||
@ -1785,7 +1780,6 @@ enum BuiltinFnId {
|
||||
BuiltinFnIdOpaqueType,
|
||||
BuiltinFnIdThis,
|
||||
BuiltinFnIdSetAlignStack,
|
||||
BuiltinFnIdArgType,
|
||||
BuiltinFnIdExport,
|
||||
BuiltinFnIdErrorReturnTrace,
|
||||
BuiltinFnIdAtomicRmw,
|
||||
@ -2630,7 +2624,6 @@ enum IrInstSrcId {
|
||||
IrInstSrcIdIntToFloat,
|
||||
IrInstSrcIdFloatToInt,
|
||||
IrInstSrcIdBoolToInt,
|
||||
IrInstSrcIdIntType,
|
||||
IrInstSrcIdVectorType,
|
||||
IrInstSrcIdShuffleVector,
|
||||
IrInstSrcIdSplat,
|
||||
@ -2638,9 +2631,6 @@ enum IrInstSrcId {
|
||||
IrInstSrcIdMemset,
|
||||
IrInstSrcIdMemcpy,
|
||||
IrInstSrcIdSlice,
|
||||
IrInstSrcIdMemberCount,
|
||||
IrInstSrcIdMemberType,
|
||||
IrInstSrcIdMemberName,
|
||||
IrInstSrcIdBreakpoint,
|
||||
IrInstSrcIdReturnAddress,
|
||||
IrInstSrcIdFrameAddress,
|
||||
@ -2677,7 +2667,6 @@ enum IrInstSrcId {
|
||||
IrInstSrcIdTypeInfo,
|
||||
IrInstSrcIdType,
|
||||
IrInstSrcIdHasField,
|
||||
IrInstSrcIdTypeId,
|
||||
IrInstSrcIdSetEvalBranchQuota,
|
||||
IrInstSrcIdPtrType,
|
||||
IrInstSrcIdAlignCast,
|
||||
@ -3636,13 +3625,6 @@ struct IrInstSrcBoolToInt {
|
||||
IrInstSrc *target;
|
||||
};
|
||||
|
||||
struct IrInstSrcIntType {
|
||||
IrInstSrc base;
|
||||
|
||||
IrInstSrc *is_signed;
|
||||
IrInstSrc *bit_count;
|
||||
};
|
||||
|
||||
struct IrInstSrcVectorType {
|
||||
IrInstSrc base;
|
||||
|
||||
@ -3715,26 +3697,6 @@ struct IrInstGenSlice {
|
||||
bool safety_check_on;
|
||||
};
|
||||
|
||||
struct IrInstSrcMemberCount {
|
||||
IrInstSrc base;
|
||||
|
||||
IrInstSrc *container;
|
||||
};
|
||||
|
||||
struct IrInstSrcMemberType {
|
||||
IrInstSrc base;
|
||||
|
||||
IrInstSrc *container_type;
|
||||
IrInstSrc *member_index;
|
||||
};
|
||||
|
||||
struct IrInstSrcMemberName {
|
||||
IrInstSrc base;
|
||||
|
||||
IrInstSrc *container_type;
|
||||
IrInstSrc *member_index;
|
||||
};
|
||||
|
||||
struct IrInstSrcBreakpoint {
|
||||
IrInstSrc base;
|
||||
};
|
||||
@ -4142,12 +4104,6 @@ struct IrInstSrcHasField {
|
||||
IrInstSrc *field_name;
|
||||
};
|
||||
|
||||
struct IrInstSrcTypeId {
|
||||
IrInstSrc base;
|
||||
|
||||
IrInstSrc *type_value;
|
||||
};
|
||||
|
||||
struct IrInstSrcSetEvalBranchQuota {
|
||||
IrInstSrc base;
|
||||
|
||||
|
||||
@ -8152,9 +8152,6 @@ static void define_builtin_fns(CodeGen *g) {
|
||||
create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);
|
||||
create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdField, "field", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
|
||||
@ -8192,7 +8189,6 @@ static void define_builtin_fns(CodeGen *g) {
|
||||
create_builtin_fn(g, BuiltinFnIdIntToEnum, "intToEnum", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
|
||||
create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
|
||||
create_builtin_fn(g, BuiltinFnIdVectorType, "Vector", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdShuffle, "shuffle", 4);
|
||||
create_builtin_fn(g, BuiltinFnIdSplat, "splat", 2);
|
||||
@ -8231,14 +8227,12 @@ static void define_builtin_fns(CodeGen *g) {
|
||||
create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);
|
||||
create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);
|
||||
create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);
|
||||
create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdShrExact, "shrExact", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdSetEvalBranchQuota, "setEvalBranchQuota", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdAlignCast, "alignCast", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);
|
||||
create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
|
||||
create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdExport, "export", 2);
|
||||
create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);
|
||||
create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);
|
||||
|
||||
348
src/ir.cpp
348
src/ir.cpp
@ -389,8 +389,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
|
||||
case IrInstSrcIdBoolToInt:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
|
||||
case IrInstSrcIdIntType:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
|
||||
case IrInstSrcIdVectorType:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
|
||||
case IrInstSrcIdShuffleVector:
|
||||
@ -405,12 +403,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
|
||||
case IrInstSrcIdSlice:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
|
||||
case IrInstSrcIdMemberCount:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
|
||||
case IrInstSrcIdMemberType:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
|
||||
case IrInstSrcIdMemberName:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
|
||||
case IrInstSrcIdBreakpoint:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
|
||||
case IrInstSrcIdReturnAddress:
|
||||
@ -477,8 +469,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
|
||||
case IrInstSrcIdHasField:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
|
||||
case IrInstSrcIdTypeId:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
|
||||
case IrInstSrcIdSetEvalBranchQuota:
|
||||
return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
|
||||
case IrInstSrcIdAlignCast:
|
||||
@ -1293,10 +1283,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
|
||||
return IrInstSrcIdBoolToInt;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
|
||||
return IrInstSrcIdIntType;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
|
||||
return IrInstSrcIdVectorType;
|
||||
}
|
||||
@ -1325,18 +1311,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
|
||||
return IrInstSrcIdSlice;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
|
||||
return IrInstSrcIdMemberCount;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
|
||||
return IrInstSrcIdMemberType;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
|
||||
return IrInstSrcIdMemberName;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
|
||||
return IrInstSrcIdBreakpoint;
|
||||
}
|
||||
@ -1481,10 +1455,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
|
||||
return IrInstSrcIdHasField;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
|
||||
return IrInstSrcIdTypeId;
|
||||
}
|
||||
|
||||
static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
|
||||
return IrInstSrcIdSetEvalBranchQuota;
|
||||
}
|
||||
@ -3542,19 +3512,6 @@ static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
|
||||
IrInstSrc *bit_count)
|
||||
{
|
||||
IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
|
||||
instruction->is_signed = is_signed;
|
||||
instruction->bit_count = bit_count;
|
||||
|
||||
ir_ref_instruction(is_signed, irb->current_basic_block);
|
||||
ir_ref_instruction(bit_count, irb->current_basic_block);
|
||||
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
|
||||
IrInstSrc *elem_type)
|
||||
{
|
||||
@ -3749,41 +3706,6 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
|
||||
IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
|
||||
instruction->container = container;
|
||||
|
||||
ir_ref_instruction(container, irb->current_basic_block);
|
||||
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
|
||||
IrInstSrc *container_type, IrInstSrc *member_index)
|
||||
{
|
||||
IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
|
||||
instruction->container_type = container_type;
|
||||
instruction->member_index = member_index;
|
||||
|
||||
ir_ref_instruction(container_type, irb->current_basic_block);
|
||||
ir_ref_instruction(member_index, irb->current_basic_block);
|
||||
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
|
||||
IrInstSrc *container_type, IrInstSrc *member_index)
|
||||
{
|
||||
IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
|
||||
instruction->container_type = container_type;
|
||||
instruction->member_index = member_index;
|
||||
|
||||
ir_ref_instruction(container_type, irb->current_basic_block);
|
||||
ir_ref_instruction(member_index, irb->current_basic_block);
|
||||
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
|
||||
IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
|
||||
return &instruction->base;
|
||||
@ -4458,15 +4380,6 @@ static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
|
||||
IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
|
||||
instruction->type_value = type_value;
|
||||
|
||||
ir_ref_instruction(type_value, irb->current_basic_block);
|
||||
|
||||
return &instruction->base;
|
||||
}
|
||||
|
||||
static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
|
||||
IrInstSrc *new_quota)
|
||||
{
|
||||
@ -6598,21 +6511,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
|
||||
IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
|
||||
return ir_lval_wrap(irb, scope, result, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdIntType:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
|
||||
if (arg0_value == irb->codegen->invalid_inst_src)
|
||||
return arg0_value;
|
||||
|
||||
AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
|
||||
IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
|
||||
if (arg1_value == irb->codegen->invalid_inst_src)
|
||||
return arg1_value;
|
||||
|
||||
IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
|
||||
return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdVectorType:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
@ -6710,48 +6608,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
|
||||
IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
|
||||
return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdMemberCount:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
|
||||
if (arg0_value == irb->codegen->invalid_inst_src)
|
||||
return arg0_value;
|
||||
|
||||
IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
|
||||
return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdMemberType:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
|
||||
if (arg0_value == irb->codegen->invalid_inst_src)
|
||||
return arg0_value;
|
||||
|
||||
AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
|
||||
IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
|
||||
if (arg1_value == irb->codegen->invalid_inst_src)
|
||||
return arg1_value;
|
||||
|
||||
|
||||
IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
|
||||
return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdMemberName:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
|
||||
if (arg0_value == irb->codegen->invalid_inst_src)
|
||||
return arg0_value;
|
||||
|
||||
AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
|
||||
IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
|
||||
if (arg1_value == irb->codegen->invalid_inst_src)
|
||||
return arg1_value;
|
||||
|
||||
|
||||
IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
|
||||
return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdField:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
@ -7109,16 +6965,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
|
||||
}
|
||||
case BuiltinFnIdAsyncCall:
|
||||
return ir_gen_async_call(irb, scope, nullptr, node, lval, result_loc);
|
||||
case BuiltinFnIdTypeId:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
|
||||
if (arg0_value == irb->codegen->invalid_inst_src)
|
||||
return arg0_value;
|
||||
|
||||
IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
|
||||
return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdShlExact:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
@ -7194,21 +7040,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
|
||||
IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
|
||||
return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdArgType:
|
||||
{
|
||||
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
|
||||
IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
|
||||
if (arg0_value == irb->codegen->invalid_inst_src)
|
||||
return arg0_value;
|
||||
|
||||
AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
|
||||
IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
|
||||
if (arg1_value == irb->codegen->invalid_inst_src)
|
||||
return arg1_value;
|
||||
|
||||
IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
|
||||
return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
|
||||
}
|
||||
case BuiltinFnIdExport:
|
||||
{
|
||||
// Cast the options parameter to the options type
|
||||
@ -24795,19 +24626,6 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
|
||||
return ir_const_type(ira, &instruction->base.base, type);
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
|
||||
IrInstGen *type_value = instruction->type_value->child;
|
||||
ZigType *type_entry = ir_resolve_type(ira, type_value);
|
||||
if (type_is_invalid(type_entry))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
|
||||
|
||||
IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
|
||||
bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
|
||||
return result;
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
|
||||
IrInstSrcSetEvalBranchQuota *instruction)
|
||||
{
|
||||
@ -25518,20 +25336,6 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
|
||||
return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
|
||||
IrInstGen *is_signed_value = instruction->is_signed->child;
|
||||
bool is_signed;
|
||||
if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
IrInstGen *bit_count_value = instruction->bit_count->child;
|
||||
uint64_t bit_count;
|
||||
if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
|
||||
uint64_t len;
|
||||
if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))
|
||||
@ -26445,143 +26249,6 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
|
||||
ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
|
||||
Error err;
|
||||
IrInstGen *container = instruction->container->child;
|
||||
if (type_is_invalid(container->value->type))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
ZigType *container_type = ir_resolve_type(ira, container);
|
||||
|
||||
if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
uint64_t result;
|
||||
if (type_is_invalid(container_type)) {
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
} else if (container_type->id == ZigTypeIdEnum) {
|
||||
result = container_type->data.enumeration.src_field_count;
|
||||
} else if (container_type->id == ZigTypeIdStruct) {
|
||||
result = container_type->data.structure.src_field_count;
|
||||
} else if (container_type->id == ZigTypeIdUnion) {
|
||||
result = container_type->data.unionation.src_field_count;
|
||||
} else if (container_type->id == ZigTypeIdErrorSet) {
|
||||
if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
if (type_is_global_error_set(container_type)) {
|
||||
ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
result = container_type->data.error_set.err_count;
|
||||
} else {
|
||||
ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
|
||||
return ir_const_unsigned(ira, &instruction->base.base, result);
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
|
||||
Error err;
|
||||
IrInstGen *container_type_value = instruction->container_type->child;
|
||||
ZigType *container_type = ir_resolve_type(ira, container_type_value);
|
||||
if (type_is_invalid(container_type))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
|
||||
uint64_t member_index;
|
||||
IrInstGen *index_value = instruction->member_index->child;
|
||||
if (!ir_resolve_usize(ira, index_value, &member_index))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
if (container_type->id == ZigTypeIdStruct) {
|
||||
if (member_index >= container_type->data.structure.src_field_count) {
|
||||
ir_add_error(ira, &index_value->base,
|
||||
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
|
||||
member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
TypeStructField *field = container_type->data.structure.fields[member_index];
|
||||
|
||||
return ir_const_type(ira, &instruction->base.base, field->type_entry);
|
||||
} else if (container_type->id == ZigTypeIdUnion) {
|
||||
if (member_index >= container_type->data.unionation.src_field_count) {
|
||||
ir_add_error(ira, &index_value->base,
|
||||
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
|
||||
member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
TypeUnionField *field = &container_type->data.unionation.fields[member_index];
|
||||
|
||||
return ir_const_type(ira, &instruction->base.base, field->type_entry);
|
||||
} else {
|
||||
ir_add_error(ira, &container_type_value->base,
|
||||
buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
|
||||
Error err;
|
||||
IrInstGen *container_type_value = instruction->container_type->child;
|
||||
ZigType *container_type = ir_resolve_type(ira, container_type_value);
|
||||
if (type_is_invalid(container_type))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
uint64_t member_index;
|
||||
IrInstGen *index_value = instruction->member_index->child;
|
||||
if (!ir_resolve_usize(ira, index_value, &member_index))
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
|
||||
if (container_type->id == ZigTypeIdStruct) {
|
||||
if (member_index >= container_type->data.structure.src_field_count) {
|
||||
ir_add_error(ira, &index_value->base,
|
||||
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
|
||||
member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
TypeStructField *field = container_type->data.structure.fields[member_index];
|
||||
|
||||
IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
|
||||
init_const_str_lit(ira->codegen, result->value, field->name);
|
||||
return result;
|
||||
} else if (container_type->id == ZigTypeIdEnum) {
|
||||
if (member_index >= container_type->data.enumeration.src_field_count) {
|
||||
ir_add_error(ira, &index_value->base,
|
||||
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
|
||||
member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
|
||||
|
||||
IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
|
||||
init_const_str_lit(ira->codegen, result->value, field->name);
|
||||
return result;
|
||||
} else if (container_type->id == ZigTypeIdUnion) {
|
||||
if (member_index >= container_type->data.unionation.src_field_count) {
|
||||
ir_add_error(ira, &index_value->base,
|
||||
buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
|
||||
member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
TypeUnionField *field = &container_type->data.unionation.fields[member_index];
|
||||
|
||||
IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
|
||||
init_const_str_lit(ira->codegen, result->value, field->name);
|
||||
return result;
|
||||
} else {
|
||||
ir_add_error(ira, &container_type_value->base,
|
||||
buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
}
|
||||
|
||||
static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
|
||||
Error err;
|
||||
ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
|
||||
@ -29540,8 +29207,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
|
||||
return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
|
||||
case IrInstSrcIdBoolToInt:
|
||||
return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
|
||||
case IrInstSrcIdIntType:
|
||||
return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
|
||||
case IrInstSrcIdVectorType:
|
||||
return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
|
||||
case IrInstSrcIdShuffleVector:
|
||||
@ -29556,12 +29221,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
|
||||
return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
|
||||
case IrInstSrcIdSlice:
|
||||
return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
|
||||
case IrInstSrcIdMemberCount:
|
||||
return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
|
||||
case IrInstSrcIdMemberType:
|
||||
return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
|
||||
case IrInstSrcIdMemberName:
|
||||
return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
|
||||
case IrInstSrcIdBreakpoint:
|
||||
return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
|
||||
case IrInstSrcIdReturnAddress:
|
||||
@ -29616,8 +29275,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
|
||||
return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
|
||||
case IrInstSrcIdHasField:
|
||||
return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
|
||||
case IrInstSrcIdTypeId:
|
||||
return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
|
||||
case IrInstSrcIdSetEvalBranchQuota:
|
||||
return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
|
||||
case IrInstSrcIdPtrType:
|
||||
@ -30032,15 +29689,11 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
|
||||
case IrInstSrcIdRef:
|
||||
case IrInstSrcIdEmbedFile:
|
||||
case IrInstSrcIdTruncate:
|
||||
case IrInstSrcIdIntType:
|
||||
case IrInstSrcIdVectorType:
|
||||
case IrInstSrcIdShuffleVector:
|
||||
case IrInstSrcIdSplat:
|
||||
case IrInstSrcIdBoolNot:
|
||||
case IrInstSrcIdSlice:
|
||||
case IrInstSrcIdMemberCount:
|
||||
case IrInstSrcIdMemberType:
|
||||
case IrInstSrcIdMemberName:
|
||||
case IrInstSrcIdAlignOf:
|
||||
case IrInstSrcIdReturnAddress:
|
||||
case IrInstSrcIdFrameAddress:
|
||||
@ -30067,7 +29720,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
|
||||
case IrInstSrcIdTypeInfo:
|
||||
case IrInstSrcIdType:
|
||||
case IrInstSrcIdHasField:
|
||||
case IrInstSrcIdTypeId:
|
||||
case IrInstSrcIdAlignCast:
|
||||
case IrInstSrcIdImplicitCast:
|
||||
case IrInstSrcIdResolveResult:
|
||||
|
||||
@ -179,8 +179,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
|
||||
return "SrcFloatToInt";
|
||||
case IrInstSrcIdBoolToInt:
|
||||
return "SrcBoolToInt";
|
||||
case IrInstSrcIdIntType:
|
||||
return "SrcIntType";
|
||||
case IrInstSrcIdVectorType:
|
||||
return "SrcVectorType";
|
||||
case IrInstSrcIdBoolNot:
|
||||
@ -191,12 +189,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
|
||||
return "SrcMemcpy";
|
||||
case IrInstSrcIdSlice:
|
||||
return "SrcSlice";
|
||||
case IrInstSrcIdMemberCount:
|
||||
return "SrcMemberCount";
|
||||
case IrInstSrcIdMemberType:
|
||||
return "SrcMemberType";
|
||||
case IrInstSrcIdMemberName:
|
||||
return "SrcMemberName";
|
||||
case IrInstSrcIdBreakpoint:
|
||||
return "SrcBreakpoint";
|
||||
case IrInstSrcIdReturnAddress:
|
||||
@ -269,8 +261,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
|
||||
return "SrcType";
|
||||
case IrInstSrcIdHasField:
|
||||
return "SrcHasField";
|
||||
case IrInstSrcIdTypeId:
|
||||
return "SrcTypeId";
|
||||
case IrInstSrcIdSetEvalBranchQuota:
|
||||
return "SrcSetEvalBranchQuota";
|
||||
case IrInstSrcIdPtrType:
|
||||
@ -1660,14 +1650,6 @@ static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instructio
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_int_type(IrPrintSrc *irp, IrInstSrcIntType *instruction) {
|
||||
fprintf(irp->f, "@IntType(");
|
||||
ir_print_other_inst_src(irp, instruction->is_signed);
|
||||
fprintf(irp->f, ", ");
|
||||
ir_print_other_inst_src(irp, instruction->bit_count);
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
|
||||
fprintf(irp->f, "@Vector(");
|
||||
ir_print_other_inst_src(irp, instruction->len);
|
||||
@ -1784,28 +1766,6 @@ static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
|
||||
ir_print_other_inst_gen(irp, instruction->result_loc);
|
||||
}
|
||||
|
||||
static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
|
||||
fprintf(irp->f, "@memberCount(");
|
||||
ir_print_other_inst_src(irp, instruction->container);
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
|
||||
fprintf(irp->f, "@memberType(");
|
||||
ir_print_other_inst_src(irp, instruction->container_type);
|
||||
fprintf(irp->f, ", ");
|
||||
ir_print_other_inst_src(irp, instruction->member_index);
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
|
||||
fprintf(irp->f, "@memberName(");
|
||||
ir_print_other_inst_src(irp, instruction->container_type);
|
||||
fprintf(irp->f, ", ");
|
||||
ir_print_other_inst_src(irp, instruction->member_index);
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
|
||||
fprintf(irp->f, "@breakpoint()");
|
||||
}
|
||||
@ -2279,12 +2239,6 @@ static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction)
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
|
||||
fprintf(irp->f, "@typeId(");
|
||||
ir_print_other_inst_src(irp, instruction->type_value);
|
||||
fprintf(irp->f, ")");
|
||||
}
|
||||
|
||||
static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
|
||||
fprintf(irp->f, "@setEvalBranchQuota(");
|
||||
ir_print_other_inst_src(irp, instruction->new_quota);
|
||||
@ -2775,9 +2729,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
|
||||
case IrInstSrcIdBoolToInt:
|
||||
ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdIntType:
|
||||
ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdVectorType:
|
||||
ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
|
||||
break;
|
||||
@ -2799,15 +2750,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
|
||||
case IrInstSrcIdSlice:
|
||||
ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdMemberCount:
|
||||
ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdMemberType:
|
||||
ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdMemberName:
|
||||
ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdBreakpoint:
|
||||
ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
|
||||
break;
|
||||
@ -2907,9 +2849,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
|
||||
case IrInstSrcIdHasField:
|
||||
ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdTypeId:
|
||||
ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
|
||||
break;
|
||||
case IrInstSrcIdSetEvalBranchQuota:
|
||||
ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
|
||||
break;
|
||||
|
||||
@ -1657,7 +1657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
\\ var ptr: [*c]u8 = (1 << 64) + 1;
|
||||
\\}
|
||||
\\export fn b() void {
|
||||
\\ var x: @IntType(false, 65) = 0x1234;
|
||||
\\ var x: u65 = 0x1234;
|
||||
\\ var ptr: [*c]u8 = x;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
@ -1896,13 +1896,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
|
||||
cases.add("exceeded maximum bit width of integer",
|
||||
\\export fn entry1() void {
|
||||
\\ const T = @IntType(false, 65536);
|
||||
\\ const T = u65536;
|
||||
\\}
|
||||
\\export fn entry2() void {
|
||||
\\ var x: i65536 = 1;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
|
||||
"tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
|
||||
});
|
||||
|
||||
@ -2942,14 +2941,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
"tmp.zig:11:13: error: error.B not a member of error set 'Set2'",
|
||||
});
|
||||
|
||||
cases.add("@memberCount of error",
|
||||
\\comptime {
|
||||
\\ _ = @memberCount(anyerror);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:9: error: global error set member count not available at comptime",
|
||||
});
|
||||
|
||||
cases.add("duplicate error value in error set",
|
||||
\\const Foo = error {
|
||||
\\ Bar,
|
||||
@ -5606,7 +5597,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
});
|
||||
|
||||
cases.add("globally shadowing a primitive type",
|
||||
\\const u16 = @intType(false, 8);
|
||||
\\const u16 = u8;
|
||||
\\export fn entry() void {
|
||||
\\ const a: u16 = 300;
|
||||
\\}
|
||||
@ -5947,93 +5938,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
"tmp.zig:2:1: error: invalid character: '\\t'",
|
||||
});
|
||||
|
||||
cases.add("@ArgType given non function parameter",
|
||||
\\comptime {
|
||||
\\ _ = @ArgType(i32, 3);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:18: error: expected function, found 'i32'",
|
||||
});
|
||||
|
||||
cases.add("@ArgType arg index out of bounds",
|
||||
\\comptime {
|
||||
\\ _ = @ArgType(@TypeOf(add), 2);
|
||||
\\}
|
||||
\\fn add(a: i32, b: i32) i32 { return a + b; }
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments",
|
||||
});
|
||||
|
||||
cases.add("@memberType on unsupported type",
|
||||
\\comptime {
|
||||
\\ _ = @memberType(i32, 0);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:21: error: type 'i32' does not support @memberType",
|
||||
});
|
||||
|
||||
cases.add("@memberType on enum",
|
||||
\\comptime {
|
||||
\\ _ = @memberType(Foo, 0);
|
||||
\\}
|
||||
\\const Foo = enum {A,};
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:21: error: type 'Foo' does not support @memberType",
|
||||
});
|
||||
|
||||
cases.add("@memberType struct out of bounds",
|
||||
\\comptime {
|
||||
\\ _ = @memberType(Foo, 0);
|
||||
\\}
|
||||
\\const Foo = struct {};
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
|
||||
});
|
||||
|
||||
cases.add("@memberType union out of bounds",
|
||||
\\comptime {
|
||||
\\ _ = @memberType(Foo, 1);
|
||||
\\}
|
||||
\\const Foo = union {A: void,};
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
|
||||
});
|
||||
|
||||
cases.add("@memberName on unsupported type",
|
||||
\\comptime {
|
||||
\\ _ = @memberName(i32, 0);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:21: error: type 'i32' does not support @memberName",
|
||||
});
|
||||
|
||||
cases.add("@memberName struct out of bounds",
|
||||
\\comptime {
|
||||
\\ _ = @memberName(Foo, 0);
|
||||
\\}
|
||||
\\const Foo = struct {};
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
|
||||
});
|
||||
|
||||
cases.add("@memberName enum out of bounds",
|
||||
\\comptime {
|
||||
\\ _ = @memberName(Foo, 1);
|
||||
\\}
|
||||
\\const Foo = enum {A,};
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
|
||||
});
|
||||
|
||||
cases.add("@memberName union out of bounds",
|
||||
\\comptime {
|
||||
\\ _ = @memberName(Foo, 1);
|
||||
\\}
|
||||
\\const Foo = union {A:i32,};
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
|
||||
});
|
||||
|
||||
cases.add("calling var args extern function, passing array instead of pointer",
|
||||
\\export fn entry() void {
|
||||
\\ foo("hello".*,);
|
||||
@ -6457,15 +6361,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
"tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",
|
||||
});
|
||||
|
||||
cases.add("getting @ArgType of generic function",
|
||||
\\fn generic(a: var) void {}
|
||||
\\comptime {
|
||||
\\ _ = @ArgType(@TypeOf(generic), 0);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var) var' is generic",
|
||||
});
|
||||
|
||||
cases.add("unsupported modifier at start of asm output constraint",
|
||||
\\export fn foo() void {
|
||||
\\ var bar: u32 = 3;
|
||||
|
||||
@ -2,9 +2,9 @@ const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
|
||||
fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
|
||||
expect(Key == @IntType(false, Key.bit_count));
|
||||
expect(Key == std.meta.IntType(false, Key.bit_count));
|
||||
expect(Key.bit_count >= mask_bit_count);
|
||||
const ShardKey = @IntType(false, mask_bit_count);
|
||||
const ShardKey = std.meta.IntType(false, mask_bit_count);
|
||||
const shift_amount = Key.bit_count - ShardKey.bit_count;
|
||||
return struct {
|
||||
const Self = @This();
|
||||
|
||||
@ -17,7 +17,7 @@ pub const GET = struct {
|
||||
};
|
||||
|
||||
pub fn isCommand(comptime T: type) bool {
|
||||
const tid = @typeId(T);
|
||||
const tid = @typeInfo(T);
|
||||
return (tid == .Struct or tid == .Enum or tid == .Union) and
|
||||
@hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
|
||||
}
|
||||
|
||||
@ -96,8 +96,8 @@ test "enum type" {
|
||||
const bar = Bar.B;
|
||||
|
||||
expect(bar == Bar.B);
|
||||
expect(@memberCount(Foo) == 3);
|
||||
expect(@memberCount(Bar) == 4);
|
||||
expect(@typeInfo(Foo).Union.fields.len == 3);
|
||||
expect(@typeInfo(Bar).Enum.fields.len == 4);
|
||||
expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
|
||||
expect(@sizeOf(Bar) == 1);
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ const expect = std.testing.expect;
|
||||
const expectError = std.testing.expectError;
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const mem = std.mem;
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn foo() anyerror!i32 {
|
||||
const x = try bar();
|
||||
@ -84,8 +83,8 @@ test "error union type " {
|
||||
fn testErrorUnionType() void {
|
||||
const x: anyerror!i32 = 1234;
|
||||
if (x) |value| expect(value == 1234) else |_| unreachable;
|
||||
expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion);
|
||||
expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);
|
||||
expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
|
||||
expect(@typeInfo(@TypeOf(x).ErrorSet) == .ErrorSet);
|
||||
expect(@TypeOf(x).ErrorSet == anyerror);
|
||||
}
|
||||
|
||||
@ -100,7 +99,7 @@ const MyErrSet = error{
|
||||
};
|
||||
|
||||
fn testErrorSetType() void {
|
||||
expect(@memberCount(MyErrSet) == 2);
|
||||
expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
|
||||
|
||||
const a: MyErrSet!i32 = 5678;
|
||||
const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
|
||||
|
||||
@ -654,8 +654,8 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
|
||||
expect(b == 2);
|
||||
}
|
||||
|
||||
test "@tagName of @typeId" {
|
||||
const str = @tagName(@typeId(u8));
|
||||
test "@tagName of @typeInfo" {
|
||||
const str = @tagName(@typeInfo(u8));
|
||||
expect(std.mem.eql(u8, str, "Int"));
|
||||
}
|
||||
|
||||
|
||||
@ -270,7 +270,7 @@ fn testBinaryNot(x: u16) void {
|
||||
}
|
||||
|
||||
test "small int addition" {
|
||||
var x: @IntType(false, 2) = 0;
|
||||
var x: u2 = 0;
|
||||
expect(x == 0);
|
||||
|
||||
x += 1;
|
||||
|
||||
@ -24,35 +24,6 @@ test "call disabled extern fn" {
|
||||
disabledExternFn();
|
||||
}
|
||||
|
||||
test "@IntType builtin" {
|
||||
expect(@IntType(true, 8) == i8);
|
||||
expect(@IntType(true, 16) == i16);
|
||||
expect(@IntType(true, 32) == i32);
|
||||
expect(@IntType(true, 64) == i64);
|
||||
|
||||
expect(@IntType(false, 8) == u8);
|
||||
expect(@IntType(false, 16) == u16);
|
||||
expect(@IntType(false, 32) == u32);
|
||||
expect(@IntType(false, 64) == u64);
|
||||
|
||||
expect(i8.bit_count == 8);
|
||||
expect(i16.bit_count == 16);
|
||||
expect(i32.bit_count == 32);
|
||||
expect(i64.bit_count == 64);
|
||||
|
||||
expect(i8.is_signed);
|
||||
expect(i16.is_signed);
|
||||
expect(i32.is_signed);
|
||||
expect(i64.is_signed);
|
||||
expect(isize.is_signed);
|
||||
|
||||
expect(!u8.is_signed);
|
||||
expect(!u16.is_signed);
|
||||
expect(!u32.is_signed);
|
||||
expect(!u64.is_signed);
|
||||
expect(!usize.is_signed);
|
||||
}
|
||||
|
||||
test "floating point primitive bit counts" {
|
||||
expect(f16.bit_count == 16);
|
||||
expect(f32.bit_count == 32);
|
||||
@ -407,7 +378,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) void {
|
||||
expect(ptr2[1] == 2.0);
|
||||
}
|
||||
|
||||
const Tid = builtin.TypeId;
|
||||
const AStruct = struct {
|
||||
x: i32,
|
||||
};
|
||||
@ -424,40 +394,6 @@ const AUnion = union {
|
||||
Two: void,
|
||||
};
|
||||
|
||||
test "@typeId" {
|
||||
comptime {
|
||||
expect(@typeId(type) == Tid.Type);
|
||||
expect(@typeId(void) == Tid.Void);
|
||||
expect(@typeId(bool) == Tid.Bool);
|
||||
expect(@typeId(noreturn) == Tid.NoReturn);
|
||||
expect(@typeId(i8) == Tid.Int);
|
||||
expect(@typeId(u8) == Tid.Int);
|
||||
expect(@typeId(i64) == Tid.Int);
|
||||
expect(@typeId(u64) == Tid.Int);
|
||||
expect(@typeId(f32) == Tid.Float);
|
||||
expect(@typeId(f64) == Tid.Float);
|
||||
expect(@typeId(*f32) == Tid.Pointer);
|
||||
expect(@typeId([2]u8) == Tid.Array);
|
||||
expect(@typeId(AStruct) == Tid.Struct);
|
||||
expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt);
|
||||
expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat);
|
||||
expect(@typeId(@TypeOf(undefined)) == Tid.Undefined);
|
||||
expect(@typeId(@TypeOf(null)) == Tid.Null);
|
||||
expect(@typeId(?i32) == Tid.Optional);
|
||||
expect(@typeId(anyerror!i32) == Tid.ErrorUnion);
|
||||
expect(@typeId(anyerror) == Tid.ErrorSet);
|
||||
expect(@typeId(AnEnum) == Tid.Enum);
|
||||
expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum);
|
||||
expect(@typeId(AUnionEnum) == Tid.Union);
|
||||
expect(@typeId(AUnion) == Tid.Union);
|
||||
expect(@typeId(fn () void) == Tid.Fn);
|
||||
expect(@typeId(@TypeOf(builtin)) == Tid.Type);
|
||||
// TODO bound fn
|
||||
// TODO arg tuple
|
||||
// TODO opaque
|
||||
}
|
||||
}
|
||||
|
||||
test "@typeName" {
|
||||
const Struct = struct {};
|
||||
const Union = union {
|
||||
|
||||
@ -16,9 +16,9 @@ test "reflection: function return type, var args, and param types" {
|
||||
expect(@TypeOf(dummy).ReturnType == i32);
|
||||
expect(!@TypeOf(dummy).is_var_args);
|
||||
expect(@TypeOf(dummy).arg_count == 3);
|
||||
expect(@ArgType(@TypeOf(dummy), 0) == bool);
|
||||
expect(@ArgType(@TypeOf(dummy), 1) == i32);
|
||||
expect(@ArgType(@TypeOf(dummy), 2) == f32);
|
||||
expect(@typeInfo(@TypeOf(dummy)).Fn.args[0].arg_type.? == bool);
|
||||
expect(@typeInfo(@TypeOf(dummy)).Fn.args[1].arg_type.? == i32);
|
||||
expect(@typeInfo(@TypeOf(dummy)).Fn.args[2].arg_type.? == f32);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,36 +26,6 @@ fn dummy(a: bool, b: i32, c: f32) i32 {
|
||||
return 1234;
|
||||
}
|
||||
|
||||
test "reflection: struct member types and names" {
|
||||
comptime {
|
||||
expect(@memberCount(Foo) == 3);
|
||||
|
||||
expect(@memberType(Foo, 0) == i32);
|
||||
expect(@memberType(Foo, 1) == bool);
|
||||
expect(@memberType(Foo, 2) == void);
|
||||
|
||||
expect(mem.eql(u8, @memberName(Foo, 0), "one"));
|
||||
expect(mem.eql(u8, @memberName(Foo, 1), "two"));
|
||||
expect(mem.eql(u8, @memberName(Foo, 2), "three"));
|
||||
}
|
||||
}
|
||||
|
||||
test "reflection: enum member types and names" {
|
||||
comptime {
|
||||
expect(@memberCount(Bar) == 4);
|
||||
|
||||
expect(@memberType(Bar, 0) == void);
|
||||
expect(@memberType(Bar, 1) == i32);
|
||||
expect(@memberType(Bar, 2) == bool);
|
||||
expect(@memberType(Bar, 3) == f64);
|
||||
|
||||
expect(mem.eql(u8, @memberName(Bar, 0), "One"));
|
||||
expect(mem.eql(u8, @memberName(Bar, 1), "Two"));
|
||||
expect(mem.eql(u8, @memberName(Bar, 2), "Three"));
|
||||
expect(mem.eql(u8, @memberName(Bar, 3), "Four"));
|
||||
}
|
||||
}
|
||||
|
||||
test "reflection: @field" {
|
||||
var f = Foo{
|
||||
.one = 42,
|
||||
|
||||
@ -531,7 +531,7 @@ var glbl: Foo1 = undefined;
|
||||
|
||||
test "global union with single field is correctly initialized" {
|
||||
glbl = Foo1{
|
||||
.f = @memberType(Foo1, 0){ .x = 123 },
|
||||
.f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
|
||||
};
|
||||
expect(glbl.f.x == 123);
|
||||
}
|
||||
|
||||
@ -1354,7 +1354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
cases.add("macro pointer cast",
|
||||
\\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
|
||||
, &[_][]const u8{
|
||||
\\pub const NRF_GPIO = if (@typeId(@TypeOf(NRF_GPIO_BASE)) == .Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@TypeOf(NRF_GPIO_BASE)) == .Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE);
|
||||
\\pub const NRF_GPIO = if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeInfo(@TypeOf(NRF_GPIO_BASE)) == .Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE);
|
||||
});
|
||||
|
||||
cases.add("basic macro function",
|
||||
@ -2538,11 +2538,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
||||
\\#define FOO(bar) baz((void *)(baz))
|
||||
\\#define BAR (void*) a
|
||||
, &[_][]const u8{
|
||||
\\pub inline fn FOO(bar: var) @TypeOf(baz(if (@typeId(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeId(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz))) {
|
||||
\\ return baz(if (@typeId(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeId(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz));
|
||||
\\pub inline fn FOO(bar: var) @TypeOf(baz(if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz))) {
|
||||
\\ return baz(if (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz));
|
||||
\\}
|
||||
,
|
||||
\\pub const BAR = if (@typeId(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, a) else if (@typeId(@TypeOf(a)) == .Int) @intToPtr(*c_void, a) else @as(*c_void, a);
|
||||
\\pub const BAR = if (@typeInfo(@TypeOf(a)) == .Pointer) @ptrCast(*c_void, a) else if (@typeInfo(@TypeOf(a)) == .Int) @intToPtr(*c_void, a) else @as(*c_void, a);
|
||||
});
|
||||
|
||||
cases.add("macro conditional operator",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user