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) {...@@ -209,7 +209,7 @@ pub const TypeInfo = union(enum) {
209 /// This data structure is used by the Zig language code generation and209 /// This data structure is used by the Zig language code generation and
210 /// therefore must be kept in sync with the compiler implementation.210 /// therefore must be kept in sync with the compiler implementation.
211 pub const Int = struct {211 pub const Int = struct {
212 is_signed: bool,212 signedness: Signedness,
213 bits: comptime_int,213 bits: comptime_int,
214 };214 };
215215
...@@ -438,6 +438,13 @@ pub const Endian = enum {...@@ -438,6 +438,13 @@ pub const Endian = enum {
438 Little,438 Little,
439};439};
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
441/// This data structure is used by the Zig language code generation and448/// This data structure is used by the Zig language code generation and
442/// therefore must be kept in sync with the compiler implementation.449/// therefore must be kept in sync with the compiler implementation.
443pub const OutputMode = enum {450pub const OutputMode = enum {
lib/std/fmt.zig+1-1
...@@ -1028,7 +1028,7 @@ pub fn formatInt(...@@ -1028,7 +1028,7 @@ pub fn formatInt(
1028 if (a == 0) break;1028 if (a == 0) break;
1029 }1029 }
10301030
1031 if (value_info.is_signed) {1031 if (value_info.signedness == .signed) {
1032 if (value < 0) {1032 if (value < 0) {
1033 // Negative integer1033 // Negative integer
1034 index -= 1;1034 index -= 1;
lib/std/io/serialization.zig+1-1
...@@ -73,7 +73,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,...@@ -73,7 +73,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
7373
74 if (int_size == 1) {74 if (int_size == 1) {
75 if (t_bit_count == 8) return @bitCast(T, buffer[0]);75 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);
77 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));77 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
78 }78 }
7979
lib/std/json/write_stream.zig+1-1
...@@ -167,7 +167,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {...@@ -167,7 +167,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
167 self.popState();167 self.popState();
168 return;168 return;
169 }169 }
170 if (value < 4503599627370496 and (!info.is_signed or value > -4503599627370496)) {170 if (value < 4503599627370496 and (info.signedness == .unsigned or value > -4503599627370496)) {
171 try self.stream.print("{}", .{value});171 try self.stream.print("{}", .{value});
172 self.popState();172 self.popState();
173 return;173 return;
lib/std/leb128.zig+2-2
...@@ -297,8 +297,8 @@ test "deserialize unsigned LEB128" {...@@ -297,8 +297,8 @@ test "deserialize unsigned LEB128" {
297297
298fn test_write_leb128(value: anytype) !void {298fn test_write_leb128(value: anytype) !void {
299 const T = @TypeOf(value);299 const T = @TypeOf(value);
300 const t_signed = @typeInfo(T).Int.is_signed;300 const signedness = @typeInfo(T).Int.signedness;
301 const signedness = if (t_signed) .signed else .unsigned;301 const t_signed = signedness == .signed;
302302
303 const writeStream = if (t_signed) writeILEB128 else writeULEB128;303 const writeStream = if (t_signed) writeILEB128 else writeULEB128;
304 const readStream = if (t_signed) readILEB128 else readULEB128;304 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 {...@@ -313,7 +313,7 @@ pub fn floatExponentBits(comptime T: type) comptime_int {
313pub fn Min(comptime A: type, comptime B: type) type {313pub fn Min(comptime A: type, comptime B: type) type {
314 switch (@typeInfo(A)) {314 switch (@typeInfo(A)) {
315 .Int => |a_info| switch (@typeInfo(B)) {315 .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) {
317 if (a_info.bits < b_info.bits) {317 if (a_info.bits < b_info.bits) {
318 return A;318 return A;
319 } else {319 } else {
...@@ -450,7 +450,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {...@@ -450,7 +450,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
450 }450 }
451 };451 };
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) {
454 if (shift_amt < 0) {454 if (shift_amt < 0) {
455 return a >> casted_shift_amt;455 return a >> casted_shift_amt;
456 }456 }
...@@ -490,7 +490,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {...@@ -490,7 +490,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
490 }490 }
491 };491 };
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) {
494 if (shift_amt < 0) {494 if (shift_amt < 0) {
495 return a << casted_shift_amt;495 return a << casted_shift_amt;
496 }496 }
...@@ -518,12 +518,12 @@ test "math.shr" {...@@ -518,12 +518,12 @@ test "math.shr" {
518pub fn rotr(comptime T: type, x: T, r: anytype) T {518pub fn rotr(comptime T: type, x: T, r: anytype) T {
519 if (@typeInfo(T) == .Vector) {519 if (@typeInfo(T) == .Vector) {
520 const C = @typeInfo(T).Vector.child;520 const C = @typeInfo(T).Vector.child;
521 if (@typeInfo(C).Int.is_signed) {521 if (@typeInfo(C).Int.signedness == .signed) {
522 @compileError("cannot rotate signed integers");522 @compileError("cannot rotate signed integers");
523 }523 }
524 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));524 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));
525 return (x >> @splat(@typeInfo(T).Vector.len, ar)) | (x << @splat(@typeInfo(T).Vector.len, 1 + ~ar));525 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) {
527 @compileError("cannot rotate signed integer");527 @compileError("cannot rotate signed integer");
528 } else {528 } else {
529 const ar = @mod(r, @typeInfo(T).Int.bits);529 const ar = @mod(r, @typeInfo(T).Int.bits);
...@@ -546,12 +546,12 @@ test "math.rotr" {...@@ -546,12 +546,12 @@ test "math.rotr" {
546pub fn rotl(comptime T: type, x: T, r: anytype) T {546pub fn rotl(comptime T: type, x: T, r: anytype) T {
547 if (@typeInfo(T) == .Vector) {547 if (@typeInfo(T) == .Vector) {
548 const C = @typeInfo(T).Vector.child;548 const C = @typeInfo(T).Vector.child;
549 if (@typeInfo(C).Int.is_signed) {549 if (@typeInfo(C).Int.signedness == .signed) {
550 @compileError("cannot rotate signed integers");550 @compileError("cannot rotate signed integers");
551 }551 }
552 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));552 const ar = @intCast(Log2Int(C), @mod(r, @typeInfo(C).Int.bits));
553 return (x << @splat(@typeInfo(T).Vector.len, ar)) | (x >> @splat(@typeInfo(T).Vector.len, 1 +% ~ar));553 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) {
555 @compileError("cannot rotate signed integer");555 @compileError("cannot rotate signed integer");
556 } else {556 } else {
557 const ar = @mod(r, @typeInfo(T).Int.bits);557 const ar = @mod(r, @typeInfo(T).Int.bits);
...@@ -585,7 +585,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t...@@ -585,7 +585,7 @@ pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) t
585 if (from == 0 and to == 0) {585 if (from == 0 and to == 0) {
586 return u0;586 return u0;
587 }587 }
588 const sign: std.meta.Signedness = if (from < 0) .signed else .unsigned;588 const sign: std.builtin.Signedness = if (from < 0) .signed else .unsigned;
589 const largest_positive_integer = max(if (from < 0) (-from) - 1 else from, to); // two's complement589 const largest_positive_integer = max(if (from < 0) (-from) - 1 else from, to); // two's complement
590 const base = log2(largest_positive_integer);590 const base = log2(largest_positive_integer);
591 const upper = (1 << base) - 1;591 const upper = (1 << base) - 1;
...@@ -658,7 +658,7 @@ fn testOverflow() void {...@@ -658,7 +658,7 @@ fn testOverflow() void {
658pub fn absInt(x: anytype) !@TypeOf(x) {658pub fn absInt(x: anytype) !@TypeOf(x) {
659 const T = @TypeOf(x);659 const T = @TypeOf(x);
660 comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt660 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 absInt661 comptime assert(@typeInfo(T).Int.signedness == .signed); // must pass a signed integer to absInt
662662
663 if (x == minInt(@TypeOf(x))) {663 if (x == minInt(@TypeOf(x))) {
664 return error.Overflow;664 return error.Overflow;
...@@ -691,7 +691,7 @@ fn testAbsFloat() void {...@@ -691,7 +691,7 @@ fn testAbsFloat() void {
691pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {691pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
692 @setRuntimeSafety(false);692 @setRuntimeSafety(false);
693 if (denominator == 0) return error.DivisionByZero;693 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;
695 return @divTrunc(numerator, denominator);695 return @divTrunc(numerator, denominator);
696}696}
697697
...@@ -712,7 +712,7 @@ fn testDivTrunc() void {...@@ -712,7 +712,7 @@ fn testDivTrunc() void {
712pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {712pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
713 @setRuntimeSafety(false);713 @setRuntimeSafety(false);
714 if (denominator == 0) return error.DivisionByZero;714 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;
716 return @divFloor(numerator, denominator);716 return @divFloor(numerator, denominator);
717}717}
718718
...@@ -786,7 +786,7 @@ fn testDivCeil() void {...@@ -786,7 +786,7 @@ fn testDivCeil() void {
786pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {786pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
787 @setRuntimeSafety(false);787 @setRuntimeSafety(false);
788 if (denominator == 0) return error.DivisionByZero;788 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;
790 const result = @divTrunc(numerator, denominator);790 const result = @divTrunc(numerator, denominator);
791 if (result * denominator != numerator) return error.UnexpectedRemainder;791 if (result * denominator != numerator) return error.UnexpectedRemainder;
792 return result;792 return result;
...@@ -892,7 +892,7 @@ test "math.absCast" {...@@ -892,7 +892,7 @@ test "math.absCast" {
892/// Returns the negation of the integer parameter.892/// Returns the negation of the integer parameter.
893/// Result is a signed integer.893/// Result is a signed integer.
894pub fn negateCast(x: anytype) !std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x))) {894pub 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
897 const int = std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x)));897 const int = std.meta.Int(.signed, std.meta.bitCount(@TypeOf(x)));
898 if (x > -minInt(int)) return error.Overflow;898 if (x > -minInt(int)) return error.Overflow;
...@@ -981,11 +981,11 @@ fn testFloorPowerOfTwo() void {...@@ -981,11 +981,11 @@ fn testFloorPowerOfTwo() void {
981/// Returns the next power of two (if the value is not already a power of two).981/// Returns the next power of two (if the value is not already a power of two).
982/// Only unsigned integers can be used. Zero is not an allowed input.982/// Only unsigned integers can be used. Zero is not an allowed input.
983/// Result is a type with 1 more bit than the input type.983/// 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) {
985 comptime assert(@typeInfo(T) == .Int);985 comptime assert(@typeInfo(T) == .Int);
986 comptime assert(!@typeInfo(T).Int.is_signed);986 comptime assert(@typeInfo(T).Int.signedness == .unsigned);
987 assert(value != 0);987 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);
989 comptime const shiftType = std.math.Log2Int(PromotedType);989 comptime const shiftType = std.math.Log2Int(PromotedType);
990 return @as(PromotedType, 1) << @intCast(shiftType, @typeInfo(T).Int.bits - @clz(T, value - 1));990 return @as(PromotedType, 1) << @intCast(shiftType, @typeInfo(T).Int.bits - @clz(T, value - 1));
991}991}
...@@ -996,8 +996,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(if (@typeI...@@ -996,8 +996,8 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(if (@typeI
996pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {996pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
997 comptime assert(@typeInfo(T) == .Int);997 comptime assert(@typeInfo(T) == .Int);
998 const info = @typeInfo(T).Int;998 const info = @typeInfo(T).Int;
999 comptime assert(!info.is_signed);999 comptime assert(info.signedness == .unsigned);
1000 comptime const PromotedType = std.meta.Int(if (info.is_signed) .signed else .unsigned, info.bits + 1);1000 comptime const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
1001 comptime const overflowBit = @as(PromotedType, 1) << info.bits;1001 comptime const overflowBit = @as(PromotedType, 1) << info.bits;
1002 var x = ceilPowerOfTwoPromote(T, value);1002 var x = ceilPowerOfTwoPromote(T, value);
1003 if (overflowBit & x != 0) {1003 if (overflowBit & x != 0) {
...@@ -1090,13 +1090,13 @@ pub fn maxInt(comptime T: type) comptime_int {...@@ -1090,13 +1090,13 @@ pub fn maxInt(comptime T: type) comptime_int {
1090 const info = @typeInfo(T);1090 const info = @typeInfo(T);
1091 const bit_count = info.Int.bits;1091 const bit_count = info.Int.bits;
1092 if (bit_count == 0) return 0;1092 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;
1094}1094}
10951095
1096pub fn minInt(comptime T: type) comptime_int {1096pub fn minInt(comptime T: type) comptime_int {
1097 const info = @typeInfo(T);1097 const info = @typeInfo(T);
1098 const bit_count = info.Int.bits;1098 const bit_count = info.Int.bits;
1099 if (!info.Int.is_signed) return 0;1099 if (info.Int.signedness == .unsigned) return 0;
1100 if (bit_count == 0) return 0;1100 if (bit_count == 0) return 0;
1101 return -(1 << (bit_count - 1));1101 return -(1 << (bit_count - 1));
1102}1102}
...@@ -1143,8 +1143,8 @@ test "max value type" {...@@ -1143,8 +1143,8 @@ test "max value type" {
1143 testing.expect(x == 2147483647);1143 testing.expect(x == 2147483647);
1144}1144}
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) {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(if (@typeInfo(T).Int.is_signed) .signed else .unsigned, @typeInfo(T).Int.bits * 2);1147 const ResultInt = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits * 2);
1148 return @as(ResultInt, a) * @as(ResultInt, b);1148 return @as(ResultInt, a) * @as(ResultInt, b);
1149}1149}
11501150
lib/std/math/big.zig+1-1
...@@ -17,7 +17,7 @@ pub const Log2Limb = std.math.Log2Int(Limb);...@@ -17,7 +17,7 @@ pub const Log2Limb = std.math.Log2Int(Limb);
17comptime {17comptime {
18 assert(std.math.floorPowerOfTwo(usize, limb_info.bits) == limb_info.bits);18 assert(std.math.floorPowerOfTwo(usize, limb_info.bits) == limb_info.bits);
19 assert(limb_info.bits <= 64); // u128 set is unsupported19 assert(limb_info.bits <= 64); // u128 set is unsupported
20 assert(limb_info.is_signed == false);20 assert(limb_info.signedness == .unsigned);
21}21}
2222
23test "" {23test "" {
lib/std/math/big/int.zig+9-9
...@@ -24,7 +24,7 @@ pub fn calcLimbLen(scalar: anytype) usize {...@@ -24,7 +24,7 @@ pub fn calcLimbLen(scalar: anytype) usize {
24 const T = @TypeOf(scalar);24 const T = @TypeOf(scalar);
25 switch (@typeInfo(T)) {25 switch (@typeInfo(T)) {
26 .Int => |info| {26 .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;
28 return @sizeOf(UT) / @sizeOf(Limb);28 return @sizeOf(UT) / @sizeOf(Limb);
29 },29 },
30 .ComptimeInt => {30 .ComptimeInt => {
...@@ -187,7 +187,7 @@ pub const Mutable = struct {...@@ -187,7 +187,7 @@ pub const Mutable = struct {
187187
188 switch (@typeInfo(T)) {188 switch (@typeInfo(T)) {
189 .Int => |info| {189 .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
192 const needed_limbs = @sizeOf(UT) / @sizeOf(Limb);192 const needed_limbs = @sizeOf(UT) / @sizeOf(Limb);
193 assert(needed_limbs <= self.limbs.len); // value too big193 assert(needed_limbs <= self.limbs.len); // value too big
...@@ -1054,22 +1054,22 @@ pub const Const = struct {...@@ -1054,22 +1054,22 @@ pub const Const = struct {
1054 return bits;1054 return bits;
1055 }1055 }
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 {
1058 if (self.eqZero()) {1058 if (self.eqZero()) {
1059 return true;1059 return true;
1060 }1060 }
1061 if (!is_signed and !self.positive) {1061 if (signedness == .unsigned and !self.positive) {
1062 return false;1062 return false;
1063 }1063 }
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);
1066 return bit_count >= req_bits;1066 return bit_count >= req_bits;
1067 }1067 }
10681068
1069 /// Returns whether self can fit into an integer of the requested type.1069 /// Returns whether self can fit into an integer of the requested type.
1070 pub fn fits(self: Const, comptime T: type) bool {1070 pub fn fits(self: Const, comptime T: type) bool {
1071 const info = @typeInfo(T).Int;1071 const info = @typeInfo(T).Int;
1072 return self.fitsInTwosComp(info.is_signed, info.bits);1072 return self.fitsInTwosComp(info.signedness, info.bits);
1073 }1073 }
10741074
1075 /// Returns the approximate size of the integer in the given base. Negative values accommodate for1075 /// Returns the approximate size of the integer in the given base. Negative values accommodate for
...@@ -1110,7 +1110,7 @@ pub const Const = struct {...@@ -1110,7 +1110,7 @@ pub const Const = struct {
1110 }1110 }
1111 }1111 }
11121112
1113 if (!info.is_signed) {1113 if (info.signedness == .unsigned) {
1114 return if (self.positive) @intCast(T, r) else error.NegativeIntoUnsigned;1114 return if (self.positive) @intCast(T, r) else error.NegativeIntoUnsigned;
1115 } else {1115 } else {
1116 if (self.positive) {1116 if (self.positive) {
...@@ -1558,8 +1558,8 @@ pub const Managed = struct {...@@ -1558,8 +1558,8 @@ pub const Managed = struct {
1558 return self.toConst().bitCountTwosComp();1558 return self.toConst().bitCountTwosComp();
1559 }1559 }
15601560
1561 pub fn fitsInTwosComp(self: Managed, is_signed: bool, bit_count: usize) bool {1561 pub fn fitsInTwosComp(self: Managed, signedness: std.builtin.Signedness, bit_count: usize) bool {
1562 return self.toConst().fitsInTwosComp(is_signed, bit_count);1562 return self.toConst().fitsInTwosComp(signedness, bit_count);
1563 }1563 }
15641564
1565 /// Returns whether self can fit into an integer of the requested type.1565 /// 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{...@@ -48,7 +48,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{
48 // powi(x, y) = Overflow for for y >= @sizeOf(x) - 1 y > 048 // powi(x, y) = Overflow for for y >= @sizeOf(x) - 1 y > 0
49 // powi(x, y) = Underflow for for y > @sizeOf(x) - 1 y < 049 // powi(x, y) = Underflow for for y > @sizeOf(x) - 1 y < 0
50 const bit_size = @sizeOf(T) * 8;50 const bit_size = @sizeOf(T) * 8;
51 if (info.Int.is_signed) {51 if (info.Int.signedness == .signed) {
52 if (x == -1) {52 if (x == -1) {
53 // powi(-1, y) = -1 for for y an odd integer53 // powi(-1, y) = -1 for for y an odd integer
54 // powi(-1, y) = 1 for for y an even integer54 // 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...@@ -718,15 +718,10 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De
718718
719pub const IntType = @compileError("replaced by std.meta.Int");719pub const IntType = @compileError("replaced by std.meta.Int");
720720
721pub const Signedness = enum {721pub fn Int(comptime signedness: builtin.Signedness, comptime bit_count: u16) type {
722 unsigned,
723 signed,
724};
725
726pub fn Int(comptime signedness: Signedness, comptime bit_count: u16) type {
727 return @Type(TypeInfo{722 return @Type(TypeInfo{
728 .Int = .{723 .Int = .{
729 .is_signed = signedness == .signed,724 .signedness = signedness,
730 .bits = bit_count,725 .bits = bit_count,
731 },726 },
732 });727 });
lib/std/meta/trait.zig+2-2
...@@ -195,7 +195,7 @@ test "std.meta.trait.isPacked" {...@@ -195,7 +195,7 @@ test "std.meta.trait.isPacked" {
195195
196pub fn isUnsignedInt(comptime T: type) bool {196pub fn isUnsignedInt(comptime T: type) bool {
197 return switch (@typeInfo(T)) {197 return switch (@typeInfo(T)) {
198 .Int => |i| !i.is_signed,198 .Int => |i| i.signedness == .unsigned,
199 else => false,199 else => false,
200 };200 };
201}201}
...@@ -210,7 +210,7 @@ test "isUnsignedInt" {...@@ -210,7 +210,7 @@ test "isUnsignedInt" {
210pub fn isSignedInt(comptime T: type) bool {210pub fn isSignedInt(comptime T: type) bool {
211 return switch (@typeInfo(T)) {211 return switch (@typeInfo(T)) {
212 .ComptimeInt => true,212 .ComptimeInt => true,
213 .Int => |i| i.is_signed,213 .Int => |i| i.signedness == .signed,
214 else => false,214 else => false,
215 };215 };
216}216}
lib/std/os.zig+1-6
...@@ -4868,12 +4868,7 @@ pub fn sendfile(...@@ -4868,12 +4868,7 @@ pub fn sendfile(
4868 var total_written: usize = 0;4868 var total_written: usize = 0;
48694869
4870 // Prevents EOVERFLOW.4870 // Prevents EOVERFLOW.
4871 const size_t = @Type(std.builtin.TypeInfo{4871 const size_t = std.meta.Int(.unsigned, @typeInfo(usize).Int.bits - 1);
4872 .Int = .{
4873 .is_signed = false,
4874 .bits = @typeInfo(usize).Int.bits - 1,
4875 },
4876 });
4877 const max_count = switch (std.Target.current.os.tag) {4872 const max_count = switch (std.Target.current.os.tag) {
4878 .linux => 0x7ffff000,4873 .linux => 0x7ffff000,
4879 .macos, .ios, .watchos, .tvos => math.maxInt(i32),4874 .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 {...@@ -777,7 +777,7 @@ pub fn seteuid(euid: uid_t) usize {
777 // The setresuid(2) man page says that if -1 is passed the corresponding777 // The setresuid(2) man page says that if -1 is passed the corresponding
778 // id will not be changed. Since uid_t is unsigned, this wraps around to the778 // id will not be changed. Since uid_t is unsigned, this wraps around to the
779 // max value in C.779 // 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);
781 return setresuid(std.math.maxInt(uid_t), euid, std.math.maxInt(uid_t));781 return setresuid(std.math.maxInt(uid_t), euid, std.math.maxInt(uid_t));
782}782}
783783
...@@ -788,7 +788,7 @@ pub fn setegid(egid: gid_t) usize {...@@ -788,7 +788,7 @@ pub fn setegid(egid: gid_t) usize {
788 // The setresgid(2) man page says that if -1 is passed the corresponding788 // The setresgid(2) man page says that if -1 is passed the corresponding
789 // id will not be changed. Since gid_t is unsigned, this wraps around to the789 // id will not be changed. Since gid_t is unsigned, this wraps around to the
790 // max value in C.790 // 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);
792 return setresgid(std.math.maxInt(gid_t), egid, std.math.maxInt(gid_t));792 return setresgid(std.math.maxInt(gid_t), egid, std.math.maxInt(gid_t));
793}793}
794794
lib/std/packed_int_array.zig+2-2
...@@ -332,7 +332,7 @@ test "PackedIntArray" {...@@ -332,7 +332,7 @@ test "PackedIntArray" {
332 comptime var bits = 0;332 comptime var bits = 0;
333 inline while (bits <= max_bits) : (bits += 1) {333 inline while (bits <= max_bits) : (bits += 1) {
334 //alternate unsigned and signed334 //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;
336 const I = std.meta.Int(sign, bits);336 const I = std.meta.Int(sign, bits);
337337
338 const PackedArray = PackedIntArray(I, int_count);338 const PackedArray = PackedIntArray(I, int_count);
...@@ -384,7 +384,7 @@ test "PackedIntSlice" {...@@ -384,7 +384,7 @@ test "PackedIntSlice" {
384 comptime var bits = 0;384 comptime var bits = 0;
385 inline while (bits <= max_bits) : (bits += 1) {385 inline while (bits <= max_bits) : (bits += 1) {
386 //alternate unsigned and signed386 //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;
388 const I = std.meta.Int(sign, bits);388 const I = std.meta.Int(sign, bits);
389 const P = PackedIntSlice(I);389 const P = PackedIntSlice(I);
390390
lib/std/rand.zig+9-9
...@@ -69,7 +69,7 @@ pub const Random = struct {...@@ -69,7 +69,7 @@ pub const Random = struct {
69 /// Constant-time implementation off `uintLessThan`.69 /// Constant-time implementation off `uintLessThan`.
70 /// The results of this function may be biased.70 /// The results of this function may be biased.
71 pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T {71 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);
73 const bits = @typeInfo(T).Int.bits;73 const bits = @typeInfo(T).Int.bits;
74 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!74 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
75 assert(0 < less_than);75 assert(0 < less_than);
...@@ -89,7 +89,7 @@ pub const Random = struct {...@@ -89,7 +89,7 @@ pub const Random = struct {
89 /// this function is guaranteed to return.89 /// this function is guaranteed to return.
90 /// If you need deterministic runtime bounds, use `uintLessThanBiased`.90 /// If you need deterministic runtime bounds, use `uintLessThanBiased`.
91 pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T {91 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);
93 const bits = @typeInfo(T).Int.bits;93 const bits = @typeInfo(T).Int.bits;
94 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!94 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
95 assert(0 < less_than);95 assert(0 < less_than);
...@@ -129,7 +129,7 @@ pub const Random = struct {...@@ -129,7 +129,7 @@ pub const Random = struct {
129 /// Constant-time implementation off `uintAtMost`.129 /// Constant-time implementation off `uintAtMost`.
130 /// The results of this function may be biased.130 /// The results of this function may be biased.
131 pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T {131 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);
133 if (at_most == maxInt(T)) {133 if (at_most == maxInt(T)) {
134 // have the full range134 // have the full range
135 return r.int(T);135 return r.int(T);
...@@ -141,7 +141,7 @@ pub const Random = struct {...@@ -141,7 +141,7 @@ pub const Random = struct {
141 /// See `uintLessThan`, which this function uses in most cases,141 /// See `uintLessThan`, which this function uses in most cases,
142 /// for commentary on the runtime of this function.142 /// for commentary on the runtime of this function.
143 pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {143 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);
145 if (at_most == maxInt(T)) {145 if (at_most == maxInt(T)) {
146 // have the full range146 // have the full range
147 return r.int(T);147 return r.int(T);
...@@ -154,7 +154,7 @@ pub const Random = struct {...@@ -154,7 +154,7 @@ pub const Random = struct {
154 pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T {154 pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T {
155 assert(at_least < less_than);155 assert(at_least < less_than);
156 const info = @typeInfo(T).Int;156 const info = @typeInfo(T).Int;
157 if (info.is_signed) {157 if (info.signedness == .signed) {
158 // Two's complement makes this math pretty easy.158 // Two's complement makes this math pretty easy.
159 const UnsignedT = std.meta.Int(.unsigned, info.bits);159 const UnsignedT = std.meta.Int(.unsigned, info.bits);
160 const lo = @bitCast(UnsignedT, at_least);160 const lo = @bitCast(UnsignedT, at_least);
...@@ -173,7 +173,7 @@ pub const Random = struct {...@@ -173,7 +173,7 @@ pub const Random = struct {
173 pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T {173 pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T {
174 assert(at_least < less_than);174 assert(at_least < less_than);
175 const info = @typeInfo(T).Int;175 const info = @typeInfo(T).Int;
176 if (info.is_signed) {176 if (info.signedness == .signed) {
177 // Two's complement makes this math pretty easy.177 // Two's complement makes this math pretty easy.
178 const UnsignedT = std.meta.Int(.unsigned, info.bits);178 const UnsignedT = std.meta.Int(.unsigned, info.bits);
179 const lo = @bitCast(UnsignedT, at_least);179 const lo = @bitCast(UnsignedT, at_least);
...@@ -191,7 +191,7 @@ pub const Random = struct {...@@ -191,7 +191,7 @@ pub const Random = struct {
191 pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T {191 pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T {
192 assert(at_least <= at_most);192 assert(at_least <= at_most);
193 const info = @typeInfo(T).Int;193 const info = @typeInfo(T).Int;
194 if (info.is_signed) {194 if (info.signedness == .signed) {
195 // Two's complement makes this math pretty easy.195 // Two's complement makes this math pretty easy.
196 const UnsignedT = std.meta.Int(.unsigned, info.bits);196 const UnsignedT = std.meta.Int(.unsigned, info.bits);
197 const lo = @bitCast(UnsignedT, at_least);197 const lo = @bitCast(UnsignedT, at_least);
...@@ -210,7 +210,7 @@ pub const Random = struct {...@@ -210,7 +210,7 @@ pub const Random = struct {
210 pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T {210 pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T {
211 assert(at_least <= at_most);211 assert(at_least <= at_most);
212 const info = @typeInfo(T).Int;212 const info = @typeInfo(T).Int;
213 if (info.is_signed) {213 if (info.signedness == .signed) {
214 // Two's complement makes this math pretty easy.214 // Two's complement makes this math pretty easy.
215 const UnsignedT = std.meta.Int(.unsigned, info.bits);215 const UnsignedT = std.meta.Int(.unsigned, info.bits);
216 const lo = @bitCast(UnsignedT, at_least);216 const lo = @bitCast(UnsignedT, at_least);
...@@ -288,7 +288,7 @@ pub const Random = struct {...@@ -288,7 +288,7 @@ pub const Random = struct {
288/// into an integer 0 <= result < less_than.288/// into an integer 0 <= result < less_than.
289/// This function introduces a minor bias.289/// This function introduces a minor bias.
290pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {290pub 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);
292 const bits = @typeInfo(T).Int.bits;292 const bits = @typeInfo(T).Int.bits;
293 const T2 = std.meta.Int(.unsigned, bits * 2);293 const T2 = std.meta.Int(.unsigned, bits * 2);
294294
lib/std/start.zig+2-2
...@@ -325,7 +325,7 @@ pub fn callMain() u8 {...@@ -325,7 +325,7 @@ pub fn callMain() u8 {
325 return 0;325 return 0;
326 },326 },
327 .Int => |info| {327 .Int => |info| {
328 if (info.bits != 8 or info.is_signed) {328 if (info.bits != 8 or info.signedness == .signed) {
329 @compileError(bad_main_ret);329 @compileError(bad_main_ret);
330 }330 }
331 return root.main();331 return root.main();
...@@ -341,7 +341,7 @@ pub fn callMain() u8 {...@@ -341,7 +341,7 @@ pub fn callMain() u8 {
341 switch (@typeInfo(@TypeOf(result))) {341 switch (@typeInfo(@TypeOf(result))) {
342 .Void => return 0,342 .Void => return 0,
343 .Int => |info| {343 .Int => |info| {
344 if (info.bits != 8 or info.is_signed) {344 if (info.bits != 8 or info.signedness == .signed) {
345 @compileError(bad_main_ret);345 @compileError(bad_main_ret);
346 }346 }
347 return result;347 return result;
src/Module.zig+4-4
...@@ -2633,7 +2633,7 @@ pub fn cmpNumeric(...@@ -2633,7 +2633,7 @@ pub fn cmpNumeric(
2633 dest_float_type = lhs.ty;2633 dest_float_type = lhs.ty;
2634 } else {2634 } else {
2635 const int_info = lhs.ty.intInfo(self.getTarget());2635 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);
2637 }2637 }
26382638
2639 var rhs_bits: usize = undefined;2639 var rhs_bits: usize = undefined;
...@@ -2668,7 +2668,7 @@ pub fn cmpNumeric(...@@ -2668,7 +2668,7 @@ pub fn cmpNumeric(
2668 dest_float_type = rhs.ty;2668 dest_float_type = rhs.ty;
2669 } else {2669 } else {
2670 const int_info = rhs.ty.intInfo(self.getTarget());2670 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);
2672 }2672 }
26732673
2674 const dest_type = if (dest_float_type) |ft| ft else blk: {2674 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...@@ -2817,9 +2817,9 @@ pub fn coerce(self: *Module, scope: *Scope, dest_type: Type, inst: *Inst) !*Inst
28172817
2818 const src_info = inst.ty.intInfo(self.getTarget());2818 const src_info = inst.ty.intInfo(self.getTarget());
2819 const dst_info = dest_type.intInfo(self.getTarget());2819 const dst_info = dest_type.intInfo(self.getTarget());
2820 if ((src_info.signed == dst_info.signed and dst_info.bits >= src_info.bits) or2820 if ((src_info.signedness == dst_info.signedness and dst_info.bits >= src_info.bits) or
2821 // small enough unsigned ints can get casted to large enough signed ints2821 // 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))
2823 {2823 {
2824 const b = try self.requireRuntimeBlock(scope, inst.src);2824 const b = try self.requireRuntimeBlock(scope, inst.src);
2825 return self.addUnOp(b, inst.src, dest_type, .intcast, inst);2825 return self.addUnOp(b, inst.src, dest_type, .intcast, inst);
src/codegen.zig+9-15
...@@ -203,7 +203,7 @@ pub fn generateSymbol(...@@ -203,7 +203,7 @@ pub fn generateSymbol(
203 .Int => {203 .Int => {
204 // TODO populate .debug_info for the integer204 // TODO populate .debug_info for the integer
205 const info = typed_value.ty.intInfo(bin_file.options.target);205 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) {
207 const x = typed_value.val.toUnsignedInt();207 const x = typed_value.val.toUnsignedInt();
208 try code.append(@intCast(u8, x));208 try code.append(@intCast(u8, x));
209 return Result{ .appended = {} };209 return Result{ .appended = {} };
...@@ -920,7 +920,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -920,7 +920,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
920 const operand = try self.resolveInst(inst.operand);920 const operand = try self.resolveInst(inst.operand);
921 const info_a = inst.operand.ty.intInfo(self.target.*);921 const info_a = inst.operand.ty.intInfo(self.target.*);
922 const info_b = inst.base.ty.intInfo(self.target.*);922 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)
924 return self.fail(inst.base.src, "TODO gen intcast sign safety in semantic analysis", .{});924 return self.fail(inst.base.src, "TODO gen intcast sign safety in semantic analysis", .{});
925925
926 if (info_a.bits == info_b.bits)926 if (info_a.bits == info_b.bits)
...@@ -1780,7 +1780,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1780,7 +1780,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
1780 fn genCmp(self: *Self, inst: *ir.Inst.BinOp, op: math.CompareOperator) !MCValue {1780 fn genCmp(self: *Self, inst: *ir.Inst.BinOp, op: math.CompareOperator) !MCValue {
1781 // No side effects, so if it's unreferenced, do nothing.1781 // No side effects, so if it's unreferenced, do nothing.
1782 if (inst.base.isUnused())1782 if (inst.base.isUnused())
1783 return MCValue.dead;1783 return MCValue{ .dead = {} };
1784 switch (arch) {1784 switch (arch) {
1785 .x86_64 => {1785 .x86_64 => {
1786 try self.code.ensureCapacity(self.code.items.len + 8);1786 try self.code.ensureCapacity(self.code.items.len + 8);
...@@ -1800,11 +1800,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -1800,11 +1800,10 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
18001800
1801 try self.genX8664BinMathCode(inst.base.src, inst.base.ty, dst_mcv, src_mcv, 7, 0x38);1801 try self.genX8664BinMathCode(inst.base.src, inst.base.ty, dst_mcv, src_mcv, 7, 0x38);
1802 const info = inst.lhs.ty.intInfo(self.target.*);1802 const info = inst.lhs.ty.intInfo(self.target.*);
1803 if (info.signed) {1803 return switch (info.signedness) {
1804 return MCValue{ .compare_flags_signed = op };1804 .signed => MCValue{ .compare_flags_signed = op },
1805 } else {1805 .unsigned => MCValue{ .compare_flags_unsigned = op },
1806 return MCValue{ .compare_flags_unsigned = op };1806 };
1807 }
1808 },1807 },
1809 else => return self.fail(inst.base.src, "TODO implement cmp for {}", .{self.target.cpu.arch}),1808 else => return self.fail(inst.base.src, "TODO implement cmp for {}", .{self.target.cpu.arch}),
1810 }1809 }
...@@ -2904,12 +2903,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2904,12 +2903,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2904 switch (mcv) {2903 switch (mcv) {
2905 .immediate => |imm| {2904 .immediate => |imm| {
2906 // This immediate is unsigned.2905 // This immediate is unsigned.
2907 const U = @Type(.{2906 const U = std.meta.Int(.unsigned, ti.bits - @boolToInt(ti.signedness == .signed));
2908 .Int = .{
2909 .bits = ti.bits - @boolToInt(ti.is_signed),
2910 .is_signed = false,
2911 },
2912 });
2913 if (imm >= math.maxInt(U)) {2907 if (imm >= math.maxInt(U)) {
2914 return MCValue{ .register = try self.copyToTmpRegister(inst.src, mcv) };2908 return MCValue{ .register = try self.copyToTmpRegister(inst.src, mcv) };
2915 }2909 }
...@@ -2949,7 +2943,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {...@@ -2949,7 +2943,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
2949 },2943 },
2950 .Int => {2944 .Int => {
2951 const info = typed_value.ty.intInfo(self.target.*);2945 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) {
2953 return self.fail(src, "TODO const int bigger than ptr and signed int", .{});2947 return self.fail(src, "TODO const int bigger than ptr and signed int", .{});
2954 }2948 }
2955 return MCValue{ .immediate = typed_value.val.toUnsignedInt() };2949 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...@@ -2443,7 +2443,10 @@ fn addDbgInfoType(self: *Elf, ty: Type, dbg_info_buffer: *std.ArrayList(u8)) !vo
2443 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12);2443 try dbg_info_buffer.ensureCapacity(dbg_info_buffer.items.len + 12);
2444 dbg_info_buffer.appendAssumeCapacity(abbrev_base_type);2444 dbg_info_buffer.appendAssumeCapacity(abbrev_base_type);
2445 // DW.AT_encoding, DW.FORM_data12445 // 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 });
2447 // DW.AT_byte_size, DW.FORM_data12450 // DW.AT_byte_size, DW.FORM_data1
2448 dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(self.base.options.target)));2451 dbg_info_buffer.appendAssumeCapacity(@intCast(u8, ty.abiSize(self.base.options.target)));
2449 // DW.AT_name, DW.FORM_string2452 // 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...@@ -25306,11 +25306,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
25306 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);25306 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
25307 result->data.x_struct.fields = fields;25307 result->data.x_struct.fields = fields;
2530825308
25309 // is_signed: bool25309 // is_signed: Signedness
25310 ensure_field_index(result->type, "is_signed", 0);25310 ensure_field_index(result->type, "signedness", 0);
25311 fields[0]->special = ConstValSpecialStatic;25311 fields[0]->special = ConstValSpecialStatic;
25312 fields[0]->type = ira->codegen->builtin_types.entry_bool;25312 fields[0]->type = get_builtin_type(ira->codegen, "Signedness");
25313 fields[0]->data.x_bool = type_entry->data.integral.is_signed;25313 bigint_init_unsigned(&fields[0]->data.x_enum_tag, !type_entry->data.integral.is_signed);
25314 // bits: u825314 // bits: u8
25315 ensure_field_index(result->type, "bits", 1);25315 ensure_field_index(result->type, "bits", 1);
25316 fields[1]->special = ConstValSpecialStatic;25316 fields[1]->special = ConstValSpecialStatic;
...@@ -26073,9 +26073,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI...@@ -26073,9 +26073,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI
26073 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);26073 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);
26074 if (bi == nullptr)26074 if (bi == nullptr)
26075 return ira->codegen->invalid_inst_gen->value->type;26075 return ira->codegen->invalid_inst_gen->value->type;
26076 bool is_signed;26076 ZigValue *value = get_const_field(ira, source_instr->source_node, payload, "signedness", 0);
26077 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed)))26077 if (value == nullptr)
26078 return ira->codegen->invalid_inst_gen->value->type;26078 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);
26079 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));26081 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
26080 }26082 }
26081 case ZigTypeIdFloat:26083 case ZigTypeIdFloat:
src/type.zig+27-27
...@@ -186,7 +186,7 @@ pub const Type = extern union {...@@ -186,7 +186,7 @@ pub const Type = extern union {
186 // The target will not be branched upon, because we handled target-dependent cases above.186 // The target will not be branched upon, because we handled target-dependent cases above.
187 const info_a = a.intInfo(@as(Target, undefined));187 const info_a = a.intInfo(@as(Target, undefined));
188 const info_b = b.intInfo(@as(Target, undefined));188 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;
190 },190 },
191 .Array => {191 .Array => {
192 if (a.arrayLen() != b.arrayLen())192 if (a.arrayLen() != b.arrayLen())
...@@ -266,7 +266,7 @@ pub const Type = extern union {...@@ -266,7 +266,7 @@ pub const Type = extern union {
266 // Remaining cases are arbitrary sized integers.266 // Remaining cases are arbitrary sized integers.
267 // The target will not be branched upon, because we handled target-dependent cases above.267 // The target will not be branched upon, because we handled target-dependent cases above.
268 const info = self.intInfo(@as(Target, undefined));268 const info = self.intInfo(@as(Target, undefined));
269 std.hash.autoHash(&hasher, info.signed);269 std.hash.autoHash(&hasher, info.signedness);
270 std.hash.autoHash(&hasher, info.bits);270 std.hash.autoHash(&hasher, info.bits);
271 }271 }
272 },272 },
...@@ -1908,7 +1908,7 @@ pub const Type = extern union {...@@ -1908,7 +1908,7 @@ pub const Type = extern union {
1908 }1908 }
19091909
1910 /// Asserts the type is an integer.1910 /// 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 } {
1912 return switch (self.tag()) {1912 return switch (self.tag()) {
1913 .f16,1913 .f16,
1914 .f32,1914 .f32,
...@@ -1958,26 +1958,26 @@ pub const Type = extern union {...@@ -1958,26 +1958,26 @@ pub const Type = extern union {
1958 .empty_struct,1958 .empty_struct,
1959 => unreachable,1959 => unreachable,
19601960
1961 .int_unsigned => .{ .signed = false, .bits = self.cast(Payload.IntUnsigned).?.bits },1961 .int_unsigned => .{ .signedness = .unsigned, .bits = self.cast(Payload.IntUnsigned).?.bits },
1962 .int_signed => .{ .signed = true, .bits = self.cast(Payload.IntSigned).?.bits },1962 .int_signed => .{ .signedness = .signed, .bits = self.cast(Payload.IntSigned).?.bits },
1963 .u8 => .{ .signed = false, .bits = 8 },1963 .u8 => .{ .signedness = .unsigned, .bits = 8 },
1964 .i8 => .{ .signed = true, .bits = 8 },1964 .i8 => .{ .signedness = .signed, .bits = 8 },
1965 .u16 => .{ .signed = false, .bits = 16 },1965 .u16 => .{ .signedness = .unsigned, .bits = 16 },
1966 .i16 => .{ .signed = true, .bits = 16 },1966 .i16 => .{ .signedness = .signed, .bits = 16 },
1967 .u32 => .{ .signed = false, .bits = 32 },1967 .u32 => .{ .signedness = .unsigned, .bits = 32 },
1968 .i32 => .{ .signed = true, .bits = 32 },1968 .i32 => .{ .signedness = .signed, .bits = 32 },
1969 .u64 => .{ .signed = false, .bits = 64 },1969 .u64 => .{ .signedness = .unsigned, .bits = 64 },
1970 .i64 => .{ .signed = true, .bits = 64 },1970 .i64 => .{ .signedness = .signed, .bits = 64 },
1971 .usize => .{ .signed = false, .bits = target.cpu.arch.ptrBitWidth() },1971 .usize => .{ .signedness = .unsigned, .bits = target.cpu.arch.ptrBitWidth() },
1972 .isize => .{ .signed = true, .bits = target.cpu.arch.ptrBitWidth() },1972 .isize => .{ .signedness = .signed, .bits = target.cpu.arch.ptrBitWidth() },
1973 .c_short => .{ .signed = true, .bits = CType.short.sizeInBits(target) },1973 .c_short => .{ .signedness = .signed, .bits = CType.short.sizeInBits(target) },
1974 .c_ushort => .{ .signed = false, .bits = CType.ushort.sizeInBits(target) },1974 .c_ushort => .{ .signedness = .unsigned, .bits = CType.ushort.sizeInBits(target) },
1975 .c_int => .{ .signed = true, .bits = CType.int.sizeInBits(target) },1975 .c_int => .{ .signedness = .signed, .bits = CType.int.sizeInBits(target) },
1976 .c_uint => .{ .signed = false, .bits = CType.uint.sizeInBits(target) },1976 .c_uint => .{ .signedness = .unsigned, .bits = CType.uint.sizeInBits(target) },
1977 .c_long => .{ .signed = true, .bits = CType.long.sizeInBits(target) },1977 .c_long => .{ .signedness = .signed, .bits = CType.long.sizeInBits(target) },
1978 .c_ulong => .{ .signed = false, .bits = CType.ulong.sizeInBits(target) },1978 .c_ulong => .{ .signedness = .unsigned, .bits = CType.ulong.sizeInBits(target) },
1979 .c_longlong => .{ .signed = true, .bits = CType.longlong.sizeInBits(target) },1979 .c_longlong => .{ .signedness = .signed, .bits = CType.longlong.sizeInBits(target) },
1980 .c_ulonglong => .{ .signed = false, .bits = CType.ulonglong.sizeInBits(target) },1980 .c_ulonglong => .{ .signedness = .unsigned, .bits = CType.ulonglong.sizeInBits(target) },
1981 };1981 };
1982 }1982 }
19831983
...@@ -2869,7 +2869,7 @@ pub const Type = extern union {...@@ -2869,7 +2869,7 @@ pub const Type = extern union {
2869 assert(self.zigTypeTag() == .Int);2869 assert(self.zigTypeTag() == .Int);
2870 const info = self.intInfo(target);2870 const info = self.intInfo(target);
28712871
2872 if (!info.signed) {2872 if (info.signedness == .unsigned) {
2873 return Value.initTag(.zero);2873 return Value.initTag(.zero);
2874 }2874 }
28752875
...@@ -2902,13 +2902,13 @@ pub const Type = extern union {...@@ -2902,13 +2902,13 @@ pub const Type = extern union {
2902 assert(self.zigTypeTag() == .Int);2902 assert(self.zigTypeTag() == .Int);
2903 const info = self.intInfo(target);2903 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)) {
2906 const payload = try arena.allocator.create(Value.Payload.Int_i64);2906 const payload = try arena.allocator.create(Value.Payload.Int_i64);
2907 payload.* = .{2907 payload.* = .{
2908 .int = (@as(i64, 1) << @truncate(u6, info.bits - 1)) - 1,2908 .int = (@as(i64, 1) << @truncate(u6, info.bits - 1)) - 1,
2909 };2909 };
2910 return Value.initPayload(&payload.base);2910 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)) {
2912 const payload = try arena.allocator.create(Value.Payload.Int_u64);2912 const payload = try arena.allocator.create(Value.Payload.Int_u64);
2913 payload.* = .{2913 payload.* = .{
2914 .int = (@as(u64, 1) << @truncate(u6, info.bits)) - 1,2914 .int = (@as(u64, 1) << @truncate(u6, info.bits)) - 1,
...@@ -2917,7 +2917,7 @@ pub const Type = extern union {...@@ -2917,7 +2917,7 @@ pub const Type = extern union {
2917 }2917 }
29182918
2919 var res = try std.math.big.int.Managed.initSet(&arena.allocator, 1);2919 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));
2921 const one = std.math.big.int.Const{2921 const one = std.math.big.int.Const{
2922 .limbs = &[_]std.math.big.Limb{1},2922 .limbs = &[_]std.math.big.Limb{1},
2923 .positive = true,2923 .positive = true,
src/value.zig+8-9
...@@ -929,11 +929,10 @@ pub const Value = extern union {...@@ -929,11 +929,10 @@ pub const Value = extern union {
929 .bool_true,929 .bool_true,
930 => {930 => {
931 const info = ty.intInfo(target);931 const info = ty.intInfo(target);
932 if (info.signed) {932 return switch (info.signedness) {
933 return info.bits >= 2;933 .signed => info.bits >= 2,
934 } else {934 .unsigned => info.bits >= 1,
935 return info.bits >= 1;935 };
936 }
937 },936 },
938937
939 .int_u64 => switch (ty.zigTypeTag()) {938 .int_u64 => switch (ty.zigTypeTag()) {
...@@ -941,7 +940,7 @@ pub const Value = extern union {...@@ -941,7 +940,7 @@ pub const Value = extern union {
941 const x = self.cast(Payload.Int_u64).?.int;940 const x = self.cast(Payload.Int_u64).?.int;
942 if (x == 0) return true;941 if (x == 0) return true;
943 const info = ty.intInfo(target);942 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);
945 return info.bits >= needed_bits;944 return info.bits >= needed_bits;
946 },945 },
947 .ComptimeInt => return true,946 .ComptimeInt => return true,
...@@ -952,7 +951,7 @@ pub const Value = extern union {...@@ -952,7 +951,7 @@ pub const Value = extern union {
952 const x = self.cast(Payload.Int_i64).?.int;951 const x = self.cast(Payload.Int_i64).?.int;
953 if (x == 0) return true;952 if (x == 0) return true;
954 const info = ty.intInfo(target);953 const info = ty.intInfo(target);
955 if (!info.signed and x < 0)954 if (info.signedness == .unsigned and x < 0)
956 return false;955 return false;
957 @panic("TODO implement i64 intFitsInType");956 @panic("TODO implement i64 intFitsInType");
958 },957 },
...@@ -962,7 +961,7 @@ pub const Value = extern union {...@@ -962,7 +961,7 @@ pub const Value = extern union {
962 .int_big_positive => switch (ty.zigTypeTag()) {961 .int_big_positive => switch (ty.zigTypeTag()) {
963 .Int => {962 .Int => {
964 const info = ty.intInfo(target);963 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);
966 },965 },
967 .ComptimeInt => return true,966 .ComptimeInt => return true,
968 else => unreachable,967 else => unreachable,
...@@ -970,7 +969,7 @@ pub const Value = extern union {...@@ -970,7 +969,7 @@ pub const Value = extern union {
970 .int_big_negative => switch (ty.zigTypeTag()) {969 .int_big_negative => switch (ty.zigTypeTag()) {
971 .Int => {970 .Int => {
972 const info = ty.intInfo(target);971 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);
974 },973 },
975 .ComptimeInt => return true,974 .ComptimeInt => return true,
976 else => unreachable,975 else => unreachable,
src/zir.zig+4-1
...@@ -2687,7 +2687,10 @@ const EmitZIR = struct {...@@ -2687,7 +2687,10 @@ const EmitZIR = struct {
2687 },2687 },
2688 .Int => {2688 .Int => {
2689 const info = ty.intInfo(self.old_module.getTarget());2689 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 });
2691 const bits_payload = try self.arena.allocator.create(Value.Payload.Int_u64);2694 const bits_payload = try self.arena.allocator.create(Value.Payload.Int_u64);
2692 bits_payload.* = .{ .int = info.bits };2695 bits_payload.* = .{ .int = info.bits };
2693 const bits = try self.emitComptimeIntVal(src, Value.initPayload(&bits_payload.base));2696 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 {...@@ -72,6 +72,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
72 "tmp.zig:8:12: note: called from here",72 "tmp.zig:8:12: note: called from here",
73 });73 });
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
75 cases.add("indexing a undefined slice at comptime",87 cases.add("indexing a undefined slice at comptime",
76 \\comptime {88 \\comptime {
77 \\ var slice: []u8 = undefined;89 \\ var slice: []u8 = undefined;
...@@ -1827,17 +1839,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1827,17 +1839,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1827 "tmp.zig:4:15: error: unable to evaluate constant expression",1839 "tmp.zig:4:15: error: unable to evaluate constant expression",
1828 });1840 });
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 });
1841 cases.add("wrong type for argument tuple to @asyncCall",1842 cases.add("wrong type for argument tuple to @asyncCall",
1842 \\export fn entry1() void {1843 \\export fn entry1() void {
1843 \\ var frame: @Frame(foo) = undefined;1844 \\ var frame: @Frame(foo) = undefined;
test/stage1/behavior/type.zig+6-6
...@@ -31,12 +31,12 @@ test "Type.NoReturn" {...@@ -31,12 +31,12 @@ test "Type.NoReturn" {
31}31}
3232
33test "Type.Int" {33test "Type.Int" {
34 testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 1 } }));34 testing.expect(u1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 1 } }));
35 testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 1 } }));35 testing.expect(i1 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 1 } }));
36 testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 8 } }));36 testing.expect(u8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 8 } }));
37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } }));37 testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 8 } }));
38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } }));38 testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .unsigned, .bits = 64 } }));
39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } }));39 testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .signedness = .signed, .bits = 64 } }));
40 testTypes(&[_]type{ u8, u32, i64 });40 testTypes(&[_]type{ u8, u32, i64 });
41}41}
4242
test/stage1/behavior/type_info.zig+1-1
...@@ -28,7 +28,7 @@ test "type info: integer, floating point type info" {...@@ -28,7 +28,7 @@ test "type info: integer, floating point type info" {
28fn testIntFloat() void {28fn testIntFloat() void {
29 const u8_info = @typeInfo(u8);29 const u8_info = @typeInfo(u8);
30 expect(u8_info == .Int);30 expect(u8_info == .Int);
31 expect(!u8_info.Int.is_signed);31 expect(u8_info.Int.signedness == .unsigned);
32 expect(u8_info.Int.bits == 8);32 expect(u8_info.Int.bits == 8);
3333
34 const f64_info = @typeInfo(f64);34 const f64_info = @typeInfo(f64);