authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-24 21:57:29-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-02-24 21:57:29-05:00
log61a50a23e88945af71c0e4c56bf378869c670f49
tree0281872fbe5bbfba6de1b527a14ec8fb932c9e3a
parent544bc42fd9b612462579928298ec467484763ae1
parentd56115ef4189a7716d9371ef87df9124a61f5ab1
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4547 from Vexu/deprecate

Remove deprecated builtins

67 files changed, 278 insertions(+), 1044 deletions(-)

doc/langref.html.in+11-102
......@@ -550,7 +550,7 @@ pub fn main() void {
550550 {#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an
551551 integer type is {#syntax#}65535{#endsyntax#}.
552552 </p>
553 {#see_also|Integers|Floats|void|Errors|@IntType#}
553 {#see_also|Integers|Floats|void|Errors|@Type#}
554554 {#header_close#}
555555 {#header_open|Primitive Values#}
556556 <div class="table-wrapper">
......@@ -2810,14 +2810,10 @@ test "@TagType" {
28102810 assert(@TagType(Small) == u2);
28112811}
28122812
2813// @memberCount tells how many fields an enum has:
2814test "@memberCount" {
2815 assert(@memberCount(Small) == 4);
2816}
2817
2818// @memberName tells the name of a field in an enum:
2819test "@memberName" {
2820 assert(mem.eql(u8, @memberName(Small, 1), "Two"));
2813// @typeInfo tells us the field count and the fields names:
2814test "@typeInfo" {
2815 assert(@typeInfo(Small).Enum.fields.len == 4);
2816 assert(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "Two"));
28212817}
28222818
28232819// @tagName gives a []const u8 representation of an enum value:
......@@ -2825,7 +2821,7 @@ test "@tagName" {
28252821 assert(mem.eql(u8, @tagName(Small.Three), "Three"));
28262822}
28272823 {#code_end#}
2828 {#see_also|@memberName|@memberCount|@tagName|@sizeOf#}
2824 {#see_also|@typeInfo|@tagName|@sizeOf#}
28292825
28302826 {#header_open|extern enum#}
28312827 <p>
......@@ -6671,18 +6667,6 @@ comptime {
66716667 </p>
66726668 {#see_also|Alignment#}
66736669 {#header_close#}
6674 {#header_open|@ArgType#}
6675 <pre>{#syntax#}@ArgType(comptime T: type, comptime n: usize) type{#endsyntax#}</pre>
6676 <p>
6677 This builtin function takes a function type and returns the type of the parameter at index {#syntax#}n{#endsyntax#}.
6678 </p>
6679 <p>
6680 {#syntax#}T{#endsyntax#} must be a function type.
6681 </p>
6682 <p>
6683 Note: This function is deprecated. Use {#link|@typeInfo#} instead.
6684 </p>
6685 {#header_close#}
66866670
66876671 {#header_open|@as#}
66886672 <pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre>
......@@ -6816,7 +6800,7 @@ async fn func(y: *i32) void {
68166800 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
68176801 </p>
68186802 <p>
6819 Asserts that {#syntax#}@typeId(DestType) != @import("builtin").TypeId.Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.
6803 Asserts that {#syntax#}@typeInfo(DestType) != .Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.
68206804 </p>
68216805 <p>
68226806 Can be used for these things for example:
......@@ -7269,7 +7253,7 @@ test "main" {
72697253 <p>
72707254 Floored division. Rounds toward negative infinity. For unsigned integers it is
72717255 the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
7272 {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
7256 {#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
72737257 </p>
72747258 <ul>
72757259 <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
......@@ -7283,7 +7267,7 @@ test "main" {
72837267 <p>
72847268 Truncated division. Rounds toward zero. For unsigned integers it is
72857269 the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
7286 {#syntax#}!(@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
7270 {#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
72877271 </p>
72887272 <ul>
72897273 <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
......@@ -7341,7 +7325,7 @@ test "main" {
73417325 {#header_close#}
73427326
73437327 {#header_open|@errorToInt#}
7344 <pre>{#syntax#}@errorToInt(err: var) @IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre>
7328 <pre>{#syntax#}@errorToInt(err: var) std.meta.IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre>
73457329 <p>
73467330 Supports the following types:
73477331 </p>
......@@ -7635,7 +7619,7 @@ test "@hasDecl" {
76357619 {#header_close#}
76367620
76377621 {#header_open|@intToError#}
7638 <pre>{#syntax#}@intToError(value: @IntType(false, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}</pre>
7622 <pre>{#syntax#}@intToError(value: std.meta.IntType(false, @sizeOf(anyerror) * 8)) anyerror{#endsyntax#}</pre>
76397623 <p>
76407624 Converts from the integer representation of an error into {#link|The Global Error Set#} type.
76417625 </p>
......@@ -7668,44 +7652,6 @@ test "@hasDecl" {
76687652 </p>
76697653 {#header_close#}
76707654
7671 {#header_open|@IntType#}
7672 <pre>{#syntax#}@IntType(comptime is_signed: bool, comptime bit_count: u16) type{#endsyntax#}</pre>
7673 <p>
7674 This function returns an integer type with the given signness and bit count. The maximum
7675 bit count for an integer type is {#syntax#}65535{#endsyntax#}.
7676 </p>
7677 <p>
7678 Deprecated. Use {#link|@Type#}.
7679 </p>
7680 {#header_close#}
7681
7682 {#header_open|@memberCount#}
7683 <pre>{#syntax#}@memberCount(comptime T: type) comptime_int{#endsyntax#}</pre>
7684 <p>
7685 This function returns the number of members in a struct, enum, or union type.
7686 </p>
7687 <p>
7688 The result is a compile time constant.
7689 </p>
7690 <p>
7691 It does not include functions, variables, or constants.
7692 </p>
7693 {#header_close#}
7694 {#header_open|@memberName#}
7695 <pre>{#syntax#}@memberName(comptime T: type, comptime index: usize) [N]u8{#endsyntax#}</pre>
7696 <p>Returns the field name of a struct, union, or enum.</p>
7697 <p>
7698 The result is a compile time constant.
7699 </p>
7700 <p>
7701 It does not include functions, variables, or constants.
7702 </p>
7703 {#header_close#}
7704 {#header_open|@memberType#}
7705 <pre>{#syntax#}@memberType(comptime T: type, comptime index: usize) type{#endsyntax#}</pre>
7706 <p>Returns the field type of a struct or union.</p>
7707 {#header_close#}
7708
77097655 {#header_open|@memcpy#}
77107656 <pre>{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize){#endsyntax#}</pre>
77117657 <p>
......@@ -8401,43 +8347,6 @@ test "integer truncation" {
84018347 <li>{#link|struct#}</li>
84028348 </ul>
84038349 {#header_close#}
8404
8405 {#header_open|@typeId#}
8406 <pre>{#syntax#}@typeId(comptime T: type) @import("builtin").TypeId{#endsyntax#}</pre>
8407 <p>
8408 Returns which kind of type something is. Possible values:
8409 </p>
8410 {#code_begin|syntax#}
8411pub const TypeId = enum {
8412 Type,
8413 Void,
8414 Bool,
8415 NoReturn,
8416 Int,
8417 Float,
8418 Pointer,
8419 Array,
8420 Struct,
8421 ComptimeFloat,
8422 ComptimeInt,
8423 Undefined,
8424 Null,
8425 Optional,
8426 ErrorUnion,
8427 ErrorSet,
8428 Enum,
8429 Union,
8430 Fn,
8431 BoundFn,
8432 Opaque,
8433 Frame,
8434 AnyFrame,
8435 Vector,
8436 EnumLiteral,
8437};
8438 {#code_end#}
8439 {#header_close#}
8440
84418350 {#header_open|@typeInfo#}
84428351 <pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
84438352 <p>
lib/std/build.zig+11-11
......@@ -609,13 +609,13 @@ pub const Builder = struct {
609609 }
610610
611611 fn typeToEnum(comptime T: type) TypeId {
612 return switch (@typeId(T)) {
613 builtin.TypeId.Int => TypeId.Int,
614 builtin.TypeId.Float => TypeId.Float,
615 builtin.TypeId.Bool => TypeId.Bool,
612 return switch (@typeInfo(T)) {
613 .Int => .Int,
614 .Float => .Float,
615 .Bool => .Bool,
616616 else => switch (T) {
617 []const u8 => TypeId.String,
618 []const []const u8 => TypeId.List,
617 []const u8 => .String,
618 []const []const u8 => .List,
619619 else => @compileError("Unsupported type: " ++ @typeName(T)),
620620 },
621621 };
......@@ -627,11 +627,11 @@ pub const Builder = struct {
627627
628628 pub fn typeIdName(id: TypeId) []const u8 {
629629 return switch (id) {
630 TypeId.Bool => "bool",
631 TypeId.Int => "int",
632 TypeId.Float => "float",
633 TypeId.String => "string",
634 TypeId.List => "list",
630 .Bool => "bool",
631 .Int => "int",
632 .Float => "float",
633 .String => "string",
634 .List => "list",
635635 };
636636 }
637637
lib/std/child_process.zig+1-1
......@@ -851,7 +851,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
851851 os.exit(1);
852852}
853853
854const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);
854const ErrInt = std.meta.IntType(false, @sizeOf(anyerror) * 8);
855855
856856fn writeIntFd(fd: i32, value: ErrInt) !void {
857857 const file = File{
lib/std/debug/leb128.zig+6-6
......@@ -2,7 +2,7 @@ const std = @import("std");
22const testing = std.testing;
33
44pub fn readULEB128(comptime T: type, in_stream: var) !T {
5 const ShiftT = @IntType(false, std.math.log2(T.bit_count));
5 const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
66
77 var result: T = 0;
88 var shift: usize = 0;
......@@ -27,7 +27,7 @@ pub fn readULEB128(comptime T: type, in_stream: var) !T {
2727}
2828
2929pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
30 const ShiftT = @IntType(false, std.math.log2(T.bit_count));
30 const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
3131
3232 var result: T = 0;
3333 var shift: usize = 0;
......@@ -55,8 +55,8 @@ pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
5555}
5656
5757pub fn readILEB128(comptime T: type, in_stream: var) !T {
58 const UT = @IntType(false, T.bit_count);
59 const ShiftT = @IntType(false, std.math.log2(T.bit_count));
58 const UT = std.meta.IntType(false, T.bit_count);
59 const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
6060
6161 var result: UT = 0;
6262 var shift: usize = 0;
......@@ -87,8 +87,8 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
8787}
8888
8989pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
90 const UT = @IntType(false, T.bit_count);
91 const ShiftT = @IntType(false, std.math.log2(T.bit_count));
90 const UT = std.meta.IntType(false, T.bit_count);
91 const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
9292
9393 var result: UT = 0;
9494 var shift: usize = 0;
lib/std/fmt.zig+11-10
......@@ -82,7 +82,7 @@ pub fn format(
8282 comptime fmt: []const u8,
8383 args: var,
8484) Errors!void {
85 const ArgSetType = @IntType(false, 32);
85 const ArgSetType = u32;
8686 if (@typeInfo(@TypeOf(args)) != .Struct) {
8787 @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args)));
8888 }
......@@ -405,7 +405,7 @@ pub fn formatType(
405405 try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});
406406 }
407407 },
408 .Struct => {
408 .Struct => |StructT| {
409409 if (comptime std.meta.trait.hasFn("format")(T)) {
410410 return value.format(fmt, options, context, Errors, output);
411411 }
......@@ -416,27 +416,28 @@ pub fn formatType(
416416 }
417417 comptime var field_i = 0;
418418 try output(context, "{");
419 inline while (field_i < @memberCount(T)) : (field_i += 1) {
419 inline for (StructT.fields) |f| {
420420 if (field_i == 0) {
421421 try output(context, " .");
422422 } else {
423423 try output(context, ", .");
424424 }
425 try output(context, @memberName(T, field_i));
425 try output(context, f.name);
426426 try output(context, " = ");
427 try formatType(@field(value, @memberName(T, field_i)), fmt, options, context, Errors, output, max_depth - 1);
427 try formatType(@field(value, f.name), fmt, options, context, Errors, output, max_depth - 1);
428 field_i += 1;
428429 }
429430 try output(context, " }");
430431 },
431432 .Pointer => |ptr_info| switch (ptr_info.size) {
432433 .One => switch (@typeInfo(ptr_info.child)) {
433 builtin.TypeId.Array => |info| {
434 .Array => |info| {
434435 if (info.child == u8) {
435436 return formatText(value, fmt, options, context, Errors, output);
436437 }
437438 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
438439 },
439 builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {
440 .Enum, .Union, .Struct => {
440441 return formatType(value.*, fmt, options, context, Errors, output, max_depth);
441442 },
442443 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
......@@ -509,7 +510,7 @@ fn formatValue(
509510 }
510511
511512 const T = @TypeOf(value);
512 switch (@typeId(T)) {
513 switch (@typeInfo(T)) {
513514 .Float => return formatFloatValue(value, fmt, options, context, Errors, output),
514515 .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
515516 .Bool => return output(context, if (value) "true" else "false"),
......@@ -943,7 +944,7 @@ fn formatIntSigned(
943944 .fill = options.fill,
944945 };
945946
946 const uint = @IntType(false, @TypeOf(value).bit_count);
947 const uint = std.meta.IntType(false, @TypeOf(value).bit_count);
947948 if (value < 0) {
948949 const minus_sign: u8 = '-';
949950 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
......@@ -971,7 +972,7 @@ fn formatIntUnsigned(
971972 assert(base >= 2);
972973 var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
973974 const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count);
974 const MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits);
975 const MinInt = std.meta.IntType(@TypeOf(value).is_signed, min_int_bits);
975976 var a: MinInt = value;
976977 var index: usize = buf.len;
977978
lib/std/fmt/parse_float.zig+1-1
......@@ -393,7 +393,7 @@ test "fmt.parseFloat" {
393393 const epsilon = 1e-7;
394394
395395 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
396 const Z = @IntType(false, T.bit_count);
396 const Z = std.meta.IntType(false, T.bit_count);
397397
398398 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
399399 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
lib/std/hash/auto_hash.zig+1-1
......@@ -93,7 +93,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
9393 // TODO Check if the situation is better after #561 is resolved.
9494 .Int => @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)}),
9595
96 .Float => |info| hash(hasher, @bitCast(@IntType(false, info.bits), key), strat),
96 .Float => |info| hash(hasher, @bitCast(std.meta.IntType(false, info.bits), key), strat),
9797
9898 .Bool => hash(hasher, @boolToInt(key), strat),
9999 .Enum => hash(hasher, @enumToInt(key), strat),
lib/std/hash/wyhash.zig+1-1
......@@ -10,7 +10,7 @@ const primes = [_]u64{
1010};
1111
1212fn read_bytes(comptime bytes: u8, data: []const u8) u64 {
13 const T = @IntType(false, 8 * bytes);
13 const T = std.meta.IntType(false, 8 * bytes);
1414 return mem.readIntSliceLittle(T, data[0..bytes]);
1515}
1616
lib/std/heap.zig+1-1
......@@ -1015,7 +1015,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
10151015 // very near usize?
10161016 if (mem.page_size << 2 > maxInt(usize)) return;
10171017
1018 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
1018 const USizeShift = std.meta.IntType(false, std.math.log2(usize.bit_count));
10191019 const large_align = @as(u29, mem.page_size << 2);
10201020
10211021 var align_mask: usize = undefined;
lib/std/io.zig+28-28
......@@ -337,7 +337,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
337337 assert(u_bit_count >= bits);
338338 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
339339 };
340 const Buf = @IntType(false, buf_bit_count);
340 const Buf = std.meta.IntType(false, buf_bit_count);
341341 const BufShift = math.Log2Int(Buf);
342342
343343 out_bits.* = @as(usize, 0);
......@@ -659,7 +659,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
659659 assert(u_bit_count >= bits);
660660 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
661661 };
662 const Buf = @IntType(false, buf_bit_count);
662 const Buf = std.meta.IntType(false, buf_bit_count);
663663 const BufShift = math.Log2Int(Buf);
664664
665665 const buf_value = @intCast(Buf, value);
......@@ -831,12 +831,12 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
831831
832832 //@BUG: inferred error issue. See: #1386
833833 fn deserializeInt(self: *Self, comptime T: type) (Error || error{EndOfStream})!T {
834 comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
834 comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T));
835835
836836 const u8_bit_count = 8;
837837 const t_bit_count = comptime meta.bitCount(T);
838838
839 const U = @IntType(false, t_bit_count);
839 const U = std.meta.IntType(false, t_bit_count);
840840 const Log2U = math.Log2Int(U);
841841 const int_size = (U.bit_count + 7) / 8;
842842
......@@ -851,7 +851,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
851851
852852 if (int_size == 1) {
853853 if (t_bit_count == 8) return @bitCast(T, buffer[0]);
854 const PossiblySignedByte = @IntType(T.is_signed, 8);
854 const PossiblySignedByte = std.meta.IntType(T.is_signed, 8);
855855 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
856856 }
857857
......@@ -880,9 +880,9 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
880880 /// Deserializes data into the type pointed to by `ptr`
881881 pub fn deserializeInto(self: *Self, ptr: var) !void {
882882 const T = @TypeOf(ptr);
883 comptime assert(trait.is(builtin.TypeId.Pointer)(T));
883 comptime assert(trait.is(.Pointer)(T));
884884
885 if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) {
885 if (comptime trait.isSlice(T) or comptime trait.isPtrTo(.Array)(T)) {
886886 for (ptr) |*v|
887887 try self.deserializeInto(v);
888888 return;
......@@ -891,7 +891,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
891891 comptime assert(trait.isSingleItemPtr(T));
892892
893893 const C = comptime meta.Child(T);
894 const child_type_id = @typeId(C);
894 const child_type_id = @typeInfo(C);
895895
896896 //custom deserializer: fn(self: *Self, deserializer: var) !void
897897 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,
902902 }
903903
904904 switch (child_type_id) {
905 builtin.TypeId.Void => return,
906 builtin.TypeId.Bool => ptr.* = (try self.deserializeInt(u1)) > 0,
907 builtin.TypeId.Float, builtin.TypeId.Int => ptr.* = try self.deserializeInt(C),
908 builtin.TypeId.Struct => {
905 .Void => return,
906 .Bool => ptr.* = (try self.deserializeInt(u1)) > 0,
907 .Float, .Int => ptr.* = try self.deserializeInt(C),
908 .Struct => {
909909 const info = @typeInfo(C).Struct;
910910
911911 inline for (info.fields) |*field_info| {
......@@ -915,7 +915,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
915915 if (FieldType == void or FieldType == u0) continue;
916916
917917 //it doesn't make any sense to read pointers
918 if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) {
918 if (comptime trait.is(.Pointer)(FieldType)) {
919919 @compileError("Will not " ++ "read field " ++ name ++ " of struct " ++
920920 @typeName(C) ++ " because it " ++ "is of pointer-type " ++
921921 @typeName(FieldType) ++ ".");
......@@ -924,7 +924,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
924924 try self.deserializeInto(&@field(ptr, name));
925925 }
926926 },
927 builtin.TypeId.Union => {
927 .Union => {
928928 const info = @typeInfo(C).Union;
929929 if (info.tag_type) |TagType| {
930930 //we avoid duplicate iteration over the enum tags
......@@ -948,7 +948,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
948948 @compileError("Cannot meaningfully deserialize " ++ @typeName(C) ++
949949 " because it is an untagged union. Use a custom deserialize().");
950950 },
951 builtin.TypeId.Optional => {
951 .Optional => {
952952 const OC = comptime meta.Child(C);
953953 const exists = (try self.deserializeInt(u1)) > 0;
954954 if (!exists) {
......@@ -960,7 +960,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
960960 const val_ptr = &ptr.*.?;
961961 try self.deserializeInto(val_ptr);
962962 },
963 builtin.TypeId.Enum => {
963 .Enum => {
964964 var value = try self.deserializeInt(@TagType(C));
965965 ptr.* = try meta.intToEnum(C, value);
966966 },
......@@ -1009,12 +1009,12 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
10091009
10101010 fn serializeInt(self: *Self, value: var) Error!void {
10111011 const T = @TypeOf(value);
1012 comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
1012 comptime assert(trait.is(.Int)(T) or trait.is(.Float)(T));
10131013
10141014 const t_bit_count = comptime meta.bitCount(T);
10151015 const u8_bit_count = comptime meta.bitCount(u8);
10161016
1017 const U = @IntType(false, t_bit_count);
1017 const U = std.meta.IntType(false, t_bit_count);
10181018 const Log2U = math.Log2Int(U);
10191019 const int_size = (U.bit_count + 7) / 8;
10201020
......@@ -1058,11 +1058,11 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
10581058 return;
10591059 }
10601060
1061 switch (@typeId(T)) {
1062 builtin.TypeId.Void => return,
1063 builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
1064 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),
1065 builtin.TypeId.Struct => {
1061 switch (@typeInfo(T)) {
1062 .Void => return,
1063 .Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
1064 .Float, .Int => try self.serializeInt(value),
1065 .Struct => {
10661066 const info = @typeInfo(T);
10671067
10681068 inline for (info.Struct.fields) |*field_info| {
......@@ -1072,7 +1072,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
10721072 if (FieldType == void or FieldType == u0) continue;
10731073
10741074 //It doesn't make sense to write pointers
1075 if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) {
1075 if (comptime trait.is(.Pointer)(FieldType)) {
10761076 @compileError("Will not " ++ "serialize field " ++ name ++
10771077 " of struct " ++ @typeName(T) ++ " because it " ++
10781078 "is of pointer-type " ++ @typeName(FieldType) ++ ".");
......@@ -1080,7 +1080,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
10801080 try self.serialize(@field(value, name));
10811081 }
10821082 },
1083 builtin.TypeId.Union => {
1083 .Union => {
10841084 const info = @typeInfo(T).Union;
10851085 if (info.tag_type) |TagType| {
10861086 const active_tag = meta.activeTag(value);
......@@ -1101,7 +1101,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11011101 @compileError("Cannot meaningfully serialize " ++ @typeName(T) ++
11021102 " because it is an untagged union. Use a custom serialize().");
11031103 },
1104 builtin.TypeId.Optional => {
1104 .Optional => {
11051105 if (value == null) {
11061106 try self.serializeInt(@as(u1, @boolToInt(false)));
11071107 return;
......@@ -1112,10 +1112,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11121112 const val_ptr = &value.?;
11131113 try self.serialize(val_ptr.*);
11141114 },
1115 builtin.TypeId.Enum => {
1115 .Enum => {
11161116 try self.serializeInt(@enumToInt(value));
11171117 },
1118 else => @compileError("Cannot serialize " ++ @tagName(@typeId(T)) ++ " types (unimplemented)."),
1118 else => @compileError("Cannot serialize " ++ @tagName(@typeInfo(T)) ++ " types (unimplemented)."),
11191119 }
11201120 }
11211121 };
lib/std/io/test.zig+5-4
......@@ -318,6 +318,7 @@ test "BitStreams with File Stream" {
318318}
319319
320320fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void {
321 @setEvalBranchQuota(1500);
321322 //@NOTE: if this test is taking too long, reduce the maximum tested bitsize
322323 const max_test_bitsize = 128;
323324
......@@ -341,8 +342,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
341342
342343 comptime var i = 0;
343344 inline while (i <= max_test_bitsize) : (i += 1) {
344 const U = @IntType(false, i);
345 const S = @IntType(true, i);
345 const U = std.meta.IntType(false, i);
346 const S = std.meta.IntType(true, i);
346347 try serializer.serializeInt(@as(U, i));
347348 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
348349 }
......@@ -350,8 +351,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
350351
351352 i = 0;
352353 inline while (i <= max_test_bitsize) : (i += 1) {
353 const U = @IntType(false, i);
354 const S = @IntType(true, i);
354 const U = std.meta.IntType(false, i);
355 const S = std.meta.IntType(true, i);
355356 const x = try deserializer.deserializeInt(U);
356357 const y = try deserializer.deserializeInt(S);
357358 expect(x == @as(U, i));
lib/std/math.zig+26-28
......@@ -1,6 +1,4 @@
1const builtin = @import("builtin");
21const std = @import("std.zig");
3const TypeId = builtin.TypeId;
42const assert = std.debug.assert;
53const testing = std.testing;
64
......@@ -89,7 +87,7 @@ pub const snan = @import("math/nan.zig").snan;
8987pub const inf = @import("math/inf.zig").inf;
9088
9189pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
92 assert(@typeId(T) == TypeId.Float);
90 assert(@typeInfo(T) == .Float);
9391 return fabs(x - y) < epsilon;
9492}
9593
......@@ -198,7 +196,7 @@ test "" {
198196}
199197
200198pub fn floatMantissaBits(comptime T: type) comptime_int {
201 assert(@typeId(T) == builtin.TypeId.Float);
199 assert(@typeInfo(T) == .Float);
202200
203201 return switch (T.bit_count) {
204202 16 => 10,
......@@ -211,7 +209,7 @@ pub fn floatMantissaBits(comptime T: type) comptime_int {
211209}
212210
213211pub fn floatExponentBits(comptime T: type) comptime_int {
214 assert(@typeId(T) == builtin.TypeId.Float);
212 assert(@typeInfo(T) == .Float);
215213
216214 return switch (T.bit_count) {
217215 16 => 5,
......@@ -446,7 +444,7 @@ pub fn Log2Int(comptime T: type) type {
446444 count += 1;
447445 }
448446
449 return @IntType(false, count);
447 return std.meta.IntType(false, count);
450448}
451449
452450pub 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
462460 if (is_signed) {
463461 magnitude_bits += 1;
464462 }
465 return @IntType(is_signed, magnitude_bits);
463 return std.meta.IntType(is_signed, magnitude_bits);
466464}
467465
468466test "math.IntFittingRange" {
......@@ -526,7 +524,7 @@ fn testOverflow() void {
526524
527525pub fn absInt(x: var) !@TypeOf(x) {
528526 const T = @TypeOf(x);
529 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
527 comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
530528 comptime assert(T.is_signed); // must pass a signed integer to absInt
531529
532530 if (x == minInt(@TypeOf(x))) {
......@@ -560,7 +558,7 @@ fn testAbsFloat() void {
560558pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
561559 @setRuntimeSafety(false);
562560 if (denominator == 0) return error.DivisionByZero;
563 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
561 if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
564562 return @divTrunc(numerator, denominator);
565563}
566564
......@@ -581,7 +579,7 @@ fn testDivTrunc() void {
581579pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
582580 @setRuntimeSafety(false);
583581 if (denominator == 0) return error.DivisionByZero;
584 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
582 if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
585583 return @divFloor(numerator, denominator);
586584}
587585
......@@ -602,7 +600,7 @@ fn testDivFloor() void {
602600pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
603601 @setRuntimeSafety(false);
604602 if (denominator == 0) return error.DivisionByZero;
605 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
603 if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
606604 const result = @divTrunc(numerator, denominator);
607605 if (result * denominator != numerator) return error.UnexpectedRemainder;
608606 return result;
......@@ -676,13 +674,13 @@ pub fn absCast(x: var) t: {
676674 if (@TypeOf(x) == comptime_int) {
677675 break :t comptime_int;
678676 } else {
679 break :t @IntType(false, @TypeOf(x).bit_count);
677 break :t std.meta.IntType(false, @TypeOf(x).bit_count);
680678 }
681679} {
682680 if (@TypeOf(x) == comptime_int) {
683681 return if (x < 0) -x else x;
684682 }
685 const uint = @IntType(false, @TypeOf(x).bit_count);
683 const uint = std.meta.IntType(false, @TypeOf(x).bit_count);
686684 if (x >= 0) return @intCast(uint, x);
687685
688686 return @intCast(uint, -(x + 1)) + 1;
......@@ -703,10 +701,10 @@ test "math.absCast" {
703701
704702/// Returns the negation of the integer parameter.
705703/// Result is a signed integer.
706pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) {
704pub fn negateCast(x: var) !std.meta.IntType(true, @TypeOf(x).bit_count) {
707705 if (@TypeOf(x).is_signed) return negate(x);
708706
709 const int = @IntType(true, @TypeOf(x).bit_count);
707 const int = std.meta.IntType(true, @TypeOf(x).bit_count);
710708 if (x > -minInt(int)) return error.Overflow;
711709
712710 if (x == -minInt(int)) return minInt(int);
......@@ -727,8 +725,8 @@ test "math.negateCast" {
727725/// Cast an integer to a different integer type. If the value doesn't fit,
728726/// return an error.
729727pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
730 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
731 comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer
728 comptime assert(@typeInfo(T) == .Int); // must pass an integer
729 comptime assert(@typeInfo(@TypeOf(x)) == .Int); // must pass an integer
732730 if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
733731 return error.Overflow;
734732 } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {
......@@ -792,11 +790,11 @@ fn testFloorPowerOfTwo() void {
792790/// Returns the next power of two (if the value is not already a power of two).
793791/// Only unsigned integers can be used. Zero is not an allowed input.
794792/// Result is a type with 1 more bit than the input type.
795pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T.bit_count + 1) {
796 comptime assert(@typeId(T) == builtin.TypeId.Int);
793pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.IntType(T.is_signed, T.bit_count + 1) {
794 comptime assert(@typeInfo(T) == .Int);
797795 comptime assert(!T.is_signed);
798796 assert(value != 0);
799 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
797 comptime const PromotedType = std.meta.IntType(T.is_signed, T.bit_count + 1);
800798 comptime const shiftType = std.math.Log2Int(PromotedType);
801799 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
802800}
......@@ -805,9 +803,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
805803/// Only unsigned integers can be used. Zero is not an allowed input.
806804/// If the value doesn't fit, returns an error.
807805pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
808 comptime assert(@typeId(T) == builtin.TypeId.Int);
806 comptime assert(@typeInfo(T) == .Int);
809807 comptime assert(!T.is_signed);
810 comptime const PromotedType = @IntType(T.is_signed, T.bit_count + 1);
808 comptime const PromotedType = std.meta.IntType(T.is_signed, T.bit_count + 1);
811809 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
812810 var x = ceilPowerOfTwoPromote(T, value);
813811 if (overflowBit & x != 0) {
......@@ -878,10 +876,10 @@ test "std.math.log2_int_ceil" {
878876
879877pub fn lossyCast(comptime T: type, value: var) T {
880878 switch (@typeInfo(@TypeOf(value))) {
881 builtin.TypeId.Int => return @intToFloat(T, value),
882 builtin.TypeId.Float => return @floatCast(T, value),
883 builtin.TypeId.ComptimeInt => return @as(T, value),
884 builtin.TypeId.ComptimeFloat => return @as(T, value),
879 .Int => return @intToFloat(T, value),
880 .Float => return @floatCast(T, value),
881 .ComptimeInt => return @as(T, value),
882 .ComptimeFloat => return @as(T, value),
885883 else => @compileError("bad type"),
886884 }
887885}
......@@ -949,8 +947,8 @@ test "max value type" {
949947 testing.expect(x == 2147483647);
950948}
951949
952pub fn mulWide(comptime T: type, a: T, b: T) @IntType(T.is_signed, T.bit_count * 2) {
953 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);
950pub fn mulWide(comptime T: type, a: T, b: T) std.meta.IntType(T.is_signed, T.bit_count * 2) {
951 const ResultInt = std.meta.IntType(T.is_signed, T.bit_count * 2);
954952 return @as(ResultInt, a) * @as(ResultInt, b);
955953}
956954
lib/std/math/big/int.zig+7-10
......@@ -1,5 +1,4 @@
11const std = @import("../../std.zig");
2const builtin = @import("builtin");
32const debug = std.debug;
43const testing = std.testing;
54const math = std.math;
......@@ -9,10 +8,8 @@ const ArrayList = std.ArrayList;
98const maxInt = std.math.maxInt;
109const minInt = std.math.minInt;
1110
12const TypeId = builtin.TypeId;
13
1411pub const Limb = usize;
15pub const DoubleLimb = @IntType(false, 2 * Limb.bit_count);
12pub const DoubleLimb = std.meta.IntType(false, 2 * Limb.bit_count);
1613pub const Log2Limb = math.Log2Int(Limb);
1714
1815comptime {
......@@ -270,8 +267,8 @@ pub const Int = struct {
270267 const T = @TypeOf(value);
271268
272269 switch (@typeInfo(T)) {
273 TypeId.Int => |info| {
274 const UT = if (T.is_signed) @IntType(false, T.bit_count - 1) else T;
270 .Int => |info| {
271 const UT = if (T.is_signed) std.meta.IntType(false, T.bit_count - 1) else T;
275272
276273 try self.ensureCapacity(@sizeOf(UT) / @sizeOf(Limb));
277274 self.metadata = 0;
......@@ -294,7 +291,7 @@ pub const Int = struct {
294291 }
295292 }
296293 },
297 TypeId.ComptimeInt => {
294 .ComptimeInt => {
298295 comptime var w_value = if (value < 0) -value else value;
299296
300297 const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1;
......@@ -332,9 +329,9 @@ pub const Int = struct {
332329 ///
333330 /// Returns an error if self cannot be narrowed into the requested type without truncation.
334331 pub fn to(self: Int, comptime T: type) ConvertError!T {
335 switch (@typeId(T)) {
336 TypeId.Int => {
337 const UT = @IntType(false, T.bit_count);
332 switch (@typeInfo(T)) {
333 .Int => {
334 const UT = std.meta.IntType(false, T.bit_count);
338335
339336 if (self.bitCountTwosComp() > T.bit_count) {
340337 return error.TargetTooSmall;
lib/std/math/big/rational.zig+6-9
......@@ -1,5 +1,4 @@
11const std = @import("../../std.zig");
2const builtin = @import("builtin");
32const debug = std.debug;
43const math = std.math;
54const mem = std.mem;
......@@ -7,8 +6,6 @@ const testing = std.testing;
76const Allocator = mem.Allocator;
87const ArrayList = std.ArrayList;
98
10const TypeId = builtin.TypeId;
11
129const bn = @import("int.zig");
1310const Limb = bn.Limb;
1411const DoubleLimb = bn.DoubleLimb;
......@@ -129,9 +126,9 @@ pub const Rational = struct {
129126 /// completely represent the provided float.
130127 pub fn setFloat(self: *Rational, comptime T: type, f: T) !void {
131128 // Translated from golang.go/src/math/big/rat.go.
132 debug.assert(@typeId(T) == builtin.TypeId.Float);
129 debug.assert(@typeInfo(T) == .Float);
133130
134 const UnsignedIntType = @IntType(false, T.bit_count);
131 const UnsignedIntType = std.meta.IntType(false, T.bit_count);
135132 const f_bits = @bitCast(UnsignedIntType, f);
136133
137134 const exponent_bits = math.floatExponentBits(T);
......@@ -187,10 +184,10 @@ pub const Rational = struct {
187184 pub fn toFloat(self: Rational, comptime T: type) !T {
188185 // Translated from golang.go/src/math/big/rat.go.
189186 // TODO: Indicate whether the result is not exact.
190 debug.assert(@typeId(T) == builtin.TypeId.Float);
187 debug.assert(@typeInfo(T) == .Float);
191188
192189 const fsize = T.bit_count;
193 const BitReprType = @IntType(false, T.bit_count);
190 const BitReprType = std.meta.IntType(false, T.bit_count);
194191
195192 const msize = math.floatMantissaBits(T);
196193 const msize1 = msize + 1;
......@@ -465,7 +462,7 @@ pub const Rational = struct {
465462 }
466463};
467464
468const SignedDoubleLimb = @IntType(true, DoubleLimb.bit_count);
465const SignedDoubleLimb = std.meta.IntType(true, DoubleLimb.bit_count);
469466
470467fn gcd(rma: *Int, x: Int, y: Int) !void {
471468 rma.assertWritable();
......@@ -653,7 +650,7 @@ test "big.rational gcd one large" {
653650}
654651
655652fn extractLowBits(a: Int, comptime T: type) T {
656 testing.expect(@typeId(T) == builtin.TypeId.Int);
653 testing.expect(@typeInfo(T) == .Int);
657654
658655 if (T.bit_count <= Limb.bit_count) {
659656 return @truncate(T, a.limbs[0]);
lib/std/math/cos.zig+1-1
......@@ -44,7 +44,7 @@ const pi4c = 2.69515142907905952645E-15;
4444const m4pi = 1.273239544735162542821171882678754627704620361328125;
4545
4646fn cos_(comptime T: type, x_: T) T {
47 const I = @IntType(true, T.bit_count);
47 const I = std.meta.IntType(true, T.bit_count);
4848
4949 var x = x_;
5050 if (math.isNan(x) or math.isInf(x)) {
lib/std/math/ln.zig+5-7
......@@ -7,8 +7,6 @@
77const std = @import("../std.zig");
88const math = std.math;
99const expect = std.testing.expect;
10const builtin = @import("builtin");
11const TypeId = builtin.TypeId;
1210
1311/// Returns the natural logarithm of x.
1412///
......@@ -19,21 +17,21 @@ const TypeId = builtin.TypeId;
1917/// - ln(nan) = nan
2018pub fn ln(x: var) @TypeOf(x) {
2119 const T = @TypeOf(x);
22 switch (@typeId(T)) {
23 TypeId.ComptimeFloat => {
20 switch (@typeInfo(T)) {
21 .ComptimeFloat => {
2422 return @as(comptime_float, ln_64(x));
2523 },
26 TypeId.Float => {
24 .Float => {
2725 return switch (T) {
2826 f32 => ln_32(x),
2927 f64 => ln_64(x),
3028 else => @compileError("ln not implemented for " ++ @typeName(T)),
3129 };
3230 },
33 TypeId.ComptimeInt => {
31 .ComptimeInt => {
3432 return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
3533 },
36 TypeId.Int => {
34 .Int => {
3735 return @as(T, math.floor(ln_64(@as(f64, x))));
3836 },
3937 else => @compileError("ln not implemented for " ++ @typeName(T)),
lib/std/math/log.zig+6-8
......@@ -6,8 +6,6 @@
66
77const std = @import("../std.zig");
88const math = std.math;
9const builtin = @import("builtin");
10const TypeId = builtin.TypeId;
119const expect = std.testing.expect;
1210
1311/// Returns the logarithm of x for the provided base.
......@@ -16,24 +14,24 @@ pub fn log(comptime T: type, base: T, x: T) T {
1614 return math.log2(x);
1715 } else if (base == 10) {
1816 return math.log10(x);
19 } else if ((@typeId(T) == TypeId.Float or @typeId(T) == TypeId.ComptimeFloat) and base == math.e) {
17 } else if ((@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat) and base == math.e) {
2018 return math.ln(x);
2119 }
2220
2321 const float_base = math.lossyCast(f64, base);
24 switch (@typeId(T)) {
25 TypeId.ComptimeFloat => {
22 switch (@typeInfo(T)) {
23 .ComptimeFloat => {
2624 return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base));
2725 },
28 TypeId.ComptimeInt => {
26 .ComptimeInt => {
2927 return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
3028 },
31 builtin.TypeId.Int => {
29 .Int => {
3230 // TODO implement integer log without using float math
3331 return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base)));
3432 },
3533
36 builtin.TypeId.Float => {
34 .Float => {
3735 switch (T) {
3836 f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),
3937 f64 => return math.ln(x) / math.ln(float_base),
lib/std/math/log10.zig+5-7
......@@ -7,8 +7,6 @@
77const std = @import("../std.zig");
88const math = std.math;
99const testing = std.testing;
10const builtin = @import("builtin");
11const TypeId = builtin.TypeId;
1210const maxInt = std.math.maxInt;
1311
1412/// Returns the base-10 logarithm of x.
......@@ -20,21 +18,21 @@ const maxInt = std.math.maxInt;
2018/// - log10(nan) = nan
2119pub fn log10(x: var) @TypeOf(x) {
2220 const T = @TypeOf(x);
23 switch (@typeId(T)) {
24 TypeId.ComptimeFloat => {
21 switch (@typeInfo(T)) {
22 .ComptimeFloat => {
2523 return @as(comptime_float, log10_64(x));
2624 },
27 TypeId.Float => {
25 .Float => {
2826 return switch (T) {
2927 f32 => log10_32(x),
3028 f64 => log10_64(x),
3129 else => @compileError("log10 not implemented for " ++ @typeName(T)),
3230 };
3331 },
34 TypeId.ComptimeInt => {
32 .ComptimeInt => {
3533 return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
3634 },
37 TypeId.Int => {
35 .Int => {
3836 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
3937 },
4038 else => @compileError("log10 not implemented for " ++ @typeName(T)),
lib/std/math/log2.zig+5-7
......@@ -7,8 +7,6 @@
77const std = @import("../std.zig");
88const math = std.math;
99const expect = std.testing.expect;
10const builtin = @import("builtin");
11const TypeId = builtin.TypeId;
1210const maxInt = std.math.maxInt;
1311
1412/// Returns the base-2 logarithm of x.
......@@ -20,18 +18,18 @@ const maxInt = std.math.maxInt;
2018/// - log2(nan) = nan
2119pub fn log2(x: var) @TypeOf(x) {
2220 const T = @TypeOf(x);
23 switch (@typeId(T)) {
24 TypeId.ComptimeFloat => {
21 switch (@typeInfo(T)) {
22 .ComptimeFloat => {
2523 return @as(comptime_float, log2_64(x));
2624 },
27 TypeId.Float => {
25 .Float => {
2826 return switch (T) {
2927 f32 => log2_32(x),
3028 f64 => log2_64(x),
3129 else => @compileError("log2 not implemented for " ++ @typeName(T)),
3230 };
3331 },
34 TypeId.ComptimeInt => comptime {
32 .ComptimeInt => comptime {
3533 var result = 0;
3634 var x_shifted = x;
3735 while (b: {
......@@ -40,7 +38,7 @@ pub fn log2(x: var) @TypeOf(x) {
4038 }) : (result += 1) {}
4139 return result;
4240 },
43 TypeId.Int => {
41 .Int => {
4442 return math.log2_int(T, x);
4543 },
4644 else => @compileError("log2 not implemented for " ++ @typeName(T)),
lib/std/math/pow.zig+1-1
......@@ -145,7 +145,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
145145 var xe = r2.exponent;
146146 var x1 = r2.significand;
147147
148 var i = @floatToInt(@IntType(true, T.bit_count), yi);
148 var i = @floatToInt(std.meta.IntType(true, T.bit_count), yi);
149149 while (i != 0) : (i >>= 1) {
150150 const overflow_shift = math.floatExponentBits(T) + 1;
151151 if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) {
lib/std/math/sin.zig+1-1
......@@ -45,7 +45,7 @@ const pi4c = 2.69515142907905952645E-15;
4545const m4pi = 1.273239544735162542821171882678754627704620361328125;
4646
4747fn sin_(comptime T: type, x_: T) T {
48 const I = @IntType(true, T.bit_count);
48 const I = std.meta.IntType(true, T.bit_count);
4949
5050 var x = x_;
5151 if (x == 0 or math.isNan(x)) {
lib/std/math/sqrt.zig+3-3
......@@ -31,7 +31,7 @@ pub fn sqrt(x: var) Sqrt(@TypeOf(x)) {
3131 }
3232}
3333
34fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
34fn sqrt_int(comptime T: type, value: T) std.meta.IntType(false, T.bit_count / 2) {
3535 var op = value;
3636 var res: T = 0;
3737 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) {
5050 one >>= 2;
5151 }
5252
53 const ResultType = @IntType(false, T.bit_count / 2);
53 const ResultType = std.meta.IntType(false, T.bit_count / 2);
5454 return @intCast(ResultType, res);
5555}
5656
......@@ -66,7 +66,7 @@ test "math.sqrt_int" {
6666/// Returns the return type `sqrt` will return given an operand of type `T`.
6767pub fn Sqrt(comptime T: type) type {
6868 return switch (@typeInfo(T)) {
69 .Int => |int| @IntType(false, int.bits / 2),
69 .Int => |int| std.meta.IntType(false, int.bits / 2),
7070 else => T,
7171 };
7272}
lib/std/math/tan.zig+1-1
......@@ -38,7 +38,7 @@ const pi4c = 2.69515142907905952645E-15;
3838const m4pi = 1.273239544735162542821171882678754627704620361328125;
3939
4040fn tan_(comptime T: type, x_: T) T {
41 const I = @IntType(true, T.bit_count);
41 const I = std.meta.IntType(true, T.bit_count);
4242
4343 var x = x_;
4444 if (x == 0 or math.isNan(x)) {
lib/std/mem.zig+2-2
......@@ -708,7 +708,7 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
708708 assert(buffer.len >= @divExact(T.bit_count, 8));
709709
710710 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough
711 const uint = @IntType(false, T.bit_count);
711 const uint = std.meta.IntType(false, T.bit_count);
712712 var bits = @truncate(uint, value);
713713 for (buffer) |*b| {
714714 b.* = @truncate(u8, bits);
......@@ -725,7 +725,7 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
725725 assert(buffer.len >= @divExact(T.bit_count, 8));
726726
727727 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough
728 const uint = @IntType(false, T.bit_count);
728 const uint = std.meta.IntType(false, T.bit_count);
729729 var bits = @truncate(uint, value);
730730 var index: usize = buffer.len;
731731 while (index != 0) {
lib/std/meta.zig+11-3
......@@ -536,9 +536,8 @@ test "intToEnum with error return" {
536536pub const IntToEnumError = error{InvalidEnumTag};
537537
538538pub fn intToEnum(comptime Tag: type, tag_int: var) IntToEnumError!Tag {
539 comptime var i = 0;
540 inline while (i != @memberCount(Tag)) : (i += 1) {
541 const this_tag_value = @field(Tag, @memberName(Tag, i));
539 inline for (@typeInfo(Tag).Enum.fields) |f| {
540 const this_tag_value = @field(Tag, f.name);
542541 if (tag_int == @enumToInt(this_tag_value)) {
543542 return this_tag_value;
544543 }
......@@ -581,3 +580,12 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
581580 return &array;
582581 }
583582}
583
584pub fn IntType(comptime is_signed: bool, comptime bit_count: u16) type {
585 return @Type(TypeInfo{
586 .Int = .{
587 .is_signed = is_signed,
588 .bits = bit_count,
589 },
590 });
591}
lib/std/meta/trait.zig+7-7
......@@ -1,5 +1,5 @@
11const std = @import("../std.zig");
2const builtin = @import("builtin");
2const builtin = std.builtin;
33const mem = std.mem;
44const debug = std.debug;
55const testing = std.testing;
......@@ -54,7 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
5454 if (!comptime isContainer(T)) return false;
5555 if (!comptime @hasDecl(T, name)) return false;
5656 const DeclType = @TypeOf(@field(T, name));
57 return @typeId(DeclType) == .Fn;
57 return @typeInfo(DeclType) == .Fn;
5858 }
5959 };
6060 return Closure.trait;
......@@ -105,7 +105,7 @@ test "std.meta.trait.hasField" {
105105pub fn is(comptime id: builtin.TypeId) TraitFn {
106106 const Closure = struct {
107107 pub fn trait(comptime T: type) bool {
108 return id == @typeId(T);
108 return id == @typeInfo(T);
109109 }
110110 };
111111 return Closure.trait;
......@@ -123,7 +123,7 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
123123 const Closure = struct {
124124 pub fn trait(comptime T: type) bool {
125125 if (!comptime isSingleItemPtr(T)) return false;
126 return id == @typeId(meta.Child(T));
126 return id == @typeInfo(meta.Child(T));
127127 }
128128 };
129129 return Closure.trait;
......@@ -139,7 +139,7 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
139139 const Closure = struct {
140140 pub fn trait(comptime T: type) bool {
141141 if (!comptime isSlice(T)) return false;
142 return id == @typeId(meta.Child(T));
142 return id == @typeInfo(meta.Child(T));
143143 }
144144 };
145145 return Closure.trait;
......@@ -285,7 +285,7 @@ test "std.meta.trait.isIndexable" {
285285}
286286
287287pub fn isNumber(comptime T: type) bool {
288 return switch (@typeId(T)) {
288 return switch (@typeInfo(T)) {
289289 .Int, .Float, .ComptimeInt, .ComptimeFloat => true,
290290 else => false,
291291 };
......@@ -320,7 +320,7 @@ test "std.meta.trait.isConstPtr" {
320320}
321321
322322pub fn isContainer(comptime T: type) bool {
323 return switch (@typeId(T)) {
323 return switch (@typeInfo(T)) {
324324 .Struct, .Union, .Enum => true,
325325 else => false,
326326 };
lib/std/os.zig+1-1
......@@ -3349,7 +3349,7 @@ pub fn res_mkquery(
33493349 // Make a reasonably unpredictable id
33503350 var ts: timespec = undefined;
33513351 clock_gettime(CLOCK_REALTIME, &ts) catch {};
3352 const UInt = @IntType(false, @TypeOf(ts.tv_nsec).bit_count);
3352 const UInt = std.meta.IntType(false, @TypeOf(ts.tv_nsec).bit_count);
33533353 const unsec = @bitCast(UInt, ts.tv_nsec);
33543354 const id = @truncate(u32, unsec + unsec / 65536);
33553355 q[0] = @truncate(u8, id / 256);
lib/std/os/bits/linux.zig+1-1
......@@ -1004,7 +1004,7 @@ pub const dl_phdr_info = extern struct {
10041004
10051005pub const CPU_SETSIZE = 128;
10061006pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;
1007pub const cpu_count_t = @IntType(false, std.math.log2(CPU_SETSIZE * 8));
1007pub const cpu_count_t = std.meta.IntType(false, std.math.log2(CPU_SETSIZE * 8));
10081008
10091009pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
10101010 var sum: cpu_count_t = 0;
lib/std/packed_int_array.zig+6-6
......@@ -34,13 +34,13 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: builtin.Endian) type {
3434
3535 //we bitcast the desired Int type to an unsigned version of itself
3636 // to avoid issues with shifting signed ints.
37 const UnInt = @IntType(false, int_bits);
37 const UnInt = std.meta.IntType(false, int_bits);
3838
3939 //The maximum container int type
40 const MinIo = @IntType(false, min_io_bits);
40 const MinIo = std.meta.IntType(false, min_io_bits);
4141
4242 //The minimum container int type
43 const MaxIo = @IntType(false, max_io_bits);
43 const MaxIo = std.meta.IntType(false, max_io_bits);
4444
4545 return struct {
4646 pub fn get(bytes: []const u8, index: usize, bit_offset: u7) Int {
......@@ -322,7 +322,7 @@ test "PackedIntArray" {
322322 inline while (bits <= 256) : (bits += 1) {
323323 //alternate unsigned and signed
324324 const even = bits % 2 == 0;
325 const I = @IntType(even, bits);
325 const I = std.meta.IntType(even, bits);
326326
327327 const PackedArray = PackedIntArray(I, int_count);
328328 const expected_bytes = ((bits * int_count) + 7) / 8;
......@@ -369,7 +369,7 @@ test "PackedIntSlice" {
369369 inline while (bits <= 256) : (bits += 1) {
370370 //alternate unsigned and signed
371371 const even = bits % 2 == 0;
372 const I = @IntType(even, bits);
372 const I = std.meta.IntType(even, bits);
373373 const P = PackedIntSlice(I);
374374
375375 var data = P.init(&buffer, int_count);
......@@ -399,7 +399,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
399399
400400 comptime var bits = 0;
401401 inline while (bits <= max_bits) : (bits += 1) {
402 const Int = @IntType(false, bits);
402 const Int = std.meta.IntType(false, bits);
403403
404404 const PackedArray = PackedIntArray(Int, int_count);
405405 var packed_array = @as(PackedArray, undefined);
lib/std/rand.zig+10-10
......@@ -45,8 +45,8 @@ pub const Random = struct {
4545 /// Returns a random int `i` such that `0 <= i <= maxInt(T)`.
4646 /// `i` is evenly distributed.
4747 pub fn int(r: *Random, comptime T: type) T {
48 const UnsignedT = @IntType(false, T.bit_count);
49 const ByteAlignedT = @IntType(false, @divTrunc(T.bit_count + 7, 8) * 8);
48 const UnsignedT = std.meta.IntType(false, T.bit_count);
49 const ByteAlignedT = std.meta.IntType(false, @divTrunc(T.bit_count + 7, 8) * 8);
5050
5151 var rand_bytes: [@sizeOf(ByteAlignedT)]u8 = undefined;
5252 r.bytes(rand_bytes[0..]);
......@@ -85,9 +85,9 @@ pub const Random = struct {
8585 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
8686 assert(0 < less_than);
8787 // Small is typically u32
88 const Small = @IntType(false, @divTrunc(T.bit_count + 31, 32) * 32);
88 const Small = std.meta.IntType(false, @divTrunc(T.bit_count + 31, 32) * 32);
8989 // Large is typically u64
90 const Large = @IntType(false, Small.bit_count * 2);
90 const Large = std.meta.IntType(false, Small.bit_count * 2);
9191
9292 // adapted from:
9393 // http://www.pcg-random.org/posts/bounded-rands.html
......@@ -99,7 +99,7 @@ pub const Random = struct {
9999 // TODO: workaround for https://github.com/ziglang/zig/issues/1770
100100 // should be:
101101 // var t: Small = -%less_than;
102 var t: Small = @bitCast(Small, -%@bitCast(@IntType(true, Small.bit_count), @as(Small, less_than)));
102 var t: Small = @bitCast(Small, -%@bitCast(std.meta.IntType(true, Small.bit_count), @as(Small, less_than)));
103103
104104 if (t >= less_than) {
105105 t -= less_than;
......@@ -145,7 +145,7 @@ pub const Random = struct {
145145 assert(at_least < less_than);
146146 if (T.is_signed) {
147147 // Two's complement makes this math pretty easy.
148 const UnsignedT = @IntType(false, T.bit_count);
148 const UnsignedT = std.meta.IntType(false, T.bit_count);
149149 const lo = @bitCast(UnsignedT, at_least);
150150 const hi = @bitCast(UnsignedT, less_than);
151151 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);
......@@ -163,7 +163,7 @@ pub const Random = struct {
163163 assert(at_least < less_than);
164164 if (T.is_signed) {
165165 // Two's complement makes this math pretty easy.
166 const UnsignedT = @IntType(false, T.bit_count);
166 const UnsignedT = std.meta.IntType(false, T.bit_count);
167167 const lo = @bitCast(UnsignedT, at_least);
168168 const hi = @bitCast(UnsignedT, less_than);
169169 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);
......@@ -180,7 +180,7 @@ pub const Random = struct {
180180 assert(at_least <= at_most);
181181 if (T.is_signed) {
182182 // Two's complement makes this math pretty easy.
183 const UnsignedT = @IntType(false, T.bit_count);
183 const UnsignedT = std.meta.IntType(false, T.bit_count);
184184 const lo = @bitCast(UnsignedT, at_least);
185185 const hi = @bitCast(UnsignedT, at_most);
186186 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);
......@@ -198,7 +198,7 @@ pub const Random = struct {
198198 assert(at_least <= at_most);
199199 if (T.is_signed) {
200200 // Two's complement makes this math pretty easy.
201 const UnsignedT = @IntType(false, T.bit_count);
201 const UnsignedT = std.meta.IntType(false, T.bit_count);
202202 const lo = @bitCast(UnsignedT, at_least);
203203 const hi = @bitCast(UnsignedT, at_most);
204204 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);
......@@ -281,7 +281,7 @@ pub const Random = struct {
281281/// This function introduces a minor bias.
282282pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
283283 comptime assert(T.is_signed == false);
284 const T2 = @IntType(false, T.bit_count * 2);
284 const T2 = std.meta.IntType(false, T.bit_count * 2);
285285
286286 // adapted from:
287287 // http://www.pcg-random.org/posts/bounded-rands.html
lib/std/special/build_runner.zig+1-1
......@@ -128,7 +128,7 @@ pub fn main() !void {
128128}
129129
130130fn runBuild(builder: *Builder) anyerror!void {
131 switch (@typeId(@TypeOf(root.build).ReturnType)) {
131 switch (@typeInfo(@TypeOf(root.build).ReturnType)) {
132132 .Void => root.build(builder),
133133 .ErrorUnion => try root.build(builder),
134134 else => @compileError("expected return type of build to be 'void' or '!void'"),
lib/std/special/c.zig+1-1
......@@ -511,7 +511,7 @@ export fn roundf(a: f32) f32 {
511511fn generic_fmod(comptime T: type, x: T, y: T) T {
512512 @setRuntimeSafety(false);
513513
514 const uint = @IntType(false, T.bit_count);
514 const uint = std.meta.IntType(false, T.bit_count);
515515 const log2uint = math.Log2Int(uint);
516516 const digits = if (T == f32) 23 else 52;
517517 const exp_bits = if (T == f32) 9 else 12;
lib/std/special/compiler_rt/addXf3.zig+7-7
......@@ -54,21 +54,21 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
5454}
5555
5656// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
57fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
58 const Z = @IntType(false, T.bit_count);
59 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
57fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
58 const Z = std.meta.IntType(false, T.bit_count);
59 const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
6060 const significandBits = std.math.floatMantissaBits(T);
6161 const implicitBit = @as(Z, 1) << significandBits;
6262
63 const shift = @clz(@IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
63 const shift = @clz(std.meta.IntType(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
6464 significand.* <<= @intCast(S, shift);
6565 return 1 - shift;
6666}
6767
6868// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
6969fn addXf3(comptime T: type, a: T, b: T) T {
70 const Z = @IntType(false, T.bit_count);
71 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
70 const Z = std.meta.IntType(false, T.bit_count);
71 const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
7272
7373 const typeWidth = T.bit_count;
7474 const significandBits = std.math.floatMantissaBits(T);
......@@ -182,7 +182,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
182182 // If partial cancellation occured, we need to left-shift the result
183183 // and adjust the exponent:
184184 if (aSignificand < implicitBit << 3) {
185 const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(@IntType(false, T.bit_count), implicitBit << 3));
185 const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.IntType(false, T.bit_count), implicitBit << 3));
186186 aSignificand <<= @intCast(S, shift);
187187 aExponent -= shift;
188188 }
lib/std/special/compiler_rt/compareXf2.zig+3-3
......@@ -22,8 +22,8 @@ const GE = extern enum(i32) {
2222pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
2323 @setRuntimeSafety(builtin.is_test);
2424
25 const srep_t = @IntType(true, T.bit_count);
26 const rep_t = @IntType(false, T.bit_count);
25 const srep_t = std.meta.IntType(true, T.bit_count);
26 const rep_t = std.meta.IntType(false, T.bit_count);
2727
2828 const significandBits = std.math.floatMantissaBits(T);
2929 const exponentBits = std.math.floatExponentBits(T);
......@@ -68,7 +68,7 @@ pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
6868pub fn unordcmp(comptime T: type, a: T, b: T) i32 {
6969 @setRuntimeSafety(builtin.is_test);
7070
71 const rep_t = @IntType(false, T.bit_count);
71 const rep_t = std.meta.IntType(false, T.bit_count);
7272
7373 const significandBits = std.math.floatMantissaBits(T);
7474 const exponentBits = std.math.floatExponentBits(T);
lib/std/special/compiler_rt/divdf3.zig+4-4
......@@ -7,8 +7,8 @@ const builtin = @import("builtin");
77
88pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
99 @setRuntimeSafety(builtin.is_test);
10 const Z = @IntType(false, f64.bit_count);
11 const SignedZ = @IntType(true, f64.bit_count);
10 const Z = std.meta.IntType(false, f64.bit_count);
11 const SignedZ = std.meta.IntType(true, f64.bit_count);
1212
1313 const typeWidth = f64.bit_count;
1414 const significandBits = std.math.floatMantissaBits(f64);
......@@ -312,9 +312,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
312312 }
313313}
314314
315fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
315fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
316316 @setRuntimeSafety(builtin.is_test);
317 const Z = @IntType(false, T.bit_count);
317 const Z = std.meta.IntType(false, T.bit_count);
318318 const significandBits = std.math.floatMantissaBits(T);
319319 const implicitBit = @as(Z, 1) << significandBits;
320320
lib/std/special/compiler_rt/divsf3.zig+3-3
......@@ -7,7 +7,7 @@ const builtin = @import("builtin");
77
88pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
99 @setRuntimeSafety(builtin.is_test);
10 const Z = @IntType(false, f32.bit_count);
10 const Z = std.meta.IntType(false, f32.bit_count);
1111
1212 const typeWidth = f32.bit_count;
1313 const significandBits = std.math.floatMantissaBits(f32);
......@@ -185,9 +185,9 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
185185 }
186186}
187187
188fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
188fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
189189 @setRuntimeSafety(builtin.is_test);
190 const Z = @IntType(false, T.bit_count);
190 const Z = std.meta.IntType(false, T.bit_count);
191191 const significandBits = std.math.floatMantissaBits(T);
192192 const implicitBit = @as(Z, 1) << significandBits;
193193
lib/std/special/compiler_rt/extendXfYf2.zig+3-3
......@@ -30,11 +30,11 @@ pub fn __aeabi_f2d(arg: f32) callconv(.AAPCS) f64 {
3030
3131const CHAR_BIT = 8;
3232
33fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @typeInfo(src_t).Float.bits)) dst_t {
33fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: std.meta.IntType(false, @typeInfo(src_t).Float.bits)) dst_t {
3434 @setRuntimeSafety(builtin.is_test);
3535
36 const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits);
37 const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);
36 const src_rep_t = std.meta.IntType(false, @typeInfo(src_t).Float.bits);
37 const dst_rep_t = std.meta.IntType(false, @typeInfo(dst_t).Float.bits);
3838 const srcSigBits = std.math.floatMantissaBits(src_t);
3939 const dstSigBits = std.math.floatMantissaBits(dst_t);
4040 const SrcShift = std.math.Log2Int(src_rep_t);
lib/std/special/compiler_rt/fixint.zig+1-1
......@@ -45,7 +45,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
4545 if (exponent < 0) return 0;
4646
4747 // The unsigned result needs to be large enough to handle an fixint_t or rep_t
48 const fixuint_t = @IntType(false, fixint_t.bit_count);
48 const fixuint_t = std.meta.IntType(false, fixint_t.bit_count);
4949 const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t;
5050 var uint_result: UintResultType = undefined;
5151
lib/std/special/compiler_rt/fixuint.zig+1-1
......@@ -10,7 +10,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
1010 f128 => u128,
1111 else => unreachable,
1212 };
13 const srep_t = @IntType(true, rep_t.bit_count);
13 const srep_t = @import("std").meta.IntType(true, rep_t.bit_count);
1414 const significandBits = switch (fp_t) {
1515 f32 => 23,
1616 f64 => 52,
lib/std/special/compiler_rt/floatsiXf.zig+2-2
......@@ -5,8 +5,8 @@ const maxInt = std.math.maxInt;
55fn floatsiXf(comptime T: type, a: i32) T {
66 @setRuntimeSafety(builtin.is_test);
77
8 const Z = @IntType(false, T.bit_count);
9 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
8 const Z = std.meta.IntType(false, T.bit_count);
9 const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
1010
1111 if (a == 0) {
1212 return @as(T, 0.0);
lib/std/special/compiler_rt/mulXf3.zig+3-3
......@@ -28,7 +28,7 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {
2828
2929fn mulXf3(comptime T: type, a: T, b: T) T {
3030 @setRuntimeSafety(builtin.is_test);
31 const Z = @IntType(false, T.bit_count);
31 const Z = std.meta.IntType(false, T.bit_count);
3232
3333 const typeWidth = T.bit_count;
3434 const significandBits = std.math.floatMantissaBits(T);
......@@ -264,9 +264,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
264264 }
265265}
266266
267fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {
267fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
268268 @setRuntimeSafety(builtin.is_test);
269 const Z = @IntType(false, T.bit_count);
269 const Z = std.meta.IntType(false, T.bit_count);
270270 const significandBits = std.math.floatMantissaBits(T);
271271 const implicitBit = @as(Z, 1) << significandBits;
272272
lib/std/special/compiler_rt/negXf2.zig+1-1
......@@ -19,7 +19,7 @@ pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
1919}
2020
2121fn negXf2(comptime T: type, a: T) T {
22 const Z = @IntType(false, T.bit_count);
22 const Z = std.meta.IntType(false, T.bit_count);
2323
2424 const typeWidth = T.bit_count;
2525 const significandBits = std.math.floatMantissaBits(T);
lib/std/special/compiler_rt/truncXfYf2.zig+2-2
......@@ -36,8 +36,8 @@ pub fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
3636}
3737
3838inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
39 const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits);
40 const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);
39 const src_rep_t = std.meta.IntType(false, @typeInfo(src_t).Float.bits);
40 const dst_rep_t = std.meta.IntType(false, @typeInfo(dst_t).Float.bits);
4141 const srcSigBits = std.math.floatMantissaBits(src_t);
4242 const dstSigBits = std.math.floatMantissaBits(dst_t);
4343 const SrcShift = std.math.Log2Int(src_rep_t);
lib/std/special/compiler_rt/udivmod.zig+2-2
......@@ -10,8 +10,8 @@ const high = 1 - low;
1010pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {
1111 @setRuntimeSafety(is_test);
1212
13 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
14 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
13 const SingleInt = @import("std").meta.IntType(false, @divExact(DoubleInt.bit_count, 2));
14 const SignedDoubleInt = @import("std").meta.IntType(true, DoubleInt.bit_count);
1515 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
1616
1717 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
lib/std/target.zig+1-1
......@@ -222,7 +222,7 @@ pub const Target = union(enum) {
222222 pub const needed_bit_count = 154;
223223 pub const byte_count = (needed_bit_count + 7) / 8;
224224 pub const usize_count = (byte_count + (@sizeOf(usize) - 1)) / @sizeOf(usize);
225 pub const Index = std.math.Log2Int(@IntType(false, usize_count * @bitSizeOf(usize)));
225 pub const Index = std.math.Log2Int(std.meta.IntType(false, usize_count * @bitSizeOf(usize)));
226226 pub const ShiftInt = std.math.Log2Int(usize);
227227
228228 pub const empty = Set{ .ints = [1]usize{0} ** usize_count };
lib/std/thread.zig+3-3
......@@ -148,7 +148,7 @@ pub const Thread = struct {
148148 const default_stack_size = 16 * 1024 * 1024;
149149
150150 const Context = @TypeOf(context);
151 comptime assert(@ArgType(@TypeOf(startFn), 0) == Context);
151 comptime assert(@typeInfo(@TypeOf(startFn)).Fn.args[0].arg_type.? == Context);
152152
153153 if (builtin.os == builtin.Os.windows) {
154154 const WinThread = struct {
......@@ -158,7 +158,7 @@ pub const Thread = struct {
158158 };
159159 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {
160160 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
161 switch (@typeId(@TypeOf(startFn).ReturnType)) {
161 switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
162162 .Int => {
163163 return startFn(arg);
164164 },
......@@ -201,7 +201,7 @@ pub const Thread = struct {
201201 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {
202202 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
203203
204 switch (@typeId(@TypeOf(startFn).ReturnType)) {
204 switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
205205 .Int => {
206206 return startFn(arg);
207207 },
lib/std/zig/ast.zig+12-16
......@@ -457,10 +457,9 @@ pub const Node = struct {
457457 }
458458
459459 pub fn iterate(base: *Node, index: usize) ?*Node {
460 comptime var i = 0;
461 inline while (i < @memberCount(Id)) : (i += 1) {
462 if (base.id == @field(Id, @memberName(Id, i))) {
463 const T = @field(Node, @memberName(Id, i));
460 inline for (@typeInfo(Id).Enum.fields) |f| {
461 if (base.id == @field(Id, f.name)) {
462 const T = @field(Node, f.name);
464463 return @fieldParentPtr(T, "base", base).iterate(index);
465464 }
466465 }
......@@ -468,10 +467,9 @@ pub const Node = struct {
468467 }
469468
470469 pub fn firstToken(base: *const Node) TokenIndex {
471 comptime var i = 0;
472 inline while (i < @memberCount(Id)) : (i += 1) {
473 if (base.id == @field(Id, @memberName(Id, i))) {
474 const T = @field(Node, @memberName(Id, i));
470 inline for (@typeInfo(Id).Enum.fields) |f| {
471 if (base.id == @field(Id, f.name)) {
472 const T = @field(Node, f.name);
475473 return @fieldParentPtr(T, "base", base).firstToken();
476474 }
477475 }
......@@ -479,10 +477,9 @@ pub const Node = struct {
479477 }
480478
481479 pub fn lastToken(base: *const Node) TokenIndex {
482 comptime var i = 0;
483 inline while (i < @memberCount(Id)) : (i += 1) {
484 if (base.id == @field(Id, @memberName(Id, i))) {
485 const T = @field(Node, @memberName(Id, i));
480 inline for (@typeInfo(Id).Enum.fields) |f| {
481 if (base.id == @field(Id, f.name)) {
482 const T = @field(Node, f.name);
486483 return @fieldParentPtr(T, "base", base).lastToken();
487484 }
488485 }
......@@ -490,10 +487,9 @@ pub const Node = struct {
490487 }
491488
492489 pub fn typeToId(comptime T: type) Id {
493 comptime var i = 0;
494 inline while (i < @memberCount(Id)) : (i += 1) {
495 if (T == @field(Node, @memberName(Id, i))) {
496 return @field(Id, @memberName(Id, i));
490 inline for (@typeInfo(Id).Enum.fields) |f| {
491 if (T == @field(Node, f.name)) {
492 return @field(Id, f.name);
497493 }
498494 }
499495 unreachable;
lib/std/zig/parser_test.zig+1-1
......@@ -1410,7 +1410,7 @@ test "zig fmt: same-line comment after non-block if expression" {
14101410test "zig fmt: same-line comment on comptime expression" {
14111411 try testCanonical(
14121412 \\test "" {
1413 \\ comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
1413 \\ comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
14141414 \\}
14151415 \\
14161416 );
lib/std/zig/render.zig+1-2
......@@ -1,5 +1,4 @@
11const std = @import("../std.zig");
2const builtin = @import("builtin");
32const assert = std.debug.assert;
43const mem = std.mem;
54const ast = std.zig.ast;
......@@ -14,7 +13,7 @@ pub const Error = error{
1413
1514/// Returns whether anything changed
1615pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool {
17 comptime assert(@typeId(@TypeOf(stream)) == builtin.TypeId.Pointer);
16 comptime assert(@typeInfo(@TypeOf(stream)) == .Pointer);
1817
1918 var anything_changed: bool = false;
2019
src-self-hosted/ir.zig+17-22
......@@ -76,20 +76,18 @@ pub const Inst = struct {
7676 }
7777
7878 pub fn typeToId(comptime T: type) Id {
79 comptime var i = 0;
80 inline while (i < @memberCount(Id)) : (i += 1) {
81 if (T == @field(Inst, @memberName(Id, i))) {
82 return @field(Id, @memberName(Id, i));
79 inline for (@typeInfo(Id).Enum.fields) |f| {
80 if (T == @field(Inst, f.name)) {
81 return @field(Id, f.name);
8382 }
8483 }
8584 unreachable;
8685 }
8786
8887 pub fn dump(base: *const Inst) void {
89 comptime var i = 0;
90 inline while (i < @memberCount(Id)) : (i += 1) {
91 if (base.id == @field(Id, @memberName(Id, i))) {
92 const T = @field(Inst, @memberName(Id, i));
88 inline for (@typeInfo(Id).Enum.fields) |f| {
89 if (base.id == @field(Id, f.name)) {
90 const T = @field(Inst, f.name);
9391 std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
9492 @fieldParentPtr(T, "base", base).dump();
9593 std.debug.warn(")", .{});
......@@ -100,10 +98,9 @@ pub const Inst = struct {
10098 }
10199
102100 pub fn hasSideEffects(base: *const Inst) bool {
103 comptime var i = 0;
104 inline while (i < @memberCount(Id)) : (i += 1) {
105 if (base.id == @field(Id, @memberName(Id, i))) {
106 const T = @field(Inst, @memberName(Id, i));
101 inline for (@typeInfo(Id).Enum.fields) |f| {
102 if (base.id == @field(Id, f.name)) {
103 const T = @field(Inst, f.name);
107104 return @fieldParentPtr(T, "base", base).hasSideEffects();
108105 }
109106 }
......@@ -1805,21 +1802,19 @@ pub const Builder = struct {
18051802 };
18061803
18071804 // Look at the params and ref() other instructions
1808 comptime var i = 0;
1809 inline while (i < @memberCount(I.Params)) : (i += 1) {
1810 const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));
1811 switch (FieldType) {
1812 *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),
1813 *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self),
1814 ?*Inst => if (@field(inst.params, @memberName(I.Params, i))) |other| other.ref(self),
1805 inline for (@typeInfo(I.Params).Struct.fields) |f| {
1806 switch (f.fiedl_type) {
1807 *Inst => @field(inst.params, f.name).ref(self),
1808 *BasicBlock => @field(inst.params, f.name).ref(self),
1809 ?*Inst => if (@field(inst.params, f.name)) |other| other.ref(self),
18151810 []*Inst => {
18161811 // TODO https://github.com/ziglang/zig/issues/1269
1817 for (@field(inst.params, @memberName(I.Params, i))) |other|
1812 for (@field(inst.params, f.name)) |other|
18181813 other.ref(self);
18191814 },
18201815 []*BasicBlock => {
18211816 // TODO https://github.com/ziglang/zig/issues/1269
1822 for (@field(inst.params, @memberName(I.Params, i))) |other|
1817 for (@field(inst.params, f.name)) |other|
18231818 other.ref(self);
18241819 },
18251820 Type.Pointer.Mut,
......@@ -1831,7 +1826,7 @@ pub const Builder = struct {
18311826 => {},
18321827 // it's ok to add more types here, just make sure that
18331828 // any instructions and basic blocks are ref'd appropriately
1834 else => @compileError("unrecognized type in Params: " ++ @typeName(FieldType)),
1829 else => @compileError("unrecognized type in Params: " ++ @typeName(f.field_type)),
18351830 }
18361831 }
18371832
src-self-hosted/translate_c.zig+4-4
......@@ -5381,15 +5381,15 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
53815381 return error.ParseError;
53825382 }
53835383
5384 //if (@typeId(@TypeOf(x)) == .Pointer)
5384 //if (@typeInfo(@TypeOf(x)) == .Pointer)
53855385 // @ptrCast(dest, x)
5386 //else if (@typeId(@TypeOf(x)) == .Integer)
5386 //else if (@typeInfo(@TypeOf(x)) == .Integer)
53875387 // @intToPtr(dest, x)
53885388 //else
53895389 // @as(dest, x)
53905390
53915391 const if_1 = try transCreateNodeIf(c);
5392 const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeId");
5392 const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
53935393 const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
53945394 try type_id_1.params.push(&type_of_1.base);
53955395 try type_of_1.params.push(node_to_cast);
......@@ -5416,7 +5416,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
54165416 if_1.@"else" = else_1;
54175417
54185418 const if_2 = try transCreateNodeIf(c);
5419 const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeId");
5419 const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
54205420 const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
54215421 try type_id_2.params.push(&type_of_2.base);
54225422 try type_of_2.params.push(node_to_cast);
src-self-hosted/type.zig+1-1
......@@ -1042,7 +1042,7 @@ fn hashAny(x: var, comptime seed: u64) u32 {
10421042 switch (@typeInfo(@TypeOf(x))) {
10431043 .Int => |info| {
10441044 comptime var rng = comptime std.rand.DefaultPrng.init(seed);
1045 const unsigned_x = @bitCast(@IntType(false, info.bits), x);
1045 const unsigned_x = @bitCast(std.meta.IntType(false, info.bits), x);
10461046 if (info.bits <= 32) {
10471047 return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);
10481048 } else {
src/all_types.hpp-44
......@@ -1695,9 +1695,6 @@ enum BuiltinFnId {
16951695 BuiltinFnIdMemset,
16961696 BuiltinFnIdSizeof,
16971697 BuiltinFnIdAlignOf,
1698 BuiltinFnIdMemberCount,
1699 BuiltinFnIdMemberType,
1700 BuiltinFnIdMemberName,
17011698 BuiltinFnIdField,
17021699 BuiltinFnIdTypeInfo,
17031700 BuiltinFnIdType,
......@@ -1757,7 +1754,6 @@ enum BuiltinFnId {
17571754 BuiltinFnIdIntToErr,
17581755 BuiltinFnIdEnumToInt,
17591756 BuiltinFnIdIntToEnum,
1760 BuiltinFnIdIntType,
17611757 BuiltinFnIdVectorType,
17621758 BuiltinFnIdShuffle,
17631759 BuiltinFnIdSplat,
......@@ -1777,7 +1773,6 @@ enum BuiltinFnId {
17771773 BuiltinFnIdBitOffsetOf,
17781774 BuiltinFnIdNewStackCall,
17791775 BuiltinFnIdAsyncCall,
1780 BuiltinFnIdTypeId,
17811776 BuiltinFnIdShlExact,
17821777 BuiltinFnIdShrExact,
17831778 BuiltinFnIdSetEvalBranchQuota,
......@@ -1785,7 +1780,6 @@ enum BuiltinFnId {
17851780 BuiltinFnIdOpaqueType,
17861781 BuiltinFnIdThis,
17871782 BuiltinFnIdSetAlignStack,
1788 BuiltinFnIdArgType,
17891783 BuiltinFnIdExport,
17901784 BuiltinFnIdErrorReturnTrace,
17911785 BuiltinFnIdAtomicRmw,
......@@ -2630,7 +2624,6 @@ enum IrInstSrcId {
26302624 IrInstSrcIdIntToFloat,
26312625 IrInstSrcIdFloatToInt,
26322626 IrInstSrcIdBoolToInt,
2633 IrInstSrcIdIntType,
26342627 IrInstSrcIdVectorType,
26352628 IrInstSrcIdShuffleVector,
26362629 IrInstSrcIdSplat,
......@@ -2638,9 +2631,6 @@ enum IrInstSrcId {
26382631 IrInstSrcIdMemset,
26392632 IrInstSrcIdMemcpy,
26402633 IrInstSrcIdSlice,
2641 IrInstSrcIdMemberCount,
2642 IrInstSrcIdMemberType,
2643 IrInstSrcIdMemberName,
26442634 IrInstSrcIdBreakpoint,
26452635 IrInstSrcIdReturnAddress,
26462636 IrInstSrcIdFrameAddress,
......@@ -2677,7 +2667,6 @@ enum IrInstSrcId {
26772667 IrInstSrcIdTypeInfo,
26782668 IrInstSrcIdType,
26792669 IrInstSrcIdHasField,
2680 IrInstSrcIdTypeId,
26812670 IrInstSrcIdSetEvalBranchQuota,
26822671 IrInstSrcIdPtrType,
26832672 IrInstSrcIdAlignCast,
......@@ -3636,13 +3625,6 @@ struct IrInstSrcBoolToInt {
36363625 IrInstSrc *target;
36373626};
36383627
3639struct IrInstSrcIntType {
3640 IrInstSrc base;
3641
3642 IrInstSrc *is_signed;
3643 IrInstSrc *bit_count;
3644};
3645
36463628struct IrInstSrcVectorType {
36473629 IrInstSrc base;
36483630
......@@ -3715,26 +3697,6 @@ struct IrInstGenSlice {
37153697 bool safety_check_on;
37163698};
37173699
3718struct IrInstSrcMemberCount {
3719 IrInstSrc base;
3720
3721 IrInstSrc *container;
3722};
3723
3724struct IrInstSrcMemberType {
3725 IrInstSrc base;
3726
3727 IrInstSrc *container_type;
3728 IrInstSrc *member_index;
3729};
3730
3731struct IrInstSrcMemberName {
3732 IrInstSrc base;
3733
3734 IrInstSrc *container_type;
3735 IrInstSrc *member_index;
3736};
3737
37383700struct IrInstSrcBreakpoint {
37393701 IrInstSrc base;
37403702};
......@@ -4142,12 +4104,6 @@ struct IrInstSrcHasField {
41424104 IrInstSrc *field_name;
41434105};
41444106
4145struct IrInstSrcTypeId {
4146 IrInstSrc base;
4147
4148 IrInstSrc *type_value;
4149};
4150
41514107struct IrInstSrcSetEvalBranchQuota {
41524108 IrInstSrc base;
41534109
src/codegen.cpp-6
......@@ -8152,9 +8152,6 @@ static void define_builtin_fns(CodeGen *g) {
81528152 create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);
81538153 create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);
81548154 create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1);
8155 create_builtin_fn(g, BuiltinFnIdMemberCount, "memberCount", 1);
8156 create_builtin_fn(g, BuiltinFnIdMemberType, "memberType", 2);
8157 create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
81588155 create_builtin_fn(g, BuiltinFnIdField, "field", 2);
81598156 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
81608157 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
......@@ -8192,7 +8189,6 @@ static void define_builtin_fns(CodeGen *g) {
81928189 create_builtin_fn(g, BuiltinFnIdIntToEnum, "intToEnum", 2);
81938190 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
81948191 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
8195 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
81968192 create_builtin_fn(g, BuiltinFnIdVectorType, "Vector", 2);
81978193 create_builtin_fn(g, BuiltinFnIdShuffle, "shuffle", 4);
81988194 create_builtin_fn(g, BuiltinFnIdSplat, "splat", 2);
......@@ -8231,14 +8227,12 @@ static void define_builtin_fns(CodeGen *g) {
82318227 create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);
82328228 create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);
82338229 create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);
8234 create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);
82358230 create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);
82368231 create_builtin_fn(g, BuiltinFnIdShrExact, "shrExact", 2);
82378232 create_builtin_fn(g, BuiltinFnIdSetEvalBranchQuota, "setEvalBranchQuota", 1);
82388233 create_builtin_fn(g, BuiltinFnIdAlignCast, "alignCast", 2);
82398234 create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);
82408235 create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
8241 create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);
82428236 create_builtin_fn(g, BuiltinFnIdExport, "export", 2);
82438237 create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);
82448238 create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);
src/ir.cpp-348
......@@ -389,8 +389,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
389389 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
390390 case IrInstSrcIdBoolToInt:
391391 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
392 case IrInstSrcIdIntType:
393 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
394392 case IrInstSrcIdVectorType:
395393 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
396394 case IrInstSrcIdShuffleVector:
......@@ -405,12 +403,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
405403 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
406404 case IrInstSrcIdSlice:
407405 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
408 case IrInstSrcIdMemberCount:
409 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
410 case IrInstSrcIdMemberType:
411 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
412 case IrInstSrcIdMemberName:
413 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
414406 case IrInstSrcIdBreakpoint:
415407 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
416408 case IrInstSrcIdReturnAddress:
......@@ -477,8 +469,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
477469 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
478470 case IrInstSrcIdHasField:
479471 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
480 case IrInstSrcIdTypeId:
481 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
482472 case IrInstSrcIdSetEvalBranchQuota:
483473 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
484474 case IrInstSrcIdAlignCast:
......@@ -1293,10 +1283,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
12931283 return IrInstSrcIdBoolToInt;
12941284}
12951285
1296static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
1297 return IrInstSrcIdIntType;
1298}
1299
13001286static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
13011287 return IrInstSrcIdVectorType;
13021288}
......@@ -1325,18 +1311,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
13251311 return IrInstSrcIdSlice;
13261312}
13271313
1328static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
1329 return IrInstSrcIdMemberCount;
1330}
1331
1332static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
1333 return IrInstSrcIdMemberType;
1334}
1335
1336static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
1337 return IrInstSrcIdMemberName;
1338}
1339
13401314static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
13411315 return IrInstSrcIdBreakpoint;
13421316}
......@@ -1481,10 +1455,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
14811455 return IrInstSrcIdHasField;
14821456}
14831457
1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1485 return IrInstSrcIdTypeId;
1486}
1487
14881458static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
14891459 return IrInstSrcIdSetEvalBranchQuota;
14901460}
......@@ -3542,19 +3512,6 @@ static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode
35423512 return &instruction->base;
35433513}
35443514
3545static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
3546 IrInstSrc *bit_count)
3547{
3548 IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
3549 instruction->is_signed = is_signed;
3550 instruction->bit_count = bit_count;
3551
3552 ir_ref_instruction(is_signed, irb->current_basic_block);
3553 ir_ref_instruction(bit_count, irb->current_basic_block);
3554
3555 return &instruction->base;
3556}
3557
35583515static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
35593516 IrInstSrc *elem_type)
35603517{
......@@ -3749,41 +3706,6 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
37493706 return &instruction->base;
37503707}
37513708
3752static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
3753 IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
3754 instruction->container = container;
3755
3756 ir_ref_instruction(container, irb->current_basic_block);
3757
3758 return &instruction->base;
3759}
3760
3761static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3762 IrInstSrc *container_type, IrInstSrc *member_index)
3763{
3764 IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
3765 instruction->container_type = container_type;
3766 instruction->member_index = member_index;
3767
3768 ir_ref_instruction(container_type, irb->current_basic_block);
3769 ir_ref_instruction(member_index, irb->current_basic_block);
3770
3771 return &instruction->base;
3772}
3773
3774static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3775 IrInstSrc *container_type, IrInstSrc *member_index)
3776{
3777 IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
3778 instruction->container_type = container_type;
3779 instruction->member_index = member_index;
3780
3781 ir_ref_instruction(container_type, irb->current_basic_block);
3782 ir_ref_instruction(member_index, irb->current_basic_block);
3783
3784 return &instruction->base;
3785}
3786
37873709static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
37883710 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
37893711 return &instruction->base;
......@@ -4458,15 +4380,6 @@ static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source
44584380 return &instruction->base;
44594381}
44604382
4461static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4462 IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
4463 instruction->type_value = type_value;
4464
4465 ir_ref_instruction(type_value, irb->current_basic_block);
4466
4467 return &instruction->base;
4468}
4469
44704383static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
44714384 IrInstSrc *new_quota)
44724385{
......@@ -6598,21 +6511,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
65986511 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
65996512 return ir_lval_wrap(irb, scope, result, lval, result_loc);
66006513 }
6601 case BuiltinFnIdIntType:
6602 {
6603 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6604 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6605 if (arg0_value == irb->codegen->invalid_inst_src)
6606 return arg0_value;
6607
6608 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6609 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6610 if (arg1_value == irb->codegen->invalid_inst_src)
6611 return arg1_value;
6612
6613 IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
6614 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
6615 }
66166514 case BuiltinFnIdVectorType:
66176515 {
66186516 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
67106608 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
67116609 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
67126610 }
6713 case BuiltinFnIdMemberCount:
6714 {
6715 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6716 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6717 if (arg0_value == irb->codegen->invalid_inst_src)
6718 return arg0_value;
6719
6720 IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
6721 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
6722 }
6723 case BuiltinFnIdMemberType:
6724 {
6725 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6726 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6727 if (arg0_value == irb->codegen->invalid_inst_src)
6728 return arg0_value;
6729
6730 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6731 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6732 if (arg1_value == irb->codegen->invalid_inst_src)
6733 return arg1_value;
6734
6735
6736 IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
6737 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
6738 }
6739 case BuiltinFnIdMemberName:
6740 {
6741 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6742 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6743 if (arg0_value == irb->codegen->invalid_inst_src)
6744 return arg0_value;
6745
6746 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6747 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6748 if (arg1_value == irb->codegen->invalid_inst_src)
6749 return arg1_value;
6750
6751
6752 IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
6753 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
6754 }
67556611 case BuiltinFnIdField:
67566612 {
67576613 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
71096965 }
71106966 case BuiltinFnIdAsyncCall:
71116967 return ir_gen_async_call(irb, scope, nullptr, node, lval, result_loc);
7112 case BuiltinFnIdTypeId:
7113 {
7114 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
7115 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7116 if (arg0_value == irb->codegen->invalid_inst_src)
7117 return arg0_value;
7118
7119 IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
7120 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
7121 }
71226968 case BuiltinFnIdShlExact:
71236969 {
71246970 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
71947040 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
71957041 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
71967042 }
7197 case BuiltinFnIdArgType:
7198 {
7199 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
7200 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
7201 if (arg0_value == irb->codegen->invalid_inst_src)
7202 return arg0_value;
7203
7204 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
7205 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
7206 if (arg1_value == irb->codegen->invalid_inst_src)
7207 return arg1_value;
7208
7209 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
7210 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
7211 }
72127043 case BuiltinFnIdExport:
72137044 {
72147045 // Cast the options parameter to the options type
......@@ -24795,19 +24626,6 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
2479524626 return ir_const_type(ira, &instruction->base.base, type);
2479624627}
2479724628
24798static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
24799 IrInstGen *type_value = instruction->type_value->child;
24800 ZigType *type_entry = ir_resolve_type(ira, type_value);
24801 if (type_is_invalid(type_entry))
24802 return ira->codegen->invalid_inst_gen;
24803
24804 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
24805
24806 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
24807 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
24808 return result;
24809}
24810
2481124629static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
2481224630 IrInstSrcSetEvalBranchQuota *instruction)
2481324631{
......@@ -25518,20 +25336,6 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
2551825336 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
2551925337}
2552025338
25521static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
25522 IrInstGen *is_signed_value = instruction->is_signed->child;
25523 bool is_signed;
25524 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
25525 return ira->codegen->invalid_inst_gen;
25526
25527 IrInstGen *bit_count_value = instruction->bit_count->child;
25528 uint64_t bit_count;
25529 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))
25530 return ira->codegen->invalid_inst_gen;
25531
25532 return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
25533}
25534
2553525339static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
2553625340 uint64_t len;
2553725341 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
2644526249 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
2644626250}
2644726251
26448static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
26449 Error err;
26450 IrInstGen *container = instruction->container->child;
26451 if (type_is_invalid(container->value->type))
26452 return ira->codegen->invalid_inst_gen;
26453 ZigType *container_type = ir_resolve_type(ira, container);
26454
26455 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
26456 return ira->codegen->invalid_inst_gen;
26457
26458 uint64_t result;
26459 if (type_is_invalid(container_type)) {
26460 return ira->codegen->invalid_inst_gen;
26461 } else if (container_type->id == ZigTypeIdEnum) {
26462 result = container_type->data.enumeration.src_field_count;
26463 } else if (container_type->id == ZigTypeIdStruct) {
26464 result = container_type->data.structure.src_field_count;
26465 } else if (container_type->id == ZigTypeIdUnion) {
26466 result = container_type->data.unionation.src_field_count;
26467 } else if (container_type->id == ZigTypeIdErrorSet) {
26468 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
26469 return ira->codegen->invalid_inst_gen;
26470 }
26471 if (type_is_global_error_set(container_type)) {
26472 ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
26473 return ira->codegen->invalid_inst_gen;
26474 }
26475 result = container_type->data.error_set.err_count;
26476 } else {
26477 ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
26478 return ira->codegen->invalid_inst_gen;
26479 }
26480
26481 return ir_const_unsigned(ira, &instruction->base.base, result);
26482}
26483
26484static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
26485 Error err;
26486 IrInstGen *container_type_value = instruction->container_type->child;
26487 ZigType *container_type = ir_resolve_type(ira, container_type_value);
26488 if (type_is_invalid(container_type))
26489 return ira->codegen->invalid_inst_gen;
26490
26491 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
26492 return ira->codegen->invalid_inst_gen;
26493
26494
26495 uint64_t member_index;
26496 IrInstGen *index_value = instruction->member_index->child;
26497 if (!ir_resolve_usize(ira, index_value, &member_index))
26498 return ira->codegen->invalid_inst_gen;
26499
26500 if (container_type->id == ZigTypeIdStruct) {
26501 if (member_index >= container_type->data.structure.src_field_count) {
26502 ir_add_error(ira, &index_value->base,
26503 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26504 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
26505 return ira->codegen->invalid_inst_gen;
26506 }
26507 TypeStructField *field = container_type->data.structure.fields[member_index];
26508
26509 return ir_const_type(ira, &instruction->base.base, field->type_entry);
26510 } else if (container_type->id == ZigTypeIdUnion) {
26511 if (member_index >= container_type->data.unionation.src_field_count) {
26512 ir_add_error(ira, &index_value->base,
26513 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26514 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
26515 return ira->codegen->invalid_inst_gen;
26516 }
26517 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
26518
26519 return ir_const_type(ira, &instruction->base.base, field->type_entry);
26520 } else {
26521 ir_add_error(ira, &container_type_value->base,
26522 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
26523 return ira->codegen->invalid_inst_gen;
26524 }
26525}
26526
26527static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
26528 Error err;
26529 IrInstGen *container_type_value = instruction->container_type->child;
26530 ZigType *container_type = ir_resolve_type(ira, container_type_value);
26531 if (type_is_invalid(container_type))
26532 return ira->codegen->invalid_inst_gen;
26533
26534 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
26535 return ira->codegen->invalid_inst_gen;
26536
26537 uint64_t member_index;
26538 IrInstGen *index_value = instruction->member_index->child;
26539 if (!ir_resolve_usize(ira, index_value, &member_index))
26540 return ira->codegen->invalid_inst_gen;
26541
26542 if (container_type->id == ZigTypeIdStruct) {
26543 if (member_index >= container_type->data.structure.src_field_count) {
26544 ir_add_error(ira, &index_value->base,
26545 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26546 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
26547 return ira->codegen->invalid_inst_gen;
26548 }
26549 TypeStructField *field = container_type->data.structure.fields[member_index];
26550
26551 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
26552 init_const_str_lit(ira->codegen, result->value, field->name);
26553 return result;
26554 } else if (container_type->id == ZigTypeIdEnum) {
26555 if (member_index >= container_type->data.enumeration.src_field_count) {
26556 ir_add_error(ira, &index_value->base,
26557 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26558 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
26559 return ira->codegen->invalid_inst_gen;
26560 }
26561 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
26562
26563 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
26564 init_const_str_lit(ira->codegen, result->value, field->name);
26565 return result;
26566 } else if (container_type->id == ZigTypeIdUnion) {
26567 if (member_index >= container_type->data.unionation.src_field_count) {
26568 ir_add_error(ira, &index_value->base,
26569 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
26570 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
26571 return ira->codegen->invalid_inst_gen;
26572 }
26573 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
26574
26575 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
26576 init_const_str_lit(ira->codegen, result->value, field->name);
26577 return result;
26578 } else {
26579 ir_add_error(ira, &container_type_value->base,
26580 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
26581 return ira->codegen->invalid_inst_gen;
26582 }
26583}
26584
2658526252static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
2658626253 Error err;
2658726254 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
2954029207 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
2954129208 case IrInstSrcIdBoolToInt:
2954229209 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
29543 case IrInstSrcIdIntType:
29544 return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
2954529210 case IrInstSrcIdVectorType:
2954629211 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
2954729212 case IrInstSrcIdShuffleVector:
......@@ -29556,12 +29221,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2955629221 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
2955729222 case IrInstSrcIdSlice:
2955829223 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
29559 case IrInstSrcIdMemberCount:
29560 return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
29561 case IrInstSrcIdMemberType:
29562 return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
29563 case IrInstSrcIdMemberName:
29564 return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
2956529224 case IrInstSrcIdBreakpoint:
2956629225 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
2956729226 case IrInstSrcIdReturnAddress:
......@@ -29616,8 +29275,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
2961629275 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
2961729276 case IrInstSrcIdHasField:
2961829277 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
29619 case IrInstSrcIdTypeId:
29620 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
2962129278 case IrInstSrcIdSetEvalBranchQuota:
2962229279 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
2962329280 case IrInstSrcIdPtrType:
......@@ -30032,15 +29689,11 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3003229689 case IrInstSrcIdRef:
3003329690 case IrInstSrcIdEmbedFile:
3003429691 case IrInstSrcIdTruncate:
30035 case IrInstSrcIdIntType:
3003629692 case IrInstSrcIdVectorType:
3003729693 case IrInstSrcIdShuffleVector:
3003829694 case IrInstSrcIdSplat:
3003929695 case IrInstSrcIdBoolNot:
3004029696 case IrInstSrcIdSlice:
30041 case IrInstSrcIdMemberCount:
30042 case IrInstSrcIdMemberType:
30043 case IrInstSrcIdMemberName:
3004429697 case IrInstSrcIdAlignOf:
3004529698 case IrInstSrcIdReturnAddress:
3004629699 case IrInstSrcIdFrameAddress:
......@@ -30067,7 +29720,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
3006729720 case IrInstSrcIdTypeInfo:
3006829721 case IrInstSrcIdType:
3006929722 case IrInstSrcIdHasField:
30070 case IrInstSrcIdTypeId:
3007129723 case IrInstSrcIdAlignCast:
3007229724 case IrInstSrcIdImplicitCast:
3007329725 case IrInstSrcIdResolveResult:
src/ir_print.cpp-61
......@@ -179,8 +179,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
179179 return "SrcFloatToInt";
180180 case IrInstSrcIdBoolToInt:
181181 return "SrcBoolToInt";
182 case IrInstSrcIdIntType:
183 return "SrcIntType";
184182 case IrInstSrcIdVectorType:
185183 return "SrcVectorType";
186184 case IrInstSrcIdBoolNot:
......@@ -191,12 +189,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
191189 return "SrcMemcpy";
192190 case IrInstSrcIdSlice:
193191 return "SrcSlice";
194 case IrInstSrcIdMemberCount:
195 return "SrcMemberCount";
196 case IrInstSrcIdMemberType:
197 return "SrcMemberType";
198 case IrInstSrcIdMemberName:
199 return "SrcMemberName";
200192 case IrInstSrcIdBreakpoint:
201193 return "SrcBreakpoint";
202194 case IrInstSrcIdReturnAddress:
......@@ -269,8 +261,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
269261 return "SrcType";
270262 case IrInstSrcIdHasField:
271263 return "SrcHasField";
272 case IrInstSrcIdTypeId:
273 return "SrcTypeId";
274264 case IrInstSrcIdSetEvalBranchQuota:
275265 return "SrcSetEvalBranchQuota";
276266 case IrInstSrcIdPtrType:
......@@ -1660,14 +1650,6 @@ static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instructio
16601650 fprintf(irp->f, ")");
16611651}
16621652
1663static void ir_print_int_type(IrPrintSrc *irp, IrInstSrcIntType *instruction) {
1664 fprintf(irp->f, "@IntType(");
1665 ir_print_other_inst_src(irp, instruction->is_signed);
1666 fprintf(irp->f, ", ");
1667 ir_print_other_inst_src(irp, instruction->bit_count);
1668 fprintf(irp->f, ")");
1669}
1670
16711653static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
16721654 fprintf(irp->f, "@Vector(");
16731655 ir_print_other_inst_src(irp, instruction->len);
......@@ -1784,28 +1766,6 @@ static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
17841766 ir_print_other_inst_gen(irp, instruction->result_loc);
17851767}
17861768
1787static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
1788 fprintf(irp->f, "@memberCount(");
1789 ir_print_other_inst_src(irp, instruction->container);
1790 fprintf(irp->f, ")");
1791}
1792
1793static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
1794 fprintf(irp->f, "@memberType(");
1795 ir_print_other_inst_src(irp, instruction->container_type);
1796 fprintf(irp->f, ", ");
1797 ir_print_other_inst_src(irp, instruction->member_index);
1798 fprintf(irp->f, ")");
1799}
1800
1801static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
1802 fprintf(irp->f, "@memberName(");
1803 ir_print_other_inst_src(irp, instruction->container_type);
1804 fprintf(irp->f, ", ");
1805 ir_print_other_inst_src(irp, instruction->member_index);
1806 fprintf(irp->f, ")");
1807}
1808
18091769static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
18101770 fprintf(irp->f, "@breakpoint()");
18111771}
......@@ -2279,12 +2239,6 @@ static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction)
22792239 fprintf(irp->f, ")");
22802240}
22812241
2282static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
2283 fprintf(irp->f, "@typeId(");
2284 ir_print_other_inst_src(irp, instruction->type_value);
2285 fprintf(irp->f, ")");
2286}
2287
22882242static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
22892243 fprintf(irp->f, "@setEvalBranchQuota(");
22902244 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
27752729 case IrInstSrcIdBoolToInt:
27762730 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
27772731 break;
2778 case IrInstSrcIdIntType:
2779 ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
2780 break;
27812732 case IrInstSrcIdVectorType:
27822733 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
27832734 break;
......@@ -2799,15 +2750,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
27992750 case IrInstSrcIdSlice:
28002751 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
28012752 break;
2802 case IrInstSrcIdMemberCount:
2803 ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
2804 break;
2805 case IrInstSrcIdMemberType:
2806 ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
2807 break;
2808 case IrInstSrcIdMemberName:
2809 ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
2810 break;
28112753 case IrInstSrcIdBreakpoint:
28122754 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
28132755 break;
......@@ -2907,9 +2849,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
29072849 case IrInstSrcIdHasField:
29082850 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
29092851 break;
2910 case IrInstSrcIdTypeId:
2911 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
2912 break;
29132852 case IrInstSrcIdSetEvalBranchQuota:
29142853 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
29152854 break;
test/compile_errors.zig+3-108
......@@ -1657,7 +1657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16571657 \\ var ptr: [*c]u8 = (1 << 64) + 1;
16581658 \\}
16591659 \\export fn b() void {
1660 \\ var x: @IntType(false, 65) = 0x1234;
1660 \\ var x: u65 = 0x1234;
16611661 \\ var ptr: [*c]u8 = x;
16621662 \\}
16631663 , &[_][]const u8{
......@@ -1896,13 +1896,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
18961896
18971897 cases.add("exceeded maximum bit width of integer",
18981898 \\export fn entry1() void {
1899 \\ const T = @IntType(false, 65536);
1899 \\ const T = u65536;
19001900 \\}
19011901 \\export fn entry2() void {
19021902 \\ var x: i65536 = 1;
19031903 \\}
19041904 , &[_][]const u8{
1905 "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
19061905 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
19071906 });
19081907
......@@ -2942,14 +2941,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29422941 "tmp.zig:11:13: error: error.B not a member of error set 'Set2'",
29432942 });
29442943
2945 cases.add("@memberCount of error",
2946 \\comptime {
2947 \\ _ = @memberCount(anyerror);
2948 \\}
2949 , &[_][]const u8{
2950 "tmp.zig:2:9: error: global error set member count not available at comptime",
2951 });
2952
29532944 cases.add("duplicate error value in error set",
29542945 \\const Foo = error {
29552946 \\ Bar,
......@@ -5606,7 +5597,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56065597 });
56075598
56085599 cases.add("globally shadowing a primitive type",
5609 \\const u16 = @intType(false, 8);
5600 \\const u16 = u8;
56105601 \\export fn entry() void {
56115602 \\ const a: u16 = 300;
56125603 \\}
......@@ -5947,93 +5938,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
59475938 "tmp.zig:2:1: error: invalid character: '\\t'",
59485939 });
59495940
5950 cases.add("@ArgType given non function parameter",
5951 \\comptime {
5952 \\ _ = @ArgType(i32, 3);
5953 \\}
5954 , &[_][]const u8{
5955 "tmp.zig:2:18: error: expected function, found 'i32'",
5956 });
5957
5958 cases.add("@ArgType arg index out of bounds",
5959 \\comptime {
5960 \\ _ = @ArgType(@TypeOf(add), 2);
5961 \\}
5962 \\fn add(a: i32, b: i32) i32 { return a + b; }
5963 , &[_][]const u8{
5964 "tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments",
5965 });
5966
5967 cases.add("@memberType on unsupported type",
5968 \\comptime {
5969 \\ _ = @memberType(i32, 0);
5970 \\}
5971 , &[_][]const u8{
5972 "tmp.zig:2:21: error: type 'i32' does not support @memberType",
5973 });
5974
5975 cases.add("@memberType on enum",
5976 \\comptime {
5977 \\ _ = @memberType(Foo, 0);
5978 \\}
5979 \\const Foo = enum {A,};
5980 , &[_][]const u8{
5981 "tmp.zig:2:21: error: type 'Foo' does not support @memberType",
5982 });
5983
5984 cases.add("@memberType struct out of bounds",
5985 \\comptime {
5986 \\ _ = @memberType(Foo, 0);
5987 \\}
5988 \\const Foo = struct {};
5989 , &[_][]const u8{
5990 "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
5991 });
5992
5993 cases.add("@memberType union out of bounds",
5994 \\comptime {
5995 \\ _ = @memberType(Foo, 1);
5996 \\}
5997 \\const Foo = union {A: void,};
5998 , &[_][]const u8{
5999 "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
6000 });
6001
6002 cases.add("@memberName on unsupported type",
6003 \\comptime {
6004 \\ _ = @memberName(i32, 0);
6005 \\}
6006 , &[_][]const u8{
6007 "tmp.zig:2:21: error: type 'i32' does not support @memberName",
6008 });
6009
6010 cases.add("@memberName struct out of bounds",
6011 \\comptime {
6012 \\ _ = @memberName(Foo, 0);
6013 \\}
6014 \\const Foo = struct {};
6015 , &[_][]const u8{
6016 "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
6017 });
6018
6019 cases.add("@memberName enum out of bounds",
6020 \\comptime {
6021 \\ _ = @memberName(Foo, 1);
6022 \\}
6023 \\const Foo = enum {A,};
6024 , &[_][]const u8{
6025 "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
6026 });
6027
6028 cases.add("@memberName union out of bounds",
6029 \\comptime {
6030 \\ _ = @memberName(Foo, 1);
6031 \\}
6032 \\const Foo = union {A:i32,};
6033 , &[_][]const u8{
6034 "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
6035 });
6036
60375941 cases.add("calling var args extern function, passing array instead of pointer",
60385942 \\export fn entry() void {
60395943 \\ foo("hello".*,);
......@@ -6457,15 +6361,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
64576361 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",
64586362 });
64596363
6460 cases.add("getting @ArgType of generic function",
6461 \\fn generic(a: var) void {}
6462 \\comptime {
6463 \\ _ = @ArgType(@TypeOf(generic), 0);
6464 \\}
6465 , &[_][]const u8{
6466 "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var) var' is generic",
6467 });
6468
64696364 cases.add("unsupported modifier at start of asm output constraint",
64706365 \\export fn foo() void {
64716366 \\ var bar: u32 = 3;
test/stage1/behavior/bit_shifting.zig+2-2
......@@ -2,9 +2,9 @@ const std = @import("std");
22const expect = std.testing.expect;
33
44fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
5 expect(Key == @IntType(false, Key.bit_count));
5 expect(Key == std.meta.IntType(false, Key.bit_count));
66 expect(Key.bit_count >= mask_bit_count);
7 const ShardKey = @IntType(false, mask_bit_count);
7 const ShardKey = std.meta.IntType(false, mask_bit_count);
88 const shift_amount = Key.bit_count - ShardKey.bit_count;
99 return struct {
1010 const Self = @This();
test/stage1/behavior/bugs/3742.zig+1-1
......@@ -17,7 +17,7 @@ pub const GET = struct {
1717};
1818
1919pub fn isCommand(comptime T: type) bool {
20 const tid = @typeId(T);
20 const tid = @typeInfo(T);
2121 return (tid == .Struct or tid == .Enum or tid == .Union) and
2222 @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
2323}
test/stage1/behavior/enum.zig+2-2
......@@ -96,8 +96,8 @@ test "enum type" {
9696 const bar = Bar.B;
9797
9898 expect(bar == Bar.B);
99 expect(@memberCount(Foo) == 3);
100 expect(@memberCount(Bar) == 4);
99 expect(@typeInfo(Foo).Union.fields.len == 3);
100 expect(@typeInfo(Bar).Enum.fields.len == 4);
101101 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
102102 expect(@sizeOf(Bar) == 1);
103103}
test/stage1/behavior/error.zig+3-4
......@@ -3,7 +3,6 @@ const expect = std.testing.expect;
33const expectError = std.testing.expectError;
44const expectEqual = std.testing.expectEqual;
55const mem = std.mem;
6const builtin = @import("builtin");
76
87pub fn foo() anyerror!i32 {
98 const x = try bar();
......@@ -84,8 +83,8 @@ test "error union type " {
8483fn testErrorUnionType() void {
8584 const x: anyerror!i32 = 1234;
8685 if (x) |value| expect(value == 1234) else |_| unreachable;
87 expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion);
88 expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);
86 expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
87 expect(@typeInfo(@TypeOf(x).ErrorSet) == .ErrorSet);
8988 expect(@TypeOf(x).ErrorSet == anyerror);
9089}
9190
......@@ -100,7 +99,7 @@ const MyErrSet = error{
10099};
101100
102101fn testErrorSetType() void {
103 expect(@memberCount(MyErrSet) == 2);
102 expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
104103
105104 const a: MyErrSet!i32 = 5678;
106105 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
test/stage1/behavior/eval.zig+2-2
......@@ -654,8 +654,8 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
654654 expect(b == 2);
655655}
656656
657test "@tagName of @typeId" {
658 const str = @tagName(@typeId(u8));
657test "@tagName of @typeInfo" {
658 const str = @tagName(@typeInfo(u8));
659659 expect(std.mem.eql(u8, str, "Int"));
660660}
661661
test/stage1/behavior/math.zig+1-1
......@@ -270,7 +270,7 @@ fn testBinaryNot(x: u16) void {
270270}
271271
272272test "small int addition" {
273 var x: @IntType(false, 2) = 0;
273 var x: u2 = 0;
274274 expect(x == 0);
275275
276276 x += 1;
test/stage1/behavior/misc.zig-64
......@@ -24,35 +24,6 @@ test "call disabled extern fn" {
2424 disabledExternFn();
2525}
2626
27test "@IntType builtin" {
28 expect(@IntType(true, 8) == i8);
29 expect(@IntType(true, 16) == i16);
30 expect(@IntType(true, 32) == i32);
31 expect(@IntType(true, 64) == i64);
32
33 expect(@IntType(false, 8) == u8);
34 expect(@IntType(false, 16) == u16);
35 expect(@IntType(false, 32) == u32);
36 expect(@IntType(false, 64) == u64);
37
38 expect(i8.bit_count == 8);
39 expect(i16.bit_count == 16);
40 expect(i32.bit_count == 32);
41 expect(i64.bit_count == 64);
42
43 expect(i8.is_signed);
44 expect(i16.is_signed);
45 expect(i32.is_signed);
46 expect(i64.is_signed);
47 expect(isize.is_signed);
48
49 expect(!u8.is_signed);
50 expect(!u16.is_signed);
51 expect(!u32.is_signed);
52 expect(!u64.is_signed);
53 expect(!usize.is_signed);
54}
55
5627test "floating point primitive bit counts" {
5728 expect(f16.bit_count == 16);
5829 expect(f32.bit_count == 32);
......@@ -407,7 +378,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) void {
407378 expect(ptr2[1] == 2.0);
408379}
409380
410const Tid = builtin.TypeId;
411381const AStruct = struct {
412382 x: i32,
413383};
......@@ -424,40 +394,6 @@ const AUnion = union {
424394 Two: void,
425395};
426396
427test "@typeId" {
428 comptime {
429 expect(@typeId(type) == Tid.Type);
430 expect(@typeId(void) == Tid.Void);
431 expect(@typeId(bool) == Tid.Bool);
432 expect(@typeId(noreturn) == Tid.NoReturn);
433 expect(@typeId(i8) == Tid.Int);
434 expect(@typeId(u8) == Tid.Int);
435 expect(@typeId(i64) == Tid.Int);
436 expect(@typeId(u64) == Tid.Int);
437 expect(@typeId(f32) == Tid.Float);
438 expect(@typeId(f64) == Tid.Float);
439 expect(@typeId(*f32) == Tid.Pointer);
440 expect(@typeId([2]u8) == Tid.Array);
441 expect(@typeId(AStruct) == Tid.Struct);
442 expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt);
443 expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat);
444 expect(@typeId(@TypeOf(undefined)) == Tid.Undefined);
445 expect(@typeId(@TypeOf(null)) == Tid.Null);
446 expect(@typeId(?i32) == Tid.Optional);
447 expect(@typeId(anyerror!i32) == Tid.ErrorUnion);
448 expect(@typeId(anyerror) == Tid.ErrorSet);
449 expect(@typeId(AnEnum) == Tid.Enum);
450 expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum);
451 expect(@typeId(AUnionEnum) == Tid.Union);
452 expect(@typeId(AUnion) == Tid.Union);
453 expect(@typeId(fn () void) == Tid.Fn);
454 expect(@typeId(@TypeOf(builtin)) == Tid.Type);
455 // TODO bound fn
456 // TODO arg tuple
457 // TODO opaque
458 }
459}
460
461397test "@typeName" {
462398 const Struct = struct {};
463399 const Union = union {
test/stage1/behavior/reflection.zig+3-33
......@@ -16,9 +16,9 @@ test "reflection: function return type, var args, and param types" {
1616 expect(@TypeOf(dummy).ReturnType == i32);
1717 expect(!@TypeOf(dummy).is_var_args);
1818 expect(@TypeOf(dummy).arg_count == 3);
19 expect(@ArgType(@TypeOf(dummy), 0) == bool);
20 expect(@ArgType(@TypeOf(dummy), 1) == i32);
21 expect(@ArgType(@TypeOf(dummy), 2) == f32);
19 expect(@typeInfo(@TypeOf(dummy)).Fn.args[0].arg_type.? == bool);
20 expect(@typeInfo(@TypeOf(dummy)).Fn.args[1].arg_type.? == i32);
21 expect(@typeInfo(@TypeOf(dummy)).Fn.args[2].arg_type.? == f32);
2222 }
2323}
2424
......@@ -26,36 +26,6 @@ fn dummy(a: bool, b: i32, c: f32) i32 {
2626 return 1234;
2727}
2828
29test "reflection: struct member types and names" {
30 comptime {
31 expect(@memberCount(Foo) == 3);
32
33 expect(@memberType(Foo, 0) == i32);
34 expect(@memberType(Foo, 1) == bool);
35 expect(@memberType(Foo, 2) == void);
36
37 expect(mem.eql(u8, @memberName(Foo, 0), "one"));
38 expect(mem.eql(u8, @memberName(Foo, 1), "two"));
39 expect(mem.eql(u8, @memberName(Foo, 2), "three"));
40 }
41}
42
43test "reflection: enum member types and names" {
44 comptime {
45 expect(@memberCount(Bar) == 4);
46
47 expect(@memberType(Bar, 0) == void);
48 expect(@memberType(Bar, 1) == i32);
49 expect(@memberType(Bar, 2) == bool);
50 expect(@memberType(Bar, 3) == f64);
51
52 expect(mem.eql(u8, @memberName(Bar, 0), "One"));
53 expect(mem.eql(u8, @memberName(Bar, 1), "Two"));
54 expect(mem.eql(u8, @memberName(Bar, 2), "Three"));
55 expect(mem.eql(u8, @memberName(Bar, 3), "Four"));
56 }
57}
58
5929test "reflection: @field" {
6030 var f = Foo{
6131 .one = 42,
test/stage1/behavior/union.zig+1-1
......@@ -531,7 +531,7 @@ var glbl: Foo1 = undefined;
531531
532532test "global union with single field is correctly initialized" {
533533 glbl = Foo1{
534 .f = @memberType(Foo1, 0){ .x = 123 },
534 .f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
535535 };
536536 expect(glbl.f.x == 123);
537537}
test/translate_c.zig+4-4
......@@ -1354,7 +1354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13541354 cases.add("macro pointer cast",
13551355 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
13561356 , &[_][]const u8{
1357 \\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);
1357 \\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);
13581358 });
13591359
13601360 cases.add("basic macro function",
......@@ -2538,11 +2538,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
25382538 \\#define FOO(bar) baz((void *)(baz))
25392539 \\#define BAR (void*) a
25402540 , &[_][]const u8{
2541 \\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))) {
2542 \\ 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));
2541 \\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))) {
2542 \\ 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));
25432543 \\}
25442544 ,
2545 \\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);
2545 \\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);
25462546 });
25472547
25482548 cases.add("macro conditional operator",