diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 349d976ddc5b688b800145e98cbc62cbdcf29942..a0b3011d5c71f9eb7c23694af1cde105731a3e86 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -330,8 +330,6 @@ pub const Type = union(enum) { /// This data structure is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. pub const Enum = struct { - /// TODO enums should no longer have this field in type info. - layout: ContainerLayout, tag_type: type, fields: []const EnumField, decls: []const Declaration, diff --git a/lib/std/meta.zig b/lib/std/meta.zig index b4a73ffb3a79e0b5b81a0e8050cc6c483ec05110..39d561469f7957c4980664acb47c98b18ad967be 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -371,16 +371,12 @@ test "std.meta.assumeSentinel" { pub fn containerLayout(comptime T: type) Type.ContainerLayout { return switch (@typeInfo(T)) { .Struct => |info| info.layout, - .Enum => |info| info.layout, .Union => |info| info.layout, - else => @compileError("Expected struct, enum or union type, found '" ++ @typeName(T) ++ "'"), + else => @compileError("expected struct or union type, found '" ++ @typeName(T) ++ "'"), }; } test "std.meta.containerLayout" { - const E1 = enum { - A, - }; const S1 = struct {}; const S2 = packed struct {}; const S3 = extern struct {}; @@ -394,7 +390,6 @@ test "std.meta.containerLayout" { a: u8, }; - try testing.expect(containerLayout(E1) == .Auto); try testing.expect(containerLayout(S1) == .Auto); try testing.expect(containerLayout(S2) == .Packed); try testing.expect(containerLayout(S3) == .Extern); @@ -634,7 +629,6 @@ pub fn FieldEnum(comptime T: type) type { if (field_infos.len == 0) { return @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u0, .fields = &.{}, .decls = &.{}, @@ -664,7 +658,6 @@ pub fn FieldEnum(comptime T: type) type { } return @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = std.math.IntFittingRange(0, field_infos.len - 1), .fields = &enumFields, .decls = &decls, @@ -676,10 +669,6 @@ pub fn FieldEnum(comptime T: type) type { fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { // TODO: https://github.com/ziglang/zig/issues/7419 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum); - try testing.expectEqual( - @typeInfo(expected).Enum.layout, - @typeInfo(actual).Enum.layout, - ); try testing.expectEqual( @typeInfo(expected).Enum.tag_type, @typeInfo(actual).Enum.tag_type, @@ -740,7 +729,6 @@ pub fn DeclEnum(comptime T: type) type { } return @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1), .fields = &enumDecls, .decls = &decls, diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index 73d1292406aa424a0b5e41f7c261b4240fe2936d..843ada7f5614598694388422c46b6ed717a433a1 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -154,7 +154,6 @@ pub fn isExtern(comptime T: type) bool { return switch (@typeInfo(T)) { .Struct => |s| s.layout == .Extern, .Union => |u| u.layout == .Extern, - .Enum => |e| e.layout == .Extern, else => false, }; } @@ -172,7 +171,6 @@ pub fn isPacked(comptime T: type) bool { return switch (@typeInfo(T)) { .Struct => |s| s.layout == .Packed, .Union => |u| u.layout == .Packed, - .Enum => |e| e.layout == .Packed, else => false, }; } diff --git a/src/Sema.zig b/src/Sema.zig index 6f1af51d28b783cb1714b93eded1b7a40078b61a..f403b7e7e2d826133a9e8aa45188e69faf579173 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -15690,14 +15690,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace()); - const field_values = try sema.arena.create([5]Value); + const field_values = try sema.arena.create([4]Value); field_values.* = .{ - // layout: ContainerLayout, - try Value.Tag.enum_field_index.create( - sema.arena, - @enumToInt(std.builtin.Type.ContainerLayout.Auto), - ), - // tag_type: type, try Value.Tag.ty.create(sema.arena, int_tag_ty), // fields: []const EnumField, @@ -18312,22 +18306,14 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in .Enum => { const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data; // TODO use reflection instead of magic numbers here - // layout: ContainerLayout, - const layout_val = struct_val[0]; // tag_type: type, - const tag_type_val = struct_val[1]; + const tag_type_val = struct_val[0]; // fields: []const EnumField, - const fields_val = struct_val[2]; + const fields_val = struct_val[1]; // decls: []const Declaration, - const decls_val = struct_val[3]; + const decls_val = struct_val[2]; // is_exhaustive: bool, - const is_exhaustive_val = struct_val[4]; - - // enum layout is always auto - const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout); - if (layout != .Auto) { - return sema.fail(block, src, "reified enums must have a layout .Auto", .{}); - } + const is_exhaustive_val = struct_val[3]; // Decls if (decls_val.sliceLen(mod) > 0) { diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index dafbfbafe8d37d89f5828188714405ba98c01a77..17194fc445d8a6e6434bf082942a3449de8e58e5 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -273,7 +273,6 @@ test "generic function instantiation turns into comptime call" { var enumFields: [1]std.builtin.Type.EnumField = .{.{ .name = "A", .value = 0 }}; return @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u0, .fields = &enumFields, .decls = &.{}, diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 157eff81e8cfcf9ceb4dd71437eb5ccdb167e109..325bf0a8edd1727c19f8f276faddc264b7524306 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -354,7 +354,6 @@ test "Type.Enum" { const Foo = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u8, .fields = &.{ .{ .name = "a", .value = 1 }, @@ -369,7 +368,6 @@ test "Type.Enum" { try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b)); const Bar = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u32, .fields = &.{ .{ .name = "a", .value = 1 }, @@ -424,7 +422,6 @@ test "Type.Union" { const Tag = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u1, .fields = &.{ .{ .name = "signed", .value = 0 }, @@ -456,7 +453,6 @@ test "Type.Union from Type.Enum" { const Tag = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u0, .fields = &.{ .{ .name = "working_as_expected", .value = 0 }, diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index 04656a2034a2a72c0c0f9bbbc59870328f360066..8c895ceb003262dc8fabac8a55a80bc5e53dfe70 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -238,7 +238,6 @@ fn testEnum() !void { const os_info = @typeInfo(Os); try expect(os_info == .Enum); - try expect(os_info.Enum.layout == .Auto); try expect(os_info.Enum.fields.len == 4); try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); try expect(os_info.Enum.fields[3].value == 3); diff --git a/test/cases/compile_errors/reified_enum_field_value_overflow.zig b/test/cases/compile_errors/reified_enum_field_value_overflow.zig index ad8596ebccd724074f8222b4543984d4faf98929..d9f0e2057fd4f505b66ae549eeb591d0741a8e11 100644 --- a/test/cases/compile_errors/reified_enum_field_value_overflow.zig +++ b/test/cases/compile_errors/reified_enum_field_value_overflow.zig @@ -1,6 +1,5 @@ comptime { const E = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u1, .fields = &.{ .{ .name = "f0", .value = 0 }, diff --git a/test/cases/compile_errors/reify_enum_with_duplicate_field.zig b/test/cases/compile_errors/reify_enum_with_duplicate_field.zig index f8cadd9185e06e71c979cc31a62c3a8f16a7c23d..a4779b65efbe2c8698bd1940dd3ffd71ee35030e 100644 --- a/test/cases/compile_errors/reify_enum_with_duplicate_field.zig +++ b/test/cases/compile_errors/reify_enum_with_duplicate_field.zig @@ -1,7 +1,6 @@ export fn entry() void { _ = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u32, .fields = &.{ .{ .name = "A", .value = 0 }, diff --git a/test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig b/test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig index c3211fe3010ab50caf4f1492239fdd6022cc8a14..b9be7cdaed707828918baaf8ddf41a868134f974 100644 --- a/test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig +++ b/test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig @@ -1,7 +1,6 @@ export fn entry() void { _ = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u32, .fields = &.{ .{ .name = "A", .value = 10 }, diff --git a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig index e72b783d83e515d41592a240007b9c42d0214810..60c6ce9a59accf1be87a9fb1f102f8ecd6a9484f 100644 --- a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig +++ b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig @@ -1,6 +1,5 @@ const Tag = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = bool, .fields = &.{}, .decls = &.{}, diff --git a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig index 1c237a17bd0bf78694fda13b654df8da6c5316a5..896d689046230f876b12cbd55c0e11d43d537226 100644 --- a/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig +++ b/test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig @@ -1,6 +1,5 @@ const Tag = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = undefined, .fields = &.{}, .decls = &.{}, diff --git a/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig b/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig index 293e5c62e393bdb09886d8377df985302ab5c87d..96da0752dfe1b9a0101dcf700b8e889c32c182ea 100644 --- a/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig +++ b/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig @@ -1,6 +1,5 @@ const Tag = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u2, .fields = &.{ .{ .name = "signed", .value = 0 }, @@ -31,6 +30,6 @@ export fn entry() void { // backend=stage2 // target=native // -// :14:16: error: enum field(s) missing in union +// :13:16: error: enum field(s) missing in union // :1:13: note: field 'arst' missing, declared here // :1:13: note: enum declared here diff --git a/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig b/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig index bb26230f22675c6d3700a71828d421616f28282b..559eb81fcd072a052ca4b15ec0a21690a0eccb3a 100644 --- a/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig +++ b/test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig @@ -1,6 +1,5 @@ const Tag = @Type(.{ .Enum = .{ - .layout = .Auto, .tag_type = u1, .fields = &.{ .{ .name = "signed", .value = 0 }, @@ -31,5 +30,5 @@ export fn entry() void { // backend=stage2 // target=native // -// :13:16: error: no field named 'arst' in enum 'tmp.Tag' +// :12:16: error: no field named 'arst' in enum 'tmp.Tag' // :1:13: note: enum declared here