authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-28 09:45:54+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-28 09:45:54+02:00
log3f1dead2fc5922b588fbfb108f421ca957d6934a
tree47a976dc2264089771fbabd70a93a3865b70f07f
parent8d1b6e339750a37207bdaa8b5e9b4bda8d330fec
parent9e80795623aa826ec03d014ccf767ea30156d699

Merge pull request 'Use struct-of-arrays style for `std.lang.Type`' (#35234) from Der_Teufel/zig:soa-builtin-type into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35234

206 files changed, 2750 insertions(+), 2488 deletions(-)

doc/langref.html.in+3-3
......@@ -5752,7 +5752,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
57525752 {#header_open|@Fn#}
57535753 <pre>{#syntax#}@Fn(
57545754 comptime param_types: []const type,
5755 comptime param_attrs: *const [param_types.len]std.lang.Type.Fn.Param.Attributes,
5755 comptime param_attrs: *const [param_types.len]std.lang.Type.Fn.ParamAttributes,
57565756 comptime ReturnType: type,
57575757 comptime attrs: std.lang.Type.Fn.Attributes,
57585758) type{#endsyntax#}</pre>
......@@ -5765,7 +5765,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
57655765 comptime BackingInt: ?type,
57665766 comptime field_names: []const []const u8,
57675767 comptime field_types: *const [field_names.len]type,
5768 comptime field_attrs: *const [field_names.len]std.lang.Type.StructField.Attributes,
5768 comptime field_attrs: *const [field_names.len]std.lang.Type.Struct.FieldAttributes,
57695769) type{#endsyntax#}</pre>
57705770 <p>Returns a {#link|struct#} type with the properties specified by the arguments.</p>
57715771 {#header_close#}
......@@ -5777,7 +5777,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
57775777 comptime ArgType: ?type,
57785778 comptime field_names: []const []const u8,
57795779 comptime field_types: *const [field_names.len]type,
5780 comptime field_attrs: *const [field_names.len]std.lang.Type.UnionField.Attributes,
5780 comptime field_attrs: *const [field_names.len]std.lang.Type.Union.FieldAttributes,
57815781) type{#endsyntax#}</pre>
57825782 <p>Returns a {#link|union#} type with the properties specified by the arguments.</p>
57835783 {#header_close#}
doc/langref/inline_prong_range.zig+2-2
......@@ -1,7 +1,7 @@
11fn isFieldOptional(comptime T: type, field_index: usize) !bool {
2 const fields = @typeInfo(T).@"struct".fields;
2 const field_types = @typeInfo(T).@"struct".field_types;
33 return switch (field_index) {
4 inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .optional,
4 inline 0...field_types.len - 1 => |idx| @typeInfo(field_types[idx]) == .optional,
55 else => return error.IndexOutOfBounds,
66 };
77}
doc/langref/test_enums.zig+2-2
......@@ -102,8 +102,8 @@ test "std.meta.Tag" {
102102
103103// @typeInfo tells us the field count and the fields names:
104104test "@typeInfo" {
105 try expectEqual(4, @typeInfo(Small).@"enum".fields.len);
106 try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");
105 try expectEqual(4, @typeInfo(Small).@"enum".field_names.len);
106 try expectEqualStrings(@typeInfo(Small).@"enum".field_names[1], "two");
107107}
108108
109109// @tagName gives a [:0]const u8 representation of an enum value:
doc/langref/test_fn_reflection.zig+1-1
......@@ -3,7 +3,7 @@ const math = std.math;
33const testing = std.testing;
44
55test "fn reflection" {
6 try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?);
6 try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".param_types[0].?);
77 try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
88
99 try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
doc/langref/test_inline_else.zig+4-3
......@@ -18,12 +18,13 @@ const AnySlice = union(enum) {
1818
1919fn withFor(any: AnySlice) usize {
2020 const Tag = @typeInfo(AnySlice).@"union".tag_type.?;
21 inline for (@typeInfo(Tag).@"enum".fields) |field| {
21 const info = @typeInfo(Tag).@"enum";
22 inline for (info.field_names, info.field_values) |field_name, field_value| {
2223 // With `inline for` the function gets generated as
2324 // a series of `if` statements relying on the optimizer
2425 // to convert it to a switch.
25 if (field.value == @intFromEnum(any)) {
26 return @field(any, field.name).len;
26 if (field_value == @intFromEnum(any)) {
27 return @field(any, field_name).len;
2728 }
2829 }
2930 // When using `inline for` the compiler doesn't know that every
doc/langref/test_inline_switch.zig+2-2
......@@ -3,11 +3,11 @@ const expect = std.testing.expect;
33const expectError = std.testing.expectError;
44
55fn isFieldOptional(comptime T: type, field_index: usize) !bool {
6 const fields = @typeInfo(T).@"struct".fields;
6 const field_types = @typeInfo(T).@"struct".field_types;
77 return switch (field_index) {
88 // This prong is analyzed twice with `idx` being a
99 // comptime-known value each time.
10 inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .optional,
10 inline 0, 1 => |idx| @typeInfo(field_types[idx]) == .optional,
1111 else => return error.IndexOutOfBounds,
1212 };
1313}
doc/langref/test_variable_func_alignment.zig+1-1
......@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;
33var foo: u8 align(4) = 100;
44
55test "global variable alignment" {
6 try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment);
6 try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.attrs.@"align");
77 try expectEqual(*align(4) u8, @TypeOf(&foo));
88 const as_pointer_to_array: *align(4) [1]u8 = &foo;
99 const as_slice: []align(4) u8 = as_pointer_to_array;
doc/langref/test_variadic_function.zig+1-1
......@@ -5,7 +5,7 @@ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
55
66test "variadic function" {
77 try testing.expectEqual(14, printf("Hello, world!\n"));
8 try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args);
8 try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".attrs.varargs);
99}
1010
1111// test
lib/compiler/Maker/ScannedConfig.zig+4-3
......@@ -49,9 +49,10 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
4949}
5050
5151fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: S) !void {
52 inline for (@typeInfo(S).@"struct".fields) |field| {
53 try s.fieldPrefix(field.name);
54 try printValue(sc, s.container.serializer, field.type, @field(v, field.name));
52 const info = @typeInfo(S).@"struct";
53 inline for (info.field_names, info.field_types) |field_name, field_type| {
54 try s.fieldPrefix(field_name);
55 try printValue(sc, s.container.serializer, field_type, @field(v, field_name));
5556 }
5657}
5758
lib/compiler/Maker/Step/FindProgram.zig+2-2
......@@ -113,8 +113,8 @@ fn checkCandidate(
113113}
114114
115115fn supportedWindowsProgramExtension(ext: []const u8) bool {
116 inline for (@typeInfo(std.process.WindowsExtension).@"enum".fields) |field| {
117 if (std.ascii.eqlIgnoreCase(ext, "." ++ field.name)) return true;
116 inline for (@typeInfo(std.process.WindowsExtension).@"enum".field_names) |field_name| {
117 if (std.ascii.eqlIgnoreCase(ext, "." ++ field_name)) return true;
118118 }
119119 return false;
120120}
lib/compiler/Maker/Watch/FsEvents.zig+3-2
......@@ -87,8 +87,9 @@ pub fn init(cwd_path: []const u8) error{ OpenFrameworkFailed, MissingCoreService
8787 errdefer core_services.close();
8888
8989 var resolved_symbols: ResolvedSymbols = undefined;
90 inline for (@typeInfo(ResolvedSymbols).@"struct".fields) |f| {
91 @field(resolved_symbols, f.name) = core_services.lookup(f.type, f.name) orelse return error.MissingCoreServicesSymbol;
90 const info = @typeInfo(ResolvedSymbols).@"struct";
91 inline for (info.field_names, info.field_types) |f_name, f_type| {
92 @field(resolved_symbols, f_name) = core_services.lookup(f_type, f_name) orelse return error.MissingCoreServicesSymbol;
9293 }
9394
9495 return .{
lib/compiler/aro/aro/Attribute.zig+52-51
......@@ -89,9 +89,9 @@ pub fn requiredArgCount(attr: Tag) u32 {
8989 inline else => |tag| {
9090 comptime var needed = 0;
9191 comptime {
92 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
93 for (fields) |arg_field| {
94 if (!mem.eql(u8, arg_field.name, "__name_tok") and @typeInfo(arg_field.type) != .optional) needed += 1;
92 const info = @typeInfo(@field(attributes, @tagName(tag))).@"struct";
93 for (info.field_names, info.field_types) |arg_field_name, arg_field_type| {
94 if (!mem.eql(u8, arg_field_name, "__name_tok") and @typeInfo(arg_field_type) != .optional) needed += 1;
9595 }
9696 }
9797 return needed;
......@@ -105,9 +105,9 @@ pub fn maxArgCount(attr: Tag) u32 {
105105 inline else => |tag| {
106106 comptime var max = 0;
107107 comptime {
108 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
109 for (fields) |arg_field| {
110 if (!mem.eql(u8, arg_field.name, "__name_tok")) max += 1;
108 const field_names = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_names;
109 for (field_names) |arg_field_name| {
110 if (!mem.eql(u8, arg_field_name, "__name_tok")) max += 1;
111111 }
112112 }
113113 return max;
......@@ -130,10 +130,10 @@ pub const Formatting = struct {
130130 switch (attr) {
131131 .calling_convention => unreachable,
132132 inline else => |tag| {
133 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
133 const field_types = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_types;
134134
135 if (fields.len == 0) unreachable;
136 const Unwrapped = UnwrapOptional(fields[0].type);
135 if (field_types.len == 0) unreachable;
136 const Unwrapped = UnwrapOptional(field_types[0]);
137137 if (@typeInfo(Unwrapped) != .@"enum") unreachable;
138138
139139 return if (Unwrapped.opts.enum_kind == .identifier) "'" else "\"";
......@@ -147,18 +147,18 @@ pub const Formatting = struct {
147147 switch (attr) {
148148 .calling_convention => unreachable,
149149 inline else => |tag| {
150 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
150 const field_types = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_types;
151151
152 if (fields.len == 0) unreachable;
153 const Unwrapped = UnwrapOptional(fields[0].type);
152 if (field_types.len == 0) unreachable;
153 const Unwrapped = UnwrapOptional(field_types[0]);
154154 if (@typeInfo(Unwrapped) != .@"enum") unreachable;
155155
156 const enum_fields = @typeInfo(Unwrapped).@"enum".fields;
156 const enum_field_names = @typeInfo(Unwrapped).@"enum".field_names;
157157 const quote = comptime quoteChar(@enumFromInt(@intFromEnum(tag)));
158 comptime var values: []const u8 = quote ++ enum_fields[0].name ++ quote;
159 inline for (enum_fields[1..]) |enum_field| {
158 comptime var values: []const u8 = quote ++ enum_field_names[0] ++ quote;
159 inline for (enum_field_names[1..]) |enum_field_name| {
160160 values = values ++ ", ";
161 values = values ++ quote ++ enum_field.name ++ quote;
161 values = values ++ quote ++ enum_field_name ++ quote;
162162 }
163163 return values;
164164 },
......@@ -171,10 +171,10 @@ pub fn wantsIdentEnum(attr: Tag) bool {
171171 switch (attr) {
172172 .calling_convention => return false,
173173 inline else => |tag| {
174 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
174 const field_types = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_types;
175175
176 if (fields.len == 0) return false;
177 const Unwrapped = UnwrapOptional(fields[0].type);
176 if (field_types.len == 0) return false;
177 const Unwrapped = UnwrapOptional(field_types[0]);
178178 if (@typeInfo(Unwrapped) != .@"enum") return false;
179179
180180 return Unwrapped.opts.enum_kind == .identifier;
......@@ -185,12 +185,12 @@ pub fn wantsIdentEnum(attr: Tag) bool {
185185pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Parser) !bool {
186186 switch (attr) {
187187 inline else => |tag| {
188 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
189 if (fields.len == 0) unreachable;
190 const Unwrapped = UnwrapOptional(fields[0].type);
188 const info = @typeInfo(@field(attributes, @tagName(tag))).@"struct";
189 if (info.field_names.len == 0) unreachable;
190 const Unwrapped = UnwrapOptional(info.field_types[0]);
191191 if (@typeInfo(Unwrapped) != .@"enum") unreachable;
192192 if (std.meta.stringToEnum(Unwrapped, normalize(p.tokSlice(ident)))) |enum_val| {
193 @field(@field(arguments, @tagName(tag)), fields[0].name) = enum_val;
193 @field(@field(arguments, @tagName(tag)), info.field_names[0]) = enum_val;
194194 return false;
195195 }
196196
......@@ -203,11 +203,11 @@ pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Pa
203203pub fn wantsAlignment(attr: Tag, idx: usize) bool {
204204 switch (attr) {
205205 inline else => |tag| {
206 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
207 if (fields.len == 0) return false;
206 const field_types = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_types;
207 if (field_types.len == 0) return false;
208208
209209 return switch (idx) {
210 inline 0...fields.len - 1 => |i| UnwrapOptional(fields[i].type) == Alignment,
210 inline 0...field_types.len - 1 => |i| UnwrapOptional(field_types[i]) == Alignment,
211211 else => false,
212212 };
213213 },
......@@ -217,12 +217,12 @@ pub fn wantsAlignment(attr: Tag, idx: usize) bool {
217217pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, p: *Parser) !bool {
218218 switch (attr) {
219219 inline else => |tag| {
220 const arg_fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;
221 if (arg_fields.len == 0) unreachable;
220 const arg_info = @typeInfo(@field(attributes, @tagName(tag))).@"struct";
221 if (arg_info.field_names.len == 0) unreachable;
222222
223223 switch (arg_idx) {
224 inline 0...arg_fields.len - 1 => |arg_i| {
225 if (UnwrapOptional(arg_fields[arg_i].type) != Alignment) unreachable;
224 inline 0...arg_info.field_names.len - 1 => |arg_i| {
225 if (UnwrapOptional(arg_info.field_types[arg_i]) != Alignment) unreachable;
226226
227227 if (!res.val.is(.int, p.comp)) {
228228 try p.err(arg_start, .alignas_unavailable, .{});
......@@ -241,7 +241,7 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa
241241 return true;
242242 }
243243
244 @field(@field(arguments, @tagName(tag)), arg_fields[arg_i].name) = .{ .requested = requested };
244 @field(@field(arguments, @tagName(tag)), arg_info.field_names[arg_i]) = .{ .requested = requested };
245245 return false;
246246 },
247247 else => unreachable,
......@@ -251,8 +251,8 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa
251251}
252252
253253fn diagnoseField(
254 comptime decl: ZigType.Declaration,
255 comptime field: ZigType.StructField,
254 comptime decl_name: []const u8,
255 comptime field_name: []const u8,
256256 comptime Wanted: type,
257257 arguments: *Arguments,
258258 res: Parser.Result,
......@@ -283,7 +283,7 @@ fn diagnoseField(
283283
284284 if (res.val.opt_ref == .none) {
285285 if (Wanted == Identifier and node == .decl_ref_expr) {
286 @field(@field(arguments, decl.name), field.name) = .{ .tok = node.decl_ref_expr.name_tok };
286 @field(@field(arguments, decl_name), field_name) = .{ .tok = node.decl_ref_expr.name_tok };
287287 return false;
288288 }
289289
......@@ -294,7 +294,7 @@ fn diagnoseField(
294294 switch (key) {
295295 .int => {
296296 if (@typeInfo(Wanted) == .int) {
297 @field(@field(arguments, decl.name), field.name) = res.val.toInt(Wanted, p.comp) orelse {
297 @field(@field(arguments, decl_name), field_name) = res.val.toInt(Wanted, p.comp) orelse {
298298 try p.err(arg_start, .attribute_int_out_of_range, .{res});
299299 return true;
300300 };
......@@ -310,20 +310,20 @@ fn diagnoseField(
310310 .char, .uchar, .schar => {},
311311 else => break :validate,
312312 }
313 @field(@field(arguments, decl.name), field.name) = try p.removeNull(res.val);
313 @field(@field(arguments, decl_name), field_name) = try p.removeNull(res.val);
314314 return false;
315315 }
316316
317 try p.err(arg_start, .attribute_requires_string, .{decl.name});
317 try p.err(arg_start, .attribute_requires_string, .{decl_name});
318318 return true;
319319 } else if (@typeInfo(Wanted) == .@"enum" and @hasDecl(Wanted, "opts") and Wanted.opts.enum_kind == .string) {
320320 const str = bytes[0 .. bytes.len - 1];
321321 if (std.meta.stringToEnum(Wanted, str)) |enum_val| {
322 @field(@field(arguments, decl.name), field.name) = enum_val;
322 @field(@field(arguments, decl_name), field_name) = enum_val;
323323 return false;
324324 }
325325
326 try p.err(arg_start, .unknown_attr_enum, .{ decl.name, Formatting.choices(@field(Tag, decl.name)) });
326 try p.err(arg_start, .unknown_attr_enum, .{ decl_name, Formatting.choices(@field(Tag, decl_name)) });
327327 return true;
328328 }
329329 },
......@@ -344,17 +344,18 @@ fn diagnoseField(
344344pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool {
345345 switch (attr) {
346346 inline else => |tag| {
347 const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];
347 const decl_name = @typeInfo(attributes).@"struct".decl_names[@intFromEnum(tag)];
348348 const max_arg_count = comptime maxArgCount(tag);
349349 if (arg_idx >= max_arg_count) {
350350 try p.err(arg_start, .attribute_too_many_args, .{ @tagName(attr), max_arg_count });
351351 return true;
352352 }
353353
354 const arg_fields = @typeInfo(@field(attributes, decl.name)).@"struct".fields;
354 const arg_field_names = @typeInfo(@field(attributes, decl_name)).@"struct".field_names;
355 const arg_field_types = @typeInfo(@field(attributes, decl_name)).@"struct".field_types;
355356 switch (arg_idx) {
356 inline 0...arg_fields.len - 1 => |arg_i| {
357 return diagnoseField(decl, arg_fields[arg_i], UnwrapOptional(arg_fields[arg_i].type), arguments, res, arg_start, node, p);
357 inline 0...arg_field_names.len - 1 => |arg_i| {
358 return diagnoseField(decl_name, arg_field_names[arg_i], UnwrapOptional(arg_field_types[arg_i]), arguments, res, arg_start, node, p);
358359 },
359360 else => unreachable,
360361 }
......@@ -722,20 +723,20 @@ const attributes = struct {
722723pub const Tag = std.meta.DeclEnum(attributes);
723724
724725pub const Arguments = blk: {
725 const decls = @typeInfo(attributes).@"struct".decls;
726 var names: [decls.len][]const u8 = undefined;
727 var types: [decls.len]type = undefined;
728 for (decls, &names, &types) |decl, *name, *T| {
729 name.* = decl.name;
730 T.* = @field(attributes, decl.name);
726 const decl_names = @typeInfo(attributes).@"struct".decl_names;
727 var names: [decl_names.len][]const u8 = undefined;
728 var types: [decl_names.len]type = undefined;
729 for (decl_names, &names, &types) |decl_name, *name, *T| {
730 name.* = decl_name;
731 T.* = @field(attributes, decl_name);
731732 }
732733
733734 break :blk @Union(.auto, null, &names, &types, &@splat(.{}));
734735};
735736
736737pub fn ArgumentsForTag(comptime tag: Tag) type {
737 const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];
738 return @field(attributes, decl.name);
738 const decl_name = @typeInfo(attributes).@"struct".decl_names[@intFromEnum(tag)];
739 return @field(attributes, decl_name);
739740}
740741
741742pub fn initArguments(tag: Tag, name_tok: TokenIndex) Arguments {
lib/compiler/aro/aro/Compilation.zig+5-5
......@@ -78,12 +78,12 @@ pub const Environment = struct {
7878 pub fn loadAll(environ_map: *const std.process.Environ.Map) Environment {
7979 var env: Environment = .{};
8080
81 inline for (@typeInfo(@TypeOf(env)).@"struct".fields) |field| {
82 std.debug.assert(@field(env, field.name) == null);
81 inline for (@typeInfo(@TypeOf(env)).@"struct".field_names) |field_name| {
82 std.debug.assert(@field(env, field_name) == null);
8383
84 var env_var_buf: [field.name.len]u8 = undefined;
85 const env_var_name = std.ascii.upperString(&env_var_buf, field.name);
86 @field(env, field.name) = environ_map.get(env_var_name);
84 var env_var_buf: [field_name.len]u8 = undefined;
85 const env_var_name = std.ascii.upperString(&env_var_buf, field_name);
86 @field(env, field_name) = environ_map.get(env_var_name);
8787 }
8888 return env;
8989 }
lib/compiler/aro/aro/Diagnostics.zig+7-7
......@@ -333,8 +333,8 @@ pub fn deinit(d: *Diagnostics) void {
333333/// Used by the __has_warning builtin macro.
334334pub fn warningExists(name: []const u8) bool {
335335 if (std.mem.eql(u8, name, "pedantic")) return true;
336 inline for (comptime std.meta.declarations(Option)) |group| {
337 if (std.mem.eql(u8, name, group.name)) return true;
336 inline for (comptime std.meta.declarations(Option)) |group_name| {
337 if (std.mem.eql(u8, name, group_name)) return true;
338338 }
339339 return std.meta.stringToEnum(Option, name) != null;
340340}
......@@ -349,9 +349,9 @@ pub fn set(d: *Diagnostics, name: []const u8, to: Message.Kind) Compilation.Erro
349349 return;
350350 }
351351
352 inline for (comptime std.meta.declarations(Option)) |group| {
353 if (std.mem.eql(u8, name, group.name)) {
354 for (@field(Option, group.name)) |option| {
352 inline for (comptime std.meta.declarations(Option)) |group_name| {
353 if (std.mem.eql(u8, name, group_name)) {
354 for (@field(Option, group_name)) |option| {
355355 d.state.options.put(option, to);
356356 }
357357 return;
......@@ -494,8 +494,8 @@ pub fn addWithLocation(
494494
495495pub fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) std.Io.Writer.Error!void {
496496 var i: usize = 0;
497 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {
498 const arg = @field(args, arg_info.name);
497 inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| {
498 const arg = @field(args, arg_name);
499499 i += switch (@TypeOf(arg)) {
500500 []const u8 => try formatString(w, fmt[i..], arg),
501501 else => switch (@typeInfo(@TypeOf(arg))) {
lib/compiler/aro/aro/Parser.zig+2-2
......@@ -456,8 +456,8 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
456456
457457fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {
458458 var i: usize = 0;
459 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {
460 const arg = @field(args, arg_info.name);
459 inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| {
460 const arg = @field(args, arg_name);
461461 i += switch (@TypeOf(arg)) {
462462 []const u8 => try Diagnostics.formatString(w, fmt[i..], arg),
463463 Tree.Token.Id => try formatTokenId(w, fmt[i..], arg),
lib/compiler/aro/aro/Tree.zig+11-11
......@@ -3048,25 +3048,25 @@ fn dumpAttribute(tree: *const Tree, attr: Attribute, w: *std.Io.Writer) !void {
30483048 switch (attr.tag) {
30493049 inline else => |tag| {
30503050 const args = @field(attr.args, @tagName(tag));
3051 const fields = @typeInfo(@TypeOf(args)).@"struct".fields;
3052 if (fields.len == 0) {
3051 const args_info = @typeInfo(@TypeOf(args)).@"struct";
3052 if (args_info.field_names.len == 0) {
30533053 try w.writeByte('\n');
30543054 return;
30553055 }
30563056 try w.writeByte(' ');
3057 inline for (fields, 0..) |f, i| {
3058 if (comptime std.mem.eql(u8, f.name, "__name_tok")) continue;
3057 inline for (args_info.field_names, args_info.field_types, 0..) |f_name, f_type, i| {
3058 if (comptime std.mem.eql(u8, f_name, "__name_tok")) continue;
30593059 if (i != 0) {
30603060 try w.writeAll(", ");
30613061 }
3062 try w.writeAll(f.name);
3062 try w.writeAll(f_name);
30633063 try w.writeAll(": ");
3064 switch (f.type) {
3065 Interner.Ref => try w.print("\"{s}\"", .{tree.interner.get(@field(args, f.name)).bytes}),
3066 ?Interner.Ref => try w.print("\"{?s}\"", .{if (@field(args, f.name)) |str| tree.interner.get(str).bytes else null}),
3067 else => switch (@typeInfo(f.type)) {
3068 .@"enum" => try w.writeAll(@tagName(@field(args, f.name))),
3069 else => try w.print("{any}", .{@field(args, f.name)}),
3064 switch (f_type) {
3065 Interner.Ref => try w.print("\"{s}\"", .{tree.interner.get(@field(args, f_name)).bytes}),
3066 ?Interner.Ref => try w.print("\"{?s}\"", .{if (@field(args, f_name)) |str| tree.interner.get(str).bytes else null}),
3067 else => switch (@typeInfo(f_type)) {
3068 .@"enum" => try w.writeAll(@tagName(@field(args, f_name))),
3069 else => try w.print("{any}", .{@field(args, f_name)}),
30703070 },
30713071 }
30723072 }
lib/compiler/aro/aro/features.zig+4-4
......@@ -46,8 +46,8 @@ pub fn hasFeature(comp: *Compilation, ext: []const u8) bool {
4646 .c_thread_local = comp.langopts.standard.atLeast(.c11) and comp.target.isTlsSupported(),
4747 .bounds_attributes = comp.langopts.bounds_safety == .clang,
4848 };
49 inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {
50 if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name);
49 inline for (@typeInfo(@TypeOf(list)).@"struct".field_names) |f_name| {
50 if (std.mem.eql(u8, f_name, ext)) return @field(list, f_name);
5151 }
5252 return false;
5353}
......@@ -70,8 +70,8 @@ pub fn hasExtension(comp: *Compilation, ext: []const u8) bool {
7070 .matrix_types = false, // TODO
7171 .matrix_types_scalar_division = false, // TODO
7272 };
73 inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {
74 if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name);
73 inline for (@typeInfo(@TypeOf(list)).@"struct".field_names) |f_name| {
74 if (std.mem.eql(u8, f_name, ext)) return @field(list, f_name);
7575 }
7676 return false;
7777}
lib/compiler/aro/aro/text_literal.zig+2-2
......@@ -335,8 +335,8 @@ pub const Parser = struct {
335335
336336 fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {
337337 var i: usize = 0;
338 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {
339 const arg = @field(args, arg_info.name);
338 inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| {
339 const arg = @field(args, arg_name);
340340 i += switch (@TypeOf(arg)) {
341341 []const u8 => try Diagnostics.formatString(w, fmt[i..], arg),
342342 Ascii => try arg.format(w, fmt[i..]),
lib/compiler/aro/backend/Interner.zig+14-13
......@@ -733,7 +733,7 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
733733 });
734734 },
735735 .record_ty => |elems| {
736 try i.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.Record).@"struct".fields.len +
736 try i.extra.ensureUnusedCapacity(gpa, @typeInfo(Tag.Record).@"struct".field_names.len +
737737 elems.len);
738738 i.items.appendAssumeCapacity(.{
739739 .tag = .record_ty,
......@@ -755,18 +755,19 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
755755}
756756
757757fn addExtra(i: *Interner, gpa: Allocator, extra: anytype) Allocator.Error!u32 {
758 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
759 try i.extra.ensureUnusedCapacity(gpa, fields.len);
758 const field_count = @typeInfo(@TypeOf(extra)).@"struct".field_names.len;
759 try i.extra.ensureUnusedCapacity(gpa, field_count);
760760 return i.addExtraAssumeCapacity(extra);
761761}
762762
763763fn addExtraAssumeCapacity(i: *Interner, extra: anytype) u32 {
764764 const result = @as(u32, @intCast(i.extra.items.len));
765 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
766 i.extra.appendAssumeCapacity(switch (field.type) {
767 Ref => @intFromEnum(@field(extra, field.name)),
768 u32 => @field(extra, field.name),
769 else => @compileError("bad field type: " ++ @typeName(field.type)),
765 const info = @typeInfo(@TypeOf(extra)).@"struct";
766 inline for (info.field_names, info.field_types) |field_name, field_type| {
767 i.extra.appendAssumeCapacity(switch (field_type) {
768 Ref => @intFromEnum(@field(extra, field_name)),
769 u32 => @field(extra, field_name),
770 else => @compileError("bad field type: " ++ @typeName(field_type)),
770771 });
771772 }
772773 return result;
......@@ -891,17 +892,17 @@ fn extraData(i: *const Interner, comptime T: type, index: usize) T {
891892
892893fn extraDataTrail(i: *const Interner, comptime T: type, index: usize) struct { data: T, end: u32 } {
893894 var result: T = undefined;
894 const fields = @typeInfo(T).@"struct".fields;
895 inline for (fields, 0..) |field, field_i| {
895 const info = @typeInfo(T).@"struct";
896 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, field_i| {
896897 const int32 = i.extra.items[field_i + index];
897 @field(result, field.name) = switch (field.type) {
898 @field(result, field_name) = switch (field_type) {
898899 Ref => @enumFromInt(int32),
899900 u32 => int32,
900 else => @compileError("bad field type: " ++ @typeName(field.type)),
901 else => @compileError("bad field type: " ++ @typeName(field_type)),
901902 };
902903 }
903904 return .{
904905 .data = result,
905 .end = @intCast(index + fields.len),
906 .end = @intCast(index + info.field_names.len),
906907 };
907908}
lib/compiler/configurer.zig+2-2
......@@ -601,8 +601,8 @@ const Serialize = struct {
601601 dest_module.* = try addModule(s, src_module);
602602 }
603603
604 comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".fields[2].name, "import_table"));
605 comptime assert(@typeInfo(Configuration.Module).@"struct".fields[2].type == Configuration.ImportTable.Index);
604 comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".field_names[2], "import_table"));
605 comptime assert(@typeInfo(Configuration.Module).@"struct".field_types[2] == Configuration.ImportTable.Index);
606606 assert(wc.extra.items[@intFromEnum(module_index) + 2] == @intFromEnum(Configuration.ImportTable.Index.invalid));
607607 const import_table_index = try wc.addDeduped(Configuration.ImportTable, .{
608608 .imports = .{ .mal = imports },
lib/compiler/resinator/bmp.zig+3-2
......@@ -241,8 +241,9 @@ pub const Compression = enum(u32) {
241241};
242242
243243fn structFieldsLittleToNative(comptime T: type, x: *T) void {
244 inline for (@typeInfo(T).@"struct".fields) |field| {
245 @field(x, field.name) = std.mem.littleToNative(field.type, @field(x, field.name));
244 const info = @typeInfo(T).@"struct";
245 inline for (info.field_names, info.field_types) |field_name, field_type| {
246 @field(x, field_name) = std.mem.littleToNative(field_type, @field(x, field_name));
246247 }
247248}
248249
lib/compiler/resinator/code_pages.zig+14-12
......@@ -178,19 +178,20 @@ pub const UnsupportedCodePage = enum(u16) {
178178};
179179
180180pub const CodePage = blk: {
181 const fields = @typeInfo(SupportedCodePage).@"enum".fields ++ @typeInfo(UnsupportedCodePage).@"enum".fields;
182 var field_names: [fields.len][]const u8 = undefined;
183 var field_values: [fields.len]u16 = undefined;
184 for (fields, &field_names, &field_values) |field, *name, *val| {
185 name.* = field.name;
186 val.* = field.value;
181 const field_names = @typeInfo(SupportedCodePage).@"enum".field_names ++ @typeInfo(UnsupportedCodePage).@"enum".field_names;
182 const field_values = @typeInfo(SupportedCodePage).@"enum".field_values ++ @typeInfo(UnsupportedCodePage).@"enum".field_values;
183 var cp_field_names: [field_names.len][]const u8 = undefined;
184 var cp_field_values: [field_names.len]u16 = undefined;
185 for (field_names, field_values, &cp_field_names, &cp_field_values) |field_name, field_value, *name, *val| {
186 name.* = field_name;
187 val.* = field_value;
187188 }
188 break :blk @Enum(u16, .exhaustive, &field_names, &field_values);
189 break :blk @Enum(u16, .exhaustive, &cp_field_names, &cp_field_values);
189190};
190191
191192pub fn isSupported(code_page: CodePage) bool {
192 inline for (@typeInfo(SupportedCodePage).@"enum".fields) |enumField| {
193 if (@intFromEnum(code_page) == @intFromEnum(@field(SupportedCodePage, enumField.name))) {
193 inline for (@typeInfo(SupportedCodePage).@"enum".field_names) |field_name| {
194 if (@intFromEnum(code_page) == @intFromEnum(@field(SupportedCodePage, field_name))) {
194195 return true;
195196 }
196197 }
......@@ -200,9 +201,10 @@ pub fn isSupported(code_page: CodePage) bool {
200201pub fn getByIdentifier(identifier: u16) !CodePage {
201202 // There's probably a more efficient way to do this (e.g. ComptimeHashMap?) but
202203 // this should be fine, especially since this function likely won't be called much.
203 inline for (@typeInfo(CodePage).@"enum".fields) |enumField| {
204 if (identifier == enumField.value) {
205 return @field(CodePage, enumField.name);
204 const info = @typeInfo(CodePage).@"enum";
205 inline for (info.field_names, info.field_values) |field_name, field_value| {
206 if (identifier == field_value) {
207 return @field(CodePage, field_name);
206208 }
207209 }
208210 return error.InvalidCodePage;
lib/compiler/resinator/cvtres.zig+11-10
......@@ -1054,17 +1054,18 @@ pub const supported_targets = struct {
10541054 .ebc,
10551055 };
10561056 comptime {
1057 for (@typeInfo(Arch).@"enum".fields) |enum_field| {
1058 _ = std.mem.indexOfScalar(Arch, ordered_for_display, @enumFromInt(enum_field.value)) orelse {
1059 @compileError(std.fmt.comptimePrint("'{s}' missing from ordered_for_display", .{enum_field.name}));
1057 const info = @typeInfo(Arch).@"enum";
1058 for (info.field_names, info.field_values) |field_name, field_value| {
1059 _ = std.mem.indexOfScalar(Arch, ordered_for_display, @enumFromInt(field_value)) orelse {
1060 @compileError(std.fmt.comptimePrint("'{s}' missing from ordered_for_display", .{field_name}));
10601061 };
10611062 }
10621063 }
10631064
10641065 pub const longest_name = blk: {
10651066 var len = 0;
1066 for (@typeInfo(Arch).@"enum".fields) |field| {
1067 if (field.name.len > len) len = field.name.len;
1067 for (@typeInfo(Arch).@"enum".field_names) |field_name| {
1068 if (field_name.len > len) len = field_name.len;
10681069 }
10691070 break :blk len;
10701071 };
......@@ -1106,14 +1107,14 @@ pub const supported_targets = struct {
11061107 // Enforce two things:
11071108 // 1. Arch enum field names are all lowercase (necessary for how fromStringIgnoreCase is implemented)
11081109 // 2. All enum fields in Arch have an associated RVA relocation type when converted to a coff.IMAGE.FILE.MACHINE
1109 for (@typeInfo(Arch).@"enum".fields) |enum_field| {
1110 const all_lower = all_lower: for (enum_field.name) |c| {
1110 for (@typeInfo(Arch).@"enum".field_names) |field_name| {
1111 const all_lower = all_lower: for (field_name) |c| {
11111112 if (std.ascii.isUpper(c)) break :all_lower false;
11121113 } else break :all_lower true;
1113 if (!all_lower) @compileError(std.fmt.comptimePrint("Arch field is not all lowercase: {s}", .{enum_field.name}));
1114 const coff_machine = @field(Arch, enum_field.name).toCoffMachineType();
1114 if (!all_lower) @compileError(std.fmt.comptimePrint("Arch field is not all lowercase: {s}", .{field_name}));
1115 const coff_machine = @field(Arch, field_name).toCoffMachineType();
11151116 _ = rvaRelocationTypeIndicator(coff_machine) orelse {
1116 @compileError(std.fmt.comptimePrint("No RVA relocation for Arch: {s}", .{enum_field.name}));
1117 @compileError(std.fmt.comptimePrint("No RVA relocation for Arch: {s}", .{field_name}));
11171118 };
11181119 }
11191120 }
lib/compiler/resinator/errors.zig+18-22
......@@ -145,8 +145,8 @@ pub const ErrorDetails = struct {
145145
146146 comptime {
147147 // all fields in the extra union should be 32 bits or less
148 for (std.meta.fields(Extra)) |field| {
149 std.debug.assert(@bitSizeOf(field.type) <= 32);
148 for (std.meta.fieldTypes(Extra)) |field_type| {
149 std.debug.assert(@bitSizeOf(field_type) <= 32);
150150 }
151151 }
152152
......@@ -257,18 +257,18 @@ pub const ErrorDetails = struct {
257257
258258 pub fn writeCommaSeparated(self: ExpectedTypes, writer: *std.Io.Writer) !void {
259259 const struct_info = @typeInfo(ExpectedTypes).@"struct";
260 const num_real_fields = struct_info.fields.len - 1;
260 const num_real_fields = struct_info.field_names.len - 1;
261261 const num_padding_bits = @bitSizeOf(ExpectedTypes) - num_real_fields;
262262 const mask = std.math.maxInt(struct_info.backing_integer.?) >> num_padding_bits;
263263 const relevant_bits_only = @as(struct_info.backing_integer.?, @bitCast(self)) & mask;
264264 const num_set_bits = @popCount(relevant_bits_only);
265265
266266 var i: usize = 0;
267 inline for (struct_info.fields) |field_info| {
268 if (field_info.type != bool) continue;
267 inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| {
268 if (field_type != bool) continue;
269269 if (i == num_set_bits) return;
270 if (@field(self, field_info.name)) {
271 try writer.writeAll(strings.get(field_info.name).?);
270 if (@field(self, field_name)) {
271 try writer.writeAll(strings.get(field_name).?);
272272 i += 1;
273273 if (num_set_bits > 2 and i != num_set_bits) {
274274 try writer.writeAll(", ");
......@@ -857,24 +857,20 @@ pub const ErrorDetails = struct {
857857
858858/// Convenience struct only useful when the code page can be inferred from the token
859859pub const ErrorDetailsWithoutCodePage = blk: {
860 const details_info = @typeInfo(ErrorDetails);
861 const fields = details_info.@"struct".fields;
862 var field_names: [fields.len - 1][]const u8 = undefined;
863 var field_types: [fields.len - 1]type = undefined;
864 var field_attrs: [fields.len - 1]std.builtin.Type.StructField.Attributes = undefined;
860 const details_info = @typeInfo(ErrorDetails).@"struct";
861 const field_count = details_info.field_names.len;
862 var field_names: [field_count - 1][]const u8 = undefined;
863 var field_types: [field_count - 1]type = undefined;
864 var field_attrs: [field_count - 1]std.builtin.Type.Struct.FieldAttributes = undefined;
865865 var i: usize = 0;
866 for (fields) |field| {
867 if (std.mem.eql(u8, field.name, "code_page")) continue;
868 field_names[i] = field.name;
869 field_types[i] = field.type;
870 field_attrs[i] = .{
871 .@"comptime" = field.is_comptime,
872 .@"align" = field.alignment,
873 .default_value_ptr = field.default_value_ptr,
874 };
866 for (details_info.field_names, details_info.field_types, details_info.field_attrs) |field_name, field_type, field_attr| {
867 if (std.mem.eql(u8, field_name, "code_page")) continue;
868 field_names[i] = field_name;
869 field_types[i] = field_type;
870 field_attrs[i] = field_attr;
875871 i += 1;
876872 }
877 std.debug.assert(i == fields.len - 1);
873 std.debug.assert(i == field_count - 1);
878874 break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
879875};
880876
lib/compiler/resinator/lang.zig+7-7
......@@ -87,8 +87,8 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId {
8787 if (parsed.multiple_suffixes) return null;
8888 const longest_known_tag = comptime blk: {
8989 var len = 0;
90 for (@typeInfo(LanguageId).@"enum".fields) |field| {
91 if (field.name.len > len) len = field.name.len;
90 for (@typeInfo(LanguageId).@"enum".field_names) |field_name| {
91 if (field_name.len > len) len = field_name.len;
9292 }
9393 break :blk len;
9494 };
......@@ -120,13 +120,13 @@ test tagToId {
120120
121121test "exhaustive tagToId" {
122122 @setEvalBranchQuota(2000);
123 inline for (@typeInfo(LanguageId).@"enum".fields) |field| {
124 const id = tagToId(field.name) catch |err| {
125 std.debug.print("tag: {s}\n", .{field.name});
123 inline for (@typeInfo(LanguageId).@"enum".field_names) |field_name| {
124 const id = tagToId(field_name) catch |err| {
125 std.debug.print("tag: {s}\n", .{field_name});
126126 return err;
127127 };
128 try std.testing.expectEqual(@field(LanguageId, field.name), id orelse {
129 std.debug.print("tag: {s}, got null\n", .{field.name});
128 try std.testing.expectEqual(@field(LanguageId, field_name), id orelse {
129 std.debug.print("tag: {s}, got null\n", .{field_name});
130130 return error.TestExpectedEqual;
131131 });
132132 }
lib/compiler/resinator/parse.zig+1-1
......@@ -137,7 +137,7 @@ pub const Parser = struct {
137137 fn parseOptionalStatements(self: *Self, resource: ResourceType) ![]*Node {
138138 var optional_statements: std.ArrayList(*Node) = .empty;
139139
140 const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len;
140 const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".field_names.len;
141141 var statement_type_has_duplicates: [num_statement_types]bool = @splat(false);
142142 var last_statement_per_type: [num_statement_types]?*Node = @splat(null);
143143
lib/compiler/translate-c/ast.zig+6-6
......@@ -925,18 +925,18 @@ const Context = struct {
925925 }
926926
927927 fn addExtra(c: *Context, extra: anytype) Allocator.Error!std.zig.Ast.ExtraIndex {
928 const fields = std.meta.fields(@TypeOf(extra));
929 try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len);
928 const info = @typeInfo(@TypeOf(extra)).@"struct";
929 try c.extra_data.ensureUnusedCapacity(c.gpa, info.field_names.len);
930930 const result: std.zig.Ast.ExtraIndex = @enumFromInt(c.extra_data.items.len);
931 inline for (fields) |field| {
932 const data: u32 = switch (field.type) {
931 inline for (info.field_names, info.field_types) |field_name, field_type| {
932 const data: u32 = switch (field_type) {
933933 NodeIndex,
934934 std.zig.Ast.Node.OptionalIndex,
935935 std.zig.Ast.OptionalTokenIndex,
936936 std.zig.Ast.ExtraIndex,
937 => @intFromEnum(@field(extra, field.name)),
937 => @intFromEnum(@field(extra, field_name)),
938938 TokenIndex,
939 => @field(extra, field.name),
939 => @field(extra, field_name),
940940 else => @compileError("unexpected field type"),
941941 };
942942 c.extra_data.appendAssumeCapacity(data);
lib/docs/wasm/markdown/Document.zig+3-3
......@@ -170,11 +170,11 @@ pub fn ExtraData(comptime T: type) type {
170170}
171171
172172pub fn extraData(doc: Document, comptime T: type, index: ExtraIndex) ExtraData(T) {
173 const fields = @typeInfo(T).@"struct".fields;
173 const info = @typeInfo(T).@"struct";
174174 var i: usize = @intFromEnum(index);
175175 var result: T = undefined;
176 inline for (fields) |field| {
177 @field(result, field.name) = switch (field.type) {
176 inline for (info.field_names, info.field_types) |field_name, field_type| {
177 @field(result, field_name) = switch (field_type) {
178178 u32 => doc.extra[i],
179179 else => @compileError("bad field type"),
180180 };
lib/docs/wasm/markdown/Parser.zig+3-3
......@@ -1574,11 +1574,11 @@ fn parseInlines(p: *Parser, content: []const u8) !ExtraIndex {
15741574}
15751575
15761576pub fn extraData(p: Parser, comptime T: type, index: ExtraIndex) ExtraData(T) {
1577 const fields = @typeInfo(T).@"struct".fields;
1577 const info = @typeInfo(T).@"struct";
15781578 var i: usize = @intFromEnum(index);
15791579 var result: T = undefined;
1580 inline for (fields) |field| {
1581 @field(result, field.name) = switch (field.type) {
1580 inline for (info.field_names, info.field_types) |field_name, field_type| {
1581 @field(result, field_name) = switch (field_type) {
15821582 u32 => p.extra.items[i],
15831583 else => @compileError("bad field type"),
15841584 };
lib/std/Build.zig+52-53
......@@ -389,9 +389,10 @@ fn createChild(
389389
390390fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap {
391391 var map = UserInputOptionsMap.init(arena);
392 inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| {
393 if (field.type == @TypeOf(null)) continue;
394 addUserInputOptionFromArg(arena, &map, field, field.type, @field(args, field.name));
392 const args_info = @typeInfo(@TypeOf(args)).@"struct";
393 inline for (args_info.field_names, args_info.field_types) |field_name, field_type| {
394 if (field_type == @TypeOf(null)) continue;
395 addUserInputOptionFromArg(arena, &map, field_name, field_type, @field(args, field_name));
395396 }
396397 return map;
397398}
......@@ -399,15 +400,15 @@ fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap
399400fn addUserInputOptionFromArg(
400401 arena: Allocator,
401402 map: *UserInputOptionsMap,
402 field: std.builtin.Type.StructField,
403 field_name: [:0]const u8,
403404 comptime T: type,
404405 /// If null, the value won't be added, but `T` will still be type-checked.
405406 maybe_value: ?T,
406407) void {
407408 switch (T) {
408409 Target.Query => return if (maybe_value) |v| {
409 map.put(field.name, .{
410 .name = field.name,
410 map.put(field_name, .{
411 .name = field_name,
411412 .value = .{ .scalar = v.zigTriple(arena) catch @panic("OOM") },
412413 .used = false,
413414 }) catch @panic("OOM");
......@@ -418,8 +419,8 @@ fn addUserInputOptionFromArg(
418419 }) catch @panic("OOM");
419420 },
420421 ResolvedTarget => return if (maybe_value) |v| {
421 map.put(field.name, .{
422 .name = field.name,
422 map.put(field_name, .{
423 .name = field_name,
423424 .value = .{ .scalar = v.query.zigTriple(arena) catch @panic("OOM") },
424425 .used = false,
425426 }) catch @panic("OOM");
......@@ -430,15 +431,15 @@ fn addUserInputOptionFromArg(
430431 }) catch @panic("OOM");
431432 },
432433 std.zig.BuildId => return if (maybe_value) |v| {
433 map.put(field.name, .{
434 .name = field.name,
434 map.put(field_name, .{
435 .name = field_name,
435436 .value = .{ .scalar = std.fmt.allocPrint(arena, "{f}", .{v}) catch @panic("OOM") },
436437 .used = false,
437438 }) catch @panic("OOM");
438439 },
439440 LazyPath => return if (maybe_value) |v| {
440 map.put(field.name, .{
441 .name = field.name,
441 map.put(field_name, .{
442 .name = field_name,
442443 .value = .{ .lazy_path = v.dupeInner(arena) },
443444 .used = false,
444445 }) catch @panic("OOM");
......@@ -446,15 +447,15 @@ fn addUserInputOptionFromArg(
446447 []const LazyPath => return if (maybe_value) |v| {
447448 var list = std.array_list.Managed(LazyPath).initCapacity(arena, v.len) catch @panic("OOM");
448449 for (v) |lp| list.appendAssumeCapacity(lp.dupeInner(arena));
449 map.put(field.name, .{
450 .name = field.name,
450 map.put(field_name, .{
451 .name = field_name,
451452 .value = .{ .lazy_path_list = list },
452453 .used = false,
453454 }) catch @panic("OOM");
454455 },
455456 []const u8 => return if (maybe_value) |v| {
456 map.put(field.name, .{
457 .name = field.name,
457 map.put(field_name, .{
458 .name = field_name,
458459 .value = .{ .scalar = arena.dupe(u8, v) catch @panic("OOM") },
459460 .used = false,
460461 }) catch @panic("OOM");
......@@ -462,37 +463,37 @@ fn addUserInputOptionFromArg(
462463 []const []const u8 => return if (maybe_value) |v| {
463464 var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM");
464465 for (v) |s| list.appendAssumeCapacity(arena.dupe(u8, s) catch @panic("OOM"));
465 map.put(field.name, .{
466 .name = field.name,
466 map.put(field_name, .{
467 .name = field_name,
467468 .value = .{ .list = list },
468469 .used = false,
469470 }) catch @panic("OOM");
470471 },
471472 else => switch (@typeInfo(T)) {
472473 .bool => return if (maybe_value) |v| {
473 map.put(field.name, .{
474 .name = field.name,
474 map.put(field_name, .{
475 .name = field_name,
475476 .value = .{ .scalar = if (v) "true" else "false" },
476477 .used = false,
477478 }) catch @panic("OOM");
478479 },
479480 .@"enum", .enum_literal => return if (maybe_value) |v| {
480 map.put(field.name, .{
481 .name = field.name,
481 map.put(field_name, .{
482 .name = field_name,
482483 .value = .{ .scalar = @tagName(v) },
483484 .used = false,
484485 }) catch @panic("OOM");
485486 },
486487 .comptime_int, .int => return if (maybe_value) |v| {
487 map.put(field.name, .{
488 .name = field.name,
488 map.put(field_name, .{
489 .name = field_name,
489490 .value = .{ .scalar = std.fmt.allocPrint(arena, "{d}", .{v}) catch @panic("OOM") },
490491 .used = false,
491492 }) catch @panic("OOM");
492493 },
493494 .comptime_float, .float => return if (maybe_value) |v| {
494 map.put(field.name, .{
495 .name = field.name,
495 map.put(field_name, .{
496 .name = field_name,
496497 .value = .{ .scalar = std.fmt.allocPrint(arena, "{x}", .{v}) catch @panic("OOM") },
497498 .used = false,
498499 }) catch @panic("OOM");
......@@ -503,7 +504,7 @@ fn addUserInputOptionFromArg(
503504 addUserInputOptionFromArg(
504505 arena,
505506 map,
506 field,
507 field_name,
507508 @Pointer(.slice, .{ .@"const" = true }, array_info.child, null),
508509 maybe_value orelse null,
509510 );
......@@ -515,8 +516,8 @@ fn addUserInputOptionFromArg(
515516 .@"enum" => return if (maybe_value) |v| {
516517 var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM");
517518 for (v) |tag| list.appendAssumeCapacity(@tagName(tag));
518 map.put(field.name, .{
519 .name = field.name,
519 map.put(field_name, .{
520 .name = field_name,
520521 .value = .{ .list = list },
521522 .used = false,
522523 }) catch @panic("OOM");
......@@ -525,7 +526,7 @@ fn addUserInputOptionFromArg(
525526 addUserInputOptionFromArg(
526527 arena,
527528 map,
528 field,
529 field_name,
529530 @Pointer(ptr_info.size, .{ .@"const" = true }, ptr_info.child, null),
530531 maybe_value orelse null,
531532 );
......@@ -541,7 +542,7 @@ fn addUserInputOptionFromArg(
541542 addUserInputOptionFromArg(
542543 arena,
543544 map,
544 field,
545 field_name,
545546 info.child,
546547 maybe_value orelse null,
547548 );
......@@ -551,7 +552,7 @@ fn addUserInputOptionFromArg(
551552 else => {},
552553 },
553554 }
554 @compileError("option '" ++ field.name ++ "' has unsupported type: " ++ @typeName(field.type));
555 @compileError("option '" ++ field_name ++ "' has unsupported type: " ++ @typeName(T));
555556}
556557
557558const OrderedUserValue = union(enum) {
......@@ -1114,11 +1115,11 @@ pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw
11141115 const type_id = comptime typeToEnum(T);
11151116 const enum_options = if (type_id == .@"enum" or type_id == .enum_list) blk: {
11161117 const EnumType = if (type_id == .enum_list) @typeInfo(T).pointer.child else T;
1117 const fields = comptime std.meta.fields(EnumType);
1118 var options = std.array_list.Managed([]const u8).initCapacity(arena, fields.len) catch @panic("OOM");
1118 const field_names = comptime std.meta.fieldNames(EnumType);
1119 var options = std.array_list.Managed([]const u8).initCapacity(b.allocator, field_names.len) catch @panic("OOM");
11191120
1120 inline for (fields) |field| {
1121 options.appendAssumeCapacity(field.name);
1121 inline for (field_names) |field_name| {
1122 options.appendAssumeCapacity(field_name);
11221123 }
11231124
11241125 break :blk options.toOwnedSlice() catch @panic("OOM");
......@@ -1407,8 +1408,8 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile
14071408 \\available operating systems:
14081409 \\
14091410 , .{diags.os_name.?});
1410 inline for (std.meta.fields(Target.Os.Tag)) |field| {
1411 std.debug.print(" {s}\n", .{field.name});
1411 inline for (comptime std.meta.fieldNames(Target.Os.Tag)) |field_name| {
1412 std.debug.print(" {s}\n", .{field_name});
14121413 }
14131414 return error.ParseFailed;
14141415 },
......@@ -1811,8 +1812,8 @@ pub fn findProgram(b: *Build, options: FindProgramOptions) ?[]const u8 {
18111812}
18121813
18131814fn supportedWindowsProgramExtension(ext: []const u8) bool {
1814 inline for (@typeInfo(std.process.WindowsExtension).@"enum".fields) |field| {
1815 if (std.ascii.eqlIgnoreCase(ext, "." ++ field.name)) return true;
1815 inline for (@typeInfo(std.process.WindowsExtension).@"enum".field_names) |field_name| {
1816 if (std.ascii.eqlIgnoreCase(ext, "." ++ field_name)) return true;
18161817 }
18171818 return false;
18181819}
......@@ -2072,8 +2073,7 @@ inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, c
20722073 const deps = build_runner.dependencies;
20732074 const arena = b.graph.arena;
20742075
2075 const b_pkg_hash, const b_pkg_deps = comptime for (@typeInfo(deps.packages).@"struct".decls) |decl| {
2076 const pkg_hash = decl.name;
2076 const b_pkg_hash, const b_pkg_deps = comptime for (@typeInfo(deps.packages).@"struct".decl_names) |pkg_hash| {
20772077 const pkg = @field(deps.packages, pkg_hash);
20782078 if (@hasDecl(pkg, "build_zig") and pkg.build_zig == asking_build_zig) break .{ pkg_hash, pkg.deps };
20792079 } else .{ "", deps.root_deps };
......@@ -2116,9 +2116,9 @@ pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency {
21162116 const deps = build_runner.dependencies;
21172117 const pkg_hash = findPkgHashOrFatal(b, name);
21182118
2119 inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {
2120 if (mem.eql(u8, decl.name, pkg_hash)) {
2121 const pkg = @field(deps.packages, decl.name);
2119 inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| {
2120 if (mem.eql(u8, decl_name, pkg_hash)) {
2121 const pkg = @field(deps.packages, decl_name);
21222122 const available = !@hasDecl(pkg, "available") or pkg.available;
21232123 if (!available) {
21242124 markNeededLazyDep(b, pkg_hash);
......@@ -2136,9 +2136,9 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
21362136 const deps = build_runner.dependencies;
21372137 const pkg_hash = findPkgHashOrFatal(b, name);
21382138
2139 inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {
2140 if (mem.eql(u8, decl.name, pkg_hash)) {
2141 const pkg = @field(deps.packages, decl.name);
2139 inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| {
2140 if (mem.eql(u8, decl_name, pkg_hash)) {
2141 const pkg = @field(deps.packages, decl_name);
21422142 if (@hasDecl(pkg, "available")) {
21432143 panic("dependency '{s}{s}' is marked as lazy in build.zig.zon which means it must use the lazyDependency function instead", .{ b.dep_prefix, name });
21442144 }
......@@ -2166,9 +2166,9 @@ pub inline fn lazyImport(
21662166 const deps = build_runner.dependencies;
21672167 const pkg_hash = findImportPkgHashOrFatal(b, asking_build_zig, dep_name);
21682168
2169 inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {
2170 if (comptime mem.eql(u8, decl.name, pkg_hash)) {
2171 const pkg = @field(deps.packages, decl.name);
2169 inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| {
2170 if (comptime mem.eql(u8, decl_name, pkg_hash)) {
2171 const pkg = @field(deps.packages, decl_name);
21722172 const available = !@hasDecl(pkg, "available") or pkg.available;
21732173 if (!available) {
21742174 markNeededLazyDep(b, pkg_hash);
......@@ -2197,8 +2197,7 @@ pub fn dependencyFromBuildZig(
21972197 const arena = graph.arena;
21982198
21992199 find_dep: {
2200 const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {
2201 const pkg_hash = decl.name;
2200 const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).@"struct".decl_names) |pkg_hash| {
22022201 const pkg = @field(deps.packages, pkg_hash);
22032202 if (@hasDecl(pkg, "build_zig") and pkg.build_zig == build_zig) break .{ pkg, pkg_hash };
22042203 } else break :find_dep;
lib/std/Build/Cache.zig+2-2
......@@ -1241,7 +1241,7 @@ pub const Manifest = struct {
12411241 }
12421242
12431243 pub fn populateFileSystemInputs(man: *Manifest, buf: *std.ArrayList(u8)) Allocator.Error!void {
1244 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".fields.len == man.cache.prefixes_len);
1244 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);
12451245 buf.clearRetainingCapacity();
12461246 const gpa = man.cache.gpa;
12471247 const files = man.files.keys();
......@@ -1259,7 +1259,7 @@ pub const Manifest = struct {
12591259
12601260 pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [4]u8) Allocator.Error!void {
12611261 const gpa = other.cache.gpa;
1262 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".fields.len == man.cache.prefixes_len);
1262 assert(@typeInfo(std.zig.Server.Message.PathPrefix).@"enum".field_names.len == man.cache.prefixes_len);
12631263 assert(man.cache.prefixes_len == 4);
12641264 for (man.files.keys()) |file| {
12651265 const prefixed_path: PrefixedPath = .{
lib/std/Build/Configuration.zig+19-16
......@@ -2884,7 +2884,10 @@ pub const Storage = enum {
28842884 }
28852885
28862886 pub fn cast(this: @This(), c: *const Configuration, comptime S: type) ?S {
2887 const wanted_tag = @typeInfo(S.Flags).@"struct".fields[0].defaultValue().?;
2887 const wanted_tag = blk: {
2888 const info = @typeInfo(S.Flags).@"struct";
2889 break :blk info.field_attrs[0].defaultValue(info.field_types[0]).?;
2890 };
28882891 const base_flags: BaseFlags = @bitCast(c.extra[@intFromEnum(this)]);
28892892 if (base_flags.tag != wanted_tag) return null;
28902893 var i: usize = @intFromEnum(this);
......@@ -3047,8 +3050,8 @@ pub const Storage = enum {
30473050 switch (@typeInfo(T)) {
30483051 .@"struct" => |info| {
30493052 var result: T = undefined;
3050 inline for (info.fields) |field| {
3051 @field(result, field.name) = dataField(buffer, i, &result, field.type);
3053 inline for (info.field_names, info.field_types) |field_name, field_type| {
3054 @field(result, field_name) = dataField(buffer, i, &result, field_type);
30523055 }
30533056 return result;
30543057 },
......@@ -3058,7 +3061,7 @@ pub const Storage = enum {
30583061 inline else => |comptime_tag| @unionInit(
30593062 T,
30603063 @tagName(comptime_tag),
3061 data(buffer, i, info.fields[@intFromEnum(comptime_tag)].type),
3064 data(buffer, i, info.field_types[@intFromEnum(comptime_tag)]),
30623065 ),
30633066 };
30643067 },
......@@ -3125,7 +3128,7 @@ pub const Storage = enum {
31253128 buffer,
31263129 i,
31273130 container,
3128 @typeInfo(Field.Union).@"union".fields[@intFromEnum(comptime_tag)].type,
3131 @typeInfo(Field.Union).@"union".field_types[@intFromEnum(comptime_tag)],
31293132 ),
31303133 ),
31313134 },
......@@ -3167,7 +3170,7 @@ pub const Storage = enum {
31673170 .multi_list => {
31683171 const data_start = i.* + 1;
31693172 const len = buffer[data_start - 1];
3170 defer i.* = data_start + len * @typeInfo(Field.Elem).@"struct".fields.len;
3173 defer i.* = data_start + len * @typeInfo(Field.Elem).@"struct".field_names.len;
31713174 return .{ .mal = .{
31723175 .bytes = @ptrCast(@constCast(buffer[data_start..][0..len])),
31733176 .len = len,
......@@ -3205,10 +3208,10 @@ pub const Storage = enum {
32053208
32063209 /// Returns new end index.
32073210 fn setExtra(buffer: []u32, index: usize, extra: anytype) usize {
3208 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
3211 const info = @typeInfo(@TypeOf(extra)).@"struct";
32093212 var i = index;
3210 inline for (fields) |field| {
3211 i += setExtraField(buffer, i, field.type, @field(extra, field.name));
3213 inline for (info.field_names, info.field_types) |field_name, field_type| {
3214 i += setExtraField(buffer, i, field_type, @field(extra, field_name));
32123215 }
32133216 return i;
32143217 }
......@@ -3236,7 +3239,7 @@ pub const Storage = enum {
32363239 .flag_length_prefixed_list,
32373240 .flag_list,
32383241 => 1 + @divExact(@sizeOf(Field.Elem), @sizeOf(u32)) * field.slice.len,
3239 .multi_list => 1 + field.mal.len * @typeInfo(Field.Elem).@"struct".fields.len,
3242 .multi_list => 1 + field.mal.len * @typeInfo(Field.Elem).@"struct".field_names.len,
32403243 .union_list => Field.extraLen(field.len),
32413244 .flag_union => switch (field.u) {
32423245 inline else => |v| extraFieldLen(v),
......@@ -3249,10 +3252,10 @@ pub const Storage = enum {
32493252 }
32503253
32513254 fn extraLen(extra: anytype) usize {
3252 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
3255 const field_names = @typeInfo(@TypeOf(extra)).@"struct".field_names;
32533256 var i: usize = 0;
3254 inline for (fields) |field| {
3255 i += Storage.extraFieldLen(@field(extra, field.name));
3257 inline for (field_names) |name| {
3258 i += Storage.extraFieldLen(@field(extra, name));
32563259 }
32573260 return i;
32583261 }
......@@ -3324,12 +3327,12 @@ pub const Storage = enum {
33243327 .multi_list => {
33253328 const len: u32 = @intCast(value.mal.len);
33263329 buffer[i] = len;
3327 const fields = @typeInfo(Field.Elem).@"struct".fields;
3328 inline for (0..fields.len) |field_i| @memcpy(
3330 const field_names = @typeInfo(Field.Elem).@"struct".field_names;
3331 inline for (0..field_names.len) |field_i| @memcpy(
33293332 buffer[i + 1 + field_i * len ..][0..len],
33303333 @as([]const u32, @ptrCast(value.mal.items(@enumFromInt(field_i)))),
33313334 );
3332 return 1 + fields.len * len;
3335 return 1 + field_names.len * len;
33333336 },
33343337 .union_list => {
33353338 if (value.len == 0) return 0;
lib/std/Build/Step/ConfigHeader.zig+3-2
......@@ -173,8 +173,9 @@ fn addValueInner(config_header: *ConfigHeader, name: []const u8, comptime T: typ
173173}
174174
175175pub fn addValues(config_header: *ConfigHeader, values: anytype) void {
176 inline for (@typeInfo(@TypeOf(values)).@"struct".fields) |field| {
177 addValue(config_header, field.name, field.type, @field(values, field.name));
176 const info = @typeInfo(@TypeOf(values)).@"struct";
177 inline for (info.field_names, info.field_types) |field_name, field_type| {
178 addValue(config_header, field_name, field_type, @field(values, field_name));
178179 }
179180}
180181
lib/std/Build/Step/Options.zig+28-22
......@@ -299,14 +299,14 @@ fn printEnum(
299299 try out.appendNTimes(gpa, ' ', indent);
300300 try out.print(gpa, "pub const {f} = enum ({s}) {{\n", .{ std.zig.fmtId(@typeName(T)), @typeName(val.tag_type) });
301301
302 inline for (val.fields) |field| {
302 inline for (val.field_names, val.field_values) |field_name, field_value| {
303303 try out.appendNTimes(gpa, ' ', indent);
304304 try out.print(gpa, " {f} = {d},\n", .{
305 std.zig.fmtIdFlags(field.name, .{ .allow_primitive = true }), field.value,
305 std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true }), field_value,
306306 });
307307 }
308308
309 if (!val.is_exhaustive) {
309 if (val.mode == .nonexhaustive) {
310310 try out.appendNTimes(gpa, ' ', indent);
311311 try out.appendSlice(gpa, " _,\n");
312312 }
......@@ -315,7 +315,13 @@ fn printEnum(
315315 try out.appendSlice(gpa, "};\n");
316316}
317317
318fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, comptime val: std.builtin.Type.Struct, indent: u8) !void {
318fn printStruct(
319 options: *Options,
320 out: *std.ArrayList(u8),
321 comptime T: type,
322 comptime val: std.builtin.Type.Struct,
323 indent: u8,
324) !void {
319325 const gpa = options.step.owner.allocator;
320326 const gop = try options.encountered_types.getOrPut(gpa, @typeName(T));
321327 if (gop.found_existing) return;
......@@ -331,32 +337,32 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com
331337
332338 try out.appendSlice(gpa, " {\n");
333339
334 inline for (val.fields) |field| {
340 inline for (val.field_names, val.field_types, val.field_attrs) |field_name, field_type, field_attrs| {
335341 try out.appendNTimes(gpa, ' ', indent);
336342
337 const type_name = @typeName(field.type);
343 const type_name = @typeName(field_type);
338344
339345 // If the type name doesn't contains a '.' the type is from zig builtins.
340346 if (std.mem.containsAtLeast(u8, type_name, 1, ".")) {
341347 try out.print(gpa, " {f}: {f}", .{
342 std.zig.fmtIdFlags(field.name, .{ .allow_underscore = true, .allow_primitive = true }),
348 std.zig.fmtIdFlags(field_name, .{ .allow_underscore = true, .allow_primitive = true }),
343349 std.zig.fmtId(type_name),
344350 });
345351 } else {
346352 try out.print(gpa, " {f}: {s}", .{
347 std.zig.fmtIdFlags(field.name, .{ .allow_underscore = true, .allow_primitive = true }),
353 std.zig.fmtIdFlags(field_name, .{ .allow_underscore = true, .allow_primitive = true }),
348354 type_name,
349355 });
350356 }
351357
352 if (field.defaultValue()) |default_value| {
358 if (field_attrs.defaultValue(field_type)) |default_value| {
353359 try out.appendSlice(gpa, " = ");
354 switch (@typeInfo(@TypeOf(default_value))) {
360 switch (@typeInfo(field_type)) {
355361 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(default_value)}),
356362 .@"struct" => |info| {
357363 try printStructValue(options, out, info, default_value, indent + 4);
358364 },
359 else => try printType(options, out, @TypeOf(default_value), default_value, indent, null),
365 else => try printType(options, out, field_type, default_value, indent, null),
360366 }
361367 } else {
362368 try out.appendSlice(gpa, ",\n");
......@@ -368,8 +374,8 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com
368374 try out.appendNTimes(gpa, ' ', indent);
369375 try out.appendSlice(gpa, "};\n");
370376
371 inline for (val.fields) |field| {
372 try printUserDefinedType(options, out, field.type, 0);
377 inline for (val.field_types) |field_type| {
378 try printUserDefinedType(options, out, field_type, 0);
373379 }
374380}
375381
......@@ -384,24 +390,24 @@ fn printStructValue(
384390 try out.appendSlice(gpa, ".{\n");
385391
386392 if (struct_val.is_tuple) {
387 inline for (struct_val.fields) |field| {
393 inline for (struct_val.field_names) |field_name| {
388394 try out.appendNTimes(gpa, ' ', indent);
389 try printType(options, out, @TypeOf(@field(val, field.name)), @field(val, field.name), indent, null);
395 try printType(options, out, @TypeOf(@field(val, field_name)), @field(val, field_name), indent, null);
390396 }
391397 } else {
392 inline for (struct_val.fields) |field| {
398 inline for (struct_val.field_names) |field_name| {
393399 try out.appendNTimes(gpa, ' ', indent);
394400 try out.print(gpa, " .{f} = ", .{
395 std.zig.fmtIdFlags(field.name, .{ .allow_primitive = true, .allow_underscore = true }),
401 std.zig.fmtIdFlags(field_name, .{ .allow_primitive = true, .allow_underscore = true }),
396402 });
397403
398 const field_name = @field(val, field.name);
399 switch (@typeInfo(@TypeOf(field_name))) {
400 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_name)}),
404 const field_val = @field(val, field_name);
405 switch (@typeInfo(@TypeOf(field_val))) {
406 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_val)}),
401407 .@"struct" => |struct_info| {
402 try printStructValue(options, out, struct_info, field_name, indent + 4);
408 try printStructValue(options, out, struct_info, field_val, indent + 4);
403409 },
404 else => try printType(options, out, @TypeOf(field_name), field_name, indent, null),
410 else => try printType(options, out, @TypeOf(field_val), field_val, indent, null),
405411 }
406412 }
407413 }
lib/std/Io.zig+7-6
......@@ -396,12 +396,13 @@ pub const Operation = union(enum) {
396396 };
397397
398398 pub const Result = Result: {
399 const operation_fields = @typeInfo(Operation).@"union".fields;
400 var field_names: [operation_fields.len][]const u8 = undefined;
401 var field_types: [operation_fields.len]type = undefined;
402 for (operation_fields, &field_names, &field_types) |field, *field_name, *field_type| {
403 field_name.* = field.name;
404 field_type.* = if (field.type == noreturn) noreturn else field.type.Result;
399 const operation_info = @typeInfo(Operation).@"union";
400 const operation_count = operation_info.field_names.len;
401 var field_names: [operation_count][]const u8 = undefined;
402 var field_types: [operation_count]type = undefined;
403 for (operation_info.field_names, operation_info.field_types, &field_names, &field_types) |f_name, f_type, *field_name, *field_type| {
404 field_name.* = f_name;
405 field_type.* = if (f_type == noreturn) noreturn else f_type.Result;
405406 }
406407 break :Result @Union(.auto, Tag, &field_names, &field_types, &@splat(.{}));
407408 };
lib/std/Io/Reader.zig+1-1
......@@ -1277,7 +1277,7 @@ pub fn takeEnum(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Tak
12771277/// Asserts the buffer was initialized with a capacity at least `@sizeOf(Enum)`.
12781278pub fn takeEnumNonexhaustive(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Error!Enum {
12791279 const info = @typeInfo(Enum).@"enum";
1280 comptime assert(!info.is_exhaustive);
1280 comptime assert(info.mode != .exhaustive);
12811281 comptime assert(@bitSizeOf(info.tag_type) == @sizeOf(info.tag_type) * 8);
12821282 return takeEnum(r, Enum, endian) catch |err| switch (err) {
12831283 error.InvalidEnumTag => unreachable,
lib/std/Io/Threaded.zig+10-10
......@@ -332,8 +332,8 @@ pub const Environ = struct {
332332 .flags = .{ .nonblocking = true },
333333 };
334334 };
335 } else inline for (@typeInfo(String).@"struct".fields) |field| {
336 if (std.mem.eql(u8, key, field.name)) @field(environ.string, field.name) = value;
335 } else inline for (@typeInfo(String).@"struct".field_names) |field_name| {
336 if (std.mem.eql(u8, key, field_name)) @field(environ.string, field_name) = value;
337337 }
338338 }
339339 }
......@@ -11785,8 +11785,8 @@ fn sleepWasi(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void {
1178511785
1178611786fn sleepNanosleep(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void {
1178711787 const t_io = io(t);
11788 const sec_type = @typeInfo(posix.timespec).@"struct".fields[0].type;
11789 const nsec_type = @typeInfo(posix.timespec).@"struct".fields[1].type;
11788 const sec_type = @typeInfo(posix.timespec).@"struct".field_types[0];
11789 const nsec_type = @typeInfo(posix.timespec).@"struct".field_types[1];
1179011790
1179111791 var timespec: posix.timespec = t: {
1179211792 const d = timeout.toDurationFromNow(t_io) orelse break :t .{
......@@ -14923,9 +14923,9 @@ const WindowsEnvironStrings = struct {
1492314923
1492414924 i += 1; // skip over null byte
1492514925
14926 inline for (@typeInfo(WindowsEnvironStrings).@"struct".fields) |field| {
14927 const field_name_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(field.name);
14928 if (windows.eqlIgnoreCaseWtf16(key_w, field_name_w)) @field(result, field.name) = value_w;
14926 inline for (@typeInfo(WindowsEnvironStrings).@"struct".field_names) |field_name| {
14927 const field_name_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(field_name);
14928 if (windows.eqlIgnoreCaseWtf16(key_w, field_name_w)) @field(result, field_name) = value_w;
1492914929 }
1493014930 }
1493114931
......@@ -16190,7 +16190,7 @@ fn windowsCreateProcessPathExt(
1619016190 }
1619116191 var io_status: windows.IO_STATUS_BLOCK = undefined;
1619216192
16193 const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".fields.len;
16193 const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".field_names.len;
1619416194 var pathext_seen: [num_supported_pathext]bool = @splat(false);
1619516195 var any_pathext_seen = false;
1619616196 var unappended_exists = false;
......@@ -16435,8 +16435,8 @@ fn windowsCreateProcess(
1643516435fn windowsCreateProcessSupportsExtension(ext: []const u16) ?process.WindowsExtension {
1643616436 comptime {
1643716437 // Ensures keeping this function in sync with the enum.
16438 const fields = @typeInfo(process.WindowsExtension).@"enum".fields;
16439 assert(fields.len == 4);
16438 const field_names = @typeInfo(process.WindowsExtension).@"enum".field_names;
16439 assert(field_names.len == 4);
1644016440 assert(@intFromEnum(process.WindowsExtension.bat) == 0);
1644116441 assert(@intFromEnum(process.WindowsExtension.cmd) == 1);
1644216442 assert(@intFromEnum(process.WindowsExtension.com) == 2);
lib/std/Io/Writer.zig+18-18
......@@ -620,14 +620,14 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
620620 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
621621 }
622622
623 const fields_info = args_type_info.@"struct".fields;
623 const field_names = args_type_info.@"struct".field_names;
624624 const max_format_args = @typeInfo(std.fmt.ArgSetType).int.bits;
625 if (fields_info.len > max_format_args) {
625 if (field_names.len > max_format_args) {
626626 @compileError("32 arguments max are supported per format call");
627627 }
628628
629629 @setEvalBranchQuota(@as(comptime_int, fmt.len) * 1000); // NOTE: We're upcasting as 16-bit usize overflows.
630 comptime var arg_state: std.fmt.ArgState = .{ .args_len = fields_info.len };
630 comptime var arg_state: std.fmt.ArgState = .{ .args_len = field_names.len };
631631 comptime var i = 0;
632632 comptime var literal: []const u8 = "";
633633 inline while (true) {
......@@ -728,7 +728,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
728728 .width = width,
729729 .precision = precision,
730730 },
731 @field(args, fields_info[arg_to_print].name),
731 @field(args, field_names[arg_to_print]),
732732 std.options.fmt_max_depth,
733733 );
734734 }
......@@ -1290,7 +1290,7 @@ pub fn printValue(
12901290 .@"enum" => |info| {
12911291 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);
12921292 optionsForbidden(options);
1293 if (info.is_exhaustive) {
1293 if (info.mode == .exhaustive) {
12941294 return printEnumExhaustive(w, value);
12951295 } else {
12961296 return printEnumNonexhaustive(w, value);
......@@ -1309,9 +1309,9 @@ pub fn printValue(
13091309 try w.writeAll(".{ .");
13101310 try w.writeAll(@tagName(@as(UnionTagType, value)));
13111311 try w.writeAll(" = ");
1312 inline for (info.fields) |u_field| {
1313 if (value == @field(UnionTagType, u_field.name)) {
1314 try w.printValue(ANY, options, @field(value, u_field.name), max_depth - 1);
1312 inline for (info.field_names) |u_field_name| {
1313 if (value == @field(UnionTagType, u_field_name)) {
1314 try w.printValue(ANY, options, @field(value, u_field_name), max_depth - 1);
13151315 }
13161316 }
13171317 try w.writeAll(" }");
......@@ -1320,14 +1320,14 @@ pub fn printValue(
13201320 return w.writeAll(".{ ... }");
13211321 },
13221322 .@"extern", .@"packed" => {
1323 if (info.fields.len == 0) return w.writeAll(".{}");
1323 if (info.field_names.len == 0) return w.writeAll(".{}");
13241324 try w.writeAll(".{ ");
1325 inline for (info.fields, 1..) |field, i| {
1325 inline for (info.field_names, 1..) |field_name, i| {
13261326 try w.writeByte('.');
1327 try w.writeAll(field.name);
1327 try w.writeAll(field_name);
13281328 try w.writeAll(" = ");
1329 try w.printValue(ANY, options, @field(value, field.name), max_depth - 1);
1330 try w.writeAll(if (i < info.fields.len) ", " else " }");
1329 try w.printValue(ANY, options, @field(value, field_name), max_depth - 1);
1330 try w.writeAll(if (i < info.field_names.len) ", " else " }");
13311331 }
13321332 },
13331333 }
......@@ -1344,13 +1344,13 @@ pub fn printValue(
13441344 return;
13451345 }
13461346 try w.writeAll(".{");
1347 inline for (info.fields, 0..) |f, i| {
1347 inline for (info.field_names, 0..) |f_name, i| {
13481348 if (i == 0) {
13491349 try w.writeAll(" ");
13501350 } else {
13511351 try w.writeAll(", ");
13521352 }
1353 try w.printValue(ANY, options, @field(value, f.name), max_depth - 1);
1353 try w.printValue(ANY, options, @field(value, f_name), max_depth - 1);
13541354 }
13551355 try w.writeAll(" }");
13561356 return;
......@@ -1360,15 +1360,15 @@ pub fn printValue(
13601360 return;
13611361 }
13621362 try w.writeAll(".{");
1363 inline for (info.fields, 0..) |f, i| {
1363 inline for (info.field_names, 0..) |f_name, i| {
13641364 if (i == 0) {
13651365 try w.writeAll(" .");
13661366 } else {
13671367 try w.writeAll(", .");
13681368 }
1369 try w.writeAll(f.name);
1369 try w.writeAll(f_name);
13701370 try w.writeAll(" = ");
1371 try w.printValue(ANY, options, @field(value, f.name), max_depth - 1);
1371 try w.printValue(ANY, options, @field(value, f_name), max_depth - 1);
13721372 }
13731373 try w.writeAll(" }");
13741374 },
lib/std/Progress.zig+2-2
......@@ -867,8 +867,8 @@ const TreeSymbol = enum {
867867
868868 fn maxByteLen(symbol: TreeSymbol) usize {
869869 var max: usize = 0;
870 inline for (@typeInfo(Encoding).@"enum".fields) |field| {
871 const len = symbol.bytes(@field(Encoding, field.name)).len;
870 inline for (@typeInfo(Encoding).@"enum".field_names) |field_name| {
871 const len = symbol.bytes(@field(Encoding, field_name)).len;
872872 max = @max(max, len);
873873 }
874874 return max;
lib/std/Target.zig+4-4
......@@ -1764,10 +1764,10 @@ pub const Cpu = struct {
17641764
17651765 fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model {
17661766 @setEvalBranchQuota(2000);
1767 const decls = @typeInfo(cpus).@"struct".decls;
1768 var array: [decls.len]*const Cpu.Model = undefined;
1769 for (decls, 0..) |decl, i| {
1770 array[i] = &@field(cpus, decl.name);
1767 const decl_names = @typeInfo(cpus).@"struct".decl_names;
1768 var array: [decl_names.len]*const Cpu.Model = undefined;
1769 for (decl_names, 0..) |decl_name, i| {
1770 array[i] = &@field(cpus, decl_name);
17711771 }
17721772 const finalized = array;
17731773 return &finalized;
lib/std/Target/aarch64.zig+2-2
......@@ -291,7 +291,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
291291
292292pub const all_features = blk: {
293293 @setEvalBranchQuota(2000);
294 const len = @typeInfo(Feature).@"enum".fields.len;
294 const len = @typeInfo(Feature).@"enum".field_names.len;
295295 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
296296 var result: [len]CpuFeature = undefined;
297297 result[@intFromEnum(Feature.a320)] = .{
......@@ -2019,7 +2019,7 @@ pub const all_features = blk: {
20192019 const ti = @typeInfo(Feature);
20202020 for (&result, 0..) |*elem, i| {
20212021 elem.index = i;
2022 elem.name = ti.@"enum".fields[i].name;
2022 elem.name = ti.@"enum".field_names[i];
20232023 }
20242024 break :blk result;
20252025};
lib/std/Target/alpha.zig+2-2
......@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1717pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1818
1919pub const all_features = blk: {
20 const len = @typeInfo(Feature).@"enum".fields.len;
20 const len = @typeInfo(Feature).@"enum".field_names.len;
2121 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
2222 var result: [len]CpuFeature = undefined;
2323 result[@intFromEnum(Feature.bwx)] = .{
......@@ -43,7 +43,7 @@ pub const all_features = blk: {
4343 const ti = @typeInfo(Feature);
4444 for (&result, 0..) |*elem, i| {
4545 elem.index = i;
46 elem.name = ti.@"enum".fields[i].name;
46 elem.name = ti.@"enum".field_names[i];
4747 }
4848 break :blk result;
4949};
lib/std/Target/amdgcn.zig+2-2
......@@ -268,7 +268,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
268268
269269pub const all_features = blk: {
270270 @setEvalBranchQuota(2000);
271 const len = @typeInfo(Feature).@"enum".fields.len;
271 const len = @typeInfo(Feature).@"enum".field_names.len;
272272 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
273273 var result: [len]CpuFeature = undefined;
274274 result[@intFromEnum(Feature.@"1024_addressable_vgprs")] = .{
......@@ -1877,7 +1877,7 @@ pub const all_features = blk: {
18771877 const ti = @typeInfo(Feature);
18781878 for (&result, 0..) |*elem, i| {
18791879 elem.index = i;
1880 elem.name = ti.@"enum".fields[i].name;
1880 elem.name = ti.@"enum".field_names[i];
18811881 }
18821882 break :blk result;
18831883};
lib/std/Target/arc.zig+2-2
......@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1414pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1515
1616pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;
17 const len = @typeInfo(Feature).@"enum".field_names.len;
1818 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
1919 var result: [len]CpuFeature = undefined;
2020 result[@intFromEnum(Feature.norm)] = .{
......@@ -25,7 +25,7 @@ pub const all_features = blk: {
2525 const ti = @typeInfo(Feature);
2626 for (&result, 0..) |*elem, i| {
2727 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;
28 elem.name = ti.@"enum".field_names[i];
2929 }
3030 break :blk result;
3131};
lib/std/Target/arm.zig+2-2
......@@ -215,7 +215,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
215215
216216pub const all_features = blk: {
217217 @setEvalBranchQuota(10000);
218 const len = @typeInfo(Feature).@"enum".fields.len;
218 const len = @typeInfo(Feature).@"enum".field_names.len;
219219 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
220220 var result: [len]CpuFeature = undefined;
221221 result[@intFromEnum(Feature.@"32bit")] = .{
......@@ -1736,7 +1736,7 @@ pub const all_features = blk: {
17361736 const ti = @typeInfo(Feature);
17371737 for (&result, 0..) |*elem, i| {
17381738 elem.index = i;
1739 elem.name = ti.@"enum".fields[i].name;
1739 elem.name = ti.@"enum".field_names[i];
17401740 }
17411741 break :blk result;
17421742};
lib/std/Target/avr.zig+2-2
......@@ -52,7 +52,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
5252pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
5353
5454pub const all_features = blk: {
55 const len = @typeInfo(Feature).@"enum".fields.len;
55 const len = @typeInfo(Feature).@"enum".field_names.len;
5656 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
5757 var result: [len]CpuFeature = undefined;
5858 result[@intFromEnum(Feature.addsubiw)] = .{
......@@ -388,7 +388,7 @@ pub const all_features = blk: {
388388 const ti = @typeInfo(Feature);
389389 for (&result, 0..) |*elem, i| {
390390 elem.index = i;
391 elem.name = ti.@"enum".fields[i].name;
391 elem.name = ti.@"enum".field_names[i];
392392 }
393393 break :blk result;
394394};
lib/std/Target/bpf.zig+2-2
......@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1717pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1818
1919pub const all_features = blk: {
20 const len = @typeInfo(Feature).@"enum".fields.len;
20 const len = @typeInfo(Feature).@"enum".field_names.len;
2121 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
2222 var result: [len]CpuFeature = undefined;
2323 result[@intFromEnum(Feature.allows_misaligned_mem_access)] = .{
......@@ -43,7 +43,7 @@ pub const all_features = blk: {
4343 const ti = @typeInfo(Feature);
4444 for (&result, 0..) |*elem, i| {
4545 elem.index = i;
46 elem.name = ti.@"enum".fields[i].name;
46 elem.name = ti.@"enum".field_names[i];
4747 }
4848 break :blk result;
4949};
lib/std/Target/csky.zig+2-2
......@@ -76,7 +76,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
7676pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
7777
7878pub const all_features = blk: {
79 const len = @typeInfo(Feature).@"enum".fields.len;
79 const len = @typeInfo(Feature).@"enum".field_names.len;
8080 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
8181 var result: [len]CpuFeature = undefined;
8282 result[@intFromEnum(Feature.@"10e60")] = .{
......@@ -418,7 +418,7 @@ pub const all_features = blk: {
418418 const ti = @typeInfo(Feature);
419419 for (&result, 0..) |*elem, i| {
420420 elem.index = i;
421 elem.name = ti.@"enum".fields[i].name;
421 elem.name = ti.@"enum".field_names[i];
422422 }
423423 break :blk result;
424424};
lib/std/Target/hexagon.zig+2-2
......@@ -60,7 +60,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
6060pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
6161
6262pub const all_features = blk: {
63 const len = @typeInfo(Feature).@"enum".fields.len;
63 const len = @typeInfo(Feature).@"enum".field_names.len;
6464 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
6565 var result: [len]CpuFeature = undefined;
6666 result[@intFromEnum(Feature.audio)] = .{
......@@ -334,7 +334,7 @@ pub const all_features = blk: {
334334 const ti = @typeInfo(Feature);
335335 for (&result, 0..) |*elem, i| {
336336 elem.index = i;
337 elem.name = ti.@"enum".fields[i].name;
337 elem.name = ti.@"enum".field_names[i];
338338 }
339339 break :blk result;
340340};
lib/std/Target/hppa.zig+2-2
......@@ -18,7 +18,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1818pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1919
2020pub const all_features = blk: {
21 const len = @typeInfo(Feature).@"enum".fields.len;
21 const len = @typeInfo(Feature).@"enum".field_names.len;
2222 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
2323 var result: [len]CpuFeature = undefined;
2424 result[@intFromEnum(Feature.@"64bit")] = .{
......@@ -56,7 +56,7 @@ pub const all_features = blk: {
5656 const ti = @typeInfo(Feature);
5757 for (&result, 0..) |*elem, i| {
5858 elem.index = i;
59 elem.name = ti.@"enum".fields[i].name;
59 elem.name = ti.@"enum".field_names[i];
6060 }
6161 break :blk result;
6262};
lib/std/Target/kvx.zig+2-2
......@@ -16,7 +16,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1616pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1717
1818pub const all_features = blk: {
19 const len = @typeInfo(Feature).@"enum".fields.len;
19 const len = @typeInfo(Feature).@"enum".field_names.len;
2020 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
2121 var result: [len]CpuFeature = undefined;
2222 result[@intFromEnum(Feature.v3_1)] = .{
......@@ -41,7 +41,7 @@ pub const all_features = blk: {
4141 const ti = @typeInfo(Feature);
4242 for (&result, 0..) |*elem, i| {
4343 elem.index = i;
44 elem.name = ti.@"enum".fields[i].name;
44 elem.name = ti.@"enum".field_names[i];
4545 }
4646 break :blk result;
4747};
lib/std/Target/lanai.zig+2-2
......@@ -12,13 +12,13 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1212pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1313
1414pub const all_features = blk: {
15 const len = @typeInfo(Feature).@"enum".fields.len;
15 const len = @typeInfo(Feature).@"enum".field_names.len;
1616 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
1717 var result: [len]CpuFeature = undefined;
1818 const ti = @typeInfo(Feature);
1919 for (&result, 0..) |*elem, i| {
2020 elem.index = i;
21 elem.name = ti.@"enum".fields[i].name;
21 elem.name = ti.@"enum".field_names[i];
2222 }
2323 break :blk result;
2424};
lib/std/Target/loongarch.zig+2-2
......@@ -34,7 +34,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
3434pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
3535
3636pub const all_features = blk: {
37 const len = @typeInfo(Feature).@"enum".fields.len;
37 const len = @typeInfo(Feature).@"enum".field_names.len;
3838 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
3939 var result: [len]CpuFeature = undefined;
4040 result[@intFromEnum(Feature.@"32bit")] = .{
......@@ -153,7 +153,7 @@ pub const all_features = blk: {
153153 const ti = @typeInfo(Feature);
154154 for (&result, 0..) |*elem, i| {
155155 elem.index = i;
156 elem.name = ti.@"enum".fields[i].name;
156 elem.name = ti.@"enum".field_names[i];
157157 }
158158 break :blk result;
159159};
lib/std/Target/m68k.zig+2-2
......@@ -36,7 +36,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
3636pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
3737
3838pub const all_features = blk: {
39 const len = @typeInfo(Feature).@"enum".fields.len;
39 const len = @typeInfo(Feature).@"enum".field_names.len;
4040 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
4141 var result: [len]CpuFeature = undefined;
4242 result[@intFromEnum(Feature.isa_68000)] = .{
......@@ -170,7 +170,7 @@ pub const all_features = blk: {
170170 const ti = @typeInfo(Feature);
171171 for (&result, 0..) |*elem, i| {
172172 elem.index = i;
173 elem.name = ti.@"enum".fields[i].name;
173 elem.name = ti.@"enum".field_names[i];
174174 }
175175 break :blk result;
176176};
lib/std/Target/mips.zig+2-2
......@@ -70,7 +70,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
7070pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
7171
7272pub const all_features = blk: {
73 const len = @typeInfo(Feature).@"enum".fields.len;
73 const len = @typeInfo(Feature).@"enum".field_names.len;
7474 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
7575 var result: [len]CpuFeature = undefined;
7676 result[@intFromEnum(Feature.abs2008)] = .{
......@@ -425,7 +425,7 @@ pub const all_features = blk: {
425425 const ti = @typeInfo(Feature);
426426 for (&result, 0..) |*elem, i| {
427427 elem.index = i;
428 elem.name = ti.@"enum".fields[i].name;
428 elem.name = ti.@"enum".field_names[i];
429429 }
430430 break :blk result;
431431};
lib/std/Target/msp430.zig+2-2
......@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1717pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1818
1919pub const all_features = blk: {
20 const len = @typeInfo(Feature).@"enum".fields.len;
20 const len = @typeInfo(Feature).@"enum".field_names.len;
2121 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
2222 var result: [len]CpuFeature = undefined;
2323 result[@intFromEnum(Feature.ext)] = .{
......@@ -43,7 +43,7 @@ pub const all_features = blk: {
4343 const ti = @typeInfo(Feature);
4444 for (&result, 0..) |*elem, i| {
4545 elem.index = i;
46 elem.name = ti.@"enum".fields[i].name;
46 elem.name = ti.@"enum".field_names[i];
4747 }
4848 break :blk result;
4949};
lib/std/Target/nvptx.zig+2-2
......@@ -84,7 +84,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
8484pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
8585
8686pub const all_features = blk: {
87 const len = @typeInfo(Feature).@"enum".fields.len;
87 const len = @typeInfo(Feature).@"enum".field_names.len;
8888 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
8989 var result: [len]CpuFeature = undefined;
9090 result[@intFromEnum(Feature.ptx32)] = .{
......@@ -445,7 +445,7 @@ pub const all_features = blk: {
445445 const ti = @typeInfo(Feature);
446446 for (&result, 0..) |*elem, i| {
447447 elem.index = i;
448 elem.name = ti.@"enum".fields[i].name;
448 elem.name = ti.@"enum".field_names[i];
449449 }
450450 break :blk result;
451451};
lib/std/Target/powerpc.zig+2-2
......@@ -93,7 +93,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
9393pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
9494
9595pub const all_features = blk: {
96 const len = @typeInfo(Feature).@"enum".fields.len;
96 const len = @typeInfo(Feature).@"enum".field_names.len;
9797 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
9898 var result: [len]CpuFeature = undefined;
9999 result[@intFromEnum(Feature.@"64bit")] = .{
......@@ -595,7 +595,7 @@ pub const all_features = blk: {
595595 const ti = @typeInfo(Feature);
596596 for (&result, 0..) |*elem, i| {
597597 elem.index = i;
598 elem.name = ti.@"enum".fields[i].name;
598 elem.name = ti.@"enum".field_names[i];
599599 }
600600 break :blk result;
601601};
lib/std/Target/propeller.zig+2-2
......@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1414pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1515
1616pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;
17 const len = @typeInfo(Feature).@"enum".field_names.len;
1818 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
1919 var result: [len]CpuFeature = undefined;
2020 result[@intFromEnum(Feature.p2)] = .{
......@@ -25,7 +25,7 @@ pub const all_features = blk: {
2525 const ti = @typeInfo(Feature);
2626 for (&result, 0..) |*elem, i| {
2727 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;
28 elem.name = ti.@"enum".field_names[i];
2929 }
3030 break :blk result;
3131};
lib/std/Target/riscv.zig+2-2
......@@ -361,7 +361,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
361361
362362pub const all_features = blk: {
363363 @setEvalBranchQuota(2000);
364 const len = @typeInfo(Feature).@"enum".fields.len;
364 const len = @typeInfo(Feature).@"enum".field_names.len;
365365 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
366366 var result: [len]CpuFeature = undefined;
367367 result[@intFromEnum(Feature.@"32bit")] = .{
......@@ -2675,7 +2675,7 @@ pub const all_features = blk: {
26752675 const ti = @typeInfo(Feature);
26762676 for (&result, 0..) |*elem, i| {
26772677 elem.index = i;
2678 elem.name = ti.@"enum".fields[i].name;
2678 elem.name = ti.@"enum".field_names[i];
26792679 }
26802680 break :blk result;
26812681};
lib/std/Target/s390x.zig+2-2
......@@ -62,7 +62,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
6262pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
6363
6464pub const all_features = blk: {
65 const len = @typeInfo(Feature).@"enum".fields.len;
65 const len = @typeInfo(Feature).@"enum".field_names.len;
6666 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
6767 var result: [len]CpuFeature = undefined;
6868 result[@intFromEnum(Feature.backchain)] = .{
......@@ -313,7 +313,7 @@ pub const all_features = blk: {
313313 const ti = @typeInfo(Feature);
314314 for (&result, 0..) |*elem, i| {
315315 elem.index = i;
316 elem.name = ti.@"enum".fields[i].name;
316 elem.name = ti.@"enum".field_names[i];
317317 }
318318 break :blk result;
319319};
lib/std/Target/sparc.zig+2-2
......@@ -72,7 +72,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
7272pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
7373
7474pub const all_features = blk: {
75 const len = @typeInfo(Feature).@"enum".fields.len;
75 const len = @typeInfo(Feature).@"enum".field_names.len;
7676 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
7777 var result: [len]CpuFeature = undefined;
7878 result[@intFromEnum(Feature.@"64bit")] = .{
......@@ -395,7 +395,7 @@ pub const all_features = blk: {
395395 const ti = @typeInfo(Feature);
396396 for (&result, 0..) |*elem, i| {
397397 elem.index = i;
398 elem.name = ti.@"enum".fields[i].name;
398 elem.name = ti.@"enum".field_names[i];
399399 }
400400 break :blk result;
401401};
lib/std/Target/spirv.zig+2-2
......@@ -29,7 +29,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
2929
3030pub const all_features = blk: {
3131 @setEvalBranchQuota(2000);
32 const len = @typeInfo(Feature).@"enum".fields.len;
32 const len = @typeInfo(Feature).@"enum".field_names.len;
3333 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
3434 var result: [len]CpuFeature = undefined;
3535 result[@intFromEnum(Feature.arbitrary_precision_integers)] = .{
......@@ -138,7 +138,7 @@ pub const all_features = blk: {
138138 const ti = @typeInfo(Feature);
139139 for (&result, 0..) |*elem, i| {
140140 elem.index = i;
141 elem.name = ti.@"enum".fields[i].name;
141 elem.name = ti.@"enum".field_names[i];
142142 }
143143 break :blk result;
144144};
lib/std/Target/ve.zig+2-2
......@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1414pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1515
1616pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;
17 const len = @typeInfo(Feature).@"enum".field_names.len;
1818 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
1919 var result: [len]CpuFeature = undefined;
2020 result[@intFromEnum(Feature.vpu)] = .{
......@@ -25,7 +25,7 @@ pub const all_features = blk: {
2525 const ti = @typeInfo(Feature);
2626 for (&result, 0..) |*elem, i| {
2727 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;
28 elem.name = ti.@"enum".field_names[i];
2929 }
3030 break :blk result;
3131};
lib/std/Target/wasm.zig+2-2
......@@ -32,7 +32,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
3232pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
3333
3434pub const all_features = blk: {
35 const len = @typeInfo(Feature).@"enum".fields.len;
35 const len = @typeInfo(Feature).@"enum".field_names.len;
3636 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
3737 var result: [len]CpuFeature = undefined;
3838 result[@intFromEnum(Feature.atomics)] = .{
......@@ -139,7 +139,7 @@ pub const all_features = blk: {
139139 const ti = @typeInfo(Feature);
140140 for (&result, 0..) |*elem, i| {
141141 elem.index = i;
142 elem.name = ti.@"enum".fields[i].name;
142 elem.name = ti.@"enum".field_names[i];
143143 }
144144 break :blk result;
145145};
lib/std/Target/x86.zig+2-2
......@@ -215,7 +215,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
215215pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
216216
217217pub const all_features = blk: {
218 const len = @typeInfo(Feature).@"enum".fields.len;
218 const len = @typeInfo(Feature).@"enum".field_names.len;
219219 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
220220 var result: [len]CpuFeature = undefined;
221221 result[@intFromEnum(Feature.@"16bit_mode")] = .{
......@@ -1374,7 +1374,7 @@ pub const all_features = blk: {
13741374 const ti = @typeInfo(Feature);
13751375 for (&result, 0..) |*elem, i| {
13761376 elem.index = i;
1377 elem.name = ti.@"enum".fields[i].name;
1377 elem.name = ti.@"enum".field_names[i];
13781378 }
13791379 break :blk result;
13801380};
lib/std/Target/xcore.zig+2-2
......@@ -12,13 +12,13 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
1212pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1313
1414pub const all_features = blk: {
15 const len = @typeInfo(Feature).@"enum".fields.len;
15 const len = @typeInfo(Feature).@"enum".field_names.len;
1616 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
1717 var result: [len]CpuFeature = undefined;
1818 const ti = @typeInfo(Feature);
1919 for (&result, 0..) |*elem, i| {
2020 elem.index = i;
21 elem.name = ti.@"enum".fields[i].name;
21 elem.name = ti.@"enum".field_names[i];
2222 }
2323 break :blk result;
2424};
lib/std/Target/xtensa.zig+2-2
......@@ -50,7 +50,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
5050pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
5151
5252pub const all_features = blk: {
53 const len = @typeInfo(Feature).@"enum".fields.len;
53 const len = @typeInfo(Feature).@"enum".field_names.len;
5454 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
5555 var result: [len]CpuFeature = undefined;
5656 result[@intFromEnum(Feature.bool)] = .{
......@@ -251,7 +251,7 @@ pub const all_features = blk: {
251251 const ti = @typeInfo(Feature);
252252 for (&result, 0..) |*elem, i| {
253253 elem.index = i;
254 elem.name = ti.@"enum".fields[i].name;
254 elem.name = ti.@"enum".field_names[i];
255255 }
256256 break :blk result;
257257};
lib/std/c/darwin.zig+1-1
......@@ -54,7 +54,7 @@ pub const EXC = enum(exception_type_t) {
5454
5555 _,
5656
57 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len;
57 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".field_names.len;
5858 pub const SOFT_SIGNAL = 0x10003;
5959
6060 pub const MASK = packed struct(u32) {
lib/std/coff.zig+1-1
......@@ -1386,7 +1386,7 @@ pub const IMAGE = struct {
13861386 RESERVED = 15,
13871387 _,
13881388
1389 pub const len = @typeInfo(IMAGE.DIRECTORY_ENTRY).@"enum".fields.len;
1389 pub const len = @typeInfo(IMAGE.DIRECTORY_ENTRY).@"enum".field_names.len;
13901390 };
13911391
13921392 pub const FILE = struct {
lib/std/crypto/codecs/asn1/Oid.zig+8-8
......@@ -177,27 +177,27 @@ pub fn StaticMap(comptime Enum: type) type {
177177 pub fn initComptime(comptime key_pairs: anytype) ReturnType {
178178 const struct_info = @typeInfo(@TypeOf(key_pairs)).@"struct";
179179 const error_msg = "Each field of '" ++ @typeName(Enum) ++ "' must map to exactly one OID";
180 if (!enum_info.is_exhaustive or enum_info.fields.len != struct_info.fields.len) {
180 if (enum_info.mode == .nonexhaustive or enum_info.field_names.len != struct_info.field_names.len) {
181181 @compileError(error_msg);
182182 }
183183
184184 comptime var enum_to_oid = EnumToOid.initUndefined();
185185
186186 const KeyPair = struct { []const u8, Enum };
187 comptime var static_key_pairs: [enum_info.fields.len]KeyPair = undefined;
187 comptime var static_key_pairs: [enum_info.field_names.len]KeyPair = undefined;
188188
189 comptime for (enum_info.fields, 0..) |f, i| {
190 if (!@hasField(@TypeOf(key_pairs), f.name)) {
191 @compileError("Field '" ++ f.name ++ "' missing Oid.StaticMap entry");
189 comptime for (enum_info.field_names, enum_info.field_values, 0..) |f_name, f_value, i| {
190 if (!@hasField(@TypeOf(key_pairs), f_name)) {
191 @compileError("Field '" ++ f_name ++ "' missing Oid.StaticMap entry");
192192 }
193 const encoded = &encodeComptime(@field(key_pairs, f.name));
194 const tag: Enum = @enumFromInt(f.value);
193 const encoded = &encodeComptime(@field(key_pairs, f_name));
194 const tag: Enum = @enumFromInt(f_value);
195195 static_key_pairs[i] = .{ encoded, tag };
196196 enum_to_oid.set(tag, encoded);
197197 };
198198
199199 const oid_to_enum = std.StaticStringMap(Enum).initComptime(static_key_pairs);
200 if (oid_to_enum.values().len != enum_info.fields.len) @compileError(error_msg);
200 if (oid_to_enum.values().len != enum_info.field_names.len) @compileError(error_msg);
201201
202202 return ReturnType{ .oid_to_enum = oid_to_enum, .enum_to_oid = enum_to_oid };
203203 }
lib/std/crypto/codecs/asn1/der/Decoder.zig+7-7
......@@ -19,14 +19,14 @@ pub fn any(self: *Decoder, comptime T: type) !T {
1919
2020 const tag = Tag.fromZig(T).toExpected();
2121 switch (@typeInfo(T)) {
22 .@"struct" => {
22 .@"struct" => |info| {
2323 const ele = try self.element(tag);
2424 defer self.index = ele.slice.end; // don't force parsing all fields
2525
2626 var res: T = undefined;
2727
28 inline for (std.meta.fields(T)) |f| {
29 self.field_tag = FieldTag.fromContainer(T, f.name);
28 inline for (info.field_names, info.field_types, info.field_attrs) |f_name, f_type, f_attrs| {
29 self.field_tag = FieldTag.fromContainer(T, f_name);
3030
3131 if (self.field_tag) |ft| {
3232 if (ft.explicit) {
......@@ -36,15 +36,15 @@ pub fn any(self: *Decoder, comptime T: type) !T {
3636 }
3737 }
3838
39 @field(res, f.name) = self.any(f.type) catch |err| brk: {
40 if (f.defaultValue()) |d| {
39 @field(res, f_name) = self.any(f_type) catch |err| brk: {
40 if (f_attrs.defaultValue(f_type)) |d| {
4141 break :brk d;
4242 }
4343 return err;
4444 };
4545 // DER encodes null values by skipping them.
46 if (@typeInfo(f.type) == .optional and @field(res, f.name) == null) {
47 if (f.defaultValue()) |d| @field(res, f.name) = d;
46 if (@typeInfo(f_type) == .optional and @field(res, f_name) == null) {
47 if (f_attrs.defaultValue(f_type)) |d| @field(res, f_name) = d;
4848 }
4949 }
5050
lib/std/crypto/codecs/asn1/der/Encoder.zig+10-8
......@@ -29,16 +29,18 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
2929
3030 switch (@typeInfo(T)) {
3131 .@"struct" => |info| {
32 inline for (0..info.fields.len) |i| {
33 const f = info.fields[info.fields.len - i - 1];
34 const field_val = @field(val, f.name);
35 const field_tag = FieldTag.fromContainer(T, f.name);
32 inline for (0..info.field_names.len) |i| {
33 const f_idx = info.field_names.len - i - 1;
34 const f_name = info.field_names[f_idx];
35 const f_type = info.field_types[f_idx];
36 const f_attrs = info.field_attrs[f_idx];
37 const field_val = @field(val, f_name);
38 const field_tag = FieldTag.fromContainer(T, f_name);
3639
3740 // > The encoding of a set value or sequence value shall not include an encoding for any
3841 // > component value which is equal to its default value.
39 const is_default = if (f.is_comptime) false else if (f.default_value_ptr) |v| brk: {
40 const default_val: *const f.type = @ptrCast(@alignCast(v));
41 break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val));
42 const is_default = if (f_attrs.@"comptime") false else if (f_attrs.defaultValue(f_type)) |default_val| brk: {
43 break :brk std.mem.eql(u8, std.mem.asBytes(&default_val), std.mem.asBytes(&field_val));
4244 } else false;
4345
4446 if (!is_default) {
......@@ -46,7 +48,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
4648 self.field_tag = field_tag;
4749 // will merge with self.field_tag.
4850 // may mutate self.field_tag.
49 try self.anyTag(Tag.fromZig(f.type), field_val);
51 try self.anyTag(Tag.fromZig(f_type), field_val);
5052 if (field_tag) |ft| {
5153 if (ft.explicit) {
5254 try self.length(self.buffer.data.len - start2);
lib/std/crypto/phc_encoding.zig+23-20
......@@ -115,22 +115,23 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
115115 while (it_params.next()) |params| {
116116 const param = kvSplit(params) catch break;
117117 var found = false;
118 inline for (comptime meta.fields(HashResult)) |p| {
119 if (mem.eql(u8, p.name, param.key)) {
120 switch (@typeInfo(p.type)) {
121 .int => @field(out, p.name) = fmt.parseUnsigned(
122 p.type,
118 const info = @typeInfo(HashResult).@"struct";
119 inline for (info.field_names, info.field_types) |p_name, p_type| {
120 if (mem.eql(u8, p_name, param.key)) {
121 switch (@typeInfo(p_type)) {
122 .int => @field(out, p_name) = fmt.parseUnsigned(
123 p_type,
123124 param.value,
124125 10,
125126 ) catch return Error.InvalidEncoding,
126127 .pointer => |ptr| {
127 if (!ptr.is_const) @compileError("Value slice must be constant");
128 @field(out, p.name) = param.value;
128 if (!ptr.attrs.@"const") @compileError("Value slice must be constant");
129 @field(out, p_name) = param.value;
129130 },
130 .@"struct" => try @field(out, p.name).fromB64(param.value),
131 .@"struct" => try @field(out, p_name).fromB64(param.value),
131132 else => std.debug.panic(
132133 "Value for [{s}] must be an integer, a constant slice or a BinValue",
133 .{p.name},
134 .{p_name},
134135 ),
135136 }
136137 set_fields += 1;
......@@ -167,8 +168,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
167168 // Check that all the required fields have been set, excluding optional values and parameters
168169 // with default values
169170 var expected_fields: usize = 0;
170 inline for (comptime meta.fields(HashResult)) |p| {
171 if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) {
171 const info = @typeInfo(HashResult).@"struct";
172 inline for (info.field_types, info.field_attrs) |p_type, p_attrs| {
173 if (@typeInfo(p_type) != .optional and p_attrs.default_value_ptr == null) {
172174 expected_fields += 1;
173175 }
174176 }
......@@ -228,21 +230,22 @@ fn serializeTo(params: anytype, out: *std.Io.Writer) !void {
228230 }
229231
230232 var has_params = false;
231 inline for (comptime meta.fields(HashResult)) |p| {
232 if (comptime !(mem.eql(u8, p.name, "alg_id") or
233 mem.eql(u8, p.name, "alg_version") or
234 mem.eql(u8, p.name, "hash") or
235 mem.eql(u8, p.name, "salt")))
233 const info = @typeInfo(HashResult).@"struct";
234 inline for (info.field_names, info.field_types) |p_name, p_type| {
235 if (comptime !(mem.eql(u8, p_name, "alg_id") or
236 mem.eql(u8, p_name, "alg_version") or
237 mem.eql(u8, p_name, "hash") or
238 mem.eql(u8, p_name, "salt")))
236239 {
237 const value = @field(params, p.name);
240 const value = @field(params, p_name);
238241 try out.writeAll(if (has_params) params_delimiter else fields_delimiter);
239 if (@typeInfo(p.type) == .@"struct") {
242 if (@typeInfo(p_type) == .@"struct") {
240243 var buf: [@TypeOf(value).max_encoded_length]u8 = undefined;
241 try out.print("{s}{s}{s}", .{ p.name, kv_delimiter, try value.toB64(&buf) });
244 try out.print("{s}{s}{s}", .{ p_name, kv_delimiter, try value.toB64(&buf) });
242245 } else {
243246 try out.print(
244247 if (@typeInfo(@TypeOf(value)) == .pointer) "{s}{s}{s}" else "{s}{s}{}",
245 .{ p.name, kv_delimiter, value },
248 .{ p_name, kv_delimiter, value },
246249 );
247250 }
248251 has_params = true;
lib/std/crypto/timing_safe.zig+1-1
......@@ -135,7 +135,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void
135135 const t = @typeInfo(@TypeOf(ptr));
136136 if (t != .pointer) @compileError("Pointer expected - Found: " ++ @typeName(@TypeOf(ptr)));
137137 const p = t.pointer;
138 if (p.is_allowzero) @compileError("A nullable pointer is always assumed to leak information via side channels");
138 if (p.attrs.@"allowzero") @compileError("A nullable pointer is always assumed to leak information via side channels");
139139 const child = @typeInfo(p.child);
140140
141141 switch (child) {
lib/std/crypto/tls.zig+1-1
......@@ -710,7 +710,7 @@ pub const Decoder = struct {
710710 else => @compileError("unsupported int type: " ++ @typeName(T)),
711711 },
712712 .@"enum" => |info| {
713 if (info.is_exhaustive) @compileError("exhaustive enum cannot be used");
713 if (info.mode == .exhaustive) @compileError("exhaustive enum cannot be used");
714714 return @enumFromInt(d.decode(info.tag_type));
715715 },
716716 else => @compileError("unsupported type: " ++ @typeName(T)),
lib/std/crypto/tls/Client.zig+3-3
......@@ -1338,11 +1338,11 @@ fn failRead(c: *Client, err: ReadError) error{ReadFailed} {
13381338}
13391339
13401340fn logSecrets(w: *Writer, context: anytype, secrets: anytype) void {
1341 inline for (@typeInfo(@TypeOf(secrets)).@"struct".fields) |field| w.print("{s}" ++
1342 (if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{field.name} ++
1341 inline for (@typeInfo(@TypeOf(secrets)).@"struct".field_names) |field_name| w.print("{s}" ++
1342 (if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{field_name} ++
13431343 (if (@hasField(@TypeOf(context), "counter")) .{context.counter} else .{}) ++ .{
13441344 context.client_random,
1345 @field(secrets, field.name),
1345 @field(secrets, field_name),
13461346 }) catch {};
13471347}
13481348
lib/std/debug/ElfFile.zig+12-8
......@@ -219,9 +219,10 @@ pub fn load(
219219 break :dwarf null; // debug info not present
220220 }
221221 var sections: Dwarf.SectionArray = @splat(null);
222 inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields) |f| {
223 if (result.sections.get(@field(Section.Id, f.name))) |s| {
224 sections[f.value] = .{ .data = s.bytes, .owned = false };
222 const info = @typeInfo(Dwarf.Section.Id).@"enum";
223 inline for (info.field_names, info.field_values) |f_name, f_value| {
224 if (result.sections.get(@field(Section.Id, f_name))) |s| {
225 sections[f_value] = .{ .data = s.bytes, .owned = false };
225226 }
226227 }
227228 break :dwarf .{ .sections = sections };
......@@ -408,8 +409,8 @@ fn loadSeparateDebugFile(
408409 return null;
409410 }
410411
411 inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields) |f| {
412 const id = @field(Section.Id, f.name);
412 inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names) |f_name| {
413 const id = @field(Section.Id, f_name);
413414 if (main_loaded.sections.get(id) == null) {
414415 main_loaded.sections.set(id, result.sections.get(id));
415416 }
......@@ -498,9 +499,12 @@ fn loadInner(
498499 if (shdr.sh_name > shstrtab.len) return error.TruncatedElfFile;
499500 const name = std.mem.sliceTo(shstrtab[@intCast(shdr.sh_name)..], 0);
500501
501 const section_id: Section.Id = inline for (@typeInfo(Section.Id).@"enum".fields) |s| {
502 if (std.mem.eql(u8, "." ++ s.name, name)) {
503 break @enumFromInt(s.value);
502 const section_id: Section.Id = inline for (
503 @typeInfo(Section.Id).@"enum".field_names,
504 @typeInfo(Section.Id).@"enum".field_values,
505 ) |s_name, s_value| {
506 if (std.mem.eql(u8, "." ++ s_name, name)) {
507 break @enumFromInt(s_value);
504508 }
505509 } else continue;
506510
lib/std/debug/MachOFile.zig+2-2
......@@ -504,8 +504,8 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
504504
505505 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;
506506
507 const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields, 0..) |section, i| {
508 if (mem.eql(u8, "__" ++ section.name, sect.sectName())) break i;
507 const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| {
508 if (mem.eql(u8, "__" ++ section_name, sect.sectName())) break i;
509509 } else continue;
510510
511511 if (mapped_ofile.len < sect.offset + sect.size) return error.InvalidMachO;
lib/std/debug/SelfInfo/MachO.zig+2-2
......@@ -408,8 +408,8 @@ fn unwindFrameInner(si: *SelfInfo, io: Io, context: *UnwindContext) !usize {
408408 const ip_ptr = fp + @sizeOf(usize);
409409
410410 var reg_addr = fp - @sizeOf(usize);
411 inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".fields, 0..) |field, i| {
412 if (@field(frame.x_reg_pairs, field.name) != 0) {
411 inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".field_names, 0..) |field_name, i| {
412 if (@field(frame.x_reg_pairs, field_name) != 0) {
413413 (try dwarfRegNative(&context.cpu_state, 19 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;
414414 reg_addr += @sizeOf(usize);
415415 (try dwarfRegNative(&context.cpu_state, 20 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;
lib/std/debug/SelfInfo/Windows.zig+2-2
......@@ -513,8 +513,8 @@ const Module = struct {
513513 if (coff_obj.getSectionByName(".debug_info") == null) break :dwarf null;
514514
515515 var sections: Dwarf.SectionArray = undefined;
516 inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields, 0..) |section, i| {
517 sections[i] = if (coff_obj.getSectionByName("." ++ section.name)) |section_header| .{
516 inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| {
517 sections[i] = if (coff_obj.getSectionByName("." ++ section_name)) |section_header| .{
518518 .data = try coff_obj.getSectionDataAlloc(section_header, arena),
519519 .owned = false,
520520 } else null;
lib/std/elf.zig+7-7
......@@ -484,7 +484,7 @@ pub const PT = enum(Word) {
484484 _,
485485
486486 /// Number of defined types
487 pub const NUM = @typeInfo(PT).@"enum".fields.len;
487 pub const NUM = @typeInfo(PT).@"enum".field_names.len;
488488
489489 /// Start of OS-specific
490490 pub const LOOS: PT = @enumFromInt(0x60000000);
......@@ -552,7 +552,7 @@ pub const SHT = enum(Word) {
552552 _,
553553
554554 /// Number of defined types
555 pub const NUM = @typeInfo(SHT).@"enum".fields.len;
555 pub const NUM = @typeInfo(SHT).@"enum".field_names.len;
556556
557557 /// Start of OS-specific
558558 pub const LOOS: SHT = @enumFromInt(0x60000000);
......@@ -595,7 +595,7 @@ pub const STB = enum(u4) {
595595 _,
596596
597597 /// Number of defined types
598 pub const NUM = @typeInfo(STB).@"enum".fields.len;
598 pub const NUM = @typeInfo(STB).@"enum".field_names.len;
599599
600600 /// Start of OS-specific
601601 pub const LOOS: STB = @enumFromInt(10);
......@@ -631,7 +631,7 @@ pub const STT = enum(u4) {
631631 _,
632632
633633 /// Number of defined types
634 pub const NUM = @typeInfo(STT).@"enum".fields.len;
634 pub const NUM = @typeInfo(STT).@"enum".field_names.len;
635635
636636 /// Start of OS-specific
637637 pub const LOOS: STT = @enumFromInt(10);
......@@ -815,7 +815,7 @@ pub const Header = struct {
815815
816816 pub fn init(hdr: anytype, endian: Endian) Header {
817817 // Converting integers to exhaustive enums using `@enumFromInt` could cause a panic.
818 comptime assert(!@typeInfo(OSABI).@"enum".is_exhaustive);
818 comptime assert(@typeInfo(OSABI).@"enum".mode == .nonexhaustive);
819819 return .{
820820 .is_64 = switch (@TypeOf(hdr)) {
821821 Elf32_Ehdr => false,
......@@ -1642,7 +1642,7 @@ pub const CLASS = enum(u8) {
16421642 @"64" = 2,
16431643 _,
16441644
1645 pub const NUM = @typeInfo(CLASS).@"enum".fields.len;
1645 pub const NUM = @typeInfo(CLASS).@"enum".field_names.len;
16461646
16471647 pub fn ElfN(comptime class: CLASS) type {
16481648 return switch (class) {
......@@ -1667,7 +1667,7 @@ pub const DATA = enum(u8) {
16671667 @"2MSB" = 2,
16681668 _,
16691669
1670 pub const NUM = @typeInfo(DATA).@"enum".fields.len;
1670 pub const NUM = @typeInfo(DATA).@"enum".field_names.len;
16711671};
16721672
16731673pub const OSABI = enum(u8) {
lib/std/enums.zig+66-67
......@@ -3,14 +3,13 @@
33const std = @import("std");
44const assert = std.debug.assert;
55const testing = std.testing;
6const EnumField = std.builtin.Type.EnumField;
76
87/// Increment this value when adding APIs that add single backwards branches.
98const eval_branch_quota_cushion = 10;
109
1110pub fn fromInt(comptime E: type, integer: anytype) ?E {
1211 const enum_info = @typeInfo(E).@"enum";
13 if (!enum_info.is_exhaustive) {
12 if (enum_info.mode == .nonexhaustive) {
1413 if (std.math.cast(enum_info.tag_type, integer)) |tag| {
1514 return @enumFromInt(tag);
1615 }
......@@ -32,20 +31,19 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E {
3231/// the first name is used. Each field is of type Data and has the provided
3332/// default, which may be undefined.
3433pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {
35 @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion);
34 @setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion);
3635 const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null;
3736 return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr }));
3837}
3938
40/// Looks up the supplied fields in the given enum type.
41/// Uses only the field names, field values are ignored.
39/// Looks up the supplied field values in the given enum type.
4240/// The result array is in the same order as the input.
43pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E {
41pub inline fn valuesFromFields(comptime E: type, comptime field_values: []const comptime_int) []const E {
4442 comptime {
45 @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion);
46 var result: [fields.len]E = undefined;
47 for (&result, fields) |*r, f| {
48 r.* = @enumFromInt(f.value);
43 @setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion);
44 var result: [field_values.len]E = undefined;
45 for (&result, field_values) |*r, f_value| {
46 r.* = @enumFromInt(f_value);
4947 }
5048 const final = result;
5149 return &final;
......@@ -55,17 +53,18 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi
5553/// Returns the set of all named values in the given enum, in
5654/// declaration order.
5755pub inline fn values(comptime E: type) []const E {
58 return comptime valuesFromFields(E, @typeInfo(E).@"enum".fields);
56 return comptime valuesFromFields(E, @typeInfo(E).@"enum".field_values);
5957}
6058
6159/// A safe alternative to @tagName() for non-exhaustive enums that doesn't
6260/// panic when `e` has no tagged value.
6361/// Returns the tag name for `e` or null if no tag exists.
6462pub fn tagName(comptime E: type, e: E) ?[:0]const u8 {
65 const fields = @typeInfo(E).@"enum".fields;
66 @setEvalBranchQuota(fields.len);
67 return inline for (fields) |f| {
68 if (@intFromEnum(e) == f.value) break f.name;
63 const field_names = @typeInfo(E).@"enum".field_names;
64 const field_values = @typeInfo(E).@"enum".field_values;
65 @setEvalBranchQuota(field_names.len);
66 return inline for (field_names, field_values) |f_name, f_value| {
67 if (@intFromEnum(e) == f_value) break f_name;
6968 } else null;
7069}
7170
......@@ -88,20 +87,20 @@ test tagName {
8887pub fn directEnumArrayLen(comptime E: type, comptime max_unused_slots: comptime_int) comptime_int {
8988 var max_value: comptime_int = -1;
9089 const max_usize: comptime_int = ~@as(usize, 0);
91 const fields = @typeInfo(E).@"enum".fields;
92 for (fields) |f| {
93 if (f.value < 0) {
94 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " has a negative value.");
95 }
96 if (f.value > max_value) {
97 if (f.value > max_usize) {
98 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " is larger than the max value of usize.");
90 const info = @typeInfo(E).@"enum";
91 for (info.field_names, info.field_values) |f_name, f_value| {
92 if (f_value < 0) {
93 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " has a negative value.");
94 }
95 if (f_value > max_value) {
96 if (f_value > max_usize) {
97 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " is larger than the max value of usize.");
9998 }
100 max_value = f.value;
99 max_value = f_value;
101100 }
102101 }
103102
104 const unused_slots = max_value + 1 - fields.len;
103 const unused_slots = max_value + 1 - info.field_names.len;
105104 if (unused_slots > max_unused_slots) {
106105 const unused_str = std.fmt.comptimePrint("{d}", .{unused_slots});
107106 const allowed_str = std.fmt.comptimePrint("{d}", .{max_unused_slots});
......@@ -167,10 +166,10 @@ pub fn directEnumArrayDefault(
167166) [directEnumArrayLen(E, max_unused_slots)]Data {
168167 const len = comptime directEnumArrayLen(E, max_unused_slots);
169168 var result: [len]Data = @splat(default orelse undefined);
170 inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| {
171 const enum_value = @field(E, f.name);
169 inline for (@typeInfo(@TypeOf(init_values)).@"struct".field_names) |f_name| {
170 const enum_value = @field(E, f_name);
172171 const index = @as(usize, @intCast(@intFromEnum(enum_value)));
173 result[index] = @field(init_values, f.name);
172 result[index] = @field(init_values, f_name);
174173 }
175174 return result;
176175}
......@@ -256,9 +255,9 @@ pub fn EnumSet(comptime E: type) type {
256255
257256 /// Initializes the set using a struct of bools
258257 pub fn init(init_values: EnumFieldStruct(E, bool, false)) Self {
259 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".fields.len);
258 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
260259 var result: Self = .{};
261 if (@typeInfo(E).@"enum".is_exhaustive) {
260 if (@typeInfo(E).@"enum".mode == .exhaustive) {
262261 inline for (0..Self.len) |i| {
263262 const key = comptime Indexer.keyForIndex(i);
264263 const tag = @tagName(key);
......@@ -267,9 +266,9 @@ pub fn EnumSet(comptime E: type) type {
267266 }
268267 }
269268 } else {
270 inline for (std.meta.fields(E)) |field| {
271 const key = @field(E, field.name);
272 if (@field(init_values, field.name)) {
269 inline for (@typeInfo(E).@"enum".field_names) |field_name| {
270 const key = @field(E, field_name);
271 if (@field(init_values, field_name)) {
273272 const i = comptime Indexer.indexOf(key);
274273 result.bits.set(i);
275274 }
......@@ -443,9 +442,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
443442
444443 /// Initializes the map using a sparse struct of optionals
445444 pub fn init(init_values: EnumFieldStruct(E, ?Value, @as(?Value, null))) Self {
446 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".fields.len);
445 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
447446 var result: Self = .{};
448 if (@typeInfo(E).@"enum".is_exhaustive) {
447 if (@typeInfo(E).@"enum".mode == .exhaustive) {
449448 inline for (0..Self.len) |i| {
450449 const key = comptime Indexer.keyForIndex(i);
451450 const tag = @tagName(key);
......@@ -455,9 +454,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
455454 }
456455 }
457456 } else {
458 inline for (std.meta.fields(E)) |field| {
459 const key = @field(E, field.name);
460 if (@field(init_values, field.name)) |*v| {
457 inline for (std.meta.fieldNames(E)) |field_name| {
458 const key = @field(E, field_name);
459 if (@field(init_values, field_name)) |*v| {
461460 const i = comptime Indexer.indexOf(key);
462461 result.bits.set(i);
463462 result.values[i] = v.*;
......@@ -487,7 +486,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
487486 /// Initializes a full mapping with a provided default.
488487 /// Consider using EnumArray instead if the map will remain full.
489488 pub fn initFullWithDefault(comptime default: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {
490 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".fields.len);
489 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
491490 var result: Self = .{
492491 .bits = .full,
493492 .values = undefined,
......@@ -673,11 +672,12 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
673672
674673 /// Initializes the multiset using a struct of counts.
675674 pub fn init(init_counts: EnumFieldStruct(E, CountSize, 0)) Self {
676 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".fields.len);
675 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
677676 var self = initWithCount(0);
678 inline for (@typeInfo(E).@"enum".fields) |field| {
679 const c = @field(init_counts, field.name);
680 const key = @as(E, @enumFromInt(field.value));
677 const info = @typeInfo(E).@"enum";
678 inline for (info.field_names, info.field_values) |field_name, field_value| {
679 const c = @field(init_counts, field_name);
680 const key: E = @enumFromInt(field_value);
681681 self.counts.set(key, c);
682682 }
683683 return self;
......@@ -745,16 +745,16 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
745745 /// Increases the all key counts by given multiset. Caller
746746 /// asserts operation will not overflow any key.
747747 pub fn addSetAssertSafe(self: *Self, other: Self) void {
748 inline for (@typeInfo(E).@"enum".fields) |field| {
749 const key = @as(E, @enumFromInt(field.value));
748 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
749 const key = @as(E, @enumFromInt(field_value));
750750 self.addAssertSafe(key, other.getCount(key));
751751 }
752752 }
753753
754754 /// Increases the all key counts by given multiset.
755755 pub fn addSet(self: *Self, other: Self) error{Overflow}!void {
756 inline for (@typeInfo(E).@"enum".fields) |field| {
757 const key = @as(E, @enumFromInt(field.value));
756 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
757 const key = @as(E, @enumFromInt(field_value));
758758 try self.add(key, other.getCount(key));
759759 }
760760 }
......@@ -763,8 +763,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
763763 /// the given multiset has more key counts than this,
764764 /// then that key will have a key count of zero.
765765 pub fn removeSet(self: *Self, other: Self) void {
766 inline for (@typeInfo(E).@"enum".fields) |field| {
767 const key = @as(E, @enumFromInt(field.value));
766 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
767 const key = @as(E, @enumFromInt(field_value));
768768 self.remove(key, other.getCount(key));
769769 }
770770 }
......@@ -772,8 +772,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
772772 /// Returns true iff all key counts are the same as
773773 /// given multiset.
774774 pub fn eql(self: Self, other: Self) bool {
775 inline for (@typeInfo(E).@"enum".fields) |field| {
776 const key = @as(E, @enumFromInt(field.value));
775 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
776 const key = @as(E, @enumFromInt(field_value));
777777 if (self.getCount(key) != other.getCount(key)) {
778778 return false;
779779 }
......@@ -784,8 +784,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
784784 /// Returns true iff all key counts less than or
785785 /// equal to the given multiset.
786786 pub fn subsetOf(self: Self, other: Self) bool {
787 inline for (@typeInfo(E).@"enum".fields) |field| {
788 const key = @as(E, @enumFromInt(field.value));
787 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
788 const key = @as(E, @enumFromInt(field_value));
789789 if (self.getCount(key) > other.getCount(key)) {
790790 return false;
791791 }
......@@ -796,8 +796,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
796796 /// Returns true iff all key counts greater than or
797797 /// equal to the given multiset.
798798 pub fn supersetOf(self: Self, other: Self) bool {
799 inline for (@typeInfo(E).@"enum".fields) |field| {
800 const key = @as(E, @enumFromInt(field.value));
799 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
800 const key = @as(E, @enumFromInt(field_value));
801801 if (self.getCount(key) < other.getCount(key)) {
802802 return false;
803803 }
......@@ -1075,7 +1075,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
10751075
10761076 /// Initializes values in the enum array, with the specified default.
10771077 pub fn initDefault(comptime default: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {
1078 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".fields.len);
1078 @setEvalBranchQuota(2 * @typeInfo(E).@"enum".field_names.len);
10791079 var result: Self = .{ .values = undefined };
10801080 inline for (0..Self.len) |i| {
10811081 const key = comptime Indexer.keyForIndex(i);
......@@ -1264,10 +1264,10 @@ test "EnumSet non-exhaustive" {
12641264
12651265pub fn EnumIndexer(comptime E: type) type {
12661266 // n log n for `std.mem.sortUnstable` call below.
1267 const fields_len = @typeInfo(E).@"enum".fields.len;
1267 const fields_len = @typeInfo(E).@"enum".field_names.len;
12681268 @setEvalBranchQuota(3 * fields_len * std.math.log2(@max(fields_len, 1)) + eval_branch_quota_cushion);
12691269
1270 if (!@typeInfo(E).@"enum".is_exhaustive) {
1270 if (@typeInfo(E).@"enum".mode == .nonexhaustive) {
12711271 const BackingInt = @typeInfo(E).@"enum".tag_type;
12721272 if (@bitSizeOf(BackingInt) > @bitSizeOf(usize))
12731273 @compileError("Cannot create an enum indexer for a given non-exhaustive enum, tag_type is larger than usize.");
......@@ -1315,18 +1315,17 @@ pub fn EnumIndexer(comptime E: type) type {
13151315 };
13161316 }
13171317
1318 var fields: [fields_len]EnumField = @typeInfo(E).@"enum".fields[0..].*;
1318 var field_values = @typeInfo(E).@"enum".field_values[0..fields_len].*;
13191319
1320 std.mem.sortUnstable(EnumField, &fields, {}, struct {
1321 fn lessThan(ctx: void, lhs: EnumField, rhs: EnumField) bool {
1322 ctx;
1323 return lhs.value < rhs.value;
1320 std.mem.sortUnstable(comptime_int, &field_values, {}, struct {
1321 fn lessThan(_: void, a: comptime_int, b: comptime_int) bool {
1322 return a < b;
13241323 }
13251324 }.lessThan);
13261325
1327 const min = fields[0].value;
1328 const max = fields[fields_len - 1].value;
1329 if (max - min == fields.len - 1) {
1326 const min = field_values[0];
1327 const max = field_values[fields_len - 1];
1328 if (max - min == field_values.len - 1) {
13301329 return struct {
13311330 pub const Key = E;
13321331 pub const count: comptime_int = fields_len;
......@@ -1343,7 +1342,7 @@ pub fn EnumIndexer(comptime E: type) type {
13431342 };
13441343 }
13451344
1346 const keys = valuesFromFields(E, &fields);
1345 const keys = valuesFromFields(E, &field_values);
13471346
13481347 return struct {
13491348 pub const Key = E;
lib/std/gpu.zig+1-1
......@@ -58,7 +58,7 @@ pub const ExecutionMode = union(Tag) {
5858
5959/// Declare the mode entry point executes in.
6060pub fn executionMode(comptime entry_point: anytype, comptime mode: ExecutionMode) void {
61 const cc = @typeInfo(@TypeOf(entry_point)).@"fn".calling_convention;
61 const cc = @typeInfo(@TypeOf(entry_point)).@"fn".attrs.@"callconv";
6262 switch (mode) {
6363 .origin_upper_left,
6464 .origin_lower_left,
lib/std/hash/auto_hash.zig+8-8
......@@ -127,10 +127,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
127127 },
128128
129129 .@"struct" => |info| {
130 inline for (info.fields) |field| {
130 inline for (info.field_names) |field_name| {
131131 // We reuse the hash of the previous field as the seed for the
132132 // next one so that they're dependant.
133 hash(hasher, @field(key, field.name), strat);
133 hash(hasher, @field(key, field_name), strat);
134134 }
135135 },
136136
......@@ -138,10 +138,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
138138 if (info.tag_type) |tag_type| {
139139 const tag = std.meta.activeTag(key);
140140 hash(hasher, tag, strat);
141 inline for (info.fields) |field| {
142 if (@field(tag_type, field.name) == tag) {
143 if (field.type != void) {
144 hash(hasher, @field(key, field.name), strat);
141 inline for (info.field_names, info.field_types) |field_name, field_type| {
142 if (@field(tag_type, field_name) == tag) {
143 if (field_type != void) {
144 hash(hasher, @field(key, field_name), strat);
145145 }
146146 break :blk;
147147 }
......@@ -165,8 +165,8 @@ inline fn typeContainsSlice(comptime K: type) bool {
165165 .pointer => |info| info.size == .slice,
166166
167167 inline .@"struct", .@"union" => |info| {
168 inline for (info.fields) |field| {
169 if (typeContainsSlice(field.type)) {
168 inline for (info.field_types) |field_type| {
169 if (typeContainsSlice(field_type)) {
170170 return true;
171171 }
172172 }
lib/std/hash/verify.zig+3-3
......@@ -2,8 +2,8 @@ const std = @import("std");
22
33fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typeInfo(@TypeOf(hash_fn)).@"fn".return_type.? {
44 const HashFn = @typeInfo(@TypeOf(hash_fn)).@"fn";
5 if (HashFn.params.len > 1) {
6 if (@typeInfo(HashFn.params[0].type.?) == .int) {
5 if (HashFn.param_types.len > 1) {
6 if (@typeInfo(HashFn.param_types[0].?) == .int) {
77 return hash_fn(@intCast(seed), buf);
88 } else {
99 return hash_fn(buf, @intCast(seed));
......@@ -15,7 +15,7 @@ fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typ
1515
1616fn initMaybeSeed(comptime Hash: anytype, seed: anytype) Hash {
1717 const HashFn = @typeInfo(@TypeOf(Hash.init)).@"fn";
18 if (HashFn.params.len == 1) {
18 if (HashFn.param_types.len == 1) {
1919 return Hash.init(@intCast(seed));
2020 } else {
2121 return Hash.init();
lib/std/http/Client.zig+2-2
......@@ -823,8 +823,8 @@ pub const Request = struct {
823823 /// Externally-owned; must outlive the Request.
824824 privileged_headers: []const http.Header,
825825
826 pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = b: {
827 var result: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = @splat(false);
826 pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = b: {
827 var result: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = @splat(false);
828828 result[@intFromEnum(http.ContentEncoding.gzip)] = true;
829829 result[@intFromEnum(http.ContentEncoding.deflate)] = true;
830830 result[@intFromEnum(http.ContentEncoding.identity)] = true;
lib/std/json/Stringify.zig+14-14
......@@ -401,9 +401,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
401401 return v.jsonStringify(self);
402402 }
403403
404 if (!enum_info.is_exhaustive) {
405 inline for (enum_info.fields) |field| {
406 if (v == @field(T, field.name)) {
404 if (enum_info.mode == .nonexhaustive) {
405 inline for (enum_info.field_names) |field_name| {
406 if (v == @field(T, field_name)) {
407407 break;
408408 }
409409 } else {
......@@ -424,15 +424,15 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
424424 const info = @typeInfo(T).@"union";
425425 if (info.tag_type) |UnionTagType| {
426426 try self.beginObject();
427 inline for (info.fields) |u_field| {
428 if (v == @field(UnionTagType, u_field.name)) {
429 try self.objectField(u_field.name);
430 if (u_field.type == void) {
427 inline for (info.field_names, info.field_types) |u_field_name, u_field_type| {
428 if (v == @field(UnionTagType, u_field_name)) {
429 try self.objectField(u_field_name);
430 if (u_field_type == void) {
431431 // void v is {}
432432 try self.beginObject();
433433 try self.endObject();
434434 } else {
435 try self.write(@field(v, u_field.name));
435 try self.write(@field(v, u_field_name));
436436 }
437437 break;
438438 }
......@@ -455,16 +455,16 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
455455 } else {
456456 try self.beginObject();
457457 }
458 inline for (S.fields) |Field| {
458 inline for (S.field_names, S.field_types) |field_name, field_type| {
459459 // don't include void fields
460 if (Field.type == void) continue;
460 if (field_type == void) continue;
461461
462462 var emit_field = true;
463463
464464 // don't include optional fields that are null when emit_null_optional_fields is set to false
465 if (@typeInfo(Field.type) == .optional) {
465 if (@typeInfo(field_type) == .optional) {
466466 if (self.options.emit_null_optional_fields == false) {
467 if (@field(v, Field.name) == null) {
467 if (@field(v, field_name) == null) {
468468 emit_field = false;
469469 }
470470 }
......@@ -472,9 +472,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
472472
473473 if (emit_field) {
474474 if (!S.is_tuple) {
475 try self.objectField(Field.name);
475 try self.objectField(field_name);
476476 }
477 try self.write(@field(v, Field.name));
477 try self.write(@field(v, field_name));
478478 }
479479 }
480480 if (S.is_tuple) {
lib/std/json/static.zig+47-31
......@@ -286,20 +286,20 @@ pub fn innerParse(
286286 },
287287 };
288288
289 inline for (unionInfo.fields) |u_field| {
290 if (std.mem.eql(u8, u_field.name, field_name)) {
289 inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| {
290 if (std.mem.eql(u8, u_field_name, field_name)) {
291291 // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.
292292 // (Recursing into innerParse() might trigger more allocations.)
293293 freeAllocated(allocator, name_token.?);
294294 name_token = null;
295 if (u_field.type == void) {
295 if (u_field_type == void) {
296296 // void isn't really a json type, but we can support void payload union tags with {} as a value.
297297 if (.object_begin != try source.next()) return error.UnexpectedToken;
298298 if (.object_end != try source.next()) return error.UnexpectedToken;
299 result = @unionInit(T, u_field.name, {});
299 result = @unionInit(T, u_field_name, {});
300300 } else {
301301 // Recurse.
302 result = @unionInit(T, u_field.name, try innerParse(u_field.type, allocator, source, options));
302 result = @unionInit(T, u_field_name, try innerParse(u_field_type, allocator, source, options));
303303 }
304304 break;
305305 }
......@@ -318,8 +318,8 @@ pub fn innerParse(
318318 if (.array_begin != try source.next()) return error.UnexpectedToken;
319319
320320 var r: T = undefined;
321 inline for (0..structInfo.fields.len) |i| {
322 r[i] = try innerParse(structInfo.fields[i].type, allocator, source, options);
321 inline for (structInfo.field_types, 0..) |field_type, i| {
322 r[i] = try innerParse(field_type, allocator, source, options);
323323 }
324324
325325 if (.array_end != try source.next()) return error.UnexpectedToken;
......@@ -334,7 +334,7 @@ pub fn innerParse(
334334 if (.object_begin != try source.next()) return error.UnexpectedToken;
335335
336336 var r: T = undefined;
337 var fields_seen: [structInfo.fields.len]bool = @splat(false);
337 var fields_seen: [structInfo.field_names.len]bool = @splat(false);
338338
339339 while (true) {
340340 var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);
......@@ -348,9 +348,14 @@ pub fn innerParse(
348348 },
349349 };
350350
351 inline for (structInfo.fields, 0..) |field, i| {
352 if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name);
353 if (std.mem.eql(u8, field.name, field_name)) {
351 inline for (
352 structInfo.field_names,
353 structInfo.field_types,
354 structInfo.field_attrs,
355 0..,
356 ) |f_name, f_type, f_attrs, i| {
357 if (f_attrs.@"comptime") @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ f_name);
358 if (std.mem.eql(u8, f_name, field_name)) {
354359 // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.
355360 // (Recursing into innerParse() might trigger more allocations.)
356361 freeAllocated(allocator, name_token.?);
......@@ -360,14 +365,14 @@ pub fn innerParse(
360365 .use_first => {
361366 // Parse and ignore the redundant value.
362367 // We don't want to skip the value, because we want type checking.
363 _ = try innerParse(field.type, allocator, source, options);
368 _ = try innerParse(f_type, allocator, source, options);
364369 break;
365370 },
366371 .@"error" => return error.DuplicateField,
367372 .use_last => {},
368373 }
369374 }
370 @field(r, field.name) = try innerParse(field.type, allocator, source, options);
375 @field(r, f_name) = try innerParse(f_type, allocator, source, options);
371376 fields_seen[i] = true;
372377 break;
373378 }
......@@ -493,7 +498,7 @@ pub fn innerParse(
493498 _ = try source.allocNextIntoArrayList(&value_list, .alloc_always);
494499 return try value_list.toOwnedSliceSentinel(s);
495500 }
496 if (ptrInfo.is_const) {
501 if (ptrInfo.attrs.@"const") {
497502 switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) {
498503 inline .string, .allocated_string => |slice| return slice,
499504 else => unreachable,
......@@ -613,16 +618,16 @@ pub fn innerParseFromValue(
613618 const kv = it.next().?;
614619 const field_name = kv.key_ptr.*;
615620
616 inline for (unionInfo.fields) |u_field| {
617 if (std.mem.eql(u8, u_field.name, field_name)) {
618 if (u_field.type == void) {
621 inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| {
622 if (std.mem.eql(u8, u_field_name, field_name)) {
623 if (u_field_type == void) {
619624 // void isn't really a json type, but we can support void payload union tags with {} as a value.
620625 if (kv.value_ptr.* != .object) return error.UnexpectedToken;
621626 if (kv.value_ptr.*.object.count() != 0) return error.UnexpectedToken;
622 return @unionInit(T, u_field.name, {});
627 return @unionInit(T, u_field_name, {});
623628 }
624629 // Recurse.
625 return @unionInit(T, u_field.name, try innerParseFromValue(u_field.type, allocator, kv.value_ptr.*, options));
630 return @unionInit(T, u_field_name, try innerParseFromValue(u_field_type, allocator, kv.value_ptr.*, options));
626631 }
627632 }
628633 // Didn't match anything.
......@@ -632,11 +637,11 @@ pub fn innerParseFromValue(
632637 .@"struct" => |structInfo| {
633638 if (structInfo.is_tuple) {
634639 if (source != .array) return error.UnexpectedToken;
635 if (source.array.items.len != structInfo.fields.len) return error.UnexpectedToken;
640 if (source.array.items.len != structInfo.field_names.len) return error.UnexpectedToken;
636641
637642 var r: T = undefined;
638 inline for (0..structInfo.fields.len, source.array.items) |i, item| {
639 r[i] = try innerParseFromValue(structInfo.fields[i].type, allocator, item, options);
643 inline for (0..structInfo.field_names.len, source.array.items) |i, item| {
644 r[i] = try innerParseFromValue(structInfo.field_types[i], allocator, item, options);
640645 }
641646
642647 return r;
......@@ -649,17 +654,22 @@ pub fn innerParseFromValue(
649654 if (source != .object) return error.UnexpectedToken;
650655
651656 var r: T = undefined;
652 var fields_seen: [structInfo.fields.len]bool = @splat(false);
657 var fields_seen: [structInfo.field_names.len]bool = @splat(false);
653658
654659 var it = source.object.iterator();
655660 while (it.next()) |kv| {
656661 const field_name = kv.key_ptr.*;
657662
658 inline for (structInfo.fields, 0..) |field, i| {
659 if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name);
660 if (std.mem.eql(u8, field.name, field_name)) {
663 inline for (
664 structInfo.field_names,
665 structInfo.field_types,
666 structInfo.field_attrs,
667 0..,
668 ) |f_name, f_type, f_attrs, i| {
669 if (f_attrs.@"comptime") @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ f_name);
670 if (std.mem.eql(u8, f_name, field_name)) {
661671 assert(!fields_seen[i]); // Can't have duplicate keys in a Value.object.
662 @field(r, field.name) = try innerParseFromValue(field.type, allocator, kv.value_ptr.*, options);
672 @field(r, f_name) = try innerParseFromValue(f_type, allocator, kv.value_ptr.*, options);
663673 fields_seen[i] = true;
664674 break;
665675 }
......@@ -782,11 +792,17 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T {
782792 return std.enums.fromInt(T, n) orelse return error.InvalidEnumTag;
783793}
784794
785fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".fields.len]bool) !void {
786 inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| {
795fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".field_names.len]bool) !void {
796 const info = @typeInfo(T).@"struct";
797 inline for (
798 info.field_names,
799 info.field_types,
800 info.field_attrs,
801 0..,
802 ) |field_name, field_type, field_attrs, i| {
787803 if (!fields_seen[i]) {
788 if (field.defaultValue()) |default| {
789 @field(r, field.name) = default;
804 if (field_attrs.defaultValue(field_type)) |default| {
805 @field(r, field_name) = default;
790806 } else {
791807 return error.MissingField;
792808 }
lib/std/lang.zig+65-97
......@@ -596,13 +596,8 @@ pub const Type = union(enum) {
596596 /// therefore must be kept in sync with the compiler implementation.
597597 pub const Pointer = struct {
598598 size: Size,
599 is_const: bool,
600 is_volatile: bool,
601 /// `null` means implicit alignment, which is equivalent to `@alignOf(child)`.
602 alignment: ?usize,
603 address_space: AddressSpace,
599 attrs: Attributes,
604600 child: type,
605 is_allowzero: bool,
606601
607602 /// The type of the sentinel is the element type of the pointer, which is
608603 /// the value of the `child` field in this struct. However there is no way
......@@ -667,44 +662,40 @@ pub const Type = union(enum) {
667662
668663 /// This data structure is used by the Zig language code generation and
669664 /// therefore must be kept in sync with the compiler implementation.
670 pub const StructField = struct {
671 name: [:0]const u8,
672 type: type,
673 /// The type of the default value is the type of this struct field, which
674 /// is the value of the `type` field in this struct. However there is no
675 /// way to refer to that type here, so we use `*const anyopaque`.
676 /// See also: `defaultValue`.
677 default_value_ptr: ?*const anyopaque,
678 is_comptime: bool,
679 /// `null` means the field alignment was not explicitly specified. The
680 /// field will still be aligned to at least `@alignOf` its `type`.
681 alignment: ?usize,
682
683 /// Loads the field's default value from `default_value_ptr`.
684 /// Returns `null` if the field has no default value.
685 pub inline fn defaultValue(comptime sf: StructField) ?sf.type {
686 const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null));
687 return dp.*;
688 }
665 pub const Struct = struct {
666 is_tuple: bool,
667 layout: ContainerLayout,
668 /// Always `null` if `layout != .@"packed"`.
669 backing_integer: ?type,
689670
690 /// This data structure is used by the Zig language code generation and
691 /// therefore must be kept in sync with the compiler implementation.
692 pub const Attributes = struct {
671 field_names: []const [:0]const u8,
672 /// Guaranteed to have the same length as `field_names`.
673 field_types: []const type,
674 /// Guaranteed to have the same length as `field_names`.
675 field_attrs: []const FieldAttributes,
676
677 decl_names: []const [:0]const u8,
678
679 pub const FieldAttributes = struct {
693680 @"comptime": bool = false,
681 /// `null` means the field alignment is not explicitly specified. The field will still
682 /// be aligned to at least `@alignOf` the field type.
694683 @"align": ?usize = null,
684 /// The type of the default value is the type of this struct field. However, that type
685 /// is not known here, so we use a type-erased pointer instead, which must be cast to
686 /// a pointer to the field type.
687 ///
688 /// See also: `defaultValue`.
695689 default_value_ptr: ?*const anyopaque = null,
696 };
697 };
698690
699 /// This data structure is used by the Zig language code generation and
700 /// therefore must be kept in sync with the compiler implementation.
701 pub const Struct = struct {
702 layout: ContainerLayout,
703 /// Only valid if layout is .@"packed"
704 backing_integer: ?type = null,
705 fields: []const StructField,
706 decls: []const Declaration,
707 is_tuple: bool,
691 /// Loads the field's default value from `default_value_ptr`.
692 /// `FieldType` must exactly match the corresponding element of `Struct.field_types`.
693 /// Returns `null` if the field has no default value.
694 pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType {
695 const dp: *const FieldType = @ptrCast(@alignCast(attrs.default_value_ptr orelse return null));
696 return dp.*;
697 }
698 };
708699 };
709700
710701 /// This data structure is used by the Zig language code generation and
......@@ -722,48 +713,25 @@ pub const Type = union(enum) {
722713
723714 /// This data structure is used by the Zig language code generation and
724715 /// therefore must be kept in sync with the compiler implementation.
725 pub const Error = struct {
726 name: [:0]const u8,
727 };
728
729 /// This data structure is used by the Zig language code generation and
730 /// therefore must be kept in sync with the compiler implementation.
731 pub const ErrorSet = ?[]const Error;
732
733 /// This data structure is used by the Zig language code generation and
734 /// therefore must be kept in sync with the compiler implementation.
735 pub const EnumField = struct {
736 name: [:0]const u8,
737 value: comptime_int,
716 pub const ErrorSet = struct {
717 error_names: ?[]const [:0]const u8,
738718 };
739719
740720 /// This data structure is used by the Zig language code generation and
741721 /// therefore must be kept in sync with the compiler implementation.
742722 pub const Enum = struct {
743723 tag_type: type,
744 fields: []const EnumField,
745 decls: []const Declaration,
746 is_exhaustive: bool,
724 mode: Mode,
747725
748 /// This data structure is used by the Zig language code generation and
749 /// therefore must be kept in sync with the compiler implementation.
750 pub const Mode = enum { exhaustive, nonexhaustive };
751 };
726 field_names: []const [:0]const u8,
727 /// Guaranteed to have the same length as `field_names`.
728 field_values: []const comptime_int,
752729
753 /// This data structure is used by the Zig language code generation and
754 /// therefore must be kept in sync with the compiler implementation.
755 pub const UnionField = struct {
756 name: [:0]const u8,
757 type: type,
758 /// `null` means the field alignment was not explicitly specified. The
759 /// field will still be aligned to at least `@alignOf` its `type`.
760 alignment: ?usize,
730 decl_names: []const [:0]const u8,
761731
762732 /// This data structure is used by the Zig language code generation and
763733 /// therefore must be kept in sync with the compiler implementation.
764 pub const Attributes = struct {
765 @"align": ?usize = null,
766 };
734 pub const Mode = enum { exhaustive, nonexhaustive };
767735 };
768736
769737 /// This data structure is used by the Zig language code generation and
......@@ -771,36 +739,42 @@ pub const Type = union(enum) {
771739 pub const Union = struct {
772740 layout: ContainerLayout,
773741 tag_type: ?type,
774 fields: []const UnionField,
775 decls: []const Declaration,
742 /// Always `null` if `layout != .@"packed"`.
743 backing_integer: ?type,
744
745 field_names: []const [:0]const u8,
746 /// Guaranteed to have the same length as `field_names`.
747 field_types: []const type,
748 /// Guaranteed to have the same length as `field_names`.
749 field_attrs: []const FieldAttributes,
750
751 decl_names: []const [:0]const u8,
752
753 pub const FieldAttributes = struct {
754 /// `null` means the field alignment is not explicitly specified. The field will still
755 /// be aligned to at least `@alignOf` the field type.
756 @"align": ?usize = null,
757 };
776758 };
777759
778760 /// This data structure is used by the Zig language code generation and
779761 /// therefore must be kept in sync with the compiler implementation.
780762 pub const Fn = struct {
781 calling_convention: CallingConvention,
763 attrs: Attributes,
782764 is_generic: bool,
783 is_var_args: bool,
784 /// TODO change the language spec to make this not optional.
765 /// `null` means the return type is generic, i.e. it depends on a function argument.
785766 return_type: ?type,
786 params: []const Param,
787767
788 /// This data structure is used by the Zig language code generation and
789 /// therefore must be kept in sync with the compiler implementation.
790 pub const Param = struct {
791 is_generic: bool,
792 is_noalias: bool,
793 type: ?type,
794
795 /// This data structure is used by the Zig language code generation and
796 /// therefore must be kept in sync with the compiler implementation.
797 pub const Attributes = struct {
798 @"noalias": bool = false,
799 };
768 /// A `null` element represents either an `anytype` parameter, or a parameter with a generic
769 /// type, i.e. where the type depends on a previous function argument.
770 param_types: []const ?type,
771 /// Guaranteed to have the same length as `param_types`.
772 param_attrs: []const ParamAttributes,
773
774 pub const ParamAttributes = struct {
775 @"noalias": bool = false,
800776 };
801777
802 /// This data structure is used by the Zig language code generation and
803 /// therefore must be kept in sync with the compiler implementation.
804778 pub const Attributes = struct {
805779 @"callconv": CallingConvention = .auto,
806780 varargs: bool = false,
......@@ -810,7 +784,7 @@ pub const Type = union(enum) {
810784 /// This data structure is used by the Zig language code generation and
811785 /// therefore must be kept in sync with the compiler implementation.
812786 pub const Opaque = struct {
813 decls: []const Declaration,
787 decl_names: []const [:0]const u8,
814788 };
815789
816790 /// This data structure is used by the Zig language code generation and
......@@ -831,12 +805,6 @@ pub const Type = union(enum) {
831805 len: comptime_int,
832806 child: type,
833807 };
834
835 /// This data structure is used by the Zig language code generation and
836 /// therefore must be kept in sync with the compiler implementation.
837 pub const Declaration = struct {
838 name: [:0]const u8,
839 };
840808};
841809
842810/// This data structure is used by the Zig language code generation and
lib/std/math.zig+2-2
......@@ -1648,8 +1648,8 @@ pub const CompareOperator = enum {
16481648 }
16491649
16501650 test reverse {
1651 inline for (@typeInfo(CompareOperator).@"enum".fields) |op_field| {
1652 const op = @as(CompareOperator, @enumFromInt(op_field.value));
1651 inline for (@typeInfo(CompareOperator).@"enum".field_values) |op_field_value| {
1652 const op = @as(CompareOperator, @enumFromInt(op_field_value));
16531653 try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
16541654 try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
16551655 try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4));
lib/std/mem.zig+86-102
......@@ -297,9 +297,13 @@ pub fn zeroes(comptime T: type) T {
297297 return item;
298298 } else {
299299 var structure: T = undefined;
300 inline for (struct_info.fields) |field| {
301 if (!field.is_comptime) {
302 @field(structure, field.name) = zeroes(field.type);
300 inline for (
301 struct_info.field_names,
302 struct_info.field_types,
303 struct_info.field_attrs,
304 ) |field_name, field_type, field_attrs| {
305 if (!field_attrs.@"comptime") {
306 @field(structure, field_name) = zeroes(field_type);
303307 }
304308 }
305309 return structure;
......@@ -321,7 +325,7 @@ pub fn zeroes(comptime T: type) T {
321325 return null;
322326 },
323327 .one, .many => {
324 if (ptr_info.is_allowzero) return @ptrFromInt(0);
328 if (ptr_info.attrs.@"allowzero") return @ptrFromInt(0);
325329 @compileError("Only nullable and allowzero pointers can be set to zero.");
326330 },
327331 }
......@@ -471,44 +475,49 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
471475 switch (@typeInfo(Init)) {
472476 .@"struct" => |init_info| {
473477 if (init_info.is_tuple) {
474 if (init_info.fields.len > struct_info.fields.len) {
478 if (init_info.field_names.len > struct_info.field_names.len) {
475479 @compileError("Tuple initializer has more elements than there are fields in `" ++ @typeName(T) ++ "`");
476480 }
477481 } else {
478 inline for (init_info.fields) |field| {
479 if (!@hasField(T, field.name)) {
480 @compileError("Encountered an initializer for `" ++ field.name ++ "`, but it is not a field of " ++ @typeName(T));
482 inline for (init_info.field_names) |field_name| {
483 if (!@hasField(T, field_name)) {
484 @compileError("Encountered an initializer for `" ++ field_name ++ "`, but it is not a field of " ++ @typeName(T));
481485 }
482486 }
483487 }
484488
485489 var value: T = if (struct_info.layout == .@"extern") zeroes(T) else undefined;
486490
487 inline for (struct_info.fields, 0..) |field, i| {
488 if (field.is_comptime) {
491 inline for (
492 struct_info.field_names,
493 struct_info.field_types,
494 struct_info.field_attrs,
495 0..,
496 ) |f_name, f_type, f_attr, i| {
497 if (f_attr.@"comptime") {
489498 continue;
490499 }
491500
492 if (init_info.is_tuple and init_info.fields.len > i) {
493 @field(value, field.name) = @field(init, init_info.fields[i].name);
494 } else if (@hasField(@TypeOf(init), field.name)) {
495 switch (@typeInfo(field.type)) {
501 if (init_info.is_tuple and init_info.field_names.len > i) {
502 @field(value, f_name) = @field(init, init_info.field_names[i]);
503 } else if (@hasField(@TypeOf(init), f_name)) {
504 switch (@typeInfo(f_type)) {
496505 .@"struct" => {
497 @field(value, field.name) = zeroInit(field.type, @field(init, field.name));
506 @field(value, f_name) = zeroInit(f_type, @field(init, f_name));
498507 },
499508 else => {
500 @field(value, field.name) = @field(init, field.name);
509 @field(value, f_name) = @field(init, f_name);
501510 },
502511 }
503 } else if (field.defaultValue()) |val| {
504 @field(value, field.name) = val;
512 } else if (f_attr.defaultValue(f_type)) |val| {
513 @field(value, f_name) = val;
505514 } else {
506 switch (@typeInfo(field.type)) {
515 switch (@typeInfo(f_type)) {
507516 .@"struct" => {
508 @field(value, field.name) = std.mem.zeroInit(field.type, .{});
517 @field(value, f_name) = std.mem.zeroInit(f_type, .{});
509518 },
510519 else => {
511 @field(value, field.name) = std.mem.zeroes(@TypeOf(@field(value, field.name)));
520 @field(value, f_name) = std.mem.zeroes(@TypeOf(@field(value, f_name)));
512521 },
513522 }
514523 }
......@@ -867,13 +876,9 @@ fn Span(comptime T: type) type {
867876 .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
868877 .c => 0,
869878 };
870 return @Pointer(.slice, .{
871 .@"const" = ptr_info.is_const,
872 .@"volatile" = ptr_info.is_volatile,
873 .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c,
874 .@"align" = ptr_info.alignment,
875 .@"addrspace" = ptr_info.address_space,
876 }, ptr_info.child, new_sentinel);
879 var attrs = ptr_info.attrs;
880 attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
881 return @Pointer(.slice, attrs, ptr_info.child, new_sentinel);
877882 },
878883 else => {},
879884 }
......@@ -933,13 +938,9 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
933938 .many => if (std.meta.sentinel(T)) |s| s == end else true,
934939 .c => true,
935940 };
936 return @Pointer(.slice, .{
937 .@"const" = ptr_info.is_const,
938 .@"volatile" = ptr_info.is_volatile,
939 .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c,
940 .@"align" = ptr_info.alignment,
941 .@"addrspace" = ptr_info.address_space,
942 }, Elem, if (have_sentinel) end else null);
941 var attrs = ptr_info.attrs;
942 attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
943 return @Pointer(.slice, attrs, Elem, if (have_sentinel) end else null);
943944 },
944945 else => {},
945946 }
......@@ -2210,19 +2211,19 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
22102211 .@"struct" => |struct_info| {
22112212 if (struct_info.backing_integer) |Int| {
22122213 ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*))));
2213 } else inline for (std.meta.fields(S)) |f| {
2214 switch (@typeInfo(f.type)) {
2215 .@"struct" => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)),
2216 .@"union", .array => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)),
2214 } else inline for (struct_info.field_types, struct_info.field_names, struct_info.field_attrs) |f_type, f_name, f_attr| {
2215 switch (@typeInfo(f_type)) {
2216 .@"struct" => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
2217 .@"union", .array => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
22172218 .@"enum" => {
2218 @field(ptr, f.name) = @enumFromInt(@byteSwap(@intFromEnum(@field(ptr, f.name))));
2219 @field(ptr, f_name) = @enumFromInt(@byteSwap(@intFromEnum(@field(ptr, f_name))));
22192220 },
22202221 .bool => {},
22212222 .float => |float_info| {
2222 @field(ptr, f.name) = @bitCast(@byteSwap(@as(@Int(.unsigned, float_info.bits), @bitCast(@field(ptr, f.name)))));
2223 @field(ptr, f_name) = @bitCast(@byteSwap(@as(@Int(.unsigned, float_info.bits), @bitCast(@field(ptr, f_name)))));
22232224 },
22242225 else => {
2225 @field(ptr, f.name) = @byteSwap(@field(ptr, f.name));
2226 @field(ptr, f_name) = @byteSwap(@field(ptr, f_name));
22262227 },
22272228 }
22282229 }
......@@ -2232,9 +2233,9 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
22322233 @compileError("byteSwapAllFields expects an untagged union");
22332234 }
22342235
2235 const first_size = @bitSizeOf(union_info.fields[0].type);
2236 inline for (union_info.fields) |field| {
2237 if (@bitSizeOf(field.type) != first_size) {
2236 const first_size = @bitSizeOf(union_info.field_types[0]);
2237 inline for (union_info.field_types) |field_type| {
2238 if (@bitSizeOf(field_type) != first_size) {
22382239 @compileError("Unable to byte-swap unions with varying field sizes");
22392240 }
22402241 }
......@@ -3940,15 +3941,8 @@ pub fn ReverseIterator(comptime T: type) type {
39403941 .many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"),
39413942 }
39423943 const Element = std.meta.Elem(T);
3943 const attrs: std.builtin.Type.Pointer.Attributes = .{
3944 .@"const" = ptr.is_const,
3945 .@"volatile" = ptr.is_volatile,
3946 .@"allowzero" = ptr.is_allowzero,
3947 .@"align" = ptr.alignment,
3948 .@"addrspace" = ptr.address_space,
3949 };
3950 const Pointer = @Pointer(.many, attrs, Element, std.meta.sentinel(T));
3951 const ElementPointer = @Pointer(.one, attrs, Element, null);
3944 const Pointer = @Pointer(.many, ptr.attrs, Element, std.meta.sentinel(T));
3945 const ElementPointer = @Pointer(.one, ptr.attrs, Element, null);
39523946 return struct {
39533947 ptr: Pointer,
39543948 index: usize,
......@@ -4255,7 +4249,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
42554249 @compileError("expected many item pointer, got " ++ @typeName(T));
42564250
42574251 // Do nothing if the pointer is already well-aligned.
4258 if (align_to <= info.pointer.alignment orelse @alignOf(info.pointer.child))
4252 if (align_to <= info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child))
42594253 return 0;
42604254
42614255 // Calculate the aligned base address with an eye out for overflow.
......@@ -4309,17 +4303,14 @@ fn CopyPtrAttrs(
43094303 comptime child: type,
43104304) type {
43114305 const ptr = @typeInfo(source).pointer;
4312 return @Pointer(size, .{
4313 .@"const" = ptr.is_const,
4314 .@"volatile" = ptr.is_volatile,
4315 .@"allowzero" = ptr.is_allowzero,
4316 .@"align" = ptr.alignment orelse a: {
4317 // If the new child is aligned differently than the old one, explicitly align the type.
4318 const want = @alignOf(ptr.child);
4319 break :a if (@alignOf(child) == want) null else want;
4320 },
4321 .@"addrspace" = ptr.address_space,
4322 }, child, null);
4306 var attrs = ptr.attrs;
4307 if (attrs.@"align" == null) {
4308 const want = @alignOf(ptr.child);
4309 if (@alignOf(child) != want) {
4310 attrs.@"align" = want;
4311 }
4312 }
4313 return @Pointer(size, attrs, child, null);
43234314}
43244315
43254316fn AsBytesReturnType(comptime P: type) type {
......@@ -4383,10 +4374,13 @@ test "asBytes preserves pointer attributes" {
43834374 const in = @typeInfo(@TypeOf(inPtr)).pointer;
43844375 const out = @typeInfo(@TypeOf(outSlice)).pointer;
43854376
4386 try testing.expectEqual(in.is_const, out.is_const);
4387 try testing.expectEqual(in.is_volatile, out.is_volatile);
4388 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4389 try testing.expectEqual(in.alignment, out.alignment);
4377 const in_attrs = in.attrs;
4378 const out_attrs = out.attrs;
4379
4380 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4381 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4382 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4383 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
43904384}
43914385
43924386/// Given any value, returns a copy of its bytes in an array.
......@@ -4463,13 +4457,13 @@ test "bytesAsValue preserves pointer attributes" {
44634457 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
44644458 const outPtr = bytesAsValue(u32, inSlice);
44654459
4466 const in = @typeInfo(@TypeOf(inSlice)).pointer;
4467 const out = @typeInfo(@TypeOf(outPtr)).pointer;
4460 const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4461 const out_attrs = @typeInfo(@TypeOf(outPtr)).pointer.attrs;
44684462
4469 try testing.expectEqual(in.is_const, out.is_const);
4470 try testing.expectEqual(in.is_volatile, out.is_volatile);
4471 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4472 try testing.expectEqual(in.alignment, out.alignment);
4463 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4464 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4465 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4466 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
44734467}
44744468
44754469/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
......@@ -4566,13 +4560,13 @@ test "bytesAsSlice preserves pointer attributes" {
45664560 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
45674561 const outSlice = bytesAsSlice(u16, inSlice);
45684562
4569 const in = @typeInfo(@TypeOf(inSlice)).pointer;
4570 const out = @typeInfo(@TypeOf(outSlice)).pointer;
4563 const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4564 const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
45714565
4572 try testing.expectEqual(in.is_const, out.is_const);
4573 try testing.expectEqual(in.is_volatile, out.is_volatile);
4574 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4575 try testing.expectEqual(in.alignment, out.alignment);
4566 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4567 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4568 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4569 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
45764570}
45774571
45784572test "bytesAsSlice with zero-bit element type" {
......@@ -4678,25 +4672,19 @@ test "sliceAsBytes preserves pointer attributes" {
46784672 const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..];
46794673 const outSlice = sliceAsBytes(inSlice);
46804674
4681 const in = @typeInfo(@TypeOf(inSlice)).pointer;
4682 const out = @typeInfo(@TypeOf(outSlice)).pointer;
4675 const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4676 const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
46834677
4684 try testing.expectEqual(in.is_const, out.is_const);
4685 try testing.expectEqual(in.is_volatile, out.is_volatile);
4686 try testing.expectEqual(in.is_allowzero, out.is_allowzero);
4687 try testing.expectEqual(in.alignment, out.alignment);
4678 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4679 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4680 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4681 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
46884682}
46894683
46904684fn AbsorbSentinelReturnType(comptime Slice: type) type {
46914685 const info = @typeInfo(Slice).pointer;
46924686 assert(info.size == .slice);
4693 return @Pointer(.slice, .{
4694 .@"const" = info.is_const,
4695 .@"volatile" = info.is_volatile,
4696 .@"allowzero" = info.is_allowzero,
4697 .@"addrspace" = info.address_space,
4698 .@"align" = info.alignment,
4699 }, info.child, null);
4687 return @Pointer(.slice, info.attrs, info.child, null);
47004688}
47014689
47024690/// If the provided slice is not sentinel terminated, do nothing and return that slice.
......@@ -4949,13 +4937,9 @@ test "freeing empty string with null-terminated sentinel" {
49494937/// all other pointer attributes copied from `AttributeSource`.
49504938fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type {
49514939 const ptr = @typeInfo(AttributeSource).pointer;
4952 return @Pointer(.slice, .{
4953 .@"const" = ptr.is_const,
4954 .@"volatile" = ptr.is_volatile,
4955 .@"allowzero" = ptr.is_allowzero,
4956 .@"align" = new_alignment,
4957 .@"addrspace" = ptr.address_space,
4958 }, ptr.child, null);
4940 var attrs = ptr.attrs;
4941 attrs.@"align" = new_alignment;
4942 return @Pointer(.slice, attrs, ptr.child, null);
49594943}
49604944
49614945/// Returns the largest slice in the given bytes that conforms to the new alignment,
lib/std/mem/Allocator.zig+9-9
......@@ -183,7 +183,7 @@ pub fn destroy(self: Allocator, ptr: anytype) void {
183183 const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
184184 self.rawFree(
185185 non_const_ptr[0..@sizeOf(T)],
186 .fromByteUnits(info.alignment orelse @alignOf(T)),
186 .fromByteUnits(info.attrs.@"align" orelse @alignOf(T)),
187187 @returnAddress(),
188188 );
189189}
......@@ -331,7 +331,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool {
331331 const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return false;
332332 return self.rawResize(
333333 old_memory,
334 .fromByteUnits(slice_info.alignment orelse @alignOf(T)),
334 .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)),
335335 new_len_bytes,
336336 @returnAddress(),
337337 );
......@@ -377,7 +377,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo
377377 const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return null;
378378 const new_ptr = self.rawRemap(
379379 old_memory,
380 .fromByteUnits(slice_info.alignment orelse @alignOf(T)),
380 .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)),
381381 new_len_bytes,
382382 @returnAddress(),
383383 ) orelse return null;
......@@ -412,11 +412,11 @@ pub fn reallocAdvanced(
412412 comptime assert(slice_info.size == .slice);
413413 const T = slice_info.child;
414414 if (old_mem.len == 0) {
415 return self.allocAdvancedWithRetAddr(T, .fromByteUnitsOptional(slice_info.alignment), new_n, return_address);
415 return self.allocAdvancedWithRetAddr(T, .fromByteUnitsOptional(slice_info.attrs.@"align"), new_n, return_address);
416416 }
417417 if (new_n == 0) {
418418 self.free(old_mem);
419 const alignment = slice_info.alignment orelse @alignOf(T);
419 const alignment = slice_info.attrs.@"align" orelse @alignOf(T);
420420 const addr = comptime std.mem.alignBackward(usize, math.maxInt(usize), alignment);
421421 const ptr: *align(alignment) [0]T = @ptrFromInt(addr);
422422 return ptr;
......@@ -425,16 +425,16 @@ pub fn reallocAdvanced(
425425 const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem)));
426426 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory;
427427 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
428 if (self.rawRemap(old_byte_slice, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), byte_count, return_address)) |p| {
428 if (self.rawRemap(old_byte_slice, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), byte_count, return_address)) |p| {
429429 return @ptrCast(@alignCast(p[0..byte_count]));
430430 }
431431
432 const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), return_address) orelse
432 const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), return_address) orelse
433433 return error.OutOfMemory;
434434 const copy_len = @min(byte_count, old_byte_slice.len);
435435 @memcpy(new_mem[0..copy_len], old_byte_slice[0..copy_len]);
436436 @memset(old_byte_slice, undefined);
437 self.rawFree(old_byte_slice, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), return_address);
437 self.rawFree(old_byte_slice, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), return_address);
438438
439439 return @ptrCast(@alignCast(new_mem[0..byte_count]));
440440}
......@@ -448,7 +448,7 @@ pub fn free(self: Allocator, memory: anytype) void {
448448 const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory)));
449449 if (bytes.len == 0) return;
450450 @memset(bytes, undefined);
451 self.rawFree(bytes, .fromByteUnits(slice_info.alignment orelse @alignOf(slice_info.child)), @returnAddress());
451 self.rawFree(bytes, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(slice_info.child)), @returnAddress());
452452}
453453
454454/// Copies `m` to newly allocated memory. Caller owns the memory.
lib/std/meta.zig+131-171
......@@ -8,7 +8,7 @@ const root = @import("root");
88
99pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags;
1010
11const Type = std.builtin.Type;
11const Type = std.lang.Type;
1212
1313test {
1414 _ = TrailerFlags;
......@@ -22,21 +22,21 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
2222 // TODO The '100' here is arbitrary and should be increased when possible:
2323 // - https://github.com/ziglang/zig/issues/4055
2424 // - https://github.com/ziglang/zig/issues/3863
25 if (@typeInfo(T).@"enum".fields.len <= 100) {
25 if (@typeInfo(T).@"enum".field_names.len <= 100) {
2626 const kvs = comptime build_kvs: {
2727 const EnumKV = struct { []const u8, T };
28 var kvs_array: [@typeInfo(T).@"enum".fields.len]EnumKV = undefined;
29 for (@typeInfo(T).@"enum".fields, 0..) |enumField, i| {
30 kvs_array[i] = .{ enumField.name, @field(T, enumField.name) };
28 var kvs_array: [@typeInfo(T).@"enum".field_names.len]EnumKV = undefined;
29 for (@typeInfo(T).@"enum".field_names, 0..) |name, i| {
30 kvs_array[i] = .{ name, @field(T, name) };
3131 }
3232 break :build_kvs kvs_array[0..];
3333 };
3434 const map = std.StaticStringMap(T).initComptime(kvs);
3535 return map.get(str);
3636 } else {
37 inline for (@typeInfo(T).@"enum".fields) |enumField| {
38 if (mem.eql(u8, str, enumField.name)) {
39 return @field(T, enumField.name);
37 inline for (@typeInfo(T).@"enum".field_names) |name| {
38 if (mem.eql(u8, str, name)) {
39 return @field(T, name);
4040 }
4141 }
4242 return null;
......@@ -63,7 +63,7 @@ pub fn alignment(comptime T: type) comptime_int {
6363 .pointer, .@"fn" => alignment(info.child),
6464 else => @alignOf(T),
6565 },
66 .pointer => |info| info.alignment orelse @alignOf(info.child),
66 .pointer => |info| info.attrs.@"align" orelse @alignOf(info.child),
6767 else => @alignOf(T),
6868 };
6969}
......@@ -171,34 +171,20 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
171171 switch (@typeInfo(T)) {
172172 .pointer => |info| switch (info.size) {
173173 .one => switch (@typeInfo(info.child)) {
174 .array => |array_info| return @Pointer(.one, .{
175 .@"const" = info.is_const,
176 .@"volatile" = info.is_volatile,
177 .@"allowzero" = info.is_allowzero,
178 .@"align" = info.alignment,
179 .@"addrspace" = info.address_space,
180 }, [array_info.len:sentinel_val]array_info.child, null),
174 .array => |array_info| return @Pointer(
175 .one,
176 info.attrs,
177 [array_info.len:sentinel_val]array_info.child,
178 null,
179 ),
181180 else => {},
182181 },
183 .many, .slice => |size| return @Pointer(size, .{
184 .@"const" = info.is_const,
185 .@"volatile" = info.is_volatile,
186 .@"allowzero" = info.is_allowzero,
187 .@"align" = info.alignment,
188 .@"addrspace" = info.address_space,
189 }, info.child, sentinel_val),
182 .many, .slice => |size| return @Pointer(size, info.attrs, info.child, sentinel_val),
190183 else => {},
191184 },
192185 .optional => |info| switch (@typeInfo(info.child)) {
193186 .pointer => |ptr_info| switch (ptr_info.size) {
194 .many => return ?@Pointer(.many, .{
195 .@"const" = ptr_info.is_const,
196 .@"volatile" = ptr_info.is_volatile,
197 .@"allowzero" = ptr_info.is_allowzero,
198 .@"align" = ptr_info.alignment,
199 .@"addrspace" = ptr_info.address_space,
200 .child = ptr_info.child,
201 }, ptr_info.child, sentinel_val),
187 .many => return ?@Pointer(.many, ptr_info.attrs, ptr_info.child, sentinel_val),
202188 else => {},
203189 },
204190 else => {},
......@@ -238,14 +224,14 @@ test containerLayout {
238224 try testing.expect(containerLayout(U3) == .@"extern");
239225}
240226
241/// Instead of this function, prefer to use e.g. `@typeInfo(foo).@"struct".decls`
227/// Instead of this function, prefer to use e.g. `@typeInfo(foo).@"struct".decl_names`
242228/// directly when you know what kind of type it is.
243pub fn declarations(comptime T: type) []const Type.Declaration {
229pub fn declarations(comptime T: type) []const [:0]const u8 {
244230 return switch (@typeInfo(T)) {
245 .@"struct" => |info| info.decls,
246 .@"enum" => |info| info.decls,
247 .@"union" => |info| info.decls,
248 .@"opaque" => |info| info.decls,
231 .@"struct" => |info| info.decl_names,
232 .@"enum" => |info| info.decl_names,
233 .@"union" => |info| info.decl_names,
234 .@"opaque" => |info| info.decl_names,
249235 else => @compileError("Expected struct, enum, union, or opaque type, found '" ++ @typeName(T) ++ "'"),
250236 };
251237}
......@@ -268,7 +254,7 @@ test declarations {
268254 pub fn a() void {}
269255 };
270256
271 const decls = comptime [_][]const Type.Declaration{
257 const decls = comptime [_][]const [:0]const u8{
272258 declarations(E1),
273259 declarations(S1),
274260 declarations(U1),
......@@ -277,99 +263,43 @@ test declarations {
277263
278264 inline for (decls) |decl| {
279265 try testing.expect(decl.len == 1);
280 try testing.expect(comptime mem.eql(u8, decl[0].name, "a"));
266 try testing.expect(comptime mem.eql(u8, decl[0], "a"));
281267 }
282268}
283269
284pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.Declaration {
285 inline for (comptime declarations(T)) |decl| {
286 if (comptime mem.eql(u8, decl.name, decl_name))
287 return decl;
288 }
289
290 @compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'");
291}
292
293test declarationInfo {
294 const E1 = enum {
295 A,
296
297 pub fn a() void {}
298 };
299 const S1 = struct {
300 pub fn a() void {}
301 };
302 const U1 = union {
303 b: u8,
304
305 pub fn a() void {}
306 };
307
308 const infos = comptime [_]Type.Declaration{
309 declarationInfo(E1, "a"),
310 declarationInfo(S1, "a"),
311 declarationInfo(U1, "a"),
312 };
270/// To be removed after Zig 0.17.0 is tagged.
271pub const declarationInfo = @compileError("Deprecated; use '@hasDecl' instead");
272/// To be removed after Zig 0.17.0 is tagged.
273pub const fields = @compileError("Deprecated; use 'fieldNames' and 'fieldTypes' instead");
313274
314 inline for (infos) |info| {
315 try testing.expect(comptime mem.eql(u8, info.name, "a"));
316 }
317}
318pub inline fn fields(comptime T: type) switch (@typeInfo(T)) {
319 .@"struct" => []const Type.StructField,
320 .@"union" => []const Type.UnionField,
321 .@"enum" => []const Type.EnumField,
322 .error_set => []const Type.Error,
275pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
276 .@"struct" => struct { name: [:0]const u8, type: type, attrs: Type.Struct.FieldAttributes },
277 .@"union" => struct { name: [:0]const u8, type: type, attrs: Type.Union.FieldAttributes },
278 .@"enum" => struct { name: [:0]const u8, value: comptime_int },
279 .error_set => struct { name: [:0]const u8 },
323280 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
324281} {
282 const idx = @intFromEnum(field);
325283 return switch (@typeInfo(T)) {
326 .@"struct" => |info| info.fields,
327 .@"union" => |info| info.fields,
328 .@"enum" => |info| info.fields,
329 .error_set => |errors| errors.?, // must be non global error set
284 .@"struct" => |info| .{
285 .name = info.field_names[idx],
286 .type = info.field_types[idx],
287 .attrs = info.field_attrs[idx],
288 },
289 .@"union" => |info| .{
290 .name = info.field_names[idx],
291 .type = info.field_types[idx],
292 .attrs = info.field_attrs[idx],
293 },
294 .@"enum" => |info| .{
295 .name = info.field_names[idx],
296 .value = info.field_values[idx],
297 },
298 .error_set => |info| .{ .name = info.error_names.?[idx] },
330299 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
331300 };
332301}
333302
334test fields {
335 const E1 = enum {
336 A,
337 };
338 const E2 = error{A};
339 const S1 = struct {
340 a: u8,
341 };
342 const U1 = union {
343 a: u8,
344 };
345
346 const e1f = comptime fields(E1);
347 const e2f = comptime fields(E2);
348 const sf = comptime fields(S1);
349 const uf = comptime fields(U1);
350
351 try testing.expect(e1f.len == 1);
352 try testing.expect(e2f.len == 1);
353 try testing.expect(sf.len == 1);
354 try testing.expect(uf.len == 1);
355 try testing.expect(mem.eql(u8, e1f[0].name, "A"));
356 try testing.expect(mem.eql(u8, e2f[0].name, "A"));
357 try testing.expect(mem.eql(u8, sf[0].name, "a"));
358 try testing.expect(mem.eql(u8, uf[0].name, "a"));
359 try testing.expect(comptime sf[0].type == u8);
360 try testing.expect(comptime uf[0].type == u8);
361}
362
363pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
364 .@"struct" => Type.StructField,
365 .@"union" => Type.UnionField,
366 .@"enum" => Type.EnumField,
367 .error_set => Type.Error,
368 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
369} {
370 return fields(T)[@intFromEnum(field)];
371}
372
373303test fieldInfo {
374304 const E1 = enum {
375305 A,
......@@ -395,13 +325,13 @@ test fieldInfo {
395325 try testing.expect(comptime uf.type == u8);
396326}
397327
398pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {
399 return comptime blk: {
400 const fieldInfos = fields(T);
401 var names: [fieldInfos.len][:0]const u8 = undefined;
402 for (&names, fieldInfos) |*name, field| name.* = field.name;
403 const final = names;
404 break :blk &final;
328pub fn fieldNames(comptime T: type) []const [:0]const u8 {
329 return switch (@typeInfo(T)) {
330 .@"struct" => |s| s.field_names,
331 .@"union" => |u| u.field_names,
332 .@"enum" => |e| e.field_names,
333 .error_set => |es| es.error_names.?,
334 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
405335 };
406336}
407337
......@@ -433,14 +363,41 @@ test fieldNames {
433363 try testing.expectEqualSlices(u8, u1names[1], "b");
434364}
435365
366pub fn fieldTypes(comptime T: type) []const type {
367 return switch (@typeInfo(T)) {
368 .@"struct" => |s| s.field_types,
369 .@"union" => |u| u.field_types,
370 else => @compileError("Expected struct or union type, found '" ++ @typeName(T) ++ "'"),
371 };
372}
373
374test fieldTypes {
375 const S1 = struct {
376 a: u8,
377 };
378 const U1 = union {
379 a: u8,
380 b: void,
381 };
382
383 const s1types = comptime fieldTypes(S1);
384 const u1types = comptime fieldTypes(U1);
385
386 try testing.expect(s1types.len == 1);
387 try testing.expect(s1types[0] == u8);
388 try testing.expect(u1types.len == 2);
389 try testing.expect(u1types[0] == u8);
390 try testing.expect(u1types[1] == void);
391}
392
436393/// Given an enum or error set type, returns a pointer to an array containing all tags for that
437394/// enum or error set.
438pub fn tags(comptime T: type) *const [fields(T).len]T {
395pub fn tags(comptime T: type) *const [fieldNames(T).len]T {
439396 return comptime blk: {
440 const fieldInfos = fields(T);
441 var res: [fieldInfos.len]T = undefined;
442 for (fieldInfos, 0..) |field, i| {
443 res[i] = @field(T, field.name);
397 const field_names = fieldNames(T);
398 var res: [field_names.len]T = undefined;
399 for (field_names, 0..) |field_name, i| {
400 res[i] = @field(T, field_name);
444401 }
445402 const final = res;
446403 break :blk &final;
......@@ -491,27 +448,30 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
491448 // because the language does not guarantee that the slice pointers for field names
492449 // and decl names will be the same.
493450 comptime {
494 const expected_fields = @typeInfo(expected).@"enum".fields;
495 const actual_fields = @typeInfo(actual).@"enum".fields;
496 if (expected_fields.len != actual_fields.len) return error.FailedTest;
497 for (expected_fields, 0..) |expected_field, i| {
498 const actual_field = actual_fields[i];
499 try testing.expectEqual(expected_field.value, actual_field.value);
500 try testing.expectEqualStrings(expected_field.name, actual_field.name);
451 const expected_field_names = @typeInfo(expected).@"enum".field_names;
452 const expected_field_values = @typeInfo(expected).@"enum".field_values;
453 const actual_field_names = @typeInfo(actual).@"enum".field_names;
454 const actual_field_values = @typeInfo(actual).@"enum".field_values;
455 if (expected_field_names.len != actual_field_names.len) return error.FailedTest;
456 for (expected_field_names, expected_field_values, 0..) |expected_field_name, expected_field_value, i| {
457 const actual_field_name = actual_field_names[i];
458 const actual_field_value = actual_field_values[i];
459 try testing.expectEqual(expected_field_value, actual_field_value);
460 try testing.expectEqualStrings(expected_field_name, actual_field_name);
501461 }
502462 }
503463 comptime {
504 const expected_decls = @typeInfo(expected).@"enum".decls;
505 const actual_decls = @typeInfo(actual).@"enum".decls;
506 if (expected_decls.len != actual_decls.len) return error.FailedTest;
507 for (expected_decls, 0..) |expected_decl, i| {
508 const actual_decl = actual_decls[i];
509 try testing.expectEqualStrings(expected_decl.name, actual_decl.name);
464 const expected_decl_names = @typeInfo(expected).@"enum".decl_names;
465 const actual_decl_names = @typeInfo(actual).@"enum".decl_names;
466 if (expected_decl_names.len != actual_decl_names.len) return error.FailedTest;
467 for (expected_decl_names, 0..) |expected_decl_name, i| {
468 const actual_decl_name = actual_decl_names[i];
469 try testing.expectEqualStrings(expected_decl_name, actual_decl_name);
510470 }
511471 }
512472 try testing.expectEqual(
513 @typeInfo(expected).@"enum".is_exhaustive,
514 @typeInfo(actual).@"enum".is_exhaustive,
473 @typeInfo(expected).@"enum".mode,
474 @typeInfo(actual).@"enum".mode,
515475 );
516476}
517477
......@@ -534,11 +494,9 @@ test FieldEnum {
534494}
535495
536496pub fn DeclEnum(comptime T: type) type {
537 const decls = declarations(T);
538 var names: [decls.len][]const u8 = undefined;
539 for (&names, decls) |*name, decl| name.* = decl.name;
540 const IntTag = std.math.IntFittingRange(0, decls.len -| 1);
541 return @Enum(IntTag, .exhaustive, &names, &std.simd.iota(IntTag, decls.len));
497 const decl_names = declarations(T);
498 const IntTag = std.math.IntFittingRange(0, decl_names.len -| 1);
499 return @Enum(IntTag, .exhaustive, decl_names, &std.simd.iota(IntTag, decl_names.len));
542500}
543501
544502test DeclEnum {
......@@ -622,8 +580,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
622580 .@"struct" => |info| {
623581 if (info.layout == .@"packed") return a == b;
624582
625 inline for (info.fields) |field_info| {
626 if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false;
583 inline for (info.field_names) |field_name| {
584 if (!eql(@field(a, field_name), @field(b, field_name))) return false;
627585 }
628586 return true;
629587 },
......@@ -744,8 +702,8 @@ test eql {
744702/// Given a type and a name, return the field index according to source order.
745703/// Returns `null` if the field is not found.
746704pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int {
747 inline for (fields(T), 0..) |field, i| {
748 if (mem.eql(u8, field.name, name))
705 inline for (fieldNames(T), 0..) |field_name, i| {
706 if (mem.eql(u8, field_name, name))
749707 return i;
750708 }
751709 return null;
......@@ -782,12 +740,12 @@ pub fn ArgsTuple(comptime Function: type) type {
782740 @compileError("ArgsTuple expects a function type");
783741
784742 const function_info = info.@"fn";
785 if (function_info.is_var_args)
743 if (function_info.attrs.varargs)
786744 @compileError("Cannot create ArgsTuple for variadic function");
787745
788 var argument_field_list: [function_info.params.len]type = undefined;
789 inline for (function_info.params, 0..) |arg, i| {
790 const T = arg.type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");
746 var argument_field_list: [function_info.param_types.len]type = undefined;
747 inline for (function_info.param_types, 0..) |arg_type, i| {
748 const T = arg_type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");
791749 argument_field_list[i] = T;
792750 }
793751
......@@ -807,13 +765,15 @@ const TupleTester = struct {
807765 if (!info.@"struct".is_tuple)
808766 @compileError("Struct type must be a tuple type");
809767
810 const fields_list = std.meta.fields(Actual);
811 if (expected.len != fields_list.len)
812 @compileError("Argument count mismatch");
768 const field_names = info.@"struct".field_names;
769 if (expected.len != field_names.len) {
770 const msg = std.fmt.comptimePrint("Argument count mismatch: expected {d}, got {d}", .{ expected.len, field_names.len });
771 @compileError(msg);
772 }
813773
814 inline for (fields_list, 0..) |fld, i| {
815 if (expected[i] != fld.type) {
816 @compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.type));
774 inline for (field_names, info.@"struct".field_types, 0..) |fld_name, fld_type, i| {
775 if (expected[i] != fld_type) {
776 @compileError("Field " ++ fld_name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld_type));
817777 }
818778 }
819779 }
......@@ -943,7 +903,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
943903 .pointer => |info| info.size != .slice,
944904
945905 .optional => |info| switch (@typeInfo(info.child)) {
946 .pointer => |ptr| !ptr.is_allowzero and switch (ptr.size) {
906 .pointer => |ptr| !ptr.attrs.@"allowzero" and switch (ptr.size) {
947907 .slice, .c => false,
948908 .one, .many => true,
949909 },
......@@ -957,10 +917,10 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
957917
958918 var sum_size = @as(usize, 0);
959919
960 inline for (info.fields) |field| {
961 if (field.is_comptime) continue;
962 if (!hasUniqueRepresentation(field.type)) return false;
963 sum_size += @sizeOf(field.type);
920 inline for (info.field_attrs, info.field_types) |field_attr, field_type| {
921 if (field_attr.@"comptime") continue;
922 if (!hasUniqueRepresentation(field_type)) return false;
923 sum_size += @sizeOf(field_type);
964924 }
965925
966926 return @sizeOf(T) == sum_size;
lib/std/meta/trailer_flags.zig+26-19
......@@ -14,7 +14,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
1414 bits: Int,
1515
1616 pub const Int = @Int(.unsigned, bit_count);
17 pub const bit_count = @typeInfo(Fields).@"struct".fields.len;
17 pub const bit_count = @typeInfo(Fields).@"struct".field_names.len;
1818
1919 pub const FieldEnum = std.meta.FieldEnum(Fields);
2020
......@@ -22,11 +22,18 @@ pub fn TrailerFlags(comptime Fields: type) type {
2222 pub const FieldValues = blk: {
2323 var field_names: [bit_count][]const u8 = undefined;
2424 var field_types: [bit_count]type = undefined;
25 var field_attrs: [bit_count]std.builtin.Type.StructField.Attributes = undefined;
26 for (@typeInfo(Fields).@"struct".fields, &field_names, &field_types, &field_attrs) |field, *new_name, *NewType, *new_attrs| {
27 new_name.* = field.name;
28 NewType.* = ?field.type;
29 const default: ?field.type = null;
25 var field_attrs: [bit_count]std.builtin.Type.Struct.FieldAttributes = undefined;
26 const fields_info = @typeInfo(Fields).@"struct";
27 for (
28 fields_info.field_names,
29 fields_info.field_types,
30 &field_names,
31 &field_types,
32 &field_attrs,
33 ) |field_name, field_type, *new_name, *NewType, *new_attrs| {
34 new_name.* = field_name;
35 NewType.* = ?field_type;
36 const default: ?field_type = null;
3037 new_attrs.* = .{ .default_value_ptr = &default };
3138 }
3239 break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
......@@ -53,8 +60,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
5360 /// `fields` is a boolean struct where each active field is set to `true`
5461 pub fn init(fields: ActiveFields) Self {
5562 var self: Self = .{ .bits = 0 };
56 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {
57 if (@field(fields, field.name))
63 inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
64 if (@field(fields, field_name))
5865 self.bits |= 1 << i;
5966 }
6067 return self;
......@@ -62,8 +69,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
6269
6370 /// `fields` is a struct with each field set to an optional value
6471 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {
65 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {
66 if (@field(fields, field.name)) |value|
72 inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
73 if (@field(fields, field_name)) |value|
6774 self.set(p, @as(FieldEnum, @enumFromInt(i)), value);
6875 }
6976 }
......@@ -93,30 +100,30 @@ pub fn TrailerFlags(comptime Fields: type) type {
93100
94101 pub fn offset(self: Self, comptime field: FieldEnum) usize {
95102 var off: usize = 0;
96 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field_info, i| {
103 inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
97104 const active = (self.bits & (1 << i)) != 0;
98105 if (i == @intFromEnum(field)) {
99106 assert(active);
100 return mem.alignForward(usize, off, @alignOf(field_info.type));
107 return mem.alignForward(usize, off, @alignOf(field_type));
101108 } else if (active) {
102 off = mem.alignForward(usize, off, @alignOf(field_info.type));
103 off += @sizeOf(field_info.type);
109 off = mem.alignForward(usize, off, @alignOf(field_type));
110 off += @sizeOf(field_type);
104111 }
105112 }
106113 }
107114
108115 pub fn Field(comptime field: FieldEnum) type {
109 return @typeInfo(Fields).@"struct".fields[@intFromEnum(field)].type;
116 return @typeInfo(Fields).@"struct".field_types[@intFromEnum(field)];
110117 }
111118
112119 pub fn sizeInBytes(self: Self) usize {
113120 var off: usize = 0;
114 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {
115 if (@sizeOf(field.type) == 0)
121 inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
122 if (@sizeOf(field_type) == 0)
116123 continue;
117124 if ((self.bits & (1 << i)) != 0) {
118 off = mem.alignForward(usize, off, @alignOf(field.type));
119 off += @sizeOf(field.type);
125 off = mem.alignForward(usize, off, @alignOf(field_type));
126 off += @sizeOf(field_type);
120127 }
121128 }
122129 return off;
lib/std/multi_array_list.zig+49-57
......@@ -44,17 +44,7 @@ pub fn MultiArrayList(comptime T: type) type {
4444 const Elem = switch (@typeInfo(T)) {
4545 .@"struct" => T,
4646 .@"union" => |u| struct {
47 pub const Bare = Bare: {
48 var field_names: [u.fields.len][]const u8 = undefined;
49 var field_types: [u.fields.len]type = undefined;
50 var field_attrs: [u.fields.len]std.builtin.Type.UnionField.Attributes = undefined;
51 for (u.fields, &field_names, &field_types, &field_attrs) |field, *name, *Type, *attrs| {
52 name.* = field.name;
53 Type.* = field.type;
54 attrs.* = .{ .@"align" = field.alignment };
55 }
56 break :Bare @Union(u.layout, null, &field_names, &field_types, &field_attrs);
57 };
47 pub const Bare = @Union(u.layout, null, u.field_names, u.field_types[0..], u.field_attrs[0..]);
5848 pub const Tag =
5949 u.tag_type orelse @compileError("MultiArrayList does not support untagged unions");
6050 tags: Tag,
......@@ -87,7 +77,7 @@ pub fn MultiArrayList(comptime T: type) type {
8777 pub const Slice = struct {
8878 /// This array is indexed by the field index which can be obtained
8979 /// by using @intFromEnum() on the Field enum
90 ptrs: [fields.len][*]u8,
80 ptrs: [field_names.len][*]u8,
9181 len: usize,
9282 capacity: usize,
9383
......@@ -116,15 +106,15 @@ pub fn MultiArrayList(comptime T: type) type {
116106 .@"union" => Elem.fromT(elem),
117107 else => unreachable,
118108 };
119 inline for (fields, 0..) |field_info, i| {
120 self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_info.name);
109 inline for (field_names, 0..) |field_name, i| {
110 self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_name);
121111 }
122112 }
123113
124114 pub fn get(self: Slice, index: usize) T {
125115 var result: Elem = undefined;
126 inline for (fields, 0..) |field_info, i| {
127 @field(result, field_info.name) = self.items(@as(Field, @enumFromInt(i)))[index];
116 inline for (field_names, 0..) |field_name, i| {
117 @field(result, field_name) = self.items(@as(Field, @enumFromInt(i)))[index];
128118 }
129119 return switch (@typeInfo(T)) {
130120 .@"struct" => result,
......@@ -134,9 +124,9 @@ pub fn MultiArrayList(comptime T: type) type {
134124 }
135125
136126 pub fn swap(self: Slice, a: usize, b: usize) void {
137 inline for (@typeInfo(Field).@"enum".fields) |field| {
138 const its = self.items(@field(Field, field.name));
139 std.mem.swap(@FieldType(T, field.name), &its[a], &its[b]);
127 inline for (@typeInfo(Field).@"enum".field_names) |field_name| {
128 const its = self.items(@field(Field, field_name));
129 std.mem.swap(@FieldType(T, field_name), &its[a], &its[b]);
140130 }
141131 }
142132
......@@ -162,9 +152,9 @@ pub fn MultiArrayList(comptime T: type) type {
162152 /// Asserts that `off + len <= s.len`.
163153 pub fn subslice(s: Slice, off: usize, len: usize) Slice {
164154 assert(off + len <= s.len);
165 var ptrs: [fields.len][*]u8 = undefined;
166 inline for (s.ptrs, &ptrs, fields) |in, *out, field| {
167 out.* = in + (off * @sizeOf(field.type));
155 var ptrs: [field_names.len][*]u8 = undefined;
156 inline for (s.ptrs, &ptrs, field_types) |in, *out, field_type| {
157 out.* = in + (off * @sizeOf(field_type));
168158 }
169159 return .{
170160 .ptrs = ptrs,
......@@ -185,7 +175,9 @@ pub fn MultiArrayList(comptime T: type) type {
185175
186176 const Self = @This();
187177
188 const fields = meta.fields(Elem);
178 const field_names = @typeInfo(Elem).@"struct".field_names;
179 const field_types = @typeInfo(Elem).@"struct".field_types;
180 const field_attrs = @typeInfo(Elem).@"struct".field_attrs;
189181 /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.
190182 /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index.
191183 /// `sizes.big_align` is the overall alignment of the allocation, which equals the maximum field alignment.
......@@ -195,13 +187,13 @@ pub fn MultiArrayList(comptime T: type) type {
195187 size_index: usize,
196188 alignment: usize,
197189 };
198 var data: [fields.len]Data = undefined;
190 var data: [field_names.len]Data = undefined;
199191 var big_align: usize = 1;
200 for (fields, 0..) |field_info, i| {
192 for (field_types, field_attrs, 0..) |f_type, f_attrs, i| {
201193 data[i] = .{
202 .size = @sizeOf(field_info.type),
194 .size = @sizeOf(f_type),
203195 .size_index = i,
204 .alignment = field_info.alignment orelse @alignOf(field_info.type),
196 .alignment = f_attrs.@"align" orelse @alignOf(f_type),
205197 };
206198 big_align = @max(big_align, data[i].alignment);
207199 }
......@@ -211,10 +203,10 @@ pub fn MultiArrayList(comptime T: type) type {
211203 return lhs.alignment > rhs.alignment;
212204 }
213205 };
214 @setEvalBranchQuota(3 * fields.len * std.math.log2(fields.len));
206 @setEvalBranchQuota(3 * field_names.len * std.math.log2(field_names.len));
215207 mem.sort(Data, &data, {}, Sort.lessThan);
216 var sizes_bytes: [fields.len]usize = undefined;
217 var field_indexes: [fields.len]usize = undefined;
208 var sizes_bytes: [field_names.len]usize = undefined;
209 var field_indexes: [field_names.len]usize = undefined;
218210 for (data, 0..) |elem, i| {
219211 sizes_bytes[i] = elem.size;
220212 field_indexes[i] = elem.size_index;
......@@ -368,13 +360,13 @@ pub fn MultiArrayList(comptime T: type) type {
368360 else => unreachable,
369361 };
370362 const slices = self.slice();
371 inline for (fields, 0..) |field_info, field_index| {
363 inline for (field_names, 0..) |field_name, field_index| {
372364 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
373365 var i: usize = self.len - 1;
374366 while (i > index) : (i -= 1) {
375367 field_slice[i] = field_slice[i - 1];
376368 }
377 field_slice[index] = @field(entry, field_info.name);
369 field_slice[index] = @field(entry, field_name);
378370 }
379371 }
380372
......@@ -394,7 +386,7 @@ pub fn MultiArrayList(comptime T: type) type {
394386 /// retain list ordering.
395387 pub fn swapRemove(self: *Self, index: usize) void {
396388 const slices = self.slice();
397 inline for (fields, 0..) |_, i| {
389 inline for (field_names, 0..) |_, i| {
398390 const field_slice = slices.items(@as(Field, @enumFromInt(i)));
399391 field_slice[index] = field_slice[self.len - 1];
400392 field_slice[self.len - 1] = undefined;
......@@ -406,7 +398,7 @@ pub fn MultiArrayList(comptime T: type) type {
406398 /// after it to preserve order.
407399 pub fn orderedRemove(self: *Self, index: usize) void {
408400 const slices = self.slice();
409 inline for (fields, 0..) |_, field_index| {
401 inline for (field_names, 0..) |_, field_index| {
410402 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
411403 var i = index;
412404 while (i < self.len - 1) : (i += 1) {
......@@ -437,7 +429,7 @@ pub fn MultiArrayList(comptime T: type) type {
437429 if (removed == end) continue; // allows duplicates in `sorted_indexes`
438430 const start = removed + 1;
439431 const len = end - start; // safety checks `sorted_indexes` are sorted
440 inline for (fields, 0..) |_, field_index| {
432 inline for (field_names, 0..) |_, field_index| {
441433 const field_slice = slices.items(@enumFromInt(field_index));
442434 @memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]); // safety checks initial `sorted_indexes` are in range
443435 }
......@@ -446,7 +438,7 @@ pub fn MultiArrayList(comptime T: type) type {
446438 const start = sorted_indexes[sorted_indexes.len - 1] + 1;
447439 const end = self.len;
448440 const len = end - start; // safety checks final `sorted_indexes` are in range
449 inline for (fields, 0..) |_, field_index| {
441 inline for (field_names, 0..) |_, field_index| {
450442 const field_slice = slices.items(@enumFromInt(field_index));
451443 @memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]);
452444 }
......@@ -471,8 +463,8 @@ pub fn MultiArrayList(comptime T: type) type {
471463
472464 const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch {
473465 const self_slice = self.slice();
474 inline for (fields, 0..) |field_info, i| {
475 if (@sizeOf(field_info.type) != 0) {
466 inline for (field_types, 0..) |field_type, i| {
467 if (@sizeOf(field_type) != 0) {
476468 const field = @as(Field, @enumFromInt(i));
477469 const dest_slice = self_slice.items(field)[new_len..];
478470 // We use memset here for more efficient codegen in safety-checked,
......@@ -492,8 +484,8 @@ pub fn MultiArrayList(comptime T: type) type {
492484 self.len = new_len;
493485 const self_slice = self.slice();
494486 const other_slice = other.slice();
495 inline for (fields, 0..) |field_info, i| {
496 if (@sizeOf(field_info.type) != 0) {
487 inline for (field_types, 0..) |field_type, i| {
488 if (@sizeOf(field_type) != 0) {
497489 const field = @as(Field, @enumFromInt(i));
498490 @memcpy(other_slice.items(field), self_slice.items(field));
499491 }
......@@ -529,7 +521,7 @@ pub fn MultiArrayList(comptime T: type) type {
529521
530522 const init_capacity: comptime_int = init: {
531523 var max: comptime_int = 1;
532 for (fields) |field| max = @max(max, @sizeOf(field.type));
524 for (field_types) |field_type| max = @max(max, @sizeOf(field_type));
533525 break :init @max(1, std.atomic.cache_line / max);
534526 };
535527
......@@ -564,8 +556,8 @@ pub fn MultiArrayList(comptime T: type) type {
564556 };
565557 const self_slice = self.slice();
566558 const other_slice = other.slice();
567 inline for (fields, 0..) |field_info, i| {
568 if (@sizeOf(field_info.type) != 0) {
559 inline for (field_types, 0..) |field_type, i| {
560 if (@sizeOf(field_type) != 0) {
569561 const field = @as(Field, @enumFromInt(i));
570562 @memcpy(other_slice.items(field), self_slice.items(field));
571563 }
......@@ -583,8 +575,8 @@ pub fn MultiArrayList(comptime T: type) type {
583575 result.len = self.len;
584576 const self_slice = self.slice();
585577 const result_slice = result.slice();
586 inline for (fields, 0..) |field_info, i| {
587 if (@sizeOf(field_info.type) != 0) {
578 inline for (field_types, 0..) |field_type, i| {
579 if (@sizeOf(field_type) != 0) {
588580 const field = @as(Field, @enumFromInt(i));
589581 @memcpy(result_slice.items(field), self_slice.items(field));
590582 }
......@@ -600,11 +592,11 @@ pub fn MultiArrayList(comptime T: type) type {
600592 slice: Slice,
601593
602594 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
603 inline for (fields, 0..) |field_info, i| {
604 if (@sizeOf(field_info.type) != 0) {
595 inline for (field_types, 0..) |field_type, i| {
596 if (@sizeOf(field_type) != 0) {
605597 const field: Field = @enumFromInt(i);
606598 const ptr = sc.slice.items(field);
607 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
599 mem.swap(field_type, &ptr[a_index], &ptr[b_index]);
608600 }
609601 }
610602 }
......@@ -676,18 +668,18 @@ pub fn MultiArrayList(comptime T: type) type {
676668 }
677669
678670 const Entry = entry: {
679 var field_names: [fields.len][]const u8 = undefined;
680 var field_types: [fields.len]type = undefined;
681 var field_attrs: [fields.len]std.builtin.Type.StructField.Attributes = undefined;
682 for (sizes.fields, &field_names, &field_types, &field_attrs) |i, *name, *Type, *attrs| {
683 name.* = fields[i].name ++ "_ptr";
684 Type.* = *fields[i].type;
671 var entry_field_names: [field_names.len][]const u8 = undefined;
672 var entry_field_types: [field_names.len]type = undefined;
673 var entry_field_attrs: [field_names.len]std.builtin.Type.Struct.FieldAttributes = undefined;
674 for (sizes.fields, &entry_field_names, &entry_field_types, &entry_field_attrs) |i, *name, *Type, *attrs| {
675 name.* = field_names[i] ++ "_ptr";
676 Type.* = *field_types[i];
685677 attrs.* = .{
686 .@"comptime" = fields[i].is_comptime,
687 .@"align" = fields[i].alignment,
678 .@"comptime" = field_attrs[i].@"comptime",
679 .@"align" = field_attrs[i].@"align",
688680 };
689681 }
690 break :entry @Struct(.@"extern", null, &field_names, &field_types, &field_attrs);
682 break :entry @Struct(.@"extern", null, &entry_field_names, &entry_field_types, &entry_field_attrs);
691683 };
692684 /// This function is used in the debugger pretty formatters in tools/ to fetch the
693685 /// child field order and entry type to facilitate fancy debug printing for this type.
lib/std/os/uefi/protocol/device_path.zig+8-7
......@@ -82,16 +82,17 @@ pub const DevicePath = extern struct {
8282 }
8383
8484 pub fn getDevicePath(self: *const DevicePath) ?uefi.DevicePath {
85 inline for (@typeInfo(uefi.DevicePath).@"union".fields) |ufield| {
86 const enum_value = std.meta.stringToEnum(uefi.DevicePath.Type, ufield.name);
85 const u_info = @typeInfo(uefi.DevicePath).@"union";
86 inline for (u_info.field_names, u_info.field_types) |ufield_name, ufield_type| {
87 const enum_value = std.meta.stringToEnum(uefi.DevicePath.Type, ufield_name);
8788
8889 // Got the associated union type for self.type, now
8990 // we need to initialize it and its subtype
9091 if (self.type == enum_value) {
91 const subtype = self.initSubtype(ufield.type);
92 const subtype = self.initSubtype(ufield_type);
9293 if (subtype) |sb| {
9394 // e.g. return .{ .hardware = .{ .pci = @ptrCast(...) } }
94 return @unionInit(uefi.DevicePath, ufield.name, sb);
95 return @unionInit(uefi.DevicePath, ufield_name, sb);
9596 }
9697 }
9798 }
......@@ -103,13 +104,13 @@ pub const DevicePath = extern struct {
103104 const type_info = @typeInfo(TUnion).@"union";
104105 const TTag = type_info.tag_type.?;
105106
106 inline for (type_info.fields) |subtype| {
107 inline for (type_info.field_names, type_info.field_types) |subtype_name, subtype_type| {
107108 // The tag names match the union names, so just grab that off the enum
108 const tag_val: u8 = @intFromEnum(@field(TTag, subtype.name));
109 const tag_val: u8 = @intFromEnum(@field(TTag, subtype_name));
109110
110111 if (self.subtype == tag_val) {
111112 // e.g. expr = .{ .pci = @ptrCast(...) }
112 return @unionInit(TUnion, subtype.name, @as(subtype.type, @ptrCast(self)));
113 return @unionInit(TUnion, subtype_name, @as(subtype_type, @ptrCast(self)));
113114 }
114115 }
115116
lib/std/os/uefi/tables/boot_services.zig+1-1
......@@ -1271,7 +1271,7 @@ fn ProtocolInterfaces(HandleType: type, Interfaces: type) type {
12711271 @compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces));
12721272 const interfaces_info = interfaces_type_info.@"struct";
12731273
1274 var tuple_types: [interfaces_info.fields.len * 2 + 2]type = undefined;
1274 var tuple_types: [interfaces_info.field_names.len * 2 + 2]type = undefined;
12751275 tuple_types[0] = HandleType;
12761276 tuple_types[tuple_types.len - 1] = ?*const Guid;
12771277
lib/std/os/windows.zig+9-15
......@@ -144,7 +144,7 @@ pub const OBJECT = struct {
144144 Session = 5,
145145 _,
146146
147 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".fields.len;
147 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
148148 };
149149
150150 pub const NAME_INFORMATION = extern struct {
......@@ -575,7 +575,7 @@ pub const FILE = struct {
575575 MupProvider = 83,
576576 _,
577577
578 pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".fields.len;
578 pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".field_names.len;
579579 };
580580
581581 pub const BASIC_INFORMATION = extern struct {
......@@ -881,7 +881,7 @@ pub const DIRECTORY = struct {
881881 NotifyFull = 3,
882882 _,
883883
884 pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".fields.len;
884 pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".field_names.len;
885885 };
886886};
887887
......@@ -930,14 +930,8 @@ pub const CONSOLE = struct {
930930
931931 pub const Tag = @typeInfo(WITH).@"union".tag_type.?;
932932 pub const Payload = PAYLOAD: {
933 const with_fields = @typeInfo(WITH).@"union".fields;
934 var field_names: [with_fields.len][]const u8 = undefined;
935 var field_types: [with_fields.len]type = undefined;
936 for (with_fields, &field_names, &field_types) |field, *field_name, *field_type| {
937 field_name.* = field.name;
938 field_type.* = field.type;
939 }
940 break :PAYLOAD @Union(.@"extern", null, &field_names, &field_types, &@splat(.{}));
933 const with_info = @typeInfo(WITH).@"union";
934 break :PAYLOAD @Union(.@"extern", null, with_info.field_names, with_info.field_types[0..], &@splat(.{}));
941935 };
942936 };
943937 };
......@@ -2122,7 +2116,7 @@ pub const HEAP = opaque {
21222116 Custom,
21232117 _,
21242118
2125 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".fields.len;
2119 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
21262120 };
21272121
21282122 pub const VA_CALLBACKS = extern struct {
......@@ -3369,7 +3363,7 @@ pub const FS_INFORMATION_CLASS = enum(c_int) {
33693363 Guid = 15,
33703364 _,
33713365
3372 pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".fields.len;
3366 pub const Maximum: @typeInfo(@This()).@"enum".tag_type = 1 + @typeInfo(@This()).@"enum".field_names.len;
33733367};
33743368
33753369pub const SECTION_INHERIT = enum(c_int) {
......@@ -3493,7 +3487,7 @@ pub const MEM = struct {
34933487 ImageMachine,
34943488 _,
34953489
3496 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".fields.len;
3490 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
34973491 };
34983492 };
34993493};
......@@ -4467,7 +4461,7 @@ pub const KEY = struct {
44674461 Layer = 5,
44684462 _,
44694463
4470 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".fields.len;
4464 pub const Max: @typeInfo(@This()).@"enum".tag_type = @typeInfo(@This()).@"enum".field_names.len;
44714465 };
44724466
44734467 pub const PARTIAL_INFORMATION = extern struct {
lib/std/posix/test.zig+2-2
......@@ -332,8 +332,8 @@ test "fsync" {
332332test "getrlimit and setrlimit" {
333333 if (posix.system.rlimit_resource == void) return error.SkipZigTest;
334334
335 inline for (@typeInfo(posix.rlimit_resource).@"enum".fields) |field| {
336 const resource: posix.rlimit_resource = @enumFromInt(field.value);
335 inline for (@typeInfo(posix.rlimit_resource).@"enum".field_values) |field_value| {
336 const resource: posix.rlimit_resource = @enumFromInt(field_value);
337337 const limit = try posix.getrlimit(resource);
338338
339339 // XNU kernel does not support RLIMIT_STACK if a custom stack is active,
lib/std/start.zig+6-6
......@@ -24,7 +24,7 @@ comptime {
2424 if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
2525 @export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
2626 } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "DllMain")) {
27 if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".calling_convention.eql(.winapi)) {
27 if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".attrs.@"callconv".eql(.winapi)) {
2828 @export(&DllMain, .{ .name = "DllMain" });
2929 }
3030 }
......@@ -32,11 +32,11 @@ comptime {
3232 if (builtin.link_libc and @hasDecl(root, "main")) {
3333 if (is_wasm) {
3434 @export(&mainWithoutEnv, .{ .name = "__main_argc_argv" });
35 } else if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) {
35 } else if (!@typeInfo(@TypeOf(root.main)).@"fn".attrs.@"callconv".eql(.c)) {
3636 @export(&main, .{ .name = "main" });
3737 }
3838 } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "wWinMain")) {
39 if (!@typeInfo(@TypeOf(root.wWinMain)).@"fn".calling_convention.eql(.c)) {
39 if (!@typeInfo(@TypeOf(root.wWinMain)).@"fn".attrs.@"callconv".eql(.c)) {
4040 @export(&wWinMain, .{ .name = "wWinMain" });
4141 }
4242 } else if (native_os == .windows) {
......@@ -728,8 +728,8 @@ var safe_allocator: std.heap.SafeAllocator = .init(std.heap.page_allocator, .{})
728728
729729inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.Block) u8 {
730730 const fn_info = @typeInfo(@TypeOf(root.main)).@"fn";
731 if (fn_info.params.len == 0) return wrapMain(root.main());
732 if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{
731 if (fn_info.param_types.len == 0) return wrapMain(root.main());
732 if (fn_info.param_types[0].? == std.process.Init.Minimal) return wrapMain(root.main(.{
733733 .args = .{ .vector = args },
734734 .environ = .{ .block = environ },
735735 }));
......@@ -809,7 +809,7 @@ inline fn wrapMain(result: anytype) u8 {
809809
810810fn call_wWinMain() std.os.windows.INT {
811811 const peb = std.os.windows.peb();
812 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).@"fn".params[0].type.?;
812 const MAIN_HINSTANCE = @typeInfo(@TypeOf(root.wWinMain)).@"fn".param_types[0].?;
813813 const hInstance: MAIN_HINSTANCE = @ptrCast(peb.ImageBaseAddress);
814814 const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer);
815815
lib/std/testing.zig+15-15
......@@ -141,16 +141,16 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
141141 },
142142
143143 .@"struct" => |structType| {
144 inline for (structType.fields) |field| {
145 try expectEqual(@field(expected, field.name), @field(actual, field.name));
144 inline for (structType.field_names) |field_name| {
145 try expectEqual(@field(expected, field_name), @field(actual, field_name));
146146 }
147147 },
148148
149149 .@"union" => |union_info| {
150150 if (union_info.tag_type == null) {
151 const first_size = @bitSizeOf(union_info.fields[0].type);
152 inline for (union_info.fields) |field| {
153 if (@bitSizeOf(field.type) != first_size) {
151 const first_size = @bitSizeOf(union_info.field_types[0]);
152 inline for (union_info.field_types) |field_type| {
153 if (@bitSizeOf(field_type) != first_size) {
154154 @compileError("Unable to compare untagged unions with varying field sizes for type " ++ @typeName(@TypeOf(actual)));
155155 }
156156 }
......@@ -840,9 +840,9 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
840840 },
841841
842842 .@"struct" => |structType| {
843 inline for (structType.fields) |field| {
844 expectEqualDeep(@field(expected, field.name), @field(actual, field.name)) catch |e| {
845 print("Field {s} incorrect. expected {any}, found {any}\n", .{ field.name, @field(expected, field.name), @field(actual, field.name) });
843 inline for (structType.field_names) |field_name| {
844 expectEqualDeep(@field(expected, field_name), @field(actual, field_name)) catch |e| {
845 print("Field {s} incorrect. expected {any}, found {any}\n", .{ field_name, @field(expected, field_name), @field(actual, field_name) });
846846 return e;
847847 };
848848 }
......@@ -1165,14 +1165,14 @@ fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type {
11651165
11661166 const ArgsTuple = std.meta.ArgsTuple(TestFn);
11671167
1168 const fields = @typeInfo(ArgsTuple).@"struct".fields;
1169 if (fields.len == 0 or fields[0].type != std.mem.Allocator) {
1168 const field_types = @typeInfo(ArgsTuple).@"struct".field_types;
1169 if (field_types.len == 0 or field_types[0] != std.mem.Allocator) {
11701170 @compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument");
11711171 }
11721172
1173 var extra_args: [fields.len - 1]type = undefined;
1174 for (&extra_args, fields[1..]) |*arg, field| {
1175 arg.* = field.type;
1173 var extra_args: [field_types.len - 1]type = undefined;
1174 for (&extra_args, field_types[1..]) |*arg, field_type| {
1175 arg.* = field_type;
11761176 }
11771177
11781178 return @Tuple(&extra_args);
......@@ -1204,8 +1204,8 @@ test "checkAllAllocationFailures provide result type to 'extra_args' argument" {
12041204/// Given a type, references all the declarations inside, so that the semantic analyzer sees them.
12051205pub fn refAllDecls(comptime T: type) void {
12061206 if (!builtin.is_test) return;
1207 inline for (comptime std.meta.declarations(T)) |decl| {
1208 _ = &@field(T, decl.name);
1207 inline for (comptime std.meta.declarations(T)) |decl_name| {
1208 _ = &@field(T, decl_name);
12091209 }
12101210}
12111211
lib/std/testing/Smith.zig+35-21
......@@ -35,7 +35,12 @@ fn fromExcessK(T: type, x: Backing(T)) T {
3535 return @as(T, @bitCast(x)) +% std.math.minInt(T);
3636}
3737
38fn enumFieldLessThan(_: void, a: std.builtin.Type.EnumField, b: std.builtin.Type.EnumField) bool {
38const EnumField = struct {
39 name: [:0]const u8,
40 value: comptime_int,
41};
42
43fn enumFieldLessThan(_: void, a: EnumField, b: EnumField) bool {
3944 return a.value < b.value;
4045}
4146
......@@ -67,17 +72,26 @@ pub inline fn baselineWeights(T: type) []const Weight {
6772 baselineWeights(Backing(T))
6873 else
6974 @compileError("non-packed unions cannot be weighted"),
70 .@"enum" => |e| if (!e.is_exhaustive)
75 .@"enum" => |e| if (e.mode == .nonexhaustive)
7176 baselineWeights(e.tag_type)
72 else if (e.fields.len == 0)
77 else if (e.field_names.len == 0)
7378 // Cannot be included in below branch due to `log2_int_ceil`
7479 @compileError("exhaustive zero-field enums cannot be weighted")
7580 else e: {
76 @setEvalBranchQuota(@intCast(4 * e.fields.len *
77 std.math.log2_int_ceil(usize, e.fields.len)));
78
79 var sorted_fields = e.fields[0..e.fields.len].*;
80 std.mem.sortUnstable(std.builtin.Type.EnumField, &sorted_fields, {}, enumFieldLessThan);
81 @setEvalBranchQuota(@intCast(4 * e.field_names.len *
82 std.math.log2_int_ceil(usize, e.field_names.len)));
83
84 var sorted_fields = blk: {
85 var fields: [e.field_names.len]EnumField = undefined;
86 for (e.field_names, e.field_values, &fields) |f_name, f_value, *field| {
87 field.* = .{
88 .name = f_name,
89 .value = f_value,
90 };
91 }
92 break :blk fields;
93 };
94 std.mem.sortUnstable(EnumField, &sorted_fields, {}, enumFieldLessThan);
8195
8296 var weights: []const Weight = &.{};
8397 var seq_first: u64 = sorted_fields[0].value;
......@@ -316,10 +330,10 @@ fn weightsContain(int: u64, weights: []const Weight) bool {
316330inline fn allBitPatternsValid(T: type) bool {
317331 return comptime switch (@typeInfo(T)) {
318332 .void, .bool, .int, .float => true,
319 inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.fields) |f| {
320 if (!allBitPatternsValid(f.type)) break false;
333 inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.field_types) |f_type| {
334 if (!allBitPatternsValid(f_type)) break false;
321335 } else true,
322 .@"enum" => |e| !e.is_exhaustive,
336 .@"enum" => |e| e.mode == .nonexhaustive,
323337 else => unreachable,
324338 };
325339}
......@@ -346,16 +360,16 @@ fn UnionTagWithoutUninitializable(T: type) type {
346360 const u = @typeInfo(T).@"union";
347361 const Tag = u.tag_type orelse @compileError("union must have tag");
348362 const e = @typeInfo(Tag).@"enum";
349 var field_names: [e.fields.len][]const u8 = undefined;
350 var field_values: [e.fields.len]e.tag_type = undefined;
363 var field_names: [e.field_names.len][]const u8 = undefined;
364 var field_values: [e.field_names.len]e.tag_type = undefined;
351365 var n_fields = 0;
352 for (u.fields) |f| {
353 switch (f.type) {
366 for (u.field_names, u.field_types) |f_name, f_type| {
367 switch (f_type) {
354368 noreturn => continue,
355369 else => {},
356370 }
357 field_names[n_fields] = f.name;
358 field_values[n_fields] = @intFromEnum(@field(Tag, f.name));
371 field_names[n_fields] = f_name;
372 field_values[n_fields] = @intFromEnum(@field(Tag, f_name));
359373 n_fields += 1;
360374 }
361375 return @Enum(e.tag_type, .exhaustive, field_names[0..n_fields], field_values[0..n_fields]);
......@@ -381,12 +395,12 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {
381395 }
382396 break :full @bitCast(int);
383397 },
384 .@"enum" => |e| if (e.is_exhaustive) v: {
398 .@"enum" => |e| if (e.mode == .exhaustive) v: {
385399 if (@bitSizeOf(e.tag_type) <= 64) {
386400 break :v s.valueWeightedWithHash(T, baselineWeights(T), hash);
387401 }
388402 break :v std.enums.fromInt(T, s.valueWithHash(e.tag_type, hash)) orelse
389 @enumFromInt(e.fields[0].value);
403 @enumFromInt(e.field_values[0]);
390404 } else @enumFromInt(s.valueWithHash(e.tag_type, hash)),
391405 .optional => |o| if (s.valueWithHash(bool, hash))
392406 null
......@@ -406,11 +420,11 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {
406420 .@"struct" => |st| if (!allBitPatternsValid(T)) v: {
407421 var v: T = undefined;
408422 var rhash = hash;
409 inline for (st.fields) |f| {
423 inline for (st.field_names, st.field_types) |f_name, f_type| {
410424 // rhash is incremented in the call so our rhash state is not reused (e.g. with
411425 // two nested structs. note that xor cannot work for this case as the bit would
412426 // be flipped back here)
413 @field(v, f.name) = s.valueWithHash(f.type, rhash +% 1);
427 @field(v, f_name) = s.valueWithHash(f_type, rhash +% 1);
414428 rhash = std.hash.int(rhash);
415429 }
416430 break :v v;
lib/std/zig.zig+4-4
......@@ -736,8 +736,8 @@ pub fn parseTargetQueryOrReportFatalError(
736736 help: {
737737 var help_text = std.array_list.Managed(u8).init(allocator);
738738 defer help_text.deinit();
739 inline for (@typeInfo(std.Target.ObjectFormat).@"enum".fields) |field| {
740 help_text.print(" {s}\n", .{field.name}) catch break :help;
739 inline for (@typeInfo(std.Target.ObjectFormat).@"enum".field_names) |field_name| {
740 help_text.print(" {s}\n", .{field_name}) catch break :help;
741741 }
742742 std.log.info("available object formats:\n{s}", .{help_text.items});
743743 }
......@@ -747,8 +747,8 @@ pub fn parseTargetQueryOrReportFatalError(
747747 help: {
748748 var help_text = std.array_list.Managed(u8).init(allocator);
749749 defer help_text.deinit();
750 inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".fields) |field| {
751 help_text.print(" {s}\n", .{field.name}) catch break :help;
750 inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".field_names) |field_name| {
751 help_text.print(" {s}\n", .{field_name}) catch break :help;
752752 }
753753 std.log.info("available architectures:\n{s} native\n", .{help_text.items});
754754 }
lib/std/zig/Ast.zig+4-4
......@@ -298,17 +298,17 @@ pub fn extraDataSliceWithLen(tree: Ast, start: ExtraIndex, len: u32, comptime T:
298298}
299299
300300pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T {
301 const fields = std.meta.fields(T);
301 const info = @typeInfo(T).@"struct";
302302 var result: T = undefined;
303 inline for (fields, 0..) |field, i| {
304 @field(result, field.name) = switch (field.type) {
303 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
304 @field(result, field_name) = switch (field_type) {
305305 Node.Index,
306306 Node.OptionalIndex,
307307 OptionalTokenIndex,
308308 ExtraIndex,
309309 => @enumFromInt(tree.extra_data[@intFromEnum(index) + i]),
310310 TokenIndex => tree.extra_data[@intFromEnum(index) + i],
311 else => @compileError("unexpected field type: " ++ @typeName(field.type)),
311 else => @compileError("unexpected field type: " ++ @typeName(field_type)),
312312 };
313313 }
314314 return result;
lib/std/zig/AstGen.zig+42-42
......@@ -74,25 +74,25 @@ src_hasher: std.zig.SrcHasher,
7474const InnerError = error{ OutOfMemory, AnalysisFail };
7575
7676fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {
77 const fields = std.meta.fields(@TypeOf(extra));
78 try astgen.extra.ensureUnusedCapacity(astgen.gpa, fields.len);
77 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
78 try astgen.extra.ensureUnusedCapacity(astgen.gpa, field_count);
7979 return addExtraAssumeCapacity(astgen, extra);
8080}
8181
8282fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {
83 const fields = std.meta.fields(@TypeOf(extra));
83 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
8484 const extra_index: u32 = @intCast(astgen.extra.items.len);
85 astgen.extra.items.len += fields.len;
85 astgen.extra.items.len += field_count;
8686 setExtra(astgen, extra_index, extra);
8787 return extra_index;
8888}
8989
9090fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
91 const fields = std.meta.fields(@TypeOf(extra));
91 const info = @typeInfo(@TypeOf(extra)).@"struct";
9292 var i = index;
93 inline for (fields) |field| {
94 astgen.extra.items[i] = switch (field.type) {
95 u32 => @field(extra, field.name),
93 inline for (info.field_names, info.field_types) |field_name, field_type| {
94 astgen.extra.items[i] = switch (field_type) {
95 u32 => @field(extra, field_name),
9696
9797 Zir.Inst.Ref,
9898 Zir.Inst.Index,
......@@ -103,13 +103,13 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
103103 Ast.OptionalTokenIndex,
104104 Ast.Node.Index,
105105 Ast.Node.OptionalIndex,
106 => @intFromEnum(@field(extra, field.name)),
106 => @intFromEnum(@field(extra, field_name)),
107107
108108 Ast.TokenOffset,
109109 Ast.OptionalTokenOffset,
110110 Ast.Node.Offset,
111111 Ast.Node.OptionalOffset,
112 => @bitCast(@intFromEnum(@field(extra, field.name))),
112 => @bitCast(@intFromEnum(@field(extra, field_name))),
113113
114114 i32,
115115 Zir.Inst.Call.Flags,
......@@ -118,7 +118,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
118118 Zir.Inst.FuncFancy.Bits,
119119 Zir.Inst.Param.Type,
120120 Zir.Inst.Func.RetTy,
121 => @bitCast(@field(extra, field.name)),
121 => @bitCast(@field(extra, field_name)),
122122
123123 else => @compileError("bad field type"),
124124 };
......@@ -166,7 +166,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
166166 try astgen.instructions.ensureTotalCapacity(gpa, tree.nodes.len);
167167
168168 // First few indexes of extra are reserved and set at the end.
169 const reserved_count = @typeInfo(Zir.ExtraIndex).@"enum".fields.len;
169 const reserved_count = @typeInfo(Zir.ExtraIndex).@"enum".field_names.len;
170170 try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count);
171171 astgen.extra.items.len += reserved_count;
172172
......@@ -212,7 +212,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
212212 astgen.extra.items[err_index] = 0;
213213 } else {
214214 try astgen.extra.ensureUnusedCapacity(gpa, 1 + astgen.compile_errors.items.len *
215 @typeInfo(Zir.Inst.CompileErrors.Item).@"struct".fields.len);
215 @typeInfo(Zir.Inst.CompileErrors.Item).@"struct".field_names.len);
216216
217217 astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{
218218 .items_len = @intCast(astgen.compile_errors.items.len),
......@@ -227,8 +227,8 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
227227 if (astgen.imports.count() == 0) {
228228 astgen.extra.items[imports_index] = 0;
229229 } else {
230 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Imports).@"struct".fields.len +
231 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).@"struct".fields.len);
230 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Imports).@"struct".field_names.len +
231 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).@"struct".field_names.len);
232232
233233 astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{
234234 .imports_len = @intCast(astgen.imports.count()),
......@@ -1888,7 +1888,7 @@ fn structInitExprAnon(
18881888 .abs_line = astgen.source_line,
18891889 .fields_len = @intCast(struct_init.ast.fields.len),
18901890 });
1891 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).@"struct".fields.len;
1891 const field_size = @typeInfo(Zir.Inst.StructInitAnon.Item).@"struct".field_names.len;
18921892 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
18931893
18941894 for (struct_init.ast.fields) |field_init| {
......@@ -1921,7 +1921,7 @@ fn structInitExprTyped(
19211921 .abs_line = astgen.source_line,
19221922 .fields_len = @intCast(struct_init.ast.fields.len),
19231923 });
1924 const field_size = @typeInfo(Zir.Inst.StructInit.Item).@"struct".fields.len;
1924 const field_size = @typeInfo(Zir.Inst.StructInit.Item).@"struct".field_names.len;
19251925 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
19261926
19271927 for (struct_init.ast.fields) |field_init| {
......@@ -3804,7 +3804,7 @@ fn ptrType(
38043804 const gpa = gz.astgen.gpa;
38053805 try gz.instructions.ensureUnusedCapacity(gpa, 1);
38063806 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
3807 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.PtrType).@"struct".fields.len +
3807 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.PtrType).@"struct".field_names.len +
38083808 trailing_count);
38093809
38103810 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.PtrType{
......@@ -5096,7 +5096,7 @@ fn tupleDecl(
50965096
50975097 const extra_trail = astgen.scratch.items[fields_start..];
50985098 assert(extra_trail.len == fields_len * 2);
5099 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.TupleDecl).@"struct".fields.len + extra_trail.len);
5099 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.TupleDecl).@"struct".field_names.len + extra_trail.len);
51005100 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.TupleDecl{
51015101 .src_node = gz.nodeIndexToRelative(node),
51025102 });
......@@ -5670,7 +5670,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
56705670 const gpa = astgen.gpa;
56715671 const tree = astgen.tree;
56725672
5673 const payload_index = try reserveExtra(astgen, @typeInfo(Zir.Inst.ErrorSetDecl).@"struct".fields.len);
5673 const payload_index = try reserveExtra(astgen, @typeInfo(Zir.Inst.ErrorSetDecl).@"struct".field_names.len);
56745674 var fields_len: usize = 0;
56755675 {
56765676 var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty;
......@@ -6332,7 +6332,7 @@ fn setCondBrPayload(
63326332 const else_body_len = astgen.countBodyLenAfterFixups(else_body);
63336333 try astgen.extra.ensureUnusedCapacity(
63346334 astgen.gpa,
6335 @typeInfo(Zir.Inst.CondBr).@"struct".fields.len + then_body_len + else_body_len,
6335 @typeInfo(Zir.Inst.CondBr).@"struct".field_names.len + then_body_len + else_body_len,
63366336 );
63376337
63386338 const zir_datas = astgen.instructions.items(.data);
......@@ -6761,7 +6761,7 @@ fn forExpr(
67616761 const len: Zir.Inst.Ref = len: {
67626762 const all_lens = @as([*]Zir.Inst.Ref, @ptrCast(lens))[0 .. lens.len * 2];
67636763 const lens_len: u32 = @intCast(all_lens.len);
6764 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).@"struct".fields.len + lens_len);
6764 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.MultiOp).@"struct".field_names.len + lens_len);
67656765 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{
67666766 .operands_len = lens_len,
67676767 });
......@@ -7791,7 +7791,7 @@ fn switchExpr(
77917791 // by copying our bodies from `payloads` to `extra`, this time in the order
77927792 // expected by ZIR consumers.
77937793
7794 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.SwitchBlock).@"struct".fields.len +
7794 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.SwitchBlock).@"struct".field_names.len +
77957795 @intFromBool(multi_cases_len > 0) + // multi_cases_len
77967796 @intFromBool(payload_capture_inst_is_placeholder) + // payload_capture_placeholder
77977797 @intFromBool(tag_capture_inst_is_placeholder) + // tag_capture_placeholder
......@@ -8878,7 +8878,7 @@ fn typeOf(
88788878 try gz.instructions.append(gpa, typeof_inst);
88798879 return rvalue(gz, ri, typeof_inst.toRef(), node);
88808880 }
8881 const payload_size: u32 = std.meta.fields(Zir.Inst.TypeOfPeer).len;
8881 const payload_size: u32 = @typeInfo(Zir.Inst.TypeOfPeer).@"struct".field_names.len;
88828882 const payload_index = try reserveExtra(astgen, payload_size + args.len);
88838883 const args_index = payload_index + payload_size;
88848884
......@@ -11348,7 +11348,7 @@ const GenZir = struct {
1134811348 const body_len = astgen.countBodyLenAfterFixups(body);
1134911349 try astgen.extra.ensureUnusedCapacity(
1135011350 gpa,
11351 @typeInfo(Zir.Inst.BoolBr).@"struct".fields.len + body_len,
11351 @typeInfo(Zir.Inst.BoolBr).@"struct".field_names.len + body_len,
1135211352 );
1135311353 const zir_datas = astgen.instructions.items(.data);
1135411354 zir_datas[@intFromEnum(bool_br)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.BoolBr{
......@@ -11372,7 +11372,7 @@ const GenZir = struct {
1137211372
1137311373 try astgen.extra.ensureUnusedCapacity(
1137411374 gpa,
11375 @typeInfo(Zir.Inst.Block).@"struct".fields.len + body_len,
11375 @typeInfo(Zir.Inst.Block).@"struct".field_names.len + body_len,
1137611376 );
1137711377 const zir_datas = astgen.instructions.items(.data);
1137811378 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
......@@ -11395,7 +11395,7 @@ const GenZir = struct {
1139511395
1139611396 try astgen.extra.ensureUnusedCapacity(
1139711397 gpa,
11398 @typeInfo(Zir.Inst.BlockComptime).@"struct".fields.len + body_len,
11398 @typeInfo(Zir.Inst.BlockComptime).@"struct".field_names.len + body_len,
1139911399 );
1140011400 const zir_datas = astgen.instructions.items(.data);
1140111401 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
......@@ -11416,7 +11416,7 @@ const GenZir = struct {
1141611416 const body_len = astgen.countBodyLenAfterFixups(body);
1141711417 try astgen.extra.ensureUnusedCapacity(
1141811418 gpa,
11419 @typeInfo(Zir.Inst.Try).@"struct".fields.len + body_len,
11419 @typeInfo(Zir.Inst.Try).@"struct".field_names.len + body_len,
1142011420 );
1142111421 const zir_datas = astgen.instructions.items(.data);
1142211422 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
......@@ -11529,7 +11529,7 @@ const GenZir = struct {
1152911529 inst_info: {
1153011530 try astgen.extra.ensureUnusedCapacity(
1153111531 gpa,
11532 @typeInfo(Zir.Inst.FuncFancy).@"struct".fields.len +
11532 @typeInfo(Zir.Inst.FuncFancy).@"struct".field_names.len +
1153311533 fancyFnExprExtraLen(astgen, &.{}, cc_body, args.cc_ref) +
1153411534 fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) +
1153511535 body_len + src_locs_and_hash.len +
......@@ -11589,7 +11589,7 @@ const GenZir = struct {
1158911589 } else inst_info: {
1159011590 try astgen.extra.ensureUnusedCapacity(
1159111591 gpa,
11592 @typeInfo(Zir.Inst.Func).@"struct".fields.len + 1 +
11592 @typeInfo(Zir.Inst.Func).@"struct".field_names.len + 1 +
1159311593 fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) +
1159411594 body_len + src_locs_and_hash.len,
1159511595 );
......@@ -11777,7 +11777,7 @@ const GenZir = struct {
1177711777 const param_body = param_gz.instructionsSlice();
1177811778 const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(param_body, prev_param_insts);
1177911779 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
11780 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).@"struct".fields.len + body_len);
11780 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Param).@"struct".field_names.len + body_len);
1178111781
1178211782 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
1178311783 .name = name,
......@@ -11847,7 +11847,7 @@ const GenZir = struct {
1184711847 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1184811848 try astgen.extra.ensureUnusedCapacity(
1184911849 gpa,
11850 @typeInfo(Zir.Inst.NodeMultiOp).@"struct".fields.len + operands.len,
11850 @typeInfo(Zir.Inst.NodeMultiOp).@"struct".field_names.len + operands.len,
1185111851 );
1185211852
1185311853 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
......@@ -12088,7 +12088,7 @@ const GenZir = struct {
1208812088 ) !Zir.Inst.Index {
1208912089 const gpa = gz.astgen.gpa;
1209012090 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);
12091 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).@"struct".fields.len);
12091 try gz.astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Break).@"struct".field_names.len);
1209212092
1209312093 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
1209412094 gz.astgen.instructions.appendAssumeCapacity(.{
......@@ -12211,7 +12211,7 @@ const GenZir = struct {
1221112211 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
1221212212 try astgen.extra.ensureUnusedCapacity(
1221312213 gpa,
12214 @typeInfo(Zir.Inst.AllocExtended).@"struct".fields.len +
12214 @typeInfo(Zir.Inst.AllocExtended).@"struct".field_names.len +
1221512215 @intFromBool(args.type_inst != .none) +
1221612216 @intFromBool(args.align_inst != .none),
1221712217 );
......@@ -12263,9 +12263,9 @@ const GenZir = struct {
1226312263
1226412264 try gz.instructions.ensureUnusedCapacity(gpa, 1);
1226512265 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
12266 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Asm).@"struct".fields.len +
12267 args.outputs.len * @typeInfo(Zir.Inst.Asm.Output).@"struct".fields.len +
12268 args.inputs.len * @typeInfo(Zir.Inst.Asm.Input).@"struct".fields.len);
12266 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Asm).@"struct".field_names.len +
12267 args.outputs.len * @typeInfo(Zir.Inst.Asm.Output).@"struct".field_names.len +
12268 args.inputs.len * @typeInfo(Zir.Inst.Asm.Input).@"struct".field_names.len);
1226912269
1227012270 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Asm{
1227112271 .src_node = gz.nodeIndexToRelative(args.node),
......@@ -12374,7 +12374,7 @@ const GenZir = struct {
1237412374
1237512375 const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash);
1237612376
12377 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.StructDecl).@"struct".fields.len +
12377 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.StructDecl).@"struct".field_names.len +
1237812378 4 + // `captures_len`, `decls_len`, `fields_len`, `backing_int_type_body_len`
1237912379 captures_len * 2 + // `capture`, `capture_name`
1238012380 args.remaining.len);
......@@ -12441,7 +12441,7 @@ const GenZir = struct {
1244112441
1244212442 const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash);
1244312443
12444 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.UnionDecl).@"struct".fields.len +
12444 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.UnionDecl).@"struct".field_names.len +
1244512445 4 + // `captures_len`, `decls_len`, `fields_len`, `arg_type_body_len`
1244612446 captures_len * 2 + // `capture`, `capture_name`
1244712447 args.remaining.len);
......@@ -12509,7 +12509,7 @@ const GenZir = struct {
1250912509
1251012510 const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash);
1251112511
12512 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.EnumDecl).@"struct".fields.len +
12512 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.EnumDecl).@"struct".field_names.len +
1251312513 4 + // `captures_len`, `decls_len`, `fields_len`, `tag_type_body_len`
1251412514 captures_len * 2 + // `capture`, `capture_name`
1251512515 args.remaining.len);
......@@ -12565,7 +12565,7 @@ const GenZir = struct {
1256512565 const captures_len: u32 = @intCast(args.captures.len);
1256612566 assert(args.capture_names.len == captures_len);
1256712567
12568 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).@"struct".fields.len +
12568 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.OpaqueDecl).@"struct".field_names.len +
1256912569 2 + // `captures_len`, `decls_len`
1257012570 captures_len * 2 + // `capture`, `capture_name`
1257112571 args.decls.len);
......@@ -13465,7 +13465,7 @@ fn setDeclaration(
1346513465 const flags_arr: [2]u32 = @bitCast(flags);
1346613466
1346713467 const need_extra: usize =
13468 @typeInfo(Zir.Inst.Declaration).@"struct".fields.len +
13468 @typeInfo(Zir.Inst.Declaration).@"struct".field_names.len +
1346913469 @as(usize, @intFromBool(id.hasName())) +
1347013470 @as(usize, @intFromBool(id.hasLibName())) +
1347113471 @as(usize, @intFromBool(id.hasTypeBody())) +
lib/std/zig/ErrorBundle.zig+16-13
......@@ -117,7 +117,7 @@ pub fn getSourceLocation(eb: ErrorBundle, index: SourceLocationIndex) SourceLoca
117117
118118pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {
119119 const notes_len = eb.getErrorMessage(index).notes_len;
120 const start = @intFromEnum(index) + @typeInfo(ErrorMessage).@"struct".fields.len;
120 const start = @intFromEnum(index) + @typeInfo(ErrorMessage).@"struct".field_names.len;
121121 return @as([]const MessageIndex, @ptrCast(eb.extra[start..][0..notes_len]));
122122}
123123
......@@ -128,11 +128,12 @@ pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {
128128/// Returns the requested data, as well as the new index which is at the start of the
129129/// trailers for the object.
130130fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T, end: usize } {
131 const fields = @typeInfo(T).@"struct".fields;
131 const field_names = @typeInfo(T).@"struct".field_names;
132 const field_types = @typeInfo(T).@"struct".field_types;
132133 var i: usize = index;
133134 var result: T = undefined;
134 inline for (fields) |field| {
135 @field(result, field.name) = switch (field.type) {
135 inline for (field_names, field_types) |field_name, field_type| {
136 @field(result, field_name) = switch (field_type) {
136137 u32 => eb.extra[i],
137138 MessageIndex => @as(MessageIndex, @enumFromInt(eb.extra[i])),
138139 SourceLocationIndex => @as(SourceLocationIndex, @enumFromInt(eb.extra[i])),
......@@ -498,7 +499,7 @@ pub const Wip = struct {
498499
499500 pub fn reserveNotes(wip: *Wip, notes_len: u32) !u32 {
500501 try wip.extra.ensureUnusedCapacity(wip.gpa, notes_len +
501 notes_len * @typeInfo(ErrorBundle.ErrorMessage).@"struct".fields.len);
502 notes_len * @typeInfo(ErrorBundle.ErrorMessage).@"struct".field_names.len);
502503 wip.extra.items.len += notes_len;
503504 return @intCast(wip.extra.items.len - notes_len);
504505 }
......@@ -731,13 +732,13 @@ pub const Wip = struct {
731732
732733 fn addExtra(wip: *Wip, extra: anytype) Allocator.Error!u32 {
733734 const gpa = wip.gpa;
734 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
735 const fields = @typeInfo(@TypeOf(extra)).@"struct".field_names;
735736 try wip.extra.ensureUnusedCapacity(gpa, fields.len);
736737 return addExtraAssumeCapacity(wip, extra);
737738 }
738739
739740 fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {
740 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
741 const fields = @typeInfo(@TypeOf(extra)).@"struct".field_names;
741742 const result: u32 = @intCast(wip.extra.items.len);
742743 wip.extra.items.len += fields.len;
743744 setExtra(wip, result, extra);
......@@ -745,13 +746,15 @@ pub const Wip = struct {
745746 }
746747
747748 fn setExtra(wip: *Wip, index: usize, extra: anytype) void {
748 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;
749 const extra_info = @typeInfo(@TypeOf(extra)).@"struct";
750 const field_names = extra_info.field_names;
751 const field_types = extra_info.field_types;
749752 var i = index;
750 inline for (fields) |field| {
751 wip.extra.items[i] = switch (field.type) {
752 u32 => @field(extra, field.name),
753 MessageIndex => @intFromEnum(@field(extra, field.name)),
754 SourceLocationIndex => @intFromEnum(@field(extra, field.name)),
753 inline for (field_names, field_types) |field_name, field_type| {
754 wip.extra.items[i] = switch (field_type) {
755 u32 => @field(extra, field_name),
756 MessageIndex => @intFromEnum(@field(extra, field_name)),
757 SourceLocationIndex => @intFromEnum(@field(extra, field_name)),
755758 else => @compileError("bad field type"),
756759 };
757760 i += 1;
lib/std/zig/LibCInstallation.zig+11-11
......@@ -43,12 +43,13 @@ pub const FindError = error{
4343pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const std.Target) !LibCInstallation {
4444 var self: LibCInstallation = .{};
4545
46 const fields = std.meta.fields(LibCInstallation);
46 const field_names = comptime std.meta.fieldNames(LibCInstallation);
4747 const FoundKey = struct {
4848 found: bool,
4949 allocated: ?[:0]u8,
5050 };
51 var found_keys: [fields.len]FoundKey = @splat(.{ .found = false, .allocated = null });
51
52 var found_keys: [field_names.len]FoundKey = @splat(.{ .found = false, .allocated = null });
5253 errdefer {
5354 self = .{};
5455 for (found_keys) |found_key| {
......@@ -65,22 +66,22 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const
6566 var line_it = std.mem.splitScalar(u8, line, '=');
6667 const name = line_it.first();
6768 const value = line_it.rest();
68 inline for (fields, 0..) |field, i| {
69 if (std.mem.eql(u8, name, field.name)) {
69 inline for (field_names, 0..) |field_name, i| {
70 if (std.mem.eql(u8, name, field_name)) {
7071 found_keys[i].found = true;
7172 if (value.len == 0) {
72 @field(self, field.name) = null;
73 @field(self, field_name) = null;
7374 } else {
7475 found_keys[i].allocated = try allocator.dupeSentinel(u8, value, 0);
75 @field(self, field.name) = found_keys[i].allocated;
76 @field(self, field_name) = found_keys[i].allocated;
7677 }
7778 break;
7879 }
7980 }
8081 }
81 inline for (fields, 0..) |field, i| {
82 inline for (field_names, 0..) |field_name, i| {
8283 if (!found_keys[i].found) {
83 log.err("missing field: {s}", .{field.name});
84 log.err("missing field: {s}", .{field_name});
8485 return error.ParseError;
8586 }
8687 }
......@@ -235,9 +236,8 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
235236
236237/// Must be the same allocator passed to `parse` or `findNative`.
237238pub fn deinit(self: *LibCInstallation, allocator: Allocator) void {
238 const fields = std.meta.fields(LibCInstallation);
239 inline for (fields) |field| {
240 if (@field(self, field.name)) |payload| {
239 inline for (@typeInfo(LibCInstallation).@"struct".field_names) |field_name| {
240 if (@field(self, field_name)) |payload| {
241241 allocator.free(payload);
242242 }
243243 }
lib/std/zig/Parse.zig+6-6
......@@ -89,18 +89,18 @@ fn unreserveNode(p: *Parse, node_index: usize) void {
8989}
9090
9191fn addExtra(p: *Parse, extra: anytype) Allocator.Error!ExtraIndex {
92 const fields = std.meta.fields(@TypeOf(extra));
93 try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len);
92 const info = @typeInfo(@TypeOf(extra)).@"struct";
93 try p.extra_data.ensureUnusedCapacity(p.gpa, info.field_names.len);
9494 const result: ExtraIndex = @enumFromInt(p.extra_data.items.len);
95 inline for (fields) |field| {
96 const data: u32 = switch (field.type) {
95 inline for (info.field_names, info.field_types) |field_name, field_type| {
96 const data: u32 = switch (field_type) {
9797 Node.Index,
9898 Node.OptionalIndex,
9999 OptionalTokenIndex,
100100 ExtraIndex,
101 => @intFromEnum(@field(extra, field.name)),
101 => @intFromEnum(@field(extra, field_name)),
102102 TokenIndex,
103 => @field(extra, field.name),
103 => @field(extra, field_name),
104104 else => @compileError("unexpected field type"),
105105 };
106106 p.extra_data.appendAssumeCapacity(data);
lib/std/zig/Zir.zig+10-10
......@@ -68,11 +68,11 @@ fn ExtraData(comptime T: type) type {
6868/// Returns the requested data, as well as the new index which is at the start of the
6969/// trailers for the object.
7070pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
71 const fields = @typeInfo(T).@"struct".fields;
71 const info = @typeInfo(T).@"struct";
7272 var i: usize = index;
7373 var result: T = undefined;
74 inline for (fields) |field| {
75 @field(result, field.name) = switch (field.type) {
74 inline for (info.field_names, info.field_types) |field_name, field_type| {
75 @field(result, field_name) = switch (field_type) {
7676 u32 => code.extra[i],
7777
7878 Inst.Ref,
......@@ -1877,7 +1877,7 @@ pub const Inst = struct {
18771877
18781878 // Uncomment to view how many tag slots are available.
18791879 //comptime {
1880 // @compileLog("ZIR tags left: ", 256 - @typeInfo(Tag).@"enum".fields.len);
1880 // @compileLog("ZIR tags left: ", 256 - @typeInfo(Tag).@"enum".field_names.len);
18811881 //}
18821882 };
18831883
......@@ -2325,7 +2325,7 @@ pub const Inst = struct {
23252325
23262326 _,
23272327
2328 pub const static_len = @typeInfo(@This()).@"enum".fields.len - 1;
2328 pub const static_len = @typeInfo(@This()).@"enum".field_names.len - 1;
23292329
23302330 pub fn toIndex(inst: Ref) ?Index {
23312331 assert(inst != .none);
......@@ -3186,7 +3186,7 @@ pub const Inst = struct {
31863186
31873187 pub const ReifySliceArgInfo = enum(u16) {
31883188 /// Input element type is `type`.
3189 /// Output element type is `std.lang.Type.Fn.Param.Attributes`.
3189 /// Output element type is `std.lang.Type.Fn.ParamAttributes`.
31903190 type_to_fn_param_attrs,
31913191 /// Input element type is `[]const u8`.
31923192 /// Output element type is `type`.
......@@ -3194,10 +3194,10 @@ pub const Inst = struct {
31943194 /// Identical to `string_to_struct_field_type` aside from emitting slightly different error messages.
31953195 string_to_union_field_type,
31963196 /// Input element type is `[]const u8`.
3197 /// Output element type is `std.lang.Type.StructField.Attributes`.
3197 /// Output element type is `std.lang.Type.Struct.FieldAttributes`.
31983198 string_to_struct_field_attrs,
31993199 /// Input element type is `[]const u8`.
3200 /// Output element type is `std.lang.Type.UnionField.Attributes`.
3200 /// Output element type is `std.lang.Type.Union.FieldAttributes`.
32013201 string_to_union_field_attrs,
32023202 };
32033203
......@@ -4842,7 +4842,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash {
48424842 const extra_index = extra.end +
48434843 extra.data.ret_ty.body_len +
48444844 extra.data.body_len +
4845 @typeInfo(Inst.Func.SrcLocs).@"struct".fields.len;
4845 @typeInfo(Inst.Func.SrcLocs).@"struct".field_names.len;
48464846 return @bitCast([4]u32{
48474847 zir.extra[extra_index + 0],
48484848 zir.extra[extra_index + 1],
......@@ -4869,7 +4869,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash {
48694869 } else extra_index += @intFromBool(bits.has_ret_ty_ref);
48704870 extra_index += @intFromBool(bits.has_any_noalias);
48714871 extra_index += extra.data.body_len;
4872 extra_index += @typeInfo(Zir.Inst.Func.SrcLocs).@"struct".fields.len;
4872 extra_index += @typeInfo(Zir.Inst.Func.SrcLocs).@"struct".field_names.len;
48734873 return @bitCast([4]u32{
48744874 zir.extra[extra_index + 0],
48754875 zir.extra[extra_index + 1],
lib/std/zig/c_translation/helpers.zig+2-2
......@@ -199,8 +199,8 @@ pub fn cast(comptime DestType: type, target: anytype) DestType {
199199 }
200200 },
201201 .@"union" => |info| {
202 inline for (info.fields) |field| {
203 if (field.type == SourceType) return @unionInit(DestType, field.name, target);
202 inline for (info.field_names, info.field_types) |field_name, field_type| {
203 if (field_type == SourceType) return @unionInit(DestType, field_name, target);
204204 }
205205
206206 @compileError("cast to union type '" ++ @typeName(DestType) ++ "' from type '" ++ @typeName(SourceType) ++ "' which is not present in union");
lib/std/zig/llvm/BitcodeReader.zig+3-3
......@@ -282,7 +282,7 @@ fn startBlock(bc: *BitcodeReader, block_id: ?u32, new_abbrev_len: u6) !void {
282282 };
283283 try state.abbrevs.abbrevs.ensureTotalCapacity(
284284 bc.allocator,
285 @typeInfo(Abbrev.Builtin).@"enum".fields.len + abbrevs.len,
285 @typeInfo(Abbrev.Builtin).@"enum".field_names.len + abbrevs.len,
286286 );
287287
288288 assert(state.abbrevs.abbrevs.items.len == @intFromEnum(Abbrev.Builtin.end_block));
......@@ -318,7 +318,7 @@ fn startBlock(bc: *BitcodeReader, block_id: ?u32, new_abbrev_len: u6) !void {
318318 .{ .encoding = .{ .vbr = 6 } }, // ops
319319 },
320320 });
321 assert(state.abbrevs.abbrevs.items.len == @typeInfo(Abbrev.Builtin).@"enum".fields.len);
321 assert(state.abbrevs.abbrevs.items.len == @typeInfo(Abbrev.Builtin).@"enum".field_names.len);
322322 for (abbrevs) |abbrev| try state.abbrevs.addAbbrevAssumeCapacity(bc.allocator, abbrev);
323323}
324324
......@@ -457,7 +457,7 @@ const Abbrev = struct {
457457 define_abbrev,
458458 unabbrev_record,
459459
460 const first_record_id: u32 = std.math.maxInt(u32) - @typeInfo(Builtin).@"enum".fields.len + 1;
460 const first_record_id: u32 = std.math.maxInt(u32) - @typeInfo(Builtin).@"enum".field_names.len + 1;
461461 fn toRecordId(builtin: Builtin) u32 {
462462 return first_record_id + @intFromEnum(builtin);
463463 }
lib/std/zig/llvm/Builder.zig+124-93
......@@ -1137,21 +1137,22 @@ pub const Attribute = union(Kind) {
11371137 .no_sanitize_hwaddress,
11381138 .sanitize_address_dyninit,
11391139 => |kind| {
1140 const field = comptime blk: {
1140 const field_name, const field_type = comptime blk: {
11411141 @setEvalBranchQuota(10_000);
1142 for (@typeInfo(Attribute).@"union".fields) |field| {
1143 if (std.mem.eql(u8, field.name, @tagName(kind))) break :blk field;
1142 const info = @typeInfo(Attribute).@"union";
1143 for (info.field_names, info.field_types) |field_name, field_type| {
1144 if (std.mem.eql(u8, field_name, @tagName(kind))) break :blk .{ field_name, field_type };
11441145 }
11451146 unreachable;
11461147 };
1147 comptime assert(std.mem.eql(u8, @tagName(kind), field.name));
1148 return @unionInit(Attribute, field.name, switch (field.type) {
1148 comptime assert(std.mem.eql(u8, @tagName(kind), field_name));
1149 return @unionInit(Attribute, field_name, switch (field_type) {
11491150 void => {},
11501151 u32 => storage.value,
11511152 Alignment.Lazy, String, Type, UwTable => @enumFromInt(storage.value),
11521153 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value),
1153 else => @compileError("bad payload type: " ++ field.name ++ ": " ++
1154 @typeName(field.type)),
1154 else => @compileError("bad payload type: " ++ field_name ++ ": " ++
1155 @typeName(field_type)),
11551156 });
11561157 },
11571158 .string, .none => unreachable,
......@@ -1258,14 +1259,14 @@ pub const Attribute = union(Kind) {
12581259 try w.print(" {s}(", .{@tagName(attribute)});
12591260 var any = false;
12601261 var remaining: Int = @bitCast(fpclass);
1261 inline for (@typeInfo(FpClass).@"struct".decls) |decl| {
1262 const pattern: Int = @bitCast(@field(FpClass, decl.name));
1262 inline for (@typeInfo(FpClass).@"struct".decl_names) |decl_name| {
1263 const pattern: Int = @bitCast(@field(FpClass, decl_name));
12631264 if (remaining & pattern == pattern) {
12641265 if (!any) {
12651266 try w.writeByte(' ');
12661267 any = true;
12671268 }
1268 try w.writeAll(decl.name);
1269 try w.writeAll(decl_name);
12691270 remaining &= ~pattern;
12701271 }
12711272 }
......@@ -1283,14 +1284,14 @@ pub const Attribute = union(Kind) {
12831284 .allockind => |allockind| {
12841285 try w.print(" {t}(\"", .{attribute});
12851286 var any = false;
1286 inline for (@typeInfo(AllocKind).@"struct".fields) |field| {
1287 if (comptime std.mem.eql(u8, field.name, "_")) continue;
1288 if (@field(allockind, field.name)) {
1287 inline for (@typeInfo(AllocKind).@"struct".field_names) |field_name| {
1288 if (comptime std.mem.eql(u8, field_name, "_")) continue;
1289 if (@field(allockind, field_name)) {
12891290 if (!any) {
12901291 try w.writeByte(',');
12911292 any = true;
12921293 }
1293 try w.writeAll(field.name);
1294 try w.writeAll(field_name);
12941295 }
12951296 }
12961297 try w.writeAll("\")");
......@@ -1442,7 +1443,7 @@ pub const Attribute = union(Kind) {
14421443 none = maxInt(u32),
14431444 _,
14441445
1445 pub const len = @typeInfo(Kind).@"enum".fields.len - 2;
1446 pub const len = @typeInfo(Kind).@"enum".field_names.len - 2;
14461447
14471448 pub fn fromString(str: String) Kind {
14481449 assert(!str.isAnon());
......@@ -5167,9 +5168,13 @@ pub const Function = struct {
51675168 index: Instruction.ExtraIndex,
51685169 ) struct { data: T, trail: ExtraDataTrail } {
51695170 var result: T = undefined;
5170 const fields = @typeInfo(T).@"struct".fields;
5171 inline for (fields, self.extra[index..][0..fields.len]) |field, value|
5172 @field(result, field.name) = switch (field.type) {
5171 const info = @typeInfo(T).@"struct";
5172 inline for (
5173 info.field_names,
5174 info.field_types,
5175 self.extra[index..][0..info.field_names.len],
5176 ) |field_name, field_type, value|
5177 @field(result, field_name) = switch (field_type) {
51735178 u32 => value,
51745179 Alignment,
51755180 AtomicOrdering,
......@@ -5183,11 +5188,11 @@ pub const Function = struct {
51835188 Instruction.Alloca.Info,
51845189 Instruction.Call.Info,
51855190 => @bitCast(value),
5186 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
5191 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
51875192 };
51885193 return .{
51895194 .data = result,
5190 .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(fields.len)) },
5195 .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(info.field_names.len)) },
51915196 };
51925197 }
51935198
......@@ -6327,9 +6332,10 @@ pub const WipFunction = struct {
63276332
63286333 fn addExtra(wip_extra: *@This(), extra: anytype) Instruction.ExtraIndex {
63296334 const result = wip_extra.index;
6330 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
6331 const value = @field(extra, field.name);
6332 wip_extra.items[wip_extra.index] = switch (field.type) {
6335 const info = @typeInfo(@TypeOf(extra)).@"struct";
6336 inline for (info.field_names, info.field_types) |field_name, field_type| {
6337 const value = @field(extra, field_name);
6338 wip_extra.items[wip_extra.index] = switch (field_type) {
63336339 u32 => value,
63346340 Alignment,
63356341 AtomicOrdering,
......@@ -6343,7 +6349,7 @@ pub const WipFunction = struct {
63436349 Instruction.Alloca.Info,
63446350 Instruction.Call.Info,
63456351 => @bitCast(value),
6346 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
6352 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
63476353 };
63486354 wip_extra.index += 1;
63496355 }
......@@ -6944,7 +6950,7 @@ pub const WipFunction = struct {
69446950 ) Allocator.Error!void {
69456951 try self.extra.ensureUnusedCapacity(
69466952 self.builder.gpa,
6947 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),
6953 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
69486954 );
69496955 }
69506956
......@@ -6983,9 +6989,10 @@ pub const WipFunction = struct {
69836989
69846990 fn addExtraAssumeCapacity(self: *WipFunction, extra: anytype) Instruction.ExtraIndex {
69856991 const result: Instruction.ExtraIndex = @intCast(self.extra.items.len);
6986 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
6987 const value = @field(extra, field.name);
6988 self.extra.appendAssumeCapacity(switch (field.type) {
6992 const info = @typeInfo(@TypeOf(extra)).@"struct";
6993 inline for (info.field_names, info.field_types) |field_name, field_type| {
6994 const value = @field(extra, field_name);
6995 self.extra.appendAssumeCapacity(switch (field_type) {
69896996 u32 => value,
69906997 Alignment,
69916998 AtomicOrdering,
......@@ -6999,7 +7006,7 @@ pub const WipFunction = struct {
69997006 Instruction.Alloca.Info,
70007007 Instruction.Call.Info,
70017008 => @bitCast(value),
7002 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
7009 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
70037010 });
70047011 }
70057012 return result;
......@@ -7032,9 +7039,13 @@ pub const WipFunction = struct {
70327039 index: Instruction.ExtraIndex,
70337040 ) struct { data: T, trail: ExtraDataTrail } {
70347041 var result: T = undefined;
7035 const fields = @typeInfo(T).@"struct".fields;
7036 inline for (fields, self.extra.items[index..][0..fields.len]) |field, value|
7037 @field(result, field.name) = switch (field.type) {
7042 const info = @typeInfo(T).@"struct";
7043 inline for (
7044 info.field_names,
7045 info.field_types,
7046 self.extra.items[index..][0..info.field_names.len],
7047 ) |field_name, field_type, value|
7048 @field(result, field_name) = switch (field_type) {
70387049 u32 => value,
70397050 Alignment,
70407051 AtomicOrdering,
......@@ -7048,11 +7059,11 @@ pub const WipFunction = struct {
70487059 Instruction.Alloca.Info,
70497060 Instruction.Call.Info,
70507061 => @bitCast(value),
7051 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
7062 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
70527063 };
70537064 return .{
70547065 .data = result,
7055 .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(fields.len)) },
7066 .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(info.field_names.len)) },
70567067 };
70577068 }
70587069
......@@ -8202,19 +8213,20 @@ pub const Metadata = packed struct(u32) {
82028213
82038214 pub fn format(self: DIFlags, w: *Writer) Writer.Error!void {
82048215 var need_pipe = false;
8205 inline for (@typeInfo(DIFlags).@"struct".fields) |field| {
8206 switch (@typeInfo(field.type)) {
8207 .bool => if (@field(self, field.name)) {
8216 const info = @typeInfo(DIFlags).@"struct";
8217 inline for (info.field_names, info.field_types) |field_name, field_type| {
8218 switch (@typeInfo(field_type)) {
8219 .bool => if (@field(self, field_name)) {
82088220 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
8209 try w.print("DIFlag{s}", .{field.name});
8221 try w.print("DIFlag{s}", .{field_name});
82108222 },
8211 .@"enum" => if (@field(self, field.name) != .Zero) {
8223 .@"enum" => if (@field(self, field_name) != .Zero) {
82128224 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
8213 try w.print("DIFlag{s}", .{@tagName(@field(self, field.name))});
8225 try w.print("DIFlag{s}", .{@tagName(@field(self, field_name))});
82148226 },
8215 .int => assert(@field(self, field.name) == 0),
8216 else => @compileError("bad field type: " ++ field.name ++ ": " ++
8217 @typeName(field.type)),
8227 .int => assert(@field(self, field_name) == 0),
8228 else => @compileError("bad field type: " ++ field_name ++ ": " ++
8229 @typeName(field_type)),
82188230 }
82198231 }
82208232 if (!need_pipe) try w.writeByte('0');
......@@ -8259,19 +8271,20 @@ pub const Metadata = packed struct(u32) {
82598271
82608272 pub fn format(self: DISPFlags, w: *Writer) Writer.Error!void {
82618273 var need_pipe = false;
8262 inline for (@typeInfo(DISPFlags).@"struct".fields) |field| {
8263 switch (@typeInfo(field.type)) {
8264 .bool => if (@field(self, field.name)) {
8274 const info = @typeInfo(DISPFlags).@"struct";
8275 inline for (info.field_names, info.field_types) |field_name, field_type| {
8276 switch (@typeInfo(field_type)) {
8277 .bool => if (@field(self, field_name)) {
82658278 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
8266 try w.print("DISPFlag{s}", .{field.name});
8279 try w.print("DISPFlag{s}", .{field_name});
82678280 },
8268 .@"enum" => if (@field(self, field.name) != .Zero) {
8281 .@"enum" => if (@field(self, field_name) != .Zero) {
82698282 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
8270 try w.print("DISPFlag{s}", .{@tagName(@field(self, field.name))});
8283 try w.print("DISPFlag{s}", .{@tagName(@field(self, field_name))});
82718284 },
8272 .int => assert(@field(self, field.name) == 0),
8273 else => @compileError("bad field type: " ++ field.name ++ ": " ++
8274 @typeName(field.type)),
8285 .int => assert(@field(self, field_name) == 0),
8286 else => @compileError("bad field type: " ++ field_name ++ ": " ++
8287 @typeName(field_type)),
82758288 }
82768289 }
82778290 if (!need_pipe) try w.writeByte('0');
......@@ -8567,7 +8580,7 @@ pub const Metadata = packed struct(u32) {
85678580 })) |some| switch (@typeInfo(Some)) {
85688581 .@"enum" => |enum_info| switch (Some) {
85698582 Metadata.String => .{ .string = some },
8570 else => if (enum_info.is_exhaustive)
8583 else => if (enum_info.mode == .exhaustive)
85718584 .{ .raw = @tagName(some) }
85728585 else
85738586 @compileError("unknown type to format: " ++ @typeName(Node)),
......@@ -8763,14 +8776,15 @@ pub fn init(options: Options) Allocator.Error!Builder {
87638776 }
87648777
87658778 {
8766 const static_len = @typeInfo(Type).@"enum".fields.len - 1;
8779 const static_len = @typeInfo(Type).@"enum".field_names.len - 1;
87678780 try self.type_map.ensureTotalCapacity(self.gpa, static_len);
87688781 try self.type_items.ensureTotalCapacity(self.gpa, static_len);
8769 inline for (@typeInfo(Type.Simple).@"enum".fields) |simple_field| {
8782 const info = @typeInfo(Type.Simple).@"enum";
8783 inline for (info.field_names, info.field_values) |simple_field_name, simple_field_value| {
87708784 const result = self.getOrPutTypeNoExtraAssumeCapacity(
8771 .{ .tag = .simple, .data = simple_field.value },
8785 .{ .tag = .simple, .data = simple_field_value },
87728786 );
8773 assert(result.new and result.type == @field(Type, simple_field.name));
8787 assert(result.new and result.type == @field(Type, simple_field_name));
87748788 }
87758789 inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits|
87768790 assert(self.intTypeAssumeCapacity(bits) ==
......@@ -11016,7 +11030,7 @@ fn ensureUnusedTypeCapacity(
1101611030 try self.type_items.ensureUnusedCapacity(self.gpa, count);
1101711031 try self.type_extra.ensureUnusedCapacity(
1101811032 self.gpa,
11019 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),
11033 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
1102011034 );
1102111035}
1102211036
......@@ -11046,12 +11060,13 @@ fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { n
1104611060
1104711061fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraIndex {
1104811062 const result: Type.Item.ExtraIndex = @intCast(self.type_extra.items.len);
11049 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
11050 const value = @field(extra, field.name);
11051 self.type_extra.appendAssumeCapacity(switch (field.type) {
11063 const info = @typeInfo(@TypeOf(extra)).@"struct";
11064 inline for (info.field_names, info.field_types) |field_name, field_type| {
11065 const value = @field(extra, field_name);
11066 self.type_extra.appendAssumeCapacity(switch (field_type) {
1105211067 u32 => value,
1105311068 String, Type => @intFromEnum(value),
11054 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
11069 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
1105511070 });
1105611071 }
1105711072 return result;
......@@ -11084,16 +11099,20 @@ fn typeExtraDataTrail(
1108411099 index: Type.Item.ExtraIndex,
1108511100) struct { data: T, trail: TypeExtraDataTrail } {
1108611101 var result: T = undefined;
11087 const fields = @typeInfo(T).@"struct".fields;
11088 inline for (fields, self.type_extra.items[index..][0..fields.len]) |field, value|
11089 @field(result, field.name) = switch (field.type) {
11102 const info = @typeInfo(T).@"struct";
11103 inline for (
11104 info.field_names,
11105 info.field_types,
11106 self.type_extra.items[index..][0..info.field_names.len],
11107 ) |field_name, field_type, value|
11108 @field(result, field_name) = switch (field_type) {
1109011109 u32 => value,
1109111110 String, Type => @enumFromInt(value),
11092 else => @compileError("bad field type: " ++ @typeName(field.type)),
11111 else => @compileError("bad field type: " ++ @typeName(field_type)),
1109311112 };
1109411113 return .{
1109511114 .data = result,
11096 .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(fields.len)) },
11115 .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(info.field_names.len)) },
1109711116 };
1109811117}
1109911118
......@@ -11899,7 +11918,7 @@ fn ensureUnusedConstantCapacity(
1189911918 try self.constant_items.ensureUnusedCapacity(self.gpa, count);
1190011919 try self.constant_extra.ensureUnusedCapacity(
1190111920 self.gpa,
11902 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),
11921 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
1190311922 );
1190411923}
1190511924
......@@ -11974,13 +11993,14 @@ fn getOrPutConstantAggregateAssumeCapacity(
1197411993
1197511994fn addConstantExtraAssumeCapacity(self: *Builder, extra: anytype) Constant.Item.ExtraIndex {
1197611995 const result: Constant.Item.ExtraIndex = @intCast(self.constant_extra.items.len);
11977 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
11978 const value = @field(extra, field.name);
11979 self.constant_extra.appendAssumeCapacity(switch (field.type) {
11996 const info = @typeInfo(@TypeOf(extra)).@"struct";
11997 inline for (info.field_names, info.field_types) |field_name, field_type| {
11998 const value = @field(extra, field_name);
11999 self.constant_extra.appendAssumeCapacity(switch (field_type) {
1198012000 u32 => value,
1198112001 String, Type, Constant, Function.Index, Function.Block.Index => @intFromEnum(value),
1198212002 Constant.GetElementPtr.Info => @bitCast(value),
11983 else => @compileError("bad field type: " ++ @typeName(field.type)),
12003 else => @compileError("bad field type: " ++ @typeName(field_type)),
1198412004 });
1198512005 }
1198612006 return result;
......@@ -12013,17 +12033,21 @@ fn constantExtraDataTrail(
1201312033 index: Constant.Item.ExtraIndex,
1201412034) struct { data: T, trail: ConstantExtraDataTrail } {
1201512035 var result: T = undefined;
12016 const fields = @typeInfo(T).@"struct".fields;
12017 inline for (fields, self.constant_extra.items[index..][0..fields.len]) |field, value|
12018 @field(result, field.name) = switch (field.type) {
12036 const info = @typeInfo(T).@"struct";
12037 inline for (
12038 info.field_names,
12039 info.field_types,
12040 self.constant_extra.items[index..][0..info.field_names.len],
12041 ) |field_name, field_type, value|
12042 @field(result, field_name) = switch (field_type) {
1201912043 u32 => value,
1202012044 String, Type, Constant, Function.Index, Function.Block.Index => @enumFromInt(value),
1202112045 Constant.GetElementPtr.Info => @bitCast(value),
12022 else => @compileError("bad field type: " ++ @typeName(field.type)),
12046 else => @compileError("bad field type: " ++ @typeName(field_type)),
1202312047 };
1202412048 return .{
1202512049 .data = result,
12026 .trail = .{ .index = index + @as(Constant.Item.ExtraIndex, @intCast(fields.len)) },
12050 .trail = .{ .index = index + @as(Constant.Item.ExtraIndex, @intCast(info.field_names.len)) },
1202712051 };
1202812052}
1202912053
......@@ -12041,19 +12065,20 @@ fn ensureUnusedMetadataCapacity(
1204112065 try self.metadata_items.ensureUnusedCapacity(self.gpa, count);
1204212066 try self.metadata_extra.ensureUnusedCapacity(
1204312067 self.gpa,
12044 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),
12068 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
1204512069 );
1204612070}
1204712071
1204812072fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.ExtraIndex {
1204912073 const result: Metadata.Item.ExtraIndex = @intCast(self.metadata_extra.items.len);
12050 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {
12051 const value = @field(extra, field.name);
12052 self.metadata_extra.appendAssumeCapacity(switch (field.type) {
12074 const info = @typeInfo(@TypeOf(extra)).@"struct";
12075 inline for (info.field_names, info.field_types) |field_name, field_type| {
12076 const value = @field(extra, field_name);
12077 self.metadata_extra.appendAssumeCapacity(switch (field_type) {
1205312078 u32 => value,
1205412079 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value),
1205512080 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
12056 else => @compileError("bad field type: " ++ @typeName(field.type)),
12081 else => @compileError("bad field type: " ++ @typeName(field_type)),
1205712082 });
1205812083 }
1205912084 return result;
......@@ -12086,17 +12111,21 @@ fn metadataExtraDataTrail(
1208612111 index: Metadata.Item.ExtraIndex,
1208712112) struct { data: T, trail: MetadataExtraDataTrail } {
1208812113 var result: T = undefined;
12089 const fields = @typeInfo(T).@"struct".fields;
12090 inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value|
12091 @field(result, field.name) = switch (field.type) {
12114 const info = @typeInfo(T).@"struct";
12115 inline for (
12116 info.field_names,
12117 info.field_types,
12118 self.metadata_extra.items[index..][0..info.field_names.len],
12119 ) |field_name, field_type, value|
12120 @field(result, field_name) = switch (field_type) {
1209212121 u32 => value,
1209312122 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value),
1209412123 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
12095 else => @compileError("bad field type: " ++ @typeName(field.type)),
12124 else => @compileError("bad field type: " ++ @typeName(field_type)),
1209612125 };
1209712126 return .{
1209812127 .data = result,
12099 .trail = .{ .index = index + @as(Metadata.Item.ExtraIndex, @intCast(fields.len)) },
12128 .trail = .{ .index = index + @as(Metadata.Item.ExtraIndex, @intCast(info.field_names.len)) },
1210012129 };
1210112130}
1210212131
......@@ -12602,8 +12631,8 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
1260212631 builder: *const Builder,
1260312632 pub fn hash(_: @This(), key: Key) u32 {
1260412633 var hasher = std.hash.Wyhash.init(std.hash.int(@intFromEnum(key.tag)));
12605 inline for (std.meta.fields(@TypeOf(value))) |field| {
12606 hasher.update(std.mem.asBytes(&@field(key.value, field.name)));
12634 inline for (comptime std.meta.fieldNames(@TypeOf(value))) |field_name| {
12635 hasher.update(std.mem.asBytes(&@field(key.value, field_name)));
1260712636 }
1260812637 return @truncate(hasher.final());
1260912638 }
......@@ -14184,12 +14213,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
1418414213 const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock;
1418514214 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);
1418614215
14187 inline for (@typeInfo(ir.FixedMetadataKind).@"enum".fields) |field| {
14216 const info = @typeInfo(ir.FixedMetadataKind).@"enum";
14217
14218 inline for (info.field_names, info.field_values) |field_name, field_value| {
1418814219 // don't include `dbg` in stripped functions
14189 if (!(self.strip and std.mem.eql(u8, field.name, "dbg"))) {
14220 if (!(self.strip and std.mem.eql(u8, field_name, "dbg"))) {
1419014221 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
14191 .id = field.value,
14192 .name = field.name,
14222 .id = field_value,
14223 .name = field_name,
1419314224 });
1419414225 }
1419514226 }
lib/std/zig/llvm/bitcode_writer.zig+4-4
......@@ -246,14 +246,14 @@ pub fn BitcodeWriter(comptime types: []const type) type {
246246
247247 try self.bitcode.writeBits(comptime abbrevId(Abbrev), abbrev_len);
248248
249 const fields = std.meta.fields(Abbrev);
249 const field_names = comptime std.meta.fieldNames(Abbrev);
250250
251251 // This abbreviation might only contain literals
252 if (fields.len == 0) return;
252 if (field_names.len == 0) return;
253253
254254 comptime var field_index: usize = 0;
255255 inline for (Abbrev.ops) |ty| {
256 const param = @field(params, fields[field_index].name);
256 const param = @field(params, field_names[field_index]);
257257 switch (ty) {
258258 .literal => continue,
259259 .fixed => |len| try self.bitcode.writeBits(adapter.get(param), len),
......@@ -296,7 +296,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
296296 },
297297 }
298298 field_index += 1;
299 if (field_index == fields.len) break;
299 if (field_index == field_names.len) break;
300300 }
301301 }
302302
lib/std/zig/system.zig+4-4
......@@ -973,10 +973,10 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ
973973 // relying on `builtin.target`.
974974 const all_abis = comptime blk: {
975975 assert(@intFromEnum(Target.Abi.none) == 0);
976 const fields = std.meta.fields(Target.Abi)[1..];
977 var array: [fields.len]Target.Abi = undefined;
978 for (fields, 0..) |field, i| {
979 array[i] = @field(Target.Abi, field.name);
976 const field_names = std.meta.fieldNames(Target.Abi)[1..];
977 var array: [field_names.len]Target.Abi = undefined;
978 for (field_names, 0..) |field_name, i| {
979 array[i] = @field(Target.Abi, field_name);
980980 }
981981 break :blk array;
982982 };
lib/std/zig/system/windows.zig+11-11
......@@ -60,14 +60,14 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
6060 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
6161 }
6262
63 const fields_info = args_type_info.@"struct".fields;
63 const fields_info = args_type_info.@"struct";
6464
6565 // Originally, I wanted to issue a single call with a more complex table structure such that we
6666 // would sequentially visit each CPU#d subkey in the registry and pull the value of interest into
6767 // a buffer, however, NT seems to be expecting a single buffer per each table meaning we would
6868 // end up pulling only the last CPU core info, overwriting everything else.
6969 // If anyone can come up with a solution to this, please do!
70 const table_size = 1 + fields_info.len;
70 const table_size = 1 + fields_info.field_names.len;
7171 var table: [table_size + 1]std.os.windows.RTL_QUERY_REGISTRY_TABLE = undefined;
7272
7373 const topkey = std.unicode.utf8ToUtf16LeStringLiteral("\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor");
......@@ -90,11 +90,11 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
9090 .DefaultLength = 0,
9191 };
9292
93 var tmp_bufs: [fields_info.len][max_value_len]u8 align(@alignOf(std.os.windows.UNICODE_STRING)) = undefined;
93 var tmp_bufs: [fields_info.field_names.len][max_value_len]u8 align(@alignOf(std.os.windows.UNICODE_STRING)) = undefined;
9494
95 inline for (fields_info, 0..) |field, i| {
95 inline for (fields_info.field_names, 0..) |field_name, i| {
9696 const ctx: *anyopaque = blk: {
97 switch (@field(args, field.name).value_type) {
97 switch (@field(args, field_name).value_type) {
9898 .SZ,
9999 .EXPAND_SZ,
100100 .MULTI_SZ,
......@@ -119,7 +119,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
119119 };
120120
121121 var key_buf: [max_value_len / 2 + 1]u16 = undefined;
122 const key_len = try std.unicode.utf8ToUtf16Le(&key_buf, @field(args, field.name).key);
122 const key_len = try std.unicode.utf8ToUtf16Le(&key_buf, @field(args, field_name).key);
123123 key_buf[key_len] = 0;
124124
125125 table[i + 1] = .{
......@@ -153,12 +153,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
153153 );
154154 switch (res) {
155155 .SUCCESS => {
156 inline for (fields_info, 0..) |field, i| switch (@field(args, field.name).value_type) {
156 inline for (fields_info.field_names, 0..) |field_name, i| switch (@field(args, field_name).value_type) {
157157 .SZ,
158158 .EXPAND_SZ,
159159 .MULTI_SZ,
160160 => {
161 var buf = @field(args, field.name).value_buf;
161 var buf = @field(args, field_name).value_buf;
162162 const entry: *const std.os.windows.UNICODE_STRING = @ptrCast(table[i + 1].EntryContext);
163163 const len = try std.unicode.utf16LeToUtf8(buf, entry.slice());
164164 buf[len] = 0;
......@@ -169,12 +169,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
169169 .QWORD,
170170 => {
171171 const entry: [*]const u8 = @ptrCast(table[i + 1].EntryContext);
172 switch (@field(args, field.name).value_type) {
172 switch (@field(args, field_name).value_type) {
173173 .DWORD, .DWORD_BIG_ENDIAN => {
174 @memcpy(@field(args, field.name).value_buf[0..4], entry[0..4]);
174 @memcpy(@field(args, field_name).value_buf[0..4], entry[0..4]);
175175 },
176176 .QWORD => {
177 @memcpy(@field(args, field.name).value_buf[0..8], entry[0..8]);
177 @memcpy(@field(args, field_name).value_buf[0..8], entry[0..8]);
178178 },
179179 else => unreachable,
180180 }
lib/std/zon/Serializer.zig+28-23
......@@ -165,7 +165,7 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
165165 },
166166 .@"struct" => |@"struct"| if (@"struct".is_tuple) {
167167 var container = try self.beginTuple(
168 .{ .whitespace_style = .{ .fields = @"struct".fields.len } },
168 .{ .whitespace_style = .{ .fields = @"struct".field_names.len } },
169169 );
170170 inline for (val) |field_value| {
171171 try container.fieldArbitraryDepth(field_value, options);
......@@ -173,15 +173,20 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
173173 try container.end();
174174 } else {
175175 // Decide which fields to emit
176 const fields, const skipped: [@"struct".fields.len]bool = if (options.emit_default_optional_fields) b: {
177 break :b .{ @"struct".fields.len, @splat(false) };
176 const fields, const skipped: [@"struct".field_names.len]bool = if (options.emit_default_optional_fields) b: {
177 break :b .{ @"struct".field_names.len, @splat(false) };
178178 } else b: {
179 var fields = @"struct".fields.len;
180 var skipped: [@"struct".fields.len]bool = @splat(false);
181 inline for (@"struct".fields, &skipped) |field_info, *skip| {
182 if (field_info.default_value_ptr) |ptr| {
183 const default: *const field_info.type = @ptrCast(@alignCast(ptr));
184 const field_value = @field(val, field_info.name);
179 var fields = @"struct".field_names.len;
180 var skipped: [@"struct".field_names.len]bool = @splat(false);
181 inline for (
182 @"struct".field_names,
183 @"struct".field_types,
184 @"struct".field_attrs,
185 &skipped,
186 ) |field_name, field_type, field_attrs, *skip| {
187 if (field_attrs.default_value_ptr) |ptr| {
188 const default: *const field_type = @ptrCast(@alignCast(ptr));
189 const field_value = @field(val, field_name);
185190 if (std.meta.eql(field_value, default.*)) {
186191 skip.* = true;
187192 fields -= 1;
......@@ -195,11 +200,11 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
195200 var container = try self.beginStruct(
196201 .{ .whitespace_style = .{ .fields = fields } },
197202 );
198 inline for (@"struct".fields, skipped) |field_info, skip| {
203 inline for (@"struct".field_names, skipped) |field_name, skip| {
199204 if (!skip) {
200205 try container.fieldArbitraryDepth(
201 field_info.name,
202 @field(val, field_info.name),
206 field_name,
207 @field(val, field_name),
203208 options,
204209 );
205210 }
......@@ -713,11 +718,11 @@ fn typeIsRecursiveInner(comptime T: type, comptime prev_visited: []const type) b
713718 .optional => |optional| typeIsRecursiveInner(optional.child, visited),
714719 .array => |array| typeIsRecursiveInner(array.child, visited),
715720 .vector => |vector| typeIsRecursiveInner(vector.child, visited),
716 .@"struct" => |@"struct"| for (@"struct".fields) |field| {
717 if (typeIsRecursiveInner(field.type, visited)) break true;
721 .@"struct" => |@"struct"| for (@"struct".field_types) |field_type| {
722 if (typeIsRecursiveInner(field_type, visited)) break true;
718723 } else false,
719 .@"union" => |@"union"| inline for (@"union".fields) |field| {
720 if (typeIsRecursiveInner(field.type, visited)) break true;
724 .@"union" => |@"union"| inline for (@"union".field_types) |field_type| {
725 if (typeIsRecursiveInner(field_type, visited)) break true;
721726 } else false,
722727 else => false,
723728 };
......@@ -761,8 +766,8 @@ fn checkValueDepth(val: anytype, depth: usize) error{ExceededMaxDepth}!void {
761766 .array => for (val) |item| {
762767 try checkValueDepth(item, child_depth);
763768 },
764 .@"struct" => |@"struct"| inline for (@"struct".fields) |field_info| {
765 try checkValueDepth(@field(val, field_info.name), child_depth);
769 .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| {
770 try checkValueDepth(@field(val, field_name), child_depth);
766771 },
767772 .@"union" => |@"union"| if (@"union".tag_type == null) {
768773 return;
......@@ -851,7 +856,7 @@ fn canSerializeTypeInner(
851856 .@"opaque",
852857 => false,
853858
854 .@"enum" => |@"enum"| @"enum".is_exhaustive,
859 .@"enum" => |@"enum"| @"enum".mode == .exhaustive,
855860
856861 .pointer => |pointer| switch (pointer.size) {
857862 .one => canSerializeTypeInner(pointer.child, visited, parent_is_optional),
......@@ -870,8 +875,8 @@ fn canSerializeTypeInner(
870875 .@"struct" => |@"struct"| {
871876 for (visited) |V| if (T == V) return true;
872877 const new_visited = visited ++ .{T};
873 for (@"struct".fields) |field| {
874 if (!canSerializeTypeInner(field.type, new_visited, false)) return false;
878 for (@"struct".field_types) |field_type| {
879 if (!canSerializeTypeInner(field_type, new_visited, false)) return false;
875880 }
876881 return true;
877882 },
......@@ -879,8 +884,8 @@ fn canSerializeTypeInner(
879884 for (visited) |V| if (T == V) return true;
880885 const new_visited = visited ++ .{T};
881886 if (@"union".tag_type == null) return false;
882 for (@"union".fields) |field| {
883 if (field.type != void and !canSerializeTypeInner(field.type, new_visited, false)) {
887 for (@"union".field_types) |field_type| {
888 if (field_type != void and !canSerializeTypeInner(field_type, new_visited, false)) {
884889 return false;
885890 }
886891 }
lib/std/zon/parse.zig+58-61
......@@ -437,8 +437,8 @@ pub fn free(gpa: Allocator, value: anytype) void {
437437 const array: [vector.len]vector.child = value;
438438 freeArray(gpa, @TypeOf(array), &array);
439439 },
440 .@"struct" => |@"struct"| inline for (@"struct".fields) |field| {
441 free(gpa, @field(value, field.name));
440 .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| {
441 free(gpa, @field(value, field_name));
442442 },
443443 .@"union" => |@"union"| if (@"union".tag_type == null) {
444444 if (comptime requiresAllocator(Value)) unreachable;
......@@ -464,13 +464,13 @@ fn requiresAllocator(T: type) bool {
464464 return switch (@typeInfo(T)) {
465465 .pointer => true,
466466 .array => |array| return array.len > 0 and requiresAllocator(array.child),
467 .@"struct" => |@"struct"| inline for (@"struct".fields) |field| {
468 if (requiresAllocator(field.type)) {
467 .@"struct" => |@"struct"| inline for (@"struct".field_types) |field_type| {
468 if (requiresAllocator(field_type)) {
469469 break true;
470470 }
471471 } else false,
472 .@"union" => |@"union"| inline for (@"union".fields) |field| {
473 if (requiresAllocator(field.type)) {
472 .@"union" => |@"union"| inline for (@"union".field_types) |field_type| {
473 if (requiresAllocator(field_type)) {
474474 break true;
475475 }
476476 } else false,
......@@ -589,9 +589,9 @@ const Parser = struct {
589589 .one => return self.failExpectedTypeInner(pointer.child, opt, node),
590590 .slice => {
591591 if (pointer.child == u8 and
592 pointer.is_const and
592 pointer.attrs.@"const" and
593593 (pointer.sentinel() == null or pointer.sentinel() == 0) and
594 (pointer.alignment == null or pointer.alignment == 1))
594 (pointer.attrs.@"align" == null or pointer.attrs.@"align" == 1))
595595 {
596596 if (opt) {
597597 return self.failNode(node, "expected optional string");
......@@ -669,10 +669,10 @@ const Parser = struct {
669669 switch (node.get(self.zoir)) {
670670 .enum_literal => |field_name| {
671671 // Create a comptime string map for the enum fields
672 const enum_fields = @typeInfo(T).@"enum".fields;
673 comptime var kvs_list: [enum_fields.len]struct { []const u8, T } = undefined;
674 inline for (enum_fields, 0..) |field, i| {
675 kvs_list[i] = .{ field.name, @enumFromInt(field.value) };
672 const enum_info = @typeInfo(T).@"enum";
673 comptime var kvs_list: [enum_info.field_names.len]struct { []const u8, T } = undefined;
674 inline for (enum_info.field_names, enum_info.field_values, 0..) |enum_field_name, enum_field_value, i| {
675 kvs_list[i] = .{ enum_field_name, @enumFromInt(enum_field_value) };
676676 }
677677 const enum_tags = std.StaticStringMap(T).initComptime(kvs_list);
678678
......@@ -715,9 +715,9 @@ const Parser = struct {
715715
716716 if (pointer.child != u8 or
717717 pointer.size != .slice or
718 !pointer.is_const or
718 !pointer.attrs.@"const" or
719719 (pointer.sentinel() != null and pointer.sentinel() != 0) or
720 (pointer.alignment != null and pointer.alignment != 1))
720 (pointer.attrs.@"align" != null and pointer.attrs.@"align" != 1))
721721 {
722722 return error.WrongType;
723723 }
......@@ -742,7 +742,7 @@ const Parser = struct {
742742 const slice = try self.gpa.allocWithOptions(
743743 pointer.child,
744744 nodes.len,
745 .fromByteUnitsOptional(pointer.alignment),
745 .fromByteUnitsOptional(pointer.attrs.@"align"),
746746 pointer.sentinel(),
747747 );
748748 errdefer self.gpa.free(slice);
......@@ -808,30 +808,30 @@ const Parser = struct {
808808 else => return error.WrongType,
809809 };
810810
811 const field_infos = @typeInfo(T).@"struct".fields;
811 const info = @typeInfo(T).@"struct";
812812
813813 // Build a map from field name to index.
814814 // The special value `comptime_field` indicates that this is actually a comptime field.
815815 const comptime_field = std.math.maxInt(usize);
816816 const field_indices: std.StaticStringMap(usize) = comptime b: {
817 var kvs_list: [field_infos.len]struct { []const u8, usize } = undefined;
818 for (&kvs_list, field_infos, 0..) |*kv, field, i| {
819 kv.* = .{ field.name, if (field.is_comptime) comptime_field else i };
817 var kvs_list: [info.field_names.len]struct { []const u8, usize } = undefined;
818 for (&kvs_list, info.field_names, info.field_attrs, 0..) |*kv, field_name, field_attrs, i| {
819 kv.* = .{ field_name, if (field_attrs.@"comptime") comptime_field else i };
820820 }
821821 break :b .initComptime(kvs_list);
822822 };
823823
824824 // Parse the struct
825825 var result: T = undefined;
826 var field_found: [field_infos.len]bool = @splat(false);
826 var field_found: [info.field_names.len]bool = @splat(false);
827827
828828 // If we fail partway through, free all already initialized fields
829829 var initialized: usize = 0;
830 errdefer if (self.options.free_on_error and field_infos.len > 0) {
830 errdefer if (self.options.free_on_error and info.field_names.len > 0) {
831831 for (fields.names[0..initialized]) |name_runtime| {
832832 switch (field_indices.get(name_runtime.get(self.zoir)) orelse continue) {
833 inline 0...(field_infos.len - 1) => |name_index| {
834 const name = field_infos[name_index].name;
833 inline 0...(info.field_names.len - 1) => |name_index| {
834 const name = info.field_names[name_index];
835835 free(self.gpa, @field(result, name));
836836 },
837837 else => unreachable, // Can't be out of bounds
......@@ -856,11 +856,11 @@ const Parser = struct {
856856 field_found[field_index] = true;
857857
858858 switch (field_index) {
859 inline 0...(field_infos.len - 1) => |j| {
860 if (field_infos[j].is_comptime) unreachable;
859 inline 0...(info.field_names.len - 1) => |j| {
860 if (info.field_attrs[j].@"comptime") unreachable;
861861
862 @field(result, field_infos[j].name) = try self.parseExpr(
863 field_infos[j].type,
862 @field(result, info.field_names[j]) = try self.parseExpr(
863 info.field_types[j],
864864 fields.vals.at(@intCast(i)),
865865 );
866866 },
......@@ -873,15 +873,14 @@ const Parser = struct {
873873 // Fill in any missing default fields
874874 inline for (field_found, 0..) |found, i| {
875875 if (!found) {
876 const field_info = field_infos[i];
877 if (field_info.default_value_ptr) |default| {
878 const typed: *const field_info.type = @ptrCast(@alignCast(default));
879 @field(result, field_info.name) = typed.*;
876 const field_attrs = info.field_attrs[i];
877 if (field_attrs.defaultValue(info.field_types[i])) |default| {
878 @field(result, info.field_names[i]) = default;
880879 } else {
881880 return self.failNodeFmt(
882881 node,
883882 "missing required field {s}",
884 .{field_infos[i].name},
883 .{info.field_names[i]},
885884 );
886885 }
887886 }
......@@ -898,22 +897,21 @@ const Parser = struct {
898897 };
899898
900899 var result: T = undefined;
901 const field_infos = @typeInfo(T).@"struct".fields;
900 const info = @typeInfo(T).@"struct";
902901
903 if (nodes.len > field_infos.len) {
902 if (nodes.len > info.field_names.len) {
904903 return self.failNodeFmt(
905 nodes.at(field_infos.len),
904 nodes.at(info.field_names.len),
906905 "index {} outside of tuple length {}",
907 .{ field_infos.len, field_infos.len },
906 .{ info.field_names.len, info.field_names.len },
908907 );
909908 }
910909
911 inline for (0..field_infos.len) |i| {
910 inline for (0..info.field_names.len) |i| {
912911 // Check if we're out of bounds
913912 if (i >= nodes.len) {
914 if (field_infos[i].default_value_ptr) |default| {
915 const typed: *const field_infos[i].type = @ptrCast(@alignCast(default));
916 @field(result, field_infos[i].name) = typed.*;
913 if (info.field_attrs[i].defaultValue(info.field_types[i])) |default| {
914 @field(result, info.field_names[i]) = default;
917915 } else {
918916 return self.failNodeFmt(node, "missing tuple field with index {}", .{i});
919917 }
......@@ -926,10 +924,10 @@ const Parser = struct {
926924 }
927925 };
928926
929 if (field_infos[i].is_comptime) {
927 if (info.field_attrs[i].@"comptime") {
930928 return self.failComptimeField(node, i);
931929 } else {
932 result[i] = try self.parseExpr(field_infos[i].type, nodes.at(i));
930 result[i] = try self.parseExpr(info.field_types[i], nodes.at(i));
933931 }
934932 }
935933 }
......@@ -939,15 +937,14 @@ const Parser = struct {
939937
940938 fn parseUnion(self: *@This(), T: type, node: Zoir.Node.Index) !T {
941939 const @"union" = @typeInfo(T).@"union";
942 const field_infos = @"union".fields;
943940
944 if (field_infos.len == 0) comptime unreachable;
941 if (@"union".field_names.len == 0) comptime unreachable;
945942
946943 // Gather info on the fields
947944 const field_indices = b: {
948 comptime var kvs_list: [field_infos.len]struct { []const u8, usize } = undefined;
949 inline for (field_infos, 0..) |field, i| {
950 kvs_list[i] = .{ field.name, i };
945 comptime var kvs_list: [@"union".field_names.len]struct { []const u8, usize } = undefined;
946 inline for (@"union".field_names, 0..) |field_name, i| {
947 kvs_list[i] = .{ field_name, i };
951948 }
952949 break :b std.StaticStringMap(usize).initComptime(kvs_list);
953950 };
......@@ -970,13 +967,13 @@ const Parser = struct {
970967
971968 // Initialize the union from the given field.
972969 switch (field_index) {
973 inline 0...field_infos.len - 1 => |i| {
970 inline 0...@"union".field_names.len - 1 => |i| {
974971 // Fail if the field is not void
975 if (field_infos[i].type != void)
972 if (@"union".field_types[i] != void)
976973 return self.failNode(node, "expected union");
977974
978975 // Instantiate the union
979 return @unionInit(T, field_infos[i].name, {});
976 return @unionInit(T, @"union".field_names[i], {});
980977 },
981978 else => unreachable, // Can't be out of bounds
982979 }
......@@ -994,12 +991,12 @@ const Parser = struct {
994991 return self.failUnexpected(T, "field", node, 0, field_name_str);
995992
996993 switch (field_index) {
997 inline 0...field_infos.len - 1 => |i| {
998 if (field_infos[i].type == void) {
994 inline 0...@"union".field_names.len - 1 => |i| {
995 if (@"union".field_types[i] == void) {
999996 return self.failNode(field_val, "expected type 'void'");
1000997 } else {
1001 const value = try self.parseExpr(field_infos[i].type, field_val);
1002 return @unionInit(T, field_infos[i].name, value);
998 const value = try self.parseExpr(@"union".field_types[i], field_val);
999 return @unionInit(T, @"union".field_names[i], value);
10031000 }
10041001 },
10051002 else => unreachable, // Can't be out of bounds
......@@ -1106,7 +1103,7 @@ const Parser = struct {
11061103 } else self.ast.nodeMainToken(node.getAstNode(self.zoir));
11071104 switch (@typeInfo(T)) {
11081105 inline .@"struct", .@"union", .@"enum" => |info| {
1109 const note: Error.TypeCheckFailure.Note = if (info.fields.len == 0) b: {
1106 const note: Error.TypeCheckFailure.Note = if (info.field_names.len == 0) b: {
11101107 break :b .{
11111108 .token = token,
11121109 .offset = 0,
......@@ -1118,9 +1115,9 @@ const Parser = struct {
11181115 var buf: std.ArrayList(u8) = try .initCapacity(gpa, 64);
11191116 defer buf.deinit(gpa);
11201117 try buf.appendSlice(gpa, msg);
1121 inline for (info.fields, 0..) |field_info, i| {
1118 inline for (info.field_names, 0..) |field_name, i| {
11221119 if (i != 0) try buf.appendSlice(gpa, ", ");
1123 try buf.print(gpa, "'{f}'", .{std.zig.fmtIdFlags(field_info.name, .{
1120 try buf.print(gpa, "'{f}'", .{std.zig.fmtIdFlags(field_name, .{
11241121 .allow_primitive = true,
11251122 .allow_underscore = true,
11261123 })});
......@@ -1236,8 +1233,8 @@ fn canParseTypeInner(
12361233 .@"struct" => |@"struct"| {
12371234 for (visited) |V| if (T == V) return true;
12381235 const new_visited = visited ++ .{T};
1239 for (@"struct".fields) |field| {
1240 if (!field.is_comptime and !canParseTypeInner(field.type, new_visited, false)) {
1236 for (@"struct".field_types, @"struct".field_attrs) |field_type, field_attrs| {
1237 if (!field_attrs.@"comptime" and !canParseTypeInner(field_type, new_visited, false)) {
12411238 return false;
12421239 }
12431240 }
......@@ -1246,8 +1243,8 @@ fn canParseTypeInner(
12461243 .@"union" => |@"union"| {
12471244 for (visited) |V| if (T == V) return true;
12481245 const new_visited = visited ++ .{T};
1249 for (@"union".fields) |field| {
1250 if (field.type != void and !canParseTypeInner(field.type, new_visited, false)) {
1246 for (@"union".field_types) |field_type| {
1247 if (field_type != void and !canParseTypeInner(field_type, new_visited, false)) {
12511248 return false;
12521249 }
12531250 }
src/Air.zig+4-4
......@@ -1805,15 +1805,15 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
18051805/// Returns the requested data, as well as the new index which is at the start of the
18061806/// trailers for the object.
18071807pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } {
1808 const fields = std.meta.fields(T);
1808 const info = @typeInfo(T).@"struct";
18091809 var i: usize = index;
18101810 var result: T = undefined;
1811 inline for (fields) |field| {
1812 @field(result, field.name) = switch (field.type) {
1811 inline for (info.field_names, info.field_types) |field_name, field_type| {
1812 @field(result, field_name) = switch (field_type) {
18131813 u32 => air.extra.items[i],
18141814 InternPool.Index, Inst.Ref => @enumFromInt(air.extra.items[i]),
18151815 i32, CondBr.BranchHints, Asm.Flags => @bitCast(air.extra.items[i]),
1816 else => @compileError("bad field type: " ++ @typeName(field.type)),
1816 else => @compileError("bad field type: " ++ @typeName(field_type)),
18171817 };
18181818 i += 1;
18191819 }
src/Air/Legalize.zig+8-8
......@@ -2635,7 +2635,7 @@ const Block = struct {
26352635 .data = .{ .legalize_compiler_rt_call = .{
26362636 .func = func,
26372637 .payload = payload: {
2638 const extra_len = @typeInfo(Air.Call).@"struct".fields.len + args.len;
2638 const extra_len = @typeInfo(Air.Call).@"struct".field_names.len + args.len;
26392639 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_len);
26402640 const index = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable;
26412641 l.air_extra.appendSliceAssumeCapacity(@ptrCast(args));
......@@ -2913,12 +2913,12 @@ fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index {
29132913}
29142914
29152915fn addExtra(l: *Legalize, comptime Extra: type, extra: Extra) Error!u32 {
2916 const extra_fields = @typeInfo(Extra).@"struct".fields;
2917 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_fields.len);
2918 defer inline for (extra_fields) |field| l.air_extra.appendAssumeCapacity(switch (field.type) {
2919 u32 => @field(extra, field.name),
2920 Air.Inst.Ref => @intFromEnum(@field(extra, field.name)),
2921 else => @compileError(@typeName(field.type)),
2916 const extra_info = @typeInfo(Extra).@"struct";
2917 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_info.field_names.len);
2918 defer inline for (extra_info.field_names, extra_info.field_types) |field_name, field_type| l.air_extra.appendAssumeCapacity(switch (field_type) {
2919 u32 => @field(extra, field_name),
2920 Air.Inst.Ref => @intFromEnum(@field(extra, field_name)),
2921 else => @compileError(@typeName(field_type)),
29222922 });
29232923 return @intCast(l.air_extra.items.len);
29242924}
......@@ -2954,7 +2954,7 @@ fn compilerRtCall(
29542954 const func_ret_ty = func.returnType();
29552955
29562956 if (func_ret_ty.toIntern() == result_ty.toIntern()) {
2957 try l.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Call).@"struct".fields.len + args.len);
2957 try l.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Call).@"struct".field_names.len + args.len);
29582958 const payload = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable;
29592959 l.air_extra.appendSliceAssumeCapacity(@ptrCast(args));
29602960 return l.replaceInst(orig_inst, .legalize_compiler_rt_call, .{ .legalize_compiler_rt_call = .{
src/Air/Liveness.zig+8-8
......@@ -351,17 +351,17 @@ const Analysis = struct {
351351 extra: std.ArrayList(u32),
352352
353353 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {
354 const fields = std.meta.fields(@TypeOf(extra));
355 try a.extra.ensureUnusedCapacity(a.gpa, fields.len);
354 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
355 try a.extra.ensureUnusedCapacity(a.gpa, field_count);
356356 return addExtraAssumeCapacity(a, extra);
357357 }
358358
359359 fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 {
360 const fields = std.meta.fields(@TypeOf(extra));
360 const info = @typeInfo(@TypeOf(extra)).@"struct";
361361 const result = @as(u32, @intCast(a.extra.items.len));
362 inline for (fields) |field| {
363 a.extra.appendAssumeCapacity(switch (field.type) {
364 u32 => @field(extra, field.name),
362 inline for (info.field_names, info.field_types) |field_name, field_type| {
363 a.extra.appendAssumeCapacity(switch (field_type) {
364 u32 => @field(extra, field_name),
365365 else => @compileError("bad field type"),
366366 });
367367 }
......@@ -1002,7 +1002,7 @@ fn analyzeInstBlock(
10021002 const block_scope = data.block_scopes.get(inst).?;
10031003 const num_deaths = data.live_set.count() - block_scope.live_set.count();
10041004
1005 try a.extra.ensureUnusedCapacity(gpa, num_deaths + std.meta.fields(Block).len);
1005 try a.extra.ensureUnusedCapacity(gpa, num_deaths + std.meta.fieldNames(Block).len);
10061006 const extra_index = a.addExtraAssumeCapacity(Block{
10071007 .death_count = num_deaths,
10081008 });
......@@ -1265,7 +1265,7 @@ fn analyzeInstCondBr(
12651265 // Write the mirrored deaths to `extra`
12661266 const then_death_count = @as(u32, @intCast(then_mirrored_deaths.items.len));
12671267 const else_death_count = @as(u32, @intCast(else_mirrored_deaths.items.len));
1268 try a.extra.ensureUnusedCapacity(gpa, std.meta.fields(CondBr).len + then_death_count + else_death_count);
1268 try a.extra.ensureUnusedCapacity(gpa, std.meta.fieldNames(CondBr).len + then_death_count + else_death_count);
12691269 const extra_index = a.addExtraAssumeCapacity(CondBr{
12701270 .then_death_count = then_death_count,
12711271 .else_death_count = else_death_count,
src/Builtin.zig+3-3
......@@ -23,8 +23,8 @@ wasi_exec_model: std.lang.WasiExecModel,
2323/// of the resulting file contents.
2424pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {
2525 var h: Cache.Hasher = Cache.hasher_init;
26 inline for (@typeInfo(@This()).@"struct".fields) |f| {
27 if (comptime std.mem.eql(u8, f.name, "target")) {
26 inline for (@typeInfo(@This()).@"struct".field_names) |f_name| {
27 if (comptime std.mem.eql(u8, f_name, "target")) {
2828 // This needs special handling.
2929 std.hash.autoHash(&h, opts.target.cpu);
3030 std.hash.autoHash(&h, opts.target.os.tag);
......@@ -33,7 +33,7 @@ pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {
3333 std.hash.autoHash(&h, opts.target.ofmt);
3434 std.hash.autoHash(&h, opts.target.dynamic_linker);
3535 } else {
36 std.hash.autoHash(&h, @field(opts, f.name));
36 std.hash.autoHash(&h, @field(opts, f_name));
3737 }
3838 }
3939 return h.finalResult();
src/Compilation.zig+18-18
......@@ -298,15 +298,15 @@ const QueuedJobs = struct {
298298 ubsan_rt_lib: bool = false,
299299 ubsan_rt_obj: bool = false,
300300 fuzzer_lib: bool = false,
301 musl_crt_file: [@typeInfo(musl.CrtFile).@"enum".fields.len]bool = @splat(false),
302 glibc_crt_file: [@typeInfo(glibc.CrtFile).@"enum".fields.len]bool = @splat(false),
303 freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".fields.len]bool = @splat(false),
304 netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".fields.len]bool = @splat(false),
305 openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".fields.len]bool = @splat(false),
301 musl_crt_file: [@typeInfo(musl.CrtFile).@"enum".field_names.len]bool = @splat(false),
302 glibc_crt_file: [@typeInfo(glibc.CrtFile).@"enum".field_names.len]bool = @splat(false),
303 freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".field_names.len]bool = @splat(false),
304 netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".field_names.len]bool = @splat(false),
305 openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".field_names.len]bool = @splat(false),
306306 /// one of WASI libc static objects
307 wasi_libc_crt_file: [@typeInfo(wasi_libc.CrtFile).@"enum".fields.len]bool = @splat(false),
307 wasi_libc_crt_file: [@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len]bool = @splat(false),
308308 /// one of the mingw-w64 static objects
309 mingw_crt_file: [@typeInfo(mingw.CrtFile).@"enum".fields.len]bool = @splat(false),
309 mingw_crt_file: [@typeInfo(mingw.CrtFile).@"enum".field_names.len]bool = @splat(false),
310310 /// all of the glibc shared objects
311311 glibc_shared_objects: bool = false,
312312 freebsd_shared_objects: bool = false,
......@@ -2552,10 +2552,10 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
25522552 error.LibCInstallationMissingCrtDir => return diag.fail(.libc_installation_missing_crt_dir),
25532553 };
25542554
2555 const fields = @typeInfo(@TypeOf(paths)).@"struct".fields;
2556 try comp.oneshot_prelink_tasks.ensureUnusedCapacity(gpa, fields.len + 1);
2557 inline for (fields) |field| {
2558 if (@field(paths, field.name)) |path| {
2555 const field_names = @typeInfo(@TypeOf(paths)).@"struct".field_names;
2556 try comp.oneshot_prelink_tasks.ensureUnusedCapacity(gpa, field_names.len + 1);
2557 inline for (field_names) |field_name| {
2558 if (@field(paths, field_name)) |path| {
25592559 comp.oneshot_prelink_tasks.appendAssumeCapacity(.{ .load_object = path });
25602560 }
25612561 }
......@@ -4667,49 +4667,49 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node
46674667 prelink_group.async(io, buildLibZigC, .{ comp, main_progress_node });
46684668 }
46694669
4670 for (0..@typeInfo(musl.CrtFile).@"enum".fields.len) |i| {
4670 for (0..@typeInfo(musl.CrtFile).@"enum".field_names.len) |i| {
46714671 if (comp.queued_jobs.musl_crt_file[i]) {
46724672 const tag: musl.CrtFile = @enumFromInt(i);
46734673 prelink_group.async(io, buildMuslCrtFile, .{ comp, tag, main_progress_node });
46744674 }
46754675 }
46764676
4677 for (0..@typeInfo(glibc.CrtFile).@"enum".fields.len) |i| {
4677 for (0..@typeInfo(glibc.CrtFile).@"enum".field_names.len) |i| {
46784678 if (comp.queued_jobs.glibc_crt_file[i]) {
46794679 const tag: glibc.CrtFile = @enumFromInt(i);
46804680 prelink_group.async(io, buildGlibcCrtFile, .{ comp, tag, main_progress_node });
46814681 }
46824682 }
46834683
4684 for (0..@typeInfo(freebsd.CrtFile).@"enum".fields.len) |i| {
4684 for (0..@typeInfo(freebsd.CrtFile).@"enum".field_names.len) |i| {
46854685 if (comp.queued_jobs.freebsd_crt_file[i]) {
46864686 const tag: freebsd.CrtFile = @enumFromInt(i);
46874687 prelink_group.async(io, buildFreeBSDCrtFile, .{ comp, tag, main_progress_node });
46884688 }
46894689 }
46904690
4691 for (0..@typeInfo(netbsd.CrtFile).@"enum".fields.len) |i| {
4691 for (0..@typeInfo(netbsd.CrtFile).@"enum".field_names.len) |i| {
46924692 if (comp.queued_jobs.netbsd_crt_file[i]) {
46934693 const tag: netbsd.CrtFile = @enumFromInt(i);
46944694 prelink_group.async(io, buildNetBSDCrtFile, .{ comp, tag, main_progress_node });
46954695 }
46964696 }
46974697
4698 for (0..@typeInfo(openbsd.CrtFile).@"enum".fields.len) |i| {
4698 for (0..@typeInfo(openbsd.CrtFile).@"enum".field_names.len) |i| {
46994699 if (comp.queued_jobs.openbsd_crt_file[i]) {
47004700 const tag: openbsd.CrtFile = @enumFromInt(i);
47014701 prelink_group.async(io, buildOpenBSDCrtFile, .{ comp, tag, main_progress_node });
47024702 }
47034703 }
47044704
4705 for (0..@typeInfo(wasi_libc.CrtFile).@"enum".fields.len) |i| {
4705 for (0..@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len) |i| {
47064706 if (comp.queued_jobs.wasi_libc_crt_file[i]) {
47074707 const tag: wasi_libc.CrtFile = @enumFromInt(i);
47084708 prelink_group.async(io, buildWasiLibcCrtFile, .{ comp, tag, main_progress_node });
47094709 }
47104710 }
47114711
4712 for (0..@typeInfo(mingw.CrtFile).@"enum".fields.len) |i| {
4712 for (0..@typeInfo(mingw.CrtFile).@"enum".field_names.len) |i| {
47134713 if (comp.queued_jobs.mingw_crt_file[i]) {
47144714 const tag: mingw.CrtFile = @enumFromInt(i);
47154715 prelink_group.async(io, buildMingwCrtFile, .{ comp, tag, main_progress_node });
src/InternPool.zig+108-107
......@@ -1070,17 +1070,15 @@ const Local = struct {
10701070
10711071 fn PtrArrayElem(comptime len: usize) type {
10721072 const elem_info = @typeInfo(Elem).@"struct";
1073 const elem_fields = elem_info.fields;
1074 var new_names: [elem_fields.len][]const u8 = undefined;
1075 var new_types: [elem_fields.len]type = undefined;
1076 for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| {
1077 new_name.* = elem_field.name;
1078 NewType.* = *[len]elem_field.type;
1073
1074 var new_types: [elem_info.field_types.len]type = undefined;
1075 for (&new_types, elem_info.field_types) |*NewType, elem_field_type| {
1076 NewType.* = *[len]elem_field_type;
10791077 }
10801078 if (elem_info.is_tuple) {
10811079 return @Tuple(&new_types);
10821080 } else {
1083 return @Struct(.auto, null, &new_names, &new_types, &@splat(.{}));
1081 return @Struct(.auto, null, elem_info.field_names, &new_types, &@splat(.{}));
10841082 }
10851083 }
10861084 fn PtrElem(comptime opts: struct {
......@@ -1088,17 +1086,14 @@ const Local = struct {
10881086 is_const: bool = false,
10891087 }) type {
10901088 const elem_info = @typeInfo(Elem).@"struct";
1091 const elem_fields = elem_info.fields;
1092 var new_names: [elem_fields.len][]const u8 = undefined;
1093 var new_types: [elem_fields.len]type = undefined;
1094 for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| {
1095 new_name.* = elem_field.name;
1096 NewType.* = @Pointer(opts.size, .{ .@"const" = opts.is_const }, elem_field.type, null);
1089 var new_types: [elem_info.field_types.len]type = undefined;
1090 for (&new_types, elem_info.field_types) |*NewType, elem_field_type| {
1091 NewType.* = @Pointer(opts.size, .{ .@"const" = opts.is_const }, elem_field_type, null);
10971092 }
10981093 if (elem_info.is_tuple) {
10991094 return @Tuple(&new_types);
11001095 } else {
1101 return @Struct(.auto, null, &new_names, &new_types, &@splat(.{}));
1096 return @Struct(.auto, null, elem_info.field_names, &new_types, &@splat(.{}));
11021097 }
11031098 }
11041099
......@@ -4295,48 +4290,51 @@ pub const Index = enum(u32) {
42954290 },
42964291 }) void {
42974292 _ = self;
4298 const map_fields = @typeInfo(@typeInfo(@TypeOf(tag_to_encoding_map)).pointer.child).@"struct".fields;
4293 const map_info = @typeInfo(@typeInfo(@TypeOf(tag_to_encoding_map)).pointer.child).@"struct";
42994294 @setEvalBranchQuota(3_000);
4300 inline for (@typeInfo(Tag).@"enum".fields, 0..) |tag, start| {
4301 inline for (0..map_fields.len) |offset| {
4302 if (comptime std.mem.eql(u8, tag.name, map_fields[(start + offset) % map_fields.len].name)) break;
4295 inline for (@typeInfo(Tag).@"enum".field_names, 0..) |tag_name, start| {
4296 inline for (0..map_info.field_names.len) |offset| {
4297 if (comptime std.mem.eql(u8, tag_name, map_info.field_names[(start + offset) % map_info.field_names.len])) break;
43034298 } else {
4304 @compileError(@typeName(Tag) ++ "." ++ tag.name ++ " missing dbHelper tag_to_encoding_map entry");
4299 @compileError(@typeName(Tag) ++ "." ++ tag_name ++ " missing dbHelper tag_to_encoding_map entry");
43054300 }
43064301 }
43074302 }
43084303 comptime {
43094304 if (!builtin.strip_debug_info) switch (builtin.zig_backend) {
43104305 .stage2_llvm => _ = &dbHelper,
4311 .stage2_x86_64 => for (@typeInfo(Tag).@"enum".fields) |tag| {
4312 if (!@hasField(@TypeOf(Tag.encodings), tag.name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name);
4313 const encoding = @field(Tag.encodings, tag.name);
4314 if (@hasField(@TypeOf(encoding), "trailing")) for (@typeInfo(encoding.trailing).@"struct".fields) |field| {
4315 struct {
4316 fn checkConfig(name: []const u8) void {
4317 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\"");
4318 const FieldType = @TypeOf(@field(encoding.config, name));
4319 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
4320 }
4321 fn checkField(name: []const u8, Type: type) void {
4322 switch (@typeInfo(Type)) {
4323 .int => {},
4324 .@"enum" => {},
4325 .@"struct" => |info| assert(info.layout == .@"packed"),
4326 .optional => |info| {
4327 checkConfig(name ++ ".?");
4328 checkField(name ++ ".?", info.child);
4329 },
4330 .pointer => |info| {
4331 assert(info.size == .slice);
4332 checkConfig(name ++ ".len");
4333 checkField(name ++ "[0]", info.child);
4334 },
4335 else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ "." ++ name ++ ": " ++ @typeName(Type)),
4306 .stage2_x86_64 => for (@typeInfo(Tag).@"enum".field_names) |tag_name| {
4307 if (!@hasField(@TypeOf(Tag.encodings), tag_name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name);
4308 const encoding = @field(Tag.encodings, tag_name);
4309 if (@hasField(@TypeOf(encoding), "trailing")) {
4310 const trailing_info = @typeInfo(encoding.trailing).@"struct";
4311 for (trailing_info.field_names, trailing_info.field_types) |field_name, field_type| {
4312 struct {
4313 fn checkConfig(name: []const u8) void {
4314 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ ".config.@\"" ++ name ++ "\"");
4315 const FieldType = @TypeOf(@field(encoding.config, name));
4316 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
43364317 }
4337 }
4338 }.checkField("trailing." ++ field.name, field.type);
4339 };
4318 fn checkField(name: []const u8, Type: type) void {
4319 switch (@typeInfo(Type)) {
4320 .int => {},
4321 .@"enum" => {},
4322 .@"struct" => |info| assert(info.layout == .@"packed"),
4323 .optional => |info| {
4324 checkConfig(name ++ ".?");
4325 checkField(name ++ ".?", info.child);
4326 },
4327 .pointer => |info| {
4328 assert(info.size == .slice);
4329 checkConfig(name ++ ".len");
4330 checkField(name ++ "[0]", info.child);
4331 },
4332 else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ "." ++ name ++ ": " ++ @typeName(Type)),
4333 }
4334 }
4335 }.checkField("trailing." ++ field_name, field_type);
4336 }
4337 }
43404338 },
43414339 else => {},
43424340 };
......@@ -6965,7 +6963,7 @@ fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local.
69656963 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);
69666964 const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]);
69676965 const func_decl = ip.funcDeclInfo(generic_owner);
6968 const end_extra_index = extra_index + @as(u32, @typeInfo(Tag.FuncInstance).@"struct".fields.len);
6966 const end_extra_index = extra_index + @as(u32, @typeInfo(Tag.FuncInstance).@"struct".field_names.len);
69696967 return .{
69706968 .tid = tid,
69716969 .ty = ty,
......@@ -7305,7 +7303,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
73057303 const names_map = try ip.addMap(gpa, io, tid, names.len);
73067304 ip.addStringsToMap(names_map, names);
73077305 const names_len = error_set_type.names.len;
7308 try extra.ensureUnusedCapacity(@typeInfo(Tag.ErrorSet).@"struct".fields.len + names_len);
7306 try extra.ensureUnusedCapacity(@typeInfo(Tag.ErrorSet).@"struct".field_names.len + names_len);
73097307 items.appendAssumeCapacity(.{
73107308 .tag = .type_error_set,
73117309 .data = addExtraAssumeCapacity(extra, Tag.ErrorSet{
......@@ -7861,7 +7859,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
78617859 .repeated_elem => |elem| elem,
78627860 };
78637861
7864 try extra.ensureUnusedCapacity(@typeInfo(Repeated).@"struct".fields.len);
7862 try extra.ensureUnusedCapacity(@typeInfo(Repeated).@"struct".field_names.len);
78657863 items.appendAssumeCapacity(.{
78667864 .tag = .repeated,
78677865 .data = addExtraAssumeCapacity(extra, Repeated{
......@@ -7876,7 +7874,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
78767874 const string_bytes = ip.getLocal(tid).getMutableStringBytes(gpa, io);
78777875 const start = string_bytes.mutate.len;
78787876 try string_bytes.ensureUnusedCapacity(@intCast(len_including_sentinel + 1));
7879 try extra.ensureUnusedCapacity(@typeInfo(Bytes).@"struct".fields.len);
7877 try extra.ensureUnusedCapacity(@typeInfo(Bytes).@"struct".field_names.len);
78807878 switch (aggregate.storage) {
78817879 .bytes => |bytes| string_bytes.appendSliceAssumeCapacity(.{bytes.toSlice(len, ip)}),
78827880 .elems => |elems| for (elems[0..@intCast(len)]) |elem| switch (ip.indexToKey(elem)) {
......@@ -7917,7 +7915,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
79177915 }
79187916
79197917 try extra.ensureUnusedCapacity(
7920 @typeInfo(Tag.Aggregate).@"struct".fields.len + @as(usize, @intCast(len_including_sentinel + 1)),
7918 @typeInfo(Tag.Aggregate).@"struct".field_names.len + @as(usize, @intCast(len_including_sentinel + 1)),
79217919 );
79227920 items.appendAssumeCapacity(.{
79237921 .tag = .aggregate,
......@@ -7943,7 +7941,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
79437941
79447942 .memoized_call => |memoized_call| {
79457943 for (memoized_call.arg_values) |arg| assert(arg != .none);
7946 try extra.ensureUnusedCapacity(@typeInfo(MemoizedCall).@"struct".fields.len +
7944 try extra.ensureUnusedCapacity(@typeInfo(MemoizedCall).@"struct".field_names.len +
79477945 memoized_call.arg_values.len);
79487946 items.appendAssumeCapacity(.{
79497947 .tag = .memoized_call,
......@@ -8006,7 +8004,7 @@ pub fn getDeclaredStructType(
80068004 .auto => false,
80078005 .@"extern" => true,
80088006 .@"packed" => {
8009 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".fields.len +
8007 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".field_names.len +
80108008 ini.captures.len + // capture
80118009 ini.fields_len + // field_name
80128010 ini.fields_len + // field_type
......@@ -8053,7 +8051,7 @@ pub fn getDeclaredStructType(
80538051 },
80548052 };
80558053
8056 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".fields.len +
8054 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".field_names.len +
80578055 1 + // captures_len
80588056 ini.captures.len + // capture
80598057 ini.fields_len + // field_name
......@@ -8150,7 +8148,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe
81508148 .auto => false,
81518149 .@"extern" => true,
81528150 .@"packed" => {
8153 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".fields.len +
8151 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".field_names.len +
81548152 2 + // type_hash
81558153 ini.fields_len + // field_name
81568154 ini.fields_len + // field_type
......@@ -8203,7 +8201,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe
82038201 },
82048202 };
82058203
8206 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".fields.len +
8204 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".field_names.len +
82078205 2 + // type_hash
82088206 ini.fields_len + // field_name
82098207 ini.fields_len + // field_type
......@@ -8323,7 +8321,7 @@ pub fn getDeclaredUnionType(
83238321 .auto => false,
83248322 .@"extern" => true,
83258323 .@"packed" => {
8326 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".fields.len +
8324 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len +
83278325 ini.captures.len + // capture
83288326 ini.fields_len); // field_type
83298327
......@@ -8364,7 +8362,7 @@ pub fn getDeclaredUnionType(
83648362 },
83658363 };
83668364
8367 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".fields.len +
8365 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".field_names.len +
83688366 1 + // captures_len
83698367 ini.captures.len + // capture
83708368 ini.fields_len + // field_type
......@@ -8445,7 +8443,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per
84458443 .auto => false,
84468444 .@"extern" => true,
84478445 .@"packed" => {
8448 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".fields.len +
8446 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len +
84498447 2 + // type_hash
84508448 ini.fields_len + // reified_field_name
84518449 ini.fields_len); // field_type
......@@ -8490,7 +8488,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per
84908488 },
84918489 };
84928490
8493 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".fields.len +
8491 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".field_names.len +
84948492 2 + // type_hash
84958493 ini.fields_len + // reified_field_name
84968494 ini.fields_len + // field_type
......@@ -8597,7 +8595,7 @@ pub fn getDeclaredEnumType(
85978595 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;
85988596 errdefer local.mutate.maps.len -= @intFromBool(have_values);
85998597
8600 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".fields.len +
8598 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".field_names.len +
86018599 1 + // zir_index
86028600 ini.captures.len + // capture
86038601 @intFromBool(have_values) + // field_value_map
......@@ -8672,7 +8670,7 @@ pub fn getReifiedEnumType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerT
86728670 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;
86738671 errdefer local.mutate.maps.len -= @intFromBool(have_values);
86748672
8675 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".fields.len +
8673 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".field_names.len +
86768674 1 + // zir_index
86778675 2 + // type_hash
86788676 @intFromBool(have_values) + // field_value_map
......@@ -8746,7 +8744,7 @@ pub fn getGeneratedEnumTagType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu
87468744 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;
87478745 errdefer local.mutate.maps.len -= @intFromBool(have_values);
87488746
8749 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".fields.len +
8747 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".field_names.len +
87508748 1 + // owner_union
87518749 @intFromBool(have_values) + // field_value_map
87528750 ini.fields_len + // field_name
......@@ -8805,7 +8803,7 @@ pub fn getDeclaredOpaqueType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.P
88058803 const extra = local.getMutableExtra(gpa, io);
88068804 try items.ensureUnusedCapacity(1);
88078805
8808 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeOpaque).@"struct".fields.len + ini.captures.len);
8806 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeOpaque).@"struct".field_names.len + ini.captures.len);
88098807 const extra_index = addExtraAssumeCapacity(extra, Tag.TypeOpaque{
88108808 .zir_index = ini.zir_index,
88118809 .captures_len = @intCast(ini.captures.len),
......@@ -8938,7 +8936,7 @@ pub fn getTupleType(
89388936
89398937 try items.ensureUnusedCapacity(1);
89408938 try extra.ensureUnusedCapacity(
8941 @typeInfo(TypeTuple).@"struct".fields.len + (fields_len * 3),
8939 @typeInfo(TypeTuple).@"struct".field_names.len + (fields_len * 3),
89428940 );
89438941
89448942 const extra_index = addExtraAssumeCapacity(extra, TypeTuple{
......@@ -8996,7 +8994,7 @@ pub fn getFuncType(
89968994 const prev_extra_len = extra.mutate.len;
89978995 const params_len: u32 = @intCast(key.param_types.len);
89988996
8999 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeFunction).@"struct".fields.len +
8997 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeFunction).@"struct".field_names.len +
90008998 @intFromBool(key.comptime_bits != 0) +
90018999 @intFromBool(key.noalias_bits != 0) +
90029000 params_len);
......@@ -9059,7 +9057,7 @@ pub fn getExtern(
90599057 const items = local.getMutableItems(gpa, io);
90609058 const extra = local.getMutableExtra(gpa, io);
90619059 try items.ensureUnusedCapacity(1);
9062 try extra.ensureUnusedCapacity(@typeInfo(Tag.Extern).@"struct".fields.len);
9060 try extra.ensureUnusedCapacity(@typeInfo(Tag.Extern).@"struct".field_names.len);
90639061 try local.getMutableNavs(gpa, io).ensureUnusedCapacity(1);
90649062
90659063 // Predict the index the `@"extern" will live at, so we can construct the owner `Nav` before releasing the shard's mutex.
......@@ -9138,7 +9136,7 @@ pub fn getFuncDecl(
91389136 // arrays. This is similar to what `getOrPutTrailingString` does.
91399137 const prev_extra_len = extra.mutate.len;
91409138
9141 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".fields.len);
9139 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".field_names.len);
91429140
91439141 const func_decl_extra_index = addExtraAssumeCapacity(extra, Tag.FuncDecl{
91449142 .analysis = .{
......@@ -9225,10 +9223,10 @@ pub fn getFuncDeclIes(
92259223 const prev_extra_len = extra.mutate.len;
92269224 const params_len: u32 = @intCast(key.param_types.len);
92279225
9228 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".fields.len +
9226 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".field_names.len +
92299227 1 + // inferred_error_set
9230 @typeInfo(Tag.ErrorUnionType).@"struct".fields.len +
9231 @typeInfo(Tag.TypeFunction).@"struct".fields.len +
9228 @typeInfo(Tag.ErrorUnionType).@"struct".field_names.len +
9229 @typeInfo(Tag.TypeFunction).@"struct".field_names.len +
92329230 @intFromBool(key.comptime_bits != 0) +
92339231 @intFromBool(key.noalias_bits != 0) +
92349232 params_len);
......@@ -9364,7 +9362,7 @@ pub fn getErrorSetType(
93649362 const local = ip.getLocal(tid);
93659363 const items = local.getMutableItems(gpa, io);
93669364 const extra = local.getMutableExtra(gpa, io);
9367 try extra.ensureUnusedCapacity(@typeInfo(Tag.ErrorSet).@"struct".fields.len + names.len);
9365 try extra.ensureUnusedCapacity(@typeInfo(Tag.ErrorSet).@"struct".field_names.len + names.len);
93689366
93699367 const names_map = try ip.addMap(gpa, io, tid, names.len);
93709368 errdefer local.mutate.maps.len -= 1;
......@@ -9440,7 +9438,7 @@ pub fn getFuncInstance(
94409438 const local = ip.getLocal(tid);
94419439 const items = local.getMutableItems(gpa, io);
94429440 const extra = local.getMutableExtra(gpa, io);
9443 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".fields.len +
9441 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".field_names.len +
94449442 arg.comptime_args.len);
94459443
94469444 assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner)));
......@@ -9524,11 +9522,11 @@ fn getFuncInstanceIes(
95249522 const prev_extra_len = extra.mutate.len;
95259523 const params_len: u32 = @intCast(arg.param_types.len);
95269524
9527 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".fields.len +
9525 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".field_names.len +
95289526 1 + // inferred_error_set
95299527 arg.comptime_args.len +
9530 @typeInfo(Tag.ErrorUnionType).@"struct".fields.len +
9531 @typeInfo(Tag.TypeFunction).@"struct".fields.len +
9528 @typeInfo(Tag.ErrorUnionType).@"struct".field_names.len +
9529 @typeInfo(Tag.TypeFunction).@"struct".field_names.len +
95329530 @intFromBool(arg.noalias_bits != 0) +
95339531 params_len);
95349532
......@@ -9774,15 +9772,16 @@ fn addInt(
97749772}
97759773
97769774fn addExtra(extra: Local.Extra.Mutable, item: anytype) Allocator.Error!u32 {
9777 const fields = @typeInfo(@TypeOf(item)).@"struct".fields;
9778 try extra.ensureUnusedCapacity(fields.len);
9775 const field_count = @typeInfo(@TypeOf(item)).@"struct".field_names.len;
9776 try extra.ensureUnusedCapacity(field_count);
97799777 return addExtraAssumeCapacity(extra, item);
97809778}
97819779
97829780fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
97839781 const result: u32 = extra.mutate.len;
9784 inline for (@typeInfo(@TypeOf(item)).@"struct".fields) |field| {
9785 extra.appendAssumeCapacity(.{switch (field.type) {
9782 const info = @typeInfo(@TypeOf(item)).@"struct";
9783 inline for (info.field_types, info.field_names) |field_type, field_name| {
9784 extra.appendAssumeCapacity(.{switch (field_type) {
97869785 Index,
97879786 Nav.Index,
97889787 Nav.Index.Optional,
......@@ -9797,7 +9796,7 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
97979796 TrackedInst.Index,
97989797 TrackedInst.Index.Optional,
97999798 ComptimeAllocIndex,
9800 => @intFromEnum(@field(item, field.name)),
9799 => @intFromEnum(@field(item, field_name)),
98019800
98029801 u32,
98039802 i32,
......@@ -9811,9 +9810,9 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
98119810 Tag.TypeStructPacked.Bits,
98129811 Tag.TypeUnionPacked.Bits,
98139812 Tag.TypeEnum.Bits,
9814 => @bitCast(@field(item, field.name)),
9813 => @bitCast(@field(item, field_name)),
98159814
9816 else => @compileError("bad field type: " ++ @typeName(field.type)),
9815 else => @compileError("bad field type: " ++ @typeName(field_type)),
98179816 }});
98189817 }
98199818 return result;
......@@ -9826,11 +9825,12 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
98269825 else => @compileError("unsupported host"),
98279826 }
98289827 const result: u32 = @intCast(ip.limbs.items.len);
9829 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields, 0..) |field, i| {
9830 const new: u32 = switch (field.type) {
9831 u32 => @field(extra, field.name),
9832 Index => @intFromEnum(@field(extra, field.name)),
9833 else => @compileError("bad field type: " ++ @typeName(field.type)),
9828 const info = @typeInfo(@TypeOf(extra)).@"struct";
9829 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
9830 const new: u32 = switch (field_type) {
9831 u32 => @field(extra, field_name),
9832 Index => @intFromEnum(@field(extra, field_name)),
9833 else => @compileError("bad field type: " ++ @typeName(field_type)),
98349834 };
98359835 if (i % 2 == 0) {
98369836 ip.limbs.appendAssumeCapacity(new);
......@@ -9844,10 +9844,11 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
98449844fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { data: T, end: u32 } {
98459845 const extra_items = extra.view().items(.@"0");
98469846 var result: T = undefined;
9847 const fields = @typeInfo(T).@"struct".fields;
9848 inline for (fields, index..) |field, extra_index| {
9847 const field_names = @typeInfo(T).@"struct".field_names;
9848 const field_types = @typeInfo(T).@"struct".field_types;
9849 inline for (field_names, field_types, index..) |field_name, field_type, extra_index| {
98499850 const extra_item = extra_items[extra_index];
9850 @field(result, field.name) = switch (field.type) {
9851 @field(result, field_name) = switch (field_type) {
98519852 Index,
98529853 Nav.Index,
98539854 Nav.Index.Optional,
......@@ -9878,12 +9879,12 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
98789879 Tag.TypeEnum.Bits,
98799880 => @bitCast(extra_item),
98809881
9881 else => @compileError("bad field type: " ++ @typeName(field.type)),
9882 else => @compileError("bad field type: " ++ @typeName(field_type)),
98829883 };
98839884 }
98849885 return .{
98859886 .data = result,
9886 .end = @intCast(index + fields.len),
9887 .end = @intCast(index + field_names.len),
98879888 };
98889889}
98899890
......@@ -10311,7 +10312,7 @@ fn getCoercedFunc(
1031110312 const extra = local.getMutableExtra(gpa, io);
1031210313
1031310314 const prev_extra_len = extra.mutate.len;
10314 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncCoerced).@"struct".fields.len);
10315 try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncCoerced).@"struct".field_names.len);
1031510316
1031610317 const extra_index = addExtraAssumeCapacity(extra, Tag.FuncCoerced{
1031710318 .ty = ty,
......@@ -10601,7 +10602,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1060110602 },
1060210603
1060310604 .type_struct => b: {
10604 var n: usize = @typeInfo(Tag.TypeStruct).@"struct".fields.len;
10605 var n: usize = @typeInfo(Tag.TypeStruct).@"struct".field_names.len;
1060510606 const extra = extraDataTrail(extra_list, Tag.TypeStruct, data);
1060610607 switch (extra.data.flags.any_captures) {
1060710608 .reified => n += 2, // type_hash: PackedU64
......@@ -10629,7 +10630,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1062910630 break :b n * @sizeOf(u32);
1063010631 },
1063110632 .type_struct_packed_auto, .type_struct_packed_explicit => b: {
10632 var n: usize = @typeInfo(Tag.TypeStructPacked).@"struct".fields.len;
10633 var n: usize = @typeInfo(Tag.TypeStructPacked).@"struct".field_names.len;
1063310634 const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data);
1063410635 switch (extra.data.bits.captures_len) {
1063510636 .reified => n += 2, // type_hash: PackedU64
......@@ -10640,7 +10641,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1064010641 break :b n * @sizeOf(u32);
1064110642 },
1064210643 .type_struct_packed_auto_defaults, .type_struct_packed_explicit_defaults => b: {
10643 var n: usize = @typeInfo(Tag.TypeStructPacked).@"struct".fields.len;
10644 var n: usize = @typeInfo(Tag.TypeStructPacked).@"struct".field_names.len;
1064410645 const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data);
1064510646 switch (extra.data.bits.captures_len) {
1064610647 .reified => n += 2, // type_hash: PackedU64
......@@ -10652,7 +10653,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1065210653 break :b n * @sizeOf(u32);
1065310654 },
1065410655 .type_union => b: {
10655 var n: usize = @typeInfo(Tag.TypeUnion).@"struct".fields.len;
10656 var n: usize = @typeInfo(Tag.TypeUnion).@"struct".field_names.len;
1065610657 const extra = extraDataTrail(extra_list, Tag.TypeUnion, data);
1065710658 switch (extra.data.flags.any_captures) {
1065810659 .reified => n += 2, // type_hash: PackedU64
......@@ -10669,7 +10670,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1066910670 break :b n * @sizeOf(u32);
1067010671 },
1067110672 .type_union_packed_auto, .type_union_packed_explicit => b: {
10672 var n: usize = @typeInfo(Tag.TypeUnionPacked).@"struct".fields.len;
10673 var n: usize = @typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len;
1067310674 const extra = extraDataTrail(extra_list, Tag.TypeUnionPacked, data);
1067410675 switch (extra.data.bits.captures_len) {
1067510676 .reified => n += 2, // type_hash: PackedU64
......@@ -10679,7 +10680,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1067910680 break :b n * @sizeOf(u32);
1068010681 },
1068110682 .type_enum_auto => b: {
10682 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".fields.len;
10683 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".field_names.len;
1068310684 const extra = extraData(extra_list, Tag.TypeEnum, data);
1068410685 switch (extra.bits.captures_len) {
1068510686 .generated_union_tag => n += 1, // owner_union: Index
......@@ -10696,7 +10697,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1069610697 break :b n * @sizeOf(u32);
1069710698 },
1069810699 .type_enum_explicit, .type_enum_nonexhaustive => b: {
10699 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".fields.len;
10700 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".field_names.len;
1070010701 const extra = extraData(extra_list, Tag.TypeEnum, data);
1070110702 switch (extra.bits.captures_len) {
1070210703 .generated_union_tag => n += 1, // owner_union: Index
......@@ -10715,7 +10716,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
1071510716 break :b n * @sizeOf(u32);
1071610717 },
1071710718 .type_opaque => b: {
10718 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".fields.len;
10719 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".field_names.len;
1071910720 const extra = extraData(extra_list, Tag.TypeOpaque, data);
1072010721 n += extra.captures_len; // capture: CaptureValue
1072110722 break :b n * @sizeOf(u32);
......@@ -12131,8 +12132,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {
1213112132 const func_extra = unwrapped_func.getExtra(ip);
1213212133 const func_item = unwrapped_func.getItem(ip);
1213312134 const extra_index = switch (func_item.tag) {
12134 .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).@"struct".fields.len,
12135 .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).@"struct".fields.len,
12135 .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).@"struct".field_names.len,
12136 .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).@"struct".field_names.len,
1213612137 .func_coerced => {
1213712138 const uncoerced_func_index: Index = @enumFromInt(func_extra.view().items(.@"0")[
1213812139 func_item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?
......@@ -12141,8 +12142,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {
1214112142 const uncoerced_func_item = unwrapped_uncoerced_func.getItem(ip);
1214212143 return @ptrCast(&unwrapped_uncoerced_func.getExtra(ip).view().items(.@"0")[
1214312144 switch (uncoerced_func_item.tag) {
12144 .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).@"struct".fields.len,
12145 .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).@"struct".fields.len,
12145 .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).@"struct".field_names.len,
12146 .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).@"struct".field_names.len,
1214612147 else => unreachable,
1214712148 }
1214812149 ]);
src/Sema.zig+462-214
......@@ -2822,6 +2822,17 @@ fn interpretStdLangType(
28222822 };
28232823}
28242824
2825fn uninterpretStdLangType(
2826 sema: *Sema,
2827 val: anytype,
2828 ty: Type,
2829) !Value {
2830 return Value.uninterpret(val, ty, sema.pt) catch |err| switch (err) {
2831 error.OutOfMemory => |e| return e,
2832 error.TypeMismatch => @panic("std.lang is corrupt"),
2833 };
2834}
2835
28252836fn zirTupleDecl(
28262837 sema: *Sema,
28272838 block: *Block,
......@@ -3934,7 +3945,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
39343945 _ = try replacement_block.addBr(placeholder_inst, .void_value);
39353946 try sema.air_extra.ensureUnusedCapacity(
39363947 gpa,
3937 @typeInfo(Air.Block).@"struct".fields.len + replacement_block.instructions.items.len,
3948 @typeInfo(Air.Block).@"struct".field_names.len + replacement_block.instructions.items.len,
39383949 );
39393950 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{
39403951 .tag = .block,
......@@ -5175,7 +5186,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
51755186
51765187 try child_block.instructions.append(gpa, loop_inst);
51775188
5178 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + loop_block_len + 1);
5189 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + loop_block_len + 1);
51795190 sema.air_instructions.items(.data)[@intFromEnum(loop_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(
51805191 Air.Block{ .body_len = @intCast(loop_block_len + 1) },
51815192 );
......@@ -5274,7 +5285,7 @@ fn resolveBlockBody(
52745285 // We need a runtime block for scoping reasons.
52755286 _ = try child_block.addBr(merges.block_inst, .void_value);
52765287 try parent_block.instructions.append(sema.gpa, merges.block_inst);
5277 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Block).@"struct".fields.len +
5288 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Block).@"struct".field_names.len +
52785289 child_block.instructions.items.len);
52795290 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
52805291 .ty = .void_type,
......@@ -5350,7 +5361,7 @@ fn resolveAnalyzedBlock(
53505361 .dbg_inline_block => {
53515362 // Create a block containing all instruction from the body.
53525363 try parent_block.instructions.append(gpa, merges.block_inst);
5353 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".fields.len +
5364 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".field_names.len +
53545365 child_block.instructions.items.len);
53555366 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
53565367 .ty = .noreturn_type,
......@@ -5388,7 +5399,7 @@ fn resolveAnalyzedBlock(
53885399 try parent_block.instructions.append(gpa, merges.block_inst);
53895400 switch (block_tag) {
53905401 .block => {
5391 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
5402 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
53925403 child_block.instructions.items.len);
53935404 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
53945405 .ty = .void_type,
......@@ -5398,7 +5409,7 @@ fn resolveAnalyzedBlock(
53985409 } };
53995410 },
54005411 .dbg_inline_block => {
5401 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".fields.len +
5412 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".field_names.len +
54025413 child_block.instructions.items.len);
54035414 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
54045415 .ty = .void_type,
......@@ -5453,7 +5464,7 @@ fn resolveAnalyzedBlock(
54535464 const ty_inst = Air.internedToRef(resolved_ty.toIntern());
54545465 switch (block_tag) {
54555466 .block => {
5456 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
5467 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
54575468 child_block.instructions.items.len);
54585469 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
54595470 .ty = ty_inst,
......@@ -5463,7 +5474,7 @@ fn resolveAnalyzedBlock(
54635474 } };
54645475 },
54655476 .dbg_inline_block => {
5466 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".fields.len +
5477 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".field_names.len +
54675478 child_block.instructions.items.len);
54685479 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
54695480 .ty = ty_inst,
......@@ -5500,7 +5511,7 @@ fn resolveAnalyzedBlock(
55005511 // Convert the br instruction to a block instruction that has the coercion
55015512 // and then a new br inside that returns the coerced instruction.
55025513 const sub_block_len: u32 = @intCast(coerce_block.instructions.items.len + 1);
5503 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
5514 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
55045515 sub_block_len);
55055516 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
55065517 const sub_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
......@@ -6061,7 +6072,7 @@ fn popErrorReturnTrace(
60616072 // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need
60626073 // to pop any error trace that may have been propagated from our arguments.
60636074
6064 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len);
6075 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len);
60656076 const cond_block_inst = try block.addInstAsIndex(.{
60666077 .tag = .block,
60676078 .data = .{
......@@ -6089,9 +6100,9 @@ fn popErrorReturnTrace(
60896100 defer else_block.instructions.deinit(gpa);
60906101 _ = try else_block.addBr(cond_block_inst, .void_value);
60916102
6092 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len +
6103 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len +
60936104 then_block.instructions.items.len + else_block.instructions.items.len +
6094 @typeInfo(Air.Block).@"struct".fields.len + 1); // +1 for the sole .cond_br instruction in the .block
6105 @typeInfo(Air.Block).@"struct".field_names.len + 1); // +1 for the sole .cond_br instruction in the .block
60956106
60966107 const cond_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
60976108 try sema.air_instructions.append(gpa, .{
......@@ -7008,7 +7019,7 @@ fn analyzeCall(
70087019 => unreachable,
70097020 };
70107021
7011 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Call).@"struct".fields.len + runtime_args.len);
7022 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Call).@"struct".field_names.len + runtime_args.len);
70127023 const call_ref = try block.addInst(.{
70137024 .tag = call_tag,
70147025 .data = .{ .pl_op = .{
......@@ -9958,7 +9969,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
99589969 }
99599970 }
99609971
9961 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len +
9972 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len +
99629973 non_err_block.instructions.items.len + switch_block.instructions.items.len);
99639974 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
99649975 .then_body_len = @intCast(non_err_block.instructions.items.len),
......@@ -10314,7 +10325,7 @@ fn analyzeSwitchBlock(
1031410325 _ = try sema.analyzeBodyRuntimeBreak(&case_block, body);
1031510326 }
1031610327
10317 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
10328 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
1031810329 case_block.instructions.items.len);
1031910330 const payload_index = sema.addExtraAssumeCapacity(Air.Block{
1032010331 .body_len = @intCast(case_block.instructions.items.len),
......@@ -10405,7 +10416,7 @@ fn analyzeSwitchBlock(
1040510416
1040610417 // Replace placeholder with a block.
1040710418 // No `br` is needed as the block is a switch dispatch so necessarily `noreturn`.
10408 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
10419 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
1040910420 replacement_block.instructions.items.len);
1041010421 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{
1041110422 .tag = .block,
......@@ -10508,7 +10519,7 @@ fn finishSwitchBr(
1050810519 defer branch_hints.bags.deinit(gpa);
1050910520
1051010521 var cases_extra: std.ArrayList(u32) = try .initCapacity(gpa, estimated_cases_len *
10511 @typeInfo(Air.SwitchBr.Case).@"struct".fields.len);
10522 @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len);
1051210523 defer cases_extra.deinit(gpa);
1051310524
1051410525 // We will reuse this block for each case.
......@@ -10598,7 +10609,7 @@ fn finishSwitchBr(
1059810609 };
1059910610 branch_hints.appendAssumeCapacity(prong_hint);
1060010611
10601 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len +
10612 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
1060210613 1 + // `item`, no ranges
1060310614 case_block.instructions.items.len);
1060410615 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
......@@ -10685,7 +10696,7 @@ fn finishSwitchBr(
1068510696 );
1068610697 try branch_hints.append(gpa, prong_hint);
1068710698
10688 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len +
10699 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
1068910700 1 + // `item`, no ranges
1069010701 case_block.instructions.items.len);
1069110702 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
......@@ -10741,7 +10752,7 @@ fn finishSwitchBr(
1074110752 };
1074210753 try branch_hints.append(gpa, prong_hint);
1074310754
10744 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len +
10755 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
1074510756 item_refs.len +
1074610757 2 * range_refs.len +
1074710758 case_block.instructions.items.len);
......@@ -10828,7 +10839,7 @@ fn finishSwitchBr(
1082810839 };
1082910840 try branch_hints.append(gpa, prong_hint);
1083010841
10831 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len +
10842 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
1083210843 1 + // `item`, no ranges
1083310844 case_block.instructions.items.len);
1083410845 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
......@@ -10888,11 +10899,11 @@ fn finishSwitchBr(
1088810899 };
1088910900 try branch_hints.append(gpa, prong_hint);
1089010901
10891 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len +
10902 try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
1089210903 (validated_switch.seen_enum_fields.len + 1 - zir_switch.totalItemsLen()) + // +1 because totalItemsLen includes the _
1089310904 case_block.instructions.items.len);
1089410905 const extra_case = cases_extra.addManyAsArrayAssumeCapacity(
10895 @typeInfo(Air.SwitchBr.Case).@"struct".fields.len,
10906 @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len,
1089610907 );
1089710908 var items_len: u32 = 0;
1089810909 for (validated_switch.seen_enum_fields, 0..) |seen_field, field_i| {
......@@ -10985,7 +10996,7 @@ fn finishSwitchBr(
1098510996
1098610997 assert(branch_hints.count == cases_len + 1); // +1 for catch-all hint
1098710998
10988 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr).@"struct".fields.len +
10999 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr).@"struct".field_names.len +
1098911000 branch_hints.bags.items.len +
1099011001 cases_extra.items.len +
1099111002 catch_all_extra.len);
......@@ -12356,7 +12367,7 @@ fn analyzeSwitchPayloadCapture(
1235612367 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
1235712368 _ = try coerce_block.addBr(capture_block_inst, coerced);
1235812369
12359 try cases_extra.ensureUnusedCapacity(@typeInfo(Air.SwitchBr.Case).@"struct".fields.len +
12370 try cases_extra.ensureUnusedCapacity(@typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
1236012371 1 + // `item`, no ranges
1236112372 coerce_block.instructions.items.len);
1236212373 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
......@@ -12384,9 +12395,9 @@ fn analyzeSwitchPayloadCapture(
1238412395 break :len coerce_block.instructions.items.len;
1238512396 };
1238612397
12387 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.SwitchBr).@"struct".fields.len +
12398 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.SwitchBr).@"struct".field_names.len +
1238812399 cases_extra.items.len +
12389 @typeInfo(Air.Block).@"struct".fields.len +
12400 @typeInfo(Air.Block).@"struct".field_names.len +
1239012401 1);
1239112402
1239212403 const switch_br_inst: u32 = @intCast(sema.air_instructions.len);
......@@ -15226,7 +15237,7 @@ fn zirAsm(
1522615237
1522715238 var extra_i = extra.end;
1522815239 var output_type_bits = extra.data.output_type_bits;
15229 var needed_capacity: usize = @typeInfo(Air.Asm).@"struct".fields.len + outputs_len + inputs_len;
15240 var needed_capacity: usize = @typeInfo(Air.Asm).@"struct".field_names.len + outputs_len + inputs_len;
1523015241
1523115242 const ConstraintName = struct { c: []const u8, n: []const u8 };
1523215243 const out_args = try sema.arena.alloc(Air.Inst.Ref, outputs_len);
......@@ -15988,13 +15999,19 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1598815999
1598916000 .@"fn" => {
1599016001 const fn_info_ty = try sema.getStdLangType(src, .@"Type.Fn");
15991 const param_info_ty = try sema.getStdLangType(src, .@"Type.Fn.Param");
16002 const param_attrs_ty = try sema.getStdLangType(src, .@"Type.Fn.ParamAttributes");
16003 const fn_attr_ty = try sema.getStdLangType(src, .@"Type.Fn.Attributes");
1599216004
1599316005 const func_ty_info = zcu.typeToFunc(ty).?;
15994 const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
16006 const param_type_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
16007 const param_attr_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
1599516008 var func_is_generic = false;
1599616009
15997 for (param_vals, 0..) |*param_val, param_index| {
16010 for (
16011 param_type_vals,
16012 param_attr_vals,
16013 0..,
16014 ) |*param_type_val, *param_attr_val, param_index| {
1599816015 const param_ty = func_ty_info.param_types.get(ip)[param_index];
1599916016 const is_generic = param_ty == .generic_poison_type;
1600016017 const is_noalias, const is_comptime = flags: {
......@@ -16011,25 +16028,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1601116028 .val = if (is_generic) .none else param_ty,
1601216029 } });
1601316030
16014 const param_fields = .{
16015 // is_generic: bool,
16016 Value.makeBool(is_generic).toIntern(),
16017 // is_noalias: bool,
16031 const param_attrs_fields = .{
16032 // @"noalias": bool,
1601816033 Value.makeBool(is_noalias).toIntern(),
16019 // type: ?type,
16020 param_ty_val,
1602116034 };
16022 param_val.* = (try pt.aggregateValue(param_info_ty, &param_fields)).toIntern();
16035
16036 param_type_val.* = param_ty_val;
16037 param_attr_val.* = (try pt.aggregateValue(param_attrs_ty, &param_attrs_fields)).toIntern();
1602316038 }
1602416039
16025 const args_val = v: {
16040 const param_types_val = v: {
1602616041 const new_decl_ty = try pt.arrayType(.{
16027 .len = param_vals.len,
16028 .child = param_info_ty.toIntern(),
16042 .len = param_type_vals.len,
16043 .child = try pt.intern(.{ .opt_type = .type_type }),
1602916044 });
16030 const new_decl_val = (try pt.aggregateValue(new_decl_ty, param_vals)).toIntern();
16045 const new_decl_val = (try pt.aggregateValue(new_decl_ty, param_type_vals)).toIntern();
1603116046 const slice_ty = (try pt.ptrType(.{
16032 .child = param_info_ty.toIntern(),
16047 .child = try pt.intern(.{ .opt_type = .type_type }),
1603316048 .flags = .{
1603416049 .size = .slice,
1603516050 .is_const = true,
......@@ -16046,7 +16061,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1604616061 } },
1604716062 .byte_offset = 0,
1604816063 } }),
16049 .len = (try pt.intValue(.usize, param_vals.len)).toIntern(),
16064 .len = (try pt.intValue(.usize, param_type_vals.len)).toIntern(),
16065 } });
16066 };
16067 const param_attrs_val = v: {
16068 const new_decl_ty = try pt.arrayType(.{
16069 .len = param_attr_vals.len,
16070 .child = param_attrs_ty.toIntern(),
16071 });
16072 const new_decl_val = (try pt.aggregateValue(new_decl_ty, param_attr_vals)).toIntern();
16073 const slice_ty = (try pt.ptrType(.{
16074 .child = param_attrs_ty.toIntern(),
16075 .flags = .{
16076 .size = .slice,
16077 .is_const = true,
16078 },
16079 })).toIntern();
16080 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
16081 break :v try pt.intern(.{ .slice = .{
16082 .ty = slice_ty,
16083 .ptr = try pt.intern(.{ .ptr = .{
16084 .ty = manyptr_ty,
16085 .base_addr = .{ .uav = .{
16086 .orig_ty = manyptr_ty,
16087 .val = new_decl_val,
16088 } },
16089 .byte_offset = 0,
16090 } }),
16091 .len = (try pt.intValue(.usize, param_attr_vals.len)).toIntern(),
1605016092 } });
1605116093 };
1605216094
......@@ -16075,17 +16117,25 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1607516117 error.OutOfMemory => |e| return e,
1607616118 };
1607716119
16078 const field_values: [5]InternPool.Index = .{
16079 // calling_convention: CallingConvention,
16120 const fn_attrs_values = .{
16121 // @"callconv": CallingConvention = .auto,
1608016122 callconv_val.toIntern(),
16123 // varargs: bool = false,
16124 Value.makeBool(func_ty_info.is_var_args).toIntern(),
16125 };
16126
16127 const field_values = .{
16128 // attrs: Attributes,
16129 (try pt.aggregateValue(fn_attr_ty, &fn_attrs_values)).toIntern(),
1608116130 // is_generic: bool,
1608216131 Value.makeBool(func_is_generic).toIntern(),
16083 // is_var_args: bool,
16084 Value.makeBool(func_ty_info.is_var_args).toIntern(),
1608516132 // return_type: ?type,
1608616133 ret_ty_opt,
16087 // args: []const Fn.Param,
16088 args_val,
16134
16135 // param_types: []const ?type,
16136 param_types_val,
16137 // param_attrs: []const ParamAttributes,
16138 param_attrs_val,
1608916139 };
1609016140 return Air.internedToRef((try pt.internUnion(.{
1609116141 .ty = type_info_ty.toIntern(),
......@@ -16139,23 +16189,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1613916189 const addrspace_ty = try sema.getStdLangType(src, .AddressSpace);
1614016190 const pointer_ty = try sema.getStdLangType(src, .@"Type.Pointer");
1614116191 const ptr_size_ty = try sema.getStdLangType(src, .@"Type.Pointer.Size");
16192 const ptr_attrs_ty = try sema.getStdLangType(src, .@"Type.Pointer.Attributes");
1614216193
16143 const field_values = .{
16144 // size: Size,
16145 (try pt.enumValueFieldIndex(ptr_size_ty, @intFromEnum(info.flags.size))).toIntern(),
16146 // is_const: bool,
16194 const opt_addrspace_val = try pt.intern(.{ .opt = .{
16195 .ty = (try pt.optionalType(addrspace_ty.toIntern())).toIntern(),
16196 .val = (try sema.uninterpretStdLangType(info.flags.address_space, addrspace_ty)).toIntern(),
16197 } });
16198
16199 const attributes = .{
16200 // @"const": bool = false,
1614716201 Value.makeBool(info.flags.is_const).toIntern(),
16148 // is_volatile: bool,
16202 // @"volatile": bool = false,
1614916203 Value.makeBool(info.flags.is_volatile).toIntern(),
16150 // alignment: ?usize,
16204 // @"allowzero": bool = false,
16205 Value.makeBool(info.flags.is_allowzero).toIntern(),
16206 // @"addrspace": ?AddressSpace = null,
16207 opt_addrspace_val,
16208 // @"align": ?usize = null,
1615116209 alignment_val.toIntern(),
16152 // address_space: AddressSpace
16153 (try pt.enumValueFieldIndex(addrspace_ty, @intFromEnum(info.flags.address_space))).toIntern(),
16210 };
16211
16212 const field_values = .{
16213 // size: Size,
16214 (try pt.enumValueFieldIndex(ptr_size_ty, @intFromEnum(info.flags.size))).toIntern(),
16215 // attrs: Attributes
16216 (try pt.aggregateValue(ptr_attrs_ty, &attributes)).toIntern(),
1615416217 // child: type,
1615516218 info.child,
16156 // is_allowzero: bool,
16157 Value.makeBool(info.flags.is_allowzero).toIntern(),
16158 // sentinel: ?*const anyopaque,
16219 // sentinel_ptr: ?*const anyopaque,
1615916220 (try sema.optRefValue(switch (info.sentinel) {
1616016221 .none => null,
1616116222 else => Value.fromInterned(info.sentinel),
......@@ -16215,8 +16276,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1621516276 })));
1621616277 },
1621716278 .error_set => {
16218 // Get the Error type
16219 const error_field_ty = try sema.getStdLangType(src, .@"Type.Error");
16279 const error_set_ty = try sema.getStdLangType(src, .@"Type.ErrorSet");
1622016280
1622116281 // Build our list of Error values
1622216282 // Optional value is only null if anyerror
......@@ -16253,20 +16313,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1625316313 } });
1625416314 };
1625516315
16256 const error_field_fields = .{
16257 // name: [:0]const u8,
16258 error_name_val,
16259 };
16260 field_val.* = (try pt.aggregateValue(error_field_ty, &error_field_fields)).toIntern();
16316 field_val.* = error_name_val;
1626116317 }
1626216318
1626316319 break :blk vals;
1626416320 },
1626516321 };
1626616322
16267 // Build our ?[]const Error value
16323 // Build our ?[]const [:0]const u8 value
1626816324 const slice_errors_ty = try pt.ptrType(.{
16269 .child = error_field_ty.toIntern(),
16325 .child = .slice_const_u8_sentinel_0_type,
1627016326 .flags = .{
1627116327 .size = .slice,
1627216328 .is_const = true,
......@@ -16276,7 +16332,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1627616332 const errors_payload_val: InternPool.Index = if (error_field_vals) |vals| v: {
1627716333 const array_errors_ty = try pt.arrayType(.{
1627816334 .len = vals.len,
16279 .child = error_field_ty.toIntern(),
16335 .child = .slice_const_u8_sentinel_0_type,
1628016336 });
1628116337 const new_decl_val = (try pt.aggregateValue(array_errors_ty, vals)).toIntern();
1628216338 const manyptr_errors_ty = slice_errors_ty.slicePtrFieldType(zcu).toIntern();
......@@ -16298,11 +16354,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1629816354 .val = errors_payload_val,
1629916355 } });
1630016356
16357 const field_values = .{
16358 // error_names: ?[]const [:0]const u8
16359 errors_val,
16360 };
16361
1630116362 // Construct Type{ .error_set = errors_val }
1630216363 return Air.internedToRef((try pt.internUnion(.{
1630316364 .ty = type_info_ty.toIntern(),
1630416365 .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.lang.TypeId.error_set))).toIntern(),
16305 .val = errors_val,
16366 .val = (try pt.aggregateValue(error_set_ty, &field_values)).toIntern(),
1630616367 })));
1630716368 },
1630816369 .error_union => {
......@@ -16322,12 +16383,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1632216383 },
1632316384 .@"enum" => {
1632416385 const enum_obj = ip.loadEnumType(ty.toIntern());
16325 const is_exhaustive: Value = .makeBool(!enum_obj.nonexhaustive);
1632616386
16327 const enum_field_ty = try sema.getStdLangType(src, .@"Type.EnumField");
16387 const enum_mode_ty = try sema.getStdLangType(src, .@"Type.Enum.Mode");
1632816388
16329 const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_obj.field_names.len);
16330 for (enum_field_vals, 0..) |*field_val, tag_index| {
16389 const enum_mode_tag: std.builtin.Type.Enum.Mode = if (enum_obj.nonexhaustive) .nonexhaustive else .exhaustive;
16390
16391 const enum_mode: Value = try sema.uninterpretStdLangType(enum_mode_tag, enum_mode_ty);
16392
16393 const enum_field_name_vals = try sema.arena.alloc(InternPool.Index, enum_obj.field_names.len);
16394 const enum_field_value_vals = try sema.arena.alloc(InternPool.Index, enum_obj.field_names.len);
16395 for (
16396 enum_field_name_vals,
16397 enum_field_value_vals,
16398 0..,
16399 ) |*field_name_val, *field_value_val, tag_index| {
1633116400 const value_val = if (enum_obj.field_values.len > 0)
1633216401 try ip.getCoercedInts(
1633316402 gpa,
......@@ -16366,23 +16435,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1636616435 } });
1636716436 };
1636816437
16369 const enum_field_fields = .{
16370 // name: [:0]const u8,
16371 name_val,
16372 // value: comptime_int,
16373 value_val,
16374 };
16375 field_val.* = (try pt.aggregateValue(enum_field_ty, &enum_field_fields)).toIntern();
16438 field_name_val.* = name_val;
16439 field_value_val.* = value_val;
1637616440 }
1637716441
16378 const fields_val = v: {
16379 const fields_array_ty = try pt.arrayType(.{
16380 .len = enum_field_vals.len,
16381 .child = enum_field_ty.toIntern(),
16442 const fields_names_val = v: {
16443 const fields_names_array_ty = try pt.arrayType(.{
16444 .len = enum_field_name_vals.len,
16445 .child = .slice_const_u8_sentinel_0_type,
1638216446 });
16383 const new_decl_val = (try pt.aggregateValue(fields_array_ty, enum_field_vals)).toIntern();
16447 const new_decl_val = (try pt.aggregateValue(fields_names_array_ty, enum_field_name_vals)).toIntern();
1638416448 const slice_ty = (try pt.ptrType(.{
16385 .child = enum_field_ty.toIntern(),
16449 .child = .slice_const_u8_sentinel_0_type,
1638616450 .flags = .{
1638716451 .size = .slice,
1638816452 .is_const = true,
......@@ -16399,23 +16463,55 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1639916463 } },
1640016464 .byte_offset = 0,
1640116465 } }),
16402 .len = (try pt.intValue(.usize, enum_field_vals.len)).toIntern(),
16466 .len = (try pt.intValue(.usize, enum_field_name_vals.len)).toIntern(),
1640316467 } });
1640416468 };
1640516469
16406 const decls_val = try sema.typeInfoDecls(src, ip.loadEnumType(ty.toIntern()).namespace.toOptional());
16470 const fields_values_val = v: {
16471 const fields_values_array_ty = try pt.arrayType(.{
16472 .len = enum_field_value_vals.len,
16473 .child = .comptime_int_type,
16474 });
16475 const new_decl_val = (try pt.aggregateValue(fields_values_array_ty, enum_field_value_vals)).toIntern();
16476 const slice_ty = (try pt.ptrType(.{
16477 .child = .comptime_int_type,
16478 .flags = .{
16479 .size = .slice,
16480 .is_const = true,
16481 },
16482 })).toIntern();
16483 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
16484 break :v try pt.intern(.{ .slice = .{
16485 .ty = slice_ty,
16486 .ptr = try pt.intern(.{ .ptr = .{
16487 .ty = manyptr_ty,
16488 .base_addr = .{ .uav = .{
16489 .val = new_decl_val,
16490 .orig_ty = manyptr_ty,
16491 } },
16492 .byte_offset = 0,
16493 } }),
16494 .len = (try pt.intValue(.usize, enum_field_value_vals.len)).toIntern(),
16495 } });
16496 };
16497
16498 const decl_names_val = try sema.typeInfoDecls(ip.loadEnumType(ty.toIntern()).namespace.toOptional());
1640716499
1640816500 const type_enum_ty = try sema.getStdLangType(src, .@"Type.Enum");
1640916501
1641016502 const field_values = .{
1641116503 // tag_type: type,
1641216504 ip.loadEnumType(ty.toIntern()).int_tag_type,
16413 // fields: []const EnumField,
16414 fields_val,
16415 // decls: []const Declaration,
16416 decls_val,
16417 // is_exhaustive: bool,
16418 is_exhaustive.toIntern(),
16505 // mode: Mode
16506 enum_mode.toIntern(),
16507
16508 // field_names: []const [:0]const u8,
16509 fields_names_val,
16510 // field_values: []const comptime_int,
16511 fields_values_val,
16512
16513 // decl_names: []const [:0]const u8,
16514 decl_names_val,
1641916515 };
1642016516 return Air.internedToRef((try pt.internUnion(.{
1642116517 .ty = type_info_ty.toIntern(),
......@@ -16425,16 +16521,26 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1642516521 },
1642616522 .@"union" => {
1642716523 const type_union_ty = try sema.getStdLangType(src, .@"Type.Union");
16428 const union_field_ty = try sema.getStdLangType(src, .@"Type.UnionField");
16524 const union_field_attr_ty = try sema.getStdLangType(src, .@"Type.Union.FieldAttributes");
1642916525
1643016526 const union_obj = ip.loadUnionType(ty.toIntern());
1643116527 const enum_obj = ip.loadEnumType(union_obj.enum_tag_type);
1643216528 const layout = union_obj.layout;
1643316529
16434 const union_field_vals = try gpa.alloc(InternPool.Index, enum_obj.field_names.len);
16435 defer gpa.free(union_field_vals);
16436
16437 for (union_field_vals, 0..) |*field_val, field_index| {
16530 const union_field_names = try gpa.alloc(InternPool.Index, enum_obj.field_names.len);
16531 defer gpa.free(union_field_names);
16532 const union_field_attrs = try gpa.alloc(InternPool.Index, enum_obj.field_names.len);
16533 defer gpa.free(union_field_attrs);
16534
16535 for (
16536 union_field_names,
16537 union_field_attrs,
16538 0..,
16539 ) |
16540 *field_name_val,
16541 *field_attr_val,
16542 field_index,
16543 | {
1643816544 const name_val = v: {
1643916545 const field_name = enum_obj.field_names.get(ip)[field_index];
1644016546 const field_name_len = field_name.length(ip);
......@@ -16461,8 +16567,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1646116567 } });
1646216568 };
1646316569
16464 const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]);
16465
1646616570 const alignment_ty = try pt.optionalType(.usize_type);
1646716571 const alignment_val: Value = val: {
1646816572 const a: Alignment = switch (layout) {
......@@ -16479,25 +16583,52 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1647916583 } }));
1648016584 };
1648116585
16482 const union_field_fields = .{
16483 // name: [:0]const u8,
16484 name_val,
16485 // type: type,
16486 field_ty.toIntern(),
16586 field_name_val.* = name_val;
16587 const union_field_attr = .{
1648716588 // alignment: ?usize,
1648816589 alignment_val.toIntern(),
1648916590 };
16490 field_val.* = (try pt.aggregateValue(union_field_ty, &union_field_fields)).toIntern();
16591
16592 field_attr_val.* = (try pt.aggregateValue(union_field_attr_ty, &union_field_attr)).toIntern();
1649116593 }
1649216594
16493 const fields_val = v: {
16595 const field_names_val = v: {
16596 const array_field_names_ty = try pt.arrayType(.{
16597 .len = union_field_names.len,
16598 .child = .slice_const_u8_sentinel_0_type,
16599 });
16600 const new_decl_val = (try pt.aggregateValue(array_field_names_ty, union_field_names)).toIntern();
16601 const slice_ty = (try pt.ptrType(.{
16602 .child = .slice_const_u8_sentinel_0_type,
16603 .flags = .{
16604 .size = .slice,
16605 .is_const = true,
16606 },
16607 })).toIntern();
16608 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
16609 break :v try pt.intern(.{ .slice = .{
16610 .ty = slice_ty,
16611 .ptr = try pt.intern(.{ .ptr = .{
16612 .ty = manyptr_ty,
16613 .base_addr = .{ .uav = .{
16614 .orig_ty = manyptr_ty,
16615 .val = new_decl_val,
16616 } },
16617 .byte_offset = 0,
16618 } }),
16619 .len = (try pt.intValue(.usize, union_field_names.len)).toIntern(),
16620 } });
16621 };
16622 const field_types_val = v: {
16623 const union_field_types = union_obj.field_types.get(ip);
16624
1649416625 const array_fields_ty = try pt.arrayType(.{
16495 .len = union_field_vals.len,
16496 .child = union_field_ty.toIntern(),
16626 .len = union_field_types.len,
16627 .child = .type_type,
1649716628 });
16498 const new_decl_val = (try pt.aggregateValue(array_fields_ty, union_field_vals)).toIntern();
16629 const new_decl_val = (try pt.aggregateValue(array_fields_ty, union_field_types)).toIntern();
1649916630 const slice_ty = (try pt.ptrType(.{
16500 .child = union_field_ty.toIntern(),
16631 .child = .type_type,
1650116632 .flags = .{
1650216633 .size = .slice,
1650316634 .is_const = true,
......@@ -16514,11 +16645,38 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1651416645 } },
1651516646 .byte_offset = 0,
1651616647 } }),
16517 .len = (try pt.intValue(.usize, union_field_vals.len)).toIntern(),
16648 .len = (try pt.intValue(.usize, union_field_types.len)).toIntern(),
16649 } });
16650 };
16651 const field_attrs_val = v: {
16652 const array_fields_ty = try pt.arrayType(.{
16653 .len = union_field_attrs.len,
16654 .child = union_field_attr_ty.toIntern(),
16655 });
16656 const new_decl_val = (try pt.aggregateValue(array_fields_ty, union_field_attrs)).toIntern();
16657 const slice_ty = (try pt.ptrType(.{
16658 .child = union_field_attr_ty.toIntern(),
16659 .flags = .{
16660 .size = .slice,
16661 .is_const = true,
16662 },
16663 })).toIntern();
16664 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
16665 break :v try pt.intern(.{ .slice = .{
16666 .ty = slice_ty,
16667 .ptr = try pt.intern(.{ .ptr = .{
16668 .ty = manyptr_ty,
16669 .base_addr = .{ .uav = .{
16670 .orig_ty = manyptr_ty,
16671 .val = new_decl_val,
16672 } },
16673 .byte_offset = 0,
16674 } }),
16675 .len = (try pt.intValue(.usize, union_field_attrs.len)).toIntern(),
1651816676 } });
1651916677 };
1652016678
16521 const decls_val = try sema.typeInfoDecls(src, ty.getNamespaceIndex(zcu).toOptional());
16679 const decl_names_val = try sema.typeInfoDecls(ty.getNamespaceIndex(zcu).toOptional());
1652216680
1652316681 const enum_tag_ty_val = try pt.intern(.{ .opt = .{
1652416682 .ty = (try pt.optionalType(.type_type)).toIntern(),
......@@ -16527,16 +16685,32 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1652716685
1652816686 const container_layout_ty = try sema.getStdLangType(src, .@"Type.ContainerLayout");
1652916687
16688 const backing_integer_val = try pt.intern(.{ .opt = .{
16689 .ty = (try pt.optionalType(.type_type)).toIntern(),
16690 .val = if (layout == .@"packed") val: {
16691 assert(Type.fromInterned(union_obj.packed_backing_int_type).isInt(zcu));
16692 break :val union_obj.packed_backing_int_type;
16693 } else .none,
16694 } });
16695
1653016696 const field_values = .{
1653116697 // layout: ContainerLayout,
1653216698 (try pt.enumValueFieldIndex(container_layout_ty, @intFromEnum(layout))).toIntern(),
1653316699
1653416700 // tag_type: ?type,
1653516701 enum_tag_ty_val,
16536 // fields: []const UnionField,
16537 fields_val,
16538 // decls: []const Declaration,
16539 decls_val,
16702 // backing_integer: ?type,
16703 backing_integer_val,
16704
16705 // field_names: []const [:0]const u8,
16706 field_names_val,
16707 // field_types: []const type,
16708 field_types_val,
16709 // field_attrs: []const FieldAttributes,
16710 field_attrs_val,
16711
16712 // decl_names: []const [:0]const u8,
16713 decl_names_val,
1654016714 };
1654116715 return Air.internedToRef((try pt.internUnion(.{
1654216716 .ty = type_info_ty.toIntern(),
......@@ -16546,16 +16720,26 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1654616720 },
1654716721 .@"struct" => {
1654816722 const type_struct_ty = try sema.getStdLangType(src, .@"Type.Struct");
16549 const struct_field_ty = try sema.getStdLangType(src, .@"Type.StructField");
16723 const struct_field_attr_ty = try sema.getStdLangType(src, .@"Type.Struct.FieldAttributes");
1655016724
16551 var struct_field_vals: []InternPool.Index = &.{};
16552 defer gpa.free(struct_field_vals);
16725 var struct_field_name_vals: []InternPool.Index = &.{};
16726 defer gpa.free(struct_field_name_vals);
16727 var struct_field_attr_vals: []InternPool.Index = &.{};
16728 defer gpa.free(struct_field_attr_vals);
1655316729 fv: {
1655416730 const struct_type = switch (ip.indexToKey(ty.toIntern())) {
1655516731 .tuple_type => |tuple_type| {
16556 struct_field_vals = try gpa.alloc(InternPool.Index, tuple_type.types.len);
16557 for (struct_field_vals, 0..) |*struct_field_val, field_index| {
16558 const field_ty = tuple_type.types.get(ip)[field_index];
16732 struct_field_name_vals = try gpa.alloc(InternPool.Index, tuple_type.types.len);
16733 struct_field_attr_vals = try gpa.alloc(InternPool.Index, tuple_type.types.len);
16734 for (
16735 struct_field_name_vals,
16736 struct_field_attr_vals,
16737 0..,
16738 ) |
16739 *struct_field_name_val,
16740 *struct_field_attr_val,
16741 field_index,
16742 | {
1655916743 const field_val = tuple_type.values.get(ip)[field_index];
1656016744 const name_val = v: {
1656116745 const field_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
......@@ -16587,19 +16771,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1658716771 const opt_default_val = if (is_comptime) Value.fromInterned(field_val) else null;
1658816772 const default_val_ptr = try sema.optRefValue(opt_default_val);
1658916773
16590 const struct_field_fields = .{
16591 // name: [:0]const u8,
16592 name_val,
16593 // type: type,
16594 field_ty,
16595 // default_value: ?*const anyopaque,
16596 default_val_ptr.toIntern(),
16597 // is_comptime: bool,
16774 const struct_field_attr_fields = .{
16775 // @"comptime": bool,
1659816776 Value.makeBool(is_comptime).toIntern(),
16599 // alignment: ?usize,
16777 // @"align": ?usize,
1660016778 (try pt.nullValue(try pt.optionalType(.usize_type))).toIntern(),
16779 // default_value_ptr: ?*const anyopaque,
16780 default_val_ptr.toIntern(),
1660116781 };
16602 struct_field_val.* = (try pt.aggregateValue(struct_field_ty, &struct_field_fields)).toIntern();
16782
16783 struct_field_name_val.* = name_val;
16784 struct_field_attr_val.* = (try pt.aggregateValue(struct_field_attr_ty, &struct_field_attr_fields)).toIntern();
1660316785 }
1660416786 break :fv;
1660516787 },
......@@ -16607,12 +16789,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1660716789 else => unreachable,
1660816790 };
1660916791 try sema.ensureStructDefaultsResolved(ty, src); // can't do this sooner, since it's not allowed on tuples
16610 struct_field_vals = try gpa.alloc(InternPool.Index, struct_type.field_types.len);
16611
16612 for (struct_field_vals, 0..) |*field_val, field_index| {
16792 struct_field_name_vals = try gpa.alloc(InternPool.Index, struct_type.field_types.len);
16793 struct_field_attr_vals = try gpa.alloc(InternPool.Index, struct_type.field_types.len);
16794
16795 for (
16796 struct_field_name_vals,
16797 struct_field_attr_vals,
16798 0..,
16799 ) |
16800 *field_name_val,
16801 *field_attr_val,
16802 field_index,
16803 | {
1661316804 const field_name = struct_type.field_names.get(ip)[field_index];
1661416805 const field_name_len = field_name.length(ip);
16615 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
1661616806 const field_default: InternPool.Index = if (struct_type.field_defaults.len > 0) d: {
1661716807 break :d struct_type.field_defaults.get(ip)[field_index];
1661816808 } else .none;
......@@ -16660,30 +16850,63 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1666016850 } }));
1666116851 };
1666216852
16663 const struct_field_fields = .{
16664 // name: [:0]const u8,
16665 name_val,
16666 // type: type,
16667 field_ty.toIntern(),
16668 // default_value: ?*const anyopaque,
16669 default_val_ptr.toIntern(),
16670 // is_comptime: bool,
16853 const struct_field_attr_fields = .{
16854 // @"comptime": bool,
1667116855 Value.makeBool(field_is_comptime).toIntern(),
16672 // alignment: ?usize,
16856 // @"align": ?usize,
1667316857 alignment_val.toIntern(),
16858 // default_value_ptr: ?*const anyopaque,
16859 default_val_ptr.toIntern(),
1667416860 };
16675 field_val.* = (try pt.aggregateValue(struct_field_ty, &struct_field_fields)).toIntern();
16861 field_name_val.* = name_val;
16862 field_attr_val.* = (try pt.aggregateValue(struct_field_attr_ty, &struct_field_attr_fields)).toIntern();
1667616863 }
1667716864 }
1667816865
16679 const fields_val = v: {
16866 const field_names_val = v: {
16867 const array_fields_ty = try pt.arrayType(.{
16868 .len = struct_field_name_vals.len,
16869 .child = .slice_const_u8_sentinel_0_type,
16870 });
16871 const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_name_vals)).toIntern();
16872 const slice_ty = (try pt.ptrType(.{
16873 .child = .slice_const_u8_sentinel_0_type,
16874 .flags = .{
16875 .size = .slice,
16876 .is_const = true,
16877 },
16878 })).toIntern();
16879 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
16880 break :v try pt.intern(.{ .slice = .{
16881 .ty = slice_ty,
16882 .ptr = try pt.intern(.{ .ptr = .{
16883 .ty = manyptr_ty,
16884 .base_addr = .{ .uav = .{
16885 .orig_ty = manyptr_ty,
16886 .val = new_decl_val,
16887 } },
16888 .byte_offset = 0,
16889 } }),
16890 .len = (try pt.intValue(.usize, struct_field_name_vals.len)).toIntern(),
16891 } });
16892 };
16893
16894 const field_types_val = v: {
16895 const struct_field_type_vals = switch (ip.indexToKey(ty.toIntern())) {
16896 .tuple_type => |tt| tt.types.get(ip),
16897 .struct_type => blk: {
16898 const st = ip.loadStructType(ty.toIntern());
16899 break :blk st.field_types.get(ip);
16900 },
16901 else => unreachable,
16902 };
1668016903 const array_fields_ty = try pt.arrayType(.{
16681 .len = struct_field_vals.len,
16682 .child = struct_field_ty.toIntern(),
16904 .len = struct_field_type_vals.len,
16905 .child = .type_type,
1668316906 });
16684 const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_vals)).toIntern();
16907 const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_type_vals)).toIntern();
1668516908 const slice_ty = (try pt.ptrType(.{
16686 .child = struct_field_ty.toIntern(),
16909 .child = .type_type,
1668716910 .flags = .{
1668816911 .size = .slice,
1668916912 .is_const = true,
......@@ -16700,11 +16923,38 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1670016923 } },
1670116924 .byte_offset = 0,
1670216925 } }),
16703 .len = (try pt.intValue(.usize, struct_field_vals.len)).toIntern(),
16926 .len = (try pt.intValue(.usize, struct_field_type_vals.len)).toIntern(),
16927 } });
16928 };
16929 const field_attrs_val = v: {
16930 const array_fields_ty = try pt.arrayType(.{
16931 .len = struct_field_attr_vals.len,
16932 .child = struct_field_attr_ty.toIntern(),
16933 });
16934 const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_attr_vals)).toIntern();
16935 const slice_ty = (try pt.ptrType(.{
16936 .child = struct_field_attr_ty.toIntern(),
16937 .flags = .{
16938 .size = .slice,
16939 .is_const = true,
16940 },
16941 })).toIntern();
16942 const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern();
16943 break :v try pt.intern(.{ .slice = .{
16944 .ty = slice_ty,
16945 .ptr = try pt.intern(.{ .ptr = .{
16946 .ty = manyptr_ty,
16947 .base_addr = .{ .uav = .{
16948 .orig_ty = manyptr_ty,
16949 .val = new_decl_val,
16950 } },
16951 .byte_offset = 0,
16952 } }),
16953 .len = (try pt.intValue(.usize, struct_field_attr_vals.len)).toIntern(),
1670416954 } });
1670516955 };
1670616956
16707 const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu));
16957 const decl_names_val = try sema.typeInfoDecls(ty.getNamespace(zcu));
1670816958
1670916959 const backing_integer_val = try pt.intern(.{ .opt = .{
1671016960 .ty = (try pt.optionalType(.type_type)).toIntern(),
......@@ -16719,16 +16969,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1671916969 const layout = ty.containerLayout(zcu);
1672016970
1672116971 const field_values = [_]InternPool.Index{
16972 // is_tuple: bool,
16973 Value.makeBool(ty.isTuple(zcu)).toIntern(),
1672216974 // layout: ContainerLayout,
1672316975 (try pt.enumValueFieldIndex(container_layout_ty, @intFromEnum(layout))).toIntern(),
1672416976 // backing_integer: ?type,
1672516977 backing_integer_val,
16726 // fields: []const StructField,
16727 fields_val,
16728 // decls: []const Declaration,
16729 decls_val,
16730 // is_tuple: bool,
16731 Value.makeBool(ty.isTuple(zcu)).toIntern(),
16978
16979 // field_names: []const [:0]const u8,
16980 field_names_val,
16981 // field_types: []const type,
16982 field_types_val,
16983 // field_attrs: []const FieldAttributes,
16984 field_attrs_val,
16985
16986 // decl_names: []const [:0]const u8,
16987 decl_names_val,
1673216988 };
1673316989 return Air.internedToRef((try pt.internUnion(.{
1673416990 .ty = type_info_ty.toIntern(),
......@@ -16739,11 +16995,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1673916995 .@"opaque" => {
1674016996 const type_opaque_ty = try sema.getStdLangType(src, .@"Type.Opaque");
1674116997
16742 const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu));
16998 const decl_names_val = try sema.typeInfoDecls(ty.getNamespace(zcu));
1674316999
1674417000 const field_values = .{
16745 // decls: []const Declaration,
16746 decls_val,
17001 // decl_names: []const [:0]const u8,
17002 decl_names_val,
1674717003 };
1674817004 return Air.internedToRef((try pt.internUnion(.{
1674917005 .ty = type_info_ty.toIntern(),
......@@ -16758,30 +17014,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1675817014
1675917015fn typeInfoDecls(
1676017016 sema: *Sema,
16761 src: LazySrcLoc,
1676217017 opt_namespace: InternPool.OptionalNamespaceIndex,
1676317018) CompileError!InternPool.Index {
1676417019 const pt = sema.pt;
1676517020 const zcu = pt.zcu;
1676617021 const gpa = sema.gpa;
1676717022
16768 const declaration_ty = try sema.getStdLangType(src, .@"Type.Declaration");
16769
1677017023 var decl_vals = std.array_list.Managed(InternPool.Index).init(gpa);
1677117024 defer decl_vals.deinit();
1677217025
1677317026 var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa);
1677417027 defer seen_namespaces.deinit();
1677517028
16776 try sema.typeInfoNamespaceDecls(opt_namespace, declaration_ty, &decl_vals, &seen_namespaces);
17029 try sema.typeInfoNamespaceDecls(opt_namespace, &decl_vals, &seen_namespaces);
1677717030
1677817031 const array_decl_ty = try pt.arrayType(.{
1677917032 .len = decl_vals.items.len,
16780 .child = declaration_ty.toIntern(),
17033 .child = .slice_const_u8_sentinel_0_type,
1678117034 });
1678217035 const new_decl_val = (try pt.aggregateValue(array_decl_ty, decl_vals.items)).toIntern();
1678317036 const slice_ty = (try pt.ptrType(.{
16784 .child = declaration_ty.toIntern(),
17037 .child = .slice_const_u8_sentinel_0_type,
1678517038 .flags = .{
1678617039 .size = .slice,
1678717040 .is_const = true,
......@@ -16805,7 +17058,6 @@ fn typeInfoDecls(
1680517058fn typeInfoNamespaceDecls(
1680617059 sema: *Sema,
1680717060 opt_namespace_index: InternPool.OptionalNamespaceIndex,
16808 declaration_ty: Type,
1680917061 decl_vals: *std.array_list.Managed(InternPool.Index),
1681017062 seen_namespaces: *std.AutoHashMap(*Namespace, void),
1681117063) !void {
......@@ -16850,11 +17102,7 @@ fn typeInfoNamespaceDecls(
1685017102 },
1685117103 });
1685217104 };
16853 const fields = [_]InternPool.Index{
16854 // name: [:0]const u8,
16855 name_val,
16856 };
16857 try decl_vals.append((try pt.aggregateValue(declaration_ty, &fields)).toIntern());
17105 try decl_vals.append(name_val);
1685817106 }
1685917107}
1686017108
......@@ -17120,9 +17368,9 @@ fn finishCondBr(
1712017368) !Air.Inst.Ref {
1712117369 const gpa = sema.gpa;
1712217370
17123 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len +
17371 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len +
1712417372 then_block.instructions.items.len + else_block.instructions.items.len +
17125 @typeInfo(Air.Block).@"struct".fields.len + child_block.instructions.items.len + 1);
17373 @typeInfo(Air.Block).@"struct".field_names.len + child_block.instructions.items.len + 1);
1712617374
1712717375 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
1712817376 .then_body_len = @intCast(then_block.instructions.items.len),
......@@ -17331,7 +17579,7 @@ fn zirCondbr(
1733117579 break :h .unlikely;
1733217580 } else try sema.analyzeBodyRuntimeBreak(&sub_block, else_body);
1733317581
17334 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len +
17582 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len +
1733517583 true_instructions.len + sub_block.instructions.items.len);
1733617584 _ = try parent_block.addInst(.{
1733717585 .tag = .cond_br,
......@@ -17403,7 +17651,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1740317651 // The only interesting hint here is `.cold`, which can come from e.g. `errdefer @panic`.
1740417652 const is_cold = sema.branch_hint == .cold;
1740517653
17406 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Try).@"struct".fields.len +
17654 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Try).@"struct".field_names.len +
1740717655 sub_block.instructions.items.len);
1740817656 const try_inst = try parent_block.addInst(.{
1740917657 .tag = if (is_cold) .try_cold else .@"try",
......@@ -17483,7 +17731,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1748317731 },
1748417732 });
1748517733 const res_ty_ref = Air.internedToRef(res_ty.toIntern());
17486 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".fields.len +
17734 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".field_names.len +
1748717735 sub_block.instructions.items.len);
1748817736 const try_inst = try parent_block.addInst(.{
1748917737 .tag = if (is_cold) .try_ptr_cold else .try_ptr,
......@@ -17731,9 +17979,9 @@ fn maybePushErrorTrace(
1773117979 try sema.air_instructions.ensureUnusedCapacity(gpa, 4);
1773217980 try sema.air_extra.ensureUnusedCapacity(
1773317981 gpa,
17734 @typeInfo(Air.Block).@"struct".fields.len +
17982 @typeInfo(Air.Block).@"struct".field_names.len +
1773517983 1 + // the main block contains only the `cond_br`
17736 @typeInfo(Air.CondBr).@"struct".fields.len +
17984 @typeInfo(Air.CondBr).@"struct".field_names.len +
1773717985 1 + // the non-error branch contains only a `br`
1773817986 err_block.instructions.items.len + 1, // the error branch contains the `returnError` call and a `br`
1773917987 );
......@@ -19470,11 +19718,11 @@ fn zirReifySliceArgTy(
1947019718
1947119719 const comptime_reason: std.zig.SimpleComptimeReason, const in_scalar_ty: Type, const out_scalar_ty: Type = switch (info) {
1947219720 // zig fmt: off
19473 .type_to_fn_param_attrs => .{ .fn_param_attrs, .type, try sema.getStdLangType(src, .@"Type.Fn.Param.Attributes") },
19721 .type_to_fn_param_attrs => .{ .fn_param_attrs, .type, try sema.getStdLangType(src, .@"Type.Fn.ParamAttributes") },
1947419722 .string_to_struct_field_type => .{ .struct_field_types, .slice_const_u8, .type },
1947519723 .string_to_union_field_type => .{ .union_field_types, .slice_const_u8, .type },
19476 .string_to_struct_field_attrs => .{ .struct_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.StructField.Attributes") },
19477 .string_to_union_field_attrs => .{ .union_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.UnionField.Attributes") },
19724 .string_to_struct_field_attrs => .{ .struct_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.Struct.FieldAttributes") },
19725 .string_to_union_field_attrs => .{ .union_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.Union.FieldAttributes") },
1947819726 // zig fmt: on
1947919727 };
1948019728
......@@ -19688,7 +19936,7 @@ fn zirReifyFn(
1968819936 const ret_ty_src = block.builtinCallArgSrc(extra.node, 2);
1968919937 const fn_attrs_src = block.builtinCallArgSrc(extra.node, 3);
1969019938
19691 const single_param_attrs_ty = try sema.getStdLangType(param_attrs_src, .@"Type.Fn.Param.Attributes");
19939 const single_param_attrs_ty = try sema.getStdLangType(param_attrs_src, .@"Type.Fn.ParamAttributes");
1969219940 const fn_attrs_ty = try sema.getStdLangType(fn_attrs_src, .@"Type.Fn.Attributes");
1969319941
1969419942 const param_types_uncoerced = sema.resolveInst(extra.param_types);
......@@ -19722,7 +19970,7 @@ fn zirReifyFn(
1972219970 block,
1972319971 param_attrs_src,
1972419972 try param_attrs_arr.elemValue(pt, param_idx),
19725 std.lang.Type.Fn.Param.Attributes,
19973 std.lang.Type.Fn.ParamAttributes,
1972619974 );
1972719975 try sema.checkParamType(
1972819976 block,
......@@ -19827,7 +20075,7 @@ fn zirReifyStruct(
1982720075 };
1982820076
1982920077 const container_layout_ty = try sema.getStdLangType(layout_src, .@"Type.ContainerLayout");
19830 const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.StructField.Attributes");
20078 const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.Struct.FieldAttributes");
1983120079
1983220080 const layout_uncoerced = sema.resolveInst(extra.layout);
1983320081 const layout_coerced = try sema.coerce(block, container_layout_ty, layout_uncoerced, layout_src);
......@@ -19913,15 +20161,15 @@ fn zirReifyStruct(
1991320161 const field_name = try sema.sliceToIpString(block, field_names_src, field_name_val, .{ .simple = .struct_field_names });
1991420162
1991520163 const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
19916 std.lang.Type.StructField.Attributes,
20164 std.lang.Type.Struct.FieldAttributes,
1991720165 "comptime",
1991820166 ).?);
1991920167 const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
19920 std.lang.Type.StructField.Attributes,
20168 std.lang.Type.Struct.FieldAttributes,
1992120169 "align",
1992220170 ).?);
1992320171 const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
19924 std.lang.Type.StructField.Attributes,
20172 std.lang.Type.Struct.FieldAttributes,
1992520173 "default_value_ptr",
1992620174 ).?);
1992720175
......@@ -19998,15 +20246,15 @@ fn zirReifyStruct(
1999820246 wip.field_types.get(ip)[field_idx] = field_ty.toIntern();
1999920247
2000020248 const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20001 std.lang.Type.StructField.Attributes,
20249 std.lang.Type.Struct.FieldAttributes,
2000220250 "comptime",
2000320251 ).?);
2000420252 const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20005 std.lang.Type.StructField.Attributes,
20253 std.lang.Type.Struct.FieldAttributes,
2000620254 "align",
2000720255 ).?);
2000820256 const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20009 std.lang.Type.StructField.Attributes,
20257 std.lang.Type.Struct.FieldAttributes,
2001020258 "default_value_ptr",
2001120259 ).?);
2001220260
......@@ -20107,7 +20355,7 @@ fn zirReifyUnion(
2010720355 };
2010820356
2010920357 const container_layout_ty = try sema.getStdLangType(layout_src, .@"Type.ContainerLayout");
20110 const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.UnionField.Attributes");
20358 const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.Union.FieldAttributes");
2011120359
2011220360 const layout_uncoerced = sema.resolveInst(extra.layout);
2011320361 const layout_coerced = try sema.coerce(block, container_layout_ty, layout_uncoerced, layout_src);
......@@ -20196,7 +20444,7 @@ fn zirReifyUnion(
2019620444 block,
2019720445 field_attrs_src,
2019820446 try field_attrs_arr.elemValue(pt, field_idx),
20199 std.lang.Type.UnionField.Attributes,
20447 std.lang.Type.Union.FieldAttributes,
2020020448 );
2020120449 if (field_attrs.@"align") |bytes| {
2020220450 if (layout == .@"packed") {
......@@ -20245,7 +20493,7 @@ fn zirReifyUnion(
2024520493 block,
2024620494 .unneeded,
2024720495 try field_attrs_arr.elemValue(pt, field_idx),
20248 std.lang.Type.UnionField.Attributes,
20496 std.lang.Type.Union.FieldAttributes,
2024920497 );
2025020498 if (field_attrs.@"align") |bytes| {
2025120499 // No source location; first loop checked this is valid.
......@@ -25211,9 +25459,9 @@ fn addSafetyCheckExtra(
2521125459
2521225460 try parent_block.instructions.ensureUnusedCapacity(gpa, 1);
2521325461
25214 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
25462 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
2521525463 1 + // The main block only needs space for the cond_br.
25216 @typeInfo(Air.CondBr).@"struct".fields.len +
25464 @typeInfo(Air.CondBr).@"struct".field_names.len +
2521725465 1 + // The ok branch of the cond_br only needs space for the br.
2521825466 fail_block.instructions.items.len);
2521925467
......@@ -33021,8 +33269,8 @@ pub fn getTmpAir(sema: Sema) Air {
3302133269}
3302233270
3302333271pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
33024 const fields = std.meta.fields(@TypeOf(extra));
33025 try sema.air_extra.ensureUnusedCapacity(sema.gpa, fields.len);
33272 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
33273 try sema.air_extra.ensureUnusedCapacity(sema.gpa, field_count);
3302633274 return sema.addExtraAssumeCapacity(extra);
3302733275}
3302833276
......@@ -33032,15 +33280,15 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
3303233280 return result;
3303333281}
3303433282
33035fn payloadToExtraItems(data: anytype) [@typeInfo(@TypeOf(data)).@"struct".fields.len]u32 {
33036 const fields = @typeInfo(@TypeOf(data)).@"struct".fields;
33037 var result: [fields.len]u32 = undefined;
33038 inline for (&result, fields) |*val, field| {
33039 val.* = switch (field.type) {
33040 u32 => @field(data, field.name),
33041 i32, Air.CondBr.BranchHints, Air.Asm.Flags => @bitCast(@field(data, field.name)),
33042 Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(data, field.name)),
33043 else => @compileError("bad field type: " ++ @typeName(field.type)),
33283fn payloadToExtraItems(data: anytype) [@typeInfo(@TypeOf(data)).@"struct".field_names.len]u32 {
33284 const info = @typeInfo(@TypeOf(data)).@"struct";
33285 var result: [info.field_names.len]u32 = undefined;
33286 inline for (&result, info.field_names, info.field_types) |*val, field_name, field_type| {
33287 val.* = switch (field_type) {
33288 u32 => @field(data, field_name),
33289 i32, Air.CondBr.BranchHints, Air.Asm.Flags => @bitCast(@field(data, field_name)),
33290 Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(data, field_name)),
33291 else => @compileError("bad field type: " ++ @typeName(field_type)),
3304433292 };
3304533293 }
3304633294 return result;
src/Value.zig+15-15
......@@ -2288,23 +2288,23 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
22882288
22892289 .@"struct" => |@"struct"| switch (interpret_mode) {
22902290 .direct => {
2291 if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;
2291 if (ty.structFieldCount(zcu) != @"struct".field_names.len) return error.TypeMismatch;
22922292 var result: T = undefined;
2293 inline for (@"struct".fields, 0..) |field, field_idx| {
2293 inline for (@"struct".field_names, @"struct".field_types, 0..) |field_name, field_type, field_idx| {
22942294 const field_val = try val.fieldValue(pt, field_idx);
2295 @field(result, field.name) = try field_val.interpret(field.type, pt);
2295 @field(result, field_name) = try field_val.interpret(field_type, pt);
22962296 }
22972297 return result;
22982298 },
22992299 .by_name => {
23002300 const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;
23012301 var result: T = undefined;
2302 inline for (@"struct".fields) |field| {
2303 const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field.name, .no_embedded_nulls);
2304 @field(result, field.name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: {
2302 inline for (@"struct".field_names, @"struct".field_types, @"struct".field_attrs) |field_name, field_type, field_attr| {
2303 const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field_name, .no_embedded_nulls);
2304 @field(result, field_name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: {
23052305 const field_val = try val.fieldValue(pt, field_idx);
2306 break :f try field_val.interpret(field.type, pt);
2307 } else (field.defaultValue() orelse return error.TypeMismatch);
2306 break :f try field_val.interpret(field_type, pt);
2307 } else (field_attr.defaultValue(field_type) orelse return error.TypeMismatch);
23082308 }
23092309 return result;
23102310 },
......@@ -2385,11 +2385,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
23852385
23862386 .@"struct" => |@"struct"| switch (interpret_mode) {
23872387 .direct => {
2388 if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;
2389 var field_vals: [@"struct".fields.len]InternPool.Index = undefined;
2390 inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| {
2388 if (ty.structFieldCount(zcu) != @"struct".field_names.len) return error.TypeMismatch;
2389 var field_vals: [@"struct".field_names.len]InternPool.Index = undefined;
2390 inline for (&field_vals, @"struct".field_names, 0..) |*field_val, field_name, field_idx| {
23912391 const field_ty = ty.fieldType(field_idx, zcu);
2392 field_val.* = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();
2392 field_val.* = (try uninterpret(@field(val, field_name), field_ty, pt)).toIntern();
23932393 }
23942394 return pt.aggregateValue(ty, &field_vals);
23952395 },
......@@ -2399,11 +2399,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
23992399 const field_vals = try zcu.gpa.alloc(InternPool.Index, want_fields_len);
24002400 defer zcu.gpa.free(field_vals);
24012401 @memset(field_vals, .none);
2402 inline for (@"struct".fields) |field| {
2403 const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field.name, .no_embedded_nulls);
2402 inline for (@"struct".field_names) |field_name| {
2403 const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field_name, .no_embedded_nulls);
24042404 if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| {
24052405 const field_ty = ty.fieldType(field_idx, zcu);
2406 field_vals[field_idx] = (try uninterpret(@field(val, field.name), field_ty, pt)).toIntern();
2406 field_vals[field_idx] = (try uninterpret(@field(val, field_name), field_ty, pt)).toIntern();
24072407 }
24082408 }
24092409 for (field_vals, 0..) |*field_val, field_idx| {
src/Zcu.zig+15-25
......@@ -48,12 +48,12 @@ const ZonGen = std.zig.ZonGen;
4848comptime {
4949 @setEvalBranchQuota(4000);
5050 for (
51 @typeInfo(Zir.Inst.Ref).@"enum".fields,
52 @typeInfo(Air.Inst.Ref).@"enum".fields,
53 @typeInfo(InternPool.Index).@"enum".fields,
54 ) |zir_field, air_field, ip_field| {
55 assert(mem.eql(u8, zir_field.name, ip_field.name));
56 assert(mem.eql(u8, air_field.name, ip_field.name));
51 @typeInfo(Zir.Inst.Ref).@"enum".field_names,
52 @typeInfo(Air.Inst.Ref).@"enum".field_names,
53 @typeInfo(InternPool.Index).@"enum".field_names,
54 ) |zir_field_name, air_field_name, ip_field_name| {
55 assert(mem.eql(u8, zir_field_name, ip_field_name));
56 assert(mem.eql(u8, air_field_name, ip_field_name));
5757 }
5858}
5959
......@@ -448,8 +448,7 @@ pub const StdLangDecl = enum {
448448
449449 Type,
450450 @"Type.Fn",
451 @"Type.Fn.Param",
452 @"Type.Fn.Param.Attributes",
451 @"Type.Fn.ParamAttributes",
453452 @"Type.Fn.Attributes",
454453 @"Type.Int",
455454 @"Type.Float",
......@@ -459,20 +458,16 @@ pub const StdLangDecl = enum {
459458 @"Type.Array",
460459 @"Type.Vector",
461460 @"Type.Optional",
462 @"Type.Error",
463461 @"Type.ErrorUnion",
464 @"Type.EnumField",
462 @"Type.ErrorSet",
465463 @"Type.Enum",
466464 @"Type.Enum.Mode",
467465 @"Type.Union",
468 @"Type.UnionField",
469 @"Type.UnionField.Attributes",
466 @"Type.Union.FieldAttributes",
470467 @"Type.Struct",
471 @"Type.StructField",
472 @"Type.StructField.Attributes",
468 @"Type.Struct.FieldAttributes",
473469 @"Type.ContainerLayout",
474470 @"Type.Opaque",
475 @"Type.Declaration",
476471
477472 panic,
478473 @"panic.call",
......@@ -533,8 +528,7 @@ pub const StdLangDecl = enum {
533528
534529 .Type,
535530 .@"Type.Fn",
536 .@"Type.Fn.Param",
537 .@"Type.Fn.Param.Attributes",
531 .@"Type.Fn.ParamAttributes",
538532 .@"Type.Fn.Attributes",
539533 .@"Type.Int",
540534 .@"Type.Float",
......@@ -544,20 +538,16 @@ pub const StdLangDecl = enum {
544538 .@"Type.Array",
545539 .@"Type.Vector",
546540 .@"Type.Optional",
547 .@"Type.Error",
548541 .@"Type.ErrorUnion",
549 .@"Type.EnumField",
542 .@"Type.ErrorSet",
550543 .@"Type.Enum",
551544 .@"Type.Enum.Mode",
552545 .@"Type.Union",
553 .@"Type.UnionField",
554 .@"Type.UnionField.Attributes",
546 .@"Type.Union.FieldAttributes",
555547 .@"Type.Struct",
556 .@"Type.StructField",
557 .@"Type.StructField.Attributes",
548 .@"Type.Struct.FieldAttributes",
558549 .@"Type.ContainerLayout",
559550 .@"Type.Opaque",
560 .@"Type.Declaration",
561551 => .type,
562552
563553 .panic => .type,
......@@ -611,7 +601,7 @@ pub const StdLangDecl = enum {
611601 .VaList => .va_list,
612602 .assembly, .@"assembly.Clobbers" => .assembly,
613603 else => {
614 if (@intFromEnum(decl) <= @intFromEnum(StdLangDecl.@"Type.Declaration")) {
604 if (@intFromEnum(decl) <= @intFromEnum(StdLangDecl.@"Type.Opaque")) {
615605 return .main;
616606 } else {
617607 return .panic;
src/Zcu/PerThread.zig+2-2
......@@ -3344,7 +3344,7 @@ fn analyzeFuncBodyInner(
33443344 ip.funcSetHasErrorTrace(io, func_index, fn_ty_info.cc == .auto);
33453345
33463346 // First few indexes of extra are reserved and set at the end.
3347 const reserved_count = @typeInfo(Air.ExtraIndex).@"enum".fields.len;
3347 const reserved_count = @typeInfo(Air.ExtraIndex).@"enum".field_names.len;
33483348 try sema.air_extra.ensureTotalCapacity(gpa, reserved_count);
33493349 sema.air_extra.items.len += reserved_count;
33503350
......@@ -3477,7 +3477,7 @@ fn analyzeFuncBodyInner(
34773477 }
34783478
34793479 // Copy the block into place and mark that as the main block.
3480 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len +
3480 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len +
34813481 inner_block.instructions.items.len);
34823482 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{
34833483 .body_len = @intCast(inner_block.instructions.items.len),
src/codegen/aarch64/Assemble.zig+27-26
......@@ -41,7 +41,7 @@ fn zonCast(comptime Result: type, zon_value: anytype, symbols: anytype) Result {
4141 .void, .bool, .int, .float, .pointer, .comptime_float, .comptime_int, .@"enum" => return zon_value,
4242 .@"struct" => |zon_struct| switch (@typeInfo(Result)) {
4343 .pointer => |result_pointer| {
44 comptime assert(result_pointer.size == .slice and result_pointer.is_const);
44 comptime assert(result_pointer.size == .slice and result_pointer.attrs.@"const");
4545 const elems = comptime blk: {
4646 var temp_elems: [zon_value.len]result_pointer.child = undefined;
4747 for (&temp_elems, zon_value) |*elem, zon_elem| elem.* = zonCast(result_pointer.child, zon_elem, symbols);
......@@ -52,16 +52,17 @@ fn zonCast(comptime Result: type, zon_value: anytype, symbols: anytype) Result {
5252 .@"struct" => |result_struct| {
5353 comptime var used_zon_fields = 0;
5454 var result: Result = undefined;
55 inline for (result_struct.fields) |result_field| @field(result, result_field.name) = if (@hasField(ZonValue, result_field.name)) result: {
56 used_zon_fields += 1;
57 break :result zonCast(@FieldType(Result, result_field.name), @field(zon_value, result_field.name), symbols);
58 } else result_field.defaultValue() orelse @compileError(std.fmt.comptimePrint("missing zon field '{s}': {} <- {any}", .{ result_field.name, Result, zon_value }));
59 if (used_zon_fields != zon_struct.fields.len) @compileError(std.fmt.comptimePrint("unused zon field: {} <- {any}", .{ Result, zon_value }));
55 inline for (result_struct.field_names, result_struct.field_types, result_struct.field_attrs) |result_field_name, result_field_type, result_field_attrs|
56 @field(result, result_field_name) = if (@hasField(ZonValue, result_field_name)) result: {
57 used_zon_fields += 1;
58 break :result zonCast(@FieldType(Result, result_field_name), @field(zon_value, result_field_name), symbols);
59 } else result_field_attrs.defaultValue(result_field_type) orelse @compileError(std.fmt.comptimePrint("missing zon field '{s}': {} <- {any}", .{ result_field_name, Result, zon_value }));
60 if (used_zon_fields != zon_struct.field_names.len) @compileError(std.fmt.comptimePrint("unused zon field: {} <- {any}", .{ Result, zon_value }));
6061 return result;
6162 },
6263 .@"union" => {
63 if (zon_struct.fields.len != 1) @compileError(std.fmt.comptimePrint("{} <- {any}", .{ Result, zon_value }));
64 const field_name = zon_struct.fields[0].name;
64 if (zon_struct.field_names.len != 1) @compileError(std.fmt.comptimePrint("{} <- {any}", .{ Result, zon_value }));
65 const field_name = zon_struct.field_names[0];
6566 return @unionInit(
6667 Result,
6768 field_name,
......@@ -106,12 +107,12 @@ const matchers = matchers: {
106107 var mut_matchers: [instructions.len]*const fn (as: *Assemble) error{InvalidSyntax}!?Instruction = undefined;
107108 for (instructions, &mut_matchers) |instruction, *matcher| matcher.* = struct {
108109 fn match(as: *Assemble) !?Instruction {
109 comptime for (@typeInfo(@TypeOf(instruction)).@"struct".fields) |field| {
110 if (std.mem.eql(u8, field.name, "requires")) continue;
111 if (std.mem.eql(u8, field.name, "pattern")) continue;
112 if (std.mem.eql(u8, field.name, "symbols")) continue;
113 if (std.mem.eql(u8, field.name, "encode")) continue;
114 @compileError("unexpected field '" ++ field.name ++ "'");
110 comptime for (@typeInfo(@TypeOf(instruction)).@"struct".field_names) |field_name| {
111 if (std.mem.eql(u8, field_name, "requires")) continue;
112 if (std.mem.eql(u8, field_name, "pattern")) continue;
113 if (std.mem.eql(u8, field_name, "symbols")) continue;
114 if (std.mem.eql(u8, field_name, "encode")) continue;
115 @compileError("unexpected field '" ++ field_name ++ "'");
115116 };
116117 if (@hasField(@TypeOf(instruction), "requires")) _ = zonCast(
117118 []const std.Target.aarch64.Feature,
......@@ -119,12 +120,12 @@ const matchers = matchers: {
119120 .{},
120121 );
121122 var symbols: Symbols: {
122 const symbols = @typeInfo(@TypeOf(instruction.symbols)).@"struct".fields;
123 var field_names: [symbols.len][]const u8 = undefined;
124 var field_types: [symbols.len]type = undefined;
125 for (symbols, &field_names, &field_types) |symbol, *field_name, *FieldType| {
126 field_name.* = symbol.name;
127 FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage();
123 const symbol_names = @typeInfo(@TypeOf(instruction.symbols)).@"struct".field_names;
124 var field_names: [symbol_names.len][]const u8 = undefined;
125 var field_types: [symbol_names.len]type = undefined;
126 for (symbol_names, &field_names, &field_types) |symbol_name, *field_name, *FieldType| {
127 field_name.* = symbol_name;
128 FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).Storage();
128129 }
129130 break :Symbols @Struct(.auto, null, &field_names, &field_types, &@splat(.{}));
130131 } = undefined;
......@@ -158,8 +159,8 @@ const matchers = matchers: {
158159 const encode = @field(Instruction, @tagName(instruction.encode[0]));
159160 const Encode = @TypeOf(encode);
160161 var args: std.meta.ArgsTuple(Encode) = undefined;
161 inline for (&args, @typeInfo(Encode).@"fn".params, 1..instruction.encode.len) |*arg, param, encode_index|
162 arg.* = zonCast(param.type.?, instruction.encode[encode_index], symbols);
162 inline for (&args, @typeInfo(Encode).@"fn".param_types, 1..instruction.encode.len) |*arg, param_type, encode_index|
163 arg.* = zonCast(param_type.?, instruction.encode[encode_index], symbols);
163164 return @call(.auto, encode, args);
164165 } else if (pattern_token[0] == '<') {
165166 const symbol_name = comptime pattern_token[1 .. std.mem.indexOfScalarPos(u8, pattern_token, 1, '|') orelse
......@@ -369,7 +370,7 @@ const SymbolSpec = union(enum) {
369370 var buf: [
370371 max_len: {
371372 var max_len = 0;
372 for (@typeInfo(Result).@"enum".fields) |field| max_len = @max(max_len, field.name.len);
373 for (@typeInfo(Result).@"enum".field_names) |field_name| max_len = @max(max_len, field_name.len);
373374 break :max_len max_len;
374375 } + 1
375376 ]u8 = undefined;
......@@ -466,7 +467,7 @@ const SymbolSpec = union(enum) {
466467 var buf: [
467468 max_len: {
468469 var max_len = 0;
469 for (@typeInfo(Result).@"enum".fields) |field| max_len = @max(max_len, field.name.len);
470 for (@typeInfo(Result).@"enum".field_names) |field_name| max_len = @max(max_len, field_name.len);
470471 break :max_len max_len;
471472 } + 1
472473 ]u8 = undefined;
......@@ -487,7 +488,7 @@ const SymbolSpec = union(enum) {
487488 var buf: [
488489 max_len: {
489490 var max_len = 0;
490 for (@typeInfo(Result).@"enum".fields) |field| max_len = @max(max_len, field.name.len);
491 for (@typeInfo(Result).@"enum".field_names) |field_name| max_len = @max(max_len, field_name.len);
491492 break :max_len max_len;
492493 } + 1
493494 ]u8 = undefined;
......@@ -508,7 +509,7 @@ const SymbolSpec = union(enum) {
508509 var buf: [
509510 max_len: {
510511 var max_len = 0;
511 for (@typeInfo(Result).@"enum".fields) |field| max_len = @max(max_len, field.name.len);
512 for (@typeInfo(Result).@"enum".field_names) |field_name| max_len = @max(max_len, field_name.len);
512513 break :max_len max_len;
513514 } + 1
514515 ]u8 = undefined;
src/codegen/aarch64/Select.zig+5-17
......@@ -8891,14 +8891,8 @@ pub const Value = struct {
88918891
88928892 pub const Tag = @typeInfo(Parent).@"union".tag_type.?;
88938893 pub const Payload = Payload: {
8894 const fields = @typeInfo(Parent).@"union".fields;
8895 var types: [fields.len]type = undefined;
8896 var names: [fields.len][]const u8 = undefined;
8897 for (fields, &types, &names) |f, *ty, *name| {
8898 ty.* = f.type;
8899 name.* = f.name;
8900 }
8901 break :Payload @Union(.auto, null, &names, &types, &@splat(.{}));
8894 const info = @typeInfo(Parent).@"union";
8895 break :Payload @Union(.auto, null, info.field_names, info.field_types[0..], &@splat(.{}));
89028896 };
89038897 };
89048898
......@@ -8916,14 +8910,8 @@ pub const Value = struct {
89168910
89178911 pub const Tag = @typeInfo(Location).@"union".tag_type.?;
89188912 pub const Payload = Payload: {
8919 const fields = @typeInfo(Location).@"union".fields;
8920 var types: [fields.len]type = undefined;
8921 var names: [fields.len][]const u8 = undefined;
8922 for (fields, &types, &names) |f, *ty, *name| {
8923 ty.* = f.type;
8924 name.* = f.name;
8925 }
8926 break :Payload @Union(.auto, null, &names, &types, &@splat(.{}));
8913 const info = @typeInfo(Location).@"union";
8914 break :Payload @Union(.auto, null, info.field_names, info.field_types[0..], &@splat(.{}));
89278915 };
89288916 };
89298917
......@@ -11257,7 +11245,7 @@ fn dumpValuesInner(isel: *Select, which: WhichValues) !void {
1125711245 var reverse_live_registers: std.AutoHashMapUnmanaged(Value.Index, Register.Alias) = .empty;
1125811246 defer reverse_live_registers.deinit(gpa);
1125911247 {
11260 try reverse_live_registers.ensureTotalCapacity(gpa, @typeInfo(Register.Alias).@"enum".fields.len);
11248 try reverse_live_registers.ensureTotalCapacity(gpa, @typeInfo(Register.Alias).@"enum".field_names.len);
1126111249 var live_reg_it = isel.live_registers.iterator();
1126211250 while (live_reg_it.next()) |live_reg_entry| switch (live_reg_entry.value.*) {
1126311251 _ => reverse_live_registers.putAssumeCapacityNoClobber(live_reg_entry.value.*, live_reg_entry.key),
src/codegen/aarch64/encoding.zig+16-16
......@@ -1271,9 +1271,9 @@ pub const Register = struct {
12711271 if (symbol_it.next() != null) break :encoded;
12721272 return .{ .op0 = op0, .op1 = op1, .CRn = CRn, .CRm = CRm, .op2 = op2 };
12731273 }
1274 inline for (@typeInfo(System).@"struct".decls) |decl| {
1275 if (@TypeOf(@field(System, decl.name)) != System) continue;
1276 if (toLowerEqlAssertLower(reg, decl.name)) return @field(System, decl.name);
1274 inline for (@typeInfo(System).@"struct".decl_names) |decl_name| {
1275 if (@TypeOf(@field(System, decl_name)) != System) continue;
1276 if (toLowerEqlAssertLower(reg, decl_name)) return @field(System, decl_name);
12771277 }
12781278 return null;
12791279 }
......@@ -16561,30 +16561,30 @@ pub const Instruction = packed union {
1656116561 if (info.layout != .@"packed" or @bitSizeOf(Type) != @bitSizeOf(Backing)) {
1656216562 @compileLog(name ++ " should have u32 abi");
1656316563 }
16564 for (info.fields) |field| verify(name ++ "." ++ field.name, field.type);
16564 for (info.field_names, info.field_types) |field_name, field_type| verify(name ++ "." ++ field_name, field_type);
1656516565 },
1656616566 .@"struct" => |info| {
1656716567 if (info.layout != .@"packed" or info.backing_integer != Backing) {
1656816568 @compileLog(name ++ " should have u32 abi");
1656916569 }
1657016570 var bit_offset = 0;
16571 for (info.fields) |field| {
16572 if (std.mem.startsWith(u8, field.name, "encoded")) {
16573 if (if (std.fmt.parseInt(u5, field.name["encoded".len..], 10)) |encoded_bit_offset| encoded_bit_offset != bit_offset else |_| true) {
16574 @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field.name, bit_offset }));
16571 for (info.field_names, info.field_types, info.field_attrs) |field_name, field_type, field_attrs| {
16572 if (std.mem.startsWith(u8, field_name, "encoded")) {
16573 if (if (std.fmt.parseInt(u5, field_name["encoded".len..], 10)) |encoded_bit_offset| encoded_bit_offset != bit_offset else |_| true) {
16574 @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field_name, bit_offset }));
1657516575 }
16576 if (field.default_value_ptr != null) {
16577 @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field.name, bit_offset }));
16576 if (field_attrs.default_value_ptr != null) {
16577 @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field_name, bit_offset }));
1657816578 }
16579 } else if (std.mem.startsWith(u8, field.name, "decoded")) {
16580 if (if (std.fmt.parseInt(u5, field.name["decoded".len..], 10)) |decoded_bit_offset| decoded_bit_offset != bit_offset else |_| true) {
16581 @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field.name, bit_offset }));
16579 } else if (std.mem.startsWith(u8, field_name, "decoded")) {
16580 if (if (std.fmt.parseInt(u5, field_name["decoded".len..], 10)) |decoded_bit_offset| decoded_bit_offset != bit_offset else |_| true) {
16581 @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field_name, bit_offset }));
1658216582 }
16583 if (field.default_value_ptr == null) {
16584 @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field.name, bit_offset }));
16583 if (field_attrs.default_value_ptr == null) {
16584 @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field_name, bit_offset }));
1658516585 }
1658616586 }
16587 bit_offset += @bitSizeOf(field.type);
16587 bit_offset += @bitSizeOf(field_type);
1658816588 }
1658916589 },
1659016590 else => @compileError(name ++ " has an unexpected field type"),
src/codegen/riscv64/bits.zig+2-2
......@@ -190,7 +190,7 @@ pub const Register = enum(u8) {
190190 /// The goal of this function is to return the same ID for `zero` and `x0` but two
191191 /// seperate IDs for `x0` and `f0`. We will assume that each register set has 32 registers
192192 /// and is repeated twice, once for the named version, once for the number version.
193 pub fn id(reg: Register) std.math.IntFittingRange(0, @typeInfo(Register).@"enum".fields.len) {
193 pub fn id(reg: Register) std.math.IntFittingRange(0, @typeInfo(Register).@"enum".field_names.len) {
194194 const base = switch (@intFromEnum(reg)) {
195195 // zig fmt: off
196196 @intFromEnum(Register.zero) ... @intFromEnum(Register.x31) => @intFromEnum(Register.zero),
......@@ -251,7 +251,7 @@ pub const FrameIndex = enum(u32) {
251251 /// Other indices are used for local variable stack slots
252252 _,
253253
254 pub const named_count = @typeInfo(FrameIndex).@"enum".fields.len;
254 pub const named_count = @typeInfo(FrameIndex).@"enum".field_names.len;
255255
256256 pub fn isNamed(fi: FrameIndex) bool {
257257 return @intFromEnum(fi) < named_count;
src/codegen/riscv64/encoding.zig+2-2
......@@ -498,8 +498,8 @@ pub const Instruction = union(Lir.Format) {
498498 extra: u32,
499499
500500 comptime {
501 for (std.meta.fields(Instruction)) |field| {
502 assert(@bitSizeOf(field.type) == 32);
501 for (std.meta.fieldTypes(Instruction)) |field_type| {
502 assert(@bitSizeOf(field_type) == 32);
503503 }
504504 }
505505
src/codegen/sparc64/Mir.zig+3-3
......@@ -410,11 +410,11 @@ pub fn emit(
410410/// Returns the requested data, as well as the new index which is at the start of the
411411/// trailers for the object.
412412pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {
413 const fields = std.meta.fields(T);
413 const info = @typeInfo(T).@"struct";
414414 var i: usize = index;
415415 var result: T = undefined;
416 inline for (fields) |field| {
417 @field(result, field.name) = switch (field.type) {
416 inline for (info.field_names, info.field_types) |field_name, field_type| {
417 @field(result, field_name) = switch (field_type) {
418418 u32 => mir.extra[i],
419419 i32 => @as(i32, @bitCast(mir.extra[i])),
420420 else => @compileError("bad field type"),
src/codegen/spirv/Section.zig+20-19
......@@ -102,13 +102,13 @@ pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
102102}
103103
104104fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void {
105 const fields = switch (@typeInfo(Operands)) {
106 .@"struct" => |info| info.fields,
105 const info = switch (@typeInfo(Operands)) {
106 .@"struct" => |info| info,
107107 .void => return,
108108 else => unreachable,
109109 };
110 inline for (fields) |field| {
111 section.writeOperand(field.type, @field(operands, field.name));
110 inline for (info.field_names, info.field_types) |field_name, field_type| {
111 section.writeOperand(field_type, @field(operands, field_name));
112112 }
113113}
114114
......@@ -171,12 +171,13 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe
171171
172172fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {
173173 var mask: Word = 0;
174 inline for (@typeInfo(Operand).@"struct".fields, 0..) |field, bit| {
175 switch (@typeInfo(field.type)) {
176 .optional => if (@field(operand, field.name) != null) {
174 const info = @typeInfo(Operand).@"struct";
175 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, bit| {
176 switch (@typeInfo(field_type)) {
177 .optional => if (@field(operand, field_name) != null) {
177178 mask |= 1 << @as(u5, @intCast(bit));
178179 },
179 .bool => if (@field(operand, field.name)) {
180 .bool => if (@field(operand, field_name)) {
180181 mask |= 1 << @as(u5, @intCast(bit));
181182 },
182183 else => unreachable,
......@@ -185,10 +186,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
185186
186187 section.writeWord(mask);
187188
188 inline for (@typeInfo(Operand).@"struct".fields) |field| {
189 switch (@typeInfo(field.type)) {
190 .optional => |info| if (@field(operand, field.name)) |child| {
191 section.writeOperands(info.child, child);
189 inline for (info.field_names, info.field_types) |field_name, field_type| {
190 switch (@typeInfo(field_type)) {
191 .optional => |opt_info| if (@field(operand, field_name)) |child| {
192 section.writeOperands(opt_info.child, child);
192193 },
193194 .bool => {},
194195 else => unreachable,
......@@ -213,15 +214,15 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us
213214}
214215
215216fn operandsSize(comptime Operands: type, operands: Operands) usize {
216 const fields = switch (@typeInfo(Operands)) {
217 .@"struct" => |info| info.fields,
217 const info = switch (@typeInfo(Operands)) {
218 .@"struct" => |info| info,
218219 .void => return 0,
219220 else => unreachable,
220221 };
221222
222223 var total: usize = 0;
223 inline for (fields) |field| {
224 total += operandSize(field.type, @field(operands, field.name));
224 inline for (info.field_names, info.field_types) |field_name, field_type| {
225 total += operandSize(field_type, @field(operands, field_name));
225226 }
226227
227228 return total;
......@@ -252,9 +253,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
252253 if (struct_info.layout == .@"packed") return 1;
253254
254255 var total: usize = 0;
255 inline for (@typeInfo(Operand).@"struct".fields) |field| {
256 switch (@typeInfo(field.type)) {
257 .optional => |info| if (@field(operand, field.name)) |child| {
256 inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| {
257 switch (@typeInfo(field_type)) {
258 .optional => |info| if (@field(operand, field_name)) |child| {
258259 total += operandsSize(info.child, child);
259260 },
260261 .bool => {},
src/codegen/wasm/CodeGen.zig+9-9
......@@ -563,24 +563,24 @@ fn addCallIntrinsic(cg: *CodeGen, intrinsic: Mir.Intrinsic) error{OutOfMemory}!v
563563/// Appends entries to `mir_extra` based on the type of `extra`.
564564/// Returns the index into `mir_extra`
565565fn addExtra(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
566 const fields = std.meta.fields(@TypeOf(extra));
567 try cg.mir_extra.ensureUnusedCapacity(cg.gpa, fields.len);
566 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
567 try cg.mir_extra.ensureUnusedCapacity(cg.gpa, field_count);
568568 return cg.addExtraAssumeCapacity(extra);
569569}
570570
571571/// Appends entries to `mir_extra` based on the type of `extra`.
572572/// Returns the index into `mir_extra`
573573fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
574 const fields = std.meta.fields(@TypeOf(extra));
574 const info = @typeInfo(@TypeOf(extra)).@"struct";
575575 const result: u32 = @intCast(cg.mir_extra.items.len);
576 inline for (fields) |field| {
577 cg.mir_extra.appendAssumeCapacity(switch (field.type) {
578 u32 => @field(extra, field.name),
579 i32 => @bitCast(@field(extra, field.name)),
576 inline for (info.field_names, info.field_types) |field_name, field_type| {
577 cg.mir_extra.appendAssumeCapacity(switch (field_type) {
578 u32 => @field(extra, field_name),
579 i32 => @bitCast(@field(extra, field_name)),
580580 InternPool.Index,
581581 InternPool.Nav.Index,
582 => @intFromEnum(@field(extra, field.name)),
583 else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)),
582 => @intFromEnum(@field(extra, field_name)),
583 else => @compileError("Unsupported field type " ++ @typeName(field_type)),
584584 });
585585 }
586586 return result;
src/codegen/wasm/Mir.zig+4-4
......@@ -731,11 +731,11 @@ pub fn lower(mir: *const Mir, wasm: *Wasm, code: *std.ArrayList(u8)) std.mem.All
731731}
732732
733733pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data: T, end: usize } {
734 const fields = std.meta.fields(T);
734 const info = @typeInfo(T).@"struct";
735735 var i: usize = index;
736736 var result: T = undefined;
737 inline for (fields) |field| {
738 @field(result, field.name) = switch (field.type) {
737 inline for (info.field_names, info.field_types) |field_name, field_type| {
738 @field(result, field_name) = switch (field_type) {
739739 u32 => self.extra[i],
740740 i32 => @bitCast(self.extra[i]),
741741 Wasm.UavsObjIndex,
......@@ -743,7 +743,7 @@ pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data
743743 InternPool.Nav.Index,
744744 InternPool.Index,
745745 => @enumFromInt(self.extra[i]),
746 else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)),
746 else => @compileError("Unsupported field type " ++ @typeName(field_type)),
747747 };
748748 i += 1;
749749 }
src/codegen/x86_64/CodeGen.zig+12-12
......@@ -1214,20 +1214,20 @@ fn addInst(self: *CodeGen, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
12141214}
12151215
12161216fn addExtra(self: *CodeGen, extra: anytype) Allocator.Error!u32 {
1217 const fields = std.meta.fields(@TypeOf(extra));
1218 try self.mir_extra.ensureUnusedCapacity(self.gpa, fields.len);
1217 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
1218 try self.mir_extra.ensureUnusedCapacity(self.gpa, field_count);
12191219 return self.addExtraAssumeCapacity(extra);
12201220}
12211221
12221222fn addExtraAssumeCapacity(self: *CodeGen, extra: anytype) u32 {
1223 const fields = std.meta.fields(@TypeOf(extra));
1223 const info = @typeInfo(@TypeOf(extra)).@"struct";
12241224 const result: u32 = @intCast(self.mir_extra.items.len);
1225 inline for (fields) |field| {
1226 self.mir_extra.appendAssumeCapacity(switch (field.type) {
1227 u32 => @field(extra, field.name),
1228 i32, Mir.Memory.Info => @bitCast(@field(extra, field.name)),
1229 FrameIndex => @intFromEnum(@field(extra, field.name)),
1230 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
1225 inline for (info.field_names, info.field_types) |field_name, field_type| {
1226 self.mir_extra.appendAssumeCapacity(switch (field_type) {
1227 u32 => @field(extra, field_name),
1228 i32, Mir.Memory.Info => @bitCast(@field(extra, field_name)),
1229 FrameIndex => @intFromEnum(@field(extra, field_name)),
1230 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
12311231 });
12321232 }
12331233 return result;
......@@ -177140,7 +177140,7 @@ fn airBr(self: *CodeGen, inst: Air.Inst.Index) !void {
177140177140}
177141177141
177142177142fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177143 @setEvalBranchQuota(1_100 + @typeInfo(Mir.Inst.Fixes).@"enum".fields.len);
177143 @setEvalBranchQuota(1_100 + @typeInfo(Mir.Inst.Fixes).@"enum".field_names.len);
177144177144 const pt = self.pt;
177145177145 const zcu = pt.zcu;
177146177146 const unwrapped_asm = self.air.unwrapAsm(inst);
......@@ -177748,8 +177748,8 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177748177748 std.mem.reverse(Operand, ops[0..ops_len]);
177749177749 if (mnem_size.size != .none and !mnem_size.used) {
177750177750 comptime var max_mnem_len: usize = 0;
177751 inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".fields) |mnem|
177752 max_mnem_len = @max(mnem.name.len, max_mnem_len);
177751 inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".field_names) |mnem_name|
177752 max_mnem_len = @max(mnem_name.len, max_mnem_len);
177753177753 var intel_mnem_buf: [max_mnem_len + 1]u8 = undefined;
177754177754 const intel_mnem_str = std.fmt.bufPrint(&intel_mnem_buf, "{s}{c}", .{
177755177755 @tagName(mnem_tag),
src/codegen/x86_64/Encoding.zig+1-1
......@@ -1028,7 +1028,7 @@ const mnemonic_to_encodings_map = init: {
10281028 const Entry = struct { Mnemonic, OpEn, []const Op, []const u8, ModrmExt, Mode, Feature };
10291029 const encodings: []const Entry = @import("encodings.zon");
10301030
1031 const mnemonic_count = @typeInfo(Mnemonic).@"enum".fields.len;
1031 const mnemonic_count = @typeInfo(Mnemonic).@"enum".field_names.len;
10321032 var mnemonic_map: [mnemonic_count][]Data = @splat(&.{});
10331033 for (encodings) |entry| mnemonic_map[@intFromEnum(entry[0])].len += 1;
10341034 var data_storage: [encodings.len]Data = undefined;
src/codegen/x86_64/Lower.zig+2-2
......@@ -425,8 +425,8 @@ fn encode(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operan
425425 lower.result_insts_len += 1;
426426}
427427
428const inst_tags_len = @typeInfo(Mir.Inst.Tag).@"enum".fields.len;
429const inst_fixes_len = @typeInfo(Mir.Inst.Fixes).@"enum".fields.len;
428const inst_tags_len = @typeInfo(Mir.Inst.Tag).@"enum".field_names.len;
429const inst_fixes_len = @typeInfo(Mir.Inst.Fixes).@"enum".field_names.len;
430430/// Lookup table, indexed by `@intFromEnum(inst.tag) * inst_fixes_len + @intFromEnum(fixes)`.
431431/// The value is the resulting `Mnemonic`, or `null` if the combination is not valid.
432432const mnemonic_table: [inst_tags_len * inst_fixes_len]?Mnemonic = table: {
src/codegen/x86_64/Mir.zig+21-21
......@@ -1732,9 +1732,9 @@ pub const Inst = struct {
17321732 assert(@sizeOf(Data) == 8);
17331733 }
17341734 const Mnemonic = @import("Encoding.zig").Mnemonic;
1735 if (@typeInfo(Mnemonic).@"enum".fields.len != 978 or
1736 @typeInfo(Fixes).@"enum".fields.len != 231 or
1737 @typeInfo(Tag).@"enum".fields.len != 251)
1735 if (@typeInfo(Mnemonic).@"enum".field_names.len != 978 or
1736 @typeInfo(Fixes).@"enum".field_names.len != 231 or
1737 @typeInfo(Tag).@"enum".field_names.len != 251)
17381738 {
17391739 const cond_src = (struct {
17401740 fn src() std.lang.SourceLocation {
......@@ -1742,32 +1742,32 @@ pub const Inst = struct {
17421742 }
17431743 }).src();
17441744 @setEvalBranchQuota(2_000_000);
1745 for (@typeInfo(Mnemonic).@"enum".fields) |mnemonic| {
1746 if (mnemonic.name[0] == '.') continue;
1747 for (@typeInfo(Fixes).@"enum".fields) |fixes| {
1748 const pattern = fixes.name[if (std.mem.indexOfScalar(u8, fixes.name, ' ')) |index| index + " ".len else 0..];
1745 for (@typeInfo(Mnemonic).@"enum".field_names) |mnemonic_name| {
1746 if (mnemonic_name[0] == '.') continue;
1747 for (@typeInfo(Fixes).@"enum".field_names) |fixes_name| {
1748 const pattern = fixes_name[if (std.mem.indexOfScalar(u8, fixes_name, ' ')) |index| index + " ".len else 0..];
17491749 const wildcard_index = std.mem.indexOfScalar(u8, pattern, '_').?;
17501750 const mnem_prefix = pattern[0..wildcard_index];
17511751 const mnem_suffix = pattern[wildcard_index + "_".len ..];
1752 if (!std.mem.startsWith(u8, mnemonic.name, mnem_prefix)) continue;
1753 if (!std.mem.endsWith(u8, mnemonic.name, mnem_suffix)) continue;
1752 if (!std.mem.startsWith(u8, mnemonic_name, mnem_prefix)) continue;
1753 if (!std.mem.endsWith(u8, mnemonic_name, mnem_suffix)) continue;
17541754 if (@hasField(
17551755 Tag,
1756 mnemonic.name[mnem_prefix.len .. mnemonic.name.len - mnem_suffix.len],
1756 mnemonic_name[mnem_prefix.len .. mnemonic_name.len - mnem_suffix.len],
17571757 )) break;
1758 } else @compileError("'" ++ mnemonic.name ++ "' is not encodable in Mir");
1758 } else @compileError("'" ++ mnemonic_name ++ "' is not encodable in Mir");
17591759 }
17601760 @compileError(std.fmt.comptimePrint(
17611761 \\All mnemonics are encodable in Mir! You may now change the condition at {s}:{d} to:
1762 \\if (@typeInfo(Mnemonic).@"enum".fields.len != {d} or
1763 \\ @typeInfo(Fixes).@"enum".fields.len != {d} or
1764 \\ @typeInfo(Tag).@"enum".fields.len != {d})
1762 \\if (@typeInfo(Mnemonic).@"enum".field_names.len != {d} or
1763 \\ @typeInfo(Fixes).@"enum".field_names.len != {d} or
1764 \\ @typeInfo(Tag).@"enum".field_names.len != {d})
17651765 , .{
17661766 cond_src.file,
17671767 cond_src.line - 6,
1768 @typeInfo(Mnemonic).@"enum".fields.len,
1769 @typeInfo(Fixes).@"enum".fields.len,
1770 @typeInfo(Tag).@"enum".fields.len,
1768 @typeInfo(Mnemonic).@"enum".field_names.len,
1769 @typeInfo(Fixes).@"enum".field_names.len,
1770 @typeInfo(Tag).@"enum".field_names.len,
17711771 }));
17721772 }
17731773 }
......@@ -2069,15 +2069,15 @@ pub fn emitLazy(
20692069}
20702070
20712071pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end: u32 } {
2072 const fields = std.meta.fields(T);
2072 const info = @typeInfo(T).@"struct";
20732073 var i: u32 = index;
20742074 var result: T = undefined;
2075 inline for (fields) |field| {
2076 @field(result, field.name) = switch (field.type) {
2075 inline for (info.field_names, info.field_types) |field_name, field_type| {
2076 @field(result, field_name) = switch (field_type) {
20772077 u32 => mir.extra[i],
20782078 i32, Memory.Info => @bitCast(mir.extra[i]),
20792079 bits.FrameIndex => @enumFromInt(mir.extra[i]),
2080 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),
2080 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
20812081 };
20822082 i += 1;
20832083 }
src/codegen/x86_64/bits.zig+1-1
......@@ -722,7 +722,7 @@ pub const FrameIndex = enum(u32) {
722722 // Other indices are used for local variable stack slots
723723 _,
724724
725 pub const named_count = @typeInfo(FrameIndex).@"enum".fields.len;
725 pub const named_count = @typeInfo(FrameIndex).@"enum".field_names.len;
726726
727727 pub fn isNamed(fi: FrameIndex) bool {
728728 return @intFromEnum(fi) < named_count;
src/codegen/x86_64/encoder.zig+6-6
......@@ -2272,9 +2272,9 @@ const Assembler = struct {
22722272
22732273 fn mnemonicFromString(bytes: []const u8) ?Instruction.Mnemonic {
22742274 const ti = @typeInfo(Instruction.Mnemonic).@"enum";
2275 inline for (ti.fields) |field| {
2276 if (std.mem.eql(u8, bytes, field.name)) {
2277 return @field(Instruction.Mnemonic, field.name);
2275 inline for (ti.field_names) |field_name| {
2276 if (std.mem.eql(u8, bytes, field_name)) {
2277 return @field(Instruction.Mnemonic, field_name);
22782278 }
22792279 }
22802280 return null;
......@@ -2325,9 +2325,9 @@ const Assembler = struct {
23252325
23262326 fn registerFromString(bytes: []const u8) ?Register {
23272327 const ti = @typeInfo(Register).@"enum";
2328 inline for (ti.fields) |field| {
2329 if (std.mem.eql(u8, bytes, field.name)) {
2330 return @field(Register, field.name);
2328 inline for (ti.field_names) |field_name| {
2329 if (std.mem.eql(u8, bytes, field_name)) {
2330 return @field(Register, field_name);
23312331 }
23322332 }
23332333 return null;
src/link.zig+1-1
......@@ -52,7 +52,7 @@ pub const Diags = struct {
5252 alloc_failure_occurred: bool = false,
5353
5454 const Int = blk: {
55 const bits = @typeInfo(@This()).@"struct".fields.len;
55 const bits = @typeInfo(@This()).@"struct".field_names.len;
5656 break :blk @Int(.unsigned, bits);
5757 };
5858
src/link/Coff.zig+5-4
......@@ -248,7 +248,7 @@ pub const Node = union(enum) {
248248
249249 pub const Tag = @typeInfo(Node).@"union".tag_type.?;
250250
251 const known_count = @typeInfo(@TypeOf(known)).@"struct".fields.len;
251 const known_count = @typeInfo(@TypeOf(known)).@"struct".field_names.len;
252252 const known = known: {
253253 const Known = enum {
254254 file,
......@@ -260,8 +260,9 @@ pub const Node = union(enum) {
260260 section_table,
261261 };
262262 var mut_known: std.enums.EnumFieldStruct(Known, MappedFile.Node.Index, null) = undefined;
263 for (@typeInfo(Known).@"enum".fields) |field|
264 @field(mut_known, field.name) = @enumFromInt(field.value);
263 const info = @typeInfo(Known).@"enum";
264 for (info.field_names, info.field_values) |field_name, field_value|
265 @field(mut_known, field_name) = @enumFromInt(field_value);
265266 break :known mut_known;
266267 };
267268
......@@ -387,7 +388,7 @@ pub const Symbol = struct {
387388 text,
388389 _,
389390
390 const known_count = @typeInfo(Index).@"enum".fields.len;
391 const known_count = @typeInfo(Index).@"enum".field_names.len;
391392
392393 pub fn get(si: Symbol.Index, coff: *Coff) *Symbol {
393394 return &coff.symbol_table.items[@intFromEnum(si)];
src/link/Dwarf.zig+7-7
......@@ -5110,16 +5110,16 @@ pub fn resolveRelocs(dwarf: *Dwarf) RelocError!void {
51105110}
51115111
51125112fn DeclValEnum(comptime T: type) type {
5113 const decls = @typeInfo(T).@"struct".decls;
5114 @setEvalBranchQuota(10 * decls.len);
5115 var field_names: [decls.len][]const u8 = undefined;
5113 const decl_names = @typeInfo(T).@"struct".decl_names;
5114 @setEvalBranchQuota(10 * decl_names.len);
5115 var field_names: [decl_names.len][]const u8 = undefined;
51165116 var fields_len = 0;
51175117 var min_value: ?comptime_int = null;
51185118 var max_value: ?comptime_int = null;
5119 for (decls) |decl| {
5120 if (std.mem.startsWith(u8, decl.name, "HP_") or std.mem.endsWith(u8, decl.name, "_user")) continue;
5121 const value = @field(T, decl.name);
5122 field_names[fields_len] = decl.name;
5119 for (decl_names) |decl_name| {
5120 if (std.mem.startsWith(u8, decl_name, "HP_") or std.mem.endsWith(u8, decl_name, "_user")) continue;
5121 const value = @field(T, decl_name);
5122 field_names[fields_len] = decl_name;
51235123 fields_len += 1;
51245124 if (min_value == null or min_value.? > value) min_value = value;
51255125 if (max_value == null or max_value.? < value) max_value = value;
src/link/Elf.zig+7-7
......@@ -1194,7 +1194,7 @@ fn parseDso(
11941194 // TODO: save this work for later
11951195 const nsyms = parsed.symbols.len;
11961196 try so.symbols.ensureTotalCapacityPrecise(gpa, nsyms);
1197 try so.symbols_extra.ensureTotalCapacityPrecise(gpa, nsyms * @typeInfo(Symbol.Extra).@"struct".fields.len);
1197 try so.symbols_extra.ensureTotalCapacityPrecise(gpa, nsyms * @typeInfo(Symbol.Extra).@"struct".field_names.len);
11981198 try so.symbols_resolver.ensureTotalCapacityPrecise(gpa, nsyms);
11991199 so.symbols_resolver.appendNTimesAssumeCapacity(0, nsyms);
12001200
......@@ -2354,9 +2354,9 @@ fn sortPhdrs(
23542354 phdr.* = slice[entry.phndx];
23552355 }
23562356
2357 inline for (@typeInfo(ProgramHeaderIndexes).@"struct".fields) |field| {
2358 if (@field(special_indexes, field.name).int()) |special_index| {
2359 @field(special_indexes, field.name) = @enumFromInt(backlinks[special_index]);
2357 inline for (@typeInfo(ProgramHeaderIndexes).@"struct".field_names) |field_name| {
2358 if (@field(special_indexes, field_name).int()) |special_index| {
2359 @field(special_indexes, field_name) = @enumFromInt(backlinks[special_index]);
23602360 }
23612361 }
23622362
......@@ -2474,9 +2474,9 @@ pub fn sortShdrs(
24742474 }
24752475 }
24762476
2477 inline for (@typeInfo(SectionIndexes).@"struct".fields) |field| {
2478 if (@field(section_indexes, field.name)) |special_index| {
2479 @field(section_indexes, field.name) = backlinks[special_index];
2477 inline for (@typeInfo(SectionIndexes).@"struct".field_names) |field_name| {
2478 if (@field(section_indexes, field_name)) |special_index| {
2479 @field(section_indexes, field_name) = backlinks[special_index];
24802480 }
24812481 }
24822482
src/link/Elf/Atom.zig+3-3
......@@ -878,9 +878,9 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any
878878pub fn addExtra(atom: *Atom, opts: Extra.AsOptionals, elf_file: *Elf) void {
879879 const file_ptr = atom.file(elf_file).?;
880880 var extras = file_ptr.atomExtra(atom.extra_index);
881 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {
882 if (@field(opts, field.name)) |x| {
883 @field(extras, field.name) = x;
881 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
882 if (@field(opts, field_name)) |x| {
883 @field(extras, field_name) = x;
884884 }
885885 }
886886 file_ptr.setAtomExtra(atom.extra_index, extras);
src/link/Elf/LinkerDefined.zig+13-13
......@@ -396,17 +396,17 @@ fn addSymbolAssumeCapacity(self: *LinkerDefined) Symbol.Index {
396396}
397397
398398pub fn addSymbolExtra(self: *LinkerDefined, allocator: Allocator, extra: Symbol.Extra) !u32 {
399 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
400 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
399 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
400 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
401401 return self.addSymbolExtraAssumeCapacity(extra);
402402}
403403
404404pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u32 {
405405 const index = @as(u32, @intCast(self.symbols_extra.items.len));
406 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
407 inline for (fields) |field| {
408 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
409 u32 => @field(extra, field.name),
406 const info = @typeInfo(Symbol.Extra).@"struct";
407 inline for (info.field_names, info.field_types) |field_name, field_type| {
408 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
409 u32 => @field(extra, field_name),
410410 else => @compileError("bad field type"),
411411 });
412412 }
......@@ -414,11 +414,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u
414414}
415415
416416pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra {
417 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
417 const info = @typeInfo(Symbol.Extra).@"struct";
418418 var i: usize = index;
419419 var result: Symbol.Extra = undefined;
420 inline for (fields) |field| {
421 @field(result, field.name) = switch (field.type) {
420 inline for (info.field_names, info.field_types) |field_name, field_type| {
421 @field(result, field_name) = switch (field_type) {
422422 u32 => self.symbols_extra.items[i],
423423 else => @compileError("bad field type"),
424424 };
......@@ -428,10 +428,10 @@ pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra {
428428}
429429
430430pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) void {
431 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
432 inline for (fields, 0..) |field, i| {
433 self.symbols_extra.items[index + i] = switch (field.type) {
434 u32 => @field(extra, field.name),
431 const info = @typeInfo(Symbol.Extra).@"struct";
432 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
433 self.symbols_extra.items[index + i] = switch (field_type) {
434 u32 => @field(extra, field_name),
435435 else => @compileError("bad field type"),
436436 };
437437 }
src/link/Elf/Object.zig+28-28
......@@ -1298,17 +1298,17 @@ fn addSymbolAssumeCapacity(self: *Object) Symbol.Index {
12981298}
12991299
13001300pub fn addSymbolExtra(self: *Object, gpa: Allocator, extra: Symbol.Extra) !u32 {
1301 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1302 try self.symbols_extra.ensureUnusedCapacity(gpa, fields.len);
1301 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
1302 try self.symbols_extra.ensureUnusedCapacity(gpa, field_count);
13031303 return self.addSymbolExtraAssumeCapacity(extra);
13041304}
13051305
13061306pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
13071307 const index = @as(u32, @intCast(self.symbols_extra.items.len));
1308 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1309 inline for (fields) |field| {
1310 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
1311 u32 => @field(extra, field.name),
1308 const info = @typeInfo(Symbol.Extra).@"struct";
1309 inline for (info.field_names, info.field_types) |field_name, field_type| {
1310 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
1311 u32 => @field(extra, field_name),
13121312 else => @compileError("bad field type"),
13131313 });
13141314 }
......@@ -1316,11 +1316,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
13161316}
13171317
13181318pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra {
1319 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1319 const info = @typeInfo(Symbol.Extra).@"struct";
13201320 var i: usize = index;
13211321 var result: Symbol.Extra = undefined;
1322 inline for (fields) |field| {
1323 @field(result, field.name) = switch (field.type) {
1322 inline for (info.field_names, info.field_types) |field_name, field_type| {
1323 @field(result, field_name) = switch (field_type) {
13241324 u32 => self.symbols_extra.items[i],
13251325 else => @compileError("bad field type"),
13261326 };
......@@ -1330,10 +1330,10 @@ pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra {
13301330}
13311331
13321332pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void {
1333 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1334 inline for (fields, 0..) |field, i| {
1335 self.symbols_extra.items[index + i] = switch (field.type) {
1336 u32 => @field(extra, field.name),
1333 const info = @typeInfo(Symbol.Extra).@"struct";
1334 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
1335 self.symbols_extra.items[index + i] = switch (field_type) {
1336 u32 => @field(extra, field_name),
13371337 else => @compileError("bad field type"),
13381338 };
13391339 }
......@@ -1408,17 +1408,17 @@ pub fn atom(self: *Object, atom_index: Atom.Index) ?*Atom {
14081408}
14091409
14101410pub fn addAtomExtra(self: *Object, gpa: Allocator, extra: Atom.Extra) !u32 {
1411 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1412 try self.atoms_extra.ensureUnusedCapacity(gpa, fields.len);
1411 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
1412 try self.atoms_extra.ensureUnusedCapacity(gpa, field_count);
14131413 return self.addAtomExtraAssumeCapacity(extra);
14141414}
14151415
14161416pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
14171417 const index: u32 = @intCast(self.atoms_extra.items.len);
1418 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1419 inline for (fields) |field| {
1420 self.atoms_extra.appendAssumeCapacity(switch (field.type) {
1421 u32 => @field(extra, field.name),
1418 const info = @typeInfo(Atom.Extra).@"struct";
1419 inline for (info.field_names, info.field_types) |field_name, field_type| {
1420 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
1421 u32 => @field(extra, field_name),
14221422 else => @compileError("bad field type"),
14231423 });
14241424 }
......@@ -1426,11 +1426,11 @@ pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
14261426}
14271427
14281428pub fn atomExtra(self: *Object, index: u32) Atom.Extra {
1429 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1429 const info = @typeInfo(Atom.Extra).@"struct";
14301430 var i: usize = index;
14311431 var result: Atom.Extra = undefined;
1432 inline for (fields) |field| {
1433 @field(result, field.name) = switch (field.type) {
1432 inline for (info.field_names, info.field_types) |field_name, field_type| {
1433 @field(result, field_name) = switch (field_type) {
14341434 u32 => self.atoms_extra.items[i],
14351435 else => @compileError("bad field type"),
14361436 };
......@@ -1440,10 +1440,10 @@ pub fn atomExtra(self: *Object, index: u32) Atom.Extra {
14401440}
14411441
14421442pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {
1443 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1444 inline for (fields, 0..) |field, i| {
1445 self.atoms_extra.items[index + i] = switch (field.type) {
1446 u32 => @field(extra, field.name),
1443 const info = @typeInfo(Atom.Extra).@"struct";
1444 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
1445 self.atoms_extra.items[index + i] = switch (field_type) {
1446 u32 => @field(extra, field_name),
14471447 else => @compileError("bad field type"),
14481448 };
14491449 }
......@@ -1452,8 +1452,8 @@ pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {
14521452fn setAtomFields(o: *Object, atom_ptr: *Atom, opts: Atom.Extra.AsOptionals) void {
14531453 assert(o.index == atom_ptr.file_index);
14541454 var extras = o.atomExtra(atom_ptr.extra_index);
1455 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {
1456 if (@field(opts, field.name)) |x| @field(extras, field.name) = x;
1455 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
1456 if (@field(opts, field_name)) |x| @field(extras, field_name) = x;
14571457 }
14581458 o.setAtomExtra(atom_ptr.extra_index, extras);
14591459}
src/link/Elf/SharedObject.zig+11-11
......@@ -498,10 +498,10 @@ pub fn addSymbolAssumeCapacity(self: *SharedObject) Symbol.Index {
498498
499499pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u32 {
500500 const index: u32 = @intCast(self.symbols_extra.items.len);
501 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
502 inline for (fields) |field| {
503 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
504 u32 => @field(extra, field.name),
501 const info = @typeInfo(Symbol.Extra).@"struct";
502 inline for (info.field_names, info.field_types) |field_name, field_type| {
503 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
504 u32 => @field(extra, field_name),
505505 else => @compileError("bad field type"),
506506 });
507507 }
......@@ -509,11 +509,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u3
509509}
510510
511511pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra {
512 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
512 const info = @typeInfo(Symbol.Extra).@"struct";
513513 var i: usize = index;
514514 var result: Symbol.Extra = undefined;
515 inline for (fields) |field| {
516 @field(result, field.name) = switch (field.type) {
515 inline for (info.field_names, info.field_types) |field_name, field_type| {
516 @field(result, field_name) = switch (field_type) {
517517 u32 => self.symbols_extra.items[i],
518518 else => @compileError("bad field type"),
519519 };
......@@ -523,10 +523,10 @@ pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra {
523523}
524524
525525pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void {
526 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
527 inline for (fields, 0..) |field, i| {
528 self.symbols_extra.items[index + i] = switch (field.type) {
529 u32 => @field(extra, field.name),
526 const info = @typeInfo(Symbol.Extra).@"struct";
527 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
528 self.symbols_extra.items[index + i] = switch (field_type) {
529 u32 => @field(extra, field_name),
530530 else => @compileError("bad field type"),
531531 };
532532 }
src/link/Elf/Symbol.zig+3-3
......@@ -259,9 +259,9 @@ const AddExtraOpts = struct {
259259
260260pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) void {
261261 var extras = symbol.extra(elf_file);
262 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {
263 if (@field(opts, field.name)) |x| {
264 @field(extras, field.name) = x;
262 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
263 if (@field(opts, field_name)) |x| {
264 @field(extras, field_name) = x;
265265 }
266266 }
267267 symbol.setExtra(extras, elf_file);
src/link/Elf/ZigObject.zig+26-26
......@@ -2214,17 +2214,17 @@ pub fn atom(self: *ZigObject, atom_index: Atom.Index) ?*Atom {
22142214}
22152215
22162216fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 {
2217 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2218 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);
2217 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
2218 try self.atoms_extra.ensureUnusedCapacity(allocator, field_count);
22192219 return self.addAtomExtraAssumeCapacity(extra);
22202220}
22212221
22222222fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
22232223 const index = @as(u32, @intCast(self.atoms_extra.items.len));
2224 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2225 inline for (fields) |field| {
2226 self.atoms_extra.appendAssumeCapacity(switch (field.type) {
2227 u32 => @field(extra, field.name),
2224 const info = @typeInfo(Atom.Extra).@"struct";
2225 inline for (info.field_names, info.field_types) |field_name, field_type| {
2226 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
2227 u32 => @field(extra, field_name),
22282228 else => @compileError("bad field type"),
22292229 });
22302230 }
......@@ -2232,11 +2232,11 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
22322232}
22332233
22342234pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra {
2235 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2235 const info = @typeInfo(Atom.Extra).@"struct";
22362236 var i: usize = index;
22372237 var result: Atom.Extra = undefined;
2238 inline for (fields) |field| {
2239 @field(result, field.name) = switch (field.type) {
2238 inline for (info.field_names, info.field_types) |field_name, field_type| {
2239 @field(result, field_name) = switch (field_type) {
22402240 u32 => self.atoms_extra.items[i],
22412241 else => @compileError("bad field type"),
22422242 };
......@@ -2247,10 +2247,10 @@ pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra {
22472247
22482248pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void {
22492249 assert(index > 0);
2250 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2251 inline for (fields, 0..) |field, i| {
2252 self.atoms_extra.items[index + i] = switch (field.type) {
2253 u32 => @field(extra, field.name),
2250 const info = @typeInfo(Atom.Extra).@"struct";
2251 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
2252 self.atoms_extra.items[index + i] = switch (field_type) {
2253 u32 => @field(extra, field_name),
22542254 else => @compileError("bad field type"),
22552255 };
22562256 }
......@@ -2286,17 +2286,17 @@ fn addSymbolAssumeCapacity(self: *ZigObject) Symbol.Index {
22862286}
22872287
22882288pub fn addSymbolExtra(self: *ZigObject, allocator: Allocator, extra: Symbol.Extra) !u32 {
2289 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2290 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
2289 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
2290 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
22912291 return self.addSymbolExtraAssumeCapacity(extra);
22922292}
22932293
22942294pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
22952295 const index = @as(u32, @intCast(self.symbols_extra.items.len));
2296 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2297 inline for (fields) |field| {
2298 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
2299 u32 => @field(extra, field.name),
2296 const info = @typeInfo(Symbol.Extra).@"struct";
2297 inline for (info.field_names, info.field_types) |field_name, field_type| {
2298 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
2299 u32 => @field(extra, field_name),
23002300 else => @compileError("bad field type"),
23012301 });
23022302 }
......@@ -2304,11 +2304,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
23042304}
23052305
23062306pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra {
2307 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2307 const info = @typeInfo(Symbol.Extra).@"struct";
23082308 var i: usize = index;
23092309 var result: Symbol.Extra = undefined;
2310 inline for (fields) |field| {
2311 @field(result, field.name) = switch (field.type) {
2310 inline for (info.field_names, info.field_types) |field_name, field_type| {
2311 @field(result, field_name) = switch (field_type) {
23122312 u32 => self.symbols_extra.items[i],
23132313 else => @compileError("bad field type"),
23142314 };
......@@ -2318,10 +2318,10 @@ pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra {
23182318}
23192319
23202320pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
2321 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2322 inline for (fields, 0..) |field, i| {
2323 self.symbols_extra.items[index + i] = switch (field.type) {
2324 u32 => @field(extra, field.name),
2321 const info = @typeInfo(Symbol.Extra).@"struct";
2322 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
2323 self.symbols_extra.items[index + i] = switch (field_type) {
2324 u32 => @field(extra, field_name),
23252325 else => @compileError("bad field type"),
23262326 };
23272327 }
src/link/Elf2.zig+3-3
......@@ -6330,10 +6330,10 @@ pub fn printNode(
63306330 const pt = elf.targetLoad(&ph.type);
63316331 if (std.enums.tagName(std.elf.PT, pt)) |pt_name|
63326332 try w.writeAll(pt_name)
6333 else inline for (@typeInfo(std.elf.PT).@"enum".decls) |decl| {
6334 const decl_val = @field(std.elf.PT, decl.name);
6333 else inline for (@typeInfo(std.elf.PT).@"enum".decl_names) |decl_name| {
6334 const decl_val = @field(std.elf.PT, decl_name);
63356335 if (@TypeOf(decl_val) != std.elf.PT) continue;
6336 if (pt == @field(std.elf.PT, decl.name)) break try w.writeAll(decl.name);
6336 if (pt == @field(std.elf.PT, decl_name)) break try w.writeAll(decl_name);
63376337 } else try w.print("0x{x}", .{pt});
63386338 try w.writeAll(", ");
63396339 const pf = elf.targetLoad(&ph.flags);
src/link/LdScript.zig+4-4
......@@ -97,15 +97,15 @@ const Command = enum {
9797 as_needed,
9898
9999 fn fromString(s: []const u8) ?Command {
100 inline for (@typeInfo(Command).@"enum".fields) |field| {
100 inline for (@typeInfo(Command).@"enum".field_names) |field_name| {
101101 const upper_name = n: {
102 comptime var buf: [field.name.len]u8 = undefined;
103 inline for (field.name, 0..) |c, i| {
102 comptime var buf: [field_name.len]u8 = undefined;
103 inline for (field_name, 0..) |c, i| {
104104 buf[i] = comptime std.ascii.toUpper(c);
105105 }
106106 break :n buf;
107107 };
108 if (std.mem.eql(u8, &upper_name, s)) return @field(Command, field.name);
108 if (std.mem.eql(u8, &upper_name, s)) return @field(Command, field_name);
109109 }
110110 return null;
111111 }
src/link/MachO/Atom.zig+3-3
......@@ -129,9 +129,9 @@ const AddExtraOpts = struct {
129129pub fn addExtra(atom: *Atom, opts: AddExtraOpts, macho_file: *MachO) void {
130130 const file = atom.getFile(macho_file);
131131 var extra = file.getAtomExtra(atom.extra);
132 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {
133 if (@field(opts, field.name)) |x| {
134 @field(extra, field.name) = x;
132 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
133 if (@field(opts, field_name)) |x| {
134 @field(extra, field_name) = x;
135135 }
136136 }
137137 file.setAtomExtra(atom.extra, extra);
src/link/MachO/Dylib.zig+13-13
......@@ -627,17 +627,17 @@ pub fn getSymbolRef(self: Dylib, index: Symbol.Index, macho_file: *MachO) MachO.
627627}
628628
629629pub fn addSymbolExtra(self: *Dylib, allocator: Allocator, extra: Symbol.Extra) !u32 {
630 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
631 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
630 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
631 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
632632 return self.addSymbolExtraAssumeCapacity(extra);
633633}
634634
635635fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 {
636636 const index = @as(u32, @intCast(self.symbols_extra.items.len));
637 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
638 inline for (fields) |field| {
639 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
640 u32 => @field(extra, field.name),
637 const info = @typeInfo(Symbol.Extra).@"struct";
638 inline for (info.field_names, info.field_types) |field_name, field_type| {
639 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
640 u32 => @field(extra, field_name),
641641 else => @compileError("bad field type"),
642642 });
643643 }
......@@ -645,11 +645,11 @@ fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 {
645645}
646646
647647pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra {
648 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
648 const info = @typeInfo(Symbol.Extra).@"struct";
649649 var i: usize = index;
650650 var result: Symbol.Extra = undefined;
651 inline for (fields) |field| {
652 @field(result, field.name) = switch (field.type) {
651 inline for (info.field_names, info.field_types) |field_name, field_type| {
652 @field(result, field_name) = switch (field_type) {
653653 u32 => self.symbols_extra.items[i],
654654 else => @compileError("bad field type"),
655655 };
......@@ -659,10 +659,10 @@ pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra {
659659}
660660
661661pub fn setSymbolExtra(self: *Dylib, index: u32, extra: Symbol.Extra) void {
662 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
663 inline for (fields, 0..) |field, i| {
664 self.symbols_extra.items[index + i] = switch (field.type) {
665 u32 => @field(extra, field.name),
662 const info = @typeInfo(Symbol.Extra).@"struct";
663 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
664 self.symbols_extra.items[index + i] = switch (field_type) {
665 u32 => @field(extra, field_name),
666666 else => @compileError("bad field type"),
667667 };
668668 }
src/link/MachO/InternalObject.zig+26-26
......@@ -708,17 +708,17 @@ pub fn getAtoms(self: InternalObject) []const Atom.Index {
708708}
709709
710710fn addAtomExtra(self: *InternalObject, allocator: Allocator, extra: Atom.Extra) !u32 {
711 const fields = @typeInfo(Atom.Extra).@"struct".fields;
712 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);
711 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
712 try self.atoms_extra.ensureUnusedCapacity(allocator, field_count);
713713 return self.addAtomExtraAssumeCapacity(extra);
714714}
715715
716716fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 {
717717 const index = @as(u32, @intCast(self.atoms_extra.items.len));
718 const fields = @typeInfo(Atom.Extra).@"struct".fields;
719 inline for (fields) |field| {
720 self.atoms_extra.appendAssumeCapacity(switch (field.type) {
721 u32 => @field(extra, field.name),
718 const info = @typeInfo(Atom.Extra).@"struct";
719 inline for (info.field_names, info.field_types) |field_name, field_type| {
720 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
721 u32 => @field(extra, field_name),
722722 else => @compileError("bad field type"),
723723 });
724724 }
......@@ -726,11 +726,11 @@ fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 {
726726}
727727
728728pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra {
729 const fields = @typeInfo(Atom.Extra).@"struct".fields;
729 const info = @typeInfo(Atom.Extra).@"struct";
730730 var i: usize = index;
731731 var result: Atom.Extra = undefined;
732 inline for (fields) |field| {
733 @field(result, field.name) = switch (field.type) {
732 inline for (info.field_names, info.field_types) |field_name, field_type| {
733 @field(result, field_name) = switch (field_type) {
734734 u32 => self.atoms_extra.items[i],
735735 else => @compileError("bad field type"),
736736 };
......@@ -741,10 +741,10 @@ pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra {
741741
742742pub fn setAtomExtra(self: *InternalObject, index: u32, extra: Atom.Extra) void {
743743 assert(index > 0);
744 const fields = @typeInfo(Atom.Extra).@"struct".fields;
745 inline for (fields, 0..) |field, i| {
746 self.atoms_extra.items[index + i] = switch (field.type) {
747 u32 => @field(extra, field.name),
744 const info = @typeInfo(Atom.Extra).@"struct";
745 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
746 self.atoms_extra.items[index + i] = switch (field_type) {
747 u32 => @field(extra, field_name),
748748 else => @compileError("bad field type"),
749749 };
750750 }
......@@ -789,17 +789,17 @@ pub fn getSymbolRef(self: InternalObject, index: Symbol.Index, macho_file: *Mach
789789}
790790
791791pub fn addSymbolExtra(self: *InternalObject, allocator: Allocator, extra: Symbol.Extra) !u32 {
792 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
793 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
792 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
793 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
794794 return self.addSymbolExtraAssumeCapacity(extra);
795795}
796796
797797fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32 {
798798 const index = @as(u32, @intCast(self.symbols_extra.items.len));
799 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
800 inline for (fields) |field| {
801 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
802 u32 => @field(extra, field.name),
799 const info = @typeInfo(Symbol.Extra).@"struct";
800 inline for (info.field_names, info.field_types) |field_name, field_type| {
801 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
802 u32 => @field(extra, field_name),
803803 else => @compileError("bad field type"),
804804 });
805805 }
......@@ -807,11 +807,11 @@ fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32
807807}
808808
809809pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra {
810 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
810 const info = @typeInfo(Symbol.Extra).@"struct";
811811 var i: usize = index;
812812 var result: Symbol.Extra = undefined;
813 inline for (fields) |field| {
814 @field(result, field.name) = switch (field.type) {
813 inline for (info.field_names, info.field_types) |field_name, field_type| {
814 @field(result, field_name) = switch (field_type) {
815815 u32 => self.symbols_extra.items[i],
816816 else => @compileError("bad field type"),
817817 };
......@@ -821,10 +821,10 @@ pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra {
821821}
822822
823823pub fn setSymbolExtra(self: *InternalObject, index: u32, extra: Symbol.Extra) void {
824 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
825 inline for (fields, 0..) |field, i| {
826 self.symbols_extra.items[index + i] = switch (field.type) {
827 u32 => @field(extra, field.name),
824 const info = @typeInfo(Symbol.Extra).@"struct";
825 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
826 self.symbols_extra.items[index + i] = switch (field_type) {
827 u32 => @field(extra, field_name),
828828 else => @compileError("bad field type"),
829829 };
830830 }
src/link/MachO/Object.zig+26-26
......@@ -2478,17 +2478,17 @@ pub fn getAtoms(self: *Object) []const Atom.Index {
24782478}
24792479
24802480fn addAtomExtra(self: *Object, allocator: Allocator, extra: Atom.Extra) !u32 {
2481 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2482 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);
2481 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
2482 try self.atoms_extra.ensureUnusedCapacity(allocator, field_count);
24832483 return self.addAtomExtraAssumeCapacity(extra);
24842484}
24852485
24862486fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
24872487 const index = @as(u32, @intCast(self.atoms_extra.items.len));
2488 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2489 inline for (fields) |field| {
2490 self.atoms_extra.appendAssumeCapacity(switch (field.type) {
2491 u32 => @field(extra, field.name),
2488 const info = @typeInfo(Atom.Extra).@"struct";
2489 inline for (info.field_names, info.field_types) |field_name, field_type| {
2490 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
2491 u32 => @field(extra, field_name),
24922492 else => @compileError("bad field type"),
24932493 });
24942494 }
......@@ -2496,11 +2496,11 @@ fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
24962496}
24972497
24982498pub fn getAtomExtra(self: Object, index: u32) Atom.Extra {
2499 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2499 const info = @typeInfo(Atom.Extra).@"struct";
25002500 var i: usize = index;
25012501 var result: Atom.Extra = undefined;
2502 inline for (fields) |field| {
2503 @field(result, field.name) = switch (field.type) {
2502 inline for (info.field_names, info.field_types) |field_name, field_type| {
2503 @field(result, field_name) = switch (field_type) {
25042504 u32 => self.atoms_extra.items[i],
25052505 else => @compileError("bad field type"),
25062506 };
......@@ -2511,10 +2511,10 @@ pub fn getAtomExtra(self: Object, index: u32) Atom.Extra {
25112511
25122512pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {
25132513 assert(index > 0);
2514 const fields = @typeInfo(Atom.Extra).@"struct".fields;
2515 inline for (fields, 0..) |field, i| {
2516 self.atoms_extra.items[index + i] = switch (field.type) {
2517 u32 => @field(extra, field.name),
2514 const info = @typeInfo(Atom.Extra).@"struct";
2515 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
2516 self.atoms_extra.items[index + i] = switch (field_type) {
2517 u32 => @field(extra, field_name),
25182518 else => @compileError("bad field type"),
25192519 };
25202520 }
......@@ -2539,17 +2539,17 @@ pub fn getSymbolRef(self: Object, index: Symbol.Index, macho_file: *MachO) MachO
25392539}
25402540
25412541pub fn addSymbolExtra(self: *Object, allocator: Allocator, extra: Symbol.Extra) !u32 {
2542 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2543 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
2542 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
2543 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
25442544 return self.addSymbolExtraAssumeCapacity(extra);
25452545}
25462546
25472547fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
25482548 const index = @as(u32, @intCast(self.symbols_extra.items.len));
2549 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2550 inline for (fields) |field| {
2551 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
2552 u32 => @field(extra, field.name),
2549 const info = @typeInfo(Symbol.Extra).@"struct";
2550 inline for (info.field_names, info.field_types) |field_name, field_type| {
2551 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
2552 u32 => @field(extra, field_name),
25532553 else => @compileError("bad field type"),
25542554 });
25552555 }
......@@ -2557,11 +2557,11 @@ fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
25572557}
25582558
25592559pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra {
2560 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2560 const info = @typeInfo(Symbol.Extra).@"struct";
25612561 var i: usize = index;
25622562 var result: Symbol.Extra = undefined;
2563 inline for (fields) |field| {
2564 @field(result, field.name) = switch (field.type) {
2563 inline for (info.field_names, info.field_types) |field_name, field_type| {
2564 @field(result, field_name) = switch (field_type) {
25652565 u32 => self.symbols_extra.items[i],
25662566 else => @compileError("bad field type"),
25672567 };
......@@ -2571,10 +2571,10 @@ pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra {
25712571}
25722572
25732573pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void {
2574 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
2575 inline for (fields, 0..) |field, i| {
2576 self.symbols_extra.items[index + i] = switch (field.type) {
2577 u32 => @field(extra, field.name),
2574 const info = @typeInfo(Symbol.Extra).@"struct";
2575 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
2576 self.symbols_extra.items[index + i] = switch (field_type) {
2577 u32 => @field(extra, field_name),
25782578 else => @compileError("bad field type"),
25792579 };
25802580 }
src/link/MachO/Symbol.zig+3-3
......@@ -211,9 +211,9 @@ const AddExtraOpts = struct {
211211
212212pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, macho_file: *MachO) void {
213213 var extra = symbol.getExtra(macho_file);
214 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {
215 if (@field(opts, field.name)) |x| {
216 @field(extra, field.name) = x;
214 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
215 if (@field(opts, field_name)) |x| {
216 @field(extra, field_name) = x;
217217 }
218218 }
219219 symbol.setExtra(extra, macho_file);
src/link/MachO/ZigObject.zig+37-25
......@@ -1570,17 +1570,19 @@ pub fn getAtoms(self: *ZigObject) []const Atom.Index {
15701570}
15711571
15721572fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 {
1573 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1574 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);
1573 const field = @typeInfo(Atom.Extra).@"struct".field_names;
1574 try self.atoms_extra.ensureUnusedCapacity(allocator, field.len);
15751575 return self.addAtomExtraAssumeCapacity(extra);
15761576}
15771577
15781578fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
15791579 const index = @as(u32, @intCast(self.atoms_extra.items.len));
1580 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1581 inline for (fields) |field| {
1582 self.atoms_extra.appendAssumeCapacity(switch (field.type) {
1583 u32 => @field(extra, field.name),
1580 const info = @typeInfo(Atom.Extra).@"struct";
1581 const field_names = info.field_names;
1582 const field_types = info.field_types;
1583 inline for (field_names, field_types) |field_name, field_type| {
1584 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
1585 u32 => @field(extra, field_name),
15841586 else => @compileError("bad field type"),
15851587 });
15861588 }
......@@ -1588,11 +1590,13 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
15881590}
15891591
15901592pub fn getAtomExtra(self: ZigObject, index: u32) Atom.Extra {
1591 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1593 const info = @typeInfo(Atom.Extra).@"struct";
1594 const field_names = info.field_names;
1595 const field_types = info.field_types;
15921596 var i: usize = index;
15931597 var result: Atom.Extra = undefined;
1594 inline for (fields) |field| {
1595 @field(result, field.name) = switch (field.type) {
1598 inline for (field_names, field_types) |field_name, field_type| {
1599 @field(result, field_name) = switch (field_type) {
15961600 u32 => self.atoms_extra.items[i],
15971601 else => @compileError("bad field type"),
15981602 };
......@@ -1603,10 +1607,12 @@ pub fn getAtomExtra(self: ZigObject, index: u32) Atom.Extra {
16031607
16041608pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void {
16051609 assert(index > 0);
1606 const fields = @typeInfo(Atom.Extra).@"struct".fields;
1607 inline for (fields, 0..) |field, i| {
1608 self.atoms_extra.items[index + i] = switch (field.type) {
1609 u32 => @field(extra, field.name),
1610 const info = @typeInfo(Atom.Extra).@"struct";
1611 const field_names = info.field_names;
1612 const field_types = info.field_types;
1613 inline for (field_names, field_types, 0..) |field_name, field_type, i| {
1614 self.atoms_extra.items[index + i] = switch (field_type) {
1615 u32 => @field(extra, field_name),
16101616 else => @compileError("bad field type"),
16111617 };
16121618 }
......@@ -1631,17 +1637,19 @@ pub fn getSymbolRef(self: ZigObject, index: Symbol.Index, macho_file: *MachO) Ma
16311637}
16321638
16331639pub fn addSymbolExtra(self: *ZigObject, allocator: Allocator, extra: Symbol.Extra) !u32 {
1634 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1640 const fields = @typeInfo(Symbol.Extra).@"struct".field_names;
16351641 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
16361642 return self.addSymbolExtraAssumeCapacity(extra);
16371643}
16381644
16391645fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
16401646 const index = @as(u32, @intCast(self.symbols_extra.items.len));
1641 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1642 inline for (fields) |field| {
1643 self.symbols_extra.appendAssumeCapacity(switch (field.type) {
1644 u32 => @field(extra, field.name),
1647 const info = @typeInfo(Symbol.Extra).@"struct";
1648 const field_names = info.field_names;
1649 const field_types = info.field_types;
1650 inline for (field_names, field_types) |field_name, field_type| {
1651 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
1652 u32 => @field(extra, field_name),
16451653 else => @compileError("bad field type"),
16461654 });
16471655 }
......@@ -1649,11 +1657,13 @@ fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
16491657}
16501658
16511659pub fn getSymbolExtra(self: ZigObject, index: u32) Symbol.Extra {
1652 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1660 const info = @typeInfo(Symbol.Extra).@"struct";
1661 const field_names = info.field_names;
1662 const field_types = info.field_types;
16531663 var i: usize = index;
16541664 var result: Symbol.Extra = undefined;
1655 inline for (fields) |field| {
1656 @field(result, field.name) = switch (field.type) {
1665 inline for (field_names, field_types) |field_name, field_type| {
1666 @field(result, field_name) = switch (field_type) {
16571667 u32 => self.symbols_extra.items[i],
16581668 else => @compileError("bad field type"),
16591669 };
......@@ -1663,10 +1673,12 @@ pub fn getSymbolExtra(self: ZigObject, index: u32) Symbol.Extra {
16631673}
16641674
16651675pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
1666 const fields = @typeInfo(Symbol.Extra).@"struct".fields;
1667 inline for (fields, 0..) |field, i| {
1668 self.symbols_extra.items[index + i] = switch (field.type) {
1669 u32 => @field(extra, field.name),
1676 const info = @typeInfo(Symbol.Extra).@"struct";
1677 const field_names = info.field_names;
1678 const field_types = info.field_types;
1679 inline for (field_names, field_types, 0..) |field_name, field_type, i| {
1680 self.symbols_extra.items[index + i] = switch (field_type) {
1681 u32 => @field(extra, field_name),
16701682 else => @compileError("bad field type"),
16711683 };
16721684 }
src/link/Wasm.zig+2-2
......@@ -2992,8 +2992,8 @@ pub fn createEmpty(
29922992
29932993 if (options.object_host_name) |name| wasm.object_host_name = (try wasm.internString(name)).toOptional();
29942994
2995 inline for (@typeInfo(PreloadedStrings).@"struct".fields) |field| {
2996 @field(wasm.preloaded_strings, field.name) = try wasm.internString(field.name);
2995 inline for (@typeInfo(PreloadedStrings).@"struct".field_names) |field_name| {
2996 @field(wasm.preloaded_strings, field_name) = try wasm.internString(field_name);
29972997 }
29982998
29992999 wasm.entry_name = switch (options.entry) {
src/link/tapi/yaml.zig+20-20
......@@ -214,8 +214,8 @@ pub const Value = union(enum) {
214214 var list: std.ArrayList(Value) = try .initCapacity(arena);
215215 defer list.deinit();
216216
217 inline for (info.fields) |field| {
218 if (try encode(arena, @field(input, field.name))) |value| {
217 inline for (info.field_names) |field_name| {
218 if (try encode(arena, @field(input, field_name))) |value| {
219219 list.appendAssumeCapacity(value);
220220 }
221221 }
......@@ -224,11 +224,11 @@ pub const Value = union(enum) {
224224 } else {
225225 var map = Map.init(arena);
226226 errdefer map.deinit();
227 try map.ensureTotalCapacity(info.fields.len);
227 try map.ensureTotalCapacity(info.field_names.len);
228228
229 inline for (info.fields) |field| {
230 if (try encode(arena, @field(input, field.name))) |value| {
231 const key = try arena.dupe(u8, field.name);
229 inline for (info.field_names) |field_name| {
230 if (try encode(arena, @field(input, field_name))) |value| {
231 const key = try arena.dupe(u8, field_name);
232232 map.putAssumeCapacityNoClobber(key, value);
233233 }
234234 }
......@@ -237,9 +237,9 @@ pub const Value = union(enum) {
237237 },
238238
239239 .@"union" => |info| if (info.tag_type) |tag_type| {
240 inline for (info.fields) |field| {
241 if (@field(tag_type, field.name) == input) {
242 return try encode(arena, @field(input, field.name));
240 inline for (info.field_names) |field_name| {
241 if (@field(tag_type, field_name) == input) {
242 return try encode(arena, @field(input, field_name));
243243 }
244244 } else unreachable;
245245 } else return error.UntaggedUnion,
......@@ -396,9 +396,9 @@ pub const Yaml = struct {
396396 const union_info = @typeInfo(T).@"union";
397397
398398 if (union_info.tag_type) |_| {
399 inline for (union_info.fields) |field| {
400 if (self.parseValue(field.type, value)) |u_value| {
401 return @unionInit(T, field.name, u_value);
399 inline for (union_info.field_names, union_info.field_types) |field_name, field_type| {
400 if (self.parseValue(field_type, value)) |u_value| {
401 return @unionInit(T, field_name, u_value);
402402 } else |err| {
403403 if (@as(@TypeOf(err) || error{TypeMismatch}, err) != error.TypeMismatch) return err;
404404 }
......@@ -418,22 +418,22 @@ pub const Yaml = struct {
418418 const struct_info = @typeInfo(T).@"struct";
419419 var parsed: T = undefined;
420420
421 inline for (struct_info.fields) |field| {
422 const value: ?Value = map.get(field.name) orelse blk: {
423 const field_name = try mem.replaceOwned(u8, self.arena.allocator(), field.name, "_", "-");
424 break :blk map.get(field_name);
421 inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| {
422 const value: ?Value = map.get(field_name) orelse blk: {
423 const field_name_ = try mem.replaceOwned(u8, self.arena.allocator(), field_name, "_", "-");
424 break :blk map.get(field_name_);
425425 };
426426
427 if (@typeInfo(field.type) == .optional) {
428 @field(parsed, field.name) = try self.parseOptional(field.type, value);
427 if (@typeInfo(field_type) == .optional) {
428 @field(parsed, field_name) = try self.parseOptional(field_type, value);
429429 continue;
430430 }
431431
432432 const unwrapped = value orelse {
433 log.debug("missing struct field: {s}: {s}", .{ field.name, @typeName(field.type) });
433 log.debug("missing struct field: {s}: {s}", .{ field_name, @typeName(field_type) });
434434 return error.StructFieldMissing;
435435 };
436 @field(parsed, field.name) = try self.parseValue(field.type, unwrapped);
436 @field(parsed, field_name) = try self.parseValue(field_type, unwrapped);
437437 }
438438
439439 return parsed;
src/print_env.zig+2-2
......@@ -59,8 +59,8 @@ pub fn cmdEnv(
5959 try root.field("version", build_options.version, .{});
6060 try root.field("target", triple, .{});
6161 var env = try root.beginStructField("env", .{});
62 inline for (@typeInfo(EnvVar).@"enum".fields) |field| {
63 try env.field(field.name, @field(EnvVar, field.name).get(environ_map), .{});
62 inline for (@typeInfo(EnvVar).@"enum".field_names) |field_name| {
63 try env.field(field_name, @field(EnvVar, field_name).get(environ_map), .{});
6464 }
6565 try env.end();
6666 try root.end();
src/print_zoir.zig+2-2
......@@ -5,8 +5,8 @@ pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: *Writer) Error!void {
55
66 const bytes_per_node = comptime n: {
77 var n: usize = 0;
8 for (@typeInfo(Zoir.Node.Repr).@"struct".fields) |f| {
9 n += @sizeOf(f.type);
8 for (@typeInfo(Zoir.Node.Repr).@"struct".field_types) |f_type| {
9 n += @sizeOf(f_type);
1010 }
1111 break :n n;
1212 };
stage1/zig.h+24-2
......@@ -21,6 +21,8 @@
2121
2222#if defined(__aarch64__) || (defined(zig_msvc) && defined(_M_ARM64))
2323#define zig_aarch64
24#elif defined(__alpha__)
25#define zig_alpha
2426#elif defined(__thumb__) || (defined(zig_msvc) && defined(_M_ARM))
2527#define zig_thumb
2628#define zig_arm
......@@ -36,6 +38,10 @@
3638#elif defined(__loongarch64)
3739#define zig_loongarch64
3840#define zig_loongarch
41#elif defined(__m68k__)
42#define zig_m68k
43#elif defined(__m88k__)
44#define zig_m88k
3945#elif defined(__mips64)
4046#define zig_mips64
4147#define zig_mips
......@@ -79,6 +85,8 @@
7985#elif defined(__I86__)
8086#define zig_x86_16
8187#define zig_x86
88#elif defined(__xtensa__)
89#define zig_xtensa
8290#elif defined (__ez80)
8391#define zig_ez80
8492#define zig_z80
......@@ -390,7 +398,9 @@
390398
391399#elif defined(zig_gnuc_asm)
392400
393#if defined(zig_thumb)
401#if defined(zig_alpha)
402#define zig_trap() __asm__ volatile("call_pal 0x000000")
403#elif defined(zig_thumb)
394404#define zig_trap() __asm__ volatile("udf #0xfe")
395405#elif defined(zig_arm) || defined(zig_aarch64)
396406#define zig_trap() __asm__ volatile("udf #0xfdee")
......@@ -398,6 +408,10 @@
398408#define zig_trap() __asm__ volatile("r27:26 = memd(#0xbadc0fee)")
399409#elif defined(zig_kvx) || defined(zig_loongarch) || defined(zig_powerpc)
400410#define zig_trap() __asm__ volatile(".word 0x0")
411#elif defined(zig_m68k)
412#define zig_trap() __asm__ volatile("illegal")
413#elif defined(zig_m88k)
414#define zig_trap() __asm__ volatile("tb0 0, %%r0, 511")
401415#elif defined(zig_mips)
402416#define zig_trap() __asm__ volatile(".word 0x3d")
403417#elif defined(zig_or1k)
......@@ -412,6 +426,8 @@
412426#define zig_trap() __asm__ volatile("int $0x3")
413427#elif defined(zig_x86)
414428#define zig_trap() __asm__ volatile("ud2")
429#elif defined(zig_xtensa)
430#define zig_trap() __asm__ volatile("ill")
415431#elif defined(zig_z80)
416432#define zig_trap() __asm__ volatile("rst 00h")
417433#else
......@@ -428,7 +444,9 @@
428444#define zig_breakpoint() __debugbreak()
429445#elif defined(zig_gnuc_asm)
430446
431#if defined(zig_arm)
447#if defined(zig_alpha)
448#define zig_breakpoint() __asm__ volatile("call_pal 0x000080")
449#elif defined(zig_arm)
432450#define zig_breakpoint() __asm__ volatile("bkpt #0x0")
433451#elif defined(zig_aarch64)
434452#define zig_breakpoint() __asm__ volatile("brk #0xf000")
......@@ -436,6 +454,8 @@
436454#define zig_breakpoint() __asm__ volatile("brkpt")
437455#elif defined(zig_kvx) || defined(zig_loongarch)
438456#define zig_breakpoint() __asm__ volatile("break 0x0")
457#elif defined(zig_m88k)
458#define zig_breakpoint() __asm__ volatile("illop1")
439459#elif defined(zig_mips)
440460#define zig_breakpoint() __asm__ volatile("break")
441461#elif defined(zig_or1k)
......@@ -450,6 +470,8 @@
450470#define zig_breakpoint() __asm__ volatile("ta 0x1")
451471#elif defined(zig_x86)
452472#define zig_breakpoint() __asm__ volatile("int $0x3")
473#elif defined(zig_xtensa)
474#define zig_breakpoint() __asm__ volatile("break 1, 1")
453475#else
454476#define zig_breakpoint() zig_breakpoint_unavailable
455477#endif
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/behavior/align.zig+1-1
......@@ -7,7 +7,7 @@ const assert = std.debug.assert;
77var foo: u8 align(4) = 100;
88
99test "global variable alignment" {
10 comptime assert(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4);
10 comptime assert(@typeInfo(@TypeOf(&foo)).pointer.attrs.@"align" == 4);
1111 comptime assert(@TypeOf(&foo) == *align(4) u8);
1212 {
1313 const slice = @as(*align(4) [1]u8, &foo)[0..];
test/behavior/basic.zig+3-3
......@@ -1159,7 +1159,7 @@ test "pointer to struct literal with runtime field is constant" {
11591159 var runtime_zero: usize = 0;
11601160 _ = &runtime_zero;
11611161 const ptr = &S{ .data = runtime_zero };
1162 try expect(@typeInfo(@TypeOf(ptr)).pointer.is_const);
1162 try expect(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"const");
11631163}
11641164
11651165fn testSignedCmp(comptime T: type) !void {
......@@ -1284,8 +1284,8 @@ test "comptime variable initialized with addresses of literals" {
12841284 };
12851285 _ = &st;
12861286
1287 inline for (@typeInfo(@TypeOf(st)).@"struct".fields) |field| {
1288 _ = field;
1287 inline for (@typeInfo(@TypeOf(st)).@"struct".field_names) |field_name| {
1288 _ = field_name;
12891289 }
12901290}
12911291
test/behavior/bitcast.zig+2-2
......@@ -359,8 +359,8 @@ test "comptime @bitCast packed struct to int and back" {
359359 _ = &i;
360360 const rt_cast = @as(S, @bitCast(i));
361361 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));
362 inline for (@typeInfo(S).@"struct".fields) |field| {
363 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));
362 inline for (@typeInfo(S).@"struct".field_names) |field_name| {
363 try expectEqual(@field(rt_cast, field_name), @field(ct_cast, field_name));
364364 }
365365}
366366
test/behavior/call.zig+2-2
......@@ -375,7 +375,7 @@ test "Enum constructed by @Enum passed as generic argument" {
375375 try expect(@intFromEnum(a) == b);
376376 }
377377 };
378 inline for (@typeInfo(S.E).@"enum".fields, 0..) |_, i| {
378 inline for (@typeInfo(S.E).@"enum".field_names, 0..) |_, i| {
379379 try S.foo(@as(S.E, @enumFromInt(i)), i);
380380 }
381381}
......@@ -556,7 +556,7 @@ test "value returned from comptime function is comptime known" {
556556 else => unreachable,
557557 } {
558558 return switch (@typeInfo(T)) {
559 .@"struct" => |info| info.fields.len,
559 .@"struct" => |info| info.field_names.len,
560560 else => unreachable,
561561 };
562562 }
test/behavior/cast.zig+35-35
......@@ -1042,9 +1042,9 @@ test "peer type resolution: error set supersets" {
10421042 const ty = @TypeOf(a, b);
10431043 const error_set_info = @typeInfo(ty);
10441044 try expect(error_set_info == .error_set);
1045 try expect(error_set_info.error_set.?.len == 2);
1046 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1047 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1045 try expect(error_set_info.error_set.error_names.?.len == 2);
1046 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1047 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
10481048 }
10491049
10501050 // B superset of A
......@@ -1052,9 +1052,9 @@ test "peer type resolution: error set supersets" {
10521052 const ty = @TypeOf(b, a);
10531053 const error_set_info = @typeInfo(ty);
10541054 try expect(error_set_info == .error_set);
1055 try expect(error_set_info.error_set.?.len == 2);
1056 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1057 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1055 try expect(error_set_info.error_set.error_names.?.len == 2);
1056 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1057 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
10581058 }
10591059}
10601060
......@@ -1070,20 +1070,20 @@ test "peer type resolution: disjoint error sets" {
10701070 const ty = @TypeOf(a, b);
10711071 const error_set_info = @typeInfo(ty);
10721072 try expect(error_set_info == .error_set);
1073 try expect(error_set_info.error_set.?.len == 3);
1074 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1075 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1076 try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three"));
1073 try expect(error_set_info.error_set.error_names.?.len == 3);
1074 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1075 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1076 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
10771077 }
10781078
10791079 {
10801080 const ty = @TypeOf(b, a);
10811081 const error_set_info = @typeInfo(ty);
10821082 try expect(error_set_info == .error_set);
1083 try expect(error_set_info.error_set.?.len == 3);
1084 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1085 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1086 try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three"));
1083 try expect(error_set_info.error_set.error_names.?.len == 3);
1084 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1085 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1086 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
10871087 }
10881088}
10891089
......@@ -1101,10 +1101,10 @@ test "peer type resolution: error union and error set" {
11011101 try expect(info == .error_union);
11021102
11031103 const error_set_info = @typeInfo(info.error_union.error_set);
1104 try expect(error_set_info.error_set.?.len == 3);
1105 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1106 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1107 try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three"));
1104 try expect(error_set_info.error_set.error_names.?.len == 3);
1105 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1106 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1107 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
11081108 }
11091109
11101110 {
......@@ -1113,10 +1113,10 @@ test "peer type resolution: error union and error set" {
11131113 try expect(info == .error_union);
11141114
11151115 const error_set_info = @typeInfo(info.error_union.error_set);
1116 try expect(error_set_info.error_set.?.len == 3);
1117 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1118 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1119 try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three"));
1116 try expect(error_set_info.error_set.error_names.?.len == 3);
1117 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1118 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1119 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
11201120 }
11211121}
11221122
......@@ -1135,9 +1135,9 @@ test "peer type resolution: error union after non-error" {
11351135 try expect(info.error_union.payload == u32);
11361136
11371137 const error_set_info = @typeInfo(info.error_union.error_set);
1138 try expect(error_set_info.error_set.?.len == 2);
1139 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1140 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1138 try expect(error_set_info.error_set.error_names.?.len == 2);
1139 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1140 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
11411141 }
11421142
11431143 {
......@@ -1147,9 +1147,9 @@ test "peer type resolution: error union after non-error" {
11471147 try expect(info.error_union.payload == u32);
11481148
11491149 const error_set_info = @typeInfo(info.error_union.error_set);
1150 try expect(error_set_info.error_set.?.len == 2);
1151 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
1152 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
1150 try expect(error_set_info.error_set.error_names.?.len == 2);
1151 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
1152 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
11531153 }
11541154}
11551155
......@@ -2552,9 +2552,9 @@ test "peer type resolution: tuples with comptime fields" {
25522552 inline for (.{ ti1, ti2 }) |ti| {
25532553 const s = ti.@"struct";
25542554 comptime assert(s.is_tuple);
2555 comptime assert(s.fields.len == 2);
2556 comptime assert(s.fields[0].type == u32);
2557 comptime assert(s.fields[1].type == i16);
2555 comptime assert(s.field_names.len == 2);
2556 comptime assert(s.field_types[0] == u32);
2557 comptime assert(s.field_types[1] == i16);
25582558 }
25592559
25602560 var t = true;
......@@ -2665,11 +2665,11 @@ test "peer type resolution: pointer attributes are combined correctly" {
26652665 const NonAllowZero = comptime blk: {
26662666 const ptr = @typeInfo(@TypeOf(r1, r2, r3, r4)).pointer;
26672667 break :blk @Pointer(ptr.size, .{
2668 .@"const" = ptr.is_const,
2669 .@"volatile" = ptr.is_volatile,
2668 .@"const" = ptr.attrs.@"const",
2669 .@"volatile" = ptr.attrs.@"volatile",
26702670 .@"allowzero" = false,
2671 .@"align" = ptr.alignment,
2672 .@"addrspace" = ptr.address_space,
2671 .@"align" = ptr.attrs.@"align",
2672 .@"addrspace" = ptr.attrs.@"addrspace",
26732673 }, ptr.child, ptr.sentinel());
26742674 };
26752675 try expectEqualSlices(u8, std.mem.span(@volatileCast(@as(NonAllowZero, @ptrCast(r1)))), "foo");
test/behavior/comptime_memory.zig+2-2
......@@ -118,8 +118,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {
118118 const pResult = @as(*align(1) [array_len]To, @ptrCast(&result));
119119 var i: usize = 0;
120120 while (i < array_len) : (i += 1) {
121 inline for (@typeInfo(To).@"struct".fields) |f| {
122 @field(pResult[i], f.name) = @field(pSource[i], f.name);
121 inline for (@typeInfo(To).@"struct".field_names) |f_name| {
122 @field(pResult[i], f_name) = @field(pSource[i], f_name);
123123 }
124124 }
125125 return result;
test/behavior/enum.zig+8-6
......@@ -644,12 +644,12 @@ test "non-exhaustive enum" {
644644 else => true,
645645 });
646646
647 try expect(@typeInfo(E).@"enum".fields.len == 2);
647 try expect(@typeInfo(E).@"enum".field_names.len == 2);
648648 e = @as(E, @enumFromInt(12));
649649 try expect(@intFromEnum(e) == 12);
650650 e = @as(E, @enumFromInt(y));
651651 try expect(@intFromEnum(e) == 52);
652 try expect(@typeInfo(E).@"enum".is_exhaustive == false);
652 try expect(@typeInfo(E).@"enum".mode == .nonexhaustive);
653653 }
654654 };
655655 try S.doTheTest(52);
......@@ -668,8 +668,9 @@ test "empty non-exhaustive enum" {
668668 });
669669 try expect(@intFromEnum(e) == y);
670670
671 try expect(@typeInfo(E).@"enum".fields.len == 0);
672 try expect(@typeInfo(E).@"enum".is_exhaustive == false);
671 try expect(@typeInfo(E).@"enum".field_names.len == 0);
672 try expect(@typeInfo(E).@"enum".field_values.len == 0);
673 try expect(@typeInfo(E).@"enum".mode == .nonexhaustive);
673674 }
674675 };
675676 try S.doTheTest(42);
......@@ -704,8 +705,9 @@ test "single field non-exhaustive enum" {
704705 });
705706
706707 try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y);
707 try expect(@typeInfo(E).@"enum".fields.len == 1);
708 try expect(@typeInfo(E).@"enum".is_exhaustive == false);
708 try expect(@typeInfo(E).@"enum".field_names.len == 1);
709 try expect(@typeInfo(E).@"enum".field_values.len == 1);
710 try expect(@typeInfo(E).@"enum".mode == .nonexhaustive);
709711 }
710712 };
711713 try S.doTheTest(23);
test/behavior/error.zig+4-4
......@@ -206,7 +206,7 @@ const MyErrSet = error{
206206};
207207
208208fn testErrorSetType() !void {
209 try expect(@typeInfo(MyErrSet).error_set.?.len == 2);
209 try expect(@typeInfo(MyErrSet).error_set.error_names.?.len == 2);
210210
211211 const a: MyErrSet!i32 = 5678;
212212 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
......@@ -1125,9 +1125,9 @@ test "@errorCast into own inferred error set" {
11251125 try expect(err == error.Bad);
11261126 }
11271127
1128 const errors = @typeInfo(@typeInfo(@TypeOf(static.foo(false))).error_union.error_set).error_set.?;
1129 comptime assert(errors.len == 1);
1130 comptime assert(std.mem.eql(u8, errors[0].name, "Bad"));
1128 const error_names = @typeInfo(@typeInfo(@TypeOf(static.foo(false))).error_union.error_set).error_set.error_names.?;
1129 comptime assert(error_names.len == 1);
1130 comptime assert(std.mem.eql(u8, error_names[0], "Bad"));
11311131}
11321132
11331133test "@errorCast into other inferred error set" {
test/behavior/eval.zig+4-4
......@@ -889,16 +889,16 @@ test "const local with comptime init through array init" {
889889 };
890890
891891 const S = struct {
892 fn declarations(comptime T: type) []const std.builtin.Type.Declaration {
893 return @typeInfo(T).@"enum".decls;
892 fn declarations(comptime T: type) []const [:0]const u8 {
893 return @typeInfo(T).@"enum".decl_names;
894894 }
895895 };
896896
897 const decls = comptime [_][]const std.builtin.Type.Declaration{
897 const decls = comptime [_][]const [:0]const u8{
898898 S.declarations(E1),
899899 };
900900
901 comptime assert(decls[0][0].name[0] == 'a');
901 comptime assert(decls[0][0][0] == 'a');
902902}
903903
904904test "closure capture type of runtime-known parameter" {
test/behavior/fn.zig+1-1
......@@ -400,7 +400,7 @@ test "function with inferred error set but returning no error" {
400400 };
401401
402402 const return_ty = @typeInfo(@TypeOf(S.foo)).@"fn".return_type.?;
403 try expectEqual(0, @typeInfo(@typeInfo(return_ty).error_union.error_set).error_set.?.len);
403 try expectEqual(0, @typeInfo(@typeInfo(return_ty).error_union.error_set).error_set.error_names.?.len);
404404}
405405
406406test "import passed byref to function in return type" {
test/behavior/generics.zig+6-3
......@@ -175,7 +175,7 @@ test "generic fn keeps non-generic parameter types" {
175175
176176 const S = struct {
177177 fn f(comptime T: type, s: []T) !void {
178 try expect(A != @typeInfo(@TypeOf(s)).pointer.alignment);
178 try expect(A != @typeInfo(@TypeOf(s)).pointer.attrs.@"align");
179179 }
180180 };
181181
......@@ -255,10 +255,13 @@ test "generic function instantiation turns into comptime call" {
255255 }
256256
257257 pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
258 .@"enum" => std.builtin.Type.EnumField,
258 .@"enum" => struct { name: [:0]const u8, value: comptime_int },
259259 else => void,
260260 } {
261 return @typeInfo(T).@"enum".fields[@intFromEnum(field)];
261 return .{
262 .name = @typeInfo(T).@"enum".field_names[@intFromEnum(field)],
263 .value = @typeInfo(T).@"enum".field_values[@intFromEnum(field)],
264 };
262265 }
263266
264267 pub fn FieldEnum(comptime T: type) type {
test/behavior/memcpy.zig+3-3
......@@ -157,9 +157,9 @@ test "@memcpy with sentinel" {
157157
158158 const S = struct {
159159 fn doTheTest() void {
160 const field = @typeInfo(struct { a: u32 }).@"struct".fields[0];
161 var buffer: [field.name.len]u8 = undefined;
162 @memcpy(&buffer, field.name);
160 const field_name = @typeInfo(struct { a: u32 }).@"struct".field_names[0];
161 var buffer: [field_name.len]u8 = undefined;
162 @memcpy(&buffer, field_name);
163163 }
164164 };
165165
test/behavior/packed-struct.zig+2-2
......@@ -1040,9 +1040,9 @@ test "packed struct field pointer aligned properly" {
10401040 };
10411041
10421042 var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&Foo.buffer[0])));
1043 try expect(@typeInfo(@TypeOf(f1)).pointer.alignment == 16);
1043 try expect(@typeInfo(@TypeOf(f1)).pointer.attrs.@"align" == 16);
10441044 try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));
1045 try expect(@typeInfo(@TypeOf(&f1.a)).pointer.alignment == 16);
1045 try expect(@typeInfo(@TypeOf(&f1.a)).pointer.attrs.@"align" == 16);
10461046}
10471047
10481048test "load flag from packed struct in union" {
test/behavior/pointers.zig+18-18
......@@ -291,8 +291,8 @@ test "allowzero pointer and slice" {
291291 comptime assert(@TypeOf(slice) == []allowzero i32);
292292 try expect(@intFromPtr(&slice[5]) == 20);
293293
294 comptime assert(@typeInfo(@TypeOf(ptr)).pointer.is_allowzero);
295 comptime assert(@typeInfo(@TypeOf(slice)).pointer.is_allowzero);
294 comptime assert(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"allowzero");
295 comptime assert(@typeInfo(@TypeOf(slice)).pointer.attrs.@"allowzero");
296296}
297297
298298test "assign null directly to C pointer and test null equality" {
......@@ -470,15 +470,15 @@ test "pointer-integer arithmetic affects the alignment" {
470470 var x: usize = 1;
471471 _ = .{ &ptr, &x };
472472
473 try expect(@typeInfo(@TypeOf(ptr)).pointer.alignment == 8);
473 try expect(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"align" == 8);
474474 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4
475 try expect(@typeInfo(@TypeOf(ptr1)).pointer.alignment == 4);
475 try expect(@typeInfo(@TypeOf(ptr1)).pointer.attrs.@"align" == 4);
476476 const ptr2 = ptr + 4; // 4 * 4 = 16 -> lcd(16,8) = 8
477 try expect(@typeInfo(@TypeOf(ptr2)).pointer.alignment == 8);
477 try expect(@typeInfo(@TypeOf(ptr2)).pointer.attrs.@"align" == 8);
478478 const ptr3 = ptr + 0; // no-op
479 try expect(@typeInfo(@TypeOf(ptr3)).pointer.alignment == 8);
479 try expect(@typeInfo(@TypeOf(ptr3)).pointer.attrs.@"align" == 8);
480480 const ptr4 = ptr + x; // runtime-known addend
481 try expect(@typeInfo(@TypeOf(ptr4)).pointer.alignment == 4);
481 try expect(@typeInfo(@TypeOf(ptr4)).pointer.attrs.@"align" == 4);
482482 }
483483 {
484484 var ptr: [*]align(8) [3]u8 = undefined;
......@@ -486,13 +486,13 @@ test "pointer-integer arithmetic affects the alignment" {
486486 _ = .{ &ptr, &x };
487487
488488 const ptr1 = ptr + 17; // 3 * 17 = 51
489 try expect(@typeInfo(@TypeOf(ptr1)).pointer.alignment == 1);
489 try expect(@typeInfo(@TypeOf(ptr1)).pointer.attrs.@"align" == 1);
490490 const ptr2 = ptr + x; // runtime-known addend
491 try expect(@typeInfo(@TypeOf(ptr2)).pointer.alignment == 1);
491 try expect(@typeInfo(@TypeOf(ptr2)).pointer.attrs.@"align" == 1);
492492 const ptr3 = ptr + 8; // 3 * 8 = 24 -> lcd(8,24) = 8
493 try expect(@typeInfo(@TypeOf(ptr3)).pointer.alignment == 8);
493 try expect(@typeInfo(@TypeOf(ptr3)).pointer.attrs.@"align" == 8);
494494 const ptr4 = ptr + 4; // 3 * 4 = 12 -> lcd(8,12) = 4
495 try expect(@typeInfo(@TypeOf(ptr4)).pointer.alignment == 4);
495 try expect(@typeInfo(@TypeOf(ptr4)).pointer.attrs.@"align" == 4);
496496 }
497497}
498498
......@@ -592,7 +592,7 @@ test "pointer to constant decl preserves alignment" {
592592 const aligned align(8) = @This(){ .a = 3, .b = 4 };
593593 };
594594
595 const alignment = @typeInfo(@TypeOf(&S.aligned)).pointer.alignment;
595 const alignment = @typeInfo(@TypeOf(&S.aligned)).pointer.attrs.@"align";
596596 try std.testing.expect(alignment == 8);
597597}
598598
......@@ -673,24 +673,24 @@ const Box2 = struct {
673673
674674fn mutable() !void {
675675 var box0: Box0 = .{ .items = undefined };
676 try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).pointer.is_const == false);
676 try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).pointer.attrs.@"const" == false);
677677
678678 var box1: Box1 = .{ .items = undefined };
679 try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).pointer.is_const == false);
679 try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).pointer.attrs.@"const" == false);
680680
681681 var box2: Box2 = .{ .items = undefined };
682 try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).pointer.is_const == false);
682 try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).pointer.attrs.@"const" == false);
683683}
684684
685685fn constant() !void {
686686 const box0: Box0 = .{ .items = undefined };
687 try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).pointer.is_const == true);
687 try std.testing.expect(@typeInfo(@TypeOf(box0.items[0..])).pointer.attrs.@"const" == true);
688688
689689 const box1: Box1 = .{ .items = undefined };
690 try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).pointer.is_const == true);
690 try std.testing.expect(@typeInfo(@TypeOf(box1.items[0..])).pointer.attrs.@"const" == true);
691691
692692 const box2: Box2 = .{ .items = undefined };
693 try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).pointer.is_const == true);
693 try std.testing.expect(@typeInfo(@TypeOf(box2.items[0..])).pointer.attrs.@"const" == true);
694694}
695695
696696test "pointer-to-array constness for zero-size elements, var" {
test/behavior/reflection.zig+5-5
......@@ -8,11 +8,11 @@ test "reflection: function return type, var args, and param types" {
88 comptime {
99 const info = @typeInfo(@TypeOf(dummy)).@"fn";
1010 try expect(info.return_type.? == i32);
11 try expect(!info.is_var_args);
12 try expect(info.params.len == 3);
13 try expect(info.params[0].type.? == bool);
14 try expect(info.params[1].type.? == i32);
15 try expect(info.params[2].type.? == f32);
11 try expect(!info.attrs.varargs);
12 try expect(info.param_types.len == 3);
13 try expect(info.param_types[0].? == bool);
14 try expect(info.param_types[1].? == i32);
15 try expect(info.param_types[2].? == f32);
1616 }
1717}
1818
test/behavior/slice.zig+3-3
......@@ -388,9 +388,9 @@ test "empty array to slice" {
388388 const align_1: []align(1) u8 = empty;
389389 const align_4: []align(4) u8 = empty;
390390 const align_16: []align(16) u8 = empty;
391 try expect(1 == @typeInfo(@TypeOf(align_1)).pointer.alignment);
392 try expect(4 == @typeInfo(@TypeOf(align_4)).pointer.alignment);
393 try expect(16 == @typeInfo(@TypeOf(align_16)).pointer.alignment);
391 try expect(1 == @typeInfo(@TypeOf(align_1)).pointer.attrs.@"align");
392 try expect(4 == @typeInfo(@TypeOf(align_4)).pointer.attrs.@"align");
393 try expect(16 == @typeInfo(@TypeOf(align_16)).pointer.attrs.@"align");
394394 }
395395 };
396396
test/behavior/struct.zig+1-1
......@@ -1627,7 +1627,7 @@ test "packed struct field in anonymous struct" {
16271627 try std.testing.expect(countFields(.{ .t = T{} }) == 1);
16281628}
16291629fn countFields(v: anytype) usize {
1630 return @typeInfo(@TypeOf(v)).@"struct".fields.len;
1630 return @typeInfo(@TypeOf(v)).@"struct".field_names.len;
16311631}
16321632
16331633test "struct init with no result pointer sets field result types" {
test/behavior/tuple.zig+8-8
......@@ -512,9 +512,9 @@ test "empty struct in tuple" {
512512
513513 const T = struct { struct {} };
514514 const info = @typeInfo(T);
515 try std.testing.expectEqual(@as(usize, 1), info.@"struct".fields.len);
516 try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name);
517 try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"struct");
515 try std.testing.expectEqual(@as(usize, 1), info.@"struct".field_names.len);
516 try std.testing.expectEqualStrings("0", info.@"struct".field_names[0]);
517 try std.testing.expect(@typeInfo(info.@"struct".field_types[0]) == .@"struct");
518518}
519519
520520test "empty union in tuple" {
......@@ -524,9 +524,9 @@ test "empty union in tuple" {
524524
525525 const T = struct { union {} };
526526 const info = @typeInfo(T);
527 try std.testing.expectEqual(@as(usize, 1), info.@"struct".fields.len);
528 try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name);
529 try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"union");
527 try std.testing.expectEqual(@as(usize, 1), info.@"struct".field_names.len);
528 try std.testing.expectEqualStrings("0", info.@"struct".field_names[0]);
529 try std.testing.expect(@typeInfo(info.@"struct".field_types[0]) == .@"union");
530530}
531531
532532test "field pointer of underaligned tuple" {
......@@ -551,11 +551,11 @@ test "field pointer of underaligned tuple" {
551551test "OPV tuple fields aren't comptime" {
552552 const T = struct { void };
553553 const t_info = @typeInfo(T);
554 try expect(!t_info.@"struct".fields[0].is_comptime);
554 try expect(!t_info.@"struct".field_attrs[0].@"comptime");
555555
556556 const T2 = @Tuple(&.{void});
557557 const t2_info = @typeInfo(T2);
558 try expect(!t2_info.@"struct".fields[0].is_comptime);
558 try expect(!t2_info.@"struct".field_attrs[0].@"comptime");
559559}
560560
561561test "array of tuples that end with a zero-bit field followed by padding" {
test/behavior/tuple_declarations.zig+15-15
......@@ -12,23 +12,23 @@ test "tuple declaration type info" {
1212 const T = struct { comptime u32 = 1, []const u8 };
1313 const info = @typeInfo(T).@"struct";
1414
15 try expect(info.is_tuple);
1516 try expect(info.layout == .auto);
1617 try expect(info.backing_integer == null);
17 try expect(info.fields.len == 2);
18 try expect(info.decls.len == 0);
19 try expect(info.is_tuple);
20
21 try expectEqualStrings(info.fields[0].name, "0");
22 try expect(info.fields[0].type == u32);
23 try expect(info.fields[0].defaultValue() == 1);
24 try expect(info.fields[0].is_comptime);
25 try expect(info.fields[0].alignment == null);
26
27 try expectEqualStrings(info.fields[1].name, "1");
28 try expect(info.fields[1].type == []const u8);
29 try expect(info.fields[1].defaultValue() == null);
30 try expect(!info.fields[1].is_comptime);
31 try expect(info.fields[1].alignment == null);
18 try expect(info.field_names.len == 2);
19 try expect(info.decl_names.len == 0);
20
21 try expectEqualStrings(info.field_names[0], "0");
22 try expect(info.field_types[0] == u32);
23 try expect(info.field_attrs[0].defaultValue(info.field_types[0]) == 1);
24 try expect(info.field_attrs[0].@"comptime");
25 try expect(info.field_attrs[0].@"align" == null);
26
27 try expectEqualStrings(info.field_names[1], "1");
28 try expect(info.field_types[1] == []const u8);
29 try expect(info.field_attrs[1].defaultValue(info.field_types[1]) == null);
30 try expect(!info.field_attrs[1].@"comptime");
31 try expect(info.field_attrs[1].@"align" == null);
3232 }
3333}
3434
test/behavior/type.zig+37-49
......@@ -57,13 +57,7 @@ test "Type.Pointer" {
5757 [*c]align(8) volatile u8, [*c]align(8) const volatile u8,
5858 }) |testType| {
5959 const ptr = @typeInfo(testType).pointer;
60 try testing.expect(testType == @Pointer(ptr.size, .{
61 .@"const" = ptr.is_const,
62 .@"volatile" = ptr.is_volatile,
63 .@"allowzero" = ptr.is_allowzero,
64 .@"align" = ptr.alignment,
65 .@"addrspace" = ptr.address_space,
66 }, ptr.child, ptr.sentinel()));
60 try testing.expect(testType == @Pointer(ptr.size, ptr.attrs, ptr.child, ptr.sentinel()));
6761 }
6862}
6963
......@@ -103,13 +97,7 @@ test "@Pointer on @typeInfo round-trips sentinels" {
10397 [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8,
10498 }) |TestType| {
10599 const ptr = @typeInfo(TestType).pointer;
106 try testing.expect(TestType == @Pointer(ptr.size, .{
107 .@"const" = ptr.is_const,
108 .@"volatile" = ptr.is_volatile,
109 .@"allowzero" = ptr.is_allowzero,
110 .@"align" = ptr.alignment,
111 .@"addrspace" = ptr.address_space,
112 }, ptr.child, ptr.sentinel()));
100 try testing.expect(TestType == @Pointer(ptr.size, ptr.attrs, ptr.child, ptr.sentinel()));
113101 }
114102}
115103
......@@ -122,9 +110,9 @@ test "Type.Opaque" {
122110 const Opaque = opaque {};
123111 try testing.expect(Opaque != opaque {});
124112 try testing.expectEqualSlices(
125 Type.Declaration,
113 [:0]const u8,
126114 &.{},
127 @typeInfo(Opaque).@"opaque".decls,
115 @typeInfo(Opaque).@"opaque".decl_names,
128116 );
129117}
130118
......@@ -141,13 +129,13 @@ test "Type.Struct" {
141129 const A = @Struct(.auto, null, &.{ "x", "y" }, &.{ u8, u32 }, &@splat(.{}));
142130 const infoA = @typeInfo(A).@"struct";
143131 try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout);
144 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);
145 try testing.expectEqual(u8, infoA.fields[0].type);
146 try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value_ptr);
147 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);
148 try testing.expectEqual(u32, infoA.fields[1].type);
149 try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value_ptr);
150 try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls);
132 try testing.expectEqualSlices(u8, "x", infoA.field_names[0]);
133 try testing.expectEqual(u8, infoA.field_types[0]);
134 try testing.expectEqual(@as(?*const anyopaque, null), infoA.field_attrs[0].default_value_ptr);
135 try testing.expectEqualSlices(u8, "y", infoA.field_names[1]);
136 try testing.expectEqual(u32, infoA.field_types[1]);
137 try testing.expectEqual(@as(?*const anyopaque, null), infoA.field_attrs[1].default_value_ptr);
138 try testing.expectEqualSlices([:0]const u8, &.{}, infoA.decl_names);
151139 try testing.expectEqual(@as(bool, false), infoA.is_tuple);
152140
153141 var a = A{ .x = 0, .y = 1 };
......@@ -165,13 +153,13 @@ test "Type.Struct" {
165153 );
166154 const infoB = @typeInfo(B).@"struct";
167155 try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout);
168 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);
169 try testing.expectEqual(u8, infoB.fields[0].type);
170 try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value_ptr);
171 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);
172 try testing.expectEqual(u32, infoB.fields[1].type);
173 try testing.expectEqual(@as(u32, 5), infoB.fields[1].defaultValue().?);
174 try testing.expectEqual(@as(usize, 0), infoB.decls.len);
156 try testing.expectEqualSlices(u8, "x", infoB.field_names[0]);
157 try testing.expectEqual(u8, infoB.field_types[0]);
158 try testing.expectEqual(@as(?*const anyopaque, null), infoB.field_attrs[0].default_value_ptr);
159 try testing.expectEqualSlices(u8, "y", infoB.field_names[1]);
160 try testing.expectEqual(u32, infoB.field_types[1]);
161 try testing.expectEqual(@as(u32, 5), infoB.field_attrs[1].defaultValue(infoB.field_types[1]).?);
162 try testing.expectEqual(@as(usize, 0), infoB.decl_names.len);
175163 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
176164
177165 const C = @Struct(
......@@ -186,20 +174,20 @@ test "Type.Struct" {
186174 );
187175 const infoC = @typeInfo(C).@"struct";
188176 try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout);
189 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);
190 try testing.expectEqual(u8, infoC.fields[0].type);
191 try testing.expectEqual(@as(u8, 3), infoC.fields[0].defaultValue().?);
192 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);
193 try testing.expectEqual(u32, infoC.fields[1].type);
194 try testing.expectEqual(@as(u32, 5), infoC.fields[1].defaultValue().?);
195 try testing.expectEqual(@as(usize, 0), infoC.decls.len);
177 try testing.expectEqualSlices(u8, "x", infoC.field_names[0]);
178 try testing.expectEqual(u8, infoC.field_types[0]);
179 try testing.expectEqual(@as(u8, 3), infoC.field_attrs[0].defaultValue(infoC.field_types[0]).?);
180 try testing.expectEqualSlices(u8, "y", infoC.field_names[1]);
181 try testing.expectEqual(u32, infoC.field_types[1]);
182 try testing.expectEqual(@as(u32, 5), infoC.field_attrs[1].defaultValue(infoC.field_types[1]).?);
183 try testing.expectEqual(@as(usize, 0), infoC.decl_names.len);
196184 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
197185
198186 // empty struct
199187 const F = @Struct(.auto, null, &.{}, &.{}, &.{});
200188 const infoF = @typeInfo(F).@"struct";
201189 try testing.expectEqual(Type.ContainerLayout.auto, infoF.layout);
202 try testing.expect(infoF.fields.len == 0);
190 try testing.expect(infoF.field_names.len == 0);
203191 try testing.expectEqual(@as(bool, false), infoF.is_tuple);
204192}
205193
......@@ -208,11 +196,11 @@ test "Type.Enum" {
208196 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
209197
210198 const Foo = @Enum(u8, .exhaustive, &.{ "a", "b" }, &.{ 1, 5 });
211 try testing.expectEqual(true, @typeInfo(Foo).@"enum".is_exhaustive);
199 try testing.expectEqual(std.builtin.Type.Enum.Mode.exhaustive, @typeInfo(Foo).@"enum".mode);
212200 try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a));
213201 try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b));
214202 const Bar = @Enum(u32, .nonexhaustive, &.{ "a", "b" }, &.{ 1, 5 });
215 try testing.expectEqual(false, @typeInfo(Bar).@"enum".is_exhaustive);
203 try testing.expectEqual(std.builtin.Type.Enum.Mode.nonexhaustive, @typeInfo(Bar).@"enum".mode);
216204 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));
217205 try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b));
218206 try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6))));
......@@ -278,13 +266,13 @@ test "Type.Union from regular enum" {
278266test "Type.Union from empty regular enum" {
279267 const E = enum {};
280268 const U = @Union(.auto, E, &.{}, &.{}, &.{});
281 try testing.expectEqual(@typeInfo(U).@"union".fields.len, 0);
269 try testing.expectEqual(@typeInfo(U).@"union".field_names.len, 0);
282270}
283271
284272test "Type.Union from empty Type.Enum" {
285273 const E = @Enum(u0, .exhaustive, &.{}, &.{});
286274 const U = @Union(.auto, E, &.{}, &.{}, &.{});
287 try testing.expectEqual(@typeInfo(U).@"union".fields.len, 0);
275 try testing.expectEqual(@typeInfo(U).@"union".field_names.len, 0);
288276}
289277
290278test "Type.Fn" {
......@@ -378,11 +366,11 @@ test "struct field names sliced at comptime from larger string" {
378366 }
379367
380368 const T = @Struct(.auto, null, field_names, &@splat(usize), &@splat(.{}));
381 const gen_fields = @typeInfo(T).@"struct".fields;
382 try testing.expectEqual(3, gen_fields.len);
383 try testing.expectEqualStrings("f1", gen_fields[0].name);
384 try testing.expectEqualStrings("f2", gen_fields[1].name);
385 try testing.expectEqualStrings("f3", gen_fields[2].name);
369 const gen_field_names = @typeInfo(T).@"struct".field_names;
370 try testing.expectEqual(3, gen_field_names.len);
371 try testing.expectEqualStrings("f1", gen_field_names[0]);
372 try testing.expectEqualStrings("f2", gen_field_names[1]);
373 try testing.expectEqualStrings("f3", gen_field_names[2]);
386374 }
387375}
388376
......@@ -431,8 +419,8 @@ test "undefined type value" {
431419test "reify struct with zero fields through const arrays" {
432420 const names: [0][]const u8 = .{};
433421 const types: [0]type = .{};
434 const attrs: [0]std.builtin.Type.StructField.Attributes = .{};
422 const attrs: [0]std.builtin.Type.Struct.FieldAttributes = .{};
435423 const S = @Struct(.auto, null, &names, &types, &attrs);
436424 comptime assert(@typeInfo(S) == .@"struct");
437 comptime assert(@typeInfo(S).@"struct".fields.len == 0);
425 comptime assert(@typeInfo(S).@"struct".field_names.len == 0);
438426}
test/behavior/type_info.zig+103-91
......@@ -45,9 +45,9 @@ fn testCPtr() !void {
4545 const ptr_info = @typeInfo([*c]align(4) const i8);
4646 try expect(ptr_info == .pointer);
4747 try expect(ptr_info.pointer.size == .c);
48 try expect(ptr_info.pointer.is_const);
49 try expect(!ptr_info.pointer.is_volatile);
50 try expect(ptr_info.pointer.alignment == 4);
48 try expect(ptr_info.pointer.attrs.@"const");
49 try expect(!ptr_info.pointer.attrs.@"volatile");
50 try expect(ptr_info.pointer.attrs.@"align" == 4);
5151 try expect(ptr_info.pointer.child == i8);
5252}
5353
......@@ -80,9 +80,9 @@ fn testPointer() !void {
8080 const u32_ptr_info = @typeInfo(*u32);
8181 try expect(u32_ptr_info == .pointer);
8282 try expect(u32_ptr_info.pointer.size == .one);
83 try expect(u32_ptr_info.pointer.is_const == false);
84 try expect(u32_ptr_info.pointer.is_volatile == false);
85 try expect(u32_ptr_info.pointer.alignment == null);
83 try expect(u32_ptr_info.pointer.attrs.@"const" == false);
84 try expect(u32_ptr_info.pointer.attrs.@"volatile" == false);
85 try expect(u32_ptr_info.pointer.attrs.@"align" == null);
8686 try expect(u32_ptr_info.pointer.child == u32);
8787 try expect(u32_ptr_info.pointer.sentinel() == null);
8888}
......@@ -96,11 +96,11 @@ fn testUnknownLenPtr() !void {
9696 const u32_ptr_info = @typeInfo([*]const volatile f64);
9797 try expect(u32_ptr_info == .pointer);
9898 try expect(u32_ptr_info.pointer.size == .many);
99 try expect(u32_ptr_info.pointer.is_const == true);
100 try expect(u32_ptr_info.pointer.is_volatile == true);
101 try expect(u32_ptr_info.pointer.sentinel() == null);
102 try expect(u32_ptr_info.pointer.alignment == null);
99 try expect(u32_ptr_info.pointer.attrs.@"const" == true);
100 try expect(u32_ptr_info.pointer.attrs.@"volatile" == true);
101 try expect(u32_ptr_info.pointer.attrs.@"align" == null);
103102 try expect(u32_ptr_info.pointer.child == f64);
103 try expect(u32_ptr_info.pointer.sentinel() == null);
104104}
105105
106106test "type info: null terminated pointer type info" {
......@@ -112,8 +112,8 @@ fn testNullTerminatedPtr() !void {
112112 const ptr_info = @typeInfo([*:0]u8);
113113 try expect(ptr_info == .pointer);
114114 try expect(ptr_info.pointer.size == .many);
115 try expect(ptr_info.pointer.is_const == false);
116 try expect(ptr_info.pointer.is_volatile == false);
115 try expect(ptr_info.pointer.attrs.@"const" == false);
116 try expect(ptr_info.pointer.attrs.@"volatile" == false);
117117 try expect(ptr_info.pointer.sentinel().? == 0);
118118
119119 try expect(@typeInfo([:0]u8).pointer.sentinel() != null);
......@@ -128,9 +128,9 @@ fn testSlice() !void {
128128 const u32_slice_info = @typeInfo([]u32);
129129 try expect(u32_slice_info == .pointer);
130130 try expect(u32_slice_info.pointer.size == .slice);
131 try expect(u32_slice_info.pointer.is_const == false);
132 try expect(u32_slice_info.pointer.is_volatile == false);
133 try expect(u32_slice_info.pointer.alignment == null);
131 try expect(u32_slice_info.pointer.attrs.@"const" == false);
132 try expect(u32_slice_info.pointer.attrs.@"volatile" == false);
133 try expect(u32_slice_info.pointer.attrs.@"align" == null);
134134 try expect(u32_slice_info.pointer.child == u32);
135135}
136136
......@@ -175,8 +175,8 @@ fn testErrorSet() !void {
175175
176176 const error_set_info = @typeInfo(TestErrorSet);
177177 try expect(error_set_info == .error_set);
178 try expect(error_set_info.error_set.?.len == 3);
179 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "First"));
178 try expect(error_set_info.error_set.error_names.?.len == 3);
179 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "First"));
180180
181181 const error_union_info = @typeInfo(TestErrorSet!usize);
182182 try expect(error_union_info == .error_union);
......@@ -185,7 +185,7 @@ fn testErrorSet() !void {
185185
186186 const global_info = @typeInfo(anyerror);
187187 try expect(global_info == .error_set);
188 try expect(global_info.error_set == null);
188 try expect(global_info.error_set.error_names == null);
189189}
190190
191191test "type info: error set single value" {
......@@ -197,8 +197,8 @@ test "type info: error set single value" {
197197
198198 const error_set_info = @typeInfo(@TypeOf(TestSet));
199199 try expect(error_set_info == .error_set);
200 try expect(error_set_info.error_set.?.len == 1);
201 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
200 try expect(error_set_info.error_set.error_names.?.len == 1);
201 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
202202}
203203
204204test "type info: error set merged" {
......@@ -210,10 +210,10 @@ test "type info: error set merged" {
210210
211211 const error_set_info = @typeInfo(TestSet);
212212 try expect(error_set_info == .error_set);
213 try expect(error_set_info.error_set.?.len == 3);
214 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));
215 try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two"));
216 try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three"));
213 try expect(error_set_info.error_set.error_names.?.len == 3);
214 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
215 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
216 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
217217}
218218
219219test "type info: enum info" {
......@@ -235,11 +235,12 @@ fn testEnum() !void {
235235
236236 const os_info = @typeInfo(Os);
237237 try expect(os_info == .@"enum");
238 try expect(os_info.@"enum".fields.len == 4);
239 try expect(mem.eql(u8, os_info.@"enum".fields[1].name, "Macos"));
240 try expect(os_info.@"enum".fields[3].value == 3);
238 try expect(os_info.@"enum".field_names.len == 4);
239 try expect(os_info.@"enum".field_values.len == os_info.@"enum".field_names.len);
240 try expect(mem.eql(u8, os_info.@"enum".field_names[1], "Macos"));
241 try expect(os_info.@"enum".field_values[3] == 3);
241242 try expect(os_info.@"enum".tag_type == u2);
242 try expect(os_info.@"enum".decls.len == 0);
243 try expect(os_info.@"enum".decl_names.len == 0);
243244}
244245
245246test "type info: union info" {
......@@ -252,9 +253,11 @@ fn testUnion() !void {
252253 try expect(typeinfo_info == .@"union");
253254 try expect(typeinfo_info.@"union".layout == .auto);
254255 try expect(typeinfo_info.@"union".tag_type.? == TypeId);
255 try expect(typeinfo_info.@"union".fields.len == 24);
256 try expect(typeinfo_info.@"union".fields[4].type == @TypeOf(@typeInfo(u8).int));
257 try expect(typeinfo_info.@"union".decls.len == 21);
256 try expect(typeinfo_info.@"union".field_names.len == 24);
257 try expect(typeinfo_info.@"union".field_names.len == typeinfo_info.@"union".field_types.len);
258 try expect(typeinfo_info.@"union".field_names.len == typeinfo_info.@"union".field_attrs.len);
259 try expect(typeinfo_info.@"union".field_types[4] == @TypeOf(@typeInfo(u8).int));
260 try expect(typeinfo_info.@"union".decl_names.len == 16);
258261
259262 const TestNoTagUnion = union {
260263 Foo: void,
......@@ -265,10 +268,12 @@ fn testUnion() !void {
265268 try expect(notag_union_info == .@"union");
266269 try expect(notag_union_info.@"union".tag_type == null);
267270 try expect(notag_union_info.@"union".layout == .auto);
268 try expect(notag_union_info.@"union".fields.len == 2);
269 try expect(notag_union_info.@"union".fields[0].alignment == null);
270 try expect(notag_union_info.@"union".fields[1].type == u32);
271 try expect(notag_union_info.@"union".fields[1].alignment == null);
271 try expect(notag_union_info.@"union".field_names.len == 2);
272 try expect(notag_union_info.@"union".field_names.len == notag_union_info.@"union".field_types.len);
273 try expect(notag_union_info.@"union".field_names.len == notag_union_info.@"union".field_attrs.len);
274 try expect(notag_union_info.@"union".field_attrs[0].@"align" == null);
275 try expect(notag_union_info.@"union".field_types[1] == u32);
276 try expect(notag_union_info.@"union".field_attrs[1].@"align" == null);
272277
273278 const TestExternUnion = extern union {
274279 foo: *anyopaque,
......@@ -277,7 +282,7 @@ fn testUnion() !void {
277282 const extern_union_info = @typeInfo(TestExternUnion);
278283 try expect(extern_union_info.@"union".layout == .@"extern");
279284 try expect(extern_union_info.@"union".tag_type == null);
280 try expect(extern_union_info.@"union".fields[0].type == *anyopaque);
285 try expect(extern_union_info.@"union".field_types[0] == *anyopaque);
281286}
282287
283288test "type info: struct info" {
......@@ -292,9 +297,11 @@ fn testStruct() !void {
292297 const unpacked_struct_info = @typeInfo(TestStruct);
293298 try expect(unpacked_struct_info.@"struct".is_tuple == false);
294299 try expect(unpacked_struct_info.@"struct".backing_integer == null);
295 try expect(unpacked_struct_info.@"struct".fields[0].alignment == null);
296 try expect(unpacked_struct_info.@"struct".fields[0].defaultValue().? == 4);
297 try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".fields[1].defaultValue().?));
300 try expect(unpacked_struct_info.@"struct".field_attrs[0].@"align" == null);
301 const field_0_type = unpacked_struct_info.@"struct".field_types[0];
302 try expect(unpacked_struct_info.@"struct".field_attrs[0].defaultValue(field_0_type).? == 4);
303 const field_1_type = unpacked_struct_info.@"struct".field_types[1];
304 try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".field_attrs[1].defaultValue(field_1_type).?));
298305}
299306
300307const TestStruct = struct {
......@@ -313,13 +320,17 @@ fn testPackedStruct() !void {
313320 try expect(struct_info.@"struct".is_tuple == false);
314321 try expect(struct_info.@"struct".layout == .@"packed");
315322 try expect(struct_info.@"struct".backing_integer == u128);
316 try expect(struct_info.@"struct".fields.len == 4);
317 try expect(struct_info.@"struct".fields[0].alignment == null);
318 try expect(struct_info.@"struct".fields[2].type == f32);
319 try expect(struct_info.@"struct".fields[2].defaultValue() == null);
320 try expect(struct_info.@"struct".fields[3].defaultValue().? == 4);
321 try expect(struct_info.@"struct".fields[3].alignment == null);
322 try expect(struct_info.@"struct".decls.len == 1);
323 try expect(struct_info.@"struct".field_names.len == 4);
324 try expect(struct_info.@"struct".field_names.len == struct_info.@"struct".field_types.len);
325 try expect(struct_info.@"struct".field_names.len == struct_info.@"struct".field_attrs.len);
326 try expect(struct_info.@"struct".field_attrs[0].@"align" == null);
327 try expect(struct_info.@"struct".field_types[2] == f32);
328 const field_2_type = struct_info.@"struct".field_types[2];
329 try expect(struct_info.@"struct".field_attrs[2].defaultValue(field_2_type) == null);
330 const field_3_type = struct_info.@"struct".field_types[3];
331 try expect(struct_info.@"struct".field_attrs[3].defaultValue(field_3_type).? == 4);
332 try expect(struct_info.@"struct".field_attrs[3].@"align" == null);
333 try expect(struct_info.@"struct".decl_names.len == 1);
323334}
324335
325336const TestPackedStruct = packed struct {
......@@ -346,7 +357,7 @@ fn testOpaque() !void {
346357 };
347358
348359 const foo_info = @typeInfo(Foo);
349 try expect(foo_info.@"opaque".decls.len == 2);
360 try expect(foo_info.@"opaque".decl_names.len == 2);
350361}
351362
352363test "type info: function type info" {
......@@ -371,18 +382,18 @@ fn testFunction() !void {
371382 _ = S;
372383 const foo_fn_type = @TypeOf(typeInfoFoo);
373384 const foo_fn_info = @typeInfo(foo_fn_type);
374 try expect(foo_fn_info.@"fn".calling_convention.eql(.c));
385 try expect(foo_fn_info.@"fn".attrs.@"callconv".eql(.c));
375386 try expect(!foo_fn_info.@"fn".is_generic);
376 try expect(foo_fn_info.@"fn".params.len == 2);
377 try expect(foo_fn_info.@"fn".is_var_args);
387 try expect(foo_fn_info.@"fn".param_types.len == 2);
388 try expect(foo_fn_info.@"fn".attrs.varargs);
378389 try expect(foo_fn_info.@"fn".return_type.? == usize);
379390 const foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFoo));
380391 try expect(foo_ptr_fn_info.pointer.size == .one);
381 try expect(foo_ptr_fn_info.pointer.is_const);
382 try expect(!foo_ptr_fn_info.pointer.is_volatile);
383 try expect(foo_ptr_fn_info.pointer.address_space == .generic);
392 try expect(foo_ptr_fn_info.pointer.attrs.@"const");
393 try expect(!foo_ptr_fn_info.pointer.attrs.@"volatile");
394 try expect(foo_ptr_fn_info.pointer.attrs.@"addrspace" == .generic);
384395 try expect(foo_ptr_fn_info.pointer.child == foo_fn_type);
385 try expect(!foo_ptr_fn_info.pointer.is_allowzero);
396 try expect(!foo_ptr_fn_info.pointer.attrs.@"allowzero");
386397 try expect(foo_ptr_fn_info.pointer.sentinel() == null);
387398
388399 // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment.
......@@ -397,19 +408,20 @@ fn testFunction() !void {
397408
398409 const aligned_foo_fn_type = @TypeOf(typeInfoFooAligned);
399410 const aligned_foo_fn_info = @typeInfo(aligned_foo_fn_type);
400 try expect(aligned_foo_fn_info.@"fn".calling_convention.eql(.c));
411 try expect(aligned_foo_fn_info.@"fn".attrs.@"callconv".eql(.c));
401412 try expect(!aligned_foo_fn_info.@"fn".is_generic);
402 try expect(aligned_foo_fn_info.@"fn".params.len == 2);
403 try expect(aligned_foo_fn_info.@"fn".is_var_args);
413 try expect(aligned_foo_fn_info.@"fn".param_types.len == 2);
414 try expect(aligned_foo_fn_info.@"fn".param_types.len == aligned_foo_fn_info.@"fn".param_attrs.len);
415 try expect(aligned_foo_fn_info.@"fn".attrs.varargs);
404416 try expect(aligned_foo_fn_info.@"fn".return_type.? == usize);
405417 const aligned_foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFooAligned));
406418 try expect(aligned_foo_ptr_fn_info.pointer.size == .one);
407 try expect(aligned_foo_ptr_fn_info.pointer.is_const);
408 try expect(!aligned_foo_ptr_fn_info.pointer.is_volatile);
409 try expect(aligned_foo_ptr_fn_info.pointer.alignment == 4);
410 try expect(aligned_foo_ptr_fn_info.pointer.address_space == .generic);
419 try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"const");
420 try expect(!aligned_foo_ptr_fn_info.pointer.attrs.@"volatile");
421 try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"align" == 4);
422 try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"addrspace" == .generic);
411423 try expect(aligned_foo_ptr_fn_info.pointer.child == aligned_foo_fn_type);
412 try expect(!aligned_foo_ptr_fn_info.pointer.is_allowzero);
424 try expect(!aligned_foo_ptr_fn_info.pointer.attrs.@"allowzero");
413425 try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null);
414426}
415427
......@@ -418,31 +430,29 @@ extern fn typeInfoFooAligned(a: usize, b: bool, ...) align(4) callconv(.c) usize
418430
419431test "type info: generic function types" {
420432 const G1 = @typeInfo(@TypeOf(generic1));
421 try expect(G1.@"fn".params.len == 1);
422 try expect(G1.@"fn".params[0].is_generic == true);
423 try expect(G1.@"fn".params[0].type == null);
433 try expect(G1.@"fn".param_types.len == 1);
434 try expect(G1.@"fn".param_types.len == G1.@"fn".param_attrs.len);
435 try expect(G1.@"fn".param_types[0] == null);
424436 try expect(G1.@"fn".return_type == void);
425437
426438 const G2 = @typeInfo(@TypeOf(generic2));
427 try expect(G2.@"fn".params.len == 3);
428 try expect(G2.@"fn".params[0].is_generic == false);
429 try expect(G2.@"fn".params[0].type == type);
430 try expect(G2.@"fn".params[1].is_generic == true);
431 try expect(G2.@"fn".params[1].type == null);
432 try expect(G2.@"fn".params[2].is_generic == false);
433 try expect(G2.@"fn".params[2].type == u8);
439 try expect(G2.@"fn".param_types.len == 3);
440 try expect(G2.@"fn".param_types.len == G2.@"fn".param_attrs.len);
441 try expect(G2.@"fn".param_types[0] == type);
442 try expect(G2.@"fn".param_types[1] == null);
443 try expect(G2.@"fn".param_types[2] == u8);
434444 try expect(G2.@"fn".return_type == void);
435445
436446 const G3 = @typeInfo(@TypeOf(generic3));
437 try expect(G3.@"fn".params.len == 1);
438 try expect(G3.@"fn".params[0].is_generic == true);
439 try expect(G3.@"fn".params[0].type == null);
447 try expect(G3.@"fn".param_types.len == 1);
448 try expect(G3.@"fn".param_types.len == G3.@"fn".param_attrs.len);
449 try expect(G3.@"fn".param_types[0] == null);
440450 try expect(G3.@"fn".return_type == null);
441451
442452 const G4 = @typeInfo(@TypeOf(generic4));
443 try expect(G4.@"fn".params.len == 1);
444 try expect(G4.@"fn".params[0].is_generic == true);
445 try expect(G4.@"fn".params[0].type == null);
453 try expect(G4.@"fn".param_types.len == 1);
454 try expect(G4.@"fn".param_types.len == G4.@"fn".param_attrs.len);
455 try expect(G4.@"fn".param_types[0] == null);
446456 try expect(G4.@"fn".return_type == null);
447457}
448458
......@@ -530,7 +540,7 @@ test "@typeInfo does not force declarations into existence" {
530540 @compileError("test failed");
531541 }
532542 };
533 comptime assert(@typeInfo(S).@"struct".fields.len == 1);
543 comptime assert(@typeInfo(S).@"struct".field_names.len == 1);
534544}
535545
536546fn add(a: i32, b: i32) i32 {
......@@ -548,12 +558,12 @@ test "Declarations are returned in declaration order" {
548558 pub const d = 4;
549559 pub const e = 5;
550560 };
551 const d = @typeInfo(S).@"struct".decls;
552 try expect(std.mem.eql(u8, d[0].name, "a"));
553 try expect(std.mem.eql(u8, d[1].name, "b"));
554 try expect(std.mem.eql(u8, d[2].name, "c"));
555 try expect(std.mem.eql(u8, d[3].name, "d"));
556 try expect(std.mem.eql(u8, d[4].name, "e"));
561 const d = @typeInfo(S).@"struct".decl_names;
562 try expect(std.mem.eql(u8, d[0], "a"));
563 try expect(std.mem.eql(u8, d[1], "b"));
564 try expect(std.mem.eql(u8, d[2], "c"));
565 try expect(std.mem.eql(u8, d[3], "d"));
566 try expect(std.mem.eql(u8, d[4], "e"));
557567}
558568
559569test "Struct.is_tuple for anon list literal" {
......@@ -567,25 +577,27 @@ test "Struct.is_tuple for anon struct literal" {
567577
568578 const info = @typeInfo(@TypeOf(.{ .a = 0 }));
569579 try expect(!info.@"struct".is_tuple);
570 try expect(std.mem.eql(u8, info.@"struct".fields[0].name, "a"));
580 try expect(std.mem.eql(u8, info.@"struct".field_names[0], "a"));
571581}
572582
573583test "StructField.is_comptime" {
574584 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).@"struct";
575 try expect(!info.fields[0].is_comptime);
576 try expect(info.fields[1].is_comptime);
585 try expect(!info.field_attrs[0].@"comptime");
586 try expect(info.field_attrs[1].@"comptime");
577587}
578588
579589test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
580590 comptime {
581 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".fields[0].default_value_ptr;
591 const a = @typeInfo(@TypeOf(.{ .foo = @as(u8, 1) })).@"struct".field_attrs[0].default_value_ptr;
582592 try expect(@as(*const u8, @ptrCast(a)).* == 1);
583593 }
584594}
585595
586596test "type info of tuple of string literal default value" {
587 const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0];
588 const value = struct_field.defaultValue().?;
597 const struct_info = @typeInfo(@TypeOf(.{"hi"})).@"struct";
598 const struct_field_attrs = struct_info.field_attrs[0];
599 const struct_field_type = struct_info.field_types[0];
600 const value = struct_field_attrs.defaultValue(struct_field_type).?;
589601 comptime std.debug.assert(value[0] == 'h');
590602}
591603
test/behavior/union.zig+3-3
......@@ -445,7 +445,7 @@ test "global union with single field is correctly initialized" {
445445 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
446446
447447 glbl = Foo1{
448 .f = @typeInfo(Foo1).@"union".fields[0].type{ .x = 123 },
448 .f = @typeInfo(Foo1).@"union".field_types[0]{ .x = 123 },
449449 };
450450 try expect(glbl.f.x == 123);
451451}
......@@ -563,8 +563,8 @@ test "tagged union type" {
563563 const baz = Baz.B;
564564
565565 try expect(baz == Baz.B);
566 try expect(@typeInfo(TaggedFoo).@"union".fields.len == 3);
567 try expect(@typeInfo(Baz).@"enum".fields.len == 4);
566 try expect(@typeInfo(TaggedFoo).@"union".field_names.len == 3);
567 try expect(@typeInfo(Baz).@"enum".field_names.len == 4);
568568 try expect(@sizeOf(TaggedFoo) == @sizeOf(FooNoVoid));
569569 try expect(@sizeOf(Baz) == 1);
570570}
test/behavior/x86_64/math.zig+2-2
......@@ -130,8 +130,8 @@ pub noinline fn checkExpected(expected: anytype, actual: @TypeOf(expected), comp
130130 };
131131 },
132132 },
133 .@"struct" => |@"struct"| inline for (@"struct".fields) |field| {
134 try checkExpected(@field(expected, field.name), @field(actual, field.name), compare);
133 .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| {
134 try checkExpected(@field(expected, field_name), @field(actual, field_name), compare);
135135 } else return,
136136 };
137137 if (switch (@typeInfo(Expected)) {
test/behavior/zon.zig+8-8
......@@ -541,31 +541,31 @@ test "anon" {
541541 try expectEqual(expected[1], actual[1]);
542542 const expected_struct = expected[0];
543543 const actual_struct = actual[0];
544 const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".fields;
545 const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".fields;
544 const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".field_names;
545 const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".field_names;
546546 try expectEqual(expected_fields.len, actual_fields.len);
547 inline for (expected_fields) |field| {
548 try expectEqual(@field(expected_struct, field.name), @field(actual_struct, field.name));
547 inline for (expected_fields) |field_name| {
548 try expectEqual(@field(expected_struct, field_name), @field(actual_struct, field_name));
549549 }
550550}
551551
552552test "build.zig.zon" {
553553 const build = @import("zon/build.zig.zon");
554554
555 try expectEqual(4, @typeInfo(@TypeOf(build)).@"struct".fields.len);
555 try expectEqual(4, @typeInfo(@TypeOf(build)).@"struct".field_names.len);
556556 try expectEqualStrings("temp", build.name);
557557 try expectEqualStrings("0.0.0", build.version);
558558
559559 const dependencies = build.dependencies;
560 try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
560 try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".field_names.len);
561561
562562 const example_0 = dependencies.example_0;
563 try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
563 try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".field_names.len);
564564 try expectEqualStrings("https://example.com/foo.tar.gz", example_0.url);
565565 try expectEqualStrings("...", example_0.hash);
566566
567567 const example_1 = dependencies.example_1;
568 try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".fields.len);
568 try expectEqual(2, @typeInfo(@TypeOf(dependencies)).@"struct".field_names.len);
569569 try expectEqualStrings("../foo", example_1.path);
570570 try expectEqual(false, example_1.lazy);
571571
test/cases/compile_errors/access_invalid_typeInfo_decl.zig+1-1
......@@ -1,6 +1,6 @@
11pub const A = B;
22export fn foo() void {
3 _ = @typeInfo(@This()).@"struct".decls[0];
3 _ = @typeInfo(@This()).@"struct".decl_names[0];
44}
55
66// error
test/cases/compile_errors/comptime_store_in_comptime_switch_in_runtime_if.zig+2-2
......@@ -7,9 +7,9 @@ pub export fn entry() void {
77
88 comptime var a = 1;
99 const info = @typeInfo(Widget).@"union";
10 inline for (info.fields) |field| {
10 inline for (info.field_types) |field_type| {
1111 if (foo()) {
12 switch (field.type) {
12 switch (field_type) {
1313 u0 => a = 2,
1414 else => unreachable,
1515 }
test/cases/compile_errors/issue_15572_break_on_inline_while.zig+3-3
......@@ -6,8 +6,8 @@ pub const DwarfSection = enum {
66};
77
88pub fn main() void {
9 const section = inline for (@typeInfo(DwarfSection).@"enum".fields) |section| {
10 if (std.mem.eql(u8, section.name, "eh_frame")) break section;
9 const section = inline for (@typeInfo(DwarfSection).@"enum".field_names) |section_name| {
10 if (std.mem.eql(u8, section_name, "eh_frame")) break section_name;
1111 };
1212
1313 _ = section;
......@@ -16,4 +16,4 @@ pub fn main() void {
1616// error
1717// target=x86_64-linux
1818//
19// :9:28: error: incompatible types: 'lang.Type.EnumField' and 'void'
19// :9:28: error: incompatible types: '[:0]const u8' and 'void'
test/cases/compile_errors/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig+1-1
......@@ -7,7 +7,7 @@ export fn foo() void {
77 wrong_type: []u8 = "foo",
88 };
99
10 comptime ignore(@typeInfo(MyStruct).@"struct".fields[0]);
10 comptime ignore(@typeInfo(MyStruct).@"struct".field_names[0]);
1111}
1212
1313// error
test/cases/compile_errors/runtime_index_into_comptime_type_slice.zig+2-3
......@@ -6,12 +6,11 @@ fn getIndex() usize {
66}
77export fn entry() void {
88 const index = getIndex();
9 const field = @typeInfo(Struct).@"struct".fields[index];
9 const field = @typeInfo(Struct).@"struct".field_types[index];
1010 _ = field;
1111}
1212
1313// error
1414//
15// :9:54: error: values of type 'lang.Type.StructField' must be comptime-known, but index value is runtime-known
16// : note: struct requires comptime because of this field
15// :9:59: error: values of type 'type' must be comptime-known, but index value is runtime-known
1716// : note: types are not available at runtime
test/cases/fn_typeinfo_passed_to_comptime_fn.zig+1-1
......@@ -9,7 +9,7 @@ fn someFn(arg: ?*c_int) f64 {
99 return 8;
1010}
1111fn foo(comptime info: std.builtin.Type) !void {
12 try std.testing.expect(info.@"fn".params[0].type.? == ?*c_int);
12 try std.testing.expect(info.@"fn".param_types[0].? == ?*c_int);
1313}
1414
1515// run
test/incremental/add_remove_struct_fields+4-4
......@@ -11,7 +11,7 @@ pub fn main(init: std.process.Init) !void {
1111 };
1212}
1313fn printFieldCount(w: *Writer) Writer.Error!void {
14 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
14 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
1515}
1616fn printOneField(w: *Writer) Writer.Error!void {
1717 const val: S = .{ .x = 100 };
......@@ -34,7 +34,7 @@ pub fn main(init: std.process.Init) !void {
3434 };
3535}
3636fn printFieldCount(w: *Writer) Writer.Error!void {
37 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
37 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
3838}
3939fn printOneField(w: *Writer) Writer.Error!void {
4040 const val: S = .{ .x = 100 };
......@@ -57,7 +57,7 @@ pub fn main(init: std.process.Init) !void {
5757 };
5858}
5959fn printFieldCount(w: *Writer) Writer.Error!void {
60 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
60 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
6161}
6262fn printOneField(w: *Writer) Writer.Error!void {
6363 const val: S = .{ .x = 100 };
......@@ -81,7 +81,7 @@ pub fn main(init: std.process.Init) !void {
8181 };
8282}
8383fn printFieldCount(w: *Writer) Writer.Error!void {
84 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
84 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
8585}
8686fn printOneField(w: *Writer) Writer.Error!void {
8787 //const val: S = .{ .x = 100 };
test/incremental/add_remove_toplevel_fields+4-4
......@@ -12,7 +12,7 @@ pub fn main(init: std.process.Init) !void {
1212 };
1313}
1414fn printFieldCount(w: *Writer) Writer.Error!void {
15 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
15 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
1616}
1717fn printOneField(w: *Writer) Writer.Error!void {
1818 const val: S = .{ .x = 100 };
......@@ -37,7 +37,7 @@ pub fn main(init: std.process.Init) !void {
3737 };
3838}
3939fn printFieldCount(w: *Writer) Writer.Error!void {
40 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
40 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
4141}
4242fn printOneField(w: *Writer) Writer.Error!void {
4343 const val: S = .{ .x = 100 };
......@@ -60,7 +60,7 @@ pub fn main(init: std.process.Init) !void {
6060 };
6161}
6262fn printFieldCount(w: *Writer) Writer.Error!void {
63 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
63 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
6464}
6565fn printOneField(w: *Writer) Writer.Error!void {
6666 const val: S = .{ .x = 100 };
......@@ -84,7 +84,7 @@ pub fn main(init: std.process.Init) !void {
8484 };
8585}
8686fn printFieldCount(w: *Writer) Writer.Error!void {
87 try w.print("{d} ", .{@typeInfo(S).@"struct".fields.len});
87 try w.print("{d} ", .{@typeInfo(S).@"struct".field_names.len});
8888}
8989fn printOneField(w: *Writer) Writer.Error!void {
9090 //const val: S = .{ .x = 100 };
test/incremental/change_union_tag_type+3-3
......@@ -4,7 +4,7 @@ const A = enum(u8) { a };
44const B = enum(u8) { b };
55const Foo = union(A) { a: u8 };
66pub fn main(init: std.process.Init) !void {
7 const field_name = @typeInfo(Foo).@"union".fields[0].name;
7 const field_name = @typeInfo(Foo).@"union".field_names[0];
88 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
99 try stdout_writer.interface.print("{s}\n", .{field_name});
1010}
......@@ -17,7 +17,7 @@ const A = enum(u8) { a };
1717const B = enum(u8) { b };
1818const Foo = union(B) { a: u8 };
1919pub fn main(init: std.process.Init) !void {
20 const field_name = @typeInfo(Foo).@"union".fields[0].name;
20 const field_name = @typeInfo(Foo).@"union".field_names[0];
2121 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
2222 try stdout_writer.interface.print("{s}\n", .{field_name});
2323}
......@@ -31,7 +31,7 @@ const A = enum(u8) { a };
3131const B = enum(u8) { b };
3232const Foo = union(B) { b: u8 };
3333pub fn main(init: std.process.Init) !void {
34 const field_name = @typeInfo(Foo).@"union".fields[0].name;
34 const field_name = @typeInfo(Foo).@"union".field_names[0];
3535 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
3636 try stdout_writer.interface.print("{s}\n", .{field_name});
3737}
test/incremental/do_nothing+2-2
......@@ -7,7 +7,7 @@ pub fn main() void {
77}
88const S = struct { foo: u32, nested: struct { x: u16 } };
99const U = union(enum) { a, b, c: S };
10const E = enum(u8) { a = @typeInfo(U).@"union".fields.len, b = 0, c };
10const E = enum(u8) { a = @typeInfo(U).@"union".field_names.len, b = 0, c };
1111const O = opaque {
1212 comptime {
1313 _ = @as(S, undefined);
......@@ -27,7 +27,7 @@ pub fn main() void {
2727}
2828const S = struct { foo: u32, nested: struct { x: u16 } };
2929const U = union(enum) { a, b, c: S };
30const E = enum(u8) { a = @typeInfo(U).@"union".fields.len, b = 0, c };
30const E = enum(u8) { a = @typeInfo(U).@"union".field_names.len, b = 0, c };
3131const O = opaque {
3232 comptime {
3333 _ = @as(S, undefined);
test/standalone/build.zig+1-2
......@@ -85,8 +85,7 @@ pub fn build(b: *std.Build) void {
8585 if (std.mem.eql(u8, dep_name, "simple")) continue;
8686
8787 const all_pkgs = @import("root").dependencies.packages;
88 inline for (@typeInfo(all_pkgs).@"struct".decls) |decl| {
89 const pkg_hash = decl.name;
88 inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| {
9089 if (std.mem.eql(u8, dep_hash, pkg_hash)) {
9190 const pkg = @field(all_pkgs, pkg_hash);
9291 if (!@hasDecl(pkg, "build_zig")) {
tools/gen_stubs.zig+16-16
......@@ -141,10 +141,10 @@ const Family = enum {
141141 x86,
142142};
143143
144const arches: [@typeInfo(Arch).@"enum".fields.len]Arch = blk: {
145 var result: [@typeInfo(Arch).@"enum".fields.len]Arch = undefined;
146 for (@typeInfo(Arch).@"enum".fields) |field| {
147 const arch: Arch = @enumFromInt(field.value);
144const arches: [@typeInfo(Arch).@"enum".field_names.len]Arch = blk: {
145 var result: [@typeInfo(Arch).@"enum".field_names.len]Arch = undefined;
146 for (@typeInfo(Arch).@"enum".field_values) |field_value| {
147 const arch: Arch = @enumFromInt(field_value);
148148 result[archIndex(arch)] = arch;
149149 }
150150 break :blk result;
......@@ -160,8 +160,8 @@ const MultiSym = struct {
160160
161161 fn isSingleArch(ms: MultiSym) ?Arch {
162162 var result: ?Arch = null;
163 inline for (@typeInfo(Arch).@"enum".fields) |field| {
164 const arch: Arch = @enumFromInt(field.value);
163 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
164 const arch: Arch = @enumFromInt(field_value);
165165 if (ms.present[archIndex(arch)]) {
166166 if (result != null) return null;
167167 result = arch;
......@@ -172,8 +172,8 @@ const MultiSym = struct {
172172
173173 fn isFamily(ms: MultiSym) ?Family {
174174 var result: ?Family = null;
175 inline for (@typeInfo(Arch).@"enum".fields) |field| {
176 const arch: Arch = @enumFromInt(field.value);
175 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
176 const arch: Arch = @enumFromInt(field_value);
177177 if (ms.present[archIndex(arch)]) {
178178 const family = arch.family();
179179 if (result) |r| if (family != r) return null;
......@@ -193,8 +193,8 @@ const MultiSym = struct {
193193 }
194194
195195 fn isTime32Only(ms: MultiSym) bool {
196 inline for (@typeInfo(Arch).@"enum".fields) |field| {
197 const arch: Arch = @enumFromInt(field.value);
196 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
197 const arch: Arch = @enumFromInt(field_value);
198198 if (ms.present[archIndex(arch)] != arch.isTime32()) {
199199 return false;
200200 }
......@@ -233,8 +233,8 @@ const MultiSym = struct {
233233 }
234234
235235 fn isPtrSize(ms: MultiSym, mult: u16) bool {
236 inline for (@typeInfo(Arch).@"enum".fields) |field| {
237 const arch: Arch = @enumFromInt(field.value);
236 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
237 const arch: Arch = @enumFromInt(field_value);
238238 const arch_index = archIndex(arch);
239239 if (ms.present[arch_index] and ms.size[arch_index] != arch.ptrSize() * mult) {
240240 return false;
......@@ -244,8 +244,8 @@ const MultiSym = struct {
244244 }
245245
246246 fn isWeak64(ms: MultiSym) bool {
247 inline for (@typeInfo(Arch).@"enum".fields) |field| {
248 const arch: Arch = @enumFromInt(field.value);
247 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
248 const arch: Arch = @enumFromInt(field_value);
249249 const arch_index = archIndex(arch);
250250 const binding: u4 = switch (arch.ptrSize()) {
251251 4 => std.elf.STB_GLOBAL,
......@@ -260,8 +260,8 @@ const MultiSym = struct {
260260 }
261261
262262 fn isWeakTime64(ms: MultiSym) bool {
263 inline for (@typeInfo(Arch).@"enum".fields) |field| {
264 const arch: Arch = @enumFromInt(field.value);
263 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
264 const arch: Arch = @enumFromInt(field_value);
265265 const arch_index = archIndex(arch);
266266 const binding: u4 = if (arch.isTime32()) std.elf.STB_GLOBAL else std.elf.STB_WEAK;
267267 if (ms.present[arch_index] and ms.binding[arch_index] != binding) {
tools/generate_c_size_and_align_checks.zig+2-2
......@@ -43,8 +43,8 @@ pub fn main(init: std.process.Init) !void {
4343 var buffer: [2000]u8 = undefined;
4444 var stdout_writer = Io.File.stdout().writerStreaming(io, &buffer);
4545 const w = &stdout_writer.interface;
46 inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| {
47 const c_type: std.Target.CType = @enumFromInt(field.value);
46 inline for (@typeInfo(std.Target.CType).@"enum".field_values) |field_value| {
47 const c_type: std.Target.CType = @enumFromInt(field_value);
4848 try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
4949 cName(c_type),
5050 target.cTypeByteSize(c_type),
tools/update_clang_options.zig+3-3
......@@ -660,9 +660,9 @@ pub fn main(init: std.process.Init) !void {
660660
661661 var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(arena);
662662
663 inline for (@typeInfo(cpu_targets).@"struct".decls) |decl| {
664 const Feature = @field(cpu_targets, decl.name).Feature;
665 const all_features = @field(cpu_targets, decl.name).all_features;
663 inline for (@typeInfo(cpu_targets).@"struct".decl_names) |decl_name| {
664 const Feature = @field(cpu_targets, decl_name).Feature;
665 const all_features = @field(cpu_targets, decl_name).all_features;
666666
667667 for (all_features, 0..) |feat, i| {
668668 const llvm_name = feat.llvm_name orelse continue;
tools/update_cpu_features.zig+2-2
......@@ -2436,7 +2436,7 @@ fn processOneTargetInner(io: Io, job: Job) !void {
24362436 try w.print(" @setEvalBranchQuota({d});\n", .{branch_quota});
24372437 }
24382438 try w.writeAll(
2439 \\ const len = @typeInfo(Feature).@"enum".fields.len;
2439 \\ const len = @typeInfo(Feature).@"enum".field_names.len;
24402440 \\ std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
24412441 \\ var result: [len]CpuFeature = undefined;
24422442 \\
......@@ -2505,7 +2505,7 @@ fn processOneTargetInner(io: Io, job: Job) !void {
25052505 \\ const ti = @typeInfo(Feature);
25062506 \\ for (&result, 0..) |*elem, i| {
25072507 \\ elem.index = i;
2508 \\ elem.name = ti.@"enum".fields[i].name;
2508 \\ elem.name = ti.@"enum".field_names[i];
25092509 \\ }
25102510 \\ break :blk result;
25112511 \\};