Skip to content

Commit

Permalink
zig update: std.builtin.Type rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Aug 28, 2024
1 parent ea25590 commit f2a77c5
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
46 changes: 23 additions & 23 deletions src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ pub fn requiredArgCount(attr: Tag) u32 {
inline else => |tag| {
comptime var needed = 0;
comptime {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
for (fields) |arg_field| {
if (!mem.eql(u8, arg_field.name, "__name_tok") and @typeInfo(arg_field.type) != .Optional) needed += 1;
if (!mem.eql(u8, arg_field.name, "__name_tok") and @typeInfo(arg_field.type) != .optional) needed += 1;
}
}
return needed;
Expand All @@ -83,7 +83,7 @@ pub fn maxArgCount(attr: Tag) u32 {
inline else => |tag| {
comptime var max = 0;
comptime {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
for (fields) |arg_field| {
if (!mem.eql(u8, arg_field.name, "__name_tok")) max += 1;
}
Expand All @@ -95,7 +95,7 @@ pub fn maxArgCount(attr: Tag) u32 {

fn UnwrapOptional(comptime T: type) type {
return switch (@typeInfo(T)) {
.Optional => |optional| optional.child,
.optional => |optional| optional.child,
else => T,
};
}
Expand All @@ -108,11 +108,11 @@ pub const Formatting = struct {
switch (attr) {
.calling_convention => unreachable,
inline else => |tag| {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;

if (fields.len == 0) unreachable;
const Unwrapped = UnwrapOptional(fields[0].type);
if (@typeInfo(Unwrapped) != .Enum) unreachable;
if (@typeInfo(Unwrapped) != .@"enum") unreachable;

return if (Unwrapped.opts.enum_kind == .identifier) "'" else "\"";
},
Expand All @@ -125,13 +125,13 @@ pub const Formatting = struct {
switch (attr) {
.calling_convention => unreachable,
inline else => |tag| {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;

if (fields.len == 0) unreachable;
const Unwrapped = UnwrapOptional(fields[0].type);
if (@typeInfo(Unwrapped) != .Enum) unreachable;
if (@typeInfo(Unwrapped) != .@"enum") unreachable;

const enum_fields = @typeInfo(Unwrapped).Enum.fields;
const enum_fields = @typeInfo(Unwrapped).@"enum".fields;
const quote = comptime quoteChar(@enumFromInt(@intFromEnum(tag)));
comptime var values: []const u8 = quote ++ enum_fields[0].name ++ quote;
inline for (enum_fields[1..]) |enum_field| {
Expand All @@ -149,11 +149,11 @@ pub fn wantsIdentEnum(attr: Tag) bool {
switch (attr) {
.calling_convention => return false,
inline else => |tag| {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;

if (fields.len == 0) return false;
const Unwrapped = UnwrapOptional(fields[0].type);
if (@typeInfo(Unwrapped) != .Enum) return false;
if (@typeInfo(Unwrapped) != .@"enum") return false;

return Unwrapped.opts.enum_kind == .identifier;
},
Expand All @@ -163,10 +163,10 @@ pub fn wantsIdentEnum(attr: Tag) bool {
pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: []const u8) ?Diagnostics.Message {
switch (attr) {
inline else => |tag| {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
if (fields.len == 0) unreachable;
const Unwrapped = UnwrapOptional(fields[0].type);
if (@typeInfo(Unwrapped) != .Enum) unreachable;
if (@typeInfo(Unwrapped) != .@"enum") unreachable;
if (std.meta.stringToEnum(Unwrapped, normalize(ident))) |enum_val| {
@field(@field(arguments, @tagName(tag)), fields[0].name) = enum_val;
return null;
Expand All @@ -182,7 +182,7 @@ pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: []const u8) ?Diagn
pub fn wantsAlignment(attr: Tag, idx: usize) bool {
switch (attr) {
inline else => |tag| {
const fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
if (fields.len == 0) return false;

return switch (idx) {
Expand All @@ -196,7 +196,7 @@ pub fn wantsAlignment(attr: Tag, idx: usize) bool {
pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, p: *Parser) !?Diagnostics.Message {
switch (attr) {
inline else => |tag| {
const arg_fields = @typeInfo(@field(attributes, @tagName(tag))).Struct.fields;
const arg_fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
if (arg_fields.len == 0) unreachable;

switch (arg_idx) {
Expand Down Expand Up @@ -240,7 +240,7 @@ fn diagnoseField(
const key = p.comp.interner.get(res.val.ref());
switch (key) {
.int => {
if (@typeInfo(Wanted) == .Int) {
if (@typeInfo(Wanted) == .int) {
@field(@field(arguments, decl.name), field.name) = res.val.toInt(Wanted, p.comp) orelse return .{
.tag = .attribute_int_out_of_range,
.extra = .{ .str = try res.str(p) },
Expand All @@ -258,7 +258,7 @@ fn diagnoseField(
}
@field(@field(arguments, decl.name), field.name) = try p.removeNull(res.val);
return null;
} else if (@typeInfo(Wanted) == .Enum and @hasDecl(Wanted, "opts") and Wanted.opts.enum_kind == .string) {
} else if (@typeInfo(Wanted) == .@"enum" and @hasDecl(Wanted, "opts") and Wanted.opts.enum_kind == .string) {
const str = bytes[0 .. bytes.len - 1];
if (std.meta.stringToEnum(Wanted, str)) |enum_val| {
@field(@field(arguments, decl.name), field.name) = enum_val;
Expand Down Expand Up @@ -303,7 +303,7 @@ fn invalidArgMsg(comptime Expected: type, actual: ArgumentType) Diagnostics.Mess
Alignment => .alignment,
CallingConvention => .identifier,
else => switch (@typeInfo(Expected)) {
.Enum => if (Expected.opts.enum_kind == .string) .string else .identifier,
.@"enum" => if (Expected.opts.enum_kind == .string) .string else .identifier,
else => unreachable,
},
}, .actual = actual } },
Expand All @@ -313,13 +313,13 @@ fn invalidArgMsg(comptime Expected: type, actual: ArgumentType) Diagnostics.Mess
pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, node: Tree.Node, p: *Parser) !?Diagnostics.Message {
switch (attr) {
inline else => |tag| {
const decl = @typeInfo(attributes).Struct.decls[@intFromEnum(tag)];
const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];
const max_arg_count = comptime maxArgCount(tag);
if (arg_idx >= max_arg_count) return Diagnostics.Message{
.tag = .attribute_too_many_args,
.extra = .{ .attr_arg_count = .{ .attribute = attr, .expected = max_arg_count } },
};
const arg_fields = @typeInfo(@field(attributes, decl.name)).Struct.fields;
const arg_fields = @typeInfo(@field(attributes, decl.name)).@"struct".fields;
switch (arg_idx) {
inline 0...arg_fields.len - 1 => |arg_i| {
return diagnoseField(decl, arg_fields[arg_i], UnwrapOptional(arg_fields[arg_i].type), arguments, res, node, p);
Expand Down Expand Up @@ -651,7 +651,7 @@ const attributes = struct {
pub const Tag = std.meta.DeclEnum(attributes);

pub const Arguments = blk: {
const decls = @typeInfo(attributes).Struct.decls;
const decls = @typeInfo(attributes).@"struct".decls;
var union_fields: [decls.len]ZigType.UnionField = undefined;
for (decls, &union_fields) |decl, *field| {
field.* = .{
Expand All @@ -662,7 +662,7 @@ pub const Arguments = blk: {
}

break :blk @Type(.{
.Union = .{
.@"union" = .{
.layout = .auto,
.tag_type = null,
.fields = &union_fields,
Expand All @@ -672,7 +672,7 @@ pub const Arguments = blk: {
};

pub fn ArgumentsForTag(comptime tag: Tag) type {
const decl = @typeInfo(attributes).Struct.decls[@intFromEnum(tag)];
const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];
return @field(attributes, decl.name);
}

Expand Down
4 changes: 2 additions & 2 deletions src/aro/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub const Environment = struct {
var env: Environment = .{};
errdefer env.deinit(allocator);

inline for (@typeInfo(@TypeOf(env)).Struct.fields) |field| {
inline for (@typeInfo(@TypeOf(env)).@"struct".fields) |field| {
std.debug.assert(@field(env, field.name) == null);

var env_var_buf: [field.name.len]u8 = undefined;
Expand All @@ -78,7 +78,7 @@ pub const Environment = struct {

/// Use this only if environment slices were allocated with `allocator` (such as via `loadAll`)
pub fn deinit(self: *Environment, allocator: std.mem.Allocator) void {
inline for (@typeInfo(@TypeOf(self.*)).Struct.fields) |field| {
inline for (@typeInfo(@TypeOf(self.*)).@"struct".fields) |field| {
if (@field(self, field.name)) |slice| {
allocator.free(slice);
}
Expand Down
4 changes: 2 additions & 2 deletions src/aro/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ errors: u32 = 0,
macro_backtrace_limit: u32 = 6,

pub fn warningExists(name: []const u8) bool {
inline for (@typeInfo(Options).Struct.fields) |f| {
inline for (@typeInfo(Options).@"struct".fields) |f| {
if (mem.eql(u8, f.name, name)) return true;
}
return false;
}

pub fn set(d: *Diagnostics, name: []const u8, to: Kind) !void {
inline for (@typeInfo(Options).Struct.fields) |f| {
inline for (@typeInfo(Options).@"struct".fields) |f| {
if (mem.eql(u8, f.name, name)) {
@field(d.options, f.name) = to;
return;
Expand Down
4 changes: 2 additions & 2 deletions src/aro/Tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ fn dumpAttribute(tree: *const Tree, attr: Attribute, writer: anytype) !void {
switch (attr.tag) {
inline else => |tag| {
const args = @field(attr.args, @tagName(tag));
const fields = @typeInfo(@TypeOf(args)).Struct.fields;
const fields = @typeInfo(@TypeOf(args)).@"struct".fields;
if (fields.len == 0) {
try writer.writeByte('\n');
return;
Expand All @@ -839,7 +839,7 @@ fn dumpAttribute(tree: *const Tree, attr: Attribute, writer: anytype) !void {
Interner.Ref => try writer.print("\"{s}\"", .{tree.interner.get(@field(args, f.name)).bytes}),
?Interner.Ref => try writer.print("\"{?s}\"", .{if (@field(args, f.name)) |str| tree.interner.get(str).bytes else null}),
else => switch (@typeInfo(f.type)) {
.Enum => try writer.writeAll(@tagName(@field(args, f.name))),
.@"enum" => try writer.writeAll(@tagName(@field(args, f.name))),
else => try writer.print("{any}", .{@field(args, f.name)}),
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn intern(comp: *Compilation, k: Interner.Key) !Value {

pub fn int(i: anytype, comp: *Compilation) !Value {
const info = @typeInfo(@TypeOf(i));
if (info == .ComptimeInt or info.Int.signedness == .unsigned) {
if (info == .comptime_int or info.int.signedness == .unsigned) {
return intern(comp, .{ .int = .{ .u64 = i } });
} else {
return intern(comp, .{ .int = .{ .i64 = i } });
Expand Down
4 changes: 2 additions & 2 deletions src/aro/features.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn hasFeature(comp: *Compilation, ext: []const u8) bool {
.c_static_assert = comp.langopts.standard.atLeast(.c11),
.c_thread_local = comp.langopts.standard.atLeast(.c11) and target_util.isTlsSupported(comp.target),
};
inline for (@typeInfo(@TypeOf(list)).Struct.fields) |f| {
inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {
if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name);
}
return false;
Expand All @@ -69,7 +69,7 @@ pub fn hasExtension(comp: *Compilation, ext: []const u8) bool {
.matrix_types = false, // TODO
.matrix_types_scalar_division = false, // TODO
};
inline for (@typeInfo(@TypeOf(list)).Struct.fields) |f| {
inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {
if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name);
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Interner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
});
},
.record_ty => |elems| {
try i.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.Record).Struct.fields.len +
try i.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.Record).@"struct".fields.len +
elems.len);
i.items.appendAssumeCapacity(.{
.tag = .record_ty,
Expand All @@ -728,14 +728,14 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
}

fn addExtra(i: *Interner, gpa: Allocator, extra: anytype) Allocator.Error!u32 {
const fields = @typeInfo(@TypeOf(extra)).Struct.fields;
const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
try i.extra.ensureUnusedCapacity(gpa, fields.len);
return i.addExtraAssumeCapacity(extra);
}

fn addExtraAssumeCapacity(i: *Interner, extra: anytype) u32 {
const result = @as(u32, @intCast(i.extra.items.len));
inline for (@typeInfo(@TypeOf(extra)).Struct.fields) |field| {
inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
i.extra.appendAssumeCapacity(switch (field.type) {
Ref => @intFromEnum(@field(extra, field.name)),
u32 => @field(extra, field.name),
Expand Down Expand Up @@ -857,7 +857,7 @@ fn extraData(i: *const Interner, comptime T: type, index: usize) T {

fn extraDataTrail(i: *const Interner, comptime T: type, index: usize) struct { data: T, end: u32 } {
var result: T = undefined;
const fields = @typeInfo(T).Struct.fields;
const fields = @typeInfo(T).@"struct".fields;
inline for (fields, 0..) |field, field_i| {
const int32 = i.extra.items[field_i + index];
@field(result, field.name) = switch (field.type) {
Expand Down
2 changes: 1 addition & 1 deletion test/runner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn addCommandLineArgs(comp: *aro.Compilation, file: aro.Source, macro_buf: anyty
var parts = std.mem.splitScalar(u8, some, '=');
const name = parts.next().?;
const val = parts.next() orelse "";
inline for (@typeInfo(aro.Compilation.Environment).Struct.fields) |field| {
inline for (@typeInfo(aro.Compilation.Environment).@"struct".fields) |field| {
if (std.ascii.eqlIgnoreCase(name, field.name)) {
@field(comp.environment, field.name) = val;
}
Expand Down

0 comments on commit f2a77c5

Please sign in to comment.