authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-10-17 18:04:53-06:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-11-19 18:59:21+02:00
log25ec2dbc1e2302d1138749262b588d3e438fcd55
tree34187fbd88b2e9b046f50cea93f482a191bc3248
parent2b7781d82ad8d2234b89257676670957e005f214

Add builtin.Signedness, use it instead of is_signed


26 files changed, 149 insertions(+), 150 deletions(-)

lib/std/builtin.zig+8-1
......@@ -209,7 +209,7 @@ pub const TypeInfo = union(enum) {
209209 /// This data structure is used by the Zig language code generation and
210210 /// therefore must be kept in sync with the compiler implementation.
211211 pub const Int = struct {
212 is_signed: bool,
212 signedness: Signedness,
213213 bits: comptime_int,
214214 };
215215
......@@ -438,6 +438,13 @@ pub const Endian = enum {
438438 Little,
439439};
440440
441/// This data structure is used by the Zig language code generation and
442/// therefore must be kept in sync with the compiler implementation.
443pub const Signedness = enum {
444 signed,
445 unsigned,
446};
447
441448/// This data structure is used by the Zig language code generation and
442449/// therefore must be kept in sync with the compiler implementation.
443450pub const OutputMode = enum {
lib/std/fmt.zig+1-1
......@@ -1028,7 +1028,7 @@ pub fn formatInt(
10281028 if (a == 0) break;
10291029 }
10301030
1031 if (value_info.is_signed) {
1031 if (value_info.signedness == .signed) {
10321032 if (value < 0) {
10331033 // Negative integer
10341034 index -= 1;
lib/std/io/serialization.zig+1-1
......@@ -73,7 +73,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
7373
7474 if (int_size == 1) {
7575 if (t_bit_count == 8) return @bitCast(T, buffer[0]);
76 const PossiblySignedByte = std.meta.Int(if (@typeInfo(T).Int.is_signed) .signed else .unsigned, 8);
76 const PossiblySignedByte = std.meta.Int(@typeInfo(T).Int.signedness, 8);
7777 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
7878 }
7979
lib/std/json/write_stream.zig+1-1
......@@ -167,7 +167,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
167167 self.popState();
168168 return;
169169 }
170 if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) {
170 if (value < 4503599627370496 and (info.signedness == .unsigned or value > -4503599627370496)) {
171171 try self.stream.print("{}", .{value});
172172 self.popState();
173173 return;
lib/std/leb128.zig+2-2
......@@ -297,8 +297,8 @@ test "deserialize unsigned LEB128" {
297297
298298fn test_write_leb128(value: anytype) !void {
299299 const T = @TypeOf(value);
300 const t_signed = @typeInfo(T).Int.is_signed;
301 const signedness = if (t_signed) .signed else .unsigned;
300 const signedness = @typeInfo(T).Int.signedness;
301 const t_signed = signedness == .signed;
302302
303303 const writeStream = if (t_signed) writeILEB128 else writeULEB128;
304304 const readStream = if (t_signed) readILEB128 else readULEB128;
lib/std/math.zig+22-22
......@@ -313,7 +313,7 @@ pub fn floatExponentBits(comptime T: type) comptime_int {
313313pub fn Min(comptime A: type, comptime B: type) type {
314314 switch (@typeInfo(A)) {
315315 .Int => |a_info| switch (@typeInfo(B)) {
316 .Int => |b_info| if (!a_info.is_signed and !b_info.is_signed) {
316 .Int => |b_info| if (a_info.signedness == .unsigned and b_info.signedness == .unsigned) {
317317 if (a_info.bits < b_info.bits) {
318318 return A;
319319 } else {
......@@ -450,7 +450,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
450450 }
451451 };
452452
453 if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.is_signed) {
453 if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.signedness == .signed) {
454454 if (shift_amt < 0) {
455455 return a >> casted_shift_amt;
456456 }
......@@ -490,7 +490,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
490490 }
491491 };
492492
493 if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.is_signed) {
493 if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.signedness == .signed) {
494494 if (shift_amt < 0) {
495495 return a << casted_shift_amt;
496496 }
......@@ -518,12 +518,12 @@ test "math.shr" {
518518pub fn rotr(comptime T: type, x: T, r: anytype) T {
519519 if (@typeInfo(T) == .Vector) {
520520 const C = @typeInfo(T).Vector.child;
521 if (@typeInfo(C).Int.is_signed) {
521 if (@typeInfo(C).Int.signedness == .signed) {
522522 @compileError("cannot rotate signed integers");
523523 }
524524 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));
525525 return (x >> @splat(@typeInfo(T).Vector.len, ar)) | (x << @splat(@typeInfo(T).Vector.len, 1 + ~ar));
526 } else if (@typeInfo(T).Int.is_signed) {
526 } else if (@typeInfo(T).Int.signedness == .signed) {
527527 @compileError("cannot rotate signed integer");
528528 } else {
529529 const ar = @mod(r, @typeInfo(T).Int.bits);
......@@ -546,12 +546,12 @@ test "math.rotr" {
546546pub fn rotl(comptime T: type, x: T, r: anytype) T {
547547 if (@typeInfo(T) == .Vector) {
548548 const C = @typeInfo(T).Vector.child;
549 if (@typeInfo(C).Int.is_signed) {
549 if (@typeInfo(C).Int.signedness == .signed) {
550550 @compileError("cannot rotate signed integers");
551551 }
552552 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));
553553 return (x << @splat(@typeInfo(T).Vector.len, ar)) | (x >> @splat(@typeInfo(T).Vector.len, 1 +% ~ar));
554 } else if (@typeInfo(T).Int.is_signed) {
554 } else if (@typeInfo(T).Int.signedness == .signed) {
555555 @compileError("cannot rotate signed integer");
556556 } else {
557557 const ar = @mod(r, @typeInfo(T).Int.bits);
......@@ -585,7 +585,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
585585 if (from == 0 and to == 0) {
586586 return u0;
587587 }
588 const sign: std.meta.Signedness = if (from < 0) .signed else .unsigned;
588 const sign: std.builtin.Signedness = if (from < 0) .signed else .unsigned;
589589 const largest_positive_integer = max(if (from < 0) (-from) - 1 else from, to); // two's complement
590590 const base = log2(largest_positive_integer);
591591 const upper = (1 << base) - 1;
......@@ -658,7 +658,7 @@ fn testOverflow() void {
658658pub fn absInt(x: anytype) !@TypeOf(x) {
659659 const T = @TypeOf(x);
660660 comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
661 comptime assert(@typeInfo(T).Int.is_signed); // must pass a signed integer to absInt
661 comptime assert(@typeInfo(T).Int.signedness == .signed); // must pass a signed integer to absInt
662662
663663 if (x == minInt(@TypeOf(x))) {
664664 return error.Overflow;
......@@ -691,7 +691,7 @@ fn testAbsFloat() void {
691691pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
692692 @setRuntimeSafety(false);
693693 if (denominator == 0) return error.DivisionByZero;
694 if (@typeInfo(T) == .Int and @typeInfo(T).Int.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
694 if (@typeInfo(T) == .Int and @typeInfo(T).Int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
695695 return @divTrunc(numerator, denominator);
696696}
697697
......@@ -712,7 +712,7 @@ fn testDivTrunc() void {
712712pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
713713 @setRuntimeSafety(false);
714714 if (denominator == 0) return error.DivisionByZero;
715 if (@typeInfo(T) == .Int and @typeInfo(T).Int.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
715 if (@typeInfo(T) == .Int and @typeInfo(T).Int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
716716 return @divFloor(numerator, denominator);
717717}
718718
......@@ -786,7 +786,7 @@ fn testDivCeil() void {
786786pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
787787 @setRuntimeSafety(false);
788788 if (denominator == 0) return error.DivisionByZero;
789 if (@typeInfo(T) == .Int and @typeInfo(T).Int.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
789 if (@typeInfo(T) == .Int and @typeInfo(T).Int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
790790 const result = @divTrunc(numerator, denominator);
791791 if (result * denominator != numerator) return error.UnexpectedRemainder;
792792 return result;
......@@ -892,7 +892,7 @@ test "math.absCast" {
892892/// Returns the negation of the integer parameter.
893893/// Result is a signed integer.
894894pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x))) {
895 if (@typeInfo(@TypeOf(x)).Int.is_signed) return negate(x);
895 if (@typeInfo(@TypeOf(x)).Int.signedness == .signed) return negate(x);
896896
897897 const int = std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x)));
898898 if (x > -minInt(int)) return error.Overflow;
......@@ -981,11 +981,11 @@ fn testFloorPowerOfTwo() void {
981981/// Returns the next power of two (if the value is not already a power of two).
982982/// Only unsigned integers can be used. Zero is not an allowed input.
983983/// Result is a type with 1 more bit than the input type.
984pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(if (@typeInfo(T).Int.is_signed) .signed else .unsigned, @typeInfo(T).Int.bits + 1) {
984pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1) {
985985 comptime assert(@typeInfo(T) == .Int);
986 comptime assert(!@typeInfo(T).Int.is_signed);
986 comptime assert(@typeInfo(T).Int.signedness == .unsigned);
987987 assert(value != 0);
988 comptime const PromotedType = std.meta.Int(if (@typeInfo(T).Int.is_signed) .signed else .unsigned, @typeInfo(T).Int.bits + 1);
988 comptime const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1);
989989 comptime const shiftType = std.math.Log2Int(PromotedType);
990990 return @as(PromotedType, 1) << @intCast(shiftType, @typeInfo(T).Int.bits - @clz(T, value - 1));
991991}
......@@ -996,8 +996,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(if (@typeI
996996pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
997997 comptime assert(@typeInfo(T) == .Int);
998998 const info = @typeInfo(T).Int;
999 comptime assert(!info.is_signed);
1000 comptime const PromotedType = std.meta.Int(if (info.is_signed) .signed else .unsigned, info.bits + 1);
999 comptime assert(info.signedness == .unsigned);
1000 comptime const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
10011001 comptime const overflowBit = @as(PromotedType, 1) << info.bits;
10021002 var x = ceilPowerOfTwoPromote(T, value);
10031003 if (overflowBit & x != 0) {
......@@ -1090,13 +1090,13 @@ pub fn maxInt(comptime T: type) comptime_int {
10901090 const info = @typeInfo(T);
10911091 const bit_count = info.Int.bits;
10921092 if (bit_count == 0) return 0;
1093 return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1;
1093 return (1 << (bit_count - @boolToInt(info.Int.signedness == .signed))) - 1;
10941094}
10951095
10961096pub fn minInt(comptime T: type) comptime_int {
10971097 const info = @typeInfo(T);
10981098 const bit_count = info.Int.bits;
1099 if (!info.Int.is_signed) return 0;
1099 if (info.Int.signedness == .unsigned) return 0;
11001100 if (bit_count == 0) return 0;
11011101 return -(1 << (bit_count - 1));
11021102}
......@@ -1143,8 +1143,8 @@ test "max value type" {
11431143 testing.expect(x == 2147483647);
11441144}
11451145
1146pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(if (@typeInfo(T).Int.is_signed) .signed else .unsigned, @typeInfo(T).Int.bits * 2) {
1147 const ResultInt = std.meta.Int(if (@typeInfo(T).Int.is_signed) .signed else .unsigned, @typeInfo(T).Int.bits * 2);
1146pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2) {
1147 const ResultInt = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2);
11481148 return @as(ResultInt, a) * @as(ResultInt, b);
11491149}
11501150
lib/std/math/big.zig+1-1
......@@ -17,7 +17,7 @@ pub const Log2Limb = std.math.Log2Int(Limb);
1717comptime {
1818 assert(std.math.floorPowerOfTwo(usize, limb_info.bits) == limb_info.bits);
1919 assert(limb_info.bits <= 64); // u128 set is unsupported
20 assert(limb_info.is_signed == false);
20 assert(limb_info.signedness == .unsigned);
2121}
2222
2323test "" {
lib/std/math/big/int.zig+9-9
......@@ -24,7 +24,7 @@ pub fn calcLimbLen(scalar: anytype) usize {
2424 const T = @TypeOf(scalar);
2525 switch (@typeInfo(T)) {
2626 .Int => |info| {
27 const UT = if (info.is_signed) std.meta.Int(.unsigned, info.bits - 1) else T;
27 const UT = if (info.signedness == .signed) std.meta.Int(.unsigned, info.bits - 1) else T;
2828 return @sizeOf(UT) / @sizeOf(Limb);
2929 },
3030 .ComptimeInt => {
......@@ -187,7 +187,7 @@ pub const Mutable = struct {
187187
188188 switch (@typeInfo(T)) {
189189 .Int => |info| {
190 const UT = if (info.is_signed) std.meta.Int(.unsigned, info.bits - 1) else T;
190 const UT = if (info.signedness == .signed) std.meta.Int(.unsigned, info.bits - 1) else T;
191191
192192 const needed_limbs = @sizeOf(UT) / @sizeOf(Limb);
193193 assert(needed_limbs <= self.limbs.len); // value too big
......@@ -1054,22 +1054,22 @@ pub const Const = struct {
10541054 return bits;
10551055 }
10561056
1057 pub fn fitsInTwosComp(self: Const, is_signed: bool, bit_count: usize) bool {
1057 pub fn fitsInTwosComp(self: Const, signedness: std.builtin.Signedness, bit_count: usize) bool {
10581058 if (self.eqZero()) {
10591059 return true;
10601060 }
1061 if (!is_signed and !self.positive) {
1061 if (signedness == .unsigned and !self.positive) {
10621062 return false;
10631063 }
10641064
1065 const req_bits = self.bitCountTwosComp() + @boolToInt(self.positive and is_signed);
1065 const req_bits = self.bitCountTwosComp() + @boolToInt(self.positive and signedness == .signed);
10661066 return bit_count >= req_bits;
10671067 }
10681068
10691069 /// Returns whether self can fit into an integer of the requested type.
10701070 pub fn fits(self: Const, comptime T: type) bool {
10711071 const info = @typeInfo(T).Int;
1072 return self.fitsInTwosComp(info.is_signed, info.bits);
1072 return self.fitsInTwosComp(info.signedness, info.bits);
10731073 }
10741074
10751075 /// Returns the approximate size of the integer in the given base. Negative values accommodate for
......@@ -1110,7 +1110,7 @@ pub const Const = struct {
11101110 }
11111111 }
11121112
1113 if (!info.is_signed) {
1113 if (info.signedness == .unsigned) {
11141114 return if (self.positive) @intCast(T, r) else error.NegativeIntoUnsigned;
11151115 } else {
11161116 if (self.positive) {
......@@ -1558,8 +1558,8 @@ pub const Managed = struct {
15581558 return self.toConst().bitCountTwosComp();
15591559 }
15601560
1561 pub fn fitsInTwosComp(self: Managed, is_signed: bool, bit_count: usize) bool {
1562 return self.toConst().fitsInTwosComp(is_signed, bit_count);
1561 pub fn fitsInTwosComp(self: Managed, signedness: std.builtin.Signedness, bit_count: usize) bool {
1562 return self.toConst().fitsInTwosComp(signedness, bit_count);
15631563 }
15641564
15651565 /// Returns whether self can fit into an integer of the requested type.
lib/std/math/powi.zig+1-1
......@@ -48,7 +48,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
4848 // powi(x, y) = Overflow for for y >= @sizeOf(x) - 1 y > 0
4949 // powi(x, y) = Underflow for for y > @sizeOf(x) - 1 y < 0
5050 const bit_size = @sizeOf(T) * 8;
51 if (info.Int.is_signed) {
51 if (info.Int.signedness == .signed) {
5252 if (x == -1) {
5353 // powi(-1, y) = -1 for for y an odd integer
5454 // powi(-1, y) = 1 for for y an even integer
lib/std/meta.zig+2-7
......@@ -718,15 +718,10 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
718718
719719pub const IntType = @compileError("replaced by std.meta.Int");
720720
721pub const Signedness = enum {
722 unsigned,
723 signed,
724};
725
726pub fn Int(comptime signedness: Signedness, comptime bit_count: u16) type {
721pub fn Int(comptime signedness: builtin.Signedness, comptime bit_count: u16) type {
727722 return @Type(TypeInfo{
728723 .Int = .{
729 .is_signed = signedness == .signed,
724 .signedness = signedness,
730725 .bits = bit_count,
731726 },
732727 });
lib/std/meta/trait.zig+2-2
......@@ -195,7 +195,7 @@ test "std.meta.trait.isPacked" {
195195
196196pub fn isUnsignedInt(comptime T: type) bool {
197197 return switch (@typeInfo(T)) {
198 .Int => |i| !i.is_signed,
198 .Int => |i| i.signedness == .unsigned,
199199 else => false,
200200 };
201201}
......@@ -210,7 +210,7 @@ test "isUnsignedInt" {
210210pub fn isSignedInt(comptime T: type) bool {
211211 return switch (@typeInfo(T)) {
212212 .ComptimeInt => true,
213 .Int => |i| i.is_signed,
213 .Int => |i| i.signedness == .signed,
214214 else => false,
215215 };
216216}
lib/std/os.zig+1-6
......@@ -4868,12 +4868,7 @@ pub fn sendfile(
48684868 var total_written: usize = 0;
48694869
48704870 // Prevents EOVERFLOW.
4871 const size_t = @Type(std.builtin.TypeInfo{
4872 .Int = .{
4873 .is_signed = false,
4874 .bits = @typeInfo(usize).Int.bits - 1,
4875 },
4876 });
4871 const size_t = std.meta.Int(.unsigned, @typeInfo(usize).Int.bits - 1);
48774872 const max_count = switch (std.Target.current.os.tag) {
48784873 .linux => 0x7ffff000,
48794874 .macos, .ios, .watchos, .tvos => math.maxInt(i32),
lib/std/os/linux.zig+2-2
......@@ -777,7 +777,7 @@ pub fn seteuid(euid: uid_t) usize {
777777 // The setresuid(2) man page says that if -1 is passed the corresponding
778778 // id will not be changed. Since uid_t is unsigned, this wraps around to the
779779 // max value in C.
780 comptime assert(@typeInfo(uid_t) == .Int and !@typeInfo(uid_t).Int.is_signed);
780 comptime assert(@typeInfo(uid_t) == .Int and @typeInfo(uid_t).Int.signedness == .unsigned);
781781 return setresuid(std.math.maxInt(uid_t), euid, std.math.maxInt(uid_t));
782782}
783783
......@@ -788,7 +788,7 @@ pub fn setegid(egid: gid_t) usize {
788788 // The setresgid(2) man page says that if -1 is passed the corresponding
789789 // id will not be changed. Since gid_t is unsigned, this wraps around to the
790790 // max value in C.
791 comptime assert(@typeInfo(uid_t) == .Int and !@typeInfo(uid_t).Int.is_signed);
791 comptime assert(@typeInfo(uid_t) == .Int and @typeInfo(uid_t).Int.signedness == .unsigned);
792792 return setresgid(std.math.maxInt(gid_t), egid, std.math.maxInt(gid_t));
793793}
794794
lib/std/packed_int_array.zig+2-2
......@@ -332,7 +332,7 @@ test "PackedIntArray" {
332332 comptime var bits = 0;
333333 inline while (bits <= max_bits) : (bits += 1) {
334334 //alternate unsigned and signed
335 const sign: std.meta.Signedness = if (bits % 2 == 0) .signed else .unsigned;
335 const sign: builtin.Signedness = if (bits % 2 == 0) .signed else .unsigned;
336336 const I = std.meta.Int(sign, bits);
337337
338338 const PackedArray = PackedIntArray(I, int_count);
......@@ -384,7 +384,7 @@ test "PackedIntSlice" {
384384 comptime var bits = 0;
385385 inline while (bits <= max_bits) : (bits += 1) {
386386 //alternate unsigned and signed
387 const sign: std.meta.Signedness = if (bits % 2 == 0) .signed else .unsigned;
387 const sign: builtin.Signedness = if (bits % 2 == 0) .signed else .unsigned;
388388 const I = std.meta.Int(sign, bits);
389389 const P = PackedIntSlice(I);
390390
lib/std/rand.zig+9-9
......@@ -69,7 +69,7 @@ pub const Random = struct {
6969 /// Constant-time implementation off `uintLessThan`.
7070 /// The results of this function may be biased.
7171 pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T {
72 comptime assert(@typeInfo(T).Int.is_signed == false);
72 comptime assert(@typeInfo(T).Int.signedness == .unsigned);
7373 const bits = @typeInfo(T).Int.bits;
7474 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
7575 assert(0 < less_than);
......@@ -89,7 +89,7 @@ pub const Random = struct {
8989 /// this function is guaranteed to return.
9090 /// If you need deterministic runtime bounds, use `uintLessThanBiased`.
9191 pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T {
92 comptime assert(@typeInfo(T).Int.is_signed == false);
92 comptime assert(@typeInfo(T).Int.signedness == .unsigned);
9393 const bits = @typeInfo(T).Int.bits;
9494 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
9595 assert(0 < less_than);
......@@ -129,7 +129,7 @@ pub const Random = struct {
129129 /// Constant-time implementation off `uintAtMost`.
130130 /// The results of this function may be biased.
131131 pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T {
132 assert(@typeInfo(T).Int.is_signed == false);
132 assert(@typeInfo(T).Int.signedness == .unsigned);
133133 if (at_most == maxInt(T)) {
134134 // have the full range
135135 return r.int(T);
......@@ -141,7 +141,7 @@ pub const Random = struct {
141141 /// See `uintLessThan`, which this function uses in most cases,
142142 /// for commentary on the runtime of this function.
143143 pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {
144 assert(@typeInfo(T).Int.is_signed == false);
144 assert(@typeInfo(T).Int.signedness == .unsigned);
145145 if (at_most == maxInt(T)) {
146146 // have the full range
147147 return r.int(T);
......@@ -154,7 +154,7 @@ pub const Random = struct {
154154 pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T {
155155 assert(at_least < less_than);
156156 const info = @typeInfo(T).Int;
157 if (info.is_signed) {
157 if (info.signedness == .signed) {
158158 // Two's complement makes this math pretty easy.
159159 const UnsignedT = std.meta.Int(.unsigned, info.bits);
160160 const lo = @bitCast(UnsignedT, at_least);
......@@ -173,7 +173,7 @@ pub const Random = struct {
173173 pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T {
174174 assert(at_least < less_than);
175175 const info = @typeInfo(T).Int;
176 if (info.is_signed) {
176 if (info.signedness == .signed) {
177177 // Two's complement makes this math pretty easy.
178178 const UnsignedT = std.meta.Int(.unsigned, info.bits);
179179 const lo = @bitCast(UnsignedT, at_least);
......@@ -191,7 +191,7 @@ pub const Random = struct {
191191 pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T {
192192 assert(at_least <= at_most);
193193 const info = @typeInfo(T).Int;
194 if (info.is_signed) {
194 if (info.signedness == .signed) {
195195 // Two's complement makes this math pretty easy.
196196 const UnsignedT = std.meta.Int(.unsigned, info.bits);
197197 const lo = @bitCast(UnsignedT, at_least);
......@@ -210,7 +210,7 @@ pub const Random = struct {
210210 pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T {
211211 assert(at_least <= at_most);
212212 const info = @typeInfo(T).Int;
213 if (info.is_signed) {
213 if (info.signedness == .signed) {
214214 // Two's complement makes this math pretty easy.
215215 const UnsignedT = std.meta.Int(.unsigned, info.bits);
216216 const lo = @bitCast(UnsignedT, at_least);
......@@ -288,7 +288,7 @@ pub const Random = struct {
288288/// into an integer 0 <= result < less_than.
289289/// This function introduces a minor bias.
290290pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
291 comptime assert(@typeInfo(T).Int.is_signed == false);
291 comptime assert(@typeInfo(T).Int.signedness == .unsigned);
292292 const bits = @typeInfo(T).Int.bits;
293293 const T2 = std.meta.Int(.unsigned, bits * 2);
294294
lib/std/start.zig+2-2
......@@ -325,7 +325,7 @@ pub fn callMain() u8 {
325325 return 0;
326326 },
327327 .Int => |info| {
328 if (info.bits != 8 or info.is_signed) {
328 if (info.bits != 8 or info.signedness == .signed) {
329329 @compileError(bad_main_ret);
330330 }
331331 return root.main();
......@@ -341,7 +341,7 @@ pub fn callMain() u8 {
341341 switch (@typeInfo(@TypeOf(result))) {
342342 .Void => return 0,
343343 .Int => |info| {
344 if (info.bits != 8 or info.is_signed) {
344 if (info.bits != 8 or info.signedness == .signed) {
345345 @compileError(bad_main_ret);
346346 }
347347 return result;
src/Module.zig+4-4
......@@ -2633,7 +2633,7 @@ pub fn cmpNumeric(
26332633 dest_float_type = lhs.ty;
26342634 } else {
26352635 const int_info = lhs.ty.intInfo(self.getTarget());
2636 lhs_bits = int_info.bits + @boolToInt(!int_info.signed and dest_int_is_signed);
2636 lhs_bits = int_info.bits + @boolToInt(int_info.signedness == .unsigned and dest_int_is_signed);
26372637 }
26382638
26392639 var rhs_bits: usize = undefined;
......@@ -2668,7 +2668,7 @@ pub fn cmpNumeric(
26682668 dest_float_type = rhs.ty;
26692669 } else {
26702670 const int_info = rhs.ty.intInfo(self.getTarget());
2671 rhs_bits = int_info.bits + @boolToInt(!int_info.signed and dest_int_is_signed);
2671 rhs_bits = int_info.bits + @boolToInt(int_info.signedness == .unsigned and dest_int_is_signed);
26722672 }
26732673
26742674 const dest_type = if (dest_float_type) |ft| ft else blk: {
......@@ -2817,9 +2817,9 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
28172817
28182818 const src_info = inst.ty.intInfo(self.getTarget());
28192819 const dst_info = dest_type.intInfo(self.getTarget());
2820 if ((src_info.signed == dst_info.signed and dst_info.bits >= src_info.bits) or
2820 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
28212821 // small enough unsigned ints can get casted to large enough signed ints
2822 (src_info.signed and !dst_info.signed and dst_info.bits > src_info.bits))
2822 (src_info.signedness == .signed and dst_info.signedness == .unsigned and dst_info.bits > src_info.bits))
28232823 {
28242824 const b = try self.requireRuntimeBlock(scope, inst.src);
28252825 return self.addUnOp(b, inst.src, dest_type, .intcast, inst);
src/codegen.zig+9-15
......@@ -203,7 +203,7 @@ pub fn generateSymbol(
203203 .Int => {
204204 // TODO populate .debug_info for the integer
205205 const info = typed_value.ty.intInfo(bin_file.options.target);
206 if (info.bits == 8 and !info.signed) {
206 if (info.bits == 8 and info.signedness == .unsigned) {
207207 const x = typed_value.val.toUnsignedInt();
208208 try code.append(@intCast(u8, x));
209209 return Result{ .appended = {} };
......@@ -920,7 +920,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
920920 const operand = try self.resolveInst(inst.operand);
921921 const info_a = inst.operand.ty.intInfo(self.target.*);
922922 const info_b = inst.base.ty.intInfo(self.target.*);
923 if (info_a.signed != info_b.signed)
923 if (info_a.signedness != info_b.signedness)
924924 return self.fail(inst.base.src, "TODO gen intcast sign safety in semantic analysis", .{});
925925
926926 if (info_a.bits == info_b.bits)
......@@ -1780,7 +1780,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
17801780 fn genCmp(self: *Self, inst: *ir.Inst.BinOp, op: math.CompareOperator) !MCValue {
17811781 // No side effects, so if it's unreferenced, do nothing.
17821782 if (inst.base.isUnused())
1783 return MCValue.dead;
1783 return MCValue{ .dead = {} };
17841784 switch (arch) {
17851785 .x86_64 => {
17861786 try self.code.ensureCapacity(self.code.items.len + 8);
......@@ -1800,11 +1800,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
18001800
18011801 try self.genX8664BinMathCode(inst.base.src, inst.base.ty, dst_mcv, src_mcv, 7, 0x38);
18021802 const info = inst.lhs.ty.intInfo(self.target.*);
1803 if (info.signed) {
1804 return MCValue{ .compare_flags_signed = op };
1805 } else {
1806 return MCValue{ .compare_flags_unsigned = op };
1807 }
1803 return switch (info.signedness) {
1804 .signed => MCValue{ .compare_flags_signed = op },
1805 .unsigned => MCValue{ .compare_flags_unsigned = op },
1806 };
18081807 },
18091808 else => return self.fail(inst.base.src, "TODO implement cmp for {}", .{self.target.cpu.arch}),
18101809 }
......@@ -2904,12 +2903,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29042903 switch (mcv) {
29052904 .immediate => |imm| {
29062905 // This immediate is unsigned.
2907 const U = @Type(.{
2908 .Int = .{
2909 .bits = ti.bits - @boolToInt(ti.is_signed),
2910 .is_signed = false,
2911 },
2912 });
2906 const U = std.meta.Int(.unsigned, ti.bits - @boolToInt(ti.signedness == .signed));
29132907 if (imm >= math.maxInt(U)) {
29142908 return MCValue{ .register = try self.copyToTmpRegister(inst.src, mcv) };
29152909 }
......@@ -2949,7 +2943,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
29492943 },
29502944 .Int => {
29512945 const info = typed_value.ty.intInfo(self.target.*);
2952 if (info.bits > ptr_bits or info.signed) {
2946 if (info.bits > ptr_bits or info.signedness == .signed) {
29532947 return self.fail(src, "TODO const int bigger than ptr and signed int", .{});
29542948 }
29552949 return MCValue{ .immediate = typed_value.val.toUnsignedInt() };
src/link/Elf.zig+4-1
......@@ -2443,7 +2443,10 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo
24432443 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12);
24442444 dbg_info_buffer.appendAssumeCapacity(abbrev_base_type);
24452445 // DW.AT_encoding, DW.FORM_data1
2446 dbg_info_buffer.appendAssumeCapacity(if (info.signed) DW.ATE_signed else DW.ATE_unsigned);
2446 dbg_info_buffer.appendAssumeCapacity(switch (info.signedness) {
2447 .signed => DW.ATE_signed,
2448 .unsigned => DW.ATE_unsigned,
2449 });
24472450 // DW.AT_byte_size, DW.FORM_data1
24482451 dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(self.base.options.target)));
24492452 // DW.AT_name, DW.FORM_string
src/stage1/ir.cpp+8-6
......@@ -25306,11 +25306,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2530625306 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2530725307 result->data.x_struct.fields = fields;
2530825308
25309 // is_signed: bool
25310 ensure_field_index(result->type, "is_signed", 0);
25309 // is_signed: Signedness
25310 ensure_field_index(result->type, "signedness", 0);
2531125311 fields[0]->special = ConstValSpecialStatic;
25312 fields[0]->type = ira->codegen->builtin_types.entry_bool;
25313 fields[0]->data.x_bool = type_entry->data.integral.is_signed;
25312 fields[0]->type = get_builtin_type(ira->codegen, "Signedness");
25313 bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed);
2531425314 // bits: u8
2531525315 ensure_field_index(result->type, "bits", 1);
2531625316 fields[1]->special = ConstValSpecialStatic;
......@@ -26073,9 +26073,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
2607326073 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);
2607426074 if (bi == nullptr)
2607526075 return ira->codegen->invalid_inst_gen->value->type;
26076 bool is_signed;
26077 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed)))
26076 ZigValue *value = get_const_field(ira, source_instr->source_node, payload, "signedness", 0);
26077 if (value == nullptr)
2607826078 return ira->codegen->invalid_inst_gen->value->type;
26079 assert(value->type == get_builtin_type(ira->codegen, "Signedness"));
26080 bool is_signed = !bigint_as_u32(&value->data.x_enum_tag);
2607926081 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
2608026082 }
2608126083 case ZigTypeIdFloat:
src/type.zig+27-27
......@@ -186,7 +186,7 @@ pub const Type = extern union {
186186 // The target will not be branched upon, because we handled target-dependent cases above.
187187 const info_a = a.intInfo(@as(Target, undefined));
188188 const info_b = b.intInfo(@as(Target, undefined));
189 return info_a.signed == info_b.signed and info_a.bits == info_b.bits;
189 return info_a.signedness == info_b.signedness and info_a.bits == info_b.bits;
190190 },
191191 .Array => {
192192 if (a.arrayLen() != b.arrayLen())
......@@ -266,7 +266,7 @@ pub const Type = extern union {
266266 // Remaining cases are arbitrary sized integers.
267267 // The target will not be branched upon, because we handled target-dependent cases above.
268268 const info = self.intInfo(@as(Target, undefined));
269 std.hash.autoHash(&hasher, info.signed);
269 std.hash.autoHash(&hasher, info.signedness);
270270 std.hash.autoHash(&hasher, info.bits);
271271 }
272272 },
......@@ -1908,7 +1908,7 @@ pub const Type = extern union {
19081908 }
19091909
19101910 /// Asserts the type is an integer.
1911 pub fn intInfo(self: Type, target: Target) struct { signed: bool, bits: u16 } {
1911 pub fn intInfo(self: Type, target: Target) struct { signedness: std.builtin.Signedness, bits: u16 } {
19121912 return switch (self.tag()) {
19131913 .f16,
19141914 .f32,
......@@ -1958,26 +1958,26 @@ pub const Type = extern union {
19581958 .empty_struct,
19591959 => unreachable,
19601960
1961 .int_unsigned => .{ .signed = false, .bits = self.cast(Payload.IntUnsigned).?.bits },
1962 .int_signed => .{ .signed = true, .bits = self.cast(Payload.IntSigned).?.bits },
1963 .u8 => .{ .signed = false, .bits = 8 },
1964 .i8 => .{ .signed = true, .bits = 8 },
1965 .u16 => .{ .signed = false, .bits = 16 },
1966 .i16 => .{ .signed = true, .bits = 16 },
1967 .u32 => .{ .signed = false, .bits = 32 },
1968 .i32 => .{ .signed = true, .bits = 32 },
1969 .u64 => .{ .signed = false, .bits = 64 },
1970 .i64 => .{ .signed = true, .bits = 64 },
1971 .usize => .{ .signed = false, .bits = target.cpu.arch.ptrBitWidth() },
1972 .isize => .{ .signed = true, .bits = target.cpu.arch.ptrBitWidth() },
1973 .c_short => .{ .signed = true, .bits = CType.short.sizeInBits(target) },
1974 .c_ushort => .{ .signed = false, .bits = CType.ushort.sizeInBits(target) },
1975 .c_int => .{ .signed = true, .bits = CType.int.sizeInBits(target) },
1976 .c_uint => .{ .signed = false, .bits = CType.uint.sizeInBits(target) },
1977 .c_long => .{ .signed = true, .bits = CType.long.sizeInBits(target) },
1978 .c_ulong => .{ .signed = false, .bits = CType.ulong.sizeInBits(target) },
1979 .c_longlong => .{ .signed = true, .bits = CType.longlong.sizeInBits(target) },
1980 .c_ulonglong => .{ .signed = false, .bits = CType.ulonglong.sizeInBits(target) },
1961 .int_unsigned => .{ .signedness = .unsigned, .bits = self.cast(Payload.IntUnsigned).?.bits },
1962 .int_signed => .{ .signedness = .signed, .bits = self.cast(Payload.IntSigned).?.bits },
1963 .u8 => .{ .signedness = .unsigned, .bits = 8 },
1964 .i8 => .{ .signedness = .signed, .bits = 8 },
1965 .u16 => .{ .signedness = .unsigned, .bits = 16 },
1966 .i16 => .{ .signedness = .signed, .bits = 16 },
1967 .u32 => .{ .signedness = .unsigned, .bits = 32 },
1968 .i32 => .{ .signedness = .signed, .bits = 32 },
1969 .u64 => .{ .signedness = .unsigned, .bits = 64 },
1970 .i64 => .{ .signedness = .signed, .bits = 64 },
1971 .usize => .{ .signedness = .unsigned, .bits = target.cpu.arch.ptrBitWidth() },
1972 .isize => .{ .signedness = .signed, .bits = target.cpu.arch.ptrBitWidth() },
1973 .c_short => .{ .signedness = .signed, .bits = CType.short.sizeInBits(target) },
1974 .c_ushort => .{ .signedness = .unsigned, .bits = CType.ushort.sizeInBits(target) },
1975 .c_int => .{ .signedness = .signed, .bits = CType.int.sizeInBits(target) },
1976 .c_uint => .{ .signedness = .unsigned, .bits = CType.uint.sizeInBits(target) },
1977 .c_long => .{ .signedness = .signed, .bits = CType.long.sizeInBits(target) },
1978 .c_ulong => .{ .signedness = .unsigned, .bits = CType.ulong.sizeInBits(target) },
1979 .c_longlong => .{ .signedness = .signed, .bits = CType.longlong.sizeInBits(target) },
1980 .c_ulonglong => .{ .signedness = .unsigned, .bits = CType.ulonglong.sizeInBits(target) },
19811981 };
19821982 }
19831983
......@@ -2869,7 +2869,7 @@ pub const Type = extern union {
28692869 assert(self.zigTypeTag() == .Int);
28702870 const info = self.intInfo(target);
28712871
2872 if (!info.signed) {
2872 if (info.signedness == .unsigned) {
28732873 return Value.initTag(.zero);
28742874 }
28752875
......@@ -2902,13 +2902,13 @@ pub const Type = extern union {
29022902 assert(self.zigTypeTag() == .Int);
29032903 const info = self.intInfo(target);
29042904
2905 if (info.signed and (info.bits - 1) <= std.math.maxInt(u6)) {
2905 if (info.signedness == .signed and (info.bits - 1) <= std.math.maxInt(u6)) {
29062906 const payload = try arena.allocator.create(Value.Payload.Int_i64);
29072907 payload.* = .{
29082908 .int = (@as(i64, 1) << @truncate(u6, info.bits - 1)) - 1,
29092909 };
29102910 return Value.initPayload(&payload.base);
2911 } else if (!info.signed and info.bits <= std.math.maxInt(u6)) {
2911 } else if (info.signedness == .signed and info.bits <= std.math.maxInt(u6)) {
29122912 const payload = try arena.allocator.create(Value.Payload.Int_u64);
29132913 payload.* = .{
29142914 .int = (@as(u64, 1) << @truncate(u6, info.bits)) - 1,
......@@ -2917,7 +2917,7 @@ pub const Type = extern union {
29172917 }
29182918
29192919 var res = try std.math.big.int.Managed.initSet(&arena.allocator, 1);
2920 try res.shiftLeft(res, info.bits - @boolToInt(info.signed));
2920 try res.shiftLeft(res, info.bits - @boolToInt(info.signedness == .signed));
29212921 const one = std.math.big.int.Const{
29222922 .limbs = &[_]std.math.big.Limb{1},
29232923 .positive = true,
src/value.zig+8-9
......@@ -929,11 +929,10 @@ pub const Value = extern union {
929929 .bool_true,
930930 => {
931931 const info = ty.intInfo(target);
932 if (info.signed) {
933 return info.bits >= 2;
934 } else {
935 return info.bits >= 1;
936 }
932 return switch (info.signedness) {
933 .signed => info.bits >= 2,
934 .unsigned => info.bits >= 1,
935 };
937936 },
938937
939938 .int_u64 => switch (ty.zigTypeTag()) {
......@@ -941,7 +940,7 @@ pub const Value = extern union {
941940 const x = self.cast(Payload.Int_u64).?.int;
942941 if (x == 0) return true;
943942 const info = ty.intInfo(target);
944 const needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signed);
943 const needed_bits = std.math.log2(x) + 1 + @boolToInt(info.signedness == .signed);
945944 return info.bits >= needed_bits;
946945 },
947946 .ComptimeInt => return true,
......@@ -952,7 +951,7 @@ pub const Value = extern union {
952951 const x = self.cast(Payload.Int_i64).?.int;
953952 if (x == 0) return true;
954953 const info = ty.intInfo(target);
955 if (!info.signed and x < 0)
954 if (info.signedness == .unsigned and x < 0)
956955 return false;
957956 @panic("TODO implement i64 intFitsInType");
958957 },
......@@ -962,7 +961,7 @@ pub const Value = extern union {
962961 .int_big_positive => switch (ty.zigTypeTag()) {
963962 .Int => {
964963 const info = ty.intInfo(target);
965 return self.cast(Payload.IntBigPositive).?.asBigInt().fitsInTwosComp(info.signed, info.bits);
964 return self.cast(Payload.IntBigPositive).?.asBigInt().fitsInTwosComp(info.signedness, info.bits);
966965 },
967966 .ComptimeInt => return true,
968967 else => unreachable,
......@@ -970,7 +969,7 @@ pub const Value = extern union {
970969 .int_big_negative => switch (ty.zigTypeTag()) {
971970 .Int => {
972971 const info = ty.intInfo(target);
973 return self.cast(Payload.IntBigNegative).?.asBigInt().fitsInTwosComp(info.signed, info.bits);
972 return self.cast(Payload.IntBigNegative).?.asBigInt().fitsInTwosComp(info.signedness, info.bits);
974973 },
975974 .ComptimeInt => return true,
976975 else => unreachable,
src/zir.zig+4-1
......@@ -2687,7 +2687,10 @@ const EmitZIR = struct {
26872687 },
26882688 .Int => {
26892689 const info = ty.intInfo(self.old_module.getTarget());
2690 const signed = try self.emitPrimitive(src, if (info.signed) .@"true" else .@"false");
2690 const signed = try self.emitPrimitive(src, switch (info.signedness) {
2691 .signed => .@"true",
2692 .unsigned => .@"false",
2693 });
26912694 const bits_payload = try self.arena.allocator.create(Value.Payload.Int_u64);
26922695 bits_payload.* = .{ .int = info.bits };
26932696 const bits = try self.emitComptimeIntVal(src, Value.initPayload(&bits_payload.base));
test/compile_errors.zig+12-11
......@@ -72,6 +72,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7272 "tmp.zig:8:12: note: called from here",
7373 });
7474
75 cases.add("@Type with TypeInfo.Int",
76 \\const builtin = @import("builtin");
77 \\export fn entry() void {
78 \\ _ = @Type(builtin.TypeInfo.Int {
79 \\ .signedness = .signed,
80 \\ .bits = 8,
81 \\ });
82 \\}
83 , &[_][]const u8{
84 "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'",
85 });
86
7587 cases.add("indexing a undefined slice at comptime",
7688 \\comptime {
7789 \\ var slice: []u8 = undefined;
......@@ -1827,17 +1839,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
18271839 "tmp.zig:4:15: error: unable to evaluate constant expression",
18281840 });
18291841
1830 cases.add("@Type with TypeInfo.Int",
1831 \\const builtin = @import("builtin");
1832 \\export fn entry() void {
1833 \\ _ = @Type(builtin.TypeInfo.Int {
1834 \\ .is_signed = true,
1835 \\ .bits = 8,
1836 \\ });
1837 \\}
1838 , &[_][]const u8{
1839 "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'",
1840 });
18411842 cases.add("wrong type for argument tuple to @asyncCall",
18421843 \\export fn entry1() void {
18431844 \\ var frame: @Frame(foo) = undefined;
test/stage1/behavior/type.zig+6-6
......@@ -31,12 +31,12 @@ test "Type.NoReturn" {
3131}
3232
3333test "Type.Int" {
34 testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 1 } }));
35 testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 1 } }));
36 testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 8 } }));
37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));
38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));
39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));
34 testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));
35 testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } }));
36 testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } }));
37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } }));
38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } }));
39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
4040 testTypes(&[_]type{ u8, u32, i64 });
4141}
4242
test/stage1/behavior/type_info.zig+1-1
......@@ -28,7 +28,7 @@ test "type info: integer, floating point type info" {
2828fn testIntFloat() void {
2929 const u8_info = @typeInfo(u8);
3030 expect(u8_info == .Int);
31 expect(!u8_info.Int.is_signed);
31 expect(u8_info.Int.signedness == .unsigned);
3232 expect(u8_info.Int.bits == 8);
3333
3434 const f64_info = @typeInfo(f64);