authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-27 16:01:08-06:00
committergravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-27 16:02:00-06:00
loge4b61aa527f7ea06943bab720f672dd435b9dfba
tree43e8b8e051ba5c0007d005334fb1cc408359f4aa
parent3c87872dc5d7574e0e845568dc753ec48cb0cba0
signature Commit is signed but in an unrecognized format.

std.meta.TrailerFlags fixes


2 files changed, 12 insertions(+), 14 deletions(-)

lib/std/meta/trailer_flags.zig+11-13
......@@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type {
2222 pub const bit_count = @typeInfo(Fields).Struct.fields.len;
2323
2424 pub const FieldEnum = blk: {
25 comptime var fields: []const TypeInfo.EnumField = &[_]TypeInfo.EnumField{};
26 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| {
27 const field = TypeInfo.EnumField{ .name = struct_field.name, .value = i };
28 fields = fields ++ [_]TypeInfo.EnumField{field};
29 }
25 comptime var fields: [bit_count]TypeInfo.EnumField = undefined;
26 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i|
27 fields[i] = .{ .name = struct_field.name, .value = i };
3028 break :blk @Type(.{
3129 .Enum = .{
3230 .layout = .Auto,
3331 .tag_type = std.math.IntFittingRange(0, bit_count - 1),
34 .fields = fields,
32 .fields = &fields,
3533 .decls = &[_]TypeInfo.Declaration{},
3634 .is_exhaustive = true,
3735 },
......@@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type {
3937 };
4038
4139 pub const InitStruct = blk: {
42 comptime var fields: []const TypeInfo.StructField = &[_]TypeInfo.StructField{};
40 comptime var fields: [bit_count]TypeInfo.StructField = undefined;
4341 inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| {
44 const field = TypeInfo.StructField{
42 fields[i] = TypeInfo.StructField{
4543 .name = struct_field.name,
4644 .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 ),
4849 };
49 fields = fields ++ [_]TypeInfo.StructField{field};
5050 }
5151 break :blk @Type(.{
5252 .Struct = .{
5353 .layout = .Auto,
54 .fields = fields,
54 .fields = &fields,
5555 .decls = &[_]TypeInfo.Declaration{},
5656 .is_tuple = false,
5757 },
......@@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type {
7777 }
7878
7979 /// `fields` is a struct with each field set to an optional value.
80 /// Missing fields are assumed to be `null`.
8180 /// Only the non-null bits are observed and are used to set the flag bits.
8281 pub fn init(fields: InitStruct) Self {
8382 var self: Self = .{ .bits = 0 };
......@@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type {
8988 }
9089
9190 /// `fields` is a struct with each field set to an optional value (same as `init`).
92 /// Missing fields are assumed to be `null`.
9391 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void {
9492 inline for (@typeInfo(Fields).Struct.fields) |field, i| {
9593 if (@field(fields, field.name)) |value|
lib/std/zig/ast.zig+1-1
......@@ -1321,7 +1321,7 @@ pub const Node = struct {
13211321 self,
13221322 self.trailer_flags.bits,
13231323 self.getTrailer(.name_token),
1324 self.trailer_flags.ptrConst(trailers_start, "name_token"),
1324 self.trailer_flags.ptrConst(trailers_start, .name_token),
13251325 self.params_len,
13261326 });
13271327 }