authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-22 19:21:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-22 19:21:50-07:00
log8dd737801355427c558876bbcb299926d47b8269
treeb54aa4604b6b164b56483efcfbcd4c2bd0ebb4ce
parent329a359974c29d62931c32ca85aa42aa9e4847f7

delete packed enums from the language

No need for any such thing. Instead, provide an integer tag type for the enum.

2 files changed, 7 insertions(+), 26 deletions(-)

doc/langref.html.in+1-20
......@@ -2588,7 +2588,7 @@ test "default struct initialization fields" {
25882588 exactly their bit width.
25892589 </li>
25902590 <li>{#syntax#}bool{#endsyntax#} fields use exactly 1 bit.</li>
2591 <li>A {#link|packed enum#} field uses exactly the bit width of its integer tag type.</li>
2591 <li>An {#link|enum#} field uses exactly the bit width of its integer tag type.</li>
25922592 <li>A {#link|packed union#} field uses exactly the bit width of the union field with
25932593 the largest bit width.</li>
25942594 <li>Non-ABI-aligned fields are packed into the smallest possible
......@@ -2983,25 +2983,6 @@ export fn entry(foo: Foo) void { }
29832983 {#code_end#}
29842984 {#header_close#}
29852985
2986 {#header_open|packed enum#}
2987 <p>By default, the size of enums is not guaranteed.</p>
2988 <p>{#syntax#}packed enum{#endsyntax#} causes the size of the enum to be the same as the size of the
2989 integer tag type of the enum:</p>
2990 {#code_begin|test#}
2991const std = @import("std");
2992
2993test "packed enum" {
2994 const Number = packed enum(u8) {
2995 one,
2996 two,
2997 three,
2998 };
2999 std.testing.expect(@sizeOf(Number) == @sizeOf(u8));
3000}
3001 {#code_end#}
3002 <p>This makes the enum eligible to be in a {#link|packed struct#}.</p>
3003 {#header_close#}
3004
30052986 {#header_open|Enum Literals#}
30062987 <p>
30072988 Enum literals allow specifying the name of an enum field without specifying the enum type:
lib/std/os/linux/bpf.zig+6-6
......@@ -398,10 +398,10 @@ pub const Insn = packed struct {
398398
399399 /// r0 - r9 are general purpose 64-bit registers, r10 points to the stack
400400 /// frame
401 pub const Reg = packed enum(u4) { r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 };
402 const Source = packed enum(u1) { reg, imm };
401 pub const Reg = enum(u4) { r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 };
402 const Source = enum(u1) { reg, imm };
403403
404 const Mode = packed enum(u8) {
404 const Mode = enum(u8) {
405405 imm = IMM,
406406 abs = ABS,
407407 ind = IND,
......@@ -410,7 +410,7 @@ pub const Insn = packed struct {
410410 msh = MSH,
411411 };
412412
413 const AluOp = packed enum(u8) {
413 const AluOp = enum(u8) {
414414 add = ADD,
415415 sub = SUB,
416416 mul = MUL,
......@@ -426,14 +426,14 @@ pub const Insn = packed struct {
426426 arsh = ARSH,
427427 };
428428
429 pub const Size = packed enum(u8) {
429 pub const Size = enum(u8) {
430430 byte = B,
431431 half_word = H,
432432 word = W,
433433 double_word = DW,
434434 };
435435
436 const JmpOp = packed enum(u8) {
436 const JmpOp = enum(u8) {
437437 ja = JA,
438438 jeq = JEQ,
439439 jgt = JGT,