track builtin API changes from zig/master

see: https://github.com/ziglang/zig/pull/13930
In this PR, std.builtin.Type.field_type is renamed to type
And there is discussion that all Enum layouts are .Auto
This commit is contained in:
Steven Kabbes 2022-12-18 12:45:36 -07:00
parent e65d5c5c23
commit 427620742a
3 changed files with 11 additions and 14 deletions

View File

@ -2752,18 +2752,18 @@ pub fn processJsonRpc(server: *Server, writer: anytype, json: []const u8) !void
inline for (std.meta.fields(Config)) |field, index| { inline for (std.meta.fields(Config)) |field, index| {
const value = result.items[index]; const value = result.items[index];
const ft = if (@typeInfo(field.field_type) == .Optional) const ft = if (@typeInfo(field.type) == .Optional)
@typeInfo(field.field_type).Optional.child @typeInfo(field.type).Optional.child
else else
field.field_type; field.type;
const ti = @typeInfo(ft); const ti = @typeInfo(ft);
if (value != .Null) { if (value != .Null) {
const new_value: field.field_type = switch (ft) { const new_value: field.type = switch (ft) {
[]const u8 => switch (value) { []const u8 => switch (value) {
.String => |s| blk: { .String => |s| blk: {
if (s.len == 0) { if (s.len == 0) {
if (field.field_type == ?[]const u8) { if (field.type == ?[]const u8) {
break :blk null; break :blk null;
} else { } else {
break :blk s; break :blk s;

View File

@ -198,9 +198,9 @@ fn getConfigurationType() type {
var fields: [config_info.Struct.fields.len]std.builtin.Type.StructField = undefined; var fields: [config_info.Struct.fields.len]std.builtin.Type.StructField = undefined;
for (config_info.Struct.fields) |field, i| { for (config_info.Struct.fields) |field, i| {
fields[i] = field; fields[i] = field;
if (@typeInfo(field.field_type) != .Optional) { if (@typeInfo(field.type) != .Optional) {
fields[i].field_type = @Type(std.builtin.Type{ fields[i].type = @Type(std.builtin.Type{
.Optional = .{ .child = field.field_type }, .Optional = .{ .child = field.type },
}); });
} }
} }

View File

@ -45,10 +45,10 @@ fn fromDynamicTreeInternal(arena: *std.heap.ArenaAllocator, value: std.json.Valu
var err = false; var err = false;
inline for (std.meta.fields(T)) |field| { inline for (std.meta.fields(T)) |field| {
const is_exists = field.field_type == Exists; const is_exists = field.type == Exists;
const is_optional = comptime std.meta.trait.is(.Optional)(field.field_type); const is_optional = comptime std.meta.trait.is(.Optional)(field.type);
const actual_type = if (is_optional) std.meta.Child(field.field_type) else field.field_type; const actual_type = if (is_optional) std.meta.Child(field.type) else field.type;
const is_struct = comptime std.meta.trait.is(.Struct)(actual_type); const is_struct = comptime std.meta.trait.is(.Struct)(actual_type);
const is_default = comptime if (is_struct) std.meta.trait.hasDecls(actual_type, .{ "default", "value_type" }) else false; const is_default = comptime if (is_struct) std.meta.trait.hasDecls(actual_type, .{ "default", "value_type" }) else false;
@ -107,9 +107,6 @@ fn fromDynamicTreeInternal(arena: *std.heap.ArenaAllocator, value: std.json.Valu
out.* = value; out.* = value;
} else if (comptime std.meta.trait.is(.Enum)(T)) { } else if (comptime std.meta.trait.is(.Enum)(T)) {
const info = @typeInfo(T).Enum; const info = @typeInfo(T).Enum;
if (info.layout != .Auto)
@compileError("Only auto layout enums are allowed");
const TagType = info.tag_type; const TagType = info.tag_type;
if (value != .Integer) return error.MalformedJson; if (value != .Integer) return error.MalformedJson;
out.* = std.meta.intToEnum( out.* = std.meta.intToEnum(