authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2026-05-07 02:20:16+02:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-27 10:03:51+01:00
log9e80795623aa826ec03d014ccf767ea30156d699
tree99426e15bd7fc1955c72acd3f088b6762eda826f
parent964cc8047e512e9fb58786af4554aef89dfd25df
signaturelock-open Commit is signed but in an unrecognized format.

all: update to use new `std.lang.Type` definitions


204 files changed, 2312 insertions(+), 2310 deletions(-)

doc/langref.html.in+3-3
...@@ -5752,7 +5752,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5752,7 +5752,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5752 {#header_open|@Fn#}5752 {#header_open|@Fn#}
5753 <pre>{#syntax#}@Fn(5753 <pre>{#syntax#}@Fn(
5754 comptime param_types: []const type,5754 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,
5756 comptime ReturnType: type,5756 comptime ReturnType: type,
5757 comptime attrs: std.lang.Type.Fn.Attributes,5757 comptime attrs: std.lang.Type.Fn.Attributes,
5758) type{#endsyntax#}</pre>5758) type{#endsyntax#}</pre>
...@@ -5765,7 +5765,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5765,7 +5765,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5765 comptime BackingInt: ?type,5765 comptime BackingInt: ?type,
5766 comptime field_names: []const []const u8,5766 comptime field_names: []const []const u8,
5767 comptime field_types: *const [field_names.len]type,5767 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,
5769) type{#endsyntax#}</pre>5769) type{#endsyntax#}</pre>
5770 <p>Returns a {#link|struct#} type with the properties specified by the arguments.</p>5770 <p>Returns a {#link|struct#} type with the properties specified by the arguments.</p>
5771 {#header_close#}5771 {#header_close#}
...@@ -5777,7 +5777,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5777,7 +5777,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5777 comptime ArgType: ?type,5777 comptime ArgType: ?type,
5778 comptime field_names: []const []const u8,5778 comptime field_names: []const []const u8,
5779 comptime field_types: *const [field_names.len]type,5779 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,
5781) type{#endsyntax#}</pre>5781) type{#endsyntax#}</pre>
5782 <p>Returns a {#link|union#} type with the properties specified by the arguments.</p>5782 <p>Returns a {#link|union#} type with the properties specified by the arguments.</p>
5783 {#header_close#}5783 {#header_close#}
doc/langref/inline_prong_range.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1fn isFieldOptional(comptime T: type, field_index: usize) !bool {1fn isFieldOptional(comptime T: type, field_index: usize) !bool {
2 const fields = @typeInfo(T).@"struct".fields;2 const field_types = @typeInfo(T).@"struct".field_types;
3 return switch (field_index) {3 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,
5 else => return error.IndexOutOfBounds,5 else => return error.IndexOutOfBounds,
6 };6 };
7}7}
doc/langref/test_enums.zig+2-2
...@@ -102,8 +102,8 @@ test "std.meta.Tag" {...@@ -102,8 +102,8 @@ test "std.meta.Tag" {
102102
103// @typeInfo tells us the field count and the fields names:103// @typeInfo tells us the field count and the fields names:
104test "@typeInfo" {104test "@typeInfo" {
105 try expectEqual(4, @typeInfo(Small).@"enum".fields.len);105 try expectEqual(4, @typeInfo(Small).@"enum".field_names.len);
106 try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two");106 try expectEqualStrings(@typeInfo(Small).@"enum".field_names[1], "two");
107}107}
108108
109// @tagName gives a [:0]const u8 representation of an enum value:109// @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;...@@ -3,7 +3,7 @@ const math = std.math;
3const testing = std.testing;3const testing = std.testing;
44
5test "fn reflection" {5test "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].?);
7 try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);7 try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?);
88
9 try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);9 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) {...@@ -18,12 +18,13 @@ const AnySlice = union(enum) {
1818
19fn withFor(any: AnySlice) usize {19fn withFor(any: AnySlice) usize {
20 const Tag = @typeInfo(AnySlice).@"union".tag_type.?;20 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| {
22 // With `inline for` the function gets generated as23 // With `inline for` the function gets generated as
23 // a series of `if` statements relying on the optimizer24 // a series of `if` statements relying on the optimizer
24 // to convert it to a switch.25 // to convert it to a switch.
25 if (field.value == @intFromEnum(any)) {26 if (field_value == @intFromEnum(any)) {
26 return @field(any, field.name).len;27 return @field(any, field_name).len;
27 }28 }
28 }29 }
29 // When using `inline for` the compiler doesn't know that every30 // 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;...@@ -3,11 +3,11 @@ const expect = std.testing.expect;
3const expectError = std.testing.expectError;3const expectError = std.testing.expectError;
44
5fn isFieldOptional(comptime T: type, field_index: usize) !bool {5fn isFieldOptional(comptime T: type, field_index: usize) !bool {
6 const fields = @typeInfo(T).@"struct".fields;6 const field_types = @typeInfo(T).@"struct".field_types;
7 return switch (field_index) {7 return switch (field_index) {
8 // This prong is analyzed twice with `idx` being a8 // This prong is analyzed twice with `idx` being a
9 // comptime-known value each time.9 // 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,
11 else => return error.IndexOutOfBounds,11 else => return error.IndexOutOfBounds,
12 };12 };
13}13}
doc/langref/test_variable_func_alignment.zig+1-1
...@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;...@@ -3,7 +3,7 @@ const expectEqual = @import("std").testing.expectEqual;
3var foo: u8 align(4) = 100;3var foo: u8 align(4) = 100;
44
5test "global variable alignment" {5test "global variable alignment" {
6 try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment);6 try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.attrs.@"align");
7 try expectEqual(*align(4) u8, @TypeOf(&foo));7 try expectEqual(*align(4) u8, @TypeOf(&foo));
8 const as_pointer_to_array: *align(4) [1]u8 = &foo;8 const as_pointer_to_array: *align(4) [1]u8 = &foo;
9 const as_slice: []align(4) u8 = as_pointer_to_array;9 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;...@@ -5,7 +5,7 @@ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
55
6test "variadic function" {6test "variadic function" {
7 try testing.expectEqual(14, printf("Hello, world!\n"));7 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);
9}9}
1010
11// test11// test
lib/compiler/Maker/ScannedConfig.zig+4-3
...@@ -49,9 +49,10 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {...@@ -49,9 +49,10 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void {
49}49}
5050
51fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: S) !void {51fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: S) !void {
52 inline for (@typeInfo(S).@"struct".fields) |field| {52 const info = @typeInfo(S).@"struct";
53 try s.fieldPrefix(field.name);53 inline for (info.field_names, info.field_types) |field_name, field_type| {
54 try printValue(sc, s.container.serializer, field.type, @field(v, field.name));54 try s.fieldPrefix(field_name);
55 try printValue(sc, s.container.serializer, field_type, @field(v, field_name));
55 }56 }
56}57}
5758
lib/compiler/Maker/Step/FindProgram.zig+2-2
...@@ -113,8 +113,8 @@ fn checkCandidate(...@@ -113,8 +113,8 @@ fn checkCandidate(
113}113}
114114
115fn supportedWindowsProgramExtension(ext: []const u8) bool {115fn supportedWindowsProgramExtension(ext: []const u8) bool {
116 inline for (@typeInfo(std.process.WindowsExtension).@"enum".fields) |field| {116 inline for (@typeInfo(std.process.WindowsExtension).@"enum".field_names) |field_name| {
117 if (std.ascii.eqlIgnoreCase(ext, "." ++ field.name)) return true;117 if (std.ascii.eqlIgnoreCase(ext, "." ++ field_name)) return true;
118 }118 }
119 return false;119 return false;
120}120}
lib/compiler/Maker/Watch/FsEvents.zig+3-2
...@@ -87,8 +87,9 @@ pub fn init(cwd_path: []const u8) error{ OpenFrameworkFailed, MissingCoreService...@@ -87,8 +87,9 @@ pub fn init(cwd_path: []const u8) error{ OpenFrameworkFailed, MissingCoreService
87 errdefer core_services.close();87 errdefer core_services.close();
8888
89 var resolved_symbols: ResolvedSymbols = undefined;89 var resolved_symbols: ResolvedSymbols = undefined;
90 inline for (@typeInfo(ResolvedSymbols).@"struct".fields) |f| {90 const info = @typeInfo(ResolvedSymbols).@"struct";
91 @field(resolved_symbols, f.name) = core_services.lookup(f.type, f.name) orelse return error.MissingCoreServicesSymbol;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;
92 }93 }
9394
94 return .{95 return .{
lib/compiler/aro/aro/Attribute.zig+52-51
...@@ -89,9 +89,9 @@ pub fn requiredArgCount(attr: Tag) u32 {...@@ -89,9 +89,9 @@ pub fn requiredArgCount(attr: Tag) u32 {
89 inline else => |tag| {89 inline else => |tag| {
90 comptime var needed = 0;90 comptime var needed = 0;
91 comptime {91 comptime {
92 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;92 const info = @typeInfo(@field(attributes, @tagName(tag))).@"struct";
93 for (fields) |arg_field| {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;94 if (!mem.eql(u8, arg_field_name, "__name_tok") and @typeInfo(arg_field_type) != .optional) needed += 1;
95 }95 }
96 }96 }
97 return needed;97 return needed;
...@@ -105,9 +105,9 @@ pub fn maxArgCount(attr: Tag) u32 {...@@ -105,9 +105,9 @@ pub fn maxArgCount(attr: Tag) u32 {
105 inline else => |tag| {105 inline else => |tag| {
106 comptime var max = 0;106 comptime var max = 0;
107 comptime {107 comptime {
108 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;108 const field_names = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_names;
109 for (fields) |arg_field| {109 for (field_names) |arg_field_name| {
110 if (!mem.eql(u8, arg_field.name, "__name_tok")) max += 1;110 if (!mem.eql(u8, arg_field_name, "__name_tok")) max += 1;
111 }111 }
112 }112 }
113 return max;113 return max;
...@@ -130,10 +130,10 @@ pub const Formatting = struct {...@@ -130,10 +130,10 @@ pub const Formatting = struct {
130 switch (attr) {130 switch (attr) {
131 .calling_convention => unreachable,131 .calling_convention => unreachable,
132 inline else => |tag| {132 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;135 if (field_types.len == 0) unreachable;
136 const Unwrapped = UnwrapOptional(fields[0].type);136 const Unwrapped = UnwrapOptional(field_types[0]);
137 if (@typeInfo(Unwrapped) != .@"enum") unreachable;137 if (@typeInfo(Unwrapped) != .@"enum") unreachable;
138138
139 return if (Unwrapped.opts.enum_kind == .identifier) "'" else "\"";139 return if (Unwrapped.opts.enum_kind == .identifier) "'" else "\"";
...@@ -147,18 +147,18 @@ pub const Formatting = struct {...@@ -147,18 +147,18 @@ pub const Formatting = struct {
147 switch (attr) {147 switch (attr) {
148 .calling_convention => unreachable,148 .calling_convention => unreachable,
149 inline else => |tag| {149 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;152 if (field_types.len == 0) unreachable;
153 const Unwrapped = UnwrapOptional(fields[0].type);153 const Unwrapped = UnwrapOptional(field_types[0]);
154 if (@typeInfo(Unwrapped) != .@"enum") unreachable;154 if (@typeInfo(Unwrapped) != .@"enum") unreachable;
155155
156 const enum_fields = @typeInfo(Unwrapped).@"enum".fields;156 const enum_field_names = @typeInfo(Unwrapped).@"enum".field_names;
157 const quote = comptime quoteChar(@enumFromInt(@intFromEnum(tag)));157 const quote = comptime quoteChar(@enumFromInt(@intFromEnum(tag)));
158 comptime var values: []const u8 = quote ++ enum_fields[0].name ++ quote;158 comptime var values: []const u8 = quote ++ enum_field_names[0] ++ quote;
159 inline for (enum_fields[1..]) |enum_field| {159 inline for (enum_field_names[1..]) |enum_field_name| {
160 values = values ++ ", ";160 values = values ++ ", ";
161 values = values ++ quote ++ enum_field.name ++ quote;161 values = values ++ quote ++ enum_field_name ++ quote;
162 }162 }
163 return values;163 return values;
164 },164 },
...@@ -171,10 +171,10 @@ pub fn wantsIdentEnum(attr: Tag) bool {...@@ -171,10 +171,10 @@ pub fn wantsIdentEnum(attr: Tag) bool {
171 switch (attr) {171 switch (attr) {
172 .calling_convention => return false,172 .calling_convention => return false,
173 inline else => |tag| {173 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;176 if (field_types.len == 0) return false;
177 const Unwrapped = UnwrapOptional(fields[0].type);177 const Unwrapped = UnwrapOptional(field_types[0]);
178 if (@typeInfo(Unwrapped) != .@"enum") return false;178 if (@typeInfo(Unwrapped) != .@"enum") return false;
179179
180 return Unwrapped.opts.enum_kind == .identifier;180 return Unwrapped.opts.enum_kind == .identifier;
...@@ -185,12 +185,12 @@ pub fn wantsIdentEnum(attr: Tag) bool {...@@ -185,12 +185,12 @@ pub fn wantsIdentEnum(attr: Tag) bool {
185pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Parser) !bool {185pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Parser) !bool {
186 switch (attr) {186 switch (attr) {
187 inline else => |tag| {187 inline else => |tag| {
188 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;188 const info = @typeInfo(@field(attributes, @tagName(tag))).@"struct";
189 if (fields.len == 0) unreachable;189 if (info.field_names.len == 0) unreachable;
190 const Unwrapped = UnwrapOptional(fields[0].type);190 const Unwrapped = UnwrapOptional(info.field_types[0]);
191 if (@typeInfo(Unwrapped) != .@"enum") unreachable;191 if (@typeInfo(Unwrapped) != .@"enum") unreachable;
192 if (std.meta.stringToEnum(Unwrapped, normalize(p.tokSlice(ident)))) |enum_val| {192 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;
194 return false;194 return false;
195 }195 }
196196
...@@ -203,11 +203,11 @@ pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Pa...@@ -203,11 +203,11 @@ pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Pa
203pub fn wantsAlignment(attr: Tag, idx: usize) bool {203pub fn wantsAlignment(attr: Tag, idx: usize) bool {
204 switch (attr) {204 switch (attr) {
205 inline else => |tag| {205 inline else => |tag| {
206 const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;206 const field_types = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_types;
207 if (fields.len == 0) return false;207 if (field_types.len == 0) return false;
208208
209 return switch (idx) {209 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,
211 else => false,211 else => false,
212 };212 };
213 },213 },
...@@ -217,12 +217,12 @@ pub fn wantsAlignment(attr: Tag, idx: usize) bool {...@@ -217,12 +217,12 @@ pub fn wantsAlignment(attr: Tag, idx: usize) bool {
217pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, p: *Parser) !bool {217pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, p: *Parser) !bool {
218 switch (attr) {218 switch (attr) {
219 inline else => |tag| {219 inline else => |tag| {
220 const arg_fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields;220 const arg_info = @typeInfo(@field(attributes, @tagName(tag))).@"struct";
221 if (arg_fields.len == 0) unreachable;221 if (arg_info.field_names.len == 0) unreachable;
222222
223 switch (arg_idx) {223 switch (arg_idx) {
224 inline 0...arg_fields.len - 1 => |arg_i| {224 inline 0...arg_info.field_names.len - 1 => |arg_i| {
225 if (UnwrapOptional(arg_fields[arg_i].type) != Alignment) unreachable;225 if (UnwrapOptional(arg_info.field_types[arg_i]) != Alignment) unreachable;
226226
227 if (!res.val.is(.int, p.comp)) {227 if (!res.val.is(.int, p.comp)) {
228 try p.err(arg_start, .alignas_unavailable, .{});228 try p.err(arg_start, .alignas_unavailable, .{});
...@@ -241,7 +241,7 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa...@@ -241,7 +241,7 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa
241 return true;241 return true;
242 }242 }
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 };
245 return false;245 return false;
246 },246 },
247 else => unreachable,247 else => unreachable,
...@@ -251,8 +251,8 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa...@@ -251,8 +251,8 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa
251}251}
252252
253fn diagnoseField(253fn diagnoseField(
254 comptime decl: ZigType.Declaration,254 comptime decl_name: []const u8,
255 comptime field: ZigType.StructField,255 comptime field_name: []const u8,
256 comptime Wanted: type,256 comptime Wanted: type,
257 arguments: *Arguments,257 arguments: *Arguments,
258 res: Parser.Result,258 res: Parser.Result,
...@@ -283,7 +283,7 @@ fn diagnoseField(...@@ -283,7 +283,7 @@ fn diagnoseField(
283283
284 if (res.val.opt_ref == .none) {284 if (res.val.opt_ref == .none) {
285 if (Wanted == Identifier and node == .decl_ref_expr) {285 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 };
287 return false;287 return false;
288 }288 }
289289
...@@ -294,7 +294,7 @@ fn diagnoseField(...@@ -294,7 +294,7 @@ fn diagnoseField(
294 switch (key) {294 switch (key) {
295 .int => {295 .int => {
296 if (@typeInfo(Wanted) == .int) {296 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 {
298 try p.err(arg_start, .attribute_int_out_of_range, .{res});298 try p.err(arg_start, .attribute_int_out_of_range, .{res});
299 return true;299 return true;
300 };300 };
...@@ -310,20 +310,20 @@ fn diagnoseField(...@@ -310,20 +310,20 @@ fn diagnoseField(
310 .char, .uchar, .schar => {},310 .char, .uchar, .schar => {},
311 else => break :validate,311 else => break :validate,
312 }312 }
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);
314 return false;314 return false;
315 }315 }
316316
317 try p.err(arg_start, .attribute_requires_string, .{decl.name});317 try p.err(arg_start, .attribute_requires_string, .{decl_name});
318 return true;318 return true;
319 } else if (@typeInfo(Wanted) == .@"enum" and @hasDecl(Wanted, "opts") and Wanted.opts.enum_kind == .string) {319 } else if (@typeInfo(Wanted) == .@"enum" and @hasDecl(Wanted, "opts") and Wanted.opts.enum_kind == .string) {
320 const str = bytes[0 .. bytes.len - 1];320 const str = bytes[0 .. bytes.len - 1];
321 if (std.meta.stringToEnum(Wanted, str)) |enum_val| {321 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;
323 return false;323 return false;
324 }324 }
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)) });
327 return true;327 return true;
328 }328 }
329 },329 },
...@@ -344,17 +344,18 @@ fn diagnoseField(...@@ -344,17 +344,18 @@ fn diagnoseField(
344pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool {344pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool {
345 switch (attr) {345 switch (attr) {
346 inline else => |tag| {346 inline else => |tag| {
347 const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];347 const decl_name = @typeInfo(attributes).@"struct".decl_names[@intFromEnum(tag)];
348 const max_arg_count = comptime maxArgCount(tag);348 const max_arg_count = comptime maxArgCount(tag);
349 if (arg_idx >= max_arg_count) {349 if (arg_idx >= max_arg_count) {
350 try p.err(arg_start, .attribute_too_many_args, .{ @tagName(attr), max_arg_count });350 try p.err(arg_start, .attribute_too_many_args, .{ @tagName(attr), max_arg_count });
351 return true;351 return true;
352 }352 }
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;
355 switch (arg_idx) {356 switch (arg_idx) {
356 inline 0...arg_fields.len - 1 => |arg_i| {357 inline 0...arg_field_names.len - 1 => |arg_i| {
357 return diagnoseField(decl, arg_fields[arg_i], UnwrapOptional(arg_fields[arg_i].type), arguments, res, arg_start, node, p);358 return diagnoseField(decl_name, arg_field_names[arg_i], UnwrapOptional(arg_field_types[arg_i]), arguments, res, arg_start, node, p);
358 },359 },
359 else => unreachable,360 else => unreachable,
360 }361 }
...@@ -722,20 +723,20 @@ const attributes = struct {...@@ -722,20 +723,20 @@ const attributes = struct {
722pub const Tag = std.meta.DeclEnum(attributes);723pub const Tag = std.meta.DeclEnum(attributes);
723724
724pub const Arguments = blk: {725pub const Arguments = blk: {
725 const decls = @typeInfo(attributes).@"struct".decls;726 const decl_names = @typeInfo(attributes).@"struct".decl_names;
726 var names: [decls.len][]const u8 = undefined;727 var names: [decl_names.len][]const u8 = undefined;
727 var types: [decls.len]type = undefined;728 var types: [decl_names.len]type = undefined;
728 for (decls, &names, &types) |decl, *name, *T| {729 for (decl_names, &names, &types) |decl_name, *name, *T| {
729 name.* = decl.name;730 name.* = decl_name;
730 T.* = @field(attributes, decl.name);731 T.* = @field(attributes, decl_name);
731 }732 }
732733
733 break :blk @Union(.auto, null, &names, &types, &@splat(.{}));734 break :blk @Union(.auto, null, &names, &types, &@splat(.{}));
734};735};
735736
736pub fn ArgumentsForTag(comptime tag: Tag) type {737pub fn ArgumentsForTag(comptime tag: Tag) type {
737 const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];738 const decl_name = @typeInfo(attributes).@"struct".decl_names[@intFromEnum(tag)];
738 return @field(attributes, decl.name);739 return @field(attributes, decl_name);
739}740}
740741
741pub fn initArguments(tag: Tag, name_tok: TokenIndex) Arguments {742pub fn initArguments(tag: Tag, name_tok: TokenIndex) Arguments {
lib/compiler/aro/aro/Compilation.zig+5-5
...@@ -78,12 +78,12 @@ pub const Environment = struct {...@@ -78,12 +78,12 @@ pub const Environment = struct {
78 pub fn loadAll(environ_map: *const std.process.Environ.Map) Environment {78 pub fn loadAll(environ_map: *const std.process.Environ.Map) Environment {
79 var env: Environment = .{};79 var env: Environment = .{};
8080
81 inline for (@typeInfo(@TypeOf(env)).@"struct".fields) |field| {81 inline for (@typeInfo(@TypeOf(env)).@"struct".field_names) |field_name| {
82 std.debug.assert(@field(env, field.name) == null);82 std.debug.assert(@field(env, field_name) == null);
8383
84 var env_var_buf: [field.name.len]u8 = undefined;84 var env_var_buf: [field_name.len]u8 = undefined;
85 const env_var_name = std.ascii.upperString(&env_var_buf, field.name);85 const env_var_name = std.ascii.upperString(&env_var_buf, field_name);
86 @field(env, field.name) = environ_map.get(env_var_name);86 @field(env, field_name) = environ_map.get(env_var_name);
87 }87 }
88 return env;88 return env;
89 }89 }
lib/compiler/aro/aro/Diagnostics.zig+7-7
...@@ -333,8 +333,8 @@ pub fn deinit(d: *Diagnostics) void {...@@ -333,8 +333,8 @@ pub fn deinit(d: *Diagnostics) void {
333/// Used by the __has_warning builtin macro.333/// Used by the __has_warning builtin macro.
334pub fn warningExists(name: []const u8) bool {334pub fn warningExists(name: []const u8) bool {
335 if (std.mem.eql(u8, name, "pedantic")) return true;335 if (std.mem.eql(u8, name, "pedantic")) return true;
336 inline for (comptime std.meta.declarations(Option)) |group| {336 inline for (comptime std.meta.declarations(Option)) |group_name| {
337 if (std.mem.eql(u8, name, group.name)) return true;337 if (std.mem.eql(u8, name, group_name)) return true;
338 }338 }
339 return std.meta.stringToEnum(Option, name) != null;339 return std.meta.stringToEnum(Option, name) != null;
340}340}
...@@ -349,9 +349,9 @@ pub fn set(d: *Diagnostics, name: []const u8, to: Message.Kind) Compilation.Erro...@@ -349,9 +349,9 @@ pub fn set(d: *Diagnostics, name: []const u8, to: Message.Kind) Compilation.Erro
349 return;349 return;
350 }350 }
351351
352 inline for (comptime std.meta.declarations(Option)) |group| {352 inline for (comptime std.meta.declarations(Option)) |group_name| {
353 if (std.mem.eql(u8, name, group.name)) {353 if (std.mem.eql(u8, name, group_name)) {
354 for (@field(Option, group.name)) |option| {354 for (@field(Option, group_name)) |option| {
355 d.state.options.put(option, to);355 d.state.options.put(option, to);
356 }356 }
357 return;357 return;
...@@ -494,8 +494,8 @@ pub fn addWithLocation(...@@ -494,8 +494,8 @@ pub fn addWithLocation(
494494
495pub fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) std.Io.Writer.Error!void {495pub fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) std.Io.Writer.Error!void {
496 var i: usize = 0;496 var i: usize = 0;
497 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {497 inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| {
498 const arg = @field(args, arg_info.name);498 const arg = @field(args, arg_name);
499 i += switch (@TypeOf(arg)) {499 i += switch (@TypeOf(arg)) {
500 []const u8 => try formatString(w, fmt[i..], arg),500 []const u8 => try formatString(w, fmt[i..], arg),
501 else => switch (@typeInfo(@TypeOf(arg))) {501 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)...@@ -456,8 +456,8 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
456456
457fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {457fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {
458 var i: usize = 0;458 var i: usize = 0;
459 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {459 inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| {
460 const arg = @field(args, arg_info.name);460 const arg = @field(args, arg_name);
461 i += switch (@TypeOf(arg)) {461 i += switch (@TypeOf(arg)) {
462 []const u8 => try Diagnostics.formatString(w, fmt[i..], arg),462 []const u8 => try Diagnostics.formatString(w, fmt[i..], arg),
463 Tree.Token.Id => try formatTokenId(w, fmt[i..], arg),463 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 {...@@ -3048,25 +3048,25 @@ fn dumpAttribute(tree: *const Tree, attr: Attribute, w: *std.Io.Writer) !void {
3048 switch (attr.tag) {3048 switch (attr.tag) {
3049 inline else => |tag| {3049 inline else => |tag| {
3050 const args = @field(attr.args, @tagName(tag));3050 const args = @field(attr.args, @tagName(tag));
3051 const fields = @typeInfo(@TypeOf(args)).@"struct".fields;3051 const args_info = @typeInfo(@TypeOf(args)).@"struct";
3052 if (fields.len == 0) {3052 if (args_info.field_names.len == 0) {
3053 try w.writeByte('\n');3053 try w.writeByte('\n');
3054 return;3054 return;
3055 }3055 }
3056 try w.writeByte(' ');3056 try w.writeByte(' ');
3057 inline for (fields, 0..) |f, i| {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;3058 if (comptime std.mem.eql(u8, f_name, "__name_tok")) continue;
3059 if (i != 0) {3059 if (i != 0) {
3060 try w.writeAll(", ");3060 try w.writeAll(", ");
3061 }3061 }
3062 try w.writeAll(f.name);3062 try w.writeAll(f_name);
3063 try w.writeAll(": ");3063 try w.writeAll(": ");
3064 switch (f.type) {3064 switch (f_type) {
3065 Interner.Ref => try w.print("\"{s}\"", .{tree.interner.get(@field(args, f.name)).bytes}),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}),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)) {3067 else => switch (@typeInfo(f_type)) {
3068 .@"enum" => try w.writeAll(@tagName(@field(args, f.name))),3068 .@"enum" => try w.writeAll(@tagName(@field(args, f_name))),
3069 else => try w.print("{any}", .{@field(args, f.name)}),3069 else => try w.print("{any}", .{@field(args, f_name)}),
3070 },3070 },
3071 }3071 }
3072 }3072 }
lib/compiler/aro/aro/features.zig+4-4
...@@ -46,8 +46,8 @@ pub fn hasFeature(comp: *Compilation, ext: []const u8) bool {...@@ -46,8 +46,8 @@ pub fn hasFeature(comp: *Compilation, ext: []const u8) bool {
46 .c_thread_local = comp.langopts.standard.atLeast(.c11) and comp.target.isTlsSupported(),46 .c_thread_local = comp.langopts.standard.atLeast(.c11) and comp.target.isTlsSupported(),
47 .bounds_attributes = comp.langopts.bounds_safety == .clang,47 .bounds_attributes = comp.langopts.bounds_safety == .clang,
48 };48 };
49 inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {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);50 if (std.mem.eql(u8, f_name, ext)) return @field(list, f_name);
51 }51 }
52 return false;52 return false;
53}53}
...@@ -70,8 +70,8 @@ pub fn hasExtension(comp: *Compilation, ext: []const u8) bool {...@@ -70,8 +70,8 @@ pub fn hasExtension(comp: *Compilation, ext: []const u8) bool {
70 .matrix_types = false, // TODO70 .matrix_types = false, // TODO
71 .matrix_types_scalar_division = false, // TODO71 .matrix_types_scalar_division = false, // TODO
72 };72 };
73 inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {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);74 if (std.mem.eql(u8, f_name, ext)) return @field(list, f_name);
75 }75 }
76 return false;76 return false;
77}77}
lib/compiler/aro/aro/text_literal.zig+2-2
...@@ -335,8 +335,8 @@ pub const Parser = struct {...@@ -335,8 +335,8 @@ pub const Parser = struct {
335335
336 fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {336 fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {
337 var i: usize = 0;337 var i: usize = 0;
338 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {338 inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| {
339 const arg = @field(args, arg_info.name);339 const arg = @field(args, arg_name);
340 i += switch (@TypeOf(arg)) {340 i += switch (@TypeOf(arg)) {
341 []const u8 => try Diagnostics.formatString(w, fmt[i..], arg),341 []const u8 => try Diagnostics.formatString(w, fmt[i..], arg),
342 Ascii => try arg.format(w, fmt[i..]),342 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 {...@@ -733,7 +733,7 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
733 });733 });
734 },734 },
735 .record_ty => |elems| {735 .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 +
737 elems.len);737 elems.len);
738 i.items.appendAssumeCapacity(.{738 i.items.appendAssumeCapacity(.{
739 .tag = .record_ty,739 .tag = .record_ty,
...@@ -755,18 +755,19 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {...@@ -755,18 +755,19 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
755}755}
756756
757fn addExtra(i: *Interner, gpa: Allocator, extra: anytype) Allocator.Error!u32 {757fn addExtra(i: *Interner, gpa: Allocator, extra: anytype) Allocator.Error!u32 {
758 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;758 const field_count = @typeInfo(@TypeOf(extra)).@"struct".field_names.len;
759 try i.extra.ensureUnusedCapacity(gpa, fields.len);759 try i.extra.ensureUnusedCapacity(gpa, field_count);
760 return i.addExtraAssumeCapacity(extra);760 return i.addExtraAssumeCapacity(extra);
761}761}
762762
763fn addExtraAssumeCapacity(i: *Interner, extra: anytype) u32 {763fn addExtraAssumeCapacity(i: *Interner, extra: anytype) u32 {
764 const result = @as(u32, @intCast(i.extra.items.len));764 const result = @as(u32, @intCast(i.extra.items.len));
765 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {765 const info = @typeInfo(@TypeOf(extra)).@"struct";
766 i.extra.appendAssumeCapacity(switch (field.type) {766 inline for (info.field_names, info.field_types) |field_name, field_type| {
767 Ref => @intFromEnum(@field(extra, field.name)),767 i.extra.appendAssumeCapacity(switch (field_type) {
768 u32 => @field(extra, field.name),768 Ref => @intFromEnum(@field(extra, field_name)),
769 else => @compileError("bad field type: " ++ @typeName(field.type)),769 u32 => @field(extra, field_name),
770 else => @compileError("bad field type: " ++ @typeName(field_type)),
770 });771 });
771 }772 }
772 return result;773 return result;
...@@ -891,17 +892,17 @@ fn extraData(i: *const Interner, comptime T: type, index: usize) T {...@@ -891,17 +892,17 @@ fn extraData(i: *const Interner, comptime T: type, index: usize) T {
891892
892fn extraDataTrail(i: *const Interner, comptime T: type, index: usize) struct { data: T, end: u32 } {893fn extraDataTrail(i: *const Interner, comptime T: type, index: usize) struct { data: T, end: u32 } {
893 var result: T = undefined;894 var result: T = undefined;
894 const fields = @typeInfo(T).@"struct".fields;895 const info = @typeInfo(T).@"struct";
895 inline for (fields, 0..) |field, field_i| {896 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, field_i| {
896 const int32 = i.extra.items[field_i + index];897 const int32 = i.extra.items[field_i + index];
897 @field(result, field.name) = switch (field.type) {898 @field(result, field_name) = switch (field_type) {
898 Ref => @enumFromInt(int32),899 Ref => @enumFromInt(int32),
899 u32 => int32,900 u32 => int32,
900 else => @compileError("bad field type: " ++ @typeName(field.type)),901 else => @compileError("bad field type: " ++ @typeName(field_type)),
901 };902 };
902 }903 }
903 return .{904 return .{
904 .data = result,905 .data = result,
905 .end = @intCast(index + fields.len),906 .end = @intCast(index + info.field_names.len),
906 };907 };
907}908}
lib/compiler/configurer.zig+2-2
...@@ -601,8 +601,8 @@ const Serialize = struct {...@@ -601,8 +601,8 @@ const Serialize = struct {
601 dest_module.* = try addModule(s, src_module);601 dest_module.* = try addModule(s, src_module);
602 }602 }
603603
604 comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".fields[2].name, "import_table"));604 comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".field_names[2], "import_table"));
605 comptime assert(@typeInfo(Configuration.Module).@"struct".fields[2].type == Configuration.ImportTable.Index);605 comptime assert(@typeInfo(Configuration.Module).@"struct".field_types[2] == Configuration.ImportTable.Index);
606 assert(wc.extra.items[@intFromEnum(module_index) + 2] == @intFromEnum(Configuration.ImportTable.Index.invalid));606 assert(wc.extra.items[@intFromEnum(module_index) + 2] == @intFromEnum(Configuration.ImportTable.Index.invalid));
607 const import_table_index = try wc.addDeduped(Configuration.ImportTable, .{607 const import_table_index = try wc.addDeduped(Configuration.ImportTable, .{
608 .imports = .{ .mal = imports },608 .imports = .{ .mal = imports },
lib/compiler/resinator/bmp.zig+3-2
...@@ -241,8 +241,9 @@ pub const Compression = enum(u32) {...@@ -241,8 +241,9 @@ pub const Compression = enum(u32) {
241};241};
242242
243fn structFieldsLittleToNative(comptime T: type, x: *T) void {243fn structFieldsLittleToNative(comptime T: type, x: *T) void {
244 inline for (@typeInfo(T).@"struct".fields) |field| {244 const info = @typeInfo(T).@"struct";
245 @field(x, field.name) = std.mem.littleToNative(field.type, @field(x, field.name));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));
246 }247 }
247}248}
248249
lib/compiler/resinator/code_pages.zig+14-12
...@@ -178,19 +178,20 @@ pub const UnsupportedCodePage = enum(u16) {...@@ -178,19 +178,20 @@ pub const UnsupportedCodePage = enum(u16) {
178};178};
179179
180pub const CodePage = blk: {180pub const CodePage = blk: {
181 const fields = @typeInfo(SupportedCodePage).@"enum".fields ++ @typeInfo(UnsupportedCodePage).@"enum".fields;181 const field_names = @typeInfo(SupportedCodePage).@"enum".field_names ++ @typeInfo(UnsupportedCodePage).@"enum".field_names;
182 var field_names: [fields.len][]const u8 = undefined;182 const field_values = @typeInfo(SupportedCodePage).@"enum".field_values ++ @typeInfo(UnsupportedCodePage).@"enum".field_values;
183 var field_values: [fields.len]u16 = undefined;183 var cp_field_names: [field_names.len][]const u8 = undefined;
184 for (fields, &field_names, &field_values) |field, *name, *val| {184 var cp_field_values: [field_names.len]u16 = undefined;
185 name.* = field.name;185 for (field_names, field_values, &cp_field_names, &cp_field_values) |field_name, field_value, *name, *val| {
186 val.* = field.value;186 name.* = field_name;
187 val.* = field_value;
187 }188 }
188 break :blk @Enum(u16, .exhaustive, &field_names, &field_values);189 break :blk @Enum(u16, .exhaustive, &cp_field_names, &cp_field_values);
189};190};
190191
191pub fn isSupported(code_page: CodePage) bool {192pub fn isSupported(code_page: CodePage) bool {
192 inline for (@typeInfo(SupportedCodePage).@"enum".fields) |enumField| {193 inline for (@typeInfo(SupportedCodePage).@"enum".field_names) |field_name| {
193 if (@intFromEnum(code_page) == @intFromEnum(@field(SupportedCodePage, enumField.name))) {194 if (@intFromEnum(code_page) == @intFromEnum(@field(SupportedCodePage, field_name))) {
194 return true;195 return true;
195 }196 }
196 }197 }
...@@ -200,9 +201,10 @@ pub fn isSupported(code_page: CodePage) bool {...@@ -200,9 +201,10 @@ pub fn isSupported(code_page: CodePage) bool {
200pub fn getByIdentifier(identifier: u16) !CodePage {201pub fn getByIdentifier(identifier: u16) !CodePage {
201 // There's probably a more efficient way to do this (e.g. ComptimeHashMap?) but202 // There's probably a more efficient way to do this (e.g. ComptimeHashMap?) but
202 // this should be fine, especially since this function likely won't be called much.203 // this should be fine, especially since this function likely won't be called much.
203 inline for (@typeInfo(CodePage).@"enum".fields) |enumField| {204 const info = @typeInfo(CodePage).@"enum";
204 if (identifier == enumField.value) {205 inline for (info.field_names, info.field_values) |field_name, field_value| {
205 return @field(CodePage, enumField.name);206 if (identifier == field_value) {
207 return @field(CodePage, field_name);
206 }208 }
207 }209 }
208 return error.InvalidCodePage;210 return error.InvalidCodePage;
lib/compiler/resinator/cvtres.zig+11-10
...@@ -1054,17 +1054,18 @@ pub const supported_targets = struct {...@@ -1054,17 +1054,18 @@ pub const supported_targets = struct {
1054 .ebc,1054 .ebc,
1055 };1055 };
1056 comptime {1056 comptime {
1057 for (@typeInfo(Arch).@"enum".fields) |enum_field| {1057 const info = @typeInfo(Arch).@"enum";
1058 _ = std.mem.indexOfScalar(Arch, ordered_for_display, @enumFromInt(enum_field.value)) orelse {1058 for (info.field_names, info.field_values) |field_name, field_value| {
1059 @compileError(std.fmt.comptimePrint("'{s}' missing from ordered_for_display", .{enum_field.name}));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}));
1060 };1061 };
1061 }1062 }
1062 }1063 }
10631064
1064 pub const longest_name = blk: {1065 pub const longest_name = blk: {
1065 var len = 0;1066 var len = 0;
1066 for (@typeInfo(Arch).@"enum".fields) |field| {1067 for (@typeInfo(Arch).@"enum".field_names) |field_name| {
1067 if (field.name.len > len) len = field.name.len;1068 if (field_name.len > len) len = field_name.len;
1068 }1069 }
1069 break :blk len;1070 break :blk len;
1070 };1071 };
...@@ -1106,14 +1107,14 @@ pub const supported_targets = struct {...@@ -1106,14 +1107,14 @@ pub const supported_targets = struct {
1106 // Enforce two things:1107 // Enforce two things:
1107 // 1. Arch enum field names are all lowercase (necessary for how fromStringIgnoreCase is implemented)1108 // 1. Arch enum field names are all lowercase (necessary for how fromStringIgnoreCase is implemented)
1108 // 2. All enum fields in Arch have an associated RVA relocation type when converted to a coff.IMAGE.FILE.MACHINE1109 // 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 for (@typeInfo(Arch).@"enum".field_names) |field_name| {
1110 const all_lower = all_lower: for (enum_field.name) |c| {1111 const all_lower = all_lower: for (field_name) |c| {
1111 if (std.ascii.isUpper(c)) break :all_lower false;1112 if (std.ascii.isUpper(c)) break :all_lower false;
1112 } else break :all_lower true;1113 } else break :all_lower true;
1113 if (!all_lower) @compileError(std.fmt.comptimePrint("Arch field is not all lowercase: {s}", .{enum_field.name}));1114 if (!all_lower) @compileError(std.fmt.comptimePrint("Arch field is not all lowercase: {s}", .{field_name}));
1114 const coff_machine = @field(Arch, enum_field.name).toCoffMachineType();1115 const coff_machine = @field(Arch, field_name).toCoffMachineType();
1115 _ = rvaRelocationTypeIndicator(coff_machine) orelse {1116 _ = 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}));
1117 };1118 };
1118 }1119 }
1119 }1120 }
lib/compiler/resinator/errors.zig+18-22
...@@ -145,8 +145,8 @@ pub const ErrorDetails = struct {...@@ -145,8 +145,8 @@ pub const ErrorDetails = struct {
145145
146 comptime {146 comptime {
147 // all fields in the extra union should be 32 bits or less147 // all fields in the extra union should be 32 bits or less
148 for (std.meta.fields(Extra)) |field| {148 for (std.meta.fieldTypes(Extra)) |field_type| {
149 std.debug.assert(@bitSizeOf(field.type) <= 32);149 std.debug.assert(@bitSizeOf(field_type) <= 32);
150 }150 }
151 }151 }
152152
...@@ -257,18 +257,18 @@ pub const ErrorDetails = struct {...@@ -257,18 +257,18 @@ pub const ErrorDetails = struct {
257257
258 pub fn writeCommaSeparated(self: ExpectedTypes, writer: *std.Io.Writer) !void {258 pub fn writeCommaSeparated(self: ExpectedTypes, writer: *std.Io.Writer) !void {
259 const struct_info = @typeInfo(ExpectedTypes).@"struct";259 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;
261 const num_padding_bits = @bitSizeOf(ExpectedTypes) - num_real_fields;261 const num_padding_bits = @bitSizeOf(ExpectedTypes) - num_real_fields;
262 const mask = std.math.maxInt(struct_info.backing_integer.?) >> num_padding_bits;262 const mask = std.math.maxInt(struct_info.backing_integer.?) >> num_padding_bits;
263 const relevant_bits_only = @as(struct_info.backing_integer.?, @bitCast(self)) & mask;263 const relevant_bits_only = @as(struct_info.backing_integer.?, @bitCast(self)) & mask;
264 const num_set_bits = @popCount(relevant_bits_only);264 const num_set_bits = @popCount(relevant_bits_only);
265265
266 var i: usize = 0;266 var i: usize = 0;
267 inline for (struct_info.fields) |field_info| {267 inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| {
268 if (field_info.type != bool) continue;268 if (field_type != bool) continue;
269 if (i == num_set_bits) return;269 if (i == num_set_bits) return;
270 if (@field(self, field_info.name)) {270 if (@field(self, field_name)) {
271 try writer.writeAll(strings.get(field_info.name).?);271 try writer.writeAll(strings.get(field_name).?);
272 i += 1;272 i += 1;
273 if (num_set_bits > 2 and i != num_set_bits) {273 if (num_set_bits > 2 and i != num_set_bits) {
274 try writer.writeAll(", ");274 try writer.writeAll(", ");
...@@ -857,24 +857,20 @@ pub const ErrorDetails = struct {...@@ -857,24 +857,20 @@ pub const ErrorDetails = struct {
857857
858/// Convenience struct only useful when the code page can be inferred from the token858/// Convenience struct only useful when the code page can be inferred from the token
859pub const ErrorDetailsWithoutCodePage = blk: {859pub const ErrorDetailsWithoutCodePage = blk: {
860 const details_info = @typeInfo(ErrorDetails);860 const details_info = @typeInfo(ErrorDetails).@"struct";
861 const fields = details_info.@"struct".fields;861 const field_count = details_info.field_names.len;
862 var field_names: [fields.len - 1][]const u8 = undefined;862 var field_names: [field_count - 1][]const u8 = undefined;
863 var field_types: [fields.len - 1]type = undefined;863 var field_types: [field_count - 1]type = undefined;
864 var field_attrs: [fields.len - 1]std.builtin.Type.StructField.Attributes = undefined;864 var field_attrs: [field_count - 1]std.builtin.Type.Struct.FieldAttributes = undefined;
865 var i: usize = 0;865 var i: usize = 0;
866 for (fields) |field| {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;867 if (std.mem.eql(u8, field_name, "code_page")) continue;
868 field_names[i] = field.name;868 field_names[i] = field_name;
869 field_types[i] = field.type;869 field_types[i] = field_type;
870 field_attrs[i] = .{870 field_attrs[i] = field_attr;
871 .@"comptime" = field.is_comptime,
872 .@"align" = field.alignment,
873 .default_value_ptr = field.default_value_ptr,
874 };
875 i += 1;871 i += 1;
876 }872 }
877 std.debug.assert(i == fields.len - 1);873 std.debug.assert(i == field_count - 1);
878 break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);874 break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
879};875};
880876
lib/compiler/resinator/lang.zig+7-7
...@@ -87,8 +87,8 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId {...@@ -87,8 +87,8 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId {
87 if (parsed.multiple_suffixes) return null;87 if (parsed.multiple_suffixes) return null;
88 const longest_known_tag = comptime blk: {88 const longest_known_tag = comptime blk: {
89 var len = 0;89 var len = 0;
90 for (@typeInfo(LanguageId).@"enum".fields) |field| {90 for (@typeInfo(LanguageId).@"enum".field_names) |field_name| {
91 if (field.name.len > len) len = field.name.len;91 if (field_name.len > len) len = field_name.len;
92 }92 }
93 break :blk len;93 break :blk len;
94 };94 };
...@@ -120,13 +120,13 @@ test tagToId {...@@ -120,13 +120,13 @@ test tagToId {
120120
121test "exhaustive tagToId" {121test "exhaustive tagToId" {
122 @setEvalBranchQuota(2000);122 @setEvalBranchQuota(2000);
123 inline for (@typeInfo(LanguageId).@"enum".fields) |field| {123 inline for (@typeInfo(LanguageId).@"enum".field_names) |field_name| {
124 const id = tagToId(field.name) catch |err| {124 const id = tagToId(field_name) catch |err| {
125 std.debug.print("tag: {s}\n", .{field.name});125 std.debug.print("tag: {s}\n", .{field_name});
126 return err;126 return err;
127 };127 };
128 try std.testing.expectEqual(@field(LanguageId, field.name), id orelse {128 try std.testing.expectEqual(@field(LanguageId, field_name), id orelse {
129 std.debug.print("tag: {s}, got null\n", .{field.name});129 std.debug.print("tag: {s}, got null\n", .{field_name});
130 return error.TestExpectedEqual;130 return error.TestExpectedEqual;
131 });131 });
132 }132 }
lib/compiler/resinator/parse.zig+1-1
...@@ -137,7 +137,7 @@ pub const Parser = struct {...@@ -137,7 +137,7 @@ pub const Parser = struct {
137 fn parseOptionalStatements(self: *Self, resource: ResourceType) ![]*Node {137 fn parseOptionalStatements(self: *Self, resource: ResourceType) ![]*Node {
138 var optional_statements: std.ArrayList(*Node) = .empty;138 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;
141 var statement_type_has_duplicates: [num_statement_types]bool = @splat(false);141 var statement_type_has_duplicates: [num_statement_types]bool = @splat(false);
142 var last_statement_per_type: [num_statement_types]?*Node = @splat(null);142 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 {...@@ -925,18 +925,18 @@ const Context = struct {
925 }925 }
926926
927 fn addExtra(c: *Context, extra: anytype) Allocator.Error!std.zig.Ast.ExtraIndex {927 fn addExtra(c: *Context, extra: anytype) Allocator.Error!std.zig.Ast.ExtraIndex {
928 const fields = std.meta.fields(@TypeOf(extra));928 const info = @typeInfo(@TypeOf(extra)).@"struct";
929 try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len);929 try c.extra_data.ensureUnusedCapacity(c.gpa, info.field_names.len);
930 const result: std.zig.Ast.ExtraIndex = @enumFromInt(c.extra_data.items.len);930 const result: std.zig.Ast.ExtraIndex = @enumFromInt(c.extra_data.items.len);
931 inline for (fields) |field| {931 inline for (info.field_names, info.field_types) |field_name, field_type| {
932 const data: u32 = switch (field.type) {932 const data: u32 = switch (field_type) {
933 NodeIndex,933 NodeIndex,
934 std.zig.Ast.Node.OptionalIndex,934 std.zig.Ast.Node.OptionalIndex,
935 std.zig.Ast.OptionalTokenIndex,935 std.zig.Ast.OptionalTokenIndex,
936 std.zig.Ast.ExtraIndex,936 std.zig.Ast.ExtraIndex,
937 => @intFromEnum(@field(extra, field.name)),937 => @intFromEnum(@field(extra, field_name)),
938 TokenIndex,938 TokenIndex,
939 => @field(extra, field.name),939 => @field(extra, field_name),
940 else => @compileError("unexpected field type"),940 else => @compileError("unexpected field type"),
941 };941 };
942 c.extra_data.appendAssumeCapacity(data);942 c.extra_data.appendAssumeCapacity(data);
lib/docs/wasm/markdown/Document.zig+3-3
...@@ -170,11 +170,11 @@ pub fn ExtraData(comptime T: type) type {...@@ -170,11 +170,11 @@ pub fn ExtraData(comptime T: type) type {
170}170}
171171
172pub fn extraData(doc: Document, comptime T: type, index: ExtraIndex) ExtraData(T) {172pub fn extraData(doc: Document, comptime T: type, index: ExtraIndex) ExtraData(T) {
173 const fields = @typeInfo(T).@"struct".fields;173 const info = @typeInfo(T).@"struct";
174 var i: usize = @intFromEnum(index);174 var i: usize = @intFromEnum(index);
175 var result: T = undefined;175 var result: T = undefined;
176 inline for (fields) |field| {176 inline for (info.field_names, info.field_types) |field_name, field_type| {
177 @field(result, field.name) = switch (field.type) {177 @field(result, field_name) = switch (field_type) {
178 u32 => doc.extra[i],178 u32 => doc.extra[i],
179 else => @compileError("bad field type"),179 else => @compileError("bad field type"),
180 };180 };
lib/docs/wasm/markdown/Parser.zig+3-3
...@@ -1574,11 +1574,11 @@ fn parseInlines(p: *Parser, content: []const u8) !ExtraIndex {...@@ -1574,11 +1574,11 @@ fn parseInlines(p: *Parser, content: []const u8) !ExtraIndex {
1574}1574}
15751575
1576pub fn extraData(p: Parser, comptime T: type, index: ExtraIndex) ExtraData(T) {1576pub fn extraData(p: Parser, comptime T: type, index: ExtraIndex) ExtraData(T) {
1577 const fields = @typeInfo(T).@"struct".fields;1577 const info = @typeInfo(T).@"struct";
1578 var i: usize = @intFromEnum(index);1578 var i: usize = @intFromEnum(index);
1579 var result: T = undefined;1579 var result: T = undefined;
1580 inline for (fields) |field| {1580 inline for (info.field_names, info.field_types) |field_name, field_type| {
1581 @field(result, field.name) = switch (field.type) {1581 @field(result, field_name) = switch (field_type) {
1582 u32 => p.extra.items[i],1582 u32 => p.extra.items[i],
1583 else => @compileError("bad field type"),1583 else => @compileError("bad field type"),
1584 };1584 };
lib/std/Build.zig+52-53
...@@ -389,9 +389,10 @@ fn createChild(...@@ -389,9 +389,10 @@ fn createChild(
389389
390fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap {390fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap {
391 var map = UserInputOptionsMap.init(arena);391 var map = UserInputOptionsMap.init(arena);
392 inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| {392 const args_info = @typeInfo(@TypeOf(args)).@"struct";
393 if (field.type == @TypeOf(null)) continue;393 inline for (args_info.field_names, args_info.field_types) |field_name, field_type| {
394 addUserInputOptionFromArg(arena, &map, field, field.type, @field(args, field.name));394 if (field_type == @TypeOf(null)) continue;
395 addUserInputOptionFromArg(arena, &map, field_name, field_type, @field(args, field_name));
395 }396 }
396 return map;397 return map;
397}398}
...@@ -399,15 +400,15 @@ fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap...@@ -399,15 +400,15 @@ fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap
399fn addUserInputOptionFromArg(400fn addUserInputOptionFromArg(
400 arena: Allocator,401 arena: Allocator,
401 map: *UserInputOptionsMap,402 map: *UserInputOptionsMap,
402 field: std.builtin.Type.StructField,403 field_name: [:0]const u8,
403 comptime T: type,404 comptime T: type,
404 /// If null, the value won't be added, but `T` will still be type-checked.405 /// If null, the value won't be added, but `T` will still be type-checked.
405 maybe_value: ?T,406 maybe_value: ?T,
406) void {407) void {
407 switch (T) {408 switch (T) {
408 Target.Query => return if (maybe_value) |v| {409 Target.Query => return if (maybe_value) |v| {
409 map.put(field.name, .{410 map.put(field_name, .{
410 .name = field.name,411 .name = field_name,
411 .value = .{ .scalar = v.zigTriple(arena) catch @panic("OOM") },412 .value = .{ .scalar = v.zigTriple(arena) catch @panic("OOM") },
412 .used = false,413 .used = false,
413 }) catch @panic("OOM");414 }) catch @panic("OOM");
...@@ -418,8 +419,8 @@ fn addUserInputOptionFromArg(...@@ -418,8 +419,8 @@ fn addUserInputOptionFromArg(
418 }) catch @panic("OOM");419 }) catch @panic("OOM");
419 },420 },
420 ResolvedTarget => return if (maybe_value) |v| {421 ResolvedTarget => return if (maybe_value) |v| {
421 map.put(field.name, .{422 map.put(field_name, .{
422 .name = field.name,423 .name = field_name,
423 .value = .{ .scalar = v.query.zigTriple(arena) catch @panic("OOM") },424 .value = .{ .scalar = v.query.zigTriple(arena) catch @panic("OOM") },
424 .used = false,425 .used = false,
425 }) catch @panic("OOM");426 }) catch @panic("OOM");
...@@ -430,15 +431,15 @@ fn addUserInputOptionFromArg(...@@ -430,15 +431,15 @@ fn addUserInputOptionFromArg(
430 }) catch @panic("OOM");431 }) catch @panic("OOM");
431 },432 },
432 std.zig.BuildId => return if (maybe_value) |v| {433 std.zig.BuildId => return if (maybe_value) |v| {
433 map.put(field.name, .{434 map.put(field_name, .{
434 .name = field.name,435 .name = field_name,
435 .value = .{ .scalar = std.fmt.allocPrint(arena, "{f}", .{v}) catch @panic("OOM") },436 .value = .{ .scalar = std.fmt.allocPrint(arena, "{f}", .{v}) catch @panic("OOM") },
436 .used = false,437 .used = false,
437 }) catch @panic("OOM");438 }) catch @panic("OOM");
438 },439 },
439 LazyPath => return if (maybe_value) |v| {440 LazyPath => return if (maybe_value) |v| {
440 map.put(field.name, .{441 map.put(field_name, .{
441 .name = field.name,442 .name = field_name,
442 .value = .{ .lazy_path = v.dupeInner(arena) },443 .value = .{ .lazy_path = v.dupeInner(arena) },
443 .used = false,444 .used = false,
444 }) catch @panic("OOM");445 }) catch @panic("OOM");
...@@ -446,15 +447,15 @@ fn addUserInputOptionFromArg(...@@ -446,15 +447,15 @@ fn addUserInputOptionFromArg(
446 []const LazyPath => return if (maybe_value) |v| {447 []const LazyPath => return if (maybe_value) |v| {
447 var list = std.array_list.Managed(LazyPath).initCapacity(arena, v.len) catch @panic("OOM");448 var list = std.array_list.Managed(LazyPath).initCapacity(arena, v.len) catch @panic("OOM");
448 for (v) |lp| list.appendAssumeCapacity(lp.dupeInner(arena));449 for (v) |lp| list.appendAssumeCapacity(lp.dupeInner(arena));
449 map.put(field.name, .{450 map.put(field_name, .{
450 .name = field.name,451 .name = field_name,
451 .value = .{ .lazy_path_list = list },452 .value = .{ .lazy_path_list = list },
452 .used = false,453 .used = false,
453 }) catch @panic("OOM");454 }) catch @panic("OOM");
454 },455 },
455 []const u8 => return if (maybe_value) |v| {456 []const u8 => return if (maybe_value) |v| {
456 map.put(field.name, .{457 map.put(field_name, .{
457 .name = field.name,458 .name = field_name,
458 .value = .{ .scalar = arena.dupe(u8, v) catch @panic("OOM") },459 .value = .{ .scalar = arena.dupe(u8, v) catch @panic("OOM") },
459 .used = false,460 .used = false,
460 }) catch @panic("OOM");461 }) catch @panic("OOM");
...@@ -462,37 +463,37 @@ fn addUserInputOptionFromArg(...@@ -462,37 +463,37 @@ fn addUserInputOptionFromArg(
462 []const []const u8 => return if (maybe_value) |v| {463 []const []const u8 => return if (maybe_value) |v| {
463 var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM");464 var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM");
464 for (v) |s| list.appendAssumeCapacity(arena.dupe(u8, s) catch @panic("OOM"));465 for (v) |s| list.appendAssumeCapacity(arena.dupe(u8, s) catch @panic("OOM"));
465 map.put(field.name, .{466 map.put(field_name, .{
466 .name = field.name,467 .name = field_name,
467 .value = .{ .list = list },468 .value = .{ .list = list },
468 .used = false,469 .used = false,
469 }) catch @panic("OOM");470 }) catch @panic("OOM");
470 },471 },
471 else => switch (@typeInfo(T)) {472 else => switch (@typeInfo(T)) {
472 .bool => return if (maybe_value) |v| {473 .bool => return if (maybe_value) |v| {
473 map.put(field.name, .{474 map.put(field_name, .{
474 .name = field.name,475 .name = field_name,
475 .value = .{ .scalar = if (v) "true" else "false" },476 .value = .{ .scalar = if (v) "true" else "false" },
476 .used = false,477 .used = false,
477 }) catch @panic("OOM");478 }) catch @panic("OOM");
478 },479 },
479 .@"enum", .enum_literal => return if (maybe_value) |v| {480 .@"enum", .enum_literal => return if (maybe_value) |v| {
480 map.put(field.name, .{481 map.put(field_name, .{
481 .name = field.name,482 .name = field_name,
482 .value = .{ .scalar = @tagName(v) },483 .value = .{ .scalar = @tagName(v) },
483 .used = false,484 .used = false,
484 }) catch @panic("OOM");485 }) catch @panic("OOM");
485 },486 },
486 .comptime_int, .int => return if (maybe_value) |v| {487 .comptime_int, .int => return if (maybe_value) |v| {
487 map.put(field.name, .{488 map.put(field_name, .{
488 .name = field.name,489 .name = field_name,
489 .value = .{ .scalar = std.fmt.allocPrint(arena, "{d}", .{v}) catch @panic("OOM") },490 .value = .{ .scalar = std.fmt.allocPrint(arena, "{d}", .{v}) catch @panic("OOM") },
490 .used = false,491 .used = false,
491 }) catch @panic("OOM");492 }) catch @panic("OOM");
492 },493 },
493 .comptime_float, .float => return if (maybe_value) |v| {494 .comptime_float, .float => return if (maybe_value) |v| {
494 map.put(field.name, .{495 map.put(field_name, .{
495 .name = field.name,496 .name = field_name,
496 .value = .{ .scalar = std.fmt.allocPrint(arena, "{x}", .{v}) catch @panic("OOM") },497 .value = .{ .scalar = std.fmt.allocPrint(arena, "{x}", .{v}) catch @panic("OOM") },
497 .used = false,498 .used = false,
498 }) catch @panic("OOM");499 }) catch @panic("OOM");
...@@ -503,7 +504,7 @@ fn addUserInputOptionFromArg(...@@ -503,7 +504,7 @@ fn addUserInputOptionFromArg(
503 addUserInputOptionFromArg(504 addUserInputOptionFromArg(
504 arena,505 arena,
505 map,506 map,
506 field,507 field_name,
507 @Pointer(.slice, .{ .@"const" = true }, array_info.child, null),508 @Pointer(.slice, .{ .@"const" = true }, array_info.child, null),
508 maybe_value orelse null,509 maybe_value orelse null,
509 );510 );
...@@ -515,8 +516,8 @@ fn addUserInputOptionFromArg(...@@ -515,8 +516,8 @@ fn addUserInputOptionFromArg(
515 .@"enum" => return if (maybe_value) |v| {516 .@"enum" => return if (maybe_value) |v| {
516 var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM");517 var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM");
517 for (v) |tag| list.appendAssumeCapacity(@tagName(tag));518 for (v) |tag| list.appendAssumeCapacity(@tagName(tag));
518 map.put(field.name, .{519 map.put(field_name, .{
519 .name = field.name,520 .name = field_name,
520 .value = .{ .list = list },521 .value = .{ .list = list },
521 .used = false,522 .used = false,
522 }) catch @panic("OOM");523 }) catch @panic("OOM");
...@@ -525,7 +526,7 @@ fn addUserInputOptionFromArg(...@@ -525,7 +526,7 @@ fn addUserInputOptionFromArg(
525 addUserInputOptionFromArg(526 addUserInputOptionFromArg(
526 arena,527 arena,
527 map,528 map,
528 field,529 field_name,
529 @Pointer(ptr_info.size, .{ .@"const" = true }, ptr_info.child, null),530 @Pointer(ptr_info.size, .{ .@"const" = true }, ptr_info.child, null),
530 maybe_value orelse null,531 maybe_value orelse null,
531 );532 );
...@@ -541,7 +542,7 @@ fn addUserInputOptionFromArg(...@@ -541,7 +542,7 @@ fn addUserInputOptionFromArg(
541 addUserInputOptionFromArg(542 addUserInputOptionFromArg(
542 arena,543 arena,
543 map,544 map,
544 field,545 field_name,
545 info.child,546 info.child,
546 maybe_value orelse null,547 maybe_value orelse null,
547 );548 );
...@@ -551,7 +552,7 @@ fn addUserInputOptionFromArg(...@@ -551,7 +552,7 @@ fn addUserInputOptionFromArg(
551 else => {},552 else => {},
552 },553 },
553 }554 }
554 @compileError("option '" ++ field.name ++ "' has unsupported type: " ++ @typeName(field.type));555 @compileError("option '" ++ field_name ++ "' has unsupported type: " ++ @typeName(T));
555}556}
556557
557const OrderedUserValue = union(enum) {558const OrderedUserValue = union(enum) {
...@@ -1084,11 +1085,11 @@ pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw...@@ -1084,11 +1085,11 @@ pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw
1084 const type_id = comptime typeToEnum(T);1085 const type_id = comptime typeToEnum(T);
1085 const enum_options = if (type_id == .@"enum" or type_id == .enum_list) blk: {1086 const enum_options = if (type_id == .@"enum" or type_id == .enum_list) blk: {
1086 const EnumType = if (type_id == .enum_list) @typeInfo(T).pointer.child else T;1087 const EnumType = if (type_id == .enum_list) @typeInfo(T).pointer.child else T;
1087 const fields = comptime std.meta.fields(EnumType);1088 const field_names = comptime std.meta.fieldNames(EnumType);
1088 var options = std.array_list.Managed([]const u8).initCapacity(arena, fields.len) catch @panic("OOM");1089 var options = std.array_list.Managed([]const u8).initCapacity(b.allocator, field_names.len) catch @panic("OOM");
10891090
1090 inline for (fields) |field| {1091 inline for (field_names) |field_name| {
1091 options.appendAssumeCapacity(field.name);1092 options.appendAssumeCapacity(field_name);
1092 }1093 }
10931094
1094 break :blk options.toOwnedSlice() catch @panic("OOM");1095 break :blk options.toOwnedSlice() catch @panic("OOM");
...@@ -1377,8 +1378,8 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile...@@ -1377,8 +1378,8 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile
1377 \\available operating systems:1378 \\available operating systems:
1378 \\1379 \\
1379 , .{diags.os_name.?});1380 , .{diags.os_name.?});
1380 inline for (std.meta.fields(Target.Os.Tag)) |field| {1381 inline for (comptime std.meta.fieldNames(Target.Os.Tag)) |field_name| {
1381 std.debug.print(" {s}\n", .{field.name});1382 std.debug.print(" {s}\n", .{field_name});
1382 }1383 }
1383 return error.ParseFailed;1384 return error.ParseFailed;
1384 },1385 },
...@@ -1781,8 +1782,8 @@ pub fn findProgram(b: *Build, options: FindProgramOptions) ?[]const u8 {...@@ -1781,8 +1782,8 @@ pub fn findProgram(b: *Build, options: FindProgramOptions) ?[]const u8 {
1781}1782}
17821783
1783fn supportedWindowsProgramExtension(ext: []const u8) bool {1784fn supportedWindowsProgramExtension(ext: []const u8) bool {
1784 inline for (@typeInfo(std.process.WindowsExtension).@"enum".fields) |field| {1785 inline for (@typeInfo(std.process.WindowsExtension).@"enum".field_names) |field_name| {
1785 if (std.ascii.eqlIgnoreCase(ext, "." ++ field.name)) return true;1786 if (std.ascii.eqlIgnoreCase(ext, "." ++ field_name)) return true;
1786 }1787 }
1787 return false;1788 return false;
1788}1789}
...@@ -2042,8 +2043,7 @@ inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, c...@@ -2042,8 +2043,7 @@ inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, c
2042 const deps = build_runner.dependencies;2043 const deps = build_runner.dependencies;
2043 const arena = b.graph.arena;2044 const arena = b.graph.arena;
20442045
2045 const b_pkg_hash, const b_pkg_deps = comptime for (@typeInfo(deps.packages).@"struct".decls) |decl| {2046 const b_pkg_hash, const b_pkg_deps = comptime for (@typeInfo(deps.packages).@"struct".decl_names) |pkg_hash| {
2046 const pkg_hash = decl.name;
2047 const pkg = @field(deps.packages, pkg_hash);2047 const pkg = @field(deps.packages, pkg_hash);
2048 if (@hasDecl(pkg, "build_zig") and pkg.build_zig == asking_build_zig) break .{ pkg_hash, pkg.deps };2048 if (@hasDecl(pkg, "build_zig") and pkg.build_zig == asking_build_zig) break .{ pkg_hash, pkg.deps };
2049 } else .{ "", deps.root_deps };2049 } else .{ "", deps.root_deps };
...@@ -2086,9 +2086,9 @@ pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency {...@@ -2086,9 +2086,9 @@ pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency {
2086 const deps = build_runner.dependencies;2086 const deps = build_runner.dependencies;
2087 const pkg_hash = findPkgHashOrFatal(b, name);2087 const pkg_hash = findPkgHashOrFatal(b, name);
20882088
2089 inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {2089 inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| {
2090 if (mem.eql(u8, decl.name, pkg_hash)) {2090 if (mem.eql(u8, decl_name, pkg_hash)) {
2091 const pkg = @field(deps.packages, decl.name);2091 const pkg = @field(deps.packages, decl_name);
2092 const available = !@hasDecl(pkg, "available") or pkg.available;2092 const available = !@hasDecl(pkg, "available") or pkg.available;
2093 if (!available) {2093 if (!available) {
2094 markNeededLazyDep(b, pkg_hash);2094 markNeededLazyDep(b, pkg_hash);
...@@ -2106,9 +2106,9 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {...@@ -2106,9 +2106,9 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency {
2106 const deps = build_runner.dependencies;2106 const deps = build_runner.dependencies;
2107 const pkg_hash = findPkgHashOrFatal(b, name);2107 const pkg_hash = findPkgHashOrFatal(b, name);
21082108
2109 inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {2109 inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| {
2110 if (mem.eql(u8, decl.name, pkg_hash)) {2110 if (mem.eql(u8, decl_name, pkg_hash)) {
2111 const pkg = @field(deps.packages, decl.name);2111 const pkg = @field(deps.packages, decl_name);
2112 if (@hasDecl(pkg, "available")) {2112 if (@hasDecl(pkg, "available")) {
2113 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 });2113 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 });
2114 }2114 }
...@@ -2136,9 +2136,9 @@ pub inline fn lazyImport(...@@ -2136,9 +2136,9 @@ pub inline fn lazyImport(
2136 const deps = build_runner.dependencies;2136 const deps = build_runner.dependencies;
2137 const pkg_hash = findImportPkgHashOrFatal(b, asking_build_zig, dep_name);2137 const pkg_hash = findImportPkgHashOrFatal(b, asking_build_zig, dep_name);
21382138
2139 inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {2139 inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| {
2140 if (comptime mem.eql(u8, decl.name, pkg_hash)) {2140 if (comptime mem.eql(u8, decl_name, pkg_hash)) {
2141 const pkg = @field(deps.packages, decl.name);2141 const pkg = @field(deps.packages, decl_name);
2142 const available = !@hasDecl(pkg, "available") or pkg.available;2142 const available = !@hasDecl(pkg, "available") or pkg.available;
2143 if (!available) {2143 if (!available) {
2144 markNeededLazyDep(b, pkg_hash);2144 markNeededLazyDep(b, pkg_hash);
...@@ -2167,8 +2167,7 @@ pub fn dependencyFromBuildZig(...@@ -2167,8 +2167,7 @@ pub fn dependencyFromBuildZig(
2167 const arena = graph.arena;2167 const arena = graph.arena;
21682168
2169 find_dep: {2169 find_dep: {
2170 const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).@"struct".decls) |decl| {2170 const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).@"struct".decl_names) |pkg_hash| {
2171 const pkg_hash = decl.name;
2172 const pkg = @field(deps.packages, pkg_hash);2171 const pkg = @field(deps.packages, pkg_hash);
2173 if (@hasDecl(pkg, "build_zig") and pkg.build_zig == build_zig) break .{ pkg, pkg_hash };2172 if (@hasDecl(pkg, "build_zig") and pkg.build_zig == build_zig) break .{ pkg, pkg_hash };
2174 } else break :find_dep;2173 } else break :find_dep;
lib/std/Build/Cache.zig+2-2
...@@ -1241,7 +1241,7 @@ pub const Manifest = struct {...@@ -1241,7 +1241,7 @@ pub const Manifest = struct {
1241 }1241 }
12421242
1243 pub fn populateFileSystemInputs(man: *Manifest, buf: *std.ArrayList(u8)) Allocator.Error!void {1243 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);
1245 buf.clearRetainingCapacity();1245 buf.clearRetainingCapacity();
1246 const gpa = man.cache.gpa;1246 const gpa = man.cache.gpa;
1247 const files = man.files.keys();1247 const files = man.files.keys();
...@@ -1259,7 +1259,7 @@ pub const Manifest = struct {...@@ -1259,7 +1259,7 @@ pub const Manifest = struct {
12591259
1260 pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [4]u8) Allocator.Error!void {1260 pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [4]u8) Allocator.Error!void {
1261 const gpa = other.cache.gpa;1261 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);
1263 assert(man.cache.prefixes_len == 4);1263 assert(man.cache.prefixes_len == 4);
1264 for (man.files.keys()) |file| {1264 for (man.files.keys()) |file| {
1265 const prefixed_path: PrefixedPath = .{1265 const prefixed_path: PrefixedPath = .{
lib/std/Build/Configuration.zig+19-16
...@@ -2884,7 +2884,10 @@ pub const Storage = enum {...@@ -2884,7 +2884,10 @@ pub const Storage = enum {
2884 }2884 }
28852885
2886 pub fn cast(this: @This(), c: *const Configuration, comptime S: type) ?S {2886 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 };
2888 const base_flags: BaseFlags = @bitCast(c.extra[@intFromEnum(this)]);2891 const base_flags: BaseFlags = @bitCast(c.extra[@intFromEnum(this)]);
2889 if (base_flags.tag != wanted_tag) return null;2892 if (base_flags.tag != wanted_tag) return null;
2890 var i: usize = @intFromEnum(this);2893 var i: usize = @intFromEnum(this);
...@@ -3047,8 +3050,8 @@ pub const Storage = enum {...@@ -3047,8 +3050,8 @@ pub const Storage = enum {
3047 switch (@typeInfo(T)) {3050 switch (@typeInfo(T)) {
3048 .@"struct" => |info| {3051 .@"struct" => |info| {
3049 var result: T = undefined;3052 var result: T = undefined;
3050 inline for (info.fields) |field| {3053 inline for (info.field_names, info.field_types) |field_name, field_type| {
3051 @field(result, field.name) = dataField(buffer, i, &result, field.type);3054 @field(result, field_name) = dataField(buffer, i, &result, field_type);
3052 }3055 }
3053 return result;3056 return result;
3054 },3057 },
...@@ -3058,7 +3061,7 @@ pub const Storage = enum {...@@ -3058,7 +3061,7 @@ pub const Storage = enum {
3058 inline else => |comptime_tag| @unionInit(3061 inline else => |comptime_tag| @unionInit(
3059 T,3062 T,
3060 @tagName(comptime_tag),3063 @tagName(comptime_tag),
3061 data(buffer, i, info.fields[@intFromEnum(comptime_tag)].type),3064 data(buffer, i, info.field_types[@intFromEnum(comptime_tag)]),
3062 ),3065 ),
3063 };3066 };
3064 },3067 },
...@@ -3125,7 +3128,7 @@ pub const Storage = enum {...@@ -3125,7 +3128,7 @@ pub const Storage = enum {
3125 buffer,3128 buffer,
3126 i,3129 i,
3127 container,3130 container,
3128 @typeInfo(Field.Union).@"union".fields[@intFromEnum(comptime_tag)].type,3131 @typeInfo(Field.Union).@"union".field_types[@intFromEnum(comptime_tag)],
3129 ),3132 ),
3130 ),3133 ),
3131 },3134 },
...@@ -3167,7 +3170,7 @@ pub const Storage = enum {...@@ -3167,7 +3170,7 @@ pub const Storage = enum {
3167 .multi_list => {3170 .multi_list => {
3168 const data_start = i.* + 1;3171 const data_start = i.* + 1;
3169 const len = buffer[data_start - 1];3172 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;
3171 return .{ .mal = .{3174 return .{ .mal = .{
3172 .bytes = @ptrCast(@constCast(buffer[data_start..][0..len])),3175 .bytes = @ptrCast(@constCast(buffer[data_start..][0..len])),
3173 .len = len,3176 .len = len,
...@@ -3205,10 +3208,10 @@ pub const Storage = enum {...@@ -3205,10 +3208,10 @@ pub const Storage = enum {
32053208
3206 /// Returns new end index.3209 /// Returns new end index.
3207 fn setExtra(buffer: []u32, index: usize, extra: anytype) usize {3210 fn setExtra(buffer: []u32, index: usize, extra: anytype) usize {
3208 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;3211 const info = @typeInfo(@TypeOf(extra)).@"struct";
3209 var i = index;3212 var i = index;
3210 inline for (fields) |field| {3213 inline for (info.field_names, info.field_types) |field_name, field_type| {
3211 i += setExtraField(buffer, i, field.type, @field(extra, field.name));3214 i += setExtraField(buffer, i, field_type, @field(extra, field_name));
3212 }3215 }
3213 return i;3216 return i;
3214 }3217 }
...@@ -3236,7 +3239,7 @@ pub const Storage = enum {...@@ -3236,7 +3239,7 @@ pub const Storage = enum {
3236 .flag_length_prefixed_list,3239 .flag_length_prefixed_list,
3237 .flag_list,3240 .flag_list,
3238 => 1 + @divExact(@sizeOf(Field.Elem), @sizeOf(u32)) * field.slice.len,3241 => 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,
3240 .union_list => Field.extraLen(field.len),3243 .union_list => Field.extraLen(field.len),
3241 .flag_union => switch (field.u) {3244 .flag_union => switch (field.u) {
3242 inline else => |v| extraFieldLen(v),3245 inline else => |v| extraFieldLen(v),
...@@ -3249,10 +3252,10 @@ pub const Storage = enum {...@@ -3249,10 +3252,10 @@ pub const Storage = enum {
3249 }3252 }
32503253
3251 fn extraLen(extra: anytype) usize {3254 fn extraLen(extra: anytype) usize {
3252 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;3255 const field_names = @typeInfo(@TypeOf(extra)).@"struct".field_names;
3253 var i: usize = 0;3256 var i: usize = 0;
3254 inline for (fields) |field| {3257 inline for (field_names) |name| {
3255 i += Storage.extraFieldLen(@field(extra, field.name));3258 i += Storage.extraFieldLen(@field(extra, name));
3256 }3259 }
3257 return i;3260 return i;
3258 }3261 }
...@@ -3324,12 +3327,12 @@ pub const Storage = enum {...@@ -3324,12 +3327,12 @@ pub const Storage = enum {
3324 .multi_list => {3327 .multi_list => {
3325 const len: u32 = @intCast(value.mal.len);3328 const len: u32 = @intCast(value.mal.len);
3326 buffer[i] = len;3329 buffer[i] = len;
3327 const fields = @typeInfo(Field.Elem).@"struct".fields;3330 const field_names = @typeInfo(Field.Elem).@"struct".field_names;
3328 inline for (0..fields.len) |field_i| @memcpy(3331 inline for (0..field_names.len) |field_i| @memcpy(
3329 buffer[i + 1 + field_i * len ..][0..len],3332 buffer[i + 1 + field_i * len ..][0..len],
3330 @as([]const u32, @ptrCast(value.mal.items(@enumFromInt(field_i)))),3333 @as([]const u32, @ptrCast(value.mal.items(@enumFromInt(field_i)))),
3331 );3334 );
3332 return 1 + fields.len * len;3335 return 1 + field_names.len * len;
3333 },3336 },
3334 .union_list => {3337 .union_list => {
3335 if (value.len == 0) return 0;3338 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...@@ -173,8 +173,9 @@ fn addValueInner(config_header: *ConfigHeader, name: []const u8, comptime T: typ
173}173}
174174
175pub fn addValues(config_header: *ConfigHeader, values: anytype) void {175pub fn addValues(config_header: *ConfigHeader, values: anytype) void {
176 inline for (@typeInfo(@TypeOf(values)).@"struct".fields) |field| {176 const info = @typeInfo(@TypeOf(values)).@"struct";
177 addValue(config_header, field.name, field.type, @field(values, field.name));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));
178 }179 }
179}180}
180181
lib/std/Build/Step/Options.zig+28-22
...@@ -299,14 +299,14 @@ fn printEnum(...@@ -299,14 +299,14 @@ fn printEnum(
299 try out.appendNTimes(gpa, ' ', indent);299 try out.appendNTimes(gpa, ' ', indent);
300 try out.print(gpa, "pub const {f} = enum ({s}) {{\n", .{ std.zig.fmtId(@typeName(T)), @typeName(val.tag_type) });300 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| {
303 try out.appendNTimes(gpa, ' ', indent);303 try out.appendNTimes(gpa, ' ', indent);
304 try out.print(gpa, " {f} = {d},\n", .{304 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,
306 });306 });
307 }307 }
308308
309 if (!val.is_exhaustive) {309 if (val.mode == .nonexhaustive) {
310 try out.appendNTimes(gpa, ' ', indent);310 try out.appendNTimes(gpa, ' ', indent);
311 try out.appendSlice(gpa, " _,\n");311 try out.appendSlice(gpa, " _,\n");
312 }312 }
...@@ -315,7 +315,13 @@ fn printEnum(...@@ -315,7 +315,13 @@ fn printEnum(
315 try out.appendSlice(gpa, "};\n");315 try out.appendSlice(gpa, "};\n");
316}316}
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 {
319 const gpa = options.step.owner.allocator;325 const gpa = options.step.owner.allocator;
320 const gop = try options.encountered_types.getOrPut(gpa, @typeName(T));326 const gop = try options.encountered_types.getOrPut(gpa, @typeName(T));
321 if (gop.found_existing) return;327 if (gop.found_existing) return;
...@@ -331,32 +337,32 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com...@@ -331,32 +337,32 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com
331337
332 try out.appendSlice(gpa, " {\n");338 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| {
335 try out.appendNTimes(gpa, ' ', indent);341 try out.appendNTimes(gpa, ' ', indent);
336342
337 const type_name = @typeName(field.type);343 const type_name = @typeName(field_type);
338344
339 // If the type name doesn't contains a '.' the type is from zig builtins.345 // If the type name doesn't contains a '.' the type is from zig builtins.
340 if (std.mem.containsAtLeast(u8, type_name, 1, ".")) {346 if (std.mem.containsAtLeast(u8, type_name, 1, ".")) {
341 try out.print(gpa, " {f}: {f}", .{347 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 }),
343 std.zig.fmtId(type_name),349 std.zig.fmtId(type_name),
344 });350 });
345 } else {351 } else {
346 try out.print(gpa, " {f}: {s}", .{352 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 }),
348 type_name,354 type_name,
349 });355 });
350 }356 }
351357
352 if (field.defaultValue()) |default_value| {358 if (field_attrs.defaultValue(field_type)) |default_value| {
353 try out.appendSlice(gpa, " = ");359 try out.appendSlice(gpa, " = ");
354 switch (@typeInfo(@TypeOf(default_value))) {360 switch (@typeInfo(field_type)) {
355 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(default_value)}),361 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(default_value)}),
356 .@"struct" => |info| {362 .@"struct" => |info| {
357 try printStructValue(options, out, info, default_value, indent + 4);363 try printStructValue(options, out, info, default_value, indent + 4);
358 },364 },
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),
360 }366 }
361 } else {367 } else {
362 try out.appendSlice(gpa, ",\n");368 try out.appendSlice(gpa, ",\n");
...@@ -368,8 +374,8 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com...@@ -368,8 +374,8 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com
368 try out.appendNTimes(gpa, ' ', indent);374 try out.appendNTimes(gpa, ' ', indent);
369 try out.appendSlice(gpa, "};\n");375 try out.appendSlice(gpa, "};\n");
370376
371 inline for (val.fields) |field| {377 inline for (val.field_types) |field_type| {
372 try printUserDefinedType(options, out, field.type, 0);378 try printUserDefinedType(options, out, field_type, 0);
373 }379 }
374}380}
375381
...@@ -384,24 +390,24 @@ fn printStructValue(...@@ -384,24 +390,24 @@ fn printStructValue(
384 try out.appendSlice(gpa, ".{\n");390 try out.appendSlice(gpa, ".{\n");
385391
386 if (struct_val.is_tuple) {392 if (struct_val.is_tuple) {
387 inline for (struct_val.fields) |field| {393 inline for (struct_val.field_names) |field_name| {
388 try out.appendNTimes(gpa, ' ', indent);394 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);
390 }396 }
391 } else {397 } else {
392 inline for (struct_val.fields) |field| {398 inline for (struct_val.field_names) |field_name| {
393 try out.appendNTimes(gpa, ' ', indent);399 try out.appendNTimes(gpa, ' ', indent);
394 try out.print(gpa, " .{f} = ", .{400 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 }),
396 });402 });
397403
398 const field_name = @field(val, field.name);404 const field_val = @field(val, field_name);
399 switch (@typeInfo(@TypeOf(field_name))) {405 switch (@typeInfo(@TypeOf(field_val))) {
400 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_name)}),406 .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_val)}),
401 .@"struct" => |struct_info| {407 .@"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);
403 },409 },
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),
405 }411 }
406 }412 }
407 }413 }
lib/std/Io.zig+7-6
...@@ -396,12 +396,13 @@ pub const Operation = union(enum) {...@@ -396,12 +396,13 @@ pub const Operation = union(enum) {
396 };396 };
397397
398 pub const Result = Result: {398 pub const Result = Result: {
399 const operation_fields = @typeInfo(Operation).@"union".fields;399 const operation_info = @typeInfo(Operation).@"union";
400 var field_names: [operation_fields.len][]const u8 = undefined;400 const operation_count = operation_info.field_names.len;
401 var field_types: [operation_fields.len]type = undefined;401 var field_names: [operation_count][]const u8 = undefined;
402 for (operation_fields, &field_names, &field_types) |field, *field_name, *field_type| {402 var field_types: [operation_count]type = undefined;
403 field_name.* = field.name;403 for (operation_info.field_names, operation_info.field_types, &field_names, &field_types) |f_name, f_type, *field_name, *field_type| {
404 field_type.* = if (field.type == noreturn) noreturn else field.type.Result;404 field_name.* = f_name;
405 field_type.* = if (f_type == noreturn) noreturn else f_type.Result;
405 }406 }
406 break :Result @Union(.auto, Tag, &field_names, &field_types, &@splat(.{}));407 break :Result @Union(.auto, Tag, &field_names, &field_types, &@splat(.{}));
407 };408 };
lib/std/Io/Reader.zig+1-1
...@@ -1277,7 +1277,7 @@ pub fn takeEnum(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Tak...@@ -1277,7 +1277,7 @@ pub fn takeEnum(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Tak
1277/// Asserts the buffer was initialized with a capacity at least `@sizeOf(Enum)`.1277/// Asserts the buffer was initialized with a capacity at least `@sizeOf(Enum)`.
1278pub fn takeEnumNonexhaustive(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Error!Enum {1278pub fn takeEnumNonexhaustive(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Error!Enum {
1279 const info = @typeInfo(Enum).@"enum";1279 const info = @typeInfo(Enum).@"enum";
1280 comptime assert(!info.is_exhaustive);1280 comptime assert(info.mode != .exhaustive);
1281 comptime assert(@bitSizeOf(info.tag_type) == @sizeOf(info.tag_type) * 8);1281 comptime assert(@bitSizeOf(info.tag_type) == @sizeOf(info.tag_type) * 8);
1282 return takeEnum(r, Enum, endian) catch |err| switch (err) {1282 return takeEnum(r, Enum, endian) catch |err| switch (err) {
1283 error.InvalidEnumTag => unreachable,1283 error.InvalidEnumTag => unreachable,
lib/std/Io/Threaded.zig+10-10
...@@ -332,8 +332,8 @@ pub const Environ = struct {...@@ -332,8 +332,8 @@ pub const Environ = struct {
332 .flags = .{ .nonblocking = true },332 .flags = .{ .nonblocking = true },
333 };333 };
334 };334 };
335 } else inline for (@typeInfo(String).@"struct".fields) |field| {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;336 if (std.mem.eql(u8, key, field_name)) @field(environ.string, field_name) = value;
337 }337 }
338 }338 }
339 }339 }
...@@ -11785,8 +11785,8 @@ fn sleepWasi(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void {...@@ -11785,8 +11785,8 @@ fn sleepWasi(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void {
1178511785
11786fn sleepNanosleep(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void {11786fn sleepNanosleep(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void {
11787 const t_io = io(t);11787 const t_io = io(t);
11788 const sec_type = @typeInfo(posix.timespec).@"struct".fields[0].type;11788 const sec_type = @typeInfo(posix.timespec).@"struct".field_types[0];
11789 const nsec_type = @typeInfo(posix.timespec).@"struct".fields[1].type;11789 const nsec_type = @typeInfo(posix.timespec).@"struct".field_types[1];
1179011790
11791 var timespec: posix.timespec = t: {11791 var timespec: posix.timespec = t: {
11792 const d = timeout.toDurationFromNow(t_io) orelse break :t .{11792 const d = timeout.toDurationFromNow(t_io) orelse break :t .{
...@@ -14923,9 +14923,9 @@ const WindowsEnvironStrings = struct {...@@ -14923,9 +14923,9 @@ const WindowsEnvironStrings = struct {
1492314923
14924 i += 1; // skip over null byte14924 i += 1; // skip over null byte
1492514925
14926 inline for (@typeInfo(WindowsEnvironStrings).@"struct".fields) |field| {14926 inline for (@typeInfo(WindowsEnvironStrings).@"struct".field_names) |field_name| {
14927 const field_name_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(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;14928 if (windows.eqlIgnoreCaseWtf16(key_w, field_name_w)) @field(result, field_name) = value_w;
14929 }14929 }
14930 }14930 }
1493114931
...@@ -16190,7 +16190,7 @@ fn windowsCreateProcessPathExt(...@@ -16190,7 +16190,7 @@ fn windowsCreateProcessPathExt(
16190 }16190 }
16191 var io_status: windows.IO_STATUS_BLOCK = undefined;16191 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;
16194 var pathext_seen: [num_supported_pathext]bool = @splat(false);16194 var pathext_seen: [num_supported_pathext]bool = @splat(false);
16195 var any_pathext_seen = false;16195 var any_pathext_seen = false;
16196 var unappended_exists = false;16196 var unappended_exists = false;
...@@ -16435,8 +16435,8 @@ fn windowsCreateProcess(...@@ -16435,8 +16435,8 @@ fn windowsCreateProcess(
16435fn windowsCreateProcessSupportsExtension(ext: []const u16) ?process.WindowsExtension {16435fn windowsCreateProcessSupportsExtension(ext: []const u16) ?process.WindowsExtension {
16436 comptime {16436 comptime {
16437 // Ensures keeping this function in sync with the enum.16437 // Ensures keeping this function in sync with the enum.
16438 const fields = @typeInfo(process.WindowsExtension).@"enum".fields;16438 const field_names = @typeInfo(process.WindowsExtension).@"enum".field_names;
16439 assert(fields.len == 4);16439 assert(field_names.len == 4);
16440 assert(@intFromEnum(process.WindowsExtension.bat) == 0);16440 assert(@intFromEnum(process.WindowsExtension.bat) == 0);
16441 assert(@intFromEnum(process.WindowsExtension.cmd) == 1);16441 assert(@intFromEnum(process.WindowsExtension.cmd) == 1);
16442 assert(@intFromEnum(process.WindowsExtension.com) == 2);16442 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 {...@@ -620,14 +620,14 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
620 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));620 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
621 }621 }
622622
623 const fields_info = args_type_info.@"struct".fields;623 const field_names = args_type_info.@"struct".field_names;
624 const max_format_args = @typeInfo(std.fmt.ArgSetType).int.bits;624 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) {
626 @compileError("32 arguments max are supported per format call");626 @compileError("32 arguments max are supported per format call");
627 }627 }
628628
629 @setEvalBranchQuota(@as(comptime_int, fmt.len) * 1000); // NOTE: We're upcasting as 16-bit usize overflows.629 @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 };
631 comptime var i = 0;631 comptime var i = 0;
632 comptime var literal: []const u8 = "";632 comptime var literal: []const u8 = "";
633 inline while (true) {633 inline while (true) {
...@@ -728,7 +728,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {...@@ -728,7 +728,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void {
728 .width = width,728 .width = width,
729 .precision = precision,729 .precision = precision,
730 },730 },
731 @field(args, fields_info[arg_to_print].name),731 @field(args, field_names[arg_to_print]),
732 std.options.fmt_max_depth,732 std.options.fmt_max_depth,
733 );733 );
734 }734 }
...@@ -1290,7 +1290,7 @@ pub fn printValue(...@@ -1290,7 +1290,7 @@ pub fn printValue(
1290 .@"enum" => |info| {1290 .@"enum" => |info| {
1291 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);1291 if (!is_any and fmt.len != 0) invalidFmtError(fmt, value);
1292 optionsForbidden(options);1292 optionsForbidden(options);
1293 if (info.is_exhaustive) {1293 if (info.mode == .exhaustive) {
1294 return printEnumExhaustive(w, value);1294 return printEnumExhaustive(w, value);
1295 } else {1295 } else {
1296 return printEnumNonexhaustive(w, value);1296 return printEnumNonexhaustive(w, value);
...@@ -1309,9 +1309,9 @@ pub fn printValue(...@@ -1309,9 +1309,9 @@ pub fn printValue(
1309 try w.writeAll(".{ .");1309 try w.writeAll(".{ .");
1310 try w.writeAll(@tagName(@as(UnionTagType, value)));1310 try w.writeAll(@tagName(@as(UnionTagType, value)));
1311 try w.writeAll(" = ");1311 try w.writeAll(" = ");
1312 inline for (info.fields) |u_field| {1312 inline for (info.field_names) |u_field_name| {
1313 if (value == @field(UnionTagType, 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);1314 try w.printValue(ANY, options, @field(value, u_field_name), max_depth - 1);
1315 }1315 }
1316 }1316 }
1317 try w.writeAll(" }");1317 try w.writeAll(" }");
...@@ -1320,14 +1320,14 @@ pub fn printValue(...@@ -1320,14 +1320,14 @@ pub fn printValue(
1320 return w.writeAll(".{ ... }");1320 return w.writeAll(".{ ... }");
1321 },1321 },
1322 .@"extern", .@"packed" => {1322 .@"extern", .@"packed" => {
1323 if (info.fields.len == 0) return w.writeAll(".{}");1323 if (info.field_names.len == 0) return w.writeAll(".{}");
1324 try w.writeAll(".{ ");1324 try w.writeAll(".{ ");
1325 inline for (info.fields, 1..) |field, i| {1325 inline for (info.field_names, 1..) |field_name, i| {
1326 try w.writeByte('.');1326 try w.writeByte('.');
1327 try w.writeAll(field.name);1327 try w.writeAll(field_name);
1328 try w.writeAll(" = ");1328 try w.writeAll(" = ");
1329 try w.printValue(ANY, options, @field(value, field.name), max_depth - 1);1329 try w.printValue(ANY, options, @field(value, field_name), max_depth - 1);
1330 try w.writeAll(if (i < info.fields.len) ", " else " }");1330 try w.writeAll(if (i < info.field_names.len) ", " else " }");
1331 }1331 }
1332 },1332 },
1333 }1333 }
...@@ -1344,13 +1344,13 @@ pub fn printValue(...@@ -1344,13 +1344,13 @@ pub fn printValue(
1344 return;1344 return;
1345 }1345 }
1346 try w.writeAll(".{");1346 try w.writeAll(".{");
1347 inline for (info.fields, 0..) |f, i| {1347 inline for (info.field_names, 0..) |f_name, i| {
1348 if (i == 0) {1348 if (i == 0) {
1349 try w.writeAll(" ");1349 try w.writeAll(" ");
1350 } else {1350 } else {
1351 try w.writeAll(", ");1351 try w.writeAll(", ");
1352 }1352 }
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);
1354 }1354 }
1355 try w.writeAll(" }");1355 try w.writeAll(" }");
1356 return;1356 return;
...@@ -1360,15 +1360,15 @@ pub fn printValue(...@@ -1360,15 +1360,15 @@ pub fn printValue(
1360 return;1360 return;
1361 }1361 }
1362 try w.writeAll(".{");1362 try w.writeAll(".{");
1363 inline for (info.fields, 0..) |f, i| {1363 inline for (info.field_names, 0..) |f_name, i| {
1364 if (i == 0) {1364 if (i == 0) {
1365 try w.writeAll(" .");1365 try w.writeAll(" .");
1366 } else {1366 } else {
1367 try w.writeAll(", .");1367 try w.writeAll(", .");
1368 }1368 }
1369 try w.writeAll(f.name);1369 try w.writeAll(f_name);
1370 try w.writeAll(" = ");1370 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);
1372 }1372 }
1373 try w.writeAll(" }");1373 try w.writeAll(" }");
1374 },1374 },
lib/std/Progress.zig+2-2
...@@ -867,8 +867,8 @@ const TreeSymbol = enum {...@@ -867,8 +867,8 @@ const TreeSymbol = enum {
867867
868 fn maxByteLen(symbol: TreeSymbol) usize {868 fn maxByteLen(symbol: TreeSymbol) usize {
869 var max: usize = 0;869 var max: usize = 0;
870 inline for (@typeInfo(Encoding).@"enum".fields) |field| {870 inline for (@typeInfo(Encoding).@"enum".field_names) |field_name| {
871 const len = symbol.bytes(@field(Encoding, field.name)).len;871 const len = symbol.bytes(@field(Encoding, field_name)).len;
872 max = @max(max, len);872 max = @max(max, len);
873 }873 }
874 return max;874 return max;
lib/std/Target.zig+4-4
...@@ -1764,10 +1764,10 @@ pub const Cpu = struct {...@@ -1764,10 +1764,10 @@ pub const Cpu = struct {
17641764
1765 fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model {1765 fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model {
1766 @setEvalBranchQuota(2000);1766 @setEvalBranchQuota(2000);
1767 const decls = @typeInfo(cpus).@"struct".decls;1767 const decl_names = @typeInfo(cpus).@"struct".decl_names;
1768 var array: [decls.len]*const Cpu.Model = undefined;1768 var array: [decl_names.len]*const Cpu.Model = undefined;
1769 for (decls, 0..) |decl, i| {1769 for (decl_names, 0..) |decl_name, i| {
1770 array[i] = &@field(cpus, decl.name);1770 array[i] = &@field(cpus, decl_name);
1771 }1771 }
1772 const finalized = array;1772 const finalized = array;
1773 return &finalized;1773 return &finalized;
lib/std/Target/aarch64.zig+2-2
...@@ -291,7 +291,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;...@@ -291,7 +291,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
291291
292pub const all_features = blk: {292pub const all_features = blk: {
293 @setEvalBranchQuota(2000);293 @setEvalBranchQuota(2000);
294 const len = @typeInfo(Feature).@"enum".fields.len;294 const len = @typeInfo(Feature).@"enum".field_names.len;
295 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);295 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
296 var result: [len]CpuFeature = undefined;296 var result: [len]CpuFeature = undefined;
297 result[@intFromEnum(Feature.a320)] = .{297 result[@intFromEnum(Feature.a320)] = .{
...@@ -2019,7 +2019,7 @@ pub const all_features = blk: {...@@ -2019,7 +2019,7 @@ pub const all_features = blk: {
2019 const ti = @typeInfo(Feature);2019 const ti = @typeInfo(Feature);
2020 for (&result, 0..) |*elem, i| {2020 for (&result, 0..) |*elem, i| {
2021 elem.index = i;2021 elem.index = i;
2022 elem.name = ti.@"enum".fields[i].name;2022 elem.name = ti.@"enum".field_names[i];
2023 }2023 }
2024 break :blk result;2024 break :blk result;
2025};2025};
lib/std/Target/alpha.zig+2-2
...@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
17pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;17pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1818
19pub const all_features = blk: {19pub const all_features = blk: {
20 const len = @typeInfo(Feature).@"enum".fields.len;20 const len = @typeInfo(Feature).@"enum".field_names.len;
21 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);21 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
22 var result: [len]CpuFeature = undefined;22 var result: [len]CpuFeature = undefined;
23 result[@intFromEnum(Feature.bwx)] = .{23 result[@intFromEnum(Feature.bwx)] = .{
...@@ -43,7 +43,7 @@ pub const all_features = blk: {...@@ -43,7 +43,7 @@ pub const all_features = blk: {
43 const ti = @typeInfo(Feature);43 const ti = @typeInfo(Feature);
44 for (&result, 0..) |*elem, i| {44 for (&result, 0..) |*elem, i| {
45 elem.index = i;45 elem.index = i;
46 elem.name = ti.@"enum".fields[i].name;46 elem.name = ti.@"enum".field_names[i];
47 }47 }
48 break :blk result;48 break :blk result;
49};49};
lib/std/Target/amdgcn.zig+2-2
...@@ -268,7 +268,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;...@@ -268,7 +268,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
268268
269pub const all_features = blk: {269pub const all_features = blk: {
270 @setEvalBranchQuota(2000);270 @setEvalBranchQuota(2000);
271 const len = @typeInfo(Feature).@"enum".fields.len;271 const len = @typeInfo(Feature).@"enum".field_names.len;
272 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);272 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
273 var result: [len]CpuFeature = undefined;273 var result: [len]CpuFeature = undefined;
274 result[@intFromEnum(Feature.@"1024_addressable_vgprs")] = .{274 result[@intFromEnum(Feature.@"1024_addressable_vgprs")] = .{
...@@ -1877,7 +1877,7 @@ pub const all_features = blk: {...@@ -1877,7 +1877,7 @@ pub const all_features = blk: {
1877 const ti = @typeInfo(Feature);1877 const ti = @typeInfo(Feature);
1878 for (&result, 0..) |*elem, i| {1878 for (&result, 0..) |*elem, i| {
1879 elem.index = i;1879 elem.index = i;
1880 elem.name = ti.@"enum".fields[i].name;1880 elem.name = ti.@"enum".field_names[i];
1881 }1881 }
1882 break :blk result;1882 break :blk result;
1883};1883};
lib/std/Target/arc.zig+2-2
...@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
14pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;14pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1515
16pub const all_features = blk: {16pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;17 const len = @typeInfo(Feature).@"enum".field_names.len;
18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
19 var result: [len]CpuFeature = undefined;19 var result: [len]CpuFeature = undefined;
20 result[@intFromEnum(Feature.norm)] = .{20 result[@intFromEnum(Feature.norm)] = .{
...@@ -25,7 +25,7 @@ pub const all_features = blk: {...@@ -25,7 +25,7 @@ pub const all_features = blk: {
25 const ti = @typeInfo(Feature);25 const ti = @typeInfo(Feature);
26 for (&result, 0..) |*elem, i| {26 for (&result, 0..) |*elem, i| {
27 elem.index = i;27 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;28 elem.name = ti.@"enum".field_names[i];
29 }29 }
30 break :blk result;30 break :blk result;
31};31};
lib/std/Target/arm.zig+2-2
...@@ -215,7 +215,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;...@@ -215,7 +215,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
215215
216pub const all_features = blk: {216pub const all_features = blk: {
217 @setEvalBranchQuota(10000);217 @setEvalBranchQuota(10000);
218 const len = @typeInfo(Feature).@"enum".fields.len;218 const len = @typeInfo(Feature).@"enum".field_names.len;
219 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);219 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
220 var result: [len]CpuFeature = undefined;220 var result: [len]CpuFeature = undefined;
221 result[@intFromEnum(Feature.@"32bit")] = .{221 result[@intFromEnum(Feature.@"32bit")] = .{
...@@ -1736,7 +1736,7 @@ pub const all_features = blk: {...@@ -1736,7 +1736,7 @@ pub const all_features = blk: {
1736 const ti = @typeInfo(Feature);1736 const ti = @typeInfo(Feature);
1737 for (&result, 0..) |*elem, i| {1737 for (&result, 0..) |*elem, i| {
1738 elem.index = i;1738 elem.index = i;
1739 elem.name = ti.@"enum".fields[i].name;1739 elem.name = ti.@"enum".field_names[i];
1740 }1740 }
1741 break :blk result;1741 break :blk result;
1742};1742};
lib/std/Target/avr.zig+2-2
...@@ -52,7 +52,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -52,7 +52,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
52pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;52pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
5353
54pub const all_features = blk: {54pub const all_features = blk: {
55 const len = @typeInfo(Feature).@"enum".fields.len;55 const len = @typeInfo(Feature).@"enum".field_names.len;
56 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);56 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
57 var result: [len]CpuFeature = undefined;57 var result: [len]CpuFeature = undefined;
58 result[@intFromEnum(Feature.addsubiw)] = .{58 result[@intFromEnum(Feature.addsubiw)] = .{
...@@ -388,7 +388,7 @@ pub const all_features = blk: {...@@ -388,7 +388,7 @@ pub const all_features = blk: {
388 const ti = @typeInfo(Feature);388 const ti = @typeInfo(Feature);
389 for (&result, 0..) |*elem, i| {389 for (&result, 0..) |*elem, i| {
390 elem.index = i;390 elem.index = i;
391 elem.name = ti.@"enum".fields[i].name;391 elem.name = ti.@"enum".field_names[i];
392 }392 }
393 break :blk result;393 break :blk result;
394};394};
lib/std/Target/bpf.zig+2-2
...@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
17pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;17pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1818
19pub const all_features = blk: {19pub const all_features = blk: {
20 const len = @typeInfo(Feature).@"enum".fields.len;20 const len = @typeInfo(Feature).@"enum".field_names.len;
21 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);21 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
22 var result: [len]CpuFeature = undefined;22 var result: [len]CpuFeature = undefined;
23 result[@intFromEnum(Feature.allows_misaligned_mem_access)] = .{23 result[@intFromEnum(Feature.allows_misaligned_mem_access)] = .{
...@@ -43,7 +43,7 @@ pub const all_features = blk: {...@@ -43,7 +43,7 @@ pub const all_features = blk: {
43 const ti = @typeInfo(Feature);43 const ti = @typeInfo(Feature);
44 for (&result, 0..) |*elem, i| {44 for (&result, 0..) |*elem, i| {
45 elem.index = i;45 elem.index = i;
46 elem.name = ti.@"enum".fields[i].name;46 elem.name = ti.@"enum".field_names[i];
47 }47 }
48 break :blk result;48 break :blk result;
49};49};
lib/std/Target/csky.zig+2-2
...@@ -76,7 +76,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -76,7 +76,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
76pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;76pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
7777
78pub const all_features = blk: {78pub const all_features = blk: {
79 const len = @typeInfo(Feature).@"enum".fields.len;79 const len = @typeInfo(Feature).@"enum".field_names.len;
80 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);80 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
81 var result: [len]CpuFeature = undefined;81 var result: [len]CpuFeature = undefined;
82 result[@intFromEnum(Feature.@"10e60")] = .{82 result[@intFromEnum(Feature.@"10e60")] = .{
...@@ -418,7 +418,7 @@ pub const all_features = blk: {...@@ -418,7 +418,7 @@ pub const all_features = blk: {
418 const ti = @typeInfo(Feature);418 const ti = @typeInfo(Feature);
419 for (&result, 0..) |*elem, i| {419 for (&result, 0..) |*elem, i| {
420 elem.index = i;420 elem.index = i;
421 elem.name = ti.@"enum".fields[i].name;421 elem.name = ti.@"enum".field_names[i];
422 }422 }
423 break :blk result;423 break :blk result;
424};424};
lib/std/Target/hexagon.zig+2-2
...@@ -60,7 +60,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -60,7 +60,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
60pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;60pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
6161
62pub const all_features = blk: {62pub const all_features = blk: {
63 const len = @typeInfo(Feature).@"enum".fields.len;63 const len = @typeInfo(Feature).@"enum".field_names.len;
64 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);64 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
65 var result: [len]CpuFeature = undefined;65 var result: [len]CpuFeature = undefined;
66 result[@intFromEnum(Feature.audio)] = .{66 result[@intFromEnum(Feature.audio)] = .{
...@@ -334,7 +334,7 @@ pub const all_features = blk: {...@@ -334,7 +334,7 @@ pub const all_features = blk: {
334 const ti = @typeInfo(Feature);334 const ti = @typeInfo(Feature);
335 for (&result, 0..) |*elem, i| {335 for (&result, 0..) |*elem, i| {
336 elem.index = i;336 elem.index = i;
337 elem.name = ti.@"enum".fields[i].name;337 elem.name = ti.@"enum".field_names[i];
338 }338 }
339 break :blk result;339 break :blk result;
340};340};
lib/std/Target/hppa.zig+2-2
...@@ -18,7 +18,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -18,7 +18,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
18pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;18pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1919
20pub const all_features = blk: {20pub const all_features = blk: {
21 const len = @typeInfo(Feature).@"enum".fields.len;21 const len = @typeInfo(Feature).@"enum".field_names.len;
22 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);22 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
23 var result: [len]CpuFeature = undefined;23 var result: [len]CpuFeature = undefined;
24 result[@intFromEnum(Feature.@"64bit")] = .{24 result[@intFromEnum(Feature.@"64bit")] = .{
...@@ -56,7 +56,7 @@ pub const all_features = blk: {...@@ -56,7 +56,7 @@ pub const all_features = blk: {
56 const ti = @typeInfo(Feature);56 const ti = @typeInfo(Feature);
57 for (&result, 0..) |*elem, i| {57 for (&result, 0..) |*elem, i| {
58 elem.index = i;58 elem.index = i;
59 elem.name = ti.@"enum".fields[i].name;59 elem.name = ti.@"enum".field_names[i];
60 }60 }
61 break :blk result;61 break :blk result;
62};62};
lib/std/Target/kvx.zig+2-2
...@@ -16,7 +16,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -16,7 +16,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
16pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;16pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1717
18pub const all_features = blk: {18pub const all_features = blk: {
19 const len = @typeInfo(Feature).@"enum".fields.len;19 const len = @typeInfo(Feature).@"enum".field_names.len;
20 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);20 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
21 var result: [len]CpuFeature = undefined;21 var result: [len]CpuFeature = undefined;
22 result[@intFromEnum(Feature.v3_1)] = .{22 result[@intFromEnum(Feature.v3_1)] = .{
...@@ -41,7 +41,7 @@ pub const all_features = blk: {...@@ -41,7 +41,7 @@ pub const all_features = blk: {
41 const ti = @typeInfo(Feature);41 const ti = @typeInfo(Feature);
42 for (&result, 0..) |*elem, i| {42 for (&result, 0..) |*elem, i| {
43 elem.index = i;43 elem.index = i;
44 elem.name = ti.@"enum".fields[i].name;44 elem.name = ti.@"enum".field_names[i];
45 }45 }
46 break :blk result;46 break :blk result;
47};47};
lib/std/Target/lanai.zig+2-2
...@@ -12,13 +12,13 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -12,13 +12,13 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
12pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;12pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1313
14pub const all_features = blk: {14pub const all_features = blk: {
15 const len = @typeInfo(Feature).@"enum".fields.len;15 const len = @typeInfo(Feature).@"enum".field_names.len;
16 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);16 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
17 var result: [len]CpuFeature = undefined;17 var result: [len]CpuFeature = undefined;
18 const ti = @typeInfo(Feature);18 const ti = @typeInfo(Feature);
19 for (&result, 0..) |*elem, i| {19 for (&result, 0..) |*elem, i| {
20 elem.index = i;20 elem.index = i;
21 elem.name = ti.@"enum".fields[i].name;21 elem.name = ti.@"enum".field_names[i];
22 }22 }
23 break :blk result;23 break :blk result;
24};24};
lib/std/Target/loongarch.zig+2-2
...@@ -34,7 +34,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -34,7 +34,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
34pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;34pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
3535
36pub const all_features = blk: {36pub const all_features = blk: {
37 const len = @typeInfo(Feature).@"enum".fields.len;37 const len = @typeInfo(Feature).@"enum".field_names.len;
38 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);38 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
39 var result: [len]CpuFeature = undefined;39 var result: [len]CpuFeature = undefined;
40 result[@intFromEnum(Feature.@"32bit")] = .{40 result[@intFromEnum(Feature.@"32bit")] = .{
...@@ -153,7 +153,7 @@ pub const all_features = blk: {...@@ -153,7 +153,7 @@ pub const all_features = blk: {
153 const ti = @typeInfo(Feature);153 const ti = @typeInfo(Feature);
154 for (&result, 0..) |*elem, i| {154 for (&result, 0..) |*elem, i| {
155 elem.index = i;155 elem.index = i;
156 elem.name = ti.@"enum".fields[i].name;156 elem.name = ti.@"enum".field_names[i];
157 }157 }
158 break :blk result;158 break :blk result;
159};159};
lib/std/Target/m68k.zig+2-2
...@@ -36,7 +36,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -36,7 +36,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
36pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;36pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
3737
38pub const all_features = blk: {38pub const all_features = blk: {
39 const len = @typeInfo(Feature).@"enum".fields.len;39 const len = @typeInfo(Feature).@"enum".field_names.len;
40 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);40 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
41 var result: [len]CpuFeature = undefined;41 var result: [len]CpuFeature = undefined;
42 result[@intFromEnum(Feature.isa_68000)] = .{42 result[@intFromEnum(Feature.isa_68000)] = .{
...@@ -170,7 +170,7 @@ pub const all_features = blk: {...@@ -170,7 +170,7 @@ pub const all_features = blk: {
170 const ti = @typeInfo(Feature);170 const ti = @typeInfo(Feature);
171 for (&result, 0..) |*elem, i| {171 for (&result, 0..) |*elem, i| {
172 elem.index = i;172 elem.index = i;
173 elem.name = ti.@"enum".fields[i].name;173 elem.name = ti.@"enum".field_names[i];
174 }174 }
175 break :blk result;175 break :blk result;
176};176};
lib/std/Target/mips.zig+2-2
...@@ -70,7 +70,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -70,7 +70,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
70pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;70pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
7171
72pub const all_features = blk: {72pub const all_features = blk: {
73 const len = @typeInfo(Feature).@"enum".fields.len;73 const len = @typeInfo(Feature).@"enum".field_names.len;
74 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);74 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
75 var result: [len]CpuFeature = undefined;75 var result: [len]CpuFeature = undefined;
76 result[@intFromEnum(Feature.abs2008)] = .{76 result[@intFromEnum(Feature.abs2008)] = .{
...@@ -425,7 +425,7 @@ pub const all_features = blk: {...@@ -425,7 +425,7 @@ pub const all_features = blk: {
425 const ti = @typeInfo(Feature);425 const ti = @typeInfo(Feature);
426 for (&result, 0..) |*elem, i| {426 for (&result, 0..) |*elem, i| {
427 elem.index = i;427 elem.index = i;
428 elem.name = ti.@"enum".fields[i].name;428 elem.name = ti.@"enum".field_names[i];
429 }429 }
430 break :blk result;430 break :blk result;
431};431};
lib/std/Target/msp430.zig+2-2
...@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -17,7 +17,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
17pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;17pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1818
19pub const all_features = blk: {19pub const all_features = blk: {
20 const len = @typeInfo(Feature).@"enum".fields.len;20 const len = @typeInfo(Feature).@"enum".field_names.len;
21 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);21 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
22 var result: [len]CpuFeature = undefined;22 var result: [len]CpuFeature = undefined;
23 result[@intFromEnum(Feature.ext)] = .{23 result[@intFromEnum(Feature.ext)] = .{
...@@ -43,7 +43,7 @@ pub const all_features = blk: {...@@ -43,7 +43,7 @@ pub const all_features = blk: {
43 const ti = @typeInfo(Feature);43 const ti = @typeInfo(Feature);
44 for (&result, 0..) |*elem, i| {44 for (&result, 0..) |*elem, i| {
45 elem.index = i;45 elem.index = i;
46 elem.name = ti.@"enum".fields[i].name;46 elem.name = ti.@"enum".field_names[i];
47 }47 }
48 break :blk result;48 break :blk result;
49};49};
lib/std/Target/nvptx.zig+2-2
...@@ -84,7 +84,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -84,7 +84,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
84pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;84pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
8585
86pub const all_features = blk: {86pub const all_features = blk: {
87 const len = @typeInfo(Feature).@"enum".fields.len;87 const len = @typeInfo(Feature).@"enum".field_names.len;
88 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);88 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
89 var result: [len]CpuFeature = undefined;89 var result: [len]CpuFeature = undefined;
90 result[@intFromEnum(Feature.ptx32)] = .{90 result[@intFromEnum(Feature.ptx32)] = .{
...@@ -445,7 +445,7 @@ pub const all_features = blk: {...@@ -445,7 +445,7 @@ pub const all_features = blk: {
445 const ti = @typeInfo(Feature);445 const ti = @typeInfo(Feature);
446 for (&result, 0..) |*elem, i| {446 for (&result, 0..) |*elem, i| {
447 elem.index = i;447 elem.index = i;
448 elem.name = ti.@"enum".fields[i].name;448 elem.name = ti.@"enum".field_names[i];
449 }449 }
450 break :blk result;450 break :blk result;
451};451};
lib/std/Target/powerpc.zig+2-2
...@@ -93,7 +93,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -93,7 +93,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
93pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;93pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
9494
95pub const all_features = blk: {95pub const all_features = blk: {
96 const len = @typeInfo(Feature).@"enum".fields.len;96 const len = @typeInfo(Feature).@"enum".field_names.len;
97 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);97 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
98 var result: [len]CpuFeature = undefined;98 var result: [len]CpuFeature = undefined;
99 result[@intFromEnum(Feature.@"64bit")] = .{99 result[@intFromEnum(Feature.@"64bit")] = .{
...@@ -595,7 +595,7 @@ pub const all_features = blk: {...@@ -595,7 +595,7 @@ pub const all_features = blk: {
595 const ti = @typeInfo(Feature);595 const ti = @typeInfo(Feature);
596 for (&result, 0..) |*elem, i| {596 for (&result, 0..) |*elem, i| {
597 elem.index = i;597 elem.index = i;
598 elem.name = ti.@"enum".fields[i].name;598 elem.name = ti.@"enum".field_names[i];
599 }599 }
600 break :blk result;600 break :blk result;
601};601};
lib/std/Target/propeller.zig+2-2
...@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
14pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;14pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1515
16pub const all_features = blk: {16pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;17 const len = @typeInfo(Feature).@"enum".field_names.len;
18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
19 var result: [len]CpuFeature = undefined;19 var result: [len]CpuFeature = undefined;
20 result[@intFromEnum(Feature.p2)] = .{20 result[@intFromEnum(Feature.p2)] = .{
...@@ -25,7 +25,7 @@ pub const all_features = blk: {...@@ -25,7 +25,7 @@ pub const all_features = blk: {
25 const ti = @typeInfo(Feature);25 const ti = @typeInfo(Feature);
26 for (&result, 0..) |*elem, i| {26 for (&result, 0..) |*elem, i| {
27 elem.index = i;27 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;28 elem.name = ti.@"enum".field_names[i];
29 }29 }
30 break :blk result;30 break :blk result;
31};31};
lib/std/Target/riscv.zig+2-2
...@@ -361,7 +361,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;...@@ -361,7 +361,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
361361
362pub const all_features = blk: {362pub const all_features = blk: {
363 @setEvalBranchQuota(2000);363 @setEvalBranchQuota(2000);
364 const len = @typeInfo(Feature).@"enum".fields.len;364 const len = @typeInfo(Feature).@"enum".field_names.len;
365 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);365 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
366 var result: [len]CpuFeature = undefined;366 var result: [len]CpuFeature = undefined;
367 result[@intFromEnum(Feature.@"32bit")] = .{367 result[@intFromEnum(Feature.@"32bit")] = .{
...@@ -2675,7 +2675,7 @@ pub const all_features = blk: {...@@ -2675,7 +2675,7 @@ pub const all_features = blk: {
2675 const ti = @typeInfo(Feature);2675 const ti = @typeInfo(Feature);
2676 for (&result, 0..) |*elem, i| {2676 for (&result, 0..) |*elem, i| {
2677 elem.index = i;2677 elem.index = i;
2678 elem.name = ti.@"enum".fields[i].name;2678 elem.name = ti.@"enum".field_names[i];
2679 }2679 }
2680 break :blk result;2680 break :blk result;
2681};2681};
lib/std/Target/s390x.zig+2-2
...@@ -62,7 +62,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -62,7 +62,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
62pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;62pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
6363
64pub const all_features = blk: {64pub const all_features = blk: {
65 const len = @typeInfo(Feature).@"enum".fields.len;65 const len = @typeInfo(Feature).@"enum".field_names.len;
66 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);66 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
67 var result: [len]CpuFeature = undefined;67 var result: [len]CpuFeature = undefined;
68 result[@intFromEnum(Feature.backchain)] = .{68 result[@intFromEnum(Feature.backchain)] = .{
...@@ -313,7 +313,7 @@ pub const all_features = blk: {...@@ -313,7 +313,7 @@ pub const all_features = blk: {
313 const ti = @typeInfo(Feature);313 const ti = @typeInfo(Feature);
314 for (&result, 0..) |*elem, i| {314 for (&result, 0..) |*elem, i| {
315 elem.index = i;315 elem.index = i;
316 elem.name = ti.@"enum".fields[i].name;316 elem.name = ti.@"enum".field_names[i];
317 }317 }
318 break :blk result;318 break :blk result;
319};319};
lib/std/Target/sparc.zig+2-2
...@@ -72,7 +72,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -72,7 +72,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
72pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;72pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
7373
74pub const all_features = blk: {74pub const all_features = blk: {
75 const len = @typeInfo(Feature).@"enum".fields.len;75 const len = @typeInfo(Feature).@"enum".field_names.len;
76 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);76 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
77 var result: [len]CpuFeature = undefined;77 var result: [len]CpuFeature = undefined;
78 result[@intFromEnum(Feature.@"64bit")] = .{78 result[@intFromEnum(Feature.@"64bit")] = .{
...@@ -395,7 +395,7 @@ pub const all_features = blk: {...@@ -395,7 +395,7 @@ pub const all_features = blk: {
395 const ti = @typeInfo(Feature);395 const ti = @typeInfo(Feature);
396 for (&result, 0..) |*elem, i| {396 for (&result, 0..) |*elem, i| {
397 elem.index = i;397 elem.index = i;
398 elem.name = ti.@"enum".fields[i].name;398 elem.name = ti.@"enum".field_names[i];
399 }399 }
400 break :blk result;400 break :blk result;
401};401};
lib/std/Target/spirv.zig+2-2
...@@ -29,7 +29,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;...@@ -29,7 +29,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
2929
30pub const all_features = blk: {30pub const all_features = blk: {
31 @setEvalBranchQuota(2000);31 @setEvalBranchQuota(2000);
32 const len = @typeInfo(Feature).@"enum".fields.len;32 const len = @typeInfo(Feature).@"enum".field_names.len;
33 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);33 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
34 var result: [len]CpuFeature = undefined;34 var result: [len]CpuFeature = undefined;
35 result[@intFromEnum(Feature.arbitrary_precision_integers)] = .{35 result[@intFromEnum(Feature.arbitrary_precision_integers)] = .{
...@@ -138,7 +138,7 @@ pub const all_features = blk: {...@@ -138,7 +138,7 @@ pub const all_features = blk: {
138 const ti = @typeInfo(Feature);138 const ti = @typeInfo(Feature);
139 for (&result, 0..) |*elem, i| {139 for (&result, 0..) |*elem, i| {
140 elem.index = i;140 elem.index = i;
141 elem.name = ti.@"enum".fields[i].name;141 elem.name = ti.@"enum".field_names[i];
142 }142 }
143 break :blk result;143 break :blk result;
144};144};
lib/std/Target/ve.zig+2-2
...@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -14,7 +14,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
14pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;14pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1515
16pub const all_features = blk: {16pub const all_features = blk: {
17 const len = @typeInfo(Feature).@"enum".fields.len;17 const len = @typeInfo(Feature).@"enum".field_names.len;
18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);18 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
19 var result: [len]CpuFeature = undefined;19 var result: [len]CpuFeature = undefined;
20 result[@intFromEnum(Feature.vpu)] = .{20 result[@intFromEnum(Feature.vpu)] = .{
...@@ -25,7 +25,7 @@ pub const all_features = blk: {...@@ -25,7 +25,7 @@ pub const all_features = blk: {
25 const ti = @typeInfo(Feature);25 const ti = @typeInfo(Feature);
26 for (&result, 0..) |*elem, i| {26 for (&result, 0..) |*elem, i| {
27 elem.index = i;27 elem.index = i;
28 elem.name = ti.@"enum".fields[i].name;28 elem.name = ti.@"enum".field_names[i];
29 }29 }
30 break :blk result;30 break :blk result;
31};31};
lib/std/Target/wasm.zig+2-2
...@@ -32,7 +32,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -32,7 +32,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
32pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;32pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
3333
34pub const all_features = blk: {34pub const all_features = blk: {
35 const len = @typeInfo(Feature).@"enum".fields.len;35 const len = @typeInfo(Feature).@"enum".field_names.len;
36 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);36 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
37 var result: [len]CpuFeature = undefined;37 var result: [len]CpuFeature = undefined;
38 result[@intFromEnum(Feature.atomics)] = .{38 result[@intFromEnum(Feature.atomics)] = .{
...@@ -139,7 +139,7 @@ pub const all_features = blk: {...@@ -139,7 +139,7 @@ pub const all_features = blk: {
139 const ti = @typeInfo(Feature);139 const ti = @typeInfo(Feature);
140 for (&result, 0..) |*elem, i| {140 for (&result, 0..) |*elem, i| {
141 elem.index = i;141 elem.index = i;
142 elem.name = ti.@"enum".fields[i].name;142 elem.name = ti.@"enum".field_names[i];
143 }143 }
144 break :blk result;144 break :blk result;
145};145};
lib/std/Target/x86.zig+2-2
...@@ -215,7 +215,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -215,7 +215,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
215pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;215pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
216216
217pub const all_features = blk: {217pub const all_features = blk: {
218 const len = @typeInfo(Feature).@"enum".fields.len;218 const len = @typeInfo(Feature).@"enum".field_names.len;
219 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);219 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
220 var result: [len]CpuFeature = undefined;220 var result: [len]CpuFeature = undefined;
221 result[@intFromEnum(Feature.@"16bit_mode")] = .{221 result[@intFromEnum(Feature.@"16bit_mode")] = .{
...@@ -1374,7 +1374,7 @@ pub const all_features = blk: {...@@ -1374,7 +1374,7 @@ pub const all_features = blk: {
1374 const ti = @typeInfo(Feature);1374 const ti = @typeInfo(Feature);
1375 for (&result, 0..) |*elem, i| {1375 for (&result, 0..) |*elem, i| {
1376 elem.index = i;1376 elem.index = i;
1377 elem.name = ti.@"enum".fields[i].name;1377 elem.name = ti.@"enum".field_names[i];
1378 }1378 }
1379 break :blk result;1379 break :blk result;
1380};1380};
lib/std/Target/xcore.zig+2-2
...@@ -12,13 +12,13 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -12,13 +12,13 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
12pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;12pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
1313
14pub const all_features = blk: {14pub const all_features = blk: {
15 const len = @typeInfo(Feature).@"enum".fields.len;15 const len = @typeInfo(Feature).@"enum".field_names.len;
16 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);16 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
17 var result: [len]CpuFeature = undefined;17 var result: [len]CpuFeature = undefined;
18 const ti = @typeInfo(Feature);18 const ti = @typeInfo(Feature);
19 for (&result, 0..) |*elem, i| {19 for (&result, 0..) |*elem, i| {
20 elem.index = i;20 elem.index = i;
21 elem.name = ti.@"enum".fields[i].name;21 elem.name = ti.@"enum".field_names[i];
22 }22 }
23 break :blk result;23 break :blk result;
24};24};
lib/std/Target/xtensa.zig+2-2
...@@ -50,7 +50,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;...@@ -50,7 +50,7 @@ pub const featureSetHasAny = CpuFeature.FeatureSetFns(Feature).featureSetHasAny;
50pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;50pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll;
5151
52pub const all_features = blk: {52pub const all_features = blk: {
53 const len = @typeInfo(Feature).@"enum".fields.len;53 const len = @typeInfo(Feature).@"enum".field_names.len;
54 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);54 std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
55 var result: [len]CpuFeature = undefined;55 var result: [len]CpuFeature = undefined;
56 result[@intFromEnum(Feature.bool)] = .{56 result[@intFromEnum(Feature.bool)] = .{
...@@ -251,7 +251,7 @@ pub const all_features = blk: {...@@ -251,7 +251,7 @@ pub const all_features = blk: {
251 const ti = @typeInfo(Feature);251 const ti = @typeInfo(Feature);
252 for (&result, 0..) |*elem, i| {252 for (&result, 0..) |*elem, i| {
253 elem.index = i;253 elem.index = i;
254 elem.name = ti.@"enum".fields[i].name;254 elem.name = ti.@"enum".field_names[i];
255 }255 }
256 break :blk result;256 break :blk result;
257};257};
lib/std/c/darwin.zig+1-1
...@@ -54,7 +54,7 @@ pub const EXC = enum(exception_type_t) {...@@ -54,7 +54,7 @@ pub const EXC = enum(exception_type_t) {
5454
55 _,55 _,
5656
57 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len;57 pub const TYPES_COUNT = @typeInfo(EXC).@"enum".field_names.len;
58 pub const SOFT_SIGNAL = 0x10003;58 pub const SOFT_SIGNAL = 0x10003;
5959
60 pub const MASK = packed struct(u32) {60 pub const MASK = packed struct(u32) {
lib/std/coff.zig+1-1
...@@ -1386,7 +1386,7 @@ pub const IMAGE = struct {...@@ -1386,7 +1386,7 @@ pub const IMAGE = struct {
1386 RESERVED = 15,1386 RESERVED = 15,
1387 _,1387 _,
13881388
1389 pub const len = @typeInfo(IMAGE.DIRECTORY_ENTRY).@"enum".fields.len;1389 pub const len = @typeInfo(IMAGE.DIRECTORY_ENTRY).@"enum".field_names.len;
1390 };1390 };
13911391
1392 pub const FILE = struct {1392 pub const FILE = struct {
lib/std/crypto/codecs/asn1/Oid.zig+8-8
...@@ -177,27 +177,27 @@ pub fn StaticMap(comptime Enum: type) type {...@@ -177,27 +177,27 @@ pub fn StaticMap(comptime Enum: type) type {
177 pub fn initComptime(comptime key_pairs: anytype) ReturnType {177 pub fn initComptime(comptime key_pairs: anytype) ReturnType {
178 const struct_info = @typeInfo(@TypeOf(key_pairs)).@"struct";178 const struct_info = @typeInfo(@TypeOf(key_pairs)).@"struct";
179 const error_msg = "Each field of '" ++ @typeName(Enum) ++ "' must map to exactly one OID";179 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) {
181 @compileError(error_msg);181 @compileError(error_msg);
182 }182 }
183183
184 comptime var enum_to_oid = EnumToOid.initUndefined();184 comptime var enum_to_oid = EnumToOid.initUndefined();
185185
186 const KeyPair = struct { []const u8, Enum };186 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| {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)) {190 if (!@hasField(@TypeOf(key_pairs), f_name)) {
191 @compileError("Field '" ++ f.name ++ "' missing Oid.StaticMap entry");191 @compileError("Field '" ++ f_name ++ "' missing Oid.StaticMap entry");
192 }192 }
193 const encoded = &encodeComptime(@field(key_pairs, f.name));193 const encoded = &encodeComptime(@field(key_pairs, f_name));
194 const tag: Enum = @enumFromInt(f.value);194 const tag: Enum = @enumFromInt(f_value);
195 static_key_pairs[i] = .{ encoded, tag };195 static_key_pairs[i] = .{ encoded, tag };
196 enum_to_oid.set(tag, encoded);196 enum_to_oid.set(tag, encoded);
197 };197 };
198198
199 const oid_to_enum = std.StaticStringMap(Enum).initComptime(static_key_pairs);199 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
202 return ReturnType{ .oid_to_enum = oid_to_enum, .enum_to_oid = enum_to_oid };202 return ReturnType{ .oid_to_enum = oid_to_enum, .enum_to_oid = enum_to_oid };
203 }203 }
lib/std/crypto/codecs/asn1/der/Decoder.zig+7-7
...@@ -19,14 +19,14 @@ pub fn any(self: *Decoder, comptime T: type) !T {...@@ -19,14 +19,14 @@ pub fn any(self: *Decoder, comptime T: type) !T {
1919
20 const tag = Tag.fromZig(T).toExpected();20 const tag = Tag.fromZig(T).toExpected();
21 switch (@typeInfo(T)) {21 switch (@typeInfo(T)) {
22 .@"struct" => {22 .@"struct" => |info| {
23 const ele = try self.element(tag);23 const ele = try self.element(tag);
24 defer self.index = ele.slice.end; // don't force parsing all fields24 defer self.index = ele.slice.end; // don't force parsing all fields
2525
26 var res: T = undefined;26 var res: T = undefined;
2727
28 inline for (std.meta.fields(T)) |f| {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);29 self.field_tag = FieldTag.fromContainer(T, f_name);
3030
31 if (self.field_tag) |ft| {31 if (self.field_tag) |ft| {
32 if (ft.explicit) {32 if (ft.explicit) {
...@@ -36,15 +36,15 @@ pub fn any(self: *Decoder, comptime T: type) !T {...@@ -36,15 +36,15 @@ pub fn any(self: *Decoder, comptime T: type) !T {
36 }36 }
37 }37 }
3838
39 @field(res, f.name) = self.any(f.type) catch |err| brk: {39 @field(res, f_name) = self.any(f_type) catch |err| brk: {
40 if (f.defaultValue()) |d| {40 if (f_attrs.defaultValue(f_type)) |d| {
41 break :brk d;41 break :brk d;
42 }42 }
43 return err;43 return err;
44 };44 };
45 // DER encodes null values by skipping them.45 // DER encodes null values by skipping them.
46 if (@typeInfo(f.type) == .optional and @field(res, f.name) == null) {46 if (@typeInfo(f_type) == .optional and @field(res, f_name) == null) {
47 if (f.defaultValue()) |d| @field(res, f.name) = d;47 if (f_attrs.defaultValue(f_type)) |d| @field(res, f_name) = d;
48 }48 }
49 }49 }
5050
lib/std/crypto/codecs/asn1/der/Encoder.zig+10-8
...@@ -29,16 +29,18 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {...@@ -29,16 +29,18 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
2929
30 switch (@typeInfo(T)) {30 switch (@typeInfo(T)) {
31 .@"struct" => |info| {31 .@"struct" => |info| {
32 inline for (0..info.fields.len) |i| {32 inline for (0..info.field_names.len) |i| {
33 const f = info.fields[info.fields.len - i - 1];33 const f_idx = info.field_names.len - i - 1;
34 const field_val = @field(val, f.name);34 const f_name = info.field_names[f_idx];
35 const field_tag = FieldTag.fromContainer(T, f.name);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
37 // > The encoding of a set value or sequence value shall not include an encoding for any40 // > The encoding of a set value or sequence value shall not include an encoding for any
38 // > component value which is equal to its default value.41 // > 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: {42 const is_default = if (f_attrs.@"comptime") false else if (f_attrs.defaultValue(f_type)) |default_val| brk: {
40 const default_val: *const f.type = @ptrCast(@alignCast(v));43 break :brk std.mem.eql(u8, std.mem.asBytes(&default_val), std.mem.asBytes(&field_val));
41 break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val));
42 } else false;44 } else false;
4345
44 if (!is_default) {46 if (!is_default) {
...@@ -46,7 +48,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {...@@ -46,7 +48,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
46 self.field_tag = field_tag;48 self.field_tag = field_tag;
47 // will merge with self.field_tag.49 // will merge with self.field_tag.
48 // may mutate self.field_tag.50 // 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);
50 if (field_tag) |ft| {52 if (field_tag) |ft| {
51 if (ft.explicit) {53 if (ft.explicit) {
52 try self.length(self.buffer.data.len - start2);54 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...@@ -115,22 +115,23 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
115 while (it_params.next()) |params| {115 while (it_params.next()) |params| {
116 const param = kvSplit(params) catch break;116 const param = kvSplit(params) catch break;
117 var found = false;117 var found = false;
118 inline for (comptime meta.fields(HashResult)) |p| {118 const info = @typeInfo(HashResult).@"struct";
119 if (mem.eql(u8, p.name, param.key)) {119 inline for (info.field_names, info.field_types) |p_name, p_type| {
120 switch (@typeInfo(p.type)) {120 if (mem.eql(u8, p_name, param.key)) {
121 .int => @field(out, p.name) = fmt.parseUnsigned(121 switch (@typeInfo(p_type)) {
122 p.type,122 .int => @field(out, p_name) = fmt.parseUnsigned(
123 p_type,
123 param.value,124 param.value,
124 10,125 10,
125 ) catch return Error.InvalidEncoding,126 ) catch return Error.InvalidEncoding,
126 .pointer => |ptr| {127 .pointer => |ptr| {
127 if (!ptr.is_const) @compileError("Value slice must be constant");128 if (!ptr.attrs.@"const") @compileError("Value slice must be constant");
128 @field(out, p.name) = param.value;129 @field(out, p_name) = param.value;
129 },130 },
130 .@"struct" => try @field(out, p.name).fromB64(param.value),131 .@"struct" => try @field(out, p_name).fromB64(param.value),
131 else => std.debug.panic(132 else => std.debug.panic(
132 "Value for [{s}] must be an integer, a constant slice or a BinValue",133 "Value for [{s}] must be an integer, a constant slice or a BinValue",
133 .{p.name},134 .{p_name},
134 ),135 ),
135 }136 }
136 set_fields += 1;137 set_fields += 1;
...@@ -167,8 +168,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult...@@ -167,8 +168,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
167 // Check that all the required fields have been set, excluding optional values and parameters168 // Check that all the required fields have been set, excluding optional values and parameters
168 // with default values169 // with default values
169 var expected_fields: usize = 0;170 var expected_fields: usize = 0;
170 inline for (comptime meta.fields(HashResult)) |p| {171 const info = @typeInfo(HashResult).@"struct";
171 if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) {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) {
172 expected_fields += 1;174 expected_fields += 1;
173 }175 }
174 }176 }
...@@ -228,21 +230,22 @@ fn serializeTo(params: anytype, out: *std.Io.Writer) !void {...@@ -228,21 +230,22 @@ fn serializeTo(params: anytype, out: *std.Io.Writer) !void {
228 }230 }
229231
230 var has_params = false;232 var has_params = false;
231 inline for (comptime meta.fields(HashResult)) |p| {233 const info = @typeInfo(HashResult).@"struct";
232 if (comptime !(mem.eql(u8, p.name, "alg_id") or234 inline for (info.field_names, info.field_types) |p_name, p_type| {
233 mem.eql(u8, p.name, "alg_version") or235 if (comptime !(mem.eql(u8, p_name, "alg_id") or
234 mem.eql(u8, p.name, "hash") or236 mem.eql(u8, p_name, "alg_version") or
235 mem.eql(u8, p.name, "salt")))237 mem.eql(u8, p_name, "hash") or
238 mem.eql(u8, p_name, "salt")))
236 {239 {
237 const value = @field(params, p.name);240 const value = @field(params, p_name);
238 try out.writeAll(if (has_params) params_delimiter else fields_delimiter);241 try out.writeAll(if (has_params) params_delimiter else fields_delimiter);
239 if (@typeInfo(p.type) == .@"struct") {242 if (@typeInfo(p_type) == .@"struct") {
240 var buf: [@TypeOf(value).max_encoded_length]u8 = undefined;243 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) });
242 } else {245 } else {
243 try out.print(246 try out.print(
244 if (@typeInfo(@TypeOf(value)) == .pointer) "{s}{s}{s}" else "{s}{s}{}",247 if (@typeInfo(@TypeOf(value)) == .pointer) "{s}{s}{s}" else "{s}{s}{}",
245 .{ p.name, kv_delimiter, value },248 .{ p_name, kv_delimiter, value },
246 );249 );
247 }250 }
248 has_params = true;251 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...@@ -135,7 +135,7 @@ fn markSecret(ptr: anytype, comptime action: enum { classify, declassify }) void
135 const t = @typeInfo(@TypeOf(ptr));135 const t = @typeInfo(@TypeOf(ptr));
136 if (t != .pointer) @compileError("Pointer expected - Found: " ++ @typeName(@TypeOf(ptr)));136 if (t != .pointer) @compileError("Pointer expected - Found: " ++ @typeName(@TypeOf(ptr)));
137 const p = t.pointer;137 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");
139 const child = @typeInfo(p.child);139 const child = @typeInfo(p.child);
140140
141 switch (child) {141 switch (child) {
lib/std/crypto/tls.zig+1-1
...@@ -710,7 +710,7 @@ pub const Decoder = struct {...@@ -710,7 +710,7 @@ pub const Decoder = struct {
710 else => @compileError("unsupported int type: " ++ @typeName(T)),710 else => @compileError("unsupported int type: " ++ @typeName(T)),
711 },711 },
712 .@"enum" => |info| {712 .@"enum" => |info| {
713 if (info.is_exhaustive) @compileError("exhaustive enum cannot be used");713 if (info.mode == .exhaustive) @compileError("exhaustive enum cannot be used");
714 return @enumFromInt(d.decode(info.tag_type));714 return @enumFromInt(d.decode(info.tag_type));
715 },715 },
716 else => @compileError("unsupported type: " ++ @typeName(T)),716 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} {...@@ -1338,11 +1338,11 @@ fn failRead(c: *Client, err: ReadError) error{ReadFailed} {
1338}1338}
13391339
1340fn logSecrets(w: *Writer, context: anytype, secrets: anytype) void {1340fn logSecrets(w: *Writer, context: anytype, secrets: anytype) void {
1341 inline for (@typeInfo(@TypeOf(secrets)).@"struct".fields) |field| w.print("{s}" ++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} ++1342 (if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{field_name} ++
1343 (if (@hasField(@TypeOf(context), "counter")) .{context.counter} else .{}) ++ .{1343 (if (@hasField(@TypeOf(context), "counter")) .{context.counter} else .{}) ++ .{
1344 context.client_random,1344 context.client_random,
1345 @field(secrets, field.name),1345 @field(secrets, field_name),
1346 }) catch {};1346 }) catch {};
1347}1347}
13481348
lib/std/debug/ElfFile.zig+12-8
...@@ -219,9 +219,10 @@ pub fn load(...@@ -219,9 +219,10 @@ pub fn load(
219 break :dwarf null; // debug info not present219 break :dwarf null; // debug info not present
220 }220 }
221 var sections: Dwarf.SectionArray = @splat(null);221 var sections: Dwarf.SectionArray = @splat(null);
222 inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields) |f| {222 const info = @typeInfo(Dwarf.Section.Id).@"enum";
223 if (result.sections.get(@field(Section.Id, f.name))) |s| {223 inline for (info.field_names, info.field_values) |f_name, f_value| {
224 sections[f.value] = .{ .data = s.bytes, .owned = false };224 if (result.sections.get(@field(Section.Id, f_name))) |s| {
225 sections[f_value] = .{ .data = s.bytes, .owned = false };
225 }226 }
226 }227 }
227 break :dwarf .{ .sections = sections };228 break :dwarf .{ .sections = sections };
...@@ -408,8 +409,8 @@ fn loadSeparateDebugFile(...@@ -408,8 +409,8 @@ fn loadSeparateDebugFile(
408 return null;409 return null;
409 }410 }
410411
411 inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields) |f| {412 inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names) |f_name| {
412 const id = @field(Section.Id, f.name);413 const id = @field(Section.Id, f_name);
413 if (main_loaded.sections.get(id) == null) {414 if (main_loaded.sections.get(id) == null) {
414 main_loaded.sections.set(id, result.sections.get(id));415 main_loaded.sections.set(id, result.sections.get(id));
415 }416 }
...@@ -498,9 +499,12 @@ fn loadInner(...@@ -498,9 +499,12 @@ fn loadInner(
498 if (shdr.sh_name > shstrtab.len) return error.TruncatedElfFile;499 if (shdr.sh_name > shstrtab.len) return error.TruncatedElfFile;
499 const name = std.mem.sliceTo(shstrtab[@intCast(shdr.sh_name)..], 0);500 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 const section_id: Section.Id = inline for (
502 if (std.mem.eql(u8, "." ++ s.name, name)) {503 @typeInfo(Section.Id).@"enum".field_names,
503 break @enumFromInt(s.value);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);
504 }508 }
505 } else continue;509 } 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 {...@@ -504,8 +504,8 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
504504
505 if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue;505 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| {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;508 if (mem.eql(u8, "__" ++ section_name, sect.sectName())) break i;
509 } else continue;509 } else continue;
510510
511 if (mapped_ofile.len < sect.offset + sect.size) return error.InvalidMachO;511 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 {...@@ -408,8 +408,8 @@ fn unwindFrameInner(si: *SelfInfo, io: Io, context: *UnwindContext) !usize {
408 const ip_ptr = fp + @sizeOf(usize);408 const ip_ptr = fp + @sizeOf(usize);
409409
410 var reg_addr = fp - @sizeOf(usize);410 var reg_addr = fp - @sizeOf(usize);
411 inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".fields, 0..) |field, i| {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) {412 if (@field(frame.x_reg_pairs, field_name) != 0) {
413 (try dwarfRegNative(&context.cpu_state, 19 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;413 (try dwarfRegNative(&context.cpu_state, 19 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;
414 reg_addr += @sizeOf(usize);414 reg_addr += @sizeOf(usize);
415 (try dwarfRegNative(&context.cpu_state, 20 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*;415 (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 {...@@ -513,8 +513,8 @@ const Module = struct {
513 if (coff_obj.getSectionByName(".debug_info") == null) break :dwarf null;513 if (coff_obj.getSectionByName(".debug_info") == null) break :dwarf null;
514514
515 var sections: Dwarf.SectionArray = undefined;515 var sections: Dwarf.SectionArray = undefined;
516 inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields, 0..) |section, i| {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| .{517 sections[i] = if (coff_obj.getSectionByName("." ++ section_name)) |section_header| .{
518 .data = try coff_obj.getSectionDataAlloc(section_header, arena),518 .data = try coff_obj.getSectionDataAlloc(section_header, arena),
519 .owned = false,519 .owned = false,
520 } else null;520 } else null;
lib/std/elf.zig+7-7
...@@ -484,7 +484,7 @@ pub const PT = enum(Word) {...@@ -484,7 +484,7 @@ pub const PT = enum(Word) {
484 _,484 _,
485485
486 /// Number of defined types486 /// Number of defined types
487 pub const NUM = @typeInfo(PT).@"enum".fields.len;487 pub const NUM = @typeInfo(PT).@"enum".field_names.len;
488488
489 /// Start of OS-specific489 /// Start of OS-specific
490 pub const LOOS: PT = @enumFromInt(0x60000000);490 pub const LOOS: PT = @enumFromInt(0x60000000);
...@@ -552,7 +552,7 @@ pub const SHT = enum(Word) {...@@ -552,7 +552,7 @@ pub const SHT = enum(Word) {
552 _,552 _,
553553
554 /// Number of defined types554 /// Number of defined types
555 pub const NUM = @typeInfo(SHT).@"enum".fields.len;555 pub const NUM = @typeInfo(SHT).@"enum".field_names.len;
556556
557 /// Start of OS-specific557 /// Start of OS-specific
558 pub const LOOS: SHT = @enumFromInt(0x60000000);558 pub const LOOS: SHT = @enumFromInt(0x60000000);
...@@ -595,7 +595,7 @@ pub const STB = enum(u4) {...@@ -595,7 +595,7 @@ pub const STB = enum(u4) {
595 _,595 _,
596596
597 /// Number of defined types597 /// Number of defined types
598 pub const NUM = @typeInfo(STB).@"enum".fields.len;598 pub const NUM = @typeInfo(STB).@"enum".field_names.len;
599599
600 /// Start of OS-specific600 /// Start of OS-specific
601 pub const LOOS: STB = @enumFromInt(10);601 pub const LOOS: STB = @enumFromInt(10);
...@@ -631,7 +631,7 @@ pub const STT = enum(u4) {...@@ -631,7 +631,7 @@ pub const STT = enum(u4) {
631 _,631 _,
632632
633 /// Number of defined types633 /// Number of defined types
634 pub const NUM = @typeInfo(STT).@"enum".fields.len;634 pub const NUM = @typeInfo(STT).@"enum".field_names.len;
635635
636 /// Start of OS-specific636 /// Start of OS-specific
637 pub const LOOS: STT = @enumFromInt(10);637 pub const LOOS: STT = @enumFromInt(10);
...@@ -815,7 +815,7 @@ pub const Header = struct {...@@ -815,7 +815,7 @@ pub const Header = struct {
815815
816 pub fn init(hdr: anytype, endian: Endian) Header {816 pub fn init(hdr: anytype, endian: Endian) Header {
817 // Converting integers to exhaustive enums using `@enumFromInt` could cause a panic.817 // 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);
819 return .{819 return .{
820 .is_64 = switch (@TypeOf(hdr)) {820 .is_64 = switch (@TypeOf(hdr)) {
821 Elf32_Ehdr => false,821 Elf32_Ehdr => false,
...@@ -1642,7 +1642,7 @@ pub const CLASS = enum(u8) {...@@ -1642,7 +1642,7 @@ pub const CLASS = enum(u8) {
1642 @"64" = 2,1642 @"64" = 2,
1643 _,1643 _,
16441644
1645 pub const NUM = @typeInfo(CLASS).@"enum".fields.len;1645 pub const NUM = @typeInfo(CLASS).@"enum".field_names.len;
16461646
1647 pub fn ElfN(comptime class: CLASS) type {1647 pub fn ElfN(comptime class: CLASS) type {
1648 return switch (class) {1648 return switch (class) {
...@@ -1667,7 +1667,7 @@ pub const DATA = enum(u8) {...@@ -1667,7 +1667,7 @@ pub const DATA = enum(u8) {
1667 @"2MSB" = 2,1667 @"2MSB" = 2,
1668 _,1668 _,
16691669
1670 pub const NUM = @typeInfo(DATA).@"enum".fields.len;1670 pub const NUM = @typeInfo(DATA).@"enum".field_names.len;
1671};1671};
16721672
1673pub const OSABI = enum(u8) {1673pub const OSABI = enum(u8) {
lib/std/enums.zig+66-67
...@@ -3,14 +3,13 @@...@@ -3,14 +3,13 @@
3const std = @import("std");3const std = @import("std");
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const testing = std.testing;5const testing = std.testing;
6const EnumField = std.builtin.Type.EnumField;
76
8/// Increment this value when adding APIs that add single backwards branches.7/// Increment this value when adding APIs that add single backwards branches.
9const eval_branch_quota_cushion = 10;8const eval_branch_quota_cushion = 10;
109
11pub fn fromInt(comptime E: type, integer: anytype) ?E {10pub fn fromInt(comptime E: type, integer: anytype) ?E {
12 const enum_info = @typeInfo(E).@"enum";11 const enum_info = @typeInfo(E).@"enum";
13 if (!enum_info.is_exhaustive) {12 if (enum_info.mode == .nonexhaustive) {
14 if (std.math.cast(enum_info.tag_type, integer)) |tag| {13 if (std.math.cast(enum_info.tag_type, integer)) |tag| {
15 return @enumFromInt(tag);14 return @enumFromInt(tag);
16 }15 }
...@@ -32,20 +31,19 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E {...@@ -32,20 +31,19 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E {
32/// the first name is used. Each field is of type Data and has the provided31/// the first name is used. Each field is of type Data and has the provided
33/// default, which may be undefined.32/// default, which may be undefined.
34pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_default: ?Data) type {33pub 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);
36 const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null;35 const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null;
37 return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr }));36 return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr }));
38}37}
3938
40/// Looks up the supplied fields in the given enum type.39/// Looks up the supplied field values in the given enum type.
41/// Uses only the field names, field values are ignored.
42/// The result array is in the same order as the input.40/// 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 {
44 comptime {42 comptime {
45 @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion);43 @setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion);
46 var result: [fields.len]E = undefined;44 var result: [field_values.len]E = undefined;
47 for (&result, fields) |*r, f| {45 for (&result, field_values) |*r, f_value| {
48 r.* = @enumFromInt(f.value);46 r.* = @enumFromInt(f_value);
49 }47 }
50 const final = result;48 const final = result;
51 return &final;49 return &final;
...@@ -55,17 +53,18 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi...@@ -55,17 +53,18 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi
55/// Returns the set of all named values in the given enum, in53/// Returns the set of all named values in the given enum, in
56/// declaration order.54/// declaration order.
57pub inline fn values(comptime E: type) []const E {55pub 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);
59}57}
6058
61/// A safe alternative to @tagName() for non-exhaustive enums that doesn't59/// A safe alternative to @tagName() for non-exhaustive enums that doesn't
62/// panic when `e` has no tagged value.60/// panic when `e` has no tagged value.
63/// Returns the tag name for `e` or null if no tag exists.61/// Returns the tag name for `e` or null if no tag exists.
64pub fn tagName(comptime E: type, e: E) ?[:0]const u8 {62pub fn tagName(comptime E: type, e: E) ?[:0]const u8 {
65 const fields = @typeInfo(E).@"enum".fields;63 const field_names = @typeInfo(E).@"enum".field_names;
66 @setEvalBranchQuota(fields.len);64 const field_values = @typeInfo(E).@"enum".field_values;
67 return inline for (fields) |f| {65 @setEvalBranchQuota(field_names.len);
68 if (@intFromEnum(e) == f.value) break f.name;66 return inline for (field_names, field_values) |f_name, f_value| {
67 if (@intFromEnum(e) == f_value) break f_name;
69 } else null;68 } else null;
70}69}
7170
...@@ -88,20 +87,20 @@ test tagName {...@@ -88,20 +87,20 @@ test tagName {
88pub fn directEnumArrayLen(comptime E: type, comptime max_unused_slots: comptime_int) comptime_int {87pub fn directEnumArrayLen(comptime E: type, comptime max_unused_slots: comptime_int) comptime_int {
89 var max_value: comptime_int = -1;88 var max_value: comptime_int = -1;
90 const max_usize: comptime_int = ~@as(usize, 0);89 const max_usize: comptime_int = ~@as(usize, 0);
91 const fields = @typeInfo(E).@"enum".fields;90 const info = @typeInfo(E).@"enum";
92 for (fields) |f| {91 for (info.field_names, info.field_values) |f_name, f_value| {
93 if (f.value < 0) {92 if (f_value < 0) {
94 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " has a negative value.");93 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " has a negative value.");
95 }94 }
96 if (f.value > max_value) {95 if (f_value > max_value) {
97 if (f.value > max_usize) {96 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.");97 @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " is larger than the max value of usize.");
99 }98 }
100 max_value = f.value;99 max_value = f_value;
101 }100 }
102 }101 }
103102
104 const unused_slots = max_value + 1 - fields.len;103 const unused_slots = max_value + 1 - info.field_names.len;
105 if (unused_slots > max_unused_slots) {104 if (unused_slots > max_unused_slots) {
106 const unused_str = std.fmt.comptimePrint("{d}", .{unused_slots});105 const unused_str = std.fmt.comptimePrint("{d}", .{unused_slots});
107 const allowed_str = std.fmt.comptimePrint("{d}", .{max_unused_slots});106 const allowed_str = std.fmt.comptimePrint("{d}", .{max_unused_slots});
...@@ -167,10 +166,10 @@ pub fn directEnumArrayDefault(...@@ -167,10 +166,10 @@ pub fn directEnumArrayDefault(
167) [directEnumArrayLen(E, max_unused_slots)]Data {166) [directEnumArrayLen(E, max_unused_slots)]Data {
168 const len = comptime directEnumArrayLen(E, max_unused_slots);167 const len = comptime directEnumArrayLen(E, max_unused_slots);
169 var result: [len]Data = @splat(default orelse undefined);168 var result: [len]Data = @splat(default orelse undefined);
170 inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| {169 inline for (@typeInfo(@TypeOf(init_values)).@"struct".field_names) |f_name| {
171 const enum_value = @field(E, f.name);170 const enum_value = @field(E, f_name);
172 const index = @as(usize, @intCast(@intFromEnum(enum_value)));171 const index = @as(usize, @intCast(@intFromEnum(enum_value)));
173 result[index] = @field(init_values, f.name);172 result[index] = @field(init_values, f_name);
174 }173 }
175 return result;174 return result;
176}175}
...@@ -256,9 +255,9 @@ pub fn EnumSet(comptime E: type) type {...@@ -256,9 +255,9 @@ pub fn EnumSet(comptime E: type) type {
256255
257 /// Initializes the set using a struct of bools256 /// Initializes the set using a struct of bools
258 pub fn init(init_values: EnumFieldStruct(E, bool, false)) Self {257 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);
260 var result: Self = .{};259 var result: Self = .{};
261 if (@typeInfo(E).@"enum".is_exhaustive) {260 if (@typeInfo(E).@"enum".mode == .exhaustive) {
262 inline for (0..Self.len) |i| {261 inline for (0..Self.len) |i| {
263 const key = comptime Indexer.keyForIndex(i);262 const key = comptime Indexer.keyForIndex(i);
264 const tag = @tagName(key);263 const tag = @tagName(key);
...@@ -267,9 +266,9 @@ pub fn EnumSet(comptime E: type) type {...@@ -267,9 +266,9 @@ pub fn EnumSet(comptime E: type) type {
267 }266 }
268 }267 }
269 } else {268 } else {
270 inline for (std.meta.fields(E)) |field| {269 inline for (@typeInfo(E).@"enum".field_names) |field_name| {
271 const key = @field(E, field.name);270 const key = @field(E, field_name);
272 if (@field(init_values, field.name)) {271 if (@field(init_values, field_name)) {
273 const i = comptime Indexer.indexOf(key);272 const i = comptime Indexer.indexOf(key);
274 result.bits.set(i);273 result.bits.set(i);
275 }274 }
...@@ -443,9 +442,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {...@@ -443,9 +442,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
443442
444 /// Initializes the map using a sparse struct of optionals443 /// Initializes the map using a sparse struct of optionals
445 pub fn init(init_values: EnumFieldStruct(E, ?Value, @as(?Value, null))) Self {444 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);
447 var result: Self = .{};446 var result: Self = .{};
448 if (@typeInfo(E).@"enum".is_exhaustive) {447 if (@typeInfo(E).@"enum".mode == .exhaustive) {
449 inline for (0..Self.len) |i| {448 inline for (0..Self.len) |i| {
450 const key = comptime Indexer.keyForIndex(i);449 const key = comptime Indexer.keyForIndex(i);
451 const tag = @tagName(key);450 const tag = @tagName(key);
...@@ -455,9 +454,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {...@@ -455,9 +454,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
455 }454 }
456 }455 }
457 } else {456 } else {
458 inline for (std.meta.fields(E)) |field| {457 inline for (std.meta.fieldNames(E)) |field_name| {
459 const key = @field(E, field.name);458 const key = @field(E, field_name);
460 if (@field(init_values, field.name)) |*v| {459 if (@field(init_values, field_name)) |*v| {
461 const i = comptime Indexer.indexOf(key);460 const i = comptime Indexer.indexOf(key);
462 result.bits.set(i);461 result.bits.set(i);
463 result.values[i] = v.*;462 result.values[i] = v.*;
...@@ -487,7 +486,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {...@@ -487,7 +486,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
487 /// Initializes a full mapping with a provided default.486 /// Initializes a full mapping with a provided default.
488 /// Consider using EnumArray instead if the map will remain full.487 /// Consider using EnumArray instead if the map will remain full.
489 pub fn initFullWithDefault(comptime default: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {488 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);
491 var result: Self = .{490 var result: Self = .{
492 .bits = .full,491 .bits = .full,
493 .values = undefined,492 .values = undefined,
...@@ -673,11 +672,12 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -673,11 +672,12 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
673672
674 /// Initializes the multiset using a struct of counts.673 /// Initializes the multiset using a struct of counts.
675 pub fn init(init_counts: EnumFieldStruct(E, CountSize, 0)) Self {674 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);
677 var self = initWithCount(0);676 var self = initWithCount(0);
678 inline for (@typeInfo(E).@"enum".fields) |field| {677 const info = @typeInfo(E).@"enum";
679 const c = @field(init_counts, field.name);678 inline for (info.field_names, info.field_values) |field_name, field_value| {
680 const key = @as(E, @enumFromInt(field.value));679 const c = @field(init_counts, field_name);
680 const key: E = @enumFromInt(field_value);
681 self.counts.set(key, c);681 self.counts.set(key, c);
682 }682 }
683 return self;683 return self;
...@@ -745,16 +745,16 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -745,16 +745,16 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
745 /// Increases the all key counts by given multiset. Caller745 /// Increases the all key counts by given multiset. Caller
746 /// asserts operation will not overflow any key.746 /// asserts operation will not overflow any key.
747 pub fn addSetAssertSafe(self: *Self, other: Self) void {747 pub fn addSetAssertSafe(self: *Self, other: Self) void {
748 inline for (@typeInfo(E).@"enum".fields) |field| {748 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
749 const key = @as(E, @enumFromInt(field.value));749 const key = @as(E, @enumFromInt(field_value));
750 self.addAssertSafe(key, other.getCount(key));750 self.addAssertSafe(key, other.getCount(key));
751 }751 }
752 }752 }
753753
754 /// Increases the all key counts by given multiset.754 /// Increases the all key counts by given multiset.
755 pub fn addSet(self: *Self, other: Self) error{Overflow}!void {755 pub fn addSet(self: *Self, other: Self) error{Overflow}!void {
756 inline for (@typeInfo(E).@"enum".fields) |field| {756 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
757 const key = @as(E, @enumFromInt(field.value));757 const key = @as(E, @enumFromInt(field_value));
758 try self.add(key, other.getCount(key));758 try self.add(key, other.getCount(key));
759 }759 }
760 }760 }
...@@ -763,8 +763,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -763,8 +763,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
763 /// the given multiset has more key counts than this,763 /// the given multiset has more key counts than this,
764 /// then that key will have a key count of zero.764 /// then that key will have a key count of zero.
765 pub fn removeSet(self: *Self, other: Self) void {765 pub fn removeSet(self: *Self, other: Self) void {
766 inline for (@typeInfo(E).@"enum".fields) |field| {766 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
767 const key = @as(E, @enumFromInt(field.value));767 const key = @as(E, @enumFromInt(field_value));
768 self.remove(key, other.getCount(key));768 self.remove(key, other.getCount(key));
769 }769 }
770 }770 }
...@@ -772,8 +772,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -772,8 +772,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
772 /// Returns true iff all key counts are the same as772 /// Returns true iff all key counts are the same as
773 /// given multiset.773 /// given multiset.
774 pub fn eql(self: Self, other: Self) bool {774 pub fn eql(self: Self, other: Self) bool {
775 inline for (@typeInfo(E).@"enum".fields) |field| {775 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
776 const key = @as(E, @enumFromInt(field.value));776 const key = @as(E, @enumFromInt(field_value));
777 if (self.getCount(key) != other.getCount(key)) {777 if (self.getCount(key) != other.getCount(key)) {
778 return false;778 return false;
779 }779 }
...@@ -784,8 +784,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -784,8 +784,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
784 /// Returns true iff all key counts less than or784 /// Returns true iff all key counts less than or
785 /// equal to the given multiset.785 /// equal to the given multiset.
786 pub fn subsetOf(self: Self, other: Self) bool {786 pub fn subsetOf(self: Self, other: Self) bool {
787 inline for (@typeInfo(E).@"enum".fields) |field| {787 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
788 const key = @as(E, @enumFromInt(field.value));788 const key = @as(E, @enumFromInt(field_value));
789 if (self.getCount(key) > other.getCount(key)) {789 if (self.getCount(key) > other.getCount(key)) {
790 return false;790 return false;
791 }791 }
...@@ -796,8 +796,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {...@@ -796,8 +796,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type {
796 /// Returns true iff all key counts greater than or796 /// Returns true iff all key counts greater than or
797 /// equal to the given multiset.797 /// equal to the given multiset.
798 pub fn supersetOf(self: Self, other: Self) bool {798 pub fn supersetOf(self: Self, other: Self) bool {
799 inline for (@typeInfo(E).@"enum".fields) |field| {799 inline for (@typeInfo(E).@"enum".field_values) |field_value| {
800 const key = @as(E, @enumFromInt(field.value));800 const key = @as(E, @enumFromInt(field_value));
801 if (self.getCount(key) < other.getCount(key)) {801 if (self.getCount(key) < other.getCount(key)) {
802 return false;802 return false;
803 }803 }
...@@ -1075,7 +1075,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {...@@ -1075,7 +1075,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
10751075
1076 /// Initializes values in the enum array, with the specified default.1076 /// Initializes values in the enum array, with the specified default.
1077 pub fn initDefault(comptime default: ?Value, init_values: EnumFieldStruct(E, Value, default)) Self {1077 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);
1079 var result: Self = .{ .values = undefined };1079 var result: Self = .{ .values = undefined };
1080 inline for (0..Self.len) |i| {1080 inline for (0..Self.len) |i| {
1081 const key = comptime Indexer.keyForIndex(i);1081 const key = comptime Indexer.keyForIndex(i);
...@@ -1264,10 +1264,10 @@ test "EnumSet non-exhaustive" {...@@ -1264,10 +1264,10 @@ test "EnumSet non-exhaustive" {
12641264
1265pub fn EnumIndexer(comptime E: type) type {1265pub fn EnumIndexer(comptime E: type) type {
1266 // n log n for `std.mem.sortUnstable` call below.1266 // 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;
1268 @setEvalBranchQuota(3 * fields_len * std.math.log2(@max(fields_len, 1)) + eval_branch_quota_cushion);1268 @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) {
1271 const BackingInt = @typeInfo(E).@"enum".tag_type;1271 const BackingInt = @typeInfo(E).@"enum".tag_type;
1272 if (@bitSizeOf(BackingInt) > @bitSizeOf(usize))1272 if (@bitSizeOf(BackingInt) > @bitSizeOf(usize))
1273 @compileError("Cannot create an enum indexer for a given non-exhaustive enum, tag_type is larger than usize.");1273 @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 {...@@ -1315,18 +1315,17 @@ pub fn EnumIndexer(comptime E: type) type {
1315 };1315 };
1316 }1316 }
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 {1320 std.mem.sortUnstable(comptime_int, &field_values, {}, struct {
1321 fn lessThan(ctx: void, lhs: EnumField, rhs: EnumField) bool {1321 fn lessThan(_: void, a: comptime_int, b: comptime_int) bool {
1322 ctx;1322 return a < b;
1323 return lhs.value < rhs.value;
1324 }1323 }
1325 }.lessThan);1324 }.lessThan);
13261325
1327 const min = fields[0].value;1326 const min = field_values[0];
1328 const max = fields[fields_len - 1].value;1327 const max = field_values[fields_len - 1];
1329 if (max - min == fields.len - 1) {1328 if (max - min == field_values.len - 1) {
1330 return struct {1329 return struct {
1331 pub const Key = E;1330 pub const Key = E;
1332 pub const count: comptime_int = fields_len;1331 pub const count: comptime_int = fields_len;
...@@ -1343,7 +1342,7 @@ pub fn EnumIndexer(comptime E: type) type {...@@ -1343,7 +1342,7 @@ pub fn EnumIndexer(comptime E: type) type {
1343 };1342 };
1344 }1343 }
13451344
1346 const keys = valuesFromFields(E, &fields);1345 const keys = valuesFromFields(E, &field_values);
13471346
1348 return struct {1347 return struct {
1349 pub const Key = E;1348 pub const Key = E;
lib/std/gpu.zig+1-1
...@@ -58,7 +58,7 @@ pub const ExecutionMode = union(Tag) {...@@ -58,7 +58,7 @@ pub const ExecutionMode = union(Tag) {
5858
59/// Declare the mode entry point executes in.59/// Declare the mode entry point executes in.
60pub fn executionMode(comptime entry_point: anytype, comptime mode: ExecutionMode) void {60pub 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";
62 switch (mode) {62 switch (mode) {
63 .origin_upper_left,63 .origin_upper_left,
64 .origin_lower_left,64 .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 {...@@ -127,10 +127,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
127 },127 },
128128
129 .@"struct" => |info| {129 .@"struct" => |info| {
130 inline for (info.fields) |field| {130 inline for (info.field_names) |field_name| {
131 // We reuse the hash of the previous field as the seed for the131 // We reuse the hash of the previous field as the seed for the
132 // next one so that they're dependant.132 // next one so that they're dependant.
133 hash(hasher, @field(key, field.name), strat);133 hash(hasher, @field(key, field_name), strat);
134 }134 }
135 },135 },
136136
...@@ -138,10 +138,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {...@@ -138,10 +138,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
138 if (info.tag_type) |tag_type| {138 if (info.tag_type) |tag_type| {
139 const tag = std.meta.activeTag(key);139 const tag = std.meta.activeTag(key);
140 hash(hasher, tag, strat);140 hash(hasher, tag, strat);
141 inline for (info.fields) |field| {141 inline for (info.field_names, info.field_types) |field_name, field_type| {
142 if (@field(tag_type, field.name) == tag) {142 if (@field(tag_type, field_name) == tag) {
143 if (field.type != void) {143 if (field_type != void) {
144 hash(hasher, @field(key, field.name), strat);144 hash(hasher, @field(key, field_name), strat);
145 }145 }
146 break :blk;146 break :blk;
147 }147 }
...@@ -165,8 +165,8 @@ inline fn typeContainsSlice(comptime K: type) bool {...@@ -165,8 +165,8 @@ inline fn typeContainsSlice(comptime K: type) bool {
165 .pointer => |info| info.size == .slice,165 .pointer => |info| info.size == .slice,
166166
167 inline .@"struct", .@"union" => |info| {167 inline .@"struct", .@"union" => |info| {
168 inline for (info.fields) |field| {168 inline for (info.field_types) |field_type| {
169 if (typeContainsSlice(field.type)) {169 if (typeContainsSlice(field_type)) {
170 return true;170 return true;
171 }171 }
172 }172 }
lib/std/hash/verify.zig+3-3
...@@ -2,8 +2,8 @@ const std = @import("std");...@@ -2,8 +2,8 @@ const std = @import("std");
22
3fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typeInfo(@TypeOf(hash_fn)).@"fn".return_type.? {3fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typeInfo(@TypeOf(hash_fn)).@"fn".return_type.? {
4 const HashFn = @typeInfo(@TypeOf(hash_fn)).@"fn";4 const HashFn = @typeInfo(@TypeOf(hash_fn)).@"fn";
5 if (HashFn.params.len > 1) {5 if (HashFn.param_types.len > 1) {
6 if (@typeInfo(HashFn.params[0].type.?) == .int) {6 if (@typeInfo(HashFn.param_types[0].?) == .int) {
7 return hash_fn(@intCast(seed), buf);7 return hash_fn(@intCast(seed), buf);
8 } else {8 } else {
9 return hash_fn(buf, @intCast(seed));9 return hash_fn(buf, @intCast(seed));
...@@ -15,7 +15,7 @@ fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typ...@@ -15,7 +15,7 @@ fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typ
1515
16fn initMaybeSeed(comptime Hash: anytype, seed: anytype) Hash {16fn initMaybeSeed(comptime Hash: anytype, seed: anytype) Hash {
17 const HashFn = @typeInfo(@TypeOf(Hash.init)).@"fn";17 const HashFn = @typeInfo(@TypeOf(Hash.init)).@"fn";
18 if (HashFn.params.len == 1) {18 if (HashFn.param_types.len == 1) {
19 return Hash.init(@intCast(seed));19 return Hash.init(@intCast(seed));
20 } else {20 } else {
21 return Hash.init();21 return Hash.init();
lib/std/http/Client.zig+2-2
...@@ -823,8 +823,8 @@ pub const Request = struct {...@@ -823,8 +823,8 @@ pub const Request = struct {
823 /// Externally-owned; must outlive the Request.823 /// Externally-owned; must outlive the Request.
824 privileged_headers: []const http.Header,824 privileged_headers: []const http.Header,
825825
826 pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = b: {826 pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = b: {
827 var result: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = @splat(false);827 var result: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = @splat(false);
828 result[@intFromEnum(http.ContentEncoding.gzip)] = true;828 result[@intFromEnum(http.ContentEncoding.gzip)] = true;
829 result[@intFromEnum(http.ContentEncoding.deflate)] = true;829 result[@intFromEnum(http.ContentEncoding.deflate)] = true;
830 result[@intFromEnum(http.ContentEncoding.identity)] = true;830 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 {...@@ -401,9 +401,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
401 return v.jsonStringify(self);401 return v.jsonStringify(self);
402 }402 }
403403
404 if (!enum_info.is_exhaustive) {404 if (enum_info.mode == .nonexhaustive) {
405 inline for (enum_info.fields) |field| {405 inline for (enum_info.field_names) |field_name| {
406 if (v == @field(T, field.name)) {406 if (v == @field(T, field_name)) {
407 break;407 break;
408 }408 }
409 } else {409 } else {
...@@ -424,15 +424,15 @@ pub fn write(self: *Stringify, v: anytype) Error!void {...@@ -424,15 +424,15 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
424 const info = @typeInfo(T).@"union";424 const info = @typeInfo(T).@"union";
425 if (info.tag_type) |UnionTagType| {425 if (info.tag_type) |UnionTagType| {
426 try self.beginObject();426 try self.beginObject();
427 inline for (info.fields) |u_field| {427 inline for (info.field_names, info.field_types) |u_field_name, u_field_type| {
428 if (v == @field(UnionTagType, u_field.name)) {428 if (v == @field(UnionTagType, u_field_name)) {
429 try self.objectField(u_field.name);429 try self.objectField(u_field_name);
430 if (u_field.type == void) {430 if (u_field_type == void) {
431 // void v is {}431 // void v is {}
432 try self.beginObject();432 try self.beginObject();
433 try self.endObject();433 try self.endObject();
434 } else {434 } else {
435 try self.write(@field(v, u_field.name));435 try self.write(@field(v, u_field_name));
436 }436 }
437 break;437 break;
438 }438 }
...@@ -455,16 +455,16 @@ pub fn write(self: *Stringify, v: anytype) Error!void {...@@ -455,16 +455,16 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
455 } else {455 } else {
456 try self.beginObject();456 try self.beginObject();
457 }457 }
458 inline for (S.fields) |Field| {458 inline for (S.field_names, S.field_types) |field_name, field_type| {
459 // don't include void fields459 // don't include void fields
460 if (Field.type == void) continue;460 if (field_type == void) continue;
461461
462 var emit_field = true;462 var emit_field = true;
463463
464 // don't include optional fields that are null when emit_null_optional_fields is set to false464 // 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) {
466 if (self.options.emit_null_optional_fields == false) {466 if (self.options.emit_null_optional_fields == false) {
467 if (@field(v, Field.name) == null) {467 if (@field(v, field_name) == null) {
468 emit_field = false;468 emit_field = false;
469 }469 }
470 }470 }
...@@ -472,9 +472,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {...@@ -472,9 +472,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void {
472472
473 if (emit_field) {473 if (emit_field) {
474 if (!S.is_tuple) {474 if (!S.is_tuple) {
475 try self.objectField(Field.name);475 try self.objectField(field_name);
476 }476 }
477 try self.write(@field(v, Field.name));477 try self.write(@field(v, field_name));
478 }478 }
479 }479 }
480 if (S.is_tuple) {480 if (S.is_tuple) {
lib/std/json/static.zig+47-31
...@@ -286,20 +286,20 @@ pub fn innerParse(...@@ -286,20 +286,20 @@ pub fn innerParse(
286 },286 },
287 };287 };
288288
289 inline for (unionInfo.fields) |u_field| {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)) {290 if (std.mem.eql(u8, u_field_name, field_name)) {
291 // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.291 // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.
292 // (Recursing into innerParse() might trigger more allocations.)292 // (Recursing into innerParse() might trigger more allocations.)
293 freeAllocated(allocator, name_token.?);293 freeAllocated(allocator, name_token.?);
294 name_token = null;294 name_token = null;
295 if (u_field.type == void) {295 if (u_field_type == void) {
296 // void isn't really a json type, but we can support void payload union tags with {} as a value.296 // void isn't really a json type, but we can support void payload union tags with {} as a value.
297 if (.object_begin != try source.next()) return error.UnexpectedToken;297 if (.object_begin != try source.next()) return error.UnexpectedToken;
298 if (.object_end != try source.next()) return error.UnexpectedToken;298 if (.object_end != try source.next()) return error.UnexpectedToken;
299 result = @unionInit(T, u_field.name, {});299 result = @unionInit(T, u_field_name, {});
300 } else {300 } else {
301 // Recurse.301 // 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));
303 }303 }
304 break;304 break;
305 }305 }
...@@ -318,8 +318,8 @@ pub fn innerParse(...@@ -318,8 +318,8 @@ pub fn innerParse(
318 if (.array_begin != try source.next()) return error.UnexpectedToken;318 if (.array_begin != try source.next()) return error.UnexpectedToken;
319319
320 var r: T = undefined;320 var r: T = undefined;
321 inline for (0..structInfo.fields.len) |i| {321 inline for (structInfo.field_types, 0..) |field_type, i| {
322 r[i] = try innerParse(structInfo.fields[i].type, allocator, source, options);322 r[i] = try innerParse(field_type, allocator, source, options);
323 }323 }
324324
325 if (.array_end != try source.next()) return error.UnexpectedToken;325 if (.array_end != try source.next()) return error.UnexpectedToken;
...@@ -334,7 +334,7 @@ pub fn innerParse(...@@ -334,7 +334,7 @@ pub fn innerParse(
334 if (.object_begin != try source.next()) return error.UnexpectedToken;334 if (.object_begin != try source.next()) return error.UnexpectedToken;
335335
336 var r: T = undefined;336 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
339 while (true) {339 while (true) {
340 var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);340 var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?);
...@@ -348,9 +348,14 @@ pub fn innerParse(...@@ -348,9 +348,14 @@ pub fn innerParse(
348 },348 },
349 };349 };
350350
351 inline for (structInfo.fields, 0..) |field, i| {351 inline for (
352 if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name);352 structInfo.field_names,
353 if (std.mem.eql(u8, field.name, field_name)) {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)) {
354 // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.359 // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object.
355 // (Recursing into innerParse() might trigger more allocations.)360 // (Recursing into innerParse() might trigger more allocations.)
356 freeAllocated(allocator, name_token.?);361 freeAllocated(allocator, name_token.?);
...@@ -360,14 +365,14 @@ pub fn innerParse(...@@ -360,14 +365,14 @@ pub fn innerParse(
360 .use_first => {365 .use_first => {
361 // Parse and ignore the redundant value.366 // Parse and ignore the redundant value.
362 // We don't want to skip the value, because we want type checking.367 // 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);
364 break;369 break;
365 },370 },
366 .@"error" => return error.DuplicateField,371 .@"error" => return error.DuplicateField,
367 .use_last => {},372 .use_last => {},
368 }373 }
369 }374 }
370 @field(r, field.name) = try innerParse(field.type, allocator, source, options);375 @field(r, f_name) = try innerParse(f_type, allocator, source, options);
371 fields_seen[i] = true;376 fields_seen[i] = true;
372 break;377 break;
373 }378 }
...@@ -493,7 +498,7 @@ pub fn innerParse(...@@ -493,7 +498,7 @@ pub fn innerParse(
493 _ = try source.allocNextIntoArrayList(&value_list, .alloc_always);498 _ = try source.allocNextIntoArrayList(&value_list, .alloc_always);
494 return try value_list.toOwnedSliceSentinel(s);499 return try value_list.toOwnedSliceSentinel(s);
495 }500 }
496 if (ptrInfo.is_const) {501 if (ptrInfo.attrs.@"const") {
497 switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) {502 switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) {
498 inline .string, .allocated_string => |slice| return slice,503 inline .string, .allocated_string => |slice| return slice,
499 else => unreachable,504 else => unreachable,
...@@ -613,16 +618,16 @@ pub fn innerParseFromValue(...@@ -613,16 +618,16 @@ pub fn innerParseFromValue(
613 const kv = it.next().?;618 const kv = it.next().?;
614 const field_name = kv.key_ptr.*;619 const field_name = kv.key_ptr.*;
615620
616 inline for (unionInfo.fields) |u_field| {621 inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| {
617 if (std.mem.eql(u8, u_field.name, field_name)) {622 if (std.mem.eql(u8, u_field_name, field_name)) {
618 if (u_field.type == void) {623 if (u_field_type == void) {
619 // void isn't really a json type, but we can support void payload union tags with {} as a value.624 // void isn't really a json type, but we can support void payload union tags with {} as a value.
620 if (kv.value_ptr.* != .object) return error.UnexpectedToken;625 if (kv.value_ptr.* != .object) return error.UnexpectedToken;
621 if (kv.value_ptr.*.object.count() != 0) return error.UnexpectedToken;626 if (kv.value_ptr.*.object.count() != 0) return error.UnexpectedToken;
622 return @unionInit(T, u_field.name, {});627 return @unionInit(T, u_field_name, {});
623 }628 }
624 // Recurse.629 // 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));
626 }631 }
627 }632 }
628 // Didn't match anything.633 // Didn't match anything.
...@@ -632,11 +637,11 @@ pub fn innerParseFromValue(...@@ -632,11 +637,11 @@ pub fn innerParseFromValue(
632 .@"struct" => |structInfo| {637 .@"struct" => |structInfo| {
633 if (structInfo.is_tuple) {638 if (structInfo.is_tuple) {
634 if (source != .array) return error.UnexpectedToken;639 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
637 var r: T = undefined;642 var r: T = undefined;
638 inline for (0..structInfo.fields.len, source.array.items) |i, item| {643 inline for (0..structInfo.field_names.len, source.array.items) |i, item| {
639 r[i] = try innerParseFromValue(structInfo.fields[i].type, allocator, item, options);644 r[i] = try innerParseFromValue(structInfo.field_types[i], allocator, item, options);
640 }645 }
641646
642 return r;647 return r;
...@@ -649,17 +654,22 @@ pub fn innerParseFromValue(...@@ -649,17 +654,22 @@ pub fn innerParseFromValue(
649 if (source != .object) return error.UnexpectedToken;654 if (source != .object) return error.UnexpectedToken;
650655
651 var r: T = undefined;656 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
654 var it = source.object.iterator();659 var it = source.object.iterator();
655 while (it.next()) |kv| {660 while (it.next()) |kv| {
656 const field_name = kv.key_ptr.*;661 const field_name = kv.key_ptr.*;
657662
658 inline for (structInfo.fields, 0..) |field, i| {663 inline for (
659 if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name);664 structInfo.field_names,
660 if (std.mem.eql(u8, field.name, field_name)) {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)) {
661 assert(!fields_seen[i]); // Can't have duplicate keys in a Value.object.671 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);
663 fields_seen[i] = true;673 fields_seen[i] = true;
664 break;674 break;
665 }675 }
...@@ -782,11 +792,17 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T {...@@ -782,11 +792,17 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T {
782 return std.enums.fromInt(T, n) orelse return error.InvalidEnumTag;792 return std.enums.fromInt(T, n) orelse return error.InvalidEnumTag;
783}793}
784794
785fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".fields.len]bool) !void {795fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".field_names.len]bool) !void {
786 inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| {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| {
787 if (!fields_seen[i]) {803 if (!fields_seen[i]) {
788 if (field.defaultValue()) |default| {804 if (field_attrs.defaultValue(field_type)) |default| {
789 @field(r, field.name) = default;805 @field(r, field_name) = default;
790 } else {806 } else {
791 return error.MissingField;807 return error.MissingField;
792 }808 }
lib/std/lang.zig+65-97
...@@ -596,13 +596,8 @@ pub const Type = union(enum) {...@@ -596,13 +596,8 @@ pub const Type = union(enum) {
596 /// therefore must be kept in sync with the compiler implementation.596 /// therefore must be kept in sync with the compiler implementation.
597 pub const Pointer = struct {597 pub const Pointer = struct {
598 size: Size,598 size: Size,
599 is_const: bool,599 attrs: Attributes,
600 is_volatile: bool,
601 /// `null` means implicit alignment, which is equivalent to `@alignOf(child)`.
602 alignment: ?usize,
603 address_space: AddressSpace,
604 child: type,600 child: type,
605 is_allowzero: bool,
606601
607 /// The type of the sentinel is the element type of the pointer, which is602 /// The type of the sentinel is the element type of the pointer, which is
608 /// the value of the `child` field in this struct. However there is no way603 /// the value of the `child` field in this struct. However there is no way
...@@ -667,44 +662,40 @@ pub const Type = union(enum) {...@@ -667,44 +662,40 @@ pub const Type = union(enum) {
667662
668 /// This data structure is used by the Zig language code generation and663 /// This data structure is used by the Zig language code generation and
669 /// therefore must be kept in sync with the compiler implementation.664 /// therefore must be kept in sync with the compiler implementation.
670 pub const StructField = struct {665 pub const Struct = struct {
671 name: [:0]const u8,666 is_tuple: bool,
672 type: type,667 layout: ContainerLayout,
673 /// The type of the default value is the type of this struct field, which668 /// Always `null` if `layout != .@"packed"`.
674 /// is the value of the `type` field in this struct. However there is no669 backing_integer: ?type,
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 }
689670
690 /// This data structure is used by the Zig language code generation and671 field_names: []const [:0]const u8,
691 /// therefore must be kept in sync with the compiler implementation.672 /// Guaranteed to have the same length as `field_names`.
692 pub const Attributes = struct {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 {
693 @"comptime": bool = false,680 @"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.
694 @"align": ?usize = null,683 @"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`.
695 default_value_ptr: ?*const anyopaque = null,689 default_value_ptr: ?*const anyopaque = null,
696 };
697 };
698690
699 /// This data structure is used by the Zig language code generation and691 /// Loads the field's default value from `default_value_ptr`.
700 /// therefore must be kept in sync with the compiler implementation.692 /// `FieldType` must exactly match the corresponding element of `Struct.field_types`.
701 pub const Struct = struct {693 /// Returns `null` if the field has no default value.
702 layout: ContainerLayout,694 pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType {
703 /// Only valid if layout is .@"packed"695 const dp: *const FieldType = @ptrCast(@alignCast(attrs.default_value_ptr orelse return null));
704 backing_integer: ?type = null,696 return dp.*;
705 fields: []const StructField,697 }
706 decls: []const Declaration,698 };
707 is_tuple: bool,
708 };699 };
709700
710 /// This data structure is used by the Zig language code generation and701 /// This data structure is used by the Zig language code generation and
...@@ -722,48 +713,25 @@ pub const Type = union(enum) {...@@ -722,48 +713,25 @@ pub const Type = union(enum) {
722713
723 /// This data structure is used by the Zig language code generation and714 /// This data structure is used by the Zig language code generation and
724 /// therefore must be kept in sync with the compiler implementation.715 /// therefore must be kept in sync with the compiler implementation.
725 pub const Error = struct {716 pub const ErrorSet = struct {
726 name: [:0]const u8,717 error_names: ?[]const [: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,
738 };718 };
739719
740 /// This data structure is used by the Zig language code generation and720 /// This data structure is used by the Zig language code generation and
741 /// therefore must be kept in sync with the compiler implementation.721 /// therefore must be kept in sync with the compiler implementation.
742 pub const Enum = struct {722 pub const Enum = struct {
743 tag_type: type,723 tag_type: type,
744 fields: []const EnumField,724 mode: Mode,
745 decls: []const Declaration,
746 is_exhaustive: bool,
747725
748 /// This data structure is used by the Zig language code generation and726 field_names: []const [:0]const u8,
749 /// therefore must be kept in sync with the compiler implementation.727 /// Guaranteed to have the same length as `field_names`.
750 pub const Mode = enum { exhaustive, nonexhaustive };728 field_values: []const comptime_int,
751 };
752729
753 /// This data structure is used by the Zig language code generation and730 decl_names: []const [:0]const u8,
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,
761731
762 /// This data structure is used by the Zig language code generation and732 /// This data structure is used by the Zig language code generation and
763 /// therefore must be kept in sync with the compiler implementation.733 /// therefore must be kept in sync with the compiler implementation.
764 pub const Attributes = struct {734 pub const Mode = enum { exhaustive, nonexhaustive };
765 @"align": ?usize = null,
766 };
767 };735 };
768736
769 /// This data structure is used by the Zig language code generation and737 /// This data structure is used by the Zig language code generation and
...@@ -771,36 +739,42 @@ pub const Type = union(enum) {...@@ -771,36 +739,42 @@ pub const Type = union(enum) {
771 pub const Union = struct {739 pub const Union = struct {
772 layout: ContainerLayout,740 layout: ContainerLayout,
773 tag_type: ?type,741 tag_type: ?type,
774 fields: []const UnionField,742 /// Always `null` if `layout != .@"packed"`.
775 decls: []const Declaration,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 };
776 };758 };
777759
778 /// This data structure is used by the Zig language code generation and760 /// This data structure is used by the Zig language code generation and
779 /// therefore must be kept in sync with the compiler implementation.761 /// therefore must be kept in sync with the compiler implementation.
780 pub const Fn = struct {762 pub const Fn = struct {
781 calling_convention: CallingConvention,763 attrs: Attributes,
782 is_generic: bool,764 is_generic: bool,
783 is_var_args: bool,765 /// `null` means the return type is generic, i.e. it depends on a function argument.
784 /// TODO change the language spec to make this not optional.
785 return_type: ?type,766 return_type: ?type,
786 params: []const Param,
787767
788 /// This data structure is used by the Zig language code generation and768 /// A `null` element represents either an `anytype` parameter, or a parameter with a generic
789 /// therefore must be kept in sync with the compiler implementation.769 /// type, i.e. where the type depends on a previous function argument.
790 pub const Param = struct {770 param_types: []const ?type,
791 is_generic: bool,771 /// Guaranteed to have the same length as `param_types`.
792 is_noalias: bool,772 param_attrs: []const ParamAttributes,
793 type: ?type,773
794774 pub const ParamAttributes = struct {
795 /// This data structure is used by the Zig language code generation and775 @"noalias": bool = false,
796 /// therefore must be kept in sync with the compiler implementation.
797 pub const Attributes = struct {
798 @"noalias": bool = false,
799 };
800 };776 };
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.
804 pub const Attributes = struct {778 pub const Attributes = struct {
805 @"callconv": CallingConvention = .auto,779 @"callconv": CallingConvention = .auto,
806 varargs: bool = false,780 varargs: bool = false,
...@@ -810,7 +784,7 @@ pub const Type = union(enum) {...@@ -810,7 +784,7 @@ pub const Type = union(enum) {
810 /// This data structure is used by the Zig language code generation and784 /// This data structure is used by the Zig language code generation and
811 /// therefore must be kept in sync with the compiler implementation.785 /// therefore must be kept in sync with the compiler implementation.
812 pub const Opaque = struct {786 pub const Opaque = struct {
813 decls: []const Declaration,787 decl_names: []const [:0]const u8,
814 };788 };
815789
816 /// This data structure is used by the Zig language code generation and790 /// This data structure is used by the Zig language code generation and
...@@ -831,12 +805,6 @@ pub const Type = union(enum) {...@@ -831,12 +805,6 @@ pub const Type = union(enum) {
831 len: comptime_int,805 len: comptime_int,
832 child: type,806 child: type,
833 };807 };
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 };
840};808};
841809
842/// This data structure is used by the Zig language code generation and810/// 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 {...@@ -1648,8 +1648,8 @@ pub const CompareOperator = enum {
1648 }1648 }
16491649
1650 test reverse {1650 test reverse {
1651 inline for (@typeInfo(CompareOperator).@"enum".fields) |op_field| {1651 inline for (@typeInfo(CompareOperator).@"enum".field_values) |op_field_value| {
1652 const op = @as(CompareOperator, @enumFromInt(op_field.value));1652 const op = @as(CompareOperator, @enumFromInt(op_field_value));
1653 try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));1653 try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
1654 try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));1654 try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
1655 try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4));1655 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 {...@@ -297,9 +297,13 @@ pub fn zeroes(comptime T: type) T {
297 return item;297 return item;
298 } else {298 } else {
299 var structure: T = undefined;299 var structure: T = undefined;
300 inline for (struct_info.fields) |field| {300 inline for (
301 if (!field.is_comptime) {301 struct_info.field_names,
302 @field(structure, field.name) = zeroes(field.type);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);
303 }307 }
304 }308 }
305 return structure;309 return structure;
...@@ -321,7 +325,7 @@ pub fn zeroes(comptime T: type) T {...@@ -321,7 +325,7 @@ pub fn zeroes(comptime T: type) T {
321 return null;325 return null;
322 },326 },
323 .one, .many => {327 .one, .many => {
324 if (ptr_info.is_allowzero) return @ptrFromInt(0);328 if (ptr_info.attrs.@"allowzero") return @ptrFromInt(0);
325 @compileError("Only nullable and allowzero pointers can be set to zero.");329 @compileError("Only nullable and allowzero pointers can be set to zero.");
326 },330 },
327 }331 }
...@@ -471,44 +475,49 @@ pub fn zeroInit(comptime T: type, init: anytype) T {...@@ -471,44 +475,49 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
471 switch (@typeInfo(Init)) {475 switch (@typeInfo(Init)) {
472 .@"struct" => |init_info| {476 .@"struct" => |init_info| {
473 if (init_info.is_tuple) {477 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) {
475 @compileError("Tuple initializer has more elements than there are fields in `" ++ @typeName(T) ++ "`");479 @compileError("Tuple initializer has more elements than there are fields in `" ++ @typeName(T) ++ "`");
476 }480 }
477 } else {481 } else {
478 inline for (init_info.fields) |field| {482 inline for (init_info.field_names) |field_name| {
479 if (!@hasField(T, field.name)) {483 if (!@hasField(T, field_name)) {
480 @compileError("Encountered an initializer for `" ++ field.name ++ "`, but it is not a field of " ++ @typeName(T));484 @compileError("Encountered an initializer for `" ++ field_name ++ "`, but it is not a field of " ++ @typeName(T));
481 }485 }
482 }486 }
483 }487 }
484488
485 var value: T = if (struct_info.layout == .@"extern") zeroes(T) else undefined;489 var value: T = if (struct_info.layout == .@"extern") zeroes(T) else undefined;
486490
487 inline for (struct_info.fields, 0..) |field, i| {491 inline for (
488 if (field.is_comptime) {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") {
489 continue;498 continue;
490 }499 }
491500
492 if (init_info.is_tuple and init_info.fields.len > i) {501 if (init_info.is_tuple and init_info.field_names.len > i) {
493 @field(value, field.name) = @field(init, init_info.fields[i].name);502 @field(value, f_name) = @field(init, init_info.field_names[i]);
494 } else if (@hasField(@TypeOf(init), field.name)) {503 } else if (@hasField(@TypeOf(init), f_name)) {
495 switch (@typeInfo(field.type)) {504 switch (@typeInfo(f_type)) {
496 .@"struct" => {505 .@"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));
498 },507 },
499 else => {508 else => {
500 @field(value, field.name) = @field(init, field.name);509 @field(value, f_name) = @field(init, f_name);
501 },510 },
502 }511 }
503 } else if (field.defaultValue()) |val| {512 } else if (f_attr.defaultValue(f_type)) |val| {
504 @field(value, field.name) = val;513 @field(value, f_name) = val;
505 } else {514 } else {
506 switch (@typeInfo(field.type)) {515 switch (@typeInfo(f_type)) {
507 .@"struct" => {516 .@"struct" => {
508 @field(value, field.name) = std.mem.zeroInit(field.type, .{});517 @field(value, f_name) = std.mem.zeroInit(f_type, .{});
509 },518 },
510 else => {519 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)));
512 },521 },
513 }522 }
514 }523 }
...@@ -867,13 +876,9 @@ fn Span(comptime T: type) type {...@@ -867,13 +876,9 @@ fn Span(comptime T: type) type {
867 .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),876 .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
868 .c => 0,877 .c => 0,
869 };878 };
870 return @Pointer(.slice, .{879 var attrs = ptr_info.attrs;
871 .@"const" = ptr_info.is_const,880 attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
872 .@"volatile" = ptr_info.is_volatile,881 return @Pointer(.slice, attrs, ptr_info.child, new_sentinel);
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);
877 },882 },
878 else => {},883 else => {},
879 }884 }
...@@ -933,13 +938,9 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {...@@ -933,13 +938,9 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
933 .many => if (std.meta.sentinel(T)) |s| s == end else true,938 .many => if (std.meta.sentinel(T)) |s| s == end else true,
934 .c => true,939 .c => true,
935 };940 };
936 return @Pointer(.slice, .{941 var attrs = ptr_info.attrs;
937 .@"const" = ptr_info.is_const,942 attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
938 .@"volatile" = ptr_info.is_volatile,943 return @Pointer(.slice, attrs, Elem, if (have_sentinel) end else null);
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);
943 },944 },
944 else => {},945 else => {},
945 }946 }
...@@ -2210,19 +2211,19 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a...@@ -2210,19 +2211,19 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
2210 .@"struct" => |struct_info| {2211 .@"struct" => |struct_info| {
2211 if (struct_info.backing_integer) |Int| {2212 if (struct_info.backing_integer) |Int| {
2212 ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*))));2213 ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*))));
2213 } else inline for (std.meta.fields(S)) |f| {2214 } else inline for (struct_info.field_types, struct_info.field_names, struct_info.field_attrs) |f_type, f_name, f_attr| {
2214 switch (@typeInfo(f.type)) {2215 switch (@typeInfo(f_type)) {
2215 .@"struct" => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)),2216 .@"struct" => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" 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)),2217 .@"union", .array => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
2217 .@"enum" => {2218 .@"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))));
2219 },2220 },
2220 .bool => {},2221 .bool => {},
2221 .float => |float_info| {2222 .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)))));
2223 },2224 },
2224 else => {2225 else => {
2225 @field(ptr, f.name) = @byteSwap(@field(ptr, f.name));2226 @field(ptr, f_name) = @byteSwap(@field(ptr, f_name));
2226 },2227 },
2227 }2228 }
2228 }2229 }
...@@ -2232,9 +2233,9 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a...@@ -2232,9 +2233,9 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
2232 @compileError("byteSwapAllFields expects an untagged union");2233 @compileError("byteSwapAllFields expects an untagged union");
2233 }2234 }
22342235
2235 const first_size = @bitSizeOf(union_info.fields[0].type);2236 const first_size = @bitSizeOf(union_info.field_types[0]);
2236 inline for (union_info.fields) |field| {2237 inline for (union_info.field_types) |field_type| {
2237 if (@bitSizeOf(field.type) != first_size) {2238 if (@bitSizeOf(field_type) != first_size) {
2238 @compileError("Unable to byte-swap unions with varying field sizes");2239 @compileError("Unable to byte-swap unions with varying field sizes");
2239 }2240 }
2240 }2241 }
...@@ -3940,15 +3941,8 @@ pub fn ReverseIterator(comptime T: type) type {...@@ -3940,15 +3941,8 @@ pub fn ReverseIterator(comptime T: type) type {
3940 .many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"),3941 .many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"),
3941 }3942 }
3942 const Element = std.meta.Elem(T);3943 const Element = std.meta.Elem(T);
3943 const attrs: std.builtin.Type.Pointer.Attributes = .{3944 const Pointer = @Pointer(.many, ptr.attrs, Element, std.meta.sentinel(T));
3944 .@"const" = ptr.is_const,3945 const ElementPointer = @Pointer(.one, ptr.attrs, Element, null);
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);
3952 return struct {3946 return struct {
3953 ptr: Pointer,3947 ptr: Pointer,
3954 index: usize,3948 index: usize,
...@@ -4255,7 +4249,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {...@@ -4255,7 +4249,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
4255 @compileError("expected many item pointer, got " ++ @typeName(T));4249 @compileError("expected many item pointer, got " ++ @typeName(T));
42564250
4257 // Do nothing if the pointer is already well-aligned.4251 // 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))
4259 return 0;4253 return 0;
42604254
4261 // Calculate the aligned base address with an eye out for overflow.4255 // Calculate the aligned base address with an eye out for overflow.
...@@ -4309,17 +4303,14 @@ fn CopyPtrAttrs(...@@ -4309,17 +4303,14 @@ fn CopyPtrAttrs(
4309 comptime child: type,4303 comptime child: type,
4310) type {4304) type {
4311 const ptr = @typeInfo(source).pointer;4305 const ptr = @typeInfo(source).pointer;
4312 return @Pointer(size, .{4306 var attrs = ptr.attrs;
4313 .@"const" = ptr.is_const,4307 if (attrs.@"align" == null) {
4314 .@"volatile" = ptr.is_volatile,4308 const want = @alignOf(ptr.child);
4315 .@"allowzero" = ptr.is_allowzero,4309 if (@alignOf(child) != want) {
4316 .@"align" = ptr.alignment orelse a: {4310 attrs.@"align" = want;
4317 // If the new child is aligned differently than the old one, explicitly align the type.4311 }
4318 const want = @alignOf(ptr.child);4312 }
4319 break :a if (@alignOf(child) == want) null else want;4313 return @Pointer(size, attrs, child, null);
4320 },
4321 .@"addrspace" = ptr.address_space,
4322 }, child, null);
4323}4314}
43244315
4325fn AsBytesReturnType(comptime P: type) type {4316fn AsBytesReturnType(comptime P: type) type {
...@@ -4383,10 +4374,13 @@ test "asBytes preserves pointer attributes" {...@@ -4383,10 +4374,13 @@ test "asBytes preserves pointer attributes" {
4383 const in = @typeInfo(@TypeOf(inPtr)).pointer;4374 const in = @typeInfo(@TypeOf(inPtr)).pointer;
4384 const out = @typeInfo(@TypeOf(outSlice)).pointer;4375 const out = @typeInfo(@TypeOf(outSlice)).pointer;
43854376
4386 try testing.expectEqual(in.is_const, out.is_const);4377 const in_attrs = in.attrs;
4387 try testing.expectEqual(in.is_volatile, out.is_volatile);4378 const out_attrs = out.attrs;
4388 try testing.expectEqual(in.is_allowzero, out.is_allowzero);4379
4389 try testing.expectEqual(in.alignment, out.alignment);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");
4390}4384}
43914385
4392/// Given any value, returns a copy of its bytes in an array.4386/// Given any value, returns a copy of its bytes in an array.
...@@ -4463,13 +4457,13 @@ test "bytesAsValue preserves pointer attributes" {...@@ -4463,13 +4457,13 @@ test "bytesAsValue preserves pointer attributes" {
4463 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];4457 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
4464 const outPtr = bytesAsValue(u32, inSlice);4458 const outPtr = bytesAsValue(u32, inSlice);
44654459
4466 const in = @typeInfo(@TypeOf(inSlice)).pointer;4460 const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4467 const out = @typeInfo(@TypeOf(outPtr)).pointer;4461 const out_attrs = @typeInfo(@TypeOf(outPtr)).pointer.attrs;
44684462
4469 try testing.expectEqual(in.is_const, out.is_const);4463 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4470 try testing.expectEqual(in.is_volatile, out.is_volatile);4464 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4471 try testing.expectEqual(in.is_allowzero, out.is_allowzero);4465 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4472 try testing.expectEqual(in.alignment, out.alignment);4466 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4473}4467}
44744468
4475/// Given a pointer to an array of bytes, returns a value of the specified type backed by a4469/// 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" {...@@ -4566,13 +4560,13 @@ test "bytesAsSlice preserves pointer attributes" {
4566 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];4560 const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
4567 const outSlice = bytesAsSlice(u16, inSlice);4561 const outSlice = bytesAsSlice(u16, inSlice);
45684562
4569 const in = @typeInfo(@TypeOf(inSlice)).pointer;4563 const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4570 const out = @typeInfo(@TypeOf(outSlice)).pointer;4564 const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
45714565
4572 try testing.expectEqual(in.is_const, out.is_const);4566 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4573 try testing.expectEqual(in.is_volatile, out.is_volatile);4567 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4574 try testing.expectEqual(in.is_allowzero, out.is_allowzero);4568 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4575 try testing.expectEqual(in.alignment, out.alignment);4569 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4576}4570}
45774571
4578test "bytesAsSlice with zero-bit element type" {4572test "bytesAsSlice with zero-bit element type" {
...@@ -4678,25 +4672,19 @@ test "sliceAsBytes preserves pointer attributes" {...@@ -4678,25 +4672,19 @@ test "sliceAsBytes preserves pointer attributes" {
4678 const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..];4672 const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..];
4679 const outSlice = sliceAsBytes(inSlice);4673 const outSlice = sliceAsBytes(inSlice);
46804674
4681 const in = @typeInfo(@TypeOf(inSlice)).pointer;4675 const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
4682 const out = @typeInfo(@TypeOf(outSlice)).pointer;4676 const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
46834677
4684 try testing.expectEqual(in.is_const, out.is_const);4678 try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
4685 try testing.expectEqual(in.is_volatile, out.is_volatile);4679 try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
4686 try testing.expectEqual(in.is_allowzero, out.is_allowzero);4680 try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
4687 try testing.expectEqual(in.alignment, out.alignment);4681 try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
4688}4682}
46894683
4690fn AbsorbSentinelReturnType(comptime Slice: type) type {4684fn AbsorbSentinelReturnType(comptime Slice: type) type {
4691 const info = @typeInfo(Slice).pointer;4685 const info = @typeInfo(Slice).pointer;
4692 assert(info.size == .slice);4686 assert(info.size == .slice);
4693 return @Pointer(.slice, .{4687 return @Pointer(.slice, info.attrs, info.child, null);
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);
4700}4688}
47014689
4702/// If the provided slice is not sentinel terminated, do nothing and return that slice.4690/// 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" {...@@ -4949,13 +4937,9 @@ test "freeing empty string with null-terminated sentinel" {
4949/// all other pointer attributes copied from `AttributeSource`.4937/// all other pointer attributes copied from `AttributeSource`.
4950fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type {4938fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type {
4951 const ptr = @typeInfo(AttributeSource).pointer;4939 const ptr = @typeInfo(AttributeSource).pointer;
4952 return @Pointer(.slice, .{4940 var attrs = ptr.attrs;
4953 .@"const" = ptr.is_const,4941 attrs.@"align" = new_alignment;
4954 .@"volatile" = ptr.is_volatile,4942 return @Pointer(.slice, attrs, ptr.child, null);
4955 .@"allowzero" = ptr.is_allowzero,
4956 .@"align" = new_alignment,
4957 .@"addrspace" = ptr.address_space,
4958 }, ptr.child, null);
4959}4943}
49604944
4961/// Returns the largest slice in the given bytes that conforms to the new alignment,4945/// 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 {...@@ -183,7 +183,7 @@ pub fn destroy(self: Allocator, ptr: anytype) void {
183 const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));183 const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr)));
184 self.rawFree(184 self.rawFree(
185 non_const_ptr[0..@sizeOf(T)],185 non_const_ptr[0..@sizeOf(T)],
186 .fromByteUnits(info.alignment orelse @alignOf(T)),186 .fromByteUnits(info.attrs.@"align" orelse @alignOf(T)),
187 @returnAddress(),187 @returnAddress(),
188 );188 );
189}189}
...@@ -331,7 +331,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool {...@@ -331,7 +331,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool {
331 const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return false;331 const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return false;
332 return self.rawResize(332 return self.rawResize(
333 old_memory,333 old_memory,
334 .fromByteUnits(slice_info.alignment orelse @alignOf(T)),334 .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)),
335 new_len_bytes,335 new_len_bytes,
336 @returnAddress(),336 @returnAddress(),
337 );337 );
...@@ -377,7 +377,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo...@@ -377,7 +377,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo
377 const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return null;377 const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return null;
378 const new_ptr = self.rawRemap(378 const new_ptr = self.rawRemap(
379 old_memory,379 old_memory,
380 .fromByteUnits(slice_info.alignment orelse @alignOf(T)),380 .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)),
381 new_len_bytes,381 new_len_bytes,
382 @returnAddress(),382 @returnAddress(),
383 ) orelse return null;383 ) orelse return null;
...@@ -412,11 +412,11 @@ pub fn reallocAdvanced(...@@ -412,11 +412,11 @@ pub fn reallocAdvanced(
412 comptime assert(slice_info.size == .slice);412 comptime assert(slice_info.size == .slice);
413 const T = slice_info.child;413 const T = slice_info.child;
414 if (old_mem.len == 0) {414 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);
416 }416 }
417 if (new_n == 0) {417 if (new_n == 0) {
418 self.free(old_mem);418 self.free(old_mem);
419 const alignment = slice_info.alignment orelse @alignOf(T);419 const alignment = slice_info.attrs.@"align" orelse @alignOf(T);
420 const addr = comptime std.mem.alignBackward(usize, math.maxInt(usize), alignment);420 const addr = comptime std.mem.alignBackward(usize, math.maxInt(usize), alignment);
421 const ptr: *align(alignment) [0]T = @ptrFromInt(addr);421 const ptr: *align(alignment) [0]T = @ptrFromInt(addr);
422 return ptr;422 return ptr;
...@@ -425,16 +425,16 @@ pub fn reallocAdvanced(...@@ -425,16 +425,16 @@ pub fn reallocAdvanced(
425 const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem)));425 const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem)));
426 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory;426 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory;
427 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure427 // 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| {
429 return @ptrCast(@alignCast(p[0..byte_count]));429 return @ptrCast(@alignCast(p[0..byte_count]));
430 }430 }
431431
432 const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), return_address) orelse432 const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), return_address) orelse
433 return error.OutOfMemory;433 return error.OutOfMemory;
434 const copy_len = @min(byte_count, old_byte_slice.len);434 const copy_len = @min(byte_count, old_byte_slice.len);
435 @memcpy(new_mem[0..copy_len], old_byte_slice[0..copy_len]);435 @memcpy(new_mem[0..copy_len], old_byte_slice[0..copy_len]);
436 @memset(old_byte_slice, undefined);436 @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
439 return @ptrCast(@alignCast(new_mem[0..byte_count]));439 return @ptrCast(@alignCast(new_mem[0..byte_count]));
440}440}
...@@ -448,7 +448,7 @@ pub fn free(self: Allocator, memory: anytype) void {...@@ -448,7 +448,7 @@ pub fn free(self: Allocator, memory: anytype) void {
448 const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory)));448 const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory)));
449 if (bytes.len == 0) return;449 if (bytes.len == 0) return;
450 @memset(bytes, undefined);450 @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());
452}452}
453453
454/// Copies `m` to newly allocated memory. Caller owns the memory.454/// Copies `m` to newly allocated memory. Caller owns the memory.
lib/std/meta.zig+131-171
...@@ -8,7 +8,7 @@ const root = @import("root");...@@ -8,7 +8,7 @@ const root = @import("root");
88
9pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags;9pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags;
1010
11const Type = std.builtin.Type;11const Type = std.lang.Type;
1212
13test {13test {
14 _ = TrailerFlags;14 _ = TrailerFlags;
...@@ -22,21 +22,21 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {...@@ -22,21 +22,21 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
22 // TODO The '100' here is arbitrary and should be increased when possible:22 // TODO The '100' here is arbitrary and should be increased when possible:
23 // - https://github.com/ziglang/zig/issues/405523 // - https://github.com/ziglang/zig/issues/4055
24 // - https://github.com/ziglang/zig/issues/386324 // - https://github.com/ziglang/zig/issues/3863
25 if (@typeInfo(T).@"enum".fields.len <= 100) {25 if (@typeInfo(T).@"enum".field_names.len <= 100) {
26 const kvs = comptime build_kvs: {26 const kvs = comptime build_kvs: {
27 const EnumKV = struct { []const u8, T };27 const EnumKV = struct { []const u8, T };
28 var kvs_array: [@typeInfo(T).@"enum".fields.len]EnumKV = undefined;28 var kvs_array: [@typeInfo(T).@"enum".field_names.len]EnumKV = undefined;
29 for (@typeInfo(T).@"enum".fields, 0..) |enumField, i| {29 for (@typeInfo(T).@"enum".field_names, 0..) |name, i| {
30 kvs_array[i] = .{ enumField.name, @field(T, enumField.name) };30 kvs_array[i] = .{ name, @field(T, name) };
31 }31 }
32 break :build_kvs kvs_array[0..];32 break :build_kvs kvs_array[0..];
33 };33 };
34 const map = std.StaticStringMap(T).initComptime(kvs);34 const map = std.StaticStringMap(T).initComptime(kvs);
35 return map.get(str);35 return map.get(str);
36 } else {36 } else {
37 inline for (@typeInfo(T).@"enum".fields) |enumField| {37 inline for (@typeInfo(T).@"enum".field_names) |name| {
38 if (mem.eql(u8, str, enumField.name)) {38 if (mem.eql(u8, str, name)) {
39 return @field(T, enumField.name);39 return @field(T, name);
40 }40 }
41 }41 }
42 return null;42 return null;
...@@ -63,7 +63,7 @@ pub fn alignment(comptime T: type) comptime_int {...@@ -63,7 +63,7 @@ pub fn alignment(comptime T: type) comptime_int {
63 .pointer, .@"fn" => alignment(info.child),63 .pointer, .@"fn" => alignment(info.child),
64 else => @alignOf(T),64 else => @alignOf(T),
65 },65 },
66 .pointer => |info| info.alignment orelse @alignOf(info.child),66 .pointer => |info| info.attrs.@"align" orelse @alignOf(info.child),
67 else => @alignOf(T),67 else => @alignOf(T),
68 };68 };
69}69}
...@@ -171,34 +171,20 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -171,34 +171,20 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
171 switch (@typeInfo(T)) {171 switch (@typeInfo(T)) {
172 .pointer => |info| switch (info.size) {172 .pointer => |info| switch (info.size) {
173 .one => switch (@typeInfo(info.child)) {173 .one => switch (@typeInfo(info.child)) {
174 .array => |array_info| return @Pointer(.one, .{174 .array => |array_info| return @Pointer(
175 .@"const" = info.is_const,175 .one,
176 .@"volatile" = info.is_volatile,176 info.attrs,
177 .@"allowzero" = info.is_allowzero,177 [array_info.len:sentinel_val]array_info.child,
178 .@"align" = info.alignment,178 null,
179 .@"addrspace" = info.address_space,179 ),
180 }, [array_info.len:sentinel_val]array_info.child, null),
181 else => {},180 else => {},
182 },181 },
183 .many, .slice => |size| return @Pointer(size, .{182 .many, .slice => |size| return @Pointer(size, info.attrs, info.child, sentinel_val),
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),
190 else => {},183 else => {},
191 },184 },
192 .optional => |info| switch (@typeInfo(info.child)) {185 .optional => |info| switch (@typeInfo(info.child)) {
193 .pointer => |ptr_info| switch (ptr_info.size) {186 .pointer => |ptr_info| switch (ptr_info.size) {
194 .many => return ?@Pointer(.many, .{187 .many => return ?@Pointer(.many, ptr_info.attrs, ptr_info.child, sentinel_val),
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),
202 else => {},188 else => {},
203 },189 },
204 else => {},190 else => {},
...@@ -238,14 +224,14 @@ test containerLayout {...@@ -238,14 +224,14 @@ test containerLayout {
238 try testing.expect(containerLayout(U3) == .@"extern");224 try testing.expect(containerLayout(U3) == .@"extern");
239}225}
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`
242/// directly when you know what kind of type it is.228/// 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 {
244 return switch (@typeInfo(T)) {230 return switch (@typeInfo(T)) {
245 .@"struct" => |info| info.decls,231 .@"struct" => |info| info.decl_names,
246 .@"enum" => |info| info.decls,232 .@"enum" => |info| info.decl_names,
247 .@"union" => |info| info.decls,233 .@"union" => |info| info.decl_names,
248 .@"opaque" => |info| info.decls,234 .@"opaque" => |info| info.decl_names,
249 else => @compileError("Expected struct, enum, union, or opaque type, found '" ++ @typeName(T) ++ "'"),235 else => @compileError("Expected struct, enum, union, or opaque type, found '" ++ @typeName(T) ++ "'"),
250 };236 };
251}237}
...@@ -268,7 +254,7 @@ test declarations {...@@ -268,7 +254,7 @@ test declarations {
268 pub fn a() void {}254 pub fn a() void {}
269 };255 };
270256
271 const decls = comptime [_][]const Type.Declaration{257 const decls = comptime [_][]const [:0]const u8{
272 declarations(E1),258 declarations(E1),
273 declarations(S1),259 declarations(S1),
274 declarations(U1),260 declarations(U1),
...@@ -277,99 +263,43 @@ test declarations {...@@ -277,99 +263,43 @@ test declarations {
277263
278 inline for (decls) |decl| {264 inline for (decls) |decl| {
279 try testing.expect(decl.len == 1);265 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"));
281 }267 }
282}268}
283269
284pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.Declaration {270/// To be removed after Zig 0.17.0 is tagged.
285 inline for (comptime declarations(T)) |decl| {271pub const declarationInfo = @compileError("Deprecated; use '@hasDecl' instead");
286 if (comptime mem.eql(u8, decl.name, decl_name))272/// To be removed after Zig 0.17.0 is tagged.
287 return decl;273pub const fields = @compileError("Deprecated; use 'fieldNames' and 'fieldTypes' instead");
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 };
313274
314 inline for (infos) |info| {275pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {
315 try testing.expect(comptime mem.eql(u8, info.name, "a"));276 .@"struct" => struct { name: [:0]const u8, type: type, attrs: Type.Struct.FieldAttributes },
316 }277 .@"union" => struct { name: [:0]const u8, type: type, attrs: Type.Union.FieldAttributes },
317}278 .@"enum" => struct { name: [:0]const u8, value: comptime_int },
318pub inline fn fields(comptime T: type) switch (@typeInfo(T)) {279 .error_set => struct { name: [:0]const u8 },
319 .@"struct" => []const Type.StructField,
320 .@"union" => []const Type.UnionField,
321 .@"enum" => []const Type.EnumField,
322 .error_set => []const Type.Error,
323 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),280 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
324} {281} {
282 const idx = @intFromEnum(field);
325 return switch (@typeInfo(T)) {283 return switch (@typeInfo(T)) {
326 .@"struct" => |info| info.fields,284 .@"struct" => |info| .{
327 .@"union" => |info| info.fields,285 .name = info.field_names[idx],
328 .@"enum" => |info| info.fields,286 .type = info.field_types[idx],
329 .error_set => |errors| errors.?, // must be non global error set287 .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] },
330 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),299 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
331 };300 };
332}301}
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
373test fieldInfo {303test fieldInfo {
374 const E1 = enum {304 const E1 = enum {
375 A,305 A,
...@@ -395,13 +325,13 @@ test fieldInfo {...@@ -395,13 +325,13 @@ test fieldInfo {
395 try testing.expect(comptime uf.type == u8);325 try testing.expect(comptime uf.type == u8);
396}326}
397327
398pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 {328pub fn fieldNames(comptime T: type) []const [:0]const u8 {
399 return comptime blk: {329 return switch (@typeInfo(T)) {
400 const fieldInfos = fields(T);330 .@"struct" => |s| s.field_names,
401 var names: [fieldInfos.len][:0]const u8 = undefined;331 .@"union" => |u| u.field_names,
402 for (&names, fieldInfos) |*name, field| name.* = field.name;332 .@"enum" => |e| e.field_names,
403 const final = names;333 .error_set => |es| es.error_names.?,
404 break :blk &final;334 else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"),
405 };335 };
406}336}
407337
...@@ -433,14 +363,41 @@ test fieldNames {...@@ -433,14 +363,41 @@ test fieldNames {
433 try testing.expectEqualSlices(u8, u1names[1], "b");363 try testing.expectEqualSlices(u8, u1names[1], "b");
434}364}
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
436/// Given an enum or error set type, returns a pointer to an array containing all tags for that393/// Given an enum or error set type, returns a pointer to an array containing all tags for that
437/// enum or error set.394/// 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 {
439 return comptime blk: {396 return comptime blk: {
440 const fieldInfos = fields(T);397 const field_names = fieldNames(T);
441 var res: [fieldInfos.len]T = undefined;398 var res: [field_names.len]T = undefined;
442 for (fieldInfos, 0..) |field, i| {399 for (field_names, 0..) |field_name, i| {
443 res[i] = @field(T, field.name);400 res[i] = @field(T, field_name);
444 }401 }
445 const final = res;402 const final = res;
446 break :blk &final;403 break :blk &final;
...@@ -491,27 +448,30 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {...@@ -491,27 +448,30 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
491 // because the language does not guarantee that the slice pointers for field names448 // because the language does not guarantee that the slice pointers for field names
492 // and decl names will be the same.449 // and decl names will be the same.
493 comptime {450 comptime {
494 const expected_fields = @typeInfo(expected).@"enum".fields;451 const expected_field_names = @typeInfo(expected).@"enum".field_names;
495 const actual_fields = @typeInfo(actual).@"enum".fields;452 const expected_field_values = @typeInfo(expected).@"enum".field_values;
496 if (expected_fields.len != actual_fields.len) return error.FailedTest;453 const actual_field_names = @typeInfo(actual).@"enum".field_names;
497 for (expected_fields, 0..) |expected_field, i| {454 const actual_field_values = @typeInfo(actual).@"enum".field_values;
498 const actual_field = actual_fields[i];455 if (expected_field_names.len != actual_field_names.len) return error.FailedTest;
499 try testing.expectEqual(expected_field.value, actual_field.value);456 for (expected_field_names, expected_field_values, 0..) |expected_field_name, expected_field_value, i| {
500 try testing.expectEqualStrings(expected_field.name, actual_field.name);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);
501 }461 }
502 }462 }
503 comptime {463 comptime {
504 const expected_decls = @typeInfo(expected).@"enum".decls;464 const expected_decl_names = @typeInfo(expected).@"enum".decl_names;
505 const actual_decls = @typeInfo(actual).@"enum".decls;465 const actual_decl_names = @typeInfo(actual).@"enum".decl_names;
506 if (expected_decls.len != actual_decls.len) return error.FailedTest;466 if (expected_decl_names.len != actual_decl_names.len) return error.FailedTest;
507 for (expected_decls, 0..) |expected_decl, i| {467 for (expected_decl_names, 0..) |expected_decl_name, i| {
508 const actual_decl = actual_decls[i];468 const actual_decl_name = actual_decl_names[i];
509 try testing.expectEqualStrings(expected_decl.name, actual_decl.name);469 try testing.expectEqualStrings(expected_decl_name, actual_decl_name);
510 }470 }
511 }471 }
512 try testing.expectEqual(472 try testing.expectEqual(
513 @typeInfo(expected).@"enum".is_exhaustive,473 @typeInfo(expected).@"enum".mode,
514 @typeInfo(actual).@"enum".is_exhaustive,474 @typeInfo(actual).@"enum".mode,
515 );475 );
516}476}
517477
...@@ -534,11 +494,9 @@ test FieldEnum {...@@ -534,11 +494,9 @@ test FieldEnum {
534}494}
535495
536pub fn DeclEnum(comptime T: type) type {496pub fn DeclEnum(comptime T: type) type {
537 const decls = declarations(T);497 const decl_names = declarations(T);
538 var names: [decls.len][]const u8 = undefined;498 const IntTag = std.math.IntFittingRange(0, decl_names.len -| 1);
539 for (&names, decls) |*name, decl| name.* = decl.name;499 return @Enum(IntTag, .exhaustive, decl_names, &std.simd.iota(IntTag, decl_names.len));
540 const IntTag = std.math.IntFittingRange(0, decls.len -| 1);
541 return @Enum(IntTag, .exhaustive, &names, &std.simd.iota(IntTag, decls.len));
542}500}
543501
544test DeclEnum {502test DeclEnum {
...@@ -622,8 +580,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {...@@ -622,8 +580,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool {
622 .@"struct" => |info| {580 .@"struct" => |info| {
623 if (info.layout == .@"packed") return a == b;581 if (info.layout == .@"packed") return a == b;
624582
625 inline for (info.fields) |field_info| {583 inline for (info.field_names) |field_name| {
626 if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false;584 if (!eql(@field(a, field_name), @field(b, field_name))) return false;
627 }585 }
628 return true;586 return true;
629 },587 },
...@@ -744,8 +702,8 @@ test eql {...@@ -744,8 +702,8 @@ test eql {
744/// Given a type and a name, return the field index according to source order.702/// Given a type and a name, return the field index according to source order.
745/// Returns `null` if the field is not found.703/// Returns `null` if the field is not found.
746pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int {704pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int {
747 inline for (fields(T), 0..) |field, i| {705 inline for (fieldNames(T), 0..) |field_name, i| {
748 if (mem.eql(u8, field.name, name))706 if (mem.eql(u8, field_name, name))
749 return i;707 return i;
750 }708 }
751 return null;709 return null;
...@@ -782,12 +740,12 @@ pub fn ArgsTuple(comptime Function: type) type {...@@ -782,12 +740,12 @@ pub fn ArgsTuple(comptime Function: type) type {
782 @compileError("ArgsTuple expects a function type");740 @compileError("ArgsTuple expects a function type");
783741
784 const function_info = info.@"fn";742 const function_info = info.@"fn";
785 if (function_info.is_var_args)743 if (function_info.attrs.varargs)
786 @compileError("Cannot create ArgsTuple for variadic function");744 @compileError("Cannot create ArgsTuple for variadic function");
787745
788 var argument_field_list: [function_info.params.len]type = undefined;746 var argument_field_list: [function_info.param_types.len]type = undefined;
789 inline for (function_info.params, 0..) |arg, i| {747 inline for (function_info.param_types, 0..) |arg_type, i| {
790 const T = arg.type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");748 const T = arg_type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter");
791 argument_field_list[i] = T;749 argument_field_list[i] = T;
792 }750 }
793751
...@@ -807,13 +765,15 @@ const TupleTester = struct {...@@ -807,13 +765,15 @@ const TupleTester = struct {
807 if (!info.@"struct".is_tuple)765 if (!info.@"struct".is_tuple)
808 @compileError("Struct type must be a tuple type");766 @compileError("Struct type must be a tuple type");
809767
810 const fields_list = std.meta.fields(Actual);768 const field_names = info.@"struct".field_names;
811 if (expected.len != fields_list.len)769 if (expected.len != field_names.len) {
812 @compileError("Argument count mismatch");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| {774 inline for (field_names, info.@"struct".field_types, 0..) |fld_name, fld_type, i| {
815 if (expected[i] != fld.type) {775 if (expected[i] != fld_type) {
816 @compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.type));776 @compileError("Field " ++ fld_name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld_type));
817 }777 }
818 }778 }
819 }779 }
...@@ -943,7 +903,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {...@@ -943,7 +903,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
943 .pointer => |info| info.size != .slice,903 .pointer => |info| info.size != .slice,
944904
945 .optional => |info| switch (@typeInfo(info.child)) {905 .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) {
947 .slice, .c => false,907 .slice, .c => false,
948 .one, .many => true,908 .one, .many => true,
949 },909 },
...@@ -957,10 +917,10 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {...@@ -957,10 +917,10 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool {
957917
958 var sum_size = @as(usize, 0);918 var sum_size = @as(usize, 0);
959919
960 inline for (info.fields) |field| {920 inline for (info.field_attrs, info.field_types) |field_attr, field_type| {
961 if (field.is_comptime) continue;921 if (field_attr.@"comptime") continue;
962 if (!hasUniqueRepresentation(field.type)) return false;922 if (!hasUniqueRepresentation(field_type)) return false;
963 sum_size += @sizeOf(field.type);923 sum_size += @sizeOf(field_type);
964 }924 }
965925
966 return @sizeOf(T) == sum_size;926 return @sizeOf(T) == sum_size;
lib/std/meta/trailer_flags.zig+26-19
...@@ -14,7 +14,7 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -14,7 +14,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
14 bits: Int,14 bits: Int,
1515
16 pub const Int = @Int(.unsigned, bit_count);16 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
19 pub const FieldEnum = std.meta.FieldEnum(Fields);19 pub const FieldEnum = std.meta.FieldEnum(Fields);
2020
...@@ -22,11 +22,18 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -22,11 +22,18 @@ pub fn TrailerFlags(comptime Fields: type) type {
22 pub const FieldValues = blk: {22 pub const FieldValues = blk: {
23 var field_names: [bit_count][]const u8 = undefined;23 var field_names: [bit_count][]const u8 = undefined;
24 var field_types: [bit_count]type = undefined;24 var field_types: [bit_count]type = undefined;
25 var field_attrs: [bit_count]std.builtin.Type.StructField.Attributes = undefined;25 var field_attrs: [bit_count]std.builtin.Type.Struct.FieldAttributes = undefined;
26 for (@typeInfo(Fields).@"struct".fields, &field_names, &field_types, &field_attrs) |field, *new_name, *NewType, *new_attrs| {26 const fields_info = @typeInfo(Fields).@"struct";
27 new_name.* = field.name;27 for (
28 NewType.* = ?field.type;28 fields_info.field_names,
29 const default: ?field.type = null;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;
30 new_attrs.* = .{ .default_value_ptr = &default };37 new_attrs.* = .{ .default_value_ptr = &default };
31 }38 }
32 break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);39 break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
...@@ -53,8 +60,8 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -53,8 +60,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
53 /// `fields` is a boolean struct where each active field is set to `true`60 /// `fields` is a boolean struct where each active field is set to `true`
54 pub fn init(fields: ActiveFields) Self {61 pub fn init(fields: ActiveFields) Self {
55 var self: Self = .{ .bits = 0 };62 var self: Self = .{ .bits = 0 };
56 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {63 inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
57 if (@field(fields, field.name))64 if (@field(fields, field_name))
58 self.bits |= 1 << i;65 self.bits |= 1 << i;
59 }66 }
60 return self;67 return self;
...@@ -62,8 +69,8 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -62,8 +69,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
6269
63 /// `fields` is a struct with each field set to an optional value70 /// `fields` is a struct with each field set to an optional value
64 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {71 pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {
65 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {72 inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
66 if (@field(fields, field.name)) |value|73 if (@field(fields, field_name)) |value|
67 self.set(p, @as(FieldEnum, @enumFromInt(i)), value);74 self.set(p, @as(FieldEnum, @enumFromInt(i)), value);
68 }75 }
69 }76 }
...@@ -93,30 +100,30 @@ pub fn TrailerFlags(comptime Fields: type) type {...@@ -93,30 +100,30 @@ pub fn TrailerFlags(comptime Fields: type) type {
93100
94 pub fn offset(self: Self, comptime field: FieldEnum) usize {101 pub fn offset(self: Self, comptime field: FieldEnum) usize {
95 var off: usize = 0;102 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| {
97 const active = (self.bits & (1 << i)) != 0;104 const active = (self.bits & (1 << i)) != 0;
98 if (i == @intFromEnum(field)) {105 if (i == @intFromEnum(field)) {
99 assert(active);106 assert(active);
100 return mem.alignForward(usize, off, @alignOf(field_info.type));107 return mem.alignForward(usize, off, @alignOf(field_type));
101 } else if (active) {108 } else if (active) {
102 off = mem.alignForward(usize, off, @alignOf(field_info.type));109 off = mem.alignForward(usize, off, @alignOf(field_type));
103 off += @sizeOf(field_info.type);110 off += @sizeOf(field_type);
104 }111 }
105 }112 }
106 }113 }
107114
108 pub fn Field(comptime field: FieldEnum) type {115 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)];
110 }117 }
111118
112 pub fn sizeInBytes(self: Self) usize {119 pub fn sizeInBytes(self: Self) usize {
113 var off: usize = 0;120 var off: usize = 0;
114 inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| {121 inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
115 if (@sizeOf(field.type) == 0)122 if (@sizeOf(field_type) == 0)
116 continue;123 continue;
117 if ((self.bits & (1 << i)) != 0) {124 if ((self.bits & (1 << i)) != 0) {
118 off = mem.alignForward(usize, off, @alignOf(field.type));125 off = mem.alignForward(usize, off, @alignOf(field_type));
119 off += @sizeOf(field.type);126 off += @sizeOf(field_type);
120 }127 }
121 }128 }
122 return off;129 return off;
lib/std/multi_array_list.zig+49-57
...@@ -44,17 +44,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -44,17 +44,7 @@ pub fn MultiArrayList(comptime T: type) type {
44 const Elem = switch (@typeInfo(T)) {44 const Elem = switch (@typeInfo(T)) {
45 .@"struct" => T,45 .@"struct" => T,
46 .@"union" => |u| struct {46 .@"union" => |u| struct {
47 pub const Bare = Bare: {47 pub const Bare = @Union(u.layout, null, u.field_names, u.field_types[0..], u.field_attrs[0..]);
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 };
58 pub const Tag =48 pub const Tag =
59 u.tag_type orelse @compileError("MultiArrayList does not support untagged unions");49 u.tag_type orelse @compileError("MultiArrayList does not support untagged unions");
60 tags: Tag,50 tags: Tag,
...@@ -87,7 +77,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -87,7 +77,7 @@ pub fn MultiArrayList(comptime T: type) type {
87 pub const Slice = struct {77 pub const Slice = struct {
88 /// This array is indexed by the field index which can be obtained78 /// This array is indexed by the field index which can be obtained
89 /// by using @intFromEnum() on the Field enum79 /// by using @intFromEnum() on the Field enum
90 ptrs: [fields.len][*]u8,80 ptrs: [field_names.len][*]u8,
91 len: usize,81 len: usize,
92 capacity: usize,82 capacity: usize,
9383
...@@ -116,15 +106,15 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -116,15 +106,15 @@ pub fn MultiArrayList(comptime T: type) type {
116 .@"union" => Elem.fromT(elem),106 .@"union" => Elem.fromT(elem),
117 else => unreachable,107 else => unreachable,
118 };108 };
119 inline for (fields, 0..) |field_info, i| {109 inline for (field_names, 0..) |field_name, i| {
120 self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_info.name);110 self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_name);
121 }111 }
122 }112 }
123113
124 pub fn get(self: Slice, index: usize) T {114 pub fn get(self: Slice, index: usize) T {
125 var result: Elem = undefined;115 var result: Elem = undefined;
126 inline for (fields, 0..) |field_info, i| {116 inline for (field_names, 0..) |field_name, i| {
127 @field(result, field_info.name) = self.items(@as(Field, @enumFromInt(i)))[index];117 @field(result, field_name) = self.items(@as(Field, @enumFromInt(i)))[index];
128 }118 }
129 return switch (@typeInfo(T)) {119 return switch (@typeInfo(T)) {
130 .@"struct" => result,120 .@"struct" => result,
...@@ -134,9 +124,9 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -134,9 +124,9 @@ pub fn MultiArrayList(comptime T: type) type {
134 }124 }
135125
136 pub fn swap(self: Slice, a: usize, b: usize) void {126 pub fn swap(self: Slice, a: usize, b: usize) void {
137 inline for (@typeInfo(Field).@"enum".fields) |field| {127 inline for (@typeInfo(Field).@"enum".field_names) |field_name| {
138 const its = self.items(@field(Field, field.name));128 const its = self.items(@field(Field, field_name));
139 std.mem.swap(@FieldType(T, field.name), &its[a], &its[b]);129 std.mem.swap(@FieldType(T, field_name), &its[a], &its[b]);
140 }130 }
141 }131 }
142132
...@@ -162,9 +152,9 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -162,9 +152,9 @@ pub fn MultiArrayList(comptime T: type) type {
162 /// Asserts that `off + len <= s.len`.152 /// Asserts that `off + len <= s.len`.
163 pub fn subslice(s: Slice, off: usize, len: usize) Slice {153 pub fn subslice(s: Slice, off: usize, len: usize) Slice {
164 assert(off + len <= s.len);154 assert(off + len <= s.len);
165 var ptrs: [fields.len][*]u8 = undefined;155 var ptrs: [field_names.len][*]u8 = undefined;
166 inline for (s.ptrs, &ptrs, fields) |in, *out, field| {156 inline for (s.ptrs, &ptrs, field_types) |in, *out, field_type| {
167 out.* = in + (off * @sizeOf(field.type));157 out.* = in + (off * @sizeOf(field_type));
168 }158 }
169 return .{159 return .{
170 .ptrs = ptrs,160 .ptrs = ptrs,
...@@ -185,7 +175,9 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -185,7 +175,9 @@ pub fn MultiArrayList(comptime T: type) type {
185175
186 const Self = @This();176 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;
189 /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.181 /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending.
190 /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index.182 /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index.
191 /// `sizes.big_align` is the overall alignment of the allocation, which equals the maximum field alignment.183 /// `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 {...@@ -195,13 +187,13 @@ pub fn MultiArrayList(comptime T: type) type {
195 size_index: usize,187 size_index: usize,
196 alignment: usize,188 alignment: usize,
197 };189 };
198 var data: [fields.len]Data = undefined;190 var data: [field_names.len]Data = undefined;
199 var big_align: usize = 1;191 var big_align: usize = 1;
200 for (fields, 0..) |field_info, i| {192 for (field_types, field_attrs, 0..) |f_type, f_attrs, i| {
201 data[i] = .{193 data[i] = .{
202 .size = @sizeOf(field_info.type),194 .size = @sizeOf(f_type),
203 .size_index = i,195 .size_index = i,
204 .alignment = field_info.alignment orelse @alignOf(field_info.type),196 .alignment = f_attrs.@"align" orelse @alignOf(f_type),
205 };197 };
206 big_align = @max(big_align, data[i].alignment);198 big_align = @max(big_align, data[i].alignment);
207 }199 }
...@@ -211,10 +203,10 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -211,10 +203,10 @@ pub fn MultiArrayList(comptime T: type) type {
211 return lhs.alignment > rhs.alignment;203 return lhs.alignment > rhs.alignment;
212 }204 }
213 };205 };
214 @setEvalBranchQuota(3 * fields.len * std.math.log2(fields.len));206 @setEvalBranchQuota(3 * field_names.len * std.math.log2(field_names.len));
215 mem.sort(Data, &data, {}, Sort.lessThan);207 mem.sort(Data, &data, {}, Sort.lessThan);
216 var sizes_bytes: [fields.len]usize = undefined;208 var sizes_bytes: [field_names.len]usize = undefined;
217 var field_indexes: [fields.len]usize = undefined;209 var field_indexes: [field_names.len]usize = undefined;
218 for (data, 0..) |elem, i| {210 for (data, 0..) |elem, i| {
219 sizes_bytes[i] = elem.size;211 sizes_bytes[i] = elem.size;
220 field_indexes[i] = elem.size_index;212 field_indexes[i] = elem.size_index;
...@@ -368,13 +360,13 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -368,13 +360,13 @@ pub fn MultiArrayList(comptime T: type) type {
368 else => unreachable,360 else => unreachable,
369 };361 };
370 const slices = self.slice();362 const slices = self.slice();
371 inline for (fields, 0..) |field_info, field_index| {363 inline for (field_names, 0..) |field_name, field_index| {
372 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));364 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
373 var i: usize = self.len - 1;365 var i: usize = self.len - 1;
374 while (i > index) : (i -= 1) {366 while (i > index) : (i -= 1) {
375 field_slice[i] = field_slice[i - 1];367 field_slice[i] = field_slice[i - 1];
376 }368 }
377 field_slice[index] = @field(entry, field_info.name);369 field_slice[index] = @field(entry, field_name);
378 }370 }
379 }371 }
380372
...@@ -394,7 +386,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -394,7 +386,7 @@ pub fn MultiArrayList(comptime T: type) type {
394 /// retain list ordering.386 /// retain list ordering.
395 pub fn swapRemove(self: *Self, index: usize) void {387 pub fn swapRemove(self: *Self, index: usize) void {
396 const slices = self.slice();388 const slices = self.slice();
397 inline for (fields, 0..) |_, i| {389 inline for (field_names, 0..) |_, i| {
398 const field_slice = slices.items(@as(Field, @enumFromInt(i)));390 const field_slice = slices.items(@as(Field, @enumFromInt(i)));
399 field_slice[index] = field_slice[self.len - 1];391 field_slice[index] = field_slice[self.len - 1];
400 field_slice[self.len - 1] = undefined;392 field_slice[self.len - 1] = undefined;
...@@ -406,7 +398,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -406,7 +398,7 @@ pub fn MultiArrayList(comptime T: type) type {
406 /// after it to preserve order.398 /// after it to preserve order.
407 pub fn orderedRemove(self: *Self, index: usize) void {399 pub fn orderedRemove(self: *Self, index: usize) void {
408 const slices = self.slice();400 const slices = self.slice();
409 inline for (fields, 0..) |_, field_index| {401 inline for (field_names, 0..) |_, field_index| {
410 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));402 const field_slice = slices.items(@as(Field, @enumFromInt(field_index)));
411 var i = index;403 var i = index;
412 while (i < self.len - 1) : (i += 1) {404 while (i < self.len - 1) : (i += 1) {
...@@ -437,7 +429,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -437,7 +429,7 @@ pub fn MultiArrayList(comptime T: type) type {
437 if (removed == end) continue; // allows duplicates in `sorted_indexes`429 if (removed == end) continue; // allows duplicates in `sorted_indexes`
438 const start = removed + 1;430 const start = removed + 1;
439 const len = end - start; // safety checks `sorted_indexes` are sorted431 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| {
441 const field_slice = slices.items(@enumFromInt(field_index));433 const field_slice = slices.items(@enumFromInt(field_index));
442 @memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]); // safety checks initial `sorted_indexes` are in range434 @memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]); // safety checks initial `sorted_indexes` are in range
443 }435 }
...@@ -446,7 +438,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -446,7 +438,7 @@ pub fn MultiArrayList(comptime T: type) type {
446 const start = sorted_indexes[sorted_indexes.len - 1] + 1;438 const start = sorted_indexes[sorted_indexes.len - 1] + 1;
447 const end = self.len;439 const end = self.len;
448 const len = end - start; // safety checks final `sorted_indexes` are in range440 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| {
450 const field_slice = slices.items(@enumFromInt(field_index));442 const field_slice = slices.items(@enumFromInt(field_index));
451 @memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]);443 @memmove(field_slice[start - shift ..][0..len], field_slice[start..][0..len]);
452 }444 }
...@@ -471,8 +463,8 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -471,8 +463,8 @@ pub fn MultiArrayList(comptime T: type) type {
471463
472 const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch {464 const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch {
473 const self_slice = self.slice();465 const self_slice = self.slice();
474 inline for (fields, 0..) |field_info, i| {466 inline for (field_types, 0..) |field_type, i| {
475 if (@sizeOf(field_info.type) != 0) {467 if (@sizeOf(field_type) != 0) {
476 const field = @as(Field, @enumFromInt(i));468 const field = @as(Field, @enumFromInt(i));
477 const dest_slice = self_slice.items(field)[new_len..];469 const dest_slice = self_slice.items(field)[new_len..];
478 // We use memset here for more efficient codegen in safety-checked,470 // We use memset here for more efficient codegen in safety-checked,
...@@ -492,8 +484,8 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -492,8 +484,8 @@ pub fn MultiArrayList(comptime T: type) type {
492 self.len = new_len;484 self.len = new_len;
493 const self_slice = self.slice();485 const self_slice = self.slice();
494 const other_slice = other.slice();486 const other_slice = other.slice();
495 inline for (fields, 0..) |field_info, i| {487 inline for (field_types, 0..) |field_type, i| {
496 if (@sizeOf(field_info.type) != 0) {488 if (@sizeOf(field_type) != 0) {
497 const field = @as(Field, @enumFromInt(i));489 const field = @as(Field, @enumFromInt(i));
498 @memcpy(other_slice.items(field), self_slice.items(field));490 @memcpy(other_slice.items(field), self_slice.items(field));
499 }491 }
...@@ -529,7 +521,7 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -529,7 +521,7 @@ pub fn MultiArrayList(comptime T: type) type {
529521
530 const init_capacity: comptime_int = init: {522 const init_capacity: comptime_int = init: {
531 var max: comptime_int = 1;523 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));
533 break :init @max(1, std.atomic.cache_line / max);525 break :init @max(1, std.atomic.cache_line / max);
534 };526 };
535527
...@@ -564,8 +556,8 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -564,8 +556,8 @@ pub fn MultiArrayList(comptime T: type) type {
564 };556 };
565 const self_slice = self.slice();557 const self_slice = self.slice();
566 const other_slice = other.slice();558 const other_slice = other.slice();
567 inline for (fields, 0..) |field_info, i| {559 inline for (field_types, 0..) |field_type, i| {
568 if (@sizeOf(field_info.type) != 0) {560 if (@sizeOf(field_type) != 0) {
569 const field = @as(Field, @enumFromInt(i));561 const field = @as(Field, @enumFromInt(i));
570 @memcpy(other_slice.items(field), self_slice.items(field));562 @memcpy(other_slice.items(field), self_slice.items(field));
571 }563 }
...@@ -583,8 +575,8 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -583,8 +575,8 @@ pub fn MultiArrayList(comptime T: type) type {
583 result.len = self.len;575 result.len = self.len;
584 const self_slice = self.slice();576 const self_slice = self.slice();
585 const result_slice = result.slice();577 const result_slice = result.slice();
586 inline for (fields, 0..) |field_info, i| {578 inline for (field_types, 0..) |field_type, i| {
587 if (@sizeOf(field_info.type) != 0) {579 if (@sizeOf(field_type) != 0) {
588 const field = @as(Field, @enumFromInt(i));580 const field = @as(Field, @enumFromInt(i));
589 @memcpy(result_slice.items(field), self_slice.items(field));581 @memcpy(result_slice.items(field), self_slice.items(field));
590 }582 }
...@@ -600,11 +592,11 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -600,11 +592,11 @@ pub fn MultiArrayList(comptime T: type) type {
600 slice: Slice,592 slice: Slice,
601593
602 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {594 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
603 inline for (fields, 0..) |field_info, i| {595 inline for (field_types, 0..) |field_type, i| {
604 if (@sizeOf(field_info.type) != 0) {596 if (@sizeOf(field_type) != 0) {
605 const field: Field = @enumFromInt(i);597 const field: Field = @enumFromInt(i);
606 const ptr = sc.slice.items(field);598 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]);
608 }600 }
609 }601 }
610 }602 }
...@@ -676,18 +668,18 @@ pub fn MultiArrayList(comptime T: type) type {...@@ -676,18 +668,18 @@ pub fn MultiArrayList(comptime T: type) type {
676 }668 }
677669
678 const Entry = entry: {670 const Entry = entry: {
679 var field_names: [fields.len][]const u8 = undefined;671 var entry_field_names: [field_names.len][]const u8 = undefined;
680 var field_types: [fields.len]type = undefined;672 var entry_field_types: [field_names.len]type = undefined;
681 var field_attrs: [fields.len]std.builtin.Type.StructField.Attributes = undefined;673 var entry_field_attrs: [field_names.len]std.builtin.Type.Struct.FieldAttributes = undefined;
682 for (sizes.fields, &field_names, &field_types, &field_attrs) |i, *name, *Type, *attrs| {674 for (sizes.fields, &entry_field_names, &entry_field_types, &entry_field_attrs) |i, *name, *Type, *attrs| {
683 name.* = fields[i].name ++ "_ptr";675 name.* = field_names[i] ++ "_ptr";
684 Type.* = *fields[i].type;676 Type.* = *field_types[i];
685 attrs.* = .{677 attrs.* = .{
686 .@"comptime" = fields[i].is_comptime,678 .@"comptime" = field_attrs[i].@"comptime",
687 .@"align" = fields[i].alignment,679 .@"align" = field_attrs[i].@"align",
688 };680 };
689 }681 }
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);
691 };683 };
692 /// This function is used in the debugger pretty formatters in tools/ to fetch the684 /// This function is used in the debugger pretty formatters in tools/ to fetch the
693 /// child field order and entry type to facilitate fancy debug printing for this type.685 /// 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 {...@@ -82,16 +82,17 @@ pub const DevicePath = extern struct {
82 }82 }
8383
84 pub fn getDevicePath(self: *const DevicePath) ?uefi.DevicePath {84 pub fn getDevicePath(self: *const DevicePath) ?uefi.DevicePath {
85 inline for (@typeInfo(uefi.DevicePath).@"union".fields) |ufield| {85 const u_info = @typeInfo(uefi.DevicePath).@"union";
86 const enum_value = std.meta.stringToEnum(uefi.DevicePath.Type, ufield.name);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
88 // Got the associated union type for self.type, now89 // Got the associated union type for self.type, now
89 // we need to initialize it and its subtype90 // we need to initialize it and its subtype
90 if (self.type == enum_value) {91 if (self.type == enum_value) {
91 const subtype = self.initSubtype(ufield.type);92 const subtype = self.initSubtype(ufield_type);
92 if (subtype) |sb| {93 if (subtype) |sb| {
93 // e.g. return .{ .hardware = .{ .pci = @ptrCast(...) } }94 // e.g. return .{ .hardware = .{ .pci = @ptrCast(...) } }
94 return @unionInit(uefi.DevicePath, ufield.name, sb);95 return @unionInit(uefi.DevicePath, ufield_name, sb);
95 }96 }
96 }97 }
97 }98 }
...@@ -103,13 +104,13 @@ pub const DevicePath = extern struct {...@@ -103,13 +104,13 @@ pub const DevicePath = extern struct {
103 const type_info = @typeInfo(TUnion).@"union";104 const type_info = @typeInfo(TUnion).@"union";
104 const TTag = type_info.tag_type.?;105 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| {
107 // The tag names match the union names, so just grab that off the enum108 // 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
110 if (self.subtype == tag_val) {111 if (self.subtype == tag_val) {
111 // e.g. expr = .{ .pci = @ptrCast(...) }112 // 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)));
113 }114 }
114 }115 }
115116
lib/std/os/uefi/tables/boot_services.zig+1-1
...@@ -1271,7 +1271,7 @@ fn ProtocolInterfaces(HandleType: type, Interfaces: type) type {...@@ -1271,7 +1271,7 @@ fn ProtocolInterfaces(HandleType: type, Interfaces: type) type {
1271 @compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces));1271 @compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces));
1272 const interfaces_info = interfaces_type_info.@"struct";1272 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;
1275 tuple_types[0] = HandleType;1275 tuple_types[0] = HandleType;
1276 tuple_types[tuple_types.len - 1] = ?*const Guid;1276 tuple_types[tuple_types.len - 1] = ?*const Guid;
12771277
lib/std/os/windows.zig+9-15
...@@ -144,7 +144,7 @@ pub const OBJECT = struct {...@@ -144,7 +144,7 @@ pub const OBJECT = struct {
144 Session = 5,144 Session = 5,
145 _,145 _,
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;
148 };148 };
149149
150 pub const NAME_INFORMATION = extern struct {150 pub const NAME_INFORMATION = extern struct {
...@@ -575,7 +575,7 @@ pub const FILE = struct {...@@ -575,7 +575,7 @@ pub const FILE = struct {
575 MupProvider = 83,575 MupProvider = 83,
576 _,576 _,
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;
579 };579 };
580580
581 pub const BASIC_INFORMATION = extern struct {581 pub const BASIC_INFORMATION = extern struct {
...@@ -881,7 +881,7 @@ pub const DIRECTORY = struct {...@@ -881,7 +881,7 @@ pub const DIRECTORY = struct {
881 NotifyFull = 3,881 NotifyFull = 3,
882 _,882 _,
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;
885 };885 };
886};886};
887887
...@@ -930,14 +930,8 @@ pub const CONSOLE = struct {...@@ -930,14 +930,8 @@ pub const CONSOLE = struct {
930930
931 pub const Tag = @typeInfo(WITH).@"union".tag_type.?;931 pub const Tag = @typeInfo(WITH).@"union".tag_type.?;
932 pub const Payload = PAYLOAD: {932 pub const Payload = PAYLOAD: {
933 const with_fields = @typeInfo(WITH).@"union".fields;933 const with_info = @typeInfo(WITH).@"union";
934 var field_names: [with_fields.len][]const u8 = undefined;934 break :PAYLOAD @Union(.@"extern", null, with_info.field_names, with_info.field_types[0..], &@splat(.{}));
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(.{}));
941 };935 };
942 };936 };
943 };937 };
...@@ -2122,7 +2116,7 @@ pub const HEAP = opaque {...@@ -2122,7 +2116,7 @@ pub const HEAP = opaque {
2122 Custom,2116 Custom,
2123 _,2117 _,
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;
2126 };2120 };
21272121
2128 pub const VA_CALLBACKS = extern struct {2122 pub const VA_CALLBACKS = extern struct {
...@@ -3369,7 +3363,7 @@ pub const FS_INFORMATION_CLASS = enum(c_int) {...@@ -3369,7 +3363,7 @@ pub const FS_INFORMATION_CLASS = enum(c_int) {
3369 Guid = 15,3363 Guid = 15,
3370 _,3364 _,
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;
3373};3367};
33743368
3375pub const SECTION_INHERIT = enum(c_int) {3369pub const SECTION_INHERIT = enum(c_int) {
...@@ -3493,7 +3487,7 @@ pub const MEM = struct {...@@ -3493,7 +3487,7 @@ pub const MEM = struct {
3493 ImageMachine,3487 ImageMachine,
3494 _,3488 _,
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;
3497 };3491 };
3498 };3492 };
3499};3493};
...@@ -4467,7 +4461,7 @@ pub const KEY = struct {...@@ -4467,7 +4461,7 @@ pub const KEY = struct {
4467 Layer = 5,4461 Layer = 5,
4468 _,4462 _,
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;
4471 };4465 };
44724466
4473 pub const PARTIAL_INFORMATION = extern struct {4467 pub const PARTIAL_INFORMATION = extern struct {
lib/std/posix/test.zig+2-2
...@@ -332,8 +332,8 @@ test "fsync" {...@@ -332,8 +332,8 @@ test "fsync" {
332test "getrlimit and setrlimit" {332test "getrlimit and setrlimit" {
333 if (posix.system.rlimit_resource == void) return error.SkipZigTest;333 if (posix.system.rlimit_resource == void) return error.SkipZigTest;
334334
335 inline for (@typeInfo(posix.rlimit_resource).@"enum".fields) |field| {335 inline for (@typeInfo(posix.rlimit_resource).@"enum".field_values) |field_value| {
336 const resource: posix.rlimit_resource = @enumFromInt(field.value);336 const resource: posix.rlimit_resource = @enumFromInt(field_value);
337 const limit = try posix.getrlimit(resource);337 const limit = try posix.getrlimit(resource);
338338
339 // XNU kernel does not support RLIMIT_STACK if a custom stack is active,339 // XNU kernel does not support RLIMIT_STACK if a custom stack is active,
lib/std/start.zig+6-6
...@@ -24,7 +24,7 @@ comptime {...@@ -24,7 +24,7 @@ comptime {
24 if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {24 if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
25 @export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });25 @export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
26 } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "DllMain")) {26 } 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)) {
28 @export(&DllMain, .{ .name = "DllMain" });28 @export(&DllMain, .{ .name = "DllMain" });
29 }29 }
30 }30 }
...@@ -32,11 +32,11 @@ comptime {...@@ -32,11 +32,11 @@ comptime {
32 if (builtin.link_libc and @hasDecl(root, "main")) {32 if (builtin.link_libc and @hasDecl(root, "main")) {
33 if (is_wasm) {33 if (is_wasm) {
34 @export(&mainWithoutEnv, .{ .name = "__main_argc_argv" });34 @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)) {
36 @export(&main, .{ .name = "main" });36 @export(&main, .{ .name = "main" });
37 }37 }
38 } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "wWinMain")) {38 } 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)) {
40 @export(&wWinMain, .{ .name = "wWinMain" });40 @export(&wWinMain, .{ .name = "wWinMain" });
41 }41 }
42 } else if (native_os == .windows) {42 } else if (native_os == .windows) {
...@@ -728,8 +728,8 @@ var safe_allocator: std.heap.SafeAllocator = .init(std.heap.page_allocator, .{})...@@ -728,8 +728,8 @@ var safe_allocator: std.heap.SafeAllocator = .init(std.heap.page_allocator, .{})
728728
729inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.Block) u8 {729inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.Block) u8 {
730 const fn_info = @typeInfo(@TypeOf(root.main)).@"fn";730 const fn_info = @typeInfo(@TypeOf(root.main)).@"fn";
731 if (fn_info.params.len == 0) return wrapMain(root.main());731 if (fn_info.param_types.len == 0) return wrapMain(root.main());
732 if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{732 if (fn_info.param_types[0].? == std.process.Init.Minimal) return wrapMain(root.main(.{
733 .args = .{ .vector = args },733 .args = .{ .vector = args },
734 .environ = .{ .block = environ },734 .environ = .{ .block = environ },
735 }));735 }));
...@@ -809,7 +809,7 @@ inline fn wrapMain(result: anytype) u8 {...@@ -809,7 +809,7 @@ inline fn wrapMain(result: anytype) u8 {
809809
810fn call_wWinMain() std.os.windows.INT {810fn call_wWinMain() std.os.windows.INT {
811 const peb = std.os.windows.peb();811 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].?;
813 const hInstance: MAIN_HINSTANCE = @ptrCast(peb.ImageBaseAddress);813 const hInstance: MAIN_HINSTANCE = @ptrCast(peb.ImageBaseAddress);
814 const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer);814 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 {...@@ -141,16 +141,16 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void {
141 },141 },
142142
143 .@"struct" => |structType| {143 .@"struct" => |structType| {
144 inline for (structType.fields) |field| {144 inline for (structType.field_names) |field_name| {
145 try expectEqual(@field(expected, field.name), @field(actual, field.name));145 try expectEqual(@field(expected, field_name), @field(actual, field_name));
146 }146 }
147 },147 },
148148
149 .@"union" => |union_info| {149 .@"union" => |union_info| {
150 if (union_info.tag_type == null) {150 if (union_info.tag_type == null) {
151 const first_size = @bitSizeOf(union_info.fields[0].type);151 const first_size = @bitSizeOf(union_info.field_types[0]);
152 inline for (union_info.fields) |field| {152 inline for (union_info.field_types) |field_type| {
153 if (@bitSizeOf(field.type) != first_size) {153 if (@bitSizeOf(field_type) != first_size) {
154 @compileError("Unable to compare untagged unions with varying field sizes for type " ++ @typeName(@TypeOf(actual)));154 @compileError("Unable to compare untagged unions with varying field sizes for type " ++ @typeName(@TypeOf(actual)));
155 }155 }
156 }156 }
...@@ -840,9 +840,9 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe...@@ -840,9 +840,9 @@ fn expectEqualDeepInner(comptime T: type, expected: T, actual: T) error{TestExpe
840 },840 },
841841
842 .@"struct" => |structType| {842 .@"struct" => |structType| {
843 inline for (structType.fields) |field| {843 inline for (structType.field_names) |field_name| {
844 expectEqualDeep(@field(expected, field.name), @field(actual, field.name)) catch |e| {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) });845 print("Field {s} incorrect. expected {any}, found {any}\n", .{ field_name, @field(expected, field_name), @field(actual, field_name) });
846 return e;846 return e;
847 };847 };
848 }848 }
...@@ -1165,14 +1165,14 @@ fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type {...@@ -1165,14 +1165,14 @@ fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type {
11651165
1166 const ArgsTuple = std.meta.ArgsTuple(TestFn);1166 const ArgsTuple = std.meta.ArgsTuple(TestFn);
11671167
1168 const fields = @typeInfo(ArgsTuple).@"struct".fields;1168 const field_types = @typeInfo(ArgsTuple).@"struct".field_types;
1169 if (fields.len == 0 or fields[0].type != std.mem.Allocator) {1169 if (field_types.len == 0 or field_types[0] != std.mem.Allocator) {
1170 @compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument");1170 @compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument");
1171 }1171 }
11721172
1173 var extra_args: [fields.len - 1]type = undefined;1173 var extra_args: [field_types.len - 1]type = undefined;
1174 for (&extra_args, fields[1..]) |*arg, field| {1174 for (&extra_args, field_types[1..]) |*arg, field_type| {
1175 arg.* = field.type;1175 arg.* = field_type;
1176 }1176 }
11771177
1178 return @Tuple(&extra_args);1178 return @Tuple(&extra_args);
...@@ -1204,8 +1204,8 @@ test "checkAllAllocationFailures provide result type to 'extra_args' argument" {...@@ -1204,8 +1204,8 @@ test "checkAllAllocationFailures provide result type to 'extra_args' argument" {
1204/// Given a type, references all the declarations inside, so that the semantic analyzer sees them.1204/// Given a type, references all the declarations inside, so that the semantic analyzer sees them.
1205pub fn refAllDecls(comptime T: type) void {1205pub fn refAllDecls(comptime T: type) void {
1206 if (!builtin.is_test) return;1206 if (!builtin.is_test) return;
1207 inline for (comptime std.meta.declarations(T)) |decl| {1207 inline for (comptime std.meta.declarations(T)) |decl_name| {
1208 _ = &@field(T, decl.name);1208 _ = &@field(T, decl_name);
1209 }1209 }
1210}1210}
12111211
lib/std/testing/Smith.zig+35-21
...@@ -35,7 +35,12 @@ fn fromExcessK(T: type, x: Backing(T)) T {...@@ -35,7 +35,12 @@ fn fromExcessK(T: type, x: Backing(T)) T {
35 return @as(T, @bitCast(x)) +% std.math.minInt(T);35 return @as(T, @bitCast(x)) +% std.math.minInt(T);
36}36}
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 {
39 return a.value < b.value;44 return a.value < b.value;
40}45}
4146
...@@ -67,17 +72,26 @@ pub inline fn baselineWeights(T: type) []const Weight {...@@ -67,17 +72,26 @@ pub inline fn baselineWeights(T: type) []const Weight {
67 baselineWeights(Backing(T))72 baselineWeights(Backing(T))
68 else73 else
69 @compileError("non-packed unions cannot be weighted"),74 @compileError("non-packed unions cannot be weighted"),
70 .@"enum" => |e| if (!e.is_exhaustive)75 .@"enum" => |e| if (e.mode == .nonexhaustive)
71 baselineWeights(e.tag_type)76 baselineWeights(e.tag_type)
72 else if (e.fields.len == 0)77 else if (e.field_names.len == 0)
73 // Cannot be included in below branch due to `log2_int_ceil`78 // Cannot be included in below branch due to `log2_int_ceil`
74 @compileError("exhaustive zero-field enums cannot be weighted")79 @compileError("exhaustive zero-field enums cannot be weighted")
75 else e: {80 else e: {
76 @setEvalBranchQuota(@intCast(4 * e.fields.len *81 @setEvalBranchQuota(@intCast(4 * e.field_names.len *
77 std.math.log2_int_ceil(usize, e.fields.len)));82 std.math.log2_int_ceil(usize, e.field_names.len)));
7883
79 var sorted_fields = e.fields[0..e.fields.len].*;84 var sorted_fields = blk: {
80 std.mem.sortUnstable(std.builtin.Type.EnumField, &sorted_fields, {}, enumFieldLessThan);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
82 var weights: []const Weight = &.{};96 var weights: []const Weight = &.{};
83 var seq_first: u64 = sorted_fields[0].value;97 var seq_first: u64 = sorted_fields[0].value;
...@@ -316,10 +330,10 @@ fn weightsContain(int: u64, weights: []const Weight) bool {...@@ -316,10 +330,10 @@ fn weightsContain(int: u64, weights: []const Weight) bool {
316inline fn allBitPatternsValid(T: type) bool {330inline fn allBitPatternsValid(T: type) bool {
317 return comptime switch (@typeInfo(T)) {331 return comptime switch (@typeInfo(T)) {
318 .void, .bool, .int, .float => true,332 .void, .bool, .int, .float => true,
319 inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.fields) |f| {333 inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.field_types) |f_type| {
320 if (!allBitPatternsValid(f.type)) break false;334 if (!allBitPatternsValid(f_type)) break false;
321 } else true,335 } else true,
322 .@"enum" => |e| !e.is_exhaustive,336 .@"enum" => |e| e.mode == .nonexhaustive,
323 else => unreachable,337 else => unreachable,
324 };338 };
325}339}
...@@ -346,16 +360,16 @@ fn UnionTagWithoutUninitializable(T: type) type {...@@ -346,16 +360,16 @@ fn UnionTagWithoutUninitializable(T: type) type {
346 const u = @typeInfo(T).@"union";360 const u = @typeInfo(T).@"union";
347 const Tag = u.tag_type orelse @compileError("union must have tag");361 const Tag = u.tag_type orelse @compileError("union must have tag");
348 const e = @typeInfo(Tag).@"enum";362 const e = @typeInfo(Tag).@"enum";
349 var field_names: [e.fields.len][]const u8 = undefined;363 var field_names: [e.field_names.len][]const u8 = undefined;
350 var field_values: [e.fields.len]e.tag_type = undefined;364 var field_values: [e.field_names.len]e.tag_type = undefined;
351 var n_fields = 0;365 var n_fields = 0;
352 for (u.fields) |f| {366 for (u.field_names, u.field_types) |f_name, f_type| {
353 switch (f.type) {367 switch (f_type) {
354 noreturn => continue,368 noreturn => continue,
355 else => {},369 else => {},
356 }370 }
357 field_names[n_fields] = f.name;371 field_names[n_fields] = f_name;
358 field_values[n_fields] = @intFromEnum(@field(Tag, f.name));372 field_values[n_fields] = @intFromEnum(@field(Tag, f_name));
359 n_fields += 1;373 n_fields += 1;
360 }374 }
361 return @Enum(e.tag_type, .exhaustive, field_names[0..n_fields], field_values[0..n_fields]);375 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 {...@@ -381,12 +395,12 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {
381 }395 }
382 break :full @bitCast(int);396 break :full @bitCast(int);
383 },397 },
384 .@"enum" => |e| if (e.is_exhaustive) v: {398 .@"enum" => |e| if (e.mode == .exhaustive) v: {
385 if (@bitSizeOf(e.tag_type) <= 64) {399 if (@bitSizeOf(e.tag_type) <= 64) {
386 break :v s.valueWeightedWithHash(T, baselineWeights(T), hash);400 break :v s.valueWeightedWithHash(T, baselineWeights(T), hash);
387 }401 }
388 break :v std.enums.fromInt(T, s.valueWithHash(e.tag_type, hash)) orelse402 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]);
390 } else @enumFromInt(s.valueWithHash(e.tag_type, hash)),404 } else @enumFromInt(s.valueWithHash(e.tag_type, hash)),
391 .optional => |o| if (s.valueWithHash(bool, hash))405 .optional => |o| if (s.valueWithHash(bool, hash))
392 null406 null
...@@ -406,11 +420,11 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {...@@ -406,11 +420,11 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T {
406 .@"struct" => |st| if (!allBitPatternsValid(T)) v: {420 .@"struct" => |st| if (!allBitPatternsValid(T)) v: {
407 var v: T = undefined;421 var v: T = undefined;
408 var rhash = hash;422 var rhash = hash;
409 inline for (st.fields) |f| {423 inline for (st.field_names, st.field_types) |f_name, f_type| {
410 // rhash is incremented in the call so our rhash state is not reused (e.g. with424 // rhash is incremented in the call so our rhash state is not reused (e.g. with
411 // two nested structs. note that xor cannot work for this case as the bit would425 // two nested structs. note that xor cannot work for this case as the bit would
412 // be flipped back here)426 // 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);
414 rhash = std.hash.int(rhash);428 rhash = std.hash.int(rhash);
415 }429 }
416 break :v v;430 break :v v;
lib/std/zig.zig+4-4
...@@ -736,8 +736,8 @@ pub fn parseTargetQueryOrReportFatalError(...@@ -736,8 +736,8 @@ pub fn parseTargetQueryOrReportFatalError(
736 help: {736 help: {
737 var help_text = std.array_list.Managed(u8).init(allocator);737 var help_text = std.array_list.Managed(u8).init(allocator);
738 defer help_text.deinit();738 defer help_text.deinit();
739 inline for (@typeInfo(std.Target.ObjectFormat).@"enum".fields) |field| {739 inline for (@typeInfo(std.Target.ObjectFormat).@"enum".field_names) |field_name| {
740 help_text.print(" {s}\n", .{field.name}) catch break :help;740 help_text.print(" {s}\n", .{field_name}) catch break :help;
741 }741 }
742 std.log.info("available object formats:\n{s}", .{help_text.items});742 std.log.info("available object formats:\n{s}", .{help_text.items});
743 }743 }
...@@ -747,8 +747,8 @@ pub fn parseTargetQueryOrReportFatalError(...@@ -747,8 +747,8 @@ pub fn parseTargetQueryOrReportFatalError(
747 help: {747 help: {
748 var help_text = std.array_list.Managed(u8).init(allocator);748 var help_text = std.array_list.Managed(u8).init(allocator);
749 defer help_text.deinit();749 defer help_text.deinit();
750 inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".fields) |field| {750 inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".field_names) |field_name| {
751 help_text.print(" {s}\n", .{field.name}) catch break :help;751 help_text.print(" {s}\n", .{field_name}) catch break :help;
752 }752 }
753 std.log.info("available architectures:\n{s} native\n", .{help_text.items});753 std.log.info("available architectures:\n{s} native\n", .{help_text.items});
754 }754 }
lib/std/zig/Ast.zig+4-4
...@@ -298,17 +298,17 @@ pub fn extraDataSliceWithLen(tree: Ast, start: ExtraIndex, len: u32, comptime T:...@@ -298,17 +298,17 @@ pub fn extraDataSliceWithLen(tree: Ast, start: ExtraIndex, len: u32, comptime T:
298}298}
299299
300pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T {300pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T {
301 const fields = std.meta.fields(T);301 const info = @typeInfo(T).@"struct";
302 var result: T = undefined;302 var result: T = undefined;
303 inline for (fields, 0..) |field, i| {303 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
304 @field(result, field.name) = switch (field.type) {304 @field(result, field_name) = switch (field_type) {
305 Node.Index,305 Node.Index,
306 Node.OptionalIndex,306 Node.OptionalIndex,
307 OptionalTokenIndex,307 OptionalTokenIndex,
308 ExtraIndex,308 ExtraIndex,
309 => @enumFromInt(tree.extra_data[@intFromEnum(index) + i]),309 => @enumFromInt(tree.extra_data[@intFromEnum(index) + i]),
310 TokenIndex => tree.extra_data[@intFromEnum(index) + i],310 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)),
312 };312 };
313 }313 }
314 return result;314 return result;
lib/std/zig/AstGen.zig+42-42
...@@ -74,25 +74,25 @@ src_hasher: std.zig.SrcHasher,...@@ -74,25 +74,25 @@ src_hasher: std.zig.SrcHasher,
74const InnerError = error{ OutOfMemory, AnalysisFail };74const InnerError = error{ OutOfMemory, AnalysisFail };
7575
76fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {76fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 {
77 const fields = std.meta.fields(@TypeOf(extra));77 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
78 try astgen.extra.ensureUnusedCapacity(astgen.gpa, fields.len);78 try astgen.extra.ensureUnusedCapacity(astgen.gpa, field_count);
79 return addExtraAssumeCapacity(astgen, extra);79 return addExtraAssumeCapacity(astgen, extra);
80}80}
8181
82fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {82fn addExtraAssumeCapacity(astgen: *AstGen, extra: anytype) u32 {
83 const fields = std.meta.fields(@TypeOf(extra));83 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
84 const extra_index: u32 = @intCast(astgen.extra.items.len);84 const extra_index: u32 = @intCast(astgen.extra.items.len);
85 astgen.extra.items.len += fields.len;85 astgen.extra.items.len += field_count;
86 setExtra(astgen, extra_index, extra);86 setExtra(astgen, extra_index, extra);
87 return extra_index;87 return extra_index;
88}88}
8989
90fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {90fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
91 const fields = std.meta.fields(@TypeOf(extra));91 const info = @typeInfo(@TypeOf(extra)).@"struct";
92 var i = index;92 var i = index;
93 inline for (fields) |field| {93 inline for (info.field_names, info.field_types) |field_name, field_type| {
94 astgen.extra.items[i] = switch (field.type) {94 astgen.extra.items[i] = switch (field_type) {
95 u32 => @field(extra, field.name),95 u32 => @field(extra, field_name),
9696
97 Zir.Inst.Ref,97 Zir.Inst.Ref,
98 Zir.Inst.Index,98 Zir.Inst.Index,
...@@ -103,13 +103,13 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {...@@ -103,13 +103,13 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
103 Ast.OptionalTokenIndex,103 Ast.OptionalTokenIndex,
104 Ast.Node.Index,104 Ast.Node.Index,
105 Ast.Node.OptionalIndex,105 Ast.Node.OptionalIndex,
106 => @intFromEnum(@field(extra, field.name)),106 => @intFromEnum(@field(extra, field_name)),
107107
108 Ast.TokenOffset,108 Ast.TokenOffset,
109 Ast.OptionalTokenOffset,109 Ast.OptionalTokenOffset,
110 Ast.Node.Offset,110 Ast.Node.Offset,
111 Ast.Node.OptionalOffset,111 Ast.Node.OptionalOffset,
112 => @bitCast(@intFromEnum(@field(extra, field.name))),112 => @bitCast(@intFromEnum(@field(extra, field_name))),
113113
114 i32,114 i32,
115 Zir.Inst.Call.Flags,115 Zir.Inst.Call.Flags,
...@@ -118,7 +118,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {...@@ -118,7 +118,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void {
118 Zir.Inst.FuncFancy.Bits,118 Zir.Inst.FuncFancy.Bits,
119 Zir.Inst.Param.Type,119 Zir.Inst.Param.Type,
120 Zir.Inst.Func.RetTy,120 Zir.Inst.Func.RetTy,
121 => @bitCast(@field(extra, field.name)),121 => @bitCast(@field(extra, field_name)),
122122
123 else => @compileError("bad field type"),123 else => @compileError("bad field type"),
124 };124 };
...@@ -166,7 +166,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -166,7 +166,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
166 try astgen.instructions.ensureTotalCapacity(gpa, tree.nodes.len);166 try astgen.instructions.ensureTotalCapacity(gpa, tree.nodes.len);
167167
168 // First few indexes of extra are reserved and set at the end.168 // 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;
170 try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count);170 try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count);
171 astgen.extra.items.len += reserved_count;171 astgen.extra.items.len += reserved_count;
172172
...@@ -212,7 +212,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -212,7 +212,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
212 astgen.extra.items[err_index] = 0;212 astgen.extra.items[err_index] = 0;
213 } else {213 } else {
214 try astgen.extra.ensureUnusedCapacity(gpa, 1 + astgen.compile_errors.items.len *214 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
217 astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{217 astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{
218 .items_len = @intCast(astgen.compile_errors.items.len),218 .items_len = @intCast(astgen.compile_errors.items.len),
...@@ -227,8 +227,8 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {...@@ -227,8 +227,8 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir {
227 if (astgen.imports.count() == 0) {227 if (astgen.imports.count() == 0) {
228 astgen.extra.items[imports_index] = 0;228 astgen.extra.items[imports_index] = 0;
229 } else {229 } else {
230 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Imports).@"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".fields.len);231 astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).@"struct".field_names.len);
232232
233 astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{233 astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{
234 .imports_len = @intCast(astgen.imports.count()),234 .imports_len = @intCast(astgen.imports.count()),
...@@ -1888,7 +1888,7 @@ fn structInitExprAnon(...@@ -1888,7 +1888,7 @@ fn structInitExprAnon(
1888 .abs_line = astgen.source_line,1888 .abs_line = astgen.source_line,
1889 .fields_len = @intCast(struct_init.ast.fields.len),1889 .fields_len = @intCast(struct_init.ast.fields.len),
1890 });1890 });
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;
1892 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);1892 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
18931893
1894 for (struct_init.ast.fields) |field_init| {1894 for (struct_init.ast.fields) |field_init| {
...@@ -1921,7 +1921,7 @@ fn structInitExprTyped(...@@ -1921,7 +1921,7 @@ fn structInitExprTyped(
1921 .abs_line = astgen.source_line,1921 .abs_line = astgen.source_line,
1922 .fields_len = @intCast(struct_init.ast.fields.len),1922 .fields_len = @intCast(struct_init.ast.fields.len),
1923 });1923 });
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;
1925 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);1925 var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size);
19261926
1927 for (struct_init.ast.fields) |field_init| {1927 for (struct_init.ast.fields) |field_init| {
...@@ -3804,7 +3804,7 @@ fn ptrType(...@@ -3804,7 +3804,7 @@ fn ptrType(
3804 const gpa = gz.astgen.gpa;3804 const gpa = gz.astgen.gpa;
3805 try gz.instructions.ensureUnusedCapacity(gpa, 1);3805 try gz.instructions.ensureUnusedCapacity(gpa, 1);
3806 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);3806 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 +
3808 trailing_count);3808 trailing_count);
38093809
3810 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.PtrType{3810 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.PtrType{
...@@ -5096,7 +5096,7 @@ fn tupleDecl(...@@ -5096,7 +5096,7 @@ fn tupleDecl(
50965096
5097 const extra_trail = astgen.scratch.items[fields_start..];5097 const extra_trail = astgen.scratch.items[fields_start..];
5098 assert(extra_trail.len == fields_len * 2);5098 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);
5100 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.TupleDecl{5100 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.TupleDecl{
5101 .src_node = gz.nodeIndexToRelative(node),5101 .src_node = gz.nodeIndexToRelative(node),
5102 });5102 });
...@@ -5670,7 +5670,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi...@@ -5670,7 +5670,7 @@ fn errorSetDecl(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index) InnerError!Zi
5670 const gpa = astgen.gpa;5670 const gpa = astgen.gpa;
5671 const tree = astgen.tree;5671 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);
5674 var fields_len: usize = 0;5674 var fields_len: usize = 0;
5675 {5675 {
5676 var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty;5676 var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty;
...@@ -6332,7 +6332,7 @@ fn setCondBrPayload(...@@ -6332,7 +6332,7 @@ fn setCondBrPayload(
6332 const else_body_len = astgen.countBodyLenAfterFixups(else_body);6332 const else_body_len = astgen.countBodyLenAfterFixups(else_body);
6333 try astgen.extra.ensureUnusedCapacity(6333 try astgen.extra.ensureUnusedCapacity(
6334 astgen.gpa,6334 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,
6336 );6336 );
63376337
6338 const zir_datas = astgen.instructions.items(.data);6338 const zir_datas = astgen.instructions.items(.data);
...@@ -6761,7 +6761,7 @@ fn forExpr(...@@ -6761,7 +6761,7 @@ fn forExpr(
6761 const len: Zir.Inst.Ref = len: {6761 const len: Zir.Inst.Ref = len: {
6762 const all_lens = @as([*]Zir.Inst.Ref, @ptrCast(lens))[0 .. lens.len * 2];6762 const all_lens = @as([*]Zir.Inst.Ref, @ptrCast(lens))[0 .. lens.len * 2];
6763 const lens_len: u32 = @intCast(all_lens.len);6763 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);
6765 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{6765 const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{
6766 .operands_len = lens_len,6766 .operands_len = lens_len,
6767 });6767 });
...@@ -7791,7 +7791,7 @@ fn switchExpr(...@@ -7791,7 +7791,7 @@ fn switchExpr(
7791 // by copying our bodies from `payloads` to `extra`, this time in the order7791 // by copying our bodies from `payloads` to `extra`, this time in the order
7792 // expected by ZIR consumers.7792 // 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 +
7795 @intFromBool(multi_cases_len > 0) + // multi_cases_len7795 @intFromBool(multi_cases_len > 0) + // multi_cases_len
7796 @intFromBool(payload_capture_inst_is_placeholder) + // payload_capture_placeholder7796 @intFromBool(payload_capture_inst_is_placeholder) + // payload_capture_placeholder
7797 @intFromBool(tag_capture_inst_is_placeholder) + // tag_capture_placeholder7797 @intFromBool(tag_capture_inst_is_placeholder) + // tag_capture_placeholder
...@@ -8878,7 +8878,7 @@ fn typeOf(...@@ -8878,7 +8878,7 @@ fn typeOf(
8878 try gz.instructions.append(gpa, typeof_inst);8878 try gz.instructions.append(gpa, typeof_inst);
8879 return rvalue(gz, ri, typeof_inst.toRef(), node);8879 return rvalue(gz, ri, typeof_inst.toRef(), node);
8880 }8880 }
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;
8882 const payload_index = try reserveExtra(astgen, payload_size + args.len);8882 const payload_index = try reserveExtra(astgen, payload_size + args.len);
8883 const args_index = payload_index + payload_size;8883 const args_index = payload_index + payload_size;
88848884
...@@ -11348,7 +11348,7 @@ const GenZir = struct {...@@ -11348,7 +11348,7 @@ const GenZir = struct {
11348 const body_len = astgen.countBodyLenAfterFixups(body);11348 const body_len = astgen.countBodyLenAfterFixups(body);
11349 try astgen.extra.ensureUnusedCapacity(11349 try astgen.extra.ensureUnusedCapacity(
11350 gpa,11350 gpa,
11351 @typeInfo(Zir.Inst.BoolBr).@"struct".fields.len + body_len,11351 @typeInfo(Zir.Inst.BoolBr).@"struct".field_names.len + body_len,
11352 );11352 );
11353 const zir_datas = astgen.instructions.items(.data);11353 const zir_datas = astgen.instructions.items(.data);
11354 zir_datas[@intFromEnum(bool_br)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.BoolBr{11354 zir_datas[@intFromEnum(bool_br)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.BoolBr{
...@@ -11372,7 +11372,7 @@ const GenZir = struct {...@@ -11372,7 +11372,7 @@ const GenZir = struct {
1137211372
11373 try astgen.extra.ensureUnusedCapacity(11373 try astgen.extra.ensureUnusedCapacity(
11374 gpa,11374 gpa,
11375 @typeInfo(Zir.Inst.Block).@"struct".fields.len + body_len,11375 @typeInfo(Zir.Inst.Block).@"struct".field_names.len + body_len,
11376 );11376 );
11377 const zir_datas = astgen.instructions.items(.data);11377 const zir_datas = astgen.instructions.items(.data);
11378 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(11378 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
...@@ -11395,7 +11395,7 @@ const GenZir = struct {...@@ -11395,7 +11395,7 @@ const GenZir = struct {
1139511395
11396 try astgen.extra.ensureUnusedCapacity(11396 try astgen.extra.ensureUnusedCapacity(
11397 gpa,11397 gpa,
11398 @typeInfo(Zir.Inst.BlockComptime).@"struct".fields.len + body_len,11398 @typeInfo(Zir.Inst.BlockComptime).@"struct".field_names.len + body_len,
11399 );11399 );
11400 const zir_datas = astgen.instructions.items(.data);11400 const zir_datas = astgen.instructions.items(.data);
11401 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(11401 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
...@@ -11416,7 +11416,7 @@ const GenZir = struct {...@@ -11416,7 +11416,7 @@ const GenZir = struct {
11416 const body_len = astgen.countBodyLenAfterFixups(body);11416 const body_len = astgen.countBodyLenAfterFixups(body);
11417 try astgen.extra.ensureUnusedCapacity(11417 try astgen.extra.ensureUnusedCapacity(
11418 gpa,11418 gpa,
11419 @typeInfo(Zir.Inst.Try).@"struct".fields.len + body_len,11419 @typeInfo(Zir.Inst.Try).@"struct".field_names.len + body_len,
11420 );11420 );
11421 const zir_datas = astgen.instructions.items(.data);11421 const zir_datas = astgen.instructions.items(.data);
11422 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(11422 zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity(
...@@ -11529,7 +11529,7 @@ const GenZir = struct {...@@ -11529,7 +11529,7 @@ const GenZir = struct {
11529 inst_info: {11529 inst_info: {
11530 try astgen.extra.ensureUnusedCapacity(11530 try astgen.extra.ensureUnusedCapacity(
11531 gpa,11531 gpa,
11532 @typeInfo(Zir.Inst.FuncFancy).@"struct".fields.len +11532 @typeInfo(Zir.Inst.FuncFancy).@"struct".field_names.len +
11533 fancyFnExprExtraLen(astgen, &.{}, cc_body, args.cc_ref) +11533 fancyFnExprExtraLen(astgen, &.{}, cc_body, args.cc_ref) +
11534 fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) +11534 fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) +
11535 body_len + src_locs_and_hash.len +11535 body_len + src_locs_and_hash.len +
...@@ -11589,7 +11589,7 @@ const GenZir = struct {...@@ -11589,7 +11589,7 @@ const GenZir = struct {
11589 } else inst_info: {11589 } else inst_info: {
11590 try astgen.extra.ensureUnusedCapacity(11590 try astgen.extra.ensureUnusedCapacity(
11591 gpa,11591 gpa,
11592 @typeInfo(Zir.Inst.Func).@"struct".fields.len + 1 +11592 @typeInfo(Zir.Inst.Func).@"struct".field_names.len + 1 +
11593 fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) +11593 fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) +
11594 body_len + src_locs_and_hash.len,11594 body_len + src_locs_and_hash.len,
11595 );11595 );
...@@ -11777,7 +11777,7 @@ const GenZir = struct {...@@ -11777,7 +11777,7 @@ const GenZir = struct {
11777 const param_body = param_gz.instructionsSlice();11777 const param_body = param_gz.instructionsSlice();
11778 const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(param_body, prev_param_insts);11778 const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(param_body, prev_param_insts);
11779 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);11779 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
11782 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{11782 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{
11783 .name = name,11783 .name = name,
...@@ -11847,7 +11847,7 @@ const GenZir = struct {...@@ -11847,7 +11847,7 @@ const GenZir = struct {
11847 try astgen.instructions.ensureUnusedCapacity(gpa, 1);11847 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
11848 try astgen.extra.ensureUnusedCapacity(11848 try astgen.extra.ensureUnusedCapacity(
11849 gpa,11849 gpa,
11850 @typeInfo(Zir.Inst.NodeMultiOp).@"struct".fields.len + operands.len,11850 @typeInfo(Zir.Inst.NodeMultiOp).@"struct".field_names.len + operands.len,
11851 );11851 );
1185211852
11853 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{11853 const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{
...@@ -12088,7 +12088,7 @@ const GenZir = struct {...@@ -12088,7 +12088,7 @@ const GenZir = struct {
12088 ) !Zir.Inst.Index {12088 ) !Zir.Inst.Index {
12089 const gpa = gz.astgen.gpa;12089 const gpa = gz.astgen.gpa;
12090 try gz.astgen.instructions.ensureUnusedCapacity(gpa, 1);12090 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
12093 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);12093 const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len);
12094 gz.astgen.instructions.appendAssumeCapacity(.{12094 gz.astgen.instructions.appendAssumeCapacity(.{
...@@ -12211,7 +12211,7 @@ const GenZir = struct {...@@ -12211,7 +12211,7 @@ const GenZir = struct {
12211 try astgen.instructions.ensureUnusedCapacity(gpa, 1);12211 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
12212 try astgen.extra.ensureUnusedCapacity(12212 try astgen.extra.ensureUnusedCapacity(
12213 gpa,12213 gpa,
12214 @typeInfo(Zir.Inst.AllocExtended).@"struct".fields.len +12214 @typeInfo(Zir.Inst.AllocExtended).@"struct".field_names.len +
12215 @intFromBool(args.type_inst != .none) +12215 @intFromBool(args.type_inst != .none) +
12216 @intFromBool(args.align_inst != .none),12216 @intFromBool(args.align_inst != .none),
12217 );12217 );
...@@ -12263,9 +12263,9 @@ const GenZir = struct {...@@ -12263,9 +12263,9 @@ const GenZir = struct {
1226312263
12264 try gz.instructions.ensureUnusedCapacity(gpa, 1);12264 try gz.instructions.ensureUnusedCapacity(gpa, 1);
12265 try astgen.instructions.ensureUnusedCapacity(gpa, 1);12265 try astgen.instructions.ensureUnusedCapacity(gpa, 1);
12266 try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Asm).@"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".fields.len +12267 args.outputs.len * @typeInfo(Zir.Inst.Asm.Output).@"struct".field_names.len +
12268 args.inputs.len * @typeInfo(Zir.Inst.Asm.Input).@"struct".fields.len);12268 args.inputs.len * @typeInfo(Zir.Inst.Asm.Input).@"struct".field_names.len);
1226912269
12270 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Asm{12270 const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Asm{
12271 .src_node = gz.nodeIndexToRelative(args.node),12271 .src_node = gz.nodeIndexToRelative(args.node),
...@@ -12374,7 +12374,7 @@ const GenZir = struct {...@@ -12374,7 +12374,7 @@ const GenZir = struct {
1237412374
12375 const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash);12375 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 +
12378 4 + // `captures_len`, `decls_len`, `fields_len`, `backing_int_type_body_len`12378 4 + // `captures_len`, `decls_len`, `fields_len`, `backing_int_type_body_len`
12379 captures_len * 2 + // `capture`, `capture_name`12379 captures_len * 2 + // `capture`, `capture_name`
12380 args.remaining.len);12380 args.remaining.len);
...@@ -12441,7 +12441,7 @@ const GenZir = struct {...@@ -12441,7 +12441,7 @@ const GenZir = struct {
1244112441
12442 const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash);12442 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 +
12445 4 + // `captures_len`, `decls_len`, `fields_len`, `arg_type_body_len`12445 4 + // `captures_len`, `decls_len`, `fields_len`, `arg_type_body_len`
12446 captures_len * 2 + // `capture`, `capture_name`12446 captures_len * 2 + // `capture`, `capture_name`
12447 args.remaining.len);12447 args.remaining.len);
...@@ -12509,7 +12509,7 @@ const GenZir = struct {...@@ -12509,7 +12509,7 @@ const GenZir = struct {
1250912509
12510 const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash);12510 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 +
12513 4 + // `captures_len`, `decls_len`, `fields_len`, `tag_type_body_len`12513 4 + // `captures_len`, `decls_len`, `fields_len`, `tag_type_body_len`
12514 captures_len * 2 + // `capture`, `capture_name`12514 captures_len * 2 + // `capture`, `capture_name`
12515 args.remaining.len);12515 args.remaining.len);
...@@ -12565,7 +12565,7 @@ const GenZir = struct {...@@ -12565,7 +12565,7 @@ const GenZir = struct {
12565 const captures_len: u32 = @intCast(args.captures.len);12565 const captures_len: u32 = @intCast(args.captures.len);
12566 assert(args.capture_names.len == captures_len);12566 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 +
12569 2 + // `captures_len`, `decls_len`12569 2 + // `captures_len`, `decls_len`
12570 captures_len * 2 + // `capture`, `capture_name`12570 captures_len * 2 + // `capture`, `capture_name`
12571 args.decls.len);12571 args.decls.len);
...@@ -13465,7 +13465,7 @@ fn setDeclaration(...@@ -13465,7 +13465,7 @@ fn setDeclaration(
13465 const flags_arr: [2]u32 = @bitCast(flags);13465 const flags_arr: [2]u32 = @bitCast(flags);
1346613466
13467 const need_extra: usize =13467 const need_extra: usize =
13468 @typeInfo(Zir.Inst.Declaration).@"struct".fields.len +13468 @typeInfo(Zir.Inst.Declaration).@"struct".field_names.len +
13469 @as(usize, @intFromBool(id.hasName())) +13469 @as(usize, @intFromBool(id.hasName())) +
13470 @as(usize, @intFromBool(id.hasLibName())) +13470 @as(usize, @intFromBool(id.hasLibName())) +
13471 @as(usize, @intFromBool(id.hasTypeBody())) +13471 @as(usize, @intFromBool(id.hasTypeBody())) +
lib/std/zig/ErrorBundle.zig+16-13
...@@ -117,7 +117,7 @@ pub fn getSourceLocation(eb: ErrorBundle, index: SourceLocationIndex) SourceLoca...@@ -117,7 +117,7 @@ pub fn getSourceLocation(eb: ErrorBundle, index: SourceLocationIndex) SourceLoca
117117
118pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {118pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex {
119 const notes_len = eb.getErrorMessage(index).notes_len;119 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;
121 return @as([]const MessageIndex, @ptrCast(eb.extra[start..][0..notes_len]));121 return @as([]const MessageIndex, @ptrCast(eb.extra[start..][0..notes_len]));
122}122}
123123
...@@ -128,11 +128,12 @@ pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {...@@ -128,11 +128,12 @@ pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 {
128/// Returns the requested data, as well as the new index which is at the start of the128/// Returns the requested data, as well as the new index which is at the start of the
129/// trailers for the object.129/// trailers for the object.
130fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T, end: usize } {130fn 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;
132 var i: usize = index;133 var i: usize = index;
133 var result: T = undefined;134 var result: T = undefined;
134 inline for (fields) |field| {135 inline for (field_names, field_types) |field_name, field_type| {
135 @field(result, field.name) = switch (field.type) {136 @field(result, field_name) = switch (field_type) {
136 u32 => eb.extra[i],137 u32 => eb.extra[i],
137 MessageIndex => @as(MessageIndex, @enumFromInt(eb.extra[i])),138 MessageIndex => @as(MessageIndex, @enumFromInt(eb.extra[i])),
138 SourceLocationIndex => @as(SourceLocationIndex, @enumFromInt(eb.extra[i])),139 SourceLocationIndex => @as(SourceLocationIndex, @enumFromInt(eb.extra[i])),
...@@ -498,7 +499,7 @@ pub const Wip = struct {...@@ -498,7 +499,7 @@ pub const Wip = struct {
498499
499 pub fn reserveNotes(wip: *Wip, notes_len: u32) !u32 {500 pub fn reserveNotes(wip: *Wip, notes_len: u32) !u32 {
500 try wip.extra.ensureUnusedCapacity(wip.gpa, notes_len +501 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);
502 wip.extra.items.len += notes_len;503 wip.extra.items.len += notes_len;
503 return @intCast(wip.extra.items.len - notes_len);504 return @intCast(wip.extra.items.len - notes_len);
504 }505 }
...@@ -731,13 +732,13 @@ pub const Wip = struct {...@@ -731,13 +732,13 @@ pub const Wip = struct {
731732
732 fn addExtra(wip: *Wip, extra: anytype) Allocator.Error!u32 {733 fn addExtra(wip: *Wip, extra: anytype) Allocator.Error!u32 {
733 const gpa = wip.gpa;734 const gpa = wip.gpa;
734 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;735 const fields = @typeInfo(@TypeOf(extra)).@"struct".field_names;
735 try wip.extra.ensureUnusedCapacity(gpa, fields.len);736 try wip.extra.ensureUnusedCapacity(gpa, fields.len);
736 return addExtraAssumeCapacity(wip, extra);737 return addExtraAssumeCapacity(wip, extra);
737 }738 }
738739
739 fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {740 fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {
740 const fields = @typeInfo(@TypeOf(extra)).@"struct".fields;741 const fields = @typeInfo(@TypeOf(extra)).@"struct".field_names;
741 const result: u32 = @intCast(wip.extra.items.len);742 const result: u32 = @intCast(wip.extra.items.len);
742 wip.extra.items.len += fields.len;743 wip.extra.items.len += fields.len;
743 setExtra(wip, result, extra);744 setExtra(wip, result, extra);
...@@ -745,13 +746,15 @@ pub const Wip = struct {...@@ -745,13 +746,15 @@ pub const Wip = struct {
745 }746 }
746747
747 fn setExtra(wip: *Wip, index: usize, extra: anytype) void {748 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;
749 var i = index;752 var i = index;
750 inline for (fields) |field| {753 inline for (field_names, field_types) |field_name, field_type| {
751 wip.extra.items[i] = switch (field.type) {754 wip.extra.items[i] = switch (field_type) {
752 u32 => @field(extra, field.name),755 u32 => @field(extra, field_name),
753 MessageIndex => @intFromEnum(@field(extra, field.name)),756 MessageIndex => @intFromEnum(@field(extra, field_name)),
754 SourceLocationIndex => @intFromEnum(@field(extra, field.name)),757 SourceLocationIndex => @intFromEnum(@field(extra, field_name)),
755 else => @compileError("bad field type"),758 else => @compileError("bad field type"),
756 };759 };
757 i += 1;760 i += 1;
lib/std/zig/LibCInstallation.zig+11-11
...@@ -43,12 +43,13 @@ pub const FindError = error{...@@ -43,12 +43,13 @@ pub const FindError = error{
43pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const std.Target) !LibCInstallation {43pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const std.Target) !LibCInstallation {
44 var self: LibCInstallation = .{};44 var self: LibCInstallation = .{};
4545
46 const fields = std.meta.fields(LibCInstallation);46 const field_names = comptime std.meta.fieldNames(LibCInstallation);
47 const FoundKey = struct {47 const FoundKey = struct {
48 found: bool,48 found: bool,
49 allocated: ?[:0]u8,49 allocated: ?[:0]u8,
50 };50 };
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 });
52 errdefer {53 errdefer {
53 self = .{};54 self = .{};
54 for (found_keys) |found_key| {55 for (found_keys) |found_key| {
...@@ -65,22 +66,22 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const...@@ -65,22 +66,22 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const
65 var line_it = std.mem.splitScalar(u8, line, '=');66 var line_it = std.mem.splitScalar(u8, line, '=');
66 const name = line_it.first();67 const name = line_it.first();
67 const value = line_it.rest();68 const value = line_it.rest();
68 inline for (fields, 0..) |field, i| {69 inline for (field_names, 0..) |field_name, i| {
69 if (std.mem.eql(u8, name, field.name)) {70 if (std.mem.eql(u8, name, field_name)) {
70 found_keys[i].found = true;71 found_keys[i].found = true;
71 if (value.len == 0) {72 if (value.len == 0) {
72 @field(self, field.name) = null;73 @field(self, field_name) = null;
73 } else {74 } else {
74 found_keys[i].allocated = try allocator.dupeSentinel(u8, value, 0);75 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;
76 }77 }
77 break;78 break;
78 }79 }
79 }80 }
80 }81 }
81 inline for (fields, 0..) |field, i| {82 inline for (field_names, 0..) |field_name, i| {
82 if (!found_keys[i].found) {83 if (!found_keys[i].found) {
83 log.err("missing field: {s}", .{field.name});84 log.err("missing field: {s}", .{field_name});
84 return error.ParseError;85 return error.ParseError;
85 }86 }
86 }87 }
...@@ -235,9 +236,8 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib...@@ -235,9 +236,8 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib
235236
236/// Must be the same allocator passed to `parse` or `findNative`.237/// Must be the same allocator passed to `parse` or `findNative`.
237pub fn deinit(self: *LibCInstallation, allocator: Allocator) void {238pub fn deinit(self: *LibCInstallation, allocator: Allocator) void {
238 const fields = std.meta.fields(LibCInstallation);239 inline for (@typeInfo(LibCInstallation).@"struct".field_names) |field_name| {
239 inline for (fields) |field| {240 if (@field(self, field_name)) |payload| {
240 if (@field(self, field.name)) |payload| {
241 allocator.free(payload);241 allocator.free(payload);
242 }242 }
243 }243 }
lib/std/zig/Parse.zig+6-6
...@@ -89,18 +89,18 @@ fn unreserveNode(p: *Parse, node_index: usize) void {...@@ -89,18 +89,18 @@ fn unreserveNode(p: *Parse, node_index: usize) void {
89}89}
9090
91fn addExtra(p: *Parse, extra: anytype) Allocator.Error!ExtraIndex {91fn addExtra(p: *Parse, extra: anytype) Allocator.Error!ExtraIndex {
92 const fields = std.meta.fields(@TypeOf(extra));92 const info = @typeInfo(@TypeOf(extra)).@"struct";
93 try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len);93 try p.extra_data.ensureUnusedCapacity(p.gpa, info.field_names.len);
94 const result: ExtraIndex = @enumFromInt(p.extra_data.items.len);94 const result: ExtraIndex = @enumFromInt(p.extra_data.items.len);
95 inline for (fields) |field| {95 inline for (info.field_names, info.field_types) |field_name, field_type| {
96 const data: u32 = switch (field.type) {96 const data: u32 = switch (field_type) {
97 Node.Index,97 Node.Index,
98 Node.OptionalIndex,98 Node.OptionalIndex,
99 OptionalTokenIndex,99 OptionalTokenIndex,
100 ExtraIndex,100 ExtraIndex,
101 => @intFromEnum(@field(extra, field.name)),101 => @intFromEnum(@field(extra, field_name)),
102 TokenIndex,102 TokenIndex,
103 => @field(extra, field.name),103 => @field(extra, field_name),
104 else => @compileError("unexpected field type"),104 else => @compileError("unexpected field type"),
105 };105 };
106 p.extra_data.appendAssumeCapacity(data);106 p.extra_data.appendAssumeCapacity(data);
lib/std/zig/Zir.zig+10-10
...@@ -68,11 +68,11 @@ fn ExtraData(comptime T: type) type {...@@ -68,11 +68,11 @@ fn ExtraData(comptime T: type) type {
68/// Returns the requested data, as well as the new index which is at the start of the68/// Returns the requested data, as well as the new index which is at the start of the
69/// trailers for the object.69/// trailers for the object.
70pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {70pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
71 const fields = @typeInfo(T).@"struct".fields;71 const info = @typeInfo(T).@"struct";
72 var i: usize = index;72 var i: usize = index;
73 var result: T = undefined;73 var result: T = undefined;
74 inline for (fields) |field| {74 inline for (info.field_names, info.field_types) |field_name, field_type| {
75 @field(result, field.name) = switch (field.type) {75 @field(result, field_name) = switch (field_type) {
76 u32 => code.extra[i],76 u32 => code.extra[i],
7777
78 Inst.Ref,78 Inst.Ref,
...@@ -1877,7 +1877,7 @@ pub const Inst = struct {...@@ -1877,7 +1877,7 @@ pub const Inst = struct {
18771877
1878 // Uncomment to view how many tag slots are available.1878 // Uncomment to view how many tag slots are available.
1879 //comptime {1879 //comptime {
1880 // @compileLog("ZIR tags left: ", 256 - @typeInfo(Tag).@"enum".fields.len);1880 // @compileLog("ZIR tags left: ", 256 - @typeInfo(Tag).@"enum".field_names.len);
1881 //}1881 //}
1882 };1882 };
18831883
...@@ -2325,7 +2325,7 @@ pub const Inst = struct {...@@ -2325,7 +2325,7 @@ pub const Inst = struct {
23252325
2326 _,2326 _,
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
2330 pub fn toIndex(inst: Ref) ?Index {2330 pub fn toIndex(inst: Ref) ?Index {
2331 assert(inst != .none);2331 assert(inst != .none);
...@@ -3186,7 +3186,7 @@ pub const Inst = struct {...@@ -3186,7 +3186,7 @@ pub const Inst = struct {
31863186
3187 pub const ReifySliceArgInfo = enum(u16) {3187 pub const ReifySliceArgInfo = enum(u16) {
3188 /// Input element type is `type`.3188 /// 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`.
3190 type_to_fn_param_attrs,3190 type_to_fn_param_attrs,
3191 /// Input element type is `[]const u8`.3191 /// Input element type is `[]const u8`.
3192 /// Output element type is `type`.3192 /// Output element type is `type`.
...@@ -3194,10 +3194,10 @@ pub const Inst = struct {...@@ -3194,10 +3194,10 @@ pub const Inst = struct {
3194 /// Identical to `string_to_struct_field_type` aside from emitting slightly different error messages.3194 /// Identical to `string_to_struct_field_type` aside from emitting slightly different error messages.
3195 string_to_union_field_type,3195 string_to_union_field_type,
3196 /// Input element type is `[]const u8`.3196 /// 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`.
3198 string_to_struct_field_attrs,3198 string_to_struct_field_attrs,
3199 /// Input element type is `[]const u8`.3199 /// 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`.
3201 string_to_union_field_attrs,3201 string_to_union_field_attrs,
3202 };3202 };
32033203
...@@ -4842,7 +4842,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash {...@@ -4842,7 +4842,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash {
4842 const extra_index = extra.end +4842 const extra_index = extra.end +
4843 extra.data.ret_ty.body_len +4843 extra.data.ret_ty.body_len +
4844 extra.data.body_len +4844 extra.data.body_len +
4845 @typeInfo(Inst.Func.SrcLocs).@"struct".fields.len;4845 @typeInfo(Inst.Func.SrcLocs).@"struct".field_names.len;
4846 return @bitCast([4]u32{4846 return @bitCast([4]u32{
4847 zir.extra[extra_index + 0],4847 zir.extra[extra_index + 0],
4848 zir.extra[extra_index + 1],4848 zir.extra[extra_index + 1],
...@@ -4869,7 +4869,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash {...@@ -4869,7 +4869,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash {
4869 } else extra_index += @intFromBool(bits.has_ret_ty_ref);4869 } else extra_index += @intFromBool(bits.has_ret_ty_ref);
4870 extra_index += @intFromBool(bits.has_any_noalias);4870 extra_index += @intFromBool(bits.has_any_noalias);
4871 extra_index += extra.data.body_len;4871 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;
4873 return @bitCast([4]u32{4873 return @bitCast([4]u32{
4874 zir.extra[extra_index + 0],4874 zir.extra[extra_index + 0],
4875 zir.extra[extra_index + 1],4875 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 {...@@ -199,8 +199,8 @@ pub fn cast(comptime DestType: type, target: anytype) DestType {
199 }199 }
200 },200 },
201 .@"union" => |info| {201 .@"union" => |info| {
202 inline for (info.fields) |field| {202 inline for (info.field_names, info.field_types) |field_name, field_type| {
203 if (field.type == SourceType) return @unionInit(DestType, field.name, target);203 if (field_type == SourceType) return @unionInit(DestType, field_name, target);
204 }204 }
205205
206 @compileError("cast to union type '" ++ @typeName(DestType) ++ "' from type '" ++ @typeName(SourceType) ++ "' which is not present in union");206 @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 {...@@ -282,7 +282,7 @@ fn startBlock(bc: *BitcodeReader, block_id: ?u32, new_abbrev_len: u6) !void {
282 };282 };
283 try state.abbrevs.abbrevs.ensureTotalCapacity(283 try state.abbrevs.abbrevs.ensureTotalCapacity(
284 bc.allocator,284 bc.allocator,
285 @typeInfo(Abbrev.Builtin).@"enum".fields.len + abbrevs.len,285 @typeInfo(Abbrev.Builtin).@"enum".field_names.len + abbrevs.len,
286 );286 );
287287
288 assert(state.abbrevs.abbrevs.items.len == @intFromEnum(Abbrev.Builtin.end_block));288 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 {...@@ -318,7 +318,7 @@ fn startBlock(bc: *BitcodeReader, block_id: ?u32, new_abbrev_len: u6) !void {
318 .{ .encoding = .{ .vbr = 6 } }, // ops318 .{ .encoding = .{ .vbr = 6 } }, // ops
319 },319 },
320 });320 });
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);
322 for (abbrevs) |abbrev| try state.abbrevs.addAbbrevAssumeCapacity(bc.allocator, abbrev);322 for (abbrevs) |abbrev| try state.abbrevs.addAbbrevAssumeCapacity(bc.allocator, abbrev);
323}323}
324324
...@@ -457,7 +457,7 @@ const Abbrev = struct {...@@ -457,7 +457,7 @@ const Abbrev = struct {
457 define_abbrev,457 define_abbrev,
458 unabbrev_record,458 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;
461 fn toRecordId(builtin: Builtin) u32 {461 fn toRecordId(builtin: Builtin) u32 {
462 return first_record_id + @intFromEnum(builtin);462 return first_record_id + @intFromEnum(builtin);
463 }463 }
lib/std/zig/llvm/Builder.zig+124-93
...@@ -1137,21 +1137,22 @@ pub const Attribute = union(Kind) {...@@ -1137,21 +1137,22 @@ pub const Attribute = union(Kind) {
1137 .no_sanitize_hwaddress,1137 .no_sanitize_hwaddress,
1138 .sanitize_address_dyninit,1138 .sanitize_address_dyninit,
1139 => |kind| {1139 => |kind| {
1140 const field = comptime blk: {1140 const field_name, const field_type = comptime blk: {
1141 @setEvalBranchQuota(10_000);1141 @setEvalBranchQuota(10_000);
1142 for (@typeInfo(Attribute).@"union".fields) |field| {1142 const info = @typeInfo(Attribute).@"union";
1143 if (std.mem.eql(u8, field.name, @tagName(kind))) break :blk field;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 };
1144 }1145 }
1145 unreachable;1146 unreachable;
1146 };1147 };
1147 comptime assert(std.mem.eql(u8, @tagName(kind), field.name));1148 comptime assert(std.mem.eql(u8, @tagName(kind), field_name));
1148 return @unionInit(Attribute, field.name, switch (field.type) {1149 return @unionInit(Attribute, field_name, switch (field_type) {
1149 void => {},1150 void => {},
1150 u32 => storage.value,1151 u32 => storage.value,
1151 Alignment.Lazy, String, Type, UwTable => @enumFromInt(storage.value),1152 Alignment.Lazy, String, Type, UwTable => @enumFromInt(storage.value),
1152 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value),1153 AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value),
1153 else => @compileError("bad payload type: " ++ field.name ++ ": " ++1154 else => @compileError("bad payload type: " ++ field_name ++ ": " ++
1154 @typeName(field.type)),1155 @typeName(field_type)),
1155 });1156 });
1156 },1157 },
1157 .string, .none => unreachable,1158 .string, .none => unreachable,
...@@ -1258,14 +1259,14 @@ pub const Attribute = union(Kind) {...@@ -1258,14 +1259,14 @@ pub const Attribute = union(Kind) {
1258 try w.print(" {s}(", .{@tagName(attribute)});1259 try w.print(" {s}(", .{@tagName(attribute)});
1259 var any = false;1260 var any = false;
1260 var remaining: Int = @bitCast(fpclass);1261 var remaining: Int = @bitCast(fpclass);
1261 inline for (@typeInfo(FpClass).@"struct".decls) |decl| {1262 inline for (@typeInfo(FpClass).@"struct".decl_names) |decl_name| {
1262 const pattern: Int = @bitCast(@field(FpClass, decl.name));1263 const pattern: Int = @bitCast(@field(FpClass, decl_name));
1263 if (remaining & pattern == pattern) {1264 if (remaining & pattern == pattern) {
1264 if (!any) {1265 if (!any) {
1265 try w.writeByte(' ');1266 try w.writeByte(' ');
1266 any = true;1267 any = true;
1267 }1268 }
1268 try w.writeAll(decl.name);1269 try w.writeAll(decl_name);
1269 remaining &= ~pattern;1270 remaining &= ~pattern;
1270 }1271 }
1271 }1272 }
...@@ -1283,14 +1284,14 @@ pub const Attribute = union(Kind) {...@@ -1283,14 +1284,14 @@ pub const Attribute = union(Kind) {
1283 .allockind => |allockind| {1284 .allockind => |allockind| {
1284 try w.print(" {t}(\"", .{attribute});1285 try w.print(" {t}(\"", .{attribute});
1285 var any = false;1286 var any = false;
1286 inline for (@typeInfo(AllocKind).@"struct".fields) |field| {1287 inline for (@typeInfo(AllocKind).@"struct".field_names) |field_name| {
1287 if (comptime std.mem.eql(u8, field.name, "_")) continue;1288 if (comptime std.mem.eql(u8, field_name, "_")) continue;
1288 if (@field(allockind, field.name)) {1289 if (@field(allockind, field_name)) {
1289 if (!any) {1290 if (!any) {
1290 try w.writeByte(',');1291 try w.writeByte(',');
1291 any = true;1292 any = true;
1292 }1293 }
1293 try w.writeAll(field.name);1294 try w.writeAll(field_name);
1294 }1295 }
1295 }1296 }
1296 try w.writeAll("\")");1297 try w.writeAll("\")");
...@@ -1442,7 +1443,7 @@ pub const Attribute = union(Kind) {...@@ -1442,7 +1443,7 @@ pub const Attribute = union(Kind) {
1442 none = maxInt(u32),1443 none = maxInt(u32),
1443 _,1444 _,
14441445
1445 pub const len = @typeInfo(Kind).@"enum".fields.len - 2;1446 pub const len = @typeInfo(Kind).@"enum".field_names.len - 2;
14461447
1447 pub fn fromString(str: String) Kind {1448 pub fn fromString(str: String) Kind {
1448 assert(!str.isAnon());1449 assert(!str.isAnon());
...@@ -5167,9 +5168,13 @@ pub const Function = struct {...@@ -5167,9 +5168,13 @@ pub const Function = struct {
5167 index: Instruction.ExtraIndex,5168 index: Instruction.ExtraIndex,
5168 ) struct { data: T, trail: ExtraDataTrail } {5169 ) struct { data: T, trail: ExtraDataTrail } {
5169 var result: T = undefined;5170 var result: T = undefined;
5170 const fields = @typeInfo(T).@"struct".fields;5171 const info = @typeInfo(T).@"struct";
5171 inline for (fields, self.extra[index..][0..fields.len]) |field, value|5172 inline for (
5172 @field(result, field.name) = switch (field.type) {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) {
5173 u32 => value,5178 u32 => value,
5174 Alignment,5179 Alignment,
5175 AtomicOrdering,5180 AtomicOrdering,
...@@ -5183,11 +5188,11 @@ pub const Function = struct {...@@ -5183,11 +5188,11 @@ pub const Function = struct {
5183 Instruction.Alloca.Info,5188 Instruction.Alloca.Info,
5184 Instruction.Call.Info,5189 Instruction.Call.Info,
5185 => @bitCast(value),5190 => @bitCast(value),
5186 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),5191 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
5187 };5192 };
5188 return .{5193 return .{
5189 .data = result,5194 .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)) },
5191 };5196 };
5192 }5197 }
51935198
...@@ -6327,9 +6332,10 @@ pub const WipFunction = struct {...@@ -6327,9 +6332,10 @@ pub const WipFunction = struct {
63276332
6328 fn addExtra(wip_extra: *@This(), extra: anytype) Instruction.ExtraIndex {6333 fn addExtra(wip_extra: *@This(), extra: anytype) Instruction.ExtraIndex {
6329 const result = wip_extra.index;6334 const result = wip_extra.index;
6330 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {6335 const info = @typeInfo(@TypeOf(extra)).@"struct";
6331 const value = @field(extra, field.name);6336 inline for (info.field_names, info.field_types) |field_name, field_type| {
6332 wip_extra.items[wip_extra.index] = switch (field.type) {6337 const value = @field(extra, field_name);
6338 wip_extra.items[wip_extra.index] = switch (field_type) {
6333 u32 => value,6339 u32 => value,
6334 Alignment,6340 Alignment,
6335 AtomicOrdering,6341 AtomicOrdering,
...@@ -6343,7 +6349,7 @@ pub const WipFunction = struct {...@@ -6343,7 +6349,7 @@ pub const WipFunction = struct {
6343 Instruction.Alloca.Info,6349 Instruction.Alloca.Info,
6344 Instruction.Call.Info,6350 Instruction.Call.Info,
6345 => @bitCast(value),6351 => @bitCast(value),
6346 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),6352 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
6347 };6353 };
6348 wip_extra.index += 1;6354 wip_extra.index += 1;
6349 }6355 }
...@@ -6944,7 +6950,7 @@ pub const WipFunction = struct {...@@ -6944,7 +6950,7 @@ pub const WipFunction = struct {
6944 ) Allocator.Error!void {6950 ) Allocator.Error!void {
6945 try self.extra.ensureUnusedCapacity(6951 try self.extra.ensureUnusedCapacity(
6946 self.builder.gpa,6952 self.builder.gpa,
6947 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),6953 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
6948 );6954 );
6949 }6955 }
69506956
...@@ -6983,9 +6989,10 @@ pub const WipFunction = struct {...@@ -6983,9 +6989,10 @@ pub const WipFunction = struct {
69836989
6984 fn addExtraAssumeCapacity(self: *WipFunction, extra: anytype) Instruction.ExtraIndex {6990 fn addExtraAssumeCapacity(self: *WipFunction, extra: anytype) Instruction.ExtraIndex {
6985 const result: Instruction.ExtraIndex = @intCast(self.extra.items.len);6991 const result: Instruction.ExtraIndex = @intCast(self.extra.items.len);
6986 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {6992 const info = @typeInfo(@TypeOf(extra)).@"struct";
6987 const value = @field(extra, field.name);6993 inline for (info.field_names, info.field_types) |field_name, field_type| {
6988 self.extra.appendAssumeCapacity(switch (field.type) {6994 const value = @field(extra, field_name);
6995 self.extra.appendAssumeCapacity(switch (field_type) {
6989 u32 => value,6996 u32 => value,
6990 Alignment,6997 Alignment,
6991 AtomicOrdering,6998 AtomicOrdering,
...@@ -6999,7 +7006,7 @@ pub const WipFunction = struct {...@@ -6999,7 +7006,7 @@ pub const WipFunction = struct {
6999 Instruction.Alloca.Info,7006 Instruction.Alloca.Info,
7000 Instruction.Call.Info,7007 Instruction.Call.Info,
7001 => @bitCast(value),7008 => @bitCast(value),
7002 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),7009 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
7003 });7010 });
7004 }7011 }
7005 return result;7012 return result;
...@@ -7032,9 +7039,13 @@ pub const WipFunction = struct {...@@ -7032,9 +7039,13 @@ pub const WipFunction = struct {
7032 index: Instruction.ExtraIndex,7039 index: Instruction.ExtraIndex,
7033 ) struct { data: T, trail: ExtraDataTrail } {7040 ) struct { data: T, trail: ExtraDataTrail } {
7034 var result: T = undefined;7041 var result: T = undefined;
7035 const fields = @typeInfo(T).@"struct".fields;7042 const info = @typeInfo(T).@"struct";
7036 inline for (fields, self.extra.items[index..][0..fields.len]) |field, value|7043 inline for (
7037 @field(result, field.name) = switch (field.type) {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) {
7038 u32 => value,7049 u32 => value,
7039 Alignment,7050 Alignment,
7040 AtomicOrdering,7051 AtomicOrdering,
...@@ -7048,11 +7059,11 @@ pub const WipFunction = struct {...@@ -7048,11 +7059,11 @@ pub const WipFunction = struct {
7048 Instruction.Alloca.Info,7059 Instruction.Alloca.Info,
7049 Instruction.Call.Info,7060 Instruction.Call.Info,
7050 => @bitCast(value),7061 => @bitCast(value),
7051 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),7062 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
7052 };7063 };
7053 return .{7064 return .{
7054 .data = result,7065 .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)) },
7056 };7067 };
7057 }7068 }
70587069
...@@ -8202,19 +8213,20 @@ pub const Metadata = packed struct(u32) {...@@ -8202,19 +8213,20 @@ pub const Metadata = packed struct(u32) {
82028213
8203 pub fn format(self: DIFlags, w: *Writer) Writer.Error!void {8214 pub fn format(self: DIFlags, w: *Writer) Writer.Error!void {
8204 var need_pipe = false;8215 var need_pipe = false;
8205 inline for (@typeInfo(DIFlags).@"struct".fields) |field| {8216 const info = @typeInfo(DIFlags).@"struct";
8206 switch (@typeInfo(field.type)) {8217 inline for (info.field_names, info.field_types) |field_name, field_type| {
8207 .bool => if (@field(self, field.name)) {8218 switch (@typeInfo(field_type)) {
8219 .bool => if (@field(self, field_name)) {
8208 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;8220 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});
8210 },8222 },
8211 .@"enum" => if (@field(self, field.name) != .Zero) {8223 .@"enum" => if (@field(self, field_name) != .Zero) {
8212 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;8224 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))});
8214 },8226 },
8215 .int => assert(@field(self, field.name) == 0),8227 .int => assert(@field(self, field_name) == 0),
8216 else => @compileError("bad field type: " ++ field.name ++ ": " ++8228 else => @compileError("bad field type: " ++ field_name ++ ": " ++
8217 @typeName(field.type)),8229 @typeName(field_type)),
8218 }8230 }
8219 }8231 }
8220 if (!need_pipe) try w.writeByte('0');8232 if (!need_pipe) try w.writeByte('0');
...@@ -8259,19 +8271,20 @@ pub const Metadata = packed struct(u32) {...@@ -8259,19 +8271,20 @@ pub const Metadata = packed struct(u32) {
82598271
8260 pub fn format(self: DISPFlags, w: *Writer) Writer.Error!void {8272 pub fn format(self: DISPFlags, w: *Writer) Writer.Error!void {
8261 var need_pipe = false;8273 var need_pipe = false;
8262 inline for (@typeInfo(DISPFlags).@"struct".fields) |field| {8274 const info = @typeInfo(DISPFlags).@"struct";
8263 switch (@typeInfo(field.type)) {8275 inline for (info.field_names, info.field_types) |field_name, field_type| {
8264 .bool => if (@field(self, field.name)) {8276 switch (@typeInfo(field_type)) {
8277 .bool => if (@field(self, field_name)) {
8265 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;8278 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});
8267 },8280 },
8268 .@"enum" => if (@field(self, field.name) != .Zero) {8281 .@"enum" => if (@field(self, field_name) != .Zero) {
8269 if (need_pipe) try w.writeAll(" | ") else need_pipe = true;8282 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))});
8271 },8284 },
8272 .int => assert(@field(self, field.name) == 0),8285 .int => assert(@field(self, field_name) == 0),
8273 else => @compileError("bad field type: " ++ field.name ++ ": " ++8286 else => @compileError("bad field type: " ++ field_name ++ ": " ++
8274 @typeName(field.type)),8287 @typeName(field_type)),
8275 }8288 }
8276 }8289 }
8277 if (!need_pipe) try w.writeByte('0');8290 if (!need_pipe) try w.writeByte('0');
...@@ -8567,7 +8580,7 @@ pub const Metadata = packed struct(u32) {...@@ -8567,7 +8580,7 @@ pub const Metadata = packed struct(u32) {
8567 })) |some| switch (@typeInfo(Some)) {8580 })) |some| switch (@typeInfo(Some)) {
8568 .@"enum" => |enum_info| switch (Some) {8581 .@"enum" => |enum_info| switch (Some) {
8569 Metadata.String => .{ .string = some },8582 Metadata.String => .{ .string = some },
8570 else => if (enum_info.is_exhaustive)8583 else => if (enum_info.mode == .exhaustive)
8571 .{ .raw = @tagName(some) }8584 .{ .raw = @tagName(some) }
8572 else8585 else
8573 @compileError("unknown type to format: " ++ @typeName(Node)),8586 @compileError("unknown type to format: " ++ @typeName(Node)),
...@@ -8763,14 +8776,15 @@ pub fn init(options: Options) Allocator.Error!Builder {...@@ -8763,14 +8776,15 @@ pub fn init(options: Options) Allocator.Error!Builder {
8763 }8776 }
87648777
8765 {8778 {
8766 const static_len = @typeInfo(Type).@"enum".fields.len - 1;8779 const static_len = @typeInfo(Type).@"enum".field_names.len - 1;
8767 try self.type_map.ensureTotalCapacity(self.gpa, static_len);8780 try self.type_map.ensureTotalCapacity(self.gpa, static_len);
8768 try self.type_items.ensureTotalCapacity(self.gpa, static_len);8781 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| {
8770 const result = self.getOrPutTypeNoExtraAssumeCapacity(8784 const result = self.getOrPutTypeNoExtraAssumeCapacity(
8771 .{ .tag = .simple, .data = simple_field.value },8785 .{ .tag = .simple, .data = simple_field_value },
8772 );8786 );
8773 assert(result.new and result.type == @field(Type, simple_field.name));8787 assert(result.new and result.type == @field(Type, simple_field_name));
8774 }8788 }
8775 inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits|8789 inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits|
8776 assert(self.intTypeAssumeCapacity(bits) ==8790 assert(self.intTypeAssumeCapacity(bits) ==
...@@ -11016,7 +11030,7 @@ fn ensureUnusedTypeCapacity(...@@ -11016,7 +11030,7 @@ fn ensureUnusedTypeCapacity(
11016 try self.type_items.ensureUnusedCapacity(self.gpa, count);11030 try self.type_items.ensureUnusedCapacity(self.gpa, count);
11017 try self.type_extra.ensureUnusedCapacity(11031 try self.type_extra.ensureUnusedCapacity(
11018 self.gpa,11032 self.gpa,
11019 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),11033 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
11020 );11034 );
11021}11035}
1102211036
...@@ -11046,12 +11060,13 @@ fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { n...@@ -11046,12 +11060,13 @@ fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { n
1104611060
11047fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraIndex {11061fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraIndex {
11048 const result: Type.Item.ExtraIndex = @intCast(self.type_extra.items.len);11062 const result: Type.Item.ExtraIndex = @intCast(self.type_extra.items.len);
11049 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {11063 const info = @typeInfo(@TypeOf(extra)).@"struct";
11050 const value = @field(extra, field.name);11064 inline for (info.field_names, info.field_types) |field_name, field_type| {
11051 self.type_extra.appendAssumeCapacity(switch (field.type) {11065 const value = @field(extra, field_name);
11066 self.type_extra.appendAssumeCapacity(switch (field_type) {
11052 u32 => value,11067 u32 => value,
11053 String, Type => @intFromEnum(value),11068 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)),
11055 });11070 });
11056 }11071 }
11057 return result;11072 return result;
...@@ -11084,16 +11099,20 @@ fn typeExtraDataTrail(...@@ -11084,16 +11099,20 @@ fn typeExtraDataTrail(
11084 index: Type.Item.ExtraIndex,11099 index: Type.Item.ExtraIndex,
11085) struct { data: T, trail: TypeExtraDataTrail } {11100) struct { data: T, trail: TypeExtraDataTrail } {
11086 var result: T = undefined;11101 var result: T = undefined;
11087 const fields = @typeInfo(T).@"struct".fields;11102 const info = @typeInfo(T).@"struct";
11088 inline for (fields, self.type_extra.items[index..][0..fields.len]) |field, value|11103 inline for (
11089 @field(result, field.name) = switch (field.type) {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) {
11090 u32 => value,11109 u32 => value,
11091 String, Type => @enumFromInt(value),11110 String, Type => @enumFromInt(value),
11092 else => @compileError("bad field type: " ++ @typeName(field.type)),11111 else => @compileError("bad field type: " ++ @typeName(field_type)),
11093 };11112 };
11094 return .{11113 return .{
11095 .data = result,11114 .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)) },
11097 };11116 };
11098}11117}
1109911118
...@@ -11899,7 +11918,7 @@ fn ensureUnusedConstantCapacity(...@@ -11899,7 +11918,7 @@ fn ensureUnusedConstantCapacity(
11899 try self.constant_items.ensureUnusedCapacity(self.gpa, count);11918 try self.constant_items.ensureUnusedCapacity(self.gpa, count);
11900 try self.constant_extra.ensureUnusedCapacity(11919 try self.constant_extra.ensureUnusedCapacity(
11901 self.gpa,11920 self.gpa,
11902 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),11921 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
11903 );11922 );
11904}11923}
1190511924
...@@ -11974,13 +11993,14 @@ fn getOrPutConstantAggregateAssumeCapacity(...@@ -11974,13 +11993,14 @@ fn getOrPutConstantAggregateAssumeCapacity(
1197411993
11975fn addConstantExtraAssumeCapacity(self: *Builder, extra: anytype) Constant.Item.ExtraIndex {11994fn addConstantExtraAssumeCapacity(self: *Builder, extra: anytype) Constant.Item.ExtraIndex {
11976 const result: Constant.Item.ExtraIndex = @intCast(self.constant_extra.items.len);11995 const result: Constant.Item.ExtraIndex = @intCast(self.constant_extra.items.len);
11977 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {11996 const info = @typeInfo(@TypeOf(extra)).@"struct";
11978 const value = @field(extra, field.name);11997 inline for (info.field_names, info.field_types) |field_name, field_type| {
11979 self.constant_extra.appendAssumeCapacity(switch (field.type) {11998 const value = @field(extra, field_name);
11999 self.constant_extra.appendAssumeCapacity(switch (field_type) {
11980 u32 => value,12000 u32 => value,
11981 String, Type, Constant, Function.Index, Function.Block.Index => @intFromEnum(value),12001 String, Type, Constant, Function.Index, Function.Block.Index => @intFromEnum(value),
11982 Constant.GetElementPtr.Info => @bitCast(value),12002 Constant.GetElementPtr.Info => @bitCast(value),
11983 else => @compileError("bad field type: " ++ @typeName(field.type)),12003 else => @compileError("bad field type: " ++ @typeName(field_type)),
11984 });12004 });
11985 }12005 }
11986 return result;12006 return result;
...@@ -12013,17 +12033,21 @@ fn constantExtraDataTrail(...@@ -12013,17 +12033,21 @@ fn constantExtraDataTrail(
12013 index: Constant.Item.ExtraIndex,12033 index: Constant.Item.ExtraIndex,
12014) struct { data: T, trail: ConstantExtraDataTrail } {12034) struct { data: T, trail: ConstantExtraDataTrail } {
12015 var result: T = undefined;12035 var result: T = undefined;
12016 const fields = @typeInfo(T).@"struct".fields;12036 const info = @typeInfo(T).@"struct";
12017 inline for (fields, self.constant_extra.items[index..][0..fields.len]) |field, value|12037 inline for (
12018 @field(result, field.name) = switch (field.type) {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) {
12019 u32 => value,12043 u32 => value,
12020 String, Type, Constant, Function.Index, Function.Block.Index => @enumFromInt(value),12044 String, Type, Constant, Function.Index, Function.Block.Index => @enumFromInt(value),
12021 Constant.GetElementPtr.Info => @bitCast(value),12045 Constant.GetElementPtr.Info => @bitCast(value),
12022 else => @compileError("bad field type: " ++ @typeName(field.type)),12046 else => @compileError("bad field type: " ++ @typeName(field_type)),
12023 };12047 };
12024 return .{12048 return .{
12025 .data = result,12049 .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)) },
12027 };12051 };
12028}12052}
1202912053
...@@ -12041,19 +12065,20 @@ fn ensureUnusedMetadataCapacity(...@@ -12041,19 +12065,20 @@ fn ensureUnusedMetadataCapacity(
12041 try self.metadata_items.ensureUnusedCapacity(self.gpa, count);12065 try self.metadata_items.ensureUnusedCapacity(self.gpa, count);
12042 try self.metadata_extra.ensureUnusedCapacity(12066 try self.metadata_extra.ensureUnusedCapacity(
12043 self.gpa,12067 self.gpa,
12044 count * (@typeInfo(Extra).@"struct".fields.len + trail_len),12068 count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
12045 );12069 );
12046}12070}
1204712071
12048fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.ExtraIndex {12072fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.ExtraIndex {
12049 const result: Metadata.Item.ExtraIndex = @intCast(self.metadata_extra.items.len);12073 const result: Metadata.Item.ExtraIndex = @intCast(self.metadata_extra.items.len);
12050 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| {12074 const info = @typeInfo(@TypeOf(extra)).@"struct";
12051 const value = @field(extra, field.name);12075 inline for (info.field_names, info.field_types) |field_name, field_type| {
12052 self.metadata_extra.appendAssumeCapacity(switch (field.type) {12076 const value = @field(extra, field_name);
12077 self.metadata_extra.appendAssumeCapacity(switch (field_type) {
12053 u32 => value,12078 u32 => value,
12054 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value),12079 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value),
12055 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),12080 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)),
12057 });12082 });
12058 }12083 }
12059 return result;12084 return result;
...@@ -12086,17 +12111,21 @@ fn metadataExtraDataTrail(...@@ -12086,17 +12111,21 @@ fn metadataExtraDataTrail(
12086 index: Metadata.Item.ExtraIndex,12111 index: Metadata.Item.ExtraIndex,
12087) struct { data: T, trail: MetadataExtraDataTrail } {12112) struct { data: T, trail: MetadataExtraDataTrail } {
12088 var result: T = undefined;12113 var result: T = undefined;
12089 const fields = @typeInfo(T).@"struct".fields;12114 const info = @typeInfo(T).@"struct";
12090 inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value|12115 inline for (
12091 @field(result, field.name) = switch (field.type) {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) {
12092 u32 => value,12121 u32 => value,
12093 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value),12122 Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value),
12094 Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),12123 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)),
12096 };12125 };
12097 return .{12126 return .{
12098 .data = result,12127 .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)) },
12100 };12129 };
12101}12130}
1210212131
...@@ -12602,8 +12631,8 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp...@@ -12602,8 +12631,8 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp
12602 builder: *const Builder,12631 builder: *const Builder,
12603 pub fn hash(_: @This(), key: Key) u32 {12632 pub fn hash(_: @This(), key: Key) u32 {
12604 var hasher = std.hash.Wyhash.init(std.hash.int(@intFromEnum(key.tag)));12633 var hasher = std.hash.Wyhash.init(std.hash.int(@intFromEnum(key.tag)));
12605 inline for (std.meta.fields(@TypeOf(value))) |field| {12634 inline for (comptime std.meta.fieldNames(@TypeOf(value))) |field_name| {
12606 hasher.update(std.mem.asBytes(&@field(key.value, field.name)));12635 hasher.update(std.mem.asBytes(&@field(key.value, field_name)));
12607 }12636 }
12608 return @truncate(hasher.final());12637 return @truncate(hasher.final());
12609 }12638 }
...@@ -14184,12 +14213,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -14184,12 +14213,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
14184 const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock;14213 const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock;
14185 var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);14214 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| {
14188 // don't include `dbg` in stripped functions14219 // 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"))) {
14190 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{14221 try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
14191 .id = field.value,14222 .id = field_value,
14192 .name = field.name,14223 .name = field_name,
14193 });14224 });
14194 }14225 }
14195 }14226 }
lib/std/zig/llvm/bitcode_writer.zig+4-4
...@@ -246,14 +246,14 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -246,14 +246,14 @@ pub fn BitcodeWriter(comptime types: []const type) type {
246246
247 try self.bitcode.writeBits(comptime abbrevId(Abbrev), abbrev_len);247 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
251 // This abbreviation might only contain literals251 // This abbreviation might only contain literals
252 if (fields.len == 0) return;252 if (field_names.len == 0) return;
253253
254 comptime var field_index: usize = 0;254 comptime var field_index: usize = 0;
255 inline for (Abbrev.ops) |ty| {255 inline for (Abbrev.ops) |ty| {
256 const param = @field(params, fields[field_index].name);256 const param = @field(params, field_names[field_index]);
257 switch (ty) {257 switch (ty) {
258 .literal => continue,258 .literal => continue,
259 .fixed => |len| try self.bitcode.writeBits(adapter.get(param), len),259 .fixed => |len| try self.bitcode.writeBits(adapter.get(param), len),
...@@ -296,7 +296,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -296,7 +296,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
296 },296 },
297 }297 }
298 field_index += 1;298 field_index += 1;
299 if (field_index == fields.len) break;299 if (field_index == field_names.len) break;
300 }300 }
301 }301 }
302302
lib/std/zig/system.zig+4-4
...@@ -973,10 +973,10 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ...@@ -973,10 +973,10 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ
973 // relying on `builtin.target`.973 // relying on `builtin.target`.
974 const all_abis = comptime blk: {974 const all_abis = comptime blk: {
975 assert(@intFromEnum(Target.Abi.none) == 0);975 assert(@intFromEnum(Target.Abi.none) == 0);
976 const fields = std.meta.fields(Target.Abi)[1..];976 const field_names = std.meta.fieldNames(Target.Abi)[1..];
977 var array: [fields.len]Target.Abi = undefined;977 var array: [field_names.len]Target.Abi = undefined;
978 for (fields, 0..) |field, i| {978 for (field_names, 0..) |field_name, i| {
979 array[i] = @field(Target.Abi, field.name);979 array[i] = @field(Target.Abi, field_name);
980 }980 }
981 break :blk array;981 break :blk array;
982 };982 };
lib/std/zig/system/windows.zig+11-11
...@@ -60,14 +60,14 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -60,14 +60,14 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
60 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));60 @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
61 }61 }
6262
63 const fields_info = args_type_info.@"struct".fields;63 const fields_info = args_type_info.@"struct";
6464
65 // Originally, I wanted to issue a single call with a more complex table structure such that we65 // Originally, I wanted to issue a single call with a more complex table structure such that we
66 // would sequentially visit each CPU#d subkey in the registry and pull the value of interest into66 // would sequentially visit each CPU#d subkey in the registry and pull the value of interest into
67 // a buffer, however, NT seems to be expecting a single buffer per each table meaning we would67 // a buffer, however, NT seems to be expecting a single buffer per each table meaning we would
68 // end up pulling only the last CPU core info, overwriting everything else.68 // end up pulling only the last CPU core info, overwriting everything else.
69 // If anyone can come up with a solution to this, please do!69 // 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;
71 var table: [table_size + 1]std.os.windows.RTL_QUERY_REGISTRY_TABLE = undefined;71 var table: [table_size + 1]std.os.windows.RTL_QUERY_REGISTRY_TABLE = undefined;
7272
73 const topkey = std.unicode.utf8ToUtf16LeStringLiteral("\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor");73 const topkey = std.unicode.utf8ToUtf16LeStringLiteral("\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor");
...@@ -90,11 +90,11 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -90,11 +90,11 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
90 .DefaultLength = 0,90 .DefaultLength = 0,
91 };91 };
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| {
96 const ctx: *anyopaque = blk: {96 const ctx: *anyopaque = blk: {
97 switch (@field(args, field.name).value_type) {97 switch (@field(args, field_name).value_type) {
98 .SZ,98 .SZ,
99 .EXPAND_SZ,99 .EXPAND_SZ,
100 .MULTI_SZ,100 .MULTI_SZ,
...@@ -119,7 +119,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -119,7 +119,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
119 };119 };
120120
121 var key_buf: [max_value_len / 2 + 1]u16 = undefined;121 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);
123 key_buf[key_len] = 0;123 key_buf[key_len] = 0;
124124
125 table[i + 1] = .{125 table[i + 1] = .{
...@@ -153,12 +153,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -153,12 +153,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
153 );153 );
154 switch (res) {154 switch (res) {
155 .SUCCESS => {155 .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) {
157 .SZ,157 .SZ,
158 .EXPAND_SZ,158 .EXPAND_SZ,
159 .MULTI_SZ,159 .MULTI_SZ,
160 => {160 => {
161 var buf = @field(args, field.name).value_buf;161 var buf = @field(args, field_name).value_buf;
162 const entry: *const std.os.windows.UNICODE_STRING = @ptrCast(table[i + 1].EntryContext);162 const entry: *const std.os.windows.UNICODE_STRING = @ptrCast(table[i + 1].EntryContext);
163 const len = try std.unicode.utf16LeToUtf8(buf, entry.slice());163 const len = try std.unicode.utf16LeToUtf8(buf, entry.slice());
164 buf[len] = 0;164 buf[len] = 0;
...@@ -169,12 +169,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {...@@ -169,12 +169,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
169 .QWORD,169 .QWORD,
170 => {170 => {
171 const entry: [*]const u8 = @ptrCast(table[i + 1].EntryContext);171 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) {
173 .DWORD, .DWORD_BIG_ENDIAN => {173 .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]);
175 },175 },
176 .QWORD => {176 .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]);
178 },178 },
179 else => unreachable,179 else => unreachable,
180 }180 }
lib/std/zon/Serializer.zig+28-23
...@@ -165,7 +165,7 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption...@@ -165,7 +165,7 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
165 },165 },
166 .@"struct" => |@"struct"| if (@"struct".is_tuple) {166 .@"struct" => |@"struct"| if (@"struct".is_tuple) {
167 var container = try self.beginTuple(167 var container = try self.beginTuple(
168 .{ .whitespace_style = .{ .fields = @"struct".fields.len } },168 .{ .whitespace_style = .{ .fields = @"struct".field_names.len } },
169 );169 );
170 inline for (val) |field_value| {170 inline for (val) |field_value| {
171 try container.fieldArbitraryDepth(field_value, options);171 try container.fieldArbitraryDepth(field_value, options);
...@@ -173,15 +173,20 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption...@@ -173,15 +173,20 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
173 try container.end();173 try container.end();
174 } else {174 } else {
175 // Decide which fields to emit175 // Decide which fields to emit
176 const fields, const skipped: [@"struct".fields.len]bool = if (options.emit_default_optional_fields) b: {176 const fields, const skipped: [@"struct".field_names.len]bool = if (options.emit_default_optional_fields) b: {
177 break :b .{ @"struct".fields.len, @splat(false) };177 break :b .{ @"struct".field_names.len, @splat(false) };
178 } else b: {178 } else b: {
179 var fields = @"struct".fields.len;179 var fields = @"struct".field_names.len;
180 var skipped: [@"struct".fields.len]bool = @splat(false);180 var skipped: [@"struct".field_names.len]bool = @splat(false);
181 inline for (@"struct".fields, &skipped) |field_info, *skip| {181 inline for (
182 if (field_info.default_value_ptr) |ptr| {182 @"struct".field_names,
183 const default: *const field_info.type = @ptrCast(@alignCast(ptr));183 @"struct".field_types,
184 const field_value = @field(val, field_info.name);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);
185 if (std.meta.eql(field_value, default.*)) {190 if (std.meta.eql(field_value, default.*)) {
186 skip.* = true;191 skip.* = true;
187 fields -= 1;192 fields -= 1;
...@@ -195,11 +200,11 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption...@@ -195,11 +200,11 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
195 var container = try self.beginStruct(200 var container = try self.beginStruct(
196 .{ .whitespace_style = .{ .fields = fields } },201 .{ .whitespace_style = .{ .fields = fields } },
197 );202 );
198 inline for (@"struct".fields, skipped) |field_info, skip| {203 inline for (@"struct".field_names, skipped) |field_name, skip| {
199 if (!skip) {204 if (!skip) {
200 try container.fieldArbitraryDepth(205 try container.fieldArbitraryDepth(
201 field_info.name,206 field_name,
202 @field(val, field_info.name),207 @field(val, field_name),
203 options,208 options,
204 );209 );
205 }210 }
...@@ -713,11 +718,11 @@ fn typeIsRecursiveInner(comptime T: type, comptime prev_visited: []const type) b...@@ -713,11 +718,11 @@ fn typeIsRecursiveInner(comptime T: type, comptime prev_visited: []const type) b
713 .optional => |optional| typeIsRecursiveInner(optional.child, visited),718 .optional => |optional| typeIsRecursiveInner(optional.child, visited),
714 .array => |array| typeIsRecursiveInner(array.child, visited),719 .array => |array| typeIsRecursiveInner(array.child, visited),
715 .vector => |vector| typeIsRecursiveInner(vector.child, visited),720 .vector => |vector| typeIsRecursiveInner(vector.child, visited),
716 .@"struct" => |@"struct"| for (@"struct".fields) |field| {721 .@"struct" => |@"struct"| for (@"struct".field_types) |field_type| {
717 if (typeIsRecursiveInner(field.type, visited)) break true;722 if (typeIsRecursiveInner(field_type, visited)) break true;
718 } else false,723 } else false,
719 .@"union" => |@"union"| inline for (@"union".fields) |field| {724 .@"union" => |@"union"| inline for (@"union".field_types) |field_type| {
720 if (typeIsRecursiveInner(field.type, visited)) break true;725 if (typeIsRecursiveInner(field_type, visited)) break true;
721 } else false,726 } else false,
722 else => false,727 else => false,
723 };728 };
...@@ -761,8 +766,8 @@ fn checkValueDepth(val: anytype, depth: usize) error{ExceededMaxDepth}!void {...@@ -761,8 +766,8 @@ fn checkValueDepth(val: anytype, depth: usize) error{ExceededMaxDepth}!void {
761 .array => for (val) |item| {766 .array => for (val) |item| {
762 try checkValueDepth(item, child_depth);767 try checkValueDepth(item, child_depth);
763 },768 },
764 .@"struct" => |@"struct"| inline for (@"struct".fields) |field_info| {769 .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| {
765 try checkValueDepth(@field(val, field_info.name), child_depth);770 try checkValueDepth(@field(val, field_name), child_depth);
766 },771 },
767 .@"union" => |@"union"| if (@"union".tag_type == null) {772 .@"union" => |@"union"| if (@"union".tag_type == null) {
768 return;773 return;
...@@ -851,7 +856,7 @@ fn canSerializeTypeInner(...@@ -851,7 +856,7 @@ fn canSerializeTypeInner(
851 .@"opaque",856 .@"opaque",
852 => false,857 => false,
853858
854 .@"enum" => |@"enum"| @"enum".is_exhaustive,859 .@"enum" => |@"enum"| @"enum".mode == .exhaustive,
855860
856 .pointer => |pointer| switch (pointer.size) {861 .pointer => |pointer| switch (pointer.size) {
857 .one => canSerializeTypeInner(pointer.child, visited, parent_is_optional),862 .one => canSerializeTypeInner(pointer.child, visited, parent_is_optional),
...@@ -870,8 +875,8 @@ fn canSerializeTypeInner(...@@ -870,8 +875,8 @@ fn canSerializeTypeInner(
870 .@"struct" => |@"struct"| {875 .@"struct" => |@"struct"| {
871 for (visited) |V| if (T == V) return true;876 for (visited) |V| if (T == V) return true;
872 const new_visited = visited ++ .{T};877 const new_visited = visited ++ .{T};
873 for (@"struct".fields) |field| {878 for (@"struct".field_types) |field_type| {
874 if (!canSerializeTypeInner(field.type, new_visited, false)) return false;879 if (!canSerializeTypeInner(field_type, new_visited, false)) return false;
875 }880 }
876 return true;881 return true;
877 },882 },
...@@ -879,8 +884,8 @@ fn canSerializeTypeInner(...@@ -879,8 +884,8 @@ fn canSerializeTypeInner(
879 for (visited) |V| if (T == V) return true;884 for (visited) |V| if (T == V) return true;
880 const new_visited = visited ++ .{T};885 const new_visited = visited ++ .{T};
881 if (@"union".tag_type == null) return false;886 if (@"union".tag_type == null) return false;
882 for (@"union".fields) |field| {887 for (@"union".field_types) |field_type| {
883 if (field.type != void and !canSerializeTypeInner(field.type, new_visited, false)) {888 if (field_type != void and !canSerializeTypeInner(field_type, new_visited, false)) {
884 return false;889 return false;
885 }890 }
886 }891 }
lib/std/zon/parse.zig+58-61
...@@ -437,8 +437,8 @@ pub fn free(gpa: Allocator, value: anytype) void {...@@ -437,8 +437,8 @@ pub fn free(gpa: Allocator, value: anytype) void {
437 const array: [vector.len]vector.child = value;437 const array: [vector.len]vector.child = value;
438 freeArray(gpa, @TypeOf(array), &array);438 freeArray(gpa, @TypeOf(array), &array);
439 },439 },
440 .@"struct" => |@"struct"| inline for (@"struct".fields) |field| {440 .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| {
441 free(gpa, @field(value, field.name));441 free(gpa, @field(value, field_name));
442 },442 },
443 .@"union" => |@"union"| if (@"union".tag_type == null) {443 .@"union" => |@"union"| if (@"union".tag_type == null) {
444 if (comptime requiresAllocator(Value)) unreachable;444 if (comptime requiresAllocator(Value)) unreachable;
...@@ -464,13 +464,13 @@ fn requiresAllocator(T: type) bool {...@@ -464,13 +464,13 @@ fn requiresAllocator(T: type) bool {
464 return switch (@typeInfo(T)) {464 return switch (@typeInfo(T)) {
465 .pointer => true,465 .pointer => true,
466 .array => |array| return array.len > 0 and requiresAllocator(array.child),466 .array => |array| return array.len > 0 and requiresAllocator(array.child),
467 .@"struct" => |@"struct"| inline for (@"struct".fields) |field| {467 .@"struct" => |@"struct"| inline for (@"struct".field_types) |field_type| {
468 if (requiresAllocator(field.type)) {468 if (requiresAllocator(field_type)) {
469 break true;469 break true;
470 }470 }
471 } else false,471 } else false,
472 .@"union" => |@"union"| inline for (@"union".fields) |field| {472 .@"union" => |@"union"| inline for (@"union".field_types) |field_type| {
473 if (requiresAllocator(field.type)) {473 if (requiresAllocator(field_type)) {
474 break true;474 break true;
475 }475 }
476 } else false,476 } else false,
...@@ -589,9 +589,9 @@ const Parser = struct {...@@ -589,9 +589,9 @@ const Parser = struct {
589 .one => return self.failExpectedTypeInner(pointer.child, opt, node),589 .one => return self.failExpectedTypeInner(pointer.child, opt, node),
590 .slice => {590 .slice => {
591 if (pointer.child == u8 and591 if (pointer.child == u8 and
592 pointer.is_const and592 pointer.attrs.@"const" and
593 (pointer.sentinel() == null or pointer.sentinel() == 0) and593 (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))
595 {595 {
596 if (opt) {596 if (opt) {
597 return self.failNode(node, "expected optional string");597 return self.failNode(node, "expected optional string");
...@@ -669,10 +669,10 @@ const Parser = struct {...@@ -669,10 +669,10 @@ const Parser = struct {
669 switch (node.get(self.zoir)) {669 switch (node.get(self.zoir)) {
670 .enum_literal => |field_name| {670 .enum_literal => |field_name| {
671 // Create a comptime string map for the enum fields671 // Create a comptime string map for the enum fields
672 const enum_fields = @typeInfo(T).@"enum".fields;672 const enum_info = @typeInfo(T).@"enum";
673 comptime var kvs_list: [enum_fields.len]struct { []const u8, T } = undefined;673 comptime var kvs_list: [enum_info.field_names.len]struct { []const u8, T } = undefined;
674 inline for (enum_fields, 0..) |field, i| {674 inline for (enum_info.field_names, enum_info.field_values, 0..) |enum_field_name, enum_field_value, i| {
675 kvs_list[i] = .{ field.name, @enumFromInt(field.value) };675 kvs_list[i] = .{ enum_field_name, @enumFromInt(enum_field_value) };
676 }676 }
677 const enum_tags = std.StaticStringMap(T).initComptime(kvs_list);677 const enum_tags = std.StaticStringMap(T).initComptime(kvs_list);
678678
...@@ -715,9 +715,9 @@ const Parser = struct {...@@ -715,9 +715,9 @@ const Parser = struct {
715715
716 if (pointer.child != u8 or716 if (pointer.child != u8 or
717 pointer.size != .slice or717 pointer.size != .slice or
718 !pointer.is_const or718 !pointer.attrs.@"const" or
719 (pointer.sentinel() != null and pointer.sentinel() != 0) or719 (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))
721 {721 {
722 return error.WrongType;722 return error.WrongType;
723 }723 }
...@@ -742,7 +742,7 @@ const Parser = struct {...@@ -742,7 +742,7 @@ const Parser = struct {
742 const slice = try self.gpa.allocWithOptions(742 const slice = try self.gpa.allocWithOptions(
743 pointer.child,743 pointer.child,
744 nodes.len,744 nodes.len,
745 .fromByteUnitsOptional(pointer.alignment),745 .fromByteUnitsOptional(pointer.attrs.@"align"),
746 pointer.sentinel(),746 pointer.sentinel(),
747 );747 );
748 errdefer self.gpa.free(slice);748 errdefer self.gpa.free(slice);
...@@ -808,30 +808,30 @@ const Parser = struct {...@@ -808,30 +808,30 @@ const Parser = struct {
808 else => return error.WrongType,808 else => return error.WrongType,
809 };809 };
810810
811 const field_infos = @typeInfo(T).@"struct".fields;811 const info = @typeInfo(T).@"struct";
812812
813 // Build a map from field name to index.813 // Build a map from field name to index.
814 // The special value `comptime_field` indicates that this is actually a comptime field.814 // The special value `comptime_field` indicates that this is actually a comptime field.
815 const comptime_field = std.math.maxInt(usize);815 const comptime_field = std.math.maxInt(usize);
816 const field_indices: std.StaticStringMap(usize) = comptime b: {816 const field_indices: std.StaticStringMap(usize) = comptime b: {
817 var kvs_list: [field_infos.len]struct { []const u8, usize } = undefined;817 var kvs_list: [info.field_names.len]struct { []const u8, usize } = undefined;
818 for (&kvs_list, field_infos, 0..) |*kv, field, i| {818 for (&kvs_list, info.field_names, info.field_attrs, 0..) |*kv, field_name, field_attrs, i| {
819 kv.* = .{ field.name, if (field.is_comptime) comptime_field else i };819 kv.* = .{ field_name, if (field_attrs.@"comptime") comptime_field else i };
820 }820 }
821 break :b .initComptime(kvs_list);821 break :b .initComptime(kvs_list);
822 };822 };
823823
824 // Parse the struct824 // Parse the struct
825 var result: T = undefined;825 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
828 // If we fail partway through, free all already initialized fields828 // If we fail partway through, free all already initialized fields
829 var initialized: usize = 0;829 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) {
831 for (fields.names[0..initialized]) |name_runtime| {831 for (fields.names[0..initialized]) |name_runtime| {
832 switch (field_indices.get(name_runtime.get(self.zoir)) orelse continue) {832 switch (field_indices.get(name_runtime.get(self.zoir)) orelse continue) {
833 inline 0...(field_infos.len - 1) => |name_index| {833 inline 0...(info.field_names.len - 1) => |name_index| {
834 const name = field_infos[name_index].name;834 const name = info.field_names[name_index];
835 free(self.gpa, @field(result, name));835 free(self.gpa, @field(result, name));
836 },836 },
837 else => unreachable, // Can't be out of bounds837 else => unreachable, // Can't be out of bounds
...@@ -856,11 +856,11 @@ const Parser = struct {...@@ -856,11 +856,11 @@ const Parser = struct {
856 field_found[field_index] = true;856 field_found[field_index] = true;
857857
858 switch (field_index) {858 switch (field_index) {
859 inline 0...(field_infos.len - 1) => |j| {859 inline 0...(info.field_names.len - 1) => |j| {
860 if (field_infos[j].is_comptime) unreachable;860 if (info.field_attrs[j].@"comptime") unreachable;
861861
862 @field(result, field_infos[j].name) = try self.parseExpr(862 @field(result, info.field_names[j]) = try self.parseExpr(
863 field_infos[j].type,863 info.field_types[j],
864 fields.vals.at(@intCast(i)),864 fields.vals.at(@intCast(i)),
865 );865 );
866 },866 },
...@@ -873,15 +873,14 @@ const Parser = struct {...@@ -873,15 +873,14 @@ const Parser = struct {
873 // Fill in any missing default fields873 // Fill in any missing default fields
874 inline for (field_found, 0..) |found, i| {874 inline for (field_found, 0..) |found, i| {
875 if (!found) {875 if (!found) {
876 const field_info = field_infos[i];876 const field_attrs = info.field_attrs[i];
877 if (field_info.default_value_ptr) |default| {877 if (field_attrs.defaultValue(info.field_types[i])) |default| {
878 const typed: *const field_info.type = @ptrCast(@alignCast(default));878 @field(result, info.field_names[i]) = default;
879 @field(result, field_info.name) = typed.*;
880 } else {879 } else {
881 return self.failNodeFmt(880 return self.failNodeFmt(
882 node,881 node,
883 "missing required field {s}",882 "missing required field {s}",
884 .{field_infos[i].name},883 .{info.field_names[i]},
885 );884 );
886 }885 }
887 }886 }
...@@ -898,22 +897,21 @@ const Parser = struct {...@@ -898,22 +897,21 @@ const Parser = struct {
898 };897 };
899898
900 var result: T = undefined;899 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) {
904 return self.failNodeFmt(903 return self.failNodeFmt(
905 nodes.at(field_infos.len),904 nodes.at(info.field_names.len),
906 "index {} outside of tuple length {}",905 "index {} outside of tuple length {}",
907 .{ field_infos.len, field_infos.len },906 .{ info.field_names.len, info.field_names.len },
908 );907 );
909 }908 }
910909
911 inline for (0..field_infos.len) |i| {910 inline for (0..info.field_names.len) |i| {
912 // Check if we're out of bounds911 // Check if we're out of bounds
913 if (i >= nodes.len) {912 if (i >= nodes.len) {
914 if (field_infos[i].default_value_ptr) |default| {913 if (info.field_attrs[i].defaultValue(info.field_types[i])) |default| {
915 const typed: *const field_infos[i].type = @ptrCast(@alignCast(default));914 @field(result, info.field_names[i]) = default;
916 @field(result, field_infos[i].name) = typed.*;
917 } else {915 } else {
918 return self.failNodeFmt(node, "missing tuple field with index {}", .{i});916 return self.failNodeFmt(node, "missing tuple field with index {}", .{i});
919 }917 }
...@@ -926,10 +924,10 @@ const Parser = struct {...@@ -926,10 +924,10 @@ const Parser = struct {
926 }924 }
927 };925 };
928926
929 if (field_infos[i].is_comptime) {927 if (info.field_attrs[i].@"comptime") {
930 return self.failComptimeField(node, i);928 return self.failComptimeField(node, i);
931 } else {929 } 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));
933 }931 }
934 }932 }
935 }933 }
...@@ -939,15 +937,14 @@ const Parser = struct {...@@ -939,15 +937,14 @@ const Parser = struct {
939937
940 fn parseUnion(self: *@This(), T: type, node: Zoir.Node.Index) !T {938 fn parseUnion(self: *@This(), T: type, node: Zoir.Node.Index) !T {
941 const @"union" = @typeInfo(T).@"union";939 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
946 // Gather info on the fields943 // Gather info on the fields
947 const field_indices = b: {944 const field_indices = b: {
948 comptime var kvs_list: [field_infos.len]struct { []const u8, usize } = undefined;945 comptime var kvs_list: [@"union".field_names.len]struct { []const u8, usize } = undefined;
949 inline for (field_infos, 0..) |field, i| {946 inline for (@"union".field_names, 0..) |field_name, i| {
950 kvs_list[i] = .{ field.name, i };947 kvs_list[i] = .{ field_name, i };
951 }948 }
952 break :b std.StaticStringMap(usize).initComptime(kvs_list);949 break :b std.StaticStringMap(usize).initComptime(kvs_list);
953 };950 };
...@@ -970,13 +967,13 @@ const Parser = struct {...@@ -970,13 +967,13 @@ const Parser = struct {
970967
971 // Initialize the union from the given field.968 // Initialize the union from the given field.
972 switch (field_index) {969 switch (field_index) {
973 inline 0...field_infos.len - 1 => |i| {970 inline 0...@"union".field_names.len - 1 => |i| {
974 // Fail if the field is not void971 // Fail if the field is not void
975 if (field_infos[i].type != void)972 if (@"union".field_types[i] != void)
976 return self.failNode(node, "expected union");973 return self.failNode(node, "expected union");
977974
978 // Instantiate the union975 // Instantiate the union
979 return @unionInit(T, field_infos[i].name, {});976 return @unionInit(T, @"union".field_names[i], {});
980 },977 },
981 else => unreachable, // Can't be out of bounds978 else => unreachable, // Can't be out of bounds
982 }979 }
...@@ -994,12 +991,12 @@ const Parser = struct {...@@ -994,12 +991,12 @@ const Parser = struct {
994 return self.failUnexpected(T, "field", node, 0, field_name_str);991 return self.failUnexpected(T, "field", node, 0, field_name_str);
995992
996 switch (field_index) {993 switch (field_index) {
997 inline 0...field_infos.len - 1 => |i| {994 inline 0...@"union".field_names.len - 1 => |i| {
998 if (field_infos[i].type == void) {995 if (@"union".field_types[i] == void) {
999 return self.failNode(field_val, "expected type 'void'");996 return self.failNode(field_val, "expected type 'void'");
1000 } else {997 } else {
1001 const value = try self.parseExpr(field_infos[i].type, field_val);998 const value = try self.parseExpr(@"union".field_types[i], field_val);
1002 return @unionInit(T, field_infos[i].name, value);999 return @unionInit(T, @"union".field_names[i], value);
1003 }1000 }
1004 },1001 },
1005 else => unreachable, // Can't be out of bounds1002 else => unreachable, // Can't be out of bounds
...@@ -1106,7 +1103,7 @@ const Parser = struct {...@@ -1106,7 +1103,7 @@ const Parser = struct {
1106 } else self.ast.nodeMainToken(node.getAstNode(self.zoir));1103 } else self.ast.nodeMainToken(node.getAstNode(self.zoir));
1107 switch (@typeInfo(T)) {1104 switch (@typeInfo(T)) {
1108 inline .@"struct", .@"union", .@"enum" => |info| {1105 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: {
1110 break :b .{1107 break :b .{
1111 .token = token,1108 .token = token,
1112 .offset = 0,1109 .offset = 0,
...@@ -1118,9 +1115,9 @@ const Parser = struct {...@@ -1118,9 +1115,9 @@ const Parser = struct {
1118 var buf: std.ArrayList(u8) = try .initCapacity(gpa, 64);1115 var buf: std.ArrayList(u8) = try .initCapacity(gpa, 64);
1119 defer buf.deinit(gpa);1116 defer buf.deinit(gpa);
1120 try buf.appendSlice(gpa, msg);1117 try buf.appendSlice(gpa, msg);
1121 inline for (info.fields, 0..) |field_info, i| {1118 inline for (info.field_names, 0..) |field_name, i| {
1122 if (i != 0) try buf.appendSlice(gpa, ", ");1119 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, .{
1124 .allow_primitive = true,1121 .allow_primitive = true,
1125 .allow_underscore = true,1122 .allow_underscore = true,
1126 })});1123 })});
...@@ -1236,8 +1233,8 @@ fn canParseTypeInner(...@@ -1236,8 +1233,8 @@ fn canParseTypeInner(
1236 .@"struct" => |@"struct"| {1233 .@"struct" => |@"struct"| {
1237 for (visited) |V| if (T == V) return true;1234 for (visited) |V| if (T == V) return true;
1238 const new_visited = visited ++ .{T};1235 const new_visited = visited ++ .{T};
1239 for (@"struct".fields) |field| {1236 for (@"struct".field_types, @"struct".field_attrs) |field_type, field_attrs| {
1240 if (!field.is_comptime and !canParseTypeInner(field.type, new_visited, false)) {1237 if (!field_attrs.@"comptime" and !canParseTypeInner(field_type, new_visited, false)) {
1241 return false;1238 return false;
1242 }1239 }
1243 }1240 }
...@@ -1246,8 +1243,8 @@ fn canParseTypeInner(...@@ -1246,8 +1243,8 @@ fn canParseTypeInner(
1246 .@"union" => |@"union"| {1243 .@"union" => |@"union"| {
1247 for (visited) |V| if (T == V) return true;1244 for (visited) |V| if (T == V) return true;
1248 const new_visited = visited ++ .{T};1245 const new_visited = visited ++ .{T};
1249 for (@"union".fields) |field| {1246 for (@"union".field_types) |field_type| {
1250 if (field.type != void and !canParseTypeInner(field.type, new_visited, false)) {1247 if (field_type != void and !canParseTypeInner(field_type, new_visited, false)) {
1251 return false;1248 return false;
1252 }1249 }
1253 }1250 }
src/Air.zig+4-4
...@@ -1805,15 +1805,15 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1805,15 +1805,15 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
1805/// Returns the requested data, as well as the new index which is at the start of the1805/// Returns the requested data, as well as the new index which is at the start of the
1806/// trailers for the object.1806/// trailers for the object.
1807pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end: usize } {1807pub 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";
1809 var i: usize = index;1809 var i: usize = index;
1810 var result: T = undefined;1810 var result: T = undefined;
1811 inline for (fields) |field| {1811 inline for (info.field_names, info.field_types) |field_name, field_type| {
1812 @field(result, field.name) = switch (field.type) {1812 @field(result, field_name) = switch (field_type) {
1813 u32 => air.extra.items[i],1813 u32 => air.extra.items[i],
1814 InternPool.Index, Inst.Ref => @enumFromInt(air.extra.items[i]),1814 InternPool.Index, Inst.Ref => @enumFromInt(air.extra.items[i]),
1815 i32, CondBr.BranchHints, Asm.Flags => @bitCast(air.extra.items[i]),1815 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)),
1817 };1817 };
1818 i += 1;1818 i += 1;
1819 }1819 }
src/Air/Legalize.zig+8-8
...@@ -2635,7 +2635,7 @@ const Block = struct {...@@ -2635,7 +2635,7 @@ const Block = struct {
2635 .data = .{ .legalize_compiler_rt_call = .{2635 .data = .{ .legalize_compiler_rt_call = .{
2636 .func = func,2636 .func = func,
2637 .payload = payload: {2637 .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;
2639 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_len);2639 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_len);
2640 const index = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable;2640 const index = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable;
2641 l.air_extra.appendSliceAssumeCapacity(@ptrCast(args));2641 l.air_extra.appendSliceAssumeCapacity(@ptrCast(args));
...@@ -2913,12 +2913,12 @@ fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index {...@@ -2913,12 +2913,12 @@ fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index {
2913}2913}
29142914
2915fn addExtra(l: *Legalize, comptime Extra: type, extra: Extra) Error!u32 {2915fn addExtra(l: *Legalize, comptime Extra: type, extra: Extra) Error!u32 {
2916 const extra_fields = @typeInfo(Extra).@"struct".fields;2916 const extra_info = @typeInfo(Extra).@"struct";
2917 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_fields.len);2917 try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_info.field_names.len);
2918 defer inline for (extra_fields) |field| l.air_extra.appendAssumeCapacity(switch (field.type) {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),2919 u32 => @field(extra, field_name),
2920 Air.Inst.Ref => @intFromEnum(@field(extra, field.name)),2920 Air.Inst.Ref => @intFromEnum(@field(extra, field_name)),
2921 else => @compileError(@typeName(field.type)),2921 else => @compileError(@typeName(field_type)),
2922 });2922 });
2923 return @intCast(l.air_extra.items.len);2923 return @intCast(l.air_extra.items.len);
2924}2924}
...@@ -2954,7 +2954,7 @@ fn compilerRtCall(...@@ -2954,7 +2954,7 @@ fn compilerRtCall(
2954 const func_ret_ty = func.returnType();2954 const func_ret_ty = func.returnType();
29552955
2956 if (func_ret_ty.toIntern() == result_ty.toIntern()) {2956 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);
2958 const payload = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable;2958 const payload = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable;
2959 l.air_extra.appendSliceAssumeCapacity(@ptrCast(args));2959 l.air_extra.appendSliceAssumeCapacity(@ptrCast(args));
2960 return l.replaceInst(orig_inst, .legalize_compiler_rt_call, .{ .legalize_compiler_rt_call = .{2960 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 {...@@ -351,17 +351,17 @@ const Analysis = struct {
351 extra: std.ArrayList(u32),351 extra: std.ArrayList(u32),
352352
353 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {353 fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 {
354 const fields = std.meta.fields(@TypeOf(extra));354 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
355 try a.extra.ensureUnusedCapacity(a.gpa, fields.len);355 try a.extra.ensureUnusedCapacity(a.gpa, field_count);
356 return addExtraAssumeCapacity(a, extra);356 return addExtraAssumeCapacity(a, extra);
357 }357 }
358358
359 fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 {359 fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 {
360 const fields = std.meta.fields(@TypeOf(extra));360 const info = @typeInfo(@TypeOf(extra)).@"struct";
361 const result = @as(u32, @intCast(a.extra.items.len));361 const result = @as(u32, @intCast(a.extra.items.len));
362 inline for (fields) |field| {362 inline for (info.field_names, info.field_types) |field_name, field_type| {
363 a.extra.appendAssumeCapacity(switch (field.type) {363 a.extra.appendAssumeCapacity(switch (field_type) {
364 u32 => @field(extra, field.name),364 u32 => @field(extra, field_name),
365 else => @compileError("bad field type"),365 else => @compileError("bad field type"),
366 });366 });
367 }367 }
...@@ -1002,7 +1002,7 @@ fn analyzeInstBlock(...@@ -1002,7 +1002,7 @@ fn analyzeInstBlock(
1002 const block_scope = data.block_scopes.get(inst).?;1002 const block_scope = data.block_scopes.get(inst).?;
1003 const num_deaths = data.live_set.count() - block_scope.live_set.count();1003 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);
1006 const extra_index = a.addExtraAssumeCapacity(Block{1006 const extra_index = a.addExtraAssumeCapacity(Block{
1007 .death_count = num_deaths,1007 .death_count = num_deaths,
1008 });1008 });
...@@ -1265,7 +1265,7 @@ fn analyzeInstCondBr(...@@ -1265,7 +1265,7 @@ fn analyzeInstCondBr(
1265 // Write the mirrored deaths to `extra`1265 // Write the mirrored deaths to `extra`
1266 const then_death_count = @as(u32, @intCast(then_mirrored_deaths.items.len));1266 const then_death_count = @as(u32, @intCast(then_mirrored_deaths.items.len));
1267 const else_death_count = @as(u32, @intCast(else_mirrored_deaths.items.len));1267 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);
1269 const extra_index = a.addExtraAssumeCapacity(CondBr{1269 const extra_index = a.addExtraAssumeCapacity(CondBr{
1270 .then_death_count = then_death_count,1270 .then_death_count = then_death_count,
1271 .else_death_count = else_death_count,1271 .else_death_count = else_death_count,
src/Builtin.zig+3-3
...@@ -23,8 +23,8 @@ wasi_exec_model: std.lang.WasiExecModel,...@@ -23,8 +23,8 @@ wasi_exec_model: std.lang.WasiExecModel,
23/// of the resulting file contents.23/// of the resulting file contents.
24pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {24pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {
25 var h: Cache.Hasher = Cache.hasher_init;25 var h: Cache.Hasher = Cache.hasher_init;
26 inline for (@typeInfo(@This()).@"struct".fields) |f| {26 inline for (@typeInfo(@This()).@"struct".field_names) |f_name| {
27 if (comptime std.mem.eql(u8, f.name, "target")) {27 if (comptime std.mem.eql(u8, f_name, "target")) {
28 // This needs special handling.28 // This needs special handling.
29 std.hash.autoHash(&h, opts.target.cpu);29 std.hash.autoHash(&h, opts.target.cpu);
30 std.hash.autoHash(&h, opts.target.os.tag);30 std.hash.autoHash(&h, opts.target.os.tag);
...@@ -33,7 +33,7 @@ pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {...@@ -33,7 +33,7 @@ pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 {
33 std.hash.autoHash(&h, opts.target.ofmt);33 std.hash.autoHash(&h, opts.target.ofmt);
34 std.hash.autoHash(&h, opts.target.dynamic_linker);34 std.hash.autoHash(&h, opts.target.dynamic_linker);
35 } else {35 } else {
36 std.hash.autoHash(&h, @field(opts, f.name));36 std.hash.autoHash(&h, @field(opts, f_name));
37 }37 }
38 }38 }
39 return h.finalResult();39 return h.finalResult();
src/Compilation.zig+18-18
...@@ -298,15 +298,15 @@ const QueuedJobs = struct {...@@ -298,15 +298,15 @@ const QueuedJobs = struct {
298 ubsan_rt_lib: bool = false,298 ubsan_rt_lib: bool = false,
299 ubsan_rt_obj: bool = false,299 ubsan_rt_obj: bool = false,
300 fuzzer_lib: bool = false,300 fuzzer_lib: bool = false,
301 musl_crt_file: [@typeInfo(musl.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".fields.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".fields.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".fields.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".fields.len]bool = @splat(false),305 openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".field_names.len]bool = @splat(false),
306 /// one of WASI libc static objects306 /// 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),
308 /// one of the mingw-w64 static objects308 /// 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),
310 /// all of the glibc shared objects310 /// all of the glibc shared objects
311 glibc_shared_objects: bool = false,311 glibc_shared_objects: bool = false,
312 freebsd_shared_objects: bool = false,312 freebsd_shared_objects: bool = false,
...@@ -2552,10 +2552,10 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2552,10 +2552,10 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2552 error.LibCInstallationMissingCrtDir => return diag.fail(.libc_installation_missing_crt_dir),2552 error.LibCInstallationMissingCrtDir => return diag.fail(.libc_installation_missing_crt_dir),
2553 };2553 };
25542554
2555 const fields = @typeInfo(@TypeOf(paths)).@"struct".fields;2555 const field_names = @typeInfo(@TypeOf(paths)).@"struct".field_names;
2556 try comp.oneshot_prelink_tasks.ensureUnusedCapacity(gpa, fields.len + 1);2556 try comp.oneshot_prelink_tasks.ensureUnusedCapacity(gpa, field_names.len + 1);
2557 inline for (fields) |field| {2557 inline for (field_names) |field_name| {
2558 if (@field(paths, field.name)) |path| {2558 if (@field(paths, field_name)) |path| {
2559 comp.oneshot_prelink_tasks.appendAssumeCapacity(.{ .load_object = path });2559 comp.oneshot_prelink_tasks.appendAssumeCapacity(.{ .load_object = path });
2560 }2560 }
2561 }2561 }
...@@ -4667,49 +4667,49 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node...@@ -4667,49 +4667,49 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node
4667 prelink_group.async(io, buildLibZigC, .{ comp, main_progress_node });4667 prelink_group.async(io, buildLibZigC, .{ comp, main_progress_node });
4668 }4668 }
46694669
4670 for (0..@typeInfo(musl.CrtFile).@"enum".fields.len) |i| {4670 for (0..@typeInfo(musl.CrtFile).@"enum".field_names.len) |i| {
4671 if (comp.queued_jobs.musl_crt_file[i]) {4671 if (comp.queued_jobs.musl_crt_file[i]) {
4672 const tag: musl.CrtFile = @enumFromInt(i);4672 const tag: musl.CrtFile = @enumFromInt(i);
4673 prelink_group.async(io, buildMuslCrtFile, .{ comp, tag, main_progress_node });4673 prelink_group.async(io, buildMuslCrtFile, .{ comp, tag, main_progress_node });
4674 }4674 }
4675 }4675 }
46764676
4677 for (0..@typeInfo(glibc.CrtFile).@"enum".fields.len) |i| {4677 for (0..@typeInfo(glibc.CrtFile).@"enum".field_names.len) |i| {
4678 if (comp.queued_jobs.glibc_crt_file[i]) {4678 if (comp.queued_jobs.glibc_crt_file[i]) {
4679 const tag: glibc.CrtFile = @enumFromInt(i);4679 const tag: glibc.CrtFile = @enumFromInt(i);
4680 prelink_group.async(io, buildGlibcCrtFile, .{ comp, tag, main_progress_node });4680 prelink_group.async(io, buildGlibcCrtFile, .{ comp, tag, main_progress_node });
4681 }4681 }
4682 }4682 }
46834683
4684 for (0..@typeInfo(freebsd.CrtFile).@"enum".fields.len) |i| {4684 for (0..@typeInfo(freebsd.CrtFile).@"enum".field_names.len) |i| {
4685 if (comp.queued_jobs.freebsd_crt_file[i]) {4685 if (comp.queued_jobs.freebsd_crt_file[i]) {
4686 const tag: freebsd.CrtFile = @enumFromInt(i);4686 const tag: freebsd.CrtFile = @enumFromInt(i);
4687 prelink_group.async(io, buildFreeBSDCrtFile, .{ comp, tag, main_progress_node });4687 prelink_group.async(io, buildFreeBSDCrtFile, .{ comp, tag, main_progress_node });
4688 }4688 }
4689 }4689 }
46904690
4691 for (0..@typeInfo(netbsd.CrtFile).@"enum".fields.len) |i| {4691 for (0..@typeInfo(netbsd.CrtFile).@"enum".field_names.len) |i| {
4692 if (comp.queued_jobs.netbsd_crt_file[i]) {4692 if (comp.queued_jobs.netbsd_crt_file[i]) {
4693 const tag: netbsd.CrtFile = @enumFromInt(i);4693 const tag: netbsd.CrtFile = @enumFromInt(i);
4694 prelink_group.async(io, buildNetBSDCrtFile, .{ comp, tag, main_progress_node });4694 prelink_group.async(io, buildNetBSDCrtFile, .{ comp, tag, main_progress_node });
4695 }4695 }
4696 }4696 }
46974697
4698 for (0..@typeInfo(openbsd.CrtFile).@"enum".fields.len) |i| {4698 for (0..@typeInfo(openbsd.CrtFile).@"enum".field_names.len) |i| {
4699 if (comp.queued_jobs.openbsd_crt_file[i]) {4699 if (comp.queued_jobs.openbsd_crt_file[i]) {
4700 const tag: openbsd.CrtFile = @enumFromInt(i);4700 const tag: openbsd.CrtFile = @enumFromInt(i);
4701 prelink_group.async(io, buildOpenBSDCrtFile, .{ comp, tag, main_progress_node });4701 prelink_group.async(io, buildOpenBSDCrtFile, .{ comp, tag, main_progress_node });
4702 }4702 }
4703 }4703 }
47044704
4705 for (0..@typeInfo(wasi_libc.CrtFile).@"enum".fields.len) |i| {4705 for (0..@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len) |i| {
4706 if (comp.queued_jobs.wasi_libc_crt_file[i]) {4706 if (comp.queued_jobs.wasi_libc_crt_file[i]) {
4707 const tag: wasi_libc.CrtFile = @enumFromInt(i);4707 const tag: wasi_libc.CrtFile = @enumFromInt(i);
4708 prelink_group.async(io, buildWasiLibcCrtFile, .{ comp, tag, main_progress_node });4708 prelink_group.async(io, buildWasiLibcCrtFile, .{ comp, tag, main_progress_node });
4709 }4709 }
4710 }4710 }
47114711
4712 for (0..@typeInfo(mingw.CrtFile).@"enum".fields.len) |i| {4712 for (0..@typeInfo(mingw.CrtFile).@"enum".field_names.len) |i| {
4713 if (comp.queued_jobs.mingw_crt_file[i]) {4713 if (comp.queued_jobs.mingw_crt_file[i]) {
4714 const tag: mingw.CrtFile = @enumFromInt(i);4714 const tag: mingw.CrtFile = @enumFromInt(i);
4715 prelink_group.async(io, buildMingwCrtFile, .{ comp, tag, main_progress_node });4715 prelink_group.async(io, buildMingwCrtFile, .{ comp, tag, main_progress_node });
src/InternPool.zig+108-107
...@@ -1070,17 +1070,15 @@ const Local = struct {...@@ -1070,17 +1070,15 @@ const Local = struct {
10701070
1071 fn PtrArrayElem(comptime len: usize) type {1071 fn PtrArrayElem(comptime len: usize) type {
1072 const elem_info = @typeInfo(Elem).@"struct";1072 const elem_info = @typeInfo(Elem).@"struct";
1073 const elem_fields = elem_info.fields;1073
1074 var new_names: [elem_fields.len][]const u8 = undefined;1074 var new_types: [elem_info.field_types.len]type = undefined;
1075 var new_types: [elem_fields.len]type = undefined;1075 for (&new_types, elem_info.field_types) |*NewType, elem_field_type| {
1076 for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| {1076 NewType.* = *[len]elem_field_type;
1077 new_name.* = elem_field.name;
1078 NewType.* = *[len]elem_field.type;
1079 }1077 }
1080 if (elem_info.is_tuple) {1078 if (elem_info.is_tuple) {
1081 return @Tuple(&new_types);1079 return @Tuple(&new_types);
1082 } else {1080 } else {
1083 return @Struct(.auto, null, &new_names, &new_types, &@splat(.{}));1081 return @Struct(.auto, null, elem_info.field_names, &new_types, &@splat(.{}));
1084 }1082 }
1085 }1083 }
1086 fn PtrElem(comptime opts: struct {1084 fn PtrElem(comptime opts: struct {
...@@ -1088,17 +1086,14 @@ const Local = struct {...@@ -1088,17 +1086,14 @@ const Local = struct {
1088 is_const: bool = false,1086 is_const: bool = false,
1089 }) type {1087 }) type {
1090 const elem_info = @typeInfo(Elem).@"struct";1088 const elem_info = @typeInfo(Elem).@"struct";
1091 const elem_fields = elem_info.fields;1089 var new_types: [elem_info.field_types.len]type = undefined;
1092 var new_names: [elem_fields.len][]const u8 = undefined;1090 for (&new_types, elem_info.field_types) |*NewType, elem_field_type| {
1093 var new_types: [elem_fields.len]type = undefined;1091 NewType.* = @Pointer(opts.size, .{ .@"const" = opts.is_const }, elem_field_type, null);
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);
1097 }1092 }
1098 if (elem_info.is_tuple) {1093 if (elem_info.is_tuple) {
1099 return @Tuple(&new_types);1094 return @Tuple(&new_types);
1100 } else {1095 } else {
1101 return @Struct(.auto, null, &new_names, &new_types, &@splat(.{}));1096 return @Struct(.auto, null, elem_info.field_names, &new_types, &@splat(.{}));
1102 }1097 }
1103 }1098 }
11041099
...@@ -4295,48 +4290,51 @@ pub const Index = enum(u32) {...@@ -4295,48 +4290,51 @@ pub const Index = enum(u32) {
4295 },4290 },
4296 }) void {4291 }) void {
4297 _ = self;4292 _ = 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";
4299 @setEvalBranchQuota(3_000);4294 @setEvalBranchQuota(3_000);
4300 inline for (@typeInfo(Tag).@"enum".fields, 0..) |tag, start| {4295 inline for (@typeInfo(Tag).@"enum".field_names, 0..) |tag_name, start| {
4301 inline for (0..map_fields.len) |offset| {4296 inline for (0..map_info.field_names.len) |offset| {
4302 if (comptime std.mem.eql(u8, tag.name, map_fields[(start + offset) % map_fields.len].name)) break;4297 if (comptime std.mem.eql(u8, tag_name, map_info.field_names[(start + offset) % map_info.field_names.len])) break;
4303 } else {4298 } 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");
4305 }4300 }
4306 }4301 }
4307 }4302 }
4308 comptime {4303 comptime {
4309 if (!builtin.strip_debug_info) switch (builtin.zig_backend) {4304 if (!builtin.strip_debug_info) switch (builtin.zig_backend) {
4310 .stage2_llvm => _ = &dbHelper,4305 .stage2_llvm => _ = &dbHelper,
4311 .stage2_x86_64 => for (@typeInfo(Tag).@"enum".fields) |tag| {4306 .stage2_x86_64 => for (@typeInfo(Tag).@"enum".field_names) |tag_name| {
4312 if (!@hasField(@TypeOf(Tag.encodings), tag.name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name);4307 if (!@hasField(@TypeOf(Tag.encodings), tag_name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name);
4313 const encoding = @field(Tag.encodings, tag.name);4308 const encoding = @field(Tag.encodings, tag_name);
4314 if (@hasField(@TypeOf(encoding), "trailing")) for (@typeInfo(encoding.trailing).@"struct".fields) |field| {4309 if (@hasField(@TypeOf(encoding), "trailing")) {
4315 struct {4310 const trailing_info = @typeInfo(encoding.trailing).@"struct";
4316 fn checkConfig(name: []const u8) void {4311 for (trailing_info.field_names, trailing_info.field_types) |field_name, field_type| {
4317 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\"");4312 struct {
4318 const FieldType = @TypeOf(@field(encoding.config, name));4313 fn checkConfig(name: []const u8) void {
4319 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));4314 if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ ".config.@\"" ++ name ++ "\"");
4320 }4315 const FieldType = @TypeOf(@field(encoding.config, name));
4321 fn checkField(name: []const u8, Type: type) void {4316 if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType));
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)),
4336 }4317 }
4337 }4318 fn checkField(name: []const u8, Type: type) void {
4338 }.checkField("trailing." ++ field.name, field.type);4319 switch (@typeInfo(Type)) {
4339 };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 }
4340 },4338 },
4341 else => {},4339 else => {},
4342 };4340 };
...@@ -6965,7 +6963,7 @@ fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local....@@ -6965,7 +6963,7 @@ fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local.
6965 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);6963 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);
6966 const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]);6964 const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]);
6967 const func_decl = ip.funcDeclInfo(generic_owner);6965 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);
6969 return .{6967 return .{
6970 .tid = tid,6968 .tid = tid,
6971 .ty = ty,6969 .ty = ty,
...@@ -7305,7 +7303,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7305,7 +7303,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
7305 const names_map = try ip.addMap(gpa, io, tid, names.len);7303 const names_map = try ip.addMap(gpa, io, tid, names.len);
7306 ip.addStringsToMap(names_map, names);7304 ip.addStringsToMap(names_map, names);
7307 const names_len = error_set_type.names.len;7305 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);
7309 items.appendAssumeCapacity(.{7307 items.appendAssumeCapacity(.{
7310 .tag = .type_error_set,7308 .tag = .type_error_set,
7311 .data = addExtraAssumeCapacity(extra, Tag.ErrorSet{7309 .data = addExtraAssumeCapacity(extra, Tag.ErrorSet{
...@@ -7861,7 +7859,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7861,7 +7859,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
7861 .repeated_elem => |elem| elem,7859 .repeated_elem => |elem| elem,
7862 };7860 };
78637861
7864 try extra.ensureUnusedCapacity(@typeInfo(Repeated).@"struct".fields.len);7862 try extra.ensureUnusedCapacity(@typeInfo(Repeated).@"struct".field_names.len);
7865 items.appendAssumeCapacity(.{7863 items.appendAssumeCapacity(.{
7866 .tag = .repeated,7864 .tag = .repeated,
7867 .data = addExtraAssumeCapacity(extra, Repeated{7865 .data = addExtraAssumeCapacity(extra, Repeated{
...@@ -7876,7 +7874,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7876,7 +7874,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
7876 const string_bytes = ip.getLocal(tid).getMutableStringBytes(gpa, io);7874 const string_bytes = ip.getLocal(tid).getMutableStringBytes(gpa, io);
7877 const start = string_bytes.mutate.len;7875 const start = string_bytes.mutate.len;
7878 try string_bytes.ensureUnusedCapacity(@intCast(len_including_sentinel + 1));7876 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);
7880 switch (aggregate.storage) {7878 switch (aggregate.storage) {
7881 .bytes => |bytes| string_bytes.appendSliceAssumeCapacity(.{bytes.toSlice(len, ip)}),7879 .bytes => |bytes| string_bytes.appendSliceAssumeCapacity(.{bytes.toSlice(len, ip)}),
7882 .elems => |elems| for (elems[0..@intCast(len)]) |elem| switch (ip.indexToKey(elem)) {7880 .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:...@@ -7917,7 +7915,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
7917 }7915 }
79187916
7919 try extra.ensureUnusedCapacity(7917 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)),
7921 );7919 );
7922 items.appendAssumeCapacity(.{7920 items.appendAssumeCapacity(.{
7923 .tag = .aggregate,7921 .tag = .aggregate,
...@@ -7943,7 +7941,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:...@@ -7943,7 +7941,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key:
79437941
7944 .memoized_call => |memoized_call| {7942 .memoized_call => |memoized_call| {
7945 for (memoized_call.arg_values) |arg| assert(arg != .none);7943 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 +
7947 memoized_call.arg_values.len);7945 memoized_call.arg_values.len);
7948 items.appendAssumeCapacity(.{7946 items.appendAssumeCapacity(.{
7949 .tag = .memoized_call,7947 .tag = .memoized_call,
...@@ -8006,7 +8004,7 @@ pub fn getDeclaredStructType(...@@ -8006,7 +8004,7 @@ pub fn getDeclaredStructType(
8006 .auto => false,8004 .auto => false,
8007 .@"extern" => true,8005 .@"extern" => true,
8008 .@"packed" => {8006 .@"packed" => {
8009 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".fields.len +8007 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".field_names.len +
8010 ini.captures.len + // capture8008 ini.captures.len + // capture
8011 ini.fields_len + // field_name8009 ini.fields_len + // field_name
8012 ini.fields_len + // field_type8010 ini.fields_len + // field_type
...@@ -8053,7 +8051,7 @@ pub fn getDeclaredStructType(...@@ -8053,7 +8051,7 @@ pub fn getDeclaredStructType(
8053 },8051 },
8054 };8052 };
80558053
8056 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".fields.len +8054 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".field_names.len +
8057 1 + // captures_len8055 1 + // captures_len
8058 ini.captures.len + // capture8056 ini.captures.len + // capture
8059 ini.fields_len + // field_name8057 ini.fields_len + // field_name
...@@ -8150,7 +8148,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe...@@ -8150,7 +8148,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe
8150 .auto => false,8148 .auto => false,
8151 .@"extern" => true,8149 .@"extern" => true,
8152 .@"packed" => {8150 .@"packed" => {
8153 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".fields.len +8151 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".field_names.len +
8154 2 + // type_hash8152 2 + // type_hash
8155 ini.fields_len + // field_name8153 ini.fields_len + // field_name
8156 ini.fields_len + // field_type8154 ini.fields_len + // field_type
...@@ -8203,7 +8201,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe...@@ -8203,7 +8201,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe
8203 },8201 },
8204 };8202 };
82058203
8206 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".fields.len +8204 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".field_names.len +
8207 2 + // type_hash8205 2 + // type_hash
8208 ini.fields_len + // field_name8206 ini.fields_len + // field_name
8209 ini.fields_len + // field_type8207 ini.fields_len + // field_type
...@@ -8323,7 +8321,7 @@ pub fn getDeclaredUnionType(...@@ -8323,7 +8321,7 @@ pub fn getDeclaredUnionType(
8323 .auto => false,8321 .auto => false,
8324 .@"extern" => true,8322 .@"extern" => true,
8325 .@"packed" => {8323 .@"packed" => {
8326 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".fields.len +8324 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len +
8327 ini.captures.len + // capture8325 ini.captures.len + // capture
8328 ini.fields_len); // field_type8326 ini.fields_len); // field_type
83298327
...@@ -8364,7 +8362,7 @@ pub fn getDeclaredUnionType(...@@ -8364,7 +8362,7 @@ pub fn getDeclaredUnionType(
8364 },8362 },
8365 };8363 };
83668364
8367 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".fields.len +8365 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".field_names.len +
8368 1 + // captures_len8366 1 + // captures_len
8369 ini.captures.len + // capture8367 ini.captures.len + // capture
8370 ini.fields_len + // field_type8368 ini.fields_len + // field_type
...@@ -8445,7 +8443,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per...@@ -8445,7 +8443,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per
8445 .auto => false,8443 .auto => false,
8446 .@"extern" => true,8444 .@"extern" => true,
8447 .@"packed" => {8445 .@"packed" => {
8448 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".fields.len +8446 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len +
8449 2 + // type_hash8447 2 + // type_hash
8450 ini.fields_len + // reified_field_name8448 ini.fields_len + // reified_field_name
8451 ini.fields_len); // field_type8449 ini.fields_len); // field_type
...@@ -8490,7 +8488,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per...@@ -8490,7 +8488,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per
8490 },8488 },
8491 };8489 };
84928490
8493 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".fields.len +8491 try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".field_names.len +
8494 2 + // type_hash8492 2 + // type_hash
8495 ini.fields_len + // reified_field_name8493 ini.fields_len + // reified_field_name
8496 ini.fields_len + // field_type8494 ini.fields_len + // field_type
...@@ -8597,7 +8595,7 @@ pub fn getDeclaredEnumType(...@@ -8597,7 +8595,7 @@ pub fn getDeclaredEnumType(
8597 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;8595 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;
8598 errdefer local.mutate.maps.len -= @intFromBool(have_values);8596 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 +
8601 1 + // zir_index8599 1 + // zir_index
8602 ini.captures.len + // capture8600 ini.captures.len + // capture
8603 @intFromBool(have_values) + // field_value_map8601 @intFromBool(have_values) + // field_value_map
...@@ -8672,7 +8670,7 @@ pub fn getReifiedEnumType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerT...@@ -8672,7 +8670,7 @@ pub fn getReifiedEnumType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerT
8672 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;8670 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;
8673 errdefer local.mutate.maps.len -= @intFromBool(have_values);8671 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 +
8676 1 + // zir_index8674 1 + // zir_index
8677 2 + // type_hash8675 2 + // type_hash
8678 @intFromBool(have_values) + // field_value_map8676 @intFromBool(have_values) + // field_value_map
...@@ -8746,7 +8744,7 @@ pub fn getGeneratedEnumTagType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu...@@ -8746,7 +8744,7 @@ pub fn getGeneratedEnumTagType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu
8746 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;8744 const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined;
8747 errdefer local.mutate.maps.len -= @intFromBool(have_values);8745 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 +
8750 1 + // owner_union8748 1 + // owner_union
8751 @intFromBool(have_values) + // field_value_map8749 @intFromBool(have_values) + // field_value_map
8752 ini.fields_len + // field_name8750 ini.fields_len + // field_name
...@@ -8805,7 +8803,7 @@ pub fn getDeclaredOpaqueType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.P...@@ -8805,7 +8803,7 @@ pub fn getDeclaredOpaqueType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.P
8805 const extra = local.getMutableExtra(gpa, io);8803 const extra = local.getMutableExtra(gpa, io);
8806 try items.ensureUnusedCapacity(1);8804 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);
8809 const extra_index = addExtraAssumeCapacity(extra, Tag.TypeOpaque{8807 const extra_index = addExtraAssumeCapacity(extra, Tag.TypeOpaque{
8810 .zir_index = ini.zir_index,8808 .zir_index = ini.zir_index,
8811 .captures_len = @intCast(ini.captures.len),8809 .captures_len = @intCast(ini.captures.len),
...@@ -8938,7 +8936,7 @@ pub fn getTupleType(...@@ -8938,7 +8936,7 @@ pub fn getTupleType(
89388936
8939 try items.ensureUnusedCapacity(1);8937 try items.ensureUnusedCapacity(1);
8940 try extra.ensureUnusedCapacity(8938 try extra.ensureUnusedCapacity(
8941 @typeInfo(TypeTuple).@"struct".fields.len + (fields_len * 3),8939 @typeInfo(TypeTuple).@"struct".field_names.len + (fields_len * 3),
8942 );8940 );
89438941
8944 const extra_index = addExtraAssumeCapacity(extra, TypeTuple{8942 const extra_index = addExtraAssumeCapacity(extra, TypeTuple{
...@@ -8996,7 +8994,7 @@ pub fn getFuncType(...@@ -8996,7 +8994,7 @@ pub fn getFuncType(
8996 const prev_extra_len = extra.mutate.len;8994 const prev_extra_len = extra.mutate.len;
8997 const params_len: u32 = @intCast(key.param_types.len);8995 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 +
9000 @intFromBool(key.comptime_bits != 0) +8998 @intFromBool(key.comptime_bits != 0) +
9001 @intFromBool(key.noalias_bits != 0) +8999 @intFromBool(key.noalias_bits != 0) +
9002 params_len);9000 params_len);
...@@ -9059,7 +9057,7 @@ pub fn getExtern(...@@ -9059,7 +9057,7 @@ pub fn getExtern(
9059 const items = local.getMutableItems(gpa, io);9057 const items = local.getMutableItems(gpa, io);
9060 const extra = local.getMutableExtra(gpa, io);9058 const extra = local.getMutableExtra(gpa, io);
9061 try items.ensureUnusedCapacity(1);9059 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);
9063 try local.getMutableNavs(gpa, io).ensureUnusedCapacity(1);9061 try local.getMutableNavs(gpa, io).ensureUnusedCapacity(1);
90649062
9065 // Predict the index the `@"extern" will live at, so we can construct the owner `Nav` before releasing the shard's mutex.9063 // 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(...@@ -9138,7 +9136,7 @@ pub fn getFuncDecl(
9138 // arrays. This is similar to what `getOrPutTrailingString` does.9136 // arrays. This is similar to what `getOrPutTrailingString` does.
9139 const prev_extra_len = extra.mutate.len;9137 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
9143 const func_decl_extra_index = addExtraAssumeCapacity(extra, Tag.FuncDecl{9141 const func_decl_extra_index = addExtraAssumeCapacity(extra, Tag.FuncDecl{
9144 .analysis = .{9142 .analysis = .{
...@@ -9225,10 +9223,10 @@ pub fn getFuncDeclIes(...@@ -9225,10 +9223,10 @@ pub fn getFuncDeclIes(
9225 const prev_extra_len = extra.mutate.len;9223 const prev_extra_len = extra.mutate.len;
9226 const params_len: u32 = @intCast(key.param_types.len);9224 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 +
9229 1 + // inferred_error_set9227 1 + // inferred_error_set
9230 @typeInfo(Tag.ErrorUnionType).@"struct".fields.len +9228 @typeInfo(Tag.ErrorUnionType).@"struct".field_names.len +
9231 @typeInfo(Tag.TypeFunction).@"struct".fields.len +9229 @typeInfo(Tag.TypeFunction).@"struct".field_names.len +
9232 @intFromBool(key.comptime_bits != 0) +9230 @intFromBool(key.comptime_bits != 0) +
9233 @intFromBool(key.noalias_bits != 0) +9231 @intFromBool(key.noalias_bits != 0) +
9234 params_len);9232 params_len);
...@@ -9364,7 +9362,7 @@ pub fn getErrorSetType(...@@ -9364,7 +9362,7 @@ pub fn getErrorSetType(
9364 const local = ip.getLocal(tid);9362 const local = ip.getLocal(tid);
9365 const items = local.getMutableItems(gpa, io);9363 const items = local.getMutableItems(gpa, io);
9366 const extra = local.getMutableExtra(gpa, io);9364 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
9369 const names_map = try ip.addMap(gpa, io, tid, names.len);9367 const names_map = try ip.addMap(gpa, io, tid, names.len);
9370 errdefer local.mutate.maps.len -= 1;9368 errdefer local.mutate.maps.len -= 1;
...@@ -9440,7 +9438,7 @@ pub fn getFuncInstance(...@@ -9440,7 +9438,7 @@ pub fn getFuncInstance(
9440 const local = ip.getLocal(tid);9438 const local = ip.getLocal(tid);
9441 const items = local.getMutableItems(gpa, io);9439 const items = local.getMutableItems(gpa, io);
9442 const extra = local.getMutableExtra(gpa, io);9440 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 +
9444 arg.comptime_args.len);9442 arg.comptime_args.len);
94459443
9446 assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner)));9444 assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner)));
...@@ -9524,11 +9522,11 @@ fn getFuncInstanceIes(...@@ -9524,11 +9522,11 @@ fn getFuncInstanceIes(
9524 const prev_extra_len = extra.mutate.len;9522 const prev_extra_len = extra.mutate.len;
9525 const params_len: u32 = @intCast(arg.param_types.len);9523 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 +
9528 1 + // inferred_error_set9526 1 + // inferred_error_set
9529 arg.comptime_args.len +9527 arg.comptime_args.len +
9530 @typeInfo(Tag.ErrorUnionType).@"struct".fields.len +9528 @typeInfo(Tag.ErrorUnionType).@"struct".field_names.len +
9531 @typeInfo(Tag.TypeFunction).@"struct".fields.len +9529 @typeInfo(Tag.TypeFunction).@"struct".field_names.len +
9532 @intFromBool(arg.noalias_bits != 0) +9530 @intFromBool(arg.noalias_bits != 0) +
9533 params_len);9531 params_len);
95349532
...@@ -9774,15 +9772,16 @@ fn addInt(...@@ -9774,15 +9772,16 @@ fn addInt(
9774}9772}
97759773
9776fn addExtra(extra: Local.Extra.Mutable, item: anytype) Allocator.Error!u32 {9774fn addExtra(extra: Local.Extra.Mutable, item: anytype) Allocator.Error!u32 {
9777 const fields = @typeInfo(@TypeOf(item)).@"struct".fields;9775 const field_count = @typeInfo(@TypeOf(item)).@"struct".field_names.len;
9778 try extra.ensureUnusedCapacity(fields.len);9776 try extra.ensureUnusedCapacity(field_count);
9779 return addExtraAssumeCapacity(extra, item);9777 return addExtraAssumeCapacity(extra, item);
9780}9778}
97819779
9782fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {9780fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
9783 const result: u32 = extra.mutate.len;9781 const result: u32 = extra.mutate.len;
9784 inline for (@typeInfo(@TypeOf(item)).@"struct".fields) |field| {9782 const info = @typeInfo(@TypeOf(item)).@"struct";
9785 extra.appendAssumeCapacity(.{switch (field.type) {9783 inline for (info.field_types, info.field_names) |field_type, field_name| {
9784 extra.appendAssumeCapacity(.{switch (field_type) {
9786 Index,9785 Index,
9787 Nav.Index,9786 Nav.Index,
9788 Nav.Index.Optional,9787 Nav.Index.Optional,
...@@ -9797,7 +9796,7 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {...@@ -9797,7 +9796,7 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
9797 TrackedInst.Index,9796 TrackedInst.Index,
9798 TrackedInst.Index.Optional,9797 TrackedInst.Index.Optional,
9799 ComptimeAllocIndex,9798 ComptimeAllocIndex,
9800 => @intFromEnum(@field(item, field.name)),9799 => @intFromEnum(@field(item, field_name)),
98019800
9802 u32,9801 u32,
9803 i32,9802 i32,
...@@ -9811,9 +9810,9 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {...@@ -9811,9 +9810,9 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 {
9811 Tag.TypeStructPacked.Bits,9810 Tag.TypeStructPacked.Bits,
9812 Tag.TypeUnionPacked.Bits,9811 Tag.TypeUnionPacked.Bits,
9813 Tag.TypeEnum.Bits,9812 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)),
9817 }});9816 }});
9818 }9817 }
9819 return result;9818 return result;
...@@ -9826,11 +9825,12 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {...@@ -9826,11 +9825,12 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
9826 else => @compileError("unsupported host"),9825 else => @compileError("unsupported host"),
9827 }9826 }
9828 const result: u32 = @intCast(ip.limbs.items.len);9827 const result: u32 = @intCast(ip.limbs.items.len);
9829 inline for (@typeInfo(@TypeOf(extra)).@"struct".fields, 0..) |field, i| {9828 const info = @typeInfo(@TypeOf(extra)).@"struct";
9830 const new: u32 = switch (field.type) {9829 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| {
9831 u32 => @field(extra, field.name),9830 const new: u32 = switch (field_type) {
9832 Index => @intFromEnum(@field(extra, field.name)),9831 u32 => @field(extra, field_name),
9833 else => @compileError("bad field type: " ++ @typeName(field.type)),9832 Index => @intFromEnum(@field(extra, field_name)),
9833 else => @compileError("bad field type: " ++ @typeName(field_type)),
9834 };9834 };
9835 if (i % 2 == 0) {9835 if (i % 2 == 0) {
9836 ip.limbs.appendAssumeCapacity(new);9836 ip.limbs.appendAssumeCapacity(new);
...@@ -9844,10 +9844,11 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {...@@ -9844,10 +9844,11 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 {
9844fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { data: T, end: u32 } {9844fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { data: T, end: u32 } {
9845 const extra_items = extra.view().items(.@"0");9845 const extra_items = extra.view().items(.@"0");
9846 var result: T = undefined;9846 var result: T = undefined;
9847 const fields = @typeInfo(T).@"struct".fields;9847 const field_names = @typeInfo(T).@"struct".field_names;
9848 inline for (fields, index..) |field, extra_index| {9848 const field_types = @typeInfo(T).@"struct".field_types;
9849 inline for (field_names, field_types, index..) |field_name, field_type, extra_index| {
9849 const extra_item = extra_items[extra_index];9850 const extra_item = extra_items[extra_index];
9850 @field(result, field.name) = switch (field.type) {9851 @field(result, field_name) = switch (field_type) {
9851 Index,9852 Index,
9852 Nav.Index,9853 Nav.Index,
9853 Nav.Index.Optional,9854 Nav.Index.Optional,
...@@ -9878,12 +9879,12 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat...@@ -9878,12 +9879,12 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat
9878 Tag.TypeEnum.Bits,9879 Tag.TypeEnum.Bits,
9879 => @bitCast(extra_item),9880 => @bitCast(extra_item),
98809881
9881 else => @compileError("bad field type: " ++ @typeName(field.type)),9882 else => @compileError("bad field type: " ++ @typeName(field_type)),
9882 };9883 };
9883 }9884 }
9884 return .{9885 return .{
9885 .data = result,9886 .data = result,
9886 .end = @intCast(index + fields.len),9887 .end = @intCast(index + field_names.len),
9887 };9888 };
9888}9889}
98899890
...@@ -10311,7 +10312,7 @@ fn getCoercedFunc(...@@ -10311,7 +10312,7 @@ fn getCoercedFunc(
10311 const extra = local.getMutableExtra(gpa, io);10312 const extra = local.getMutableExtra(gpa, io);
1031210313
10313 const prev_extra_len = extra.mutate.len;10314 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
10316 const extra_index = addExtraAssumeCapacity(extra, Tag.FuncCoerced{10317 const extra_index = addExtraAssumeCapacity(extra, Tag.FuncCoerced{
10317 .ty = ty,10318 .ty = ty,
...@@ -10601,7 +10602,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10601,7 +10602,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10601 },10602 },
1060210603
10603 .type_struct => b: {10604 .type_struct => b: {
10604 var n: usize = @typeInfo(Tag.TypeStruct).@"struct".fields.len;10605 var n: usize = @typeInfo(Tag.TypeStruct).@"struct".field_names.len;
10605 const extra = extraDataTrail(extra_list, Tag.TypeStruct, data);10606 const extra = extraDataTrail(extra_list, Tag.TypeStruct, data);
10606 switch (extra.data.flags.any_captures) {10607 switch (extra.data.flags.any_captures) {
10607 .reified => n += 2, // type_hash: PackedU6410608 .reified => n += 2, // type_hash: PackedU64
...@@ -10629,7 +10630,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10629,7 +10630,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10629 break :b n * @sizeOf(u32);10630 break :b n * @sizeOf(u32);
10630 },10631 },
10631 .type_struct_packed_auto, .type_struct_packed_explicit => b: {10632 .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;
10633 const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data);10634 const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data);
10634 switch (extra.data.bits.captures_len) {10635 switch (extra.data.bits.captures_len) {
10635 .reified => n += 2, // type_hash: PackedU6410636 .reified => n += 2, // type_hash: PackedU64
...@@ -10640,7 +10641,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10640,7 +10641,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10640 break :b n * @sizeOf(u32);10641 break :b n * @sizeOf(u32);
10641 },10642 },
10642 .type_struct_packed_auto_defaults, .type_struct_packed_explicit_defaults => b: {10643 .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;
10644 const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data);10645 const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data);
10645 switch (extra.data.bits.captures_len) {10646 switch (extra.data.bits.captures_len) {
10646 .reified => n += 2, // type_hash: PackedU6410647 .reified => n += 2, // type_hash: PackedU64
...@@ -10652,7 +10653,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10652,7 +10653,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10652 break :b n * @sizeOf(u32);10653 break :b n * @sizeOf(u32);
10653 },10654 },
10654 .type_union => b: {10655 .type_union => b: {
10655 var n: usize = @typeInfo(Tag.TypeUnion).@"struct".fields.len;10656 var n: usize = @typeInfo(Tag.TypeUnion).@"struct".field_names.len;
10656 const extra = extraDataTrail(extra_list, Tag.TypeUnion, data);10657 const extra = extraDataTrail(extra_list, Tag.TypeUnion, data);
10657 switch (extra.data.flags.any_captures) {10658 switch (extra.data.flags.any_captures) {
10658 .reified => n += 2, // type_hash: PackedU6410659 .reified => n += 2, // type_hash: PackedU64
...@@ -10669,7 +10670,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10669,7 +10670,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10669 break :b n * @sizeOf(u32);10670 break :b n * @sizeOf(u32);
10670 },10671 },
10671 .type_union_packed_auto, .type_union_packed_explicit => b: {10672 .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;
10673 const extra = extraDataTrail(extra_list, Tag.TypeUnionPacked, data);10674 const extra = extraDataTrail(extra_list, Tag.TypeUnionPacked, data);
10674 switch (extra.data.bits.captures_len) {10675 switch (extra.data.bits.captures_len) {
10675 .reified => n += 2, // type_hash: PackedU6410676 .reified => n += 2, // type_hash: PackedU64
...@@ -10679,7 +10680,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10679,7 +10680,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10679 break :b n * @sizeOf(u32);10680 break :b n * @sizeOf(u32);
10680 },10681 },
10681 .type_enum_auto => b: {10682 .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;
10683 const extra = extraData(extra_list, Tag.TypeEnum, data);10684 const extra = extraData(extra_list, Tag.TypeEnum, data);
10684 switch (extra.bits.captures_len) {10685 switch (extra.bits.captures_len) {
10685 .generated_union_tag => n += 1, // owner_union: Index10686 .generated_union_tag => n += 1, // owner_union: Index
...@@ -10696,7 +10697,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10696,7 +10697,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10696 break :b n * @sizeOf(u32);10697 break :b n * @sizeOf(u32);
10697 },10698 },
10698 .type_enum_explicit, .type_enum_nonexhaustive => b: {10699 .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;
10700 const extra = extraData(extra_list, Tag.TypeEnum, data);10701 const extra = extraData(extra_list, Tag.TypeEnum, data);
10701 switch (extra.bits.captures_len) {10702 switch (extra.bits.captures_len) {
10702 .generated_union_tag => n += 1, // owner_union: Index10703 .generated_union_tag => n += 1, // owner_union: Index
...@@ -10715,7 +10716,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo...@@ -10715,7 +10716,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo
10715 break :b n * @sizeOf(u32);10716 break :b n * @sizeOf(u32);
10716 },10717 },
10717 .type_opaque => b: {10718 .type_opaque => b: {
10718 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".fields.len;10719 var n: usize = @typeInfo(Tag.TypeEnum).@"struct".field_names.len;
10719 const extra = extraData(extra_list, Tag.TypeOpaque, data);10720 const extra = extraData(extra_list, Tag.TypeOpaque, data);
10720 n += extra.captures_len; // capture: CaptureValue10721 n += extra.captures_len; // capture: CaptureValue
10721 break :b n * @sizeOf(u32);10722 break :b n * @sizeOf(u32);
...@@ -12131,8 +12132,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {...@@ -12131,8 +12132,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {
12131 const func_extra = unwrapped_func.getExtra(ip);12132 const func_extra = unwrapped_func.getExtra(ip);
12132 const func_item = unwrapped_func.getItem(ip);12133 const func_item = unwrapped_func.getItem(ip);
12133 const extra_index = switch (func_item.tag) {12134 const extra_index = switch (func_item.tag) {
12134 .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).@"struct".fields.len,12135 .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).@"struct".field_names.len,
12135 .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).@"struct".fields.len,12136 .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).@"struct".field_names.len,
12136 .func_coerced => {12137 .func_coerced => {
12137 const uncoerced_func_index: Index = @enumFromInt(func_extra.view().items(.@"0")[12138 const uncoerced_func_index: Index = @enumFromInt(func_extra.view().items(.@"0")[
12138 func_item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?12139 func_item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?
...@@ -12141,8 +12142,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {...@@ -12141,8 +12142,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index {
12141 const uncoerced_func_item = unwrapped_uncoerced_func.getItem(ip);12142 const uncoerced_func_item = unwrapped_uncoerced_func.getItem(ip);
12142 return @ptrCast(&unwrapped_uncoerced_func.getExtra(ip).view().items(.@"0")[12143 return @ptrCast(&unwrapped_uncoerced_func.getExtra(ip).view().items(.@"0")[
12143 switch (uncoerced_func_item.tag) {12144 switch (uncoerced_func_item.tag) {
12144 .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).@"struct".fields.len,12145 .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).@"struct".field_names.len,
12145 .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).@"struct".fields.len,12146 .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).@"struct".field_names.len,
12146 else => unreachable,12147 else => unreachable,
12147 }12148 }
12148 ]);12149 ]);
src/Sema.zig+57-57
...@@ -3945,7 +3945,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3945,7 +3945,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3945 _ = try replacement_block.addBr(placeholder_inst, .void_value);3945 _ = try replacement_block.addBr(placeholder_inst, .void_value);
3946 try sema.air_extra.ensureUnusedCapacity(3946 try sema.air_extra.ensureUnusedCapacity(
3947 gpa,3947 gpa,
3948 @typeInfo(Air.Block).@"struct".fields.len + replacement_block.instructions.items.len,3948 @typeInfo(Air.Block).@"struct".field_names.len + replacement_block.instructions.items.len,
3949 );3949 );
3950 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{3950 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{
3951 .tag = .block,3951 .tag = .block,
...@@ -5186,7 +5186,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5186,7 +5186,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
51865186
5187 try child_block.instructions.append(gpa, loop_inst);5187 try child_block.instructions.append(gpa, loop_inst);
51885188
5189 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);
5190 sema.air_instructions.items(.data)[@intFromEnum(loop_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(5190 sema.air_instructions.items(.data)[@intFromEnum(loop_inst)].ty_pl.payload = sema.addExtraAssumeCapacity(
5191 Air.Block{ .body_len = @intCast(loop_block_len + 1) },5191 Air.Block{ .body_len = @intCast(loop_block_len + 1) },
5192 );5192 );
...@@ -5285,7 +5285,7 @@ fn resolveBlockBody(...@@ -5285,7 +5285,7 @@ fn resolveBlockBody(
5285 // We need a runtime block for scoping reasons.5285 // We need a runtime block for scoping reasons.
5286 _ = try child_block.addBr(merges.block_inst, .void_value);5286 _ = try child_block.addBr(merges.block_inst, .void_value);
5287 try parent_block.instructions.append(sema.gpa, merges.block_inst);5287 try parent_block.instructions.append(sema.gpa, merges.block_inst);
5288 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 +
5289 child_block.instructions.items.len);5289 child_block.instructions.items.len);
5290 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{5290 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5291 .ty = .void_type,5291 .ty = .void_type,
...@@ -5361,7 +5361,7 @@ fn resolveAnalyzedBlock(...@@ -5361,7 +5361,7 @@ fn resolveAnalyzedBlock(
5361 .dbg_inline_block => {5361 .dbg_inline_block => {
5362 // Create a block containing all instruction from the body.5362 // Create a block containing all instruction from the body.
5363 try parent_block.instructions.append(gpa, merges.block_inst);5363 try parent_block.instructions.append(gpa, merges.block_inst);
5364 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 +
5365 child_block.instructions.items.len);5365 child_block.instructions.items.len);
5366 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{5366 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5367 .ty = .noreturn_type,5367 .ty = .noreturn_type,
...@@ -5399,7 +5399,7 @@ fn resolveAnalyzedBlock(...@@ -5399,7 +5399,7 @@ fn resolveAnalyzedBlock(
5399 try parent_block.instructions.append(gpa, merges.block_inst);5399 try parent_block.instructions.append(gpa, merges.block_inst);
5400 switch (block_tag) {5400 switch (block_tag) {
5401 .block => {5401 .block => {
5402 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 +
5403 child_block.instructions.items.len);5403 child_block.instructions.items.len);
5404 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{5404 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5405 .ty = .void_type,5405 .ty = .void_type,
...@@ -5409,7 +5409,7 @@ fn resolveAnalyzedBlock(...@@ -5409,7 +5409,7 @@ fn resolveAnalyzedBlock(
5409 } };5409 } };
5410 },5410 },
5411 .dbg_inline_block => {5411 .dbg_inline_block => {
5412 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 +
5413 child_block.instructions.items.len);5413 child_block.instructions.items.len);
5414 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{5414 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5415 .ty = .void_type,5415 .ty = .void_type,
...@@ -5464,7 +5464,7 @@ fn resolveAnalyzedBlock(...@@ -5464,7 +5464,7 @@ fn resolveAnalyzedBlock(
5464 const ty_inst = Air.internedToRef(resolved_ty.toIntern());5464 const ty_inst = Air.internedToRef(resolved_ty.toIntern());
5465 switch (block_tag) {5465 switch (block_tag) {
5466 .block => {5466 .block => {
5467 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 +
5468 child_block.instructions.items.len);5468 child_block.instructions.items.len);
5469 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{5469 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5470 .ty = ty_inst,5470 .ty = ty_inst,
...@@ -5474,7 +5474,7 @@ fn resolveAnalyzedBlock(...@@ -5474,7 +5474,7 @@ fn resolveAnalyzedBlock(
5474 } };5474 } };
5475 },5475 },
5476 .dbg_inline_block => {5476 .dbg_inline_block => {
5477 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 +
5478 child_block.instructions.items.len);5478 child_block.instructions.items.len);
5479 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{5479 sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{
5480 .ty = ty_inst,5480 .ty = ty_inst,
...@@ -5511,7 +5511,7 @@ fn resolveAnalyzedBlock(...@@ -5511,7 +5511,7 @@ fn resolveAnalyzedBlock(
5511 // Convert the br instruction to a block instruction that has the coercion5511 // Convert the br instruction to a block instruction that has the coercion
5512 // and then a new br inside that returns the coerced instruction.5512 // and then a new br inside that returns the coerced instruction.
5513 const sub_block_len: u32 = @intCast(coerce_block.instructions.items.len + 1);5513 const sub_block_len: u32 = @intCast(coerce_block.instructions.items.len + 1);
5514 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 +
5515 sub_block_len);5515 sub_block_len);
5516 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);5516 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
5517 const sub_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);5517 const sub_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
...@@ -6072,7 +6072,7 @@ fn popErrorReturnTrace(...@@ -6072,7 +6072,7 @@ fn popErrorReturnTrace(
6072 // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need6072 // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need
6073 // to pop any error trace that may have been propagated from our arguments.6073 // to pop any error trace that may have been propagated from our arguments.
60746074
6075 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);
6076 const cond_block_inst = try block.addInstAsIndex(.{6076 const cond_block_inst = try block.addInstAsIndex(.{
6077 .tag = .block,6077 .tag = .block,
6078 .data = .{6078 .data = .{
...@@ -6100,9 +6100,9 @@ fn popErrorReturnTrace(...@@ -6100,9 +6100,9 @@ fn popErrorReturnTrace(
6100 defer else_block.instructions.deinit(gpa);6100 defer else_block.instructions.deinit(gpa);
6101 _ = try else_block.addBr(cond_block_inst, .void_value);6101 _ = try else_block.addBr(cond_block_inst, .void_value);
61026102
6103 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 +
6104 then_block.instructions.items.len + else_block.instructions.items.len +6104 then_block.instructions.items.len + else_block.instructions.items.len +
6105 @typeInfo(Air.Block).@"struct".fields.len + 1); // +1 for the sole .cond_br instruction in the .block6105 @typeInfo(Air.Block).@"struct".field_names.len + 1); // +1 for the sole .cond_br instruction in the .block
61066106
6107 const cond_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);6107 const cond_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
6108 try sema.air_instructions.append(gpa, .{6108 try sema.air_instructions.append(gpa, .{
...@@ -7019,7 +7019,7 @@ fn analyzeCall(...@@ -7019,7 +7019,7 @@ fn analyzeCall(
7019 => unreachable,7019 => unreachable,
7020 };7020 };
70217021
7022 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);
7023 const call_ref = try block.addInst(.{7023 const call_ref = try block.addInst(.{
7024 .tag = call_tag,7024 .tag = call_tag,
7025 .data = .{ .pl_op = .{7025 .data = .{ .pl_op = .{
...@@ -9969,7 +9969,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -9969,7 +9969,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
9969 }9969 }
9970 }9970 }
99719971
9972 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 +
9973 non_err_block.instructions.items.len + switch_block.instructions.items.len);9973 non_err_block.instructions.items.len + switch_block.instructions.items.len);
9974 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{9974 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
9975 .then_body_len = @intCast(non_err_block.instructions.items.len),9975 .then_body_len = @intCast(non_err_block.instructions.items.len),
...@@ -10325,7 +10325,7 @@ fn analyzeSwitchBlock(...@@ -10325,7 +10325,7 @@ fn analyzeSwitchBlock(
10325 _ = try sema.analyzeBodyRuntimeBreak(&case_block, body);10325 _ = try sema.analyzeBodyRuntimeBreak(&case_block, body);
10326 }10326 }
1032710327
10328 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 +
10329 case_block.instructions.items.len);10329 case_block.instructions.items.len);
10330 const payload_index = sema.addExtraAssumeCapacity(Air.Block{10330 const payload_index = sema.addExtraAssumeCapacity(Air.Block{
10331 .body_len = @intCast(case_block.instructions.items.len),10331 .body_len = @intCast(case_block.instructions.items.len),
...@@ -10416,7 +10416,7 @@ fn analyzeSwitchBlock(...@@ -10416,7 +10416,7 @@ fn analyzeSwitchBlock(
1041610416
10417 // Replace placeholder with a block.10417 // Replace placeholder with a block.
10418 // No `br` is needed as the block is a switch dispatch so necessarily `noreturn`.10418 // No `br` is needed as the block is a switch dispatch so necessarily `noreturn`.
10419 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 +
10420 replacement_block.instructions.items.len);10420 replacement_block.instructions.items.len);
10421 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{10421 sema.air_instructions.set(@intFromEnum(placeholder_inst), .{
10422 .tag = .block,10422 .tag = .block,
...@@ -10519,7 +10519,7 @@ fn finishSwitchBr(...@@ -10519,7 +10519,7 @@ fn finishSwitchBr(
10519 defer branch_hints.bags.deinit(gpa);10519 defer branch_hints.bags.deinit(gpa);
1052010520
10521 var cases_extra: std.ArrayList(u32) = try .initCapacity(gpa, estimated_cases_len *10521 var cases_extra: std.ArrayList(u32) = try .initCapacity(gpa, estimated_cases_len *
10522 @typeInfo(Air.SwitchBr.Case).@"struct".fields.len);10522 @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len);
10523 defer cases_extra.deinit(gpa);10523 defer cases_extra.deinit(gpa);
1052410524
10525 // We will reuse this block for each case.10525 // We will reuse this block for each case.
...@@ -10609,7 +10609,7 @@ fn finishSwitchBr(...@@ -10609,7 +10609,7 @@ fn finishSwitchBr(
10609 };10609 };
10610 branch_hints.appendAssumeCapacity(prong_hint);10610 branch_hints.appendAssumeCapacity(prong_hint);
1061110611
10612 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 +
10613 1 + // `item`, no ranges10613 1 + // `item`, no ranges
10614 case_block.instructions.items.len);10614 case_block.instructions.items.len);
10615 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{10615 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
...@@ -10696,7 +10696,7 @@ fn finishSwitchBr(...@@ -10696,7 +10696,7 @@ fn finishSwitchBr(
10696 );10696 );
10697 try branch_hints.append(gpa, prong_hint);10697 try branch_hints.append(gpa, prong_hint);
1069810698
10699 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 +
10700 1 + // `item`, no ranges10700 1 + // `item`, no ranges
10701 case_block.instructions.items.len);10701 case_block.instructions.items.len);
10702 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{10702 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
...@@ -10752,7 +10752,7 @@ fn finishSwitchBr(...@@ -10752,7 +10752,7 @@ fn finishSwitchBr(
10752 };10752 };
10753 try branch_hints.append(gpa, prong_hint);10753 try branch_hints.append(gpa, prong_hint);
1075410754
10755 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 +
10756 item_refs.len +10756 item_refs.len +
10757 2 * range_refs.len +10757 2 * range_refs.len +
10758 case_block.instructions.items.len);10758 case_block.instructions.items.len);
...@@ -10839,7 +10839,7 @@ fn finishSwitchBr(...@@ -10839,7 +10839,7 @@ fn finishSwitchBr(
10839 };10839 };
10840 try branch_hints.append(gpa, prong_hint);10840 try branch_hints.append(gpa, prong_hint);
1084110841
10842 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 +
10843 1 + // `item`, no ranges10843 1 + // `item`, no ranges
10844 case_block.instructions.items.len);10844 case_block.instructions.items.len);
10845 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{10845 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
...@@ -10899,11 +10899,11 @@ fn finishSwitchBr(...@@ -10899,11 +10899,11 @@ fn finishSwitchBr(
10899 };10899 };
10900 try branch_hints.append(gpa, prong_hint);10900 try branch_hints.append(gpa, prong_hint);
1090110901
10902 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 +
10903 (validated_switch.seen_enum_fields.len + 1 - zir_switch.totalItemsLen()) + // +1 because totalItemsLen includes the _10903 (validated_switch.seen_enum_fields.len + 1 - zir_switch.totalItemsLen()) + // +1 because totalItemsLen includes the _
10904 case_block.instructions.items.len);10904 case_block.instructions.items.len);
10905 const extra_case = cases_extra.addManyAsArrayAssumeCapacity(10905 const extra_case = cases_extra.addManyAsArrayAssumeCapacity(
10906 @typeInfo(Air.SwitchBr.Case).@"struct".fields.len,10906 @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len,
10907 );10907 );
10908 var items_len: u32 = 0;10908 var items_len: u32 = 0;
10909 for (validated_switch.seen_enum_fields, 0..) |seen_field, field_i| {10909 for (validated_switch.seen_enum_fields, 0..) |seen_field, field_i| {
...@@ -10996,7 +10996,7 @@ fn finishSwitchBr(...@@ -10996,7 +10996,7 @@ fn finishSwitchBr(
1099610996
10997 assert(branch_hints.count == cases_len + 1); // +1 for catch-all hint10997 assert(branch_hints.count == cases_len + 1); // +1 for catch-all hint
1099810998
10999 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 +
11000 branch_hints.bags.items.len +11000 branch_hints.bags.items.len +
11001 cases_extra.items.len +11001 cases_extra.items.len +
11002 catch_all_extra.len);11002 catch_all_extra.len);
...@@ -12367,7 +12367,7 @@ fn analyzeSwitchPayloadCapture(...@@ -12367,7 +12367,7 @@ fn analyzeSwitchPayloadCapture(
12367 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);12367 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
12368 _ = try coerce_block.addBr(capture_block_inst, coerced);12368 _ = try coerce_block.addBr(capture_block_inst, coerced);
1236912369
12370 try cases_extra.ensureUnusedCapacity(@typeInfo(Air.SwitchBr.Case).@"struct".fields.len +12370 try cases_extra.ensureUnusedCapacity(@typeInfo(Air.SwitchBr.Case).@"struct".field_names.len +
12371 1 + // `item`, no ranges12371 1 + // `item`, no ranges
12372 coerce_block.instructions.items.len);12372 coerce_block.instructions.items.len);
12373 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{12373 cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{
...@@ -12395,9 +12395,9 @@ fn analyzeSwitchPayloadCapture(...@@ -12395,9 +12395,9 @@ fn analyzeSwitchPayloadCapture(
12395 break :len coerce_block.instructions.items.len;12395 break :len coerce_block.instructions.items.len;
12396 };12396 };
1239712397
12398 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 +
12399 cases_extra.items.len +12399 cases_extra.items.len +
12400 @typeInfo(Air.Block).@"struct".fields.len +12400 @typeInfo(Air.Block).@"struct".field_names.len +
12401 1);12401 1);
1240212402
12403 const switch_br_inst: u32 = @intCast(sema.air_instructions.len);12403 const switch_br_inst: u32 = @intCast(sema.air_instructions.len);
...@@ -15237,7 +15237,7 @@ fn zirAsm(...@@ -15237,7 +15237,7 @@ fn zirAsm(
1523715237
15238 var extra_i = extra.end;15238 var extra_i = extra.end;
15239 var output_type_bits = extra.data.output_type_bits;15239 var output_type_bits = extra.data.output_type_bits;
15240 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;
1524115241
15242 const ConstraintName = struct { c: []const u8, n: []const u8 };15242 const ConstraintName = struct { c: []const u8, n: []const u8 };
15243 const out_args = try sema.arena.alloc(Air.Inst.Ref, outputs_len);15243 const out_args = try sema.arena.alloc(Air.Inst.Ref, outputs_len);
...@@ -17368,9 +17368,9 @@ fn finishCondBr(...@@ -17368,9 +17368,9 @@ fn finishCondBr(
17368) !Air.Inst.Ref {17368) !Air.Inst.Ref {
17369 const gpa = sema.gpa;17369 const gpa = sema.gpa;
1737017370
17371 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 +
17372 then_block.instructions.items.len + else_block.instructions.items.len +17372 then_block.instructions.items.len + else_block.instructions.items.len +
17373 @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);
1737417374
17375 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{17375 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
17376 .then_body_len = @intCast(then_block.instructions.items.len),17376 .then_body_len = @intCast(then_block.instructions.items.len),
...@@ -17579,7 +17579,7 @@ fn zirCondbr(...@@ -17579,7 +17579,7 @@ fn zirCondbr(
17579 break :h .unlikely;17579 break :h .unlikely;
17580 } else try sema.analyzeBodyRuntimeBreak(&sub_block, else_body);17580 } else try sema.analyzeBodyRuntimeBreak(&sub_block, else_body);
1758117581
17582 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 +
17583 true_instructions.len + sub_block.instructions.items.len);17583 true_instructions.len + sub_block.instructions.items.len);
17584 _ = try parent_block.addInst(.{17584 _ = try parent_block.addInst(.{
17585 .tag = .cond_br,17585 .tag = .cond_br,
...@@ -17651,7 +17651,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -17651,7 +17651,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
17651 // The only interesting hint here is `.cold`, which can come from e.g. `errdefer @panic`.17651 // The only interesting hint here is `.cold`, which can come from e.g. `errdefer @panic`.
17652 const is_cold = sema.branch_hint == .cold;17652 const is_cold = sema.branch_hint == .cold;
1765317653
17654 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 +
17655 sub_block.instructions.items.len);17655 sub_block.instructions.items.len);
17656 const try_inst = try parent_block.addInst(.{17656 const try_inst = try parent_block.addInst(.{
17657 .tag = if (is_cold) .try_cold else .@"try",17657 .tag = if (is_cold) .try_cold else .@"try",
...@@ -17731,7 +17731,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -17731,7 +17731,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
17731 },17731 },
17732 });17732 });
17733 const res_ty_ref = Air.internedToRef(res_ty.toIntern());17733 const res_ty_ref = Air.internedToRef(res_ty.toIntern());
17734 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 +
17735 sub_block.instructions.items.len);17735 sub_block.instructions.items.len);
17736 const try_inst = try parent_block.addInst(.{17736 const try_inst = try parent_block.addInst(.{
17737 .tag = if (is_cold) .try_ptr_cold else .try_ptr,17737 .tag = if (is_cold) .try_ptr_cold else .try_ptr,
...@@ -17979,9 +17979,9 @@ fn maybePushErrorTrace(...@@ -17979,9 +17979,9 @@ fn maybePushErrorTrace(
17979 try sema.air_instructions.ensureUnusedCapacity(gpa, 4);17979 try sema.air_instructions.ensureUnusedCapacity(gpa, 4);
17980 try sema.air_extra.ensureUnusedCapacity(17980 try sema.air_extra.ensureUnusedCapacity(
17981 gpa,17981 gpa,
17982 @typeInfo(Air.Block).@"struct".fields.len +17982 @typeInfo(Air.Block).@"struct".field_names.len +
17983 1 + // the main block contains only the `cond_br`17983 1 + // the main block contains only the `cond_br`
17984 @typeInfo(Air.CondBr).@"struct".fields.len +17984 @typeInfo(Air.CondBr).@"struct".field_names.len +
17985 1 + // the non-error branch contains only a `br`17985 1 + // the non-error branch contains only a `br`
17986 err_block.instructions.items.len + 1, // the error branch contains the `returnError` call and a `br`17986 err_block.instructions.items.len + 1, // the error branch contains the `returnError` call and a `br`
17987 );17987 );
...@@ -19970,7 +19970,7 @@ fn zirReifyFn(...@@ -19970,7 +19970,7 @@ fn zirReifyFn(
19970 block,19970 block,
19971 param_attrs_src,19971 param_attrs_src,
19972 try param_attrs_arr.elemValue(pt, param_idx),19972 try param_attrs_arr.elemValue(pt, param_idx),
19973 std.lang.Type.Fn.Param.Attributes,19973 std.lang.Type.Fn.ParamAttributes,
19974 );19974 );
19975 try sema.checkParamType(19975 try sema.checkParamType(
19976 block,19976 block,
...@@ -20161,15 +20161,15 @@ fn zirReifyStruct(...@@ -20161,15 +20161,15 @@ fn zirReifyStruct(
20161 const field_name = try sema.sliceToIpString(block, field_names_src, field_name_val, .{ .simple = .struct_field_names });20161 const field_name = try sema.sliceToIpString(block, field_names_src, field_name_val, .{ .simple = .struct_field_names });
2016220162
20163 const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(20163 const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20164 std.lang.Type.StructField.Attributes,20164 std.lang.Type.Struct.FieldAttributes,
20165 "comptime",20165 "comptime",
20166 ).?);20166 ).?);
20167 const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(20167 const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20168 std.lang.Type.StructField.Attributes,20168 std.lang.Type.Struct.FieldAttributes,
20169 "align",20169 "align",
20170 ).?);20170 ).?);
20171 const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(20171 const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20172 std.lang.Type.StructField.Attributes,20172 std.lang.Type.Struct.FieldAttributes,
20173 "default_value_ptr",20173 "default_value_ptr",
20174 ).?);20174 ).?);
2017520175
...@@ -20246,15 +20246,15 @@ fn zirReifyStruct(...@@ -20246,15 +20246,15 @@ fn zirReifyStruct(
20246 wip.field_types.get(ip)[field_idx] = field_ty.toIntern();20246 wip.field_types.get(ip)[field_idx] = field_ty.toIntern();
2024720247
20248 const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(20248 const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20249 std.lang.Type.StructField.Attributes,20249 std.lang.Type.Struct.FieldAttributes,
20250 "comptime",20250 "comptime",
20251 ).?);20251 ).?);
20252 const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(20252 const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20253 std.lang.Type.StructField.Attributes,20253 std.lang.Type.Struct.FieldAttributes,
20254 "align",20254 "align",
20255 ).?);20255 ).?);
20256 const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(20256 const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex(
20257 std.lang.Type.StructField.Attributes,20257 std.lang.Type.Struct.FieldAttributes,
20258 "default_value_ptr",20258 "default_value_ptr",
20259 ).?);20259 ).?);
2026020260
...@@ -20444,7 +20444,7 @@ fn zirReifyUnion(...@@ -20444,7 +20444,7 @@ fn zirReifyUnion(
20444 block,20444 block,
20445 field_attrs_src,20445 field_attrs_src,
20446 try field_attrs_arr.elemValue(pt, field_idx),20446 try field_attrs_arr.elemValue(pt, field_idx),
20447 std.lang.Type.UnionField.Attributes,20447 std.lang.Type.Union.FieldAttributes,
20448 );20448 );
20449 if (field_attrs.@"align") |bytes| {20449 if (field_attrs.@"align") |bytes| {
20450 if (layout == .@"packed") {20450 if (layout == .@"packed") {
...@@ -20493,7 +20493,7 @@ fn zirReifyUnion(...@@ -20493,7 +20493,7 @@ fn zirReifyUnion(
20493 block,20493 block,
20494 .unneeded,20494 .unneeded,
20495 try field_attrs_arr.elemValue(pt, field_idx),20495 try field_attrs_arr.elemValue(pt, field_idx),
20496 std.lang.Type.UnionField.Attributes,20496 std.lang.Type.Union.FieldAttributes,
20497 );20497 );
20498 if (field_attrs.@"align") |bytes| {20498 if (field_attrs.@"align") |bytes| {
20499 // No source location; first loop checked this is valid.20499 // No source location; first loop checked this is valid.
...@@ -25459,9 +25459,9 @@ fn addSafetyCheckExtra(...@@ -25459,9 +25459,9 @@ fn addSafetyCheckExtra(
2545925459
25460 try parent_block.instructions.ensureUnusedCapacity(gpa, 1);25460 try parent_block.instructions.ensureUnusedCapacity(gpa, 1);
2546125461
25462 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 +
25463 1 + // The main block only needs space for the cond_br.25463 1 + // The main block only needs space for the cond_br.
25464 @typeInfo(Air.CondBr).@"struct".fields.len +25464 @typeInfo(Air.CondBr).@"struct".field_names.len +
25465 1 + // The ok branch of the cond_br only needs space for the br.25465 1 + // The ok branch of the cond_br only needs space for the br.
25466 fail_block.instructions.items.len);25466 fail_block.instructions.items.len);
2546725467
...@@ -33269,8 +33269,8 @@ pub fn getTmpAir(sema: Sema) Air {...@@ -33269,8 +33269,8 @@ pub fn getTmpAir(sema: Sema) Air {
33269}33269}
3327033270
33271pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {33271pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
33272 const fields = std.meta.fields(@TypeOf(extra));33272 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
33273 try sema.air_extra.ensureUnusedCapacity(sema.gpa, fields.len);33273 try sema.air_extra.ensureUnusedCapacity(sema.gpa, field_count);
33274 return sema.addExtraAssumeCapacity(extra);33274 return sema.addExtraAssumeCapacity(extra);
33275}33275}
3327633276
...@@ -33280,15 +33280,15 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {...@@ -33280,15 +33280,15 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
33280 return result;33280 return result;
33281}33281}
3328233282
33283fn payloadToExtraItems(data: anytype) [@typeInfo(@TypeOf(data)).@"struct".fields.len]u32 {33283fn payloadToExtraItems(data: anytype) [@typeInfo(@TypeOf(data)).@"struct".field_names.len]u32 {
33284 const fields = @typeInfo(@TypeOf(data)).@"struct".fields;33284 const info = @typeInfo(@TypeOf(data)).@"struct";
33285 var result: [fields.len]u32 = undefined;33285 var result: [info.field_names.len]u32 = undefined;
33286 inline for (&result, fields) |*val, field| {33286 inline for (&result, info.field_names, info.field_types) |*val, field_name, field_type| {
33287 val.* = switch (field.type) {33287 val.* = switch (field_type) {
33288 u32 => @field(data, field.name),33288 u32 => @field(data, field_name),
33289 i32, Air.CondBr.BranchHints, Air.Asm.Flags => @bitCast(@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)),33290 Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(data, field_name)),
33291 else => @compileError("bad field type: " ++ @typeName(field.type)),33291 else => @compileError("bad field type: " ++ @typeName(field_type)),
33292 };33292 };
33293 }33293 }
33294 return result;33294 return result;
src/Value.zig+15-15
...@@ -2288,23 +2288,23 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe...@@ -2288,23 +2288,23 @@ pub fn interpret(val: Value, comptime T: type, pt: Zcu.PerThread) error{ OutOfMe
22882288
2289 .@"struct" => |@"struct"| switch (interpret_mode) {2289 .@"struct" => |@"struct"| switch (interpret_mode) {
2290 .direct => {2290 .direct => {
2291 if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;2291 if (ty.structFieldCount(zcu) != @"struct".field_names.len) return error.TypeMismatch;
2292 var result: T = undefined;2292 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| {
2294 const field_val = try val.fieldValue(pt, field_idx);2294 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);
2296 }2296 }
2297 return result;2297 return result;
2298 },2298 },
2299 .by_name => {2299 .by_name => {
2300 const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;2300 const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch;
2301 var result: T = undefined;2301 var result: T = undefined;
2302 inline for (@"struct".fields) |field| {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);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: {2304 @field(result, field_name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: {
2305 const field_val = try val.fieldValue(pt, field_idx);2305 const field_val = try val.fieldValue(pt, field_idx);
2306 break :f try field_val.interpret(field.type, pt);2306 break :f try field_val.interpret(field_type, pt);
2307 } else (field.defaultValue() orelse return error.TypeMismatch);2307 } else (field_attr.defaultValue(field_type) orelse return error.TypeMismatch);
2308 }2308 }
2309 return result;2309 return result;
2310 },2310 },
...@@ -2385,11 +2385,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory...@@ -2385,11 +2385,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
23852385
2386 .@"struct" => |@"struct"| switch (interpret_mode) {2386 .@"struct" => |@"struct"| switch (interpret_mode) {
2387 .direct => {2387 .direct => {
2388 if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch;2388 if (ty.structFieldCount(zcu) != @"struct".field_names.len) return error.TypeMismatch;
2389 var field_vals: [@"struct".fields.len]InternPool.Index = undefined;2389 var field_vals: [@"struct".field_names.len]InternPool.Index = undefined;
2390 inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| {2390 inline for (&field_vals, @"struct".field_names, 0..) |*field_val, field_name, field_idx| {
2391 const field_ty = ty.fieldType(field_idx, zcu);2391 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();
2393 }2393 }
2394 return pt.aggregateValue(ty, &field_vals);2394 return pt.aggregateValue(ty, &field_vals);
2395 },2395 },
...@@ -2399,11 +2399,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory...@@ -2399,11 +2399,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory
2399 const field_vals = try zcu.gpa.alloc(InternPool.Index, want_fields_len);2399 const field_vals = try zcu.gpa.alloc(InternPool.Index, want_fields_len);
2400 defer zcu.gpa.free(field_vals);2400 defer zcu.gpa.free(field_vals);
2401 @memset(field_vals, .none);2401 @memset(field_vals, .none);
2402 inline for (@"struct".fields) |field| {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);2403 const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field_name, .no_embedded_nulls);
2404 if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| {2404 if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| {
2405 const field_ty = ty.fieldType(field_idx, zcu);2405 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();
2407 }2407 }
2408 }2408 }
2409 for (field_vals, 0..) |*field_val, field_idx| {2409 for (field_vals, 0..) |*field_val, field_idx| {
src/Zcu.zig+6-6
...@@ -48,12 +48,12 @@ const ZonGen = std.zig.ZonGen;...@@ -48,12 +48,12 @@ const ZonGen = std.zig.ZonGen;
48comptime {48comptime {
49 @setEvalBranchQuota(4000);49 @setEvalBranchQuota(4000);
50 for (50 for (
51 @typeInfo(Zir.Inst.Ref).@"enum".fields,51 @typeInfo(Zir.Inst.Ref).@"enum".field_names,
52 @typeInfo(Air.Inst.Ref).@"enum".fields,52 @typeInfo(Air.Inst.Ref).@"enum".field_names,
53 @typeInfo(InternPool.Index).@"enum".fields,53 @typeInfo(InternPool.Index).@"enum".field_names,
54 ) |zir_field, air_field, ip_field| {54 ) |zir_field_name, air_field_name, ip_field_name| {
55 assert(mem.eql(u8, zir_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));56 assert(mem.eql(u8, air_field_name, ip_field_name));
57 }57 }
58}58}
5959
src/Zcu/PerThread.zig+2-2
...@@ -3344,7 +3344,7 @@ fn analyzeFuncBodyInner(...@@ -3344,7 +3344,7 @@ fn analyzeFuncBodyInner(
3344 ip.funcSetHasErrorTrace(io, func_index, fn_ty_info.cc == .auto);3344 ip.funcSetHasErrorTrace(io, func_index, fn_ty_info.cc == .auto);
33453345
3346 // First few indexes of extra are reserved and set at the end.3346 // 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;
3348 try sema.air_extra.ensureTotalCapacity(gpa, reserved_count);3348 try sema.air_extra.ensureTotalCapacity(gpa, reserved_count);
3349 sema.air_extra.items.len += reserved_count;3349 sema.air_extra.items.len += reserved_count;
33503350
...@@ -3477,7 +3477,7 @@ fn analyzeFuncBodyInner(...@@ -3477,7 +3477,7 @@ fn analyzeFuncBodyInner(
3477 }3477 }
34783478
3479 // Copy the block into place and mark that as the main block.3479 // 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 +
3481 inner_block.instructions.items.len);3481 inner_block.instructions.items.len);
3482 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{3482 const main_block_index = sema.addExtraAssumeCapacity(Air.Block{
3483 .body_len = @intCast(inner_block.instructions.items.len),3483 .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 {...@@ -41,7 +41,7 @@ fn zonCast(comptime Result: type, zon_value: anytype, symbols: anytype) Result {
41 .void, .bool, .int, .float, .pointer, .comptime_float, .comptime_int, .@"enum" => return zon_value,41 .void, .bool, .int, .float, .pointer, .comptime_float, .comptime_int, .@"enum" => return zon_value,
42 .@"struct" => |zon_struct| switch (@typeInfo(Result)) {42 .@"struct" => |zon_struct| switch (@typeInfo(Result)) {
43 .pointer => |result_pointer| {43 .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");
45 const elems = comptime blk: {45 const elems = comptime blk: {
46 var temp_elems: [zon_value.len]result_pointer.child = undefined;46 var temp_elems: [zon_value.len]result_pointer.child = undefined;
47 for (&temp_elems, zon_value) |*elem, zon_elem| elem.* = zonCast(result_pointer.child, zon_elem, symbols);47 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 {...@@ -52,16 +52,17 @@ fn zonCast(comptime Result: type, zon_value: anytype, symbols: anytype) Result {
52 .@"struct" => |result_struct| {52 .@"struct" => |result_struct| {
53 comptime var used_zon_fields = 0;53 comptime var used_zon_fields = 0;
54 var result: Result = undefined;54 var result: Result = undefined;
55 inline for (result_struct.fields) |result_field| @field(result, result_field.name) = if (@hasField(ZonValue, result_field.name)) result: {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 used_zon_fields += 1;56 @field(result, result_field_name) = if (@hasField(ZonValue, result_field_name)) result: {
57 break :result zonCast(@FieldType(Result, result_field.name), @field(zon_value, result_field.name), symbols);57 used_zon_fields += 1;
58 } else result_field.defaultValue() orelse @compileError(std.fmt.comptimePrint("missing zon field '{s}': {} <- {any}", .{ result_field.name, Result, zon_value }));58 break :result zonCast(@FieldType(Result, result_field_name), @field(zon_value, result_field_name), symbols);
59 if (used_zon_fields != zon_struct.fields.len) @compileError(std.fmt.comptimePrint("unused zon field: {} <- {any}", .{ Result, zon_value }));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 }));
60 return result;61 return result;
61 },62 },
62 .@"union" => {63 .@"union" => {
63 if (zon_struct.fields.len != 1) @compileError(std.fmt.comptimePrint("{} <- {any}", .{ Result, zon_value }));64 if (zon_struct.field_names.len != 1) @compileError(std.fmt.comptimePrint("{} <- {any}", .{ Result, zon_value }));
64 const field_name = zon_struct.fields[0].name;65 const field_name = zon_struct.field_names[0];
65 return @unionInit(66 return @unionInit(
66 Result,67 Result,
67 field_name,68 field_name,
...@@ -106,12 +107,12 @@ const matchers = matchers: {...@@ -106,12 +107,12 @@ const matchers = matchers: {
106 var mut_matchers: [instructions.len]*const fn (as: *Assemble) error{InvalidSyntax}!?Instruction = undefined;107 var mut_matchers: [instructions.len]*const fn (as: *Assemble) error{InvalidSyntax}!?Instruction = undefined;
107 for (instructions, &mut_matchers) |instruction, *matcher| matcher.* = struct {108 for (instructions, &mut_matchers) |instruction, *matcher| matcher.* = struct {
108 fn match(as: *Assemble) !?Instruction {109 fn match(as: *Assemble) !?Instruction {
109 comptime for (@typeInfo(@TypeOf(instruction)).@"struct".fields) |field| {110 comptime for (@typeInfo(@TypeOf(instruction)).@"struct".field_names) |field_name| {
110 if (std.mem.eql(u8, field.name, "requires")) continue;111 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, "pattern")) continue;
112 if (std.mem.eql(u8, field.name, "symbols")) continue;113 if (std.mem.eql(u8, field_name, "symbols")) continue;
113 if (std.mem.eql(u8, field.name, "encode")) continue;114 if (std.mem.eql(u8, field_name, "encode")) continue;
114 @compileError("unexpected field '" ++ field.name ++ "'");115 @compileError("unexpected field '" ++ field_name ++ "'");
115 };116 };
116 if (@hasField(@TypeOf(instruction), "requires")) _ = zonCast(117 if (@hasField(@TypeOf(instruction), "requires")) _ = zonCast(
117 []const std.Target.aarch64.Feature,118 []const std.Target.aarch64.Feature,
...@@ -119,12 +120,12 @@ const matchers = matchers: {...@@ -119,12 +120,12 @@ const matchers = matchers: {
119 .{},120 .{},
120 );121 );
121 var symbols: Symbols: {122 var symbols: Symbols: {
122 const symbols = @typeInfo(@TypeOf(instruction.symbols)).@"struct".fields;123 const symbol_names = @typeInfo(@TypeOf(instruction.symbols)).@"struct".field_names;
123 var field_names: [symbols.len][]const u8 = undefined;124 var field_names: [symbol_names.len][]const u8 = undefined;
124 var field_types: [symbols.len]type = undefined;125 var field_types: [symbol_names.len]type = undefined;
125 for (symbols, &field_names, &field_types) |symbol, *field_name, *FieldType| {126 for (symbol_names, &field_names, &field_types) |symbol_name, *field_name, *FieldType| {
126 field_name.* = symbol.name;127 field_name.* = symbol_name;
127 FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage();128 FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).Storage();
128 }129 }
129 break :Symbols @Struct(.auto, null, &field_names, &field_types, &@splat(.{}));130 break :Symbols @Struct(.auto, null, &field_names, &field_types, &@splat(.{}));
130 } = undefined;131 } = undefined;
...@@ -158,8 +159,8 @@ const matchers = matchers: {...@@ -158,8 +159,8 @@ const matchers = matchers: {
158 const encode = @field(Instruction, @tagName(instruction.encode[0]));159 const encode = @field(Instruction, @tagName(instruction.encode[0]));
159 const Encode = @TypeOf(encode);160 const Encode = @TypeOf(encode);
160 var args: std.meta.ArgsTuple(Encode) = undefined;161 var args: std.meta.ArgsTuple(Encode) = undefined;
161 inline for (&args, @typeInfo(Encode).@"fn".params, 1..instruction.encode.len) |*arg, param, encode_index|162 inline for (&args, @typeInfo(Encode).@"fn".param_types, 1..instruction.encode.len) |*arg, param_type, encode_index|
162 arg.* = zonCast(param.type.?, instruction.encode[encode_index], symbols);163 arg.* = zonCast(param_type.?, instruction.encode[encode_index], symbols);
163 return @call(.auto, encode, args);164 return @call(.auto, encode, args);
164 } else if (pattern_token[0] == '<') {165 } else if (pattern_token[0] == '<') {
165 const symbol_name = comptime pattern_token[1 .. std.mem.indexOfScalarPos(u8, pattern_token, 1, '|') orelse166 const symbol_name = comptime pattern_token[1 .. std.mem.indexOfScalarPos(u8, pattern_token, 1, '|') orelse
...@@ -369,7 +370,7 @@ const SymbolSpec = union(enum) {...@@ -369,7 +370,7 @@ const SymbolSpec = union(enum) {
369 var buf: [370 var buf: [
370 max_len: {371 max_len: {
371 var max_len = 0;372 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);
373 break :max_len max_len;374 break :max_len max_len;
374 } + 1375 } + 1
375 ]u8 = undefined;376 ]u8 = undefined;
...@@ -466,7 +467,7 @@ const SymbolSpec = union(enum) {...@@ -466,7 +467,7 @@ const SymbolSpec = union(enum) {
466 var buf: [467 var buf: [
467 max_len: {468 max_len: {
468 var max_len = 0;469 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);
470 break :max_len max_len;471 break :max_len max_len;
471 } + 1472 } + 1
472 ]u8 = undefined;473 ]u8 = undefined;
...@@ -487,7 +488,7 @@ const SymbolSpec = union(enum) {...@@ -487,7 +488,7 @@ const SymbolSpec = union(enum) {
487 var buf: [488 var buf: [
488 max_len: {489 max_len: {
489 var max_len = 0;490 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);
491 break :max_len max_len;492 break :max_len max_len;
492 } + 1493 } + 1
493 ]u8 = undefined;494 ]u8 = undefined;
...@@ -508,7 +509,7 @@ const SymbolSpec = union(enum) {...@@ -508,7 +509,7 @@ const SymbolSpec = union(enum) {
508 var buf: [509 var buf: [
509 max_len: {510 max_len: {
510 var max_len = 0;511 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);
512 break :max_len max_len;513 break :max_len max_len;
513 } + 1514 } + 1
514 ]u8 = undefined;515 ]u8 = undefined;
src/codegen/aarch64/Select.zig+5-17
...@@ -8891,14 +8891,8 @@ pub const Value = struct {...@@ -8891,14 +8891,8 @@ pub const Value = struct {
88918891
8892 pub const Tag = @typeInfo(Parent).@"union".tag_type.?;8892 pub const Tag = @typeInfo(Parent).@"union".tag_type.?;
8893 pub const Payload = Payload: {8893 pub const Payload = Payload: {
8894 const fields = @typeInfo(Parent).@"union".fields;8894 const info = @typeInfo(Parent).@"union";
8895 var types: [fields.len]type = undefined;8895 break :Payload @Union(.auto, null, info.field_names, info.field_types[0..], &@splat(.{}));
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(.{}));
8902 };8896 };
8903 };8897 };
89048898
...@@ -8916,14 +8910,8 @@ pub const Value = struct {...@@ -8916,14 +8910,8 @@ pub const Value = struct {
89168910
8917 pub const Tag = @typeInfo(Location).@"union".tag_type.?;8911 pub const Tag = @typeInfo(Location).@"union".tag_type.?;
8918 pub const Payload = Payload: {8912 pub const Payload = Payload: {
8919 const fields = @typeInfo(Location).@"union".fields;8913 const info = @typeInfo(Location).@"union";
8920 var types: [fields.len]type = undefined;8914 break :Payload @Union(.auto, null, info.field_names, info.field_types[0..], &@splat(.{}));
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(.{}));
8927 };8915 };
8928 };8916 };
89298917
...@@ -11257,7 +11245,7 @@ fn dumpValuesInner(isel: *Select, which: WhichValues) !void {...@@ -11257,7 +11245,7 @@ fn dumpValuesInner(isel: *Select, which: WhichValues) !void {
11257 var reverse_live_registers: std.AutoHashMapUnmanaged(Value.Index, Register.Alias) = .empty;11245 var reverse_live_registers: std.AutoHashMapUnmanaged(Value.Index, Register.Alias) = .empty;
11258 defer reverse_live_registers.deinit(gpa);11246 defer reverse_live_registers.deinit(gpa);
11259 {11247 {
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);
11261 var live_reg_it = isel.live_registers.iterator();11249 var live_reg_it = isel.live_registers.iterator();
11262 while (live_reg_it.next()) |live_reg_entry| switch (live_reg_entry.value.*) {11250 while (live_reg_it.next()) |live_reg_entry| switch (live_reg_entry.value.*) {
11263 _ => reverse_live_registers.putAssumeCapacityNoClobber(live_reg_entry.value.*, live_reg_entry.key),11251 _ => 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 {...@@ -1271,9 +1271,9 @@ pub const Register = struct {
1271 if (symbol_it.next() != null) break :encoded;1271 if (symbol_it.next() != null) break :encoded;
1272 return .{ .op0 = op0, .op1 = op1, .CRn = CRn, .CRm = CRm, .op2 = op2 };1272 return .{ .op0 = op0, .op1 = op1, .CRn = CRn, .CRm = CRm, .op2 = op2 };
1273 }1273 }
1274 inline for (@typeInfo(System).@"struct".decls) |decl| {1274 inline for (@typeInfo(System).@"struct".decl_names) |decl_name| {
1275 if (@TypeOf(@field(System, decl.name)) != System) continue;1275 if (@TypeOf(@field(System, decl_name)) != System) continue;
1276 if (toLowerEqlAssertLower(reg, decl.name)) return @field(System, decl.name);1276 if (toLowerEqlAssertLower(reg, decl_name)) return @field(System, decl_name);
1277 }1277 }
1278 return null;1278 return null;
1279 }1279 }
...@@ -16561,30 +16561,30 @@ pub const Instruction = packed union {...@@ -16561,30 +16561,30 @@ pub const Instruction = packed union {
16561 if (info.layout != .@"packed" or @bitSizeOf(Type) != @bitSizeOf(Backing)) {16561 if (info.layout != .@"packed" or @bitSizeOf(Type) != @bitSizeOf(Backing)) {
16562 @compileLog(name ++ " should have u32 abi");16562 @compileLog(name ++ " should have u32 abi");
16563 }16563 }
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);
16565 },16565 },
16566 .@"struct" => |info| {16566 .@"struct" => |info| {
16567 if (info.layout != .@"packed" or info.backing_integer != Backing) {16567 if (info.layout != .@"packed" or info.backing_integer != Backing) {
16568 @compileLog(name ++ " should have u32 abi");16568 @compileLog(name ++ " should have u32 abi");
16569 }16569 }
16570 var bit_offset = 0;16570 var bit_offset = 0;
16571 for (info.fields) |field| {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")) {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) {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 }));16574 @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field_name, bit_offset }));
16575 }16575 }
16576 if (field.default_value_ptr != null) {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 }));16577 @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field_name, bit_offset }));
16578 }16578 }
16579 } else if (std.mem.startsWith(u8, field.name, "decoded")) {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) {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 }));16581 @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field_name, bit_offset }));
16582 }16582 }
16583 if (field.default_value_ptr == null) {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 }));16584 @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field_name, bit_offset }));
16585 }16585 }
16586 }16586 }
16587 bit_offset += @bitSizeOf(field.type);16587 bit_offset += @bitSizeOf(field_type);
16588 }16588 }
16589 },16589 },
16590 else => @compileError(name ++ " has an unexpected field type"),16590 else => @compileError(name ++ " has an unexpected field type"),
src/codegen/riscv64/bits.zig+2-2
...@@ -190,7 +190,7 @@ pub const Register = enum(u8) {...@@ -190,7 +190,7 @@ pub const Register = enum(u8) {
190 /// The goal of this function is to return the same ID for `zero` and `x0` but two190 /// The goal of this function is to return the same ID for `zero` and `x0` but two
191 /// seperate IDs for `x0` and `f0`. We will assume that each register set has 32 registers191 /// seperate IDs for `x0` and `f0`. We will assume that each register set has 32 registers
192 /// and is repeated twice, once for the named version, once for the number version.192 /// 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) {
194 const base = switch (@intFromEnum(reg)) {194 const base = switch (@intFromEnum(reg)) {
195 // zig fmt: off195 // zig fmt: off
196 @intFromEnum(Register.zero) ... @intFromEnum(Register.x31) => @intFromEnum(Register.zero),196 @intFromEnum(Register.zero) ... @intFromEnum(Register.x31) => @intFromEnum(Register.zero),
...@@ -251,7 +251,7 @@ pub const FrameIndex = enum(u32) {...@@ -251,7 +251,7 @@ pub const FrameIndex = enum(u32) {
251 /// Other indices are used for local variable stack slots251 /// Other indices are used for local variable stack slots
252 _,252 _,
253253
254 pub const named_count = @typeInfo(FrameIndex).@"enum".fields.len;254 pub const named_count = @typeInfo(FrameIndex).@"enum".field_names.len;
255255
256 pub fn isNamed(fi: FrameIndex) bool {256 pub fn isNamed(fi: FrameIndex) bool {
257 return @intFromEnum(fi) < named_count;257 return @intFromEnum(fi) < named_count;
src/codegen/riscv64/encoding.zig+2-2
...@@ -498,8 +498,8 @@ pub const Instruction = union(Lir.Format) {...@@ -498,8 +498,8 @@ pub const Instruction = union(Lir.Format) {
498 extra: u32,498 extra: u32,
499499
500 comptime {500 comptime {
501 for (std.meta.fields(Instruction)) |field| {501 for (std.meta.fieldTypes(Instruction)) |field_type| {
502 assert(@bitSizeOf(field.type) == 32);502 assert(@bitSizeOf(field_type) == 32);
503 }503 }
504 }504 }
505505
src/codegen/sparc64/Mir.zig+3-3
...@@ -410,11 +410,11 @@ pub fn emit(...@@ -410,11 +410,11 @@ pub fn emit(
410/// Returns the requested data, as well as the new index which is at the start of the410/// Returns the requested data, as well as the new index which is at the start of the
411/// trailers for the object.411/// trailers for the object.
412pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end: usize } {412pub 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";
414 var i: usize = index;414 var i: usize = index;
415 var result: T = undefined;415 var result: T = undefined;
416 inline for (fields) |field| {416 inline for (info.field_names, info.field_types) |field_name, field_type| {
417 @field(result, field.name) = switch (field.type) {417 @field(result, field_name) = switch (field_type) {
418 u32 => mir.extra[i],418 u32 => mir.extra[i],
419 i32 => @as(i32, @bitCast(mir.extra[i])),419 i32 => @as(i32, @bitCast(mir.extra[i])),
420 else => @compileError("bad field type"),420 else => @compileError("bad field type"),
src/codegen/spirv/Section.zig+20-19
...@@ -102,13 +102,13 @@ pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {...@@ -102,13 +102,13 @@ pub fn writeDoubleWord(section: *Section, dword: DoubleWord) void {
102}102}
103103
104fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void {104fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void {
105 const fields = switch (@typeInfo(Operands)) {105 const info = switch (@typeInfo(Operands)) {
106 .@"struct" => |info| info.fields,106 .@"struct" => |info| info,
107 .void => return,107 .void => return,
108 else => unreachable,108 else => unreachable,
109 };109 };
110 inline for (fields) |field| {110 inline for (info.field_names, info.field_types) |field_name, field_type| {
111 section.writeOperand(field.type, @field(operands, field.name));111 section.writeOperand(field_type, @field(operands, field_name));
112 }112 }
113}113}
114114
...@@ -171,12 +171,13 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe...@@ -171,12 +171,13 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe
171171
172fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {172fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void {
173 var mask: Word = 0;173 var mask: Word = 0;
174 inline for (@typeInfo(Operand).@"struct".fields, 0..) |field, bit| {174 const info = @typeInfo(Operand).@"struct";
175 switch (@typeInfo(field.type)) {175 inline for (info.field_names, info.field_types, 0..) |field_name, field_type, bit| {
176 .optional => if (@field(operand, field.name) != null) {176 switch (@typeInfo(field_type)) {
177 .optional => if (@field(operand, field_name) != null) {
177 mask |= 1 << @as(u5, @intCast(bit));178 mask |= 1 << @as(u5, @intCast(bit));
178 },179 },
179 .bool => if (@field(operand, field.name)) {180 .bool => if (@field(operand, field_name)) {
180 mask |= 1 << @as(u5, @intCast(bit));181 mask |= 1 << @as(u5, @intCast(bit));
181 },182 },
182 else => unreachable,183 else => unreachable,
...@@ -185,10 +186,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand...@@ -185,10 +186,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand
185186
186 section.writeWord(mask);187 section.writeWord(mask);
187188
188 inline for (@typeInfo(Operand).@"struct".fields) |field| {189 inline for (info.field_names, info.field_types) |field_name, field_type| {
189 switch (@typeInfo(field.type)) {190 switch (@typeInfo(field_type)) {
190 .optional => |info| if (@field(operand, field.name)) |child| {191 .optional => |opt_info| if (@field(operand, field_name)) |child| {
191 section.writeOperands(info.child, child);192 section.writeOperands(opt_info.child, child);
192 },193 },
193 .bool => {},194 .bool => {},
194 else => unreachable,195 else => unreachable,
...@@ -213,15 +214,15 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us...@@ -213,15 +214,15 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us
213}214}
214215
215fn operandsSize(comptime Operands: type, operands: Operands) usize {216fn operandsSize(comptime Operands: type, operands: Operands) usize {
216 const fields = switch (@typeInfo(Operands)) {217 const info = switch (@typeInfo(Operands)) {
217 .@"struct" => |info| info.fields,218 .@"struct" => |info| info,
218 .void => return 0,219 .void => return 0,
219 else => unreachable,220 else => unreachable,
220 };221 };
221222
222 var total: usize = 0;223 var total: usize = 0;
223 inline for (fields) |field| {224 inline for (info.field_names, info.field_types) |field_name, field_type| {
224 total += operandSize(field.type, @field(operands, field.name));225 total += operandSize(field_type, @field(operands, field_name));
225 }226 }
226227
227 return total;228 return total;
...@@ -252,9 +253,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {...@@ -252,9 +253,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize {
252 if (struct_info.layout == .@"packed") return 1;253 if (struct_info.layout == .@"packed") return 1;
253254
254 var total: usize = 0;255 var total: usize = 0;
255 inline for (@typeInfo(Operand).@"struct".fields) |field| {256 inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| {
256 switch (@typeInfo(field.type)) {257 switch (@typeInfo(field_type)) {
257 .optional => |info| if (@field(operand, field.name)) |child| {258 .optional => |info| if (@field(operand, field_name)) |child| {
258 total += operandsSize(info.child, child);259 total += operandsSize(info.child, child);
259 },260 },
260 .bool => {},261 .bool => {},
src/codegen/wasm/CodeGen.zig+9-9
...@@ -563,24 +563,24 @@ fn addCallIntrinsic(cg: *CodeGen, intrinsic: Mir.Intrinsic) error{OutOfMemory}!v...@@ -563,24 +563,24 @@ fn addCallIntrinsic(cg: *CodeGen, intrinsic: Mir.Intrinsic) error{OutOfMemory}!v
563/// Appends entries to `mir_extra` based on the type of `extra`.563/// Appends entries to `mir_extra` based on the type of `extra`.
564/// Returns the index into `mir_extra`564/// Returns the index into `mir_extra`
565fn addExtra(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {565fn addExtra(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
566 const fields = std.meta.fields(@TypeOf(extra));566 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
567 try cg.mir_extra.ensureUnusedCapacity(cg.gpa, fields.len);567 try cg.mir_extra.ensureUnusedCapacity(cg.gpa, field_count);
568 return cg.addExtraAssumeCapacity(extra);568 return cg.addExtraAssumeCapacity(extra);
569}569}
570570
571/// Appends entries to `mir_extra` based on the type of `extra`.571/// Appends entries to `mir_extra` based on the type of `extra`.
572/// Returns the index into `mir_extra`572/// Returns the index into `mir_extra`
573fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {573fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 {
574 const fields = std.meta.fields(@TypeOf(extra));574 const info = @typeInfo(@TypeOf(extra)).@"struct";
575 const result: u32 = @intCast(cg.mir_extra.items.len);575 const result: u32 = @intCast(cg.mir_extra.items.len);
576 inline for (fields) |field| {576 inline for (info.field_names, info.field_types) |field_name, field_type| {
577 cg.mir_extra.appendAssumeCapacity(switch (field.type) {577 cg.mir_extra.appendAssumeCapacity(switch (field_type) {
578 u32 => @field(extra, field.name),578 u32 => @field(extra, field_name),
579 i32 => @bitCast(@field(extra, field.name)),579 i32 => @bitCast(@field(extra, field_name)),
580 InternPool.Index,580 InternPool.Index,
581 InternPool.Nav.Index,581 InternPool.Nav.Index,
582 => @intFromEnum(@field(extra, field.name)),582 => @intFromEnum(@field(extra, field_name)),
583 else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)),583 else => @compileError("Unsupported field type " ++ @typeName(field_type)),
584 });584 });
585 }585 }
586 return result;586 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...@@ -731,11 +731,11 @@ pub fn lower(mir: *const Mir, wasm: *Wasm, code: *std.ArrayList(u8)) std.mem.All
731}731}
732732
733pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data: T, end: usize } {733pub 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";
735 var i: usize = index;735 var i: usize = index;
736 var result: T = undefined;736 var result: T = undefined;
737 inline for (fields) |field| {737 inline for (info.field_names, info.field_types) |field_name, field_type| {
738 @field(result, field.name) = switch (field.type) {738 @field(result, field_name) = switch (field_type) {
739 u32 => self.extra[i],739 u32 => self.extra[i],
740 i32 => @bitCast(self.extra[i]),740 i32 => @bitCast(self.extra[i]),
741 Wasm.UavsObjIndex,741 Wasm.UavsObjIndex,
...@@ -743,7 +743,7 @@ pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data...@@ -743,7 +743,7 @@ pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data
743 InternPool.Nav.Index,743 InternPool.Nav.Index,
744 InternPool.Index,744 InternPool.Index,
745 => @enumFromInt(self.extra[i]),745 => @enumFromInt(self.extra[i]),
746 else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)),746 else => @compileError("Unsupported field type " ++ @typeName(field_type)),
747 };747 };
748 i += 1;748 i += 1;
749 }749 }
src/codegen/x86_64/CodeGen.zig+12-12
...@@ -1214,20 +1214,20 @@ fn addInst(self: *CodeGen, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {...@@ -1214,20 +1214,20 @@ fn addInst(self: *CodeGen, inst: Mir.Inst) error{OutOfMemory}!Mir.Inst.Index {
1214}1214}
12151215
1216fn addExtra(self: *CodeGen, extra: anytype) Allocator.Error!u32 {1216fn addExtra(self: *CodeGen, extra: anytype) Allocator.Error!u32 {
1217 const fields = std.meta.fields(@TypeOf(extra));1217 const field_count = std.meta.fieldNames(@TypeOf(extra)).len;
1218 try self.mir_extra.ensureUnusedCapacity(self.gpa, fields.len);1218 try self.mir_extra.ensureUnusedCapacity(self.gpa, field_count);
1219 return self.addExtraAssumeCapacity(extra);1219 return self.addExtraAssumeCapacity(extra);
1220}1220}
12211221
1222fn addExtraAssumeCapacity(self: *CodeGen, extra: anytype) u32 {1222fn addExtraAssumeCapacity(self: *CodeGen, extra: anytype) u32 {
1223 const fields = std.meta.fields(@TypeOf(extra));1223 const info = @typeInfo(@TypeOf(extra)).@"struct";
1224 const result: u32 = @intCast(self.mir_extra.items.len);1224 const result: u32 = @intCast(self.mir_extra.items.len);
1225 inline for (fields) |field| {1225 inline for (info.field_names, info.field_types) |field_name, field_type| {
1226 self.mir_extra.appendAssumeCapacity(switch (field.type) {1226 self.mir_extra.appendAssumeCapacity(switch (field_type) {
1227 u32 => @field(extra, field.name),1227 u32 => @field(extra, field_name),
1228 i32, Mir.Memory.Info => @bitCast(@field(extra, field.name)),1228 i32, Mir.Memory.Info => @bitCast(@field(extra, field_name)),
1229 FrameIndex => @intFromEnum(@field(extra, field.name)),1229 FrameIndex => @intFromEnum(@field(extra, field_name)),
1230 else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)),1230 else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
1231 });1231 });
1232 }1232 }
1233 return result;1233 return result;
...@@ -177140,7 +177140,7 @@ fn airBr(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177140,7 +177140,7 @@ fn airBr(self: *CodeGen, inst: Air.Inst.Index) !void {
177140}177140}
177141177141
177142fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {177142fn 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);
177144 const pt = self.pt;177144 const pt = self.pt;
177145 const zcu = pt.zcu;177145 const zcu = pt.zcu;
177146 const unwrapped_asm = self.air.unwrapAsm(inst);177146 const unwrapped_asm = self.air.unwrapAsm(inst);
...@@ -177748,8 +177748,8 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177748,8 +177748,8 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177748 std.mem.reverse(Operand, ops[0..ops_len]);177748 std.mem.reverse(Operand, ops[0..ops_len]);
177749 if (mnem_size.size != .none and !mnem_size.used) {177749 if (mnem_size.size != .none and !mnem_size.used) {
177750 comptime var max_mnem_len: usize = 0;177750 comptime var max_mnem_len: usize = 0;
177751 inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".fields) |mnem|177751 inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".field_names) |mnem_name|
177752 max_mnem_len = @max(mnem.name.len, max_mnem_len);177752 max_mnem_len = @max(mnem_name.len, max_mnem_len);
177753 var intel_mnem_buf: [max_mnem_len + 1]u8 = undefined;177753 var intel_mnem_buf: [max_mnem_len + 1]u8 = undefined;
177754 const intel_mnem_str = std.fmt.bufPrint(&intel_mnem_buf, "{s}{c}", .{177754 const intel_mnem_str = std.fmt.bufPrint(&intel_mnem_buf, "{s}{c}", .{
177755 @tagName(mnem_tag),177755 @tagName(mnem_tag),
src/codegen/x86_64/Encoding.zig+1-1
...@@ -1028,7 +1028,7 @@ const mnemonic_to_encodings_map = init: {...@@ -1028,7 +1028,7 @@ const mnemonic_to_encodings_map = init: {
1028 const Entry = struct { Mnemonic, OpEn, []const Op, []const u8, ModrmExt, Mode, Feature };1028 const Entry = struct { Mnemonic, OpEn, []const Op, []const u8, ModrmExt, Mode, Feature };
1029 const encodings: []const Entry = @import("encodings.zon");1029 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;
1032 var mnemonic_map: [mnemonic_count][]Data = @splat(&.{});1032 var mnemonic_map: [mnemonic_count][]Data = @splat(&.{});
1033 for (encodings) |entry| mnemonic_map[@intFromEnum(entry[0])].len += 1;1033 for (encodings) |entry| mnemonic_map[@intFromEnum(entry[0])].len += 1;
1034 var data_storage: [encodings.len]Data = undefined;1034 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...@@ -425,8 +425,8 @@ fn encode(lower: *Lower, prefix: Prefix, mnemonic: Mnemonic, ops: []const Operan
425 lower.result_insts_len += 1;425 lower.result_insts_len += 1;
426}426}
427427
428const inst_tags_len = @typeInfo(Mir.Inst.Tag).@"enum".fields.len;428const inst_tags_len = @typeInfo(Mir.Inst.Tag).@"enum".field_names.len;
429const inst_fixes_len = @typeInfo(Mir.Inst.Fixes).@"enum".fields.len;429const inst_fixes_len = @typeInfo(Mir.Inst.Fixes).@"enum".field_names.len;
430/// Lookup table, indexed by `@intFromEnum(inst.tag) * inst_fixes_len + @intFromEnum(fixes)`.430/// Lookup table, indexed by `@intFromEnum(inst.tag) * inst_fixes_len + @intFromEnum(fixes)`.
431/// The value is the resulting `Mnemonic`, or `null` if the combination is not valid.431/// The value is the resulting `Mnemonic`, or `null` if the combination is not valid.
432const mnemonic_table: [inst_tags_len * inst_fixes_len]?Mnemonic = table: {432const 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 {...@@ -1732,9 +1732,9 @@ pub const Inst = struct {
1732 assert(@sizeOf(Data) == 8);1732 assert(@sizeOf(Data) == 8);
1733 }1733 }
1734 const Mnemonic = @import("Encoding.zig").Mnemonic;1734 const Mnemonic = @import("Encoding.zig").Mnemonic;
1735 if (@typeInfo(Mnemonic).@"enum".fields.len != 978 or1735 if (@typeInfo(Mnemonic).@"enum".field_names.len != 978 or
1736 @typeInfo(Fixes).@"enum".fields.len != 231 or1736 @typeInfo(Fixes).@"enum".field_names.len != 231 or
1737 @typeInfo(Tag).@"enum".fields.len != 251)1737 @typeInfo(Tag).@"enum".field_names.len != 251)
1738 {1738 {
1739 const cond_src = (struct {1739 const cond_src = (struct {
1740 fn src() std.lang.SourceLocation {1740 fn src() std.lang.SourceLocation {
...@@ -1742,32 +1742,32 @@ pub const Inst = struct {...@@ -1742,32 +1742,32 @@ pub const Inst = struct {
1742 }1742 }
1743 }).src();1743 }).src();
1744 @setEvalBranchQuota(2_000_000);1744 @setEvalBranchQuota(2_000_000);
1745 for (@typeInfo(Mnemonic).@"enum".fields) |mnemonic| {1745 for (@typeInfo(Mnemonic).@"enum".field_names) |mnemonic_name| {
1746 if (mnemonic.name[0] == '.') continue;1746 if (mnemonic_name[0] == '.') continue;
1747 for (@typeInfo(Fixes).@"enum".fields) |fixes| {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..];1748 const pattern = fixes_name[if (std.mem.indexOfScalar(u8, fixes_name, ' ')) |index| index + " ".len else 0..];
1749 const wildcard_index = std.mem.indexOfScalar(u8, pattern, '_').?;1749 const wildcard_index = std.mem.indexOfScalar(u8, pattern, '_').?;
1750 const mnem_prefix = pattern[0..wildcard_index];1750 const mnem_prefix = pattern[0..wildcard_index];
1751 const mnem_suffix = pattern[wildcard_index + "_".len ..];1751 const mnem_suffix = pattern[wildcard_index + "_".len ..];
1752 if (!std.mem.startsWith(u8, mnemonic.name, mnem_prefix)) continue;1752 if (!std.mem.startsWith(u8, mnemonic_name, mnem_prefix)) continue;
1753 if (!std.mem.endsWith(u8, mnemonic.name, mnem_suffix)) continue;1753 if (!std.mem.endsWith(u8, mnemonic_name, mnem_suffix)) continue;
1754 if (@hasField(1754 if (@hasField(
1755 Tag,1755 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],
1757 )) break;1757 )) break;
1758 } else @compileError("'" ++ mnemonic.name ++ "' is not encodable in Mir");1758 } else @compileError("'" ++ mnemonic_name ++ "' is not encodable in Mir");
1759 }1759 }
1760 @compileError(std.fmt.comptimePrint(1760 @compileError(std.fmt.comptimePrint(
1761 \\All mnemonics are encodable in Mir! You may now change the condition at {s}:{d} to:1761 \\All mnemonics are encodable in Mir! You may now change the condition at {s}:{d} to:
1762 \\if (@typeInfo(Mnemonic).@"enum".fields.len != {d} or1762 \\if (@typeInfo(Mnemonic).@"enum".field_names.len != {d} or
1763 \\ @typeInfo(Fixes).@"enum".fields.len != {d} or1763 \\ @typeInfo(Fixes).@"enum".field_names.len != {d} or
1764 \\ @typeInfo(Tag).@"enum".fields.len != {d})1764 \\ @typeInfo(Tag).@"enum".field_names.len != {d})
1765 , .{1765 , .{
1766 cond_src.file,1766 cond_src.file,
1767 cond_src.line - 6,1767 cond_src.line - 6,
1768 @typeInfo(Mnemonic).@"enum".fields.len,1768 @typeInfo(Mnemonic).@"enum".field_names.len,
1769 @typeInfo(Fixes).@"enum".fields.len,1769 @typeInfo(Fixes).@"enum".field_names.len,
1770 @typeInfo(Tag).@"enum".fields.len,1770 @typeInfo(Tag).@"enum".field_names.len,
1771 }));1771 }));
1772 }1772 }
1773 }1773 }
...@@ -2069,15 +2069,15 @@ pub fn emitLazy(...@@ -2069,15 +2069,15 @@ pub fn emitLazy(
2069}2069}
20702070
2071pub fn extraData(mir: Mir, comptime T: type, index: u32) struct { data: T, end: u32 } {2071pub 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";
2073 var i: u32 = index;2073 var i: u32 = index;
2074 var result: T = undefined;2074 var result: T = undefined;
2075 inline for (fields) |field| {2075 inline for (info.field_names, info.field_types) |field_name, field_type| {
2076 @field(result, field.name) = switch (field.type) {2076 @field(result, field_name) = switch (field_type) {
2077 u32 => mir.extra[i],2077 u32 => mir.extra[i],
2078 i32, Memory.Info => @bitCast(mir.extra[i]),2078 i32, Memory.Info => @bitCast(mir.extra[i]),
2079 bits.FrameIndex => @enumFromInt(mir.extra[i]),2079 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)),
2081 };2081 };
2082 i += 1;2082 i += 1;
2083 }2083 }
src/codegen/x86_64/bits.zig+1-1
...@@ -722,7 +722,7 @@ pub const FrameIndex = enum(u32) {...@@ -722,7 +722,7 @@ pub const FrameIndex = enum(u32) {
722 // Other indices are used for local variable stack slots722 // Other indices are used for local variable stack slots
723 _,723 _,
724724
725 pub const named_count = @typeInfo(FrameIndex).@"enum".fields.len;725 pub const named_count = @typeInfo(FrameIndex).@"enum".field_names.len;
726726
727 pub fn isNamed(fi: FrameIndex) bool {727 pub fn isNamed(fi: FrameIndex) bool {
728 return @intFromEnum(fi) < named_count;728 return @intFromEnum(fi) < named_count;
src/codegen/x86_64/encoder.zig+6-6
...@@ -2272,9 +2272,9 @@ const Assembler = struct {...@@ -2272,9 +2272,9 @@ const Assembler = struct {
22722272
2273 fn mnemonicFromString(bytes: []const u8) ?Instruction.Mnemonic {2273 fn mnemonicFromString(bytes: []const u8) ?Instruction.Mnemonic {
2274 const ti = @typeInfo(Instruction.Mnemonic).@"enum";2274 const ti = @typeInfo(Instruction.Mnemonic).@"enum";
2275 inline for (ti.fields) |field| {2275 inline for (ti.field_names) |field_name| {
2276 if (std.mem.eql(u8, bytes, field.name)) {2276 if (std.mem.eql(u8, bytes, field_name)) {
2277 return @field(Instruction.Mnemonic, field.name);2277 return @field(Instruction.Mnemonic, field_name);
2278 }2278 }
2279 }2279 }
2280 return null;2280 return null;
...@@ -2325,9 +2325,9 @@ const Assembler = struct {...@@ -2325,9 +2325,9 @@ const Assembler = struct {
23252325
2326 fn registerFromString(bytes: []const u8) ?Register {2326 fn registerFromString(bytes: []const u8) ?Register {
2327 const ti = @typeInfo(Register).@"enum";2327 const ti = @typeInfo(Register).@"enum";
2328 inline for (ti.fields) |field| {2328 inline for (ti.field_names) |field_name| {
2329 if (std.mem.eql(u8, bytes, field.name)) {2329 if (std.mem.eql(u8, bytes, field_name)) {
2330 return @field(Register, field.name);2330 return @field(Register, field_name);
2331 }2331 }
2332 }2332 }
2333 return null;2333 return null;
src/link.zig+1-1
...@@ -52,7 +52,7 @@ pub const Diags = struct {...@@ -52,7 +52,7 @@ pub const Diags = struct {
52 alloc_failure_occurred: bool = false,52 alloc_failure_occurred: bool = false,
5353
54 const Int = blk: {54 const Int = blk: {
55 const bits = @typeInfo(@This()).@"struct".fields.len;55 const bits = @typeInfo(@This()).@"struct".field_names.len;
56 break :blk @Int(.unsigned, bits);56 break :blk @Int(.unsigned, bits);
57 };57 };
5858
src/link/Coff.zig+5-4
...@@ -248,7 +248,7 @@ pub const Node = union(enum) {...@@ -248,7 +248,7 @@ pub const Node = union(enum) {
248248
249 pub const Tag = @typeInfo(Node).@"union".tag_type.?;249 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;
252 const known = known: {252 const known = known: {
253 const Known = enum {253 const Known = enum {
254 file,254 file,
...@@ -260,8 +260,9 @@ pub const Node = union(enum) {...@@ -260,8 +260,9 @@ pub const Node = union(enum) {
260 section_table,260 section_table,
261 };261 };
262 var mut_known: std.enums.EnumFieldStruct(Known, MappedFile.Node.Index, null) = undefined;262 var mut_known: std.enums.EnumFieldStruct(Known, MappedFile.Node.Index, null) = undefined;
263 for (@typeInfo(Known).@"enum".fields) |field|263 const info = @typeInfo(Known).@"enum";
264 @field(mut_known, field.name) = @enumFromInt(field.value);264 for (info.field_names, info.field_values) |field_name, field_value|
265 @field(mut_known, field_name) = @enumFromInt(field_value);
265 break :known mut_known;266 break :known mut_known;
266 };267 };
267268
...@@ -387,7 +388,7 @@ pub const Symbol = struct {...@@ -387,7 +388,7 @@ pub const Symbol = struct {
387 text,388 text,
388 _,389 _,
389390
390 const known_count = @typeInfo(Index).@"enum".fields.len;391 const known_count = @typeInfo(Index).@"enum".field_names.len;
391392
392 pub fn get(si: Symbol.Index, coff: *Coff) *Symbol {393 pub fn get(si: Symbol.Index, coff: *Coff) *Symbol {
393 return &coff.symbol_table.items[@intFromEnum(si)];394 return &coff.symbol_table.items[@intFromEnum(si)];
src/link/Dwarf.zig+7-7
...@@ -5110,16 +5110,16 @@ pub fn resolveRelocs(dwarf: *Dwarf) RelocError!void {...@@ -5110,16 +5110,16 @@ pub fn resolveRelocs(dwarf: *Dwarf) RelocError!void {
5110}5110}
51115111
5112fn DeclValEnum(comptime T: type) type {5112fn DeclValEnum(comptime T: type) type {
5113 const decls = @typeInfo(T).@"struct".decls;5113 const decl_names = @typeInfo(T).@"struct".decl_names;
5114 @setEvalBranchQuota(10 * decls.len);5114 @setEvalBranchQuota(10 * decl_names.len);
5115 var field_names: [decls.len][]const u8 = undefined;5115 var field_names: [decl_names.len][]const u8 = undefined;
5116 var fields_len = 0;5116 var fields_len = 0;
5117 var min_value: ?comptime_int = null;5117 var min_value: ?comptime_int = null;
5118 var max_value: ?comptime_int = null;5118 var max_value: ?comptime_int = null;
5119 for (decls) |decl| {5119 for (decl_names) |decl_name| {
5120 if (std.mem.startsWith(u8, decl.name, "HP_") or std.mem.endsWith(u8, decl.name, "_user")) continue;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);5121 const value = @field(T, decl_name);
5122 field_names[fields_len] = decl.name;5122 field_names[fields_len] = decl_name;
5123 fields_len += 1;5123 fields_len += 1;
5124 if (min_value == null or min_value.? > value) min_value = value;5124 if (min_value == null or min_value.? > value) min_value = value;
5125 if (max_value == null or max_value.? < value) max_value = value;5125 if (max_value == null or max_value.? < value) max_value = value;
src/link/Elf.zig+7-7
...@@ -1194,7 +1194,7 @@ fn parseDso(...@@ -1194,7 +1194,7 @@ fn parseDso(
1194 // TODO: save this work for later1194 // TODO: save this work for later
1195 const nsyms = parsed.symbols.len;1195 const nsyms = parsed.symbols.len;
1196 try so.symbols.ensureTotalCapacityPrecise(gpa, nsyms);1196 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);
1198 try so.symbols_resolver.ensureTotalCapacityPrecise(gpa, nsyms);1198 try so.symbols_resolver.ensureTotalCapacityPrecise(gpa, nsyms);
1199 so.symbols_resolver.appendNTimesAssumeCapacity(0, nsyms);1199 so.symbols_resolver.appendNTimesAssumeCapacity(0, nsyms);
12001200
...@@ -2354,9 +2354,9 @@ fn sortPhdrs(...@@ -2354,9 +2354,9 @@ fn sortPhdrs(
2354 phdr.* = slice[entry.phndx];2354 phdr.* = slice[entry.phndx];
2355 }2355 }
23562356
2357 inline for (@typeInfo(ProgramHeaderIndexes).@"struct".fields) |field| {2357 inline for (@typeInfo(ProgramHeaderIndexes).@"struct".field_names) |field_name| {
2358 if (@field(special_indexes, field.name).int()) |special_index| {2358 if (@field(special_indexes, field_name).int()) |special_index| {
2359 @field(special_indexes, field.name) = @enumFromInt(backlinks[special_index]);2359 @field(special_indexes, field_name) = @enumFromInt(backlinks[special_index]);
2360 }2360 }
2361 }2361 }
23622362
...@@ -2474,9 +2474,9 @@ pub fn sortShdrs(...@@ -2474,9 +2474,9 @@ pub fn sortShdrs(
2474 }2474 }
2475 }2475 }
24762476
2477 inline for (@typeInfo(SectionIndexes).@"struct".fields) |field| {2477 inline for (@typeInfo(SectionIndexes).@"struct".field_names) |field_name| {
2478 if (@field(section_indexes, field.name)) |special_index| {2478 if (@field(section_indexes, field_name)) |special_index| {
2479 @field(section_indexes, field.name) = backlinks[special_index];2479 @field(section_indexes, field_name) = backlinks[special_index];
2480 }2480 }
2481 }2481 }
24822482
src/link/Elf/Atom.zig+3-3
...@@ -878,9 +878,9 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any...@@ -878,9 +878,9 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any
878pub fn addExtra(atom: *Atom, opts: Extra.AsOptionals, elf_file: *Elf) void {878pub fn addExtra(atom: *Atom, opts: Extra.AsOptionals, elf_file: *Elf) void {
879 const file_ptr = atom.file(elf_file).?;879 const file_ptr = atom.file(elf_file).?;
880 var extras = file_ptr.atomExtra(atom.extra_index);880 var extras = file_ptr.atomExtra(atom.extra_index);
881 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {881 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
882 if (@field(opts, field.name)) |x| {882 if (@field(opts, field_name)) |x| {
883 @field(extras, field.name) = x;883 @field(extras, field_name) = x;
884 }884 }
885 }885 }
886 file_ptr.setAtomExtra(atom.extra_index, extras);886 file_ptr.setAtomExtra(atom.extra_index, extras);
src/link/Elf/LinkerDefined.zig+13-13
...@@ -396,17 +396,17 @@ fn addSymbolAssumeCapacity(self: *LinkerDefined) Symbol.Index {...@@ -396,17 +396,17 @@ fn addSymbolAssumeCapacity(self: *LinkerDefined) Symbol.Index {
396}396}
397397
398pub fn addSymbolExtra(self: *LinkerDefined, allocator: Allocator, extra: Symbol.Extra) !u32 {398pub fn addSymbolExtra(self: *LinkerDefined, allocator: Allocator, extra: Symbol.Extra) !u32 {
399 const fields = @typeInfo(Symbol.Extra).@"struct".fields;399 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
400 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);400 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
401 return self.addSymbolExtraAssumeCapacity(extra);401 return self.addSymbolExtraAssumeCapacity(extra);
402}402}
403403
404pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u32 {404pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u32 {
405 const index = @as(u32, @intCast(self.symbols_extra.items.len));405 const index = @as(u32, @intCast(self.symbols_extra.items.len));
406 const fields = @typeInfo(Symbol.Extra).@"struct".fields;406 const info = @typeInfo(Symbol.Extra).@"struct";
407 inline for (fields) |field| {407 inline for (info.field_names, info.field_types) |field_name, field_type| {
408 self.symbols_extra.appendAssumeCapacity(switch (field.type) {408 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
409 u32 => @field(extra, field.name),409 u32 => @field(extra, field_name),
410 else => @compileError("bad field type"),410 else => @compileError("bad field type"),
411 });411 });
412 }412 }
...@@ -414,11 +414,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u...@@ -414,11 +414,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u
414}414}
415415
416pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra {416pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra {
417 const fields = @typeInfo(Symbol.Extra).@"struct".fields;417 const info = @typeInfo(Symbol.Extra).@"struct";
418 var i: usize = index;418 var i: usize = index;
419 var result: Symbol.Extra = undefined;419 var result: Symbol.Extra = undefined;
420 inline for (fields) |field| {420 inline for (info.field_names, info.field_types) |field_name, field_type| {
421 @field(result, field.name) = switch (field.type) {421 @field(result, field_name) = switch (field_type) {
422 u32 => self.symbols_extra.items[i],422 u32 => self.symbols_extra.items[i],
423 else => @compileError("bad field type"),423 else => @compileError("bad field type"),
424 };424 };
...@@ -428,10 +428,10 @@ pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra {...@@ -428,10 +428,10 @@ pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra {
428}428}
429429
430pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) void {430pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) void {
431 const fields = @typeInfo(Symbol.Extra).@"struct".fields;431 const info = @typeInfo(Symbol.Extra).@"struct";
432 inline for (fields, 0..) |field, i| {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) {433 self.symbols_extra.items[index + i] = switch (field_type) {
434 u32 => @field(extra, field.name),434 u32 => @field(extra, field_name),
435 else => @compileError("bad field type"),435 else => @compileError("bad field type"),
436 };436 };
437 }437 }
src/link/Elf/Object.zig+28-28
...@@ -1298,17 +1298,17 @@ fn addSymbolAssumeCapacity(self: *Object) Symbol.Index {...@@ -1298,17 +1298,17 @@ fn addSymbolAssumeCapacity(self: *Object) Symbol.Index {
1298}1298}
12991299
1300pub fn addSymbolExtra(self: *Object, gpa: Allocator, extra: Symbol.Extra) !u32 {1300pub fn addSymbolExtra(self: *Object, gpa: Allocator, extra: Symbol.Extra) !u32 {
1301 const fields = @typeInfo(Symbol.Extra).@"struct".fields;1301 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
1302 try self.symbols_extra.ensureUnusedCapacity(gpa, fields.len);1302 try self.symbols_extra.ensureUnusedCapacity(gpa, field_count);
1303 return self.addSymbolExtraAssumeCapacity(extra);1303 return self.addSymbolExtraAssumeCapacity(extra);
1304}1304}
13051305
1306pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {1306pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
1307 const index = @as(u32, @intCast(self.symbols_extra.items.len));1307 const index = @as(u32, @intCast(self.symbols_extra.items.len));
1308 const fields = @typeInfo(Symbol.Extra).@"struct".fields;1308 const info = @typeInfo(Symbol.Extra).@"struct";
1309 inline for (fields) |field| {1309 inline for (info.field_names, info.field_types) |field_name, field_type| {
1310 self.symbols_extra.appendAssumeCapacity(switch (field.type) {1310 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
1311 u32 => @field(extra, field.name),1311 u32 => @field(extra, field_name),
1312 else => @compileError("bad field type"),1312 else => @compileError("bad field type"),
1313 });1313 });
1314 }1314 }
...@@ -1316,11 +1316,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {...@@ -1316,11 +1316,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
1316}1316}
13171317
1318pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra {1318pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra {
1319 const fields = @typeInfo(Symbol.Extra).@"struct".fields;1319 const info = @typeInfo(Symbol.Extra).@"struct";
1320 var i: usize = index;1320 var i: usize = index;
1321 var result: Symbol.Extra = undefined;1321 var result: Symbol.Extra = undefined;
1322 inline for (fields) |field| {1322 inline for (info.field_names, info.field_types) |field_name, field_type| {
1323 @field(result, field.name) = switch (field.type) {1323 @field(result, field_name) = switch (field_type) {
1324 u32 => self.symbols_extra.items[i],1324 u32 => self.symbols_extra.items[i],
1325 else => @compileError("bad field type"),1325 else => @compileError("bad field type"),
1326 };1326 };
...@@ -1330,10 +1330,10 @@ pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra {...@@ -1330,10 +1330,10 @@ pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra {
1330}1330}
13311331
1332pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void {1332pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void {
1333 const fields = @typeInfo(Symbol.Extra).@"struct".fields;1333 const info = @typeInfo(Symbol.Extra).@"struct";
1334 inline for (fields, 0..) |field, i| {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) {1335 self.symbols_extra.items[index + i] = switch (field_type) {
1336 u32 => @field(extra, field.name),1336 u32 => @field(extra, field_name),
1337 else => @compileError("bad field type"),1337 else => @compileError("bad field type"),
1338 };1338 };
1339 }1339 }
...@@ -1408,17 +1408,17 @@ pub fn atom(self: *Object, atom_index: Atom.Index) ?*Atom {...@@ -1408,17 +1408,17 @@ pub fn atom(self: *Object, atom_index: Atom.Index) ?*Atom {
1408}1408}
14091409
1410pub fn addAtomExtra(self: *Object, gpa: Allocator, extra: Atom.Extra) !u32 {1410pub fn addAtomExtra(self: *Object, gpa: Allocator, extra: Atom.Extra) !u32 {
1411 const fields = @typeInfo(Atom.Extra).@"struct".fields;1411 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
1412 try self.atoms_extra.ensureUnusedCapacity(gpa, fields.len);1412 try self.atoms_extra.ensureUnusedCapacity(gpa, field_count);
1413 return self.addAtomExtraAssumeCapacity(extra);1413 return self.addAtomExtraAssumeCapacity(extra);
1414}1414}
14151415
1416pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {1416pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
1417 const index: u32 = @intCast(self.atoms_extra.items.len);1417 const index: u32 = @intCast(self.atoms_extra.items.len);
1418 const fields = @typeInfo(Atom.Extra).@"struct".fields;1418 const info = @typeInfo(Atom.Extra).@"struct";
1419 inline for (fields) |field| {1419 inline for (info.field_names, info.field_types) |field_name, field_type| {
1420 self.atoms_extra.appendAssumeCapacity(switch (field.type) {1420 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
1421 u32 => @field(extra, field.name),1421 u32 => @field(extra, field_name),
1422 else => @compileError("bad field type"),1422 else => @compileError("bad field type"),
1423 });1423 });
1424 }1424 }
...@@ -1426,11 +1426,11 @@ pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {...@@ -1426,11 +1426,11 @@ pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
1426}1426}
14271427
1428pub fn atomExtra(self: *Object, index: u32) Atom.Extra {1428pub fn atomExtra(self: *Object, index: u32) Atom.Extra {
1429 const fields = @typeInfo(Atom.Extra).@"struct".fields;1429 const info = @typeInfo(Atom.Extra).@"struct";
1430 var i: usize = index;1430 var i: usize = index;
1431 var result: Atom.Extra = undefined;1431 var result: Atom.Extra = undefined;
1432 inline for (fields) |field| {1432 inline for (info.field_names, info.field_types) |field_name, field_type| {
1433 @field(result, field.name) = switch (field.type) {1433 @field(result, field_name) = switch (field_type) {
1434 u32 => self.atoms_extra.items[i],1434 u32 => self.atoms_extra.items[i],
1435 else => @compileError("bad field type"),1435 else => @compileError("bad field type"),
1436 };1436 };
...@@ -1440,10 +1440,10 @@ pub fn atomExtra(self: *Object, index: u32) Atom.Extra {...@@ -1440,10 +1440,10 @@ pub fn atomExtra(self: *Object, index: u32) Atom.Extra {
1440}1440}
14411441
1442pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {1442pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {
1443 const fields = @typeInfo(Atom.Extra).@"struct".fields;1443 const info = @typeInfo(Atom.Extra).@"struct";
1444 inline for (fields, 0..) |field, i| {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) {1445 self.atoms_extra.items[index + i] = switch (field_type) {
1446 u32 => @field(extra, field.name),1446 u32 => @field(extra, field_name),
1447 else => @compileError("bad field type"),1447 else => @compileError("bad field type"),
1448 };1448 };
1449 }1449 }
...@@ -1452,8 +1452,8 @@ pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {...@@ -1452,8 +1452,8 @@ pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {
1452fn setAtomFields(o: *Object, atom_ptr: *Atom, opts: Atom.Extra.AsOptionals) void {1452fn setAtomFields(o: *Object, atom_ptr: *Atom, opts: Atom.Extra.AsOptionals) void {
1453 assert(o.index == atom_ptr.file_index);1453 assert(o.index == atom_ptr.file_index);
1454 var extras = o.atomExtra(atom_ptr.extra_index);1454 var extras = o.atomExtra(atom_ptr.extra_index);
1455 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {1455 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
1456 if (@field(opts, field.name)) |x| @field(extras, field.name) = x;1456 if (@field(opts, field_name)) |x| @field(extras, field_name) = x;
1457 }1457 }
1458 o.setAtomExtra(atom_ptr.extra_index, extras);1458 o.setAtomExtra(atom_ptr.extra_index, extras);
1459}1459}
src/link/Elf/SharedObject.zig+11-11
...@@ -498,10 +498,10 @@ pub fn addSymbolAssumeCapacity(self: *SharedObject) Symbol.Index {...@@ -498,10 +498,10 @@ pub fn addSymbolAssumeCapacity(self: *SharedObject) Symbol.Index {
498498
499pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u32 {499pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u32 {
500 const index: u32 = @intCast(self.symbols_extra.items.len);500 const index: u32 = @intCast(self.symbols_extra.items.len);
501 const fields = @typeInfo(Symbol.Extra).@"struct".fields;501 const info = @typeInfo(Symbol.Extra).@"struct";
502 inline for (fields) |field| {502 inline for (info.field_names, info.field_types) |field_name, field_type| {
503 self.symbols_extra.appendAssumeCapacity(switch (field.type) {503 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
504 u32 => @field(extra, field.name),504 u32 => @field(extra, field_name),
505 else => @compileError("bad field type"),505 else => @compileError("bad field type"),
506 });506 });
507 }507 }
...@@ -509,11 +509,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u3...@@ -509,11 +509,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u3
509}509}
510510
511pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra {511pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra {
512 const fields = @typeInfo(Symbol.Extra).@"struct".fields;512 const info = @typeInfo(Symbol.Extra).@"struct";
513 var i: usize = index;513 var i: usize = index;
514 var result: Symbol.Extra = undefined;514 var result: Symbol.Extra = undefined;
515 inline for (fields) |field| {515 inline for (info.field_names, info.field_types) |field_name, field_type| {
516 @field(result, field.name) = switch (field.type) {516 @field(result, field_name) = switch (field_type) {
517 u32 => self.symbols_extra.items[i],517 u32 => self.symbols_extra.items[i],
518 else => @compileError("bad field type"),518 else => @compileError("bad field type"),
519 };519 };
...@@ -523,10 +523,10 @@ pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra {...@@ -523,10 +523,10 @@ pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra {
523}523}
524524
525pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void {525pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void {
526 const fields = @typeInfo(Symbol.Extra).@"struct".fields;526 const info = @typeInfo(Symbol.Extra).@"struct";
527 inline for (fields, 0..) |field, i| {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) {528 self.symbols_extra.items[index + i] = switch (field_type) {
529 u32 => @field(extra, field.name),529 u32 => @field(extra, field_name),
530 else => @compileError("bad field type"),530 else => @compileError("bad field type"),
531 };531 };
532 }532 }
src/link/Elf/Symbol.zig+3-3
...@@ -259,9 +259,9 @@ const AddExtraOpts = struct {...@@ -259,9 +259,9 @@ const AddExtraOpts = struct {
259259
260pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) void {260pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) void {
261 var extras = symbol.extra(elf_file);261 var extras = symbol.extra(elf_file);
262 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {262 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
263 if (@field(opts, field.name)) |x| {263 if (@field(opts, field_name)) |x| {
264 @field(extras, field.name) = x;264 @field(extras, field_name) = x;
265 }265 }
266 }266 }
267 symbol.setExtra(extras, elf_file);267 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 {...@@ -2214,17 +2214,17 @@ pub fn atom(self: *ZigObject, atom_index: Atom.Index) ?*Atom {
2214}2214}
22152215
2216fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 {2216fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 {
2217 const fields = @typeInfo(Atom.Extra).@"struct".fields;2217 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
2218 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);2218 try self.atoms_extra.ensureUnusedCapacity(allocator, field_count);
2219 return self.addAtomExtraAssumeCapacity(extra);2219 return self.addAtomExtraAssumeCapacity(extra);
2220}2220}
22212221
2222fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {2222fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
2223 const index = @as(u32, @intCast(self.atoms_extra.items.len));2223 const index = @as(u32, @intCast(self.atoms_extra.items.len));
2224 const fields = @typeInfo(Atom.Extra).@"struct".fields;2224 const info = @typeInfo(Atom.Extra).@"struct";
2225 inline for (fields) |field| {2225 inline for (info.field_names, info.field_types) |field_name, field_type| {
2226 self.atoms_extra.appendAssumeCapacity(switch (field.type) {2226 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
2227 u32 => @field(extra, field.name),2227 u32 => @field(extra, field_name),
2228 else => @compileError("bad field type"),2228 else => @compileError("bad field type"),
2229 });2229 });
2230 }2230 }
...@@ -2232,11 +2232,11 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {...@@ -2232,11 +2232,11 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
2232}2232}
22332233
2234pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra {2234pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra {
2235 const fields = @typeInfo(Atom.Extra).@"struct".fields;2235 const info = @typeInfo(Atom.Extra).@"struct";
2236 var i: usize = index;2236 var i: usize = index;
2237 var result: Atom.Extra = undefined;2237 var result: Atom.Extra = undefined;
2238 inline for (fields) |field| {2238 inline for (info.field_names, info.field_types) |field_name, field_type| {
2239 @field(result, field.name) = switch (field.type) {2239 @field(result, field_name) = switch (field_type) {
2240 u32 => self.atoms_extra.items[i],2240 u32 => self.atoms_extra.items[i],
2241 else => @compileError("bad field type"),2241 else => @compileError("bad field type"),
2242 };2242 };
...@@ -2247,10 +2247,10 @@ pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra {...@@ -2247,10 +2247,10 @@ pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra {
22472247
2248pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void {2248pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void {
2249 assert(index > 0);2249 assert(index > 0);
2250 const fields = @typeInfo(Atom.Extra).@"struct".fields;2250 const info = @typeInfo(Atom.Extra).@"struct";
2251 inline for (fields, 0..) |field, i| {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) {2252 self.atoms_extra.items[index + i] = switch (field_type) {
2253 u32 => @field(extra, field.name),2253 u32 => @field(extra, field_name),
2254 else => @compileError("bad field type"),2254 else => @compileError("bad field type"),
2255 };2255 };
2256 }2256 }
...@@ -2286,17 +2286,17 @@ fn addSymbolAssumeCapacity(self: *ZigObject) Symbol.Index {...@@ -2286,17 +2286,17 @@ fn addSymbolAssumeCapacity(self: *ZigObject) Symbol.Index {
2286}2286}
22872287
2288pub fn addSymbolExtra(self: *ZigObject, allocator: Allocator, extra: Symbol.Extra) !u32 {2288pub fn addSymbolExtra(self: *ZigObject, allocator: Allocator, extra: Symbol.Extra) !u32 {
2289 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2289 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
2290 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);2290 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
2291 return self.addSymbolExtraAssumeCapacity(extra);2291 return self.addSymbolExtraAssumeCapacity(extra);
2292}2292}
22932293
2294pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {2294pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
2295 const index = @as(u32, @intCast(self.symbols_extra.items.len));2295 const index = @as(u32, @intCast(self.symbols_extra.items.len));
2296 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2296 const info = @typeInfo(Symbol.Extra).@"struct";
2297 inline for (fields) |field| {2297 inline for (info.field_names, info.field_types) |field_name, field_type| {
2298 self.symbols_extra.appendAssumeCapacity(switch (field.type) {2298 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
2299 u32 => @field(extra, field.name),2299 u32 => @field(extra, field_name),
2300 else => @compileError("bad field type"),2300 else => @compileError("bad field type"),
2301 });2301 });
2302 }2302 }
...@@ -2304,11 +2304,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {...@@ -2304,11 +2304,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
2304}2304}
23052305
2306pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra {2306pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra {
2307 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2307 const info = @typeInfo(Symbol.Extra).@"struct";
2308 var i: usize = index;2308 var i: usize = index;
2309 var result: Symbol.Extra = undefined;2309 var result: Symbol.Extra = undefined;
2310 inline for (fields) |field| {2310 inline for (info.field_names, info.field_types) |field_name, field_type| {
2311 @field(result, field.name) = switch (field.type) {2311 @field(result, field_name) = switch (field_type) {
2312 u32 => self.symbols_extra.items[i],2312 u32 => self.symbols_extra.items[i],
2313 else => @compileError("bad field type"),2313 else => @compileError("bad field type"),
2314 };2314 };
...@@ -2318,10 +2318,10 @@ pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra {...@@ -2318,10 +2318,10 @@ pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra {
2318}2318}
23192319
2320pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {2320pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
2321 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2321 const info = @typeInfo(Symbol.Extra).@"struct";
2322 inline for (fields, 0..) |field, i| {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) {2323 self.symbols_extra.items[index + i] = switch (field_type) {
2324 u32 => @field(extra, field.name),2324 u32 => @field(extra, field_name),
2325 else => @compileError("bad field type"),2325 else => @compileError("bad field type"),
2326 };2326 };
2327 }2327 }
src/link/Elf2.zig+3-3
...@@ -6330,10 +6330,10 @@ pub fn printNode(...@@ -6330,10 +6330,10 @@ pub fn printNode(
6330 const pt = elf.targetLoad(&ph.type);6330 const pt = elf.targetLoad(&ph.type);
6331 if (std.enums.tagName(std.elf.PT, pt)) |pt_name|6331 if (std.enums.tagName(std.elf.PT, pt)) |pt_name|
6332 try w.writeAll(pt_name)6332 try w.writeAll(pt_name)
6333 else inline for (@typeInfo(std.elf.PT).@"enum".decls) |decl| {6333 else inline for (@typeInfo(std.elf.PT).@"enum".decl_names) |decl_name| {
6334 const decl_val = @field(std.elf.PT, decl.name);6334 const decl_val = @field(std.elf.PT, decl_name);
6335 if (@TypeOf(decl_val) != std.elf.PT) continue;6335 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);
6337 } else try w.print("0x{x}", .{pt});6337 } else try w.print("0x{x}", .{pt});
6338 try w.writeAll(", ");6338 try w.writeAll(", ");
6339 const pf = elf.targetLoad(&ph.flags);6339 const pf = elf.targetLoad(&ph.flags);
src/link/LdScript.zig+4-4
...@@ -97,15 +97,15 @@ const Command = enum {...@@ -97,15 +97,15 @@ const Command = enum {
97 as_needed,97 as_needed,
9898
99 fn fromString(s: []const u8) ?Command {99 fn fromString(s: []const u8) ?Command {
100 inline for (@typeInfo(Command).@"enum".fields) |field| {100 inline for (@typeInfo(Command).@"enum".field_names) |field_name| {
101 const upper_name = n: {101 const upper_name = n: {
102 comptime var buf: [field.name.len]u8 = undefined;102 comptime var buf: [field_name.len]u8 = undefined;
103 inline for (field.name, 0..) |c, i| {103 inline for (field_name, 0..) |c, i| {
104 buf[i] = comptime std.ascii.toUpper(c);104 buf[i] = comptime std.ascii.toUpper(c);
105 }105 }
106 break :n buf;106 break :n buf;
107 };107 };
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);
109 }109 }
110 return null;110 return null;
111 }111 }
src/link/MachO/Atom.zig+3-3
...@@ -129,9 +129,9 @@ const AddExtraOpts = struct {...@@ -129,9 +129,9 @@ const AddExtraOpts = struct {
129pub fn addExtra(atom: *Atom, opts: AddExtraOpts, macho_file: *MachO) void {129pub fn addExtra(atom: *Atom, opts: AddExtraOpts, macho_file: *MachO) void {
130 const file = atom.getFile(macho_file);130 const file = atom.getFile(macho_file);
131 var extra = file.getAtomExtra(atom.extra);131 var extra = file.getAtomExtra(atom.extra);
132 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {132 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
133 if (@field(opts, field.name)) |x| {133 if (@field(opts, field_name)) |x| {
134 @field(extra, field.name) = x;134 @field(extra, field_name) = x;
135 }135 }
136 }136 }
137 file.setAtomExtra(atom.extra, extra);137 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....@@ -627,17 +627,17 @@ pub fn getSymbolRef(self: Dylib, index: Symbol.Index, macho_file: *MachO) MachO.
627}627}
628628
629pub fn addSymbolExtra(self: *Dylib, allocator: Allocator, extra: Symbol.Extra) !u32 {629pub fn addSymbolExtra(self: *Dylib, allocator: Allocator, extra: Symbol.Extra) !u32 {
630 const fields = @typeInfo(Symbol.Extra).@"struct".fields;630 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
631 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);631 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
632 return self.addSymbolExtraAssumeCapacity(extra);632 return self.addSymbolExtraAssumeCapacity(extra);
633}633}
634634
635fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 {635fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 {
636 const index = @as(u32, @intCast(self.symbols_extra.items.len));636 const index = @as(u32, @intCast(self.symbols_extra.items.len));
637 const fields = @typeInfo(Symbol.Extra).@"struct".fields;637 const info = @typeInfo(Symbol.Extra).@"struct";
638 inline for (fields) |field| {638 inline for (info.field_names, info.field_types) |field_name, field_type| {
639 self.symbols_extra.appendAssumeCapacity(switch (field.type) {639 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
640 u32 => @field(extra, field.name),640 u32 => @field(extra, field_name),
641 else => @compileError("bad field type"),641 else => @compileError("bad field type"),
642 });642 });
643 }643 }
...@@ -645,11 +645,11 @@ fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 {...@@ -645,11 +645,11 @@ fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 {
645}645}
646646
647pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra {647pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra {
648 const fields = @typeInfo(Symbol.Extra).@"struct".fields;648 const info = @typeInfo(Symbol.Extra).@"struct";
649 var i: usize = index;649 var i: usize = index;
650 var result: Symbol.Extra = undefined;650 var result: Symbol.Extra = undefined;
651 inline for (fields) |field| {651 inline for (info.field_names, info.field_types) |field_name, field_type| {
652 @field(result, field.name) = switch (field.type) {652 @field(result, field_name) = switch (field_type) {
653 u32 => self.symbols_extra.items[i],653 u32 => self.symbols_extra.items[i],
654 else => @compileError("bad field type"),654 else => @compileError("bad field type"),
655 };655 };
...@@ -659,10 +659,10 @@ pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra {...@@ -659,10 +659,10 @@ pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra {
659}659}
660660
661pub fn setSymbolExtra(self: *Dylib, index: u32, extra: Symbol.Extra) void {661pub fn setSymbolExtra(self: *Dylib, index: u32, extra: Symbol.Extra) void {
662 const fields = @typeInfo(Symbol.Extra).@"struct".fields;662 const info = @typeInfo(Symbol.Extra).@"struct";
663 inline for (fields, 0..) |field, i| {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) {664 self.symbols_extra.items[index + i] = switch (field_type) {
665 u32 => @field(extra, field.name),665 u32 => @field(extra, field_name),
666 else => @compileError("bad field type"),666 else => @compileError("bad field type"),
667 };667 };
668 }668 }
src/link/MachO/InternalObject.zig+26-26
...@@ -708,17 +708,17 @@ pub fn getAtoms(self: InternalObject) []const Atom.Index {...@@ -708,17 +708,17 @@ pub fn getAtoms(self: InternalObject) []const Atom.Index {
708}708}
709709
710fn addAtomExtra(self: *InternalObject, allocator: Allocator, extra: Atom.Extra) !u32 {710fn addAtomExtra(self: *InternalObject, allocator: Allocator, extra: Atom.Extra) !u32 {
711 const fields = @typeInfo(Atom.Extra).@"struct".fields;711 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
712 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);712 try self.atoms_extra.ensureUnusedCapacity(allocator, field_count);
713 return self.addAtomExtraAssumeCapacity(extra);713 return self.addAtomExtraAssumeCapacity(extra);
714}714}
715715
716fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 {716fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 {
717 const index = @as(u32, @intCast(self.atoms_extra.items.len));717 const index = @as(u32, @intCast(self.atoms_extra.items.len));
718 const fields = @typeInfo(Atom.Extra).@"struct".fields;718 const info = @typeInfo(Atom.Extra).@"struct";
719 inline for (fields) |field| {719 inline for (info.field_names, info.field_types) |field_name, field_type| {
720 self.atoms_extra.appendAssumeCapacity(switch (field.type) {720 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
721 u32 => @field(extra, field.name),721 u32 => @field(extra, field_name),
722 else => @compileError("bad field type"),722 else => @compileError("bad field type"),
723 });723 });
724 }724 }
...@@ -726,11 +726,11 @@ fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 {...@@ -726,11 +726,11 @@ fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 {
726}726}
727727
728pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra {728pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra {
729 const fields = @typeInfo(Atom.Extra).@"struct".fields;729 const info = @typeInfo(Atom.Extra).@"struct";
730 var i: usize = index;730 var i: usize = index;
731 var result: Atom.Extra = undefined;731 var result: Atom.Extra = undefined;
732 inline for (fields) |field| {732 inline for (info.field_names, info.field_types) |field_name, field_type| {
733 @field(result, field.name) = switch (field.type) {733 @field(result, field_name) = switch (field_type) {
734 u32 => self.atoms_extra.items[i],734 u32 => self.atoms_extra.items[i],
735 else => @compileError("bad field type"),735 else => @compileError("bad field type"),
736 };736 };
...@@ -741,10 +741,10 @@ pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra {...@@ -741,10 +741,10 @@ pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra {
741741
742pub fn setAtomExtra(self: *InternalObject, index: u32, extra: Atom.Extra) void {742pub fn setAtomExtra(self: *InternalObject, index: u32, extra: Atom.Extra) void {
743 assert(index > 0);743 assert(index > 0);
744 const fields = @typeInfo(Atom.Extra).@"struct".fields;744 const info = @typeInfo(Atom.Extra).@"struct";
745 inline for (fields, 0..) |field, i| {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) {746 self.atoms_extra.items[index + i] = switch (field_type) {
747 u32 => @field(extra, field.name),747 u32 => @field(extra, field_name),
748 else => @compileError("bad field type"),748 else => @compileError("bad field type"),
749 };749 };
750 }750 }
...@@ -789,17 +789,17 @@ pub fn getSymbolRef(self: InternalObject, index: Symbol.Index, macho_file: *Mach...@@ -789,17 +789,17 @@ pub fn getSymbolRef(self: InternalObject, index: Symbol.Index, macho_file: *Mach
789}789}
790790
791pub fn addSymbolExtra(self: *InternalObject, allocator: Allocator, extra: Symbol.Extra) !u32 {791pub fn addSymbolExtra(self: *InternalObject, allocator: Allocator, extra: Symbol.Extra) !u32 {
792 const fields = @typeInfo(Symbol.Extra).@"struct".fields;792 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
793 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);793 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
794 return self.addSymbolExtraAssumeCapacity(extra);794 return self.addSymbolExtraAssumeCapacity(extra);
795}795}
796796
797fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32 {797fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32 {
798 const index = @as(u32, @intCast(self.symbols_extra.items.len));798 const index = @as(u32, @intCast(self.symbols_extra.items.len));
799 const fields = @typeInfo(Symbol.Extra).@"struct".fields;799 const info = @typeInfo(Symbol.Extra).@"struct";
800 inline for (fields) |field| {800 inline for (info.field_names, info.field_types) |field_name, field_type| {
801 self.symbols_extra.appendAssumeCapacity(switch (field.type) {801 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
802 u32 => @field(extra, field.name),802 u32 => @field(extra, field_name),
803 else => @compileError("bad field type"),803 else => @compileError("bad field type"),
804 });804 });
805 }805 }
...@@ -807,11 +807,11 @@ fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32...@@ -807,11 +807,11 @@ fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32
807}807}
808808
809pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra {809pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra {
810 const fields = @typeInfo(Symbol.Extra).@"struct".fields;810 const info = @typeInfo(Symbol.Extra).@"struct";
811 var i: usize = index;811 var i: usize = index;
812 var result: Symbol.Extra = undefined;812 var result: Symbol.Extra = undefined;
813 inline for (fields) |field| {813 inline for (info.field_names, info.field_types) |field_name, field_type| {
814 @field(result, field.name) = switch (field.type) {814 @field(result, field_name) = switch (field_type) {
815 u32 => self.symbols_extra.items[i],815 u32 => self.symbols_extra.items[i],
816 else => @compileError("bad field type"),816 else => @compileError("bad field type"),
817 };817 };
...@@ -821,10 +821,10 @@ pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra {...@@ -821,10 +821,10 @@ pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra {
821}821}
822822
823pub fn setSymbolExtra(self: *InternalObject, index: u32, extra: Symbol.Extra) void {823pub fn setSymbolExtra(self: *InternalObject, index: u32, extra: Symbol.Extra) void {
824 const fields = @typeInfo(Symbol.Extra).@"struct".fields;824 const info = @typeInfo(Symbol.Extra).@"struct";
825 inline for (fields, 0..) |field, i| {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) {826 self.symbols_extra.items[index + i] = switch (field_type) {
827 u32 => @field(extra, field.name),827 u32 => @field(extra, field_name),
828 else => @compileError("bad field type"),828 else => @compileError("bad field type"),
829 };829 };
830 }830 }
src/link/MachO/Object.zig+26-26
...@@ -2478,17 +2478,17 @@ pub fn getAtoms(self: *Object) []const Atom.Index {...@@ -2478,17 +2478,17 @@ pub fn getAtoms(self: *Object) []const Atom.Index {
2478}2478}
24792479
2480fn addAtomExtra(self: *Object, allocator: Allocator, extra: Atom.Extra) !u32 {2480fn addAtomExtra(self: *Object, allocator: Allocator, extra: Atom.Extra) !u32 {
2481 const fields = @typeInfo(Atom.Extra).@"struct".fields;2481 const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len;
2482 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);2482 try self.atoms_extra.ensureUnusedCapacity(allocator, field_count);
2483 return self.addAtomExtraAssumeCapacity(extra);2483 return self.addAtomExtraAssumeCapacity(extra);
2484}2484}
24852485
2486fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {2486fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
2487 const index = @as(u32, @intCast(self.atoms_extra.items.len));2487 const index = @as(u32, @intCast(self.atoms_extra.items.len));
2488 const fields = @typeInfo(Atom.Extra).@"struct".fields;2488 const info = @typeInfo(Atom.Extra).@"struct";
2489 inline for (fields) |field| {2489 inline for (info.field_names, info.field_types) |field_name, field_type| {
2490 self.atoms_extra.appendAssumeCapacity(switch (field.type) {2490 self.atoms_extra.appendAssumeCapacity(switch (field_type) {
2491 u32 => @field(extra, field.name),2491 u32 => @field(extra, field_name),
2492 else => @compileError("bad field type"),2492 else => @compileError("bad field type"),
2493 });2493 });
2494 }2494 }
...@@ -2496,11 +2496,11 @@ fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {...@@ -2496,11 +2496,11 @@ fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 {
2496}2496}
24972497
2498pub fn getAtomExtra(self: Object, index: u32) Atom.Extra {2498pub fn getAtomExtra(self: Object, index: u32) Atom.Extra {
2499 const fields = @typeInfo(Atom.Extra).@"struct".fields;2499 const info = @typeInfo(Atom.Extra).@"struct";
2500 var i: usize = index;2500 var i: usize = index;
2501 var result: Atom.Extra = undefined;2501 var result: Atom.Extra = undefined;
2502 inline for (fields) |field| {2502 inline for (info.field_names, info.field_types) |field_name, field_type| {
2503 @field(result, field.name) = switch (field.type) {2503 @field(result, field_name) = switch (field_type) {
2504 u32 => self.atoms_extra.items[i],2504 u32 => self.atoms_extra.items[i],
2505 else => @compileError("bad field type"),2505 else => @compileError("bad field type"),
2506 };2506 };
...@@ -2511,10 +2511,10 @@ pub fn getAtomExtra(self: Object, index: u32) Atom.Extra {...@@ -2511,10 +2511,10 @@ pub fn getAtomExtra(self: Object, index: u32) Atom.Extra {
25112511
2512pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {2512pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void {
2513 assert(index > 0);2513 assert(index > 0);
2514 const fields = @typeInfo(Atom.Extra).@"struct".fields;2514 const info = @typeInfo(Atom.Extra).@"struct";
2515 inline for (fields, 0..) |field, i| {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) {2516 self.atoms_extra.items[index + i] = switch (field_type) {
2517 u32 => @field(extra, field.name),2517 u32 => @field(extra, field_name),
2518 else => @compileError("bad field type"),2518 else => @compileError("bad field type"),
2519 };2519 };
2520 }2520 }
...@@ -2539,17 +2539,17 @@ pub fn getSymbolRef(self: Object, index: Symbol.Index, macho_file: *MachO) MachO...@@ -2539,17 +2539,17 @@ pub fn getSymbolRef(self: Object, index: Symbol.Index, macho_file: *MachO) MachO
2539}2539}
25402540
2541pub fn addSymbolExtra(self: *Object, allocator: Allocator, extra: Symbol.Extra) !u32 {2541pub fn addSymbolExtra(self: *Object, allocator: Allocator, extra: Symbol.Extra) !u32 {
2542 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2542 const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len;
2543 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);2543 try self.symbols_extra.ensureUnusedCapacity(allocator, field_count);
2544 return self.addSymbolExtraAssumeCapacity(extra);2544 return self.addSymbolExtraAssumeCapacity(extra);
2545}2545}
25462546
2547fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {2547fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
2548 const index = @as(u32, @intCast(self.symbols_extra.items.len));2548 const index = @as(u32, @intCast(self.symbols_extra.items.len));
2549 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2549 const info = @typeInfo(Symbol.Extra).@"struct";
2550 inline for (fields) |field| {2550 inline for (info.field_names, info.field_types) |field_name, field_type| {
2551 self.symbols_extra.appendAssumeCapacity(switch (field.type) {2551 self.symbols_extra.appendAssumeCapacity(switch (field_type) {
2552 u32 => @field(extra, field.name),2552 u32 => @field(extra, field_name),
2553 else => @compileError("bad field type"),2553 else => @compileError("bad field type"),
2554 });2554 });
2555 }2555 }
...@@ -2557,11 +2557,11 @@ fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {...@@ -2557,11 +2557,11 @@ fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 {
2557}2557}
25582558
2559pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra {2559pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra {
2560 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2560 const info = @typeInfo(Symbol.Extra).@"struct";
2561 var i: usize = index;2561 var i: usize = index;
2562 var result: Symbol.Extra = undefined;2562 var result: Symbol.Extra = undefined;
2563 inline for (fields) |field| {2563 inline for (info.field_names, info.field_types) |field_name, field_type| {
2564 @field(result, field.name) = switch (field.type) {2564 @field(result, field_name) = switch (field_type) {
2565 u32 => self.symbols_extra.items[i],2565 u32 => self.symbols_extra.items[i],
2566 else => @compileError("bad field type"),2566 else => @compileError("bad field type"),
2567 };2567 };
...@@ -2571,10 +2571,10 @@ pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra {...@@ -2571,10 +2571,10 @@ pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra {
2571}2571}
25722572
2573pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void {2573pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void {
2574 const fields = @typeInfo(Symbol.Extra).@"struct".fields;2574 const info = @typeInfo(Symbol.Extra).@"struct";
2575 inline for (fields, 0..) |field, i| {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) {2576 self.symbols_extra.items[index + i] = switch (field_type) {
2577 u32 => @field(extra, field.name),2577 u32 => @field(extra, field_name),
2578 else => @compileError("bad field type"),2578 else => @compileError("bad field type"),
2579 };2579 };
2580 }2580 }
src/link/MachO/Symbol.zig+3-3
...@@ -211,9 +211,9 @@ const AddExtraOpts = struct {...@@ -211,9 +211,9 @@ const AddExtraOpts = struct {
211211
212pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, macho_file: *MachO) void {212pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, macho_file: *MachO) void {
213 var extra = symbol.getExtra(macho_file);213 var extra = symbol.getExtra(macho_file);
214 inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| {214 inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| {
215 if (@field(opts, field.name)) |x| {215 if (@field(opts, field_name)) |x| {
216 @field(extra, field.name) = x;216 @field(extra, field_name) = x;
217 }217 }
218 }218 }
219 symbol.setExtra(extra, macho_file);219 symbol.setExtra(extra, macho_file);
src/link/MachO/ZigObject.zig+37-25
...@@ -1570,17 +1570,19 @@ pub fn getAtoms(self: *ZigObject) []const Atom.Index {...@@ -1570,17 +1570,19 @@ pub fn getAtoms(self: *ZigObject) []const Atom.Index {
1570}1570}
15711571
1572fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 {1572fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 {
1573 const fields = @typeInfo(Atom.Extra).@"struct".fields;1573 const field = @typeInfo(Atom.Extra).@"struct".field_names;
1574 try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len);1574 try self.atoms_extra.ensureUnusedCapacity(allocator, field.len);
1575 return self.addAtomExtraAssumeCapacity(extra);1575 return self.addAtomExtraAssumeCapacity(extra);
1576}1576}
15771577
1578fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {1578fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
1579 const index = @as(u32, @intCast(self.atoms_extra.items.len));1579 const index = @as(u32, @intCast(self.atoms_extra.items.len));
1580 const fields = @typeInfo(Atom.Extra).@"struct".fields;1580 const info = @typeInfo(Atom.Extra).@"struct";
1581 inline for (fields) |field| {1581 const field_names = info.field_names;
1582 self.atoms_extra.appendAssumeCapacity(switch (field.type) {1582 const field_types = info.field_types;
1583 u32 => @field(extra, field.name),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),
1584 else => @compileError("bad field type"),1586 else => @compileError("bad field type"),
1585 });1587 });
1586 }1588 }
...@@ -1588,11 +1590,13 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {...@@ -1588,11 +1590,13 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 {
1588}1590}
15891591
1590pub fn getAtomExtra(self: ZigObject, index: u32) Atom.Extra {1592pub 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;
1592 var i: usize = index;1596 var i: usize = index;
1593 var result: Atom.Extra = undefined;1597 var result: Atom.Extra = undefined;
1594 inline for (fields) |field| {1598 inline for (field_names, field_types) |field_name, field_type| {
1595 @field(result, field.name) = switch (field.type) {1599 @field(result, field_name) = switch (field_type) {
1596 u32 => self.atoms_extra.items[i],1600 u32 => self.atoms_extra.items[i],
1597 else => @compileError("bad field type"),1601 else => @compileError("bad field type"),
1598 };1602 };
...@@ -1603,10 +1607,12 @@ pub fn getAtomExtra(self: ZigObject, index: u32) Atom.Extra {...@@ -1603,10 +1607,12 @@ pub fn getAtomExtra(self: ZigObject, index: u32) Atom.Extra {
16031607
1604pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void {1608pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void {
1605 assert(index > 0);1609 assert(index > 0);
1606 const fields = @typeInfo(Atom.Extra).@"struct".fields;1610 const info = @typeInfo(Atom.Extra).@"struct";
1607 inline for (fields, 0..) |field, i| {1611 const field_names = info.field_names;
1608 self.atoms_extra.items[index + i] = switch (field.type) {1612 const field_types = info.field_types;
1609 u32 => @field(extra, field.name),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),
1610 else => @compileError("bad field type"),1616 else => @compileError("bad field type"),
1611 };1617 };
1612 }1618 }
...@@ -1631,17 +1637,19 @@ pub fn getSymbolRef(self: ZigObject, index: Symbol.Index, macho_file: *MachO) Ma...@@ -1631,17 +1637,19 @@ pub fn getSymbolRef(self: ZigObject, index: Symbol.Index, macho_file: *MachO) Ma
1631}1637}
16321638
1633pub fn addSymbolExtra(self: *ZigObject, allocator: Allocator, extra: Symbol.Extra) !u32 {1639pub 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;
1635 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);1641 try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len);
1636 return self.addSymbolExtraAssumeCapacity(extra);1642 return self.addSymbolExtraAssumeCapacity(extra);
1637}1643}
16381644
1639fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {1645fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
1640 const index = @as(u32, @intCast(self.symbols_extra.items.len));1646 const index = @as(u32, @intCast(self.symbols_extra.items.len));
1641 const fields = @typeInfo(Symbol.Extra).@"struct".fields;1647 const info = @typeInfo(Symbol.Extra).@"struct";
1642 inline for (fields) |field| {1648 const field_names = info.field_names;
1643 self.symbols_extra.appendAssumeCapacity(switch (field.type) {1649 const field_types = info.field_types;
1644 u32 => @field(extra, field.name),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),
1645 else => @compileError("bad field type"),1653 else => @compileError("bad field type"),
1646 });1654 });
1647 }1655 }
...@@ -1649,11 +1657,13 @@ fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {...@@ -1649,11 +1657,13 @@ fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 {
1649}1657}
16501658
1651pub fn getSymbolExtra(self: ZigObject, index: u32) Symbol.Extra {1659pub 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;
1653 var i: usize = index;1663 var i: usize = index;
1654 var result: Symbol.Extra = undefined;1664 var result: Symbol.Extra = undefined;
1655 inline for (fields) |field| {1665 inline for (field_names, field_types) |field_name, field_type| {
1656 @field(result, field.name) = switch (field.type) {1666 @field(result, field_name) = switch (field_type) {
1657 u32 => self.symbols_extra.items[i],1667 u32 => self.symbols_extra.items[i],
1658 else => @compileError("bad field type"),1668 else => @compileError("bad field type"),
1659 };1669 };
...@@ -1663,10 +1673,12 @@ pub fn getSymbolExtra(self: ZigObject, index: u32) Symbol.Extra {...@@ -1663,10 +1673,12 @@ pub fn getSymbolExtra(self: ZigObject, index: u32) Symbol.Extra {
1663}1673}
16641674
1665pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {1675pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void {
1666 const fields = @typeInfo(Symbol.Extra).@"struct".fields;1676 const info = @typeInfo(Symbol.Extra).@"struct";
1667 inline for (fields, 0..) |field, i| {1677 const field_names = info.field_names;
1668 self.symbols_extra.items[index + i] = switch (field.type) {1678 const field_types = info.field_types;
1669 u32 => @field(extra, field.name),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),
1670 else => @compileError("bad field type"),1682 else => @compileError("bad field type"),
1671 };1683 };
1672 }1684 }
src/link/Wasm.zig+2-2
...@@ -2992,8 +2992,8 @@ pub fn createEmpty(...@@ -2992,8 +2992,8 @@ pub fn createEmpty(
29922992
2993 if (options.object_host_name) |name| wasm.object_host_name = (try wasm.internString(name)).toOptional();2993 if (options.object_host_name) |name| wasm.object_host_name = (try wasm.internString(name)).toOptional();
29942994
2995 inline for (@typeInfo(PreloadedStrings).@"struct".fields) |field| {2995 inline for (@typeInfo(PreloadedStrings).@"struct".field_names) |field_name| {
2996 @field(wasm.preloaded_strings, field.name) = try wasm.internString(field.name);2996 @field(wasm.preloaded_strings, field_name) = try wasm.internString(field_name);
2997 }2997 }
29982998
2999 wasm.entry_name = switch (options.entry) {2999 wasm.entry_name = switch (options.entry) {
src/link/tapi/yaml.zig+20-20
...@@ -214,8 +214,8 @@ pub const Value = union(enum) {...@@ -214,8 +214,8 @@ pub const Value = union(enum) {
214 var list: std.ArrayList(Value) = try .initCapacity(arena);214 var list: std.ArrayList(Value) = try .initCapacity(arena);
215 defer list.deinit();215 defer list.deinit();
216216
217 inline for (info.fields) |field| {217 inline for (info.field_names) |field_name| {
218 if (try encode(arena, @field(input, field.name))) |value| {218 if (try encode(arena, @field(input, field_name))) |value| {
219 list.appendAssumeCapacity(value);219 list.appendAssumeCapacity(value);
220 }220 }
221 }221 }
...@@ -224,11 +224,11 @@ pub const Value = union(enum) {...@@ -224,11 +224,11 @@ pub const Value = union(enum) {
224 } else {224 } else {
225 var map = Map.init(arena);225 var map = Map.init(arena);
226 errdefer map.deinit();226 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| {229 inline for (info.field_names) |field_name| {
230 if (try encode(arena, @field(input, field.name))) |value| {230 if (try encode(arena, @field(input, field_name))) |value| {
231 const key = try arena.dupe(u8, field.name);231 const key = try arena.dupe(u8, field_name);
232 map.putAssumeCapacityNoClobber(key, value);232 map.putAssumeCapacityNoClobber(key, value);
233 }233 }
234 }234 }
...@@ -237,9 +237,9 @@ pub const Value = union(enum) {...@@ -237,9 +237,9 @@ pub const Value = union(enum) {
237 },237 },
238238
239 .@"union" => |info| if (info.tag_type) |tag_type| {239 .@"union" => |info| if (info.tag_type) |tag_type| {
240 inline for (info.fields) |field| {240 inline for (info.field_names) |field_name| {
241 if (@field(tag_type, field.name) == input) {241 if (@field(tag_type, field_name) == input) {
242 return try encode(arena, @field(input, field.name));242 return try encode(arena, @field(input, field_name));
243 }243 }
244 } else unreachable;244 } else unreachable;
245 } else return error.UntaggedUnion,245 } else return error.UntaggedUnion,
...@@ -396,9 +396,9 @@ pub const Yaml = struct {...@@ -396,9 +396,9 @@ pub const Yaml = struct {
396 const union_info = @typeInfo(T).@"union";396 const union_info = @typeInfo(T).@"union";
397397
398 if (union_info.tag_type) |_| {398 if (union_info.tag_type) |_| {
399 inline for (union_info.fields) |field| {399 inline for (union_info.field_names, union_info.field_types) |field_name, field_type| {
400 if (self.parseValue(field.type, value)) |u_value| {400 if (self.parseValue(field_type, value)) |u_value| {
401 return @unionInit(T, field.name, u_value);401 return @unionInit(T, field_name, u_value);
402 } else |err| {402 } else |err| {
403 if (@as(@TypeOf(err) || error{TypeMismatch}, err) != error.TypeMismatch) return err;403 if (@as(@TypeOf(err) || error{TypeMismatch}, err) != error.TypeMismatch) return err;
404 }404 }
...@@ -418,22 +418,22 @@ pub const Yaml = struct {...@@ -418,22 +418,22 @@ pub const Yaml = struct {
418 const struct_info = @typeInfo(T).@"struct";418 const struct_info = @typeInfo(T).@"struct";
419 var parsed: T = undefined;419 var parsed: T = undefined;
420420
421 inline for (struct_info.fields) |field| {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: {422 const value: ?Value = map.get(field_name) orelse blk: {
423 const field_name = try mem.replaceOwned(u8, self.arena.allocator(), field.name, "_", "-");423 const field_name_ = try mem.replaceOwned(u8, self.arena.allocator(), field_name, "_", "-");
424 break :blk map.get(field_name);424 break :blk map.get(field_name_);
425 };425 };
426426
427 if (@typeInfo(field.type) == .optional) {427 if (@typeInfo(field_type) == .optional) {
428 @field(parsed, field.name) = try self.parseOptional(field.type, value);428 @field(parsed, field_name) = try self.parseOptional(field_type, value);
429 continue;429 continue;
430 }430 }
431431
432 const unwrapped = value orelse {432 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) });
434 return error.StructFieldMissing;434 return error.StructFieldMissing;
435 };435 };
436 @field(parsed, field.name) = try self.parseValue(field.type, unwrapped);436 @field(parsed, field_name) = try self.parseValue(field_type, unwrapped);
437 }437 }
438438
439 return parsed;439 return parsed;
src/print_env.zig+2-2
...@@ -59,8 +59,8 @@ pub fn cmdEnv(...@@ -59,8 +59,8 @@ pub fn cmdEnv(
59 try root.field("version", build_options.version, .{});59 try root.field("version", build_options.version, .{});
60 try root.field("target", triple, .{});60 try root.field("target", triple, .{});
61 var env = try root.beginStructField("env", .{});61 var env = try root.beginStructField("env", .{});
62 inline for (@typeInfo(EnvVar).@"enum".fields) |field| {62 inline for (@typeInfo(EnvVar).@"enum".field_names) |field_name| {
63 try env.field(field.name, @field(EnvVar, field.name).get(environ_map), .{});63 try env.field(field_name, @field(EnvVar, field_name).get(environ_map), .{});
64 }64 }
65 try env.end();65 try env.end();
66 try root.end();66 try root.end();
src/print_zoir.zig+2-2
...@@ -5,8 +5,8 @@ pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: *Writer) Error!void {...@@ -5,8 +5,8 @@ pub fn renderToWriter(zoir: Zoir, arena: Allocator, w: *Writer) Error!void {
55
6 const bytes_per_node = comptime n: {6 const bytes_per_node = comptime n: {
7 var n: usize = 0;7 var n: usize = 0;
8 for (@typeInfo(Zoir.Node.Repr).@"struct".fields) |f| {8 for (@typeInfo(Zoir.Node.Repr).@"struct".field_types) |f_type| {
9 n += @sizeOf(f.type);9 n += @sizeOf(f_type);
10 }10 }
11 break :n n;11 break :n n;
12 };12 };
test/behavior/align.zig+1-1
...@@ -7,7 +7,7 @@ const assert = std.debug.assert;...@@ -7,7 +7,7 @@ const assert = std.debug.assert;
7var foo: u8 align(4) = 100;7var foo: u8 align(4) = 100;
88
9test "global variable alignment" {9test "global variable alignment" {
10 comptime assert(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4);10 comptime assert(@typeInfo(@TypeOf(&foo)).pointer.attrs.@"align" == 4);
11 comptime assert(@TypeOf(&foo) == *align(4) u8);11 comptime assert(@TypeOf(&foo) == *align(4) u8);
12 {12 {
13 const slice = @as(*align(4) [1]u8, &foo)[0..];13 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" {...@@ -1159,7 +1159,7 @@ test "pointer to struct literal with runtime field is constant" {
1159 var runtime_zero: usize = 0;1159 var runtime_zero: usize = 0;
1160 _ = &runtime_zero;1160 _ = &runtime_zero;
1161 const ptr = &S{ .data = runtime_zero };1161 const ptr = &S{ .data = runtime_zero };
1162 try expect(@typeInfo(@TypeOf(ptr)).pointer.is_const);1162 try expect(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"const");
1163}1163}
11641164
1165fn testSignedCmp(comptime T: type) !void {1165fn testSignedCmp(comptime T: type) !void {
...@@ -1284,8 +1284,8 @@ test "comptime variable initialized with addresses of literals" {...@@ -1284,8 +1284,8 @@ test "comptime variable initialized with addresses of literals" {
1284 };1284 };
1285 _ = &st;1285 _ = &st;
12861286
1287 inline for (@typeInfo(@TypeOf(st)).@"struct".fields) |field| {1287 inline for (@typeInfo(@TypeOf(st)).@"struct".field_names) |field_name| {
1288 _ = field;1288 _ = field_name;
1289 }1289 }
1290}1290}
12911291
test/behavior/bitcast.zig+2-2
...@@ -359,8 +359,8 @@ test "comptime @bitCast packed struct to int and back" {...@@ -359,8 +359,8 @@ test "comptime @bitCast packed struct to int and back" {
359 _ = &i;359 _ = &i;
360 const rt_cast = @as(S, @bitCast(i));360 const rt_cast = @as(S, @bitCast(i));
361 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));361 const ct_cast = comptime @as(S, @bitCast(@as(Int, 0)));
362 inline for (@typeInfo(S).@"struct".fields) |field| {362 inline for (@typeInfo(S).@"struct".field_names) |field_name| {
363 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));363 try expectEqual(@field(rt_cast, field_name), @field(ct_cast, field_name));
364 }364 }
365}365}
366366
test/behavior/call.zig+2-2
...@@ -375,7 +375,7 @@ test "Enum constructed by @Enum passed as generic argument" {...@@ -375,7 +375,7 @@ test "Enum constructed by @Enum passed as generic argument" {
375 try expect(@intFromEnum(a) == b);375 try expect(@intFromEnum(a) == b);
376 }376 }
377 };377 };
378 inline for (@typeInfo(S.E).@"enum".fields, 0..) |_, i| {378 inline for (@typeInfo(S.E).@"enum".field_names, 0..) |_, i| {
379 try S.foo(@as(S.E, @enumFromInt(i)), i);379 try S.foo(@as(S.E, @enumFromInt(i)), i);
380 }380 }
381}381}
...@@ -556,7 +556,7 @@ test "value returned from comptime function is comptime known" {...@@ -556,7 +556,7 @@ test "value returned from comptime function is comptime known" {
556 else => unreachable,556 else => unreachable,
557 } {557 } {
558 return switch (@typeInfo(T)) {558 return switch (@typeInfo(T)) {
559 .@"struct" => |info| info.fields.len,559 .@"struct" => |info| info.field_names.len,
560 else => unreachable,560 else => unreachable,
561 };561 };
562 }562 }
test/behavior/cast.zig+35-35
...@@ -1042,9 +1042,9 @@ test "peer type resolution: error set supersets" {...@@ -1042,9 +1042,9 @@ test "peer type resolution: error set supersets" {
1042 const ty = @TypeOf(a, b);1042 const ty = @TypeOf(a, b);
1043 const error_set_info = @typeInfo(ty);1043 const error_set_info = @typeInfo(ty);
1044 try expect(error_set_info == .error_set);1044 try expect(error_set_info == .error_set);
1045 try expect(error_set_info.error_set.?.len == 2);1045 try expect(error_set_info.error_set.error_names.?.len == 2);
1046 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));1047 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1048 }1048 }
10491049
1050 // B superset of A1050 // B superset of A
...@@ -1052,9 +1052,9 @@ test "peer type resolution: error set supersets" {...@@ -1052,9 +1052,9 @@ test "peer type resolution: error set supersets" {
1052 const ty = @TypeOf(b, a);1052 const ty = @TypeOf(b, a);
1053 const error_set_info = @typeInfo(ty);1053 const error_set_info = @typeInfo(ty);
1054 try expect(error_set_info == .error_set);1054 try expect(error_set_info == .error_set);
1055 try expect(error_set_info.error_set.?.len == 2);1055 try expect(error_set_info.error_set.error_names.?.len == 2);
1056 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));1057 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1058 }1058 }
1059}1059}
10601060
...@@ -1070,20 +1070,20 @@ test "peer type resolution: disjoint error sets" {...@@ -1070,20 +1070,20 @@ test "peer type resolution: disjoint error sets" {
1070 const ty = @TypeOf(a, b);1070 const ty = @TypeOf(a, b);
1071 const error_set_info = @typeInfo(ty);1071 const error_set_info = @typeInfo(ty);
1072 try expect(error_set_info == .error_set);1072 try expect(error_set_info == .error_set);
1073 try expect(error_set_info.error_set.?.len == 3);1073 try expect(error_set_info.error_set.error_names.?.len == 3);
1074 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));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.?[2].name, "Three"));1076 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
1077 }1077 }
10781078
1079 {1079 {
1080 const ty = @TypeOf(b, a);1080 const ty = @TypeOf(b, a);
1081 const error_set_info = @typeInfo(ty);1081 const error_set_info = @typeInfo(ty);
1082 try expect(error_set_info == .error_set);1082 try expect(error_set_info == .error_set);
1083 try expect(error_set_info.error_set.?.len == 3);1083 try expect(error_set_info.error_set.error_names.?.len == 3);
1084 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));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.?[2].name, "Three"));1086 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
1087 }1087 }
1088}1088}
10891089
...@@ -1101,10 +1101,10 @@ test "peer type resolution: error union and error set" {...@@ -1101,10 +1101,10 @@ test "peer type resolution: error union and error set" {
1101 try expect(info == .error_union);1101 try expect(info == .error_union);
11021102
1103 const error_set_info = @typeInfo(info.error_union.error_set);1103 const error_set_info = @typeInfo(info.error_union.error_set);
1104 try expect(error_set_info.error_set.?.len == 3);1104 try expect(error_set_info.error_set.error_names.?.len == 3);
1105 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));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.?[2].name, "Three"));1107 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
1108 }1108 }
11091109
1110 {1110 {
...@@ -1113,10 +1113,10 @@ test "peer type resolution: error union and error set" {...@@ -1113,10 +1113,10 @@ test "peer type resolution: error union and error set" {
1113 try expect(info == .error_union);1113 try expect(info == .error_union);
11141114
1115 const error_set_info = @typeInfo(info.error_union.error_set);1115 const error_set_info = @typeInfo(info.error_union.error_set);
1116 try expect(error_set_info.error_set.?.len == 3);1116 try expect(error_set_info.error_set.error_names.?.len == 3);
1117 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));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.?[2].name, "Three"));1119 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
1120 }1120 }
1121}1121}
11221122
...@@ -1135,9 +1135,9 @@ test "peer type resolution: error union after non-error" {...@@ -1135,9 +1135,9 @@ test "peer type resolution: error union after non-error" {
1135 try expect(info.error_union.payload == u32);1135 try expect(info.error_union.payload == u32);
11361136
1137 const error_set_info = @typeInfo(info.error_union.error_set);1137 const error_set_info = @typeInfo(info.error_union.error_set);
1138 try expect(error_set_info.error_set.?.len == 2);1138 try expect(error_set_info.error_set.error_names.?.len == 2);
1139 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));1140 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1141 }1141 }
11421142
1143 {1143 {
...@@ -1147,9 +1147,9 @@ test "peer type resolution: error union after non-error" {...@@ -1147,9 +1147,9 @@ test "peer type resolution: error union after non-error" {
1147 try expect(info.error_union.payload == u32);1147 try expect(info.error_union.payload == u32);
11481148
1149 const error_set_info = @typeInfo(info.error_union.error_set);1149 const error_set_info = @typeInfo(info.error_union.error_set);
1150 try expect(error_set_info.error_set.?.len == 2);1150 try expect(error_set_info.error_set.error_names.?.len == 2);
1151 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));1152 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two"));
1153 }1153 }
1154}1154}
11551155
...@@ -2552,9 +2552,9 @@ test "peer type resolution: tuples with comptime fields" {...@@ -2552,9 +2552,9 @@ test "peer type resolution: tuples with comptime fields" {
2552 inline for (.{ ti1, ti2 }) |ti| {2552 inline for (.{ ti1, ti2 }) |ti| {
2553 const s = ti.@"struct";2553 const s = ti.@"struct";
2554 comptime assert(s.is_tuple);2554 comptime assert(s.is_tuple);
2555 comptime assert(s.fields.len == 2);2555 comptime assert(s.field_names.len == 2);
2556 comptime assert(s.fields[0].type == u32);2556 comptime assert(s.field_types[0] == u32);
2557 comptime assert(s.fields[1].type == i16);2557 comptime assert(s.field_types[1] == i16);
2558 }2558 }
25592559
2560 var t = true;2560 var t = true;
...@@ -2665,11 +2665,11 @@ test "peer type resolution: pointer attributes are combined correctly" {...@@ -2665,11 +2665,11 @@ test "peer type resolution: pointer attributes are combined correctly" {
2665 const NonAllowZero = comptime blk: {2665 const NonAllowZero = comptime blk: {
2666 const ptr = @typeInfo(@TypeOf(r1, r2, r3, r4)).pointer;2666 const ptr = @typeInfo(@TypeOf(r1, r2, r3, r4)).pointer;
2667 break :blk @Pointer(ptr.size, .{2667 break :blk @Pointer(ptr.size, .{
2668 .@"const" = ptr.is_const,2668 .@"const" = ptr.attrs.@"const",
2669 .@"volatile" = ptr.is_volatile,2669 .@"volatile" = ptr.attrs.@"volatile",
2670 .@"allowzero" = false,2670 .@"allowzero" = false,
2671 .@"align" = ptr.alignment,2671 .@"align" = ptr.attrs.@"align",
2672 .@"addrspace" = ptr.address_space,2672 .@"addrspace" = ptr.attrs.@"addrspace",
2673 }, ptr.child, ptr.sentinel());2673 }, ptr.child, ptr.sentinel());
2674 };2674 };
2675 try expectEqualSlices(u8, std.mem.span(@volatileCast(@as(NonAllowZero, @ptrCast(r1)))), "foo");2675 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 {...@@ -118,8 +118,8 @@ fn shuffle(ptr: usize, comptime From: type, comptime To: type) usize {
118 const pResult = @as(*align(1) [array_len]To, @ptrCast(&result));118 const pResult = @as(*align(1) [array_len]To, @ptrCast(&result));
119 var i: usize = 0;119 var i: usize = 0;
120 while (i < array_len) : (i += 1) {120 while (i < array_len) : (i += 1) {
121 inline for (@typeInfo(To).@"struct".fields) |f| {121 inline for (@typeInfo(To).@"struct".field_names) |f_name| {
122 @field(pResult[i], f.name) = @field(pSource[i], f.name);122 @field(pResult[i], f_name) = @field(pSource[i], f_name);
123 }123 }
124 }124 }
125 return result;125 return result;
test/behavior/enum.zig+8-6
...@@ -644,12 +644,12 @@ test "non-exhaustive enum" {...@@ -644,12 +644,12 @@ test "non-exhaustive enum" {
644 else => true,644 else => true,
645 });645 });
646646
647 try expect(@typeInfo(E).@"enum".fields.len == 2);647 try expect(@typeInfo(E).@"enum".field_names.len == 2);
648 e = @as(E, @enumFromInt(12));648 e = @as(E, @enumFromInt(12));
649 try expect(@intFromEnum(e) == 12);649 try expect(@intFromEnum(e) == 12);
650 e = @as(E, @enumFromInt(y));650 e = @as(E, @enumFromInt(y));
651 try expect(@intFromEnum(e) == 52);651 try expect(@intFromEnum(e) == 52);
652 try expect(@typeInfo(E).@"enum".is_exhaustive == false);652 try expect(@typeInfo(E).@"enum".mode == .nonexhaustive);
653 }653 }
654 };654 };
655 try S.doTheTest(52);655 try S.doTheTest(52);
...@@ -668,8 +668,9 @@ test "empty non-exhaustive enum" {...@@ -668,8 +668,9 @@ test "empty non-exhaustive enum" {
668 });668 });
669 try expect(@intFromEnum(e) == y);669 try expect(@intFromEnum(e) == y);
670670
671 try expect(@typeInfo(E).@"enum".fields.len == 0);671 try expect(@typeInfo(E).@"enum".field_names.len == 0);
672 try expect(@typeInfo(E).@"enum".is_exhaustive == false);672 try expect(@typeInfo(E).@"enum".field_values.len == 0);
673 try expect(@typeInfo(E).@"enum".mode == .nonexhaustive);
673 }674 }
674 };675 };
675 try S.doTheTest(42);676 try S.doTheTest(42);
...@@ -704,8 +705,9 @@ test "single field non-exhaustive enum" {...@@ -704,8 +705,9 @@ test "single field non-exhaustive enum" {
704 });705 });
705706
706 try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y);707 try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y);
707 try expect(@typeInfo(E).@"enum".fields.len == 1);708 try expect(@typeInfo(E).@"enum".field_names.len == 1);
708 try expect(@typeInfo(E).@"enum".is_exhaustive == false);709 try expect(@typeInfo(E).@"enum".field_values.len == 1);
710 try expect(@typeInfo(E).@"enum".mode == .nonexhaustive);
709 }711 }
710 };712 };
711 try S.doTheTest(23);713 try S.doTheTest(23);
test/behavior/error.zig+4-4
...@@ -206,7 +206,7 @@ const MyErrSet = error{...@@ -206,7 +206,7 @@ const MyErrSet = error{
206};206};
207207
208fn testErrorSetType() !void {208fn testErrorSetType() !void {
209 try expect(@typeInfo(MyErrSet).error_set.?.len == 2);209 try expect(@typeInfo(MyErrSet).error_set.error_names.?.len == 2);
210210
211 const a: MyErrSet!i32 = 5678;211 const a: MyErrSet!i32 = 5678;
212 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;212 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
...@@ -1125,9 +1125,9 @@ test "@errorCast into own inferred error set" {...@@ -1125,9 +1125,9 @@ test "@errorCast into own inferred error set" {
1125 try expect(err == error.Bad);1125 try expect(err == error.Bad);
1126 }1126 }
11271127
1128 const errors = @typeInfo(@typeInfo(@TypeOf(static.foo(false))).error_union.error_set).error_set.?;1128 const error_names = @typeInfo(@typeInfo(@TypeOf(static.foo(false))).error_union.error_set).error_set.error_names.?;
1129 comptime assert(errors.len == 1);1129 comptime assert(error_names.len == 1);
1130 comptime assert(std.mem.eql(u8, errors[0].name, "Bad"));1130 comptime assert(std.mem.eql(u8, error_names[0], "Bad"));
1131}1131}
11321132
1133test "@errorCast into other inferred error set" {1133test "@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" {...@@ -889,16 +889,16 @@ test "const local with comptime init through array init" {
889 };889 };
890890
891 const S = struct {891 const S = struct {
892 fn declarations(comptime T: type) []const std.builtin.Type.Declaration {892 fn declarations(comptime T: type) []const [:0]const u8 {
893 return @typeInfo(T).@"enum".decls;893 return @typeInfo(T).@"enum".decl_names;
894 }894 }
895 };895 };
896896
897 const decls = comptime [_][]const std.builtin.Type.Declaration{897 const decls = comptime [_][]const [:0]const u8{
898 S.declarations(E1),898 S.declarations(E1),
899 };899 };
900900
901 comptime assert(decls[0][0].name[0] == 'a');901 comptime assert(decls[0][0][0] == 'a');
902}902}
903903
904test "closure capture type of runtime-known parameter" {904test "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" {...@@ -400,7 +400,7 @@ test "function with inferred error set but returning no error" {
400 };400 };
401401
402 const return_ty = @typeInfo(@TypeOf(S.foo)).@"fn".return_type.?;402 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);
404}404}
405405
406test "import passed byref to function in return type" {406test "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" {...@@ -175,7 +175,7 @@ test "generic fn keeps non-generic parameter types" {
175175
176 const S = struct {176 const S = struct {
177 fn f(comptime T: type, s: []T) !void {177 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");
179 }179 }
180 };180 };
181181
...@@ -255,10 +255,13 @@ test "generic function instantiation turns into comptime call" {...@@ -255,10 +255,13 @@ test "generic function instantiation turns into comptime call" {
255 }255 }
256256
257 pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) {257 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 },
259 else => void,259 else => void,
260 } {260 } {
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 };
262 }265 }
263266
264 pub fn FieldEnum(comptime T: type) type {267 pub fn FieldEnum(comptime T: type) type {
test/behavior/memcpy.zig+3-3
...@@ -157,9 +157,9 @@ test "@memcpy with sentinel" {...@@ -157,9 +157,9 @@ test "@memcpy with sentinel" {
157157
158 const S = struct {158 const S = struct {
159 fn doTheTest() void {159 fn doTheTest() void {
160 const field = @typeInfo(struct { a: u32 }).@"struct".fields[0];160 const field_name = @typeInfo(struct { a: u32 }).@"struct".field_names[0];
161 var buffer: [field.name.len]u8 = undefined;161 var buffer: [field_name.len]u8 = undefined;
162 @memcpy(&buffer, field.name);162 @memcpy(&buffer, field_name);
163 }163 }
164 };164 };
165165
test/behavior/packed-struct.zig+2-2
...@@ -1040,9 +1040,9 @@ test "packed struct field pointer aligned properly" {...@@ -1040,9 +1040,9 @@ test "packed struct field pointer aligned properly" {
1040 };1040 };
10411041
1042 var f1: *align(16) Foo = @alignCast(@as(*align(1) Foo, @ptrCast(&Foo.buffer[0])));1042 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);
1044 try expect(@intFromPtr(f1) == @intFromPtr(&f1.a));1044 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);
1046}1046}
10471047
1048test "load flag from packed struct in union" {1048test "load flag from packed struct in union" {
test/behavior/pointers.zig+18-18
...@@ -291,8 +291,8 @@ test "allowzero pointer and slice" {...@@ -291,8 +291,8 @@ test "allowzero pointer and slice" {
291 comptime assert(@TypeOf(slice) == []allowzero i32);291 comptime assert(@TypeOf(slice) == []allowzero i32);
292 try expect(@intFromPtr(&slice[5]) == 20);292 try expect(@intFromPtr(&slice[5]) == 20);
293293
294 comptime assert(@typeInfo(@TypeOf(ptr)).pointer.is_allowzero);294 comptime assert(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"allowzero");
295 comptime assert(@typeInfo(@TypeOf(slice)).pointer.is_allowzero);295 comptime assert(@typeInfo(@TypeOf(slice)).pointer.attrs.@"allowzero");
296}296}
297297
298test "assign null directly to C pointer and test null equality" {298test "assign null directly to C pointer and test null equality" {
...@@ -470,15 +470,15 @@ test "pointer-integer arithmetic affects the alignment" {...@@ -470,15 +470,15 @@ test "pointer-integer arithmetic affects the alignment" {
470 var x: usize = 1;470 var x: usize = 1;
471 _ = .{ &ptr, &x };471 _ = .{ &ptr, &x };
472472
473 try expect(@typeInfo(@TypeOf(ptr)).pointer.alignment == 8);473 try expect(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"align" == 8);
474 const ptr1 = ptr + 1; // 1 * 4 = 4 -> lcd(4,8) = 4474 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);
476 const ptr2 = ptr + 4; // 4 * 4 = 16 -> lcd(16,8) = 8476 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);
478 const ptr3 = ptr + 0; // no-op478 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);
480 const ptr4 = ptr + x; // runtime-known addend480 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);
482 }482 }
483 {483 {
484 var ptr: [*]align(8) [3]u8 = undefined;484 var ptr: [*]align(8) [3]u8 = undefined;
...@@ -486,13 +486,13 @@ test "pointer-integer arithmetic affects the alignment" {...@@ -486,13 +486,13 @@ test "pointer-integer arithmetic affects the alignment" {
486 _ = .{ &ptr, &x };486 _ = .{ &ptr, &x };
487487
488 const ptr1 = ptr + 17; // 3 * 17 = 51488 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);
490 const ptr2 = ptr + x; // runtime-known addend490 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);
492 const ptr3 = ptr + 8; // 3 * 8 = 24 -> lcd(8,24) = 8492 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);
494 const ptr4 = ptr + 4; // 3 * 4 = 12 -> lcd(8,12) = 4494 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);
496 }496 }
497}497}
498498
...@@ -592,7 +592,7 @@ test "pointer to constant decl preserves alignment" {...@@ -592,7 +592,7 @@ test "pointer to constant decl preserves alignment" {
592 const aligned align(8) = @This(){ .a = 3, .b = 4 };592 const aligned align(8) = @This(){ .a = 3, .b = 4 };
593 };593 };
594594
595 const alignment = @typeInfo(@TypeOf(&S.aligned)).pointer.alignment;595 const alignment = @typeInfo(@TypeOf(&S.aligned)).pointer.attrs.@"align";
596 try std.testing.expect(alignment == 8);596 try std.testing.expect(alignment == 8);
597}597}
598598
...@@ -673,24 +673,24 @@ const Box2 = struct {...@@ -673,24 +673,24 @@ const Box2 = struct {
673673
674fn mutable() !void {674fn mutable() !void {
675 var box0: Box0 = .{ .items = undefined };675 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
678 var box1: Box1 = .{ .items = undefined };678 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
681 var box2: Box2 = .{ .items = undefined };681 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);
683}683}
684684
685fn constant() !void {685fn constant() !void {
686 const box0: Box0 = .{ .items = undefined };686 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
689 const box1: Box1 = .{ .items = undefined };689 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
692 const box2: Box2 = .{ .items = undefined };692 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);
694}694}
695695
696test "pointer-to-array constness for zero-size elements, var" {696test "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" {...@@ -8,11 +8,11 @@ test "reflection: function return type, var args, and param types" {
8 comptime {8 comptime {
9 const info = @typeInfo(@TypeOf(dummy)).@"fn";9 const info = @typeInfo(@TypeOf(dummy)).@"fn";
10 try expect(info.return_type.? == i32);10 try expect(info.return_type.? == i32);
11 try expect(!info.is_var_args);11 try expect(!info.attrs.varargs);
12 try expect(info.params.len == 3);12 try expect(info.param_types.len == 3);
13 try expect(info.params[0].type.? == bool);13 try expect(info.param_types[0].? == bool);
14 try expect(info.params[1].type.? == i32);14 try expect(info.param_types[1].? == i32);
15 try expect(info.params[2].type.? == f32);15 try expect(info.param_types[2].? == f32);
16 }16 }
17}17}
1818
test/behavior/slice.zig+3-3
...@@ -388,9 +388,9 @@ test "empty array to slice" {...@@ -388,9 +388,9 @@ test "empty array to slice" {
388 const align_1: []align(1) u8 = empty;388 const align_1: []align(1) u8 = empty;
389 const align_4: []align(4) u8 = empty;389 const align_4: []align(4) u8 = empty;
390 const align_16: []align(16) u8 = empty;390 const align_16: []align(16) u8 = empty;
391 try expect(1 == @typeInfo(@TypeOf(align_1)).pointer.alignment);391 try expect(1 == @typeInfo(@TypeOf(align_1)).pointer.attrs.@"align");
392 try expect(4 == @typeInfo(@TypeOf(align_4)).pointer.alignment);392 try expect(4 == @typeInfo(@TypeOf(align_4)).pointer.attrs.@"align");
393 try expect(16 == @typeInfo(@TypeOf(align_16)).pointer.alignment);393 try expect(16 == @typeInfo(@TypeOf(align_16)).pointer.attrs.@"align");
394 }394 }
395 };395 };
396396
test/behavior/struct.zig+1-1
...@@ -1627,7 +1627,7 @@ test "packed struct field in anonymous struct" {...@@ -1627,7 +1627,7 @@ test "packed struct field in anonymous struct" {
1627 try std.testing.expect(countFields(.{ .t = T{} }) == 1);1627 try std.testing.expect(countFields(.{ .t = T{} }) == 1);
1628}1628}
1629fn countFields(v: anytype) usize {1629fn countFields(v: anytype) usize {
1630 return @typeInfo(@TypeOf(v)).@"struct".fields.len;1630 return @typeInfo(@TypeOf(v)).@"struct".field_names.len;
1631}1631}
16321632
1633test "struct init with no result pointer sets field result types" {1633test "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" {...@@ -512,9 +512,9 @@ test "empty struct in tuple" {
512512
513 const T = struct { struct {} };513 const T = struct { struct {} };
514 const info = @typeInfo(T);514 const info = @typeInfo(T);
515 try std.testing.expectEqual(@as(usize, 1), info.@"struct".fields.len);515 try std.testing.expectEqual(@as(usize, 1), info.@"struct".field_names.len);
516 try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name);516 try std.testing.expectEqualStrings("0", info.@"struct".field_names[0]);
517 try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"struct");517 try std.testing.expect(@typeInfo(info.@"struct".field_types[0]) == .@"struct");
518}518}
519519
520test "empty union in tuple" {520test "empty union in tuple" {
...@@ -524,9 +524,9 @@ test "empty union in tuple" {...@@ -524,9 +524,9 @@ test "empty union in tuple" {
524524
525 const T = struct { union {} };525 const T = struct { union {} };
526 const info = @typeInfo(T);526 const info = @typeInfo(T);
527 try std.testing.expectEqual(@as(usize, 1), info.@"struct".fields.len);527 try std.testing.expectEqual(@as(usize, 1), info.@"struct".field_names.len);
528 try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name);528 try std.testing.expectEqualStrings("0", info.@"struct".field_names[0]);
529 try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"union");529 try std.testing.expect(@typeInfo(info.@"struct".field_types[0]) == .@"union");
530}530}
531531
532test "field pointer of underaligned tuple" {532test "field pointer of underaligned tuple" {
...@@ -551,11 +551,11 @@ test "field pointer of underaligned tuple" {...@@ -551,11 +551,11 @@ test "field pointer of underaligned tuple" {
551test "OPV tuple fields aren't comptime" {551test "OPV tuple fields aren't comptime" {
552 const T = struct { void };552 const T = struct { void };
553 const t_info = @typeInfo(T);553 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
556 const T2 = @Tuple(&.{void});556 const T2 = @Tuple(&.{void});
557 const t2_info = @typeInfo(T2);557 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");
559}559}
560560
561test "array of tuples that end with a zero-bit field followed by padding" {561test "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" {...@@ -12,23 +12,23 @@ test "tuple declaration type info" {
12 const T = struct { comptime u32 = 1, []const u8 };12 const T = struct { comptime u32 = 1, []const u8 };
13 const info = @typeInfo(T).@"struct";13 const info = @typeInfo(T).@"struct";
1414
15 try expect(info.is_tuple);
15 try expect(info.layout == .auto);16 try expect(info.layout == .auto);
16 try expect(info.backing_integer == null);17 try expect(info.backing_integer == null);
17 try expect(info.fields.len == 2);18 try expect(info.field_names.len == 2);
18 try expect(info.decls.len == 0);19 try expect(info.decl_names.len == 0);
19 try expect(info.is_tuple);20
2021 try expectEqualStrings(info.field_names[0], "0");
21 try expectEqualStrings(info.fields[0].name, "0");22 try expect(info.field_types[0] == u32);
22 try expect(info.fields[0].type == u32);23 try expect(info.field_attrs[0].defaultValue(info.field_types[0]) == 1);
23 try expect(info.fields[0].defaultValue() == 1);24 try expect(info.field_attrs[0].@"comptime");
24 try expect(info.fields[0].is_comptime);25 try expect(info.field_attrs[0].@"align" == null);
25 try expect(info.fields[0].alignment == null);26
2627 try expectEqualStrings(info.field_names[1], "1");
27 try expectEqualStrings(info.fields[1].name, "1");28 try expect(info.field_types[1] == []const u8);
28 try expect(info.fields[1].type == []const u8);29 try expect(info.field_attrs[1].defaultValue(info.field_types[1]) == null);
29 try expect(info.fields[1].defaultValue() == null);30 try expect(!info.field_attrs[1].@"comptime");
30 try expect(!info.fields[1].is_comptime);31 try expect(info.field_attrs[1].@"align" == null);
31 try expect(info.fields[1].alignment == null);
32 }32 }
33}33}
3434
test/behavior/type.zig+37-49
...@@ -57,13 +57,7 @@ test "Type.Pointer" {...@@ -57,13 +57,7 @@ test "Type.Pointer" {
57 [*c]align(8) volatile u8, [*c]align(8) const volatile u8,57 [*c]align(8) volatile u8, [*c]align(8) const volatile u8,
58 }) |testType| {58 }) |testType| {
59 const ptr = @typeInfo(testType).pointer;59 const ptr = @typeInfo(testType).pointer;
60 try testing.expect(testType == @Pointer(ptr.size, .{60 try testing.expect(testType == @Pointer(ptr.size, ptr.attrs, ptr.child, ptr.sentinel()));
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()));
67 }61 }
68}62}
6963
...@@ -103,13 +97,7 @@ test "@Pointer on @typeInfo round-trips sentinels" {...@@ -103,13 +97,7 @@ test "@Pointer on @typeInfo round-trips sentinels" {
103 [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8,97 [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8,
104 }) |TestType| {98 }) |TestType| {
105 const ptr = @typeInfo(TestType).pointer;99 const ptr = @typeInfo(TestType).pointer;
106 try testing.expect(TestType == @Pointer(ptr.size, .{100 try testing.expect(TestType == @Pointer(ptr.size, ptr.attrs, ptr.child, ptr.sentinel()));
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()));
113 }101 }
114}102}
115103
...@@ -122,9 +110,9 @@ test "Type.Opaque" {...@@ -122,9 +110,9 @@ test "Type.Opaque" {
122 const Opaque = opaque {};110 const Opaque = opaque {};
123 try testing.expect(Opaque != opaque {});111 try testing.expect(Opaque != opaque {});
124 try testing.expectEqualSlices(112 try testing.expectEqualSlices(
125 Type.Declaration,113 [:0]const u8,
126 &.{},114 &.{},
127 @typeInfo(Opaque).@"opaque".decls,115 @typeInfo(Opaque).@"opaque".decl_names,
128 );116 );
129}117}
130118
...@@ -141,13 +129,13 @@ test "Type.Struct" {...@@ -141,13 +129,13 @@ test "Type.Struct" {
141 const A = @Struct(.auto, null, &.{ "x", "y" }, &.{ u8, u32 }, &@splat(.{}));129 const A = @Struct(.auto, null, &.{ "x", "y" }, &.{ u8, u32 }, &@splat(.{}));
142 const infoA = @typeInfo(A).@"struct";130 const infoA = @typeInfo(A).@"struct";
143 try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout);131 try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout);
144 try testing.expectEqualSlices(u8, "x", infoA.fields[0].name);132 try testing.expectEqualSlices(u8, "x", infoA.field_names[0]);
145 try testing.expectEqual(u8, infoA.fields[0].type);133 try testing.expectEqual(u8, infoA.field_types[0]);
146 try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value_ptr);134 try testing.expectEqual(@as(?*const anyopaque, null), infoA.field_attrs[0].default_value_ptr);
147 try testing.expectEqualSlices(u8, "y", infoA.fields[1].name);135 try testing.expectEqualSlices(u8, "y", infoA.field_names[1]);
148 try testing.expectEqual(u32, infoA.fields[1].type);136 try testing.expectEqual(u32, infoA.field_types[1]);
149 try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value_ptr);137 try testing.expectEqual(@as(?*const anyopaque, null), infoA.field_attrs[1].default_value_ptr);
150 try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls);138 try testing.expectEqualSlices([:0]const u8, &.{}, infoA.decl_names);
151 try testing.expectEqual(@as(bool, false), infoA.is_tuple);139 try testing.expectEqual(@as(bool, false), infoA.is_tuple);
152140
153 var a = A{ .x = 0, .y = 1 };141 var a = A{ .x = 0, .y = 1 };
...@@ -165,13 +153,13 @@ test "Type.Struct" {...@@ -165,13 +153,13 @@ test "Type.Struct" {
165 );153 );
166 const infoB = @typeInfo(B).@"struct";154 const infoB = @typeInfo(B).@"struct";
167 try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout);155 try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout);
168 try testing.expectEqualSlices(u8, "x", infoB.fields[0].name);156 try testing.expectEqualSlices(u8, "x", infoB.field_names[0]);
169 try testing.expectEqual(u8, infoB.fields[0].type);157 try testing.expectEqual(u8, infoB.field_types[0]);
170 try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value_ptr);158 try testing.expectEqual(@as(?*const anyopaque, null), infoB.field_attrs[0].default_value_ptr);
171 try testing.expectEqualSlices(u8, "y", infoB.fields[1].name);159 try testing.expectEqualSlices(u8, "y", infoB.field_names[1]);
172 try testing.expectEqual(u32, infoB.fields[1].type);160 try testing.expectEqual(u32, infoB.field_types[1]);
173 try testing.expectEqual(@as(u32, 5), infoB.fields[1].defaultValue().?);161 try testing.expectEqual(@as(u32, 5), infoB.field_attrs[1].defaultValue(infoB.field_types[1]).?);
174 try testing.expectEqual(@as(usize, 0), infoB.decls.len);162 try testing.expectEqual(@as(usize, 0), infoB.decl_names.len);
175 try testing.expectEqual(@as(bool, false), infoB.is_tuple);163 try testing.expectEqual(@as(bool, false), infoB.is_tuple);
176164
177 const C = @Struct(165 const C = @Struct(
...@@ -186,20 +174,20 @@ test "Type.Struct" {...@@ -186,20 +174,20 @@ test "Type.Struct" {
186 );174 );
187 const infoC = @typeInfo(C).@"struct";175 const infoC = @typeInfo(C).@"struct";
188 try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout);176 try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout);
189 try testing.expectEqualSlices(u8, "x", infoC.fields[0].name);177 try testing.expectEqualSlices(u8, "x", infoC.field_names[0]);
190 try testing.expectEqual(u8, infoC.fields[0].type);178 try testing.expectEqual(u8, infoC.field_types[0]);
191 try testing.expectEqual(@as(u8, 3), infoC.fields[0].defaultValue().?);179 try testing.expectEqual(@as(u8, 3), infoC.field_attrs[0].defaultValue(infoC.field_types[0]).?);
192 try testing.expectEqualSlices(u8, "y", infoC.fields[1].name);180 try testing.expectEqualSlices(u8, "y", infoC.field_names[1]);
193 try testing.expectEqual(u32, infoC.fields[1].type);181 try testing.expectEqual(u32, infoC.field_types[1]);
194 try testing.expectEqual(@as(u32, 5), infoC.fields[1].defaultValue().?);182 try testing.expectEqual(@as(u32, 5), infoC.field_attrs[1].defaultValue(infoC.field_types[1]).?);
195 try testing.expectEqual(@as(usize, 0), infoC.decls.len);183 try testing.expectEqual(@as(usize, 0), infoC.decl_names.len);
196 try testing.expectEqual(@as(bool, false), infoC.is_tuple);184 try testing.expectEqual(@as(bool, false), infoC.is_tuple);
197185
198 // empty struct186 // empty struct
199 const F = @Struct(.auto, null, &.{}, &.{}, &.{});187 const F = @Struct(.auto, null, &.{}, &.{}, &.{});
200 const infoF = @typeInfo(F).@"struct";188 const infoF = @typeInfo(F).@"struct";
201 try testing.expectEqual(Type.ContainerLayout.auto, infoF.layout);189 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);
203 try testing.expectEqual(@as(bool, false), infoF.is_tuple);191 try testing.expectEqual(@as(bool, false), infoF.is_tuple);
204}192}
205193
...@@ -208,11 +196,11 @@ test "Type.Enum" {...@@ -208,11 +196,11 @@ test "Type.Enum" {
208 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;196 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
209197
210 const Foo = @Enum(u8, .exhaustive, &.{ "a", "b" }, &.{ 1, 5 });198 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);
212 try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a));200 try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a));
213 try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b));201 try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b));
214 const Bar = @Enum(u32, .nonexhaustive, &.{ "a", "b" }, &.{ 1, 5 });202 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);
216 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));204 try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a));
217 try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b));205 try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b));
218 try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6))));206 try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6))));
...@@ -278,13 +266,13 @@ test "Type.Union from regular enum" {...@@ -278,13 +266,13 @@ test "Type.Union from regular enum" {
278test "Type.Union from empty regular enum" {266test "Type.Union from empty regular enum" {
279 const E = enum {};267 const E = enum {};
280 const U = @Union(.auto, E, &.{}, &.{}, &.{});268 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);
282}270}
283271
284test "Type.Union from empty Type.Enum" {272test "Type.Union from empty Type.Enum" {
285 const E = @Enum(u0, .exhaustive, &.{}, &.{});273 const E = @Enum(u0, .exhaustive, &.{}, &.{});
286 const U = @Union(.auto, E, &.{}, &.{}, &.{});274 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);
288}276}
289277
290test "Type.Fn" {278test "Type.Fn" {
...@@ -378,11 +366,11 @@ test "struct field names sliced at comptime from larger string" {...@@ -378,11 +366,11 @@ test "struct field names sliced at comptime from larger string" {
378 }366 }
379367
380 const T = @Struct(.auto, null, field_names, &@splat(usize), &@splat(.{}));368 const T = @Struct(.auto, null, field_names, &@splat(usize), &@splat(.{}));
381 const gen_fields = @typeInfo(T).@"struct".fields;369 const gen_field_names = @typeInfo(T).@"struct".field_names;
382 try testing.expectEqual(3, gen_fields.len);370 try testing.expectEqual(3, gen_field_names.len);
383 try testing.expectEqualStrings("f1", gen_fields[0].name);371 try testing.expectEqualStrings("f1", gen_field_names[0]);
384 try testing.expectEqualStrings("f2", gen_fields[1].name);372 try testing.expectEqualStrings("f2", gen_field_names[1]);
385 try testing.expectEqualStrings("f3", gen_fields[2].name);373 try testing.expectEqualStrings("f3", gen_field_names[2]);
386 }374 }
387}375}
388376
...@@ -431,8 +419,8 @@ test "undefined type value" {...@@ -431,8 +419,8 @@ test "undefined type value" {
431test "reify struct with zero fields through const arrays" {419test "reify struct with zero fields through const arrays" {
432 const names: [0][]const u8 = .{};420 const names: [0][]const u8 = .{};
433 const types: [0]type = .{};421 const types: [0]type = .{};
434 const attrs: [0]std.builtin.Type.StructField.Attributes = .{};422 const attrs: [0]std.builtin.Type.Struct.FieldAttributes = .{};
435 const S = @Struct(.auto, null, &names, &types, &attrs);423 const S = @Struct(.auto, null, &names, &types, &attrs);
436 comptime assert(@typeInfo(S) == .@"struct");424 comptime assert(@typeInfo(S) == .@"struct");
437 comptime assert(@typeInfo(S).@"struct".fields.len == 0);425 comptime assert(@typeInfo(S).@"struct".field_names.len == 0);
438}426}
test/behavior/type_info.zig+103-91
...@@ -45,9 +45,9 @@ fn testCPtr() !void {...@@ -45,9 +45,9 @@ fn testCPtr() !void {
45 const ptr_info = @typeInfo([*c]align(4) const i8);45 const ptr_info = @typeInfo([*c]align(4) const i8);
46 try expect(ptr_info == .pointer);46 try expect(ptr_info == .pointer);
47 try expect(ptr_info.pointer.size == .c);47 try expect(ptr_info.pointer.size == .c);
48 try expect(ptr_info.pointer.is_const);48 try expect(ptr_info.pointer.attrs.@"const");
49 try expect(!ptr_info.pointer.is_volatile);49 try expect(!ptr_info.pointer.attrs.@"volatile");
50 try expect(ptr_info.pointer.alignment == 4);50 try expect(ptr_info.pointer.attrs.@"align" == 4);
51 try expect(ptr_info.pointer.child == i8);51 try expect(ptr_info.pointer.child == i8);
52}52}
5353
...@@ -80,9 +80,9 @@ fn testPointer() !void {...@@ -80,9 +80,9 @@ fn testPointer() !void {
80 const u32_ptr_info = @typeInfo(*u32);80 const u32_ptr_info = @typeInfo(*u32);
81 try expect(u32_ptr_info == .pointer);81 try expect(u32_ptr_info == .pointer);
82 try expect(u32_ptr_info.pointer.size == .one);82 try expect(u32_ptr_info.pointer.size == .one);
83 try expect(u32_ptr_info.pointer.is_const == false);83 try expect(u32_ptr_info.pointer.attrs.@"const" == false);
84 try expect(u32_ptr_info.pointer.is_volatile == false);84 try expect(u32_ptr_info.pointer.attrs.@"volatile" == false);
85 try expect(u32_ptr_info.pointer.alignment == null);85 try expect(u32_ptr_info.pointer.attrs.@"align" == null);
86 try expect(u32_ptr_info.pointer.child == u32);86 try expect(u32_ptr_info.pointer.child == u32);
87 try expect(u32_ptr_info.pointer.sentinel() == null);87 try expect(u32_ptr_info.pointer.sentinel() == null);
88}88}
...@@ -96,11 +96,11 @@ fn testUnknownLenPtr() !void {...@@ -96,11 +96,11 @@ fn testUnknownLenPtr() !void {
96 const u32_ptr_info = @typeInfo([*]const volatile f64);96 const u32_ptr_info = @typeInfo([*]const volatile f64);
97 try expect(u32_ptr_info == .pointer);97 try expect(u32_ptr_info == .pointer);
98 try expect(u32_ptr_info.pointer.size == .many);98 try expect(u32_ptr_info.pointer.size == .many);
99 try expect(u32_ptr_info.pointer.is_const == true);99 try expect(u32_ptr_info.pointer.attrs.@"const" == true);
100 try expect(u32_ptr_info.pointer.is_volatile == true);100 try expect(u32_ptr_info.pointer.attrs.@"volatile" == true);
101 try expect(u32_ptr_info.pointer.sentinel() == null);101 try expect(u32_ptr_info.pointer.attrs.@"align" == null);
102 try expect(u32_ptr_info.pointer.alignment == null);
103 try expect(u32_ptr_info.pointer.child == f64);102 try expect(u32_ptr_info.pointer.child == f64);
103 try expect(u32_ptr_info.pointer.sentinel() == null);
104}104}
105105
106test "type info: null terminated pointer type info" {106test "type info: null terminated pointer type info" {
...@@ -112,8 +112,8 @@ fn testNullTerminatedPtr() !void {...@@ -112,8 +112,8 @@ fn testNullTerminatedPtr() !void {
112 const ptr_info = @typeInfo([*:0]u8);112 const ptr_info = @typeInfo([*:0]u8);
113 try expect(ptr_info == .pointer);113 try expect(ptr_info == .pointer);
114 try expect(ptr_info.pointer.size == .many);114 try expect(ptr_info.pointer.size == .many);
115 try expect(ptr_info.pointer.is_const == false);115 try expect(ptr_info.pointer.attrs.@"const" == false);
116 try expect(ptr_info.pointer.is_volatile == false);116 try expect(ptr_info.pointer.attrs.@"volatile" == false);
117 try expect(ptr_info.pointer.sentinel().? == 0);117 try expect(ptr_info.pointer.sentinel().? == 0);
118118
119 try expect(@typeInfo([:0]u8).pointer.sentinel() != null);119 try expect(@typeInfo([:0]u8).pointer.sentinel() != null);
...@@ -128,9 +128,9 @@ fn testSlice() !void {...@@ -128,9 +128,9 @@ fn testSlice() !void {
128 const u32_slice_info = @typeInfo([]u32);128 const u32_slice_info = @typeInfo([]u32);
129 try expect(u32_slice_info == .pointer);129 try expect(u32_slice_info == .pointer);
130 try expect(u32_slice_info.pointer.size == .slice);130 try expect(u32_slice_info.pointer.size == .slice);
131 try expect(u32_slice_info.pointer.is_const == false);131 try expect(u32_slice_info.pointer.attrs.@"const" == false);
132 try expect(u32_slice_info.pointer.is_volatile == false);132 try expect(u32_slice_info.pointer.attrs.@"volatile" == false);
133 try expect(u32_slice_info.pointer.alignment == null);133 try expect(u32_slice_info.pointer.attrs.@"align" == null);
134 try expect(u32_slice_info.pointer.child == u32);134 try expect(u32_slice_info.pointer.child == u32);
135}135}
136136
...@@ -175,8 +175,8 @@ fn testErrorSet() !void {...@@ -175,8 +175,8 @@ fn testErrorSet() !void {
175175
176 const error_set_info = @typeInfo(TestErrorSet);176 const error_set_info = @typeInfo(TestErrorSet);
177 try expect(error_set_info == .error_set);177 try expect(error_set_info == .error_set);
178 try expect(error_set_info.error_set.?.len == 3);178 try expect(error_set_info.error_set.error_names.?.len == 3);
179 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "First"));179 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "First"));
180180
181 const error_union_info = @typeInfo(TestErrorSet!usize);181 const error_union_info = @typeInfo(TestErrorSet!usize);
182 try expect(error_union_info == .error_union);182 try expect(error_union_info == .error_union);
...@@ -185,7 +185,7 @@ fn testErrorSet() !void {...@@ -185,7 +185,7 @@ fn testErrorSet() !void {
185185
186 const global_info = @typeInfo(anyerror);186 const global_info = @typeInfo(anyerror);
187 try expect(global_info == .error_set);187 try expect(global_info == .error_set);
188 try expect(global_info.error_set == null);188 try expect(global_info.error_set.error_names == null);
189}189}
190190
191test "type info: error set single value" {191test "type info: error set single value" {
...@@ -197,8 +197,8 @@ test "type info: error set single value" {...@@ -197,8 +197,8 @@ test "type info: error set single value" {
197197
198 const error_set_info = @typeInfo(@TypeOf(TestSet));198 const error_set_info = @typeInfo(@TypeOf(TestSet));
199 try expect(error_set_info == .error_set);199 try expect(error_set_info == .error_set);
200 try expect(error_set_info.error_set.?.len == 1);200 try expect(error_set_info.error_set.error_names.?.len == 1);
201 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));201 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One"));
202}202}
203203
204test "type info: error set merged" {204test "type info: error set merged" {
...@@ -210,10 +210,10 @@ test "type info: error set merged" {...@@ -210,10 +210,10 @@ test "type info: error set merged" {
210210
211 const error_set_info = @typeInfo(TestSet);211 const error_set_info = @typeInfo(TestSet);
212 try expect(error_set_info == .error_set);212 try expect(error_set_info == .error_set);
213 try expect(error_set_info.error_set.?.len == 3);213 try expect(error_set_info.error_set.error_names.?.len == 3);
214 try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One"));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.?[1].name, "Two"));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.?[2].name, "Three"));216 try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three"));
217}217}
218218
219test "type info: enum info" {219test "type info: enum info" {
...@@ -235,11 +235,12 @@ fn testEnum() !void {...@@ -235,11 +235,12 @@ fn testEnum() !void {
235235
236 const os_info = @typeInfo(Os);236 const os_info = @typeInfo(Os);
237 try expect(os_info == .@"enum");237 try expect(os_info == .@"enum");
238 try expect(os_info.@"enum".fields.len == 4);238 try expect(os_info.@"enum".field_names.len == 4);
239 try expect(mem.eql(u8, os_info.@"enum".fields[1].name, "Macos"));239 try expect(os_info.@"enum".field_values.len == os_info.@"enum".field_names.len);
240 try expect(os_info.@"enum".fields[3].value == 3);240 try expect(mem.eql(u8, os_info.@"enum".field_names[1], "Macos"));
241 try expect(os_info.@"enum".field_values[3] == 3);
241 try expect(os_info.@"enum".tag_type == u2);242 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);
243}244}
244245
245test "type info: union info" {246test "type info: union info" {
...@@ -252,9 +253,11 @@ fn testUnion() !void {...@@ -252,9 +253,11 @@ fn testUnion() !void {
252 try expect(typeinfo_info == .@"union");253 try expect(typeinfo_info == .@"union");
253 try expect(typeinfo_info.@"union".layout == .auto);254 try expect(typeinfo_info.@"union".layout == .auto);
254 try expect(typeinfo_info.@"union".tag_type.? == TypeId);255 try expect(typeinfo_info.@"union".tag_type.? == TypeId);
255 try expect(typeinfo_info.@"union".fields.len == 24);256 try expect(typeinfo_info.@"union".field_names.len == 24);
256 try expect(typeinfo_info.@"union".fields[4].type == @TypeOf(@typeInfo(u8).int));257 try expect(typeinfo_info.@"union".field_names.len == typeinfo_info.@"union".field_types.len);
257 try expect(typeinfo_info.@"union".decls.len == 21);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
259 const TestNoTagUnion = union {262 const TestNoTagUnion = union {
260 Foo: void,263 Foo: void,
...@@ -265,10 +268,12 @@ fn testUnion() !void {...@@ -265,10 +268,12 @@ fn testUnion() !void {
265 try expect(notag_union_info == .@"union");268 try expect(notag_union_info == .@"union");
266 try expect(notag_union_info.@"union".tag_type == null);269 try expect(notag_union_info.@"union".tag_type == null);
267 try expect(notag_union_info.@"union".layout == .auto);270 try expect(notag_union_info.@"union".layout == .auto);
268 try expect(notag_union_info.@"union".fields.len == 2);271 try expect(notag_union_info.@"union".field_names.len == 2);
269 try expect(notag_union_info.@"union".fields[0].alignment == null);272 try expect(notag_union_info.@"union".field_names.len == notag_union_info.@"union".field_types.len);
270 try expect(notag_union_info.@"union".fields[1].type == u32);273 try expect(notag_union_info.@"union".field_names.len == notag_union_info.@"union".field_attrs.len);
271 try expect(notag_union_info.@"union".fields[1].alignment == null);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
273 const TestExternUnion = extern union {278 const TestExternUnion = extern union {
274 foo: *anyopaque,279 foo: *anyopaque,
...@@ -277,7 +282,7 @@ fn testUnion() !void {...@@ -277,7 +282,7 @@ fn testUnion() !void {
277 const extern_union_info = @typeInfo(TestExternUnion);282 const extern_union_info = @typeInfo(TestExternUnion);
278 try expect(extern_union_info.@"union".layout == .@"extern");283 try expect(extern_union_info.@"union".layout == .@"extern");
279 try expect(extern_union_info.@"union".tag_type == null);284 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);
281}286}
282287
283test "type info: struct info" {288test "type info: struct info" {
...@@ -292,9 +297,11 @@ fn testStruct() !void {...@@ -292,9 +297,11 @@ fn testStruct() !void {
292 const unpacked_struct_info = @typeInfo(TestStruct);297 const unpacked_struct_info = @typeInfo(TestStruct);
293 try expect(unpacked_struct_info.@"struct".is_tuple == false);298 try expect(unpacked_struct_info.@"struct".is_tuple == false);
294 try expect(unpacked_struct_info.@"struct".backing_integer == null);299 try expect(unpacked_struct_info.@"struct".backing_integer == null);
295 try expect(unpacked_struct_info.@"struct".fields[0].alignment == null);300 try expect(unpacked_struct_info.@"struct".field_attrs[0].@"align" == null);
296 try expect(unpacked_struct_info.@"struct".fields[0].defaultValue().? == 4);301 const field_0_type = unpacked_struct_info.@"struct".field_types[0];
297 try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".fields[1].defaultValue().?));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).?));
298}305}
299306
300const TestStruct = struct {307const TestStruct = struct {
...@@ -313,13 +320,17 @@ fn testPackedStruct() !void {...@@ -313,13 +320,17 @@ fn testPackedStruct() !void {
313 try expect(struct_info.@"struct".is_tuple == false);320 try expect(struct_info.@"struct".is_tuple == false);
314 try expect(struct_info.@"struct".layout == .@"packed");321 try expect(struct_info.@"struct".layout == .@"packed");
315 try expect(struct_info.@"struct".backing_integer == u128);322 try expect(struct_info.@"struct".backing_integer == u128);
316 try expect(struct_info.@"struct".fields.len == 4);323 try expect(struct_info.@"struct".field_names.len == 4);
317 try expect(struct_info.@"struct".fields[0].alignment == null);324 try expect(struct_info.@"struct".field_names.len == struct_info.@"struct".field_types.len);
318 try expect(struct_info.@"struct".fields[2].type == f32);325 try expect(struct_info.@"struct".field_names.len == struct_info.@"struct".field_attrs.len);
319 try expect(struct_info.@"struct".fields[2].defaultValue() == null);326 try expect(struct_info.@"struct".field_attrs[0].@"align" == null);
320 try expect(struct_info.@"struct".fields[3].defaultValue().? == 4);327 try expect(struct_info.@"struct".field_types[2] == f32);
321 try expect(struct_info.@"struct".fields[3].alignment == null);328 const field_2_type = struct_info.@"struct".field_types[2];
322 try expect(struct_info.@"struct".decls.len == 1);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);
323}334}
324335
325const TestPackedStruct = packed struct {336const TestPackedStruct = packed struct {
...@@ -346,7 +357,7 @@ fn testOpaque() !void {...@@ -346,7 +357,7 @@ fn testOpaque() !void {
346 };357 };
347358
348 const foo_info = @typeInfo(Foo);359 const foo_info = @typeInfo(Foo);
349 try expect(foo_info.@"opaque".decls.len == 2);360 try expect(foo_info.@"opaque".decl_names.len == 2);
350}361}
351362
352test "type info: function type info" {363test "type info: function type info" {
...@@ -371,18 +382,18 @@ fn testFunction() !void {...@@ -371,18 +382,18 @@ fn testFunction() !void {
371 _ = S;382 _ = S;
372 const foo_fn_type = @TypeOf(typeInfoFoo);383 const foo_fn_type = @TypeOf(typeInfoFoo);
373 const foo_fn_info = @typeInfo(foo_fn_type);384 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));
375 try expect(!foo_fn_info.@"fn".is_generic);386 try expect(!foo_fn_info.@"fn".is_generic);
376 try expect(foo_fn_info.@"fn".params.len == 2);387 try expect(foo_fn_info.@"fn".param_types.len == 2);
377 try expect(foo_fn_info.@"fn".is_var_args);388 try expect(foo_fn_info.@"fn".attrs.varargs);
378 try expect(foo_fn_info.@"fn".return_type.? == usize);389 try expect(foo_fn_info.@"fn".return_type.? == usize);
379 const foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFoo));390 const foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFoo));
380 try expect(foo_ptr_fn_info.pointer.size == .one);391 try expect(foo_ptr_fn_info.pointer.size == .one);
381 try expect(foo_ptr_fn_info.pointer.is_const);392 try expect(foo_ptr_fn_info.pointer.attrs.@"const");
382 try expect(!foo_ptr_fn_info.pointer.is_volatile);393 try expect(!foo_ptr_fn_info.pointer.attrs.@"volatile");
383 try expect(foo_ptr_fn_info.pointer.address_space == .generic);394 try expect(foo_ptr_fn_info.pointer.attrs.@"addrspace" == .generic);
384 try expect(foo_ptr_fn_info.pointer.child == foo_fn_type);395 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");
386 try expect(foo_ptr_fn_info.pointer.sentinel() == null);397 try expect(foo_ptr_fn_info.pointer.sentinel() == null);
387398
388 // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment.399 // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment.
...@@ -397,19 +408,20 @@ fn testFunction() !void {...@@ -397,19 +408,20 @@ fn testFunction() !void {
397408
398 const aligned_foo_fn_type = @TypeOf(typeInfoFooAligned);409 const aligned_foo_fn_type = @TypeOf(typeInfoFooAligned);
399 const aligned_foo_fn_info = @typeInfo(aligned_foo_fn_type);410 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));
401 try expect(!aligned_foo_fn_info.@"fn".is_generic);412 try expect(!aligned_foo_fn_info.@"fn".is_generic);
402 try expect(aligned_foo_fn_info.@"fn".params.len == 2);413 try expect(aligned_foo_fn_info.@"fn".param_types.len == 2);
403 try expect(aligned_foo_fn_info.@"fn".is_var_args);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);
404 try expect(aligned_foo_fn_info.@"fn".return_type.? == usize);416 try expect(aligned_foo_fn_info.@"fn".return_type.? == usize);
405 const aligned_foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFooAligned));417 const aligned_foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFooAligned));
406 try expect(aligned_foo_ptr_fn_info.pointer.size == .one);418 try expect(aligned_foo_ptr_fn_info.pointer.size == .one);
407 try expect(aligned_foo_ptr_fn_info.pointer.is_const);419 try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"const");
408 try expect(!aligned_foo_ptr_fn_info.pointer.is_volatile);420 try expect(!aligned_foo_ptr_fn_info.pointer.attrs.@"volatile");
409 try expect(aligned_foo_ptr_fn_info.pointer.alignment == 4);421 try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"align" == 4);
410 try expect(aligned_foo_ptr_fn_info.pointer.address_space == .generic);422 try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"addrspace" == .generic);
411 try expect(aligned_foo_ptr_fn_info.pointer.child == aligned_foo_fn_type);423 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");
413 try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null);425 try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null);
414}426}
415427
...@@ -418,31 +430,29 @@ extern fn typeInfoFooAligned(a: usize, b: bool, ...) align(4) callconv(.c) usize...@@ -418,31 +430,29 @@ extern fn typeInfoFooAligned(a: usize, b: bool, ...) align(4) callconv(.c) usize
418430
419test "type info: generic function types" {431test "type info: generic function types" {
420 const G1 = @typeInfo(@TypeOf(generic1));432 const G1 = @typeInfo(@TypeOf(generic1));
421 try expect(G1.@"fn".params.len == 1);433 try expect(G1.@"fn".param_types.len == 1);
422 try expect(G1.@"fn".params[0].is_generic == true);434 try expect(G1.@"fn".param_types.len == G1.@"fn".param_attrs.len);
423 try expect(G1.@"fn".params[0].type == null);435 try expect(G1.@"fn".param_types[0] == null);
424 try expect(G1.@"fn".return_type == void);436 try expect(G1.@"fn".return_type == void);
425437
426 const G2 = @typeInfo(@TypeOf(generic2));438 const G2 = @typeInfo(@TypeOf(generic2));
427 try expect(G2.@"fn".params.len == 3);439 try expect(G2.@"fn".param_types.len == 3);
428 try expect(G2.@"fn".params[0].is_generic == false);440 try expect(G2.@"fn".param_types.len == G2.@"fn".param_attrs.len);
429 try expect(G2.@"fn".params[0].type == type);441 try expect(G2.@"fn".param_types[0] == type);
430 try expect(G2.@"fn".params[1].is_generic == true);442 try expect(G2.@"fn".param_types[1] == null);
431 try expect(G2.@"fn".params[1].type == null);443 try expect(G2.@"fn".param_types[2] == u8);
432 try expect(G2.@"fn".params[2].is_generic == false);
433 try expect(G2.@"fn".params[2].type == u8);
434 try expect(G2.@"fn".return_type == void);444 try expect(G2.@"fn".return_type == void);
435445
436 const G3 = @typeInfo(@TypeOf(generic3));446 const G3 = @typeInfo(@TypeOf(generic3));
437 try expect(G3.@"fn".params.len == 1);447 try expect(G3.@"fn".param_types.len == 1);
438 try expect(G3.@"fn".params[0].is_generic == true);448 try expect(G3.@"fn".param_types.len == G3.@"fn".param_attrs.len);
439 try expect(G3.@"fn".params[0].type == null);449 try expect(G3.@"fn".param_types[0] == null);
440 try expect(G3.@"fn".return_type == null);450 try expect(G3.@"fn".return_type == null);
441451
442 const G4 = @typeInfo(@TypeOf(generic4));452 const G4 = @typeInfo(@TypeOf(generic4));
443 try expect(G4.@"fn".params.len == 1);453 try expect(G4.@"fn".param_types.len == 1);
444 try expect(G4.@"fn".params[0].is_generic == true);454 try expect(G4.@"fn".param_types.len == G4.@"fn".param_attrs.len);
445 try expect(G4.@"fn".params[0].type == null);455 try expect(G4.@"fn".param_types[0] == null);
446 try expect(G4.@"fn".return_type == null);456 try expect(G4.@"fn".return_type == null);
447}457}
448458
...@@ -530,7 +540,7 @@ test "@typeInfo does not force declarations into existence" {...@@ -530,7 +540,7 @@ test "@typeInfo does not force declarations into existence" {
530 @compileError("test failed");540 @compileError("test failed");
531 }541 }
532 };542 };
533 comptime assert(@typeInfo(S).@"struct".fields.len == 1);543 comptime assert(@typeInfo(S).@"struct".field_names.len == 1);
534}544}
535545
536fn add(a: i32, b: i32) i32 {546fn add(a: i32, b: i32) i32 {
...@@ -548,12 +558,12 @@ test "Declarations are returned in declaration order" {...@@ -548,12 +558,12 @@ test "Declarations are returned in declaration order" {
548 pub const d = 4;558 pub const d = 4;
549 pub const e = 5;559 pub const e = 5;
550 };560 };
551 const d = @typeInfo(S).@"struct".decls;561 const d = @typeInfo(S).@"struct".decl_names;
552 try expect(std.mem.eql(u8, d[0].name, "a"));562 try expect(std.mem.eql(u8, d[0], "a"));
553 try expect(std.mem.eql(u8, d[1].name, "b"));563 try expect(std.mem.eql(u8, d[1], "b"));
554 try expect(std.mem.eql(u8, d[2].name, "c"));564 try expect(std.mem.eql(u8, d[2], "c"));
555 try expect(std.mem.eql(u8, d[3].name, "d"));565 try expect(std.mem.eql(u8, d[3], "d"));
556 try expect(std.mem.eql(u8, d[4].name, "e"));566 try expect(std.mem.eql(u8, d[4], "e"));
557}567}
558568
559test "Struct.is_tuple for anon list literal" {569test "Struct.is_tuple for anon list literal" {
...@@ -567,25 +577,27 @@ test "Struct.is_tuple for anon struct literal" {...@@ -567,25 +577,27 @@ test "Struct.is_tuple for anon struct literal" {
567577
568 const info = @typeInfo(@TypeOf(.{ .a = 0 }));578 const info = @typeInfo(@TypeOf(.{ .a = 0 }));
569 try expect(!info.@"struct".is_tuple);579 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"));
571}581}
572582
573test "StructField.is_comptime" {583test "StructField.is_comptime" {
574 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).@"struct";584 const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).@"struct";
575 try expect(!info.fields[0].is_comptime);585 try expect(!info.field_attrs[0].@"comptime");
576 try expect(info.fields[1].is_comptime);586 try expect(info.field_attrs[1].@"comptime");
577}587}
578588
579test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {589test "value from struct @typeInfo default_value_ptr can be loaded at comptime" {
580 comptime {590 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;
582 try expect(@as(*const u8, @ptrCast(a)).* == 1);592 try expect(@as(*const u8, @ptrCast(a)).* == 1);
583 }593 }
584}594}
585595
586test "type info of tuple of string literal default value" {596test "type info of tuple of string literal default value" {
587 const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0];597 const struct_info = @typeInfo(@TypeOf(.{"hi"})).@"struct";
588 const value = struct_field.defaultValue().?;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).?;
589 comptime std.debug.assert(value[0] == 'h');601 comptime std.debug.assert(value[0] == 'h');
590}602}
591603
test/behavior/union.zig+3-3
...@@ -445,7 +445,7 @@ test "global union with single field is correctly initialized" {...@@ -445,7 +445,7 @@ test "global union with single field is correctly initialized" {
445 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO445 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
446446
447 glbl = Foo1{447 glbl = Foo1{
448 .f = @typeInfo(Foo1).@"union".fields[0].type{ .x = 123 },448 .f = @typeInfo(Foo1).@"union".field_types[0]{ .x = 123 },
449 };449 };
450 try expect(glbl.f.x == 123);450 try expect(glbl.f.x == 123);
451}451}
...@@ -563,8 +563,8 @@ test "tagged union type" {...@@ -563,8 +563,8 @@ test "tagged union type" {
563 const baz = Baz.B;563 const baz = Baz.B;
564564
565 try expect(baz == Baz.B);565 try expect(baz == Baz.B);
566 try expect(@typeInfo(TaggedFoo).@"union".fields.len == 3);566 try expect(@typeInfo(TaggedFoo).@"union".field_names.len == 3);
567 try expect(@typeInfo(Baz).@"enum".fields.len == 4);567 try expect(@typeInfo(Baz).@"enum".field_names.len == 4);
568 try expect(@sizeOf(TaggedFoo) == @sizeOf(FooNoVoid));568 try expect(@sizeOf(TaggedFoo) == @sizeOf(FooNoVoid));
569 try expect(@sizeOf(Baz) == 1);569 try expect(@sizeOf(Baz) == 1);
570}570}
test/behavior/x86_64/math.zig+2-2
...@@ -130,8 +130,8 @@ pub noinline fn checkExpected(expected: anytype, actual: @TypeOf(expected), comp...@@ -130,8 +130,8 @@ pub noinline fn checkExpected(expected: anytype, actual: @TypeOf(expected), comp
130 };130 };
131 },131 },
132 },132 },
133 .@"struct" => |@"struct"| inline for (@"struct".fields) |field| {133 .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| {
134 try checkExpected(@field(expected, field.name), @field(actual, field.name), compare);134 try checkExpected(@field(expected, field_name), @field(actual, field_name), compare);
135 } else return,135 } else return,
136 };136 };
137 if (switch (@typeInfo(Expected)) {137 if (switch (@typeInfo(Expected)) {
test/behavior/zon.zig+8-8
...@@ -541,31 +541,31 @@ test "anon" {...@@ -541,31 +541,31 @@ test "anon" {
541 try expectEqual(expected[1], actual[1]);541 try expectEqual(expected[1], actual[1]);
542 const expected_struct = expected[0];542 const expected_struct = expected[0];
543 const actual_struct = actual[0];543 const actual_struct = actual[0];
544 const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".fields;544 const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".field_names;
545 const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".fields;545 const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".field_names;
546 try expectEqual(expected_fields.len, actual_fields.len);546 try expectEqual(expected_fields.len, actual_fields.len);
547 inline for (expected_fields) |field| {547 inline for (expected_fields) |field_name| {
548 try expectEqual(@field(expected_struct, field.name), @field(actual_struct, field.name));548 try expectEqual(@field(expected_struct, field_name), @field(actual_struct, field_name));
549 }549 }
550}550}
551551
552test "build.zig.zon" {552test "build.zig.zon" {
553 const build = @import("zon/build.zig.zon");553 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);
556 try expectEqualStrings("temp", build.name);556 try expectEqualStrings("temp", build.name);
557 try expectEqualStrings("0.0.0", build.version);557 try expectEqualStrings("0.0.0", build.version);
558558
559 const dependencies = build.dependencies;559 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
562 const example_0 = dependencies.example_0;562 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);
564 try expectEqualStrings("https://example.com/foo.tar.gz", example_0.url);564 try expectEqualStrings("https://example.com/foo.tar.gz", example_0.url);
565 try expectEqualStrings("...", example_0.hash);565 try expectEqualStrings("...", example_0.hash);
566566
567 const example_1 = dependencies.example_1;567 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);
569 try expectEqualStrings("../foo", example_1.path);569 try expectEqualStrings("../foo", example_1.path);
570 try expectEqual(false, example_1.lazy);570 try expectEqual(false, example_1.lazy);
571571
test/cases/compile_errors/access_invalid_typeInfo_decl.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub const A = B;1pub const A = B;
2export fn foo() void {2export fn foo() void {
3 _ = @typeInfo(@This()).@"struct".decls[0];3 _ = @typeInfo(@This()).@"struct".decl_names[0];
4}4}
55
6// error6// 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 {...@@ -7,9 +7,9 @@ pub export fn entry() void {
77
8 comptime var a = 1;8 comptime var a = 1;
9 const info = @typeInfo(Widget).@"union";9 const info = @typeInfo(Widget).@"union";
10 inline for (info.fields) |field| {10 inline for (info.field_types) |field_type| {
11 if (foo()) {11 if (foo()) {
12 switch (field.type) {12 switch (field_type) {
13 u0 => a = 2,13 u0 => a = 2,
14 else => unreachable,14 else => unreachable,
15 }15 }
test/cases/compile_errors/issue_15572_break_on_inline_while.zig+3-3
...@@ -6,8 +6,8 @@ pub const DwarfSection = enum {...@@ -6,8 +6,8 @@ pub const DwarfSection = enum {
6};6};
77
8pub fn main() void {8pub fn main() void {
9 const section = inline for (@typeInfo(DwarfSection).@"enum".fields) |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;10 if (std.mem.eql(u8, section_name, "eh_frame")) break section_name;
11 };11 };
1212
13 _ = section;13 _ = section;
...@@ -16,4 +16,4 @@ pub fn main() void {...@@ -16,4 +16,4 @@ pub fn main() void {
16// error16// error
17// target=x86_64-linux17// target=x86_64-linux
18//18//
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 {...@@ -7,7 +7,7 @@ export fn foo() void {
7 wrong_type: []u8 = "foo",7 wrong_type: []u8 = "foo",
8 };8 };
99
10 comptime ignore(@typeInfo(MyStruct).@"struct".fields[0]);10 comptime ignore(@typeInfo(MyStruct).@"struct".field_names[0]);
11}11}
1212
13// error13// error
test/cases/compile_errors/runtime_index_into_comptime_type_slice.zig+2-3
...@@ -6,12 +6,11 @@ fn getIndex() usize {...@@ -6,12 +6,11 @@ fn getIndex() usize {
6}6}
7export fn entry() void {7export fn entry() void {
8 const index = getIndex();8 const index = getIndex();
9 const field = @typeInfo(Struct).@"struct".fields[index];9 const field = @typeInfo(Struct).@"struct".field_types[index];
10 _ = field;10 _ = field;
11}11}
1212
13// error13// error
14//14//
15// :9:54: error: values of type 'lang.Type.StructField' must be comptime-known, but index value is runtime-known15// :9:59: error: values of type 'type' must be comptime-known, but index value is runtime-known
16// : note: struct requires comptime because of this field
17// : note: types are not available at runtime16// : 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 {...@@ -9,7 +9,7 @@ fn someFn(arg: ?*c_int) f64 {
9 return 8;9 return 8;
10}10}
11fn foo(comptime info: std.builtin.Type) !void {11fn 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);
13}13}
1414
15// run15// run
test/incremental/add_remove_struct_fields+4-4
...@@ -11,7 +11,7 @@ pub fn main(init: std.process.Init) !void {...@@ -11,7 +11,7 @@ pub fn main(init: std.process.Init) !void {
11 };11 };
12}12}
13fn printFieldCount(w: *Writer) Writer.Error!void {13fn 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});
15}15}
16fn printOneField(w: *Writer) Writer.Error!void {16fn printOneField(w: *Writer) Writer.Error!void {
17 const val: S = .{ .x = 100 };17 const val: S = .{ .x = 100 };
...@@ -34,7 +34,7 @@ pub fn main(init: std.process.Init) !void {...@@ -34,7 +34,7 @@ pub fn main(init: std.process.Init) !void {
34 };34 };
35}35}
36fn printFieldCount(w: *Writer) Writer.Error!void {36fn 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});
38}38}
39fn printOneField(w: *Writer) Writer.Error!void {39fn printOneField(w: *Writer) Writer.Error!void {
40 const val: S = .{ .x = 100 };40 const val: S = .{ .x = 100 };
...@@ -57,7 +57,7 @@ pub fn main(init: std.process.Init) !void {...@@ -57,7 +57,7 @@ pub fn main(init: std.process.Init) !void {
57 };57 };
58}58}
59fn printFieldCount(w: *Writer) Writer.Error!void {59fn 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});
61}61}
62fn printOneField(w: *Writer) Writer.Error!void {62fn printOneField(w: *Writer) Writer.Error!void {
63 const val: S = .{ .x = 100 };63 const val: S = .{ .x = 100 };
...@@ -81,7 +81,7 @@ pub fn main(init: std.process.Init) !void {...@@ -81,7 +81,7 @@ pub fn main(init: std.process.Init) !void {
81 };81 };
82}82}
83fn printFieldCount(w: *Writer) Writer.Error!void {83fn 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});
85}85}
86fn printOneField(w: *Writer) Writer.Error!void {86fn printOneField(w: *Writer) Writer.Error!void {
87 //const val: S = .{ .x = 100 };87 //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 {...@@ -12,7 +12,7 @@ pub fn main(init: std.process.Init) !void {
12 };12 };
13}13}
14fn printFieldCount(w: *Writer) Writer.Error!void {14fn 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});
16}16}
17fn printOneField(w: *Writer) Writer.Error!void {17fn printOneField(w: *Writer) Writer.Error!void {
18 const val: S = .{ .x = 100 };18 const val: S = .{ .x = 100 };
...@@ -37,7 +37,7 @@ pub fn main(init: std.process.Init) !void {...@@ -37,7 +37,7 @@ pub fn main(init: std.process.Init) !void {
37 };37 };
38}38}
39fn printFieldCount(w: *Writer) Writer.Error!void {39fn 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});
41}41}
42fn printOneField(w: *Writer) Writer.Error!void {42fn printOneField(w: *Writer) Writer.Error!void {
43 const val: S = .{ .x = 100 };43 const val: S = .{ .x = 100 };
...@@ -60,7 +60,7 @@ pub fn main(init: std.process.Init) !void {...@@ -60,7 +60,7 @@ pub fn main(init: std.process.Init) !void {
60 };60 };
61}61}
62fn printFieldCount(w: *Writer) Writer.Error!void {62fn 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});
64}64}
65fn printOneField(w: *Writer) Writer.Error!void {65fn printOneField(w: *Writer) Writer.Error!void {
66 const val: S = .{ .x = 100 };66 const val: S = .{ .x = 100 };
...@@ -84,7 +84,7 @@ pub fn main(init: std.process.Init) !void {...@@ -84,7 +84,7 @@ pub fn main(init: std.process.Init) !void {
84 };84 };
85}85}
86fn printFieldCount(w: *Writer) Writer.Error!void {86fn 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});
88}88}
89fn printOneField(w: *Writer) Writer.Error!void {89fn printOneField(w: *Writer) Writer.Error!void {
90 //const val: S = .{ .x = 100 };90 //const val: S = .{ .x = 100 };
test/incremental/change_union_tag_type+3-3
...@@ -4,7 +4,7 @@ const A = enum(u8) { a };...@@ -4,7 +4,7 @@ const A = enum(u8) { a };
4const B = enum(u8) { b };4const B = enum(u8) { b };
5const Foo = union(A) { a: u8 };5const Foo = union(A) { a: u8 };
6pub fn main(init: std.process.Init) !void {6pub 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];
8 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});8 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
9 try stdout_writer.interface.print("{s}\n", .{field_name});9 try stdout_writer.interface.print("{s}\n", .{field_name});
10}10}
...@@ -17,7 +17,7 @@ const A = enum(u8) { a };...@@ -17,7 +17,7 @@ const A = enum(u8) { a };
17const B = enum(u8) { b };17const B = enum(u8) { b };
18const Foo = union(B) { a: u8 };18const Foo = union(B) { a: u8 };
19pub fn main(init: std.process.Init) !void {19pub 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];
21 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});21 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
22 try stdout_writer.interface.print("{s}\n", .{field_name});22 try stdout_writer.interface.print("{s}\n", .{field_name});
23}23}
...@@ -31,7 +31,7 @@ const A = enum(u8) { a };...@@ -31,7 +31,7 @@ const A = enum(u8) { a };
31const B = enum(u8) { b };31const B = enum(u8) { b };
32const Foo = union(B) { b: u8 };32const Foo = union(B) { b: u8 };
33pub fn main(init: std.process.Init) !void {33pub 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];
35 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});35 var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
36 try stdout_writer.interface.print("{s}\n", .{field_name});36 try stdout_writer.interface.print("{s}\n", .{field_name});
37}37}
test/incremental/do_nothing+2-2
...@@ -7,7 +7,7 @@ pub fn main() void {...@@ -7,7 +7,7 @@ pub fn main() void {
7}7}
8const S = struct { foo: u32, nested: struct { x: u16 } };8const S = struct { foo: u32, nested: struct { x: u16 } };
9const U = union(enum) { a, b, c: S };9const 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 };
11const O = opaque {11const O = opaque {
12 comptime {12 comptime {
13 _ = @as(S, undefined);13 _ = @as(S, undefined);
...@@ -27,7 +27,7 @@ pub fn main() void {...@@ -27,7 +27,7 @@ pub fn main() void {
27}27}
28const S = struct { foo: u32, nested: struct { x: u16 } };28const S = struct { foo: u32, nested: struct { x: u16 } };
29const U = union(enum) { a, b, c: S };29const 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 };
31const O = opaque {31const O = opaque {
32 comptime {32 comptime {
33 _ = @as(S, undefined);33 _ = @as(S, undefined);
test/standalone/build.zig+1-2
...@@ -85,8 +85,7 @@ pub fn build(b: *std.Build) void {...@@ -85,8 +85,7 @@ pub fn build(b: *std.Build) void {
85 if (std.mem.eql(u8, dep_name, "simple")) continue;85 if (std.mem.eql(u8, dep_name, "simple")) continue;
8686
87 const all_pkgs = @import("root").dependencies.packages;87 const all_pkgs = @import("root").dependencies.packages;
88 inline for (@typeInfo(all_pkgs).@"struct".decls) |decl| {88 inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| {
89 const pkg_hash = decl.name;
90 if (std.mem.eql(u8, dep_hash, pkg_hash)) {89 if (std.mem.eql(u8, dep_hash, pkg_hash)) {
91 const pkg = @field(all_pkgs, pkg_hash);90 const pkg = @field(all_pkgs, pkg_hash);
92 if (!@hasDecl(pkg, "build_zig")) {91 if (!@hasDecl(pkg, "build_zig")) {
tools/gen_stubs.zig+16-16
...@@ -141,10 +141,10 @@ const Family = enum {...@@ -141,10 +141,10 @@ const Family = enum {
141 x86,141 x86,
142};142};
143143
144const arches: [@typeInfo(Arch).@"enum".fields.len]Arch = blk: {144const arches: [@typeInfo(Arch).@"enum".field_names.len]Arch = blk: {
145 var result: [@typeInfo(Arch).@"enum".fields.len]Arch = undefined;145 var result: [@typeInfo(Arch).@"enum".field_names.len]Arch = undefined;
146 for (@typeInfo(Arch).@"enum".fields) |field| {146 for (@typeInfo(Arch).@"enum".field_values) |field_value| {
147 const arch: Arch = @enumFromInt(field.value);147 const arch: Arch = @enumFromInt(field_value);
148 result[archIndex(arch)] = arch;148 result[archIndex(arch)] = arch;
149 }149 }
150 break :blk result;150 break :blk result;
...@@ -160,8 +160,8 @@ const MultiSym = struct {...@@ -160,8 +160,8 @@ const MultiSym = struct {
160160
161 fn isSingleArch(ms: MultiSym) ?Arch {161 fn isSingleArch(ms: MultiSym) ?Arch {
162 var result: ?Arch = null;162 var result: ?Arch = null;
163 inline for (@typeInfo(Arch).@"enum".fields) |field| {163 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
164 const arch: Arch = @enumFromInt(field.value);164 const arch: Arch = @enumFromInt(field_value);
165 if (ms.present[archIndex(arch)]) {165 if (ms.present[archIndex(arch)]) {
166 if (result != null) return null;166 if (result != null) return null;
167 result = arch;167 result = arch;
...@@ -172,8 +172,8 @@ const MultiSym = struct {...@@ -172,8 +172,8 @@ const MultiSym = struct {
172172
173 fn isFamily(ms: MultiSym) ?Family {173 fn isFamily(ms: MultiSym) ?Family {
174 var result: ?Family = null;174 var result: ?Family = null;
175 inline for (@typeInfo(Arch).@"enum".fields) |field| {175 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
176 const arch: Arch = @enumFromInt(field.value);176 const arch: Arch = @enumFromInt(field_value);
177 if (ms.present[archIndex(arch)]) {177 if (ms.present[archIndex(arch)]) {
178 const family = arch.family();178 const family = arch.family();
179 if (result) |r| if (family != r) return null;179 if (result) |r| if (family != r) return null;
...@@ -193,8 +193,8 @@ const MultiSym = struct {...@@ -193,8 +193,8 @@ const MultiSym = struct {
193 }193 }
194194
195 fn isTime32Only(ms: MultiSym) bool {195 fn isTime32Only(ms: MultiSym) bool {
196 inline for (@typeInfo(Arch).@"enum".fields) |field| {196 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
197 const arch: Arch = @enumFromInt(field.value);197 const arch: Arch = @enumFromInt(field_value);
198 if (ms.present[archIndex(arch)] != arch.isTime32()) {198 if (ms.present[archIndex(arch)] != arch.isTime32()) {
199 return false;199 return false;
200 }200 }
...@@ -233,8 +233,8 @@ const MultiSym = struct {...@@ -233,8 +233,8 @@ const MultiSym = struct {
233 }233 }
234234
235 fn isPtrSize(ms: MultiSym, mult: u16) bool {235 fn isPtrSize(ms: MultiSym, mult: u16) bool {
236 inline for (@typeInfo(Arch).@"enum".fields) |field| {236 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
237 const arch: Arch = @enumFromInt(field.value);237 const arch: Arch = @enumFromInt(field_value);
238 const arch_index = archIndex(arch);238 const arch_index = archIndex(arch);
239 if (ms.present[arch_index] and ms.size[arch_index] != arch.ptrSize() * mult) {239 if (ms.present[arch_index] and ms.size[arch_index] != arch.ptrSize() * mult) {
240 return false;240 return false;
...@@ -244,8 +244,8 @@ const MultiSym = struct {...@@ -244,8 +244,8 @@ const MultiSym = struct {
244 }244 }
245245
246 fn isWeak64(ms: MultiSym) bool {246 fn isWeak64(ms: MultiSym) bool {
247 inline for (@typeInfo(Arch).@"enum".fields) |field| {247 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
248 const arch: Arch = @enumFromInt(field.value);248 const arch: Arch = @enumFromInt(field_value);
249 const arch_index = archIndex(arch);249 const arch_index = archIndex(arch);
250 const binding: u4 = switch (arch.ptrSize()) {250 const binding: u4 = switch (arch.ptrSize()) {
251 4 => std.elf.STB_GLOBAL,251 4 => std.elf.STB_GLOBAL,
...@@ -260,8 +260,8 @@ const MultiSym = struct {...@@ -260,8 +260,8 @@ const MultiSym = struct {
260 }260 }
261261
262 fn isWeakTime64(ms: MultiSym) bool {262 fn isWeakTime64(ms: MultiSym) bool {
263 inline for (@typeInfo(Arch).@"enum".fields) |field| {263 inline for (@typeInfo(Arch).@"enum".field_values) |field_value| {
264 const arch: Arch = @enumFromInt(field.value);264 const arch: Arch = @enumFromInt(field_value);
265 const arch_index = archIndex(arch);265 const arch_index = archIndex(arch);
266 const binding: u4 = if (arch.isTime32()) std.elf.STB_GLOBAL else std.elf.STB_WEAK;266 const binding: u4 = if (arch.isTime32()) std.elf.STB_GLOBAL else std.elf.STB_WEAK;
267 if (ms.present[arch_index] and ms.binding[arch_index] != binding) {267 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 {...@@ -43,8 +43,8 @@ pub fn main(init: std.process.Init) !void {
43 var buffer: [2000]u8 = undefined;43 var buffer: [2000]u8 = undefined;
44 var stdout_writer = Io.File.stdout().writerStreaming(io, &buffer);44 var stdout_writer = Io.File.stdout().writerStreaming(io, &buffer);
45 const w = &stdout_writer.interface;45 const w = &stdout_writer.interface;
46 inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| {46 inline for (@typeInfo(std.Target.CType).@"enum".field_values) |field_value| {
47 const c_type: std.Target.CType = @enumFromInt(field.value);47 const c_type: std.Target.CType = @enumFromInt(field_value);
48 try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{48 try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
49 cName(c_type),49 cName(c_type),
50 target.cTypeByteSize(c_type),50 target.cTypeByteSize(c_type),
tools/update_clang_options.zig+3-3
...@@ -660,9 +660,9 @@ pub fn main(init: std.process.Init) !void {...@@ -660,9 +660,9 @@ pub fn main(init: std.process.Init) !void {
660660
661 var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(arena);661 var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(arena);
662662
663 inline for (@typeInfo(cpu_targets).@"struct".decls) |decl| {663 inline for (@typeInfo(cpu_targets).@"struct".decl_names) |decl_name| {
664 const Feature = @field(cpu_targets, decl.name).Feature;664 const Feature = @field(cpu_targets, decl_name).Feature;
665 const all_features = @field(cpu_targets, decl.name).all_features;665 const all_features = @field(cpu_targets, decl_name).all_features;
666666
667 for (all_features, 0..) |feat, i| {667 for (all_features, 0..) |feat, i| {
668 const llvm_name = feat.llvm_name orelse continue;668 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 {...@@ -2436,7 +2436,7 @@ fn processOneTargetInner(io: Io, job: Job) !void {
2436 try w.print(" @setEvalBranchQuota({d});\n", .{branch_quota});2436 try w.print(" @setEvalBranchQuota({d});\n", .{branch_quota});
2437 }2437 }
2438 try w.writeAll(2438 try w.writeAll(
2439 \\ const len = @typeInfo(Feature).@"enum".fields.len;2439 \\ const len = @typeInfo(Feature).@"enum".field_names.len;
2440 \\ std.debug.assert(len <= CpuFeature.Set.needed_bit_count);2440 \\ std.debug.assert(len <= CpuFeature.Set.needed_bit_count);
2441 \\ var result: [len]CpuFeature = undefined;2441 \\ var result: [len]CpuFeature = undefined;
2442 \\2442 \\
...@@ -2505,7 +2505,7 @@ fn processOneTargetInner(io: Io, job: Job) !void {...@@ -2505,7 +2505,7 @@ fn processOneTargetInner(io: Io, job: Job) !void {
2505 \\ const ti = @typeInfo(Feature);2505 \\ const ti = @typeInfo(Feature);
2506 \\ for (&result, 0..) |*elem, i| {2506 \\ for (&result, 0..) |*elem, i| {
2507 \\ elem.index = i;2507 \\ elem.index = i;
2508 \\ elem.name = ti.@"enum".fields[i].name;2508 \\ elem.name = ti.@"enum".field_names[i];
2509 \\ }2509 \\ }
2510 \\ break :blk result;2510 \\ break :blk result;
2511 \\};2511 \\};