From f2a77c5c7014315cfe0cfddc94822a80e5dc6e10 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Wed, 28 Aug 2024 14:21:24 -0700 Subject: [PATCH] zig update: std.builtin.Type rename --- src/aro/Attribute.zig | 46 ++++++++++++++++++++-------------------- src/aro/Compilation.zig | 4 ++-- src/aro/Diagnostics.zig | 4 ++-- src/aro/Tree.zig | 4 ++-- src/aro/Value.zig | 2 +- src/aro/features.zig | 4 ++-- src/backend/Interner.zig | 8 +++---- test/runner.zig | 2 +- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/aro/Attribute.zig b/src/aro/Attribute.zig index fe9770e2..35e8aeee 100644 --- a/src/aro/Attribute.zig +++ b/src/aro/Attribute.zig @@ -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; @@ -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; } @@ -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, }; } @@ -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 "\""; }, @@ -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| { @@ -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; }, @@ -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; @@ -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) { @@ -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) { @@ -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) }, @@ -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; @@ -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 } }, @@ -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); @@ -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.* = .{ @@ -662,7 +662,7 @@ pub const Arguments = blk: { } break :blk @Type(.{ - .Union = .{ + .@"union" = .{ .layout = .auto, .tag_type = null, .fields = &union_fields, @@ -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); } diff --git a/src/aro/Compilation.zig b/src/aro/Compilation.zig index c39b1c03..f1f5585f 100644 --- a/src/aro/Compilation.zig +++ b/src/aro/Compilation.zig @@ -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; @@ -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); } diff --git a/src/aro/Diagnostics.zig b/src/aro/Diagnostics.zig index 29076f08..fc69e2b1 100644 --- a/src/aro/Diagnostics.zig +++ b/src/aro/Diagnostics.zig @@ -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; diff --git a/src/aro/Tree.zig b/src/aro/Tree.zig index b82cea2f..c2210f63 100644 --- a/src/aro/Tree.zig +++ b/src/aro/Tree.zig @@ -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; @@ -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)}), }, } diff --git a/src/aro/Value.zig b/src/aro/Value.zig index aad6f0e0..61b8f0f8 100644 --- a/src/aro/Value.zig +++ b/src/aro/Value.zig @@ -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 } }); diff --git a/src/aro/features.zig b/src/aro/features.zig index 684fec48..fdc49b72 100644 --- a/src/aro/features.zig +++ b/src/aro/features.zig @@ -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; @@ -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; diff --git a/src/backend/Interner.zig b/src/backend/Interner.zig index 0cb6540a..631ec8ee 100644 --- a/src/backend/Interner.zig +++ b/src/backend/Interner.zig @@ -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, @@ -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), @@ -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) { diff --git a/test/runner.zig b/test/runner.zig index a6677598..2481ff5c 100644 --- a/test/runner.zig +++ b/test/runner.zig @@ -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; }