authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-03 18:09:55+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-09-03 18:10:40+03:00
log1df0f3ac24f090e8c58cd4cd6e752110cc5262b8
tree7cd201e5c347270f4865a2e738147b0f12c7661e
parent4eeeda0f52e6f7a6da53c11930cfd3cb714e4df6
signature Commit is signed but in an unrecognized format.

update uses of deprecated type field access


63 files changed, 362 insertions(+), 366 deletions(-)

lib/std/child_process.zig+1-3
......@@ -275,9 +275,7 @@ pub const ChildProcess = struct {
275275 }
276276
277277 fn handleWaitResult(self: *ChildProcess, status: u32) void {
278 // TODO https://github.com/ziglang/zig/issues/3190
279 var term = self.cleanupAfterWait(status);
280 self.term = term;
278 self.term = self.cleanupAfterWait(status);
281279 }
282280
283281 fn cleanupStreams(self: *ChildProcess) void {
lib/std/debug/leb128.zig+24-23
......@@ -9,10 +9,10 @@ const testing = std.testing;
99/// Read a single unsigned LEB128 value from the given reader as type T,
1010/// or error.Overflow if the value cannot fit.
1111pub fn readULEB128(comptime T: type, reader: anytype) !T {
12 const U = if (T.bit_count < 8) u8 else T;
12 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
1313 const ShiftT = std.math.Log2Int(U);
1414
15 const max_group = (U.bit_count + 6) / 7;
15 const max_group = (@typeInfo(U).Int.bits + 6) / 7;
1616
1717 var value = @as(U, 0);
1818 var group = @as(ShiftT, 0);
......@@ -40,7 +40,7 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
4040/// Write a single unsigned integer as unsigned LEB128 to the given writer.
4141pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
4242 const T = @TypeOf(uint_value);
43 const U = if (T.bit_count < 8) u8 else T;
43 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
4444 var value = @intCast(U, uint_value);
4545
4646 while (true) {
......@@ -68,7 +68,7 @@ pub fn readULEB128Mem(comptime T: type, ptr: *[]const u8) !T {
6868/// returning the number of bytes written.
6969pub fn writeULEB128Mem(ptr: []u8, uint_value: anytype) !usize {
7070 const T = @TypeOf(uint_value);
71 const max_group = (T.bit_count + 6) / 7;
71 const max_group = (@typeInfo(T).Int.bits + 6) / 7;
7272 var buf = std.io.fixedBufferStream(ptr);
7373 try writeULEB128(buf.writer(), uint_value);
7474 return buf.pos;
......@@ -77,11 +77,11 @@ pub fn writeULEB128Mem(ptr: []u8, uint_value: anytype) !usize {
7777/// Read a single signed LEB128 value from the given reader as type T,
7878/// or error.Overflow if the value cannot fit.
7979pub fn readILEB128(comptime T: type, reader: anytype) !T {
80 const S = if (T.bit_count < 8) i8 else T;
81 const U = std.meta.Int(false, S.bit_count);
80 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
81 const U = std.meta.Int(false, @typeInfo(S).Int.bits);
8282 const ShiftU = std.math.Log2Int(U);
8383
84 const max_group = (U.bit_count + 6) / 7;
84 const max_group = (@typeInfo(U).Int.bits + 6) / 7;
8585
8686 var value = @as(U, 0);
8787 var group = @as(ShiftU, 0);
......@@ -97,7 +97,7 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
9797 if (@bitCast(S, temp) >= 0) return error.Overflow;
9898
9999 // and all the overflowed bits are 1
100 const remaining_shift = @intCast(u3, U.bit_count - @as(u16, shift));
100 const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));
101101 const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;
102102 if (remaining_bits != -1) return error.Overflow;
103103 }
......@@ -127,8 +127,8 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
127127/// Write a single signed integer as signed LEB128 to the given writer.
128128pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
129129 const T = @TypeOf(int_value);
130 const S = if (T.bit_count < 8) i8 else T;
131 const U = std.meta.Int(false, S.bit_count);
130 const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
131 const U = std.meta.Int(false, @typeInfo(S).Int.bits);
132132
133133 var value = @intCast(S, int_value);
134134
......@@ -173,7 +173,7 @@ pub fn writeILEB128Mem(ptr: []u8, int_value: anytype) !usize {
173173/// different value without shifting all the following code.
174174pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(false, l * 7)) void {
175175 const T = @TypeOf(int);
176 const U = if (T.bit_count < 8) u8 else T;
176 const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
177177 var value = @intCast(U, int);
178178
179179 comptime var i = 0;
......@@ -346,28 +346,29 @@ test "deserialize unsigned LEB128" {
346346
347347fn test_write_leb128(value: anytype) !void {
348348 const T = @TypeOf(value);
349 const t_signed = @typeInfo(T).Int.is_signed;
349350
350 const writeStream = if (T.is_signed) writeILEB128 else writeULEB128;
351 const writeMem = if (T.is_signed) writeILEB128Mem else writeULEB128Mem;
352 const readStream = if (T.is_signed) readILEB128 else readULEB128;
353 const readMem = if (T.is_signed) readILEB128Mem else readULEB128Mem;
351 const writeStream = if (t_signed) writeILEB128 else writeULEB128;
352 const writeMem = if (t_signed) writeILEB128Mem else writeULEB128Mem;
353 const readStream = if (t_signed) readILEB128 else readULEB128;
354 const readMem = if (t_signed) readILEB128Mem else readULEB128Mem;
354355
355356 // decode to a larger bit size too, to ensure sign extension
356357 // is working as expected
357 const larger_type_bits = ((T.bit_count + 8) / 8) * 8;
358 const B = std.meta.Int(T.is_signed, larger_type_bits);
358 const larger_type_bits = ((@typeInfo(T).Int.bits + 8) / 8) * 8;
359 const B = std.meta.Int(t_signed, larger_type_bits);
359360
360361 const bytes_needed = bn: {
361 const S = std.meta.Int(T.is_signed, @sizeOf(T) * 8);
362 if (T.bit_count <= 7) break :bn @as(u16, 1);
362 const S = std.meta.Int(t_signed, @sizeOf(T) * 8);
363 if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1);
363364
364365 const unused_bits = if (value < 0) @clz(T, ~value) else @clz(T, value);
365 const used_bits: u16 = (T.bit_count - unused_bits) + @boolToInt(T.is_signed);
366 const used_bits: u16 = (@typeInfo(T).Int.bits - unused_bits) + @boolToInt(t_signed);
366367 if (used_bits <= 7) break :bn @as(u16, 1);
367368 break :bn ((used_bits + 6) / 7);
368369 };
369370
370 const max_groups = if (T.bit_count == 0) 1 else (T.bit_count + 6) / 7;
371 const max_groups = if (@typeInfo(T).Int.bits == 0) 1 else (@typeInfo(T).Int.bits + 6) / 7;
371372
372373 var buf: [max_groups]u8 = undefined;
373374 var fbs = std.io.fixedBufferStream(&buf);
......@@ -414,7 +415,7 @@ test "serialize unsigned LEB128" {
414415 const T = std.meta.Int(false, t);
415416 const min = std.math.minInt(T);
416417 const max = std.math.maxInt(T);
417 var i = @as(std.meta.Int(false, T.bit_count + 1), min);
418 var i = @as(std.meta.Int(false, @typeInfo(T).Int.bits + 1), min);
418419
419420 while (i <= max) : (i += 1) try test_write_leb128(@intCast(T, i));
420421 }
......@@ -432,7 +433,7 @@ test "serialize signed LEB128" {
432433 const T = std.meta.Int(true, t);
433434 const min = std.math.minInt(T);
434435 const max = std.math.maxInt(T);
435 var i = @as(std.meta.Int(true, T.bit_count + 1), min);
436 var i = @as(std.meta.Int(true, @typeInfo(T).Int.bits + 1), min);
436437
437438 while (i <= max) : (i += 1) try test_write_leb128(@intCast(T, i));
438439 }
lib/std/fmt.zig+11-10
......@@ -91,7 +91,7 @@ pub fn format(
9191 if (@typeInfo(@TypeOf(args)) != .Struct) {
9292 @compileError("Expected tuple or struct argument, found " ++ @typeName(@TypeOf(args)));
9393 }
94 if (args.len > ArgSetType.bit_count) {
94 if (args.len > @typeInfo(ArgSetType).Int.bits) {
9595 @compileError("32 arguments max are supported per format call");
9696 }
9797
......@@ -325,7 +325,7 @@ pub fn formatType(
325325 max_depth: usize,
326326) @TypeOf(writer).Error!void {
327327 if (comptime std.mem.eql(u8, fmt, "*")) {
328 try writer.writeAll(@typeName(@TypeOf(value).Child));
328 try writer.writeAll(@typeName(@typeInfo(@TypeOf(value)).Pointer.child));
329329 try writer.writeAll("@");
330330 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, writer);
331331 return;
......@@ -430,12 +430,12 @@ pub fn formatType(
430430 if (info.child == u8) {
431431 return formatText(value, fmt, options, writer);
432432 }
433 return format(writer, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
433 return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) });
434434 },
435435 .Enum, .Union, .Struct => {
436436 return formatType(value.*, fmt, options, writer, max_depth);
437437 },
438 else => return format(writer, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) }),
438 else => return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) }),
439439 },
440440 .Many, .C => {
441441 if (ptr_info.sentinel) |sentinel| {
......@@ -446,7 +446,7 @@ pub fn formatType(
446446 return formatText(mem.span(value), fmt, options, writer);
447447 }
448448 }
449 return format(writer, "{}@{x}", .{ @typeName(T.Child), @ptrToInt(value) });
449 return format(writer, "{}@{x}", .{ @typeName(@typeInfo(T).Pointer.child), @ptrToInt(value) });
450450 },
451451 .Slice => {
452452 if (fmt.len > 0 and ((fmt[0] == 'x') or (fmt[0] == 'X'))) {
......@@ -536,7 +536,7 @@ pub fn formatIntValue(
536536 radix = 10;
537537 uppercase = false;
538538 } else if (comptime std.mem.eql(u8, fmt, "c")) {
539 if (@TypeOf(int_value).bit_count <= 8) {
539 if (@typeInfo(@TypeOf(int_value)).Int.bits <= 8) {
540540 return formatAsciiChar(@as(u8, int_value), options, writer);
541541 } else {
542542 @compileError("Cannot print integer that is larger than 8 bits as a ascii");
......@@ -945,7 +945,7 @@ pub fn formatInt(
945945 } else
946946 value;
947947
948 if (@TypeOf(int_value).is_signed) {
948 if (@typeInfo(@TypeOf(int_value)).Int.is_signed) {
949949 return formatIntSigned(int_value, base, uppercase, options, writer);
950950 } else {
951951 return formatIntUnsigned(int_value, base, uppercase, options, writer);
......@@ -987,9 +987,10 @@ fn formatIntUnsigned(
987987 writer: anytype,
988988) !void {
989989 assert(base >= 2);
990 var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
991 const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count);
992 const MinInt = std.meta.Int(@TypeOf(value).is_signed, min_int_bits);
990 const value_info = @typeInfo(@TypeOf(value)).Int;
991 var buf: [math.max(value_info.bits, 1)]u8 = undefined;
992 const min_int_bits = comptime math.max(value_info.bits, @typeInfo(@TypeOf(base)).Int.bits);
993 const MinInt = std.meta.Int(value_info.is_signed, min_int_bits);
993994 var a: MinInt = value;
994995 var index: usize = buf.len;
995996
lib/std/fmt/parse_float.zig+1-1
......@@ -372,7 +372,7 @@ test "fmt.parseFloat" {
372372 const epsilon = 1e-7;
373373
374374 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
375 const Z = std.meta.Int(false, T.bit_count);
375 const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
376376
377377 testing.expectError(error.InvalidCharacter, parseFloat(T, ""));
378378 testing.expectError(error.InvalidCharacter, parseFloat(T, " 1"));
lib/std/hash/auto_hash.zig+1-1
......@@ -113,7 +113,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
113113 .Array => hashArray(hasher, key, strat),
114114
115115 .Vector => |info| {
116 if (info.child.bit_count % 8 == 0) {
116 if (std.meta.bitCount(info.child) % 8 == 0) {
117117 // If there's no unused bits in the child type, we can just hash
118118 // this as an array of bytes.
119119 hasher.update(mem.asBytes(&key));
lib/std/heap.zig+1-1
......@@ -952,7 +952,7 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) mem.Allocator
952952 // very near usize?
953953 if (mem.page_size << 2 > maxInt(usize)) return;
954954
955 const USizeShift = std.meta.Int(false, std.math.log2(usize.bit_count));
955 const USizeShift = std.meta.Int(false, std.math.log2(std.meta.bitCount(usize)));
956956 const large_align = @as(u29, mem.page_size << 2);
957957
958958 var align_mask: usize = undefined;
lib/std/io/reader.zig+5-5
......@@ -198,28 +198,28 @@ pub fn Reader(
198198
199199 /// Reads a native-endian integer
200200 pub fn readIntNative(self: Self, comptime T: type) !T {
201 const bytes = try self.readBytesNoEof((T.bit_count + 7) / 8);
201 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);
202202 return mem.readIntNative(T, &bytes);
203203 }
204204
205205 /// Reads a foreign-endian integer
206206 pub fn readIntForeign(self: Self, comptime T: type) !T {
207 const bytes = try self.readBytesNoEof((T.bit_count + 7) / 8);
207 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);
208208 return mem.readIntForeign(T, &bytes);
209209 }
210210
211211 pub fn readIntLittle(self: Self, comptime T: type) !T {
212 const bytes = try self.readBytesNoEof((T.bit_count + 7) / 8);
212 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);
213213 return mem.readIntLittle(T, &bytes);
214214 }
215215
216216 pub fn readIntBig(self: Self, comptime T: type) !T {
217 const bytes = try self.readBytesNoEof((T.bit_count + 7) / 8);
217 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);
218218 return mem.readIntBig(T, &bytes);
219219 }
220220
221221 pub fn readInt(self: Self, comptime T: type, endian: builtin.Endian) !T {
222 const bytes = try self.readBytesNoEof((T.bit_count + 7) / 8);
222 const bytes = try self.readBytesNoEof((@typeInfo(T).Int.bits + 7) / 8);
223223 return mem.readInt(T, &bytes, endian);
224224 }
225225
lib/std/io/serialization.zig+3-3
......@@ -60,7 +60,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
6060
6161 const U = std.meta.Int(false, t_bit_count);
6262 const Log2U = math.Log2Int(U);
63 const int_size = (U.bit_count + 7) / 8;
63 const int_size = (t_bit_count + 7) / 8;
6464
6565 if (packing == .Bit) {
6666 const result = try self.in_stream.readBitsNoEof(U, t_bit_count);
......@@ -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(T.is_signed, 8);
76 const PossiblySignedByte = std.meta.Int(@typeInfo(T).Int.is_signed, 8);
7777 return @truncate(T, @bitCast(PossiblySignedByte, buffer[0]));
7878 }
7979
......@@ -247,7 +247,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
247247
248248 const U = std.meta.Int(false, t_bit_count);
249249 const Log2U = math.Log2Int(U);
250 const int_size = (U.bit_count + 7) / 8;
250 const int_size = (t_bit_count + 7) / 8;
251251
252252 const u_value = @bitCast(U, value);
253253
lib/std/io/writer.zig+5-5
......@@ -53,7 +53,7 @@ pub fn Writer(
5353 /// Write a native-endian integer.
5454 /// TODO audit non-power-of-two int sizes
5555 pub fn writeIntNative(self: Self, comptime T: type, value: T) Error!void {
56 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
56 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
5757 mem.writeIntNative(T, &bytes, value);
5858 return self.writeAll(&bytes);
5959 }
......@@ -61,28 +61,28 @@ pub fn Writer(
6161 /// Write a foreign-endian integer.
6262 /// TODO audit non-power-of-two int sizes
6363 pub fn writeIntForeign(self: Self, comptime T: type, value: T) Error!void {
64 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
64 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
6565 mem.writeIntForeign(T, &bytes, value);
6666 return self.writeAll(&bytes);
6767 }
6868
6969 /// TODO audit non-power-of-two int sizes
7070 pub fn writeIntLittle(self: Self, comptime T: type, value: T) Error!void {
71 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
71 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
7272 mem.writeIntLittle(T, &bytes, value);
7373 return self.writeAll(&bytes);
7474 }
7575
7676 /// TODO audit non-power-of-two int sizes
7777 pub fn writeIntBig(self: Self, comptime T: type, value: T) Error!void {
78 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
78 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
7979 mem.writeIntBig(T, &bytes, value);
8080 return self.writeAll(&bytes);
8181 }
8282
8383 /// TODO audit non-power-of-two int sizes
8484 pub fn writeInt(self: Self, comptime T: type, value: T, endian: builtin.Endian) Error!void {
85 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
85 var bytes: [(@typeInfo(T).Int.bits + 7) / 8]u8 = undefined;
8686 mem.writeInt(T, &bytes, value, endian);
8787 return self.writeAll(&bytes);
8888 }
lib/std/math.zig+32-31
......@@ -195,7 +195,7 @@ test "" {
195195pub fn floatMantissaBits(comptime T: type) comptime_int {
196196 assert(@typeInfo(T) == .Float);
197197
198 return switch (T.bit_count) {
198 return switch (@typeInfo(T).Float.bits) {
199199 16 => 10,
200200 32 => 23,
201201 64 => 52,
......@@ -208,7 +208,7 @@ pub fn floatMantissaBits(comptime T: type) comptime_int {
208208pub fn floatExponentBits(comptime T: type) comptime_int {
209209 assert(@typeInfo(T) == .Float);
210210
211 return switch (T.bit_count) {
211 return switch (@typeInfo(T).Float.bits) {
212212 16 => 5,
213213 32 => 8,
214214 64 => 11,
......@@ -347,9 +347,9 @@ pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {
347347/// A negative shift amount results in a right shift.
348348pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
349349 const abs_shift_amt = absCast(shift_amt);
350 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
350 const casted_shift_amt = if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0 else @intCast(Log2Int(T), abs_shift_amt);
351351
352 if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
352 if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.is_signed) {
353353 if (shift_amt < 0) {
354354 return a >> casted_shift_amt;
355355 }
......@@ -373,9 +373,9 @@ test "math.shl" {
373373/// A negative shift amount results in a left shift.
374374pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
375375 const abs_shift_amt = absCast(shift_amt);
376 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
376 const casted_shift_amt = if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0 else @intCast(Log2Int(T), abs_shift_amt);
377377
378 if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
378 if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.is_signed) {
379379 if (shift_amt >= 0) {
380380 return a >> casted_shift_amt;
381381 } else {
......@@ -400,11 +400,11 @@ test "math.shr" {
400400/// Rotates right. Only unsigned values can be rotated.
401401/// Negative shift values results in shift modulo the bit count.
402402pub fn rotr(comptime T: type, x: T, r: anytype) T {
403 if (T.is_signed) {
403 if (@typeInfo(T).Int.is_signed) {
404404 @compileError("cannot rotate signed integer");
405405 } else {
406 const ar = @mod(r, T.bit_count);
407 return shr(T, x, ar) | shl(T, x, T.bit_count - ar);
406 const ar = @mod(r, @typeInfo(T).Int.bits);
407 return shr(T, x, ar) | shl(T, x, @typeInfo(T).Int.bits - ar);
408408 }
409409}
410410
......@@ -419,11 +419,11 @@ test "math.rotr" {
419419/// Rotates left. Only unsigned values can be rotated.
420420/// Negative shift values results in shift modulo the bit count.
421421pub fn rotl(comptime T: type, x: T, r: anytype) T {
422 if (T.is_signed) {
422 if (@typeInfo(T).Int.is_signed) {
423423 @compileError("cannot rotate signed integer");
424424 } else {
425 const ar = @mod(r, T.bit_count);
426 return shl(T, x, ar) | shr(T, x, T.bit_count - ar);
425 const ar = @mod(r, @typeInfo(T).Int.bits);
426 return shl(T, x, ar) | shr(T, x, @typeInfo(T).Int.bits - ar);
427427 }
428428}
429429
......@@ -438,7 +438,7 @@ test "math.rotl" {
438438pub fn Log2Int(comptime T: type) type {
439439 // comptime ceil log2
440440 comptime var count = 0;
441 comptime var s = T.bit_count - 1;
441 comptime var s = @typeInfo(T).Int.bits - 1;
442442 inline while (s != 0) : (s >>= 1) {
443443 count += 1;
444444 }
......@@ -524,7 +524,7 @@ fn testOverflow() void {
524524pub fn absInt(x: anytype) !@TypeOf(x) {
525525 const T = @TypeOf(x);
526526 comptime assert(@typeInfo(T) == .Int); // must pass an integer to absInt
527 comptime assert(T.is_signed); // must pass a signed integer to absInt
527 comptime assert(@typeInfo(T).Int.is_signed); // must pass a signed integer to absInt
528528
529529 if (x == minInt(@TypeOf(x))) {
530530 return error.Overflow;
......@@ -557,7 +557,7 @@ fn testAbsFloat() void {
557557pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
558558 @setRuntimeSafety(false);
559559 if (denominator == 0) return error.DivisionByZero;
560 if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
560 if (@typeInfo(T) == .Int and @typeInfo(T).Int.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
561561 return @divTrunc(numerator, denominator);
562562}
563563
......@@ -578,7 +578,7 @@ fn testDivTrunc() void {
578578pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
579579 @setRuntimeSafety(false);
580580 if (denominator == 0) return error.DivisionByZero;
581 if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
581 if (@typeInfo(T) == .Int and @typeInfo(T).Int.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
582582 return @divFloor(numerator, denominator);
583583}
584584
......@@ -652,7 +652,7 @@ fn testDivCeil() void {
652652pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
653653 @setRuntimeSafety(false);
654654 if (denominator == 0) return error.DivisionByZero;
655 if (@typeInfo(T) == .Int and T.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
655 if (@typeInfo(T) == .Int and @typeInfo(T).Int.is_signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
656656 const result = @divTrunc(numerator, denominator);
657657 if (result * denominator != numerator) return error.UnexpectedRemainder;
658658 return result;
......@@ -757,10 +757,10 @@ test "math.absCast" {
757757
758758/// Returns the negation of the integer parameter.
759759/// Result is a signed integer.
760pub fn negateCast(x: anytype) !std.meta.Int(true, @TypeOf(x).bit_count) {
761 if (@TypeOf(x).is_signed) return negate(x);
760pub fn negateCast(x: anytype) !std.meta.Int(true, std.meta.bitCount(@TypeOf(x))) {
761 if (@typeInfo(@TypeOf(x)).Int.is_signed) return negate(x);
762762
763 const int = std.meta.Int(true, @TypeOf(x).bit_count);
763 const int = std.meta.Int(true, std.meta.bitCount(@TypeOf(x)));
764764 if (x > -minInt(int)) return error.Overflow;
765765
766766 if (x == -minInt(int)) return minInt(int);
......@@ -823,7 +823,7 @@ pub fn floorPowerOfTwo(comptime T: type, value: T) T {
823823 var x = value;
824824
825825 comptime var i = 1;
826 inline while (T.bit_count > i) : (i *= 2) {
826 inline while (@typeInfo(T).Int.bits > i) : (i *= 2) {
827827 x |= (x >> i);
828828 }
829829
......@@ -847,13 +847,13 @@ fn testFloorPowerOfTwo() void {
847847/// Returns the next power of two (if the value is not already a power of two).
848848/// Only unsigned integers can be used. Zero is not an allowed input.
849849/// Result is a type with 1 more bit than the input type.
850pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(T.is_signed, T.bit_count + 1) {
850pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(T).Int.is_signed, @typeInfo(T).Int.bits + 1) {
851851 comptime assert(@typeInfo(T) == .Int);
852 comptime assert(!T.is_signed);
852 comptime assert(!@typeInfo(T).Int.is_signed);
853853 assert(value != 0);
854 comptime const PromotedType = std.meta.Int(T.is_signed, T.bit_count + 1);
854 comptime const PromotedType = std.meta.Int(@typeInfo(T).Int.is_signed, @typeInfo(T).Int.bits + 1);
855855 comptime const shiftType = std.math.Log2Int(PromotedType);
856 return @as(PromotedType, 1) << @intCast(shiftType, T.bit_count - @clz(T, value - 1));
856 return @as(PromotedType, 1) << @intCast(shiftType, @typeInfo(T).Int.bits - @clz(T, value - 1));
857857}
858858
859859/// Returns the next power of two (if the value is not already a power of two).
......@@ -861,9 +861,10 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(T.is_signe
861861/// If the value doesn't fit, returns an error.
862862pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
863863 comptime assert(@typeInfo(T) == .Int);
864 comptime assert(!T.is_signed);
865 comptime const PromotedType = std.meta.Int(T.is_signed, T.bit_count + 1);
866 comptime const overflowBit = @as(PromotedType, 1) << T.bit_count;
864 const info = @typeInfo(T).Int;
865 comptime assert(!info.is_signed);
866 comptime const PromotedType = std.meta.Int(info.is_signed, info.bits + 1);
867 comptime const overflowBit = @as(PromotedType, 1) << info.bits;
867868 var x = ceilPowerOfTwoPromote(T, value);
868869 if (overflowBit & x != 0) {
869870 return error.Overflow;
......@@ -911,7 +912,7 @@ fn testCeilPowerOfTwo() !void {
911912
912913pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
913914 assert(x != 0);
914 return @intCast(Log2Int(T), T.bit_count - 1 - @clz(T, x));
915 return @intCast(Log2Int(T), @typeInfo(T).Int.bits - 1 - @clz(T, x));
915916}
916917
917918pub fn log2_int_ceil(comptime T: type, x: T) Log2Int(T) {
......@@ -1008,8 +1009,8 @@ test "max value type" {
10081009 testing.expect(x == 2147483647);
10091010}
10101011
1011pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(T.is_signed, T.bit_count * 2) {
1012 const ResultInt = std.meta.Int(T.is_signed, T.bit_count * 2);
1012pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(@typeInfo(T).Int.is_signed, @typeInfo(T).Int.bits * 2) {
1013 const ResultInt = std.meta.Int(@typeInfo(T).Int.is_signed, @typeInfo(T).Int.bits * 2);
10131014 return @as(ResultInt, a) * @as(ResultInt, b);
10141015}
10151016
lib/std/math/big.zig+6-5
......@@ -9,14 +9,15 @@ const assert = std.debug.assert;
99pub const Rational = @import("big/rational.zig").Rational;
1010pub const int = @import("big/int.zig");
1111pub const Limb = usize;
12pub const DoubleLimb = std.meta.IntType(false, 2 * Limb.bit_count);
13pub const SignedDoubleLimb = std.meta.IntType(true, DoubleLimb.bit_count);
12const limb_info = @typeInfo(Limb).Int;
13pub const DoubleLimb = std.meta.IntType(false, 2 * limb_info.bits);
14pub const SignedDoubleLimb = std.meta.IntType(true, 2 * limb_info.bits);
1415pub const Log2Limb = std.math.Log2Int(Limb);
1516
1617comptime {
17 assert(std.math.floorPowerOfTwo(usize, Limb.bit_count) == Limb.bit_count);
18 assert(Limb.bit_count <= 64); // u128 set is unsupported
19 assert(Limb.is_signed == false);
18 assert(std.math.floorPowerOfTwo(usize, limb_info.bits) == limb_info.bits);
19 assert(limb_info.bits <= 64); // u128 set is unsupported
20 assert(limb_info.is_signed == false);
2021}
2122
2223test "" {
lib/std/math/big/int.zig+43-42
......@@ -6,6 +6,7 @@
66const std = @import("../../std.zig");
77const math = std.math;
88const Limb = std.math.big.Limb;
9const limb_bits = @typeInfo(Limb).Int.bits;
910const DoubleLimb = std.math.big.DoubleLimb;
1011const SignedDoubleLimb = std.math.big.SignedDoubleLimb;
1112const Log2Limb = std.math.big.Log2Limb;
......@@ -28,7 +29,7 @@ pub fn calcLimbLen(scalar: anytype) usize {
2829 },
2930 .ComptimeInt => {
3031 const w_value = if (scalar < 0) -scalar else scalar;
31 return @divFloor(math.log2(w_value), Limb.bit_count) + 1;
32 return @divFloor(math.log2(w_value), limb_bits) + 1;
3233 },
3334 else => @compileError("parameter must be a primitive integer type"),
3435 }
......@@ -54,7 +55,7 @@ pub fn calcSetStringLimbsBufferLen(base: u8, string_len: usize) usize {
5455}
5556
5657pub fn calcSetStringLimbCount(base: u8, string_len: usize) usize {
57 return (string_len + (Limb.bit_count / base - 1)) / (Limb.bit_count / base);
58 return (string_len + (limb_bits / base - 1)) / (limb_bits / base);
5859}
5960
6061/// a + b * c + *carry, sets carry to the overflow bits
......@@ -68,7 +69,7 @@ pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
6869 // r2 = b * c
6970 const bc = @as(DoubleLimb, math.mulWide(Limb, b, c));
7071 const r2 = @truncate(Limb, bc);
71 const c2 = @truncate(Limb, bc >> Limb.bit_count);
72 const c2 = @truncate(Limb, bc >> limb_bits);
7273
7374 // r1 = r1 + r2
7475 const c3: Limb = @boolToInt(@addWithOverflow(Limb, r1, r2, &r1));
......@@ -181,7 +182,7 @@ pub const Mutable = struct {
181182
182183 switch (@typeInfo(T)) {
183184 .Int => |info| {
184 const UT = if (T.is_signed) std.meta.Int(false, T.bit_count - 1) else T;
185 const UT = if (info.is_signed) std.meta.Int(false, info.bits - 1) else T;
185186
186187 const needed_limbs = @sizeOf(UT) / @sizeOf(Limb);
187188 assert(needed_limbs <= self.limbs.len); // value too big
......@@ -190,7 +191,7 @@ pub const Mutable = struct {
190191
191192 var w_value: UT = if (value < 0) @intCast(UT, -value) else @intCast(UT, value);
192193
193 if (info.bits <= Limb.bit_count) {
194 if (info.bits <= limb_bits) {
194195 self.limbs[0] = @as(Limb, w_value);
195196 self.len += 1;
196197 } else {
......@@ -200,15 +201,15 @@ pub const Mutable = struct {
200201 self.len += 1;
201202
202203 // TODO: shift == 64 at compile-time fails. Fails on u128 limbs.
203 w_value >>= Limb.bit_count / 2;
204 w_value >>= Limb.bit_count / 2;
204 w_value >>= limb_bits / 2;
205 w_value >>= limb_bits / 2;
205206 }
206207 }
207208 },
208209 .ComptimeInt => {
209210 comptime var w_value = if (value < 0) -value else value;
210211
211 const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1;
212 const req_limbs = @divFloor(math.log2(w_value), limb_bits) + 1;
212213 assert(req_limbs <= self.limbs.len); // value too big
213214
214215 self.len = req_limbs;
......@@ -217,14 +218,14 @@ pub const Mutable = struct {
217218 if (w_value <= maxInt(Limb)) {
218219 self.limbs[0] = w_value;
219220 } else {
220 const mask = (1 << Limb.bit_count) - 1;
221 const mask = (1 << limb_bits) - 1;
221222
222223 comptime var i = 0;
223224 inline while (w_value != 0) : (i += 1) {
224225 self.limbs[i] = w_value & mask;
225226
226 w_value >>= Limb.bit_count / 2;
227 w_value >>= Limb.bit_count / 2;
227 w_value >>= limb_bits / 2;
228 w_value >>= limb_bits / 2;
228229 }
229230 }
230231 },
......@@ -506,7 +507,7 @@ pub const Mutable = struct {
506507 /// `a.limbs.len + (shift / (@sizeOf(Limb) * 8))`.
507508 pub fn shiftLeft(r: *Mutable, a: Const, shift: usize) void {
508509 llshl(r.limbs[0..], a.limbs[0..a.limbs.len], shift);
509 r.normalize(a.limbs.len + (shift / Limb.bit_count) + 1);
510 r.normalize(a.limbs.len + (shift / limb_bits) + 1);
510511 r.positive = a.positive;
511512 }
512513
......@@ -516,7 +517,7 @@ pub const Mutable = struct {
516517 /// Asserts there is enough memory to fit the result. The upper bound Limb count is
517518 /// `a.limbs.len - (shift / (@sizeOf(Limb) * 8))`.
518519 pub fn shiftRight(r: *Mutable, a: Const, shift: usize) void {
519 if (a.limbs.len <= shift / Limb.bit_count) {
520 if (a.limbs.len <= shift / limb_bits) {
520521 r.len = 1;
521522 r.positive = true;
522523 r.limbs[0] = 0;
......@@ -524,7 +525,7 @@ pub const Mutable = struct {
524525 }
525526
526527 const r_len = llshr(r.limbs[0..], a.limbs[0..a.limbs.len], shift);
527 r.len = a.limbs.len - (shift / Limb.bit_count);
528 r.len = a.limbs.len - (shift / limb_bits);
528529 r.positive = a.positive;
529530 }
530531
......@@ -772,7 +773,7 @@ pub const Mutable = struct {
772773 }
773774
774775 if (ab_zero_limb_count != 0) {
775 rem.shiftLeft(rem.toConst(), ab_zero_limb_count * Limb.bit_count);
776 rem.shiftLeft(rem.toConst(), ab_zero_limb_count * limb_bits);
776777 }
777778 }
778779
......@@ -803,10 +804,10 @@ pub const Mutable = struct {
803804 };
804805 tmp.limbs[0] = 0;
805806
806 // Normalize so y > Limb.bit_count / 2 (i.e. leading bit is set) and even
807 // Normalize so y > limb_bits / 2 (i.e. leading bit is set) and even
807808 var norm_shift = @clz(Limb, y.limbs[y.len - 1]);
808809 if (norm_shift == 0 and y.toConst().isOdd()) {
809 norm_shift = Limb.bit_count;
810 norm_shift = limb_bits;
810811 }
811812 x.shiftLeft(x.toConst(), norm_shift);
812813 y.shiftLeft(y.toConst(), norm_shift);
......@@ -820,7 +821,7 @@ pub const Mutable = struct {
820821 mem.set(Limb, q.limbs[0..q.len], 0);
821822
822823 // 2.
823 tmp.shiftLeft(y.toConst(), Limb.bit_count * (n - t));
824 tmp.shiftLeft(y.toConst(), limb_bits * (n - t));
824825 while (x.toConst().order(tmp.toConst()) != .lt) {
825826 q.limbs[n - t] += 1;
826827 x.sub(x.toConst(), tmp.toConst());
......@@ -833,7 +834,7 @@ pub const Mutable = struct {
833834 if (x.limbs[i] == y.limbs[t]) {
834835 q.limbs[i - t - 1] = maxInt(Limb);
835836 } else {
836 const num = (@as(DoubleLimb, x.limbs[i]) << Limb.bit_count) | @as(DoubleLimb, x.limbs[i - 1]);
837 const num = (@as(DoubleLimb, x.limbs[i]) << limb_bits) | @as(DoubleLimb, x.limbs[i - 1]);
837838 const z = @intCast(Limb, num / @as(DoubleLimb, y.limbs[t]));
838839 q.limbs[i - t - 1] = if (z > maxInt(Limb)) maxInt(Limb) else @as(Limb, z);
839840 }
......@@ -862,11 +863,11 @@ pub const Mutable = struct {
862863 // 3.3
863864 tmp.set(q.limbs[i - t - 1]);
864865 tmp.mul(tmp.toConst(), y.toConst(), mul_limb_buf, allocator);
865 tmp.shiftLeft(tmp.toConst(), Limb.bit_count * (i - t - 1));
866 tmp.shiftLeft(tmp.toConst(), limb_bits * (i - t - 1));
866867 x.sub(x.toConst(), tmp.toConst());
867868
868869 if (!x.positive) {
869 tmp.shiftLeft(y.toConst(), Limb.bit_count * (i - t - 1));
870 tmp.shiftLeft(y.toConst(), limb_bits * (i - t - 1));
870871 x.add(x.toConst(), tmp.toConst());
871872 q.limbs[i - t - 1] -= 1;
872873 }
......@@ -949,7 +950,7 @@ pub const Const = struct {
949950
950951 /// Returns the number of bits required to represent the absolute value of an integer.
951952 pub fn bitCountAbs(self: Const) usize {
952 return (self.limbs.len - 1) * Limb.bit_count + (Limb.bit_count - @clz(Limb, self.limbs[self.limbs.len - 1]));
953 return (self.limbs.len - 1) * limb_bits + (limb_bits - @clz(Limb, self.limbs[self.limbs.len - 1]));
953954 }
954955
955956 /// Returns the number of bits required to represent the integer in twos-complement form.
......@@ -1019,10 +1020,10 @@ pub const Const = struct {
10191020 /// Returns an error if self cannot be narrowed into the requested type without truncation.
10201021 pub fn to(self: Const, comptime T: type) ConvertError!T {
10211022 switch (@typeInfo(T)) {
1022 .Int => {
1023 const UT = std.meta.Int(false, T.bit_count);
1023 .Int => |info| {
1024 const UT = std.meta.Int(false, info.bits);
10241025
1025 if (self.bitCountTwosComp() > T.bit_count) {
1026 if (self.bitCountTwosComp() > info.bits) {
10261027 return error.TargetTooSmall;
10271028 }
10281029
......@@ -1033,12 +1034,12 @@ pub const Const = struct {
10331034 } else {
10341035 for (self.limbs[0..self.limbs.len]) |_, ri| {
10351036 const limb = self.limbs[self.limbs.len - ri - 1];
1036 r <<= Limb.bit_count;
1037 r <<= limb_bits;
10371038 r |= limb;
10381039 }
10391040 }
10401041
1041 if (!T.is_signed) {
1042 if (!info.is_signed) {
10421043 return if (self.positive) @intCast(T, r) else error.NegativeIntoUnsigned;
10431044 } else {
10441045 if (self.positive) {
......@@ -1149,7 +1150,7 @@ pub const Const = struct {
11491150
11501151 outer: for (self.limbs[0..self.limbs.len]) |limb| {
11511152 var shift: usize = 0;
1152 while (shift < Limb.bit_count) : (shift += base_shift) {
1153 while (shift < limb_bits) : (shift += base_shift) {
11531154 const r = @intCast(u8, (limb >> @intCast(Log2Limb, shift)) & @as(Limb, base - 1));
11541155 const ch = std.fmt.digitToChar(r, uppercase);
11551156 string[digits_len] = ch;
......@@ -1295,7 +1296,7 @@ pub const Const = struct {
12951296/// Memory is allocated as needed to ensure operations never overflow. The range
12961297/// is bounded only by available memory.
12971298pub const Managed = struct {
1298 pub const sign_bit: usize = 1 << (usize.bit_count - 1);
1299 pub const sign_bit: usize = 1 << (@typeInfo(usize).Int.bits - 1);
12991300
13001301 /// Default number of limbs to allocate on creation of a `Managed`.
13011302 pub const default_capacity = 4;
......@@ -1716,7 +1717,7 @@ pub const Managed = struct {
17161717
17171718 /// r = a << shift, in other words, r = a * 2^shift
17181719 pub fn shiftLeft(r: *Managed, a: Managed, shift: usize) !void {
1719 try r.ensureCapacity(a.len() + (shift / Limb.bit_count) + 1);
1720 try r.ensureCapacity(a.len() + (shift / limb_bits) + 1);
17201721 var m = r.toMutable();
17211722 m.shiftLeft(a.toConst(), shift);
17221723 r.setMetadata(m.positive, m.len);
......@@ -1724,13 +1725,13 @@ pub const Managed = struct {
17241725
17251726 /// r = a >> shift
17261727 pub fn shiftRight(r: *Managed, a: Managed, shift: usize) !void {
1727 if (a.len() <= shift / Limb.bit_count) {
1728 if (a.len() <= shift / limb_bits) {
17281729 r.metadata = 1;
17291730 r.limbs[0] = 0;
17301731 return;
17311732 }
17321733
1733 try r.ensureCapacity(a.len() - (shift / Limb.bit_count));
1734 try r.ensureCapacity(a.len() - (shift / limb_bits));
17341735 var m = r.toMutable();
17351736 m.shiftRight(a.toConst(), shift);
17361737 r.setMetadata(m.positive, m.len);
......@@ -2021,7 +2022,7 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
20212022 rem.* = 0;
20222023 for (a) |_, ri| {
20232024 const i = a.len - ri - 1;
2024 const pdiv = ((@as(DoubleLimb, rem.*) << Limb.bit_count) | a[i]);
2025 const pdiv = ((@as(DoubleLimb, rem.*) << limb_bits) | a[i]);
20252026
20262027 if (pdiv == 0) {
20272028 quo[i] = 0;
......@@ -2042,10 +2043,10 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
20422043fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
20432044 @setRuntimeSafety(debug_safety);
20442045 assert(a.len >= 1);
2045 assert(r.len >= a.len + (shift / Limb.bit_count) + 1);
2046 assert(r.len >= a.len + (shift / limb_bits) + 1);
20462047
2047 const limb_shift = shift / Limb.bit_count + 1;
2048 const interior_limb_shift = @intCast(Log2Limb, shift % Limb.bit_count);
2048 const limb_shift = shift / limb_bits + 1;
2049 const interior_limb_shift = @intCast(Log2Limb, shift % limb_bits);
20492050
20502051 var carry: Limb = 0;
20512052 var i: usize = 0;
......@@ -2057,7 +2058,7 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
20572058 r[dst_i] = carry | @call(.{ .modifier = .always_inline }, math.shr, .{
20582059 Limb,
20592060 src_digit,
2060 Limb.bit_count - @intCast(Limb, interior_limb_shift),
2061 limb_bits - @intCast(Limb, interior_limb_shift),
20612062 });
20622063 carry = (src_digit << interior_limb_shift);
20632064 }
......@@ -2069,10 +2070,10 @@ fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
20692070fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
20702071 @setRuntimeSafety(debug_safety);
20712072 assert(a.len >= 1);
2072 assert(r.len >= a.len - (shift / Limb.bit_count));
2073 assert(r.len >= a.len - (shift / limb_bits));
20732074
2074 const limb_shift = shift / Limb.bit_count;
2075 const interior_limb_shift = @intCast(Log2Limb, shift % Limb.bit_count);
2075 const limb_shift = shift / limb_bits;
2076 const interior_limb_shift = @intCast(Log2Limb, shift % limb_bits);
20762077
20772078 var carry: Limb = 0;
20782079 var i: usize = 0;
......@@ -2085,7 +2086,7 @@ fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
20852086 carry = @call(.{ .modifier = .always_inline }, math.shl, .{
20862087 Limb,
20872088 src_digit,
2088 Limb.bit_count - @intCast(Limb, interior_limb_shift),
2089 limb_bits - @intCast(Limb, interior_limb_shift),
20892090 });
20902091 }
20912092}
......@@ -2135,7 +2136,7 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {
21352136 const A_is_positive = A >= 0;
21362137 const Au = @intCast(DoubleLimb, if (A < 0) -A else A);
21372138 storage[0] = @truncate(Limb, Au);
2138 storage[1] = @truncate(Limb, Au >> Limb.bit_count);
2139 storage[1] = @truncate(Limb, Au >> limb_bits);
21392140 return .{
21402141 .limbs = storage[0..2],
21412142 .positive = A_is_positive,
lib/std/math/big/int_test.zig+3-3
......@@ -23,13 +23,13 @@ test "big.int comptime_int set" {
2323 var a = try Managed.initSet(testing.allocator, s);
2424 defer a.deinit();
2525
26 const s_limb_count = 128 / Limb.bit_count;
26 const s_limb_count = 128 / @typeInfo(Limb).Int.bits;
2727
2828 comptime var i: usize = 0;
2929 inline while (i < s_limb_count) : (i += 1) {
3030 const result = @as(Limb, s & maxInt(Limb));
31 s >>= Limb.bit_count / 2;
32 s >>= Limb.bit_count / 2;
31 s >>= @typeInfo(Limb).Int.bits / 2;
32 s >>= @typeInfo(Limb).Int.bits / 2;
3333 testing.expect(a.limbs[i] == result);
3434 }
3535}
lib/std/math/big/rational.zig+9-7
......@@ -136,7 +136,7 @@ pub const Rational = struct {
136136 // Translated from golang.go/src/math/big/rat.go.
137137 debug.assert(@typeInfo(T) == .Float);
138138
139 const UnsignedInt = std.meta.Int(false, T.bit_count);
139 const UnsignedInt = std.meta.Int(false, @typeInfo(T).Float.bits);
140140 const f_bits = @bitCast(UnsignedInt, f);
141141
142142 const exponent_bits = math.floatExponentBits(T);
......@@ -194,8 +194,8 @@ pub const Rational = struct {
194194 // TODO: Indicate whether the result is not exact.
195195 debug.assert(@typeInfo(T) == .Float);
196196
197 const fsize = T.bit_count;
198 const BitReprType = std.meta.Int(false, T.bit_count);
197 const fsize = @typeInfo(T).Float.bits;
198 const BitReprType = std.meta.Int(false, fsize);
199199
200200 const msize = math.floatMantissaBits(T);
201201 const msize1 = msize + 1;
......@@ -475,16 +475,18 @@ pub const Rational = struct {
475475fn extractLowBits(a: Int, comptime T: type) T {
476476 testing.expect(@typeInfo(T) == .Int);
477477
478 if (T.bit_count <= Limb.bit_count) {
478 const t_bits = @typeInfo(T).Int.bits;
479 const limb_bits = @typeInfo(Limb).Int.bits;
480 if (t_bits <= limb_bits) {
479481 return @truncate(T, a.limbs[0]);
480482 } else {
481483 var r: T = 0;
482484 comptime var i: usize = 0;
483485
484 // Remainder is always 0 since if T.bit_count >= Limb.bit_count -> Limb | T and both
486 // Remainder is always 0 since if t_bits >= limb_bits -> Limb | T and both
485487 // are powers of two.
486 inline while (i < T.bit_count / Limb.bit_count) : (i += 1) {
487 r |= math.shl(T, a.limbs[i], i * Limb.bit_count);
488 inline while (i < t_bits / limb_bits) : (i += 1) {
489 r |= math.shl(T, a.limbs[i], i * limb_bits);
488490 }
489491
490492 return r;
lib/std/math/cos.zig+1-1
......@@ -49,7 +49,7 @@ const pi4c = 2.69515142907905952645E-15;
4949const m4pi = 1.273239544735162542821171882678754627704620361328125;
5050
5151fn cos_(comptime T: type, x_: T) T {
52 const I = std.meta.Int(true, T.bit_count);
52 const I = std.meta.Int(true, @typeInfo(T).Float.bits);
5353
5454 var x = x_;
5555 if (math.isNan(x) or math.isInf(x)) {
lib/std/math/pow.zig+2-2
......@@ -128,7 +128,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
128128 if (yf != 0 and x < 0) {
129129 return math.nan(T);
130130 }
131 if (yi >= 1 << (T.bit_count - 1)) {
131 if (yi >= 1 << (@typeInfo(T).Float.bits - 1)) {
132132 return math.exp(y * math.ln(x));
133133 }
134134
......@@ -150,7 +150,7 @@ pub fn pow(comptime T: type, x: T, y: T) T {
150150 var xe = r2.exponent;
151151 var x1 = r2.significand;
152152
153 var i = @floatToInt(std.meta.Int(true, T.bit_count), yi);
153 var i = @floatToInt(std.meta.Int(true, @typeInfo(T).Float.bits), yi);
154154 while (i != 0) : (i >>= 1) {
155155 const overflow_shift = math.floatExponentBits(T) + 1;
156156 if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) {
lib/std/math/sin.zig+1-1
......@@ -50,7 +50,7 @@ const pi4c = 2.69515142907905952645E-15;
5050const m4pi = 1.273239544735162542821171882678754627704620361328125;
5151
5252fn sin_(comptime T: type, x_: T) T {
53 const I = std.meta.Int(true, T.bit_count);
53 const I = std.meta.Int(true, @typeInfo(T).Float.bits);
5454
5555 var x = x_;
5656 if (x == 0 or math.isNan(x)) {
lib/std/math/sqrt.zig+3-3
......@@ -36,10 +36,10 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) {
3636 }
3737}
3838
39fn sqrt_int(comptime T: type, value: T) std.meta.Int(false, T.bit_count / 2) {
39fn sqrt_int(comptime T: type, value: T) std.meta.Int(false, @typeInfo(T).Int.bits / 2) {
4040 var op = value;
4141 var res: T = 0;
42 var one: T = 1 << (T.bit_count - 2);
42 var one: T = 1 << (@typeInfo(T).Int.bits - 2);
4343
4444 // "one" starts at the highest power of four <= than the argument.
4545 while (one > op) {
......@@ -55,7 +55,7 @@ fn sqrt_int(comptime T: type, value: T) std.meta.Int(false, T.bit_count / 2) {
5555 one >>= 2;
5656 }
5757
58 const ResultType = std.meta.Int(false, T.bit_count / 2);
58 const ResultType = std.meta.Int(false, @typeInfo(T).Int.bits / 2);
5959 return @intCast(ResultType, res);
6060}
6161
lib/std/math/tan.zig+1-1
......@@ -43,7 +43,7 @@ const pi4c = 2.69515142907905952645E-15;
4343const m4pi = 1.273239544735162542821171882678754627704620361328125;
4444
4545fn tan_(comptime T: type, x_: T) T {
46 const I = std.meta.Int(true, T.bit_count);
46 const I = std.meta.Int(true, @typeInfo(T).Float.bits);
4747
4848 var x = x_;
4949 if (x == 0 or math.isNan(x)) {
lib/std/mem.zig+21-21
......@@ -949,7 +949,7 @@ pub fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: builtin.
949949/// This function cannot fail and cannot cause undefined behavior.
950950/// Assumes the endianness of memory is native. This means the function can
951951/// simply pointer cast memory.
952pub fn readIntNative(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)]u8) T {
952pub fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {
953953 return @ptrCast(*align(1) const T, bytes).*;
954954}
955955
......@@ -957,7 +957,7 @@ pub fn readIntNative(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)]
957957/// The bit count of T must be evenly divisible by 8.
958958/// This function cannot fail and cannot cause undefined behavior.
959959/// Assumes the endianness of memory is foreign, so it must byte-swap.
960pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)]u8) T {
960pub fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T {
961961 return @byteSwap(T, readIntNative(T, bytes));
962962}
963963
......@@ -971,18 +971,18 @@ pub const readIntBig = switch (builtin.endian) {
971971 .Big => readIntNative,
972972};
973973
974/// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0
974/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
975975/// and ignores extra bytes.
976976/// The bit count of T must be evenly divisible by 8.
977977/// Assumes the endianness of memory is native. This means the function can
978978/// simply pointer cast memory.
979979pub fn readIntSliceNative(comptime T: type, bytes: []const u8) T {
980 const n = @divExact(T.bit_count, 8);
980 const n = @divExact(@typeInfo(T).Int.bits, 8);
981981 assert(bytes.len >= n);
982982 return readIntNative(T, bytes[0..n]);
983983}
984984
985/// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0
985/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
986986/// and ignores extra bytes.
987987/// The bit count of T must be evenly divisible by 8.
988988/// Assumes the endianness of memory is foreign, so it must byte-swap.
......@@ -1003,7 +1003,7 @@ pub const readIntSliceBig = switch (builtin.endian) {
10031003/// Reads an integer from memory with bit count specified by T.
10041004/// The bit count of T must be evenly divisible by 8.
10051005/// This function cannot fail and cannot cause undefined behavior.
1006pub fn readInt(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)]u8, endian: builtin.Endian) T {
1006pub fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: builtin.Endian) T {
10071007 if (endian == builtin.endian) {
10081008 return readIntNative(T, bytes);
10091009 } else {
......@@ -1011,11 +1011,11 @@ pub fn readInt(comptime T: type, bytes: *const [@divExact(T.bit_count, 8)]u8, en
10111011 }
10121012}
10131013
1014/// Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0
1014/// Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0
10151015/// and ignores extra bytes.
10161016/// The bit count of T must be evenly divisible by 8.
10171017pub fn readIntSlice(comptime T: type, bytes: []const u8, endian: builtin.Endian) T {
1018 const n = @divExact(T.bit_count, 8);
1018 const n = @divExact(@typeInfo(T).Int.bits, 8);
10191019 assert(bytes.len >= n);
10201020 return readInt(T, bytes[0..n], endian);
10211021}
......@@ -1060,7 +1060,7 @@ test "readIntBig and readIntLittle" {
10601060/// accepts any integer bit width.
10611061/// This function stores in native endian, which means it is implemented as a simple
10621062/// memory store.
1063pub fn writeIntNative(comptime T: type, buf: *[(T.bit_count + 7) / 8]u8, value: T) void {
1063pub fn writeIntNative(comptime T: type, buf: *[(@typeInfo(T).Int.bits + 7) / 8]u8, value: T) void {
10641064 @ptrCast(*align(1) T, buf).* = value;
10651065}
10661066
......@@ -1068,7 +1068,7 @@ pub fn writeIntNative(comptime T: type, buf: *[(T.bit_count + 7) / 8]u8, value:
10681068/// This function always succeeds, has defined behavior for all inputs, but
10691069/// the integer bit width must be divisible by 8.
10701070/// This function stores in foreign endian, which means it does a @byteSwap first.
1071pub fn writeIntForeign(comptime T: type, buf: *[@divExact(T.bit_count, 8)]u8, value: T) void {
1071pub fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T) void {
10721072 writeIntNative(T, buf, @byteSwap(T, value));
10731073}
10741074
......@@ -1085,7 +1085,7 @@ pub const writeIntBig = switch (builtin.endian) {
10851085/// Writes an integer to memory, storing it in twos-complement.
10861086/// This function always succeeds, has defined behavior for all inputs, but
10871087/// the integer bit width must be divisible by 8.
1088pub fn writeInt(comptime T: type, buffer: *[@divExact(T.bit_count, 8)]u8, value: T, endian: builtin.Endian) void {
1088pub fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: builtin.Endian) void {
10891089 if (endian == builtin.endian) {
10901090 return writeIntNative(T, buffer, value);
10911091 } else {
......@@ -1094,19 +1094,19 @@ pub fn writeInt(comptime T: type, buffer: *[@divExact(T.bit_count, 8)]u8, value:
10941094}
10951095
10961096/// Writes a twos-complement little-endian integer to memory.
1097/// Asserts that buf.len >= T.bit_count / 8.
1097/// Asserts that buf.len >= @typeInfo(T).Int.bits / 8.
10981098/// The bit count of T must be divisible by 8.
10991099/// Any extra bytes in buffer after writing the integer are set to zero. To
11001100/// avoid the branch to check for extra buffer bytes, use writeIntLittle
11011101/// instead.
11021102pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
1103 assert(buffer.len >= @divExact(T.bit_count, 8));
1103 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
11041104
1105 if (T.bit_count == 0)
1105 if (@typeInfo(T).Int.bits == 0)
11061106 return set(u8, buffer, 0);
11071107
11081108 // TODO I want to call writeIntLittle here but comptime eval facilities aren't good enough
1109 const uint = std.meta.Int(false, T.bit_count);
1109 const uint = std.meta.Int(false, @typeInfo(T).Int.bits);
11101110 var bits = @truncate(uint, value);
11111111 for (buffer) |*b| {
11121112 b.* = @truncate(u8, bits);
......@@ -1115,18 +1115,18 @@ pub fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void {
11151115}
11161116
11171117/// Writes a twos-complement big-endian integer to memory.
1118/// Asserts that buffer.len >= T.bit_count / 8.
1118/// Asserts that buffer.len >= @typeInfo(T).Int.bits / 8.
11191119/// The bit count of T must be divisible by 8.
11201120/// Any extra bytes in buffer before writing the integer are set to zero. To
11211121/// avoid the branch to check for extra buffer bytes, use writeIntBig instead.
11221122pub fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void {
1123 assert(buffer.len >= @divExact(T.bit_count, 8));
1123 assert(buffer.len >= @divExact(@typeInfo(T).Int.bits, 8));
11241124
1125 if (T.bit_count == 0)
1125 if (@typeInfo(T).Int.bits == 0)
11261126 return set(u8, buffer, 0);
11271127
11281128 // TODO I want to call writeIntBig here but comptime eval facilities aren't good enough
1129 const uint = std.meta.Int(false, T.bit_count);
1129 const uint = std.meta.Int(false, @typeInfo(T).Int.bits);
11301130 var bits = @truncate(uint, value);
11311131 var index: usize = buffer.len;
11321132 while (index != 0) {
......@@ -1147,13 +1147,13 @@ pub const writeIntSliceForeign = switch (builtin.endian) {
11471147};
11481148
11491149/// Writes a twos-complement integer to memory, with the specified endianness.
1150/// Asserts that buf.len >= T.bit_count / 8.
1150/// Asserts that buf.len >= @typeInfo(T).Int.bits / 8.
11511151/// The bit count of T must be evenly divisible by 8.
11521152/// Any extra bytes in buffer not part of the integer are set to zero, with
11531153/// respect to endianness. To avoid the branch to check for extra buffer bytes,
11541154/// use writeInt instead.
11551155pub fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: builtin.Endian) void {
1156 comptime assert(T.bit_count % 8 == 0);
1156 comptime assert(@typeInfo(T).Int.bits % 8 == 0);
11571157 return switch (endian) {
11581158 .Little => writeIntSliceLittle(T, buffer, value),
11591159 .Big => writeIntSliceBig(T, buffer, value),
lib/std/mem/Allocator.zig+3-3
......@@ -167,11 +167,11 @@ pub fn create(self: *Allocator, comptime T: type) Error!*T {
167167/// `ptr` should be the return value of `create`, or otherwise
168168/// have the same address and alignment property.
169169pub fn destroy(self: *Allocator, ptr: anytype) void {
170 const T = @TypeOf(ptr).Child;
170 const info = @typeInfo(@TypeOf(ptr)).Pointer;
171 const T = info.child;
171172 if (@sizeOf(T) == 0) return;
172173 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
173 const ptr_align = @typeInfo(@TypeOf(ptr)).Pointer.alignment;
174 _ = self.shrinkBytes(non_const_ptr[0..@sizeOf(T)], ptr_align, 0, 0, @returnAddress());
174 _ = self.shrinkBytes(non_const_ptr[0..@sizeOf(T)], info.alignment, 0, 0, @returnAddress());
175175}
176176
177177/// Allocates an array of `n` items of type `T` and sets all the
lib/std/os.zig+1-1
......@@ -4504,7 +4504,7 @@ pub fn res_mkquery(
45044504 // Make a reasonably unpredictable id
45054505 var ts: timespec = undefined;
45064506 clock_gettime(CLOCK_REALTIME, &ts) catch {};
4507 const UInt = std.meta.Int(false, @TypeOf(ts.tv_nsec).bit_count);
4507 const UInt = std.meta.Int(false, std.meta.bitCount(@TypeOf(ts.tv_nsec)));
45084508 const unsec = @bitCast(UInt, ts.tv_nsec);
45094509 const id = @truncate(u32, unsec + unsec / 65536);
45104510 q[0] = @truncate(u8, id / 256);
lib/std/os/bits/linux.zig+1-1
......@@ -846,7 +846,7 @@ pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
846846pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
847847pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
848848
849pub const empty_sigset = [_]u32{0} ** sigset_t.len;
849pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;
850850
851851pub const signalfd_siginfo = extern struct {
852852 signo: u32,
lib/std/os/linux.zig+5-3
......@@ -815,17 +815,19 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
815815 return 0;
816816}
817817
818const usize_bits = @typeInfo(usize).Int.bits;
819
818820pub fn sigaddset(set: *sigset_t, sig: u6) void {
819821 const s = sig - 1;
820822 // shift in musl: s&8*sizeof *set->__bits-1
821 const shift = @intCast(u5, s & (usize.bit_count - 1));
823 const shift = @intCast(u5, s & (usize_bits - 1));
822824 const val = @intCast(u32, 1) << shift;
823 (set.*)[@intCast(usize, s) / usize.bit_count] |= val;
825 (set.*)[@intCast(usize, s) / usize_bits] |= val;
824826}
825827
826828pub fn sigismember(set: *const sigset_t, sig: u6) bool {
827829 const s = sig - 1;
828 return ((set.*)[@intCast(usize, s) / usize.bit_count] & (@intCast(usize, 1) << (s & (usize.bit_count - 1)))) != 0;
830 return ((set.*)[@intCast(usize, s) / usize_bits] & (@intCast(usize, 1) << (s & (usize_bits - 1)))) != 0;
829831}
830832
831833pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
lib/std/os/windows/ws2_32.zig+1-1
......@@ -12,7 +12,7 @@ pub const SOCKET_ERROR = -1;
1212pub const WSADESCRIPTION_LEN = 256;
1313pub const WSASYS_STATUS_LEN = 128;
1414
15pub const WSADATA = if (usize.bit_count == u64.bit_count)
15pub const WSADATA = if (@sizeOf(usize) == @sizeOf(u64))
1616 extern struct {
1717 wVersion: WORD,
1818 wHighVersion: WORD,
lib/std/rand.zig+33-24
......@@ -51,8 +51,9 @@ pub const Random = struct {
5151 /// Returns a random int `i` such that `0 <= i <= maxInt(T)`.
5252 /// `i` is evenly distributed.
5353 pub fn int(r: *Random, comptime T: type) T {
54 const UnsignedT = std.meta.Int(false, T.bit_count);
55 const ByteAlignedT = std.meta.Int(false, @divTrunc(T.bit_count + 7, 8) * 8);
54 const bits = @typeInfo(T).Int.bits;
55 const UnsignedT = std.meta.Int(false, bits);
56 const ByteAlignedT = std.meta.Int(false, @divTrunc(bits + 7, 8) * 8);
5657
5758 var rand_bytes: [@sizeOf(ByteAlignedT)]u8 = undefined;
5859 r.bytes(rand_bytes[0..]);
......@@ -68,10 +69,11 @@ pub const Random = struct {
6869 /// Constant-time implementation off `uintLessThan`.
6970 /// The results of this function may be biased.
7071 pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T {
71 comptime assert(T.is_signed == false);
72 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
72 comptime assert(@typeInfo(T).Int.is_signed == false);
73 const bits = @typeInfo(T).Int.bits;
74 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
7375 assert(0 < less_than);
74 if (T.bit_count <= 32) {
76 if (bits <= 32) {
7577 return @intCast(T, limitRangeBiased(u32, r.int(u32), less_than));
7678 } else {
7779 return @intCast(T, limitRangeBiased(u64, r.int(u64), less_than));
......@@ -87,13 +89,15 @@ pub const Random = struct {
8789 /// this function is guaranteed to return.
8890 /// If you need deterministic runtime bounds, use `uintLessThanBiased`.
8991 pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T {
90 comptime assert(T.is_signed == false);
91 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
92 comptime assert(@typeInfo(T).Int.is_signed == false);
93 const bits = @typeInfo(T).Int.bits;
94 comptime assert(bits <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
9295 assert(0 < less_than);
9396 // Small is typically u32
94 const Small = std.meta.Int(false, @divTrunc(T.bit_count + 31, 32) * 32);
97 const small_bits = @divTrunc(bits + 31, 32) * 32;
98 const Small = std.meta.Int(false, small_bits);
9599 // Large is typically u64
96 const Large = std.meta.Int(false, Small.bit_count * 2);
100 const Large = std.meta.Int(false, small_bits * 2);
97101
98102 // adapted from:
99103 // http://www.pcg-random.org/posts/bounded-rands.html
......@@ -105,7 +109,7 @@ pub const Random = struct {
105109 // TODO: workaround for https://github.com/ziglang/zig/issues/1770
106110 // should be:
107111 // var t: Small = -%less_than;
108 var t: Small = @bitCast(Small, -%@bitCast(std.meta.Int(true, Small.bit_count), @as(Small, less_than)));
112 var t: Small = @bitCast(Small, -%@bitCast(std.meta.Int(true, small_bits), @as(Small, less_than)));
109113
110114 if (t >= less_than) {
111115 t -= less_than;
......@@ -119,13 +123,13 @@ pub const Random = struct {
119123 l = @truncate(Small, m);
120124 }
121125 }
122 return @intCast(T, m >> Small.bit_count);
126 return @intCast(T, m >> small_bits);
123127 }
124128
125129 /// Constant-time implementation off `uintAtMost`.
126130 /// The results of this function may be biased.
127131 pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T {
128 assert(T.is_signed == false);
132 assert(@typeInfo(T).Int.is_signed == false);
129133 if (at_most == maxInt(T)) {
130134 // have the full range
131135 return r.int(T);
......@@ -137,7 +141,7 @@ pub const Random = struct {
137141 /// See `uintLessThan`, which this function uses in most cases,
138142 /// for commentary on the runtime of this function.
139143 pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {
140 assert(T.is_signed == false);
144 assert(@typeInfo(T).Int.is_signed == false);
141145 if (at_most == maxInt(T)) {
142146 // have the full range
143147 return r.int(T);
......@@ -149,9 +153,10 @@ pub const Random = struct {
149153 /// The results of this function may be biased.
150154 pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T {
151155 assert(at_least < less_than);
152 if (T.is_signed) {
156 const info = @typeInfo(T).Int;
157 if (info.is_signed) {
153158 // Two's complement makes this math pretty easy.
154 const UnsignedT = std.meta.Int(false, T.bit_count);
159 const UnsignedT = std.meta.Int(false, info.bits);
155160 const lo = @bitCast(UnsignedT, at_least);
156161 const hi = @bitCast(UnsignedT, less_than);
157162 const result = lo +% r.uintLessThanBiased(UnsignedT, hi -% lo);
......@@ -167,9 +172,10 @@ pub const Random = struct {
167172 /// for commentary on the runtime of this function.
168173 pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T {
169174 assert(at_least < less_than);
170 if (T.is_signed) {
175 const info = @typeInfo(T).Int;
176 if (info.is_signed) {
171177 // Two's complement makes this math pretty easy.
172 const UnsignedT = std.meta.Int(false, T.bit_count);
178 const UnsignedT = std.meta.Int(false, info.bits);
173179 const lo = @bitCast(UnsignedT, at_least);
174180 const hi = @bitCast(UnsignedT, less_than);
175181 const result = lo +% r.uintLessThan(UnsignedT, hi -% lo);
......@@ -184,9 +190,10 @@ pub const Random = struct {
184190 /// The results of this function may be biased.
185191 pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T {
186192 assert(at_least <= at_most);
187 if (T.is_signed) {
193 const info = @typeInfo(T).Int;
194 if (info.is_signed) {
188195 // Two's complement makes this math pretty easy.
189 const UnsignedT = std.meta.Int(false, T.bit_count);
196 const UnsignedT = std.meta.Int(false, info.bits);
190197 const lo = @bitCast(UnsignedT, at_least);
191198 const hi = @bitCast(UnsignedT, at_most);
192199 const result = lo +% r.uintAtMostBiased(UnsignedT, hi -% lo);
......@@ -202,9 +209,10 @@ pub const Random = struct {
202209 /// for commentary on the runtime of this function.
203210 pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T {
204211 assert(at_least <= at_most);
205 if (T.is_signed) {
212 const info = @typeInfo(T).Int;
213 if (info.is_signed) {
206214 // Two's complement makes this math pretty easy.
207 const UnsignedT = std.meta.Int(false, T.bit_count);
215 const UnsignedT = std.meta.Int(false, info.bits);
208216 const lo = @bitCast(UnsignedT, at_least);
209217 const hi = @bitCast(UnsignedT, at_most);
210218 const result = lo +% r.uintAtMost(UnsignedT, hi -% lo);
......@@ -280,14 +288,15 @@ pub const Random = struct {
280288/// into an integer 0 <= result < less_than.
281289/// This function introduces a minor bias.
282290pub fn limitRangeBiased(comptime T: type, random_int: T, less_than: T) T {
283 comptime assert(T.is_signed == false);
284 const T2 = std.meta.Int(false, T.bit_count * 2);
291 comptime assert(@typeInfo(T).Int.is_signed == false);
292 const bits = @typeInfo(T).Int.bits;
293 const T2 = std.meta.Int(false, bits * 2);
285294
286295 // adapted from:
287296 // http://www.pcg-random.org/posts/bounded-rands.html
288297 // "Integer Multiplication (Biased)"
289298 var m: T2 = @as(T2, random_int) * @as(T2, less_than);
290 return @intCast(T, m >> T.bit_count);
299 return @intCast(T, m >> bits);
291300}
292301
293302const SequentialPrng = struct {
lib/std/special/build_runner.zig+1-1
......@@ -133,7 +133,7 @@ pub fn main() !void {
133133}
134134
135135fn runBuild(builder: *Builder) anyerror!void {
136 switch (@typeInfo(@TypeOf(root.build).ReturnType)) {
136 switch (@typeInfo(@typeInfo(@TypeOf(root.build)).Fn.return_type.?)) {
137137 .Void => root.build(builder),
138138 .ErrorUnion => try root.build(builder),
139139 else => @compileError("expected return type of build to be 'void' or '!void'"),
lib/std/special/c.zig+3-2
......@@ -516,11 +516,12 @@ export fn roundf(a: f32) f32 {
516516fn generic_fmod(comptime T: type, x: T, y: T) T {
517517 @setRuntimeSafety(false);
518518
519 const uint = std.meta.Int(false, T.bit_count);
519 const bits = @typeInfo(T).Float.bits;
520 const uint = std.meta.Int(false, bits);
520521 const log2uint = math.Log2Int(uint);
521522 const digits = if (T == f32) 23 else 52;
522523 const exp_bits = if (T == f32) 9 else 12;
523 const bits_minus_1 = T.bit_count - 1;
524 const bits_minus_1 = bits - 1;
524525 const mask = if (T == f32) 0xff else 0x7ff;
525526 var ux = @bitCast(uint, x);
526527 var uy = @bitCast(uint, y);
lib/std/special/compiler_rt/addXf3.zig+10-8
......@@ -59,23 +59,25 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
5959}
6060
6161// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
62fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
63 const Z = std.meta.Int(false, T.bit_count);
64 const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
62fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
63 const bits = @typeInfo(T).Float.bits;
64 const Z = std.meta.Int(false, bits);
65 const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
6566 const significandBits = std.math.floatMantissaBits(T);
6667 const implicitBit = @as(Z, 1) << significandBits;
6768
68 const shift = @clz(std.meta.Int(false, T.bit_count), significand.*) - @clz(Z, implicitBit);
69 const shift = @clz(std.meta.Int(false, bits), significand.*) - @clz(Z, implicitBit);
6970 significand.* <<= @intCast(S, shift);
7071 return 1 - shift;
7172}
7273
7374// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
7475fn addXf3(comptime T: type, a: T, b: T) T {
75 const Z = std.meta.Int(false, T.bit_count);
76 const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
76 const bits = @typeInfo(T).Float.bits;
77 const Z = std.meta.Int(false, bits);
78 const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
7779
78 const typeWidth = T.bit_count;
80 const typeWidth = bits;
7981 const significandBits = std.math.floatMantissaBits(T);
8082 const exponentBits = std.math.floatExponentBits(T);
8183
......@@ -187,7 +189,7 @@ fn addXf3(comptime T: type, a: T, b: T) T {
187189 // If partial cancellation occured, we need to left-shift the result
188190 // and adjust the exponent:
189191 if (aSignificand < implicitBit << 3) {
190 const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.Int(false, T.bit_count), implicitBit << 3));
192 const shift = @intCast(i32, @clz(Z, aSignificand)) - @intCast(i32, @clz(std.meta.Int(false, bits), implicitBit << 3));
191193 aSignificand <<= @intCast(S, shift);
192194 aExponent -= shift;
193195 }
lib/std/special/compiler_rt/aulldiv.zig+2-2
......@@ -7,8 +7,8 @@ const builtin = @import("builtin");
77
88pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
99 @setRuntimeSafety(builtin.is_test);
10 const s_a = a >> (i64.bit_count - 1);
11 const s_b = b >> (i64.bit_count - 1);
10 const s_a = a >> (64 - 1);
11 const s_b = b >> (64 - 1);
1212
1313 const an = (a ^ s_a) -% s_a;
1414 const bn = (b ^ s_b) -% s_b;
lib/std/special/compiler_rt/aullrem.zig+2-2
......@@ -7,8 +7,8 @@ const builtin = @import("builtin");
77
88pub fn _allrem(a: i64, b: i64) callconv(.Stdcall) i64 {
99 @setRuntimeSafety(builtin.is_test);
10 const s_a = a >> (i64.bit_count - 1);
11 const s_b = b >> (i64.bit_count - 1);
10 const s_a = a >> (64 - 1);
11 const s_b = b >> (64 - 1);
1212
1313 const an = (a ^ s_a) -% s_a;
1414 const bn = (b ^ s_b) -% s_b;
lib/std/special/compiler_rt/compareXf2.zig+4-3
......@@ -27,8 +27,9 @@ const GE = extern enum(i32) {
2727pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
2828 @setRuntimeSafety(builtin.is_test);
2929
30 const srep_t = std.meta.Int(true, T.bit_count);
31 const rep_t = std.meta.Int(false, T.bit_count);
30 const bits = @typeInfo(T).Float.bits;
31 const srep_t = std.meta.Int(true, bits);
32 const rep_t = std.meta.Int(false, bits);
3233
3334 const significandBits = std.math.floatMantissaBits(T);
3435 const exponentBits = std.math.floatExponentBits(T);
......@@ -73,7 +74,7 @@ pub fn cmp(comptime T: type, comptime RT: type, a: T, b: T) RT {
7374pub fn unordcmp(comptime T: type, a: T, b: T) i32 {
7475 @setRuntimeSafety(builtin.is_test);
7576
76 const rep_t = std.meta.Int(false, T.bit_count);
77 const rep_t = std.meta.Int(false, @typeInfo(T).Float.bits);
7778
7879 const significandBits = std.math.floatMantissaBits(T);
7980 const exponentBits = std.math.floatExponentBits(T);
lib/std/special/compiler_rt/divdf3.zig+4-5
......@@ -12,10 +12,9 @@ const builtin = @import("builtin");
1212
1313pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
1414 @setRuntimeSafety(builtin.is_test);
15 const Z = std.meta.Int(false, f64.bit_count);
16 const SignedZ = std.meta.Int(true, f64.bit_count);
15 const Z = std.meta.Int(false, 64);
16 const SignedZ = std.meta.Int(true, 64);
1717
18 const typeWidth = f64.bit_count;
1918 const significandBits = std.math.floatMantissaBits(f64);
2019 const exponentBits = std.math.floatExponentBits(f64);
2120
......@@ -317,9 +316,9 @@ pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
317316 }
318317}
319318
320pub fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
319pub fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
321320 @setRuntimeSafety(builtin.is_test);
322 const Z = std.meta.Int(false, T.bit_count);
321 const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
323322 const significandBits = std.math.floatMantissaBits(T);
324323 const implicitBit = @as(Z, 1) << significandBits;
325324
lib/std/special/compiler_rt/divsf3.zig+3-4
......@@ -12,9 +12,8 @@ const builtin = @import("builtin");
1212
1313pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
1414 @setRuntimeSafety(builtin.is_test);
15 const Z = std.meta.Int(false, f32.bit_count);
15 const Z = std.meta.Int(false, 32);
1616
17 const typeWidth = f32.bit_count;
1817 const significandBits = std.math.floatMantissaBits(f32);
1918 const exponentBits = std.math.floatExponentBits(f32);
2019
......@@ -190,9 +189,9 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
190189 }
191190}
192191
193fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
192fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
194193 @setRuntimeSafety(builtin.is_test);
195 const Z = std.meta.Int(false, T.bit_count);
194 const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
196195 const significandBits = std.math.floatMantissaBits(T);
197196 const implicitBit = @as(Z, 1) << significandBits;
198197
lib/std/special/compiler_rt/divtf3.zig+2-3
......@@ -11,10 +11,9 @@ const wideMultiply = @import("divdf3.zig").wideMultiply;
1111
1212pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {
1313 @setRuntimeSafety(builtin.is_test);
14 const Z = std.meta.Int(false, f128.bit_count);
15 const SignedZ = std.meta.Int(true, f128.bit_count);
14 const Z = std.meta.Int(false, 128);
15 const SignedZ = std.meta.Int(true, 128);
1616
17 const typeWidth = f128.bit_count;
1817 const significandBits = std.math.floatMantissaBits(f128);
1918 const exponentBits = std.math.floatExponentBits(f128);
2019
lib/std/special/compiler_rt/divti3.zig+2-2
......@@ -9,8 +9,8 @@ const builtin = @import("builtin");
99pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
1010 @setRuntimeSafety(builtin.is_test);
1111
12 const s_a = a >> (i128.bit_count - 1);
13 const s_b = b >> (i128.bit_count - 1);
12 const s_a = a >> (128 - 1);
13 const s_b = b >> (128 - 1);
1414
1515 const an = (a ^ s_a) -% s_a;
1616 const bn = (b ^ s_b) -% s_b;
lib/std/special/compiler_rt/fixint.zig+5-4
......@@ -28,7 +28,7 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
2828 else => unreachable,
2929 };
3030
31 const typeWidth = rep_t.bit_count;
31 const typeWidth = @typeInfo(rep_t).Int.bits;
3232 const exponentBits = (typeWidth - significandBits - 1);
3333 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
3434 const maxExponent = ((1 << exponentBits) - 1);
......@@ -50,12 +50,13 @@ pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t {
5050 if (exponent < 0) return 0;
5151
5252 // The unsigned result needs to be large enough to handle an fixint_t or rep_t
53 const fixuint_t = std.meta.Int(false, fixint_t.bit_count);
54 const UintResultType = if (fixint_t.bit_count > rep_t.bit_count) fixuint_t else rep_t;
53 const fixint_bits = @typeInfo(fixint_t).Int.bits;
54 const fixuint_t = std.meta.Int(false, fixint_bits);
55 const UintResultType = if (fixint_bits > typeWidth) fixuint_t else rep_t;
5556 var uint_result: UintResultType = undefined;
5657
5758 // If the value is too large for the integer type, saturate.
58 if (@intCast(usize, exponent) >= fixint_t.bit_count) {
59 if (@intCast(usize, exponent) >= fixint_bits) {
5960 return if (negative) @as(fixint_t, minInt(fixint_t)) else @as(fixint_t, maxInt(fixint_t));
6061 }
6162
lib/std/special/compiler_rt/fixuint.zig+3-3
......@@ -15,14 +15,14 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
1515 f128 => u128,
1616 else => unreachable,
1717 };
18 const srep_t = @import("std").meta.Int(true, rep_t.bit_count);
18 const typeWidth = @typeInfo(rep_t).Int.bits;
19 const srep_t = @import("std").meta.Int(true, typeWidth);
1920 const significandBits = switch (fp_t) {
2021 f32 => 23,
2122 f64 => 52,
2223 f128 => 112,
2324 else => unreachable,
2425 };
25 const typeWidth = rep_t.bit_count;
2626 const exponentBits = (typeWidth - significandBits - 1);
2727 const signBit = (@as(rep_t, 1) << (significandBits + exponentBits));
2828 const maxExponent = ((1 << exponentBits) - 1);
......@@ -44,7 +44,7 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
4444 if (sign == -1 or exponent < 0) return 0;
4545
4646 // If the value is too large for the integer type, saturate.
47 if (@intCast(c_uint, exponent) >= fixuint_t.bit_count) return ~@as(fixuint_t, 0);
47 if (@intCast(c_uint, exponent) >= @typeInfo(fixuint_t).Int.bits) return ~@as(fixuint_t, 0);
4848
4949 // If 0 <= exponent < significandBits, right shift to get the result.
5050 // Otherwise, shift left.
lib/std/special/compiler_rt/floatXisf.zig+5-4
......@@ -12,15 +12,16 @@ const FLT_MANT_DIG = 24;
1212fn __floatXisf(comptime T: type, arg: T) f32 {
1313 @setRuntimeSafety(builtin.is_test);
1414
15 const Z = std.meta.Int(false, T.bit_count);
16 const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
15 const bits = @typeInfo(T).Int.bits;
16 const Z = std.meta.Int(false, bits);
17 const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
1718
1819 if (arg == 0) {
1920 return @as(f32, 0.0);
2021 }
2122
2223 var ai = arg;
23 const N: u32 = T.bit_count;
24 const N: u32 = bits;
2425 const si = ai >> @intCast(S, (N - 1));
2526 ai = ((ai ^ si) -% si);
2627 var a = @bitCast(Z, ai);
......@@ -66,7 +67,7 @@ fn __floatXisf(comptime T: type, arg: T) f32 {
6667 // a is now rounded to FLT_MANT_DIG bits
6768 }
6869
69 const s = @bitCast(Z, arg) >> (T.bit_count - 32);
70 const s = @bitCast(Z, arg) >> (@typeInfo(T).Int.bits - 32);
7071 const r = (@intCast(u32, s) & 0x80000000) | // sign
7172 (@intCast(u32, (e + 127)) << 23) | // exponent
7273 (@truncate(u32, a) & 0x007fffff); // mantissa-high
lib/std/special/compiler_rt/floatsiXf.zig+4-3
......@@ -10,8 +10,9 @@ const maxInt = std.math.maxInt;
1010fn floatsiXf(comptime T: type, a: i32) T {
1111 @setRuntimeSafety(builtin.is_test);
1212
13 const Z = std.meta.Int(false, T.bit_count);
14 const S = std.meta.Int(false, T.bit_count - @clz(Z, @as(Z, T.bit_count) - 1));
13 const bits = @typeInfo(T).Float.bits;
14 const Z = std.meta.Int(false, bits);
15 const S = std.meta.Int(false, bits - @clz(Z, @as(Z, bits) - 1));
1516
1617 if (a == 0) {
1718 return @as(T, 0.0);
......@@ -22,7 +23,7 @@ fn floatsiXf(comptime T: type, a: i32) T {
2223 const exponentBias = ((1 << exponentBits - 1) - 1);
2324
2425 const implicitBit = @as(Z, 1) << significandBits;
25 const signBit = @as(Z, 1 << Z.bit_count - 1);
26 const signBit = @as(Z, 1 << bits - 1);
2627
2728 const sign = a >> 31;
2829 // Take absolute value of a via abs(x) = (x^(x >> 31)) - (x >> 31).
lib/std/special/compiler_rt/floatundisf.zig+1-1
......@@ -15,7 +15,7 @@ pub fn __floatundisf(arg: u64) callconv(.C) f32 {
1515 if (arg == 0) return 0;
1616
1717 var a = arg;
18 const N: usize = @TypeOf(a).bit_count;
18 const N: usize = @typeInfo(@TypeOf(a)).Int.bits;
1919 // Number of significant digits
2020 const sd = N - @clz(u64, a);
2121 // 8 exponent
lib/std/special/compiler_rt/floatunditf.zig+1-1
......@@ -19,7 +19,7 @@ pub fn __floatunditf(a: u64) callconv(.C) f128 {
1919 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
2020 const implicit_bit = 1 << mantissa_bits;
2121
22 const exp: u128 = (u64.bit_count - 1) - @clz(u64, a);
22 const exp: u128 = (64 - 1) - @clz(u64, a);
2323 const shift: u7 = mantissa_bits - @intCast(u7, exp);
2424
2525 var result: u128 = (@intCast(u128, a) << shift) ^ implicit_bit;
lib/std/special/compiler_rt/floatunsitf.zig+1-1
......@@ -19,7 +19,7 @@ pub fn __floatunsitf(a: u64) callconv(.C) f128 {
1919 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
2020 const implicit_bit = 1 << mantissa_bits;
2121
22 const exp = (u64.bit_count - 1) - @clz(u64, a);
22 const exp = (64 - 1) - @clz(u64, a);
2323 const shift = mantissa_bits - @intCast(u7, exp);
2424
2525 // TODO(#1148): @bitCast alignment error
lib/std/special/compiler_rt/int.zig+1-1
......@@ -219,7 +219,7 @@ fn test_one_divsi3(a: i32, b: i32, expected_q: i32) void {
219219pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
220220 @setRuntimeSafety(builtin.is_test);
221221
222 const n_uword_bits: c_uint = u32.bit_count;
222 const n_uword_bits: c_uint = 32;
223223 // special cases
224224 if (d == 0) return 0; // ?!
225225 if (n == 0) return 0;
lib/std/special/compiler_rt/modti3.zig+2-2
......@@ -14,8 +14,8 @@ const compiler_rt = @import("../compiler_rt.zig");
1414pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
1515 @setRuntimeSafety(builtin.is_test);
1616
17 const s_a = a >> (i128.bit_count - 1); // s = a < 0 ? -1 : 0
18 const s_b = b >> (i128.bit_count - 1); // s = b < 0 ? -1 : 0
17 const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0
18 const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0
1919
2020 const an = (a ^ s_a) -% s_a; // negate if s == -1
2121 const bn = (b ^ s_b) -% s_b; // negate if s == -1
lib/std/special/compiler_rt/mulXf3.zig+5-5
......@@ -33,9 +33,9 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {
3333
3434fn mulXf3(comptime T: type, a: T, b: T) T {
3535 @setRuntimeSafety(builtin.is_test);
36 const Z = std.meta.Int(false, T.bit_count);
36 const typeWidth = @typeInfo(T).Float.bits;
37 const Z = std.meta.Int(false, typeWidth);
3738
38 const typeWidth = T.bit_count;
3939 const significandBits = std.math.floatMantissaBits(T);
4040 const exponentBits = std.math.floatExponentBits(T);
4141
......@@ -269,9 +269,9 @@ fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
269269 }
270270}
271271
272fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i32 {
272fn normalize(comptime T: type, significand: *std.meta.Int(false, @typeInfo(T).Float.bits)) i32 {
273273 @setRuntimeSafety(builtin.is_test);
274 const Z = std.meta.Int(false, T.bit_count);
274 const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
275275 const significandBits = std.math.floatMantissaBits(T);
276276 const implicitBit = @as(Z, 1) << significandBits;
277277
......@@ -282,7 +282,7 @@ fn normalize(comptime T: type, significand: *std.meta.Int(false, T.bit_count)) i
282282
283283fn wideRightShiftWithSticky(comptime Z: type, hi: *Z, lo: *Z, count: u32) void {
284284 @setRuntimeSafety(builtin.is_test);
285 const typeWidth = Z.bit_count;
285 const typeWidth = @typeInfo(Z).Int.bits;
286286 const S = std.math.Log2Int(Z);
287287 if (count < typeWidth) {
288288 const sticky = @truncate(u8, lo.* << @intCast(S, typeWidth -% count));
lib/std/special/compiler_rt/mulodi4.zig+1-1
......@@ -11,7 +11,7 @@ const minInt = std.math.minInt;
1111pub fn __mulodi4(a: i64, b: i64, overflow: *c_int) callconv(.C) i64 {
1212 @setRuntimeSafety(builtin.is_test);
1313
14 const min = @bitCast(i64, @as(u64, 1 << (i64.bit_count - 1)));
14 const min = @bitCast(i64, @as(u64, 1 << (64 - 1)));
1515 const max = ~min;
1616
1717 overflow.* = 0;
lib/std/special/compiler_rt/muloti4.zig+3-3
......@@ -9,7 +9,7 @@ const compiler_rt = @import("../compiler_rt.zig");
99pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
1010 @setRuntimeSafety(builtin.is_test);
1111
12 const min = @bitCast(i128, @as(u128, 1 << (i128.bit_count - 1)));
12 const min = @bitCast(i128, @as(u128, 1 << (128 - 1)));
1313 const max = ~min;
1414 overflow.* = 0;
1515
......@@ -27,9 +27,9 @@ pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
2727 return r;
2828 }
2929
30 const sa = a >> (i128.bit_count - 1);
30 const sa = a >> (128 - 1);
3131 const abs_a = (a ^ sa) -% sa;
32 const sb = b >> (i128.bit_count - 1);
32 const sb = b >> (128 - 1);
3333 const abs_b = (b ^ sb) -% sb;
3434
3535 if (abs_a < 2 or abs_b < 2) {
lib/std/special/compiler_rt/negXf2.zig+1-2
......@@ -24,9 +24,8 @@ pub fn __aeabi_dneg(arg: f64) callconv(.AAPCS) f64 {
2424}
2525
2626fn negXf2(comptime T: type, a: T) T {
27 const Z = std.meta.Int(false, T.bit_count);
27 const Z = std.meta.Int(false, @typeInfo(T).Float.bits);
2828
29 const typeWidth = T.bit_count;
3029 const significandBits = std.math.floatMantissaBits(T);
3130 const exponentBits = std.math.floatExponentBits(T);
3231
lib/std/special/compiler_rt/shift.zig+13-12
......@@ -9,8 +9,9 @@ const Log2Int = std.math.Log2Int;
99
1010fn Dwords(comptime T: type, comptime signed_half: bool) type {
1111 return extern union {
12 pub const HalfTU = std.meta.Int(false, @divExact(T.bit_count, 2));
13 pub const HalfTS = std.meta.Int(true, @divExact(T.bit_count, 2));
12 pub const bits = @divExact(@typeInfo(T).Int.bits, 2);
13 pub const HalfTU = std.meta.Int(false, bits);
14 pub const HalfTS = std.meta.Int(true, bits);
1415 pub const HalfT = if (signed_half) HalfTS else HalfTU;
1516
1617 all: T,
......@@ -30,15 +31,15 @@ pub fn ashlXi3(comptime T: type, a: T, b: i32) T {
3031 const input = dwords{ .all = a };
3132 var output: dwords = undefined;
3233
33 if (b >= dwords.HalfT.bit_count) {
34 if (b >= dwords.bits) {
3435 output.s.low = 0;
35 output.s.high = input.s.low << @intCast(S, b - dwords.HalfT.bit_count);
36 output.s.high = input.s.low << @intCast(S, b - dwords.bits);
3637 } else if (b == 0) {
3738 return a;
3839 } else {
3940 output.s.low = input.s.low << @intCast(S, b);
4041 output.s.high = input.s.high << @intCast(S, b);
41 output.s.high |= input.s.low >> @intCast(S, dwords.HalfT.bit_count - b);
42 output.s.high |= input.s.low >> @intCast(S, dwords.bits - b);
4243 }
4344
4445 return output.all;
......@@ -53,14 +54,14 @@ pub fn ashrXi3(comptime T: type, a: T, b: i32) T {
5354 const input = dwords{ .all = a };
5455 var output: dwords = undefined;
5556
56 if (b >= dwords.HalfT.bit_count) {
57 output.s.high = input.s.high >> (dwords.HalfT.bit_count - 1);
58 output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count);
57 if (b >= dwords.bits) {
58 output.s.high = input.s.high >> (dwords.bits - 1);
59 output.s.low = input.s.high >> @intCast(S, b - dwords.bits);
5960 } else if (b == 0) {
6061 return a;
6162 } else {
6263 output.s.high = input.s.high >> @intCast(S, b);
63 output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b);
64 output.s.low = input.s.high << @intCast(S, dwords.bits - b);
6465 // Avoid sign-extension here
6566 output.s.low |= @bitCast(
6667 dwords.HalfT,
......@@ -80,14 +81,14 @@ pub fn lshrXi3(comptime T: type, a: T, b: i32) T {
8081 const input = dwords{ .all = a };
8182 var output: dwords = undefined;
8283
83 if (b >= dwords.HalfT.bit_count) {
84 if (b >= dwords.bits) {
8485 output.s.high = 0;
85 output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count);
86 output.s.low = input.s.high >> @intCast(S, b - dwords.bits);
8687 } else if (b == 0) {
8788 return a;
8889 } else {
8990 output.s.high = input.s.high >> @intCast(S, b);
90 output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b);
91 output.s.low = input.s.high << @intCast(S, dwords.bits - b);
9192 output.s.low |= input.s.low >> @intCast(S, b);
9293 }
9394
lib/std/special/compiler_rt/truncXfYf2.zig+2-2
......@@ -50,7 +50,7 @@ fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
5050
5151 // Various constants whose values follow from the type parameters.
5252 // Any reasonable optimizer will fold and propagate all of these.
53 const srcBits = src_t.bit_count;
53 const srcBits = @typeInfo(src_t).Float.bits;
5454 const srcExpBits = srcBits - srcSigBits - 1;
5555 const srcInfExp = (1 << srcExpBits) - 1;
5656 const srcExpBias = srcInfExp >> 1;
......@@ -65,7 +65,7 @@ fn truncXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
6565 const srcQNaN = 1 << (srcSigBits - 1);
6666 const srcNaNCode = srcQNaN - 1;
6767
68 const dstBits = dst_t.bit_count;
68 const dstBits = @typeInfo(dst_t).Float.bits;
6969 const dstExpBits = dstBits - dstSigBits - 1;
7070 const dstInfExp = (1 << dstExpBits) - 1;
7171 const dstExpBias = dstInfExp >> 1;
lib/std/special/compiler_rt/udivmod.zig+36-34
......@@ -15,8 +15,10 @@ const high = 1 - low;
1515pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?*DoubleInt) DoubleInt {
1616 @setRuntimeSafety(is_test);
1717
18 const SingleInt = @import("std").meta.Int(false, @divExact(DoubleInt.bit_count, 2));
19 const SignedDoubleInt = @import("std").meta.Int(true, DoubleInt.bit_count);
18 const double_int_bits = @typeInfo(DoubleInt).Int.bits;
19 const single_int_bits = @divExact(double_int_bits, 2);
20 const SingleInt = @import("std").meta.Int(false, single_int_bits);
21 const SignedDoubleInt = @import("std").meta.Int(true, double_int_bits);
2022 const Log2SingleInt = @import("std").math.Log2Int(SingleInt);
2123
2224 const n = @ptrCast(*const [2]SingleInt, &a).*; // TODO issue #421
......@@ -82,21 +84,21 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
8284 // ---
8385 // K 0
8486 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
85 // 0 <= sr <= SingleInt.bit_count - 2 or sr large
86 if (sr > SingleInt.bit_count - 2) {
87 // 0 <= sr <= single_int_bits - 2 or sr large
88 if (sr > single_int_bits - 2) {
8789 if (maybe_rem) |rem| {
8890 rem.* = a;
8991 }
9092 return 0;
9193 }
9294 sr += 1;
93 // 1 <= sr <= SingleInt.bit_count - 1
94 // q.all = a << (DoubleInt.bit_count - sr);
95 // 1 <= sr <= single_int_bits - 1
96 // q.all = a << (double_int_bits - sr);
9597 q[low] = 0;
96 q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
98 q[high] = n[low] << @intCast(Log2SingleInt, single_int_bits - sr);
9799 // r.all = a >> sr;
98100 r[high] = n[high] >> @intCast(Log2SingleInt, sr);
99 r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
101 r[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
100102 } else {
101103 // d[low] != 0
102104 if (d[high] == 0) {
......@@ -113,74 +115,74 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
113115 }
114116 sr = @ctz(SingleInt, d[low]);
115117 q[high] = n[high] >> @intCast(Log2SingleInt, sr);
116 q[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
118 q[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
117119 return @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
118120 }
119121 // K X
120122 // ---
121123 // 0 K
122 sr = 1 + SingleInt.bit_count + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
123 // 2 <= sr <= DoubleInt.bit_count - 1
124 // q.all = a << (DoubleInt.bit_count - sr);
124 sr = 1 + single_int_bits + @as(c_uint, @clz(SingleInt, d[low])) - @as(c_uint, @clz(SingleInt, n[high]));
125 // 2 <= sr <= double_int_bits - 1
126 // q.all = a << (double_int_bits - sr);
125127 // r.all = a >> sr;
126 if (sr == SingleInt.bit_count) {
128 if (sr == single_int_bits) {
127129 q[low] = 0;
128130 q[high] = n[low];
129131 r[high] = 0;
130132 r[low] = n[high];
131 } else if (sr < SingleInt.bit_count) {
132 // 2 <= sr <= SingleInt.bit_count - 1
133 } else if (sr < single_int_bits) {
134 // 2 <= sr <= single_int_bits - 1
133135 q[low] = 0;
134 q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
136 q[high] = n[low] << @intCast(Log2SingleInt, single_int_bits - sr);
135137 r[high] = n[high] >> @intCast(Log2SingleInt, sr);
136 r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
138 r[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
137139 } else {
138 // SingleInt.bit_count + 1 <= sr <= DoubleInt.bit_count - 1
139 q[low] = n[low] << @intCast(Log2SingleInt, DoubleInt.bit_count - sr);
140 q[high] = (n[high] << @intCast(Log2SingleInt, DoubleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr - SingleInt.bit_count));
140 // single_int_bits + 1 <= sr <= double_int_bits - 1
141 q[low] = n[low] << @intCast(Log2SingleInt, double_int_bits - sr);
142 q[high] = (n[high] << @intCast(Log2SingleInt, double_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr - single_int_bits));
141143 r[high] = 0;
142 r[low] = n[high] >> @intCast(Log2SingleInt, sr - SingleInt.bit_count);
144 r[low] = n[high] >> @intCast(Log2SingleInt, sr - single_int_bits);
143145 }
144146 } else {
145147 // K X
146148 // ---
147149 // K K
148150 sr = @bitCast(c_uint, @as(c_int, @clz(SingleInt, d[high])) - @as(c_int, @clz(SingleInt, n[high])));
149 // 0 <= sr <= SingleInt.bit_count - 1 or sr large
150 if (sr > SingleInt.bit_count - 1) {
151 // 0 <= sr <= single_int_bits - 1 or sr large
152 if (sr > single_int_bits - 1) {
151153 if (maybe_rem) |rem| {
152154 rem.* = a;
153155 }
154156 return 0;
155157 }
156158 sr += 1;
157 // 1 <= sr <= SingleInt.bit_count
158 // q.all = a << (DoubleInt.bit_count - sr);
159 // 1 <= sr <= single_int_bits
160 // q.all = a << (double_int_bits - sr);
159161 // r.all = a >> sr;
160162 q[low] = 0;
161 if (sr == SingleInt.bit_count) {
163 if (sr == single_int_bits) {
162164 q[high] = n[low];
163165 r[high] = 0;
164166 r[low] = n[high];
165167 } else {
166168 r[high] = n[high] >> @intCast(Log2SingleInt, sr);
167 r[low] = (n[high] << @intCast(Log2SingleInt, SingleInt.bit_count - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
168 q[high] = n[low] << @intCast(Log2SingleInt, SingleInt.bit_count - sr);
169 r[low] = (n[high] << @intCast(Log2SingleInt, single_int_bits - sr)) | (n[low] >> @intCast(Log2SingleInt, sr));
170 q[high] = n[low] << @intCast(Log2SingleInt, single_int_bits - sr);
169171 }
170172 }
171173 }
172174 // Not a special case
173175 // q and r are initialized with:
174 // q.all = a << (DoubleInt.bit_count - sr);
176 // q.all = a << (double_int_bits - sr);
175177 // r.all = a >> sr;
176 // 1 <= sr <= DoubleInt.bit_count - 1
178 // 1 <= sr <= double_int_bits - 1
177179 var carry: u32 = 0;
178180 var r_all: DoubleInt = undefined;
179181 while (sr > 0) : (sr -= 1) {
180182 // r:q = ((r:q) << 1) | carry
181 r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
182 r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
183 q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
183 r[high] = (r[high] << 1) | (r[low] >> (single_int_bits - 1));
184 r[low] = (r[low] << 1) | (q[high] >> (single_int_bits - 1));
185 q[high] = (q[high] << 1) | (q[low] >> (single_int_bits - 1));
184186 q[low] = (q[low] << 1) | carry;
185187 // carry = 0;
186188 // if (r.all >= b)
......@@ -189,7 +191,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
189191 // carry = 1;
190192 // }
191193 r_all = @ptrCast(*align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
192 const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
194 const s: SignedDoubleInt = @bitCast(SignedDoubleInt, b -% r_all -% 1) >> (double_int_bits - 1);
193195 carry = @intCast(u32, s & 1);
194196 r_all -= b & @bitCast(DoubleInt, s);
195197 r = @ptrCast(*[2]SingleInt, &r_all).*; // TODO issue #421
lib/std/start.zig+1-1
......@@ -239,7 +239,7 @@ fn callMainAsync(loop: *std.event.Loop) callconv(.Async) u8 {
239239// This is not marked inline because it is called with @asyncCall when
240240// there is an event loop.
241241pub fn callMain() u8 {
242 switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
242 switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
243243 .NoReturn => {
244244 root.main();
245245 },
lib/std/thread.zig+3-3
......@@ -166,7 +166,7 @@ pub const Thread = struct {
166166 fn threadMain(raw_arg: windows.LPVOID) callconv(.C) windows.DWORD {
167167 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
168168
169 switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
169 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {
170170 .NoReturn => {
171171 startFn(arg);
172172 },
......@@ -227,7 +227,7 @@ pub const Thread = struct {
227227 fn linuxThreadMain(ctx_addr: usize) callconv(.C) u8 {
228228 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
229229
230 switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
230 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {
231231 .NoReturn => {
232232 startFn(arg);
233233 },
......@@ -259,7 +259,7 @@ pub const Thread = struct {
259259 fn posixThreadMain(ctx: ?*c_void) callconv(.C) ?*c_void {
260260 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), ctx)).*;
261261
262 switch (@typeInfo(@TypeOf(startFn).ReturnType)) {
262 switch (@typeInfo(@typeInfo(@TypeOf(startFn)).Fn.return_type.?)) {
263263 .NoReturn => {
264264 startFn(arg);
265265 },
lib/std/zig.zig+1-1
......@@ -22,7 +22,7 @@ pub const SrcHash = [16]u8;
2222/// If it is long, blake3 hash is computed.
2323pub fn hashSrc(src: []const u8) SrcHash {
2424 var out: SrcHash = undefined;
25 if (src.len <= SrcHash.len) {
25 if (src.len <= @typeInfo(SrcHash).Array.len) {
2626 std.mem.copy(u8, &out, src);
2727 std.mem.set(u8, out[src.len..], 0);
2828 } else {
test/stage1/behavior/align.zig+1-1
......@@ -5,7 +5,7 @@ const builtin = @import("builtin");
55var foo: u8 align(4) = 100;
66
77test "global variable alignment" {
8 comptime expect(@TypeOf(&foo).alignment == 4);
8 comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
99 comptime expect(@TypeOf(&foo) == *align(4) u8);
1010 {
1111 const slice = @as(*[1]u8, &foo)[0..];
test/stage1/behavior/array.zig-10
......@@ -136,16 +136,6 @@ test "array literal with specified size" {
136136 expect(array[1] == 2);
137137}
138138
139test "array child property" {
140 var x: [5]i32 = undefined;
141 expect(@TypeOf(x).Child == i32);
142}
143
144test "array len property" {
145 var x: [5]i32 = undefined;
146 expect(@TypeOf(x).len == 5);
147}
148
149139test "array len field" {
150140 var arr = [4]u8{ 0, 0, 0, 0 };
151141 var ptr = &arr;
test/stage1/behavior/async_fn.zig+3-3
......@@ -331,7 +331,7 @@ test "async fn with inferred error set" {
331331 fn doTheTest() void {
332332 var frame: [1]@Frame(middle) = undefined;
333333 var fn_ptr = middle;
334 var result: @TypeOf(fn_ptr).ReturnType.ErrorSet!void = undefined;
334 var result: @typeInfo(@typeInfo(@TypeOf(fn_ptr)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
335335 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, fn_ptr, .{});
336336 resume global_frame;
337337 std.testing.expectError(error.Fail, result);
......@@ -950,7 +950,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
950950
951951 fn doTheTest() void {
952952 var frame: [1]@Frame(middle) = undefined;
953 var result: @TypeOf(middle).ReturnType.ErrorSet!void = undefined;
953 var result: @typeInfo(@typeInfo(@TypeOf(middle)).Fn.return_type.?).ErrorUnion.error_set!void = undefined;
954954 _ = @asyncCall(std.mem.sliceAsBytes(frame[0..]), &result, middle, .{});
955955 resume global_frame;
956956 std.testing.expectError(error.Fail, result);
......@@ -1018,7 +1018,7 @@ test "@TypeOf an async function call of generic fn with error union type" {
10181018 const S = struct {
10191019 fn func(comptime x: anytype) anyerror!i32 {
10201020 const T = @TypeOf(async func(x));
1021 comptime expect(T == @TypeOf(@frame()).Child);
1021 comptime expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
10221022 return undefined;
10231023 }
10241024 };
test/stage1/behavior/bit_shifting.zig+7-5
......@@ -2,16 +2,18 @@ const std = @import("std");
22const expect = std.testing.expect;
33
44fn ShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, comptime V: type) type {
5 expect(Key == std.meta.Int(false, Key.bit_count));
6 expect(Key.bit_count >= mask_bit_count);
5 const key_bits = @typeInfo(Key).Int.bits;
6 expect(Key == std.meta.Int(false, key_bits));
7 expect(key_bits >= mask_bit_count);
8 const shard_key_bits = mask_bit_count;
79 const ShardKey = std.meta.Int(false, mask_bit_count);
8 const shift_amount = Key.bit_count - ShardKey.bit_count;
10 const shift_amount = key_bits - shard_key_bits;
911 return struct {
1012 const Self = @This();
11 shards: [1 << ShardKey.bit_count]?*Node,
13 shards: [1 << shard_key_bits]?*Node,
1214
1315 pub fn create() Self {
14 return Self{ .shards = [_]?*Node{null} ** (1 << ShardKey.bit_count) };
16 return Self{ .shards = [_]?*Node{null} ** (1 << shard_key_bits) };
1517 }
1618
1719 fn getShardKey(key: Key) ShardKey {
test/stage1/behavior/bugs/5487.zig+2-2
......@@ -3,8 +3,8 @@ const io = @import("std").io;
33pub fn write(_: void, bytes: []const u8) !usize {
44 return 0;
55}
6pub fn outStream() io.OutStream(void, @TypeOf(write).ReturnType.ErrorSet, write) {
7 return io.OutStream(void, @TypeOf(write).ReturnType.ErrorSet, write){ .context = {} };
6pub fn outStream() io.OutStream(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write) {
7 return io.OutStream(void, @typeInfo(@typeInfo(@TypeOf(write)).Fn.return_type.?).ErrorUnion.error_set, write){ .context = {} };
88}
99
1010test "crash" {
test/stage1/behavior/error.zig+2-2
......@@ -84,8 +84,8 @@ fn testErrorUnionType() void {
8484 const x: anyerror!i32 = 1234;
8585 if (x) |value| expect(value == 1234) else |_| unreachable;
8686 expect(@typeInfo(@TypeOf(x)) == .ErrorUnion);
87 expect(@typeInfo(@TypeOf(x).ErrorSet) == .ErrorSet);
88 expect(@TypeOf(x).ErrorSet == anyerror);
87 expect(@typeInfo(@typeInfo(@TypeOf(x)).ErrorUnion.error_set) == .ErrorSet);
88 expect(@typeInfo(@TypeOf(x)).ErrorUnion.error_set == anyerror);
8989}
9090
9191test "error set type" {
test/stage1/behavior/misc.zig-10
......@@ -24,12 +24,6 @@ test "call disabled extern fn" {
2424 disabledExternFn();
2525}
2626
27test "floating point primitive bit counts" {
28 expect(f16.bit_count == 16);
29 expect(f32.bit_count == 32);
30 expect(f64.bit_count == 64);
31}
32
3327test "short circuit" {
3428 testShortCircuit(false, true);
3529 comptime testShortCircuit(false, true);
......@@ -577,10 +571,6 @@ test "slice string literal has correct type" {
577571 comptime expect(@TypeOf(array[runtime_zero..]) == []const i32);
578572}
579573
580test "pointer child field" {
581 expect((*u32).Child == u32);
582}
583
584574test "struct inside function" {
585575 testStructInFn();
586576 comptime testStructInFn();
test/stage1/behavior/reflection.zig+7-15
......@@ -2,23 +2,15 @@ const expect = @import("std").testing.expect;
22const mem = @import("std").mem;
33const reflection = @This();
44
5test "reflection: array, pointer, optional, error union type child" {
6 comptime {
7 expect(([10]u8).Child == u8);
8 expect((*u8).Child == u8);
9 expect((anyerror!u8).Payload == u8);
10 expect((?u8).Child == u8);
11 }
12}
13
145test "reflection: function return type, var args, and param types" {
156 comptime {
16 expect(@TypeOf(dummy).ReturnType == i32);
17 expect(!@TypeOf(dummy).is_var_args);
18 expect(@TypeOf(dummy).arg_count == 3);
19 expect(@typeInfo(@TypeOf(dummy)).Fn.args[0].arg_type.? == bool);
20 expect(@typeInfo(@TypeOf(dummy)).Fn.args[1].arg_type.? == i32);
21 expect(@typeInfo(@TypeOf(dummy)).Fn.args[2].arg_type.? == f32);
7 const info = @typeInfo(@TypeOf(dummy)).Fn;
8 expect(info.return_type.? == i32);
9 expect(!info.is_var_args);
10 expect(info.args.len == 3);
11 expect(info.args[0].arg_type.? == bool);
12 expect(info.args[1].arg_type.? == i32);
13 expect(info.args[2].arg_type.? == f32);
2214 }
2315}
2416