| author | |
| committer | |
| log | dec1163fbb892f276179ae74b51007c656157d99 |
| tree | 7efa4ebe2ffb6876ffd6de0f417303232f559d87 |
| parent | ce0df033cf2bb6986c6c226786e6543d05e29a77 |
| signature |
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>108 files changed, 631 insertions(+), 1893 deletions(-)
doc/langref/std_options.zig+1-1| ... | @@ -11,7 +11,7 @@ pub const std_options: std.Options = .{ | ... | @@ -11,7 +11,7 @@ pub const std_options: std.Options = .{ |
| 11 | 11 | ||
| 12 | fn myLogFn( | 12 | fn myLogFn( |
| 13 | comptime level: std.log.Level, | 13 | comptime level: std.log.Level, |
| 14 | comptime scope: @Type(.enum_literal), | 14 | comptime scope: @EnumLiteral(), |
| 15 | comptime format: []const u8, | 15 | comptime format: []const u8, |
| 16 | args: anytype, | 16 | args: anytype, |
| 17 | ) void { | 17 | ) void { |
doc/langref/test_coerce_unions_enums.zig+1-1| ... | @@ -41,7 +41,7 @@ test "coercion between unions and enums" { | ... | @@ -41,7 +41,7 @@ test "coercion between unions and enums" { |
| 41 | try expect(u_4.tag() == 1); | 41 | try expect(u_4.tag() == 1); |
| 42 | 42 | ||
| 43 | // The following example is invalid. | 43 | // The following example is invalid. |
| 44 | // error: coercion from enum '@TypeOf(.enum_literal)' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b' | 44 | // error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b' |
| 45 | //var u_5: U2 = .b; | 45 | //var u_5: U2 = .b; |
| 46 | //try expect(u_5.tag() == 2); | 46 | //try expect(u_5.tag() == 2); |
| 47 | } | 47 | } |
lib/build-web/main.zig+1-1| ... | @@ -49,7 +49,7 @@ pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, addr: ?usize) noretu | ... | @@ -49,7 +49,7 @@ pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, addr: ?usize) noretu |
| 49 | 49 | ||
| 50 | fn logFn( | 50 | fn logFn( |
| 51 | comptime message_level: log.Level, | 51 | comptime message_level: log.Level, |
| 52 | comptime scope: @TypeOf(.enum_literal), | 52 | comptime scope: @EnumLiteral(), |
| 53 | comptime format: []const u8, | 53 | comptime format: []const u8, |
| 54 | args: anytype, | 54 | args: anytype, |
| 55 | ) void { | 55 | ) void { |
lib/compiler/aro/aro/Attribute.zig+6-16| ... | @@ -717,23 +717,13 @@ pub const Tag = std.meta.DeclEnum(attributes); | ... | @@ -717,23 +717,13 @@ pub const Tag = std.meta.DeclEnum(attributes); |
| 717 | 717 | ||
| 718 | pub const Arguments = blk: { | 718 | pub const Arguments = blk: { |
| 719 | const decls = @typeInfo(attributes).@"struct".decls; | 719 | const decls = @typeInfo(attributes).@"struct".decls; |
| 720 | var union_fields: [decls.len]ZigType.UnionField = undefined; | 720 | var names: [decls.len][]const u8 = undefined; |
| 721 | for (decls, &union_fields) |decl, *field| { | 721 | var types: [decls.len]type = undefined; |
| 722 | field.* = .{ | 722 | for (decls, &names, &types) |decl, *name, *T| { |
| 723 | .name = decl.name, | 723 | name.* = decl.name; |
| 724 | .type = @field(attributes, decl.name), | 724 | T.* = @field(attributes, decl.name); |
| 725 | .alignment = @alignOf(@field(attributes, decl.name)), | ||
| 726 | }; | ||
| 727 | } | 725 | } |
| 728 | 726 | break :blk @Union(.auto, null, &names, &types, &@splat(.{})); | |
| 729 | break :blk @Type(.{ | ||
| 730 | .@"union" = .{ | ||
| 731 | .layout = .auto, | ||
| 732 | .tag_type = null, | ||
| 733 | .fields = &union_fields, | ||
| 734 | .decls = &.{}, | ||
| 735 | }, | ||
| 736 | }); | ||
| 737 | }; | 727 | }; |
| 738 | 728 | ||
| 739 | pub fn ArgumentsForTag(comptime tag: Tag) type { | 729 | pub fn ArgumentsForTag(comptime tag: Tag) type { |
lib/compiler/aro/assembly_backend/x86_64.zig+1-1| ... | @@ -59,7 +59,7 @@ fn serializeFloat(comptime T: type, value: T, w: *std.Io.Writer) !void { | ... | @@ -59,7 +59,7 @@ fn serializeFloat(comptime T: type, value: T, w: *std.Io.Writer) !void { |
| 59 | else => { | 59 | else => { |
| 60 | const size = @bitSizeOf(T); | 60 | const size = @bitSizeOf(T); |
| 61 | const storage_unit = std.meta.intToEnum(StorageUnit, size) catch unreachable; | 61 | const storage_unit = std.meta.intToEnum(StorageUnit, size) catch unreachable; |
| 62 | const IntTy = @Type(.{ .int = .{ .signedness = .unsigned, .bits = size } }); | 62 | const IntTy = @Int(.unsigned, size); |
| 63 | const int_val: IntTy = @bitCast(value); | 63 | const int_val: IntTy = @bitCast(value); |
| 64 | return serializeInt(int_val, storage_unit, w); | 64 | return serializeInt(int_val, storage_unit, w); |
| 65 | }, | 65 | }, |
lib/compiler/resinator/code_pages.zig+7-6| ... | @@ -179,12 +179,13 @@ pub const UnsupportedCodePage = enum(u16) { | ... | @@ -179,12 +179,13 @@ pub const UnsupportedCodePage = enum(u16) { |
| 179 | 179 | ||
| 180 | pub const CodePage = blk: { | 180 | pub const CodePage = blk: { |
| 181 | const fields = @typeInfo(SupportedCodePage).@"enum".fields ++ @typeInfo(UnsupportedCodePage).@"enum".fields; | 181 | const fields = @typeInfo(SupportedCodePage).@"enum".fields ++ @typeInfo(UnsupportedCodePage).@"enum".fields; |
| 182 | break :blk @Type(.{ .@"enum" = .{ | 182 | var field_names: [fields.len][]const u8 = undefined; |
| 183 | .tag_type = u16, | 183 | var field_values: [fields.len]u16 = undefined; |
| 184 | .decls = &.{}, | 184 | for (fields, &field_names, &field_values) |field, *name, *val| { |
| 185 | .fields = fields, | 185 | name.* = field.name; |
| 186 | .is_exhaustive = true, | 186 | val.* = field.value; |
| 187 | } }); | 187 | } |
| 188 | break :blk @Enum(u16, .exhaustive, &field_names, &field_values); | ||
| 188 | }; | 189 | }; |
| 189 | 190 | ||
| 190 | pub fn isSupported(code_page: CodePage) bool { | 191 | pub fn isSupported(code_page: CodePage) bool { |
lib/compiler/resinator/errors.zig+12-9| ... | @@ -862,20 +862,23 @@ pub const ErrorDetails = struct { | ... | @@ -862,20 +862,23 @@ pub const ErrorDetails = struct { |
| 862 | pub const ErrorDetailsWithoutCodePage = blk: { | 862 | pub const ErrorDetailsWithoutCodePage = blk: { |
| 863 | const details_info = @typeInfo(ErrorDetails); | 863 | const details_info = @typeInfo(ErrorDetails); |
| 864 | const fields = details_info.@"struct".fields; | 864 | const fields = details_info.@"struct".fields; |
| 865 | var fields_without_codepage: [fields.len - 1]std.builtin.Type.StructField = undefined; | 865 | var field_names: [fields.len - 1][]const u8 = undefined; |
| 866 | var field_types: [fields.len - 1]type = undefined; | ||
| 867 | var field_attrs: [fields.len - 1]std.builtin.Type.StructField.Attributes = undefined; | ||
| 866 | var i: usize = 0; | 868 | var i: usize = 0; |
| 867 | for (fields) |field| { | 869 | for (fields) |field| { |
| 868 | if (std.mem.eql(u8, field.name, "code_page")) continue; | 870 | if (std.mem.eql(u8, field.name, "code_page")) continue; |
| 869 | fields_without_codepage[i] = field; | 871 | field_names[i] = field.name; |
| 872 | field_types[i] = field.type; | ||
| 873 | field_attrs[i] = .{ | ||
| 874 | .@"comptime" = field.is_comptime, | ||
| 875 | .@"align" = field.alignment, | ||
| 876 | .default_value_ptr = field.default_value_ptr, | ||
| 877 | }; | ||
| 870 | i += 1; | 878 | i += 1; |
| 871 | } | 879 | } |
| 872 | std.debug.assert(i == fields_without_codepage.len); | 880 | std.debug.assert(i == fields.len - 1); |
| 873 | break :blk @Type(.{ .@"struct" = .{ | 881 | break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs); |
| 874 | .layout = .auto, | ||
| 875 | .fields = &fields_without_codepage, | ||
| 876 | .decls = &.{}, | ||
| 877 | .is_tuple = false, | ||
| 878 | } }); | ||
| 879 | }; | 882 | }; |
| 880 | 883 | ||
| 881 | fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usize, end_index: usize) usize { | 884 | fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usize, end_index: usize) usize { |
lib/compiler/test_runner.zig+1-1| ... | @@ -298,7 +298,7 @@ fn mainTerminal() void { | ... | @@ -298,7 +298,7 @@ fn mainTerminal() void { |
| 298 | 298 | ||
| 299 | pub fn log( | 299 | pub fn log( |
| 300 | comptime message_level: std.log.Level, | 300 | comptime message_level: std.log.Level, |
| 301 | comptime scope: @Type(.enum_literal), | 301 | comptime scope: @EnumLiteral(), |
| 302 | comptime format: []const u8, | 302 | comptime format: []const u8, |
| 303 | args: anytype, | 303 | args: anytype, |
| 304 | ) void { | 304 | ) void { |
lib/compiler_rt/common.zig+1-4| ... | @@ -290,10 +290,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn | ... | @@ -290,10 +290,7 @@ pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeIn |
| 290 | pub inline fn fneg(a: anytype) @TypeOf(a) { | 290 | pub inline fn fneg(a: anytype) @TypeOf(a) { |
| 291 | const F = @TypeOf(a); | 291 | const F = @TypeOf(a); |
| 292 | const bits = @typeInfo(F).float.bits; | 292 | const bits = @typeInfo(F).float.bits; |
| 293 | const U = @Type(.{ .int = .{ | 293 | const U = @Int(.unsigned, bits); |
| 294 | .signedness = .unsigned, | ||
| 295 | .bits = bits, | ||
| 296 | } }); | ||
| 297 | const sign_bit_mask = @as(U, 1) << (bits - 1); | 294 | const sign_bit_mask = @as(U, 1) << (bits - 1); |
| 298 | const negated = @as(U, @bitCast(a)) ^ sign_bit_mask; | 295 | const negated = @as(U, @bitCast(a)) ^ sign_bit_mask; |
| 299 | return @bitCast(negated); | 296 | return @bitCast(negated); |
lib/compiler_rt/float_from_int.zig+5-5| ... | @@ -66,17 +66,17 @@ pub inline fn floatFromBigInt(comptime T: type, comptime signedness: std.builtin | ... | @@ -66,17 +66,17 @@ pub inline fn floatFromBigInt(comptime T: type, comptime signedness: std.builtin |
| 66 | switch (x.len) { | 66 | switch (x.len) { |
| 67 | 0 => return 0, | 67 | 0 => return 0, |
| 68 | inline 1...4 => |limbs_len| return @floatFromInt(@as( | 68 | inline 1...4 => |limbs_len| return @floatFromInt(@as( |
| 69 | @Type(.{ .int = .{ .signedness = signedness, .bits = 32 * limbs_len } }), | 69 | @Int(signedness, 32 * limbs_len), |
| 70 | @bitCast(x[0..limbs_len].*), | 70 | @bitCast(x[0..limbs_len].*), |
| 71 | )), | 71 | )), |
| 72 | else => {}, | 72 | else => {}, |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | // sign implicit fraction round sticky | 75 | // sign implicit fraction round sticky |
| 76 | const I = comptime @Type(.{ .int = .{ | 76 | const I = comptime @Int( |
| 77 | .signedness = signedness, | 77 | signedness, |
| 78 | .bits = @as(u16, @intFromBool(signedness == .signed)) + 1 + math.floatFractionalBits(T) + 1 + 1, | 78 | @as(u16, @intFromBool(signedness == .signed)) + 1 + math.floatFractionalBits(T) + 1 + 1, |
| 79 | } }); | 79 | ); |
| 80 | 80 | ||
| 81 | const clrsb = clrsb: { | 81 | const clrsb = clrsb: { |
| 82 | var clsb: usize = 0; | 82 | var clsb: usize = 0; |
lib/compiler_rt/int_from_float.zig+2-5| ... | @@ -56,7 +56,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul | ... | @@ -56,7 +56,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul |
| 56 | 0 => return, | 56 | 0 => return, |
| 57 | inline 1...4 => |limbs_len| { | 57 | inline 1...4 => |limbs_len| { |
| 58 | result[0..limbs_len].* = @bitCast(@as( | 58 | result[0..limbs_len].* = @bitCast(@as( |
| 59 | @Type(.{ .int = .{ .signedness = signedness, .bits = 32 * limbs_len } }), | 59 | @Int(signedness, 32 * limbs_len), |
| 60 | @intFromFloat(a), | 60 | @intFromFloat(a), |
| 61 | )); | 61 | )); |
| 62 | return; | 62 | return; |
| ... | @@ -66,10 +66,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul | ... | @@ -66,10 +66,7 @@ pub inline fn bigIntFromFloat(comptime signedness: std.builtin.Signedness, resul |
| 66 | 66 | ||
| 67 | // sign implicit fraction | 67 | // sign implicit fraction |
| 68 | const significand_bits = 1 + math.floatFractionalBits(@TypeOf(a)); | 68 | const significand_bits = 1 + math.floatFractionalBits(@TypeOf(a)); |
| 69 | const I = @Type(comptime .{ .int = .{ | 69 | const I = @Int(signedness, @as(u16, @intFromBool(signedness == .signed)) + significand_bits); |
| 70 | .signedness = signedness, | ||
| 71 | .bits = @as(u16, @intFromBool(signedness == .signed)) + significand_bits, | ||
| 72 | } }); | ||
| 73 | 70 | ||
| 74 | const parts = math.frexp(a); | 71 | const parts = math.frexp(a); |
| 75 | const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) + | 72 | const significand_bits_adjusted_to_handle_smin = @as(i32, significand_bits) + |
lib/compiler_rt/memcpy.zig+1-1| ... | @@ -159,7 +159,7 @@ inline fn copyFixedLength( | ... | @@ -159,7 +159,7 @@ inline fn copyFixedLength( |
| 159 | else if (len > @sizeOf(usize)) | 159 | else if (len > @sizeOf(usize)) |
| 160 | @Vector(len, u8) | 160 | @Vector(len, u8) |
| 161 | else | 161 | else |
| 162 | @Type(.{ .int = .{ .signedness = .unsigned, .bits = len * 8 } }); | 162 | @Int(.unsigned, len * 8); |
| 163 | 163 | ||
| 164 | const loop_count = @divExact(len, @sizeOf(T)); | 164 | const loop_count = @divExact(len, @sizeOf(T)); |
| 165 | 165 |
lib/docs/wasm/main.zig+1-1| ... | @@ -41,7 +41,7 @@ pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, addr: ?usize) noretu | ... | @@ -41,7 +41,7 @@ pub fn panic(msg: []const u8, st: ?*std.builtin.StackTrace, addr: ?usize) noretu |
| 41 | 41 | ||
| 42 | fn logFn( | 42 | fn logFn( |
| 43 | comptime message_level: log.Level, | 43 | comptime message_level: log.Level, |
| 44 | comptime scope: @TypeOf(.enum_literal), | 44 | comptime scope: @EnumLiteral(), |
| 45 | comptime format: []const u8, | 45 | comptime format: []const u8, |
| 46 | args: anytype, | 46 | args: anytype, |
| 47 | ) void { | 47 | ) void { |
lib/fuzzer.zig+1-1| ... | @@ -15,7 +15,7 @@ pub const std_options = std.Options{ | ... | @@ -15,7 +15,7 @@ pub const std_options = std.Options{ |
| 15 | 15 | ||
| 16 | fn logOverride( | 16 | fn logOverride( |
| 17 | comptime level: std.log.Level, | 17 | comptime level: std.log.Level, |
| 18 | comptime scope: @Type(.enum_literal), | 18 | comptime scope: @EnumLiteral(), |
| 19 | comptime format: []const u8, | 19 | comptime format: []const u8, |
| 20 | args: anytype, | 20 | args: anytype, |
| 21 | ) void { | 21 | ) void { |
lib/std/Build.zig+3-11| ... | @@ -416,7 +416,7 @@ fn createChildOnly( | ... | @@ -416,7 +416,7 @@ fn createChildOnly( |
| 416 | fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap { | 416 | fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap { |
| 417 | var map = UserInputOptionsMap.init(arena); | 417 | var map = UserInputOptionsMap.init(arena); |
| 418 | inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| { | 418 | inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| { |
| 419 | if (field.type == @Type(.null)) continue; | 419 | if (field.type == @TypeOf(null)) continue; |
| 420 | addUserInputOptionFromArg(arena, &map, field, field.type, @field(args, field.name)); | 420 | addUserInputOptionFromArg(arena, &map, field, field.type, @field(args, field.name)); |
| 421 | } | 421 | } |
| 422 | return map; | 422 | return map; |
| ... | @@ -526,16 +526,11 @@ fn addUserInputOptionFromArg( | ... | @@ -526,16 +526,11 @@ fn addUserInputOptionFromArg( |
| 526 | .pointer => |ptr_info| switch (ptr_info.size) { | 526 | .pointer => |ptr_info| switch (ptr_info.size) { |
| 527 | .one => switch (@typeInfo(ptr_info.child)) { | 527 | .one => switch (@typeInfo(ptr_info.child)) { |
| 528 | .array => |array_info| { | 528 | .array => |array_info| { |
| 529 | comptime var slice_info = ptr_info; | ||
| 530 | slice_info.size = .slice; | ||
| 531 | slice_info.is_const = true; | ||
| 532 | slice_info.child = array_info.child; | ||
| 533 | slice_info.sentinel_ptr = null; | ||
| 534 | addUserInputOptionFromArg( | 529 | addUserInputOptionFromArg( |
| 535 | arena, | 530 | arena, |
| 536 | map, | 531 | map, |
| 537 | field, | 532 | field, |
| 538 | @Type(.{ .pointer = slice_info }), | 533 | @Pointer(.slice, .{ .@"const" = true }, array_info.child, null), |
| 539 | maybe_value orelse null, | 534 | maybe_value orelse null, |
| 540 | ); | 535 | ); |
| 541 | return; | 536 | return; |
| ... | @@ -553,14 +548,11 @@ fn addUserInputOptionFromArg( | ... | @@ -553,14 +548,11 @@ fn addUserInputOptionFromArg( |
| 553 | }) catch @panic("OOM"); | 548 | }) catch @panic("OOM"); |
| 554 | }, | 549 | }, |
| 555 | else => { | 550 | else => { |
| 556 | comptime var slice_info = ptr_info; | ||
| 557 | slice_info.is_const = true; | ||
| 558 | slice_info.sentinel_ptr = null; | ||
| 559 | addUserInputOptionFromArg( | 551 | addUserInputOptionFromArg( |
| 560 | arena, | 552 | arena, |
| 561 | map, | 553 | map, |
| 562 | field, | 554 | field, |
| 563 | @Type(.{ .pointer = slice_info }), | 555 | @Pointer(ptr_info.size, .{ .@"const" = true }, ptr_info.child, null), |
| 564 | maybe_value orelse null, | 556 | maybe_value orelse null, |
| 565 | ); | 557 | ); |
| 566 | return; | 558 | return; |
lib/std/Io.zig+8-32| ... | @@ -528,23 +528,7 @@ pub fn Poller(comptime StreamEnum: type) type { | ... | @@ -528,23 +528,7 @@ pub fn Poller(comptime StreamEnum: type) type { |
| 528 | /// Given an enum, returns a struct with fields of that enum, each field | 528 | /// Given an enum, returns a struct with fields of that enum, each field |
| 529 | /// representing an I/O stream for polling. | 529 | /// representing an I/O stream for polling. |
| 530 | pub fn PollFiles(comptime StreamEnum: type) type { | 530 | pub fn PollFiles(comptime StreamEnum: type) type { |
| 531 | const enum_fields = @typeInfo(StreamEnum).@"enum".fields; | 531 | return @Struct(.auto, null, std.meta.fieldNames(StreamEnum), &@splat(std.fs.File), &@splat(.{})); |
| 532 | var struct_fields: [enum_fields.len]std.builtin.Type.StructField = undefined; | ||
| 533 | for (&struct_fields, enum_fields) |*struct_field, enum_field| { | ||
| 534 | struct_field.* = .{ | ||
| 535 | .name = enum_field.name, | ||
| 536 | .type = std.fs.File, | ||
| 537 | .default_value_ptr = null, | ||
| 538 | .is_comptime = false, | ||
| 539 | .alignment = @alignOf(std.fs.File), | ||
| 540 | }; | ||
| 541 | } | ||
| 542 | return @Type(.{ .@"struct" = .{ | ||
| 543 | .layout = .auto, | ||
| 544 | .fields = &struct_fields, | ||
| 545 | .decls = &.{}, | ||
| 546 | .is_tuple = false, | ||
| 547 | } }); | ||
| 548 | } | 532 | } |
| 549 | 533 | ||
| 550 | test { | 534 | test { |
| ... | @@ -1625,22 +1609,14 @@ pub fn sleep(io: Io, duration: Duration, clock: Clock) SleepError!void { | ... | @@ -1625,22 +1609,14 @@ pub fn sleep(io: Io, duration: Duration, clock: Clock) SleepError!void { |
| 1625 | /// fields, each field type the future's result. | 1609 | /// fields, each field type the future's result. |
| 1626 | pub fn SelectUnion(S: type) type { | 1610 | pub fn SelectUnion(S: type) type { |
| 1627 | const struct_fields = @typeInfo(S).@"struct".fields; | 1611 | const struct_fields = @typeInfo(S).@"struct".fields; |
| 1628 | var fields: [struct_fields.len]std.builtin.Type.UnionField = undefined; | 1612 | var names: [struct_fields.len][]const u8 = undefined; |
| 1629 | for (&fields, struct_fields) |*union_field, struct_field| { | 1613 | var types: [struct_fields.len]type = undefined; |
| 1630 | const F = @typeInfo(struct_field.type).pointer.child; | 1614 | for (struct_fields, &names, &types) |struct_field, *union_field_name, *UnionFieldType| { |
| 1631 | const Result = @TypeOf(@as(F, undefined).result); | 1615 | const FieldFuture = @typeInfo(struct_field.type).pointer.child; |
| 1632 | union_field.* = .{ | 1616 | union_field_name.* = struct_field.name; |
| 1633 | .name = struct_field.name, | 1617 | UnionFieldType.* = @FieldType(FieldFuture, "result"); |
| 1634 | .type = Result, | ||
| 1635 | .alignment = struct_field.alignment, | ||
| 1636 | }; | ||
| 1637 | } | 1618 | } |
| 1638 | return @Type(.{ .@"union" = .{ | 1619 | return @Union(.auto, std.meta.FieldEnum(S), &names, &types, &@splat(.{})); |
| 1639 | .layout = .auto, | ||
| 1640 | .tag_type = std.meta.FieldEnum(S), | ||
| 1641 | .fields = &fields, | ||
| 1642 | .decls = &.{}, | ||
| 1643 | } }); | ||
| 1644 | } | 1620 | } |
| 1645 | 1621 | ||
| 1646 | /// `s` is a struct with every field a `*Future(T)`, where `T` can be any type, | 1622 | /// `s` is a struct with every field a `*Future(T)`, where `T` can be any type, |
lib/std/Io/Reader.zig+5-8| ... | @@ -1273,20 +1273,17 @@ pub const TakeLeb128Error = Error || error{Overflow}; | ... | @@ -1273,20 +1273,17 @@ pub const TakeLeb128Error = Error || error{Overflow}; |
| 1273 | /// Read a single LEB128 value as type T, or `error.Overflow` if the value cannot fit. | 1273 | /// Read a single LEB128 value as type T, or `error.Overflow` if the value cannot fit. |
| 1274 | pub fn takeLeb128(r: *Reader, comptime Result: type) TakeLeb128Error!Result { | 1274 | pub fn takeLeb128(r: *Reader, comptime Result: type) TakeLeb128Error!Result { |
| 1275 | const result_info = @typeInfo(Result).int; | 1275 | const result_info = @typeInfo(Result).int; |
| 1276 | return std.math.cast(Result, try r.takeMultipleOf7Leb128(@Type(.{ .int = .{ | 1276 | return std.math.cast(Result, try r.takeMultipleOf7Leb128(@Int( |
| 1277 | .signedness = result_info.signedness, | 1277 | result_info.signedness, |
| 1278 | .bits = std.mem.alignForwardAnyAlign(u16, result_info.bits, 7), | 1278 | std.mem.alignForwardAnyAlign(u16, result_info.bits, 7), |
| 1279 | } }))) orelse error.Overflow; | 1279 | ))) orelse error.Overflow; |
| 1280 | } | 1280 | } |
| 1281 | 1281 | ||
| 1282 | fn takeMultipleOf7Leb128(r: *Reader, comptime Result: type) TakeLeb128Error!Result { | 1282 | fn takeMultipleOf7Leb128(r: *Reader, comptime Result: type) TakeLeb128Error!Result { |
| 1283 | const result_info = @typeInfo(Result).int; | 1283 | const result_info = @typeInfo(Result).int; |
| 1284 | comptime assert(result_info.bits % 7 == 0); | 1284 | comptime assert(result_info.bits % 7 == 0); |
| 1285 | var remaining_bits: std.math.Log2IntCeil(Result) = result_info.bits; | 1285 | var remaining_bits: std.math.Log2IntCeil(Result) = result_info.bits; |
| 1286 | const UnsignedResult = @Type(.{ .int = .{ | 1286 | const UnsignedResult = @Int(.unsigned, result_info.bits); |
| 1287 | .signedness = .unsigned, | ||
| 1288 | .bits = result_info.bits, | ||
| 1289 | } }); | ||
| 1290 | var result: UnsignedResult = 0; | 1287 | var result: UnsignedResult = 0; |
| 1291 | var fits = true; | 1288 | var fits = true; |
| 1292 | while (true) { | 1289 | while (true) { |
lib/std/Io/Writer.zig+10-10| ... | @@ -1890,7 +1890,7 @@ pub fn writeUleb128(w: *Writer, value: anytype) Error!void { | ... | @@ -1890,7 +1890,7 @@ pub fn writeUleb128(w: *Writer, value: anytype) Error!void { |
| 1890 | try w.writeLeb128(switch (@typeInfo(@TypeOf(value))) { | 1890 | try w.writeLeb128(switch (@typeInfo(@TypeOf(value))) { |
| 1891 | .comptime_int => @as(std.math.IntFittingRange(0, @abs(value)), value), | 1891 | .comptime_int => @as(std.math.IntFittingRange(0, @abs(value)), value), |
| 1892 | .int => |value_info| switch (value_info.signedness) { | 1892 | .int => |value_info| switch (value_info.signedness) { |
| 1893 | .signed => @as(@Type(.{ .int = .{ .signedness = .unsigned, .bits = value_info.bits -| 1 } }), @intCast(value)), | 1893 | .signed => @as(@Int(.unsigned, value_info.bits -| 1), @intCast(value)), |
| 1894 | .unsigned => value, | 1894 | .unsigned => value, |
| 1895 | }, | 1895 | }, |
| 1896 | else => comptime unreachable, | 1896 | else => comptime unreachable, |
| ... | @@ -1903,7 +1903,7 @@ pub fn writeSleb128(w: *Writer, value: anytype) Error!void { | ... | @@ -1903,7 +1903,7 @@ pub fn writeSleb128(w: *Writer, value: anytype) Error!void { |
| 1903 | .comptime_int => @as(std.math.IntFittingRange(@min(value, -1), @max(0, value)), value), | 1903 | .comptime_int => @as(std.math.IntFittingRange(@min(value, -1), @max(0, value)), value), |
| 1904 | .int => |value_info| switch (value_info.signedness) { | 1904 | .int => |value_info| switch (value_info.signedness) { |
| 1905 | .signed => value, | 1905 | .signed => value, |
| 1906 | .unsigned => @as(@Type(.{ .int = .{ .signedness = .signed, .bits = value_info.bits + 1 } }), value), | 1906 | .unsigned => @as(@Int(.signed, value_info.bits + 1), value), |
| 1907 | }, | 1907 | }, |
| 1908 | else => comptime unreachable, | 1908 | else => comptime unreachable, |
| 1909 | }); | 1909 | }); |
| ... | @@ -1912,10 +1912,10 @@ pub fn writeSleb128(w: *Writer, value: anytype) Error!void { | ... | @@ -1912,10 +1912,10 @@ pub fn writeSleb128(w: *Writer, value: anytype) Error!void { |
| 1912 | /// Write a single integer as LEB128 to the given writer. | 1912 | /// Write a single integer as LEB128 to the given writer. |
| 1913 | pub fn writeLeb128(w: *Writer, value: anytype) Error!void { | 1913 | pub fn writeLeb128(w: *Writer, value: anytype) Error!void { |
| 1914 | const value_info = @typeInfo(@TypeOf(value)).int; | 1914 | const value_info = @typeInfo(@TypeOf(value)).int; |
| 1915 | try w.writeMultipleOf7Leb128(@as(@Type(.{ .int = .{ | 1915 | try w.writeMultipleOf7Leb128(@as(@Int( |
| 1916 | .signedness = value_info.signedness, | 1916 | value_info.signedness, |
| 1917 | .bits = @max(std.mem.alignForwardAnyAlign(u16, value_info.bits, 7), 7), | 1917 | @max(std.mem.alignForwardAnyAlign(u16, value_info.bits, 7), 7), |
| 1918 | } }), value)); | 1918 | ), value)); |
| 1919 | } | 1919 | } |
| 1920 | 1920 | ||
| 1921 | fn writeMultipleOf7Leb128(w: *Writer, value: anytype) Error!void { | 1921 | fn writeMultipleOf7Leb128(w: *Writer, value: anytype) Error!void { |
| ... | @@ -1929,10 +1929,10 @@ fn writeMultipleOf7Leb128(w: *Writer, value: anytype) Error!void { | ... | @@ -1929,10 +1929,10 @@ fn writeMultipleOf7Leb128(w: *Writer, value: anytype) Error!void { |
| 1929 | .unsigned => remaining > std.math.maxInt(u7), | 1929 | .unsigned => remaining > std.math.maxInt(u7), |
| 1930 | }; | 1930 | }; |
| 1931 | byte.* = .{ | 1931 | byte.* = .{ |
| 1932 | .bits = @bitCast(@as(@Type(.{ .int = .{ | 1932 | .bits = @bitCast(@as( |
| 1933 | .signedness = value_info.signedness, | 1933 | @Int(value_info.signedness, 7), |
| 1934 | .bits = 7, | 1934 | @truncate(remaining), |
| 1935 | } }), @truncate(remaining))), | 1935 | )), |
| 1936 | .more = more, | 1936 | .more = more, |
| 1937 | }; | 1937 | }; |
| 1938 | if (value_info.bits > 7) remaining >>= 7; | 1938 | if (value_info.bits > 7) remaining >>= 7; |
lib/std/crypto/phc_encoding.zig+4-4| ... | @@ -94,12 +94,12 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult | ... | @@ -94,12 +94,12 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult |
| 94 | if (kvSplit(field)) |opt_version| { | 94 | if (kvSplit(field)) |opt_version| { |
| 95 | if (mem.eql(u8, opt_version.key, version_param_name)) { | 95 | if (mem.eql(u8, opt_version.key, version_param_name)) { |
| 96 | if (@hasField(HashResult, "alg_version")) { | 96 | if (@hasField(HashResult, "alg_version")) { |
| 97 | const value_type_info = switch (@typeInfo(@TypeOf(out.alg_version))) { | 97 | const ValueType = switch (@typeInfo(@TypeOf(out.alg_version))) { |
| 98 | .optional => |opt| @typeInfo(opt.child), | 98 | .optional => |opt| opt.child, |
| 99 | else => |t| t, | 99 | else => @TypeOf(out.alg_version), |
| 100 | }; | 100 | }; |
| 101 | out.alg_version = fmt.parseUnsigned( | 101 | out.alg_version = fmt.parseUnsigned( |
| 102 | @Type(value_type_info), | 102 | ValueType, |
| 103 | opt_version.value, | 103 | opt_version.value, |
| 104 | 10, | 104 | 10, |
| 105 | ) catch return Error.InvalidEncoding; | 105 | ) catch return Error.InvalidEncoding; |
lib/std/crypto/tls.zig+1-1| ... | @@ -606,7 +606,7 @@ pub fn array( | ... | @@ -606,7 +606,7 @@ pub fn array( |
| 606 | const elem_size = @divExact(@bitSizeOf(Elem), 8); | 606 | const elem_size = @divExact(@bitSizeOf(Elem), 8); |
| 607 | var arr: [len_size + elem_size * elems.len]u8 = undefined; | 607 | var arr: [len_size + elem_size * elems.len]u8 = undefined; |
| 608 | std.mem.writeInt(Len, arr[0..len_size], @intCast(elem_size * elems.len), .big); | 608 | std.mem.writeInt(Len, arr[0..len_size], @intCast(elem_size * elems.len), .big); |
| 609 | const ElemInt = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(Elem) } }); | 609 | const ElemInt = @Int(.unsigned, @bitSizeOf(Elem)); |
| 610 | for (0.., @as([elems.len]Elem, elems)) |index, elem| { | 610 | for (0.., @as([elems.len]Elem, elems)) |index, elem| { |
| 611 | std.mem.writeInt( | 611 | std.mem.writeInt( |
| 612 | ElemInt, | 612 | ElemInt, |
lib/std/enums.zig+11-29| ... | @@ -33,22 +33,8 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E { | ... | @@ -33,22 +33,8 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E { |
| 33 | /// default, which may be undefined. | 33 | /// default, which may be undefined. |
| 34 | pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type { | 34 | pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type { |
| 35 | @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion); | 35 | @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion); |
| 36 | var struct_fields: [@typeInfo(E).@"enum".fields.len]std.builtin.Type.StructField = undefined; | 36 | const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null; |
| 37 | for (&struct_fields, @typeInfo(E).@"enum".fields) |*struct_field, enum_field| { | 37 | return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr })); |
| 38 | struct_field.* = .{ | ||
| 39 | .name = enum_field.name, | ||
| 40 | .type = Data, | ||
| 41 | .default_value_ptr = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null, | ||
| 42 | .is_comptime = false, | ||
| 43 | .alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0, | ||
| 44 | }; | ||
| 45 | } | ||
| 46 | return @Type(.{ .@"struct" = .{ | ||
| 47 | .layout = .auto, | ||
| 48 | .fields = &struct_fields, | ||
| 49 | .decls = &.{}, | ||
| 50 | .is_tuple = false, | ||
| 51 | } }); | ||
| 52 | } | 38 | } |
| 53 | 39 | ||
| 54 | /// Looks up the supplied fields in the given enum type. | 40 | /// Looks up the supplied fields in the given enum type. |
| ... | @@ -1532,19 +1518,15 @@ test "EnumIndexer empty" { | ... | @@ -1532,19 +1518,15 @@ test "EnumIndexer empty" { |
| 1532 | test "EnumIndexer large dense unsorted" { | 1518 | test "EnumIndexer large dense unsorted" { |
| 1533 | @setEvalBranchQuota(500_000); // many `comptimePrint`s | 1519 | @setEvalBranchQuota(500_000); // many `comptimePrint`s |
| 1534 | // Make an enum with 500 fields with values in *descending* order. | 1520 | // Make an enum with 500 fields with values in *descending* order. |
| 1535 | const E = @Type(.{ .@"enum" = .{ | 1521 | const E = @Enum(u32, .exhaustive, names: { |
| 1536 | .tag_type = u32, | 1522 | var names: [500][]const u8 = undefined; |
| 1537 | .fields = comptime fields: { | 1523 | for (&names, 0..) |*name, i| name.* = std.fmt.comptimePrint("f{d}", .{i}); |
| 1538 | var fields: [500]EnumField = undefined; | 1524 | break :names &names; |
| 1539 | for (&fields, 0..) |*f, i| f.* = .{ | 1525 | }, vals: { |
| 1540 | .name = std.fmt.comptimePrint("f{d}", .{i}), | 1526 | var vals: [500]u32 = undefined; |
| 1541 | .value = 500 - i, | 1527 | for (&vals, 0..) |*val, i| val.* = 500 - i; |
| 1542 | }; | 1528 | break :vals &vals; |
| 1543 | break :fields &fields; | 1529 | }); |
| 1544 | }, | ||
| 1545 | .decls = &.{}, | ||
| 1546 | .is_exhaustive = true, | ||
| 1547 | } }); | ||
| 1548 | const Indexer = EnumIndexer(E); | 1530 | const Indexer = EnumIndexer(E); |
| 1549 | try testing.expectEqual(E.f0, Indexer.keyForIndex(499)); | 1531 | try testing.expectEqual(E.f0, Indexer.keyForIndex(499)); |
| 1550 | try testing.expectEqual(E.f499, Indexer.keyForIndex(0)); | 1532 | try testing.expectEqual(E.f499, Indexer.keyForIndex(0)); |
lib/std/fmt.zig+1-1| ... | @@ -279,7 +279,7 @@ pub fn Alt( | ... | @@ -279,7 +279,7 @@ pub fn Alt( |
| 279 | /// Helper for calling alternate format methods besides one named "format". | 279 | /// Helper for calling alternate format methods besides one named "format". |
| 280 | pub fn alt( | 280 | pub fn alt( |
| 281 | context: anytype, | 281 | context: anytype, |
| 282 | comptime func_name: @TypeOf(.enum_literal), | 282 | comptime func_name: @EnumLiteral(), |
| 283 | ) Alt(@TypeOf(context), @field(@TypeOf(context), @tagName(func_name))) { | 283 | ) Alt(@TypeOf(context), @field(@TypeOf(context), @tagName(func_name))) { |
| 284 | return .{ .data = context }; | 284 | return .{ .data = context }; |
| 285 | } | 285 | } |
lib/std/fmt/float.zig+2-2| ... | @@ -61,7 +61,7 @@ pub fn render(buf: []u8, value: anytype, options: Options) Error![]const u8 { | ... | @@ -61,7 +61,7 @@ pub fn render(buf: []u8, value: anytype, options: Options) Error![]const u8 { |
| 61 | 61 | ||
| 62 | const T = @TypeOf(v); | 62 | const T = @TypeOf(v); |
| 63 | comptime std.debug.assert(@typeInfo(T) == .float); | 63 | comptime std.debug.assert(@typeInfo(T) == .float); |
| 64 | const I = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } }); | 64 | const I = @Int(.unsigned, @bitSizeOf(T)); |
| 65 | 65 | ||
| 66 | const DT = if (@bitSizeOf(T) <= 64) u64 else u128; | 66 | const DT = if (@bitSizeOf(T) <= 64) u64 else u128; |
| 67 | const tables = switch (DT) { | 67 | const tables = switch (DT) { |
| ... | @@ -1516,7 +1516,7 @@ const FLOAT128_POW5_INV_ERRORS: [154]u64 = .{ | ... | @@ -1516,7 +1516,7 @@ const FLOAT128_POW5_INV_ERRORS: [154]u64 = .{ |
| 1516 | const builtin = @import("builtin"); | 1516 | const builtin = @import("builtin"); |
| 1517 | 1517 | ||
| 1518 | fn check(comptime T: type, value: T, comptime expected: []const u8) !void { | 1518 | fn check(comptime T: type, value: T, comptime expected: []const u8) !void { |
| 1519 | const I = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } }); | 1519 | const I = @Int(.unsigned, @bitSizeOf(T)); |
| 1520 | 1520 | ||
| 1521 | var buf: [6000]u8 = undefined; | 1521 | var buf: [6000]u8 = undefined; |
| 1522 | const value_bits: I = @bitCast(value); | 1522 | const value_bits: I = @bitCast(value); |
lib/std/hash.zig+1-1| ... | @@ -42,7 +42,7 @@ pub fn int(input: anytype) @TypeOf(input) { | ... | @@ -42,7 +42,7 @@ pub fn int(input: anytype) @TypeOf(input) { |
| 42 | const info = @typeInfo(@TypeOf(input)).int; | 42 | const info = @typeInfo(@TypeOf(input)).int; |
| 43 | const bits = info.bits; | 43 | const bits = info.bits; |
| 44 | // Convert input to unsigned integer (easier to deal with) | 44 | // Convert input to unsigned integer (easier to deal with) |
| 45 | const Uint = @Type(.{ .int = .{ .bits = bits, .signedness = .unsigned } }); | 45 | const Uint = @Int(.unsigned, bits); |
| 46 | const u_input: Uint = @bitCast(input); | 46 | const u_input: Uint = @bitCast(input); |
| 47 | if (bits > 256) @compileError("bit widths > 256 are unsupported, use std.hash.autoHash functionality."); | 47 | if (bits > 256) @compileError("bit widths > 256 are unsupported, use std.hash.autoHash functionality."); |
| 48 | // For bit widths that don't have a dedicated function, use a heuristic | 48 | // For bit widths that don't have a dedicated function, use a heuristic |
lib/std/hash/auto_hash.zig+1-4| ... | @@ -91,10 +91,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { | ... | @@ -91,10 +91,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 91 | // Help the optimizer see that hashing an int is easy by inlining! | 91 | // Help the optimizer see that hashing an int is easy by inlining! |
| 92 | // TODO Check if the situation is better after #561 is resolved. | 92 | // TODO Check if the situation is better after #561 is resolved. |
| 93 | .int => |int| switch (int.signedness) { | 93 | .int => |int| switch (int.signedness) { |
| 94 | .signed => hash(hasher, @as(@Type(.{ .int = .{ | 94 | .signed => hash(hasher, @as(@Int(.unsigned, int.bits), @bitCast(key)), strat), |
| 95 | .bits = int.bits, | ||
| 96 | .signedness = .unsigned, | ||
| 97 | } }), @bitCast(key)), strat), | ||
| 98 | .unsigned => { | 95 | .unsigned => { |
| 99 | if (std.meta.hasUniqueRepresentation(Key)) { | 96 | if (std.meta.hasUniqueRepresentation(Key)) { |
| 100 | @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key) }); | 97 | @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key) }); |
lib/std/log.zig+5-5| ... | @@ -57,13 +57,13 @@ pub const default_level: Level = switch (builtin.mode) { | ... | @@ -57,13 +57,13 @@ pub const default_level: Level = switch (builtin.mode) { |
| 57 | }; | 57 | }; |
| 58 | 58 | ||
| 59 | pub const ScopeLevel = struct { | 59 | pub const ScopeLevel = struct { |
| 60 | scope: @Type(.enum_literal), | 60 | scope: @EnumLiteral(), |
| 61 | level: Level, | 61 | level: Level, |
| 62 | }; | 62 | }; |
| 63 | 63 | ||
| 64 | fn log( | 64 | fn log( |
| 65 | comptime level: Level, | 65 | comptime level: Level, |
| 66 | comptime scope: @Type(.enum_literal), | 66 | comptime scope: @EnumLiteral(), |
| 67 | comptime format: []const u8, | 67 | comptime format: []const u8, |
| 68 | args: anytype, | 68 | args: anytype, |
| 69 | ) void { | 69 | ) void { |
| ... | @@ -73,7 +73,7 @@ fn log( | ... | @@ -73,7 +73,7 @@ fn log( |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | /// Determine if a specific log message level and scope combination are enabled for logging. | 75 | /// Determine if a specific log message level and scope combination are enabled for logging. |
| 76 | pub fn logEnabled(comptime level: Level, comptime scope: @Type(.enum_literal)) bool { | 76 | pub fn logEnabled(comptime level: Level, comptime scope: @EnumLiteral()) bool { |
| 77 | inline for (std.options.log_scope_levels) |scope_level| { | 77 | inline for (std.options.log_scope_levels) |scope_level| { |
| 78 | if (scope_level.scope == scope) return @intFromEnum(level) <= @intFromEnum(scope_level.level); | 78 | if (scope_level.scope == scope) return @intFromEnum(level) <= @intFromEnum(scope_level.level); |
| 79 | } | 79 | } |
| ... | @@ -87,7 +87,7 @@ pub fn logEnabled(comptime level: Level, comptime scope: @Type(.enum_literal)) b | ... | @@ -87,7 +87,7 @@ pub fn logEnabled(comptime level: Level, comptime scope: @Type(.enum_literal)) b |
| 87 | /// function returns. | 87 | /// function returns. |
| 88 | pub fn defaultLog( | 88 | pub fn defaultLog( |
| 89 | comptime level: Level, | 89 | comptime level: Level, |
| 90 | comptime scope: @Type(.enum_literal), | 90 | comptime scope: @EnumLiteral(), |
| 91 | comptime format: []const u8, | 91 | comptime format: []const u8, |
| 92 | args: anytype, | 92 | args: anytype, |
| 93 | ) void { | 93 | ) void { |
| ... | @@ -115,7 +115,7 @@ pub fn defaultLog( | ... | @@ -115,7 +115,7 @@ pub fn defaultLog( |
| 115 | 115 | ||
| 116 | /// Returns a scoped logging namespace that logs all messages using the scope | 116 | /// Returns a scoped logging namespace that logs all messages using the scope |
| 117 | /// provided here. | 117 | /// provided here. |
| 118 | pub fn scoped(comptime scope: @Type(.enum_literal)) type { | 118 | pub fn scoped(comptime scope: @EnumLiteral()) type { |
| 119 | return struct { | 119 | return struct { |
| 120 | /// Log an error message. This log level is intended to be used | 120 | /// Log an error message. This log level is intended to be used |
| 121 | /// when something has gone wrong. This might be recoverable or might | 121 | /// when something has gone wrong. This might be recoverable or might |
lib/std/math.zig+13-13| ... | @@ -450,12 +450,7 @@ pub fn wrap(x: anytype, r: anytype) @TypeOf(x) { | ... | @@ -450,12 +450,7 @@ pub fn wrap(x: anytype, r: anytype) @TypeOf(x) { |
| 450 | // in the rare usecase of r not being comptime_int or float, | 450 | // in the rare usecase of r not being comptime_int or float, |
| 451 | // take the penalty of having an intermediary type conversion, | 451 | // take the penalty of having an intermediary type conversion, |
| 452 | // otherwise the alternative is to unwind iteratively to avoid overflow | 452 | // otherwise the alternative is to unwind iteratively to avoid overflow |
| 453 | const R = comptime do: { | 453 | const R = @Int(.signed, info_r.int.bits + 1); |
| 454 | var info = info_r; | ||
| 455 | info.int.bits += 1; | ||
| 456 | info.int.signedness = .signed; | ||
| 457 | break :do @Type(info); | ||
| 458 | }; | ||
| 459 | const radius: if (info_r.int.signedness == .signed) @TypeOf(r) else R = r; | 454 | const radius: if (info_r.int.signedness == .signed) @TypeOf(r) else R = r; |
| 460 | return @intCast(@mod(x - radius, 2 * @as(R, r)) - r); // provably impossible to overflow | 455 | return @intCast(@mod(x - radius, 2 * @as(R, r)) - r); // provably impossible to overflow |
| 461 | }, | 456 | }, |
| ... | @@ -799,14 +794,14 @@ pub fn Log2IntCeil(comptime T: type) type { | ... | @@ -799,14 +794,14 @@ pub fn Log2IntCeil(comptime T: type) type { |
| 799 | pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) type { | 794 | pub fn IntFittingRange(comptime from: comptime_int, comptime to: comptime_int) type { |
| 800 | assert(from <= to); | 795 | assert(from <= to); |
| 801 | const signedness: std.builtin.Signedness = if (from < 0) .signed else .unsigned; | 796 | const signedness: std.builtin.Signedness = if (from < 0) .signed else .unsigned; |
| 802 | return @Type(.{ .int = .{ | 797 | return @Int( |
| 803 | .signedness = signedness, | 798 | signedness, |
| 804 | .bits = @as(u16, @intFromBool(signedness == .signed)) + | 799 | @as(u16, @intFromBool(signedness == .signed)) + |
| 805 | switch (if (from < 0) @max(@abs(from) - 1, to) else to) { | 800 | switch (if (from < 0) @max(@abs(from) - 1, to) else to) { |
| 806 | 0 => 0, | 801 | 0 => 0, |
| 807 | else => |pos_max| 1 + log2(pos_max), | 802 | else => |pos_max| 1 + log2(pos_max), |
| 808 | }, | 803 | }, |
| 809 | } }); | 804 | ); |
| 810 | } | 805 | } |
| 811 | 806 | ||
| 812 | test IntFittingRange { | 807 | test IntFittingRange { |
| ... | @@ -1107,9 +1102,14 @@ test cast { | ... | @@ -1107,9 +1102,14 @@ test cast { |
| 1107 | pub const AlignCastError = error{UnalignedMemory}; | 1102 | pub const AlignCastError = error{UnalignedMemory}; |
| 1108 | 1103 | ||
| 1109 | fn AlignCastResult(comptime alignment: Alignment, comptime Ptr: type) type { | 1104 | fn AlignCastResult(comptime alignment: Alignment, comptime Ptr: type) type { |
| 1110 | var ptr_info = @typeInfo(Ptr); | 1105 | const orig = @typeInfo(Ptr).pointer; |
| 1111 | ptr_info.pointer.alignment = alignment.toByteUnits(); | 1106 | return @Pointer(orig.size, .{ |
| 1112 | return @Type(ptr_info); | 1107 | .@"const" = orig.is_const, |
| 1108 | .@"volatile" = orig.is_volatile, | ||
| 1109 | .@"allowzero" = orig.is_allowzero, | ||
| 1110 | .@"align" = alignment.toByteUnits(), | ||
| 1111 | .@"addrspace" = orig.address_space, | ||
| 1112 | }, orig.child, orig.sentinel()); | ||
| 1113 | } | 1113 | } |
| 1114 | 1114 | ||
| 1115 | /// Align cast a pointer but return an error if it's the wrong alignment | 1115 | /// Align cast a pointer but return an error if it's the wrong alignment |
lib/std/math/big/int_test.zig+2-2| ... | @@ -2787,11 +2787,11 @@ test "bitNotWrap more than two limbs" { | ... | @@ -2787,11 +2787,11 @@ test "bitNotWrap more than two limbs" { |
| 2787 | const bits = @bitSizeOf(Limb) * 4 + 2; | 2787 | const bits = @bitSizeOf(Limb) * 4 + 2; |
| 2788 | 2788 | ||
| 2789 | try res.bitNotWrap(&a, .unsigned, bits); | 2789 | try res.bitNotWrap(&a, .unsigned, bits); |
| 2790 | const Unsigned = @Type(.{ .int = .{ .signedness = .unsigned, .bits = bits } }); | 2790 | const Unsigned = @Int(.unsigned, bits); |
| 2791 | try testing.expectEqual((try res.toInt(Unsigned)), ~@as(Unsigned, maxInt(Limb))); | 2791 | try testing.expectEqual((try res.toInt(Unsigned)), ~@as(Unsigned, maxInt(Limb))); |
| 2792 | 2792 | ||
| 2793 | try res.bitNotWrap(&a, .signed, bits); | 2793 | try res.bitNotWrap(&a, .signed, bits); |
| 2794 | const Signed = @Type(.{ .int = .{ .signedness = .signed, .bits = bits } }); | 2794 | const Signed = @Int(.signed, bits); |
| 2795 | try testing.expectEqual((try res.toInt(Signed)), ~@as(Signed, maxInt(Limb))); | 2795 | try testing.expectEqual((try res.toInt(Signed)), ~@as(Signed, maxInt(Limb))); |
| 2796 | } | 2796 | } |
| 2797 | 2797 |
lib/std/math/float.zig+8-26| ... | @@ -14,22 +14,10 @@ pub fn FloatRepr(comptime Float: type) type { | ... | @@ -14,22 +14,10 @@ pub fn FloatRepr(comptime Float: type) type { |
| 14 | exponent: BiasedExponent, | 14 | exponent: BiasedExponent, |
| 15 | sign: std.math.Sign, | 15 | sign: std.math.Sign, |
| 16 | 16 | ||
| 17 | pub const StoredMantissa = @Type(.{ .int = .{ | 17 | pub const StoredMantissa = @Int(.unsigned, floatMantissaBits(Float)); |
| 18 | .signedness = .unsigned, | 18 | pub const Mantissa = @Int(.unsigned, 1 + fractional_bits); |
| 19 | .bits = floatMantissaBits(Float), | 19 | pub const Exponent = @Int(.signed, exponent_bits); |
| 20 | } }); | 20 | pub const BiasedExponent = enum(@Int(.unsigned, exponent_bits)) { |
| 21 | pub const Mantissa = @Type(.{ .int = .{ | ||
| 22 | .signedness = .unsigned, | ||
| 23 | .bits = 1 + fractional_bits, | ||
| 24 | } }); | ||
| 25 | pub const Exponent = @Type(.{ .int = .{ | ||
| 26 | .signedness = .signed, | ||
| 27 | .bits = exponent_bits, | ||
| 28 | } }); | ||
| 29 | pub const BiasedExponent = enum(@Type(.{ .int = .{ | ||
| 30 | .signedness = .unsigned, | ||
| 31 | .bits = exponent_bits, | ||
| 32 | } })) { | ||
| 33 | denormal = 0, | 21 | denormal = 0, |
| 34 | min_normal = 1, | 22 | min_normal = 1, |
| 35 | zero = (1 << (exponent_bits - 1)) - 1, | 23 | zero = (1 << (exponent_bits - 1)) - 1, |
| ... | @@ -56,14 +44,8 @@ pub fn FloatRepr(comptime Float: type) type { | ... | @@ -56,14 +44,8 @@ pub fn FloatRepr(comptime Float: type) type { |
| 56 | fraction: Fraction, | 44 | fraction: Fraction, |
| 57 | exponent: Normalized.Exponent, | 45 | exponent: Normalized.Exponent, |
| 58 | 46 | ||
| 59 | pub const Fraction = @Type(.{ .int = .{ | 47 | pub const Fraction = @Int(.unsigned, fractional_bits); |
| 60 | .signedness = .unsigned, | 48 | pub const Exponent = @Int(.signed, 1 + exponent_bits); |
| 61 | .bits = fractional_bits, | ||
| 62 | } }); | ||
| 63 | pub const Exponent = @Type(.{ .int = .{ | ||
| 64 | .signedness = .signed, | ||
| 65 | .bits = 1 + exponent_bits, | ||
| 66 | } }); | ||
| 67 | 49 | ||
| 68 | /// This currently truncates denormal values, which needs to be fixed before this can be used to | 50 | /// This currently truncates denormal values, which needs to be fixed before this can be used to |
| 69 | /// produce a rounded value. | 51 | /// produce a rounded value. |
| ... | @@ -122,7 +104,7 @@ inline fn mantissaOne(comptime T: type) comptime_int { | ... | @@ -122,7 +104,7 @@ inline fn mantissaOne(comptime T: type) comptime_int { |
| 122 | 104 | ||
| 123 | /// Creates floating point type T from an unbiased exponent and raw mantissa. | 105 | /// Creates floating point type T from an unbiased exponent and raw mantissa. |
| 124 | inline fn reconstructFloat(comptime T: type, comptime exponent: comptime_int, comptime mantissa: comptime_int) T { | 106 | inline fn reconstructFloat(comptime T: type, comptime exponent: comptime_int, comptime mantissa: comptime_int) T { |
| 125 | const TBits = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } }); | 107 | const TBits = @Int(.unsigned, @bitSizeOf(T)); |
| 126 | const biased_exponent = @as(TBits, exponent + floatExponentMax(T)); | 108 | const biased_exponent = @as(TBits, exponent + floatExponentMax(T)); |
| 127 | return @as(T, @bitCast((biased_exponent << floatMantissaBits(T)) | @as(TBits, mantissa))); | 109 | return @as(T, @bitCast((biased_exponent << floatMantissaBits(T)) | @as(TBits, mantissa))); |
| 128 | } | 110 | } |
| ... | @@ -209,7 +191,7 @@ pub inline fn floatEps(comptime T: type) T { | ... | @@ -209,7 +191,7 @@ pub inline fn floatEps(comptime T: type) T { |
| 209 | pub inline fn floatEpsAt(comptime T: type, x: T) T { | 191 | pub inline fn floatEpsAt(comptime T: type, x: T) T { |
| 210 | switch (@typeInfo(T)) { | 192 | switch (@typeInfo(T)) { |
| 211 | .float => |F| { | 193 | .float => |F| { |
| 212 | const U: type = @Type(.{ .int = .{ .signedness = .unsigned, .bits = F.bits } }); | 194 | const U: type = @Int(.unsigned, F.bits); |
| 213 | const u: U = @bitCast(x); | 195 | const u: U = @bitCast(x); |
| 214 | const y: T = @bitCast(u ^ 1); | 196 | const y: T = @bitCast(u ^ 1); |
| 215 | return @abs(x - y); | 197 | return @abs(x - y); |
lib/std/math/log2.zig+1-4| ... | @@ -33,10 +33,7 @@ pub fn log2(x: anytype) @TypeOf(x) { | ... | @@ -33,10 +33,7 @@ pub fn log2(x: anytype) @TypeOf(x) { |
| 33 | return result; | 33 | return result; |
| 34 | }, | 34 | }, |
| 35 | .int => |int_info| math.log2_int(switch (int_info.signedness) { | 35 | .int => |int_info| math.log2_int(switch (int_info.signedness) { |
| 36 | .signed => @Type(.{ .int = .{ | 36 | .signed => @Int(.unsigned, int_info.bits -| 1), |
| 37 | .signedness = .unsigned, | ||
| 38 | .bits = int_info.bits -| 1, | ||
| 39 | } }), | ||
| 40 | .unsigned => T, | 37 | .unsigned => T, |
| 41 | }, @intCast(x)), | 38 | }, @intCast(x)), |
| 42 | else => @compileError("log2 not implemented for " ++ @typeName(T)), | 39 | else => @compileError("log2 not implemented for " ++ @typeName(T)), |
lib/std/math/log_int.zig+1-1| ... | @@ -65,7 +65,7 @@ test "log_int" { | ... | @@ -65,7 +65,7 @@ test "log_int" { |
| 65 | // Test all unsigned integers with 2, 3, ..., 64 bits. | 65 | // Test all unsigned integers with 2, 3, ..., 64 bits. |
| 66 | // We cannot test 0 or 1 bits since base must be > 1. | 66 | // We cannot test 0 or 1 bits since base must be > 1. |
| 67 | inline for (2..64 + 1) |bits| { | 67 | inline for (2..64 + 1) |bits| { |
| 68 | const T = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @intCast(bits) } }); | 68 | const T = @Int(.unsigned, @intCast(bits)); |
| 69 | 69 | ||
| 70 | // for base = 2, 3, ..., min(maxInt(T),1024) | 70 | // for base = 2, 3, ..., min(maxInt(T),1024) |
| 71 | var base: T = 1; | 71 | var base: T = 1; |
lib/std/math/signbit.zig+1-4| ... | @@ -6,10 +6,7 @@ const expect = std.testing.expect; | ... | @@ -6,10 +6,7 @@ const expect = std.testing.expect; |
| 6 | pub fn signbit(x: anytype) bool { | 6 | pub fn signbit(x: anytype) bool { |
| 7 | return switch (@typeInfo(@TypeOf(x))) { | 7 | return switch (@typeInfo(@TypeOf(x))) { |
| 8 | .int, .comptime_int => x, | 8 | .int, .comptime_int => x, |
| 9 | .float => |float| @as(@Type(.{ .int = .{ | 9 | .float => |float| @as(@Int(.signed, float.bits), @bitCast(x)), |
| 10 | .signedness = .signed, | ||
| 11 | .bits = float.bits, | ||
| 12 | } }), @bitCast(x)), | ||
| 13 | .comptime_float => @as(i128, @bitCast(@as(f128, x))), // any float type will do | 10 | .comptime_float => @as(i128, @bitCast(@as(f128, x))), // any float type will do |
| 14 | else => @compileError("std.math.signbit does not support " ++ @typeName(@TypeOf(x))), | 11 | else => @compileError("std.math.signbit does not support " ++ @typeName(@TypeOf(x))), |
| 15 | } < 0; | 12 | } < 0; |
lib/std/math/sqrt.zig+1-1| ... | @@ -80,7 +80,7 @@ test sqrt_int { | ... | @@ -80,7 +80,7 @@ test sqrt_int { |
| 80 | /// Returns the return type `sqrt` will return given an operand of type `T`. | 80 | /// Returns the return type `sqrt` will return given an operand of type `T`. |
| 81 | pub fn Sqrt(comptime T: type) type { | 81 | pub fn Sqrt(comptime T: type) type { |
| 82 | return switch (@typeInfo(T)) { | 82 | return switch (@typeInfo(T)) { |
| 83 | .int => |int| @Type(.{ .int = .{ .signedness = .unsigned, .bits = (int.bits + 1) / 2 } }), | 83 | .int => |int| @Int(.unsigned, (int.bits + 1) / 2), |
| 84 | else => T, | 84 | else => T, |
| 85 | }; | 85 | }; |
| 86 | } | 86 | } |
lib/std/mem.zig+57-106| ... | @@ -846,17 +846,18 @@ fn Span(comptime T: type) type { | ... | @@ -846,17 +846,18 @@ fn Span(comptime T: type) type { |
| 846 | return ?Span(optional_info.child); | 846 | return ?Span(optional_info.child); |
| 847 | }, | 847 | }, |
| 848 | .pointer => |ptr_info| { | 848 | .pointer => |ptr_info| { |
| 849 | var new_ptr_info = ptr_info; | 849 | const new_sentinel: ?ptr_info.child = switch (ptr_info.size) { |
| 850 | switch (ptr_info.size) { | ||
| 851 | .c => { | ||
| 852 | new_ptr_info.sentinel_ptr = &@as(ptr_info.child, 0); | ||
| 853 | new_ptr_info.is_allowzero = false; | ||
| 854 | }, | ||
| 855 | .many => if (ptr_info.sentinel() == null) @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), | ||
| 856 | .one, .slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), | 850 | .one, .slice => @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), |
| 857 | } | 851 | .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), |
| 858 | new_ptr_info.size = .slice; | 852 | .c => 0, |
| 859 | return @Type(.{ .pointer = new_ptr_info }); | 853 | }; |
| 854 | return @Pointer(.slice, .{ | ||
| 855 | .@"const" = ptr_info.is_const, | ||
| 856 | .@"volatile" = ptr_info.is_volatile, | ||
| 857 | .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c, | ||
| 858 | .@"align" = ptr_info.alignment, | ||
| 859 | .@"addrspace" = ptr_info.address_space, | ||
| 860 | }, ptr_info.child, new_sentinel); | ||
| 860 | }, | 861 | }, |
| 861 | else => {}, | 862 | else => {}, |
| 862 | } | 863 | } |
| ... | @@ -910,45 +911,18 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type { | ... | @@ -910,45 +911,18 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type { |
| 910 | return ?SliceTo(optional_info.child, end); | 911 | return ?SliceTo(optional_info.child, end); |
| 911 | }, | 912 | }, |
| 912 | .pointer => |ptr_info| { | 913 | .pointer => |ptr_info| { |
| 913 | var new_ptr_info = ptr_info; | 914 | const Elem = std.meta.Elem(T); |
| 914 | new_ptr_info.size = .slice; | 915 | const have_sentinel: bool = switch (ptr_info.size) { |
| 915 | switch (ptr_info.size) { | 916 | .one, .slice, .many => if (std.meta.sentinel(T)) |s| s == end else false, |
| 916 | .one => switch (@typeInfo(ptr_info.child)) { | 917 | .c => false, |
| 917 | .array => |array_info| { | 918 | }; |
| 918 | new_ptr_info.child = array_info.child; | 919 | return @Pointer(.slice, .{ |
| 919 | // The return type must only be sentinel terminated if we are guaranteed | 920 | .@"const" = ptr_info.is_const, |
| 920 | // to find the value searched for, which is only the case if it matches | 921 | .@"volatile" = ptr_info.is_volatile, |
| 921 | // the sentinel of the type passed. | 922 | .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c, |
| 922 | if (array_info.sentinel()) |s| { | 923 | .@"align" = ptr_info.alignment, |
| 923 | if (end == s) { | 924 | .@"addrspace" = ptr_info.address_space, |
| 924 | new_ptr_info.sentinel_ptr = &end; | 925 | }, Elem, if (have_sentinel) end else null); |
| 925 | } else { | ||
| 926 | new_ptr_info.sentinel_ptr = null; | ||
| 927 | } | ||
| 928 | } | ||
| 929 | }, | ||
| 930 | else => {}, | ||
| 931 | }, | ||
| 932 | .many, .slice => { | ||
| 933 | // The return type must only be sentinel terminated if we are guaranteed | ||
| 934 | // to find the value searched for, which is only the case if it matches | ||
| 935 | // the sentinel of the type passed. | ||
| 936 | if (ptr_info.sentinel()) |s| { | ||
| 937 | if (end == s) { | ||
| 938 | new_ptr_info.sentinel_ptr = &end; | ||
| 939 | } else { | ||
| 940 | new_ptr_info.sentinel_ptr = null; | ||
| 941 | } | ||
| 942 | } | ||
| 943 | }, | ||
| 944 | .c => { | ||
| 945 | new_ptr_info.sentinel_ptr = &end; | ||
| 946 | // C pointers are always allowzero, but we don't want the return type to be. | ||
| 947 | assert(new_ptr_info.is_allowzero); | ||
| 948 | new_ptr_info.is_allowzero = false; | ||
| 949 | }, | ||
| 950 | } | ||
| 951 | return @Type(.{ .pointer = new_ptr_info }); | ||
| 952 | }, | 926 | }, |
| 953 | else => {}, | 927 | else => {}, |
| 954 | } | 928 | } |
| ... | @@ -3951,38 +3925,25 @@ test reverse { | ... | @@ -3951,38 +3925,25 @@ test reverse { |
| 3951 | } | 3925 | } |
| 3952 | } | 3926 | } |
| 3953 | fn ReverseIterator(comptime T: type) type { | 3927 | fn ReverseIterator(comptime T: type) type { |
| 3954 | const Pointer = blk: { | 3928 | const ptr = switch (@typeInfo(T)) { |
| 3955 | switch (@typeInfo(T)) { | 3929 | .pointer => |ptr| ptr, |
| 3956 | .pointer => |ptr_info| switch (ptr_info.size) { | 3930 | else => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"), |
| 3957 | .one => switch (@typeInfo(ptr_info.child)) { | ||
| 3958 | .array => |array_info| { | ||
| 3959 | var new_ptr_info = ptr_info; | ||
| 3960 | new_ptr_info.size = .many; | ||
| 3961 | new_ptr_info.child = array_info.child; | ||
| 3962 | new_ptr_info.sentinel_ptr = array_info.sentinel_ptr; | ||
| 3963 | break :blk @Type(.{ .pointer = new_ptr_info }); | ||
| 3964 | }, | ||
| 3965 | else => {}, | ||
| 3966 | }, | ||
| 3967 | .slice => { | ||
| 3968 | var new_ptr_info = ptr_info; | ||
| 3969 | new_ptr_info.size = .many; | ||
| 3970 | break :blk @Type(.{ .pointer = new_ptr_info }); | ||
| 3971 | }, | ||
| 3972 | else => {}, | ||
| 3973 | }, | ||
| 3974 | else => {}, | ||
| 3975 | } | ||
| 3976 | @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"); | ||
| 3977 | }; | 3931 | }; |
| 3978 | const Element = std.meta.Elem(Pointer); | 3932 | switch (ptr.size) { |
| 3979 | const ElementPointer = @Type(.{ .pointer = ptr: { | 3933 | .slice => {}, |
| 3980 | var ptr = @typeInfo(Pointer).pointer; | 3934 | .one => if (@typeInfo(ptr.child) != .array) @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"), |
| 3981 | ptr.size = .one; | 3935 | .many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"), |
| 3982 | ptr.child = Element; | 3936 | } |
| 3983 | ptr.sentinel_ptr = null; | 3937 | const Element = std.meta.Elem(T); |
| 3984 | break :ptr ptr; | 3938 | const attrs: std.builtin.Type.Pointer.Attributes = .{ |
| 3985 | } }); | 3939 | .@"const" = ptr.is_const, |
| 3940 | .@"volatile" = ptr.is_volatile, | ||
| 3941 | .@"allowzero" = ptr.is_allowzero, | ||
| 3942 | .@"align" = ptr.alignment, | ||
| 3943 | .@"addrspace" = ptr.address_space, | ||
| 3944 | }; | ||
| 3945 | const Pointer = @Pointer(.many, attrs, Element, std.meta.sentinel(T)); | ||
| 3946 | const ElementPointer = @Pointer(.one, attrs, Element, null); | ||
| 3986 | return struct { | 3947 | return struct { |
| 3987 | ptr: Pointer, | 3948 | ptr: Pointer, |
| 3988 | index: usize, | 3949 | index: usize, |
| ... | @@ -4342,19 +4303,14 @@ fn CopyPtrAttrs( | ... | @@ -4342,19 +4303,14 @@ fn CopyPtrAttrs( |
| 4342 | comptime size: std.builtin.Type.Pointer.Size, | 4303 | comptime size: std.builtin.Type.Pointer.Size, |
| 4343 | comptime child: type, | 4304 | comptime child: type, |
| 4344 | ) type { | 4305 | ) type { |
| 4345 | const info = @typeInfo(source).pointer; | 4306 | const ptr = @typeInfo(source).pointer; |
| 4346 | return @Type(.{ | 4307 | return @Pointer(size, .{ |
| 4347 | .pointer = .{ | 4308 | .@"const" = ptr.is_const, |
| 4348 | .size = size, | 4309 | .@"volatile" = ptr.is_volatile, |
| 4349 | .is_const = info.is_const, | 4310 | .@"allowzero" = ptr.is_allowzero, |
| 4350 | .is_volatile = info.is_volatile, | 4311 | .@"align" = ptr.alignment, |
| 4351 | .is_allowzero = info.is_allowzero, | 4312 | .@"addrspace" = ptr.address_space, |
| 4352 | .alignment = info.alignment, | 4313 | }, child, null); |
| 4353 | .address_space = info.address_space, | ||
| 4354 | .child = child, | ||
| 4355 | .sentinel_ptr = null, | ||
| 4356 | }, | ||
| 4357 | }); | ||
| 4358 | } | 4314 | } |
| 4359 | 4315 | ||
| 4360 | fn AsBytesReturnType(comptime P: type) type { | 4316 | fn AsBytesReturnType(comptime P: type) type { |
| ... | @@ -4936,19 +4892,14 @@ test "freeing empty string with null-terminated sentinel" { | ... | @@ -4936,19 +4892,14 @@ test "freeing empty string with null-terminated sentinel" { |
| 4936 | /// Returns a slice with the given new alignment, | 4892 | /// Returns a slice with the given new alignment, |
| 4937 | /// all other pointer attributes copied from `AttributeSource`. | 4893 | /// all other pointer attributes copied from `AttributeSource`. |
| 4938 | fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type { | 4894 | fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type { |
| 4939 | const info = @typeInfo(AttributeSource).pointer; | 4895 | const ptr = @typeInfo(AttributeSource).pointer; |
| 4940 | return @Type(.{ | 4896 | return @Pointer(.slice, .{ |
| 4941 | .pointer = .{ | 4897 | .@"const" = ptr.is_const, |
| 4942 | .size = .slice, | 4898 | .@"volatile" = ptr.is_volatile, |
| 4943 | .is_const = info.is_const, | 4899 | .@"allowzero" = ptr.is_allowzero, |
| 4944 | .is_volatile = info.is_volatile, | 4900 | .@"align" = new_alignment, |
| 4945 | .is_allowzero = info.is_allowzero, | 4901 | .@"addrspace" = ptr.address_space, |
| 4946 | .alignment = new_alignment, | 4902 | }, ptr.child, null); |
| 4947 | .address_space = info.address_space, | ||
| 4948 | .child = info.child, | ||
| 4949 | .sentinel_ptr = null, | ||
| 4950 | }, | ||
| 4951 | }); | ||
| 4952 | } | 4903 | } |
| 4953 | 4904 | ||
| 4954 | /// Returns the largest slice in the given bytes that conforms to the new alignment, | 4905 | /// Returns the largest slice in the given bytes that conforms to the new alignment, |
lib/std/meta.zig+52-136| ... | @@ -171,58 +171,34 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { | ... | @@ -171,58 +171,34 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type { |
| 171 | switch (@typeInfo(T)) { | 171 | switch (@typeInfo(T)) { |
| 172 | .pointer => |info| switch (info.size) { | 172 | .pointer => |info| switch (info.size) { |
| 173 | .one => switch (@typeInfo(info.child)) { | 173 | .one => switch (@typeInfo(info.child)) { |
| 174 | .array => |array_info| return @Type(.{ | 174 | .array => |array_info| return @Pointer(.one, .{ |
| 175 | .pointer = .{ | 175 | .@"const" = info.is_const, |
| 176 | .size = info.size, | 176 | .@"volatile" = info.is_volatile, |
| 177 | .is_const = info.is_const, | 177 | .@"allowzero" = info.is_allowzero, |
| 178 | .is_volatile = info.is_volatile, | 178 | .@"align" = info.alignment, |
| 179 | .alignment = info.alignment, | 179 | .@"addrspace" = info.address_space, |
| 180 | .address_space = info.address_space, | 180 | }, [array_info.len:sentinel_val]array_info.child, null), |
| 181 | .child = @Type(.{ | ||
| 182 | .array = .{ | ||
| 183 | .len = array_info.len, | ||
| 184 | .child = array_info.child, | ||
| 185 | .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | ||
| 186 | }, | ||
| 187 | }), | ||
| 188 | .is_allowzero = info.is_allowzero, | ||
| 189 | .sentinel_ptr = info.sentinel_ptr, | ||
| 190 | }, | ||
| 191 | }), | ||
| 192 | else => {}, | 181 | else => {}, |
| 193 | }, | 182 | }, |
| 194 | .many, .slice => return @Type(.{ | 183 | .many, .slice => |size| return @Pointer(size, .{ |
| 195 | .pointer = .{ | 184 | .@"const" = info.is_const, |
| 196 | .size = info.size, | 185 | .@"volatile" = info.is_volatile, |
| 197 | .is_const = info.is_const, | 186 | .@"allowzero" = info.is_allowzero, |
| 198 | .is_volatile = info.is_volatile, | 187 | .@"align" = info.alignment, |
| 199 | .alignment = info.alignment, | 188 | .@"addrspace" = info.address_space, |
| 200 | .address_space = info.address_space, | 189 | }, info.child, sentinel_val), |
| 201 | .child = info.child, | ||
| 202 | .is_allowzero = info.is_allowzero, | ||
| 203 | .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | ||
| 204 | }, | ||
| 205 | }), | ||
| 206 | else => {}, | 190 | else => {}, |
| 207 | }, | 191 | }, |
| 208 | .optional => |info| switch (@typeInfo(info.child)) { | 192 | .optional => |info| switch (@typeInfo(info.child)) { |
| 209 | .pointer => |ptr_info| switch (ptr_info.size) { | 193 | .pointer => |ptr_info| switch (ptr_info.size) { |
| 210 | .many => return @Type(.{ | 194 | .many => return ?@Pointer(.many, .{ |
| 211 | .optional = .{ | 195 | .@"const" = ptr_info.is_const, |
| 212 | .child = @Type(.{ | 196 | .@"volatile" = ptr_info.is_volatile, |
| 213 | .pointer = .{ | 197 | .@"allowzero" = ptr_info.is_allowzero, |
| 214 | .size = ptr_info.size, | 198 | .@"align" = ptr_info.alignment, |
| 215 | .is_const = ptr_info.is_const, | 199 | .@"addrspace" = ptr_info.address_space, |
| 216 | .is_volatile = ptr_info.is_volatile, | 200 | .child = ptr_info.child, |
| 217 | .alignment = ptr_info.alignment, | 201 | }, ptr_info.child, sentinel_val), |
| 218 | .address_space = ptr_info.address_space, | ||
| 219 | .child = ptr_info.child, | ||
| 220 | .is_allowzero = ptr_info.is_allowzero, | ||
| 221 | .sentinel_ptr = @as(?*const anyopaque, @ptrCast(&sentinel_val)), | ||
| 222 | }, | ||
| 223 | }), | ||
| 224 | }, | ||
| 225 | }), | ||
| 226 | else => {}, | 202 | else => {}, |
| 227 | }, | 203 | }, |
| 228 | else => {}, | 204 | else => {}, |
| ... | @@ -487,46 +463,22 @@ test tags { | ... | @@ -487,46 +463,22 @@ test tags { |
| 487 | 463 | ||
| 488 | /// Returns an enum with a variant named after each field of `T`. | 464 | /// Returns an enum with a variant named after each field of `T`. |
| 489 | pub fn FieldEnum(comptime T: type) type { | 465 | pub fn FieldEnum(comptime T: type) type { |
| 490 | const field_infos = fields(T); | 466 | const field_names = fieldNames(T); |
| 491 | |||
| 492 | if (field_infos.len == 0) { | ||
| 493 | return @Type(.{ | ||
| 494 | .@"enum" = .{ | ||
| 495 | .tag_type = u0, | ||
| 496 | .fields = &.{}, | ||
| 497 | .decls = &.{}, | ||
| 498 | .is_exhaustive = true, | ||
| 499 | }, | ||
| 500 | }); | ||
| 501 | } | ||
| 502 | 467 | ||
| 503 | if (@typeInfo(T) == .@"union") { | 468 | switch (@typeInfo(T)) { |
| 504 | if (@typeInfo(T).@"union".tag_type) |tag_type| { | 469 | .@"union" => |@"union"| if (@"union".tag_type) |EnumTag| { |
| 505 | for (std.enums.values(tag_type), 0..) |v, i| { | 470 | for (std.enums.values(EnumTag), 0..) |v, i| { |
| 506 | if (@intFromEnum(v) != i) break; // enum values not consecutive | 471 | if (@intFromEnum(v) != i) break; // enum values not consecutive |
| 507 | if (!std.mem.eql(u8, @tagName(v), field_infos[i].name)) break; // fields out of order | 472 | if (!std.mem.eql(u8, @tagName(v), field_names[i])) break; // fields out of order |
| 508 | } else { | 473 | } else { |
| 509 | return tag_type; | 474 | return EnumTag; |
| 510 | } | 475 | } |
| 511 | } | 476 | }, |
| 477 | else => {}, | ||
| 512 | } | 478 | } |
| 513 | 479 | ||
| 514 | var enumFields: [field_infos.len]std.builtin.Type.EnumField = undefined; | 480 | const IntTag = std.math.IntFittingRange(0, field_names.len -| 1); |
| 515 | var decls = [_]std.builtin.Type.Declaration{}; | 481 | return @Enum(IntTag, .exhaustive, field_names, &std.simd.iota(IntTag, field_names.len)); |
| 516 | inline for (field_infos, 0..) |field, i| { | ||
| 517 | enumFields[i] = .{ | ||
| 518 | .name = field.name, | ||
| 519 | .value = i, | ||
| 520 | }; | ||
| 521 | } | ||
| 522 | return @Type(.{ | ||
| 523 | .@"enum" = .{ | ||
| 524 | .tag_type = std.math.IntFittingRange(0, field_infos.len - 1), | ||
| 525 | .fields = &enumFields, | ||
| 526 | .decls = &decls, | ||
| 527 | .is_exhaustive = true, | ||
| 528 | }, | ||
| 529 | }); | ||
| 530 | } | 482 | } |
| 531 | 483 | ||
| 532 | fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { | 484 | fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| ... | @@ -583,20 +535,11 @@ test FieldEnum { | ... | @@ -583,20 +535,11 @@ test FieldEnum { |
| 583 | } | 535 | } |
| 584 | 536 | ||
| 585 | pub fn DeclEnum(comptime T: type) type { | 537 | pub fn DeclEnum(comptime T: type) type { |
| 586 | const fieldInfos = std.meta.declarations(T); | 538 | const decls = declarations(T); |
| 587 | var enumDecls: [fieldInfos.len]std.builtin.Type.EnumField = undefined; | 539 | var names: [decls.len][]const u8 = undefined; |
| 588 | var decls = [_]std.builtin.Type.Declaration{}; | 540 | for (&names, decls) |*name, decl| name.* = decl.name; |
| 589 | inline for (fieldInfos, 0..) |field, i| { | 541 | const IntTag = std.math.IntFittingRange(0, decls.len -| 1); |
| 590 | enumDecls[i] = .{ .name = field.name, .value = i }; | 542 | return @Enum(IntTag, .exhaustive, &names, &std.simd.iota(IntTag, decls.len)); |
| 591 | } | ||
| 592 | return @Type(.{ | ||
| 593 | .@"enum" = .{ | ||
| 594 | .tag_type = std.math.IntFittingRange(0, if (fieldInfos.len == 0) 0 else fieldInfos.len - 1), | ||
| 595 | .fields = &enumDecls, | ||
| 596 | .decls = &decls, | ||
| 597 | .is_exhaustive = true, | ||
| 598 | }, | ||
| 599 | }); | ||
| 600 | } | 543 | } |
| 601 | 544 | ||
| 602 | test DeclEnum { | 545 | test DeclEnum { |
| ... | @@ -868,25 +811,26 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De | ... | @@ -868,25 +811,26 @@ pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const De |
| 868 | } | 811 | } |
| 869 | } | 812 | } |
| 870 | 813 | ||
| 814 | /// Deprecated: use @Int | ||
| 871 | pub fn Int(comptime signedness: std.builtin.Signedness, comptime bit_count: u16) type { | 815 | pub fn Int(comptime signedness: std.builtin.Signedness, comptime bit_count: u16) type { |
| 872 | return @Type(.{ | 816 | return @Int(signedness, bit_count); |
| 873 | .int = .{ | ||
| 874 | .signedness = signedness, | ||
| 875 | .bits = bit_count, | ||
| 876 | }, | ||
| 877 | }); | ||
| 878 | } | 817 | } |
| 879 | 818 | ||
| 880 | pub fn Float(comptime bit_count: u8) type { | 819 | pub fn Float(comptime bit_count: u8) type { |
| 881 | return @Type(.{ | 820 | return switch (bit_count) { |
| 882 | .float = .{ .bits = bit_count }, | 821 | 16 => f16, |
| 883 | }); | 822 | 32 => f32, |
| 823 | 64 => f64, | ||
| 824 | 80 => f80, | ||
| 825 | 128 => f128, | ||
| 826 | else => @compileError("invalid float bit count"), | ||
| 827 | }; | ||
| 884 | } | 828 | } |
| 885 | |||
| 886 | test Float { | 829 | test Float { |
| 887 | try testing.expectEqual(f16, Float(16)); | 830 | try testing.expectEqual(f16, Float(16)); |
| 888 | try testing.expectEqual(f32, Float(32)); | 831 | try testing.expectEqual(f32, Float(32)); |
| 889 | try testing.expectEqual(f64, Float(64)); | 832 | try testing.expectEqual(f64, Float(64)); |
| 833 | try testing.expectEqual(f80, Float(80)); | ||
| 890 | try testing.expectEqual(f128, Float(128)); | 834 | try testing.expectEqual(f128, Float(128)); |
| 891 | } | 835 | } |
| 892 | 836 | ||
| ... | @@ -912,42 +856,14 @@ pub fn ArgsTuple(comptime Function: type) type { | ... | @@ -912,42 +856,14 @@ pub fn ArgsTuple(comptime Function: type) type { |
| 912 | argument_field_list[i] = T; | 856 | argument_field_list[i] = T; |
| 913 | } | 857 | } |
| 914 | 858 | ||
| 915 | return CreateUniqueTuple(argument_field_list.len, argument_field_list); | 859 | return Tuple(&argument_field_list); |
| 916 | } | 860 | } |
| 917 | 861 | ||
| 918 | /// For a given anonymous list of types, returns a new tuple type | 862 | /// Deprecated; use `@Tuple` instead. |
| 919 | /// with those types as fields. | ||
| 920 | /// | 863 | /// |
| 921 | /// Examples: | 864 | /// To be removed after Zig 0.16.0 releases. |
| 922 | /// - `Tuple(&[_]type {})` ⇒ `tuple { }` | ||
| 923 | /// - `Tuple(&[_]type {f32})` ⇒ `tuple { f32 }` | ||
| 924 | /// - `Tuple(&[_]type {f32,u32})` ⇒ `tuple { f32, u32 }` | ||
| 925 | pub fn Tuple(comptime types: []const type) type { | 865 | pub fn Tuple(comptime types: []const type) type { |
| 926 | return CreateUniqueTuple(types.len, types[0..types.len].*); | 866 | return @Tuple(types); |
| 927 | } | ||
| 928 | |||
| 929 | fn CreateUniqueTuple(comptime N: comptime_int, comptime types: [N]type) type { | ||
| 930 | var tuple_fields: [types.len]std.builtin.Type.StructField = undefined; | ||
| 931 | inline for (types, 0..) |T, i| { | ||
| 932 | @setEvalBranchQuota(10_000); | ||
| 933 | var num_buf: [128]u8 = undefined; | ||
| 934 | tuple_fields[i] = .{ | ||
| 935 | .name = std.fmt.bufPrintSentinel(&num_buf, "{d}", .{i}, 0) catch unreachable, | ||
| 936 | .type = T, | ||
| 937 | .default_value_ptr = null, | ||
| 938 | .is_comptime = false, | ||
| 939 | .alignment = @alignOf(T), | ||
| 940 | }; | ||
| 941 | } | ||
| 942 | |||
| 943 | return @Type(.{ | ||
| 944 | .@"struct" = .{ | ||
| 945 | .is_tuple = true, | ||
| 946 | .layout = .auto, | ||
| 947 | .decls = &.{}, | ||
| 948 | .fields = &tuple_fields, | ||
| 949 | }, | ||
| 950 | }); | ||
| 951 | } | 867 | } |
| 952 | 868 | ||
| 953 | const TupleTester = struct { | 869 | const TupleTester = struct { |
lib/std/meta/trailer_flags.zig+9-17| ... | @@ -20,24 +20,16 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -20,24 +20,16 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 20 | 20 | ||
| 21 | pub const ActiveFields = std.enums.EnumFieldStruct(FieldEnum, bool, false); | 21 | pub const ActiveFields = std.enums.EnumFieldStruct(FieldEnum, bool, false); |
| 22 | pub const FieldValues = blk: { | 22 | pub const FieldValues = blk: { |
| 23 | var fields: [bit_count]Type.StructField = undefined; | 23 | var field_names: [bit_count][]const u8 = undefined; |
| 24 | for (@typeInfo(Fields).@"struct".fields, 0..) |struct_field, i| { | 24 | var field_types: [bit_count]type = undefined; |
| 25 | fields[i] = Type.StructField{ | 25 | var field_attrs: [bit_count]std.builtin.Type.StructField.Attributes = undefined; |
| 26 | .name = struct_field.name, | 26 | for (@typeInfo(Fields).@"struct".fields, &field_names, &field_types, &field_attrs) |field, *new_name, *NewType, *new_attrs| { |
| 27 | .type = ?struct_field.type, | 27 | new_name.* = field.name; |
| 28 | .default_value_ptr = &@as(?struct_field.type, null), | 28 | NewType.* = ?field.type; |
| 29 | .is_comptime = false, | 29 | const default: ?field.type = null; |
| 30 | .alignment = @alignOf(?struct_field.type), | 30 | new_attrs.* = .{ .default_value_ptr = &default }; |
| 31 | }; | ||
| 32 | } | 31 | } |
| 33 | break :blk @Type(.{ | 32 | break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs); |
| 34 | .@"struct" = .{ | ||
| 35 | .layout = .auto, | ||
| 36 | .fields = &fields, | ||
| 37 | .decls = &.{}, | ||
| 38 | .is_tuple = false, | ||
| 39 | }, | ||
| 40 | }); | ||
| 41 | }; | 33 | }; |
| 42 | 34 | ||
| 43 | pub const Self = @This(); | 35 | pub const Self = @This(); |
lib/std/multi_array_list.zig+26-37| ... | @@ -32,12 +32,17 @@ pub fn MultiArrayList(comptime T: type) type { | ... | @@ -32,12 +32,17 @@ pub fn MultiArrayList(comptime T: type) type { |
| 32 | const Elem = switch (@typeInfo(T)) { | 32 | const Elem = switch (@typeInfo(T)) { |
| 33 | .@"struct" => T, | 33 | .@"struct" => T, |
| 34 | .@"union" => |u| struct { | 34 | .@"union" => |u| struct { |
| 35 | pub const Bare = @Type(.{ .@"union" = .{ | 35 | pub const Bare = Bare: { |
| 36 | .layout = u.layout, | 36 | var field_names: [u.fields.len][]const u8 = undefined; |
| 37 | .tag_type = null, | 37 | var field_types: [u.fields.len]type = undefined; |
| 38 | .fields = u.fields, | 38 | var field_attrs: [u.fields.len]std.builtin.Type.UnionField.Attributes = undefined; |
| 39 | .decls = &.{}, | 39 | for (u.fields, &field_names, &field_types, &field_attrs) |field, *name, *Type, *attrs| { |
| 40 | } }); | 40 | name.* = field.name; |
| 41 | Type.* = field.type; | ||
| 42 | attrs.* = .{ .@"align" = field.alignment }; | ||
| 43 | } | ||
| 44 | break :Bare @Union(u.layout, null, &field_names, &field_types, &field_attrs); | ||
| 45 | }; | ||
| 41 | pub const Tag = | 46 | pub const Tag = |
| 42 | u.tag_type orelse @compileError("MultiArrayList does not support untagged unions"); | 47 | u.tag_type orelse @compileError("MultiArrayList does not support untagged unions"); |
| 43 | tags: Tag, | 48 | tags: Tag, |
| ... | @@ -609,20 +614,18 @@ pub fn MultiArrayList(comptime T: type) type { | ... | @@ -609,20 +614,18 @@ pub fn MultiArrayList(comptime T: type) type { |
| 609 | } | 614 | } |
| 610 | 615 | ||
| 611 | const Entry = entry: { | 616 | const Entry = entry: { |
| 612 | var entry_fields: [fields.len]std.builtin.Type.StructField = undefined; | 617 | var field_names: [fields.len][]const u8 = undefined; |
| 613 | for (&entry_fields, sizes.fields) |*entry_field, i| entry_field.* = .{ | 618 | var field_types: [fields.len]type = undefined; |
| 614 | .name = fields[i].name ++ "_ptr", | 619 | var field_attrs: [fields.len]std.builtin.Type.StructField.Attributes = undefined; |
| 615 | .type = *fields[i].type, | 620 | for (sizes.fields, &field_names, &field_types, &field_attrs) |i, *name, *Type, *attrs| { |
| 616 | .default_value_ptr = null, | 621 | name.* = fields[i].name ++ "_ptr"; |
| 617 | .is_comptime = fields[i].is_comptime, | 622 | Type.* = *fields[i].type; |
| 618 | .alignment = fields[i].alignment, | 623 | attrs.* = .{ |
| 619 | }; | 624 | .@"comptime" = fields[i].is_comptime, |
| 620 | break :entry @Type(.{ .@"struct" = .{ | 625 | .@"align" = fields[i].alignment, |
| 621 | .layout = .@"extern", | 626 | }; |
| 622 | .fields = &entry_fields, | 627 | } |
| 623 | .decls = &.{}, | 628 | break :entry @Struct(.@"extern", null, &field_names, &field_types, &field_attrs); |
| 624 | .is_tuple = false, | ||
| 625 | } }); | ||
| 626 | }; | 629 | }; |
| 627 | /// This function is used in the debugger pretty formatters in tools/ to fetch the | 630 | /// This function is used in the debugger pretty formatters in tools/ to fetch the |
| 628 | /// child field order and entry type to facilitate fancy debug printing for this type. | 631 | /// child field order and entry type to facilitate fancy debug printing for this type. |
| ... | @@ -1023,23 +1026,9 @@ test "struct with many fields" { | ... | @@ -1023,23 +1026,9 @@ test "struct with many fields" { |
| 1023 | const ManyFields = struct { | 1026 | const ManyFields = struct { |
| 1024 | fn Type(count: comptime_int) type { | 1027 | fn Type(count: comptime_int) type { |
| 1025 | @setEvalBranchQuota(50000); | 1028 | @setEvalBranchQuota(50000); |
| 1026 | var fields: [count]std.builtin.Type.StructField = undefined; | 1029 | var field_names: [count][]const u8 = undefined; |
| 1027 | for (0..count) |i| { | 1030 | for (&field_names, 0..) |*n, i| n.* = std.fmt.comptimePrint("a{d}", .{i}); |
| 1028 | fields[i] = .{ | 1031 | return @Struct(.@"extern", null, &field_names, &@splat(u32), &@splat(.{})); |
| 1029 | .name = std.fmt.comptimePrint("a{}", .{i}), | ||
| 1030 | .type = u32, | ||
| 1031 | .default_value_ptr = null, | ||
| 1032 | .is_comptime = false, | ||
| 1033 | .alignment = @alignOf(u32), | ||
| 1034 | }; | ||
| 1035 | } | ||
| 1036 | const info: std.builtin.Type = .{ .@"struct" = .{ | ||
| 1037 | .layout = .auto, | ||
| 1038 | .fields = &fields, | ||
| 1039 | .decls = &.{}, | ||
| 1040 | .is_tuple = false, | ||
| 1041 | } }; | ||
| 1042 | return @Type(info); | ||
| 1043 | } | 1032 | } |
| 1044 | 1033 | ||
| 1045 | fn doTest(ally: std.mem.Allocator, count: comptime_int) !void { | 1034 | fn doTest(ally: std.mem.Allocator, count: comptime_int) !void { |
lib/std/std.zig+1-1| ... | @@ -124,7 +124,7 @@ pub const Options = struct { | ... | @@ -124,7 +124,7 @@ pub const Options = struct { |
| 124 | 124 | ||
| 125 | logFn: fn ( | 125 | logFn: fn ( |
| 126 | comptime message_level: log.Level, | 126 | comptime message_level: log.Level, |
| 127 | comptime scope: @TypeOf(.enum_literal), | 127 | comptime scope: @EnumLiteral(), |
| 128 | comptime format: []const u8, | 128 | comptime format: []const u8, |
| 129 | args: anytype, | 129 | args: anytype, |
| 130 | ) void = log.defaultLog, | 130 | ) void = log.defaultLog, |
lib/std/zig/c_translation/helpers.zig+10-18| ... | @@ -81,23 +81,15 @@ fn ToUnsigned(comptime T: type) type { | ... | @@ -81,23 +81,15 @@ fn ToUnsigned(comptime T: type) type { |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | /// Constructs a [*c] pointer with the const and volatile annotations | 83 | /// Constructs a [*c] pointer with the const and volatile annotations |
| 84 | /// from SelfType for pointing to a C flexible array of ElementType. | 84 | /// from Self for pointing to a C flexible array of Element. |
| 85 | pub fn FlexibleArrayType(comptime SelfType: type, comptime ElementType: type) type { | 85 | pub fn FlexibleArrayType(comptime Self: type, comptime Element: type) type { |
| 86 | switch (@typeInfo(SelfType)) { | 86 | return switch (@typeInfo(Self)) { |
| 87 | .pointer => |ptr| { | 87 | .pointer => |ptr| @Pointer(.c, .{ |
| 88 | return @Type(.{ .pointer = .{ | 88 | .@"const" = ptr.is_const, |
| 89 | .size = .c, | 89 | .@"volatile" = ptr.is_volatile, |
| 90 | .is_const = ptr.is_const, | 90 | }, Element, null), |
| 91 | .is_volatile = ptr.is_volatile, | 91 | else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(Self)), |
| 92 | .alignment = @alignOf(ElementType), | 92 | }; |
| 93 | .address_space = .generic, | ||
| 94 | .child = ElementType, | ||
| 95 | .is_allowzero = true, | ||
| 96 | .sentinel_ptr = null, | ||
| 97 | } }); | ||
| 98 | }, | ||
| 99 | else => |info| @compileError("Invalid self type \"" ++ @tagName(info) ++ "\" for flexible array getter: " ++ @typeName(SelfType)), | ||
| 100 | } | ||
| 101 | } | 93 | } |
| 102 | 94 | ||
| 103 | /// Promote the type of an integer literal until it fits as C would. | 95 | /// Promote the type of an integer literal until it fits as C would. |
| ... | @@ -219,7 +211,7 @@ fn castInt(comptime DestType: type, target: anytype) DestType { | ... | @@ -219,7 +211,7 @@ fn castInt(comptime DestType: type, target: anytype) DestType { |
| 219 | const dest = @typeInfo(DestType).int; | 211 | const dest = @typeInfo(DestType).int; |
| 220 | const source = @typeInfo(@TypeOf(target)).int; | 212 | const source = @typeInfo(@TypeOf(target)).int; |
| 221 | 213 | ||
| 222 | const Int = @Type(.{ .int = .{ .bits = dest.bits, .signedness = source.signedness } }); | 214 | const Int = @Int(source.signedness, dest.bits); |
| 223 | 215 | ||
| 224 | if (dest.bits < source.bits) | 216 | if (dest.bits < source.bits) |
| 225 | return @as(DestType, @bitCast(@as(Int, @truncate(target)))) | 217 | return @as(DestType, @bitCast(@as(Int, @truncate(target)))) |
lib/std/zig/llvm/Builder.zig+9-30| ... | @@ -8614,39 +8614,18 @@ pub const Metadata = packed struct(u32) { | ... | @@ -8614,39 +8614,18 @@ pub const Metadata = packed struct(u32) { |
| 8614 | nodes: anytype, | 8614 | nodes: anytype, |
| 8615 | w: *Writer, | 8615 | w: *Writer, |
| 8616 | ) !void { | 8616 | ) !void { |
| 8617 | comptime var fmt_str: []const u8 = ""; | ||
| 8618 | const names = comptime std.meta.fieldNames(@TypeOf(nodes)); | 8617 | const names = comptime std.meta.fieldNames(@TypeOf(nodes)); |
| 8619 | comptime var fields: [2 + names.len]std.builtin.Type.StructField = undefined; | 8618 | |
| 8620 | inline for (fields[0..2], .{ "distinct", "node" }) |*field, name| { | 8619 | comptime var fmt_str: []const u8 = "{[distinct]s}{[node]s}("; |
| 8621 | fmt_str = fmt_str ++ "{[" ++ name ++ "]s}"; | 8620 | inline for (names) |name| fmt_str = fmt_str ++ "{[" ++ name ++ "]f}"; |
| 8622 | field.* = .{ | ||
| 8623 | .name = name, | ||
| 8624 | .type = []const u8, | ||
| 8625 | .default_value_ptr = null, | ||
| 8626 | .is_comptime = false, | ||
| 8627 | .alignment = @alignOf([]const u8), | ||
| 8628 | }; | ||
| 8629 | } | ||
| 8630 | fmt_str = fmt_str ++ "("; | ||
| 8631 | inline for (fields[2..], names) |*field, name| { | ||
| 8632 | fmt_str = fmt_str ++ "{[" ++ name ++ "]f}"; | ||
| 8633 | const T = std.fmt.Alt(FormatData, format); | ||
| 8634 | field.* = .{ | ||
| 8635 | .name = name, | ||
| 8636 | .type = T, | ||
| 8637 | .default_value_ptr = null, | ||
| 8638 | .is_comptime = false, | ||
| 8639 | .alignment = @alignOf(T), | ||
| 8640 | }; | ||
| 8641 | } | ||
| 8642 | fmt_str = fmt_str ++ ")\n"; | 8621 | fmt_str = fmt_str ++ ")\n"; |
| 8643 | 8622 | ||
| 8644 | var fmt_args: @Type(.{ .@"struct" = .{ | 8623 | const field_names = @as([]const []const u8, &.{ "distinct", "node" }) ++ names; |
| 8645 | .layout = .auto, | 8624 | comptime var field_types: [2 + names.len]type = undefined; |
| 8646 | .fields = &fields, | 8625 | @memset(field_types[0..2], []const u8); |
| 8647 | .decls = &.{}, | 8626 | @memset(field_types[2..], std.fmt.Alt(FormatData, format)); |
| 8648 | .is_tuple = false, | 8627 | |
| 8649 | } }) = undefined; | 8628 | var fmt_args: @Struct(.auto, null, field_names, &field_types, &@splat(.{})) = undefined; |
| 8650 | fmt_args.distinct = @tagName(distinct); | 8629 | fmt_args.distinct = @tagName(distinct); |
| 8651 | fmt_args.node = @tagName(node); | 8630 | fmt_args.node = @tagName(node); |
| 8652 | inline for (names) |name| @field(fmt_args, name) = try formatter.fmt( | 8631 | inline for (names) |name| @field(fmt_args, name) = try formatter.fmt( |
src/InternPool.zig+20-41| ... | @@ -1153,23 +1153,17 @@ const Local = struct { | ... | @@ -1153,23 +1153,17 @@ const Local = struct { |
| 1153 | fn PtrArrayElem(comptime len: usize) type { | 1153 | fn PtrArrayElem(comptime len: usize) type { |
| 1154 | const elem_info = @typeInfo(Elem).@"struct"; | 1154 | const elem_info = @typeInfo(Elem).@"struct"; |
| 1155 | const elem_fields = elem_info.fields; | 1155 | const elem_fields = elem_info.fields; |
| 1156 | var new_fields: [elem_fields.len]std.builtin.Type.StructField = undefined; | 1156 | var new_names: [elem_fields.len][]const u8 = undefined; |
| 1157 | for (&new_fields, elem_fields) |*new_field, elem_field| { | 1157 | var new_types: [elem_fields.len]type = undefined; |
| 1158 | const T = *[len]elem_field.type; | 1158 | for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| { |
| 1159 | new_field.* = .{ | 1159 | new_name.* = elem_field.name; |
| 1160 | .name = elem_field.name, | 1160 | NewType.* = *[len]elem_field.type; |
| 1161 | .type = T, | 1161 | } |
| 1162 | .default_value_ptr = null, | 1162 | if (elem_info.is_tuple) { |
| 1163 | .is_comptime = false, | 1163 | return @Tuple(&new_types); |
| 1164 | .alignment = @alignOf(T), | 1164 | } else { |
| 1165 | }; | 1165 | return @Struct(.auto, null, &new_names, &new_types, &@splat(.{})); |
| 1166 | } | 1166 | } |
| 1167 | return @Type(.{ .@"struct" = .{ | ||
| 1168 | .layout = .auto, | ||
| 1169 | .fields = &new_fields, | ||
| 1170 | .decls = &.{}, | ||
| 1171 | .is_tuple = elem_info.is_tuple, | ||
| 1172 | } }); | ||
| 1173 | } | 1167 | } |
| 1174 | fn PtrElem(comptime opts: struct { | 1168 | fn PtrElem(comptime opts: struct { |
| 1175 | size: std.builtin.Type.Pointer.Size, | 1169 | size: std.builtin.Type.Pointer.Size, |
| ... | @@ -1177,32 +1171,17 @@ const Local = struct { | ... | @@ -1177,32 +1171,17 @@ const Local = struct { |
| 1177 | }) type { | 1171 | }) type { |
| 1178 | const elem_info = @typeInfo(Elem).@"struct"; | 1172 | const elem_info = @typeInfo(Elem).@"struct"; |
| 1179 | const elem_fields = elem_info.fields; | 1173 | const elem_fields = elem_info.fields; |
| 1180 | var new_fields: [elem_fields.len]std.builtin.Type.StructField = undefined; | 1174 | var new_names: [elem_fields.len][]const u8 = undefined; |
| 1181 | for (&new_fields, elem_fields) |*new_field, elem_field| { | 1175 | var new_types: [elem_fields.len]type = undefined; |
| 1182 | const T = @Type(.{ .pointer = .{ | 1176 | for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| { |
| 1183 | .size = opts.size, | 1177 | new_name.* = elem_field.name; |
| 1184 | .is_const = opts.is_const, | 1178 | NewType.* = @Pointer(opts.size, .{ .@"const" = opts.is_const }, elem_field.type, null); |
| 1185 | .is_volatile = false, | 1179 | } |
| 1186 | .alignment = @alignOf(elem_field.type), | 1180 | if (elem_info.is_tuple) { |
| 1187 | .address_space = .generic, | 1181 | return @Tuple(&new_types); |
| 1188 | .child = elem_field.type, | 1182 | } else { |
| 1189 | .is_allowzero = false, | 1183 | return @Struct(.auto, null, &new_names, &new_types, &@splat(.{})); |
| 1190 | .sentinel_ptr = null, | ||
| 1191 | } }); | ||
| 1192 | new_field.* = .{ | ||
| 1193 | .name = elem_field.name, | ||
| 1194 | .type = T, | ||
| 1195 | .default_value_ptr = null, | ||
| 1196 | .is_comptime = false, | ||
| 1197 | .alignment = @alignOf(T), | ||
| 1198 | }; | ||
| 1199 | } | 1184 | } |
| 1200 | return @Type(.{ .@"struct" = .{ | ||
| 1201 | .layout = .auto, | ||
| 1202 | .fields = &new_fields, | ||
| 1203 | .decls = &.{}, | ||
| 1204 | .is_tuple = elem_info.is_tuple, | ||
| 1205 | } }); | ||
| 1206 | } | 1185 | } |
| 1207 | 1186 | ||
| 1208 | pub fn addOne(mutable: Mutable) Allocator.Error!PtrElem(.{ .size = .one }) { | 1187 | pub fn addOne(mutable: Mutable) Allocator.Error!PtrElem(.{ .size = .one }) { |
src/Sema.zig+2-2| ... | @@ -23904,7 +23904,7 @@ fn analyzeShuffle( | ... | @@ -23904,7 +23904,7 @@ fn analyzeShuffle( |
| 23904 | const b_src = block.builtinCallArgSrc(src_node, 2); | 23904 | const b_src = block.builtinCallArgSrc(src_node, 2); |
| 23905 | const mask_src = block.builtinCallArgSrc(src_node, 3); | 23905 | const mask_src = block.builtinCallArgSrc(src_node, 3); |
| 23906 | 23906 | ||
| 23907 | // If the type of `a` is `@Type(.undefined)`, i.e. the argument is untyped, | 23907 | // If the type of `a` is `@TypeOf(undefined)`, i.e. the argument is untyped, |
| 23908 | // this is 0, because it is an error to index into this vector. | 23908 | // this is 0, because it is an error to index into this vector. |
| 23909 | const a_len: u32 = switch (sema.typeOf(a_uncoerced).zigTypeTag(zcu)) { | 23909 | const a_len: u32 = switch (sema.typeOf(a_uncoerced).zigTypeTag(zcu)) { |
| 23910 | .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)), | 23910 | .array, .vector => @intCast(sema.typeOf(a_uncoerced).arrayLen(zcu)), |
| ... | @@ -23916,7 +23916,7 @@ fn analyzeShuffle( | ... | @@ -23916,7 +23916,7 @@ fn analyzeShuffle( |
| 23916 | const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() }); | 23916 | const a_ty = try pt.vectorType(.{ .len = a_len, .child = elem_ty.toIntern() }); |
| 23917 | const a_coerced = try sema.coerce(block, a_ty, a_uncoerced, a_src); | 23917 | const a_coerced = try sema.coerce(block, a_ty, a_uncoerced, a_src); |
| 23918 | 23918 | ||
| 23919 | // If the type of `b` is `@Type(.undefined)`, i.e. the argument is untyped, this is 0, because it is an error to index into this vector. | 23919 | // If the type of `b` is `@TypeOf(undefined)`, i.e. the argument is untyped, this is 0, because it is an error to index into this vector. |
| 23920 | const b_len: u32 = switch (sema.typeOf(b_uncoerced).zigTypeTag(zcu)) { | 23920 | const b_len: u32 = switch (sema.typeOf(b_uncoerced).zigTypeTag(zcu)) { |
| 23921 | .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)), | 23921 | .array, .vector => @intCast(sema.typeOf(b_uncoerced).arrayLen(zcu)), |
| 23922 | .undefined => 0, | 23922 | .undefined => 0, |
src/codegen/aarch64/Assemble.zig+11-21| ... | @@ -120,23 +120,13 @@ const matchers = matchers: { | ... | @@ -120,23 +120,13 @@ const matchers = matchers: { |
| 120 | ); | 120 | ); |
| 121 | var symbols: Symbols: { | 121 | var symbols: Symbols: { |
| 122 | const symbols = @typeInfo(@TypeOf(instruction.symbols)).@"struct".fields; | 122 | const symbols = @typeInfo(@TypeOf(instruction.symbols)).@"struct".fields; |
| 123 | var symbol_fields: [symbols.len]std.builtin.Type.StructField = undefined; | 123 | var field_names: [symbols.len][]const u8 = undefined; |
| 124 | for (&symbol_fields, symbols) |*symbol_field, symbol| { | 124 | var field_types: [symbols.len]type = undefined; |
| 125 | const Storage = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage(); | 125 | for (symbols, &field_names, &field_types) |symbol, *field_name, *FieldType| { |
| 126 | symbol_field.* = .{ | 126 | field_name.* = symbol.name; |
| 127 | .name = symbol.name, | 127 | FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage(); |
| 128 | .type = Storage, | ||
| 129 | .default_value_ptr = null, | ||
| 130 | .is_comptime = false, | ||
| 131 | .alignment = @alignOf(Storage), | ||
| 132 | }; | ||
| 133 | } | 128 | } |
| 134 | break :Symbols @Type(.{ .@"struct" = .{ | 129 | break :Symbols @Struct(.auto, null, &field_names, &field_types, &@splat(.{})); |
| 135 | .layout = .auto, | ||
| 136 | .fields = &symbol_fields, | ||
| 137 | .decls = &.{}, | ||
| 138 | .is_tuple = false, | ||
| 139 | } }); | ||
| 140 | } = undefined; | 130 | } = undefined; |
| 141 | const Symbol = std.meta.FieldEnum(@TypeOf(instruction.symbols)); | 131 | const Symbol = std.meta.FieldEnum(@TypeOf(instruction.symbols)); |
| 142 | comptime var unused_symbols: std.enums.EnumSet(Symbol) = .initFull(); | 132 | comptime var unused_symbols: std.enums.EnumSet(Symbol) = .initFull(); |
| ... | @@ -334,7 +324,7 @@ const SymbolSpec = union(enum) { | ... | @@ -334,7 +324,7 @@ const SymbolSpec = union(enum) { |
| 334 | .reg => aarch64.encoding.Register, | 324 | .reg => aarch64.encoding.Register, |
| 335 | .arrangement => aarch64.encoding.Register.Arrangement, | 325 | .arrangement => aarch64.encoding.Register.Arrangement, |
| 336 | .systemreg => aarch64.encoding.Register.System, | 326 | .systemreg => aarch64.encoding.Register.System, |
| 337 | .imm => |imm_spec| @Type(.{ .int = imm_spec.type }), | 327 | .imm => |imm_spec| @Int(imm_spec.type.signedness, imm_spec.type.bits), |
| 338 | .fimm => f16, | 328 | .fimm => f16, |
| 339 | .extend => Instruction.DataProcessingRegister.AddSubtractExtendedRegister.Option, | 329 | .extend => Instruction.DataProcessingRegister.AddSubtractExtendedRegister.Option, |
| 340 | .shift => Instruction.DataProcessingRegister.Shift.Op, | 330 | .shift => Instruction.DataProcessingRegister.Shift.Op, |
| ... | @@ -413,13 +403,13 @@ const SymbolSpec = union(enum) { | ... | @@ -413,13 +403,13 @@ const SymbolSpec = union(enum) { |
| 413 | return systemreg; | 403 | return systemreg; |
| 414 | }, | 404 | }, |
| 415 | .imm => |imm_spec| { | 405 | .imm => |imm_spec| { |
| 416 | const imm = std.fmt.parseInt(@Type(.{ .int = .{ | 406 | const imm = std.fmt.parseInt(@Int( |
| 417 | .signedness = imm_spec.type.signedness, | 407 | imm_spec.type.signedness, |
| 418 | .bits = switch (imm_spec.adjust) { | 408 | switch (imm_spec.adjust) { |
| 419 | .none, .neg_wrap => imm_spec.type.bits, | 409 | .none, .neg_wrap => imm_spec.type.bits, |
| 420 | .dec => imm_spec.type.bits + 1, | 410 | .dec => imm_spec.type.bits + 1, |
| 421 | }, | 411 | }, |
| 422 | } }), token, 0) catch { | 412 | ), token, 0) catch { |
| 423 | log.debug("invalid immediate: \"{f}\"", .{std.zig.fmtString(token)}); | 413 | log.debug("invalid immediate: \"{f}\"", .{std.zig.fmtString(token)}); |
| 424 | return null; | 414 | return null; |
| 425 | }; | 415 | }; |
src/codegen/aarch64/Select.zig+22-14| ... | @@ -8928,12 +8928,16 @@ pub const Value = struct { | ... | @@ -8928,12 +8928,16 @@ pub const Value = struct { |
| 8928 | constant: Constant, | 8928 | constant: Constant, |
| 8929 | 8929 | ||
| 8930 | pub const Tag = @typeInfo(Parent).@"union".tag_type.?; | 8930 | pub const Tag = @typeInfo(Parent).@"union".tag_type.?; |
| 8931 | pub const Payload = @Type(.{ .@"union" = .{ | 8931 | pub const Payload = Payload: { |
| 8932 | .layout = .auto, | 8932 | const fields = @typeInfo(Parent).@"union".fields; |
| 8933 | .tag_type = null, | 8933 | var types: [fields.len]type = undefined; |
| 8934 | .fields = @typeInfo(Parent).@"union".fields, | 8934 | var names: [fields.len][]const u8 = undefined; |
| 8935 | .decls = &.{}, | 8935 | for (fields, &types, &names) |f, *ty, *name| { |
| 8936 | } }); | 8936 | ty.* = f.type; |
| 8937 | name.* = f.name; | ||
| 8938 | } | ||
| 8939 | break :Payload @Union(.auto, null, &names, &types, &@splat(.{})); | ||
| 8940 | }; | ||
| 8937 | }; | 8941 | }; |
| 8938 | 8942 | ||
| 8939 | pub const Location = union(enum(u1)) { | 8943 | pub const Location = union(enum(u1)) { |
| ... | @@ -8949,12 +8953,16 @@ pub const Value = struct { | ... | @@ -8949,12 +8953,16 @@ pub const Value = struct { |
| 8949 | }, | 8953 | }, |
| 8950 | 8954 | ||
| 8951 | pub const Tag = @typeInfo(Location).@"union".tag_type.?; | 8955 | pub const Tag = @typeInfo(Location).@"union".tag_type.?; |
| 8952 | pub const Payload = @Type(.{ .@"union" = .{ | 8956 | pub const Payload = Payload: { |
| 8953 | .layout = .auto, | 8957 | const fields = @typeInfo(Location).@"union".fields; |
| 8954 | .tag_type = null, | 8958 | var types: [fields.len]type = undefined; |
| 8955 | .fields = @typeInfo(Location).@"union".fields, | 8959 | var names: [fields.len][]const u8 = undefined; |
| 8956 | .decls = &.{}, | 8960 | for (fields, &types, &names) |f, *ty, *name| { |
| 8957 | } }); | 8961 | ty.* = f.type; |
| 8962 | name.* = f.name; | ||
| 8963 | } | ||
| 8964 | break :Payload @Union(.auto, null, &names, &types, &@splat(.{})); | ||
| 8965 | }; | ||
| 8958 | }; | 8966 | }; |
| 8959 | 8967 | ||
| 8960 | pub const Indirect = packed struct(u32) { | 8968 | pub const Indirect = packed struct(u32) { |
| ... | @@ -11210,7 +11218,7 @@ pub const Value = struct { | ... | @@ -11210,7 +11218,7 @@ pub const Value = struct { |
| 11210 | .storage = .{ .u64 = switch (size) { | 11218 | .storage = .{ .u64 = switch (size) { |
| 11211 | else => unreachable, | 11219 | else => unreachable, |
| 11212 | inline 1...8 => |ct_size| std.mem.readInt( | 11220 | inline 1...8 => |ct_size| std.mem.readInt( |
| 11213 | @Type(.{ .int = .{ .signedness = .unsigned, .bits = 8 * ct_size } }), | 11221 | @Int(.unsigned, 8 * ct_size), |
| 11214 | buffer[@intCast(offset)..][0..ct_size], | 11222 | buffer[@intCast(offset)..][0..ct_size], |
| 11215 | isel.target.cpu.arch.endian(), | 11223 | isel.target.cpu.arch.endian(), |
| 11216 | ), | 11224 | ), |
| ... | @@ -11438,7 +11446,7 @@ fn writeKeyToMemory(isel: *Select, constant_key: InternPool.Key, buffer: []u8) e | ... | @@ -11438,7 +11446,7 @@ fn writeKeyToMemory(isel: *Select, constant_key: InternPool.Key, buffer: []u8) e |
| 11438 | switch (buffer.len) { | 11446 | switch (buffer.len) { |
| 11439 | else => unreachable, | 11447 | else => unreachable, |
| 11440 | inline 1...4 => |size| std.mem.writeInt( | 11448 | inline 1...4 => |size| std.mem.writeInt( |
| 11441 | @Type(.{ .int = .{ .signedness = .unsigned, .bits = 8 * size } }), | 11449 | @Int(.unsigned, 8 * size), |
| 11442 | buffer[0..size], | 11450 | buffer[0..size], |
| 11443 | @intCast(error_int), | 11451 | @intCast(error_int), |
| 11444 | isel.target.cpu.arch.endian(), | 11452 | isel.target.cpu.arch.endian(), |
src/codegen/x86_64/CodeGen.zig+5-7| ... | @@ -189867,9 +189867,7 @@ const Select = struct { | ... | @@ -189867,9 +189867,7 @@ const Select = struct { |
| 189867 | } | 189867 | } |
| 189868 | 189868 | ||
| 189869 | fn adjustedImm(op: Select.Operand, comptime SignedImm: type, s: *const Select) SignedImm { | 189869 | fn adjustedImm(op: Select.Operand, comptime SignedImm: type, s: *const Select) SignedImm { |
| 189870 | const UnsignedImm = @Type(.{ | 189870 | const UnsignedImm = @Int(.unsigned, @typeInfo(SignedImm).int.bits); |
| 189871 | .int = .{ .signedness = .unsigned, .bits = @typeInfo(SignedImm).int.bits }, | ||
| 189872 | }); | ||
| 189873 | const lhs: SignedImm = lhs: switch (op.flags.adjust.lhs) { | 189871 | const lhs: SignedImm = lhs: switch (op.flags.adjust.lhs) { |
| 189874 | .none => 0, | 189872 | .none => 0, |
| 189875 | .ptr_size => @divExact(s.cg.target.ptrBitWidth(), 8), | 189873 | .ptr_size => @divExact(s.cg.target.ptrBitWidth(), 8), |
| ... | @@ -189934,10 +189932,10 @@ const Select = struct { | ... | @@ -189934,10 +189932,10 @@ const Select = struct { |
| 189934 | const RefImm = switch (size) { | 189932 | const RefImm = switch (size) { |
| 189935 | else => comptime unreachable, | 189933 | else => comptime unreachable, |
| 189936 | .none => Imm, | 189934 | .none => Imm, |
| 189937 | .byte, .word, .dword, .qword => @Type(comptime .{ .int = .{ | 189935 | .byte, .word, .dword, .qword => @Int( |
| 189938 | .signedness = @typeInfo(Imm).int.signedness, | 189936 | @typeInfo(Imm).int.signedness, |
| 189939 | .bits = size.bitSize(undefined), | 189937 | size.bitSize(undefined), |
| 189940 | } }), | 189938 | ), |
| 189941 | }; | 189939 | }; |
| 189942 | break :lhs @bitCast(@as(Imm, @intCast(@as(RefImm, switch (adjust) { | 189940 | break :lhs @bitCast(@as(Imm, @intCast(@as(RefImm, switch (adjust) { |
| 189943 | else => comptime unreachable, | 189941 | else => comptime unreachable, |
src/codegen/x86_64/Emit.zig+1-1| ... | @@ -708,7 +708,7 @@ pub fn emitMir(emit: *Emit) Error!void { | ... | @@ -708,7 +708,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 708 | switch (reloc.source_length) { | 708 | switch (reloc.source_length) { |
| 709 | else => unreachable, | 709 | else => unreachable, |
| 710 | inline 1, 4 => |source_length| std.mem.writeInt( | 710 | inline 1, 4 => |source_length| std.mem.writeInt( |
| 711 | @Type(.{ .int = .{ .signedness = .signed, .bits = @as(u16, 8) * source_length } }), | 711 | @Int(.signed, @as(u16, 8) * source_length), |
| 712 | inst_bytes[reloc.source_offset..][0..source_length], | 712 | inst_bytes[reloc.source_offset..][0..source_length], |
| 713 | @intCast(disp), | 713 | @intCast(disp), |
| 714 | .little, | 714 | .little, |
src/link.zig+1-4| ... | @@ -51,10 +51,7 @@ pub const Diags = struct { | ... | @@ -51,10 +51,7 @@ pub const Diags = struct { |
| 51 | 51 | ||
| 52 | const Int = blk: { | 52 | const Int = blk: { |
| 53 | const bits = @typeInfo(@This()).@"struct".fields.len; | 53 | const bits = @typeInfo(@This()).@"struct".fields.len; |
| 54 | break :blk @Type(.{ .int = .{ | 54 | break :blk @Int(.unsigned, bits); |
| 55 | .signedness = .unsigned, | ||
| 56 | .bits = bits, | ||
| 57 | } }); | ||
| 58 | }; | 55 | }; |
| 59 | 56 | ||
| 60 | pub fn anySet(ef: Flags) bool { | 57 | pub fn anySet(ef: Flags) bool { |
src/link/Dwarf.zig+13-13| ... | @@ -5130,25 +5130,23 @@ pub fn resolveRelocs(dwarf: *Dwarf) RelocError!void { | ... | @@ -5130,25 +5130,23 @@ pub fn resolveRelocs(dwarf: *Dwarf) RelocError!void { |
| 5130 | 5130 | ||
| 5131 | fn DeclValEnum(comptime T: type) type { | 5131 | fn DeclValEnum(comptime T: type) type { |
| 5132 | const decls = @typeInfo(T).@"struct".decls; | 5132 | const decls = @typeInfo(T).@"struct".decls; |
| 5133 | @setEvalBranchQuota(7 * decls.len); | 5133 | @setEvalBranchQuota(10 * decls.len); |
| 5134 | var fields: [decls.len]std.builtin.Type.EnumField = undefined; | 5134 | var field_names: [decls.len][]const u8 = undefined; |
| 5135 | var fields_len = 0; | 5135 | var fields_len = 0; |
| 5136 | var min_value: ?comptime_int = null; | 5136 | var min_value: ?comptime_int = null; |
| 5137 | var max_value: ?comptime_int = null; | 5137 | var max_value: ?comptime_int = null; |
| 5138 | for (decls) |decl| { | 5138 | for (decls) |decl| { |
| 5139 | if (std.mem.startsWith(u8, decl.name, "HP_") or std.mem.endsWith(u8, decl.name, "_user")) continue; | 5139 | if (std.mem.startsWith(u8, decl.name, "HP_") or std.mem.endsWith(u8, decl.name, "_user")) continue; |
| 5140 | const value = @field(T, decl.name); | 5140 | const value = @field(T, decl.name); |
| 5141 | fields[fields_len] = .{ .name = decl.name, .value = value }; | 5141 | field_names[fields_len] = decl.name; |
| 5142 | fields_len += 1; | 5142 | fields_len += 1; |
| 5143 | if (min_value == null or min_value.? > value) min_value = value; | 5143 | if (min_value == null or min_value.? > value) min_value = value; |
| 5144 | if (max_value == null or max_value.? < value) max_value = value; | 5144 | if (max_value == null or max_value.? < value) max_value = value; |
| 5145 | } | 5145 | } |
| 5146 | return @Type(.{ .@"enum" = .{ | 5146 | const TagInt = std.math.IntFittingRange(min_value orelse 0, max_value orelse 0); |
| 5147 | .tag_type = std.math.IntFittingRange(min_value orelse 0, max_value orelse 0), | 5147 | var field_vals: [fields_len]TagInt = undefined; |
| 5148 | .fields = fields[0..fields_len], | 5148 | for (field_names[0..fields_len], &field_vals) |name, *val| val.* = @field(T, name); |
| 5149 | .decls = &.{}, | 5149 | return @Enum(TagInt, .exhaustive, field_names[0..fields_len], &field_vals); |
| 5150 | .is_exhaustive = true, | ||
| 5151 | } }); | ||
| 5152 | } | 5150 | } |
| 5153 | 5151 | ||
| 5154 | const AbbrevCode = enum { | 5152 | const AbbrevCode = enum { |
| ... | @@ -6382,10 +6380,12 @@ fn freeCommonEntry( | ... | @@ -6382,10 +6380,12 @@ fn freeCommonEntry( |
| 6382 | 6380 | ||
| 6383 | fn writeInt(dwarf: *Dwarf, buf: []u8, int: u64) void { | 6381 | fn writeInt(dwarf: *Dwarf, buf: []u8, int: u64) void { |
| 6384 | switch (buf.len) { | 6382 | switch (buf.len) { |
| 6385 | inline 0...8 => |len| std.mem.writeInt(@Type(.{ .int = .{ | 6383 | inline 0...8 => |len| std.mem.writeInt( |
| 6386 | .signedness = .unsigned, | 6384 | @Int(.unsigned, len * 8), |
| 6387 | .bits = len * 8, | 6385 | buf[0..len], |
| 6388 | } }), buf[0..len], @intCast(int), dwarf.endian), | 6386 | @intCast(int), |
| 6387 | dwarf.endian, | ||
| 6388 | ), | ||
| 6389 | else => unreachable, | 6389 | else => unreachable, |
| 6390 | } | 6390 | } |
| 6391 | } | 6391 | } |
src/link/MappedFile.zig+6-14| ... | @@ -108,10 +108,7 @@ pub const Node = extern struct { | ... | @@ -108,10 +108,7 @@ pub const Node = extern struct { |
| 108 | has_content: bool, | 108 | has_content: bool, |
| 109 | /// Whether a moved event on this node bubbles down to children. | 109 | /// Whether a moved event on this node bubbles down to children. |
| 110 | bubbles_moved: bool, | 110 | bubbles_moved: bool, |
| 111 | unused: @Type(.{ .int = .{ | 111 | unused: @Int(.unsigned, 32 - @bitSizeOf(std.mem.Alignment) - 6) = 0, |
| 112 | .signedness = .unsigned, | ||
| 113 | .bits = 32 - @bitSizeOf(std.mem.Alignment) - 6, | ||
| 114 | } }) = 0, | ||
| 115 | }; | 112 | }; |
| 116 | 113 | ||
| 117 | pub const Location = union(enum(u1)) { | 114 | pub const Location = union(enum(u1)) { |
| ... | @@ -122,19 +119,14 @@ pub const Node = extern struct { | ... | @@ -122,19 +119,14 @@ pub const Node = extern struct { |
| 122 | }, | 119 | }, |
| 123 | large: extern struct { | 120 | large: extern struct { |
| 124 | index: usize, | 121 | index: usize, |
| 125 | unused: @Type(.{ .int = .{ | 122 | unused: @Int(.unsigned, 64 - @bitSizeOf(usize)) = 0, |
| 126 | .signedness = .unsigned, | ||
| 127 | .bits = 64 - @bitSizeOf(usize), | ||
| 128 | } }) = 0, | ||
| 129 | }, | 123 | }, |
| 130 | 124 | ||
| 131 | pub const Tag = @typeInfo(Location).@"union".tag_type.?; | 125 | pub const Tag = @typeInfo(Location).@"union".tag_type.?; |
| 132 | pub const Payload = @Type(.{ .@"union" = .{ | 126 | pub const Payload = extern union { |
| 133 | .layout = .@"extern", | 127 | small: @FieldType(Location, "small"), |
| 134 | .tag_type = null, | 128 | large: @FieldType(Location, "large"), |
| 135 | .fields = @typeInfo(Location).@"union".fields, | 129 | }; |
| 136 | .decls = &.{}, | ||
| 137 | } }); | ||
| 138 | 130 | ||
| 139 | pub fn resolve(loc: Location, mf: *const MappedFile) [2]u64 { | 131 | pub fn resolve(loc: Location, mf: *const MappedFile) [2]u64 { |
| 140 | return switch (loc) { | 132 | return switch (loc) { |
src/main.zig+1-1| ... | @@ -136,7 +136,7 @@ var log_scopes: std.ArrayList([]const u8) = .empty; | ... | @@ -136,7 +136,7 @@ var log_scopes: std.ArrayList([]const u8) = .empty; |
| 136 | 136 | ||
| 137 | pub fn log( | 137 | pub fn log( |
| 138 | comptime level: std.log.Level, | 138 | comptime level: std.log.Level, |
| 139 | comptime scope: @Type(.enum_literal), | 139 | comptime scope: @EnumLiteral(), |
| 140 | comptime format: []const u8, | 140 | comptime format: []const u8, |
| 141 | args: anytype, | 141 | args: anytype, |
| 142 | ) void { | 142 | ) void { |
test/behavior/basic.zig+2-5| ... | @@ -1264,12 +1264,9 @@ test "reference to inferred local variable works as expected" { | ... | @@ -1264,12 +1264,9 @@ test "reference to inferred local variable works as expected" { |
| 1264 | try expect(crasher_local.lets_crash != a.lets_crash); | 1264 | try expect(crasher_local.lets_crash != a.lets_crash); |
| 1265 | } | 1265 | } |
| 1266 | 1266 | ||
| 1267 | test "@Type returned from block" { | 1267 | test "@Int returned from block" { |
| 1268 | const T = comptime b: { | 1268 | const T = comptime b: { |
| 1269 | break :b @Type(.{ .int = .{ | 1269 | break :b @Int(.unsigned, 8); |
| 1270 | .signedness = .unsigned, | ||
| 1271 | .bits = 8, | ||
| 1272 | } }); | ||
| 1273 | }; | 1270 | }; |
| 1274 | try std.testing.expect(T == u8); | 1271 | try std.testing.expect(T == u8); |
| 1275 | } | 1272 | } |
test/behavior/bit_shifting.zig+1-10| ... | @@ -119,21 +119,12 @@ test "Saturating Shift Left where lhs is of a computed type" { | ... | @@ -119,21 +119,12 @@ test "Saturating Shift Left where lhs is of a computed type" { |
| 119 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; | 119 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; |
| 120 | 120 | ||
| 121 | const S = struct { | 121 | const S = struct { |
| 122 | fn getIntShiftType(comptime T: type) type { | ||
| 123 | var unsigned_shift_type = @typeInfo(std.math.Log2Int(T)).int; | ||
| 124 | unsigned_shift_type.signedness = .signed; | ||
| 125 | |||
| 126 | return @Type(.{ | ||
| 127 | .int = unsigned_shift_type, | ||
| 128 | }); | ||
| 129 | } | ||
| 130 | |||
| 131 | pub fn FixedPoint(comptime ValueType: type) type { | 122 | pub fn FixedPoint(comptime ValueType: type) type { |
| 132 | return struct { | 123 | return struct { |
| 133 | value: ValueType, | 124 | value: ValueType, |
| 134 | exponent: ShiftType, | 125 | exponent: ShiftType, |
| 135 | 126 | ||
| 136 | const ShiftType: type = getIntShiftType(ValueType); | 127 | const ShiftType = @Int(.signed, @typeInfo(std.math.Log2Int(ValueType)).int.bits); |
| 137 | 128 | ||
| 138 | pub fn shiftExponent(self: @This(), shift: ShiftType) @This() { | 129 | pub fn shiftExponent(self: @This(), shift: ShiftType) @This() { |
| 139 | const shiftAbs = @abs(shift); | 130 | const shiftAbs = @abs(shift); |
test/behavior/call.zig+1-1| ... | @@ -355,7 +355,7 @@ test "inline call doesn't re-evaluate non generic struct" { | ... | @@ -355,7 +355,7 @@ test "inline call doesn't re-evaluate non generic struct" { |
| 355 | try comptime @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); | 355 | try comptime @call(.always_inline, S.foo, ArgTuple{.{ .a = 123, .b = 45 }}); |
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | test "Enum constructed by @Type passed as generic argument" { | 358 | test "Enum constructed by @Enum passed as generic argument" { |
| 359 | const S = struct { | 359 | const S = struct { |
| 360 | const E = std.meta.FieldEnum(struct { | 360 | const E = std.meta.FieldEnum(struct { |
| 361 | prev_pos: bool, | 361 | prev_pos: bool, |
test/behavior/cast.zig+8-3| ... | @@ -2446,9 +2446,14 @@ test "peer type resolution: pointer attributes are combined correctly" { | ... | @@ -2446,9 +2446,14 @@ test "peer type resolution: pointer attributes are combined correctly" { |
| 2446 | }; | 2446 | }; |
| 2447 | 2447 | ||
| 2448 | const NonAllowZero = comptime blk: { | 2448 | const NonAllowZero = comptime blk: { |
| 2449 | var ti = @typeInfo(@TypeOf(r1, r2, r3, r4)); | 2449 | const ptr = @typeInfo(@TypeOf(r1, r2, r3, r4)).pointer; |
| 2450 | ti.pointer.is_allowzero = false; | 2450 | break :blk @Pointer(ptr.size, .{ |
| 2451 | break :blk @Type(ti); | 2451 | .@"const" = ptr.is_const, |
| 2452 | .@"volatile" = ptr.is_volatile, | ||
| 2453 | .@"allowzero" = false, | ||
| 2454 | .@"align" = ptr.alignment, | ||
| 2455 | .@"addrspace" = ptr.address_space, | ||
| 2456 | }, ptr.child, ptr.sentinel()); | ||
| 2452 | }; | 2457 | }; |
| 2453 | try expectEqualSlices(u8, std.mem.span(@volatileCast(@as(NonAllowZero, @ptrCast(r1)))), "foo"); | 2458 | try expectEqualSlices(u8, std.mem.span(@volatileCast(@as(NonAllowZero, @ptrCast(r1)))), "foo"); |
| 2454 | try expectEqualSlices(u8, std.mem.span(@volatileCast(@as(NonAllowZero, @ptrCast(r2)))), "bar"); | 2459 | try expectEqualSlices(u8, std.mem.span(@volatileCast(@as(NonAllowZero, @ptrCast(r2)))), "bar"); |
test/behavior/enum.zig+1-4| ... | @@ -1283,10 +1283,7 @@ test "Non-exhaustive enum backed by comptime_int" { | ... | @@ -1283,10 +1283,7 @@ test "Non-exhaustive enum backed by comptime_int" { |
| 1283 | test "matching captures causes enum equivalence" { | 1283 | test "matching captures causes enum equivalence" { |
| 1284 | const S = struct { | 1284 | const S = struct { |
| 1285 | fn Nonexhaustive(comptime I: type) type { | 1285 | fn Nonexhaustive(comptime I: type) type { |
| 1286 | const UTag = @Type(.{ .int = .{ | 1286 | const UTag = @Int(.unsigned, @typeInfo(I).int.bits); |
| 1287 | .signedness = .unsigned, | ||
| 1288 | .bits = @typeInfo(I).int.bits, | ||
| 1289 | } }); | ||
| 1290 | return enum(UTag) { _ }; | 1287 | return enum(UTag) { _ }; |
| 1291 | } | 1288 | } |
| 1292 | }; | 1289 | }; |
test/behavior/fn.zig+2-2| ... | @@ -556,10 +556,10 @@ test "lazy values passed to anytype parameter" { | ... | @@ -556,10 +556,10 @@ test "lazy values passed to anytype parameter" { |
| 556 | 556 | ||
| 557 | test "pass and return comptime-only types" { | 557 | test "pass and return comptime-only types" { |
| 558 | const S = struct { | 558 | const S = struct { |
| 559 | fn returnNull(comptime x: @Type(.null)) @Type(.null) { | 559 | fn returnNull(comptime x: @TypeOf(null)) @TypeOf(null) { |
| 560 | return x; | 560 | return x; |
| 561 | } | 561 | } |
| 562 | fn returnUndefined(comptime x: @Type(.undefined)) @Type(.undefined) { | 562 | fn returnUndefined(comptime x: @TypeOf(undefined)) @TypeOf(undefined) { |
| 563 | return x; | 563 | return x; |
| 564 | } | 564 | } |
| 565 | }; | 565 | }; |
test/behavior/generics.zig+1-9| ... | @@ -263,15 +263,7 @@ test "generic function instantiation turns into comptime call" { | ... | @@ -263,15 +263,7 @@ test "generic function instantiation turns into comptime call" { |
| 263 | 263 | ||
| 264 | pub fn FieldEnum(comptime T: type) type { | 264 | pub fn FieldEnum(comptime T: type) type { |
| 265 | _ = T; | 265 | _ = T; |
| 266 | var enumFields: [1]std.builtin.Type.EnumField = .{.{ .name = "A", .value = 0 }}; | 266 | return @Enum(u0, .exhaustive, &.{"A"}, &.{0}); |
| 267 | return @Type(.{ | ||
| 268 | .@"enum" = .{ | ||
| 269 | .tag_type = u0, | ||
| 270 | .fields = &enumFields, | ||
| 271 | .decls = &.{}, | ||
| 272 | .is_exhaustive = true, | ||
| 273 | }, | ||
| 274 | }); | ||
| 275 | } | 267 | } |
| 276 | }; | 268 | }; |
| 277 | try S.doTheTest(); | 269 | try S.doTheTest(); |
test/behavior/sizeof_and_typeof.zig+6-6| ... | @@ -338,14 +338,14 @@ test "peer type resolution with @TypeOf doesn't trigger dependency loop check" { | ... | @@ -338,14 +338,14 @@ test "peer type resolution with @TypeOf doesn't trigger dependency loop check" { |
| 338 | 338 | ||
| 339 | test "@sizeOf reified union zero-size payload fields" { | 339 | test "@sizeOf reified union zero-size payload fields" { |
| 340 | comptime { | 340 | comptime { |
| 341 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union {})))); | 341 | try std.testing.expect(0 == @sizeOf(@Union(.auto, null, &.{}, &.{}, &.{}))); |
| 342 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void })))); | 342 | try std.testing.expect(0 == @sizeOf(@Union(.auto, null, &.{"a"}, &.{void}, &.{.{}}))); |
| 343 | if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) { | 343 | if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) { |
| 344 | try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void })))); | 344 | try std.testing.expect(1 == @sizeOf(@Union(.auto, null, &.{ "a", "b" }, &.{ void, void }, &.{ .{}, .{} }))); |
| 345 | try std.testing.expect(1 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void })))); | 345 | try std.testing.expect(1 == @sizeOf(@Union(.auto, null, &.{ "a", "b", "c" }, &.{ void, void, void }, &.{ .{}, .{}, .{} }))); |
| 346 | } else { | 346 | } else { |
| 347 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void })))); | 347 | try std.testing.expect(0 == @sizeOf(@Union(.auto, null, &.{ "a", "b" }, &.{ void, void }, &.{ .{}, .{} }))); |
| 348 | try std.testing.expect(0 == @sizeOf(@Type(@typeInfo(union { a: void, b: void, c: void })))); | 348 | try std.testing.expect(0 == @sizeOf(@Union(.auto, null, &.{ "a", "b", "c" }, &.{ void, void, void }, &.{ .{}, .{}, .{} }))); |
| 349 | } | 349 | } |
| 350 | } | 350 | } |
| 351 | } | 351 | } |
test/behavior/struct.zig+1-4| ... | @@ -2034,10 +2034,7 @@ test "matching captures causes struct equivalence" { | ... | @@ -2034,10 +2034,7 @@ test "matching captures causes struct equivalence" { |
| 2034 | fn UnsignedWrapper(comptime I: type) type { | 2034 | fn UnsignedWrapper(comptime I: type) type { |
| 2035 | const bits = @typeInfo(I).int.bits; | 2035 | const bits = @typeInfo(I).int.bits; |
| 2036 | return struct { | 2036 | return struct { |
| 2037 | x: @Type(.{ .int = .{ | 2037 | x: @Int(.unsigned, bits), |
| 2038 | .signedness = .unsigned, | ||
| 2039 | .bits = bits, | ||
| 2040 | } }), | ||
| 2041 | }; | 2038 | }; |
| 2042 | } | 2039 | } |
| 2043 | }; | 2040 | }; |
test/behavior/switch.zig+4-2| ... | @@ -843,7 +843,8 @@ test "switch capture peer type resolution for in-memory coercible payloads" { | ... | @@ -843,7 +843,8 @@ test "switch capture peer type resolution for in-memory coercible payloads" { |
| 843 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 843 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 844 | 844 | ||
| 845 | const T1 = c_int; | 845 | const T1 = c_int; |
| 846 | const T2 = @Type(@typeInfo(T1)); | 846 | const t1_info = @typeInfo(T1).int; |
| 847 | const T2 = @Int(t1_info.signedness, t1_info.bits); | ||
| 847 | 848 | ||
| 848 | comptime assert(T1 != T2); | 849 | comptime assert(T1 != T2); |
| 849 | 850 | ||
| ... | @@ -865,7 +866,8 @@ test "switch pointer capture peer type resolution" { | ... | @@ -865,7 +866,8 @@ test "switch pointer capture peer type resolution" { |
| 865 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 866 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 866 | 867 | ||
| 867 | const T1 = c_int; | 868 | const T1 = c_int; |
| 868 | const T2 = @Type(@typeInfo(T1)); | 869 | const t1_info = @typeInfo(T1).int; |
| 870 | const T2 = @Int(t1_info.signedness, t1_info.bits); | ||
| 869 | 871 | ||
| 870 | comptime assert(T1 != T2); | 872 | comptime assert(T1 != T2); |
| 871 | 873 |
test/behavior/switch_loop.zig+1-4| ... | @@ -230,10 +230,7 @@ test "switch loop on larger than pointer integer" { | ... | @@ -230,10 +230,7 @@ test "switch loop on larger than pointer integer" { |
| 230 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; | 230 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| 231 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 231 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 232 | 232 | ||
| 233 | var entry: @Type(.{ .int = .{ | 233 | var entry: @Int(.unsigned, @bitSizeOf(usize) + 1) = undefined; |
| 234 | .signedness = .unsigned, | ||
| 235 | .bits = @bitSizeOf(usize) + 1, | ||
| 236 | } }) = undefined; | ||
| 237 | entry = 0; | 234 | entry = 0; |
| 238 | loop: switch (entry) { | 235 | loop: switch (entry) { |
| 239 | 0 => { | 236 | 0 => { |
test/behavior/tuple.zig+4-55| ... | @@ -130,29 +130,7 @@ test "array-like initializer for tuple types" { | ... | @@ -130,29 +130,7 @@ test "array-like initializer for tuple types" { |
| 130 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 130 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 131 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 131 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 132 | 132 | ||
| 133 | const T = @Type(.{ | 133 | const T = @Tuple(&.{ i32, u8 }); |
| 134 | .@"struct" = .{ | ||
| 135 | .is_tuple = true, | ||
| 136 | .layout = .auto, | ||
| 137 | .decls = &.{}, | ||
| 138 | .fields = &.{ | ||
| 139 | .{ | ||
| 140 | .name = "0", | ||
| 141 | .type = i32, | ||
| 142 | .default_value_ptr = null, | ||
| 143 | .is_comptime = false, | ||
| 144 | .alignment = @alignOf(i32), | ||
| 145 | }, | ||
| 146 | .{ | ||
| 147 | .name = "1", | ||
| 148 | .type = u8, | ||
| 149 | .default_value_ptr = null, | ||
| 150 | .is_comptime = false, | ||
| 151 | .alignment = @alignOf(u8), | ||
| 152 | }, | ||
| 153 | }, | ||
| 154 | }, | ||
| 155 | }); | ||
| 156 | const S = struct { | 134 | const S = struct { |
| 157 | fn doTheTest() !void { | 135 | fn doTheTest() !void { |
| 158 | var obj: T = .{ -1234, 128 }; | 136 | var obj: T = .{ -1234, 128 }; |
| ... | @@ -320,20 +298,7 @@ test "zero sized struct in tuple handled correctly" { | ... | @@ -320,20 +298,7 @@ test "zero sized struct in tuple handled correctly" { |
| 320 | const Self = @This(); | 298 | const Self = @This(); |
| 321 | const Inner = struct {}; | 299 | const Inner = struct {}; |
| 322 | 300 | ||
| 323 | data: @Type(.{ | 301 | data: @Tuple(&.{Inner}), |
| 324 | .@"struct" = .{ | ||
| 325 | .is_tuple = true, | ||
| 326 | .layout = .auto, | ||
| 327 | .decls = &.{}, | ||
| 328 | .fields = &.{.{ | ||
| 329 | .name = "0", | ||
| 330 | .type = Inner, | ||
| 331 | .default_value_ptr = null, | ||
| 332 | .is_comptime = false, | ||
| 333 | .alignment = @alignOf(Inner), | ||
| 334 | }}, | ||
| 335 | }, | ||
| 336 | }), | ||
| 337 | 302 | ||
| 338 | pub fn do(this: Self) usize { | 303 | pub fn do(this: Self) usize { |
| 339 | return @sizeOf(@TypeOf(this)); | 304 | return @sizeOf(@TypeOf(this)); |
| ... | @@ -470,12 +435,7 @@ test "coerce anon tuple to tuple" { | ... | @@ -470,12 +435,7 @@ test "coerce anon tuple to tuple" { |
| 470 | } | 435 | } |
| 471 | 436 | ||
| 472 | test "empty tuple type" { | 437 | test "empty tuple type" { |
| 473 | const S = @Type(.{ .@"struct" = .{ | 438 | const S = @Tuple(&.{}); |
| 474 | .layout = .auto, | ||
| 475 | .fields = &.{}, | ||
| 476 | .decls = &.{}, | ||
| 477 | .is_tuple = true, | ||
| 478 | } }); | ||
| 479 | 439 | ||
| 480 | const s: S = .{}; | 440 | const s: S = .{}; |
| 481 | try expect(s.len == 0); | 441 | try expect(s.len == 0); |
| ... | @@ -616,18 +576,7 @@ test "OPV tuple fields aren't comptime" { | ... | @@ -616,18 +576,7 @@ test "OPV tuple fields aren't comptime" { |
| 616 | const t_info = @typeInfo(T); | 576 | const t_info = @typeInfo(T); |
| 617 | try expect(!t_info.@"struct".fields[0].is_comptime); | 577 | try expect(!t_info.@"struct".fields[0].is_comptime); |
| 618 | 578 | ||
| 619 | const T2 = @Type(.{ .@"struct" = .{ | 579 | const T2 = @Tuple(&.{void}); |
| 620 | .layout = .auto, | ||
| 621 | .fields = &.{.{ | ||
| 622 | .name = "0", | ||
| 623 | .type = void, | ||
| 624 | .default_value_ptr = null, | ||
| 625 | .is_comptime = false, | ||
| 626 | .alignment = @alignOf(void), | ||
| 627 | }}, | ||
| 628 | .decls = &.{}, | ||
| 629 | .is_tuple = true, | ||
| 630 | } }); | ||
| 631 | const t2_info = @typeInfo(T2); | 580 | const t2_info = @typeInfo(T2); |
| 632 | try expect(!t2_info.@"struct".fields[0].is_comptime); | 581 | try expect(!t2_info.@"struct".fields[0].is_comptime); |
| 633 | } | 582 | } |
test/behavior/type.zig+93-477| ... | @@ -4,63 +4,17 @@ const Type = std.builtin.Type; | ... | @@ -4,63 +4,17 @@ const Type = std.builtin.Type; |
| 4 | const testing = std.testing; | 4 | const testing = std.testing; |
| 5 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 6 | 6 | ||
| 7 | fn testTypes(comptime types: []const type) !void { | ||
| 8 | inline for (types) |testType| { | ||
| 9 | try testing.expect(testType == @Type(@typeInfo(testType))); | ||
| 10 | } | ||
| 11 | } | ||
| 12 | |||
| 13 | test "Type.MetaType" { | ||
| 14 | try testing.expect(type == @Type(.{ .type = {} })); | ||
| 15 | try testTypes(&[_]type{type}); | ||
| 16 | } | ||
| 17 | |||
| 18 | test "Type.Void" { | ||
| 19 | try testing.expect(void == @Type(.{ .void = {} })); | ||
| 20 | try testTypes(&[_]type{void}); | ||
| 21 | } | ||
| 22 | |||
| 23 | test "Type.Bool" { | ||
| 24 | try testing.expect(bool == @Type(.{ .bool = {} })); | ||
| 25 | try testTypes(&[_]type{bool}); | ||
| 26 | } | ||
| 27 | |||
| 28 | test "Type.NoReturn" { | ||
| 29 | try testing.expect(noreturn == @Type(.{ .noreturn = {} })); | ||
| 30 | try testTypes(&[_]type{noreturn}); | ||
| 31 | } | ||
| 32 | |||
| 33 | test "Type.Int" { | 7 | test "Type.Int" { |
| 34 | try testing.expect(u1 == @Type(.{ .int = .{ .signedness = .unsigned, .bits = 1 } })); | 8 | try testing.expect(u1 == @Int(.unsigned, 1)); |
| 35 | try testing.expect(i1 == @Type(.{ .int = .{ .signedness = .signed, .bits = 1 } })); | 9 | try testing.expect(i1 == @Int(.signed, 1)); |
| 36 | try testing.expect(u8 == @Type(.{ .int = .{ .signedness = .unsigned, .bits = 8 } })); | 10 | try testing.expect(u8 == @Int(.unsigned, 8)); |
| 37 | try testing.expect(i8 == @Type(.{ .int = .{ .signedness = .signed, .bits = 8 } })); | 11 | try testing.expect(i8 == @Int(.signed, 8)); |
| 38 | try testing.expect(u64 == @Type(.{ .int = .{ .signedness = .unsigned, .bits = 64 } })); | 12 | try testing.expect(u64 == @Int(.unsigned, 64)); |
| 39 | try testing.expect(i64 == @Type(.{ .int = .{ .signedness = .signed, .bits = 64 } })); | 13 | try testing.expect(i64 == @Int(.signed, 64)); |
| 40 | try testTypes(&[_]type{ u8, u32, i64 }); | ||
| 41 | } | ||
| 42 | |||
| 43 | test "Type.ComptimeFloat" { | ||
| 44 | try testTypes(&[_]type{comptime_float}); | ||
| 45 | } | ||
| 46 | test "Type.ComptimeInt" { | ||
| 47 | try testTypes(&[_]type{comptime_int}); | ||
| 48 | } | ||
| 49 | test "Type.Undefined" { | ||
| 50 | try testTypes(&[_]type{@TypeOf(undefined)}); | ||
| 51 | } | ||
| 52 | test "Type.Null" { | ||
| 53 | try testTypes(&[_]type{@TypeOf(null)}); | ||
| 54 | } | ||
| 55 | |||
| 56 | test "Type.EnumLiteral" { | ||
| 57 | try testTypes(&[_]type{ | ||
| 58 | @TypeOf(.Dummy), | ||
| 59 | }); | ||
| 60 | } | 14 | } |
| 61 | 15 | ||
| 62 | test "Type.Pointer" { | 16 | test "Type.Pointer" { |
| 63 | try testTypes(&[_]type{ | 17 | inline for (&[_]type{ |
| 64 | // One Value Pointer Types | 18 | // One Value Pointer Types |
| 65 | *u8, *const u8, | 19 | *u8, *const u8, |
| 66 | *volatile u8, *const volatile u8, | 20 | *volatile u8, *const volatile u8, |
| ... | @@ -101,62 +55,30 @@ test "Type.Pointer" { | ... | @@ -101,62 +55,30 @@ test "Type.Pointer" { |
| 101 | [*c]align(4) volatile u8, [*c]align(4) const volatile u8, | 55 | [*c]align(4) volatile u8, [*c]align(4) const volatile u8, |
| 102 | [*c]align(8) u8, [*c]align(8) const u8, | 56 | [*c]align(8) u8, [*c]align(8) const u8, |
| 103 | [*c]align(8) volatile u8, [*c]align(8) const volatile u8, | 57 | [*c]align(8) volatile u8, [*c]align(8) const volatile u8, |
| 104 | }); | 58 | }) |testType| { |
| 59 | const ptr = @typeInfo(testType).pointer; | ||
| 60 | try testing.expect(testType == @Pointer(ptr.size, .{ | ||
| 61 | .@"const" = ptr.is_const, | ||
| 62 | .@"volatile" = ptr.is_volatile, | ||
| 63 | .@"allowzero" = ptr.is_allowzero, | ||
| 64 | .@"align" = ptr.alignment, | ||
| 65 | .@"addrspace" = ptr.address_space, | ||
| 66 | }, ptr.child, ptr.sentinel())); | ||
| 67 | } | ||
| 105 | } | 68 | } |
| 106 | 69 | ||
| 107 | test "Type.Float" { | 70 | test "@Pointer create slice without sentinel" { |
| 108 | try testing.expect(f16 == @Type(.{ .float = .{ .bits = 16 } })); | 71 | const Slice = @Pointer(.slice, .{ .@"const" = true, .@"align" = 8 }, ?*i32, null); |
| 109 | try testing.expect(f32 == @Type(.{ .float = .{ .bits = 32 } })); | 72 | try testing.expect(Slice == []align(8) const ?*i32); |
| 110 | try testing.expect(f64 == @Type(.{ .float = .{ .bits = 64 } })); | ||
| 111 | try testing.expect(f80 == @Type(.{ .float = .{ .bits = 80 } })); | ||
| 112 | try testing.expect(f128 == @Type(.{ .float = .{ .bits = 128 } })); | ||
| 113 | try testTypes(&[_]type{ f16, f32, f64, f80, f128 }); | ||
| 114 | } | 73 | } |
| 115 | 74 | ||
| 116 | test "Type.Array" { | 75 | test "@Pointer create slice with null sentinel" { |
| 117 | try testing.expect([123]u8 == @Type(.{ | 76 | const Slice = @Pointer(.slice, .{ .@"const" = true, .@"align" = 8 }, ?*i32, @as(?*i32, null)); |
| 118 | .array = .{ | 77 | try testing.expect(Slice == [:null]align(8) const ?*i32); |
| 119 | .len = 123, | ||
| 120 | .child = u8, | ||
| 121 | .sentinel_ptr = null, | ||
| 122 | }, | ||
| 123 | })); | ||
| 124 | try testing.expect([2]u32 == @Type(.{ | ||
| 125 | .array = .{ | ||
| 126 | .len = 2, | ||
| 127 | .child = u32, | ||
| 128 | .sentinel_ptr = null, | ||
| 129 | }, | ||
| 130 | })); | ||
| 131 | try testing.expect([2:0]u32 == @Type(.{ | ||
| 132 | .array = .{ | ||
| 133 | .len = 2, | ||
| 134 | .child = u32, | ||
| 135 | .sentinel_ptr = &@as(u32, 0), | ||
| 136 | }, | ||
| 137 | })); | ||
| 138 | try testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); | ||
| 139 | } | 78 | } |
| 140 | 79 | ||
| 141 | test "@Type create slice with null sentinel" { | 80 | test "@Pointer on @typeInfo round-trips sentinels" { |
| 142 | const Slice = @Type(.{ | 81 | inline for (&[_]type{ |
| 143 | .pointer = .{ | ||
| 144 | .size = .slice, | ||
| 145 | .is_const = true, | ||
| 146 | .is_volatile = false, | ||
| 147 | .is_allowzero = false, | ||
| 148 | .alignment = 8, | ||
| 149 | .address_space = .generic, | ||
| 150 | .child = *i32, | ||
| 151 | .sentinel_ptr = null, | ||
| 152 | }, | ||
| 153 | }); | ||
| 154 | try testing.expect(Slice == []align(8) const *i32); | ||
| 155 | } | ||
| 156 | |||
| 157 | test "@Type picks up the sentinel value from Type" { | ||
| 158 | try testTypes(&[_]type{ | ||
| 159 | [11:0]u8, [4:10]u8, | ||
| 160 | [*:0]u8, [*:0]const u8, | 82 | [*:0]u8, [*:0]const u8, |
| 161 | [*:0]volatile u8, [*:0]const volatile u8, | 83 | [*:0]volatile u8, [*:0]const volatile u8, |
| 162 | [*:0]align(4) u8, [*:0]align(4) const u8, | 84 | [*:0]align(4) u8, [*:0]align(4) const u8, |
| ... | @@ -179,24 +101,16 @@ test "@Type picks up the sentinel value from Type" { | ... | @@ -179,24 +101,16 @@ test "@Type picks up the sentinel value from Type" { |
| 179 | [:0]allowzero align(4) u8, [:0]allowzero align(4) const u8, | 101 | [:0]allowzero align(4) u8, [:0]allowzero align(4) const u8, |
| 180 | [:0]allowzero align(4) volatile u8, [:0]allowzero align(4) const volatile u8, | 102 | [:0]allowzero align(4) volatile u8, [:0]allowzero align(4) const volatile u8, |
| 181 | [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8, | 103 | [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8, |
| 182 | }); | 104 | }) |TestType| { |
| 183 | } | 105 | const ptr = @typeInfo(TestType).pointer; |
| 184 | 106 | try testing.expect(TestType == @Pointer(ptr.size, .{ | |
| 185 | test "Type.Optional" { | 107 | .@"const" = ptr.is_const, |
| 186 | try testTypes(&[_]type{ | 108 | .@"volatile" = ptr.is_volatile, |
| 187 | ?u8, | 109 | .@"allowzero" = ptr.is_allowzero, |
| 188 | ?*u8, | 110 | .@"align" = ptr.alignment, |
| 189 | ?[]u8, | 111 | .@"addrspace" = ptr.address_space, |
| 190 | ?[*]u8, | 112 | }, ptr.child, ptr.sentinel())); |
| 191 | ?[*c]u8, | 113 | } |
| 192 | }); | ||
| 193 | } | ||
| 194 | |||
| 195 | test "Type.ErrorUnion" { | ||
| 196 | try testTypes(&[_]type{ | ||
| 197 | error{}!void, | ||
| 198 | error{Error}!void, | ||
| 199 | }); | ||
| 200 | } | 114 | } |
| 201 | 115 | ||
| 202 | test "Type.Opaque" { | 116 | test "Type.Opaque" { |
| ... | @@ -205,11 +119,7 @@ test "Type.Opaque" { | ... | @@ -205,11 +119,7 @@ test "Type.Opaque" { |
| 205 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 119 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 206 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 120 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 207 | 121 | ||
| 208 | const Opaque = @Type(.{ | 122 | const Opaque = opaque {}; |
| 209 | .@"opaque" = .{ | ||
| 210 | .decls = &.{}, | ||
| 211 | }, | ||
| 212 | }); | ||
| 213 | try testing.expect(Opaque != opaque {}); | 123 | try testing.expect(Opaque != opaque {}); |
| 214 | try testing.expectEqualSlices( | 124 | try testing.expectEqualSlices( |
| 215 | Type.Declaration, | 125 | Type.Declaration, |
| ... | @@ -218,52 +128,17 @@ test "Type.Opaque" { | ... | @@ -218,52 +128,17 @@ test "Type.Opaque" { |
| 218 | ); | 128 | ); |
| 219 | } | 129 | } |
| 220 | 130 | ||
| 221 | test "Type.Vector" { | ||
| 222 | try testTypes(&[_]type{ | ||
| 223 | @Vector(0, u8), | ||
| 224 | @Vector(4, u8), | ||
| 225 | @Vector(8, *u8), | ||
| 226 | @Vector(0, u8), | ||
| 227 | @Vector(4, u8), | ||
| 228 | @Vector(8, *u8), | ||
| 229 | }); | ||
| 230 | } | ||
| 231 | |||
| 232 | test "Type.AnyFrame" { | ||
| 233 | if (true) { | ||
| 234 | // https://github.com/ziglang/zig/issues/6025 | ||
| 235 | return error.SkipZigTest; | ||
| 236 | } | ||
| 237 | |||
| 238 | try testTypes(&[_]type{ | ||
| 239 | anyframe, | ||
| 240 | anyframe->u8, | ||
| 241 | anyframe->anyframe->u8, | ||
| 242 | }); | ||
| 243 | } | ||
| 244 | |||
| 245 | fn add(a: i32, b: i32) i32 { | 131 | fn add(a: i32, b: i32) i32 { |
| 246 | return a + b; | 132 | return a + b; |
| 247 | } | 133 | } |
| 248 | 134 | ||
| 249 | test "Type.ErrorSet" { | ||
| 250 | try testing.expect(@Type(.{ .error_set = null }) == anyerror); | ||
| 251 | |||
| 252 | // error sets don't compare equal so just check if they compile | ||
| 253 | inline for (.{ error{}, error{A}, error{ A, B, C } }) |T| { | ||
| 254 | const info = @typeInfo(T); | ||
| 255 | const T2 = @Type(info); | ||
| 256 | try testing.expect(T == T2); | ||
| 257 | } | ||
| 258 | } | ||
| 259 | |||
| 260 | test "Type.Struct" { | 135 | test "Type.Struct" { |
| 261 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | 136 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| 262 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 137 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 263 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 138 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 264 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 139 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 265 | 140 | ||
| 266 | const A = @Type(@typeInfo(struct { x: u8, y: u32 })); | 141 | const A = @Struct(.auto, null, &.{ "x", "y" }, &.{ u8, u32 }, &@splat(.{})); |
| 267 | const infoA = @typeInfo(A).@"struct"; | 142 | const infoA = @typeInfo(A).@"struct"; |
| 268 | try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout); | 143 | try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout); |
| 269 | try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); | 144 | try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); |
| ... | @@ -281,7 +156,13 @@ test "Type.Struct" { | ... | @@ -281,7 +156,13 @@ test "Type.Struct" { |
| 281 | a.y += 1; | 156 | a.y += 1; |
| 282 | try testing.expectEqual(@as(u32, 2), a.y); | 157 | try testing.expectEqual(@as(u32, 2), a.y); |
| 283 | 158 | ||
| 284 | const B = @Type(@typeInfo(extern struct { x: u8, y: u32 = 5 })); | 159 | const B = @Struct( |
| 160 | .@"extern", | ||
| 161 | null, | ||
| 162 | &.{ "x", "y" }, | ||
| 163 | &.{ u8, u32 }, | ||
| 164 | &.{ .{}, .{ .default_value_ptr = &@as(u32, 5) } }, | ||
| 165 | ); | ||
| 285 | const infoB = @typeInfo(B).@"struct"; | 166 | const infoB = @typeInfo(B).@"struct"; |
| 286 | try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout); | 167 | try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout); |
| 287 | try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); | 168 | try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); |
| ... | @@ -293,7 +174,16 @@ test "Type.Struct" { | ... | @@ -293,7 +174,16 @@ test "Type.Struct" { |
| 293 | try testing.expectEqual(@as(usize, 0), infoB.decls.len); | 174 | try testing.expectEqual(@as(usize, 0), infoB.decls.len); |
| 294 | try testing.expectEqual(@as(bool, false), infoB.is_tuple); | 175 | try testing.expectEqual(@as(bool, false), infoB.is_tuple); |
| 295 | 176 | ||
| 296 | const C = @Type(@typeInfo(packed struct { x: u8 = 3, y: u32 = 5 })); | 177 | const C = @Struct( |
| 178 | .@"packed", | ||
| 179 | null, | ||
| 180 | &.{ "x", "y" }, | ||
| 181 | &.{ u8, u32 }, | ||
| 182 | &.{ | ||
| 183 | .{ .default_value_ptr = &@as(u8, 3) }, | ||
| 184 | .{ .default_value_ptr = &@as(u32, 5) }, | ||
| 185 | }, | ||
| 186 | ); | ||
| 297 | const infoC = @typeInfo(C).@"struct"; | 187 | const infoC = @typeInfo(C).@"struct"; |
| 298 | try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout); | 188 | try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout); |
| 299 | try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); | 189 | try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); |
| ... | @@ -305,76 +195,23 @@ test "Type.Struct" { | ... | @@ -305,76 +195,23 @@ test "Type.Struct" { |
| 305 | try testing.expectEqual(@as(usize, 0), infoC.decls.len); | 195 | try testing.expectEqual(@as(usize, 0), infoC.decls.len); |
| 306 | try testing.expectEqual(@as(bool, false), infoC.is_tuple); | 196 | try testing.expectEqual(@as(bool, false), infoC.is_tuple); |
| 307 | 197 | ||
| 308 | // anon structs | ||
| 309 | const D = @Type(@typeInfo(@TypeOf(.{ .x = 3, .y = 5 }))); | ||
| 310 | const infoD = @typeInfo(D).@"struct"; | ||
| 311 | try testing.expectEqual(Type.ContainerLayout.auto, infoD.layout); | ||
| 312 | try testing.expectEqualSlices(u8, "x", infoD.fields[0].name); | ||
| 313 | try testing.expectEqual(comptime_int, infoD.fields[0].type); | ||
| 314 | try testing.expectEqual(@as(comptime_int, 3), infoD.fields[0].defaultValue().?); | ||
| 315 | try testing.expectEqualSlices(u8, "y", infoD.fields[1].name); | ||
| 316 | try testing.expectEqual(comptime_int, infoD.fields[1].type); | ||
| 317 | try testing.expectEqual(@as(comptime_int, 5), infoD.fields[1].defaultValue().?); | ||
| 318 | try testing.expectEqual(@as(usize, 0), infoD.decls.len); | ||
| 319 | try testing.expectEqual(@as(bool, false), infoD.is_tuple); | ||
| 320 | |||
| 321 | // tuples | ||
| 322 | const E = @Type(@typeInfo(@TypeOf(.{ 1, 2 }))); | ||
| 323 | const infoE = @typeInfo(E).@"struct"; | ||
| 324 | try testing.expectEqual(Type.ContainerLayout.auto, infoE.layout); | ||
| 325 | try testing.expectEqualSlices(u8, "0", infoE.fields[0].name); | ||
| 326 | try testing.expectEqual(comptime_int, infoE.fields[0].type); | ||
| 327 | try testing.expectEqual(@as(comptime_int, 1), infoE.fields[0].defaultValue().?); | ||
| 328 | try testing.expectEqualSlices(u8, "1", infoE.fields[1].name); | ||
| 329 | try testing.expectEqual(comptime_int, infoE.fields[1].type); | ||
| 330 | try testing.expectEqual(@as(comptime_int, 2), infoE.fields[1].defaultValue().?); | ||
| 331 | try testing.expectEqual(@as(usize, 0), infoE.decls.len); | ||
| 332 | try testing.expectEqual(@as(bool, true), infoE.is_tuple); | ||
| 333 | |||
| 334 | // empty struct | 198 | // empty struct |
| 335 | const F = @Type(@typeInfo(struct {})); | 199 | const F = @Struct(.auto, null, &.{}, &.{}, &.{}); |
| 336 | const infoF = @typeInfo(F).@"struct"; | 200 | const infoF = @typeInfo(F).@"struct"; |
| 337 | try testing.expectEqual(Type.ContainerLayout.auto, infoF.layout); | 201 | try testing.expectEqual(Type.ContainerLayout.auto, infoF.layout); |
| 338 | try testing.expect(infoF.fields.len == 0); | 202 | try testing.expect(infoF.fields.len == 0); |
| 339 | try testing.expectEqual(@as(bool, false), infoF.is_tuple); | 203 | try testing.expectEqual(@as(bool, false), infoF.is_tuple); |
| 340 | |||
| 341 | // empty tuple | ||
| 342 | const G = @Type(@typeInfo(@TypeOf(.{}))); | ||
| 343 | const infoG = @typeInfo(G).@"struct"; | ||
| 344 | try testing.expectEqual(Type.ContainerLayout.auto, infoG.layout); | ||
| 345 | try testing.expect(infoG.fields.len == 0); | ||
| 346 | try testing.expectEqual(@as(bool, true), infoG.is_tuple); | ||
| 347 | } | 204 | } |
| 348 | 205 | ||
| 349 | test "Type.Enum" { | 206 | test "Type.Enum" { |
| 350 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 207 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 351 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 208 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 352 | 209 | ||
| 353 | const Foo = @Type(.{ | 210 | const Foo = @Enum(u8, .exhaustive, &.{ "a", "b" }, &.{ 1, 5 }); |
| 354 | .@"enum" = .{ | ||
| 355 | .tag_type = u8, | ||
| 356 | .fields = &.{ | ||
| 357 | .{ .name = "a", .value = 1 }, | ||
| 358 | .{ .name = "b", .value = 5 }, | ||
| 359 | }, | ||
| 360 | .decls = &.{}, | ||
| 361 | .is_exhaustive = true, | ||
| 362 | }, | ||
| 363 | }); | ||
| 364 | try testing.expectEqual(true, @typeInfo(Foo).@"enum".is_exhaustive); | 211 | try testing.expectEqual(true, @typeInfo(Foo).@"enum".is_exhaustive); |
| 365 | try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a)); | 212 | try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a)); |
| 366 | try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b)); | 213 | try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b)); |
| 367 | const Bar = @Type(.{ | 214 | const Bar = @Enum(u32, .nonexhaustive, &.{ "a", "b" }, &.{ 1, 5 }); |
| 368 | .@"enum" = .{ | ||
| 369 | .tag_type = u32, | ||
| 370 | .fields = &.{ | ||
| 371 | .{ .name = "a", .value = 1 }, | ||
| 372 | .{ .name = "b", .value = 5 }, | ||
| 373 | }, | ||
| 374 | .decls = &.{}, | ||
| 375 | .is_exhaustive = false, | ||
| 376 | }, | ||
| 377 | }); | ||
| 378 | try testing.expectEqual(false, @typeInfo(Bar).@"enum".is_exhaustive); | 215 | try testing.expectEqual(false, @typeInfo(Bar).@"enum".is_exhaustive); |
| 379 | try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a)); | 216 | try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a)); |
| 380 | try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b)); | 217 | try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b)); |
| ... | @@ -382,12 +219,7 @@ test "Type.Enum" { | ... | @@ -382,12 +219,7 @@ test "Type.Enum" { |
| 382 | 219 | ||
| 383 | { // from https://github.com/ziglang/zig/issues/19985 | 220 | { // from https://github.com/ziglang/zig/issues/19985 |
| 384 | { // enum with single field can be initialized. | 221 | { // enum with single field can be initialized. |
| 385 | const E = @Type(.{ .@"enum" = .{ | 222 | const E = @Enum(u0, .exhaustive, &.{"foo"}, &.{0}); |
| 386 | .tag_type = u0, | ||
| 387 | .is_exhaustive = true, | ||
| 388 | .fields = &.{.{ .name = "foo", .value = 0 }}, | ||
| 389 | .decls = &.{}, | ||
| 390 | } }); | ||
| 391 | const s: struct { E } = .{.foo}; | 223 | const s: struct { E } = .{.foo}; |
| 392 | try testing.expectEqual(.foo, s[0]); | 224 | try testing.expectEqual(.foo, s[0]); |
| 393 | } | 225 | } |
| ... | @@ -411,60 +243,20 @@ test "Type.Union" { | ... | @@ -411,60 +243,20 @@ test "Type.Union" { |
| 411 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 243 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 412 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; | 244 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 413 | 245 | ||
| 414 | const Untagged = @Type(.{ | 246 | const Untagged = @Union(.@"extern", null, &.{ "int", "float" }, &.{ i32, f32 }, &.{ .{}, .{} }); |
| 415 | .@"union" = .{ | ||
| 416 | .layout = .@"extern", | ||
| 417 | .tag_type = null, | ||
| 418 | .fields = &.{ | ||
| 419 | .{ .name = "int", .type = i32, .alignment = @alignOf(f32) }, | ||
| 420 | .{ .name = "float", .type = f32, .alignment = @alignOf(f32) }, | ||
| 421 | }, | ||
| 422 | .decls = &.{}, | ||
| 423 | }, | ||
| 424 | }); | ||
| 425 | var untagged = Untagged{ .int = 1 }; | 247 | var untagged = Untagged{ .int = 1 }; |
| 426 | untagged.float = 2.0; | 248 | untagged.float = 2.0; |
| 427 | untagged.int = 3; | 249 | untagged.int = 3; |
| 428 | try testing.expectEqual(@as(i32, 3), untagged.int); | 250 | try testing.expectEqual(@as(i32, 3), untagged.int); |
| 429 | 251 | ||
| 430 | const PackedUntagged = @Type(.{ | 252 | const PackedUntagged = @Union(.@"packed", null, &.{ "signed", "unsigned" }, &.{ i32, u32 }, &.{ .{}, .{} }); |
| 431 | .@"union" = .{ | ||
| 432 | .layout = .@"packed", | ||
| 433 | .tag_type = null, | ||
| 434 | .fields = &.{ | ||
| 435 | .{ .name = "signed", .type = i32, .alignment = 0 }, | ||
| 436 | .{ .name = "unsigned", .type = u32, .alignment = 0 }, | ||
| 437 | }, | ||
| 438 | .decls = &.{}, | ||
| 439 | }, | ||
| 440 | }); | ||
| 441 | var packed_untagged: PackedUntagged = .{ .signed = -1 }; | 253 | var packed_untagged: PackedUntagged = .{ .signed = -1 }; |
| 442 | _ = &packed_untagged; | 254 | _ = &packed_untagged; |
| 443 | try testing.expectEqual(@as(i32, -1), packed_untagged.signed); | 255 | try testing.expectEqual(@as(i32, -1), packed_untagged.signed); |
| 444 | try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); | 256 | try testing.expectEqual(~@as(u32, 0), packed_untagged.unsigned); |
| 445 | 257 | ||
| 446 | const Tag = @Type(.{ | 258 | const Tag = @Enum(u1, .exhaustive, &.{ "signed", "unsigned" }, &.{ 0, 1 }); |
| 447 | .@"enum" = .{ | 259 | const Tagged = @Union(.auto, Tag, &.{ "signed", "unsigned" }, &.{ i32, u32 }, &.{ .{}, .{} }); |
| 448 | .tag_type = u1, | ||
| 449 | .fields = &.{ | ||
| 450 | .{ .name = "signed", .value = 0 }, | ||
| 451 | .{ .name = "unsigned", .value = 1 }, | ||
| 452 | }, | ||
| 453 | .decls = &.{}, | ||
| 454 | .is_exhaustive = true, | ||
| 455 | }, | ||
| 456 | }); | ||
| 457 | const Tagged = @Type(.{ | ||
| 458 | .@"union" = .{ | ||
| 459 | .layout = .auto, | ||
| 460 | .tag_type = Tag, | ||
| 461 | .fields = &.{ | ||
| 462 | .{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
| 463 | .{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
| 464 | }, | ||
| 465 | .decls = &.{}, | ||
| 466 | }, | ||
| 467 | }); | ||
| 468 | var tagged = Tagged{ .signed = -1 }; | 260 | var tagged = Tagged{ .signed = -1 }; |
| 469 | try testing.expectEqual(Tag.signed, @as(Tag, tagged)); | 261 | try testing.expectEqual(Tag.signed, @as(Tag, tagged)); |
| 470 | tagged = .{ .unsigned = 1 }; | 262 | tagged = .{ .unsigned = 1 }; |
| ... | @@ -472,74 +264,26 @@ test "Type.Union" { | ... | @@ -472,74 +264,26 @@ test "Type.Union" { |
| 472 | } | 264 | } |
| 473 | 265 | ||
| 474 | test "Type.Union from Type.Enum" { | 266 | test "Type.Union from Type.Enum" { |
| 475 | const Tag = @Type(.{ | 267 | const Tag = @Enum(u0, .exhaustive, &.{"working_as_expected"}, &.{0}); |
| 476 | .@"enum" = .{ | 268 | const T = @Union(.auto, Tag, &.{"working_as_expected"}, &.{u32}, &.{.{}}); |
| 477 | .tag_type = u0, | ||
| 478 | .fields = &.{ | ||
| 479 | .{ .name = "working_as_expected", .value = 0 }, | ||
| 480 | }, | ||
| 481 | .decls = &.{}, | ||
| 482 | .is_exhaustive = true, | ||
| 483 | }, | ||
| 484 | }); | ||
| 485 | const T = @Type(.{ | ||
| 486 | .@"union" = .{ | ||
| 487 | .layout = .auto, | ||
| 488 | .tag_type = Tag, | ||
| 489 | .fields = &.{ | ||
| 490 | .{ .name = "working_as_expected", .type = u32, .alignment = @alignOf(u32) }, | ||
| 491 | }, | ||
| 492 | .decls = &.{}, | ||
| 493 | }, | ||
| 494 | }); | ||
| 495 | _ = @typeInfo(T).@"union"; | 269 | _ = @typeInfo(T).@"union"; |
| 496 | } | 270 | } |
| 497 | 271 | ||
| 498 | test "Type.Union from regular enum" { | 272 | test "Type.Union from regular enum" { |
| 499 | const E = enum { working_as_expected }; | 273 | const E = enum { working_as_expected }; |
| 500 | const T = @Type(.{ | 274 | const T = @Union(.auto, E, &.{"working_as_expected"}, &.{u32}, &.{.{}}); |
| 501 | .@"union" = .{ | ||
| 502 | .layout = .auto, | ||
| 503 | .tag_type = E, | ||
| 504 | .fields = &.{ | ||
| 505 | .{ .name = "working_as_expected", .type = u32, .alignment = @alignOf(u32) }, | ||
| 506 | }, | ||
| 507 | .decls = &.{}, | ||
| 508 | }, | ||
| 509 | }); | ||
| 510 | _ = @typeInfo(T).@"union"; | 275 | _ = @typeInfo(T).@"union"; |
| 511 | } | 276 | } |
| 512 | 277 | ||
| 513 | test "Type.Union from empty regular enum" { | 278 | test "Type.Union from empty regular enum" { |
| 514 | const E = enum {}; | 279 | const E = enum {}; |
| 515 | const U = @Type(.{ | 280 | const U = @Union(.auto, E, &.{}, &.{}, &.{}); |
| 516 | .@"union" = .{ | ||
| 517 | .layout = .auto, | ||
| 518 | .tag_type = E, | ||
| 519 | .fields = &.{}, | ||
| 520 | .decls = &.{}, | ||
| 521 | }, | ||
| 522 | }); | ||
| 523 | try testing.expectEqual(@sizeOf(U), 0); | 281 | try testing.expectEqual(@sizeOf(U), 0); |
| 524 | } | 282 | } |
| 525 | 283 | ||
| 526 | test "Type.Union from empty Type.Enum" { | 284 | test "Type.Union from empty Type.Enum" { |
| 527 | const E = @Type(.{ | 285 | const E = @Enum(u0, .exhaustive, &.{}, &.{}); |
| 528 | .@"enum" = .{ | 286 | const U = @Union(.auto, E, &.{}, &.{}, &.{}); |
| 529 | .tag_type = u0, | ||
| 530 | .fields = &.{}, | ||
| 531 | .decls = &.{}, | ||
| 532 | .is_exhaustive = true, | ||
| 533 | }, | ||
| 534 | }); | ||
| 535 | const U = @Type(.{ | ||
| 536 | .@"union" = .{ | ||
| 537 | .layout = .auto, | ||
| 538 | .tag_type = E, | ||
| 539 | .fields = &.{}, | ||
| 540 | .decls = &.{}, | ||
| 541 | }, | ||
| 542 | }); | ||
| 543 | try testing.expectEqual(@sizeOf(U), 0); | 287 | try testing.expectEqual(@sizeOf(U), 0); |
| 544 | } | 288 | } |
| 545 | 289 | ||
| ... | @@ -548,47 +292,22 @@ test "Type.Fn" { | ... | @@ -548,47 +292,22 @@ test "Type.Fn" { |
| 548 | 292 | ||
| 549 | const some_opaque = opaque {}; | 293 | const some_opaque = opaque {}; |
| 550 | const some_ptr = *some_opaque; | 294 | const some_ptr = *some_opaque; |
| 551 | const T = fn (c_int, some_ptr) callconv(.c) void; | ||
| 552 | |||
| 553 | { | ||
| 554 | const fn_info = std.builtin.Type{ .@"fn" = .{ | ||
| 555 | .calling_convention = .c, | ||
| 556 | .is_generic = false, | ||
| 557 | .is_var_args = false, | ||
| 558 | .return_type = void, | ||
| 559 | .params = &.{ | ||
| 560 | .{ .is_generic = false, .is_noalias = false, .type = c_int }, | ||
| 561 | .{ .is_generic = false, .is_noalias = false, .type = some_ptr }, | ||
| 562 | }, | ||
| 563 | } }; | ||
| 564 | |||
| 565 | const fn_type = @Type(fn_info); | ||
| 566 | try std.testing.expectEqual(T, fn_type); | ||
| 567 | } | ||
| 568 | 295 | ||
| 569 | { | 296 | const A = @Fn(&.{ c_int, some_ptr }, &@splat(.{}), void, .{ .@"callconv" = .c }); |
| 570 | const fn_info = @typeInfo(T); | 297 | comptime assert(A == fn (c_int, some_ptr) callconv(.c) void); |
| 571 | const fn_type = @Type(fn_info); | 298 | |
| 572 | try std.testing.expectEqual(T, fn_type); | 299 | const B = @Fn(&.{ c_int, some_ptr, u32 }, &.{ .{}, .{ .@"noalias" = true }, .{} }, u64, .{}); |
| 573 | } | 300 | comptime assert(B == fn (c_int, noalias some_ptr, u32) u64); |
| 301 | |||
| 302 | const C = @Fn(&.{?[*]u8}, &.{.{}}, *const anyopaque, .{ .@"callconv" = .c, .varargs = true }); | ||
| 303 | comptime assert(C == fn (?[*]u8, ...) callconv(.c) *const anyopaque); | ||
| 574 | } | 304 | } |
| 575 | 305 | ||
| 576 | test "reified struct field name from optional payload" { | 306 | test "reified struct field name from optional payload" { |
| 577 | comptime { | 307 | comptime { |
| 578 | const m_name: ?[1:0]u8 = "a".*; | 308 | const m_name: ?[1:0]u8 = "a".*; |
| 579 | if (m_name) |*name| { | 309 | if (m_name) |*name| { |
| 580 | const T = @Type(.{ .@"struct" = .{ | 310 | const T = @Struct(.auto, null, &.{name}, &.{u8}, &.{.{}}); |
| 581 | .layout = .auto, | ||
| 582 | .fields = &.{.{ | ||
| 583 | .name = name, | ||
| 584 | .type = u8, | ||
| 585 | .default_value_ptr = null, | ||
| 586 | .is_comptime = false, | ||
| 587 | .alignment = 1, | ||
| 588 | }}, | ||
| 589 | .decls = &.{}, | ||
| 590 | .is_tuple = false, | ||
| 591 | } }); | ||
| 592 | const t: T = .{ .a = 123 }; | 311 | const t: T = .{ .a = 123 }; |
| 593 | try std.testing.expect(t.a == 123); | 312 | try std.testing.expect(t.a == 123); |
| 594 | } | 313 | } |
| ... | @@ -598,20 +317,7 @@ test "reified struct field name from optional payload" { | ... | @@ -598,20 +317,7 @@ test "reified struct field name from optional payload" { |
| 598 | test "reified union uses @alignOf" { | 317 | test "reified union uses @alignOf" { |
| 599 | const S = struct { | 318 | const S = struct { |
| 600 | fn CreateUnion(comptime T: type) type { | 319 | fn CreateUnion(comptime T: type) type { |
| 601 | return @Type(.{ | 320 | return @Union(.auto, null, &.{"field"}, &.{T}, &.{.{}}); |
| 602 | .@"union" = .{ | ||
| 603 | .layout = .auto, | ||
| 604 | .tag_type = null, | ||
| 605 | .fields = &[_]std.builtin.Type.UnionField{ | ||
| 606 | .{ | ||
| 607 | .name = "field", | ||
| 608 | .type = T, | ||
| 609 | .alignment = @alignOf(T), | ||
| 610 | }, | ||
| 611 | }, | ||
| 612 | .decls = &.{}, | ||
| 613 | }, | ||
| 614 | }); | ||
| 615 | } | 321 | } |
| 616 | }; | 322 | }; |
| 617 | _ = S.CreateUnion(struct {}); | 323 | _ = S.CreateUnion(struct {}); |
| ... | @@ -620,22 +326,13 @@ test "reified union uses @alignOf" { | ... | @@ -620,22 +326,13 @@ test "reified union uses @alignOf" { |
| 620 | test "reified struct uses @alignOf" { | 326 | test "reified struct uses @alignOf" { |
| 621 | const S = struct { | 327 | const S = struct { |
| 622 | fn NamespacedGlobals(comptime modules: anytype) type { | 328 | fn NamespacedGlobals(comptime modules: anytype) type { |
| 623 | return @Type(.{ | 329 | return @Struct( |
| 624 | .@"struct" = .{ | 330 | .auto, |
| 625 | .layout = .auto, | 331 | null, |
| 626 | .is_tuple = false, | 332 | &.{"globals"}, |
| 627 | .fields = &.{ | 333 | &.{modules.mach.globals}, |
| 628 | .{ | 334 | &.{.{ .@"align" = @alignOf(modules.mach.globals) }}, |
| 629 | .name = "globals", | 335 | ); |
| 630 | .type = modules.mach.globals, | ||
| 631 | .default_value_ptr = null, | ||
| 632 | .is_comptime = false, | ||
| 633 | .alignment = @alignOf(modules.mach.globals), | ||
| 634 | }, | ||
| 635 | }, | ||
| 636 | .decls = &.{}, | ||
| 637 | }, | ||
| 638 | }); | ||
| 639 | } | 336 | } |
| 640 | }; | 337 | }; |
| 641 | _ = S.NamespacedGlobals(.{ | 338 | _ = S.NamespacedGlobals(.{ |
| ... | @@ -645,56 +342,10 @@ test "reified struct uses @alignOf" { | ... | @@ -645,56 +342,10 @@ test "reified struct uses @alignOf" { |
| 645 | }); | 342 | }); |
| 646 | } | 343 | } |
| 647 | 344 | ||
| 648 | test "reified error set initialized with field pointer" { | ||
| 649 | const S = struct { | ||
| 650 | const info = .{ | ||
| 651 | .args = [_]Type.Error{ | ||
| 652 | .{ .name = "bar" }, | ||
| 653 | }, | ||
| 654 | }; | ||
| 655 | const Foo = @Type(.{ | ||
| 656 | .error_set = &info.args, | ||
| 657 | }); | ||
| 658 | }; | ||
| 659 | try testing.expect(S.Foo == error{bar}); | ||
| 660 | } | ||
| 661 | test "reified function type params initialized with field pointer" { | ||
| 662 | const S = struct { | ||
| 663 | const fn_info = .{ | ||
| 664 | .params = [_]Type.Fn.Param{ | ||
| 665 | .{ .is_generic = false, .is_noalias = false, .type = u8 }, | ||
| 666 | }, | ||
| 667 | }; | ||
| 668 | const Bar = @Type(.{ | ||
| 669 | .@"fn" = .{ | ||
| 670 | .calling_convention = .auto, | ||
| 671 | .is_generic = false, | ||
| 672 | .is_var_args = false, | ||
| 673 | .return_type = void, | ||
| 674 | .params = &fn_info.params, | ||
| 675 | }, | ||
| 676 | }); | ||
| 677 | }; | ||
| 678 | try testing.expect(@typeInfo(S.Bar) == .@"fn"); | ||
| 679 | } | ||
| 680 | |||
| 681 | test "empty struct assigned to reified struct field" { | 345 | test "empty struct assigned to reified struct field" { |
| 682 | const S = struct { | 346 | const S = struct { |
| 683 | fn NamespacedComponents(comptime modules: anytype) type { | 347 | fn NamespacedComponents(comptime modules: anytype) type { |
| 684 | return @Type(.{ | 348 | return @Struct(.auto, null, &.{"components"}, &.{@TypeOf(modules.components)}, &.{.{}}); |
| 685 | .@"struct" = .{ | ||
| 686 | .layout = .auto, | ||
| 687 | .is_tuple = false, | ||
| 688 | .fields = &.{.{ | ||
| 689 | .name = "components", | ||
| 690 | .type = @TypeOf(modules.components), | ||
| 691 | .default_value_ptr = null, | ||
| 692 | .is_comptime = false, | ||
| 693 | .alignment = @alignOf(@TypeOf(modules.components)), | ||
| 694 | }}, | ||
| 695 | .decls = &.{}, | ||
| 696 | }, | ||
| 697 | }); | ||
| 698 | } | 349 | } |
| 699 | 350 | ||
| 700 | fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) { | 351 | fn namespacedComponents(comptime modules: anytype) NamespacedComponents(modules) { |
| ... | @@ -710,16 +361,6 @@ test "empty struct assigned to reified struct field" { | ... | @@ -710,16 +361,6 @@ test "empty struct assigned to reified struct field" { |
| 710 | }); | 361 | }); |
| 711 | } | 362 | } |
| 712 | 363 | ||
| 713 | test "@Type should resolve its children types" { | ||
| 714 | const sparse = enum(u2) { a, b, c }; | ||
| 715 | const dense = enum(u2) { a, b, c, d }; | ||
| 716 | |||
| 717 | comptime var sparse_info = @typeInfo(anyerror!sparse); | ||
| 718 | sparse_info.error_union.payload = dense; | ||
| 719 | const B = @Type(sparse_info); | ||
| 720 | try testing.expectEqual(anyerror!dense, B); | ||
| 721 | } | ||
| 722 | |||
| 723 | test "struct field names sliced at comptime from larger string" { | 364 | test "struct field names sliced at comptime from larger string" { |
| 724 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | 365 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 725 | 366 | ||
| ... | @@ -729,28 +370,14 @@ test "struct field names sliced at comptime from larger string" { | ... | @@ -729,28 +370,14 @@ test "struct field names sliced at comptime from larger string" { |
| 729 | \\f3 | 370 | \\f3 |
| 730 | ; | 371 | ; |
| 731 | comptime { | 372 | comptime { |
| 732 | var fields: []const Type.StructField = &[0]Type.StructField{}; | 373 | var field_names: []const []const u8 = &.{}; |
| 733 | 374 | ||
| 734 | var it = std.mem.tokenizeScalar(u8, text, '\n'); | 375 | var it = std.mem.tokenizeScalar(u8, text, '\n'); |
| 735 | while (it.next()) |name| { | 376 | while (it.next()) |name| { |
| 736 | fields = fields ++ &[_]Type.StructField{.{ | 377 | field_names = field_names ++ @as([]const []const u8, &.{name}); |
| 737 | .alignment = @alignOf(usize), | ||
| 738 | .name = name ++ "", | ||
| 739 | .type = usize, | ||
| 740 | .default_value_ptr = null, | ||
| 741 | .is_comptime = false, | ||
| 742 | }}; | ||
| 743 | } | 378 | } |
| 744 | 379 | ||
| 745 | const T = @Type(.{ | 380 | const T = @Struct(.auto, null, field_names, &@splat(usize), &@splat(.{})); |
| 746 | .@"struct" = .{ | ||
| 747 | .layout = .auto, | ||
| 748 | .is_tuple = false, | ||
| 749 | .fields = fields, | ||
| 750 | .decls = &.{}, | ||
| 751 | }, | ||
| 752 | }); | ||
| 753 | |||
| 754 | const gen_fields = @typeInfo(T).@"struct".fields; | 381 | const gen_fields = @typeInfo(T).@"struct".fields; |
| 755 | try testing.expectEqual(3, gen_fields.len); | 382 | try testing.expectEqual(3, gen_fields.len); |
| 756 | try testing.expectEqualStrings("f1", gen_fields[0].name); | 383 | try testing.expectEqualStrings("f1", gen_fields[0].name); |
| ... | @@ -762,10 +389,7 @@ test "struct field names sliced at comptime from larger string" { | ... | @@ -762,10 +389,7 @@ test "struct field names sliced at comptime from larger string" { |
| 762 | test "matching captures causes opaque equivalence" { | 389 | test "matching captures causes opaque equivalence" { |
| 763 | const S = struct { | 390 | const S = struct { |
| 764 | fn UnsignedId(comptime I: type) type { | 391 | fn UnsignedId(comptime I: type) type { |
| 765 | const U = @Type(.{ .int = .{ | 392 | const U = @Int(.unsigned, @typeInfo(I).int.bits); |
| 766 | .signedness = .unsigned, | ||
| 767 | .bits = @typeInfo(I).int.bits, | ||
| 768 | } }); | ||
| 769 | return opaque { | 393 | return opaque { |
| 770 | fn id(x: U) U { | 394 | fn id(x: U) U { |
| 771 | return x; | 395 | return x; |
| ... | @@ -785,17 +409,9 @@ test "matching captures causes opaque equivalence" { | ... | @@ -785,17 +409,9 @@ test "matching captures causes opaque equivalence" { |
| 785 | } | 409 | } |
| 786 | 410 | ||
| 787 | test "reify enum where fields refers to part of array" { | 411 | test "reify enum where fields refers to part of array" { |
| 788 | const fields: [3]std.builtin.Type.EnumField = .{ | 412 | const field_names: [3][]const u8 = .{ "foo", "bar", undefined }; |
| 789 | .{ .name = "foo", .value = 0 }, | 413 | const field_values: [3]u8 = .{ undefined, 0, 1 }; |
| 790 | .{ .name = "bar", .value = 1 }, | 414 | const E = @Enum(u8, .exhaustive, field_names[0..2], field_values[1..3]); |
| 791 | undefined, | ||
| 792 | }; | ||
| 793 | const E = @Type(.{ .@"enum" = .{ | ||
| 794 | .tag_type = u8, | ||
| 795 | .fields = fields[0..2], | ||
| 796 | .decls = &.{}, | ||
| 797 | .is_exhaustive = true, | ||
| 798 | } }); | ||
| 799 | var a: E = undefined; | 415 | var a: E = undefined; |
| 800 | var b: E = undefined; | 416 | var b: E = undefined; |
| 801 | a = .foo; | 417 | a = .foo; |
test/behavior/union.zig+2-8| ... | @@ -2198,14 +2198,8 @@ test "matching captures causes union equivalence" { | ... | @@ -2198,14 +2198,8 @@ test "matching captures causes union equivalence" { |
| 2198 | fn SignedUnsigned(comptime I: type) type { | 2198 | fn SignedUnsigned(comptime I: type) type { |
| 2199 | const bits = @typeInfo(I).int.bits; | 2199 | const bits = @typeInfo(I).int.bits; |
| 2200 | return union { | 2200 | return union { |
| 2201 | u: @Type(.{ .int = .{ | 2201 | u: @Int(.unsigned, bits), |
| 2202 | .signedness = .unsigned, | 2202 | i: @Int(.signed, bits), |
| 2203 | .bits = bits, | ||
| 2204 | } }), | ||
| 2205 | i: @Type(.{ .int = .{ | ||
| 2206 | .signedness = .signed, | ||
| 2207 | .bits = bits, | ||
| 2208 | } }), | ||
| 2209 | }; | 2203 | }; |
| 2210 | } | 2204 | } |
| 2211 | }; | 2205 | }; |
test/behavior/x86_64/math.zig+5-14| ... | @@ -36,34 +36,28 @@ pub fn ChangeScalar(comptime Type: type, comptime NewScalar: type) type { | ... | @@ -36,34 +36,28 @@ pub fn ChangeScalar(comptime Type: type, comptime NewScalar: type) type { |
| 36 | } | 36 | } |
| 37 | pub fn AsSignedness(comptime Type: type, comptime signedness: std.builtin.Signedness) type { | 37 | pub fn AsSignedness(comptime Type: type, comptime signedness: std.builtin.Signedness) type { |
| 38 | return switch (@typeInfo(Scalar(Type))) { | 38 | return switch (@typeInfo(Scalar(Type))) { |
| 39 | .int => |int| ChangeScalar(Type, @Type(.{ .int = .{ | 39 | .int => |int| ChangeScalar(Type, @Int(signedness, int.bits)), |
| 40 | .signedness = signedness, | ||
| 41 | .bits = int.bits, | ||
| 42 | } })), | ||
| 43 | .float => Type, | 40 | .float => Type, |
| 44 | else => @compileError(@typeName(Type)), | 41 | else => @compileError(@typeName(Type)), |
| 45 | }; | 42 | }; |
| 46 | } | 43 | } |
| 47 | pub fn AddOneBit(comptime Type: type) type { | 44 | pub fn AddOneBit(comptime Type: type) type { |
| 48 | return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) { | 45 | return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) { |
| 49 | .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = 1 + int.bits } }), | 46 | .int => |int| @Int(int.signedness, 1 + int.bits), |
| 50 | .float => Scalar(Type), | 47 | .float => Scalar(Type), |
| 51 | else => @compileError(@typeName(Type)), | 48 | else => @compileError(@typeName(Type)), |
| 52 | }); | 49 | }); |
| 53 | } | 50 | } |
| 54 | pub fn DoubleBits(comptime Type: type) type { | 51 | pub fn DoubleBits(comptime Type: type) type { |
| 55 | return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) { | 52 | return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) { |
| 56 | .int => |int| @Type(.{ .int = .{ .signedness = int.signedness, .bits = int.bits * 2 } }), | 53 | .int => |int| @Int(int.signedness, int.bits * 2), |
| 57 | .float => Scalar(Type), | 54 | .float => Scalar(Type), |
| 58 | else => @compileError(@typeName(Type)), | 55 | else => @compileError(@typeName(Type)), |
| 59 | }); | 56 | }); |
| 60 | } | 57 | } |
| 61 | pub fn RoundBitsUp(comptime Type: type, comptime multiple: u16) type { | 58 | pub fn RoundBitsUp(comptime Type: type, comptime multiple: u16) type { |
| 62 | return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) { | 59 | return ChangeScalar(Type, switch (@typeInfo(Scalar(Type))) { |
| 63 | .int => |int| @Type(.{ .int = .{ | 60 | .int => |int| @Int(int.signedness, std.mem.alignForward(u16, int.bits, multiple)), |
| 64 | .signedness = int.signedness, | ||
| 65 | .bits = std.mem.alignForward(u16, int.bits, multiple), | ||
| 66 | } }), | ||
| 67 | .float => Scalar(Type), | 61 | .float => Scalar(Type), |
| 68 | else => @compileError(@typeName(Type)), | 62 | else => @compileError(@typeName(Type)), |
| 69 | }); | 63 | }); |
| ... | @@ -83,10 +77,7 @@ pub fn splat(comptime Type: type, scalar: Scalar(Type)) Type { | ... | @@ -83,10 +77,7 @@ pub fn splat(comptime Type: type, scalar: Scalar(Type)) Type { |
| 83 | pub fn sign(rhs: anytype) ChangeScalar(@TypeOf(rhs), bool) { | 77 | pub fn sign(rhs: anytype) ChangeScalar(@TypeOf(rhs), bool) { |
| 84 | const Int = ChangeScalar(@TypeOf(rhs), switch (@typeInfo(Scalar(@TypeOf(rhs)))) { | 78 | const Int = ChangeScalar(@TypeOf(rhs), switch (@typeInfo(Scalar(@TypeOf(rhs)))) { |
| 85 | .int, .comptime_int => Scalar(@TypeOf(rhs)), | 79 | .int, .comptime_int => Scalar(@TypeOf(rhs)), |
| 86 | .float => |float| @Type(.{ .int = .{ | 80 | .float => |float| @Int(.signed, float.bits), |
| 87 | .signedness = .signed, | ||
| 88 | .bits = float.bits, | ||
| 89 | } }), | ||
| 90 | else => @compileError(@typeName(@TypeOf(rhs))), | 81 | else => @compileError(@typeName(@TypeOf(rhs))), |
| 91 | }); | 82 | }); |
| 92 | return @as(Int, @bitCast(rhs)) < splat(Int, 0); | 83 | return @as(Int, @bitCast(rhs)) < splat(Int, 0); |
test/cases/compile_errors/@import_zon_bad_type.zig+1-1| ... | @@ -116,7 +116,7 @@ export fn testMutablePointer() void { | ... | @@ -116,7 +116,7 @@ export fn testMutablePointer() void { |
| 116 | // tmp.zig:85:26: note: ZON does not allow nested optionals | 116 | // tmp.zig:85:26: note: ZON does not allow nested optionals |
| 117 | // tmp.zig:90:29: error: type '*i32' is not available in ZON | 117 | // tmp.zig:90:29: error: type '*i32' is not available in ZON |
| 118 | // tmp.zig:90:29: note: ZON does not allow mutable pointers | 118 | // tmp.zig:90:29: note: ZON does not allow mutable pointers |
| 119 | // neg_inf.zon:1:1: error: expected type '@Type(.enum_literal)' | 119 | // neg_inf.zon:1:1: error: expected type '@EnumLiteral()' |
| 120 | // tmp.zig:37:38: note: imported here | 120 | // tmp.zig:37:38: note: imported here |
| 121 | // neg_inf.zon:1:1: error: expected type '?u8' | 121 | // neg_inf.zon:1:1: error: expected type '?u8' |
| 122 | // tmp.zig:57:28: note: imported here | 122 | // tmp.zig:57:28: note: imported here |
test/cases/compile_errors/@import_zon_opt_in_err.zig+1-1| ... | @@ -70,7 +70,7 @@ export fn testVector() void { | ... | @@ -70,7 +70,7 @@ export fn testVector() void { |
| 70 | // tmp.zig:22:29: note: imported here | 70 | // tmp.zig:22:29: note: imported here |
| 71 | // vec2.zon:1:2: error: expected type '?tmp.Enum' | 71 | // vec2.zon:1:2: error: expected type '?tmp.Enum' |
| 72 | // tmp.zig:28:30: note: imported here | 72 | // tmp.zig:28:30: note: imported here |
| 73 | // vec2.zon:1:2: error: expected type '?@Type(.enum_literal)' | 73 | // vec2.zon:1:2: error: expected type '?@EnumLiteral()' |
| 74 | // tmp.zig:33:39: note: imported here | 74 | // tmp.zig:33:39: note: imported here |
| 75 | // vec2.zon:1:2: error: expected type '?[1]u8' | 75 | // vec2.zon:1:2: error: expected type '?[1]u8' |
| 76 | // tmp.zig:38:31: note: imported here | 76 | // tmp.zig:38:31: note: imported here |
test/cases/compile_errors/align_zero.zig+4-24| ... | @@ -38,31 +38,11 @@ export fn i() void { | ... | @@ -38,31 +38,11 @@ export fn i() void { |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | export fn j() void { | 40 | export fn j() void { |
| 41 | _ = @Type(.{ .@"struct" = .{ | 41 | _ = @Struct(.auto, null, &.{"test"}, &.{u32}, &.{.{ .@"align" = 0 }}); |
| 42 | .layout = .auto, | ||
| 43 | .fields = &.{.{ | ||
| 44 | .name = "test", | ||
| 45 | .type = u32, | ||
| 46 | .default_value_ptr = null, | ||
| 47 | .is_comptime = false, | ||
| 48 | .alignment = 0, | ||
| 49 | }}, | ||
| 50 | .decls = &.{}, | ||
| 51 | .is_tuple = false, | ||
| 52 | } }); | ||
| 53 | } | 42 | } |
| 54 | 43 | ||
| 55 | export fn k() void { | 44 | export fn k() void { |
| 56 | _ = @Type(.{ .pointer = .{ | 45 | _ = @Pointer(.one, .{ .@"align" = 0 }, u32, null); |
| 57 | .size = .one, | ||
| 58 | .is_const = false, | ||
| 59 | .is_volatile = false, | ||
| 60 | .alignment = 0, | ||
| 61 | .address_space = .generic, | ||
| 62 | .child = u32, | ||
| 63 | .is_allowzero = false, | ||
| 64 | .sentinel_ptr = null, | ||
| 65 | } }); | ||
| 66 | } | 46 | } |
| 67 | 47 | ||
| 68 | // error | 48 | // error |
| ... | @@ -76,5 +56,5 @@ export fn k() void { | ... | @@ -76,5 +56,5 @@ export fn k() void { |
| 76 | // :29:17: error: alignment must be >= 1 | 56 | // :29:17: error: alignment must be >= 1 |
| 77 | // :33:35: error: alignment must be >= 1 | 57 | // :33:35: error: alignment must be >= 1 |
| 78 | // :37:34: error: alignment must be >= 1 | 58 | // :37:34: error: alignment must be >= 1 |
| 79 | // :41:9: error: alignment must be >= 1 | 59 | // :41:51: error: alignment must be >= 1 |
| 80 | // :56:9: error: alignment must be >= 1 | 60 | // :45:25: error: alignment must be >= 1 |
test/cases/compile_errors/attempt_to_cast_enum_literal_to_error.zig+1-1| ... | @@ -6,4 +6,4 @@ export fn entry() void { | ... | @@ -6,4 +6,4 @@ export fn entry() void { |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
| 8 | // | 8 | // |
| 9 | // :3:10: error: expected type 'error{Hi}', found '@Type(.enum_literal)' | 9 | // :3:10: error: expected type 'error{Hi}', found '@EnumLiteral()' |
test/cases/compile_errors/attempt_to_create_17_bit_float_type.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | const builtin = @import("std").builtin; | ||
| 2 | comptime { | ||
| 3 | _ = @Type(.{ .float = .{ .bits = 17 } }); | ||
| 4 | } | ||
| 5 | |||
| 6 | // error | ||
| 7 | // | ||
| 8 | // :3:9: error: 17-bit float unsupported | ||
test/cases/compile_errors/enum_with_declarations_unavailable_for_reify_type.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | _ = @Type(@typeInfo(enum { | ||
| 3 | foo, | ||
| 4 | pub const bar = 1; | ||
| 5 | })); | ||
| 6 | } | ||
| 7 | |||
| 8 | // error | ||
| 9 | // | ||
| 10 | // :2:9: error: reified enums must have no decls | ||
test/cases/compile_errors/error_set_decl_literal.zig+1-1| ... | @@ -6,4 +6,4 @@ export fn entry() void { | ... | @@ -6,4 +6,4 @@ export fn entry() void { |
| 6 | 6 | ||
| 7 | // error | 7 | // error |
| 8 | // | 8 | // |
| 9 | // :3:19: error: expected type 'error{Foo}', found '@Type(.enum_literal)' | 9 | // :3:19: error: expected type 'error{Foo}', found '@EnumLiteral()' |
test/cases/compile_errors/invalid_pointer_to_opaque.zig+5-32| ... | @@ -9,40 +9,13 @@ export fn c() void { | ... | @@ -9,40 +9,13 @@ export fn c() void { |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | export fn d() void { | 11 | export fn d() void { |
| 12 | _ = @Type(.{ .pointer = .{ | 12 | _ = @Pointer(.slice, .{}, anyopaque, null); |
| 13 | .size = .slice, | ||
| 14 | .is_const = false, | ||
| 15 | .is_volatile = false, | ||
| 16 | .alignment = 1, | ||
| 17 | .address_space = .generic, | ||
| 18 | .child = anyopaque, | ||
| 19 | .is_allowzero = false, | ||
| 20 | .sentinel_ptr = null, | ||
| 21 | } }); | ||
| 22 | } | 13 | } |
| 23 | export fn e() void { | 14 | export fn e() void { |
| 24 | _ = @Type(.{ .pointer = .{ | 15 | _ = @Pointer(.many, .{}, anyopaque, null); |
| 25 | .size = .many, | ||
| 26 | .is_const = false, | ||
| 27 | .is_volatile = false, | ||
| 28 | .alignment = 1, | ||
| 29 | .address_space = .generic, | ||
| 30 | .child = anyopaque, | ||
| 31 | .is_allowzero = false, | ||
| 32 | .sentinel_ptr = null, | ||
| 33 | } }); | ||
| 34 | } | 16 | } |
| 35 | export fn f() void { | 17 | export fn f() void { |
| 36 | _ = @Type(.{ .pointer = .{ | 18 | _ = @Pointer(.c, .{}, anyopaque, null); |
| 37 | .size = .c, | ||
| 38 | .is_const = false, | ||
| 39 | .is_volatile = false, | ||
| 40 | .alignment = 1, | ||
| 41 | .address_space = .generic, | ||
| 42 | .child = anyopaque, | ||
| 43 | .is_allowzero = false, | ||
| 44 | .sentinel_ptr = null, | ||
| 45 | } }); | ||
| 46 | } | 19 | } |
| 47 | 20 | ||
| 48 | // error | 21 | // error |
| ... | @@ -51,5 +24,5 @@ export fn f() void { | ... | @@ -51,5 +24,5 @@ export fn f() void { |
| 51 | // :5:12: error: indexable pointer to opaque type 'anyopaque' not allowed | 24 | // :5:12: error: indexable pointer to opaque type 'anyopaque' not allowed |
| 52 | // :8:13: error: indexable pointer to opaque type 'anyopaque' not allowed | 25 | // :8:13: error: indexable pointer to opaque type 'anyopaque' not allowed |
| 53 | // :12:9: error: indexable pointer to opaque type 'anyopaque' not allowed | 26 | // :12:9: error: indexable pointer to opaque type 'anyopaque' not allowed |
| 54 | // :24:9: error: indexable pointer to opaque type 'anyopaque' not allowed | 27 | // :15:9: error: indexable pointer to opaque type 'anyopaque' not allowed |
| 55 | // :36:9: error: indexable pointer to opaque type 'anyopaque' not allowed | 28 | // :18:9: error: indexable pointer to opaque type 'anyopaque' not allowed |
test/cases/compile_errors/invalid_pointer_with_reify_type.zig+2-11| ... | @@ -1,16 +1,7 @@ | ... | @@ -1,16 +1,7 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | _ = @Type(.{ .pointer = .{ | 2 | _ = @Pointer(.one, .{}, u8, 0); |
| 3 | .size = .one, | ||
| 4 | .is_const = false, | ||
| 5 | .is_volatile = false, | ||
| 6 | .alignment = 1, | ||
| 7 | .address_space = .generic, | ||
| 8 | .child = u8, | ||
| 9 | .is_allowzero = false, | ||
| 10 | .sentinel_ptr = &@as(u8, 0), | ||
| 11 | } }); | ||
| 12 | } | 3 | } |
| 13 | 4 | ||
| 14 | // error | 5 | // error |
| 15 | // | 6 | // |
| 16 | // :2:9: error: sentinels are only allowed on slices and unknown-length pointers | 7 | // :2:33: error: sentinels are only allowed on slices and unknown-length pointers |
test/cases/compile_errors/minmax_nonnumeric_operand.zig+1-1| ... | @@ -36,4 +36,4 @@ const Union = union { foo: void }; | ... | @@ -36,4 +36,4 @@ const Union = union { foo: void }; |
| 36 | // :13:29: error: expected number, found 'tmp.Union' | 36 | // :13:29: error: expected number, found 'tmp.Union' |
| 37 | // :19:15: note: union declared here | 37 | // :19:15: note: union declared here |
| 38 | // :14:61: error: expected number, found 'fn () u8' | 38 | // :14:61: error: expected number, found 'fn () u8' |
| 39 | // :15:25: error: expected number, found '@Type(.enum_literal)' | 39 | // :15:25: error: expected number, found '@EnumLiteral()' |
test/cases/compile_errors/nested_vectors.zig+2-2| ... | @@ -1,10 +1,10 @@ | ... | @@ -1,10 +1,10 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | const V1 = @Vector(4, u8); | 2 | const V1 = @Vector(4, u8); |
| 3 | const V2 = @Type(.{ .vector = .{ .len = 4, .child = V1 } }); | 3 | const V2 = @Vector(4, V1); |
| 4 | const v: V2 = undefined; | 4 | const v: V2 = undefined; |
| 5 | _ = v; | 5 | _ = v; |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | // error | 8 | // error |
| 9 | // | 9 | // |
| 10 | // :3:16: error: expected integer, float, bool, or pointer for the vector element type; found '@Vector(4, u8)' | 10 | // :3:27: error: expected integer, float, bool, or pointer for the vector element type; found '@Vector(4, u8)' |
test/cases/compile_errors/non_constant_expression_in_array_size.zig+1-1| ... | @@ -14,4 +14,4 @@ export fn entry() usize { | ... | @@ -14,4 +14,4 @@ export fn entry() usize { |
| 14 | // | 14 | // |
| 15 | // :6:12: error: unable to resolve comptime value | 15 | // :6:12: error: unable to resolve comptime value |
| 16 | // :2:12: note: called at comptime from here | 16 | // :2:12: note: called at comptime from here |
| 17 | // :1:13: note: struct fields must be comptime-known | 17 | // :1:13: note: types must be comptime-known |
test/cases/compile_errors/non_scalar_sentinel.zig+4-27| ... | @@ -12,31 +12,10 @@ comptime { | ... | @@ -12,31 +12,10 @@ comptime { |
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | comptime { | 14 | comptime { |
| 15 | _ = @Type(.{ .array = .{ .child = S, .len = 0, .sentinel_ptr = &sentinel } }); | 15 | _ = @Pointer(.slice, .{}, S, sentinel); |
| 16 | } | 16 | } |
| 17 | comptime { | 17 | comptime { |
| 18 | _ = @Type(.{ .pointer = .{ | 18 | _ = @Pointer(.many, .{}, S, sentinel); |
| 19 | .size = .slice, | ||
| 20 | .is_const = false, | ||
| 21 | .is_volatile = false, | ||
| 22 | .alignment = @alignOf(S), | ||
| 23 | .address_space = .generic, | ||
| 24 | .child = S, | ||
| 25 | .is_allowzero = false, | ||
| 26 | .sentinel_ptr = &sentinel, | ||
| 27 | } }); | ||
| 28 | } | ||
| 29 | comptime { | ||
| 30 | _ = @Type(.{ .pointer = .{ | ||
| 31 | .size = .many, | ||
| 32 | .is_const = false, | ||
| 33 | .is_volatile = false, | ||
| 34 | .alignment = @alignOf(S), | ||
| 35 | .address_space = .generic, | ||
| 36 | .child = S, | ||
| 37 | .is_allowzero = false, | ||
| 38 | .sentinel_ptr = &sentinel, | ||
| 39 | } }); | ||
| 40 | } | 19 | } |
| 41 | 20 | ||
| 42 | // error | 21 | // error |
| ... | @@ -47,9 +26,7 @@ comptime { | ... | @@ -47,9 +26,7 @@ comptime { |
| 47 | // :1:11: note: struct declared here | 26 | // :1:11: note: struct declared here |
| 48 | // :11:12: error: non-scalar sentinel type 'tmp.S' | 27 | // :11:12: error: non-scalar sentinel type 'tmp.S' |
| 49 | // :1:11: note: struct declared here | 28 | // :1:11: note: struct declared here |
| 50 | // :15:9: error: non-scalar sentinel type 'tmp.S' | 29 | // :15:34: error: non-scalar sentinel type 'tmp.S' |
| 51 | // :1:11: note: struct declared here | ||
| 52 | // :18:9: error: non-scalar sentinel type 'tmp.S' | ||
| 53 | // :1:11: note: struct declared here | 30 | // :1:11: note: struct declared here |
| 54 | // :30:9: error: non-scalar sentinel type 'tmp.S' | 31 | // :18:33: error: non-scalar sentinel type 'tmp.S' |
| 55 | // :1:11: note: struct declared here | 32 | // :1:11: note: struct declared here |
test/cases/compile_errors/reified_enum_field_value_overflow.zig+2-11| ... | @@ -1,17 +1,8 @@ | ... | @@ -1,17 +1,8 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | const E = @Type(.{ .@"enum" = .{ | 2 | const E = @Enum(u1, .exhaustive, &.{ "f0", "f1", "f2" }, &.{ 0, 1, 2 }); |
| 3 | .tag_type = u1, | ||
| 4 | .fields = &.{ | ||
| 5 | .{ .name = "f0", .value = 0 }, | ||
| 6 | .{ .name = "f1", .value = 1 }, | ||
| 7 | .{ .name = "f2", .value = 2 }, | ||
| 8 | }, | ||
| 9 | .decls = &.{}, | ||
| 10 | .is_exhaustive = true, | ||
| 11 | } }); | ||
| 12 | _ = E; | 3 | _ = E; |
| 13 | } | 4 | } |
| 14 | 5 | ||
| 15 | // error | 6 | // error |
| 16 | // | 7 | // |
| 17 | // :2:15: error: field 'f2' with enumeration value '2' is too large for backing int type 'u1' | 8 | // :2:72: error: type 'u1' cannot represent integer value '2' |
test/cases/compile_errors/reify_enum_with_duplicate_field.zig+3-13| ... | @@ -1,18 +1,8 @@ | ... | @@ -1,18 +1,8 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | _ = @Type(.{ | 2 | _ = @Enum(u32, .nonexhaustive, &.{ "A", "A" }, &.{ 0, 1 }); |
| 3 | .@"enum" = .{ | ||
| 4 | .tag_type = u32, | ||
| 5 | .fields = &.{ | ||
| 6 | .{ .name = "A", .value = 0 }, | ||
| 7 | .{ .name = "A", .value = 1 }, | ||
| 8 | }, | ||
| 9 | .decls = &.{}, | ||
| 10 | .is_exhaustive = false, | ||
| 11 | }, | ||
| 12 | }); | ||
| 13 | } | 3 | } |
| 14 | 4 | ||
| 15 | // error | 5 | // error |
| 16 | // | 6 | // |
| 17 | // :2:9: error: duplicate enum field 'A' | 7 | // :2:36: error: duplicate enum field 'A' |
| 18 | // :2:9: note: other field here | 8 | // :2:36: note: other field here |
test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig+3-13| ... | @@ -1,18 +1,8 @@ | ... | @@ -1,18 +1,8 @@ |
| 1 | export fn entry() void { | 1 | export fn entry() void { |
| 2 | _ = @Type(.{ | 2 | _ = @Enum(u32, .nonexhaustive, &.{ "A", "B" }, &.{ 10, 10 }); |
| 3 | .@"enum" = .{ | ||
| 4 | .tag_type = u32, | ||
| 5 | .fields = &.{ | ||
| 6 | .{ .name = "A", .value = 10 }, | ||
| 7 | .{ .name = "B", .value = 10 }, | ||
| 8 | }, | ||
| 9 | .decls = &.{}, | ||
| 10 | .is_exhaustive = false, | ||
| 11 | }, | ||
| 12 | }); | ||
| 13 | } | 3 | } |
| 14 | 4 | ||
| 15 | // error | 5 | // error |
| 16 | // | 6 | // |
| 17 | // :2:9: error: enum tag value 10 already taken | 7 | // :2:52: error: enum tag value 10 already taken |
| 18 | // :2:9: note: other enum tag value here | 8 | // :2:52: note: other enum tag value here |
test/cases/compile_errors/reify_struct.zig+6-69| ... | @@ -1,79 +1,16 @@ | ... | @@ -1,79 +1,16 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | @Type(.{ .@"struct" = .{ | 2 | @Struct(.auto, null, &.{"foo"}, &.{u32}, &.{.{ .@"comptime" = true }}); |
| 3 | .layout = .auto, | ||
| 4 | .fields = &.{.{ | ||
| 5 | .name = "foo", | ||
| 6 | .type = u32, | ||
| 7 | .default_value_ptr = null, | ||
| 8 | .is_comptime = false, | ||
| 9 | .alignment = 4, | ||
| 10 | }}, | ||
| 11 | .decls = &.{}, | ||
| 12 | .is_tuple = true, | ||
| 13 | } }); | ||
| 14 | } | 3 | } |
| 15 | comptime { | 4 | comptime { |
| 16 | @Type(.{ .@"struct" = .{ | 5 | @Struct(.@"extern", null, &.{"foo"}, &.{u32}, &.{.{ .@"comptime" = true, .default_value_ptr = &@as(u32, 10) }}); |
| 17 | .layout = .auto, | ||
| 18 | .fields = &.{.{ | ||
| 19 | .name = "3", | ||
| 20 | .type = u32, | ||
| 21 | .default_value_ptr = null, | ||
| 22 | .is_comptime = false, | ||
| 23 | .alignment = 4, | ||
| 24 | }}, | ||
| 25 | .decls = &.{}, | ||
| 26 | .is_tuple = true, | ||
| 27 | } }); | ||
| 28 | } | 6 | } |
| 29 | comptime { | 7 | comptime { |
| 30 | @Type(.{ .@"struct" = .{ | 8 | @Struct(.@"packed", null, &.{"foo"}, &.{u32}, &.{.{ .@"align" = 4 }}); |
| 31 | .layout = .auto, | ||
| 32 | .fields = &.{.{ | ||
| 33 | .name = "0", | ||
| 34 | .type = u32, | ||
| 35 | .default_value_ptr = null, | ||
| 36 | .is_comptime = true, | ||
| 37 | .alignment = 4, | ||
| 38 | }}, | ||
| 39 | .decls = &.{}, | ||
| 40 | .is_tuple = true, | ||
| 41 | } }); | ||
| 42 | } | ||
| 43 | comptime { | ||
| 44 | @Type(.{ .@"struct" = .{ | ||
| 45 | .layout = .@"extern", | ||
| 46 | .fields = &.{.{ | ||
| 47 | .name = "0", | ||
| 48 | .type = u32, | ||
| 49 | .default_value_ptr = null, | ||
| 50 | .is_comptime = true, | ||
| 51 | .alignment = 4, | ||
| 52 | }}, | ||
| 53 | .decls = &.{}, | ||
| 54 | .is_tuple = false, | ||
| 55 | } }); | ||
| 56 | } | ||
| 57 | comptime { | ||
| 58 | @Type(.{ .@"struct" = .{ | ||
| 59 | .layout = .@"packed", | ||
| 60 | .fields = &.{.{ | ||
| 61 | .name = "0", | ||
| 62 | .type = u32, | ||
| 63 | .default_value_ptr = null, | ||
| 64 | .is_comptime = true, | ||
| 65 | .alignment = 4, | ||
| 66 | }}, | ||
| 67 | .decls = &.{}, | ||
| 68 | .is_tuple = false, | ||
| 69 | } }); | ||
| 70 | } | 9 | } |
| 71 | 10 | ||
| 72 | // error | 11 | // error |
| 73 | // | 12 | // |
| 74 | // :2:5: error: tuple cannot have non-numeric field 'foo' | 13 | // :2:46: error: comptime field without default initialization value |
| 75 | // :16:5: error: tuple field name '3' does not match field index 0 | 14 | // :5:51: error: extern struct fields cannot be marked comptime |
| 76 | // :30:5: error: comptime field without default initialization value | 15 | // :8:51: error: packed struct fields cannot be aligned |
| 77 | // :44:5: error: extern struct fields cannot be marked comptime | ||
| 78 | // :58:5: error: alignment of a packed struct field must be set to 0 | ||
| 79 | 16 |
test/cases/compile_errors/reify_type.Fn_with_is_generic_true.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const Foo = @Type(.{ | ||
| 2 | .@"fn" = .{ | ||
| 3 | .calling_convention = .auto, | ||
| 4 | .is_generic = true, | ||
| 5 | .is_var_args = false, | ||
| 6 | .return_type = u0, | ||
| 7 | .params = &.{}, | ||
| 8 | }, | ||
| 9 | }); | ||
| 10 | comptime { | ||
| 11 | _ = Foo; | ||
| 12 | } | ||
| 13 | |||
| 14 | // error | ||
| 15 | // | ||
| 16 | // :1:13: error: Type.Fn.is_generic must be false for @Type | ||
test/cases/compile_errors/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig+3-12| ... | @@ -1,18 +1,9 @@ | ... | @@ -1,18 +1,9 @@ |
| 1 | const Foo = @Type(.{ | ||
| 2 | .@"fn" = .{ | ||
| 3 | .calling_convention = .auto, | ||
| 4 | .is_generic = false, | ||
| 5 | .is_var_args = true, | ||
| 6 | .return_type = u0, | ||
| 7 | .params = &.{}, | ||
| 8 | }, | ||
| 9 | }); | ||
| 10 | comptime { | 1 | comptime { |
| 11 | _ = Foo; | 2 | _ = @Fn(&.{u32}, &.{.{}}, u8, .{ .varargs = true }); |
| 12 | } | 3 | } |
| 13 | 4 | ||
| 14 | // error | 5 | // error |
| 15 | // target=x86_64-linux | 6 | // target=x86_64-linux |
| 16 | // | 7 | // |
| 17 | // :1:13: error: variadic function does not support 'auto' calling convention | 8 | // :2:36: error: variadic function does not support 'auto' calling convention |
| 18 | // :1:13: note: supported calling conventions: 'x86_64_sysv', 'x86_64_x32', 'x86_64_win' | 9 | // :2:36: note: supported calling conventions: 'x86_64_sysv', 'x86_64_x32', 'x86_64_win' |
test/cases/compile_errors/reify_type.Fn_with_return_type_null.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const Foo = @Type(.{ | ||
| 2 | .@"fn" = .{ | ||
| 3 | .calling_convention = .auto, | ||
| 4 | .is_generic = false, | ||
| 5 | .is_var_args = false, | ||
| 6 | .return_type = null, | ||
| 7 | .params = &.{}, | ||
| 8 | }, | ||
| 9 | }); | ||
| 10 | comptime { | ||
| 11 | _ = Foo; | ||
| 12 | } | ||
| 13 | |||
| 14 | // error | ||
| 15 | // | ||
| 16 | // :1:13: error: Type.Fn.return_type must be non-null for @Type | ||
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig+2-9| ... | @@ -1,15 +1,8 @@ | ... | @@ -1,15 +1,8 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(bool, .nonexhaustive, &.{}, &.{}); |
| 2 | .@"enum" = .{ | ||
| 3 | .tag_type = bool, | ||
| 4 | .fields = &.{}, | ||
| 5 | .decls = &.{}, | ||
| 6 | .is_exhaustive = false, | ||
| 7 | }, | ||
| 8 | }); | ||
| 9 | export fn entry() void { | 2 | export fn entry() void { |
| 10 | _ = @as(Tag, @enumFromInt(0)); | 3 | _ = @as(Tag, @enumFromInt(0)); |
| 11 | } | 4 | } |
| 12 | 5 | ||
| 13 | // error | 6 | // error |
| 14 | // | 7 | // |
| 15 | // :1:13: error: Type.Enum.tag_type must be an integer type | 8 | // :1:19: error: tag type must be an integer type |
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig+2-9| ... | @@ -1,15 +1,8 @@ | ... | @@ -1,15 +1,8 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(undefined, .exhaustive, &.{}, &.{}); |
| 2 | .@"enum" = .{ | ||
| 3 | .tag_type = undefined, | ||
| 4 | .fields = &.{}, | ||
| 5 | .decls = &.{}, | ||
| 6 | .is_exhaustive = false, | ||
| 7 | }, | ||
| 8 | }); | ||
| 9 | export fn entry() void { | 2 | export fn entry() void { |
| 10 | _ = @as(Tag, @enumFromInt(0)); | 3 | _ = @as(Tag, @enumFromInt(0)); |
| 11 | } | 4 | } |
| 12 | 5 | ||
| 13 | // error | 6 | // error |
| 14 | // | 7 | // |
| 15 | // :1:20: error: use of undefined value here causes illegal behavior | 8 | // :1:19: error: use of undefined value here causes illegal behavior |
test/cases/compile_errors/reify_type_for_tagged_extern_union.zig+3-24| ... | @@ -1,26 +1,5 @@ | ... | @@ -1,26 +1,5 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(u2, .exhaustive, &.{ "signed", "unsigned" }, &.{ 0, 1 }); |
| 2 | .@"enum" = .{ | 2 | const Extern = @Union(.@"extern", Tag, &.{ "signed", "unsigned" }, &.{ i32, u32 }, &@splat(.{})); |
| 3 | .tag_type = u2, | ||
| 4 | .fields = &.{ | ||
| 5 | .{ .name = "signed", .value = 0 }, | ||
| 6 | .{ .name = "unsigned", .value = 1 }, | ||
| 7 | }, | ||
| 8 | .decls = &.{}, | ||
| 9 | .is_exhaustive = true, | ||
| 10 | }, | ||
| 11 | }); | ||
| 12 | |||
| 13 | const Extern = @Type(.{ | ||
| 14 | .@"union" = .{ | ||
| 15 | .layout = .@"extern", | ||
| 16 | .tag_type = Tag, | ||
| 17 | .fields = &.{ | ||
| 18 | .{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
| 19 | .{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
| 20 | }, | ||
| 21 | .decls = &.{}, | ||
| 22 | }, | ||
| 23 | }); | ||
| 24 | 3 | ||
| 25 | export fn entry() void { | 4 | export fn entry() void { |
| 26 | const tagged: Extern = .{ .signed = -1 }; | 5 | const tagged: Extern = .{ .signed = -1 }; |
| ... | @@ -29,4 +8,4 @@ export fn entry() void { | ... | @@ -29,4 +8,4 @@ export fn entry() void { |
| 29 | 8 | ||
| 30 | // error | 9 | // error |
| 31 | // | 10 | // |
| 32 | // :13:16: error: extern union does not support enum tag type | 11 | // :2:35: error: extern union does not support enum tag type |
test/cases/compile_errors/reify_type_for_tagged_packed_union.zig+3-24| ... | @@ -1,26 +1,5 @@ | ... | @@ -1,26 +1,5 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(u2, .exhaustive, &.{ "signed", "unsigned" }, &.{ 0, 1 }); |
| 2 | .@"enum" = .{ | 2 | const Packed = @Union(.@"packed", Tag, &.{ "signed", "unsigned" }, &.{ i32, u32 }, &@splat(.{})); |
| 3 | .tag_type = u2, | ||
| 4 | .fields = &.{ | ||
| 5 | .{ .name = "signed", .value = 0 }, | ||
| 6 | .{ .name = "unsigned", .value = 1 }, | ||
| 7 | }, | ||
| 8 | .decls = &.{}, | ||
| 9 | .is_exhaustive = true, | ||
| 10 | }, | ||
| 11 | }); | ||
| 12 | |||
| 13 | const Packed = @Type(.{ | ||
| 14 | .@"union" = .{ | ||
| 15 | .layout = .@"packed", | ||
| 16 | .tag_type = Tag, | ||
| 17 | .fields = &.{ | ||
| 18 | .{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
| 19 | .{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
| 20 | }, | ||
| 21 | .decls = &.{}, | ||
| 22 | }, | ||
| 23 | }); | ||
| 24 | 3 | ||
| 25 | export fn entry() void { | 4 | export fn entry() void { |
| 26 | const tagged: Packed = .{ .signed = -1 }; | 5 | const tagged: Packed = .{ .signed = -1 }; |
| ... | @@ -29,4 +8,4 @@ export fn entry() void { | ... | @@ -29,4 +8,4 @@ export fn entry() void { |
| 29 | 8 | ||
| 30 | // error | 9 | // error |
| 31 | // | 10 | // |
| 32 | // :13:16: error: packed union does not support enum tag type | 11 | // :2:35: error: packed union does not support enum tag type |
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig+3-24| ... | @@ -1,26 +1,5 @@ | ... | @@ -1,26 +1,5 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(u2, .exhaustive, &.{ "signed", "unsigned", "arst" }, &.{ 0, 1, 2 }); |
| 2 | .@"enum" = .{ | 2 | const Tagged = @Union(.auto, Tag, &.{ "signed", "unsigned" }, &.{ i32, u32 }, &@splat(.{})); |
| 3 | .tag_type = u2, | ||
| 4 | .fields = &.{ | ||
| 5 | .{ .name = "signed", .value = 0 }, | ||
| 6 | .{ .name = "unsigned", .value = 1 }, | ||
| 7 | .{ .name = "arst", .value = 2 }, | ||
| 8 | }, | ||
| 9 | .decls = &.{}, | ||
| 10 | .is_exhaustive = true, | ||
| 11 | }, | ||
| 12 | }); | ||
| 13 | const Tagged = @Type(.{ | ||
| 14 | .@"union" = .{ | ||
| 15 | .layout = .auto, | ||
| 16 | .tag_type = Tag, | ||
| 17 | .fields = &.{ | ||
| 18 | .{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
| 19 | .{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
| 20 | }, | ||
| 21 | .decls = &.{}, | ||
| 22 | }, | ||
| 23 | }); | ||
| 24 | export fn entry() void { | 3 | export fn entry() void { |
| 25 | var tagged = Tagged{ .signed = -1 }; | 4 | var tagged = Tagged{ .signed = -1 }; |
| 26 | tagged = .{ .unsigned = 1 }; | 5 | tagged = .{ .unsigned = 1 }; |
| ... | @@ -28,6 +7,6 @@ export fn entry() void { | ... | @@ -28,6 +7,6 @@ export fn entry() void { |
| 28 | 7 | ||
| 29 | // error | 8 | // error |
| 30 | // | 9 | // |
| 31 | // :13:16: error: enum fields missing in union | 10 | // :2:35: error: 1 enum fields missing in union |
| 32 | // :1:13: note: field 'arst' missing, declared here | 11 | // :1:13: note: field 'arst' missing, declared here |
| 33 | // :1:13: note: enum declared here | 12 | // :1:13: note: enum declared here |
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig+3-24| ... | @@ -1,26 +1,5 @@ | ... | @@ -1,26 +1,5 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(u1, .exhaustive, &.{ "signed", "unsigned" }, &.{ 0, 1 }); |
| 2 | .@"enum" = .{ | 2 | const Tagged = @Union(.auto, Tag, &.{ "signed", "unsigned", "arst" }, &.{ i32, u32, f32 }, &@splat(.{})); |
| 3 | .tag_type = u1, | ||
| 4 | .fields = &.{ | ||
| 5 | .{ .name = "signed", .value = 0 }, | ||
| 6 | .{ .name = "unsigned", .value = 1 }, | ||
| 7 | }, | ||
| 8 | .decls = &.{}, | ||
| 9 | .is_exhaustive = true, | ||
| 10 | }, | ||
| 11 | }); | ||
| 12 | const Tagged = @Type(.{ | ||
| 13 | .@"union" = .{ | ||
| 14 | .layout = .auto, | ||
| 15 | .tag_type = Tag, | ||
| 16 | .fields = &.{ | ||
| 17 | .{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
| 18 | .{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
| 19 | .{ .name = "arst", .type = f32, .alignment = @alignOf(f32) }, | ||
| 20 | }, | ||
| 21 | .decls = &.{}, | ||
| 22 | }, | ||
| 23 | }); | ||
| 24 | export fn entry() void { | 3 | export fn entry() void { |
| 25 | var tagged = Tagged{ .signed = -1 }; | 4 | var tagged = Tagged{ .signed = -1 }; |
| 26 | tagged = .{ .unsigned = 1 }; | 5 | tagged = .{ .unsigned = 1 }; |
| ... | @@ -28,5 +7,5 @@ export fn entry() void { | ... | @@ -28,5 +7,5 @@ export fn entry() void { |
| 28 | 7 | ||
| 29 | // error | 8 | // error |
| 30 | // | 9 | // |
| 31 | // :12:16: error: no field named 'arst' in enum 'tmp.Tag' | 10 | // :2:35: error: no field named 'arst' in enum 'tmp.Tag' |
| 32 | // :1:13: note: enum declared here | 11 | // :1:13: note: enum declared here |
test/cases/compile_errors/reify_type_for_tagged_union_with_no_enum_fields.zig+3-20| ... | @@ -1,22 +1,5 @@ | ... | @@ -1,22 +1,5 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(u0, .exhaustive, &.{}, &.{}); |
| 2 | .@"enum" = .{ | 2 | const Tagged = @Union(.auto, Tag, &.{ "signed", "unsigned" }, &.{ i32, u32 }, &@splat(.{})); |
| 3 | .tag_type = u0, | ||
| 4 | .fields = &.{}, | ||
| 5 | .decls = &.{}, | ||
| 6 | .is_exhaustive = true, | ||
| 7 | }, | ||
| 8 | }); | ||
| 9 | const Tagged = @Type(.{ | ||
| 10 | .@"union" = .{ | ||
| 11 | .layout = .auto, | ||
| 12 | .tag_type = Tag, | ||
| 13 | .fields = &.{ | ||
| 14 | .{ .name = "signed", .type = i32, .alignment = @alignOf(i32) }, | ||
| 15 | .{ .name = "unsigned", .type = u32, .alignment = @alignOf(u32) }, | ||
| 16 | }, | ||
| 17 | .decls = &.{}, | ||
| 18 | }, | ||
| 19 | }); | ||
| 20 | export fn entry() void { | 3 | export fn entry() void { |
| 21 | const tagged: Tagged = undefined; | 4 | const tagged: Tagged = undefined; |
| 22 | _ = tagged; | 5 | _ = tagged; |
| ... | @@ -24,5 +7,5 @@ export fn entry() void { | ... | @@ -24,5 +7,5 @@ export fn entry() void { |
| 24 | 7 | ||
| 25 | // error | 8 | // error |
| 26 | // | 9 | // |
| 27 | // :9:16: error: no field named 'signed' in enum 'tmp.Tag' | 10 | // :2:35: error: no field named 'signed' in enum 'tmp.Tag' |
| 28 | // :1:13: note: enum declared here | 11 | // :1:13: note: enum declared here |
test/cases/compile_errors/reify_type_for_tagged_union_with_no_union_fields.zig+3-20| ... | @@ -1,22 +1,5 @@ | ... | @@ -1,22 +1,5 @@ |
| 1 | const Tag = @Type(.{ | 1 | const Tag = @Enum(u1, .exhaustive, &.{ "signed", "unsigned" }, &.{ 0, 1 }); |
| 2 | .@"enum" = .{ | 2 | const Tagged = @Union(.auto, Tag, &.{}, &.{}, &.{}); |
| 3 | .tag_type = u1, | ||
| 4 | .fields = &.{ | ||
| 5 | .{ .name = "signed", .value = 0 }, | ||
| 6 | .{ .name = "unsigned", .value = 1 }, | ||
| 7 | }, | ||
| 8 | .decls = &.{}, | ||
| 9 | .is_exhaustive = true, | ||
| 10 | }, | ||
| 11 | }); | ||
| 12 | const Tagged = @Type(.{ | ||
| 13 | .@"union" = .{ | ||
| 14 | .layout = .auto, | ||
| 15 | .tag_type = Tag, | ||
| 16 | .fields = &.{}, | ||
| 17 | .decls = &.{}, | ||
| 18 | }, | ||
| 19 | }); | ||
| 20 | export fn entry() void { | 3 | export fn entry() void { |
| 21 | const tagged: Tagged = undefined; | 4 | const tagged: Tagged = undefined; |
| 22 | _ = tagged; | 5 | _ = tagged; |
| ... | @@ -24,7 +7,7 @@ export fn entry() void { | ... | @@ -24,7 +7,7 @@ export fn entry() void { |
| 24 | 7 | ||
| 25 | // error | 8 | // error |
| 26 | // | 9 | // |
| 27 | // :12:16: error: enum fields missing in union | 10 | // :2:35: error: 2 enum fields missing in union |
| 28 | // :1:13: note: field 'signed' missing, declared here | 11 | // :1:13: note: field 'signed' missing, declared here |
| 29 | // :1:13: note: field 'unsigned' missing, declared here | 12 | // :1:13: note: field 'unsigned' missing, declared here |
| 30 | // :1:13: note: enum declared here | 13 | // :1:13: note: enum declared here |
test/cases/compile_errors/reify_type_for_union_with_opaque_field.zig+3-12| ... | @@ -1,18 +1,9 @@ | ... | @@ -1,18 +1,9 @@ |
| 1 | const Untagged = @Type(.{ | 1 | const Untagged = @Union(.auto, null, &.{"foo"}, &.{opaque {}}, &.{.{}}); |
| 2 | .@"union" = .{ | ||
| 3 | .layout = .auto, | ||
| 4 | .tag_type = null, | ||
| 5 | .fields = &.{ | ||
| 6 | .{ .name = "foo", .type = opaque {}, .alignment = 1 }, | ||
| 7 | }, | ||
| 8 | .decls = &.{}, | ||
| 9 | }, | ||
| 10 | }); | ||
| 11 | export fn entry() usize { | 2 | export fn entry() usize { |
| 12 | return @sizeOf(Untagged); | 3 | return @sizeOf(Untagged); |
| 13 | } | 4 | } |
| 14 | 5 | ||
| 15 | // error | 6 | // error |
| 16 | // | 7 | // |
| 17 | // :1:18: error: opaque types have unknown size and therefore cannot be directly embedded in unions | 8 | // :1:49: error: opaque types have unknown size and therefore cannot be directly embedded in unions |
| 18 | // :6:39: note: opaque declared here | 9 | // :1:52: note: opaque declared here |
test/cases/compile_errors/reify_type_union_payload_is_undefined.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | const Foo = @Type(.{ | ||
| 2 | .@"struct" = undefined, | ||
| 3 | }); | ||
| 4 | comptime { | ||
| 5 | _ = Foo; | ||
| 6 | } | ||
| 7 | |||
| 8 | // error | ||
| 9 | // | ||
| 10 | // :1:20: error: use of undefined value here causes illegal behavior | ||
test/cases/compile_errors/reify_type_with_Type.Int.zig deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | const builtin = @import("std").builtin; | ||
| 2 | export fn entry() void { | ||
| 3 | _ = @Type(builtin.Type.Int{ | ||
| 4 | .signedness = .signed, | ||
| 5 | .bits = 8, | ||
| 6 | }); | ||
| 7 | } | ||
| 8 | |||
| 9 | // error | ||
| 10 | // | ||
| 11 | // :3:31: error: expected type 'builtin.Type', found 'builtin.Type.Int' | ||
| 12 | // :?:?: note: struct declared here | ||
| 13 | // :?:?: note: union declared here | ||
test/cases/compile_errors/reify_type_with_invalid_field_alignment.zig+6-39| ... | @@ -1,48 +1,15 @@ | ... | @@ -1,48 +1,15 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | _ = @Type(.{ | 2 | _ = @Union(.auto, null, &.{"foo"}, &.{usize}, &.{.{ .@"align" = 3 }}); |
| 3 | .@"union" = .{ | ||
| 4 | .layout = .auto, | ||
| 5 | .tag_type = null, | ||
| 6 | .fields = &.{ | ||
| 7 | .{ .name = "foo", .type = usize, .alignment = 3 }, | ||
| 8 | }, | ||
| 9 | .decls = &.{}, | ||
| 10 | }, | ||
| 11 | }); | ||
| 12 | } | 3 | } |
| 13 | comptime { | 4 | comptime { |
| 14 | _ = @Type(.{ | 5 | _ = @Struct(.auto, null, &.{"a"}, &.{u32}, &.{.{ .@"comptime" = true, .@"align" = 5 }}); |
| 15 | .@"struct" = .{ | ||
| 16 | .layout = .auto, | ||
| 17 | .fields = &.{.{ | ||
| 18 | .name = "0", | ||
| 19 | .type = u32, | ||
| 20 | .default_value_ptr = null, | ||
| 21 | .is_comptime = true, | ||
| 22 | .alignment = 5, | ||
| 23 | }}, | ||
| 24 | .decls = &.{}, | ||
| 25 | .is_tuple = false, | ||
| 26 | }, | ||
| 27 | }); | ||
| 28 | } | 6 | } |
| 29 | comptime { | 7 | comptime { |
| 30 | _ = @Type(.{ | 8 | _ = @Pointer(.many, .{ .@"align" = 7 }, u8, null); |
| 31 | .pointer = .{ | ||
| 32 | .size = .many, | ||
| 33 | .is_const = true, | ||
| 34 | .is_volatile = false, | ||
| 35 | .alignment = 7, | ||
| 36 | .address_space = .generic, | ||
| 37 | .child = u8, | ||
| 38 | .is_allowzero = false, | ||
| 39 | .sentinel_ptr = null, | ||
| 40 | }, | ||
| 41 | }); | ||
| 42 | } | 9 | } |
| 43 | 10 | ||
| 44 | // error | 11 | // error |
| 45 | // | 12 | // |
| 46 | // :2:9: error: alignment value '3' is not a power of two | 13 | // :2:51: error: alignment value '3' is not a power of two |
| 47 | // :14:9: error: alignment value '5' is not a power of two | 14 | // :5:48: error: alignment value '5' is not a power of two |
| 48 | // :30:9: error: alignment value '7' is not a power of two | 15 | // :8:26: error: alignment value '7' is not a power of two |
test/cases/compile_errors/reify_type_with_undefined.zig+4-24| ... | @@ -1,31 +1,11 @@ | ... | @@ -1,31 +1,11 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | _ = @Type(.{ .array = .{ .len = 0, .child = u8, .sentinel_ptr = undefined } }); | 2 | _ = @Struct(.auto, null, &.{}, &.{}, undefined); |
| 3 | } | 3 | } |
| 4 | comptime { | 4 | comptime { |
| 5 | _ = @Type(.{ | 5 | _ = @Struct(.auto, null, &.{"foo"}, &.{undefined}, &.{.{}}); |
| 6 | .@"struct" = .{ | ||
| 7 | .fields = undefined, | ||
| 8 | .decls = undefined, | ||
| 9 | .is_tuple = false, | ||
| 10 | .layout = .auto, | ||
| 11 | }, | ||
| 12 | }); | ||
| 13 | } | ||
| 14 | comptime { | ||
| 15 | const std = @import("std"); | ||
| 16 | const fields: [1]std.builtin.Type.StructField = undefined; | ||
| 17 | _ = @Type(.{ | ||
| 18 | .@"struct" = .{ | ||
| 19 | .layout = .auto, | ||
| 20 | .fields = &fields, | ||
| 21 | .decls = &.{}, | ||
| 22 | .is_tuple = false, | ||
| 23 | }, | ||
| 24 | }); | ||
| 25 | } | 6 | } |
| 26 | 7 | ||
| 27 | // error | 8 | // error |
| 28 | // | 9 | // |
| 29 | // :2:16: error: use of undefined value here causes illegal behavior | 10 | // :2:42: error: use of undefined value here causes illegal behavior |
| 30 | // :5:16: error: use of undefined value here causes illegal behavior | 11 | // :5:41: error: use of undefined value here causes illegal behavior |
| 31 | // :17:16: error: use of undefined value here causes illegal behavior |
test/cases/compile_errors/runtime_condition_comptime_type_in_destructure.zig+1-1| ... | @@ -7,4 +7,4 @@ export fn foobar() void { | ... | @@ -7,4 +7,4 @@ export fn foobar() void { |
| 7 | 7 | ||
| 8 | // error | 8 | // error |
| 9 | // | 9 | // |
| 10 | // :4:5: error: value with comptime-only type '@Type(.enum_literal)' depends on runtime control flow | 10 | // :4:5: error: value with comptime-only type '@EnumLiteral()' depends on runtime control flow |
test/cases/compile_errors/struct_with_declarations_unavailable_for_reify_type.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | export fn entry() void { | ||
| 2 | _ = @Type(@typeInfo(struct { | ||
| 3 | pub const foo = 1; | ||
| 4 | })); | ||
| 5 | } | ||
| 6 | |||
| 7 | // error | ||
| 8 | // | ||
| 9 | // :2:9: error: reified structs must have no decls | ||
test/cases/compile_errors/tagName_on_undef_enum_literal.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | comptime { | 1 | comptime { |
| 2 | const undef: @Type(.enum_literal) = undefined; | 2 | const undef: @EnumLiteral() = undefined; |
| 3 | _ = @tagName(undef); | 3 | _ = @tagName(undef); |
| 4 | } | 4 | } |
| 5 | 5 |
test/cases/compile_errors/unable_to_evaluate_comptime_expr.zig+1-1| ... | @@ -42,4 +42,4 @@ pub export fn entry3() void { | ... | @@ -42,4 +42,4 @@ pub export fn entry3() void { |
| 42 | // :13:13: note: initializer of container-level variable must be comptime-known | 42 | // :13:13: note: initializer of container-level variable must be comptime-known |
| 43 | // :22:9: error: unable to evaluate comptime expression | 43 | // :22:9: error: unable to evaluate comptime expression |
| 44 | // :22:21: note: operation is runtime due to this operand | 44 | // :22:21: note: operation is runtime due to this operand |
| 45 | // :21:13: note: enum fields must be comptime-known | 45 | // :21:13: note: enum field values must be comptime-known |
test/cases/compile_errors/wrong_type_for_reify_type.zig+21-4| ... | @@ -1,8 +1,25 @@ | ... | @@ -1,8 +1,25 @@ |
| 1 | export fn entry() void { | 1 | export fn entryI() void { |
| 2 | _ = @Type(0); | 2 | _ = @Int(0, 0); |
| 3 | } | ||
| 4 | |||
| 5 | export fn entryE() void { | ||
| 6 | _ = @Enum(0, 0, 0, 0); | ||
| 7 | } | ||
| 8 | |||
| 9 | export fn entryS() void { | ||
| 10 | _ = @Struct(0, 0, &.{}, &.{}, &.{}); | ||
| 11 | } | ||
| 12 | |||
| 13 | export fn entryU() void { | ||
| 14 | _ = @Union(0, 0, &.{}, &.{}, &.{}); | ||
| 3 | } | 15 | } |
| 4 | 16 | ||
| 5 | // error | 17 | // error |
| 6 | // | 18 | // |
| 7 | // :2:15: error: expected type 'builtin.Type', found 'comptime_int' | 19 | // :2:14: error: expected type 'builtin.Signedness', found 'comptime_int' |
| 8 | // :?:?: note: union declared here | 20 | // :?:?: note: enum declared here |
| 21 | // :6:15: error: expected type 'type', found 'comptime_int' | ||
| 22 | // :10:17: error: expected type 'builtin.Type.ContainerLayout', found 'comptime_int' | ||
| 23 | // :?:?: enum declared here | ||
| 24 | // :14:16: error: expected type 'builtin.Type.ContainerLayout', found 'comptime_int' | ||
| 25 | // :?:?: enum declared here |
test/cases/default_value_references_comptime_var.zig+13-35| ... | @@ -2,49 +2,27 @@ export fn foo() void { | ... | @@ -2,49 +2,27 @@ export fn foo() void { |
| 2 | comptime var a: u8 = 0; | 2 | comptime var a: u8 = 0; |
| 3 | _ = struct { comptime *u8 = &a }; | 3 | _ = struct { comptime *u8 = &a }; |
| 4 | } | 4 | } |
| 5 | export fn bar() void { | ||
| 6 | comptime var a: u8 = 0; | ||
| 7 | _ = @Type(.{ .@"struct" = .{ | ||
| 8 | .layout = .auto, | ||
| 9 | .fields = &.{.{ | ||
| 10 | .name = "0", | ||
| 11 | .type = *u8, | ||
| 12 | .default_value_ptr = @ptrCast(&&a), | ||
| 13 | .is_comptime = true, | ||
| 14 | .alignment = @alignOf(*u8), | ||
| 15 | }}, | ||
| 16 | .decls = &.{}, | ||
| 17 | .is_tuple = true, | ||
| 18 | } }); | ||
| 19 | } | ||
| 20 | 5 | ||
| 21 | export fn baz() void { | 6 | export fn bar() void { |
| 22 | comptime var a: u8 = 0; | 7 | comptime var a: u8 = 0; |
| 23 | _ = struct { foo: *u8 = &a }; | 8 | _ = struct { foo: *u8 = &a }; |
| 24 | } | 9 | } |
| 25 | export fn qux() void { | 10 | export fn baz() void { |
| 26 | comptime var a: u8 = 0; | 11 | comptime var a: u8 = 0; |
| 27 | _ = @Type(.{ .@"struct" = .{ | 12 | _ = @Struct( |
| 28 | .layout = .auto, | 13 | .auto, |
| 29 | .fields = &.{.{ | 14 | null, |
| 30 | .name = "foo", | 15 | &.{"foo"}, |
| 31 | .type = *u8, | 16 | &.{*u8}, |
| 32 | .default_value_ptr = @ptrCast(&&a), | 17 | &.{.{ .default_value_ptr = @ptrCast(&&a) }}, |
| 33 | .is_comptime = false, | 18 | ); |
| 34 | .alignment = @alignOf(*u8), | ||
| 35 | }}, | ||
| 36 | .decls = &.{}, | ||
| 37 | .is_tuple = false, | ||
| 38 | } }); | ||
| 39 | } | 19 | } |
| 40 | 20 | ||
| 41 | // error | 21 | // error |
| 42 | // | 22 | // |
| 43 | // :3:33: error: field default value contains reference to comptime var | 23 | // :3:33: error: field default value contains reference to comptime var |
| 44 | // :2:14: note: '0' points to comptime var declared here | 24 | // :2:14: note: '0' points to comptime var declared here |
| 45 | // :7:9: error: field default value contains reference to comptime var | 25 | // :8:9: error: captured value contains reference to comptime var |
| 46 | // :6:14: note: '0' points to comptime var declared here | 26 | // :7:14: note: 'a' points to comptime var declared here |
| 47 | // :23:9: error: captured value contains reference to comptime var | 27 | // :17:9: error: field default value contains reference to comptime var |
| 48 | // :22:14: note: 'a' points to comptime var declared here | 28 | // :11:14: note: 'foo' points to comptime var declared here |
| 49 | // :27:9: error: field default value contains reference to comptime var | ||
| 50 | // :26:14: note: 'foo' points to comptime var declared here |
test/cases/sentinel_references_comptime_var.zig+5-24| ... | @@ -2,14 +2,6 @@ export fn foo() void { | ... | @@ -2,14 +2,6 @@ export fn foo() void { |
| 2 | comptime var a: u8 = 0; | 2 | comptime var a: u8 = 0; |
| 3 | _ = [0:&a]*u8; | 3 | _ = [0:&a]*u8; |
| 4 | } | 4 | } |
| 5 | export fn bar() void { | ||
| 6 | comptime var a: u8 = 0; | ||
| 7 | _ = @Type(.{ .array = .{ | ||
| 8 | .child = *u8, | ||
| 9 | .len = 0, | ||
| 10 | .sentinel_ptr = @ptrCast(&&a), | ||
| 11 | } }); | ||
| 12 | } | ||
| 13 | 5 | ||
| 14 | export fn baz() void { | 6 | export fn baz() void { |
| 15 | comptime var a: u8 = 0; | 7 | comptime var a: u8 = 0; |
| ... | @@ -17,25 +9,14 @@ export fn baz() void { | ... | @@ -17,25 +9,14 @@ export fn baz() void { |
| 17 | } | 9 | } |
| 18 | export fn qux() void { | 10 | export fn qux() void { |
| 19 | comptime var a: u8 = 0; | 11 | comptime var a: u8 = 0; |
| 20 | _ = @Type(.{ .pointer = .{ | 12 | _ = @Pointer(.many, .{}, *u8, &a); |
| 21 | .size = .many, | ||
| 22 | .is_const = false, | ||
| 23 | .is_volatile = false, | ||
| 24 | .alignment = @alignOf(u8), | ||
| 25 | .address_space = .generic, | ||
| 26 | .child = *u8, | ||
| 27 | .is_allowzero = false, | ||
| 28 | .sentinel_ptr = @ptrCast(&&a), | ||
| 29 | } }); | ||
| 30 | } | 13 | } |
| 31 | 14 | ||
| 32 | // error | 15 | // error |
| 33 | // | 16 | // |
| 34 | // :3:12: error: sentinel contains reference to comptime var | 17 | // :3:12: error: sentinel contains reference to comptime var |
| 35 | // :2:14: note: 'sentinel' points to comptime var declared here | 18 | // :2:14: note: 'sentinel' points to comptime var declared here |
| 36 | // :7:9: error: sentinel contains reference to comptime var | 19 | // :8:11: error: sentinel contains reference to comptime var |
| 37 | // :6:14: note: 'sentinel_ptr' points to comptime var declared here | 20 | // :7:14: note: 'sentinel' points to comptime var declared here |
| 38 | // :16:11: error: sentinel contains reference to comptime var | 21 | // :12:35: error: sentinel contains reference to comptime var |
| 39 | // :15:14: note: 'sentinel' points to comptime var declared here | 22 | // :11:14: note: 'sentinel' points to comptime var declared here |
| 40 | // :20:9: error: sentinel contains reference to comptime var | ||
| 41 | // :19:14: note: 'sentinel_ptr' points to comptime var declared here |
test/standalone/simple/issue_7030.zig+1-1| ... | @@ -6,7 +6,7 @@ pub const std_options: std.Options = .{ | ... | @@ -6,7 +6,7 @@ pub const std_options: std.Options = .{ |
| 6 | 6 | ||
| 7 | pub fn log( | 7 | pub fn log( |
| 8 | comptime message_level: std.log.Level, | 8 | comptime message_level: std.log.Level, |
| 9 | comptime scope: @Type(.enum_literal), | 9 | comptime scope: @EnumLiteral(), |
| 10 | comptime format: []const u8, | 10 | comptime format: []const u8, |
| 11 | args: anytype, | 11 | args: anytype, |
| 12 | ) void { | 12 | ) void { |
test/standalone/simple/std_enums_big_enums.zig+14-15| ... | @@ -3,20 +3,18 @@ const std = @import("std"); | ... | @@ -3,20 +3,18 @@ const std = @import("std"); |
| 3 | // big enums should not hit the eval branch quota | 3 | // big enums should not hit the eval branch quota |
| 4 | pub fn main() void { | 4 | pub fn main() void { |
| 5 | const big = struct { | 5 | const big = struct { |
| 6 | const Big = @Type(.{ .@"enum" = .{ | 6 | const Big = Big: { |
| 7 | .tag_type = u16, | 7 | @setEvalBranchQuota(500000); |
| 8 | .fields = make_fields: { | 8 | var names: [1001][]const u8 = undefined; |
| 9 | @setEvalBranchQuota(500000); | 9 | var values: [1001]u16 = undefined; |
| 10 | var fields: [1001]std.builtin.Type.EnumField = undefined; | 10 | for (values[0..1000], names[0..1000], 0..1000) |*val, *name, i| { |
| 11 | for (&fields, 0..) |*field, i| { | 11 | name.* = std.fmt.comptimePrint("field_{d}", .{i}); |
| 12 | field.* = .{ .name = std.fmt.comptimePrint("field_{d}", .{i}), .value = i }; | 12 | val.* = i; |
| 13 | } | 13 | } |
| 14 | fields[1000] = .{ .name = "field_9999", .value = 9999 }; | 14 | names[1000] = "field_9999"; |
| 15 | break :make_fields &fields; | 15 | values[1000] = 9999; |
| 16 | }, | 16 | break :Big @Enum(u16, .exhaustive, &names, &values); |
| 17 | .decls = &.{}, | 17 | }; |
| 18 | .is_exhaustive = true, | ||
| 19 | } }); | ||
| 20 | }; | 18 | }; |
| 21 | 19 | ||
| 22 | var set = std.enums.EnumSet(big.Big).init(.{}); | 20 | var set = std.enums.EnumSet(big.Big).init(.{}); |
| ... | @@ -29,10 +27,11 @@ pub fn main() void { | ... | @@ -29,10 +27,11 @@ pub fn main() void { |
| 29 | var multiset = std.enums.EnumMultiset(big.Big).init(.{}); | 27 | var multiset = std.enums.EnumMultiset(big.Big).init(.{}); |
| 30 | _ = &multiset; | 28 | _ = &multiset; |
| 31 | 29 | ||
| 30 | @setEvalBranchQuota(4000); | ||
| 31 | |||
| 32 | var bounded_multiset = std.enums.BoundedEnumMultiset(big.Big, u8).init(.{}); | 32 | var bounded_multiset = std.enums.BoundedEnumMultiset(big.Big, u8).init(.{}); |
| 33 | _ = &bounded_multiset; | 33 | _ = &bounded_multiset; |
| 34 | 34 | ||
| 35 | @setEvalBranchQuota(3000); | ||
| 36 | var array = std.enums.EnumArray(big.Big, u8).init(undefined); | 35 | var array = std.enums.EnumArray(big.Big, u8).init(undefined); |
| 37 | array = std.enums.EnumArray(big.Big, u8).initDefault(123, .{}); | 36 | array = std.enums.EnumArray(big.Big, u8).initDefault(123, .{}); |
| 38 | } | 37 | } |
tools/lldb_pretty_printers.py+1-1| ... | @@ -559,7 +559,7 @@ type_tag_handlers = { | ... | @@ -559,7 +559,7 @@ type_tag_handlers = { |
| 559 | 'extern_options': lambda payload: 'std.builtin.ExternOptions', | 559 | 'extern_options': lambda payload: 'std.builtin.ExternOptions', |
| 560 | 'type_info': lambda payload: 'std.builtin.Type', | 560 | 'type_info': lambda payload: 'std.builtin.Type', |
| 561 | 561 | ||
| 562 | 'enum_literal': lambda payload: '@TypeOf(.enum_literal)', | 562 | 'enum_literal': lambda payload: '@EnumLiteral()', |
| 563 | 'null': lambda payload: '@TypeOf(null)', | 563 | 'null': lambda payload: '@TypeOf(null)', |
| 564 | 'undefined': lambda payload: '@TypeOf(undefined)', | 564 | 'undefined': lambda payload: '@TypeOf(undefined)', |
| 565 | 'empty_struct_literal': lambda payload: '@TypeOf(.{})', | 565 | 'empty_struct_literal': lambda payload: '@TypeOf(.{})', |