| ... | @@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 22 | pub const bit_count = @typeInfo(Fields).Struct.fields.len; | 22 | pub const bit_count = @typeInfo(Fields).Struct.fields.len; |
| 23 | | 23 | |
| 24 | pub const FieldEnum = blk: { | 24 | pub const FieldEnum = blk: { |
| 25 | comptime var fields: []const TypeInfo.EnumField = &[_]TypeInfo.EnumField{}; | 25 | comptime var fields: [bit_count]TypeInfo.EnumField = undefined; |
| 26 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { | 26 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| |
| 27 | const field = TypeInfo.EnumField{ .name = struct_field.name, .value = i }; | 27 | fields[i] = .{ .name = struct_field.name, .value = i }; |
| 28 | fields = fields ++ [_]TypeInfo.EnumField{field}; | | |
| 29 | } | | |
| 30 | break :blk @Type(.{ | 28 | break :blk @Type(.{ |
| 31 | .Enum = .{ | 29 | .Enum = .{ |
| 32 | .layout = .Auto, | 30 | .layout = .Auto, |
| 33 | .tag_type = std.math.IntFittingRange(0, bit_count - 1), | 31 | .tag_type = std.math.IntFittingRange(0, bit_count - 1), |
| 34 | .fields = fields, | 32 | .fields = &fields, |
| 35 | .decls = &[_]TypeInfo.Declaration{}, | 33 | .decls = &[_]TypeInfo.Declaration{}, |
| 36 | .is_exhaustive = true, | 34 | .is_exhaustive = true, |
| 37 | }, | 35 | }, |
| ... | @@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 39 | }; | 37 | }; |
| 40 | | 38 | |
| 41 | pub const InitStruct = blk: { | 39 | pub const InitStruct = blk: { |
| 42 | comptime var fields: []const TypeInfo.StructField = &[_]TypeInfo.StructField{}; | 40 | comptime var fields: [bit_count]TypeInfo.StructField = undefined; |
| 43 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { | 41 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { |
| 44 | const field = TypeInfo.StructField{ | 42 | fields[i] = TypeInfo.StructField{ |
| 45 | .name = struct_field.name, | 43 | .name = struct_field.name, |
| 46 | .field_type = ?struct_field.field_type, | 44 | .field_type = ?struct_field.field_type, |
| 47 | .default_value = @as(??struct_field.field_type, @as(?struct_field.field_type, null)), | 45 | .default_value = @as( |
| | 46 | ??struct_field.field_type, |
| | 47 | @as(?struct_field.field_type, null), |
| | 48 | ), |
| 48 | }; | 49 | }; |
| 49 | fields = fields ++ [_]TypeInfo.StructField{field}; | | |
| 50 | } | 50 | } |
| 51 | break :blk @Type(.{ | 51 | break :blk @Type(.{ |
| 52 | .Struct = .{ | 52 | .Struct = .{ |
| 53 | .layout = .Auto, | 53 | .layout = .Auto, |
| 54 | .fields = fields, | 54 | .fields = &fields, |
| 55 | .decls = &[_]TypeInfo.Declaration{}, | 55 | .decls = &[_]TypeInfo.Declaration{}, |
| 56 | .is_tuple = false, | 56 | .is_tuple = false, |
| 57 | }, | 57 | }, |
| ... | @@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 77 | } | 77 | } |
| 78 | | 78 | |
| 79 | /// `fields` is a struct with each field set to an optional value. | 79 | /// `fields` is a struct with each field set to an optional value. |
| 80 | /// Missing fields are assumed to be `null`. | | |
| 81 | /// Only the non-null bits are observed and are used to set the flag bits. | 80 | /// Only the non-null bits are observed and are used to set the flag bits. |
| 82 | pub fn init(fields: InitStruct) Self { | 81 | pub fn init(fields: InitStruct) Self { |
| 83 | var self: Self = .{ .bits = 0 }; | 82 | var self: Self = .{ .bits = 0 }; |
| ... | @@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type { | ... | @@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 89 | } | 88 | } |
| 90 | | 89 | |
| 91 | /// `fields` is a struct with each field set to an optional value (same as `init`). | 90 | /// `fields` is a struct with each field set to an optional value (same as `init`). |
| 92 | /// Missing fields are assumed to be `null`. | | |
| 93 | pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void { | 91 | pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void { |
| 94 | inline for (@typeInfo(Fields).Struct.fields) |field, i| { | 92 | inline for (@typeInfo(Fields).Struct.fields) |field, i| { |
| 95 | if (@field(fields, field.name)) |value| | 93 | if (@field(fields, field.name)) |value| |