From 8dd737801355427c558876bbcb299926d47b8269 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 22 Apr 2021 19:21:50 -0700 Subject: [PATCH] delete packed enums from the language No need for any such thing. Instead, provide an integer tag type for the enum. --- doc/langref.html.in | 21 +-------------------- lib/std/os/linux/bpf.zig | 12 ++++++------ 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 63e4c946b6..155fcbf468 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2588,7 +2588,7 @@ test "default struct initialization fields" { exactly their bit width.
  • {#syntax#}bool{#endsyntax#} fields use exactly 1 bit.
  • -
  • A {#link|packed enum#} field uses exactly the bit width of its integer tag type.
  • +
  • An {#link|enum#} field uses exactly the bit width of its integer tag type.
  • A {#link|packed union#} field uses exactly the bit width of the union field with the largest bit width.
  • Non-ABI-aligned fields are packed into the smallest possible @@ -2983,25 +2983,6 @@ export fn entry(foo: Foo) void { } {#code_end#} {#header_close#} - {#header_open|packed enum#} -

    By default, the size of enums is not guaranteed.

    -

    {#syntax#}packed enum{#endsyntax#} causes the size of the enum to be the same as the size of the - integer tag type of the enum:

    - {#code_begin|test#} -const std = @import("std"); - -test "packed enum" { - const Number = packed enum(u8) { - one, - two, - three, - }; - std.testing.expect(@sizeOf(Number) == @sizeOf(u8)); -} - {#code_end#} -

    This makes the enum eligible to be in a {#link|packed struct#}.

    - {#header_close#} - {#header_open|Enum Literals#}

    Enum literals allow specifying the name of an enum field without specifying the enum type: diff --git a/lib/std/os/linux/bpf.zig b/lib/std/os/linux/bpf.zig index 0d7e0a19ed..d8b78d5029 100644 --- a/lib/std/os/linux/bpf.zig +++ b/lib/std/os/linux/bpf.zig @@ -398,10 +398,10 @@ pub const Insn = packed struct { /// r0 - r9 are general purpose 64-bit registers, r10 points to the stack /// frame - pub const Reg = packed enum(u4) { r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 }; - const Source = packed enum(u1) { reg, imm }; + pub const Reg = enum(u4) { r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 }; + const Source = enum(u1) { reg, imm }; - const Mode = packed enum(u8) { + const Mode = enum(u8) { imm = IMM, abs = ABS, ind = IND, @@ -410,7 +410,7 @@ pub const Insn = packed struct { msh = MSH, }; - const AluOp = packed enum(u8) { + const AluOp = enum(u8) { add = ADD, sub = SUB, mul = MUL, @@ -426,14 +426,14 @@ pub const Insn = packed struct { arsh = ARSH, }; - pub const Size = packed enum(u8) { + pub const Size = enum(u8) { byte = B, half_word = H, word = W, double_word = DW, }; - const JmpOp = packed enum(u8) { + const JmpOp = enum(u8) { ja = JA, jeq = JEQ, jgt = JGT,