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