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