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) {...@@ -330,8 +330,6 @@ pub const Type = union(enum) {
330 /// This data structure is used by the Zig language code generation and330 /// This data structure is used by the Zig language code generation and
331 /// therefore must be kept in sync with the compiler implementation.331 /// therefore must be kept in sync with the compiler implementation.
332 pub const Enum = struct {332 pub const Enum = struct {
333 /// TODO enums should no longer have this field in type info.
334 layout: ContainerLayout,
335 tag_type: type,333 tag_type: type,
336 fields: []const EnumField,334 fields: []const EnumField,
337 decls: []const Declaration,335 decls: []const Declaration,
lib/std/meta.zig+1-13
...@@ -371,16 +371,12 @@ test "std.meta.assumeSentinel" {...@@ -371,16 +371,12 @@ test "std.meta.assumeSentinel" {
371pub fn containerLayout(comptime T: type) Type.ContainerLayout {371pub fn containerLayout(comptime T: type) Type.ContainerLayout {
372 return switch (@typeInfo(T)) {372 return switch (@typeInfo(T)) {
373 .Struct => |info| info.layout,373 .Struct => |info| info.layout,
374 .Enum => |info| info.layout,
375 .Union => |info| info.layout,374 .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) ++ "'"),
377 };376 };
378}377}
379378
380test "std.meta.containerLayout" {379test "std.meta.containerLayout" {
381 const E1 = enum {
382 A,
383 };
384 const S1 = struct {};380 const S1 = struct {};
385 const S2 = packed struct {};381 const S2 = packed struct {};
386 const S3 = extern struct {};382 const S3 = extern struct {};
...@@ -394,7 +390,6 @@ test "std.meta.containerLayout" {...@@ -394,7 +390,6 @@ test "std.meta.containerLayout" {
394 a: u8,390 a: u8,
395 };391 };
396392
397 try testing.expect(containerLayout(E1) == .Auto);
398 try testing.expect(containerLayout(S1) == .Auto);393 try testing.expect(containerLayout(S1) == .Auto);
399 try testing.expect(containerLayout(S2) == .Packed);394 try testing.expect(containerLayout(S2) == .Packed);
400 try testing.expect(containerLayout(S3) == .Extern);395 try testing.expect(containerLayout(S3) == .Extern);
...@@ -634,7 +629,6 @@ pub fn FieldEnum(comptime T: type) type {...@@ -634,7 +629,6 @@ pub fn FieldEnum(comptime T: type) type {
634 if (field_infos.len == 0) {629 if (field_infos.len == 0) {
635 return @Type(.{630 return @Type(.{
636 .Enum = .{631 .Enum = .{
637 .layout = .Auto,
638 .tag_type = u0,632 .tag_type = u0,
639 .fields = &.{},633 .fields = &.{},
640 .decls = &.{},634 .decls = &.{},
...@@ -664,7 +658,6 @@ pub fn FieldEnum(comptime T: type) type {...@@ -664,7 +658,6 @@ pub fn FieldEnum(comptime T: type) type {
664 }658 }
665 return @Type(.{659 return @Type(.{
666 .Enum = .{660 .Enum = .{
667 .layout = .Auto,
668 .tag_type = std.math.IntFittingRange(0, field_infos.len - 1),661 .tag_type = std.math.IntFittingRange(0, field_infos.len - 1),
669 .fields = &enumFields,662 .fields = &enumFields,
670 .decls = &decls,663 .decls = &decls,
...@@ -676,10 +669,6 @@ pub fn FieldEnum(comptime T: type) type {...@@ -676,10 +669,6 @@ pub fn FieldEnum(comptime T: type) type {
676fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {669fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
677 // TODO: https://github.com/ziglang/zig/issues/7419670 // TODO: https://github.com/ziglang/zig/issues/7419
678 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);671 // testing.expectEqual(@typeInfo(expected).Enum, @typeInfo(actual).Enum);
679 try testing.expectEqual(
680 @typeInfo(expected).Enum.layout,
681 @typeInfo(actual).Enum.layout,
682 );
683 try testing.expectEqual(672 try testing.expectEqual(
684 @typeInfo(expected).Enum.tag_type,673 @typeInfo(expected).Enum.tag_type,
685 @typeInfo(actual).Enum.tag_type,674 @typeInfo(actual).Enum.tag_type,
...@@ -740,7 +729,6 @@ pub fn DeclEnum(comptime T: type) type {...@@ -740,7 +729,6 @@ pub fn DeclEnum(comptime T: type) type {
740 }729 }
741 return @Type(.{730 return @Type(.{
742 .Enum = .{731 .Enum = .{
743 .layout = .Auto,
744 .tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1),732 .tag_type = std.math.IntFittingRange(0, fieldInfos.len - 1),
745 .fields = &enumDecls,733 .fields = &enumDecls,
746 .decls = &decls,734 .decls = &decls,
lib/std/meta/trait.zig-2
...@@ -154,7 +154,6 @@ pub fn isExtern(comptime T: type) bool {...@@ -154,7 +154,6 @@ pub fn isExtern(comptime T: type) bool {
154 return switch (@typeInfo(T)) {154 return switch (@typeInfo(T)) {
155 .Struct => |s| s.layout == .Extern,155 .Struct => |s| s.layout == .Extern,
156 .Union => |u| u.layout == .Extern,156 .Union => |u| u.layout == .Extern,
157 .Enum => |e| e.layout == .Extern,
158 else => false,157 else => false,
159 };158 };
160}159}
...@@ -172,7 +171,6 @@ pub fn isPacked(comptime T: type) bool {...@@ -172,7 +171,6 @@ pub fn isPacked(comptime T: type) bool {
172 return switch (@typeInfo(T)) {171 return switch (@typeInfo(T)) {
173 .Struct => |s| s.layout == .Packed,172 .Struct => |s| s.layout == .Packed,
174 .Union => |u| u.layout == .Packed,173 .Union => |u| u.layout == .Packed,
175 .Enum => |e| e.layout == .Packed,
176 else => false,174 else => false,
177 };175 };
178}176}
src/Sema.zig+5-19
...@@ -15690,14 +15690,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15690,14 +15690,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1569015690
15691 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, ty.getNamespace());15691 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);
15694 field_values.* = .{15694 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
15701 // tag_type: type,15695 // tag_type: type,
15702 try Value.Tag.ty.create(sema.arena, int_tag_ty),15696 try Value.Tag.ty.create(sema.arena, int_tag_ty),
15703 // fields: []const EnumField,15697 // fields: []const EnumField,
...@@ -18312,22 +18306,14 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in...@@ -18312,22 +18306,14 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
18312 .Enum => {18306 .Enum => {
18313 const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data;18307 const struct_val: []const Value = union_val.val.castTag(.aggregate).?.data;
18314 // TODO use reflection instead of magic numbers here18308 // TODO use reflection instead of magic numbers here
18315 // layout: ContainerLayout,
18316 const layout_val = struct_val[0];
18317 // tag_type: type,18309 // tag_type: type,
18318 const tag_type_val = struct_val[1];18310 const tag_type_val = struct_val[0];
18319 // fields: []const EnumField,18311 // fields: []const EnumField,
18320 const fields_val = struct_val[2];18312 const fields_val = struct_val[1];
18321 // decls: []const Declaration,18313 // decls: []const Declaration,
18322 const decls_val = struct_val[3];18314 const decls_val = struct_val[2];
18323 // is_exhaustive: bool,18315 // is_exhaustive: bool,
18324 const is_exhaustive_val = struct_val[4];18316 const is_exhaustive_val = struct_val[3];
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 }
1833118317
18332 // Decls18318 // Decls
18333 if (decls_val.sliceLen(mod) > 0) {18319 if (decls_val.sliceLen(mod) > 0) {
test/behavior/generics.zig-1
...@@ -273,7 +273,6 @@ test "generic function instantiation turns into comptime call" {...@@ -273,7 +273,6 @@ test "generic function instantiation turns into comptime call" {
273 var enumFields: [1]std.builtin.Type.EnumField = .{.{ .name = "A", .value = 0 }};273 var enumFields: [1]std.builtin.Type.EnumField = .{.{ .name = "A", .value = 0 }};
274 return @Type(.{274 return @Type(.{
275 .Enum = .{275 .Enum = .{
276 .layout = .Auto,
277 .tag_type = u0,276 .tag_type = u0,
278 .fields = &enumFields,277 .fields = &enumFields,
279 .decls = &.{},278 .decls = &.{},
test/behavior/type.zig-4
...@@ -354,7 +354,6 @@ test "Type.Enum" {...@@ -354,7 +354,6 @@ test "Type.Enum" {
354354
355 const Foo = @Type(.{355 const Foo = @Type(.{
356 .Enum = .{356 .Enum = .{
357 .layout = .Auto,
358 .tag_type = u8,357 .tag_type = u8,
359 .fields = &.{358 .fields = &.{
360 .{ .name = "a", .value = 1 },359 .{ .name = "a", .value = 1 },
...@@ -369,7 +368,6 @@ test "Type.Enum" {...@@ -369,7 +368,6 @@ test "Type.Enum" {
369 try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));368 try testing.expectEqual(@as(u8, 5), @enumToInt(Foo.b));
370 const Bar = @Type(.{369 const Bar = @Type(.{
371 .Enum = .{370 .Enum = .{
372 .layout = .Auto,
373 .tag_type = u32,371 .tag_type = u32,
374 .fields = &.{372 .fields = &.{
375 .{ .name = "a", .value = 1 },373 .{ .name = "a", .value = 1 },
...@@ -424,7 +422,6 @@ test "Type.Union" {...@@ -424,7 +422,6 @@ test "Type.Union" {
424422
425 const Tag = @Type(.{423 const Tag = @Type(.{
426 .Enum = .{424 .Enum = .{
427 .layout = .Auto,
428 .tag_type = u1,425 .tag_type = u1,
429 .fields = &.{426 .fields = &.{
430 .{ .name = "signed", .value = 0 },427 .{ .name = "signed", .value = 0 },
...@@ -456,7 +453,6 @@ test "Type.Union from Type.Enum" {...@@ -456,7 +453,6 @@ test "Type.Union from Type.Enum" {
456453
457 const Tag = @Type(.{454 const Tag = @Type(.{
458 .Enum = .{455 .Enum = .{
459 .layout = .Auto,
460 .tag_type = u0,456 .tag_type = u0,
461 .fields = &.{457 .fields = &.{
462 .{ .name = "working_as_expected", .value = 0 },458 .{ .name = "working_as_expected", .value = 0 },
test/behavior/type_info.zig-1
...@@ -238,7 +238,6 @@ fn testEnum() !void {...@@ -238,7 +238,6 @@ fn testEnum() !void {
238238
239 const os_info = @typeInfo(Os);239 const os_info = @typeInfo(Os);
240 try expect(os_info == .Enum);240 try expect(os_info == .Enum);
241 try expect(os_info.Enum.layout == .Auto);
242 try expect(os_info.Enum.fields.len == 4);241 try expect(os_info.Enum.fields.len == 4);
243 try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));242 try expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos"));
244 try expect(os_info.Enum.fields[3].value == 3);243 try expect(os_info.Enum.fields[3].value == 3);
test/cases/compile_errors/reified_enum_field_value_overflow.zig-1
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1comptime {1comptime {
2 const E = @Type(.{ .Enum = .{2 const E = @Type(.{ .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,3 .tag_type = u1,
5 .fields = &.{4 .fields = &.{
6 .{ .name = "f0", .value = 0 },5 .{ .name = "f0", .value = 0 },
test/cases/compile_errors/reify_enum_with_duplicate_field.zig-1
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 _ = @Type(.{2 _ = @Type(.{
3 .Enum = .{3 .Enum = .{
4 .layout = .Auto,
5 .tag_type = u32,4 .tag_type = u32,
6 .fields = &.{5 .fields = &.{
7 .{ .name = "A", .value = 0 },6 .{ .name = "A", .value = 0 },
test/cases/compile_errors/reify_enum_with_duplicate_tag_value.zig-1
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 _ = @Type(.{2 _ = @Type(.{
3 .Enum = .{3 .Enum = .{
4 .layout = .Auto,
5 .tag_type = u32,4 .tag_type = u32,
6 .fields = &.{5 .fields = &.{
7 .{ .name = "A", .value = 10 },6 .{ .name = "A", .value = 10 },
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig-1
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const Tag = @Type(.{1const Tag = @Type(.{
2 .Enum = .{2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = bool,3 .tag_type = bool,
5 .fields = &.{},4 .fields = &.{},
6 .decls = &.{},5 .decls = &.{},
test/cases/compile_errors/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig-1
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const Tag = @Type(.{1const Tag = @Type(.{
2 .Enum = .{2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = undefined,3 .tag_type = undefined,
5 .fields = &.{},4 .fields = &.{},
6 .decls = &.{},5 .decls = &.{},
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig+1-2
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const Tag = @Type(.{1const Tag = @Type(.{
2 .Enum = .{2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u2,3 .tag_type = u2,
5 .fields = &.{4 .fields = &.{
6 .{ .name = "signed", .value = 0 },5 .{ .name = "signed", .value = 0 },
...@@ -31,6 +30,6 @@ export fn entry() void {...@@ -31,6 +30,6 @@ export fn entry() void {
31// backend=stage230// backend=stage2
32// target=native31// target=native
33//32//
34// :14:16: error: enum field(s) missing in union33// :13:16: error: enum field(s) missing in union
35// :1:13: note: field 'arst' missing, declared here34// :1:13: note: field 'arst' missing, declared here
36// :1:13: note: enum declared here35// :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 @@...@@ -1,6 +1,5 @@
1const Tag = @Type(.{1const Tag = @Type(.{
2 .Enum = .{2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,3 .tag_type = u1,
5 .fields = &.{4 .fields = &.{
6 .{ .name = "signed", .value = 0 },5 .{ .name = "signed", .value = 0 },
...@@ -31,5 +30,5 @@ export fn entry() void {...@@ -31,5 +30,5 @@ export fn entry() void {
31// backend=stage230// backend=stage2
32// target=native31// target=native
33//32//
34// :13:16: error: no field named 'arst' in enum 'tmp.Tag'33// :12:16: error: no field named 'arst' in enum 'tmp.Tag'
35// :1:13: note: enum declared here34// :1:13: note: enum declared here