authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-16 18:05:21+01:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-18 13:31:38+01:00
logceff03f3e96a9c51dc24e21b1f343f2b2650e2aa
tree68390ee9675cbaabe61892a879af0840293c66f8
parentaac2d6b56f32134ea32fb3d984e3fcdfddd8aaf6

std.builtin: remove layout field from Type.Enum


14 files changed, 8 insertions(+), 51 deletions(-)

lib/std/builtin.zig-2
......@@ -330,8 +330,6 @@ pub const Type = union(enum) {
330330 /// This data structure is used by the Zig language code generation and
331331 /// therefore must be kept in sync with the compiler implementation.
332332 pub const Enum = struct {
333 /// TODO enums should no longer have this field in type info.
334 layout: ContainerLayout,
335333 tag_type: type,
336334 fields: []const EnumField,
337335 decls: []const Declaration,
lib/std/meta.zig+1-13
......@@ -371,16 +371,12 @@ test "std.meta.assumeSentinel" {
371371pub fn containerLayout(comptime T: type) Type.ContainerLayout {
372372 return switch (@typeInfo(T)) {
373373 .Struct => |info| info.layout,
374 .Enum => |info| info.layout,
375374 .Union => |info| info.layout,
376 else => @compileError("Expected struct, enum or union type, found '" ++ @typeName(T) ++ "'"),
375 else => @compileError("expected struct or union type, found '" ++ @typeName(T) ++ "'"),
377376 };
378377}
379378
380379test "std.meta.containerLayout" {
381 const E1 = enum {
382 A,
383 };
384380 const S1 = struct {};
385381 const S2 = packed struct {};
386382 const S3 = extern struct {};
......@@ -394,7 +390,6 @@ test "std.meta.containerLayout" {
394390 a: u8,
395391 };
396392
397 try testing.expect(containerLayout(E1) == .Auto);
398393 try testing.expect(containerLayout(S1) == .Auto);
399394 try testing.expect(containerLayout(S2) == .Packed);
400395 try testing.expect(containerLayout(S3) == .Extern);
......@@ -634,7 +629,6 @@ pub fn FieldEnum(comptime T: type) type {
634629 if (field_infos.len == 0) {
635630 return @Type(.{
636631 .Enum = .{
637 .layout = .Auto,
638632 .tag_type = u0,
639633 .fields = &.{},
640634 .decls = &.{},
......@@ -664,7 +658,6 @@ pub fn FieldEnum(comptime T: type) type {
664658 }
665659 return @Type(.{
666660 .Enum = .{
667 .layout = .Auto,
668661 .tag_type = std.math.IntFittingRange(0, field_infos.len - 1),
669662 .fields = &enumFields,
670663 .decls = &decls,
......@@ -676,10 +669,6 @@ pub fn FieldEnum(comptime T: type) type {
676669fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
677670 // TODO: https://github.com/ziglang/zig/issues/7419
678671 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
679 try testing.expectEqual(
680 @typeInfo(expected).Enum.layout,
681 @typeInfo(actual).Enum.layout,
682 );
683672 try testing.expectEqual(
684673 @typeInfo(expected).Enum.tag_type,
685674 @typeInfo(actual).Enum.tag_type,
......@@ -740,7 +729,6 @@ pub fn DeclEnum(comptime T: type) type {
740729 }
741730 return @Type(.{
742731 .Enum = .{
743 .layout = .Auto,
744732 .tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1),
745733 .fields = &enumDecls,
746734 .decls = &decls,
lib/std/meta/trait.zig-2
......@@ -154,7 +154,6 @@ pub fn isExtern(comptime T: type) bool {
154154 return switch (@typeInfo(T)) {
155155 .Struct => |s| s.layout == .Extern,
156156 .Union => |u| u.layout == .Extern,
157 .Enum => |e| e.layout == .Extern,
158157 else => false,
159158 };
160159}
......@@ -172,7 +171,6 @@ pub fn isPacked(comptime T: type) bool {
172171 return switch (@typeInfo(T)) {
173172 .Struct => |s| s.layout == .Packed,
174173 .Union => |u| u.layout == .Packed,
175 .Enum => |e| e.layout == .Packed,
176174 else => false,
177175 };
178176}
src/Sema.zig+5-19
......@@ -15690,14 +15690,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1569015690
1569115691 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace());
1569215692
15693 const field_values = try sema.arena.create([5]Value);
15693 const field_values = try sema.arena.create([4]Value);
1569415694 field_values.* = .{
15695 // layout: ContainerLayout,
15696 try Value.Tag.enum_field_index.create(
15697 sema.arena,
15698 @enumToInt(std.builtin.Type.ContainerLayout.Auto),
15699 ),
15700
1570115695 // tag_type: type,
1570215696 try Value.Tag.ty.create(sema.arena, int_tag_ty),
1570315697 // fields: []const EnumField,
......@@ -18312,22 +18306,14 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1831218306 .Enum => {
1831318307 const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data;
1831418308 // TODO use reflection instead of magic numbers here
18315 // layout: ContainerLayout,
18316 const layout_val = struct_val[0];
1831718309 // tag_type: type,
18318 const tag_type_val = struct_val[1];
18310 const tag_type_val = struct_val[0];
1831918311 // fields: []const EnumField,
18320 const fields_val = struct_val[2];
18312 const fields_val = struct_val[1];
1832118313 // decls: []const Declaration,
18322 const decls_val = struct_val[3];
18314 const decls_val = struct_val[2];
1832318315 // is_exhaustive: bool,
18324 const is_exhaustive_val = struct_val[4];
18325
18326 // enum layout is always auto
18327 const layout = layout_val.toEnum(std.builtin.Type.ContainerLayout);
18328 if (layout != .Auto) {
18329 return sema.fail(block, src, "reified enums must have a layout .Auto", .{});
18330 }
18316 const is_exhaustive_val = struct_val[3];
1833118317
1833218318 // Decls
1833318319 if (decls_val.sliceLen(mod) > 0) {
test/behavior/generics.zig-1
......@@ -273,7 +273,6 @@ test "generic function instantiation turns into comptime call" {
273273 var enumFields: [1]std.builtin.Type.EnumField = .{.{ .name = "A", .value = 0 }};
274274 return @Type(.{
275275 .Enum = .{
276 .layout = .Auto,
277276 .tag_type = u0,
278277 .fields = &enumFields,
279278 .decls = &.{},
test/behavior/type.zig-4
......@@ -354,7 +354,6 @@ test "Type.Enum" {
354354
355355 const Foo = @Type(.{
356356 .Enum = .{
357 .layout = .Auto,
358357 .tag_type = u8,
359358 .fields = &.{
360359 .{ .name = "a", .value = 1 },
......@@ -369,7 +368,6 @@ test "Type.Enum" {
369368 try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
370369 const Bar = @Type(.{
371370 .Enum = .{
372 .layout = .Auto,
373371 .tag_type = u32,
374372 .fields = &.{
375373 .{ .name = "a", .value = 1 },
......@@ -424,7 +422,6 @@ test "Type.Union" {
424422
425423 const Tag = @Type(.{
426424 .Enum = .{
427 .layout = .Auto,
428425 .tag_type = u1,
429426 .fields = &.{
430427 .{ .name = "signed", .value = 0 },
......@@ -456,7 +453,6 @@ test "Type.Union from Type.Enum" {
456453
457454 const Tag = @Type(.{
458455 .Enum = .{
459 .layout = .Auto,
460456 .tag_type = u0,
461457 .fields = &.{
462458 .{ .name = "working_as_expected", .value = 0 },
test/behavior/type_info.zig-1
......@@ -238,7 +238,6 @@ fn testEnum() !void {
238238
239239 const os_info = @typeInfo(Os);
240240 try expect(os_info == .Enum);
241 try expect(os_info.Enum.layout == .Auto);
242241 try expect(os_info.Enum.fields.len == 4);
243242 try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
244243 try expect(os_info.Enum.fields[3].value == 3);
test/cases/compile_errors/reified_enum_field_value_overflow.zig-1
......@@ -1,6 +1,5 @@
11comptime {
22 const E = @Type(.{ .Enum = .{
3 .layout = .Auto,
43 .tag_type = u1,
54 .fields = &.{
65 .{ .name = "f0", .value = 0 },
test/cases/compile_errors/reify_enum_with_duplicate_field.zig-1
......@@ -1,7 +1,6 @@
11export fn entry() void {
22 _ = @Type(.{
33 .Enum = .{
4 .layout = .Auto,
54 .tag_type = u32,
65 .fields = &.{
76 .{ .name = "A", .value = 0 },
test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig-1
......@@ -1,7 +1,6 @@
11export fn entry() void {
22 _ = @Type(.{
33 .Enum = .{
4 .layout = .Auto,
54 .tag_type = u32,
65 .fields = &.{
76 .{ .name = "A", .value = 10 },
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig-1
......@@ -1,6 +1,5 @@
11const Tag = @Type(.{
22 .Enum = .{
3 .layout = .Auto,
43 .tag_type = bool,
54 .fields = &.{},
65 .decls = &.{},
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig-1
......@@ -1,6 +1,5 @@
11const Tag = @Type(.{
22 .Enum = .{
3 .layout = .Auto,
43 .tag_type = undefined,
54 .fields = &.{},
65 .decls = &.{},
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig+1-2
......@@ -1,6 +1,5 @@
11const Tag = @Type(.{
22 .Enum = .{
3 .layout = .Auto,
43 .tag_type = u2,
54 .fields = &.{
65 .{ .name = "signed", .value = 0 },
......@@ -31,6 +30,6 @@ export fn entry() void {
3130// backend=stage2
3231// target=native
3332//
34// :14:16: error: enum field(s) missing in union
33// :13:16: error: enum field(s) missing in union
3534// :1:13: note: field 'arst' missing, declared here
3635// :1:13: note: enum declared here
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig+1-2
......@@ -1,6 +1,5 @@
11const Tag = @Type(.{
22 .Enum = .{
3 .layout = .Auto,
43 .tag_type = u1,
54 .fields = &.{
65 .{ .name = "signed", .value = 0 },
......@@ -31,5 +30,5 @@ export fn entry() void {
3130// backend=stage2
3231// target=native
3332//
34// :13:16: error: no field named 'arst' in enum 'tmp.Tag'
33// :12:16: error: no field named 'arst' in enum 'tmp.Tag'
3534// :1:13: note: enum declared here