pub fn toAttribute(self: Index, builder: *const Builder) Attribute {
@setEvalBranchQuota(2_000);
const storage = self.toStorage(builder);
if (storage.kind.toString()) |kind| return .{ .string = .{
.kind = kind,
.value = @fromBackingInt(storage.value),
} } else return switch (storage.kind) {
inline else => |kind| {
const field_name, const field_type = comptime blk: {
@setEvalBranchQuota(12_000);
const info = @typeInfo(Attribute).@"union";
for (info.field_names, info.field_types) |field_name, field_type| {
if (std.mem.eql(u8, field_name, @tagName(kind))) break :blk .{ field_name, field_type };
}
unreachable;
};
comptime assert(std.mem.eql(u8, @tagName(kind), field_name));
return @unionInit(Attribute, field_name, switch (field_type) {
void => {},
u32 => storage.value,
Alignment.Lazy, String, Type, UwTable => @fromBackingInt(storage.value),
AllocKind, AllocSize, Captures, FpClass, Memory, VScaleRange => @bitCast(storage.value),
else => @compileError("bad payload type: " ++ field_name ++ ": " ++
@typeName(field_type)),
});
},
.initializes,
.dead_on_return,
.range,
=> @panic("TODO"),
.string, .none, _ => unreachable,
};
}