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 {...@@ -550,7 +550,7 @@ pub fn main() void {
550 {#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an550 {#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an
551 integer type is {#syntax#}65535{#endsyntax#}.551 integer type is {#syntax#}65535{#endsyntax#}.
552 </p>552 </p>
553 {#see_also|Integers|Floats|void|Errors|@IntType#}553 {#see_also|Integers|Floats|void|Errors|@Type#}
554 {#header_close#}554 {#header_close#}
555 {#header_open|Primitive Values#}555 {#header_open|Primitive Values#}
556 <div class="table-wrapper">556 <div class="table-wrapper">
...@@ -2810,14 +2810,10 @@ test "@TagType" {...@@ -2810,14 +2810,10 @@ test "@TagType" {
2810 assert(@TagType(Small) == u2);2810 assert(@TagType(Small) == u2);
2811}2811}
28122812
2813// @memberCount tells how many fields an enum has:2813// @typeInfo tells us the field count and the fields names:
2814test "@memberCount" {2814test "@typeInfo" {
2815 assert(@memberCount(Small) == 4);2815 assert(@typeInfo(Small).Enum.fields.len == 4);
2816}2816 assert(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "Two"));
2817
2818// @memberName tells the name of a field in an enum:
2819test "@memberName" {
2820 assert(mem.eql(u8, @memberName(Small, 1), "Two"));
2821}2817}
28222818
2823// @tagName gives a []const u8 representation of an enum value:2819// @tagName gives a []const u8 representation of an enum value:
...@@ -2825,7 +2821,7 @@ test "@tagName" {...@@ -2825,7 +2821,7 @@ test "@tagName" {
2825 assert(mem.eql(u8, @tagName(Small.Three), "Three"));2821 assert(mem.eql(u8, @tagName(Small.Three), "Three"));
2826}2822}
2827 {#code_end#}2823 {#code_end#}
2828 {#see_also|@memberName|@memberCount|@tagName|@sizeOf#}2824 {#see_also|@typeInfo|@tagName|@sizeOf#}
28292825
2830 {#header_open|extern enum#}2826 {#header_open|extern enum#}
2831 <p>2827 <p>
...@@ -6671,18 +6667,6 @@ comptime {...@@ -6671,18 +6667,6 @@ comptime {
6671 </p>6667 </p>
6672 {#see_also|Alignment#}6668 {#see_also|Alignment#}
6673 {#header_close#}6669 {#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
6687 {#header_open|@as#}6671 {#header_open|@as#}
6688 <pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre>6672 <pre>{#syntax#}@as(comptime T: type, expression) T{#endsyntax#}</pre>
...@@ -6816,7 +6800,7 @@ async fn func(y: *i32) void {...@@ -6816,7 +6800,7 @@ async fn func(y: *i32) void {
6816 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.6800 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
6817 </p>6801 </p>
6818 <p>6802 <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.
6820 </p>6804 </p>
6821 <p>6805 <p>
6822 Can be used for these things for example:6806 Can be used for these things for example:
...@@ -7269,7 +7253,7 @@ test "main" {...@@ -7269,7 +7253,7 @@ test "main" {
7269 <p>7253 <p>
7270 Floored division. Rounds toward negative infinity. For unsigned integers it is7254 Floored division. Rounds toward negative infinity. For unsigned integers it is
7271 the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and7255 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#}.
7273 </p>7257 </p>
7274 <ul>7258 <ul>
7275 <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>7259 <li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
...@@ -7283,7 +7267,7 @@ test "main" {...@@ -7283,7 +7267,7 @@ test "main" {
7283 <p>7267 <p>
7284 Truncated division. Rounds toward zero. For unsigned integers it is7268 Truncated division. Rounds toward zero. For unsigned integers it is
7285 the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and7269 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#}.
7287 </p>7271 </p>
7288 <ul>7272 <ul>
7289 <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>7273 <li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
...@@ -7341,7 +7325,7 @@ test "main" {...@@ -7341,7 +7325,7 @@ test "main" {
7341 {#header_close#}7325 {#header_close#}
73427326
7343 {#header_open|@errorToInt#}7327 {#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>
7345 <p>7329 <p>
7346 Supports the following types:7330 Supports the following types:
7347 </p>7331 </p>
...@@ -7635,7 +7619,7 @@ test "@hasDecl" {...@@ -7635,7 +7619,7 @@ test "@hasDecl" {
7635 {#header_close#}7619 {#header_close#}
76367620
7637 {#header_open|@intToError#}7621 {#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>
7639 <p>7623 <p>
7640 Converts from the integer representation of an error into {#link|The Global Error Set#} type.7624 Converts from the integer representation of an error into {#link|The Global Error Set#} type.
7641 </p>7625 </p>
...@@ -7668,44 +7652,6 @@ test "@hasDecl" {...@@ -7668,44 +7652,6 @@ test "@hasDecl" {
7668 </p>7652 </p>
7669 {#header_close#}7653 {#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
7709 {#header_open|@memcpy#}7655 {#header_open|@memcpy#}
7710 <pre>{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize){#endsyntax#}</pre>7656 <pre>{#syntax#}@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize){#endsyntax#}</pre>
7711 <p>7657 <p>
...@@ -8401,43 +8347,6 @@ test "integer truncation" {...@@ -8401,43 +8347,6 @@ test "integer truncation" {
8401 <li>{#link|struct#}</li>8347 <li>{#link|struct#}</li>
8402 </ul>8348 </ul>
8403 {#header_close#}8349 {#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
8441 {#header_open|@typeInfo#}8350 {#header_open|@typeInfo#}
8442 <pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>8351 <pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
8443 <p>8352 <p>
lib/std/build.zig+11-11
...@@ -609,13 +609,13 @@ pub const Builder = struct {...@@ -609,13 +609,13 @@ pub const Builder = struct {
609 }609 }
610610
611 fn typeToEnum(comptime T: type) TypeId {611 fn typeToEnum(comptime T: type) TypeId {
612 return switch (@typeId(T)) {612 return switch (@typeInfo(T)) {
613 builtin.TypeId.Int => TypeId.Int,613 .Int => .Int,
614 builtin.TypeId.Float => TypeId.Float,614 .Float => .Float,
615 builtin.TypeId.Bool => TypeId.Bool,615 .Bool => .Bool,
616 else => switch (T) {616 else => switch (T) {
617 []const u8 => TypeId.String,617 []const u8 => .String,
618 []const []const u8 => TypeId.List,618 []const []const u8 => .List,
619 else => @compileError("Unsupported type: " ++ @typeName(T)),619 else => @compileError("Unsupported type: " ++ @typeName(T)),
620 },620 },
621 };621 };
...@@ -627,11 +627,11 @@ pub const Builder = struct {...@@ -627,11 +627,11 @@ pub const Builder = struct {
627627
628 pub fn typeIdName(id: TypeId) []const u8 {628 pub fn typeIdName(id: TypeId) []const u8 {
629 return switch (id) {629 return switch (id) {
630 TypeId.Bool => "bool",630 .Bool => "bool",
631 TypeId.Int => "int",631 .Int => "int",
632 TypeId.Float => "float",632 .Float => "float",
633 TypeId.String => "string",633 .String => "string",
634 TypeId.List => "list",634 .List => "list",
635 };635 };
636 }636 }
637637
lib/std/child_process.zig+1-1
...@@ -851,7 +851,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {...@@ -851,7 +851,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
851 os.exit(1);851 os.exit(1);
852}852}
853853
854const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);854const ErrInt = std.meta.IntType(false, @sizeOf(anyerror) * 8);
855855
856fn writeIntFd(fd: i32, value: ErrInt) !void {856fn writeIntFd(fd: i32, value: ErrInt) !void {
857 const file = File{857 const file = File{
lib/std/debug/leb128.zig+6-6
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
2const testing = std.testing;2const testing = std.testing;
33
4pub fn readULEB128(comptime T: type, in_stream: var) !T {4pub 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
7 var result: T = 0;7 var result: T = 0;
8 var shift: usize = 0;8 var shift: usize = 0;
...@@ -27,7 +27,7 @@ pub fn readULEB128(comptime T: type, in_stream: var) !T {...@@ -27,7 +27,7 @@ pub fn readULEB128(comptime T: type, in_stream: var) !T {
27}27}
2828
29pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {29pub 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
32 var result: T = 0;32 var result: T = 0;
33 var shift: usize = 0;33 var shift: usize = 0;
...@@ -55,8 +55,8 @@ pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {...@@ -55,8 +55,8 @@ pub fn readULEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
55}55}
5656
57pub fn readILEB128(comptime T: type, in_stream: var) !T {57pub fn readILEB128(comptime T: type, in_stream: var) !T {
58 const UT = @IntType(false, T.bit_count);58 const UT = std.meta.IntType(false, T.bit_count);
59 const ShiftT = @IntType(false, std.math.log2(T.bit_count));59 const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
6060
61 var result: UT = 0;61 var result: UT = 0;
62 var shift: usize = 0;62 var shift: usize = 0;
...@@ -87,8 +87,8 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {...@@ -87,8 +87,8 @@ pub fn readILEB128(comptime T: type, in_stream: var) !T {
87}87}
8888
89pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {89pub fn readILEB128Mem(comptime T: type, ptr: *[*]const u8) !T {
90 const UT = @IntType(false, T.bit_count);90 const UT = std.meta.IntType(false, T.bit_count);
91 const ShiftT = @IntType(false, std.math.log2(T.bit_count));91 const ShiftT = std.meta.IntType(false, std.math.log2(T.bit_count));
9292
93 var result: UT = 0;93 var result: UT = 0;
94 var shift: usize = 0;94 var shift: usize = 0;
lib/std/fmt.zig+11-10
...@@ -82,7 +82,7 @@ pub fn format(...@@ -82,7 +82,7 @@ pub fn format(
82 comptime fmt: []const u8,82 comptime fmt: []const u8,
83 args: var,83 args: var,
84) Errors!void {84) Errors!void {
85 const ArgSetType = @IntType(false, 32);85 const ArgSetType = u32;
86 if (@typeInfo(@TypeOf(args)) != .Struct) {86 if (@typeInfo(@TypeOf(args)) != .Struct) {
87 @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args)));87 @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args)));
88 }88 }
...@@ -405,7 +405,7 @@ pub fn formatType(...@@ -405,7 +405,7 @@ pub fn formatType(
405 try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});405 try format(context, Errors, output, "@{x}", .{@ptrToInt(&value)});
406 }406 }
407 },407 },
408 .Struct => {408 .Struct => |StructT| {
409 if (comptime std.meta.trait.hasFn("format")(T)) {409 if (comptime std.meta.trait.hasFn("format")(T)) {
410 return value.format(fmt, options, context, Errors, output);410 return value.format(fmt, options, context, Errors, output);
411 }411 }
...@@ -416,27 +416,28 @@ pub fn formatType(...@@ -416,27 +416,28 @@ pub fn formatType(
416 }416 }
417 comptime var field_i = 0;417 comptime var field_i = 0;
418 try output(context, "{");418 try output(context, "{");
419 inline while (field_i < @memberCount(T)) : (field_i += 1) {419 inline for (StructT.fields) |f| {
420 if (field_i == 0) {420 if (field_i == 0) {
421 try output(context, " .");421 try output(context, " .");
422 } else {422 } else {
423 try output(context, ", .");423 try output(context, ", .");
424 }424 }
425 try output(context, @memberName(T, field_i));425 try output(context, f.name);
426 try output(context, " = ");426 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;
428 }429 }
429 try output(context, " }");430 try output(context, " }");
430 },431 },
431 .Pointer => |ptr_info| switch (ptr_info.size) {432 .Pointer => |ptr_info| switch (ptr_info.size) {
432 .One => switch (@typeInfo(ptr_info.child)) {433 .One => switch (@typeInfo(ptr_info.child)) {
433 builtin.TypeId.Array => |info| {434 .Array => |info| {
434 if (info.child == u8) {435 if (info.child == u8) {
435 return formatText(value, fmt, options, context, Errors, output);436 return formatText(value, fmt, options, context, Errors, output);
436 }437 }
437 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });438 return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
438 },439 },
439 builtin.TypeId.Enum, builtin.TypeId.Union, builtin.TypeId.Struct => {440 .Enum, .Union, .Struct => {
440 return formatType(value.*, fmt, options, context, Errors, output, max_depth);441 return formatType(value.*, fmt, options, context, Errors, output, max_depth);
441 },442 },
442 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),443 else => return format(context, Errors, output, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
...@@ -509,7 +510,7 @@ fn formatValue(...@@ -509,7 +510,7 @@ fn formatValue(
509 }510 }
510511
511 const T = @TypeOf(value);512 const T = @TypeOf(value);
512 switch (@typeId(T)) {513 switch (@typeInfo(T)) {
513 .Float => return formatFloatValue(value, fmt, options, context, Errors, output),514 .Float => return formatFloatValue(value, fmt, options, context, Errors, output),
514 .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),515 .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
515 .Bool => return output(context, if (value) "true" else "false"),516 .Bool => return output(context, if (value) "true" else "false"),
...@@ -943,7 +944,7 @@ fn formatIntSigned(...@@ -943,7 +944,7 @@ fn formatIntSigned(
943 .fill = options.fill,944 .fill = options.fill,
944 };945 };
945946
946 const uint = @IntType(false, @TypeOf(value).bit_count);947 const uint = std.meta.IntType(false, @TypeOf(value).bit_count);
947 if (value < 0) {948 if (value < 0) {
948 const minus_sign: u8 = '-';949 const minus_sign: u8 = '-';
949 try output(context, @as(*const [1]u8, &minus_sign)[0..]);950 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
...@@ -971,7 +972,7 @@ fn formatIntUnsigned(...@@ -971,7 +972,7 @@ fn formatIntUnsigned(
971 assert(base >= 2);972 assert(base >= 2);
972 var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;973 var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
973 const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count);974 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);
975 var a: MinInt = value;976 var a: MinInt = value;
976 var index: usize = buf.len;977 var index: usize = buf.len;
977978
lib/std/fmt/parse_float.zig+1-1
...@@ -393,7 +393,7 @@ test "fmt.parseFloat" {...@@ -393,7 +393,7 @@ test "fmt.parseFloat" {
393 const epsilon = 1e-7;393 const epsilon = 1e-7;
394394
395 inline for ([_]type{ f16, f32, f64, f128 }) |T| {395 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
398 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));398 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
399 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));399 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 {...@@ -93,7 +93,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
93 // TODO Check if the situation is better after #561 is resolved.93 // TODO Check if the situation is better after #561 is resolved.
94 .Int => @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)}),94 .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
98 .Bool => hash(hasher, @boolToInt(key), strat),98 .Bool => hash(hasher, @boolToInt(key), strat),
99 .Enum => hash(hasher, @enumToInt(key), strat),99 .Enum => hash(hasher, @enumToInt(key), strat),
lib/std/hash/wyhash.zig+1-1
...@@ -10,7 +10,7 @@ const primes = [_]u64{...@@ -10,7 +10,7 @@ const primes = [_]u64{
10};10};
1111
12fn read_bytes(comptime bytes: u8, data: []const u8) u64 {12fn 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);
14 return mem.readIntSliceLittle(T, data[0..bytes]);14 return mem.readIntSliceLittle(T, data[0..bytes]);
15}15}
1616
lib/std/heap.zig+1-1
...@@ -1015,7 +1015,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo...@@ -1015,7 +1015,7 @@ fn testAllocatorLargeAlignment(allocator: *mem.Allocator) mem.Allocator.Error!vo
1015 // very near usize?1015 // very near usize?
1016 if (mem.page_size << 2 > maxInt(usize)) return;1016 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));
1019 const large_align = @as(u29, mem.page_size << 2);1019 const large_align = @as(u29, mem.page_size << 2);
10201020
1021 var align_mask: usize = undefined;1021 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 {...@@ -337,7 +337,7 @@ pub fn BitInStream(endian: builtin.Endian, comptime Error: type) type {
337 assert(u_bit_count >= bits);337 assert(u_bit_count >= bits);
338 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;338 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
339 };339 };
340 const Buf = @IntType(false, buf_bit_count);340 const Buf = std.meta.IntType(false, buf_bit_count);
341 const BufShift = math.Log2Int(Buf);341 const BufShift = math.Log2Int(Buf);
342342
343 out_bits.* = @as(usize, 0);343 out_bits.* = @as(usize, 0);
...@@ -659,7 +659,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {...@@ -659,7 +659,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
659 assert(u_bit_count >= bits);659 assert(u_bit_count >= bits);
660 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;660 break :bc if (u_bit_count <= u8_bit_count) u8_bit_count else u_bit_count;
661 };661 };
662 const Buf = @IntType(false, buf_bit_count);662 const Buf = std.meta.IntType(false, buf_bit_count);
663 const BufShift = math.Log2Int(Buf);663 const BufShift = math.Log2Int(Buf);
664664
665 const buf_value = @intCast(Buf, value);665 const buf_value = @intCast(Buf, value);
...@@ -831,12 +831,12 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -831,12 +831,12 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
831831
832 //@BUG: inferred error issue. See: #1386832 //@BUG: inferred error issue. See: #1386
833 fn deserializeInt(self: *Self, comptime T: type) (Error || error{EndOfStream})!T {833 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
836 const u8_bit_count = 8;836 const u8_bit_count = 8;
837 const t_bit_count = comptime meta.bitCount(T);837 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);
840 const Log2U = math.Log2Int(U);840 const Log2U = math.Log2Int(U);
841 const int_size = (U.bit_count + 7) / 8;841 const int_size = (U.bit_count + 7) / 8;
842842
...@@ -851,7 +851,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -851,7 +851,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
851851
852 if (int_size == 1) {852 if (int_size == 1) {
853 if (t_bit_count == 8) return @bitCast(T, buffer[0]);853 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);
855 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));855 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
856 }856 }
857857
...@@ -880,9 +880,9 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -880,9 +880,9 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
880 /// Deserializes data into the type pointed to by `ptr`880 /// Deserializes data into the type pointed to by `ptr`
881 pub fn deserializeInto(self: *Self, ptr: var) !void {881 pub fn deserializeInto(self: *Self, ptr: var) !void {
882 const T = @TypeOf(ptr);882 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)) {
886 for (ptr) |*v|886 for (ptr) |*v|
887 try self.deserializeInto(v);887 try self.deserializeInto(v);
888 return;888 return;
...@@ -891,7 +891,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -891,7 +891,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
891 comptime assert(trait.isSingleItemPtr(T));891 comptime assert(trait.isSingleItemPtr(T));
892892
893 const C = comptime meta.Child(T);893 const C = comptime meta.Child(T);
894 const child_type_id = @typeId(C);894 const child_type_id = @typeInfo(C);
895895
896 //custom deserializer: fn(self: *Self, deserializer: var) !void896 //custom deserializer: fn(self: *Self, deserializer: var) !void
897 if (comptime trait.hasFn("deserialize")(C)) return C.deserialize(ptr, self);897 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,...@@ -902,10 +902,10 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
902 }902 }
903903
904 switch (child_type_id) {904 switch (child_type_id) {
905 builtin.TypeId.Void => return,905 .Void => return,
906 builtin.TypeId.Bool => ptr.* = (try self.deserializeInt(u1)) > 0,906 .Bool => ptr.* = (try self.deserializeInt(u1)) > 0,
907 builtin.TypeId.Float, builtin.TypeId.Int => ptr.* = try self.deserializeInt(C),907 .Float, .Int => ptr.* = try self.deserializeInt(C),
908 builtin.TypeId.Struct => {908 .Struct => {
909 const info = @typeInfo(C).Struct;909 const info = @typeInfo(C).Struct;
910910
911 inline for (info.fields) |*field_info| {911 inline for (info.fields) |*field_info| {
...@@ -915,7 +915,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -915,7 +915,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
915 if (FieldType == void or FieldType == u0) continue;915 if (FieldType == void or FieldType == u0) continue;
916916
917 //it doesn't make any sense to read pointers917 //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)) {
919 @compileError("Will not " ++ "read field " ++ name ++ " of struct " ++919 @compileError("Will not " ++ "read field " ++ name ++ " of struct " ++
920 @typeName(C) ++ " because it " ++ "is of pointer-type " ++920 @typeName(C) ++ " because it " ++ "is of pointer-type " ++
921 @typeName(FieldType) ++ ".");921 @typeName(FieldType) ++ ".");
...@@ -924,7 +924,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -924,7 +924,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
924 try self.deserializeInto(&@field(ptr, name));924 try self.deserializeInto(&@field(ptr, name));
925 }925 }
926 },926 },
927 builtin.TypeId.Union => {927 .Union => {
928 const info = @typeInfo(C).Union;928 const info = @typeInfo(C).Union;
929 if (info.tag_type) |TagType| {929 if (info.tag_type) |TagType| {
930 //we avoid duplicate iteration over the enum tags930 //we avoid duplicate iteration over the enum tags
...@@ -948,7 +948,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -948,7 +948,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
948 @compileError("Cannot meaningfully deserialize " ++ @typeName(C) ++948 @compileError("Cannot meaningfully deserialize " ++ @typeName(C) ++
949 " because it is an untagged union. Use a custom deserialize().");949 " because it is an untagged union. Use a custom deserialize().");
950 },950 },
951 builtin.TypeId.Optional => {951 .Optional => {
952 const OC = comptime meta.Child(C);952 const OC = comptime meta.Child(C);
953 const exists = (try self.deserializeInt(u1)) > 0;953 const exists = (try self.deserializeInt(u1)) > 0;
954 if (!exists) {954 if (!exists) {
...@@ -960,7 +960,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -960,7 +960,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
960 const val_ptr = &ptr.*.?;960 const val_ptr = &ptr.*.?;
961 try self.deserializeInto(val_ptr);961 try self.deserializeInto(val_ptr);
962 },962 },
963 builtin.TypeId.Enum => {963 .Enum => {
964 var value = try self.deserializeInt(@TagType(C));964 var value = try self.deserializeInt(@TagType(C));
965 ptr.* = try meta.intToEnum(C, value);965 ptr.* = try meta.intToEnum(C, value);
966 },966 },
...@@ -1009,12 +1009,12 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1009,12 +1009,12 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
10091009
1010 fn serializeInt(self: *Self, value: var) Error!void {1010 fn serializeInt(self: *Self, value: var) Error!void {
1011 const T = @TypeOf(value);1011 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
1014 const t_bit_count = comptime meta.bitCount(T);1014 const t_bit_count = comptime meta.bitCount(T);
1015 const u8_bit_count = comptime meta.bitCount(u8);1015 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);
1018 const Log2U = math.Log2Int(U);1018 const Log2U = math.Log2Int(U);
1019 const int_size = (U.bit_count + 7) / 8;1019 const int_size = (U.bit_count + 7) / 8;
10201020
...@@ -1058,11 +1058,11 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1058,11 +1058,11 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1058 return;1058 return;
1059 }1059 }
10601060
1061 switch (@typeId(T)) {1061 switch (@typeInfo(T)) {
1062 builtin.TypeId.Void => return,1062 .Void => return,
1063 builtin.TypeId.Bool => try self.serializeInt(@as(u1, @boolToInt(value))),1063 .Bool => try self.serializeInt(@as(u1, @boolToInt(value))),
1064 builtin.TypeId.Float, builtin.TypeId.Int => try self.serializeInt(value),1064 .Float, .Int => try self.serializeInt(value),
1065 builtin.TypeId.Struct => {1065 .Struct => {
1066 const info = @typeInfo(T);1066 const info = @typeInfo(T);
10671067
1068 inline for (info.Struct.fields) |*field_info| {1068 inline for (info.Struct.fields) |*field_info| {
...@@ -1072,7 +1072,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1072,7 +1072,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1072 if (FieldType == void or FieldType == u0) continue;1072 if (FieldType == void or FieldType == u0) continue;
10731073
1074 //It doesn't make sense to write pointers1074 //It doesn't make sense to write pointers
1075 if (comptime trait.is(builtin.TypeId.Pointer)(FieldType)) {1075 if (comptime trait.is(.Pointer)(FieldType)) {
1076 @compileError("Will not " ++ "serialize field " ++ name ++1076 @compileError("Will not " ++ "serialize field " ++ name ++
1077 " of struct " ++ @typeName(T) ++ " because it " ++1077 " of struct " ++ @typeName(T) ++ " because it " ++
1078 "is of pointer-type " ++ @typeName(FieldType) ++ ".");1078 "is of pointer-type " ++ @typeName(FieldType) ++ ".");
...@@ -1080,7 +1080,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1080,7 +1080,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1080 try self.serialize(@field(value, name));1080 try self.serialize(@field(value, name));
1081 }1081 }
1082 },1082 },
1083 builtin.TypeId.Union => {1083 .Union => {
1084 const info = @typeInfo(T).Union;1084 const info = @typeInfo(T).Union;
1085 if (info.tag_type) |TagType| {1085 if (info.tag_type) |TagType| {
1086 const active_tag = meta.activeTag(value);1086 const active_tag = meta.activeTag(value);
...@@ -1101,7 +1101,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1101,7 +1101,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1101 @compileError("Cannot meaningfully serialize " ++ @typeName(T) ++1101 @compileError("Cannot meaningfully serialize " ++ @typeName(T) ++
1102 " because it is an untagged union. Use a custom serialize().");1102 " because it is an untagged union. Use a custom serialize().");
1103 },1103 },
1104 builtin.TypeId.Optional => {1104 .Optional => {
1105 if (value == null) {1105 if (value == null) {
1106 try self.serializeInt(@as(u1, @boolToInt(false)));1106 try self.serializeInt(@as(u1, @boolToInt(false)));
1107 return;1107 return;
...@@ -1112,10 +1112,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1112,10 +1112,10 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1112 const val_ptr = &value.?;1112 const val_ptr = &value.?;
1113 try self.serialize(val_ptr.*);1113 try self.serialize(val_ptr.*);
1114 },1114 },
1115 builtin.TypeId.Enum => {1115 .Enum => {
1116 try self.serializeInt(@enumToInt(value));1116 try self.serializeInt(@enumToInt(value));
1117 },1117 },
1118 else => @compileError("Cannot serialize " ++ @tagName(@typeId(T)) ++ " types (unimplemented)."),1118 else => @compileError("Cannot serialize " ++ @tagName(@typeInfo(T)) ++ " types (unimplemented)."),
1119 }1119 }
1120 }1120 }
1121 };1121 };
lib/std/io/test.zig+5-4
...@@ -318,6 +318,7 @@ test "BitStreams with File Stream" {...@@ -318,6 +318,7 @@ test "BitStreams with File Stream" {
318}318}
319319
320fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void {320fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void {
321 @setEvalBranchQuota(1500);
321 //@NOTE: if this test is taking too long, reduce the maximum tested bitsize322 //@NOTE: if this test is taking too long, reduce the maximum tested bitsize
322 const max_test_bitsize = 128;323 const max_test_bitsize = 128;
323324
...@@ -341,8 +342,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi...@@ -341,8 +342,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
341342
342 comptime var i = 0;343 comptime var i = 0;
343 inline while (i <= max_test_bitsize) : (i += 1) {344 inline while (i <= max_test_bitsize) : (i += 1) {
344 const U = @IntType(false, i);345 const U = std.meta.IntType(false, i);
345 const S = @IntType(true, i);346 const S = std.meta.IntType(true, i);
346 try serializer.serializeInt(@as(U, i));347 try serializer.serializeInt(@as(U, i));
347 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));348 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
348 }349 }
...@@ -350,8 +351,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi...@@ -350,8 +351,8 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
350351
351 i = 0;352 i = 0;
352 inline while (i <= max_test_bitsize) : (i += 1) {353 inline while (i <= max_test_bitsize) : (i += 1) {
353 const U = @IntType(false, i);354 const U = std.meta.IntType(false, i);
354 const S = @IntType(true, i);355 const S = std.meta.IntType(true, i);
355 const x = try deserializer.deserializeInt(U);356 const x = try deserializer.deserializeInt(U);
356 const y = try deserializer.deserializeInt(S);357 const y = try deserializer.deserializeInt(S);
357 expect(x == @as(U, i));358 expect(x == @as(U, i));
lib/std/math.zig+26-28
...@@ -1,6 +1,4 @@...@@ -1,6 +1,4 @@
1const builtin = @import("builtin");
2const std = @import("std.zig");1const std = @import("std.zig");
3const TypeId = builtin.TypeId;
4const assert = std.debug.assert;2const assert = std.debug.assert;
5const testing = std.testing;3const testing = std.testing;
64
...@@ -89,7 +87,7 @@ pub const snan = @import("math/nan.zig").snan;...@@ -89,7 +87,7 @@ pub const snan = @import("math/nan.zig").snan;
89pub const inf = @import("math/inf.zig").inf;87pub const inf = @import("math/inf.zig").inf;
9088
91pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {89pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
92 assert(@typeId(T) == TypeId.Float);90 assert(@typeInfo(T) == .Float);
93 return fabs(x - y) < epsilon;91 return fabs(x - y) < epsilon;
94}92}
9593
...@@ -198,7 +196,7 @@ test "" {...@@ -198,7 +196,7 @@ test "" {
198}196}
199197
200pub fn floatMantissaBits(comptime T: type) comptime_int {198pub fn floatMantissaBits(comptime T: type) comptime_int {
201 assert(@typeId(T) == builtin.TypeId.Float);199 assert(@typeInfo(T) == .Float);
202200
203 return switch (T.bit_count) {201 return switch (T.bit_count) {
204 16 => 10,202 16 => 10,
...@@ -211,7 +209,7 @@ pub fn floatMantissaBits(comptime T: type) comptime_int {...@@ -211,7 +209,7 @@ pub fn floatMantissaBits(comptime T: type) comptime_int {
211}209}
212210
213pub fn floatExponentBits(comptime T: type) comptime_int {211pub fn floatExponentBits(comptime T: type) comptime_int {
214 assert(@typeId(T) == builtin.TypeId.Float);212 assert(@typeInfo(T) == .Float);
215213
216 return switch (T.bit_count) {214 return switch (T.bit_count) {
217 16 => 5,215 16 => 5,
...@@ -446,7 +444,7 @@ pub fn Log2Int(comptime T: type) type {...@@ -446,7 +444,7 @@ pub fn Log2Int(comptime T: type) type {
446 count += 1;444 count += 1;
447 }445 }
448446
449 return @IntType(false, count);447 return std.meta.IntType(false, count);
450}448}
451449
452pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) type {450pub 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...@@ -462,7 +460,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
462 if (is_signed) {460 if (is_signed) {
463 magnitude_bits += 1;461 magnitude_bits += 1;
464 }462 }
465 return @IntType(is_signed, magnitude_bits);463 return std.meta.IntType(is_signed, magnitude_bits);
466}464}
467465
468test "math.IntFittingRange" {466test "math.IntFittingRange" {
...@@ -526,7 +524,7 @@ fn testOverflow() void {...@@ -526,7 +524,7 @@ fn testOverflow() void {
526524
527pub fn absInt(x: var) !@TypeOf(x) {525pub fn absInt(x: var) !@TypeOf(x) {
528 const T = @TypeOf(x);526 const T = @TypeOf(x);
529 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt527 comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
530 comptime assert(T.is_signed); // must pass a signed integer to absInt528 comptime assert(T.is_signed); // must pass a signed integer to absInt
531529
532 if (x == minInt(@TypeOf(x))) {530 if (x == minInt(@TypeOf(x))) {
...@@ -560,7 +558,7 @@ fn testAbsFloat() void {...@@ -560,7 +558,7 @@ fn testAbsFloat() void {
560pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {558pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
561 @setRuntimeSafety(false);559 @setRuntimeSafety(false);
562 if (denominator == 0) return error.DivisionByZero;560 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;
564 return @divTrunc(numerator, denominator);562 return @divTrunc(numerator, denominator);
565}563}
566564
...@@ -581,7 +579,7 @@ fn testDivTrunc() void {...@@ -581,7 +579,7 @@ fn testDivTrunc() void {
581pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {579pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
582 @setRuntimeSafety(false);580 @setRuntimeSafety(false);
583 if (denominator == 0) return error.DivisionByZero;581 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;
585 return @divFloor(numerator, denominator);583 return @divFloor(numerator, denominator);
586}584}
587585
...@@ -602,7 +600,7 @@ fn testDivFloor() void {...@@ -602,7 +600,7 @@ fn testDivFloor() void {
602pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {600pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
603 @setRuntimeSafety(false);601 @setRuntimeSafety(false);
604 if (denominator == 0) return error.DivisionByZero;602 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;
606 const result = @divTrunc(numerator, denominator);604 const result = @divTrunc(numerator, denominator);
607 if (result * denominator != numerator) return error.UnexpectedRemainder;605 if (result * denominator != numerator) return error.UnexpectedRemainder;
608 return result;606 return result;
...@@ -676,13 +674,13 @@ pub fn absCast(x: var) t: {...@@ -676,13 +674,13 @@ pub fn absCast(x: var) t: {
676 if (@TypeOf(x) == comptime_int) {674 if (@TypeOf(x) == comptime_int) {
677 break :t comptime_int;675 break :t comptime_int;
678 } else {676 } else {
679 break :t @IntType(false, @TypeOf(x).bit_count);677 break :t std.meta.IntType(false, @TypeOf(x).bit_count);
680 }678 }
681} {679} {
682 if (@TypeOf(x) == comptime_int) {680 if (@TypeOf(x) == comptime_int) {
683 return if (x < 0) -x else x;681 return if (x < 0) -x else x;
684 }682 }
685 const uint = @IntType(false, @TypeOf(x).bit_count);683 const uint = std.meta.IntType(false, @TypeOf(x).bit_count);
686 if (x >= 0) return @intCast(uint, x);684 if (x >= 0) return @intCast(uint, x);
687685
688 return @intCast(uint, -(x + 1)) + 1;686 return @intCast(uint, -(x + 1)) + 1;
...@@ -703,10 +701,10 @@ test "math.absCast" {...@@ -703,10 +701,10 @@ test "math.absCast" {
703701
704/// Returns the negation of the integer parameter.702/// Returns the negation of the integer parameter.
705/// Result is a signed integer.703/// 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) {
707 if (@TypeOf(x).is_signed) return negate(x);705 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);
710 if (x > -minInt(int)) return error.Overflow;708 if (x > -minInt(int)) return error.Overflow;
711709
712 if (x == -minInt(int)) return minInt(int);710 if (x == -minInt(int)) return minInt(int);
...@@ -727,8 +725,8 @@ test "math.negateCast" {...@@ -727,8 +725,8 @@ test "math.negateCast" {
727/// Cast an integer to a different integer type. If the value doesn't fit,725/// Cast an integer to a different integer type. If the value doesn't fit,
728/// return an error.726/// return an error.
729pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {727pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
730 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer728 comptime assert(@typeInfo(T) == .Int); // must pass an integer
731 comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer729 comptime assert(@typeInfo(@TypeOf(x)) == .Int); // must pass an integer
732 if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {730 if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
733 return error.Overflow;731 return error.Overflow;
734 } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {732 } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {
...@@ -792,11 +790,11 @@ fn testFloorPowerOfTwo() void {...@@ -792,11 +790,11 @@ fn testFloorPowerOfTwo() void {
792/// Returns the next power of two (if the value is not already a power of two).790/// Returns the next power of two (if the value is not already a power of two).
793/// Only unsigned integers can be used. Zero is not an allowed input.791/// Only unsigned integers can be used. Zero is not an allowed input.
794/// Result is a type with 1 more bit than the input type.792/// 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) {793pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.IntType(T.is_signed, T.bit_count + 1) {
796 comptime assert(@typeId(T) == builtin.TypeId.Int);794 comptime assert(@typeInfo(T) == .Int);
797 comptime assert(!T.is_signed);795 comptime assert(!T.is_signed);
798 assert(value != 0);796 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);
800 comptime const shiftType = std.math.Log2Int(PromotedType);798 comptime const shiftType = std.math.Log2Int(PromotedType);
801 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));799 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
802}800}
...@@ -805,9 +803,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T...@@ -805,9 +803,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) @IntType(T.is_signed, T
805/// Only unsigned integers can be used. Zero is not an allowed input.803/// Only unsigned integers can be used. Zero is not an allowed input.
806/// If the value doesn't fit, returns an error.804/// If the value doesn't fit, returns an error.
807pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {805pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
808 comptime assert(@typeId(T) == builtin.TypeId.Int);806 comptime assert(@typeInfo(T) == .Int);
809 comptime assert(!T.is_signed);807 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);
811 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;809 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
812 var x = ceilPowerOfTwoPromote(T, value);810 var x = ceilPowerOfTwoPromote(T, value);
813 if (overflowBit & x != 0) {811 if (overflowBit & x != 0) {
...@@ -878,10 +876,10 @@ test "std.math.log2_int_ceil" {...@@ -878,10 +876,10 @@ test "std.math.log2_int_ceil" {
878876
879pub fn lossyCast(comptime T: type, value: var) T {877pub fn lossyCast(comptime T: type, value: var) T {
880 switch (@typeInfo(@TypeOf(value))) {878 switch (@typeInfo(@TypeOf(value))) {
881 builtin.TypeId.Int => return @intToFloat(T, value),879 .Int => return @intToFloat(T, value),
882 builtin.TypeId.Float => return @floatCast(T, value),880 .Float => return @floatCast(T, value),
883 builtin.TypeId.ComptimeInt => return @as(T, value),881 .ComptimeInt => return @as(T, value),
884 builtin.TypeId.ComptimeFloat => return @as(T, value),882 .ComptimeFloat => return @as(T, value),
885 else => @compileError("bad type"),883 else => @compileError("bad type"),
886 }884 }
887}885}
...@@ -949,8 +947,8 @@ test "max value type" {...@@ -949,8 +947,8 @@ test "max value type" {
949 testing.expect(x == 2147483647);947 testing.expect(x == 2147483647);
950}948}
951949
952pub fn mulWide(comptime T: type, a: T, b: T) @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) {
953 const ResultInt = @IntType(T.is_signed, T.bit_count * 2);951 const ResultInt = std.meta.IntType(T.is_signed, T.bit_count * 2);
954 return @as(ResultInt, a) * @as(ResultInt, b);952 return @as(ResultInt, a) * @as(ResultInt, b);
955}953}
956954
lib/std/math/big/int.zig+7-10
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
3const debug = std.debug;2const debug = std.debug;
4const testing = std.testing;3const testing = std.testing;
5const math = std.math;4const math = std.math;
...@@ -9,10 +8,8 @@ const ArrayList = std.ArrayList;...@@ -9,10 +8,8 @@ const ArrayList = std.ArrayList;
9const maxInt = std.math.maxInt;8const maxInt = std.math.maxInt;
10const minInt = std.math.minInt;9const minInt = std.math.minInt;
1110
12const TypeId = builtin.TypeId;
13
14pub const Limb = usize;11pub const Limb = usize;
15pub const DoubleLimb = @IntType(false, 2 * Limb.bit_count);12pub const DoubleLimb = std.meta.IntType(false, 2 * Limb.bit_count);
16pub const Log2Limb = math.Log2Int(Limb);13pub const Log2Limb = math.Log2Int(Limb);
1714
18comptime {15comptime {
...@@ -270,8 +267,8 @@ pub const Int = struct {...@@ -270,8 +267,8 @@ pub const Int = struct {
270 const T = @TypeOf(value);267 const T = @TypeOf(value);
271268
272 switch (@typeInfo(T)) {269 switch (@typeInfo(T)) {
273 TypeId.Int => |info| {270 .Int => |info| {
274 const UT = if (T.is_signed) @IntType(false, T.bit_count - 1) else T;271 const UT = if (T.is_signed) std.meta.IntType(false, T.bit_count - 1) else T;
275272
276 try self.ensureCapacity(@sizeOf(UT) / @sizeOf(Limb));273 try self.ensureCapacity(@sizeOf(UT) / @sizeOf(Limb));
277 self.metadata = 0;274 self.metadata = 0;
...@@ -294,7 +291,7 @@ pub const Int = struct {...@@ -294,7 +291,7 @@ pub const Int = struct {
294 }291 }
295 }292 }
296 },293 },
297 TypeId.ComptimeInt => {294 .ComptimeInt => {
298 comptime var w_value = if (value < 0) -value else value;295 comptime var w_value = if (value < 0) -value else value;
299296
300 const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1;297 const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1;
...@@ -332,9 +329,9 @@ pub const Int = struct {...@@ -332,9 +329,9 @@ pub const Int = struct {
332 ///329 ///
333 /// Returns an error if self cannot be narrowed into the requested type without truncation.330 /// Returns an error if self cannot be narrowed into the requested type without truncation.
334 pub fn to(self: Int, comptime T: type) ConvertError!T {331 pub fn to(self: Int, comptime T: type) ConvertError!T {
335 switch (@typeId(T)) {332 switch (@typeInfo(T)) {
336 TypeId.Int => {333 .Int => {
337 const UT = @IntType(false, T.bit_count);334 const UT = std.meta.IntType(false, T.bit_count);
338335
339 if (self.bitCountTwosComp() > T.bit_count) {336 if (self.bitCountTwosComp() > T.bit_count) {
340 return error.TargetTooSmall;337 return error.TargetTooSmall;
lib/std/math/big/rational.zig+6-9
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../../std.zig");1const std = @import("../../std.zig");
2const builtin = @import("builtin");
3const debug = std.debug;2const debug = std.debug;
4const math = std.math;3const math = std.math;
5const mem = std.mem;4const mem = std.mem;
...@@ -7,8 +6,6 @@ const testing = std.testing;...@@ -7,8 +6,6 @@ const testing = std.testing;
7const Allocator = mem.Allocator;6const Allocator = mem.Allocator;
8const ArrayList = std.ArrayList;7const ArrayList = std.ArrayList;
98
10const TypeId = builtin.TypeId;
11
12const bn = @import("int.zig");9const bn = @import("int.zig");
13const Limb = bn.Limb;10const Limb = bn.Limb;
14const DoubleLimb = bn.DoubleLimb;11const DoubleLimb = bn.DoubleLimb;
...@@ -129,9 +126,9 @@ pub const Rational = struct {...@@ -129,9 +126,9 @@ pub const Rational = struct {
129 /// completely represent the provided float.126 /// completely represent the provided float.
130 pub fn setFloat(self: *Rational, comptime T: type, f: T) !void {127 pub fn setFloat(self: *Rational, comptime T: type, f: T) !void {
131 // Translated from golang.go/src/math/big/rat.go.128 // 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);
135 const f_bits = @bitCast(UnsignedIntType, f);132 const f_bits = @bitCast(UnsignedIntType, f);
136133
137 const exponent_bits = math.floatExponentBits(T);134 const exponent_bits = math.floatExponentBits(T);
...@@ -187,10 +184,10 @@ pub const Rational = struct {...@@ -187,10 +184,10 @@ pub const Rational = struct {
187 pub fn toFloat(self: Rational, comptime T: type) !T {184 pub fn toFloat(self: Rational, comptime T: type) !T {
188 // Translated from golang.go/src/math/big/rat.go.185 // Translated from golang.go/src/math/big/rat.go.
189 // TODO: Indicate whether the result is not exact.186 // TODO: Indicate whether the result is not exact.
190 debug.assert(@typeId(T) == builtin.TypeId.Float);187 debug.assert(@typeInfo(T) == .Float);
191188
192 const fsize = T.bit_count;189 const fsize = T.bit_count;
193 const BitReprType = @IntType(false, T.bit_count);190 const BitReprType = std.meta.IntType(false, T.bit_count);
194191
195 const msize = math.floatMantissaBits(T);192 const msize = math.floatMantissaBits(T);
196 const msize1 = msize + 1;193 const msize1 = msize + 1;
...@@ -465,7 +462,7 @@ pub const Rational = struct {...@@ -465,7 +462,7 @@ pub const Rational = struct {
465 }462 }
466};463};
467464
468const SignedDoubleLimb = @IntType(true, DoubleLimb.bit_count);465const SignedDoubleLimb = std.meta.IntType(true, DoubleLimb.bit_count);
469466
470fn gcd(rma: *Int, x: Int, y: Int) !void {467fn gcd(rma: *Int, x: Int, y: Int) !void {
471 rma.assertWritable();468 rma.assertWritable();
...@@ -653,7 +650,7 @@ test "big.rational gcd one large" {...@@ -653,7 +650,7 @@ test "big.rational gcd one large" {
653}650}
654651
655fn extractLowBits(a: Int, comptime T: type) T {652fn extractLowBits(a: Int, comptime T: type) T {
656 testing.expect(@typeId(T) == builtin.TypeId.Int);653 testing.expect(@typeInfo(T) == .Int);
657654
658 if (T.bit_count <= Limb.bit_count) {655 if (T.bit_count <= Limb.bit_count) {
659 return @truncate(T, a.limbs[0]);656 return @truncate(T, a.limbs[0]);
lib/std/math/cos.zig+1-1
...@@ -44,7 +44,7 @@ const pi4c = 2.69515142907905952645E-15;...@@ -44,7 +44,7 @@ const pi4c = 2.69515142907905952645E-15;
44const m4pi = 1.273239544735162542821171882678754627704620361328125;44const m4pi = 1.273239544735162542821171882678754627704620361328125;
4545
46fn cos_(comptime T: type, x_: T) T {46fn 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
49 var x = x_;49 var x = x_;
50 if (math.isNan(x) or math.isInf(x)) {50 if (math.isNan(x) or math.isInf(x)) {
lib/std/math/ln.zig+5-7
...@@ -7,8 +7,6 @@...@@ -7,8 +7,6 @@
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const math = std.math;8const math = std.math;
9const expect = std.testing.expect;9const expect = std.testing.expect;
10const builtin = @import("builtin");
11const TypeId = builtin.TypeId;
1210
13/// Returns the natural logarithm of x.11/// Returns the natural logarithm of x.
14///12///
...@@ -19,21 +17,21 @@ const TypeId = builtin.TypeId;...@@ -19,21 +17,21 @@ const TypeId = builtin.TypeId;
19/// - ln(nan) = nan17/// - ln(nan) = nan
20pub fn ln(x: var) @TypeOf(x) {18pub fn ln(x: var) @TypeOf(x) {
21 const T = @TypeOf(x);19 const T = @TypeOf(x);
22 switch (@typeId(T)) {20 switch (@typeInfo(T)) {
23 TypeId.ComptimeFloat => {21 .ComptimeFloat => {
24 return @as(comptime_float, ln_64(x));22 return @as(comptime_float, ln_64(x));
25 },23 },
26 TypeId.Float => {24 .Float => {
27 return switch (T) {25 return switch (T) {
28 f32 => ln_32(x),26 f32 => ln_32(x),
29 f64 => ln_64(x),27 f64 => ln_64(x),
30 else => @compileError("ln not implemented for " ++ @typeName(T)),28 else => @compileError("ln not implemented for " ++ @typeName(T)),
31 };29 };
32 },30 },
33 TypeId.ComptimeInt => {31 .ComptimeInt => {
34 return @as(comptime_int, math.floor(ln_64(@as(f64, x))));32 return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
35 },33 },
36 TypeId.Int => {34 .Int => {
37 return @as(T, math.floor(ln_64(@as(f64, x))));35 return @as(T, math.floor(ln_64(@as(f64, x))));
38 },36 },
39 else => @compileError("ln not implemented for " ++ @typeName(T)),37 else => @compileError("ln not implemented for " ++ @typeName(T)),
lib/std/math/log.zig+6-8
...@@ -6,8 +6,6 @@...@@ -6,8 +6,6 @@
66
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const math = std.math;8const math = std.math;
9const builtin = @import("builtin");
10const TypeId = builtin.TypeId;
11const expect = std.testing.expect;9const expect = std.testing.expect;
1210
13/// Returns the logarithm of x for the provided base.11/// Returns the logarithm of x for the provided base.
...@@ -16,24 +14,24 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -16,24 +14,24 @@ pub fn log(comptime T: type, base: T, x: T) T {
16 return math.log2(x);14 return math.log2(x);
17 } else if (base == 10) {15 } else if (base == 10) {
18 return math.log10(x);16 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) {
20 return math.ln(x);18 return math.ln(x);
21 }19 }
2220
23 const float_base = math.lossyCast(f64, base);21 const float_base = math.lossyCast(f64, base);
24 switch (@typeId(T)) {22 switch (@typeInfo(T)) {
25 TypeId.ComptimeFloat => {23 .ComptimeFloat => {
26 return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base));24 return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base));
27 },25 },
28 TypeId.ComptimeInt => {26 .ComptimeInt => {
29 return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));27 return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
30 },28 },
31 builtin.TypeId.Int => {29 .Int => {
32 // TODO implement integer log without using float math30 // TODO implement integer log without using float math
33 return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base)));31 return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base)));
34 },32 },
3533
36 builtin.TypeId.Float => {34 .Float => {
37 switch (T) {35 switch (T) {
38 f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),36 f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)),
39 f64 => return math.ln(x) / math.ln(float_base),37 f64 => return math.ln(x) / math.ln(float_base),
lib/std/math/log10.zig+5-7
...@@ -7,8 +7,6 @@...@@ -7,8 +7,6 @@
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const math = std.math;8const math = std.math;
9const testing = std.testing;9const testing = std.testing;
10const builtin = @import("builtin");
11const TypeId = builtin.TypeId;
12const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1311
14/// Returns the base-10 logarithm of x.12/// Returns the base-10 logarithm of x.
...@@ -20,21 +18,21 @@ const maxInt = std.math.maxInt;...@@ -20,21 +18,21 @@ const maxInt = std.math.maxInt;
20/// - log10(nan) = nan18/// - log10(nan) = nan
21pub fn log10(x: var) @TypeOf(x) {19pub fn log10(x: var) @TypeOf(x) {
22 const T = @TypeOf(x);20 const T = @TypeOf(x);
23 switch (@typeId(T)) {21 switch (@typeInfo(T)) {
24 TypeId.ComptimeFloat => {22 .ComptimeFloat => {
25 return @as(comptime_float, log10_64(x));23 return @as(comptime_float, log10_64(x));
26 },24 },
27 TypeId.Float => {25 .Float => {
28 return switch (T) {26 return switch (T) {
29 f32 => log10_32(x),27 f32 => log10_32(x),
30 f64 => log10_64(x),28 f64 => log10_64(x),
31 else => @compileError("log10 not implemented for " ++ @typeName(T)),29 else => @compileError("log10 not implemented for " ++ @typeName(T)),
32 };30 };
33 },31 },
34 TypeId.ComptimeInt => {32 .ComptimeInt => {
35 return @as(comptime_int, math.floor(log10_64(@as(f64, x))));33 return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
36 },34 },
37 TypeId.Int => {35 .Int => {
38 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));36 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
39 },37 },
40 else => @compileError("log10 not implemented for " ++ @typeName(T)),38 else => @compileError("log10 not implemented for " ++ @typeName(T)),
lib/std/math/log2.zig+5-7
...@@ -7,8 +7,6 @@...@@ -7,8 +7,6 @@
7const std = @import("../std.zig");7const std = @import("../std.zig");
8const math = std.math;8const math = std.math;
9const expect = std.testing.expect;9const expect = std.testing.expect;
10const builtin = @import("builtin");
11const TypeId = builtin.TypeId;
12const maxInt = std.math.maxInt;10const maxInt = std.math.maxInt;
1311
14/// Returns the base-2 logarithm of x.12/// Returns the base-2 logarithm of x.
...@@ -20,18 +18,18 @@ const maxInt = std.math.maxInt;...@@ -20,18 +18,18 @@ const maxInt = std.math.maxInt;
20/// - log2(nan) = nan18/// - log2(nan) = nan
21pub fn log2(x: var) @TypeOf(x) {19pub fn log2(x: var) @TypeOf(x) {
22 const T = @TypeOf(x);20 const T = @TypeOf(x);
23 switch (@typeId(T)) {21 switch (@typeInfo(T)) {
24 TypeId.ComptimeFloat => {22 .ComptimeFloat => {
25 return @as(comptime_float, log2_64(x));23 return @as(comptime_float, log2_64(x));
26 },24 },
27 TypeId.Float => {25 .Float => {
28 return switch (T) {26 return switch (T) {
29 f32 => log2_32(x),27 f32 => log2_32(x),
30 f64 => log2_64(x),28 f64 => log2_64(x),
31 else => @compileError("log2 not implemented for " ++ @typeName(T)),29 else => @compileError("log2 not implemented for " ++ @typeName(T)),
32 };30 };
33 },31 },
34 TypeId.ComptimeInt => comptime {32 .ComptimeInt => comptime {
35 var result = 0;33 var result = 0;
36 var x_shifted = x;34 var x_shifted = x;
37 while (b: {35 while (b: {
...@@ -40,7 +38,7 @@ pub fn log2(x: var) @TypeOf(x) {...@@ -40,7 +38,7 @@ pub fn log2(x: var) @TypeOf(x) {
40 }) : (result += 1) {}38 }) : (result += 1) {}
41 return result;39 return result;
42 },40 },
43 TypeId.Int => {41 .Int => {
44 return math.log2_int(T, x);42 return math.log2_int(T, x);
45 },43 },
46 else => @compileError("log2 not implemented for " ++ @typeName(T)),44 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 {...@@ -145,7 +145,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
145 var xe = r2.exponent;145 var xe = r2.exponent;
146 var x1 = r2.significand;146 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);
149 while (i != 0) : (i >>= 1) {149 while (i != 0) : (i >>= 1) {
150 const overflow_shift = math.floatExponentBits(T) + 1;150 const overflow_shift = math.floatExponentBits(T) + 1;
151 if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) {151 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;...@@ -45,7 +45,7 @@ const pi4c = 2.69515142907905952645E-15;
45const m4pi = 1.273239544735162542821171882678754627704620361328125;45const m4pi = 1.273239544735162542821171882678754627704620361328125;
4646
47fn sin_(comptime T: type, x_: T) T {47fn 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
50 var x = x_;50 var x = x_;
51 if (x == 0 or math.isNan(x)) {51 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)) {...@@ -31,7 +31,7 @@ pub fn sqrt(x: var) Sqrt(@TypeOf(x)) {
31 }31 }
32}32}
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) {
35 var op = value;35 var op = value;
36 var res: T = 0;36 var res: T = 0;
37 var one: T = 1 << (T.bit_count - 2);37 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) {...@@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) {
50 one >>= 2;50 one >>= 2;
51 }51 }
5252
53 const ResultType = @IntType(false, T.bit_count / 2);53 const ResultType = std.meta.IntType(false, T.bit_count / 2);
54 return @intCast(ResultType, res);54 return @intCast(ResultType, res);
55}55}
5656
...@@ -66,7 +66,7 @@ test "math.sqrt_int" {...@@ -66,7 +66,7 @@ test "math.sqrt_int" {
66/// Returns the return type `sqrt` will return given an operand of type `T`.66/// Returns the return type `sqrt` will return given an operand of type `T`.
67pub fn Sqrt(comptime T: type) type {67pub fn Sqrt(comptime T: type) type {
68 return switch (@typeInfo(T)) {68 return switch (@typeInfo(T)) {
69 .Int => |int| @IntType(false, int.bits / 2),69 .Int => |int| std.meta.IntType(false, int.bits / 2),
70 else => T,70 else => T,
71 };71 };
72}72}
lib/std/math/tan.zig+1-1
...@@ -38,7 +38,7 @@ const pi4c = 2.69515142907905952645E-15;...@@ -38,7 +38,7 @@ const pi4c = 2.69515142907905952645E-15;
38const m4pi = 1.273239544735162542821171882678754627704620361328125;38const m4pi = 1.273239544735162542821171882678754627704620361328125;
3939
40fn tan_(comptime T: type, x_: T) T {40fn 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
43 var x = x_;43 var x = x_;
44 if (x == 0 or math.isNan(x)) {44 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 {...@@ -708,7 +708,7 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
708 assert(buffer.len >= @divExact(T.bit_count, 8));708 assert(buffer.len >= @divExact(T.bit_count, 8));
709709
710 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough710 // 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);
712 var bits = @truncate(uint, value);712 var bits = @truncate(uint, value);
713 for (buffer) |*b| {713 for (buffer) |*b| {
714 b.* = @truncate(u8, bits);714 b.* = @truncate(u8, bits);
...@@ -725,7 +725,7 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {...@@ -725,7 +725,7 @@ pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
725 assert(buffer.len >= @divExact(T.bit_count, 8));725 assert(buffer.len >= @divExact(T.bit_count, 8));
726726
727 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough727 // 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);
729 var bits = @truncate(uint, value);729 var bits = @truncate(uint, value);
730 var index: usize = buffer.len;730 var index: usize = buffer.len;
731 while (index != 0) {731 while (index != 0) {
lib/std/meta.zig+11-3
...@@ -536,9 +536,8 @@ test "intToEnum with error return" {...@@ -536,9 +536,8 @@ test "intToEnum with error return" {
536pub const IntToEnumError = error{InvalidEnumTag};536pub const IntToEnumError = error{InvalidEnumTag};
537537
538pub fn intToEnum(comptime Tag: type, tag_int: var) IntToEnumError!Tag {538pub fn intToEnum(comptime Tag: type, tag_int: var) IntToEnumError!Tag {
539 comptime var i = 0;539 inline for (@typeInfo(Tag).Enum.fields) |f| {
540 inline while (i != @memberCount(Tag)) : (i += 1) {540 const this_tag_value = @field(Tag, f.name);
541 const this_tag_value = @field(Tag, @memberName(Tag, i));
542 if (tag_int == @enumToInt(this_tag_value)) {541 if (tag_int == @enumToInt(this_tag_value)) {
543 return this_tag_value;542 return this_tag_value;
544 }543 }
...@@ -581,3 +580,12 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De...@@ -581,3 +580,12 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
581 return &array;580 return &array;
582 }581 }
583}582}
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 @@...@@ -1,5 +1,5 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");2const builtin = std.builtin;
3const mem = std.mem;3const mem = std.mem;
4const debug = std.debug;4const debug = std.debug;
5const testing = std.testing;5const testing = std.testing;
...@@ -54,7 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {...@@ -54,7 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
54 if (!comptime isContainer(T)) return false;54 if (!comptime isContainer(T)) return false;
55 if (!comptime @hasDecl(T, name)) return false;55 if (!comptime @hasDecl(T, name)) return false;
56 const DeclType = @TypeOf(@field(T, name));56 const DeclType = @TypeOf(@field(T, name));
57 return @typeId(DeclType) == .Fn;57 return @typeInfo(DeclType) == .Fn;
58 }58 }
59 };59 };
60 return Closure.trait;60 return Closure.trait;
...@@ -105,7 +105,7 @@ test "std.meta.trait.hasField" {...@@ -105,7 +105,7 @@ test "std.meta.trait.hasField" {
105pub fn is(comptime id: builtin.TypeId) TraitFn {105pub fn is(comptime id: builtin.TypeId) TraitFn {
106 const Closure = struct {106 const Closure = struct {
107 pub fn trait(comptime T: type) bool {107 pub fn trait(comptime T: type) bool {
108 return id == @typeId(T);108 return id == @typeInfo(T);
109 }109 }
110 };110 };
111 return Closure.trait;111 return Closure.trait;
...@@ -123,7 +123,7 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {...@@ -123,7 +123,7 @@ pub fn isPtrTo(comptime id: builtin.TypeId) TraitFn {
123 const Closure = struct {123 const Closure = struct {
124 pub fn trait(comptime T: type) bool {124 pub fn trait(comptime T: type) bool {
125 if (!comptime isSingleItemPtr(T)) return false;125 if (!comptime isSingleItemPtr(T)) return false;
126 return id == @typeId(meta.Child(T));126 return id == @typeInfo(meta.Child(T));
127 }127 }
128 };128 };
129 return Closure.trait;129 return Closure.trait;
...@@ -139,7 +139,7 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {...@@ -139,7 +139,7 @@ pub fn isSliceOf(comptime id: builtin.TypeId) TraitFn {
139 const Closure = struct {139 const Closure = struct {
140 pub fn trait(comptime T: type) bool {140 pub fn trait(comptime T: type) bool {
141 if (!comptime isSlice(T)) return false;141 if (!comptime isSlice(T)) return false;
142 return id == @typeId(meta.Child(T));142 return id == @typeInfo(meta.Child(T));
143 }143 }
144 };144 };
145 return Closure.trait;145 return Closure.trait;
...@@ -285,7 +285,7 @@ test "std.meta.trait.isIndexable" {...@@ -285,7 +285,7 @@ test "std.meta.trait.isIndexable" {
285}285}
286286
287pub fn isNumber(comptime T: type) bool {287pub fn isNumber(comptime T: type) bool {
288 return switch (@typeId(T)) {288 return switch (@typeInfo(T)) {
289 .Int, .Float, .ComptimeInt, .ComptimeFloat => true,289 .Int, .Float, .ComptimeInt, .ComptimeFloat => true,
290 else => false,290 else => false,
291 };291 };
...@@ -320,7 +320,7 @@ test "std.meta.trait.isConstPtr" {...@@ -320,7 +320,7 @@ test "std.meta.trait.isConstPtr" {
320}320}
321321
322pub fn isContainer(comptime T: type) bool {322pub fn isContainer(comptime T: type) bool {
323 return switch (@typeId(T)) {323 return switch (@typeInfo(T)) {
324 .Struct, .Union, .Enum => true,324 .Struct, .Union, .Enum => true,
325 else => false,325 else => false,
326 };326 };
lib/std/os.zig+1-1
...@@ -3349,7 +3349,7 @@ pub fn res_mkquery(...@@ -3349,7 +3349,7 @@ pub fn res_mkquery(
3349 // Make a reasonably unpredictable id3349 // Make a reasonably unpredictable id
3350 var ts: timespec = undefined;3350 var ts: timespec = undefined;
3351 clock_gettime(CLOCK_REALTIME, &ts) catch {};3351 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);
3353 const unsec = @bitCast(UInt, ts.tv_nsec);3353 const unsec = @bitCast(UInt, ts.tv_nsec);
3354 const id = @truncate(u32, unsec + unsec / 65536);3354 const id = @truncate(u32, unsec + unsec / 65536);
3355 q[0] = @truncate(u8, id / 256);3355 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 {...@@ -1004,7 +1004,7 @@ pub const dl_phdr_info = extern struct {
10041004
1005pub const CPU_SETSIZE = 128;1005pub const CPU_SETSIZE = 128;
1006pub const cpu_set_t = [CPU_SETSIZE / @sizeOf(usize)]usize;1006pub 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
1009pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {1009pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t {
1010 var sum: cpu_count_t = 0;1010 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 {...@@ -34,13 +34,13 @@ pub fn PackedIntIo(comptime Int: type, comptime endian: builtin.Endian) type {
3434
35 //we bitcast the desired Int type to an unsigned version of itself35 //we bitcast the desired Int type to an unsigned version of itself
36 // to avoid issues with shifting signed ints.36 // to avoid issues with shifting signed ints.
37 const UnInt = @IntType(false, int_bits);37 const UnInt = std.meta.IntType(false, int_bits);
3838
39 //The maximum container int type39 //The maximum container int type
40 const MinIo = @IntType(false, min_io_bits);40 const MinIo = std.meta.IntType(false, min_io_bits);
4141
42 //The minimum container int type42 //The minimum container int type
43 const MaxIo = @IntType(false, max_io_bits);43 const MaxIo = std.meta.IntType(false, max_io_bits);
4444
45 return struct {45 return struct {
46 pub fn get(bytes: []const u8, index: usize, bit_offset: u7) Int {46 pub fn get(bytes: []const u8, index: usize, bit_offset: u7) Int {
...@@ -322,7 +322,7 @@ test "PackedIntArray" {...@@ -322,7 +322,7 @@ test "PackedIntArray" {
322 inline while (bits <= 256) : (bits += 1) {322 inline while (bits <= 256) : (bits += 1) {
323 //alternate unsigned and signed323 //alternate unsigned and signed
324 const even = bits % 2 == 0;324 const even = bits % 2 == 0;
325 const I = @IntType(even, bits);325 const I = std.meta.IntType(even, bits);
326326
327 const PackedArray = PackedIntArray(I, int_count);327 const PackedArray = PackedIntArray(I, int_count);
328 const expected_bytes = ((bits * int_count) + 7) / 8;328 const expected_bytes = ((bits * int_count) + 7) / 8;
...@@ -369,7 +369,7 @@ test "PackedIntSlice" {...@@ -369,7 +369,7 @@ test "PackedIntSlice" {
369 inline while (bits <= 256) : (bits += 1) {369 inline while (bits <= 256) : (bits += 1) {
370 //alternate unsigned and signed370 //alternate unsigned and signed
371 const even = bits % 2 == 0;371 const even = bits % 2 == 0;
372 const I = @IntType(even, bits);372 const I = std.meta.IntType(even, bits);
373 const P = PackedIntSlice(I);373 const P = PackedIntSlice(I);
374374
375 var data = P.init(&buffer, int_count);375 var data = P.init(&buffer, int_count);
...@@ -399,7 +399,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {...@@ -399,7 +399,7 @@ test "PackedIntSlice of PackedInt(Array/Slice)" {
399399
400 comptime var bits = 0;400 comptime var bits = 0;
401 inline while (bits <= max_bits) : (bits += 1) {401 inline while (bits <= max_bits) : (bits += 1) {
402 const Int = @IntType(false, bits);402 const Int = std.meta.IntType(false, bits);
403403
404 const PackedArray = PackedIntArray(Int, int_count);404 const PackedArray = PackedIntArray(Int, int_count);
405 var packed_array = @as(PackedArray, undefined);405 var packed_array = @as(PackedArray, undefined);
lib/std/rand.zig+10-10
...@@ -45,8 +45,8 @@ pub const Random = struct {...@@ -45,8 +45,8 @@ pub const Random = struct {
45 /// Returns a random int `i` such that `0 <= i <= maxInt(T)`.45 /// Returns a random int `i` such that `0 <= i <= maxInt(T)`.
46 /// `i` is evenly distributed.46 /// `i` is evenly distributed.
47 pub fn int(r: *Random, comptime T: type) T {47 pub fn int(r: *Random, comptime T: type) T {
48 const UnsignedT = @IntType(false, T.bit_count);48 const UnsignedT = std.meta.IntType(false, T.bit_count);
49 const ByteAlignedT = @IntType(false, @divTrunc(T.bit_count + 7, 8) * 8);49 const ByteAlignedT = std.meta.IntType(false, @divTrunc(T.bit_count + 7, 8) * 8);
5050
51 var rand_bytes: [@sizeOf(ByteAlignedT)]u8 = undefined;51 var rand_bytes: [@sizeOf(ByteAlignedT)]u8 = undefined;
52 r.bytes(rand_bytes[0..]);52 r.bytes(rand_bytes[0..]);
...@@ -85,9 +85,9 @@ pub const Random = struct {...@@ -85,9 +85,9 @@ pub const Random = struct {
85 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!85 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
86 assert(0 < less_than);86 assert(0 < less_than);
87 // Small is typically u3287 // 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);
89 // Large is typically u6489 // 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
92 // adapted from:92 // adapted from:
93 // http://www.pcg-random.org/posts/bounded-rands.html93 // http://www.pcg-random.org/posts/bounded-rands.html
...@@ -99,7 +99,7 @@ pub const Random = struct {...@@ -99,7 +99,7 @@ pub const Random = struct {
99 // TODO: workaround for https://github.com/ziglang/zig/issues/177099 // TODO: workaround for https://github.com/ziglang/zig/issues/1770
100 // should be:100 // should be:
101 // var t: Small = -%less_than;101 // 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
104 if (t >= less_than) {104 if (t >= less_than) {
105 t -= less_than;105 t -= less_than;
...@@ -145,7 +145,7 @@ pub const Random = struct {...@@ -145,7 +145,7 @@ pub const Random = struct {
145 assert(at_least < less_than);145 assert(at_least < less_than);
146 if (T.is_signed) {146 if (T.is_signed) {
147 // Two's complement makes this math pretty easy.147 // 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);
149 const lo = @bitCast(UnsignedT, at_least);149 const lo = @bitCast(UnsignedT, at_least);
150 const hi = @bitCast(UnsignedT, less_than);150 const hi = @bitCast(UnsignedT, less_than);
151 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);151 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);
...@@ -163,7 +163,7 @@ pub const Random = struct {...@@ -163,7 +163,7 @@ pub const Random = struct {
163 assert(at_least < less_than);163 assert(at_least < less_than);
164 if (T.is_signed) {164 if (T.is_signed) {
165 // Two's complement makes this math pretty easy.165 // 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);
167 const lo = @bitCast(UnsignedT, at_least);167 const lo = @bitCast(UnsignedT, at_least);
168 const hi = @bitCast(UnsignedT, less_than);168 const hi = @bitCast(UnsignedT, less_than);
169 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);169 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);
...@@ -180,7 +180,7 @@ pub const Random = struct {...@@ -180,7 +180,7 @@ pub const Random = struct {
180 assert(at_least <= at_most);180 assert(at_least <= at_most);
181 if (T.is_signed) {181 if (T.is_signed) {
182 // Two's complement makes this math pretty easy.182 // 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);
184 const lo = @bitCast(UnsignedT, at_least);184 const lo = @bitCast(UnsignedT, at_least);
185 const hi = @bitCast(UnsignedT, at_most);185 const hi = @bitCast(UnsignedT, at_most);
186 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);186 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);
...@@ -198,7 +198,7 @@ pub const Random = struct {...@@ -198,7 +198,7 @@ pub const Random = struct {
198 assert(at_least <= at_most);198 assert(at_least <= at_most);
199 if (T.is_signed) {199 if (T.is_signed) {
200 // Two's complement makes this math pretty easy.200 // 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);
202 const lo = @bitCast(UnsignedT, at_least);202 const lo = @bitCast(UnsignedT, at_least);
203 const hi = @bitCast(UnsignedT, at_most);203 const hi = @bitCast(UnsignedT, at_most);
204 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);204 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);
...@@ -281,7 +281,7 @@ pub const Random = struct {...@@ -281,7 +281,7 @@ pub const Random = struct {
281/// This function introduces a minor bias.281/// This function introduces a minor bias.
282pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {282pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
283 comptime assert(T.is_signed == false);283 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
286 // adapted from:286 // adapted from:
287 // http://www.pcg-random.org/posts/bounded-rands.html287 // 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 {...@@ -128,7 +128,7 @@ pub fn main() !void {
128}128}
129129
130fn runBuild(builder: *Builder) anyerror!void {130fn runBuild(builder: *Builder) anyerror!void {
131 switch (@typeId(@TypeOf(root.build).ReturnType)) {131 switch (@typeInfo(@TypeOf(root.build).ReturnType)) {
132 .Void => root.build(builder),132 .Void => root.build(builder),
133 .ErrorUnion => try root.build(builder),133 .ErrorUnion => try root.build(builder),
134 else => @compileError("expected return type of build to be 'void' or '!void'"),134 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 {...@@ -511,7 +511,7 @@ export fn roundf(a: f32) f32 {
511fn generic_fmod(comptime T: type, x: T, y: T) T {511fn generic_fmod(comptime T: type, x: T, y: T) T {
512 @setRuntimeSafety(false);512 @setRuntimeSafety(false);
513513
514 const uint = @IntType(false, T.bit_count);514 const uint = std.meta.IntType(false, T.bit_count);
515 const log2uint = math.Log2Int(uint);515 const log2uint = math.Log2Int(uint);
516 const digits = if (T == f32) 23 else 52;516 const digits = if (T == f32) 23 else 52;
517 const exp_bits = if (T == f32) 9 else 12;517 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 {...@@ -54,21 +54,21 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
54}54}
5555
56// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/215456// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
57fn normalize(comptime T: type, significand: *@IntType(false, T.bit_count)) i32 {57fn normalize(comptime T: type, significand: *std.meta.IntType(false, T.bit_count)) i32 {
58 const Z = @IntType(false, T.bit_count);58 const Z = std.meta.IntType(false, T.bit_count);
59 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));59 const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
60 const significandBits = std.math.floatMantissaBits(T);60 const significandBits = std.math.floatMantissaBits(T);
61 const implicitBit = @as(Z, 1) << significandBits;61 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);
64 significand.* <<= @intCast(S, shift);64 significand.* <<= @intCast(S, shift);
65 return 1 - shift;65 return 1 - shift;
66}66}
6767
68// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/215468// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
69fn addXf3(comptime T: type, a: T, b: T) T {69fn addXf3(comptime T: type, a: T, b: T) T {
70 const Z = @IntType(false, T.bit_count);70 const Z = std.meta.IntType(false, T.bit_count);
71 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));71 const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
7272
73 const typeWidth = T.bit_count;73 const typeWidth = T.bit_count;
74 const significandBits = std.math.floatMantissaBits(T);74 const significandBits = std.math.floatMantissaBits(T);
...@@ -182,7 +182,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {...@@ -182,7 +182,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
182 // If partial cancellation occured, we need to left-shift the result182 // If partial cancellation occured, we need to left-shift the result
183 // and adjust the exponent:183 // and adjust the exponent:
184 if (aSignificand < implicitBit << 3) {184 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));
186 aSignificand <<= @intCast(S, shift);186 aSignificand <<= @intCast(S, shift);
187 aExponent -= shift;187 aExponent -= shift;
188 }188 }
lib/std/special/compiler_rt/compareXf2.zig+3-3
...@@ -22,8 +22,8 @@ const GE = extern enum(i32) {...@@ -22,8 +22,8 @@ const GE = extern enum(i32) {
22pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {22pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
23 @setRuntimeSafety(builtin.is_test);23 @setRuntimeSafety(builtin.is_test);
2424
25 const srep_t = @IntType(true, T.bit_count);25 const srep_t = std.meta.IntType(true, T.bit_count);
26 const rep_t = @IntType(false, T.bit_count);26 const rep_t = std.meta.IntType(false, T.bit_count);
2727
28 const significandBits = std.math.floatMantissaBits(T);28 const significandBits = std.math.floatMantissaBits(T);
29 const exponentBits = std.math.floatExponentBits(T);29 const exponentBits = std.math.floatExponentBits(T);
...@@ -68,7 +68,7 @@ pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {...@@ -68,7 +68,7 @@ pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
68pub fn unordcmp(comptime T: type, a: T, b: T) i32 {68pub fn unordcmp(comptime T: type, a: T, b: T) i32 {
69 @setRuntimeSafety(builtin.is_test);69 @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
73 const significandBits = std.math.floatMantissaBits(T);73 const significandBits = std.math.floatMantissaBits(T);
74 const exponentBits = std.math.floatExponentBits(T);74 const exponentBits = std.math.floatExponentBits(T);
lib/std/special/compiler_rt/divdf3.zig+4-4
...@@ -7,8 +7,8 @@ const builtin = @import("builtin");...@@ -7,8 +7,8 @@ const builtin = @import("builtin");
77
8pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {8pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
9 @setRuntimeSafety(builtin.is_test);9 @setRuntimeSafety(builtin.is_test);
10 const Z = @IntType(false, f64.bit_count);10 const Z = std.meta.IntType(false, f64.bit_count);
11 const SignedZ = @IntType(true, f64.bit_count);11 const SignedZ = std.meta.IntType(true, f64.bit_count);
1212
13 const typeWidth = f64.bit_count;13 const typeWidth = f64.bit_count;
14 const significandBits = std.math.floatMantissaBits(f64);14 const significandBits = std.math.floatMantissaBits(f64);
...@@ -312,9 +312,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -312,9 +312,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
312 }312 }
313}313}
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 {
316 @setRuntimeSafety(builtin.is_test);316 @setRuntimeSafety(builtin.is_test);
317 const Z = @IntType(false, T.bit_count);317 const Z = std.meta.IntType(false, T.bit_count);
318 const significandBits = std.math.floatMantissaBits(T);318 const significandBits = std.math.floatMantissaBits(T);
319 const implicitBit = @as(Z, 1) << significandBits;319 const implicitBit = @as(Z, 1) << significandBits;
320320
lib/std/special/compiler_rt/divsf3.zig+3-3
...@@ -7,7 +7,7 @@ const builtin = @import("builtin");...@@ -7,7 +7,7 @@ const builtin = @import("builtin");
77
8pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {8pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
9 @setRuntimeSafety(builtin.is_test);9 @setRuntimeSafety(builtin.is_test);
10 const Z = @IntType(false, f32.bit_count);10 const Z = std.meta.IntType(false, f32.bit_count);
1111
12 const typeWidth = f32.bit_count;12 const typeWidth = f32.bit_count;
13 const significandBits = std.math.floatMantissaBits(f32);13 const significandBits = std.math.floatMantissaBits(f32);
...@@ -185,9 +185,9 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {...@@ -185,9 +185,9 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
185 }185 }
186}186}
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 {
189 @setRuntimeSafety(builtin.is_test);189 @setRuntimeSafety(builtin.is_test);
190 const Z = @IntType(false, T.bit_count);190 const Z = std.meta.IntType(false, T.bit_count);
191 const significandBits = std.math.floatMantissaBits(T);191 const significandBits = std.math.floatMantissaBits(T);
192 const implicitBit = @as(Z, 1) << significandBits;192 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 {...@@ -30,11 +30,11 @@ pub fn __aeabi_f2d(arg: f32) callconv(.AAPCS) f64 {
3030
31const CHAR_BIT = 8;31const 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 {
34 @setRuntimeSafety(builtin.is_test);34 @setRuntimeSafety(builtin.is_test);
3535
36 const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits);36 const src_rep_t = std.meta.IntType(false, @typeInfo(src_t).Float.bits);
37 const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);37 const dst_rep_t = std.meta.IntType(false, @typeInfo(dst_t).Float.bits);
38 const srcSigBits = std.math.floatMantissaBits(src_t);38 const srcSigBits = std.math.floatMantissaBits(src_t);
39 const dstSigBits = std.math.floatMantissaBits(dst_t);39 const dstSigBits = std.math.floatMantissaBits(dst_t);
40 const SrcShift = std.math.Log2Int(src_rep_t);40 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 {...@@ -45,7 +45,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
45 if (exponent < 0) return 0;45 if (exponent < 0) return 0;
4646
47 // The unsigned result needs to be large enough to handle an fixint_t or rep_t47 // 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);
49 const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t;49 const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t;
50 var uint_result: UintResultType = undefined;50 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...@@ -10,7 +10,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
10 f128 => u128,10 f128 => u128,
11 else => unreachable,11 else => unreachable,
12 };12 };
13 const srep_t = @IntType(true, rep_t.bit_count);13 const srep_t = @import("std").meta.IntType(true, rep_t.bit_count);
14 const significandBits = switch (fp_t) {14 const significandBits = switch (fp_t) {
15 f32 => 23,15 f32 => 23,
16 f64 => 52,16 f64 => 52,
lib/std/special/compiler_rt/floatsiXf.zig+2-2
...@@ -5,8 +5,8 @@ const maxInt = std.math.maxInt;...@@ -5,8 +5,8 @@ const maxInt = std.math.maxInt;
5fn floatsiXf(comptime T: type, a: i32) T {5fn floatsiXf(comptime T: type, a: i32) T {
6 @setRuntimeSafety(builtin.is_test);6 @setRuntimeSafety(builtin.is_test);
77
8 const Z = @IntType(false, T.bit_count);8 const Z = std.meta.IntType(false, T.bit_count);
9 const S = @IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));9 const S = std.meta.IntType(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
1010
11 if (a == 0) {11 if (a == 0) {
12 return @as(T, 0.0);12 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 {...@@ -28,7 +28,7 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {
2828
29fn mulXf3(comptime T: type, a: T, b: T) T {29fn mulXf3(comptime T: type, a: T, b: T) T {
30 @setRuntimeSafety(builtin.is_test);30 @setRuntimeSafety(builtin.is_test);
31 const Z = @IntType(false, T.bit_count);31 const Z = std.meta.IntType(false, T.bit_count);
3232
33 const typeWidth = T.bit_count;33 const typeWidth = T.bit_count;
34 const significandBits = std.math.floatMantissaBits(T);34 const significandBits = std.math.floatMantissaBits(T);
...@@ -264,9 +264,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {...@@ -264,9 +264,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
264 }264 }
265}265}
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 {
268 @setRuntimeSafety(builtin.is_test);268 @setRuntimeSafety(builtin.is_test);
269 const Z = @IntType(false, T.bit_count);269 const Z = std.meta.IntType(false, T.bit_count);
270 const significandBits = std.math.floatMantissaBits(T);270 const significandBits = std.math.floatMantissaBits(T);
271 const implicitBit = @as(Z, 1) << significandBits;271 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 {...@@ -19,7 +19,7 @@ pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
19}19}
2020
21fn negXf2(comptime T: type, a: T) T {21fn 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
24 const typeWidth = T.bit_count;24 const typeWidth = T.bit_count;
25 const significandBits = std.math.floatMantissaBits(T);25 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 {...@@ -36,8 +36,8 @@ pub fn __aeabi_f2h(a: f32) callconv(.AAPCS) u16 {
36}36}
3737
38inline fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {38inline 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);39 const src_rep_t = std.meta.IntType(false, @typeInfo(src_t).Float.bits);
40 const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);40 const dst_rep_t = std.meta.IntType(false, @typeInfo(dst_t).Float.bits);
41 const srcSigBits = std.math.floatMantissaBits(src_t);41 const srcSigBits = std.math.floatMantissaBits(src_t);
42 const dstSigBits = std.math.floatMantissaBits(dst_t);42 const dstSigBits = std.math.floatMantissaBits(dst_t);
43 const SrcShift = std.math.Log2Int(src_rep_t);43 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;...@@ -10,8 +10,8 @@ const high = 1 - low;
10pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {10pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {
11 @setRuntimeSafety(is_test);11 @setRuntimeSafety(is_test);
1212
13 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));13 const SingleInt = @import("std").meta.IntType(false, @divExact(DoubleInt.bit_count, 2));
14 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);14 const SignedDoubleInt = @import("std").meta.IntType(true, DoubleInt.bit_count);
15 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);15 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
1616
17 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #42117 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) {...@@ -222,7 +222,7 @@ pub const Target = union(enum) {
222 pub const needed_bit_count = 154;222 pub const needed_bit_count = 154;
223 pub const byte_count = (needed_bit_count + 7) / 8;223 pub const byte_count = (needed_bit_count + 7) / 8;
224 pub const usize_count = (byte_count + (@sizeOf(usize) - 1)) / @sizeOf(usize);224 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)));
226 pub const ShiftInt = std.math.Log2Int(usize);226 pub const ShiftInt = std.math.Log2Int(usize);
227227
228 pub const empty = Set{ .ints = [1]usize{0} ** usize_count };228 pub const empty = Set{ .ints = [1]usize{0} ** usize_count };
lib/std/thread.zig+3-3
...@@ -148,7 +148,7 @@ pub const Thread = struct {...@@ -148,7 +148,7 @@ pub const Thread = struct {
148 const default_stack_size = 16 * 1024 * 1024;148 const default_stack_size = 16 * 1024 * 1024;
149149
150 const Context = @TypeOf(context);150 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
153 if (builtin.os == builtin.Os.windows) {153 if (builtin.os == builtin.Os.windows) {
154 const WinThread = struct {154 const WinThread = struct {
...@@ -158,7 +158,7 @@ pub const Thread = struct {...@@ -158,7 +158,7 @@ pub const Thread = struct {
158 };158 };
159 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {159 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {
160 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;160 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)) {
162 .Int => {162 .Int => {
163 return startFn(arg);163 return startFn(arg);
164 },164 },
...@@ -201,7 +201,7 @@ pub const Thread = struct {...@@ -201,7 +201,7 @@ pub const Thread = struct {
201 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {201 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {
202 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;202 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)) {
205 .Int => {205 .Int => {
206 return startFn(arg);206 return startFn(arg);
207 },207 },
lib/std/zig/ast.zig+12-16
...@@ -457,10 +457,9 @@ pub const Node = struct {...@@ -457,10 +457,9 @@ pub const Node = struct {
457 }457 }
458458
459 pub fn iterate(base: *Node, index: usize) ?*Node {459 pub fn iterate(base: *Node, index: usize) ?*Node {
460 comptime var i = 0;460 inline for (@typeInfo(Id).Enum.fields) |f| {
461 inline while (i < @memberCount(Id)) : (i += 1) {461 if (base.id == @field(Id, f.name)) {
462 if (base.id == @field(Id, @memberName(Id, i))) {462 const T = @field(Node, f.name);
463 const T = @field(Node, @memberName(Id, i));
464 return @fieldParentPtr(T, "base", base).iterate(index);463 return @fieldParentPtr(T, "base", base).iterate(index);
465 }464 }
466 }465 }
...@@ -468,10 +467,9 @@ pub const Node = struct {...@@ -468,10 +467,9 @@ pub const Node = struct {
468 }467 }
469468
470 pub fn firstToken(base: *const Node) TokenIndex {469 pub fn firstToken(base: *const Node) TokenIndex {
471 comptime var i = 0;470 inline for (@typeInfo(Id).Enum.fields) |f| {
472 inline while (i < @memberCount(Id)) : (i += 1) {471 if (base.id == @field(Id, f.name)) {
473 if (base.id == @field(Id, @memberName(Id, i))) {472 const T = @field(Node, f.name);
474 const T = @field(Node, @memberName(Id, i));
475 return @fieldParentPtr(T, "base", base).firstToken();473 return @fieldParentPtr(T, "base", base).firstToken();
476 }474 }
477 }475 }
...@@ -479,10 +477,9 @@ pub const Node = struct {...@@ -479,10 +477,9 @@ pub const Node = struct {
479 }477 }
480478
481 pub fn lastToken(base: *const Node) TokenIndex {479 pub fn lastToken(base: *const Node) TokenIndex {
482 comptime var i = 0;480 inline for (@typeInfo(Id).Enum.fields) |f| {
483 inline while (i < @memberCount(Id)) : (i += 1) {481 if (base.id == @field(Id, f.name)) {
484 if (base.id == @field(Id, @memberName(Id, i))) {482 const T = @field(Node, f.name);
485 const T = @field(Node, @memberName(Id, i));
486 return @fieldParentPtr(T, "base", base).lastToken();483 return @fieldParentPtr(T, "base", base).lastToken();
487 }484 }
488 }485 }
...@@ -490,10 +487,9 @@ pub const Node = struct {...@@ -490,10 +487,9 @@ pub const Node = struct {
490 }487 }
491488
492 pub fn typeToId(comptime T: type) Id {489 pub fn typeToId(comptime T: type) Id {
493 comptime var i = 0;490 inline for (@typeInfo(Id).Enum.fields) |f| {
494 inline while (i < @memberCount(Id)) : (i += 1) {491 if (T == @field(Node, f.name)) {
495 if (T == @field(Node, @memberName(Id, i))) {492 return @field(Id, f.name);
496 return @field(Id, @memberName(Id, i));
497 }493 }
498 }494 }
499 unreachable;495 unreachable;
lib/std/zig/parser_test.zig+1-1
...@@ -1410,7 +1410,7 @@ test "zig fmt: same-line comment after non-block if expression" {...@@ -1410,7 +1410,7 @@ test "zig fmt: same-line comment after non-block if expression" {
1410test "zig fmt: same-line comment on comptime expression" {1410test "zig fmt: same-line comment on comptime expression" {
1411 try testCanonical(1411 try testCanonical(
1412 \\test "" {1412 \\test "" {
1413 \\ comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt1413 \\ comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
1414 \\}1414 \\}
1415 \\1415 \\
1416 );1416 );
lib/std/zig/render.zig+1-2
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const assert = std.debug.assert;2const assert = std.debug.assert;
4const mem = std.mem;3const mem = std.mem;
5const ast = std.zig.ast;4const ast = std.zig.ast;
...@@ -14,7 +13,7 @@ pub const Error = error{...@@ -14,7 +13,7 @@ pub const Error = error{
1413
15/// Returns whether anything changed14/// Returns whether anything changed
16pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool {15pub 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
19 var anything_changed: bool = false;18 var anything_changed: bool = false;
2019
src-self-hosted/ir.zig+17-22
...@@ -76,20 +76,18 @@ pub const Inst = struct {...@@ -76,20 +76,18 @@ pub const Inst = struct {
76 }76 }
7777
78 pub fn typeToId(comptime T: type) Id {78 pub fn typeToId(comptime T: type) Id {
79 comptime var i = 0;79 inline for (@typeInfo(Id).Enum.fields) |f| {
80 inline while (i < @memberCount(Id)) : (i += 1) {80 if (T == @field(Inst, f.name)) {
81 if (T == @field(Inst, @memberName(Id, i))) {81 return @field(Id, f.name);
82 return @field(Id, @memberName(Id, i));
83 }82 }
84 }83 }
85 unreachable;84 unreachable;
86 }85 }
8786
88 pub fn dump(base: *const Inst) void {87 pub fn dump(base: *const Inst) void {
89 comptime var i = 0;88 inline for (@typeInfo(Id).Enum.fields) |f| {
90 inline while (i < @memberCount(Id)) : (i += 1) {89 if (base.id == @field(Id, f.name)) {
91 if (base.id == @field(Id, @memberName(Id, i))) {90 const T = @field(Inst, f.name);
92 const T = @field(Inst, @memberName(Id, i));
93 std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });91 std.debug.warn("#{} = {}(", .{ base.debug_id, @tagName(base.id) });
94 @fieldParentPtr(T, "base", base).dump();92 @fieldParentPtr(T, "base", base).dump();
95 std.debug.warn(")", .{});93 std.debug.warn(")", .{});
...@@ -100,10 +98,9 @@ pub const Inst = struct {...@@ -100,10 +98,9 @@ pub const Inst = struct {
100 }98 }
10199
102 pub fn hasSideEffects(base: *const Inst) bool {100 pub fn hasSideEffects(base: *const Inst) bool {
103 comptime var i = 0;101 inline for (@typeInfo(Id).Enum.fields) |f| {
104 inline while (i < @memberCount(Id)) : (i += 1) {102 if (base.id == @field(Id, f.name)) {
105 if (base.id == @field(Id, @memberName(Id, i))) {103 const T = @field(Inst, f.name);
106 const T = @field(Inst, @memberName(Id, i));
107 return @fieldParentPtr(T, "base", base).hasSideEffects();104 return @fieldParentPtr(T, "base", base).hasSideEffects();
108 }105 }
109 }106 }
...@@ -1805,21 +1802,19 @@ pub const Builder = struct {...@@ -1805,21 +1802,19 @@ pub const Builder = struct {
1805 };1802 };
18061803
1807 // Look at the params and ref() other instructions1804 // Look at the params and ref() other instructions
1808 comptime var i = 0;1805 inline for (@typeInfo(I.Params).Struct.fields) |f| {
1809 inline while (i < @memberCount(I.Params)) : (i += 1) {1806 switch (f.fiedl_type) {
1810 const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));1807 *Inst => @field(inst.params, f.name).ref(self),
1811 switch (FieldType) {1808 *BasicBlock => @field(inst.params, f.name).ref(self),
1812 *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),1809 ?*Inst => if (@field(inst.params, f.name)) |other| other.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),
1815 []*Inst => {1810 []*Inst => {
1816 // TODO https://github.com/ziglang/zig/issues/12691811 // 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|
1818 other.ref(self);1813 other.ref(self);
1819 },1814 },
1820 []*BasicBlock => {1815 []*BasicBlock => {
1821 // TODO https://github.com/ziglang/zig/issues/12691816 // 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|
1823 other.ref(self);1818 other.ref(self);
1824 },1819 },
1825 Type.Pointer.Mut,1820 Type.Pointer.Mut,
...@@ -1831,7 +1826,7 @@ pub const Builder = struct {...@@ -1831,7 +1826,7 @@ pub const Builder = struct {
1831 => {},1826 => {},
1832 // it's ok to add more types here, just make sure that1827 // it's ok to add more types here, just make sure that
1833 // any instructions and basic blocks are ref'd appropriately1828 // 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)),
1835 }1830 }
1836 }1831 }
18371832
src-self-hosted/translate_c.zig+4-4
...@@ -5381,15 +5381,15 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5381,15 +5381,15 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5381 return error.ParseError;5381 return error.ParseError;
5382 }5382 }
53835383
5384 //if (@typeId(@TypeOf(x)) == .Pointer)5384 //if (@typeInfo(@TypeOf(x)) == .Pointer)
5385 // @ptrCast(dest, x)5385 // @ptrCast(dest, x)
5386 //else if (@typeId(@TypeOf(x)) == .Integer)5386 //else if (@typeInfo(@TypeOf(x)) == .Integer)
5387 // @intToPtr(dest, x)5387 // @intToPtr(dest, x)
5388 //else5388 //else
5389 // @as(dest, x)5389 // @as(dest, x)
53905390
5391 const if_1 = try transCreateNodeIf(c);5391 const if_1 = try transCreateNodeIf(c);
5392 const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeId");5392 const type_id_1 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
5393 const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");5393 const type_of_1 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
5394 try type_id_1.params.push(&type_of_1.base);5394 try type_id_1.params.push(&type_of_1.base);
5395 try type_of_1.params.push(node_to_cast);5395 try type_of_1.params.push(node_to_cast);
...@@ -5416,7 +5416,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,...@@ -5416,7 +5416,7 @@ fn parseCPrimaryExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
5416 if_1.@"else" = else_1;5416 if_1.@"else" = else_1;
54175417
5418 const if_2 = try transCreateNodeIf(c);5418 const if_2 = try transCreateNodeIf(c);
5419 const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeId");5419 const type_id_2 = try transCreateNodeBuiltinFnCall(c, "@typeInfo");
5420 const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");5420 const type_of_2 = try transCreateNodeBuiltinFnCall(c, "@TypeOf");
5421 try type_id_2.params.push(&type_of_2.base);5421 try type_id_2.params.push(&type_of_2.base);
5422 try type_of_2.params.push(node_to_cast);5422 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 {...@@ -1042,7 +1042,7 @@ fn hashAny(x: var, comptime seed: u64) u32 {
1042 switch (@typeInfo(@TypeOf(x))) {1042 switch (@typeInfo(@TypeOf(x))) {
1043 .Int => |info| {1043 .Int => |info| {
1044 comptime var rng = comptime std.rand.DefaultPrng.init(seed);1044 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);
1046 if (info.bits <= 32) {1046 if (info.bits <= 32) {
1047 return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);1047 return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);
1048 } else {1048 } else {
src/all_types.hpp-44
...@@ -1695,9 +1695,6 @@ enum BuiltinFnId {...@@ -1695,9 +1695,6 @@ enum BuiltinFnId {
1695 BuiltinFnIdMemset,1695 BuiltinFnIdMemset,
1696 BuiltinFnIdSizeof,1696 BuiltinFnIdSizeof,
1697 BuiltinFnIdAlignOf,1697 BuiltinFnIdAlignOf,
1698 BuiltinFnIdMemberCount,
1699 BuiltinFnIdMemberType,
1700 BuiltinFnIdMemberName,
1701 BuiltinFnIdField,1698 BuiltinFnIdField,
1702 BuiltinFnIdTypeInfo,1699 BuiltinFnIdTypeInfo,
1703 BuiltinFnIdType,1700 BuiltinFnIdType,
...@@ -1757,7 +1754,6 @@ enum BuiltinFnId {...@@ -1757,7 +1754,6 @@ enum BuiltinFnId {
1757 BuiltinFnIdIntToErr,1754 BuiltinFnIdIntToErr,
1758 BuiltinFnIdEnumToInt,1755 BuiltinFnIdEnumToInt,
1759 BuiltinFnIdIntToEnum,1756 BuiltinFnIdIntToEnum,
1760 BuiltinFnIdIntType,
1761 BuiltinFnIdVectorType,1757 BuiltinFnIdVectorType,
1762 BuiltinFnIdShuffle,1758 BuiltinFnIdShuffle,
1763 BuiltinFnIdSplat,1759 BuiltinFnIdSplat,
...@@ -1777,7 +1773,6 @@ enum BuiltinFnId {...@@ -1777,7 +1773,6 @@ enum BuiltinFnId {
1777 BuiltinFnIdBitOffsetOf,1773 BuiltinFnIdBitOffsetOf,
1778 BuiltinFnIdNewStackCall,1774 BuiltinFnIdNewStackCall,
1779 BuiltinFnIdAsyncCall,1775 BuiltinFnIdAsyncCall,
1780 BuiltinFnIdTypeId,
1781 BuiltinFnIdShlExact,1776 BuiltinFnIdShlExact,
1782 BuiltinFnIdShrExact,1777 BuiltinFnIdShrExact,
1783 BuiltinFnIdSetEvalBranchQuota,1778 BuiltinFnIdSetEvalBranchQuota,
...@@ -1785,7 +1780,6 @@ enum BuiltinFnId {...@@ -1785,7 +1780,6 @@ enum BuiltinFnId {
1785 BuiltinFnIdOpaqueType,1780 BuiltinFnIdOpaqueType,
1786 BuiltinFnIdThis,1781 BuiltinFnIdThis,
1787 BuiltinFnIdSetAlignStack,1782 BuiltinFnIdSetAlignStack,
1788 BuiltinFnIdArgType,
1789 BuiltinFnIdExport,1783 BuiltinFnIdExport,
1790 BuiltinFnIdErrorReturnTrace,1784 BuiltinFnIdErrorReturnTrace,
1791 BuiltinFnIdAtomicRmw,1785 BuiltinFnIdAtomicRmw,
...@@ -2630,7 +2624,6 @@ enum IrInstSrcId {...@@ -2630,7 +2624,6 @@ enum IrInstSrcId {
2630 IrInstSrcIdIntToFloat,2624 IrInstSrcIdIntToFloat,
2631 IrInstSrcIdFloatToInt,2625 IrInstSrcIdFloatToInt,
2632 IrInstSrcIdBoolToInt,2626 IrInstSrcIdBoolToInt,
2633 IrInstSrcIdIntType,
2634 IrInstSrcIdVectorType,2627 IrInstSrcIdVectorType,
2635 IrInstSrcIdShuffleVector,2628 IrInstSrcIdShuffleVector,
2636 IrInstSrcIdSplat,2629 IrInstSrcIdSplat,
...@@ -2638,9 +2631,6 @@ enum IrInstSrcId {...@@ -2638,9 +2631,6 @@ enum IrInstSrcId {
2638 IrInstSrcIdMemset,2631 IrInstSrcIdMemset,
2639 IrInstSrcIdMemcpy,2632 IrInstSrcIdMemcpy,
2640 IrInstSrcIdSlice,2633 IrInstSrcIdSlice,
2641 IrInstSrcIdMemberCount,
2642 IrInstSrcIdMemberType,
2643 IrInstSrcIdMemberName,
2644 IrInstSrcIdBreakpoint,2634 IrInstSrcIdBreakpoint,
2645 IrInstSrcIdReturnAddress,2635 IrInstSrcIdReturnAddress,
2646 IrInstSrcIdFrameAddress,2636 IrInstSrcIdFrameAddress,
...@@ -2677,7 +2667,6 @@ enum IrInstSrcId {...@@ -2677,7 +2667,6 @@ enum IrInstSrcId {
2677 IrInstSrcIdTypeInfo,2667 IrInstSrcIdTypeInfo,
2678 IrInstSrcIdType,2668 IrInstSrcIdType,
2679 IrInstSrcIdHasField,2669 IrInstSrcIdHasField,
2680 IrInstSrcIdTypeId,
2681 IrInstSrcIdSetEvalBranchQuota,2670 IrInstSrcIdSetEvalBranchQuota,
2682 IrInstSrcIdPtrType,2671 IrInstSrcIdPtrType,
2683 IrInstSrcIdAlignCast,2672 IrInstSrcIdAlignCast,
...@@ -3636,13 +3625,6 @@ struct IrInstSrcBoolToInt {...@@ -3636,13 +3625,6 @@ struct IrInstSrcBoolToInt {
3636 IrInstSrc *target;3625 IrInstSrc *target;
3637};3626};
36383627
3639struct IrInstSrcIntType {
3640 IrInstSrc base;
3641
3642 IrInstSrc *is_signed;
3643 IrInstSrc *bit_count;
3644};
3645
3646struct IrInstSrcVectorType {3628struct IrInstSrcVectorType {
3647 IrInstSrc base;3629 IrInstSrc base;
36483630
...@@ -3715,26 +3697,6 @@ struct IrInstGenSlice {...@@ -3715,26 +3697,6 @@ struct IrInstGenSlice {
3715 bool safety_check_on;3697 bool safety_check_on;
3716};3698};
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
3738struct IrInstSrcBreakpoint {3700struct IrInstSrcBreakpoint {
3739 IrInstSrc base;3701 IrInstSrc base;
3740};3702};
...@@ -4142,12 +4104,6 @@ struct IrInstSrcHasField {...@@ -4142,12 +4104,6 @@ struct IrInstSrcHasField {
4142 IrInstSrc *field_name;4104 IrInstSrc *field_name;
4143};4105};
41444106
4145struct IrInstSrcTypeId {
4146 IrInstSrc base;
4147
4148 IrInstSrc *type_value;
4149};
4150
4151struct IrInstSrcSetEvalBranchQuota {4107struct IrInstSrcSetEvalBranchQuota {
4152 IrInstSrc base;4108 IrInstSrc base;
41534109
src/codegen.cpp-6
...@@ -8152,9 +8152,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8152,9 +8152,6 @@ static void define_builtin_fns(CodeGen *g) {
8152 create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);8152 create_builtin_fn(g, BuiltinFnIdMemset, "memset", 3);
8153 create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);8153 create_builtin_fn(g, BuiltinFnIdSizeof, "sizeOf", 1);
8154 create_builtin_fn(g, BuiltinFnIdAlignOf, "alignOf", 1);8154 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);
8158 create_builtin_fn(g, BuiltinFnIdField, "field", 2);8155 create_builtin_fn(g, BuiltinFnIdField, "field", 2);
8159 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);8156 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
8160 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);8157 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
...@@ -8192,7 +8189,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8192,7 +8189,6 @@ static void define_builtin_fns(CodeGen *g) {
8192 create_builtin_fn(g, BuiltinFnIdIntToEnum, "intToEnum", 2);8189 create_builtin_fn(g, BuiltinFnIdIntToEnum, "intToEnum", 2);
8193 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);8190 create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
8194 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);8191 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
8195 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
8196 create_builtin_fn(g, BuiltinFnIdVectorType, "Vector", 2);8192 create_builtin_fn(g, BuiltinFnIdVectorType, "Vector", 2);
8197 create_builtin_fn(g, BuiltinFnIdShuffle, "shuffle", 4);8193 create_builtin_fn(g, BuiltinFnIdShuffle, "shuffle", 4);
8198 create_builtin_fn(g, BuiltinFnIdSplat, "splat", 2);8194 create_builtin_fn(g, BuiltinFnIdSplat, "splat", 2);
...@@ -8231,14 +8227,12 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8231,14 +8227,12 @@ static void define_builtin_fns(CodeGen *g) {
8231 create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);8227 create_builtin_fn(g, BuiltinFnIdMulAdd, "mulAdd", 4);
8232 create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);8228 create_builtin_fn(g, BuiltinFnIdNewStackCall, "newStackCall", SIZE_MAX);
8233 create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);8229 create_builtin_fn(g, BuiltinFnIdAsyncCall, "asyncCall", SIZE_MAX);
8234 create_builtin_fn(g, BuiltinFnIdTypeId, "typeId", 1);
8235 create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);8230 create_builtin_fn(g, BuiltinFnIdShlExact, "shlExact", 2);
8236 create_builtin_fn(g, BuiltinFnIdShrExact, "shrExact", 2);8231 create_builtin_fn(g, BuiltinFnIdShrExact, "shrExact", 2);
8237 create_builtin_fn(g, BuiltinFnIdSetEvalBranchQuota, "setEvalBranchQuota", 1);8232 create_builtin_fn(g, BuiltinFnIdSetEvalBranchQuota, "setEvalBranchQuota", 1);
8238 create_builtin_fn(g, BuiltinFnIdAlignCast, "alignCast", 2);8233 create_builtin_fn(g, BuiltinFnIdAlignCast, "alignCast", 2);
8239 create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);8234 create_builtin_fn(g, BuiltinFnIdOpaqueType, "OpaqueType", 0);
8240 create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);8235 create_builtin_fn(g, BuiltinFnIdSetAlignStack, "setAlignStack", 1);
8241 create_builtin_fn(g, BuiltinFnIdArgType, "ArgType", 2);
8242 create_builtin_fn(g, BuiltinFnIdExport, "export", 2);8236 create_builtin_fn(g, BuiltinFnIdExport, "export", 2);
8243 create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);8237 create_builtin_fn(g, BuiltinFnIdErrorReturnTrace, "errorReturnTrace", 0);
8244 create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);8238 create_builtin_fn(g, BuiltinFnIdAtomicRmw, "atomicRmw", 5);
src/ir.cpp-348
...@@ -389,8 +389,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {...@@ -389,8 +389,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
389 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));389 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
390 case IrInstSrcIdBoolToInt:390 case IrInstSrcIdBoolToInt:
391 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));391 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
392 case IrInstSrcIdIntType:
393 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
394 case IrInstSrcIdVectorType:392 case IrInstSrcIdVectorType:
395 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));393 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
396 case IrInstSrcIdShuffleVector:394 case IrInstSrcIdShuffleVector:
...@@ -405,12 +403,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {...@@ -405,12 +403,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
405 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));403 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
406 case IrInstSrcIdSlice:404 case IrInstSrcIdSlice:
407 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));405 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));
414 case IrInstSrcIdBreakpoint:406 case IrInstSrcIdBreakpoint:
415 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));407 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
416 case IrInstSrcIdReturnAddress:408 case IrInstSrcIdReturnAddress:
...@@ -477,8 +469,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {...@@ -477,8 +469,6 @@ static void destroy_instruction_src(IrInstSrc *inst) {
477 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));469 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
478 case IrInstSrcIdHasField:470 case IrInstSrcIdHasField:
479 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));471 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
480 case IrInstSrcIdTypeId:
481 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
482 case IrInstSrcIdSetEvalBranchQuota:472 case IrInstSrcIdSetEvalBranchQuota:
483 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));473 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
484 case IrInstSrcIdAlignCast:474 case IrInstSrcIdAlignCast:
...@@ -1293,10 +1283,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {...@@ -1293,10 +1283,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
1293 return IrInstSrcIdBoolToInt;1283 return IrInstSrcIdBoolToInt;
1294}1284}
12951285
1296static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
1297 return IrInstSrcIdIntType;
1298}
1299
1300static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {1286static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
1301 return IrInstSrcIdVectorType;1287 return IrInstSrcIdVectorType;
1302}1288}
...@@ -1325,18 +1311,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {...@@ -1325,18 +1311,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
1325 return IrInstSrcIdSlice;1311 return IrInstSrcIdSlice;
1326}1312}
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
1340static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {1314static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
1341 return IrInstSrcIdBreakpoint;1315 return IrInstSrcIdBreakpoint;
1342}1316}
...@@ -1481,10 +1455,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {...@@ -1481,10 +1455,6 @@ static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
1481 return IrInstSrcIdHasField;1455 return IrInstSrcIdHasField;
1482}1456}
14831457
1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1485 return IrInstSrcIdTypeId;
1486}
1487
1488static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {1458static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
1489 return IrInstSrcIdSetEvalBranchQuota;1459 return IrInstSrcIdSetEvalBranchQuota;
1490}1460}
...@@ -3542,19 +3512,6 @@ static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode...@@ -3542,19 +3512,6 @@ static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode
3542 return &instruction->base;3512 return &instruction->base;
3543}3513}
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
3558static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,3515static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
3559 IrInstSrc *elem_type)3516 IrInstSrc *elem_type)
3560{3517{
...@@ -3749,41 +3706,6 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,...@@ -3749,41 +3706,6 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction,
3749 return &instruction->base;3706 return &instruction->base;
3750}3707}
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
3787static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {3709static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3788 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);3710 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
3789 return &instruction->base;3711 return &instruction->base;
...@@ -4458,15 +4380,6 @@ static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source...@@ -4458,15 +4380,6 @@ static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source
4458 return &instruction->base;4380 return &instruction->base;
4459}4381}
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
4470static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,4383static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4471 IrInstSrc *new_quota)4384 IrInstSrc *new_quota)
4472{4385{
...@@ -6598,21 +6511,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod...@@ -6598,21 +6511,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
6598 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);6511 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
6599 return ir_lval_wrap(irb, scope, result, lval, result_loc);6512 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6600 }6513 }
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 }
6616 case BuiltinFnIdVectorType:6514 case BuiltinFnIdVectorType:
6617 {6515 {
6618 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6516 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...@@ -6710,48 +6608,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
6710 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);6608 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
6711 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);6609 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
6712 }6610 }
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 }
6755 case BuiltinFnIdField:6611 case BuiltinFnIdField:
6756 {6612 {
6757 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6613 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...@@ -7109,16 +6965,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
7109 }6965 }
7110 case BuiltinFnIdAsyncCall:6966 case BuiltinFnIdAsyncCall:
7111 return ir_gen_async_call(irb, scope, nullptr, node, lval, result_loc);6967 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 }
7122 case BuiltinFnIdShlExact:6968 case BuiltinFnIdShlExact:
7123 {6969 {
7124 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6970 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...@@ -7194,21 +7040,6 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
7194 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);7040 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
7195 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);7041 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
7196 }7042 }
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 }
7212 case BuiltinFnIdExport:7043 case BuiltinFnIdExport:
7213 {7044 {
7214 // Cast the options parameter to the options type7045 // Cast the options parameter to the options type
...@@ -24795,19 +24626,6 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins...@@ -24795,19 +24626,6 @@ static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *ins
24795 return ir_const_type(ira, &instruction->base.base, type);24626 return ir_const_type(ira, &instruction->base.base, type);
24796}24627}
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
24811static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,24629static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
24812 IrInstSrcSetEvalBranchQuota *instruction)24630 IrInstSrcSetEvalBranchQuota *instruction)
24813{24631{
...@@ -25518,20 +25336,6 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo...@@ -25518,20 +25336,6 @@ static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBo
25518 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);25336 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
25519}25337}
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
25535static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {25339static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
25536 uint64_t len;25340 uint64_t len;
25537 if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))25341 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...@@ -26445,143 +26249,6 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
26445 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);26249 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
26446}26250}
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
26585static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {26252static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
26586 Error err;26253 Error err;
26587 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);26254 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...@@ -29540,8 +29207,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
29540 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);29207 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
29541 case IrInstSrcIdBoolToInt:29208 case IrInstSrcIdBoolToInt:
29542 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);29209 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
29543 case IrInstSrcIdIntType:
29544 return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
29545 case IrInstSrcIdVectorType:29210 case IrInstSrcIdVectorType:
29546 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);29211 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
29547 case IrInstSrcIdShuffleVector:29212 case IrInstSrcIdShuffleVector:
...@@ -29556,12 +29221,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc...@@ -29556,12 +29221,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
29556 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);29221 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
29557 case IrInstSrcIdSlice:29222 case IrInstSrcIdSlice:
29558 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);29223 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);
29565 case IrInstSrcIdBreakpoint:29224 case IrInstSrcIdBreakpoint:
29566 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);29225 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
29567 case IrInstSrcIdReturnAddress:29226 case IrInstSrcIdReturnAddress:
...@@ -29616,8 +29275,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc...@@ -29616,8 +29275,6 @@ static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruc
29616 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);29275 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
29617 case IrInstSrcIdHasField:29276 case IrInstSrcIdHasField:
29618 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);29277 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
29619 case IrInstSrcIdTypeId:
29620 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
29621 case IrInstSrcIdSetEvalBranchQuota:29278 case IrInstSrcIdSetEvalBranchQuota:
29622 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);29279 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
29623 case IrInstSrcIdPtrType:29280 case IrInstSrcIdPtrType:
...@@ -30032,15 +29689,11 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {...@@ -30032,15 +29689,11 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
30032 case IrInstSrcIdRef:29689 case IrInstSrcIdRef:
30033 case IrInstSrcIdEmbedFile:29690 case IrInstSrcIdEmbedFile:
30034 case IrInstSrcIdTruncate:29691 case IrInstSrcIdTruncate:
30035 case IrInstSrcIdIntType:
30036 case IrInstSrcIdVectorType:29692 case IrInstSrcIdVectorType:
30037 case IrInstSrcIdShuffleVector:29693 case IrInstSrcIdShuffleVector:
30038 case IrInstSrcIdSplat:29694 case IrInstSrcIdSplat:
30039 case IrInstSrcIdBoolNot:29695 case IrInstSrcIdBoolNot:
30040 case IrInstSrcIdSlice:29696 case IrInstSrcIdSlice:
30041 case IrInstSrcIdMemberCount:
30042 case IrInstSrcIdMemberType:
30043 case IrInstSrcIdMemberName:
30044 case IrInstSrcIdAlignOf:29697 case IrInstSrcIdAlignOf:
30045 case IrInstSrcIdReturnAddress:29698 case IrInstSrcIdReturnAddress:
30046 case IrInstSrcIdFrameAddress:29699 case IrInstSrcIdFrameAddress:
...@@ -30067,7 +29720,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {...@@ -30067,7 +29720,6 @@ bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
30067 case IrInstSrcIdTypeInfo:29720 case IrInstSrcIdTypeInfo:
30068 case IrInstSrcIdType:29721 case IrInstSrcIdType:
30069 case IrInstSrcIdHasField:29722 case IrInstSrcIdHasField:
30070 case IrInstSrcIdTypeId:
30071 case IrInstSrcIdAlignCast:29723 case IrInstSrcIdAlignCast:
30072 case IrInstSrcIdImplicitCast:29724 case IrInstSrcIdImplicitCast:
30073 case IrInstSrcIdResolveResult:29725 case IrInstSrcIdResolveResult:
src/ir_print.cpp-61
...@@ -179,8 +179,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {...@@ -179,8 +179,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
179 return "SrcFloatToInt";179 return "SrcFloatToInt";
180 case IrInstSrcIdBoolToInt:180 case IrInstSrcIdBoolToInt:
181 return "SrcBoolToInt";181 return "SrcBoolToInt";
182 case IrInstSrcIdIntType:
183 return "SrcIntType";
184 case IrInstSrcIdVectorType:182 case IrInstSrcIdVectorType:
185 return "SrcVectorType";183 return "SrcVectorType";
186 case IrInstSrcIdBoolNot:184 case IrInstSrcIdBoolNot:
...@@ -191,12 +189,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {...@@ -191,12 +189,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
191 return "SrcMemcpy";189 return "SrcMemcpy";
192 case IrInstSrcIdSlice:190 case IrInstSrcIdSlice:
193 return "SrcSlice";191 return "SrcSlice";
194 case IrInstSrcIdMemberCount:
195 return "SrcMemberCount";
196 case IrInstSrcIdMemberType:
197 return "SrcMemberType";
198 case IrInstSrcIdMemberName:
199 return "SrcMemberName";
200 case IrInstSrcIdBreakpoint:192 case IrInstSrcIdBreakpoint:
201 return "SrcBreakpoint";193 return "SrcBreakpoint";
202 case IrInstSrcIdReturnAddress:194 case IrInstSrcIdReturnAddress:
...@@ -269,8 +261,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {...@@ -269,8 +261,6 @@ const char* ir_inst_src_type_str(IrInstSrcId id) {
269 return "SrcType";261 return "SrcType";
270 case IrInstSrcIdHasField:262 case IrInstSrcIdHasField:
271 return "SrcHasField";263 return "SrcHasField";
272 case IrInstSrcIdTypeId:
273 return "SrcTypeId";
274 case IrInstSrcIdSetEvalBranchQuota:264 case IrInstSrcIdSetEvalBranchQuota:
275 return "SrcSetEvalBranchQuota";265 return "SrcSetEvalBranchQuota";
276 case IrInstSrcIdPtrType:266 case IrInstSrcIdPtrType:
...@@ -1660,14 +1650,6 @@ static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instructio...@@ -1660,14 +1650,6 @@ static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instructio
1660 fprintf(irp->f, ")");1650 fprintf(irp->f, ")");
1661}1651}
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
1671static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {1653static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
1672 fprintf(irp->f, "@Vector(");1654 fprintf(irp->f, "@Vector(");
1673 ir_print_other_inst_src(irp, instruction->len);1655 ir_print_other_inst_src(irp, instruction->len);
...@@ -1784,28 +1766,6 @@ static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {...@@ -1784,28 +1766,6 @@ static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
1784 ir_print_other_inst_gen(irp, instruction->result_loc);1766 ir_print_other_inst_gen(irp, instruction->result_loc);
1785}1767}
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
1809static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {1769static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
1810 fprintf(irp->f, "@breakpoint()");1770 fprintf(irp->f, "@breakpoint()");
1811}1771}
...@@ -2279,12 +2239,6 @@ static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction)...@@ -2279,12 +2239,6 @@ static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction)
2279 fprintf(irp->f, ")");2239 fprintf(irp->f, ")");
2280}2240}
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
2288static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {2242static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
2289 fprintf(irp->f, "@setEvalBranchQuota(");2243 fprintf(irp->f, "@setEvalBranchQuota(");
2290 ir_print_other_inst_src(irp, instruction->new_quota);2244 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...@@ -2775,9 +2729,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
2775 case IrInstSrcIdBoolToInt:2729 case IrInstSrcIdBoolToInt:
2776 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);2730 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
2777 break;2731 break;
2778 case IrInstSrcIdIntType:
2779 ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
2780 break;
2781 case IrInstSrcIdVectorType:2732 case IrInstSrcIdVectorType:
2782 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);2733 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
2783 break;2734 break;
...@@ -2799,15 +2750,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai...@@ -2799,15 +2750,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
2799 case IrInstSrcIdSlice:2750 case IrInstSrcIdSlice:
2800 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);2751 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
2801 break;2752 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;
2811 case IrInstSrcIdBreakpoint:2753 case IrInstSrcIdBreakpoint:
2812 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);2754 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
2813 break;2755 break;
...@@ -2907,9 +2849,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai...@@ -2907,9 +2849,6 @@ static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trai
2907 case IrInstSrcIdHasField:2849 case IrInstSrcIdHasField:
2908 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);2850 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
2909 break;2851 break;
2910 case IrInstSrcIdTypeId:
2911 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
2912 break;
2913 case IrInstSrcIdSetEvalBranchQuota:2852 case IrInstSrcIdSetEvalBranchQuota:
2914 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);2853 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
2915 break;2854 break;
test/compile_errors.zig+3-108
...@@ -1657,7 +1657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1657,7 +1657,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1657 \\ var ptr: [*c]u8 = (1 << 64) + 1;1657 \\ var ptr: [*c]u8 = (1 << 64) + 1;
1658 \\}1658 \\}
1659 \\export fn b() void {1659 \\export fn b() void {
1660 \\ var x: @IntType(false, 65) = 0x1234;1660 \\ var x: u65 = 0x1234;
1661 \\ var ptr: [*c]u8 = x;1661 \\ var ptr: [*c]u8 = x;
1662 \\}1662 \\}
1663 , &[_][]const u8{1663 , &[_][]const u8{
...@@ -1896,13 +1896,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1896,13 +1896,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
18961896
1897 cases.add("exceeded maximum bit width of integer",1897 cases.add("exceeded maximum bit width of integer",
1898 \\export fn entry1() void {1898 \\export fn entry1() void {
1899 \\ const T = @IntType(false, 65536);1899 \\ const T = u65536;
1900 \\}1900 \\}
1901 \\export fn entry2() void {1901 \\export fn entry2() void {
1902 \\ var x: i65536 = 1;1902 \\ var x: i65536 = 1;
1903 \\}1903 \\}
1904 , &[_][]const u8{1904 , &[_][]const u8{
1905 "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
1906 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",1905 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
1907 });1906 });
19081907
...@@ -2942,14 +2941,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2942,14 +2941,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2942 "tmp.zig:11:13: error: error.B not a member of error set 'Set2'",2941 "tmp.zig:11:13: error: error.B not a member of error set 'Set2'",
2943 });2942 });
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
2953 cases.add("duplicate error value in error set",2944 cases.add("duplicate error value in error set",
2954 \\const Foo = error {2945 \\const Foo = error {
2955 \\ Bar,2946 \\ Bar,
...@@ -5606,7 +5597,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5606,7 +5597,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5606 });5597 });
56075598
5608 cases.add("globally shadowing a primitive type",5599 cases.add("globally shadowing a primitive type",
5609 \\const u16 = @intType(false, 8);5600 \\const u16 = u8;
5610 \\export fn entry() void {5601 \\export fn entry() void {
5611 \\ const a: u16 = 300;5602 \\ const a: u16 = 300;
5612 \\}5603 \\}
...@@ -5947,93 +5938,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5947,93 +5938,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5947 "tmp.zig:2:1: error: invalid character: '\\t'",5938 "tmp.zig:2:1: error: invalid character: '\\t'",
5948 });5939 });
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
6037 cases.add("calling var args extern function, passing array instead of pointer",5941 cases.add("calling var args extern function, passing array instead of pointer",
6038 \\export fn entry() void {5942 \\export fn entry() void {
6039 \\ foo("hello".*,);5943 \\ foo("hello".*,);
...@@ -6457,15 +6361,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6457,15 +6361,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6457 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",6361 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var) var' is generic",
6458 });6362 });
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
6469 cases.add("unsupported modifier at start of asm output constraint",6364 cases.add("unsupported modifier at start of asm output constraint",
6470 \\export fn foo() void {6365 \\export fn foo() void {
6471 \\ var bar: u32 = 3;6366 \\ var bar: u32 = 3;
test/stage1/behavior/bit_shifting.zig+2-2
...@@ -2,9 +2,9 @@ const std = @import("std");...@@ -2,9 +2,9 @@ const std = @import("std");
2const expect = std.testing.expect;2const expect = std.testing.expect;
33
4fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {4fn 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));
6 expect(Key.bit_count >= mask_bit_count);6 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);
8 const shift_amount = Key.bit_count - ShardKey.bit_count;8 const shift_amount = Key.bit_count - ShardKey.bit_count;
9 return struct {9 return struct {
10 const Self = @This();10 const Self = @This();
test/stage1/behavior/bugs/3742.zig+1-1
...@@ -17,7 +17,7 @@ pub const GET = struct {...@@ -17,7 +17,7 @@ pub const GET = struct {
17};17};
1818
19pub fn isCommand(comptime T: type) bool {19pub fn isCommand(comptime T: type) bool {
20 const tid = @typeId(T);20 const tid = @typeInfo(T);
21 return (tid == .Struct or tid == .Enum or tid == .Union) and21 return (tid == .Struct or tid == .Enum or tid == .Union) and
22 @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");22 @hasDecl(T, "Redis") and @hasDecl(T.Redis, "Command");
23}23}
test/stage1/behavior/enum.zig+2-2
...@@ -96,8 +96,8 @@ test "enum type" {...@@ -96,8 +96,8 @@ test "enum type" {
96 const bar = Bar.B;96 const bar = Bar.B;
9797
98 expect(bar == Bar.B);98 expect(bar == Bar.B);
99 expect(@memberCount(Foo) == 3);99 expect(@typeInfo(Foo).Union.fields.len == 3);
100 expect(@memberCount(Bar) == 4);100 expect(@typeInfo(Bar).Enum.fields.len == 4);
101 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));101 expect(@sizeOf(Foo) == @sizeOf(FooNoVoid));
102 expect(@sizeOf(Bar) == 1);102 expect(@sizeOf(Bar) == 1);
103}103}
test/stage1/behavior/error.zig+3-4
...@@ -3,7 +3,6 @@ const expect = std.testing.expect;...@@ -3,7 +3,6 @@ const expect = std.testing.expect;
3const expectError = std.testing.expectError;3const expectError = std.testing.expectError;
4const expectEqual = std.testing.expectEqual;4const expectEqual = std.testing.expectEqual;
5const mem = std.mem;5const mem = std.mem;
6const builtin = @import("builtin");
76
8pub fn foo() anyerror!i32 {7pub fn foo() anyerror!i32 {
9 const x = try bar();8 const x = try bar();
...@@ -84,8 +83,8 @@ test "error union type " {...@@ -84,8 +83,8 @@ test "error union type " {
84fn testErrorUnionType() void {83fn testErrorUnionType() void {
85 const x: anyerror!i32 = 1234;84 const x: anyerror!i32 = 1234;
86 if (x) |value| expect(value == 1234) else |_| unreachable;85 if (x) |value| expect(value == 1234) else |_| unreachable;
87 expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion);86 expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
88 expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);87 expect(@typeInfo(@TypeOf(x).ErrorSet) == .ErrorSet);
89 expect(@TypeOf(x).ErrorSet == anyerror);88 expect(@TypeOf(x).ErrorSet == anyerror);
90}89}
9190
...@@ -100,7 +99,7 @@ const MyErrSet = error{...@@ -100,7 +99,7 @@ const MyErrSet = error{
100};99};
101100
102fn testErrorSetType() void {101fn testErrorSetType() void {
103 expect(@memberCount(MyErrSet) == 2);102 expect(@typeInfo(MyErrSet).ErrorSet.?.len == 2);
104103
105 const a: MyErrSet!i32 = 5678;104 const a: MyErrSet!i32 = 5678;
106 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;105 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" {...@@ -654,8 +654,8 @@ test "call method with comptime pass-by-non-copying-value self parameter" {
654 expect(b == 2);654 expect(b == 2);
655}655}
656656
657test "@tagName of @typeId" {657test "@tagName of @typeInfo" {
658 const str = @tagName(@typeId(u8));658 const str = @tagName(@typeInfo(u8));
659 expect(std.mem.eql(u8, str, "Int"));659 expect(std.mem.eql(u8, str, "Int"));
660}660}
661661
test/stage1/behavior/math.zig+1-1
...@@ -270,7 +270,7 @@ fn testBinaryNot(x: u16) void {...@@ -270,7 +270,7 @@ fn testBinaryNot(x: u16) void {
270}270}
271271
272test "small int addition" {272test "small int addition" {
273 var x: @IntType(false, 2) = 0;273 var x: u2 = 0;
274 expect(x == 0);274 expect(x == 0);
275275
276 x += 1;276 x += 1;
test/stage1/behavior/misc.zig-64
...@@ -24,35 +24,6 @@ test "call disabled extern fn" {...@@ -24,35 +24,6 @@ test "call disabled extern fn" {
24 disabledExternFn();24 disabledExternFn();
25}25}
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
56test "floating point primitive bit counts" {27test "floating point primitive bit counts" {
57 expect(f16.bit_count == 16);28 expect(f16.bit_count == 16);
58 expect(f32.bit_count == 32);29 expect(f32.bit_count == 32);
...@@ -407,7 +378,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) void {...@@ -407,7 +378,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) void {
407 expect(ptr2[1] == 2.0);378 expect(ptr2[1] == 2.0);
408}379}
409380
410const Tid = builtin.TypeId;
411const AStruct = struct {381const AStruct = struct {
412 x: i32,382 x: i32,
413};383};
...@@ -424,40 +394,6 @@ const AUnion = union {...@@ -424,40 +394,6 @@ const AUnion = union {
424 Two: void,394 Two: void,
425};395};
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
461test "@typeName" {397test "@typeName" {
462 const Struct = struct {};398 const Struct = struct {};
463 const Union = union {399 const Union = union {
test/stage1/behavior/reflection.zig+3-33
...@@ -16,9 +16,9 @@ test "reflection: function return type, var args, and param types" {...@@ -16,9 +16,9 @@ test "reflection: function return type, var args, and param types" {
16 expect(@TypeOf(dummy).ReturnType == i32);16 expect(@TypeOf(dummy).ReturnType == i32);
17 expect(!@TypeOf(dummy).is_var_args);17 expect(!@TypeOf(dummy).is_var_args);
18 expect(@TypeOf(dummy).arg_count == 3);18 expect(@TypeOf(dummy).arg_count == 3);
19 expect(@ArgType(@TypeOf(dummy), 0) == bool);19 expect(@typeInfo(@TypeOf(dummy)).Fn.args[0].arg_type.? == bool);
20 expect(@ArgType(@TypeOf(dummy), 1) == i32);20 expect(@typeInfo(@TypeOf(dummy)).Fn.args[1].arg_type.? == i32);
21 expect(@ArgType(@TypeOf(dummy), 2) == f32);21 expect(@typeInfo(@TypeOf(dummy)).Fn.args[2].arg_type.? == f32);
22 }22 }
23}23}
2424
...@@ -26,36 +26,6 @@ fn dummy(a: bool, b: i32, c: f32) i32 {...@@ -26,36 +26,6 @@ fn dummy(a: bool, b: i32, c: f32) i32 {
26 return 1234;26 return 1234;
27}27}
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
59test "reflection: @field" {29test "reflection: @field" {
60 var f = Foo{30 var f = Foo{
61 .one = 42,31 .one = 42,
test/stage1/behavior/union.zig+1-1
...@@ -531,7 +531,7 @@ var glbl: Foo1 = undefined;...@@ -531,7 +531,7 @@ var glbl: Foo1 = undefined;
531531
532test "global union with single field is correctly initialized" {532test "global union with single field is correctly initialized" {
533 glbl = Foo1{533 glbl = Foo1{
534 .f = @memberType(Foo1, 0){ .x = 123 },534 .f = @typeInfo(Foo1).Union.fields[0].field_type{ .x = 123 },
535 };535 };
536 expect(glbl.f.x == 123);536 expect(glbl.f.x == 123);
537}537}
test/translate_c.zig+4-4
...@@ -1354,7 +1354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1354,7 +1354,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1354 cases.add("macro pointer cast",1354 cases.add("macro pointer cast",
1355 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)1355 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
1356 , &[_][]const u8{1356 , &[_][]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);
1358 });1358 });
13591359
1360 cases.add("basic macro function",1360 cases.add("basic macro function",
...@@ -2538,11 +2538,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2538,11 +2538,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2538 \\#define FOO(bar) baz((void *)(baz))2538 \\#define FOO(bar) baz((void *)(baz))
2539 \\#define BAR (void*) a2539 \\#define BAR (void*) a
2540 , &[_][]const u8{2540 , &[_][]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))) {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 (@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 (@typeInfo(@TypeOf(baz)) == .Pointer) @ptrCast(*c_void, baz) else if (@typeInfo(@TypeOf(baz)) == .Int) @intToPtr(*c_void, baz) else @as(*c_void, baz));
2543 \\}2543 \\}
2544 ,2544 ,
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);
2546 });2546 });
25472547
2548 cases.add("macro conditional operator",2548 cases.add("macro conditional operator",