| author | |
| committer | |
| log | 3f1dead2fc5922b588fbfb108f421ca957d6934a |
| tree | 47a976dc2264089771fbabd70a93a3865b70f07f |
| parent | 8d1b6e339750a37207bdaa8b5e9b4bda8d330fec |
| parent | 9e80795623aa826ec03d014ccf767ea30156d699 |
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35234206 files changed, 2750 insertions(+), 2488 deletions(-)
doc/langref.html.in+3-3| ... | ... | @@ -5752,7 +5752,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5752 | 5752 | {#header_open|@Fn#} |
| 5753 | 5753 | <pre>{#syntax#}@Fn( |
| 5754 | 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 | 5756 | comptime ReturnType: type, |
| 5757 | 5757 | comptime attrs: std.lang.Type.Fn.Attributes, |
| 5758 | 5758 | ) type{#endsyntax#}</pre> |
| ... | ... | @@ -5765,7 +5765,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5765 | 5765 | comptime BackingInt: ?type, |
| 5766 | 5766 | comptime field_names: []const []const u8, |
| 5767 | 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 | 5769 | ) type{#endsyntax#}</pre> |
| 5770 | 5770 | <p>Returns a {#link|struct#} type with the properties specified by the arguments.</p> |
| 5771 | 5771 | {#header_close#} |
| ... | ... | @@ -5777,7 +5777,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 5777 | 5777 | comptime ArgType: ?type, |
| 5778 | 5778 | comptime field_names: []const []const u8, |
| 5779 | 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 | 5781 | ) type{#endsyntax#}</pre> |
| 5782 | 5782 | <p>Returns a {#link|union#} type with the properties specified by the arguments.</p> |
| 5783 | 5783 | {#header_close#} |
doc/langref/inline_prong_range.zig+2-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | fn 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 | 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 | 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 | 102 | |
| 103 | 103 | // @typeInfo tells us the field count and the fields names: |
| 104 | 104 | test "@typeInfo" { |
| 105 | try expectEqual(4, @typeInfo(Small).@"enum".fields.len); | |
| 106 | try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two"); | |
| 105 | try expectEqual(4, @typeInfo(Small).@"enum".field_names.len); | |
| 106 | try expectEqualStrings(@typeInfo(Small).@"enum".field_names[1], "two"); | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 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 | 3 | const testing = std.testing; |
| 4 | 4 | |
| 5 | 5 | test "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 | 7 | try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?); |
| 8 | 8 | |
| 9 | 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 | 18 | |
| 19 | 19 | fn withFor(any: AnySlice) usize { |
| 20 | 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 | 23 | // With `inline for` the function gets generated as |
| 23 | 24 | // a series of `if` statements relying on the optimizer |
| 24 | 25 | // to convert it to a switch. |
| 25 | if (field.value == @intFromEnum(any)) { | |
| 26 | return @field(any, field.name).len; | |
| 26 | if (field_value == @intFromEnum(any)) { | |
| 27 | return @field(any, field_name).len; | |
| 27 | 28 | } |
| 28 | 29 | } |
| 29 | 30 | // 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 | 3 | const expectError = std.testing.expectError; |
| 4 | 4 | |
| 5 | 5 | fn 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 | 7 | return switch (field_index) { |
| 8 | 8 | // This prong is analyzed twice with `idx` being a |
| 9 | 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 | 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 | 3 | var foo: u8 align(4) = 100; |
| 4 | 4 | |
| 5 | 5 | test "global variable alignment" { |
| 6 | try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment); | |
| 6 | try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.attrs.@"align"); | |
| 7 | 7 | try expectEqual(*align(4) u8, @TypeOf(&foo)); |
| 8 | 8 | const as_pointer_to_array: *align(4) [1]u8 = &foo; |
| 9 | 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 | 5 | |
| 6 | 6 | test "variadic function" { |
| 7 | 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 | } |
| 10 | 10 | |
| 11 | 11 | // test |
lib/compiler/Maker/ScannedConfig.zig+4-3| ... | ... | @@ -49,9 +49,10 @@ pub fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | fn printStruct(sc: *const ScannedConfig, s: *Serializer.Struct, comptime S: type, v: S) !void { |
| 52 | inline for (@typeInfo(S).@"struct".fields) |field| { | |
| 53 | try s.fieldPrefix(field.name); | |
| 54 | try printValue(sc, s.container.serializer, field.type, @field(v, field.name)); | |
| 52 | const info = @typeInfo(S).@"struct"; | |
| 53 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 54 | try s.fieldPrefix(field_name); | |
| 55 | try printValue(sc, s.container.serializer, field_type, @field(v, field_name)); | |
| 55 | 56 | } |
| 56 | 57 | } |
| 57 | 58 |
lib/compiler/Maker/Step/FindProgram.zig+2-2| ... | ... | @@ -113,8 +113,8 @@ fn checkCandidate( |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | fn supportedWindowsProgramExtension(ext: []const u8) bool { |
| 116 | inline for (@typeInfo(std.process.WindowsExtension).@"enum".fields) |field| { | |
| 117 | if (std.ascii.eqlIgnoreCase(ext, "." ++ field.name)) return true; | |
| 116 | inline for (@typeInfo(std.process.WindowsExtension).@"enum".field_names) |field_name| { | |
| 117 | if (std.ascii.eqlIgnoreCase(ext, "." ++ field_name)) return true; | |
| 118 | 118 | } |
| 119 | 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 | 87 | errdefer core_services.close(); |
| 88 | 88 | |
| 89 | 89 | var resolved_symbols: ResolvedSymbols = undefined; |
| 90 | inline for (@typeInfo(ResolvedSymbols).@"struct".fields) |f| { | |
| 91 | @field(resolved_symbols, f.name) = core_services.lookup(f.type, f.name) orelse return error.MissingCoreServicesSymbol; | |
| 90 | const info = @typeInfo(ResolvedSymbols).@"struct"; | |
| 91 | inline for (info.field_names, info.field_types) |f_name, f_type| { | |
| 92 | @field(resolved_symbols, f_name) = core_services.lookup(f_type, f_name) orelse return error.MissingCoreServicesSymbol; | |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | 95 | return .{ |
lib/compiler/aro/aro/Attribute.zig+52-51| ... | ... | @@ -89,9 +89,9 @@ pub fn requiredArgCount(attr: Tag) u32 { |
| 89 | 89 | inline else => |tag| { |
| 90 | 90 | comptime var needed = 0; |
| 91 | 91 | comptime { |
| 92 | const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields; | |
| 93 | for (fields) |arg_field| { | |
| 94 | if (!mem.eql(u8, arg_field.name, "__name_tok") and @typeInfo(arg_field.type) != .optional) needed += 1; | |
| 92 | const info = @typeInfo(@field(attributes, @tagName(tag))).@"struct"; | |
| 93 | for (info.field_names, info.field_types) |arg_field_name, arg_field_type| { | |
| 94 | if (!mem.eql(u8, arg_field_name, "__name_tok") and @typeInfo(arg_field_type) != .optional) needed += 1; | |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | return needed; |
| ... | ... | @@ -105,9 +105,9 @@ pub fn maxArgCount(attr: Tag) u32 { |
| 105 | 105 | inline else => |tag| { |
| 106 | 106 | comptime var max = 0; |
| 107 | 107 | comptime { |
| 108 | const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields; | |
| 109 | for (fields) |arg_field| { | |
| 110 | if (!mem.eql(u8, arg_field.name, "__name_tok")) max += 1; | |
| 108 | const field_names = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_names; | |
| 109 | for (field_names) |arg_field_name| { | |
| 110 | if (!mem.eql(u8, arg_field_name, "__name_tok")) max += 1; | |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | return max; |
| ... | ... | @@ -130,10 +130,10 @@ pub const Formatting = struct { |
| 130 | 130 | switch (attr) { |
| 131 | 131 | .calling_convention => unreachable, |
| 132 | 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; | |
| 134 | 134 | |
| 135 | if (fields.len == 0) unreachable; | |
| 136 | const Unwrapped = UnwrapOptional(fields[0].type); | |
| 135 | if (field_types.len == 0) unreachable; | |
| 136 | const Unwrapped = UnwrapOptional(field_types[0]); | |
| 137 | 137 | if (@typeInfo(Unwrapped) != .@"enum") unreachable; |
| 138 | 138 | |
| 139 | 139 | return if (Unwrapped.opts.enum_kind == .identifier) "'" else "\""; |
| ... | ... | @@ -147,18 +147,18 @@ pub const Formatting = struct { |
| 147 | 147 | switch (attr) { |
| 148 | 148 | .calling_convention => unreachable, |
| 149 | 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; | |
| 151 | 151 | |
| 152 | if (fields.len == 0) unreachable; | |
| 153 | const Unwrapped = UnwrapOptional(fields[0].type); | |
| 152 | if (field_types.len == 0) unreachable; | |
| 153 | const Unwrapped = UnwrapOptional(field_types[0]); | |
| 154 | 154 | if (@typeInfo(Unwrapped) != .@"enum") unreachable; |
| 155 | 155 | |
| 156 | const enum_fields = @typeInfo(Unwrapped).@"enum".fields; | |
| 156 | const enum_field_names = @typeInfo(Unwrapped).@"enum".field_names; | |
| 157 | 157 | const quote = comptime quoteChar(@enumFromInt(@intFromEnum(tag))); |
| 158 | comptime var values: []const u8 = quote ++ enum_fields[0].name ++ quote; | |
| 159 | inline for (enum_fields[1..]) |enum_field| { | |
| 158 | comptime var values: []const u8 = quote ++ enum_field_names[0] ++ quote; | |
| 159 | inline for (enum_field_names[1..]) |enum_field_name| { | |
| 160 | 160 | values = values ++ ", "; |
| 161 | values = values ++ quote ++ enum_field.name ++ quote; | |
| 161 | values = values ++ quote ++ enum_field_name ++ quote; | |
| 162 | 162 | } |
| 163 | 163 | return values; |
| 164 | 164 | }, |
| ... | ... | @@ -171,10 +171,10 @@ pub fn wantsIdentEnum(attr: Tag) bool { |
| 171 | 171 | switch (attr) { |
| 172 | 172 | .calling_convention => return false, |
| 173 | 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; | |
| 175 | 175 | |
| 176 | if (fields.len == 0) return false; | |
| 177 | const Unwrapped = UnwrapOptional(fields[0].type); | |
| 176 | if (field_types.len == 0) return false; | |
| 177 | const Unwrapped = UnwrapOptional(field_types[0]); | |
| 178 | 178 | if (@typeInfo(Unwrapped) != .@"enum") return false; |
| 179 | 179 | |
| 180 | 180 | return Unwrapped.opts.enum_kind == .identifier; |
| ... | ... | @@ -185,12 +185,12 @@ pub fn wantsIdentEnum(attr: Tag) bool { |
| 185 | 185 | pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Parser) !bool { |
| 186 | 186 | switch (attr) { |
| 187 | 187 | inline else => |tag| { |
| 188 | const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields; | |
| 189 | if (fields.len == 0) unreachable; | |
| 190 | const Unwrapped = UnwrapOptional(fields[0].type); | |
| 188 | const info = @typeInfo(@field(attributes, @tagName(tag))).@"struct"; | |
| 189 | if (info.field_names.len == 0) unreachable; | |
| 190 | const Unwrapped = UnwrapOptional(info.field_types[0]); | |
| 191 | 191 | if (@typeInfo(Unwrapped) != .@"enum") unreachable; |
| 192 | 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 | 194 | return false; |
| 195 | 195 | } |
| 196 | 196 | |
| ... | ... | @@ -203,11 +203,11 @@ pub fn diagnoseIdent(attr: Tag, arguments: *Arguments, ident: TokenIndex, p: *Pa |
| 203 | 203 | pub fn wantsAlignment(attr: Tag, idx: usize) bool { |
| 204 | 204 | switch (attr) { |
| 205 | 205 | inline else => |tag| { |
| 206 | const fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields; | |
| 207 | if (fields.len == 0) return false; | |
| 206 | const field_types = @typeInfo(@field(attributes, @tagName(tag))).@"struct".field_types; | |
| 207 | if (field_types.len == 0) return false; | |
| 208 | 208 | |
| 209 | 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 | 211 | else => false, |
| 212 | 212 | }; |
| 213 | 213 | }, |
| ... | ... | @@ -217,12 +217,12 @@ pub fn wantsAlignment(attr: Tag, idx: usize) bool { |
| 217 | 217 | pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, p: *Parser) !bool { |
| 218 | 218 | switch (attr) { |
| 219 | 219 | inline else => |tag| { |
| 220 | const arg_fields = @typeInfo(@field(attributes, @tagName(tag))).@"struct".fields; | |
| 221 | if (arg_fields.len == 0) unreachable; | |
| 220 | const arg_info = @typeInfo(@field(attributes, @tagName(tag))).@"struct"; | |
| 221 | if (arg_info.field_names.len == 0) unreachable; | |
| 222 | 222 | |
| 223 | 223 | switch (arg_idx) { |
| 224 | inline 0...arg_fields.len - 1 => |arg_i| { | |
| 225 | if (UnwrapOptional(arg_fields[arg_i].type) != Alignment) unreachable; | |
| 224 | inline 0...arg_info.field_names.len - 1 => |arg_i| { | |
| 225 | if (UnwrapOptional(arg_info.field_types[arg_i]) != Alignment) unreachable; | |
| 226 | 226 | |
| 227 | 227 | if (!res.val.is(.int, p.comp)) { |
| 228 | 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 | 241 | return true; |
| 242 | 242 | } |
| 243 | 243 | |
| 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 | 245 | return false; |
| 246 | 246 | }, |
| 247 | 247 | else => unreachable, |
| ... | ... | @@ -251,8 +251,8 @@ pub fn diagnoseAlignment(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Pa |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | fn diagnoseField( |
| 254 | comptime decl: ZigType.Declaration, | |
| 255 | comptime field: ZigType.StructField, | |
| 254 | comptime decl_name: []const u8, | |
| 255 | comptime field_name: []const u8, | |
| 256 | 256 | comptime Wanted: type, |
| 257 | 257 | arguments: *Arguments, |
| 258 | 258 | res: Parser.Result, |
| ... | ... | @@ -283,7 +283,7 @@ fn diagnoseField( |
| 283 | 283 | |
| 284 | 284 | if (res.val.opt_ref == .none) { |
| 285 | 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 | 287 | return false; |
| 288 | 288 | } |
| 289 | 289 | |
| ... | ... | @@ -294,7 +294,7 @@ fn diagnoseField( |
| 294 | 294 | switch (key) { |
| 295 | 295 | .int => { |
| 296 | 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 | 298 | try p.err(arg_start, .attribute_int_out_of_range, .{res}); |
| 299 | 299 | return true; |
| 300 | 300 | }; |
| ... | ... | @@ -310,20 +310,20 @@ fn diagnoseField( |
| 310 | 310 | .char, .uchar, .schar => {}, |
| 311 | 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 | 314 | return false; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | try p.err(arg_start, .attribute_requires_string, .{decl.name}); | |
| 317 | try p.err(arg_start, .attribute_requires_string, .{decl_name}); | |
| 318 | 318 | return true; |
| 319 | 319 | } else if (@typeInfo(Wanted) == .@"enum" and @hasDecl(Wanted, "opts") and Wanted.opts.enum_kind == .string) { |
| 320 | 320 | const str = bytes[0 .. bytes.len - 1]; |
| 321 | 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 | 323 | return false; |
| 324 | 324 | } |
| 325 | 325 | |
| 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 | 327 | return true; |
| 328 | 328 | } |
| 329 | 329 | }, |
| ... | ... | @@ -344,17 +344,18 @@ fn diagnoseField( |
| 344 | 344 | pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool { |
| 345 | 345 | switch (attr) { |
| 346 | 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 | 348 | const max_arg_count = comptime maxArgCount(tag); |
| 349 | 349 | if (arg_idx >= max_arg_count) { |
| 350 | 350 | try p.err(arg_start, .attribute_too_many_args, .{ @tagName(attr), max_arg_count }); |
| 351 | 351 | return true; |
| 352 | 352 | } |
| 353 | 353 | |
| 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 | 356 | switch (arg_idx) { |
| 356 | inline 0...arg_fields.len - 1 => |arg_i| { | |
| 357 | return diagnoseField(decl, arg_fields[arg_i], UnwrapOptional(arg_fields[arg_i].type), arguments, res, arg_start, node, p); | |
| 357 | inline 0...arg_field_names.len - 1 => |arg_i| { | |
| 358 | return diagnoseField(decl_name, arg_field_names[arg_i], UnwrapOptional(arg_field_types[arg_i]), arguments, res, arg_start, node, p); | |
| 358 | 359 | }, |
| 359 | 360 | else => unreachable, |
| 360 | 361 | } |
| ... | ... | @@ -722,20 +723,20 @@ const attributes = struct { |
| 722 | 723 | pub const Tag = std.meta.DeclEnum(attributes); |
| 723 | 724 | |
| 724 | 725 | pub const Arguments = blk: { |
| 725 | const decls = @typeInfo(attributes).@"struct".decls; | |
| 726 | var names: [decls.len][]const u8 = undefined; | |
| 727 | var types: [decls.len]type = undefined; | |
| 728 | for (decls, &names, &types) |decl, *name, *T| { | |
| 729 | name.* = decl.name; | |
| 730 | T.* = @field(attributes, decl.name); | |
| 726 | const decl_names = @typeInfo(attributes).@"struct".decl_names; | |
| 727 | var names: [decl_names.len][]const u8 = undefined; | |
| 728 | var types: [decl_names.len]type = undefined; | |
| 729 | for (decl_names, &names, &types) |decl_name, *name, *T| { | |
| 730 | name.* = decl_name; | |
| 731 | T.* = @field(attributes, decl_name); | |
| 731 | 732 | } |
| 732 | 733 | |
| 733 | 734 | break :blk @Union(.auto, null, &names, &types, &@splat(.{})); |
| 734 | 735 | }; |
| 735 | 736 | |
| 736 | 737 | pub fn ArgumentsForTag(comptime tag: Tag) type { |
| 737 | const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)]; | |
| 738 | return @field(attributes, decl.name); | |
| 738 | const decl_name = @typeInfo(attributes).@"struct".decl_names[@intFromEnum(tag)]; | |
| 739 | return @field(attributes, decl_name); | |
| 739 | 740 | } |
| 740 | 741 | |
| 741 | 742 | pub 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 | 78 | pub fn loadAll(environ_map: *const std.process.Environ.Map) Environment { |
| 79 | 79 | var env: Environment = .{}; |
| 80 | 80 | |
| 81 | inline for (@typeInfo(@TypeOf(env)).@"struct".fields) |field| { | |
| 82 | std.debug.assert(@field(env, field.name) == null); | |
| 81 | inline for (@typeInfo(@TypeOf(env)).@"struct".field_names) |field_name| { | |
| 82 | std.debug.assert(@field(env, field_name) == null); | |
| 83 | 83 | |
| 84 | var env_var_buf: [field.name.len]u8 = undefined; | |
| 85 | const env_var_name = std.ascii.upperString(&env_var_buf, field.name); | |
| 86 | @field(env, field.name) = environ_map.get(env_var_name); | |
| 84 | var env_var_buf: [field_name.len]u8 = undefined; | |
| 85 | const env_var_name = std.ascii.upperString(&env_var_buf, field_name); | |
| 86 | @field(env, field_name) = environ_map.get(env_var_name); | |
| 87 | 87 | } |
| 88 | 88 | return env; |
| 89 | 89 | } |
lib/compiler/aro/aro/Diagnostics.zig+7-7| ... | ... | @@ -333,8 +333,8 @@ pub fn deinit(d: *Diagnostics) void { |
| 333 | 333 | /// Used by the __has_warning builtin macro. |
| 334 | 334 | pub fn warningExists(name: []const u8) bool { |
| 335 | 335 | if (std.mem.eql(u8, name, "pedantic")) return true; |
| 336 | inline for (comptime std.meta.declarations(Option)) |group| { | |
| 337 | if (std.mem.eql(u8, name, group.name)) return true; | |
| 336 | inline for (comptime std.meta.declarations(Option)) |group_name| { | |
| 337 | if (std.mem.eql(u8, name, group_name)) return true; | |
| 338 | 338 | } |
| 339 | 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 | 349 | return; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | inline for (comptime std.meta.declarations(Option)) |group| { | |
| 353 | if (std.mem.eql(u8, name, group.name)) { | |
| 354 | for (@field(Option, group.name)) |option| { | |
| 352 | inline for (comptime std.meta.declarations(Option)) |group_name| { | |
| 353 | if (std.mem.eql(u8, name, group_name)) { | |
| 354 | for (@field(Option, group_name)) |option| { | |
| 355 | 355 | d.state.options.put(option, to); |
| 356 | 356 | } |
| 357 | 357 | return; |
| ... | ... | @@ -494,8 +494,8 @@ pub fn addWithLocation( |
| 494 | 494 | |
| 495 | 495 | pub fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) std.Io.Writer.Error!void { |
| 496 | 496 | var i: usize = 0; |
| 497 | inline for (std.meta.fields(@TypeOf(args))) |arg_info| { | |
| 498 | const arg = @field(args, arg_info.name); | |
| 497 | inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| { | |
| 498 | const arg = @field(args, arg_name); | |
| 499 | 499 | i += switch (@TypeOf(arg)) { |
| 500 | 500 | []const u8 => try formatString(w, fmt[i..], arg), |
| 501 | 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 | 456 | |
| 457 | 457 | fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !void { |
| 458 | 458 | var i: usize = 0; |
| 459 | inline for (std.meta.fields(@TypeOf(args))) |arg_info| { | |
| 460 | const arg = @field(args, arg_info.name); | |
| 459 | inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| { | |
| 460 | const arg = @field(args, arg_name); | |
| 461 | 461 | i += switch (@TypeOf(arg)) { |
| 462 | 462 | []const u8 => try Diagnostics.formatString(w, fmt[i..], arg), |
| 463 | 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 | 3048 | switch (attr.tag) { |
| 3049 | 3049 | inline else => |tag| { |
| 3050 | 3050 | const args = @field(attr.args, @tagName(tag)); |
| 3051 | const fields = @typeInfo(@TypeOf(args)).@"struct".fields; | |
| 3052 | if (fields.len == 0) { | |
| 3051 | const args_info = @typeInfo(@TypeOf(args)).@"struct"; | |
| 3052 | if (args_info.field_names.len == 0) { | |
| 3053 | 3053 | try w.writeByte('\n'); |
| 3054 | 3054 | return; |
| 3055 | 3055 | } |
| 3056 | 3056 | try w.writeByte(' '); |
| 3057 | inline for (fields, 0..) |f, i| { | |
| 3058 | if (comptime std.mem.eql(u8, f.name, "__name_tok")) continue; | |
| 3057 | inline for (args_info.field_names, args_info.field_types, 0..) |f_name, f_type, i| { | |
| 3058 | if (comptime std.mem.eql(u8, f_name, "__name_tok")) continue; | |
| 3059 | 3059 | if (i != 0) { |
| 3060 | 3060 | try w.writeAll(", "); |
| 3061 | 3061 | } |
| 3062 | try w.writeAll(f.name); | |
| 3062 | try w.writeAll(f_name); | |
| 3063 | 3063 | try w.writeAll(": "); |
| 3064 | switch (f.type) { | |
| 3065 | Interner.Ref => try w.print("\"{s}\"", .{tree.interner.get(@field(args, f.name)).bytes}), | |
| 3066 | ?Interner.Ref => try w.print("\"{?s}\"", .{if (@field(args, f.name)) |str| tree.interner.get(str).bytes else null}), | |
| 3067 | else => switch (@typeInfo(f.type)) { | |
| 3068 | .@"enum" => try w.writeAll(@tagName(@field(args, f.name))), | |
| 3069 | else => try w.print("{any}", .{@field(args, f.name)}), | |
| 3064 | switch (f_type) { | |
| 3065 | Interner.Ref => try w.print("\"{s}\"", .{tree.interner.get(@field(args, f_name)).bytes}), | |
| 3066 | ?Interner.Ref => try w.print("\"{?s}\"", .{if (@field(args, f_name)) |str| tree.interner.get(str).bytes else null}), | |
| 3067 | else => switch (@typeInfo(f_type)) { | |
| 3068 | .@"enum" => try w.writeAll(@tagName(@field(args, f_name))), | |
| 3069 | else => try w.print("{any}", .{@field(args, f_name)}), | |
| 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 | 46 | .c_thread_local = comp.langopts.standard.atLeast(.c11) and comp.target.isTlsSupported(), |
| 47 | 47 | .bounds_attributes = comp.langopts.bounds_safety == .clang, |
| 48 | 48 | }; |
| 49 | inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| { | |
| 50 | if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name); | |
| 49 | inline for (@typeInfo(@TypeOf(list)).@"struct".field_names) |f_name| { | |
| 50 | if (std.mem.eql(u8, f_name, ext)) return @field(list, f_name); | |
| 51 | 51 | } |
| 52 | 52 | return false; |
| 53 | 53 | } |
| ... | ... | @@ -70,8 +70,8 @@ pub fn hasExtension(comp: *Compilation, ext: []const u8) bool { |
| 70 | 70 | .matrix_types = false, // TODO |
| 71 | 71 | .matrix_types_scalar_division = false, // TODO |
| 72 | 72 | }; |
| 73 | inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| { | |
| 74 | if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name); | |
| 73 | inline for (@typeInfo(@TypeOf(list)).@"struct".field_names) |f_name| { | |
| 74 | if (std.mem.eql(u8, f_name, ext)) return @field(list, f_name); | |
| 75 | 75 | } |
| 76 | 76 | return false; |
| 77 | 77 | } |
lib/compiler/aro/aro/text_literal.zig+2-2| ... | ... | @@ -335,8 +335,8 @@ pub const Parser = struct { |
| 335 | 335 | |
| 336 | 336 | fn formatArgs(w: *std.Io.Writer, fmt: []const u8, args: anytype) !void { |
| 337 | 337 | var i: usize = 0; |
| 338 | inline for (std.meta.fields(@TypeOf(args))) |arg_info| { | |
| 339 | const arg = @field(args, arg_info.name); | |
| 338 | inline for (comptime std.meta.fieldNames(@TypeOf(args))) |arg_name| { | |
| 339 | const arg = @field(args, arg_name); | |
| 340 | 340 | i += switch (@TypeOf(arg)) { |
| 341 | 341 | []const u8 => try Diagnostics.formatString(w, fmt[i..], arg), |
| 342 | 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 | 733 | }); |
| 734 | 734 | }, |
| 735 | 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 | 737 | elems.len); |
| 738 | 738 | i.items.appendAssumeCapacity(.{ |
| 739 | 739 | .tag = .record_ty, |
| ... | ... | @@ -755,18 +755,19 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref { |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | fn addExtra(i: *Interner, gpa: Allocator, extra: anytype) Allocator.Error!u32 { |
| 758 | const fields = @typeInfo(@TypeOf(extra)).@"struct".fields; | |
| 759 | try i.extra.ensureUnusedCapacity(gpa, fields.len); | |
| 758 | const field_count = @typeInfo(@TypeOf(extra)).@"struct".field_names.len; | |
| 759 | try i.extra.ensureUnusedCapacity(gpa, field_count); | |
| 760 | 760 | return i.addExtraAssumeCapacity(extra); |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | fn addExtraAssumeCapacity(i: *Interner, extra: anytype) u32 { |
| 764 | 764 | const result = @as(u32, @intCast(i.extra.items.len)); |
| 765 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| { | |
| 766 | i.extra.appendAssumeCapacity(switch (field.type) { | |
| 767 | Ref => @intFromEnum(@field(extra, field.name)), | |
| 768 | u32 => @field(extra, field.name), | |
| 769 | else => @compileError("bad field type: " ++ @typeName(field.type)), | |
| 765 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 766 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 767 | i.extra.appendAssumeCapacity(switch (field_type) { | |
| 768 | Ref => @intFromEnum(@field(extra, field_name)), | |
| 769 | u32 => @field(extra, field_name), | |
| 770 | else => @compileError("bad field type: " ++ @typeName(field_type)), | |
| 770 | 771 | }); |
| 771 | 772 | } |
| 772 | 773 | return result; |
| ... | ... | @@ -891,17 +892,17 @@ fn extraData(i: *const Interner, comptime T: type, index: usize) T { |
| 891 | 892 | |
| 892 | 893 | fn extraDataTrail(i: *const Interner, comptime T: type, index: usize) struct { data: T, end: u32 } { |
| 893 | 894 | var result: T = undefined; |
| 894 | const fields = @typeInfo(T).@"struct".fields; | |
| 895 | inline for (fields, 0..) |field, field_i| { | |
| 895 | const info = @typeInfo(T).@"struct"; | |
| 896 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, field_i| { | |
| 896 | 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 | 899 | Ref => @enumFromInt(int32), |
| 899 | 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 | 904 | return .{ |
| 904 | 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 | 601 | dest_module.* = try addModule(s, src_module); |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".fields[2].name, "import_table")); | |
| 605 | comptime assert(@typeInfo(Configuration.Module).@"struct".fields[2].type == Configuration.ImportTable.Index); | |
| 604 | comptime assert(std.mem.eql(u8, @typeInfo(Configuration.Module).@"struct".field_names[2], "import_table")); | |
| 605 | comptime assert(@typeInfo(Configuration.Module).@"struct".field_types[2] == Configuration.ImportTable.Index); | |
| 606 | 606 | assert(wc.extra.items[@intFromEnum(module_index) + 2] == @intFromEnum(Configuration.ImportTable.Index.invalid)); |
| 607 | 607 | const import_table_index = try wc.addDeduped(Configuration.ImportTable, .{ |
| 608 | 608 | .imports = .{ .mal = imports }, |
lib/compiler/resinator/bmp.zig+3-2| ... | ... | @@ -241,8 +241,9 @@ pub const Compression = enum(u32) { |
| 241 | 241 | }; |
| 242 | 242 | |
| 243 | 243 | fn structFieldsLittleToNative(comptime T: type, x: *T) void { |
| 244 | inline for (@typeInfo(T).@"struct".fields) |field| { | |
| 245 | @field(x, field.name) = std.mem.littleToNative(field.type, @field(x, field.name)); | |
| 244 | const info = @typeInfo(T).@"struct"; | |
| 245 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 246 | @field(x, field_name) = std.mem.littleToNative(field_type, @field(x, field_name)); | |
| 246 | 247 | } |
| 247 | 248 | } |
| 248 | 249 |
lib/compiler/resinator/code_pages.zig+14-12| ... | ... | @@ -178,19 +178,20 @@ pub const UnsupportedCodePage = enum(u16) { |
| 178 | 178 | }; |
| 179 | 179 | |
| 180 | 180 | pub const CodePage = blk: { |
| 181 | const fields = @typeInfo(SupportedCodePage).@"enum".fields ++ @typeInfo(UnsupportedCodePage).@"enum".fields; | |
| 182 | var field_names: [fields.len][]const u8 = undefined; | |
| 183 | var field_values: [fields.len]u16 = undefined; | |
| 184 | for (fields, &field_names, &field_values) |field, *name, *val| { | |
| 185 | name.* = field.name; | |
| 186 | val.* = field.value; | |
| 181 | const field_names = @typeInfo(SupportedCodePage).@"enum".field_names ++ @typeInfo(UnsupportedCodePage).@"enum".field_names; | |
| 182 | const field_values = @typeInfo(SupportedCodePage).@"enum".field_values ++ @typeInfo(UnsupportedCodePage).@"enum".field_values; | |
| 183 | var cp_field_names: [field_names.len][]const u8 = undefined; | |
| 184 | var cp_field_values: [field_names.len]u16 = undefined; | |
| 185 | for (field_names, field_values, &cp_field_names, &cp_field_values) |field_name, field_value, *name, *val| { | |
| 186 | name.* = field_name; | |
| 187 | val.* = field_value; | |
| 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 | }; |
| 190 | 191 | |
| 191 | 192 | pub fn isSupported(code_page: CodePage) bool { |
| 192 | inline for (@typeInfo(SupportedCodePage).@"enum".fields) |enumField| { | |
| 193 | if (@intFromEnum(code_page) == @intFromEnum(@field(SupportedCodePage, enumField.name))) { | |
| 193 | inline for (@typeInfo(SupportedCodePage).@"enum".field_names) |field_name| { | |
| 194 | if (@intFromEnum(code_page) == @intFromEnum(@field(SupportedCodePage, field_name))) { | |
| 194 | 195 | return true; |
| 195 | 196 | } |
| 196 | 197 | } |
| ... | ... | @@ -200,9 +201,10 @@ pub fn isSupported(code_page: CodePage) bool { |
| 200 | 201 | pub fn getByIdentifier(identifier: u16) !CodePage { |
| 201 | 202 | // There's probably a more efficient way to do this (e.g. ComptimeHashMap?) but |
| 202 | 203 | // this should be fine, especially since this function likely won't be called much. |
| 203 | inline for (@typeInfo(CodePage).@"enum".fields) |enumField| { | |
| 204 | if (identifier == enumField.value) { | |
| 205 | return @field(CodePage, enumField.name); | |
| 204 | const info = @typeInfo(CodePage).@"enum"; | |
| 205 | inline for (info.field_names, info.field_values) |field_name, field_value| { | |
| 206 | if (identifier == field_value) { | |
| 207 | return @field(CodePage, field_name); | |
| 206 | 208 | } |
| 207 | 209 | } |
| 208 | 210 | return error.InvalidCodePage; |
lib/compiler/resinator/cvtres.zig+11-10| ... | ... | @@ -1054,17 +1054,18 @@ pub const supported_targets = struct { |
| 1054 | 1054 | .ebc, |
| 1055 | 1055 | }; |
| 1056 | 1056 | comptime { |
| 1057 | for (@typeInfo(Arch).@"enum".fields) |enum_field| { | |
| 1058 | _ = std.mem.indexOfScalar(Arch, ordered_for_display, @enumFromInt(enum_field.value)) orelse { | |
| 1059 | @compileError(std.fmt.comptimePrint("'{s}' missing from ordered_for_display", .{enum_field.name})); | |
| 1057 | const info = @typeInfo(Arch).@"enum"; | |
| 1058 | for (info.field_names, info.field_values) |field_name, field_value| { | |
| 1059 | _ = std.mem.indexOfScalar(Arch, ordered_for_display, @enumFromInt(field_value)) orelse { | |
| 1060 | @compileError(std.fmt.comptimePrint("'{s}' missing from ordered_for_display", .{field_name})); | |
| 1060 | 1061 | }; |
| 1061 | 1062 | } |
| 1062 | 1063 | } |
| 1063 | 1064 | |
| 1064 | 1065 | pub const longest_name = blk: { |
| 1065 | 1066 | var len = 0; |
| 1066 | for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 1067 | if (field.name.len > len) len = field.name.len; | |
| 1067 | for (@typeInfo(Arch).@"enum".field_names) |field_name| { | |
| 1068 | if (field_name.len > len) len = field_name.len; | |
| 1068 | 1069 | } |
| 1069 | 1070 | break :blk len; |
| 1070 | 1071 | }; |
| ... | ... | @@ -1106,14 +1107,14 @@ pub const supported_targets = struct { |
| 1106 | 1107 | // Enforce two things: |
| 1107 | 1108 | // 1. Arch enum field names are all lowercase (necessary for how fromStringIgnoreCase is implemented) |
| 1108 | 1109 | // 2. All enum fields in Arch have an associated RVA relocation type when converted to a coff.IMAGE.FILE.MACHINE |
| 1109 | for (@typeInfo(Arch).@"enum".fields) |enum_field| { | |
| 1110 | const all_lower = all_lower: for (enum_field.name) |c| { | |
| 1110 | for (@typeInfo(Arch).@"enum".field_names) |field_name| { | |
| 1111 | const all_lower = all_lower: for (field_name) |c| { | |
| 1111 | 1112 | if (std.ascii.isUpper(c)) break :all_lower false; |
| 1112 | 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 | const coff_machine = @field(Arch, enum_field.name).toCoffMachineType(); | |
| 1114 | if (!all_lower) @compileError(std.fmt.comptimePrint("Arch field is not all lowercase: {s}", .{field_name})); | |
| 1115 | const coff_machine = @field(Arch, field_name).toCoffMachineType(); | |
| 1115 | 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 | 145 | |
| 146 | 146 | comptime { |
| 147 | 147 | // all fields in the extra union should be 32 bits or less |
| 148 | for (std.meta.fields(Extra)) |field| { | |
| 149 | std.debug.assert(@bitSizeOf(field.type) <= 32); | |
| 148 | for (std.meta.fieldTypes(Extra)) |field_type| { | |
| 149 | std.debug.assert(@bitSizeOf(field_type) <= 32); | |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| ... | ... | @@ -257,18 +257,18 @@ pub const ErrorDetails = struct { |
| 257 | 257 | |
| 258 | 258 | pub fn writeCommaSeparated(self: ExpectedTypes, writer: *std.Io.Writer) !void { |
| 259 | 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 | 261 | const num_padding_bits = @bitSizeOf(ExpectedTypes) - num_real_fields; |
| 262 | 262 | const mask = std.math.maxInt(struct_info.backing_integer.?) >> num_padding_bits; |
| 263 | 263 | const relevant_bits_only = @as(struct_info.backing_integer.?, @bitCast(self)) & mask; |
| 264 | 264 | const num_set_bits = @popCount(relevant_bits_only); |
| 265 | 265 | |
| 266 | 266 | var i: usize = 0; |
| 267 | inline for (struct_info.fields) |field_info| { | |
| 268 | if (field_info.type != bool) continue; | |
| 267 | inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| { | |
| 268 | if (field_type != bool) continue; | |
| 269 | 269 | if (i == num_set_bits) return; |
| 270 | if (@field(self, field_info.name)) { | |
| 271 | try writer.writeAll(strings.get(field_info.name).?); | |
| 270 | if (@field(self, field_name)) { | |
| 271 | try writer.writeAll(strings.get(field_name).?); | |
| 272 | 272 | i += 1; |
| 273 | 273 | if (num_set_bits > 2 and i != num_set_bits) { |
| 274 | 274 | try writer.writeAll(", "); |
| ... | ... | @@ -857,24 +857,20 @@ pub const ErrorDetails = struct { |
| 857 | 857 | |
| 858 | 858 | /// Convenience struct only useful when the code page can be inferred from the token |
| 859 | 859 | pub const ErrorDetailsWithoutCodePage = blk: { |
| 860 | const details_info = @typeInfo(ErrorDetails); | |
| 861 | const fields = details_info.@"struct".fields; | |
| 862 | var field_names: [fields.len - 1][]const u8 = undefined; | |
| 863 | var field_types: [fields.len - 1]type = undefined; | |
| 864 | var field_attrs: [fields.len - 1]std.builtin.Type.StructField.Attributes = undefined; | |
| 860 | const details_info = @typeInfo(ErrorDetails).@"struct"; | |
| 861 | const field_count = details_info.field_names.len; | |
| 862 | var field_names: [field_count - 1][]const u8 = undefined; | |
| 863 | var field_types: [field_count - 1]type = undefined; | |
| 864 | var field_attrs: [field_count - 1]std.builtin.Type.Struct.FieldAttributes = undefined; | |
| 865 | 865 | var i: usize = 0; |
| 866 | for (fields) |field| { | |
| 867 | if (std.mem.eql(u8, field.name, "code_page")) continue; | |
| 868 | field_names[i] = field.name; | |
| 869 | field_types[i] = field.type; | |
| 870 | field_attrs[i] = .{ | |
| 871 | .@"comptime" = field.is_comptime, | |
| 872 | .@"align" = field.alignment, | |
| 873 | .default_value_ptr = field.default_value_ptr, | |
| 874 | }; | |
| 866 | for (details_info.field_names, details_info.field_types, details_info.field_attrs) |field_name, field_type, field_attr| { | |
| 867 | if (std.mem.eql(u8, field_name, "code_page")) continue; | |
| 868 | field_names[i] = field_name; | |
| 869 | field_types[i] = field_type; | |
| 870 | field_attrs[i] = field_attr; | |
| 875 | 871 | i += 1; |
| 876 | 872 | } |
| 877 | std.debug.assert(i == fields.len - 1); | |
| 873 | std.debug.assert(i == field_count - 1); | |
| 878 | 874 | break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs); |
| 879 | 875 | }; |
| 880 | 876 |
lib/compiler/resinator/lang.zig+7-7| ... | ... | @@ -87,8 +87,8 @@ pub fn tagToId(tag: []const u8) error{InvalidLanguageTag}!?LanguageId { |
| 87 | 87 | if (parsed.multiple_suffixes) return null; |
| 88 | 88 | const longest_known_tag = comptime blk: { |
| 89 | 89 | var len = 0; |
| 90 | for (@typeInfo(LanguageId).@"enum".fields) |field| { | |
| 91 | if (field.name.len > len) len = field.name.len; | |
| 90 | for (@typeInfo(LanguageId).@"enum".field_names) |field_name| { | |
| 91 | if (field_name.len > len) len = field_name.len; | |
| 92 | 92 | } |
| 93 | 93 | break :blk len; |
| 94 | 94 | }; |
| ... | ... | @@ -120,13 +120,13 @@ test tagToId { |
| 120 | 120 | |
| 121 | 121 | test "exhaustive tagToId" { |
| 122 | 122 | @setEvalBranchQuota(2000); |
| 123 | inline for (@typeInfo(LanguageId).@"enum".fields) |field| { | |
| 124 | const id = tagToId(field.name) catch |err| { | |
| 125 | std.debug.print("tag: {s}\n", .{field.name}); | |
| 123 | inline for (@typeInfo(LanguageId).@"enum".field_names) |field_name| { | |
| 124 | const id = tagToId(field_name) catch |err| { | |
| 125 | std.debug.print("tag: {s}\n", .{field_name}); | |
| 126 | 126 | return err; |
| 127 | 127 | }; |
| 128 | try std.testing.expectEqual(@field(LanguageId, field.name), id orelse { | |
| 129 | std.debug.print("tag: {s}, got null\n", .{field.name}); | |
| 128 | try std.testing.expectEqual(@field(LanguageId, field_name), id orelse { | |
| 129 | std.debug.print("tag: {s}, got null\n", .{field_name}); | |
| 130 | 130 | return error.TestExpectedEqual; |
| 131 | 131 | }); |
| 132 | 132 | } |
lib/compiler/resinator/parse.zig+1-1| ... | ... | @@ -137,7 +137,7 @@ pub const Parser = struct { |
| 137 | 137 | fn parseOptionalStatements(self: *Self, resource: ResourceType) ![]*Node { |
| 138 | 138 | var optional_statements: std.ArrayList(*Node) = .empty; |
| 139 | 139 | |
| 140 | const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".fields.len; | |
| 140 | const num_statement_types = @typeInfo(rc.OptionalStatements).@"enum".field_names.len; | |
| 141 | 141 | var statement_type_has_duplicates: [num_statement_types]bool = @splat(false); |
| 142 | 142 | var last_statement_per_type: [num_statement_types]?*Node = @splat(null); |
| 143 | 143 |
lib/compiler/translate-c/ast.zig+6-6| ... | ... | @@ -925,18 +925,18 @@ const Context = struct { |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | fn addExtra(c: *Context, extra: anytype) Allocator.Error!std.zig.Ast.ExtraIndex { |
| 928 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 929 | try c.extra_data.ensureUnusedCapacity(c.gpa, fields.len); | |
| 928 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 929 | try c.extra_data.ensureUnusedCapacity(c.gpa, info.field_names.len); | |
| 930 | 930 | const result: std.zig.Ast.ExtraIndex = @enumFromInt(c.extra_data.items.len); |
| 931 | inline for (fields) |field| { | |
| 932 | const data: u32 = switch (field.type) { | |
| 931 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 932 | const data: u32 = switch (field_type) { | |
| 933 | 933 | NodeIndex, |
| 934 | 934 | std.zig.Ast.Node.OptionalIndex, |
| 935 | 935 | std.zig.Ast.OptionalTokenIndex, |
| 936 | 936 | std.zig.Ast.ExtraIndex, |
| 937 | => @intFromEnum(@field(extra, field.name)), | |
| 937 | => @intFromEnum(@field(extra, field_name)), | |
| 938 | 938 | TokenIndex, |
| 939 | => @field(extra, field.name), | |
| 939 | => @field(extra, field_name), | |
| 940 | 940 | else => @compileError("unexpected field type"), |
| 941 | 941 | }; |
| 942 | 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 | 170 | } |
| 171 | 171 | |
| 172 | 172 | pub 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 | 174 | var i: usize = @intFromEnum(index); |
| 175 | 175 | var result: T = undefined; |
| 176 | inline for (fields) |field| { | |
| 177 | @field(result, field.name) = switch (field.type) { | |
| 176 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 177 | @field(result, field_name) = switch (field_type) { | |
| 178 | 178 | u32 => doc.extra[i], |
| 179 | 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 | 1574 | } |
| 1575 | 1575 | |
| 1576 | 1576 | pub 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 | 1578 | var i: usize = @intFromEnum(index); |
| 1579 | 1579 | var result: T = undefined; |
| 1580 | inline for (fields) |field| { | |
| 1581 | @field(result, field.name) = switch (field.type) { | |
| 1580 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1581 | @field(result, field_name) = switch (field_type) { | |
| 1582 | 1582 | u32 => p.extra.items[i], |
| 1583 | 1583 | else => @compileError("bad field type"), |
| 1584 | 1584 | }; |
lib/std/Build.zig+52-53| ... | ... | @@ -389,9 +389,10 @@ fn createChild( |
| 389 | 389 | |
| 390 | 390 | fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap { |
| 391 | 391 | var map = UserInputOptionsMap.init(arena); |
| 392 | inline for (@typeInfo(@TypeOf(args)).@"struct".fields) |field| { | |
| 393 | if (field.type == @TypeOf(null)) continue; | |
| 394 | addUserInputOptionFromArg(arena, &map, field, field.type, @field(args, field.name)); | |
| 392 | const args_info = @typeInfo(@TypeOf(args)).@"struct"; | |
| 393 | inline for (args_info.field_names, args_info.field_types) |field_name, field_type| { | |
| 394 | if (field_type == @TypeOf(null)) continue; | |
| 395 | addUserInputOptionFromArg(arena, &map, field_name, field_type, @field(args, field_name)); | |
| 395 | 396 | } |
| 396 | 397 | return map; |
| 397 | 398 | } |
| ... | ... | @@ -399,15 +400,15 @@ fn userInputOptionsFromArgs(arena: Allocator, args: anytype) UserInputOptionsMap |
| 399 | 400 | fn addUserInputOptionFromArg( |
| 400 | 401 | arena: Allocator, |
| 401 | 402 | map: *UserInputOptionsMap, |
| 402 | field: std.builtin.Type.StructField, | |
| 403 | field_name: [:0]const u8, | |
| 403 | 404 | comptime T: type, |
| 404 | 405 | /// If null, the value won't be added, but `T` will still be type-checked. |
| 405 | 406 | maybe_value: ?T, |
| 406 | 407 | ) void { |
| 407 | 408 | switch (T) { |
| 408 | 409 | Target.Query => return if (maybe_value) |v| { |
| 409 | map.put(field.name, .{ | |
| 410 | .name = field.name, | |
| 410 | map.put(field_name, .{ | |
| 411 | .name = field_name, | |
| 411 | 412 | .value = .{ .scalar = v.zigTriple(arena) catch @panic("OOM") }, |
| 412 | 413 | .used = false, |
| 413 | 414 | }) catch @panic("OOM"); |
| ... | ... | @@ -418,8 +419,8 @@ fn addUserInputOptionFromArg( |
| 418 | 419 | }) catch @panic("OOM"); |
| 419 | 420 | }, |
| 420 | 421 | ResolvedTarget => return if (maybe_value) |v| { |
| 421 | map.put(field.name, .{ | |
| 422 | .name = field.name, | |
| 422 | map.put(field_name, .{ | |
| 423 | .name = field_name, | |
| 423 | 424 | .value = .{ .scalar = v.query.zigTriple(arena) catch @panic("OOM") }, |
| 424 | 425 | .used = false, |
| 425 | 426 | }) catch @panic("OOM"); |
| ... | ... | @@ -430,15 +431,15 @@ fn addUserInputOptionFromArg( |
| 430 | 431 | }) catch @panic("OOM"); |
| 431 | 432 | }, |
| 432 | 433 | std.zig.BuildId => return if (maybe_value) |v| { |
| 433 | map.put(field.name, .{ | |
| 434 | .name = field.name, | |
| 434 | map.put(field_name, .{ | |
| 435 | .name = field_name, | |
| 435 | 436 | .value = .{ .scalar = std.fmt.allocPrint(arena, "{f}", .{v}) catch @panic("OOM") }, |
| 436 | 437 | .used = false, |
| 437 | 438 | }) catch @panic("OOM"); |
| 438 | 439 | }, |
| 439 | 440 | LazyPath => return if (maybe_value) |v| { |
| 440 | map.put(field.name, .{ | |
| 441 | .name = field.name, | |
| 441 | map.put(field_name, .{ | |
| 442 | .name = field_name, | |
| 442 | 443 | .value = .{ .lazy_path = v.dupeInner(arena) }, |
| 443 | 444 | .used = false, |
| 444 | 445 | }) catch @panic("OOM"); |
| ... | ... | @@ -446,15 +447,15 @@ fn addUserInputOptionFromArg( |
| 446 | 447 | []const LazyPath => return if (maybe_value) |v| { |
| 447 | 448 | var list = std.array_list.Managed(LazyPath).initCapacity(arena, v.len) catch @panic("OOM"); |
| 448 | 449 | for (v) |lp| list.appendAssumeCapacity(lp.dupeInner(arena)); |
| 449 | map.put(field.name, .{ | |
| 450 | .name = field.name, | |
| 450 | map.put(field_name, .{ | |
| 451 | .name = field_name, | |
| 451 | 452 | .value = .{ .lazy_path_list = list }, |
| 452 | 453 | .used = false, |
| 453 | 454 | }) catch @panic("OOM"); |
| 454 | 455 | }, |
| 455 | 456 | []const u8 => return if (maybe_value) |v| { |
| 456 | map.put(field.name, .{ | |
| 457 | .name = field.name, | |
| 457 | map.put(field_name, .{ | |
| 458 | .name = field_name, | |
| 458 | 459 | .value = .{ .scalar = arena.dupe(u8, v) catch @panic("OOM") }, |
| 459 | 460 | .used = false, |
| 460 | 461 | }) catch @panic("OOM"); |
| ... | ... | @@ -462,37 +463,37 @@ fn addUserInputOptionFromArg( |
| 462 | 463 | []const []const u8 => return if (maybe_value) |v| { |
| 463 | 464 | var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM"); |
| 464 | 465 | for (v) |s| list.appendAssumeCapacity(arena.dupe(u8, s) catch @panic("OOM")); |
| 465 | map.put(field.name, .{ | |
| 466 | .name = field.name, | |
| 466 | map.put(field_name, .{ | |
| 467 | .name = field_name, | |
| 467 | 468 | .value = .{ .list = list }, |
| 468 | 469 | .used = false, |
| 469 | 470 | }) catch @panic("OOM"); |
| 470 | 471 | }, |
| 471 | 472 | else => switch (@typeInfo(T)) { |
| 472 | 473 | .bool => return if (maybe_value) |v| { |
| 473 | map.put(field.name, .{ | |
| 474 | .name = field.name, | |
| 474 | map.put(field_name, .{ | |
| 475 | .name = field_name, | |
| 475 | 476 | .value = .{ .scalar = if (v) "true" else "false" }, |
| 476 | 477 | .used = false, |
| 477 | 478 | }) catch @panic("OOM"); |
| 478 | 479 | }, |
| 479 | 480 | .@"enum", .enum_literal => return if (maybe_value) |v| { |
| 480 | map.put(field.name, .{ | |
| 481 | .name = field.name, | |
| 481 | map.put(field_name, .{ | |
| 482 | .name = field_name, | |
| 482 | 483 | .value = .{ .scalar = @tagName(v) }, |
| 483 | 484 | .used = false, |
| 484 | 485 | }) catch @panic("OOM"); |
| 485 | 486 | }, |
| 486 | 487 | .comptime_int, .int => return if (maybe_value) |v| { |
| 487 | map.put(field.name, .{ | |
| 488 | .name = field.name, | |
| 488 | map.put(field_name, .{ | |
| 489 | .name = field_name, | |
| 489 | 490 | .value = .{ .scalar = std.fmt.allocPrint(arena, "{d}", .{v}) catch @panic("OOM") }, |
| 490 | 491 | .used = false, |
| 491 | 492 | }) catch @panic("OOM"); |
| 492 | 493 | }, |
| 493 | 494 | .comptime_float, .float => return if (maybe_value) |v| { |
| 494 | map.put(field.name, .{ | |
| 495 | .name = field.name, | |
| 495 | map.put(field_name, .{ | |
| 496 | .name = field_name, | |
| 496 | 497 | .value = .{ .scalar = std.fmt.allocPrint(arena, "{x}", .{v}) catch @panic("OOM") }, |
| 497 | 498 | .used = false, |
| 498 | 499 | }) catch @panic("OOM"); |
| ... | ... | @@ -503,7 +504,7 @@ fn addUserInputOptionFromArg( |
| 503 | 504 | addUserInputOptionFromArg( |
| 504 | 505 | arena, |
| 505 | 506 | map, |
| 506 | field, | |
| 507 | field_name, | |
| 507 | 508 | @Pointer(.slice, .{ .@"const" = true }, array_info.child, null), |
| 508 | 509 | maybe_value orelse null, |
| 509 | 510 | ); |
| ... | ... | @@ -515,8 +516,8 @@ fn addUserInputOptionFromArg( |
| 515 | 516 | .@"enum" => return if (maybe_value) |v| { |
| 516 | 517 | var list = std.array_list.Managed([]const u8).initCapacity(arena, v.len) catch @panic("OOM"); |
| 517 | 518 | for (v) |tag| list.appendAssumeCapacity(@tagName(tag)); |
| 518 | map.put(field.name, .{ | |
| 519 | .name = field.name, | |
| 519 | map.put(field_name, .{ | |
| 520 | .name = field_name, | |
| 520 | 521 | .value = .{ .list = list }, |
| 521 | 522 | .used = false, |
| 522 | 523 | }) catch @panic("OOM"); |
| ... | ... | @@ -525,7 +526,7 @@ fn addUserInputOptionFromArg( |
| 525 | 526 | addUserInputOptionFromArg( |
| 526 | 527 | arena, |
| 527 | 528 | map, |
| 528 | field, | |
| 529 | field_name, | |
| 529 | 530 | @Pointer(ptr_info.size, .{ .@"const" = true }, ptr_info.child, null), |
| 530 | 531 | maybe_value orelse null, |
| 531 | 532 | ); |
| ... | ... | @@ -541,7 +542,7 @@ fn addUserInputOptionFromArg( |
| 541 | 542 | addUserInputOptionFromArg( |
| 542 | 543 | arena, |
| 543 | 544 | map, |
| 544 | field, | |
| 545 | field_name, | |
| 545 | 546 | info.child, |
| 546 | 547 | maybe_value orelse null, |
| 547 | 548 | ); |
| ... | ... | @@ -551,7 +552,7 @@ fn addUserInputOptionFromArg( |
| 551 | 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 | } |
| 556 | 557 | |
| 557 | 558 | const OrderedUserValue = union(enum) { |
| ... | ... | @@ -1114,11 +1115,11 @@ pub fn option(b: *Build, comptime T: type, name_raw: []const u8, description_raw |
| 1114 | 1115 | const type_id = comptime typeToEnum(T); |
| 1115 | 1116 | const enum_options = if (type_id == .@"enum" or type_id == .enum_list) blk: { |
| 1116 | 1117 | const EnumType = if (type_id == .enum_list) @typeInfo(T).pointer.child else T; |
| 1117 | const fields = comptime std.meta.fields(EnumType); | |
| 1118 | var options = std.array_list.Managed([]const u8).initCapacity(arena, fields.len) catch @panic("OOM"); | |
| 1118 | const field_names = comptime std.meta.fieldNames(EnumType); | |
| 1119 | var options = std.array_list.Managed([]const u8).initCapacity(b.allocator, field_names.len) catch @panic("OOM"); | |
| 1119 | 1120 | |
| 1120 | inline for (fields) |field| { | |
| 1121 | options.appendAssumeCapacity(field.name); | |
| 1121 | inline for (field_names) |field_name| { | |
| 1122 | options.appendAssumeCapacity(field_name); | |
| 1122 | 1123 | } |
| 1123 | 1124 | |
| 1124 | 1125 | break :blk options.toOwnedSlice() catch @panic("OOM"); |
| ... | ... | @@ -1407,8 +1408,8 @@ pub fn parseTargetQuery(options: std.Target.Query.ParseOptions) error{ParseFaile |
| 1407 | 1408 | \\available operating systems: |
| 1408 | 1409 | \\ |
| 1409 | 1410 | , .{diags.os_name.?}); |
| 1410 | inline for (std.meta.fields(Target.Os.Tag)) |field| { | |
| 1411 | std.debug.print(" {s}\n", .{field.name}); | |
| 1411 | inline for (comptime std.meta.fieldNames(Target.Os.Tag)) |field_name| { | |
| 1412 | std.debug.print(" {s}\n", .{field_name}); | |
| 1412 | 1413 | } |
| 1413 | 1414 | return error.ParseFailed; |
| 1414 | 1415 | }, |
| ... | ... | @@ -1811,8 +1812,8 @@ pub fn findProgram(b: *Build, options: FindProgramOptions) ?[]const u8 { |
| 1811 | 1812 | } |
| 1812 | 1813 | |
| 1813 | 1814 | fn supportedWindowsProgramExtension(ext: []const u8) bool { |
| 1814 | inline for (@typeInfo(std.process.WindowsExtension).@"enum".fields) |field| { | |
| 1815 | if (std.ascii.eqlIgnoreCase(ext, "." ++ field.name)) return true; | |
| 1815 | inline for (@typeInfo(std.process.WindowsExtension).@"enum".field_names) |field_name| { | |
| 1816 | if (std.ascii.eqlIgnoreCase(ext, "." ++ field_name)) return true; | |
| 1816 | 1817 | } |
| 1817 | 1818 | return false; |
| 1818 | 1819 | } |
| ... | ... | @@ -2072,8 +2073,7 @@ inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, c |
| 2072 | 2073 | const deps = build_runner.dependencies; |
| 2073 | 2074 | const arena = b.graph.arena; |
| 2074 | 2075 | |
| 2075 | const b_pkg_hash, const b_pkg_deps = comptime for (@typeInfo(deps.packages).@"struct".decls) |decl| { | |
| 2076 | const pkg_hash = decl.name; | |
| 2076 | const b_pkg_hash, const b_pkg_deps = comptime for (@typeInfo(deps.packages).@"struct".decl_names) |pkg_hash| { | |
| 2077 | 2077 | const pkg = @field(deps.packages, pkg_hash); |
| 2078 | 2078 | if (@hasDecl(pkg, "build_zig") and pkg.build_zig == asking_build_zig) break .{ pkg_hash, pkg.deps }; |
| 2079 | 2079 | } else .{ "", deps.root_deps }; |
| ... | ... | @@ -2116,9 +2116,9 @@ pub fn lazyDependency(b: *Build, name: []const u8, args: anytype) ?*Dependency { |
| 2116 | 2116 | const deps = build_runner.dependencies; |
| 2117 | 2117 | const pkg_hash = findPkgHashOrFatal(b, name); |
| 2118 | 2118 | |
| 2119 | inline for (@typeInfo(deps.packages).@"struct".decls) |decl| { | |
| 2120 | if (mem.eql(u8, decl.name, pkg_hash)) { | |
| 2121 | const pkg = @field(deps.packages, decl.name); | |
| 2119 | inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| { | |
| 2120 | if (mem.eql(u8, decl_name, pkg_hash)) { | |
| 2121 | const pkg = @field(deps.packages, decl_name); | |
| 2122 | 2122 | const available = !@hasDecl(pkg, "available") or pkg.available; |
| 2123 | 2123 | if (!available) { |
| 2124 | 2124 | markNeededLazyDep(b, pkg_hash); |
| ... | ... | @@ -2136,9 +2136,9 @@ pub fn dependency(b: *Build, name: []const u8, args: anytype) *Dependency { |
| 2136 | 2136 | const deps = build_runner.dependencies; |
| 2137 | 2137 | const pkg_hash = findPkgHashOrFatal(b, name); |
| 2138 | 2138 | |
| 2139 | inline for (@typeInfo(deps.packages).@"struct".decls) |decl| { | |
| 2140 | if (mem.eql(u8, decl.name, pkg_hash)) { | |
| 2141 | const pkg = @field(deps.packages, decl.name); | |
| 2139 | inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| { | |
| 2140 | if (mem.eql(u8, decl_name, pkg_hash)) { | |
| 2141 | const pkg = @field(deps.packages, decl_name); | |
| 2142 | 2142 | if (@hasDecl(pkg, "available")) { |
| 2143 | 2143 | 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 }); |
| 2144 | 2144 | } |
| ... | ... | @@ -2166,9 +2166,9 @@ pub inline fn lazyImport( |
| 2166 | 2166 | const deps = build_runner.dependencies; |
| 2167 | 2167 | const pkg_hash = findImportPkgHashOrFatal(b, asking_build_zig, dep_name); |
| 2168 | 2168 | |
| 2169 | inline for (@typeInfo(deps.packages).@"struct".decls) |decl| { | |
| 2170 | if (comptime mem.eql(u8, decl.name, pkg_hash)) { | |
| 2171 | const pkg = @field(deps.packages, decl.name); | |
| 2169 | inline for (@typeInfo(deps.packages).@"struct".decl_names) |decl_name| { | |
| 2170 | if (comptime mem.eql(u8, decl_name, pkg_hash)) { | |
| 2171 | const pkg = @field(deps.packages, decl_name); | |
| 2172 | 2172 | const available = !@hasDecl(pkg, "available") or pkg.available; |
| 2173 | 2173 | if (!available) { |
| 2174 | 2174 | markNeededLazyDep(b, pkg_hash); |
| ... | ... | @@ -2197,8 +2197,7 @@ pub fn dependencyFromBuildZig( |
| 2197 | 2197 | const arena = graph.arena; |
| 2198 | 2198 | |
| 2199 | 2199 | find_dep: { |
| 2200 | const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).@"struct".decls) |decl| { | |
| 2201 | const pkg_hash = decl.name; | |
| 2200 | const pkg, const pkg_hash = inline for (@typeInfo(deps.packages).@"struct".decl_names) |pkg_hash| { | |
| 2202 | 2201 | const pkg = @field(deps.packages, pkg_hash); |
| 2203 | 2202 | if (@hasDecl(pkg, "build_zig") and pkg.build_zig == build_zig) break .{ pkg, pkg_hash }; |
| 2204 | 2203 | } else break :find_dep; |
lib/std/Build/Cache.zig+2-2| ... | ... | @@ -1241,7 +1241,7 @@ pub const Manifest = struct { |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 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 | 1245 | buf.clearRetainingCapacity(); |
| 1246 | 1246 | const gpa = man.cache.gpa; |
| 1247 | 1247 | const files = man.files.keys(); |
| ... | ... | @@ -1259,7 +1259,7 @@ pub const Manifest = struct { |
| 1259 | 1259 | |
| 1260 | 1260 | pub fn populateOtherManifest(man: *Manifest, other: *Manifest, prefix_map: [4]u8) Allocator.Error!void { |
| 1261 | 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 | 1263 | assert(man.cache.prefixes_len == 4); |
| 1264 | 1264 | for (man.files.keys()) |file| { |
| 1265 | 1265 | const prefixed_path: PrefixedPath = .{ |
lib/std/Build/Configuration.zig+19-16| ... | ... | @@ -2884,7 +2884,10 @@ pub const Storage = enum { |
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | 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 | 2891 | const base_flags: BaseFlags = @bitCast(c.extra[@intFromEnum(this)]); |
| 2889 | 2892 | if (base_flags.tag != wanted_tag) return null; |
| 2890 | 2893 | var i: usize = @intFromEnum(this); |
| ... | ... | @@ -3047,8 +3050,8 @@ pub const Storage = enum { |
| 3047 | 3050 | switch (@typeInfo(T)) { |
| 3048 | 3051 | .@"struct" => |info| { |
| 3049 | 3052 | var result: T = undefined; |
| 3050 | inline for (info.fields) |field| { | |
| 3051 | @field(result, field.name) = dataField(buffer, i, &result, field.type); | |
| 3053 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 3054 | @field(result, field_name) = dataField(buffer, i, &result, field_type); | |
| 3052 | 3055 | } |
| 3053 | 3056 | return result; |
| 3054 | 3057 | }, |
| ... | ... | @@ -3058,7 +3061,7 @@ pub const Storage = enum { |
| 3058 | 3061 | inline else => |comptime_tag| @unionInit( |
| 3059 | 3062 | T, |
| 3060 | 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 | 3128 | buffer, |
| 3126 | 3129 | i, |
| 3127 | 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 | 3170 | .multi_list => { |
| 3168 | 3171 | const data_start = i.* + 1; |
| 3169 | 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 | 3174 | return .{ .mal = .{ |
| 3172 | 3175 | .bytes = @ptrCast(@constCast(buffer[data_start..][0..len])), |
| 3173 | 3176 | .len = len, |
| ... | ... | @@ -3205,10 +3208,10 @@ pub const Storage = enum { |
| 3205 | 3208 | |
| 3206 | 3209 | /// Returns new end index. |
| 3207 | 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 | 3212 | var i = index; |
| 3210 | inline for (fields) |field| { | |
| 3211 | i += setExtraField(buffer, i, field.type, @field(extra, field.name)); | |
| 3213 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 3214 | i += setExtraField(buffer, i, field_type, @field(extra, field_name)); | |
| 3212 | 3215 | } |
| 3213 | 3216 | return i; |
| 3214 | 3217 | } |
| ... | ... | @@ -3236,7 +3239,7 @@ pub const Storage = enum { |
| 3236 | 3239 | .flag_length_prefixed_list, |
| 3237 | 3240 | .flag_list, |
| 3238 | 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 | 3243 | .union_list => Field.extraLen(field.len), |
| 3241 | 3244 | .flag_union => switch (field.u) { |
| 3242 | 3245 | inline else => |v| extraFieldLen(v), |
| ... | ... | @@ -3249,10 +3252,10 @@ pub const Storage = enum { |
| 3249 | 3252 | } |
| 3250 | 3253 | |
| 3251 | 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 | 3256 | var i: usize = 0; |
| 3254 | inline for (fields) |field| { | |
| 3255 | i += Storage.extraFieldLen(@field(extra, field.name)); | |
| 3257 | inline for (field_names) |name| { | |
| 3258 | i += Storage.extraFieldLen(@field(extra, name)); | |
| 3256 | 3259 | } |
| 3257 | 3260 | return i; |
| 3258 | 3261 | } |
| ... | ... | @@ -3324,12 +3327,12 @@ pub const Storage = enum { |
| 3324 | 3327 | .multi_list => { |
| 3325 | 3328 | const len: u32 = @intCast(value.mal.len); |
| 3326 | 3329 | buffer[i] = len; |
| 3327 | const fields = @typeInfo(Field.Elem).@"struct".fields; | |
| 3328 | inline for (0..fields.len) |field_i| @memcpy( | |
| 3330 | const field_names = @typeInfo(Field.Elem).@"struct".field_names; | |
| 3331 | inline for (0..field_names.len) |field_i| @memcpy( | |
| 3329 | 3332 | buffer[i + 1 + field_i * len ..][0..len], |
| 3330 | 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 | 3337 | .union_list => { |
| 3335 | 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 | 173 | } |
| 174 | 174 | |
| 175 | 175 | pub fn addValues(config_header: *ConfigHeader, values: anytype) void { |
| 176 | inline for (@typeInfo(@TypeOf(values)).@"struct".fields) |field| { | |
| 177 | addValue(config_header, field.name, field.type, @field(values, field.name)); | |
| 176 | const info = @typeInfo(@TypeOf(values)).@"struct"; | |
| 177 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 178 | addValue(config_header, field_name, field_type, @field(values, field_name)); | |
| 178 | 179 | } |
| 179 | 180 | } |
| 180 | 181 |
lib/std/Build/Step/Options.zig+28-22| ... | ... | @@ -299,14 +299,14 @@ fn printEnum( |
| 299 | 299 | try out.appendNTimes(gpa, ' ', indent); |
| 300 | 300 | try out.print(gpa, "pub const {f} = enum ({s}) {{\n", .{ std.zig.fmtId(@typeName(T)), @typeName(val.tag_type) }); |
| 301 | 301 | |
| 302 | inline for (val.fields) |field| { | |
| 302 | inline for (val.field_names, val.field_values) |field_name, field_value| { | |
| 303 | 303 | try out.appendNTimes(gpa, ' ', indent); |
| 304 | 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 | } |
| 308 | 308 | |
| 309 | if (!val.is_exhaustive) { | |
| 309 | if (val.mode == .nonexhaustive) { | |
| 310 | 310 | try out.appendNTimes(gpa, ' ', indent); |
| 311 | 311 | try out.appendSlice(gpa, " _,\n"); |
| 312 | 312 | } |
| ... | ... | @@ -315,7 +315,13 @@ fn printEnum( |
| 315 | 315 | try out.appendSlice(gpa, "};\n"); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, comptime val: std.builtin.Type.Struct, indent: u8) !void { | |
| 318 | fn 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 | 325 | const gpa = options.step.owner.allocator; |
| 320 | 326 | const gop = try options.encountered_types.getOrPut(gpa, @typeName(T)); |
| 321 | 327 | if (gop.found_existing) return; |
| ... | ... | @@ -331,32 +337,32 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com |
| 331 | 337 | |
| 332 | 338 | try out.appendSlice(gpa, " {\n"); |
| 333 | 339 | |
| 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 | 341 | try out.appendNTimes(gpa, ' ', indent); |
| 336 | 342 | |
| 337 | const type_name = @typeName(field.type); | |
| 343 | const type_name = @typeName(field_type); | |
| 338 | 344 | |
| 339 | 345 | // If the type name doesn't contains a '.' the type is from zig builtins. |
| 340 | 346 | if (std.mem.containsAtLeast(u8, type_name, 1, ".")) { |
| 341 | 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 | 349 | std.zig.fmtId(type_name), |
| 344 | 350 | }); |
| 345 | 351 | } else { |
| 346 | 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 | 354 | type_name, |
| 349 | 355 | }); |
| 350 | 356 | } |
| 351 | 357 | |
| 352 | if (field.defaultValue()) |default_value| { | |
| 358 | if (field_attrs.defaultValue(field_type)) |default_value| { | |
| 353 | 359 | try out.appendSlice(gpa, " = "); |
| 354 | switch (@typeInfo(@TypeOf(default_value))) { | |
| 360 | switch (@typeInfo(field_type)) { | |
| 355 | 361 | .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(default_value)}), |
| 356 | 362 | .@"struct" => |info| { |
| 357 | 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 | 367 | } else { |
| 362 | 368 | try out.appendSlice(gpa, ",\n"); |
| ... | ... | @@ -368,8 +374,8 @@ fn printStruct(options: *Options, out: *std.ArrayList(u8), comptime T: type, com |
| 368 | 374 | try out.appendNTimes(gpa, ' ', indent); |
| 369 | 375 | try out.appendSlice(gpa, "};\n"); |
| 370 | 376 | |
| 371 | inline for (val.fields) |field| { | |
| 372 | try printUserDefinedType(options, out, field.type, 0); | |
| 377 | inline for (val.field_types) |field_type| { | |
| 378 | try printUserDefinedType(options, out, field_type, 0); | |
| 373 | 379 | } |
| 374 | 380 | } |
| 375 | 381 | |
| ... | ... | @@ -384,24 +390,24 @@ fn printStructValue( |
| 384 | 390 | try out.appendSlice(gpa, ".{\n"); |
| 385 | 391 | |
| 386 | 392 | if (struct_val.is_tuple) { |
| 387 | inline for (struct_val.fields) |field| { | |
| 393 | inline for (struct_val.field_names) |field_name| { | |
| 388 | 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 | 397 | } else { |
| 392 | inline for (struct_val.fields) |field| { | |
| 398 | inline for (struct_val.field_names) |field_name| { | |
| 393 | 399 | try out.appendNTimes(gpa, ' ', indent); |
| 394 | 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 | }); |
| 397 | 403 | |
| 398 | const field_name = @field(val, field.name); | |
| 399 | switch (@typeInfo(@TypeOf(field_name))) { | |
| 400 | .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_name)}), | |
| 404 | const field_val = @field(val, field_name); | |
| 405 | switch (@typeInfo(@TypeOf(field_val))) { | |
| 406 | .@"enum" => try out.print(gpa, ".{s},\n", .{@tagName(field_val)}), | |
| 401 | 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 | 396 | }; |
| 397 | 397 | |
| 398 | 398 | pub const Result = Result: { |
| 399 | const operation_fields = @typeInfo(Operation).@"union".fields; | |
| 400 | var field_names: [operation_fields.len][]const u8 = undefined; | |
| 401 | var field_types: [operation_fields.len]type = undefined; | |
| 402 | for (operation_fields, &field_names, &field_types) |field, *field_name, *field_type| { | |
| 403 | field_name.* = field.name; | |
| 404 | field_type.* = if (field.type == noreturn) noreturn else field.type.Result; | |
| 399 | const operation_info = @typeInfo(Operation).@"union"; | |
| 400 | const operation_count = operation_info.field_names.len; | |
| 401 | var field_names: [operation_count][]const u8 = undefined; | |
| 402 | var field_types: [operation_count]type = undefined; | |
| 403 | for (operation_info.field_names, operation_info.field_types, &field_names, &field_types) |f_name, f_type, *field_name, *field_type| { | |
| 404 | field_name.* = f_name; | |
| 405 | field_type.* = if (f_type == noreturn) noreturn else f_type.Result; | |
| 405 | 406 | } |
| 406 | 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 | 1277 | /// Asserts the buffer was initialized with a capacity at least `@sizeOf(Enum)`. |
| 1278 | 1278 | pub fn takeEnumNonexhaustive(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Error!Enum { |
| 1279 | 1279 | const info = @typeInfo(Enum).@"enum"; |
| 1280 | comptime assert(!info.is_exhaustive); | |
| 1280 | comptime assert(info.mode != .exhaustive); | |
| 1281 | 1281 | comptime assert(@bitSizeOf(info.tag_type) == @sizeOf(info.tag_type) * 8); |
| 1282 | 1282 | return takeEnum(r, Enum, endian) catch |err| switch (err) { |
| 1283 | 1283 | error.InvalidEnumTag => unreachable, |
lib/std/Io/Threaded.zig+10-10| ... | ... | @@ -332,8 +332,8 @@ pub const Environ = struct { |
| 332 | 332 | .flags = .{ .nonblocking = true }, |
| 333 | 333 | }; |
| 334 | 334 | }; |
| 335 | } else inline for (@typeInfo(String).@"struct".fields) |field| { | |
| 336 | if (std.mem.eql(u8, key, field.name)) @field(environ.string, field.name) = value; | |
| 335 | } else inline for (@typeInfo(String).@"struct".field_names) |field_name| { | |
| 336 | if (std.mem.eql(u8, key, field_name)) @field(environ.string, field_name) = value; | |
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | } |
| ... | ... | @@ -11785,8 +11785,8 @@ fn sleepWasi(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void { |
| 11785 | 11785 | |
| 11786 | 11786 | fn sleepNanosleep(t: *Threaded, timeout: Io.Timeout) Io.Cancelable!void { |
| 11787 | 11787 | const t_io = io(t); |
| 11788 | const sec_type = @typeInfo(posix.timespec).@"struct".fields[0].type; | |
| 11789 | const nsec_type = @typeInfo(posix.timespec).@"struct".fields[1].type; | |
| 11788 | const sec_type = @typeInfo(posix.timespec).@"struct".field_types[0]; | |
| 11789 | const nsec_type = @typeInfo(posix.timespec).@"struct".field_types[1]; | |
| 11790 | 11790 | |
| 11791 | 11791 | var timespec: posix.timespec = t: { |
| 11792 | 11792 | const d = timeout.toDurationFromNow(t_io) orelse break :t .{ |
| ... | ... | @@ -14923,9 +14923,9 @@ const WindowsEnvironStrings = struct { |
| 14923 | 14923 | |
| 14924 | 14924 | i += 1; // skip over null byte |
| 14925 | 14925 | |
| 14926 | inline for (@typeInfo(WindowsEnvironStrings).@"struct".fields) |field| { | |
| 14927 | const field_name_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(field.name); | |
| 14928 | if (windows.eqlIgnoreCaseWtf16(key_w, field_name_w)) @field(result, field.name) = value_w; | |
| 14926 | inline for (@typeInfo(WindowsEnvironStrings).@"struct".field_names) |field_name| { | |
| 14927 | const field_name_w = comptime std.unicode.wtf8ToWtf16LeStringLiteral(field_name); | |
| 14928 | if (windows.eqlIgnoreCaseWtf16(key_w, field_name_w)) @field(result, field_name) = value_w; | |
| 14929 | 14929 | } |
| 14930 | 14930 | } |
| 14931 | 14931 | |
| ... | ... | @@ -16190,7 +16190,7 @@ fn windowsCreateProcessPathExt( |
| 16190 | 16190 | } |
| 16191 | 16191 | var io_status: windows.IO_STATUS_BLOCK = undefined; |
| 16192 | 16192 | |
| 16193 | const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".fields.len; | |
| 16193 | const num_supported_pathext = @typeInfo(process.WindowsExtension).@"enum".field_names.len; | |
| 16194 | 16194 | var pathext_seen: [num_supported_pathext]bool = @splat(false); |
| 16195 | 16195 | var any_pathext_seen = false; |
| 16196 | 16196 | var unappended_exists = false; |
| ... | ... | @@ -16435,8 +16435,8 @@ fn windowsCreateProcess( |
| 16435 | 16435 | fn windowsCreateProcessSupportsExtension(ext: []const u16) ?process.WindowsExtension { |
| 16436 | 16436 | comptime { |
| 16437 | 16437 | // Ensures keeping this function in sync with the enum. |
| 16438 | const fields = @typeInfo(process.WindowsExtension).@"enum".fields; | |
| 16439 | assert(fields.len == 4); | |
| 16438 | const field_names = @typeInfo(process.WindowsExtension).@"enum".field_names; | |
| 16439 | assert(field_names.len == 4); | |
| 16440 | 16440 | assert(@intFromEnum(process.WindowsExtension.bat) == 0); |
| 16441 | 16441 | assert(@intFromEnum(process.WindowsExtension.cmd) == 1); |
| 16442 | 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 | 620 | @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType)); |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | const fields_info = args_type_info.@"struct".fields; | |
| 623 | const field_names = args_type_info.@"struct".field_names; | |
| 624 | 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 | 626 | @compileError("32 arguments max are supported per format call"); |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 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 | 631 | comptime var i = 0; |
| 632 | 632 | comptime var literal: []const u8 = ""; |
| 633 | 633 | inline while (true) { |
| ... | ... | @@ -728,7 +728,7 @@ pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void { |
| 728 | 728 | .width = width, |
| 729 | 729 | .precision = precision, |
| 730 | 730 | }, |
| 731 | @field(args, fields_info[arg_to_print].name), | |
| 731 | @field(args, field_names[arg_to_print]), | |
| 732 | 732 | std.options.fmt_max_depth, |
| 733 | 733 | ); |
| 734 | 734 | } |
| ... | ... | @@ -1290,7 +1290,7 @@ pub fn printValue( |
| 1290 | 1290 | .@"enum" => |info| { |
| 1291 | 1291 | if (!is_any and fmt.len != 0) invalidFmtError(fmt, value); |
| 1292 | 1292 | optionsForbidden(options); |
| 1293 | if (info.is_exhaustive) { | |
| 1293 | if (info.mode == .exhaustive) { | |
| 1294 | 1294 | return printEnumExhaustive(w, value); |
| 1295 | 1295 | } else { |
| 1296 | 1296 | return printEnumNonexhaustive(w, value); |
| ... | ... | @@ -1309,9 +1309,9 @@ pub fn printValue( |
| 1309 | 1309 | try w.writeAll(".{ ."); |
| 1310 | 1310 | try w.writeAll(@tagName(@as(UnionTagType, value))); |
| 1311 | 1311 | try w.writeAll(" = "); |
| 1312 | inline for (info.fields) |u_field| { | |
| 1313 | if (value == @field(UnionTagType, u_field.name)) { | |
| 1314 | try w.printValue(ANY, options, @field(value, u_field.name), max_depth - 1); | |
| 1312 | inline for (info.field_names) |u_field_name| { | |
| 1313 | if (value == @field(UnionTagType, u_field_name)) { | |
| 1314 | try w.printValue(ANY, options, @field(value, u_field_name), max_depth - 1); | |
| 1315 | 1315 | } |
| 1316 | 1316 | } |
| 1317 | 1317 | try w.writeAll(" }"); |
| ... | ... | @@ -1320,14 +1320,14 @@ pub fn printValue( |
| 1320 | 1320 | return w.writeAll(".{ ... }"); |
| 1321 | 1321 | }, |
| 1322 | 1322 | .@"extern", .@"packed" => { |
| 1323 | if (info.fields.len == 0) return w.writeAll(".{}"); | |
| 1323 | if (info.field_names.len == 0) return w.writeAll(".{}"); | |
| 1324 | 1324 | try w.writeAll(".{ "); |
| 1325 | inline for (info.fields, 1..) |field, i| { | |
| 1325 | inline for (info.field_names, 1..) |field_name, i| { | |
| 1326 | 1326 | try w.writeByte('.'); |
| 1327 | try w.writeAll(field.name); | |
| 1327 | try w.writeAll(field_name); | |
| 1328 | 1328 | try w.writeAll(" = "); |
| 1329 | try w.printValue(ANY, options, @field(value, field.name), max_depth - 1); | |
| 1330 | try w.writeAll(if (i < info.fields.len) ", " else " }"); | |
| 1329 | try w.printValue(ANY, options, @field(value, field_name), max_depth - 1); | |
| 1330 | try w.writeAll(if (i < info.field_names.len) ", " else " }"); | |
| 1331 | 1331 | } |
| 1332 | 1332 | }, |
| 1333 | 1333 | } |
| ... | ... | @@ -1344,13 +1344,13 @@ pub fn printValue( |
| 1344 | 1344 | return; |
| 1345 | 1345 | } |
| 1346 | 1346 | try w.writeAll(".{"); |
| 1347 | inline for (info.fields, 0..) |f, i| { | |
| 1347 | inline for (info.field_names, 0..) |f_name, i| { | |
| 1348 | 1348 | if (i == 0) { |
| 1349 | 1349 | try w.writeAll(" "); |
| 1350 | 1350 | } else { |
| 1351 | 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 | 1355 | try w.writeAll(" }"); |
| 1356 | 1356 | return; |
| ... | ... | @@ -1360,15 +1360,15 @@ pub fn printValue( |
| 1360 | 1360 | return; |
| 1361 | 1361 | } |
| 1362 | 1362 | try w.writeAll(".{"); |
| 1363 | inline for (info.fields, 0..) |f, i| { | |
| 1363 | inline for (info.field_names, 0..) |f_name, i| { | |
| 1364 | 1364 | if (i == 0) { |
| 1365 | 1365 | try w.writeAll(" ."); |
| 1366 | 1366 | } else { |
| 1367 | 1367 | try w.writeAll(", ."); |
| 1368 | 1368 | } |
| 1369 | try w.writeAll(f.name); | |
| 1369 | try w.writeAll(f_name); | |
| 1370 | 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 | 1373 | try w.writeAll(" }"); |
| 1374 | 1374 | }, |
lib/std/Progress.zig+2-2| ... | ... | @@ -867,8 +867,8 @@ const TreeSymbol = enum { |
| 867 | 867 | |
| 868 | 868 | fn maxByteLen(symbol: TreeSymbol) usize { |
| 869 | 869 | var max: usize = 0; |
| 870 | inline for (@typeInfo(Encoding).@"enum".fields) |field| { | |
| 871 | const len = symbol.bytes(@field(Encoding, field.name)).len; | |
| 870 | inline for (@typeInfo(Encoding).@"enum".field_names) |field_name| { | |
| 871 | const len = symbol.bytes(@field(Encoding, field_name)).len; | |
| 872 | 872 | max = @max(max, len); |
| 873 | 873 | } |
| 874 | 874 | return max; |
lib/std/Target.zig+4-4| ... | ... | @@ -1764,10 +1764,10 @@ pub const Cpu = struct { |
| 1764 | 1764 | |
| 1765 | 1765 | fn allCpusFromDecls(comptime cpus: type) []const *const Cpu.Model { |
| 1766 | 1766 | @setEvalBranchQuota(2000); |
| 1767 | const decls = @typeInfo(cpus).@"struct".decls; | |
| 1768 | var array: [decls.len]*const Cpu.Model = undefined; | |
| 1769 | for (decls, 0..) |decl, i| { | |
| 1770 | array[i] = &@field(cpus, decl.name); | |
| 1767 | const decl_names = @typeInfo(cpus).@"struct".decl_names; | |
| 1768 | var array: [decl_names.len]*const Cpu.Model = undefined; | |
| 1769 | for (decl_names, 0..) |decl_name, i| { | |
| 1770 | array[i] = &@field(cpus, decl_name); | |
| 1771 | 1771 | } |
| 1772 | 1772 | const finalized = array; |
| 1773 | 1773 | return &finalized; |
lib/std/Target/aarch64.zig+2-2| ... | ... | @@ -291,7 +291,7 @@ pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 291 | 291 | |
| 292 | 292 | pub const all_features = blk: { |
| 293 | 293 | @setEvalBranchQuota(2000); |
| 294 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 294 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 295 | 295 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 296 | 296 | var result: [len]CpuFeature = undefined; |
| 297 | 297 | result[@intFromEnum(Feature.a320)] = .{ |
| ... | ... | @@ -2019,7 +2019,7 @@ pub const all_features = blk: { |
| 2019 | 2019 | const ti = @typeInfo(Feature); |
| 2020 | 2020 | for (&result, 0..) |*elem, i| { |
| 2021 | 2021 | elem.index = i; |
| 2022 | elem.name = ti.@"enum".fields[i].name; | |
| 2022 | elem.name = ti.@"enum".field_names[i]; | |
| 2023 | 2023 | } |
| 2024 | 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 | 17 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 18 | 18 | |
| 19 | 19 | pub const all_features = blk: { |
| 20 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 20 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 21 | 21 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 22 | 22 | var result: [len]CpuFeature = undefined; |
| 23 | 23 | result[@intFromEnum(Feature.bwx)] = .{ |
| ... | ... | @@ -43,7 +43,7 @@ pub const all_features = blk: { |
| 43 | 43 | const ti = @typeInfo(Feature); |
| 44 | 44 | for (&result, 0..) |*elem, i| { |
| 45 | 45 | elem.index = i; |
| 46 | elem.name = ti.@"enum".fields[i].name; | |
| 46 | elem.name = ti.@"enum".field_names[i]; | |
| 47 | 47 | } |
| 48 | 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 | 268 | |
| 269 | 269 | pub const all_features = blk: { |
| 270 | 270 | @setEvalBranchQuota(2000); |
| 271 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 271 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 272 | 272 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 273 | 273 | var result: [len]CpuFeature = undefined; |
| 274 | 274 | result[@intFromEnum(Feature.@"1024_addressable_vgprs")] = .{ |
| ... | ... | @@ -1877,7 +1877,7 @@ pub const all_features = blk: { |
| 1877 | 1877 | const ti = @typeInfo(Feature); |
| 1878 | 1878 | for (&result, 0..) |*elem, i| { |
| 1879 | 1879 | elem.index = i; |
| 1880 | elem.name = ti.@"enum".fields[i].name; | |
| 1880 | elem.name = ti.@"enum".field_names[i]; | |
| 1881 | 1881 | } |
| 1882 | 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 | 14 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 15 | 15 | |
| 16 | 16 | pub const all_features = blk: { |
| 17 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 17 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 18 | 18 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 19 | 19 | var result: [len]CpuFeature = undefined; |
| 20 | 20 | result[@intFromEnum(Feature.norm)] = .{ |
| ... | ... | @@ -25,7 +25,7 @@ pub const all_features = blk: { |
| 25 | 25 | const ti = @typeInfo(Feature); |
| 26 | 26 | for (&result, 0..) |*elem, i| { |
| 27 | 27 | elem.index = i; |
| 28 | elem.name = ti.@"enum".fields[i].name; | |
| 28 | elem.name = ti.@"enum".field_names[i]; | |
| 29 | 29 | } |
| 30 | 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 | 215 | |
| 216 | 216 | pub const all_features = blk: { |
| 217 | 217 | @setEvalBranchQuota(10000); |
| 218 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 218 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 219 | 219 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 220 | 220 | var result: [len]CpuFeature = undefined; |
| 221 | 221 | result[@intFromEnum(Feature.@"32bit")] = .{ |
| ... | ... | @@ -1736,7 +1736,7 @@ pub const all_features = blk: { |
| 1736 | 1736 | const ti = @typeInfo(Feature); |
| 1737 | 1737 | for (&result, 0..) |*elem, i| { |
| 1738 | 1738 | elem.index = i; |
| 1739 | elem.name = ti.@"enum".fields[i].name; | |
| 1739 | elem.name = ti.@"enum".field_names[i]; | |
| 1740 | 1740 | } |
| 1741 | 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 | 52 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 53 | 53 | |
| 54 | 54 | pub const all_features = blk: { |
| 55 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 55 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 56 | 56 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 57 | 57 | var result: [len]CpuFeature = undefined; |
| 58 | 58 | result[@intFromEnum(Feature.addsubiw)] = .{ |
| ... | ... | @@ -388,7 +388,7 @@ pub const all_features = blk: { |
| 388 | 388 | const ti = @typeInfo(Feature); |
| 389 | 389 | for (&result, 0..) |*elem, i| { |
| 390 | 390 | elem.index = i; |
| 391 | elem.name = ti.@"enum".fields[i].name; | |
| 391 | elem.name = ti.@"enum".field_names[i]; | |
| 392 | 392 | } |
| 393 | 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 | 17 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 18 | 18 | |
| 19 | 19 | pub const all_features = blk: { |
| 20 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 20 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 21 | 21 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 22 | 22 | var result: [len]CpuFeature = undefined; |
| 23 | 23 | result[@intFromEnum(Feature.allows_misaligned_mem_access)] = .{ |
| ... | ... | @@ -43,7 +43,7 @@ pub const all_features = blk: { |
| 43 | 43 | const ti = @typeInfo(Feature); |
| 44 | 44 | for (&result, 0..) |*elem, i| { |
| 45 | 45 | elem.index = i; |
| 46 | elem.name = ti.@"enum".fields[i].name; | |
| 46 | elem.name = ti.@"enum".field_names[i]; | |
| 47 | 47 | } |
| 48 | 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 | 76 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 77 | 77 | |
| 78 | 78 | pub const all_features = blk: { |
| 79 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 79 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 80 | 80 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 81 | 81 | var result: [len]CpuFeature = undefined; |
| 82 | 82 | result[@intFromEnum(Feature.@"10e60")] = .{ |
| ... | ... | @@ -418,7 +418,7 @@ pub const all_features = blk: { |
| 418 | 418 | const ti = @typeInfo(Feature); |
| 419 | 419 | for (&result, 0..) |*elem, i| { |
| 420 | 420 | elem.index = i; |
| 421 | elem.name = ti.@"enum".fields[i].name; | |
| 421 | elem.name = ti.@"enum".field_names[i]; | |
| 422 | 422 | } |
| 423 | 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 | 60 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 61 | 61 | |
| 62 | 62 | pub const all_features = blk: { |
| 63 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 63 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 64 | 64 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 65 | 65 | var result: [len]CpuFeature = undefined; |
| 66 | 66 | result[@intFromEnum(Feature.audio)] = .{ |
| ... | ... | @@ -334,7 +334,7 @@ pub const all_features = blk: { |
| 334 | 334 | const ti = @typeInfo(Feature); |
| 335 | 335 | for (&result, 0..) |*elem, i| { |
| 336 | 336 | elem.index = i; |
| 337 | elem.name = ti.@"enum".fields[i].name; | |
| 337 | elem.name = ti.@"enum".field_names[i]; | |
| 338 | 338 | } |
| 339 | 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 | 18 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 19 | 19 | |
| 20 | 20 | pub const all_features = blk: { |
| 21 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 21 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 22 | 22 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 23 | 23 | var result: [len]CpuFeature = undefined; |
| 24 | 24 | result[@intFromEnum(Feature.@"64bit")] = .{ |
| ... | ... | @@ -56,7 +56,7 @@ pub const all_features = blk: { |
| 56 | 56 | const ti = @typeInfo(Feature); |
| 57 | 57 | for (&result, 0..) |*elem, i| { |
| 58 | 58 | elem.index = i; |
| 59 | elem.name = ti.@"enum".fields[i].name; | |
| 59 | elem.name = ti.@"enum".field_names[i]; | |
| 60 | 60 | } |
| 61 | 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 | 16 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 17 | 17 | |
| 18 | 18 | pub const all_features = blk: { |
| 19 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 19 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 20 | 20 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 21 | 21 | var result: [len]CpuFeature = undefined; |
| 22 | 22 | result[@intFromEnum(Feature.v3_1)] = .{ |
| ... | ... | @@ -41,7 +41,7 @@ pub const all_features = blk: { |
| 41 | 41 | const ti = @typeInfo(Feature); |
| 42 | 42 | for (&result, 0..) |*elem, i| { |
| 43 | 43 | elem.index = i; |
| 44 | elem.name = ti.@"enum".fields[i].name; | |
| 44 | elem.name = ti.@"enum".field_names[i]; | |
| 45 | 45 | } |
| 46 | 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 | 12 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 13 | 13 | |
| 14 | 14 | pub const all_features = blk: { |
| 15 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 15 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 16 | 16 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 17 | 17 | var result: [len]CpuFeature = undefined; |
| 18 | 18 | const ti = @typeInfo(Feature); |
| 19 | 19 | for (&result, 0..) |*elem, i| { |
| 20 | 20 | elem.index = i; |
| 21 | elem.name = ti.@"enum".fields[i].name; | |
| 21 | elem.name = ti.@"enum".field_names[i]; | |
| 22 | 22 | } |
| 23 | 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 | 34 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 35 | 35 | |
| 36 | 36 | pub const all_features = blk: { |
| 37 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 37 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 38 | 38 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 39 | 39 | var result: [len]CpuFeature = undefined; |
| 40 | 40 | result[@intFromEnum(Feature.@"32bit")] = .{ |
| ... | ... | @@ -153,7 +153,7 @@ pub const all_features = blk: { |
| 153 | 153 | const ti = @typeInfo(Feature); |
| 154 | 154 | for (&result, 0..) |*elem, i| { |
| 155 | 155 | elem.index = i; |
| 156 | elem.name = ti.@"enum".fields[i].name; | |
| 156 | elem.name = ti.@"enum".field_names[i]; | |
| 157 | 157 | } |
| 158 | 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 | 36 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 37 | 37 | |
| 38 | 38 | pub const all_features = blk: { |
| 39 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 39 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 40 | 40 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 41 | 41 | var result: [len]CpuFeature = undefined; |
| 42 | 42 | result[@intFromEnum(Feature.isa_68000)] = .{ |
| ... | ... | @@ -170,7 +170,7 @@ pub const all_features = blk: { |
| 170 | 170 | const ti = @typeInfo(Feature); |
| 171 | 171 | for (&result, 0..) |*elem, i| { |
| 172 | 172 | elem.index = i; |
| 173 | elem.name = ti.@"enum".fields[i].name; | |
| 173 | elem.name = ti.@"enum".field_names[i]; | |
| 174 | 174 | } |
| 175 | 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 | 70 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 71 | 71 | |
| 72 | 72 | pub const all_features = blk: { |
| 73 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 73 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 74 | 74 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 75 | 75 | var result: [len]CpuFeature = undefined; |
| 76 | 76 | result[@intFromEnum(Feature.abs2008)] = .{ |
| ... | ... | @@ -425,7 +425,7 @@ pub const all_features = blk: { |
| 425 | 425 | const ti = @typeInfo(Feature); |
| 426 | 426 | for (&result, 0..) |*elem, i| { |
| 427 | 427 | elem.index = i; |
| 428 | elem.name = ti.@"enum".fields[i].name; | |
| 428 | elem.name = ti.@"enum".field_names[i]; | |
| 429 | 429 | } |
| 430 | 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 | 17 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 18 | 18 | |
| 19 | 19 | pub const all_features = blk: { |
| 20 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 20 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 21 | 21 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 22 | 22 | var result: [len]CpuFeature = undefined; |
| 23 | 23 | result[@intFromEnum(Feature.ext)] = .{ |
| ... | ... | @@ -43,7 +43,7 @@ pub const all_features = blk: { |
| 43 | 43 | const ti = @typeInfo(Feature); |
| 44 | 44 | for (&result, 0..) |*elem, i| { |
| 45 | 45 | elem.index = i; |
| 46 | elem.name = ti.@"enum".fields[i].name; | |
| 46 | elem.name = ti.@"enum".field_names[i]; | |
| 47 | 47 | } |
| 48 | 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 | 84 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 85 | 85 | |
| 86 | 86 | pub const all_features = blk: { |
| 87 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 87 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 88 | 88 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 89 | 89 | var result: [len]CpuFeature = undefined; |
| 90 | 90 | result[@intFromEnum(Feature.ptx32)] = .{ |
| ... | ... | @@ -445,7 +445,7 @@ pub const all_features = blk: { |
| 445 | 445 | const ti = @typeInfo(Feature); |
| 446 | 446 | for (&result, 0..) |*elem, i| { |
| 447 | 447 | elem.index = i; |
| 448 | elem.name = ti.@"enum".fields[i].name; | |
| 448 | elem.name = ti.@"enum".field_names[i]; | |
| 449 | 449 | } |
| 450 | 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 | 93 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 94 | 94 | |
| 95 | 95 | pub const all_features = blk: { |
| 96 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 96 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 97 | 97 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 98 | 98 | var result: [len]CpuFeature = undefined; |
| 99 | 99 | result[@intFromEnum(Feature.@"64bit")] = .{ |
| ... | ... | @@ -595,7 +595,7 @@ pub const all_features = blk: { |
| 595 | 595 | const ti = @typeInfo(Feature); |
| 596 | 596 | for (&result, 0..) |*elem, i| { |
| 597 | 597 | elem.index = i; |
| 598 | elem.name = ti.@"enum".fields[i].name; | |
| 598 | elem.name = ti.@"enum".field_names[i]; | |
| 599 | 599 | } |
| 600 | 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 | 14 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 15 | 15 | |
| 16 | 16 | pub const all_features = blk: { |
| 17 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 17 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 18 | 18 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 19 | 19 | var result: [len]CpuFeature = undefined; |
| 20 | 20 | result[@intFromEnum(Feature.p2)] = .{ |
| ... | ... | @@ -25,7 +25,7 @@ pub const all_features = blk: { |
| 25 | 25 | const ti = @typeInfo(Feature); |
| 26 | 26 | for (&result, 0..) |*elem, i| { |
| 27 | 27 | elem.index = i; |
| 28 | elem.name = ti.@"enum".fields[i].name; | |
| 28 | elem.name = ti.@"enum".field_names[i]; | |
| 29 | 29 | } |
| 30 | 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 | 361 | |
| 362 | 362 | pub const all_features = blk: { |
| 363 | 363 | @setEvalBranchQuota(2000); |
| 364 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 364 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 365 | 365 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 366 | 366 | var result: [len]CpuFeature = undefined; |
| 367 | 367 | result[@intFromEnum(Feature.@"32bit")] = .{ |
| ... | ... | @@ -2675,7 +2675,7 @@ pub const all_features = blk: { |
| 2675 | 2675 | const ti = @typeInfo(Feature); |
| 2676 | 2676 | for (&result, 0..) |*elem, i| { |
| 2677 | 2677 | elem.index = i; |
| 2678 | elem.name = ti.@"enum".fields[i].name; | |
| 2678 | elem.name = ti.@"enum".field_names[i]; | |
| 2679 | 2679 | } |
| 2680 | 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 | 62 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 63 | 63 | |
| 64 | 64 | pub const all_features = blk: { |
| 65 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 65 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 66 | 66 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 67 | 67 | var result: [len]CpuFeature = undefined; |
| 68 | 68 | result[@intFromEnum(Feature.backchain)] = .{ |
| ... | ... | @@ -313,7 +313,7 @@ pub const all_features = blk: { |
| 313 | 313 | const ti = @typeInfo(Feature); |
| 314 | 314 | for (&result, 0..) |*elem, i| { |
| 315 | 315 | elem.index = i; |
| 316 | elem.name = ti.@"enum".fields[i].name; | |
| 316 | elem.name = ti.@"enum".field_names[i]; | |
| 317 | 317 | } |
| 318 | 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 | 72 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 73 | 73 | |
| 74 | 74 | pub const all_features = blk: { |
| 75 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 75 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 76 | 76 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 77 | 77 | var result: [len]CpuFeature = undefined; |
| 78 | 78 | result[@intFromEnum(Feature.@"64bit")] = .{ |
| ... | ... | @@ -395,7 +395,7 @@ pub const all_features = blk: { |
| 395 | 395 | const ti = @typeInfo(Feature); |
| 396 | 396 | for (&result, 0..) |*elem, i| { |
| 397 | 397 | elem.index = i; |
| 398 | elem.name = ti.@"enum".fields[i].name; | |
| 398 | elem.name = ti.@"enum".field_names[i]; | |
| 399 | 399 | } |
| 400 | 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 | 29 | |
| 30 | 30 | pub const all_features = blk: { |
| 31 | 31 | @setEvalBranchQuota(2000); |
| 32 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 32 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 33 | 33 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 34 | 34 | var result: [len]CpuFeature = undefined; |
| 35 | 35 | result[@intFromEnum(Feature.arbitrary_precision_integers)] = .{ |
| ... | ... | @@ -138,7 +138,7 @@ pub const all_features = blk: { |
| 138 | 138 | const ti = @typeInfo(Feature); |
| 139 | 139 | for (&result, 0..) |*elem, i| { |
| 140 | 140 | elem.index = i; |
| 141 | elem.name = ti.@"enum".fields[i].name; | |
| 141 | elem.name = ti.@"enum".field_names[i]; | |
| 142 | 142 | } |
| 143 | 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 | 14 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 15 | 15 | |
| 16 | 16 | pub const all_features = blk: { |
| 17 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 17 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 18 | 18 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 19 | 19 | var result: [len]CpuFeature = undefined; |
| 20 | 20 | result[@intFromEnum(Feature.vpu)] = .{ |
| ... | ... | @@ -25,7 +25,7 @@ pub const all_features = blk: { |
| 25 | 25 | const ti = @typeInfo(Feature); |
| 26 | 26 | for (&result, 0..) |*elem, i| { |
| 27 | 27 | elem.index = i; |
| 28 | elem.name = ti.@"enum".fields[i].name; | |
| 28 | elem.name = ti.@"enum".field_names[i]; | |
| 29 | 29 | } |
| 30 | 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 | 32 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 33 | 33 | |
| 34 | 34 | pub const all_features = blk: { |
| 35 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 35 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 36 | 36 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 37 | 37 | var result: [len]CpuFeature = undefined; |
| 38 | 38 | result[@intFromEnum(Feature.atomics)] = .{ |
| ... | ... | @@ -139,7 +139,7 @@ pub const all_features = blk: { |
| 139 | 139 | const ti = @typeInfo(Feature); |
| 140 | 140 | for (&result, 0..) |*elem, i| { |
| 141 | 141 | elem.index = i; |
| 142 | elem.name = ti.@"enum".fields[i].name; | |
| 142 | elem.name = ti.@"enum".field_names[i]; | |
| 143 | 143 | } |
| 144 | 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 | 215 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 216 | 216 | |
| 217 | 217 | pub const all_features = blk: { |
| 218 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 218 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 219 | 219 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 220 | 220 | var result: [len]CpuFeature = undefined; |
| 221 | 221 | result[@intFromEnum(Feature.@"16bit_mode")] = .{ |
| ... | ... | @@ -1374,7 +1374,7 @@ pub const all_features = blk: { |
| 1374 | 1374 | const ti = @typeInfo(Feature); |
| 1375 | 1375 | for (&result, 0..) |*elem, i| { |
| 1376 | 1376 | elem.index = i; |
| 1377 | elem.name = ti.@"enum".fields[i].name; | |
| 1377 | elem.name = ti.@"enum".field_names[i]; | |
| 1378 | 1378 | } |
| 1379 | 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 | 12 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 13 | 13 | |
| 14 | 14 | pub const all_features = blk: { |
| 15 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 15 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 16 | 16 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 17 | 17 | var result: [len]CpuFeature = undefined; |
| 18 | 18 | const ti = @typeInfo(Feature); |
| 19 | 19 | for (&result, 0..) |*elem, i| { |
| 20 | 20 | elem.index = i; |
| 21 | elem.name = ti.@"enum".fields[i].name; | |
| 21 | elem.name = ti.@"enum".field_names[i]; | |
| 22 | 22 | } |
| 23 | 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 | 50 | pub const featureSetHasAll = CpuFeature.FeatureSetFns(Feature).featureSetHasAll; |
| 51 | 51 | |
| 52 | 52 | pub const all_features = blk: { |
| 53 | const len = @typeInfo(Feature).@"enum".fields.len; | |
| 53 | const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 54 | 54 | std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 55 | 55 | var result: [len]CpuFeature = undefined; |
| 56 | 56 | result[@intFromEnum(Feature.bool)] = .{ |
| ... | ... | @@ -251,7 +251,7 @@ pub const all_features = blk: { |
| 251 | 251 | const ti = @typeInfo(Feature); |
| 252 | 252 | for (&result, 0..) |*elem, i| { |
| 253 | 253 | elem.index = i; |
| 254 | elem.name = ti.@"enum".fields[i].name; | |
| 254 | elem.name = ti.@"enum".field_names[i]; | |
| 255 | 255 | } |
| 256 | 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 | 54 | |
| 55 | 55 | _, |
| 56 | 56 | |
| 57 | pub const TYPES_COUNT = @typeInfo(EXC).@"enum".fields.len; | |
| 57 | pub const TYPES_COUNT = @typeInfo(EXC).@"enum".field_names.len; | |
| 58 | 58 | pub const SOFT_SIGNAL = 0x10003; |
| 59 | 59 | |
| 60 | 60 | pub const MASK = packed struct(u32) { |
lib/std/coff.zig+1-1| ... | ... | @@ -1386,7 +1386,7 @@ pub const IMAGE = struct { |
| 1386 | 1386 | RESERVED = 15, |
| 1387 | 1387 | _, |
| 1388 | 1388 | |
| 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 | }; |
| 1391 | 1391 | |
| 1392 | 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 | 177 | pub fn initComptime(comptime key_pairs: anytype) ReturnType { |
| 178 | 178 | const struct_info = @typeInfo(@TypeOf(key_pairs)).@"struct"; |
| 179 | 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 | 181 | @compileError(error_msg); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | comptime var enum_to_oid = EnumToOid.initUndefined(); |
| 185 | 185 | |
| 186 | 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; | |
| 188 | 188 | |
| 189 | comptime for (enum_info.fields, 0..) |f, i| { | |
| 190 | if (!@hasField(@TypeOf(key_pairs), f.name)) { | |
| 191 | @compileError("Field '" ++ f.name ++ "' missing Oid.StaticMap entry"); | |
| 189 | comptime for (enum_info.field_names, enum_info.field_values, 0..) |f_name, f_value, i| { | |
| 190 | if (!@hasField(@TypeOf(key_pairs), f_name)) { | |
| 191 | @compileError("Field '" ++ f_name ++ "' missing Oid.StaticMap entry"); | |
| 192 | 192 | } |
| 193 | const encoded = &encodeComptime(@field(key_pairs, f.name)); | |
| 194 | const tag: Enum = @enumFromInt(f.value); | |
| 193 | const encoded = &encodeComptime(@field(key_pairs, f_name)); | |
| 194 | const tag: Enum = @enumFromInt(f_value); | |
| 195 | 195 | static_key_pairs[i] = .{ encoded, tag }; |
| 196 | 196 | enum_to_oid.set(tag, encoded); |
| 197 | 197 | }; |
| 198 | 198 | |
| 199 | 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); | |
| 201 | 201 | |
| 202 | 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 | 19 | |
| 20 | 20 | const tag = Tag.fromZig(T).toExpected(); |
| 21 | 21 | switch (@typeInfo(T)) { |
| 22 | .@"struct" => { | |
| 22 | .@"struct" => |info| { | |
| 23 | 23 | const ele = try self.element(tag); |
| 24 | 24 | defer self.index = ele.slice.end; // don't force parsing all fields |
| 25 | 25 | |
| 26 | 26 | var res: T = undefined; |
| 27 | 27 | |
| 28 | inline for (std.meta.fields(T)) |f| { | |
| 29 | self.field_tag = FieldTag.fromContainer(T, f.name); | |
| 28 | inline for (info.field_names, info.field_types, info.field_attrs) |f_name, f_type, f_attrs| { | |
| 29 | self.field_tag = FieldTag.fromContainer(T, f_name); | |
| 30 | 30 | |
| 31 | 31 | if (self.field_tag) |ft| { |
| 32 | 32 | if (ft.explicit) { |
| ... | ... | @@ -36,15 +36,15 @@ pub fn any(self: *Decoder, comptime T: type) !T { |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | @field(res, f.name) = self.any(f.type) catch |err| brk: { | |
| 40 | if (f.defaultValue()) |d| { | |
| 39 | @field(res, f_name) = self.any(f_type) catch |err| brk: { | |
| 40 | if (f_attrs.defaultValue(f_type)) |d| { | |
| 41 | 41 | break :brk d; |
| 42 | 42 | } |
| 43 | 43 | return err; |
| 44 | 44 | }; |
| 45 | 45 | // DER encodes null values by skipping them. |
| 46 | if (@typeInfo(f.type) == .optional and @field(res, f.name) == null) { | |
| 47 | if (f.defaultValue()) |d| @field(res, f.name) = d; | |
| 46 | if (@typeInfo(f_type) == .optional and @field(res, f_name) == null) { | |
| 47 | if (f_attrs.defaultValue(f_type)) |d| @field(res, f_name) = d; | |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 |
lib/std/crypto/codecs/asn1/der/Encoder.zig+10-8| ... | ... | @@ -29,16 +29,18 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { |
| 29 | 29 | |
| 30 | 30 | switch (@typeInfo(T)) { |
| 31 | 31 | .@"struct" => |info| { |
| 32 | inline for (0..info.fields.len) |i| { | |
| 33 | const f = info.fields[info.fields.len - i - 1]; | |
| 34 | const field_val = @field(val, f.name); | |
| 35 | const field_tag = FieldTag.fromContainer(T, f.name); | |
| 32 | inline for (0..info.field_names.len) |i| { | |
| 33 | const f_idx = info.field_names.len - i - 1; | |
| 34 | const f_name = info.field_names[f_idx]; | |
| 35 | const f_type = info.field_types[f_idx]; | |
| 36 | const f_attrs = info.field_attrs[f_idx]; | |
| 37 | const field_val = @field(val, f_name); | |
| 38 | const field_tag = FieldTag.fromContainer(T, f_name); | |
| 36 | 39 | |
| 37 | 40 | // > The encoding of a set value or sequence value shall not include an encoding for any |
| 38 | 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: { | |
| 40 | const default_val: *const f.type = @ptrCast(@alignCast(v)); | |
| 41 | break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val)); | |
| 42 | const is_default = if (f_attrs.@"comptime") false else if (f_attrs.defaultValue(f_type)) |default_val| brk: { | |
| 43 | break :brk std.mem.eql(u8, std.mem.asBytes(&default_val), std.mem.asBytes(&field_val)); | |
| 42 | 44 | } else false; |
| 43 | 45 | |
| 44 | 46 | if (!is_default) { |
| ... | ... | @@ -46,7 +48,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { |
| 46 | 48 | self.field_tag = field_tag; |
| 47 | 49 | // will merge with self.field_tag. |
| 48 | 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 | 52 | if (field_tag) |ft| { |
| 51 | 53 | if (ft.explicit) { |
| 52 | 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 | 115 | while (it_params.next()) |params| { |
| 116 | 116 | const param = kvSplit(params) catch break; |
| 117 | 117 | var found = false; |
| 118 | inline for (comptime meta.fields(HashResult)) |p| { | |
| 119 | if (mem.eql(u8, p.name, param.key)) { | |
| 120 | switch (@typeInfo(p.type)) { | |
| 121 | .int => @field(out, p.name) = fmt.parseUnsigned( | |
| 122 | p.type, | |
| 118 | const info = @typeInfo(HashResult).@"struct"; | |
| 119 | inline for (info.field_names, info.field_types) |p_name, p_type| { | |
| 120 | if (mem.eql(u8, p_name, param.key)) { | |
| 121 | switch (@typeInfo(p_type)) { | |
| 122 | .int => @field(out, p_name) = fmt.parseUnsigned( | |
| 123 | p_type, | |
| 123 | 124 | param.value, |
| 124 | 125 | 10, |
| 125 | 126 | ) catch return Error.InvalidEncoding, |
| 126 | 127 | .pointer => |ptr| { |
| 127 | if (!ptr.is_const) @compileError("Value slice must be constant"); | |
| 128 | @field(out, p.name) = param.value; | |
| 128 | if (!ptr.attrs.@"const") @compileError("Value slice must be constant"); | |
| 129 | @field(out, p_name) = param.value; | |
| 129 | 130 | }, |
| 130 | .@"struct" => try @field(out, p.name).fromB64(param.value), | |
| 131 | .@"struct" => try @field(out, p_name).fromB64(param.value), | |
| 131 | 132 | else => std.debug.panic( |
| 132 | 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 | 137 | set_fields += 1; |
| ... | ... | @@ -167,8 +168,9 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult |
| 167 | 168 | // Check that all the required fields have been set, excluding optional values and parameters |
| 168 | 169 | // with default values |
| 169 | 170 | var expected_fields: usize = 0; |
| 170 | inline for (comptime meta.fields(HashResult)) |p| { | |
| 171 | if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) { | |
| 171 | const info = @typeInfo(HashResult).@"struct"; | |
| 172 | inline for (info.field_types, info.field_attrs) |p_type, p_attrs| { | |
| 173 | if (@typeInfo(p_type) != .optional and p_attrs.default_value_ptr == null) { | |
| 172 | 174 | expected_fields += 1; |
| 173 | 175 | } |
| 174 | 176 | } |
| ... | ... | @@ -228,21 +230,22 @@ fn serializeTo(params: anytype, out: *std.Io.Writer) !void { |
| 228 | 230 | } |
| 229 | 231 | |
| 230 | 232 | var has_params = false; |
| 231 | inline for (comptime meta.fields(HashResult)) |p| { | |
| 232 | if (comptime !(mem.eql(u8, p.name, "alg_id") or | |
| 233 | mem.eql(u8, p.name, "alg_version") or | |
| 234 | mem.eql(u8, p.name, "hash") or | |
| 235 | mem.eql(u8, p.name, "salt"))) | |
| 233 | const info = @typeInfo(HashResult).@"struct"; | |
| 234 | inline for (info.field_names, info.field_types) |p_name, p_type| { | |
| 235 | if (comptime !(mem.eql(u8, p_name, "alg_id") or | |
| 236 | mem.eql(u8, p_name, "alg_version") or | |
| 237 | mem.eql(u8, p_name, "hash") or | |
| 238 | mem.eql(u8, p_name, "salt"))) | |
| 236 | 239 | { |
| 237 | const value = @field(params, p.name); | |
| 240 | const value = @field(params, p_name); | |
| 238 | 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 | 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 | 245 | } else { |
| 243 | 246 | try out.print( |
| 244 | 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 | 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 | 135 | const t = @typeInfo(@TypeOf(ptr)); |
| 136 | 136 | if (t != .pointer) @compileError("Pointer expected - Found: " ++ @typeName(@TypeOf(ptr))); |
| 137 | 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 | 139 | const child = @typeInfo(p.child); |
| 140 | 140 | |
| 141 | 141 | switch (child) { |
lib/std/crypto/tls.zig+1-1| ... | ... | @@ -710,7 +710,7 @@ pub const Decoder = struct { |
| 710 | 710 | else => @compileError("unsupported int type: " ++ @typeName(T)), |
| 711 | 711 | }, |
| 712 | 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 | 714 | return @enumFromInt(d.decode(info.tag_type)); |
| 715 | 715 | }, |
| 716 | 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 | 1338 | } |
| 1339 | 1339 | |
| 1340 | 1340 | fn logSecrets(w: *Writer, context: anytype, secrets: anytype) void { |
| 1341 | inline for (@typeInfo(@TypeOf(secrets)).@"struct".fields) |field| w.print("{s}" ++ | |
| 1342 | (if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{field.name} ++ | |
| 1341 | inline for (@typeInfo(@TypeOf(secrets)).@"struct".field_names) |field_name| w.print("{s}" ++ | |
| 1342 | (if (@hasField(@TypeOf(context), "counter")) "_{d}" else "") ++ " {x} {x}\n", .{field_name} ++ | |
| 1343 | 1343 | (if (@hasField(@TypeOf(context), "counter")) .{context.counter} else .{}) ++ .{ |
| 1344 | 1344 | context.client_random, |
| 1345 | @field(secrets, field.name), | |
| 1345 | @field(secrets, field_name), | |
| 1346 | 1346 | }) catch {}; |
| 1347 | 1347 | } |
| 1348 | 1348 |
lib/std/debug/ElfFile.zig+12-8| ... | ... | @@ -219,9 +219,10 @@ pub fn load( |
| 219 | 219 | break :dwarf null; // debug info not present |
| 220 | 220 | } |
| 221 | 221 | var sections: Dwarf.SectionArray = @splat(null); |
| 222 | inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields) |f| { | |
| 223 | if (result.sections.get(@field(Section.Id, f.name))) |s| { | |
| 224 | sections[f.value] = .{ .data = s.bytes, .owned = false }; | |
| 222 | const info = @typeInfo(Dwarf.Section.Id).@"enum"; | |
| 223 | inline for (info.field_names, info.field_values) |f_name, f_value| { | |
| 224 | if (result.sections.get(@field(Section.Id, f_name))) |s| { | |
| 225 | sections[f_value] = .{ .data = s.bytes, .owned = false }; | |
| 225 | 226 | } |
| 226 | 227 | } |
| 227 | 228 | break :dwarf .{ .sections = sections }; |
| ... | ... | @@ -408,8 +409,8 @@ fn loadSeparateDebugFile( |
| 408 | 409 | return null; |
| 409 | 410 | } |
| 410 | 411 | |
| 411 | inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields) |f| { | |
| 412 | const id = @field(Section.Id, f.name); | |
| 412 | inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names) |f_name| { | |
| 413 | const id = @field(Section.Id, f_name); | |
| 413 | 414 | if (main_loaded.sections.get(id) == null) { |
| 414 | 415 | main_loaded.sections.set(id, result.sections.get(id)); |
| 415 | 416 | } |
| ... | ... | @@ -498,9 +499,12 @@ fn loadInner( |
| 498 | 499 | if (shdr.sh_name > shstrtab.len) return error.TruncatedElfFile; |
| 499 | 500 | const name = std.mem.sliceTo(shstrtab[@intCast(shdr.sh_name)..], 0); |
| 500 | 501 | |
| 501 | const section_id: Section.Id = inline for (@typeInfo(Section.Id).@"enum".fields) |s| { | |
| 502 | if (std.mem.eql(u8, "." ++ s.name, name)) { | |
| 503 | break @enumFromInt(s.value); | |
| 502 | const section_id: Section.Id = inline for ( | |
| 503 | @typeInfo(Section.Id).@"enum".field_names, | |
| 504 | @typeInfo(Section.Id).@"enum".field_values, | |
| 505 | ) |s_name, s_value| { | |
| 506 | if (std.mem.eql(u8, "." ++ s_name, name)) { | |
| 507 | break @enumFromInt(s_value); | |
| 504 | 508 | } |
| 505 | 509 | } else continue; |
| 506 | 510 |
lib/std/debug/MachOFile.zig+2-2| ... | ... | @@ -504,8 +504,8 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile { |
| 504 | 504 | |
| 505 | 505 | if (!std.mem.eql(u8, "__DWARF", sect.segName())) continue; |
| 506 | 506 | |
| 507 | const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields, 0..) |section, i| { | |
| 508 | if (mem.eql(u8, "__" ++ section.name, sect.sectName())) break i; | |
| 507 | const section_index: usize = inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| { | |
| 508 | if (mem.eql(u8, "__" ++ section_name, sect.sectName())) break i; | |
| 509 | 509 | } else continue; |
| 510 | 510 | |
| 511 | 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 | 408 | const ip_ptr = fp + @sizeOf(usize); |
| 409 | 409 | |
| 410 | 410 | var reg_addr = fp - @sizeOf(usize); |
| 411 | inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".fields, 0..) |field, i| { | |
| 412 | if (@field(frame.x_reg_pairs, field.name) != 0) { | |
| 411 | inline for (@typeInfo(@TypeOf(frame.x_reg_pairs)).@"struct".field_names, 0..) |field_name, i| { | |
| 412 | if (@field(frame.x_reg_pairs, field_name) != 0) { | |
| 413 | 413 | (try dwarfRegNative(&context.cpu_state, 19 + i)).* = @as(*const usize, @ptrFromInt(reg_addr)).*; |
| 414 | 414 | reg_addr += @sizeOf(usize); |
| 415 | 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 | 513 | if (coff_obj.getSectionByName(".debug_info") == null) break :dwarf null; |
| 514 | 514 | |
| 515 | 515 | var sections: Dwarf.SectionArray = undefined; |
| 516 | inline for (@typeInfo(Dwarf.Section.Id).@"enum".fields, 0..) |section, i| { | |
| 517 | sections[i] = if (coff_obj.getSectionByName("." ++ section.name)) |section_header| .{ | |
| 516 | inline for (@typeInfo(Dwarf.Section.Id).@"enum".field_names, 0..) |section_name, i| { | |
| 517 | sections[i] = if (coff_obj.getSectionByName("." ++ section_name)) |section_header| .{ | |
| 518 | 518 | .data = try coff_obj.getSectionDataAlloc(section_header, arena), |
| 519 | 519 | .owned = false, |
| 520 | 520 | } else null; |
lib/std/elf.zig+7-7| ... | ... | @@ -484,7 +484,7 @@ pub const PT = enum(Word) { |
| 484 | 484 | _, |
| 485 | 485 | |
| 486 | 486 | /// Number of defined types |
| 487 | pub const NUM = @typeInfo(PT).@"enum".fields.len; | |
| 487 | pub const NUM = @typeInfo(PT).@"enum".field_names.len; | |
| 488 | 488 | |
| 489 | 489 | /// Start of OS-specific |
| 490 | 490 | pub const LOOS: PT = @enumFromInt(0x60000000); |
| ... | ... | @@ -552,7 +552,7 @@ pub const SHT = enum(Word) { |
| 552 | 552 | _, |
| 553 | 553 | |
| 554 | 554 | /// Number of defined types |
| 555 | pub const NUM = @typeInfo(SHT).@"enum".fields.len; | |
| 555 | pub const NUM = @typeInfo(SHT).@"enum".field_names.len; | |
| 556 | 556 | |
| 557 | 557 | /// Start of OS-specific |
| 558 | 558 | pub const LOOS: SHT = @enumFromInt(0x60000000); |
| ... | ... | @@ -595,7 +595,7 @@ pub const STB = enum(u4) { |
| 595 | 595 | _, |
| 596 | 596 | |
| 597 | 597 | /// Number of defined types |
| 598 | pub const NUM = @typeInfo(STB).@"enum".fields.len; | |
| 598 | pub const NUM = @typeInfo(STB).@"enum".field_names.len; | |
| 599 | 599 | |
| 600 | 600 | /// Start of OS-specific |
| 601 | 601 | pub const LOOS: STB = @enumFromInt(10); |
| ... | ... | @@ -631,7 +631,7 @@ pub const STT = enum(u4) { |
| 631 | 631 | _, |
| 632 | 632 | |
| 633 | 633 | /// Number of defined types |
| 634 | pub const NUM = @typeInfo(STT).@"enum".fields.len; | |
| 634 | pub const NUM = @typeInfo(STT).@"enum".field_names.len; | |
| 635 | 635 | |
| 636 | 636 | /// Start of OS-specific |
| 637 | 637 | pub const LOOS: STT = @enumFromInt(10); |
| ... | ... | @@ -815,7 +815,7 @@ pub const Header = struct { |
| 815 | 815 | |
| 816 | 816 | pub fn init(hdr: anytype, endian: Endian) Header { |
| 817 | 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 | 819 | return .{ |
| 820 | 820 | .is_64 = switch (@TypeOf(hdr)) { |
| 821 | 821 | Elf32_Ehdr => false, |
| ... | ... | @@ -1642,7 +1642,7 @@ pub const CLASS = enum(u8) { |
| 1642 | 1642 | @"64" = 2, |
| 1643 | 1643 | _, |
| 1644 | 1644 | |
| 1645 | pub const NUM = @typeInfo(CLASS).@"enum".fields.len; | |
| 1645 | pub const NUM = @typeInfo(CLASS).@"enum".field_names.len; | |
| 1646 | 1646 | |
| 1647 | 1647 | pub fn ElfN(comptime class: CLASS) type { |
| 1648 | 1648 | return switch (class) { |
| ... | ... | @@ -1667,7 +1667,7 @@ pub const DATA = enum(u8) { |
| 1667 | 1667 | @"2MSB" = 2, |
| 1668 | 1668 | _, |
| 1669 | 1669 | |
| 1670 | pub const NUM = @typeInfo(DATA).@"enum".fields.len; | |
| 1670 | pub const NUM = @typeInfo(DATA).@"enum".field_names.len; | |
| 1671 | 1671 | }; |
| 1672 | 1672 | |
| 1673 | 1673 | pub const OSABI = enum(u8) { |
lib/std/enums.zig+66-67| ... | ... | @@ -3,14 +3,13 @@ |
| 3 | 3 | const std = @import("std"); |
| 4 | 4 | const assert = std.debug.assert; |
| 5 | 5 | const testing = std.testing; |
| 6 | const EnumField = std.builtin.Type.EnumField; | |
| 7 | 6 | |
| 8 | 7 | /// Increment this value when adding APIs that add single backwards branches. |
| 9 | 8 | const eval_branch_quota_cushion = 10; |
| 10 | 9 | |
| 11 | 10 | pub fn fromInt(comptime E: type, integer: anytype) ?E { |
| 12 | 11 | const enum_info = @typeInfo(E).@"enum"; |
| 13 | if (!enum_info.is_exhaustive) { | |
| 12 | if (enum_info.mode == .nonexhaustive) { | |
| 14 | 13 | if (std.math.cast(enum_info.tag_type, integer)) |tag| { |
| 15 | 14 | return @enumFromInt(tag); |
| 16 | 15 | } |
| ... | ... | @@ -32,20 +31,19 @@ pub fn fromInt(comptime E: type, integer: anytype) ?E { |
| 32 | 31 | /// the first name is used. Each field is of type Data and has the provided |
| 33 | 32 | /// default, which may be undefined. |
| 34 | 33 | pub 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 | 35 | const default_ptr: ?*const anyopaque = if (field_default) |d| @ptrCast(&d) else null; |
| 37 | 36 | return @Struct(.auto, null, std.meta.fieldNames(E), &@splat(Data), &@splat(.{ .default_value_ptr = default_ptr })); |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | /// Looks up the supplied fields in the given enum type. | |
| 41 | /// Uses only the field names, field values are ignored. | |
| 39 | /// Looks up the supplied field values in the given enum type. | |
| 42 | 40 | /// The result array is in the same order as the input. |
| 43 | pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumField) []const E { | |
| 41 | pub inline fn valuesFromFields(comptime E: type, comptime field_values: []const comptime_int) []const E { | |
| 44 | 42 | comptime { |
| 45 | @setEvalBranchQuota(@typeInfo(E).@"enum".fields.len + eval_branch_quota_cushion); | |
| 46 | var result: [fields.len]E = undefined; | |
| 47 | for (&result, fields) |*r, f| { | |
| 48 | r.* = @enumFromInt(f.value); | |
| 43 | @setEvalBranchQuota(@typeInfo(E).@"enum".field_names.len + eval_branch_quota_cushion); | |
| 44 | var result: [field_values.len]E = undefined; | |
| 45 | for (&result, field_values) |*r, f_value| { | |
| 46 | r.* = @enumFromInt(f_value); | |
| 49 | 47 | } |
| 50 | 48 | const final = result; |
| 51 | 49 | return &final; |
| ... | ... | @@ -55,17 +53,18 @@ pub inline fn valuesFromFields(comptime E: type, comptime fields: []const EnumFi |
| 55 | 53 | /// Returns the set of all named values in the given enum, in |
| 56 | 54 | /// declaration order. |
| 57 | 55 | pub 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 | } |
| 60 | 58 | |
| 61 | 59 | /// A safe alternative to @tagName() for non-exhaustive enums that doesn't |
| 62 | 60 | /// panic when `e` has no tagged value. |
| 63 | 61 | /// Returns the tag name for `e` or null if no tag exists. |
| 64 | 62 | pub fn tagName(comptime E: type, e: E) ?[:0]const u8 { |
| 65 | const fields = @typeInfo(E).@"enum".fields; | |
| 66 | @setEvalBranchQuota(fields.len); | |
| 67 | return inline for (fields) |f| { | |
| 68 | if (@intFromEnum(e) == f.value) break f.name; | |
| 63 | const field_names = @typeInfo(E).@"enum".field_names; | |
| 64 | const field_values = @typeInfo(E).@"enum".field_values; | |
| 65 | @setEvalBranchQuota(field_names.len); | |
| 66 | return inline for (field_names, field_values) |f_name, f_value| { | |
| 67 | if (@intFromEnum(e) == f_value) break f_name; | |
| 69 | 68 | } else null; |
| 70 | 69 | } |
| 71 | 70 | |
| ... | ... | @@ -88,20 +87,20 @@ test tagName { |
| 88 | 87 | pub fn directEnumArrayLen(comptime E: type, comptime max_unused_slots: comptime_int) comptime_int { |
| 89 | 88 | var max_value: comptime_int = -1; |
| 90 | 89 | const max_usize: comptime_int = ~@as(usize, 0); |
| 91 | const fields = @typeInfo(E).@"enum".fields; | |
| 92 | for (fields) |f| { | |
| 93 | if (f.value < 0) { | |
| 94 | @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " has a negative value."); | |
| 95 | } | |
| 96 | if (f.value > max_value) { | |
| 97 | if (f.value > max_usize) { | |
| 98 | @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f.name ++ " is larger than the max value of usize."); | |
| 90 | const info = @typeInfo(E).@"enum"; | |
| 91 | for (info.field_names, info.field_values) |f_name, f_value| { | |
| 92 | if (f_value < 0) { | |
| 93 | @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " has a negative value."); | |
| 94 | } | |
| 95 | if (f_value > max_value) { | |
| 96 | if (f_value > max_usize) { | |
| 97 | @compileError("Cannot create a direct enum array for " ++ @typeName(E) ++ ", field ." ++ f_name ++ " is larger than the max value of usize."); | |
| 99 | 98 | } |
| 100 | max_value = f.value; | |
| 99 | max_value = f_value; | |
| 101 | 100 | } |
| 102 | 101 | } |
| 103 | 102 | |
| 104 | const unused_slots = max_value + 1 - fields.len; | |
| 103 | const unused_slots = max_value + 1 - info.field_names.len; | |
| 105 | 104 | if (unused_slots > max_unused_slots) { |
| 106 | 105 | const unused_str = std.fmt.comptimePrint("{d}", .{unused_slots}); |
| 107 | 106 | const allowed_str = std.fmt.comptimePrint("{d}", .{max_unused_slots}); |
| ... | ... | @@ -167,10 +166,10 @@ pub fn directEnumArrayDefault( |
| 167 | 166 | ) [directEnumArrayLen(E, max_unused_slots)]Data { |
| 168 | 167 | const len = comptime directEnumArrayLen(E, max_unused_slots); |
| 169 | 168 | var result: [len]Data = @splat(default orelse undefined); |
| 170 | inline for (@typeInfo(@TypeOf(init_values)).@"struct".fields) |f| { | |
| 171 | const enum_value = @field(E, f.name); | |
| 169 | inline for (@typeInfo(@TypeOf(init_values)).@"struct".field_names) |f_name| { | |
| 170 | const enum_value = @field(E, f_name); | |
| 172 | 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 | 174 | return result; |
| 176 | 175 | } |
| ... | ... | @@ -256,9 +255,9 @@ pub fn EnumSet(comptime E: type) type { |
| 256 | 255 | |
| 257 | 256 | /// Initializes the set using a struct of bools |
| 258 | 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 | 259 | var result: Self = .{}; |
| 261 | if (@typeInfo(E).@"enum".is_exhaustive) { | |
| 260 | if (@typeInfo(E).@"enum".mode == .exhaustive) { | |
| 262 | 261 | inline for (0..Self.len) |i| { |
| 263 | 262 | const key = comptime Indexer.keyForIndex(i); |
| 264 | 263 | const tag = @tagName(key); |
| ... | ... | @@ -267,9 +266,9 @@ pub fn EnumSet(comptime E: type) type { |
| 267 | 266 | } |
| 268 | 267 | } |
| 269 | 268 | } else { |
| 270 | inline for (std.meta.fields(E)) |field| { | |
| 271 | const key = @field(E, field.name); | |
| 272 | if (@field(init_values, field.name)) { | |
| 269 | inline for (@typeInfo(E).@"enum".field_names) |field_name| { | |
| 270 | const key = @field(E, field_name); | |
| 271 | if (@field(init_values, field_name)) { | |
| 273 | 272 | const i = comptime Indexer.indexOf(key); |
| 274 | 273 | result.bits.set(i); |
| 275 | 274 | } |
| ... | ... | @@ -443,9 +442,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type { |
| 443 | 442 | |
| 444 | 443 | /// Initializes the map using a sparse struct of optionals |
| 445 | 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 | 446 | var result: Self = .{}; |
| 448 | if (@typeInfo(E).@"enum".is_exhaustive) { | |
| 447 | if (@typeInfo(E).@"enum".mode == .exhaustive) { | |
| 449 | 448 | inline for (0..Self.len) |i| { |
| 450 | 449 | const key = comptime Indexer.keyForIndex(i); |
| 451 | 450 | const tag = @tagName(key); |
| ... | ... | @@ -455,9 +454,9 @@ pub fn EnumMap(comptime E: type, comptime V: type) type { |
| 455 | 454 | } |
| 456 | 455 | } |
| 457 | 456 | } else { |
| 458 | inline for (std.meta.fields(E)) |field| { | |
| 459 | const key = @field(E, field.name); | |
| 460 | if (@field(init_values, field.name)) |*v| { | |
| 457 | inline for (std.meta.fieldNames(E)) |field_name| { | |
| 458 | const key = @field(E, field_name); | |
| 459 | if (@field(init_values, field_name)) |*v| { | |
| 461 | 460 | const i = comptime Indexer.indexOf(key); |
| 462 | 461 | result.bits.set(i); |
| 463 | 462 | result.values[i] = v.*; |
| ... | ... | @@ -487,7 +486,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type { |
| 487 | 486 | /// Initializes a full mapping with a provided default. |
| 488 | 487 | /// Consider using EnumArray instead if the map will remain full. |
| 489 | 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 | 490 | var result: Self = .{ |
| 492 | 491 | .bits = .full, |
| 493 | 492 | .values = undefined, |
| ... | ... | @@ -673,11 +672,12 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type { |
| 673 | 672 | |
| 674 | 673 | /// Initializes the multiset using a struct of counts. |
| 675 | 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 | 676 | var self = initWithCount(0); |
| 678 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 679 | const c = @field(init_counts, field.name); | |
| 680 | const key = @as(E, @enumFromInt(field.value)); | |
| 677 | const info = @typeInfo(E).@"enum"; | |
| 678 | inline for (info.field_names, info.field_values) |field_name, field_value| { | |
| 679 | const c = @field(init_counts, field_name); | |
| 680 | const key: E = @enumFromInt(field_value); | |
| 681 | 681 | self.counts.set(key, c); |
| 682 | 682 | } |
| 683 | 683 | return self; |
| ... | ... | @@ -745,16 +745,16 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type { |
| 745 | 745 | /// Increases the all key counts by given multiset. Caller |
| 746 | 746 | /// asserts operation will not overflow any key. |
| 747 | 747 | pub fn addSetAssertSafe(self: *Self, other: Self) void { |
| 748 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 749 | const key = @as(E, @enumFromInt(field.value)); | |
| 748 | inline for (@typeInfo(E).@"enum".field_values) |field_value| { | |
| 749 | const key = @as(E, @enumFromInt(field_value)); | |
| 750 | 750 | self.addAssertSafe(key, other.getCount(key)); |
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /// Increases the all key counts by given multiset. |
| 755 | 755 | pub fn addSet(self: *Self, other: Self) error{Overflow}!void { |
| 756 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 757 | const key = @as(E, @enumFromInt(field.value)); | |
| 756 | inline for (@typeInfo(E).@"enum".field_values) |field_value| { | |
| 757 | const key = @as(E, @enumFromInt(field_value)); | |
| 758 | 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 | 763 | /// the given multiset has more key counts than this, |
| 764 | 764 | /// then that key will have a key count of zero. |
| 765 | 765 | pub fn removeSet(self: *Self, other: Self) void { |
| 766 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 767 | const key = @as(E, @enumFromInt(field.value)); | |
| 766 | inline for (@typeInfo(E).@"enum".field_values) |field_value| { | |
| 767 | const key = @as(E, @enumFromInt(field_value)); | |
| 768 | 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 | 772 | /// Returns true iff all key counts are the same as |
| 773 | 773 | /// given multiset. |
| 774 | 774 | pub fn eql(self: Self, other: Self) bool { |
| 775 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 776 | const key = @as(E, @enumFromInt(field.value)); | |
| 775 | inline for (@typeInfo(E).@"enum".field_values) |field_value| { | |
| 776 | const key = @as(E, @enumFromInt(field_value)); | |
| 777 | 777 | if (self.getCount(key) != other.getCount(key)) { |
| 778 | 778 | return false; |
| 779 | 779 | } |
| ... | ... | @@ -784,8 +784,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type { |
| 784 | 784 | /// Returns true iff all key counts less than or |
| 785 | 785 | /// equal to the given multiset. |
| 786 | 786 | pub fn subsetOf(self: Self, other: Self) bool { |
| 787 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 788 | const key = @as(E, @enumFromInt(field.value)); | |
| 787 | inline for (@typeInfo(E).@"enum".field_values) |field_value| { | |
| 788 | const key = @as(E, @enumFromInt(field_value)); | |
| 789 | 789 | if (self.getCount(key) > other.getCount(key)) { |
| 790 | 790 | return false; |
| 791 | 791 | } |
| ... | ... | @@ -796,8 +796,8 @@ pub fn BoundedEnumMultiset(comptime E: type, comptime CountSize: type) type { |
| 796 | 796 | /// Returns true iff all key counts greater than or |
| 797 | 797 | /// equal to the given multiset. |
| 798 | 798 | pub fn supersetOf(self: Self, other: Self) bool { |
| 799 | inline for (@typeInfo(E).@"enum".fields) |field| { | |
| 800 | const key = @as(E, @enumFromInt(field.value)); | |
| 799 | inline for (@typeInfo(E).@"enum".field_values) |field_value| { | |
| 800 | const key = @as(E, @enumFromInt(field_value)); | |
| 801 | 801 | if (self.getCount(key) < other.getCount(key)) { |
| 802 | 802 | return false; |
| 803 | 803 | } |
| ... | ... | @@ -1075,7 +1075,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type { |
| 1075 | 1075 | |
| 1076 | 1076 | /// Initializes values in the enum array, with the specified default. |
| 1077 | 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 | 1079 | var result: Self = .{ .values = undefined }; |
| 1080 | 1080 | inline for (0..Self.len) |i| { |
| 1081 | 1081 | const key = comptime Indexer.keyForIndex(i); |
| ... | ... | @@ -1264,10 +1264,10 @@ test "EnumSet non-exhaustive" { |
| 1264 | 1264 | |
| 1265 | 1265 | pub fn EnumIndexer(comptime E: type) type { |
| 1266 | 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 | 1268 | @setEvalBranchQuota(3 * fields_len * std.math.log2(@max(fields_len, 1)) + eval_branch_quota_cushion); |
| 1269 | 1269 | |
| 1270 | if (!@typeInfo(E).@"enum".is_exhaustive) { | |
| 1270 | if (@typeInfo(E).@"enum".mode == .nonexhaustive) { | |
| 1271 | 1271 | const BackingInt = @typeInfo(E).@"enum".tag_type; |
| 1272 | 1272 | if (@bitSizeOf(BackingInt) > @bitSizeOf(usize)) |
| 1273 | 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 | 1315 | }; |
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | var fields: [fields_len]EnumField = @typeInfo(E).@"enum".fields[0..].*; | |
| 1318 | var field_values = @typeInfo(E).@"enum".field_values[0..fields_len].*; | |
| 1319 | 1319 | |
| 1320 | std.mem.sortUnstable(EnumField, &fields, {}, struct { | |
| 1321 | fn lessThan(ctx: void, lhs: EnumField, rhs: EnumField) bool { | |
| 1322 | ctx; | |
| 1323 | return lhs.value < rhs.value; | |
| 1320 | std.mem.sortUnstable(comptime_int, &field_values, {}, struct { | |
| 1321 | fn lessThan(_: void, a: comptime_int, b: comptime_int) bool { | |
| 1322 | return a < b; | |
| 1324 | 1323 | } |
| 1325 | 1324 | }.lessThan); |
| 1326 | 1325 | |
| 1327 | const min = fields[0].value; | |
| 1328 | const max = fields[fields_len - 1].value; | |
| 1329 | if (max - min == fields.len - 1) { | |
| 1326 | const min = field_values[0]; | |
| 1327 | const max = field_values[fields_len - 1]; | |
| 1328 | if (max - min == field_values.len - 1) { | |
| 1330 | 1329 | return struct { |
| 1331 | 1330 | pub const Key = E; |
| 1332 | 1331 | pub const count: comptime_int = fields_len; |
| ... | ... | @@ -1343,7 +1342,7 @@ pub fn EnumIndexer(comptime E: type) type { |
| 1343 | 1342 | }; |
| 1344 | 1343 | } |
| 1345 | 1344 | |
| 1346 | const keys = valuesFromFields(E, &fields); | |
| 1345 | const keys = valuesFromFields(E, &field_values); | |
| 1347 | 1346 | |
| 1348 | 1347 | return struct { |
| 1349 | 1348 | pub const Key = E; |
lib/std/gpu.zig+1-1| ... | ... | @@ -58,7 +58,7 @@ pub const ExecutionMode = union(Tag) { |
| 58 | 58 | |
| 59 | 59 | /// Declare the mode entry point executes in. |
| 60 | 60 | pub 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 | 62 | switch (mode) { |
| 63 | 63 | .origin_upper_left, |
| 64 | 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 | 127 | }, |
| 128 | 128 | |
| 129 | 129 | .@"struct" => |info| { |
| 130 | inline for (info.fields) |field| { | |
| 130 | inline for (info.field_names) |field_name| { | |
| 131 | 131 | // We reuse the hash of the previous field as the seed for the |
| 132 | 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 | }, |
| 136 | 136 | |
| ... | ... | @@ -138,10 +138,10 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 138 | 138 | if (info.tag_type) |tag_type| { |
| 139 | 139 | const tag = std.meta.activeTag(key); |
| 140 | 140 | hash(hasher, tag, strat); |
| 141 | inline for (info.fields) |field| { | |
| 142 | if (@field(tag_type, field.name) == tag) { | |
| 143 | if (field.type != void) { | |
| 144 | hash(hasher, @field(key, field.name), strat); | |
| 141 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 142 | if (@field(tag_type, field_name) == tag) { | |
| 143 | if (field_type != void) { | |
| 144 | hash(hasher, @field(key, field_name), strat); | |
| 145 | 145 | } |
| 146 | 146 | break :blk; |
| 147 | 147 | } |
| ... | ... | @@ -165,8 +165,8 @@ inline fn typeContainsSlice(comptime K: type) bool { |
| 165 | 165 | .pointer => |info| info.size == .slice, |
| 166 | 166 | |
| 167 | 167 | inline .@"struct", .@"union" => |info| { |
| 168 | inline for (info.fields) |field| { | |
| 169 | if (typeContainsSlice(field.type)) { | |
| 168 | inline for (info.field_types) |field_type| { | |
| 169 | if (typeContainsSlice(field_type)) { | |
| 170 | 170 | return true; |
| 171 | 171 | } |
| 172 | 172 | } |
lib/std/hash/verify.zig+3-3| ... | ... | @@ -2,8 +2,8 @@ const std = @import("std"); |
| 2 | 2 | |
| 3 | 3 | fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typeInfo(@TypeOf(hash_fn)).@"fn".return_type.? { |
| 4 | 4 | const HashFn = @typeInfo(@TypeOf(hash_fn)).@"fn"; |
| 5 | if (HashFn.params.len > 1) { | |
| 6 | if (@typeInfo(HashFn.params[0].type.?) == .int) { | |
| 5 | if (HashFn.param_types.len > 1) { | |
| 6 | if (@typeInfo(HashFn.param_types[0].?) == .int) { | |
| 7 | 7 | return hash_fn(@intCast(seed), buf); |
| 8 | 8 | } else { |
| 9 | 9 | return hash_fn(buf, @intCast(seed)); |
| ... | ... | @@ -15,7 +15,7 @@ fn hashMaybeSeed(comptime hash_fn: anytype, seed: anytype, buf: []const u8) @typ |
| 15 | 15 | |
| 16 | 16 | fn initMaybeSeed(comptime Hash: anytype, seed: anytype) Hash { |
| 17 | 17 | const HashFn = @typeInfo(@TypeOf(Hash.init)).@"fn"; |
| 18 | if (HashFn.params.len == 1) { | |
| 18 | if (HashFn.param_types.len == 1) { | |
| 19 | 19 | return Hash.init(@intCast(seed)); |
| 20 | 20 | } else { |
| 21 | 21 | return Hash.init(); |
lib/std/http/Client.zig+2-2| ... | ... | @@ -823,8 +823,8 @@ pub const Request = struct { |
| 823 | 823 | /// Externally-owned; must outlive the Request. |
| 824 | 824 | privileged_headers: []const http.Header, |
| 825 | 825 | |
| 826 | pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = b: { | |
| 827 | var result: [@typeInfo(http.ContentEncoding).@"enum".fields.len]bool = @splat(false); | |
| 826 | pub const default_accept_encoding: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = b: { | |
| 827 | var result: [@typeInfo(http.ContentEncoding).@"enum".field_names.len]bool = @splat(false); | |
| 828 | 828 | result[@intFromEnum(http.ContentEncoding.gzip)] = true; |
| 829 | 829 | result[@intFromEnum(http.ContentEncoding.deflate)] = true; |
| 830 | 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 | 401 | return v.jsonStringify(self); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | if (!enum_info.is_exhaustive) { | |
| 405 | inline for (enum_info.fields) |field| { | |
| 406 | if (v == @field(T, field.name)) { | |
| 404 | if (enum_info.mode == .nonexhaustive) { | |
| 405 | inline for (enum_info.field_names) |field_name| { | |
| 406 | if (v == @field(T, field_name)) { | |
| 407 | 407 | break; |
| 408 | 408 | } |
| 409 | 409 | } else { |
| ... | ... | @@ -424,15 +424,15 @@ pub fn write(self: *Stringify, v: anytype) Error!void { |
| 424 | 424 | const info = @typeInfo(T).@"union"; |
| 425 | 425 | if (info.tag_type) |UnionTagType| { |
| 426 | 426 | try self.beginObject(); |
| 427 | inline for (info.fields) |u_field| { | |
| 428 | if (v == @field(UnionTagType, u_field.name)) { | |
| 429 | try self.objectField(u_field.name); | |
| 430 | if (u_field.type == void) { | |
| 427 | inline for (info.field_names, info.field_types) |u_field_name, u_field_type| { | |
| 428 | if (v == @field(UnionTagType, u_field_name)) { | |
| 429 | try self.objectField(u_field_name); | |
| 430 | if (u_field_type == void) { | |
| 431 | 431 | // void v is {} |
| 432 | 432 | try self.beginObject(); |
| 433 | 433 | try self.endObject(); |
| 434 | 434 | } else { |
| 435 | try self.write(@field(v, u_field.name)); | |
| 435 | try self.write(@field(v, u_field_name)); | |
| 436 | 436 | } |
| 437 | 437 | break; |
| 438 | 438 | } |
| ... | ... | @@ -455,16 +455,16 @@ pub fn write(self: *Stringify, v: anytype) Error!void { |
| 455 | 455 | } else { |
| 456 | 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 | 459 | // don't include void fields |
| 460 | if (Field.type == void) continue; | |
| 460 | if (field_type == void) continue; | |
| 461 | 461 | |
| 462 | 462 | var emit_field = true; |
| 463 | 463 | |
| 464 | 464 | // 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 | 466 | if (self.options.emit_null_optional_fields == false) { |
| 467 | if (@field(v, Field.name) == null) { | |
| 467 | if (@field(v, field_name) == null) { | |
| 468 | 468 | emit_field = false; |
| 469 | 469 | } |
| 470 | 470 | } |
| ... | ... | @@ -472,9 +472,9 @@ pub fn write(self: *Stringify, v: anytype) Error!void { |
| 472 | 472 | |
| 473 | 473 | if (emit_field) { |
| 474 | 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 | 480 | if (S.is_tuple) { |
lib/std/json/static.zig+47-31| ... | ... | @@ -286,20 +286,20 @@ pub fn innerParse( |
| 286 | 286 | }, |
| 287 | 287 | }; |
| 288 | 288 | |
| 289 | inline for (unionInfo.fields) |u_field| { | |
| 290 | if (std.mem.eql(u8, u_field.name, field_name)) { | |
| 289 | inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| { | |
| 290 | if (std.mem.eql(u8, u_field_name, field_name)) { | |
| 291 | 291 | // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object. |
| 292 | 292 | // (Recursing into innerParse() might trigger more allocations.) |
| 293 | 293 | freeAllocated(allocator, name_token.?); |
| 294 | 294 | name_token = null; |
| 295 | if (u_field.type == void) { | |
| 295 | if (u_field_type == void) { | |
| 296 | 296 | // void isn't really a json type, but we can support void payload union tags with {} as a value. |
| 297 | 297 | if (.object_begin != try source.next()) return error.UnexpectedToken; |
| 298 | 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 | 300 | } else { |
| 301 | 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 | 304 | break; |
| 305 | 305 | } |
| ... | ... | @@ -318,8 +318,8 @@ pub fn innerParse( |
| 318 | 318 | if (.array_begin != try source.next()) return error.UnexpectedToken; |
| 319 | 319 | |
| 320 | 320 | var r: T = undefined; |
| 321 | inline for (0..structInfo.fields.len) |i| { | |
| 322 | r[i] = try innerParse(structInfo.fields[i].type, allocator, source, options); | |
| 321 | inline for (structInfo.field_types, 0..) |field_type, i| { | |
| 322 | r[i] = try innerParse(field_type, allocator, source, options); | |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | if (.array_end != try source.next()) return error.UnexpectedToken; |
| ... | ... | @@ -334,7 +334,7 @@ pub fn innerParse( |
| 334 | 334 | if (.object_begin != try source.next()) return error.UnexpectedToken; |
| 335 | 335 | |
| 336 | 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); | |
| 338 | 338 | |
| 339 | 339 | while (true) { |
| 340 | 340 | var name_token: ?Token = try source.nextAllocMax(allocator, .alloc_if_needed, options.max_value_len.?); |
| ... | ... | @@ -348,9 +348,14 @@ pub fn innerParse( |
| 348 | 348 | }, |
| 349 | 349 | }; |
| 350 | 350 | |
| 351 | inline for (structInfo.fields, 0..) |field, i| { | |
| 352 | if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name); | |
| 353 | if (std.mem.eql(u8, field.name, field_name)) { | |
| 351 | inline for ( | |
| 352 | structInfo.field_names, | |
| 353 | structInfo.field_types, | |
| 354 | structInfo.field_attrs, | |
| 355 | 0.., | |
| 356 | ) |f_name, f_type, f_attrs, i| { | |
| 357 | if (f_attrs.@"comptime") @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ f_name); | |
| 358 | if (std.mem.eql(u8, f_name, field_name)) { | |
| 354 | 359 | // Free the name token now in case we're using an allocator that optimizes freeing the last allocated object. |
| 355 | 360 | // (Recursing into innerParse() might trigger more allocations.) |
| 356 | 361 | freeAllocated(allocator, name_token.?); |
| ... | ... | @@ -360,14 +365,14 @@ pub fn innerParse( |
| 360 | 365 | .use_first => { |
| 361 | 366 | // Parse and ignore the redundant value. |
| 362 | 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 | 369 | break; |
| 365 | 370 | }, |
| 366 | 371 | .@"error" => return error.DuplicateField, |
| 367 | 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 | 376 | fields_seen[i] = true; |
| 372 | 377 | break; |
| 373 | 378 | } |
| ... | ... | @@ -493,7 +498,7 @@ pub fn innerParse( |
| 493 | 498 | _ = try source.allocNextIntoArrayList(&value_list, .alloc_always); |
| 494 | 499 | return try value_list.toOwnedSliceSentinel(s); |
| 495 | 500 | } |
| 496 | if (ptrInfo.is_const) { | |
| 501 | if (ptrInfo.attrs.@"const") { | |
| 497 | 502 | switch (try source.nextAllocMax(allocator, options.allocate.?, options.max_value_len.?)) { |
| 498 | 503 | inline .string, .allocated_string => |slice| return slice, |
| 499 | 504 | else => unreachable, |
| ... | ... | @@ -613,16 +618,16 @@ pub fn innerParseFromValue( |
| 613 | 618 | const kv = it.next().?; |
| 614 | 619 | const field_name = kv.key_ptr.*; |
| 615 | 620 | |
| 616 | inline for (unionInfo.fields) |u_field| { | |
| 617 | if (std.mem.eql(u8, u_field.name, field_name)) { | |
| 618 | if (u_field.type == void) { | |
| 621 | inline for (unionInfo.field_names, unionInfo.field_types) |u_field_name, u_field_type| { | |
| 622 | if (std.mem.eql(u8, u_field_name, field_name)) { | |
| 623 | if (u_field_type == void) { | |
| 619 | 624 | // void isn't really a json type, but we can support void payload union tags with {} as a value. |
| 620 | 625 | if (kv.value_ptr.* != .object) return error.UnexpectedToken; |
| 621 | 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 | 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 | 633 | // Didn't match anything. |
| ... | ... | @@ -632,11 +637,11 @@ pub fn innerParseFromValue( |
| 632 | 637 | .@"struct" => |structInfo| { |
| 633 | 638 | if (structInfo.is_tuple) { |
| 634 | 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; | |
| 636 | 641 | |
| 637 | 642 | var r: T = undefined; |
| 638 | inline for (0..structInfo.fields.len, source.array.items) |i, item| { | |
| 639 | r[i] = try innerParseFromValue(structInfo.fields[i].type, allocator, item, options); | |
| 643 | inline for (0..structInfo.field_names.len, source.array.items) |i, item| { | |
| 644 | r[i] = try innerParseFromValue(structInfo.field_types[i], allocator, item, options); | |
| 640 | 645 | } |
| 641 | 646 | |
| 642 | 647 | return r; |
| ... | ... | @@ -649,17 +654,22 @@ pub fn innerParseFromValue( |
| 649 | 654 | if (source != .object) return error.UnexpectedToken; |
| 650 | 655 | |
| 651 | 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); | |
| 653 | 658 | |
| 654 | 659 | var it = source.object.iterator(); |
| 655 | 660 | while (it.next()) |kv| { |
| 656 | 661 | const field_name = kv.key_ptr.*; |
| 657 | 662 | |
| 658 | inline for (structInfo.fields, 0..) |field, i| { | |
| 659 | if (field.is_comptime) @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ field.name); | |
| 660 | if (std.mem.eql(u8, field.name, field_name)) { | |
| 663 | inline for ( | |
| 664 | structInfo.field_names, | |
| 665 | structInfo.field_types, | |
| 666 | structInfo.field_attrs, | |
| 667 | 0.., | |
| 668 | ) |f_name, f_type, f_attrs, i| { | |
| 669 | if (f_attrs.@"comptime") @compileError("comptime fields are not supported: " ++ @typeName(T) ++ "." ++ f_name); | |
| 670 | if (std.mem.eql(u8, f_name, field_name)) { | |
| 661 | 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 | 673 | fields_seen[i] = true; |
| 664 | 674 | break; |
| 665 | 675 | } |
| ... | ... | @@ -782,11 +792,17 @@ fn sliceToEnum(comptime T: type, slice: []const u8) !T { |
| 782 | 792 | return std.enums.fromInt(T, n) orelse return error.InvalidEnumTag; |
| 783 | 793 | } |
| 784 | 794 | |
| 785 | fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".fields.len]bool) !void { | |
| 786 | inline for (@typeInfo(T).@"struct".fields, 0..) |field, i| { | |
| 795 | fn fillDefaultStructValues(comptime T: type, r: *T, fields_seen: *[@typeInfo(T).@"struct".field_names.len]bool) !void { | |
| 796 | const info = @typeInfo(T).@"struct"; | |
| 797 | inline for ( | |
| 798 | info.field_names, | |
| 799 | info.field_types, | |
| 800 | info.field_attrs, | |
| 801 | 0.., | |
| 802 | ) |field_name, field_type, field_attrs, i| { | |
| 787 | 803 | if (!fields_seen[i]) { |
| 788 | if (field.defaultValue()) |default| { | |
| 789 | @field(r, field.name) = default; | |
| 804 | if (field_attrs.defaultValue(field_type)) |default| { | |
| 805 | @field(r, field_name) = default; | |
| 790 | 806 | } else { |
| 791 | 807 | return error.MissingField; |
| 792 | 808 | } |
lib/std/lang.zig+65-97| ... | ... | @@ -596,13 +596,8 @@ pub const Type = union(enum) { |
| 596 | 596 | /// therefore must be kept in sync with the compiler implementation. |
| 597 | 597 | pub const Pointer = struct { |
| 598 | 598 | size: Size, |
| 599 | is_const: bool, | |
| 600 | is_volatile: bool, | |
| 601 | /// `null` means implicit alignment, which is equivalent to `@alignOf(child)`. | |
| 602 | alignment: ?usize, | |
| 603 | address_space: AddressSpace, | |
| 599 | attrs: Attributes, | |
| 604 | 600 | child: type, |
| 605 | is_allowzero: bool, | |
| 606 | 601 | |
| 607 | 602 | /// The type of the sentinel is the element type of the pointer, which is |
| 608 | 603 | /// the value of the `child` field in this struct. However there is no way |
| ... | ... | @@ -667,44 +662,40 @@ pub const Type = union(enum) { |
| 667 | 662 | |
| 668 | 663 | /// This data structure is used by the Zig language code generation and |
| 669 | 664 | /// therefore must be kept in sync with the compiler implementation. |
| 670 | pub const StructField = struct { | |
| 671 | name: [:0]const u8, | |
| 672 | type: type, | |
| 673 | /// The type of the default value is the type of this struct field, which | |
| 674 | /// is the value of the `type` field in this struct. However there is no | |
| 675 | /// way to refer to that type here, so we use `*const anyopaque`. | |
| 676 | /// See also: `defaultValue`. | |
| 677 | default_value_ptr: ?*const anyopaque, | |
| 678 | is_comptime: bool, | |
| 679 | /// `null` means the field alignment was not explicitly specified. The | |
| 680 | /// field will still be aligned to at least `@alignOf` its `type`. | |
| 681 | alignment: ?usize, | |
| 682 | ||
| 683 | /// Loads the field's default value from `default_value_ptr`. | |
| 684 | /// Returns `null` if the field has no default value. | |
| 685 | pub inline fn defaultValue(comptime sf: StructField) ?sf.type { | |
| 686 | const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null)); | |
| 687 | return dp.*; | |
| 688 | } | |
| 665 | pub const Struct = struct { | |
| 666 | is_tuple: bool, | |
| 667 | layout: ContainerLayout, | |
| 668 | /// Always `null` if `layout != .@"packed"`. | |
| 669 | backing_integer: ?type, | |
| 689 | 670 | |
| 690 | /// This data structure is used by the Zig language code generation and | |
| 691 | /// therefore must be kept in sync with the compiler implementation. | |
| 692 | pub const Attributes = struct { | |
| 671 | field_names: []const [:0]const u8, | |
| 672 | /// Guaranteed to have the same length as `field_names`. | |
| 673 | field_types: []const type, | |
| 674 | /// Guaranteed to have the same length as `field_names`. | |
| 675 | field_attrs: []const FieldAttributes, | |
| 676 | ||
| 677 | decl_names: []const [:0]const u8, | |
| 678 | ||
| 679 | pub const FieldAttributes = struct { | |
| 693 | 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 | 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 | 689 | default_value_ptr: ?*const anyopaque = null, |
| 696 | }; | |
| 697 | }; | |
| 698 | 690 | |
| 699 | /// This data structure is used by the Zig language code generation and | |
| 700 | /// therefore must be kept in sync with the compiler implementation. | |
| 701 | pub const Struct = struct { | |
| 702 | layout: ContainerLayout, | |
| 703 | /// Only valid if layout is .@"packed" | |
| 704 | backing_integer: ?type = null, | |
| 705 | fields: []const StructField, | |
| 706 | decls: []const Declaration, | |
| 707 | is_tuple: bool, | |
| 691 | /// Loads the field's default value from `default_value_ptr`. | |
| 692 | /// `FieldType` must exactly match the corresponding element of `Struct.field_types`. | |
| 693 | /// Returns `null` if the field has no default value. | |
| 694 | pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType { | |
| 695 | const dp: *const FieldType = @ptrCast(@alignCast(attrs.default_value_ptr orelse return null)); | |
| 696 | return dp.*; | |
| 697 | } | |
| 698 | }; | |
| 708 | 699 | }; |
| 709 | 700 | |
| 710 | 701 | /// This data structure is used by the Zig language code generation and |
| ... | ... | @@ -722,48 +713,25 @@ pub const Type = union(enum) { |
| 722 | 713 | |
| 723 | 714 | /// This data structure is used by the Zig language code generation and |
| 724 | 715 | /// therefore must be kept in sync with the compiler implementation. |
| 725 | pub const Error = struct { | |
| 726 | name: [:0]const u8, | |
| 727 | }; | |
| 728 | ||
| 729 | /// This data structure is used by the Zig language code generation and | |
| 730 | /// therefore must be kept in sync with the compiler implementation. | |
| 731 | pub const ErrorSet = ?[]const Error; | |
| 732 | ||
| 733 | /// This data structure is used by the Zig language code generation and | |
| 734 | /// therefore must be kept in sync with the compiler implementation. | |
| 735 | pub const EnumField = struct { | |
| 736 | name: [:0]const u8, | |
| 737 | value: comptime_int, | |
| 716 | pub const ErrorSet = struct { | |
| 717 | error_names: ?[]const [:0]const u8, | |
| 738 | 718 | }; |
| 739 | 719 | |
| 740 | 720 | /// This data structure is used by the Zig language code generation and |
| 741 | 721 | /// therefore must be kept in sync with the compiler implementation. |
| 742 | 722 | pub const Enum = struct { |
| 743 | 723 | tag_type: type, |
| 744 | fields: []const EnumField, | |
| 745 | decls: []const Declaration, | |
| 746 | is_exhaustive: bool, | |
| 724 | mode: Mode, | |
| 747 | 725 | |
| 748 | /// This data structure is used by the Zig language code generation and | |
| 749 | /// therefore must be kept in sync with the compiler implementation. | |
| 750 | pub const Mode = enum { exhaustive, nonexhaustive }; | |
| 751 | }; | |
| 726 | field_names: []const [:0]const u8, | |
| 727 | /// Guaranteed to have the same length as `field_names`. | |
| 728 | field_values: []const comptime_int, | |
| 752 | 729 | |
| 753 | /// This data structure is used by the Zig language code generation and | |
| 754 | /// therefore must be kept in sync with the compiler implementation. | |
| 755 | pub const UnionField = struct { | |
| 756 | name: [:0]const u8, | |
| 757 | type: type, | |
| 758 | /// `null` means the field alignment was not explicitly specified. The | |
| 759 | /// field will still be aligned to at least `@alignOf` its `type`. | |
| 760 | alignment: ?usize, | |
| 730 | decl_names: []const [:0]const u8, | |
| 761 | 731 | |
| 762 | 732 | /// This data structure is used by the Zig language code generation and |
| 763 | 733 | /// therefore must be kept in sync with the compiler implementation. |
| 764 | pub const Attributes = struct { | |
| 765 | @"align": ?usize = null, | |
| 766 | }; | |
| 734 | pub const Mode = enum { exhaustive, nonexhaustive }; | |
| 767 | 735 | }; |
| 768 | 736 | |
| 769 | 737 | /// This data structure is used by the Zig language code generation and |
| ... | ... | @@ -771,36 +739,42 @@ pub const Type = union(enum) { |
| 771 | 739 | pub const Union = struct { |
| 772 | 740 | layout: ContainerLayout, |
| 773 | 741 | tag_type: ?type, |
| 774 | fields: []const UnionField, | |
| 775 | decls: []const Declaration, | |
| 742 | /// Always `null` if `layout != .@"packed"`. | |
| 743 | backing_integer: ?type, | |
| 744 | ||
| 745 | field_names: []const [:0]const u8, | |
| 746 | /// Guaranteed to have the same length as `field_names`. | |
| 747 | field_types: []const type, | |
| 748 | /// Guaranteed to have the same length as `field_names`. | |
| 749 | field_attrs: []const FieldAttributes, | |
| 750 | ||
| 751 | decl_names: []const [:0]const u8, | |
| 752 | ||
| 753 | pub const FieldAttributes = struct { | |
| 754 | /// `null` means the field alignment is not explicitly specified. The field will still | |
| 755 | /// be aligned to at least `@alignOf` the field type. | |
| 756 | @"align": ?usize = null, | |
| 757 | }; | |
| 776 | 758 | }; |
| 777 | 759 | |
| 778 | 760 | /// This data structure is used by the Zig language code generation and |
| 779 | 761 | /// therefore must be kept in sync with the compiler implementation. |
| 780 | 762 | pub const Fn = struct { |
| 781 | calling_convention: CallingConvention, | |
| 763 | attrs: Attributes, | |
| 782 | 764 | is_generic: bool, |
| 783 | is_var_args: bool, | |
| 784 | /// TODO change the language spec to make this not optional. | |
| 765 | /// `null` means the return type is generic, i.e. it depends on a function argument. | |
| 785 | 766 | return_type: ?type, |
| 786 | params: []const Param, | |
| 787 | 767 | |
| 788 | /// This data structure is used by the Zig language code generation and | |
| 789 | /// therefore must be kept in sync with the compiler implementation. | |
| 790 | pub const Param = struct { | |
| 791 | is_generic: bool, | |
| 792 | is_noalias: bool, | |
| 793 | type: ?type, | |
| 794 | ||
| 795 | /// This data structure is used by the Zig language code generation and | |
| 796 | /// therefore must be kept in sync with the compiler implementation. | |
| 797 | pub const Attributes = struct { | |
| 798 | @"noalias": bool = false, | |
| 799 | }; | |
| 768 | /// A `null` element represents either an `anytype` parameter, or a parameter with a generic | |
| 769 | /// type, i.e. where the type depends on a previous function argument. | |
| 770 | param_types: []const ?type, | |
| 771 | /// Guaranteed to have the same length as `param_types`. | |
| 772 | param_attrs: []const ParamAttributes, | |
| 773 | ||
| 774 | pub const ParamAttributes = struct { | |
| 775 | @"noalias": bool = false, | |
| 800 | 776 | }; |
| 801 | 777 | |
| 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 | 778 | pub const Attributes = struct { |
| 805 | 779 | @"callconv": CallingConvention = .auto, |
| 806 | 780 | varargs: bool = false, |
| ... | ... | @@ -810,7 +784,7 @@ pub const Type = union(enum) { |
| 810 | 784 | /// This data structure is used by the Zig language code generation and |
| 811 | 785 | /// therefore must be kept in sync with the compiler implementation. |
| 812 | 786 | pub const Opaque = struct { |
| 813 | decls: []const Declaration, | |
| 787 | decl_names: []const [:0]const u8, | |
| 814 | 788 | }; |
| 815 | 789 | |
| 816 | 790 | /// This data structure is used by the Zig language code generation and |
| ... | ... | @@ -831,12 +805,6 @@ pub const Type = union(enum) { |
| 831 | 805 | len: comptime_int, |
| 832 | 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 | }; |
| 841 | 809 | |
| 842 | 810 | /// 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 | 1648 | } |
| 1649 | 1649 | |
| 1650 | 1650 | test reverse { |
| 1651 | inline for (@typeInfo(CompareOperator).@"enum".fields) |op_field| { | |
| 1652 | const op = @as(CompareOperator, @enumFromInt(op_field.value)); | |
| 1651 | inline for (@typeInfo(CompareOperator).@"enum".field_values) |op_field_value| { | |
| 1652 | const op = @as(CompareOperator, @enumFromInt(op_field_value)); | |
| 1653 | 1653 | try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2)); |
| 1654 | 1654 | try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3)); |
| 1655 | 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 | 297 | return item; |
| 298 | 298 | } else { |
| 299 | 299 | var structure: T = undefined; |
| 300 | inline for (struct_info.fields) |field| { | |
| 301 | if (!field.is_comptime) { | |
| 302 | @field(structure, field.name) = zeroes(field.type); | |
| 300 | inline for ( | |
| 301 | struct_info.field_names, | |
| 302 | struct_info.field_types, | |
| 303 | struct_info.field_attrs, | |
| 304 | ) |field_name, field_type, field_attrs| { | |
| 305 | if (!field_attrs.@"comptime") { | |
| 306 | @field(structure, field_name) = zeroes(field_type); | |
| 303 | 307 | } |
| 304 | 308 | } |
| 305 | 309 | return structure; |
| ... | ... | @@ -321,7 +325,7 @@ pub fn zeroes(comptime T: type) T { |
| 321 | 325 | return null; |
| 322 | 326 | }, |
| 323 | 327 | .one, .many => { |
| 324 | if (ptr_info.is_allowzero) return @ptrFromInt(0); | |
| 328 | if (ptr_info.attrs.@"allowzero") return @ptrFromInt(0); | |
| 325 | 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 | 475 | switch (@typeInfo(Init)) { |
| 472 | 476 | .@"struct" => |init_info| { |
| 473 | 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 | 479 | @compileError("Tuple initializer has more elements than there are fields in `" ++ @typeName(T) ++ "`"); |
| 476 | 480 | } |
| 477 | 481 | } else { |
| 478 | inline for (init_info.fields) |field| { | |
| 479 | if (!@hasField(T, field.name)) { | |
| 480 | @compileError("Encountered an initializer for `" ++ field.name ++ "`, but it is not a field of " ++ @typeName(T)); | |
| 482 | inline for (init_info.field_names) |field_name| { | |
| 483 | if (!@hasField(T, field_name)) { | |
| 484 | @compileError("Encountered an initializer for `" ++ field_name ++ "`, but it is not a field of " ++ @typeName(T)); | |
| 481 | 485 | } |
| 482 | 486 | } |
| 483 | 487 | } |
| 484 | 488 | |
| 485 | 489 | var value: T = if (struct_info.layout == .@"extern") zeroes(T) else undefined; |
| 486 | 490 | |
| 487 | inline for (struct_info.fields, 0..) |field, i| { | |
| 488 | if (field.is_comptime) { | |
| 491 | inline for ( | |
| 492 | struct_info.field_names, | |
| 493 | struct_info.field_types, | |
| 494 | struct_info.field_attrs, | |
| 495 | 0.., | |
| 496 | ) |f_name, f_type, f_attr, i| { | |
| 497 | if (f_attr.@"comptime") { | |
| 489 | 498 | continue; |
| 490 | 499 | } |
| 491 | 500 | |
| 492 | if (init_info.is_tuple and init_info.fields.len > i) { | |
| 493 | @field(value, field.name) = @field(init, init_info.fields[i].name); | |
| 494 | } else if (@hasField(@TypeOf(init), field.name)) { | |
| 495 | switch (@typeInfo(field.type)) { | |
| 501 | if (init_info.is_tuple and init_info.field_names.len > i) { | |
| 502 | @field(value, f_name) = @field(init, init_info.field_names[i]); | |
| 503 | } else if (@hasField(@TypeOf(init), f_name)) { | |
| 504 | switch (@typeInfo(f_type)) { | |
| 496 | 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 | 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| { | |
| 504 | @field(value, field.name) = val; | |
| 512 | } else if (f_attr.defaultValue(f_type)) |val| { | |
| 513 | @field(value, f_name) = val; | |
| 505 | 514 | } else { |
| 506 | switch (@typeInfo(field.type)) { | |
| 515 | switch (@typeInfo(f_type)) { | |
| 507 | 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 | 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 | 876 | .many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)), |
| 868 | 877 | .c => 0, |
| 869 | 878 | }; |
| 870 | return @Pointer(.slice, .{ | |
| 871 | .@"const" = ptr_info.is_const, | |
| 872 | .@"volatile" = ptr_info.is_volatile, | |
| 873 | .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c, | |
| 874 | .@"align" = ptr_info.alignment, | |
| 875 | .@"addrspace" = ptr_info.address_space, | |
| 876 | }, ptr_info.child, new_sentinel); | |
| 879 | var attrs = ptr_info.attrs; | |
| 880 | attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c; | |
| 881 | return @Pointer(.slice, attrs, ptr_info.child, new_sentinel); | |
| 877 | 882 | }, |
| 878 | 883 | else => {}, |
| 879 | 884 | } |
| ... | ... | @@ -933,13 +938,9 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type { |
| 933 | 938 | .many => if (std.meta.sentinel(T)) |s| s == end else true, |
| 934 | 939 | .c => true, |
| 935 | 940 | }; |
| 936 | return @Pointer(.slice, .{ | |
| 937 | .@"const" = ptr_info.is_const, | |
| 938 | .@"volatile" = ptr_info.is_volatile, | |
| 939 | .@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c, | |
| 940 | .@"align" = ptr_info.alignment, | |
| 941 | .@"addrspace" = ptr_info.address_space, | |
| 942 | }, Elem, if (have_sentinel) end else null); | |
| 941 | var attrs = ptr_info.attrs; | |
| 942 | attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c; | |
| 943 | return @Pointer(.slice, attrs, Elem, if (have_sentinel) end else null); | |
| 943 | 944 | }, |
| 944 | 945 | else => {}, |
| 945 | 946 | } |
| ... | ... | @@ -2210,19 +2211,19 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a |
| 2210 | 2211 | .@"struct" => |struct_info| { |
| 2211 | 2212 | if (struct_info.backing_integer) |Int| { |
| 2212 | 2213 | ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*)))); |
| 2213 | } else inline for (std.meta.fields(S)) |f| { | |
| 2214 | switch (@typeInfo(f.type)) { | |
| 2215 | .@"struct" => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)), | |
| 2216 | .@"union", .array => byteSwapAllFieldsAligned(f.type, .fromByteUnits(f.alignment orelse @alignOf(f.type)), &@field(ptr, f.name)), | |
| 2214 | } else inline for (struct_info.field_types, struct_info.field_names, struct_info.field_attrs) |f_type, f_name, f_attr| { | |
| 2215 | switch (@typeInfo(f_type)) { | |
| 2216 | .@"struct" => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)), | |
| 2217 | .@"union", .array => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)), | |
| 2217 | 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 | 2221 | .bool => {}, |
| 2221 | 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 | 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 | 2233 | @compileError("byteSwapAllFields expects an untagged union"); |
| 2233 | 2234 | } |
| 2234 | 2235 | |
| 2235 | const first_size = @bitSizeOf(union_info.fields[0].type); | |
| 2236 | inline for (union_info.fields) |field| { | |
| 2237 | if (@bitSizeOf(field.type) != first_size) { | |
| 2236 | const first_size = @bitSizeOf(union_info.field_types[0]); | |
| 2237 | inline for (union_info.field_types) |field_type| { | |
| 2238 | if (@bitSizeOf(field_type) != first_size) { | |
| 2238 | 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 | 3941 | .many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"), |
| 3941 | 3942 | } |
| 3942 | 3943 | const Element = std.meta.Elem(T); |
| 3943 | const attrs: std.builtin.Type.Pointer.Attributes = .{ | |
| 3944 | .@"const" = ptr.is_const, | |
| 3945 | .@"volatile" = ptr.is_volatile, | |
| 3946 | .@"allowzero" = ptr.is_allowzero, | |
| 3947 | .@"align" = ptr.alignment, | |
| 3948 | .@"addrspace" = ptr.address_space, | |
| 3949 | }; | |
| 3950 | const Pointer = @Pointer(.many, attrs, Element, std.meta.sentinel(T)); | |
| 3951 | const ElementPointer = @Pointer(.one, attrs, Element, null); | |
| 3944 | const Pointer = @Pointer(.many, ptr.attrs, Element, std.meta.sentinel(T)); | |
| 3945 | const ElementPointer = @Pointer(.one, ptr.attrs, Element, null); | |
| 3952 | 3946 | return struct { |
| 3953 | 3947 | ptr: Pointer, |
| 3954 | 3948 | index: usize, |
| ... | ... | @@ -4255,7 +4249,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize { |
| 4255 | 4249 | @compileError("expected many item pointer, got " ++ @typeName(T)); |
| 4256 | 4250 | |
| 4257 | 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 | 4253 | return 0; |
| 4260 | 4254 | |
| 4261 | 4255 | // Calculate the aligned base address with an eye out for overflow. |
| ... | ... | @@ -4309,17 +4303,14 @@ fn CopyPtrAttrs( |
| 4309 | 4303 | comptime child: type, |
| 4310 | 4304 | ) type { |
| 4311 | 4305 | const ptr = @typeInfo(source).pointer; |
| 4312 | return @Pointer(size, .{ | |
| 4313 | .@"const" = ptr.is_const, | |
| 4314 | .@"volatile" = ptr.is_volatile, | |
| 4315 | .@"allowzero" = ptr.is_allowzero, | |
| 4316 | .@"align" = ptr.alignment orelse a: { | |
| 4317 | // If the new child is aligned differently than the old one, explicitly align the type. | |
| 4318 | const want = @alignOf(ptr.child); | |
| 4319 | break :a if (@alignOf(child) == want) null else want; | |
| 4320 | }, | |
| 4321 | .@"addrspace" = ptr.address_space, | |
| 4322 | }, child, null); | |
| 4306 | var attrs = ptr.attrs; | |
| 4307 | if (attrs.@"align" == null) { | |
| 4308 | const want = @alignOf(ptr.child); | |
| 4309 | if (@alignOf(child) != want) { | |
| 4310 | attrs.@"align" = want; | |
| 4311 | } | |
| 4312 | } | |
| 4313 | return @Pointer(size, attrs, child, null); | |
| 4323 | 4314 | } |
| 4324 | 4315 | |
| 4325 | 4316 | fn AsBytesReturnType(comptime P: type) type { |
| ... | ... | @@ -4383,10 +4374,13 @@ test "asBytes preserves pointer attributes" { |
| 4383 | 4374 | const in = @typeInfo(@TypeOf(inPtr)).pointer; |
| 4384 | 4375 | const out = @typeInfo(@TypeOf(outSlice)).pointer; |
| 4385 | 4376 | |
| 4386 | try testing.expectEqual(in.is_const, out.is_const); | |
| 4387 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 4388 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 4389 | try testing.expectEqual(in.alignment, out.alignment); | |
| 4377 | const in_attrs = in.attrs; | |
| 4378 | const out_attrs = out.attrs; | |
| 4379 | ||
| 4380 | try testing.expectEqual(in_attrs.@"const", out_attrs.@"const"); | |
| 4381 | try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile"); | |
| 4382 | try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero"); | |
| 4383 | try testing.expectEqual(in_attrs.@"align", out_attrs.@"align"); | |
| 4390 | 4384 | } |
| 4391 | 4385 | |
| 4392 | 4386 | /// Given any value, returns a copy of its bytes in an array. |
| ... | ... | @@ -4463,13 +4457,13 @@ test "bytesAsValue preserves pointer attributes" { |
| 4463 | 4457 | const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..]; |
| 4464 | 4458 | const outPtr = bytesAsValue(u32, inSlice); |
| 4465 | 4459 | |
| 4466 | const in = @typeInfo(@TypeOf(inSlice)).pointer; | |
| 4467 | const out = @typeInfo(@TypeOf(outPtr)).pointer; | |
| 4460 | const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs; | |
| 4461 | const out_attrs = @typeInfo(@TypeOf(outPtr)).pointer.attrs; | |
| 4468 | 4462 | |
| 4469 | try testing.expectEqual(in.is_const, out.is_const); | |
| 4470 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 4471 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 4472 | try testing.expectEqual(in.alignment, out.alignment); | |
| 4463 | try testing.expectEqual(in_attrs.@"const", out_attrs.@"const"); | |
| 4464 | try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile"); | |
| 4465 | try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero"); | |
| 4466 | try testing.expectEqual(in_attrs.@"align", out_attrs.@"align"); | |
| 4473 | 4467 | } |
| 4474 | 4468 | |
| 4475 | 4469 | /// 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 | 4560 | const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..]; |
| 4567 | 4561 | const outSlice = bytesAsSlice(u16, inSlice); |
| 4568 | 4562 | |
| 4569 | const in = @typeInfo(@TypeOf(inSlice)).pointer; | |
| 4570 | const out = @typeInfo(@TypeOf(outSlice)).pointer; | |
| 4563 | const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs; | |
| 4564 | const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs; | |
| 4571 | 4565 | |
| 4572 | try testing.expectEqual(in.is_const, out.is_const); | |
| 4573 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 4574 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 4575 | try testing.expectEqual(in.alignment, out.alignment); | |
| 4566 | try testing.expectEqual(in_attrs.@"const", out_attrs.@"const"); | |
| 4567 | try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile"); | |
| 4568 | try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero"); | |
| 4569 | try testing.expectEqual(in_attrs.@"align", out_attrs.@"align"); | |
| 4576 | 4570 | } |
| 4577 | 4571 | |
| 4578 | 4572 | test "bytesAsSlice with zero-bit element type" { |
| ... | ... | @@ -4678,25 +4672,19 @@ test "sliceAsBytes preserves pointer attributes" { |
| 4678 | 4672 | const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..]; |
| 4679 | 4673 | const outSlice = sliceAsBytes(inSlice); |
| 4680 | 4674 | |
| 4681 | const in = @typeInfo(@TypeOf(inSlice)).pointer; | |
| 4682 | const out = @typeInfo(@TypeOf(outSlice)).pointer; | |
| 4675 | const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs; | |
| 4676 | const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs; | |
| 4683 | 4677 | |
| 4684 | try testing.expectEqual(in.is_const, out.is_const); | |
| 4685 | try testing.expectEqual(in.is_volatile, out.is_volatile); | |
| 4686 | try testing.expectEqual(in.is_allowzero, out.is_allowzero); | |
| 4687 | try testing.expectEqual(in.alignment, out.alignment); | |
| 4678 | try testing.expectEqual(in_attrs.@"const", out_attrs.@"const"); | |
| 4679 | try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile"); | |
| 4680 | try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero"); | |
| 4681 | try testing.expectEqual(in_attrs.@"align", out_attrs.@"align"); | |
| 4688 | 4682 | } |
| 4689 | 4683 | |
| 4690 | 4684 | fn AbsorbSentinelReturnType(comptime Slice: type) type { |
| 4691 | 4685 | const info = @typeInfo(Slice).pointer; |
| 4692 | 4686 | assert(info.size == .slice); |
| 4693 | return @Pointer(.slice, .{ | |
| 4694 | .@"const" = info.is_const, | |
| 4695 | .@"volatile" = info.is_volatile, | |
| 4696 | .@"allowzero" = info.is_allowzero, | |
| 4697 | .@"addrspace" = info.address_space, | |
| 4698 | .@"align" = info.alignment, | |
| 4699 | }, info.child, null); | |
| 4687 | return @Pointer(.slice, info.attrs, info.child, null); | |
| 4700 | 4688 | } |
| 4701 | 4689 | |
| 4702 | 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 | 4937 | /// all other pointer attributes copied from `AttributeSource`. |
| 4950 | 4938 | fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type { |
| 4951 | 4939 | const ptr = @typeInfo(AttributeSource).pointer; |
| 4952 | return @Pointer(.slice, .{ | |
| 4953 | .@"const" = ptr.is_const, | |
| 4954 | .@"volatile" = ptr.is_volatile, | |
| 4955 | .@"allowzero" = ptr.is_allowzero, | |
| 4956 | .@"align" = new_alignment, | |
| 4957 | .@"addrspace" = ptr.address_space, | |
| 4958 | }, ptr.child, null); | |
| 4940 | var attrs = ptr.attrs; | |
| 4941 | attrs.@"align" = new_alignment; | |
| 4942 | return @Pointer(.slice, attrs, ptr.child, null); | |
| 4959 | 4943 | } |
| 4960 | 4944 | |
| 4961 | 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 | 183 | const non_const_ptr = @as([*]u8, @ptrCast(@constCast(ptr))); |
| 184 | 184 | self.rawFree( |
| 185 | 185 | non_const_ptr[0..@sizeOf(T)], |
| 186 | .fromByteUnits(info.alignment orelse @alignOf(T)), | |
| 186 | .fromByteUnits(info.attrs.@"align" orelse @alignOf(T)), | |
| 187 | 187 | @returnAddress(), |
| 188 | 188 | ); |
| 189 | 189 | } |
| ... | ... | @@ -331,7 +331,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool { |
| 331 | 331 | const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return false; |
| 332 | 332 | return self.rawResize( |
| 333 | 333 | old_memory, |
| 334 | .fromByteUnits(slice_info.alignment orelse @alignOf(T)), | |
| 334 | .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), | |
| 335 | 335 | new_len_bytes, |
| 336 | 336 | @returnAddress(), |
| 337 | 337 | ); |
| ... | ... | @@ -377,7 +377,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo |
| 377 | 377 | const new_len_bytes = math.mul(usize, @sizeOf(T), new_len) catch return null; |
| 378 | 378 | const new_ptr = self.rawRemap( |
| 379 | 379 | old_memory, |
| 380 | .fromByteUnits(slice_info.alignment orelse @alignOf(T)), | |
| 380 | .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), | |
| 381 | 381 | new_len_bytes, |
| 382 | 382 | @returnAddress(), |
| 383 | 383 | ) orelse return null; |
| ... | ... | @@ -412,11 +412,11 @@ pub fn reallocAdvanced( |
| 412 | 412 | comptime assert(slice_info.size == .slice); |
| 413 | 413 | const T = slice_info.child; |
| 414 | 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 | 417 | if (new_n == 0) { |
| 418 | 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 | 420 | const addr = comptime std.mem.alignBackward(usize, math.maxInt(usize), alignment); |
| 421 | 421 | const ptr: *align(alignment) [0]T = @ptrFromInt(addr); |
| 422 | 422 | return ptr; |
| ... | ... | @@ -425,16 +425,16 @@ pub fn reallocAdvanced( |
| 425 | 425 | const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem))); |
| 426 | 426 | const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory; |
| 427 | 427 | // 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 | 429 | return @ptrCast(@alignCast(p[0..byte_count])); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), return_address) orelse | |
| 432 | const new_mem = self.rawAlloc(byte_count, .fromByteUnits(slice_info.attrs.@"align" orelse @alignOf(T)), return_address) orelse | |
| 433 | 433 | return error.OutOfMemory; |
| 434 | 434 | const copy_len = @min(byte_count, old_byte_slice.len); |
| 435 | 435 | @memcpy(new_mem[0..copy_len], old_byte_slice[0..copy_len]); |
| 436 | 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); | |
| 438 | 438 | |
| 439 | 439 | return @ptrCast(@alignCast(new_mem[0..byte_count])); |
| 440 | 440 | } |
| ... | ... | @@ -448,7 +448,7 @@ pub fn free(self: Allocator, memory: anytype) void { |
| 448 | 448 | const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory))); |
| 449 | 449 | if (bytes.len == 0) return; |
| 450 | 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 | } |
| 453 | 453 | |
| 454 | 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 | 8 | |
| 9 | 9 | pub const TrailerFlags = @import("meta/trailer_flags.zig").TrailerFlags; |
| 10 | 10 | |
| 11 | const Type = std.builtin.Type; | |
| 11 | const Type = std.lang.Type; | |
| 12 | 12 | |
| 13 | 13 | test { |
| 14 | 14 | _ = TrailerFlags; |
| ... | ... | @@ -22,21 +22,21 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T { |
| 22 | 22 | // TODO The '100' here is arbitrary and should be increased when possible: |
| 23 | 23 | // - https://github.com/ziglang/zig/issues/4055 |
| 24 | 24 | // - 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 | 26 | const kvs = comptime build_kvs: { |
| 27 | 27 | const EnumKV = struct { []const u8, T }; |
| 28 | var kvs_array: [@typeInfo(T).@"enum".fields.len]EnumKV = undefined; | |
| 29 | for (@typeInfo(T).@"enum".fields, 0..) |enumField, i| { | |
| 30 | kvs_array[i] = .{ enumField.name, @field(T, enumField.name) }; | |
| 28 | var kvs_array: [@typeInfo(T).@"enum".field_names.len]EnumKV = undefined; | |
| 29 | for (@typeInfo(T).@"enum".field_names, 0..) |name, i| { | |
| 30 | kvs_array[i] = .{ name, @field(T, name) }; | |
| 31 | 31 | } |
| 32 | 32 | break :build_kvs kvs_array[0..]; |
| 33 | 33 | }; |
| 34 | 34 | const map = std.StaticStringMap(T).initComptime(kvs); |
| 35 | 35 | return map.get(str); |
| 36 | 36 | } else { |
| 37 | inline for (@typeInfo(T).@"enum".fields) |enumField| { | |
| 38 | if (mem.eql(u8, str, enumField.name)) { | |
| 39 | return @field(T, enumField.name); | |
| 37 | inline for (@typeInfo(T).@"enum".field_names) |name| { | |
| 38 | if (mem.eql(u8, str, name)) { | |
| 39 | return @field(T, name); | |
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | return null; |
| ... | ... | @@ -63,7 +63,7 @@ pub fn alignment(comptime T: type) comptime_int { |
| 63 | 63 | .pointer, .@"fn" => alignment(info.child), |
| 64 | 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 | 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 | 171 | switch (@typeInfo(T)) { |
| 172 | 172 | .pointer => |info| switch (info.size) { |
| 173 | 173 | .one => switch (@typeInfo(info.child)) { |
| 174 | .array => |array_info| return @Pointer(.one, .{ | |
| 175 | .@"const" = info.is_const, | |
| 176 | .@"volatile" = info.is_volatile, | |
| 177 | .@"allowzero" = info.is_allowzero, | |
| 178 | .@"align" = info.alignment, | |
| 179 | .@"addrspace" = info.address_space, | |
| 180 | }, [array_info.len:sentinel_val]array_info.child, null), | |
| 174 | .array => |array_info| return @Pointer( | |
| 175 | .one, | |
| 176 | info.attrs, | |
| 177 | [array_info.len:sentinel_val]array_info.child, | |
| 178 | null, | |
| 179 | ), | |
| 181 | 180 | else => {}, |
| 182 | 181 | }, |
| 183 | .many, .slice => |size| return @Pointer(size, .{ | |
| 184 | .@"const" = info.is_const, | |
| 185 | .@"volatile" = info.is_volatile, | |
| 186 | .@"allowzero" = info.is_allowzero, | |
| 187 | .@"align" = info.alignment, | |
| 188 | .@"addrspace" = info.address_space, | |
| 189 | }, info.child, sentinel_val), | |
| 182 | .many, .slice => |size| return @Pointer(size, info.attrs, info.child, sentinel_val), | |
| 190 | 183 | else => {}, |
| 191 | 184 | }, |
| 192 | 185 | .optional => |info| switch (@typeInfo(info.child)) { |
| 193 | 186 | .pointer => |ptr_info| switch (ptr_info.size) { |
| 194 | .many => return ?@Pointer(.many, .{ | |
| 195 | .@"const" = ptr_info.is_const, | |
| 196 | .@"volatile" = ptr_info.is_volatile, | |
| 197 | .@"allowzero" = ptr_info.is_allowzero, | |
| 198 | .@"align" = ptr_info.alignment, | |
| 199 | .@"addrspace" = ptr_info.address_space, | |
| 200 | .child = ptr_info.child, | |
| 201 | }, ptr_info.child, sentinel_val), | |
| 187 | .many => return ?@Pointer(.many, ptr_info.attrs, ptr_info.child, sentinel_val), | |
| 202 | 188 | else => {}, |
| 203 | 189 | }, |
| 204 | 190 | else => {}, |
| ... | ... | @@ -238,14 +224,14 @@ test containerLayout { |
| 238 | 224 | try testing.expect(containerLayout(U3) == .@"extern"); |
| 239 | 225 | } |
| 240 | 226 | |
| 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 | 228 | /// directly when you know what kind of type it is. |
| 243 | pub fn declarations(comptime T: type) []const Type.Declaration { | |
| 229 | pub fn declarations(comptime T: type) []const [:0]const u8 { | |
| 244 | 230 | return switch (@typeInfo(T)) { |
| 245 | .@"struct" => |info| info.decls, | |
| 246 | .@"enum" => |info| info.decls, | |
| 247 | .@"union" => |info| info.decls, | |
| 248 | .@"opaque" => |info| info.decls, | |
| 231 | .@"struct" => |info| info.decl_names, | |
| 232 | .@"enum" => |info| info.decl_names, | |
| 233 | .@"union" => |info| info.decl_names, | |
| 234 | .@"opaque" => |info| info.decl_names, | |
| 249 | 235 | else => @compileError("Expected struct, enum, union, or opaque type, found '" ++ @typeName(T) ++ "'"), |
| 250 | 236 | }; |
| 251 | 237 | } |
| ... | ... | @@ -268,7 +254,7 @@ test declarations { |
| 268 | 254 | pub fn a() void {} |
| 269 | 255 | }; |
| 270 | 256 | |
| 271 | const decls = comptime [_][]const Type.Declaration{ | |
| 257 | const decls = comptime [_][]const [:0]const u8{ | |
| 272 | 258 | declarations(E1), |
| 273 | 259 | declarations(S1), |
| 274 | 260 | declarations(U1), |
| ... | ... | @@ -277,99 +263,43 @@ test declarations { |
| 277 | 263 | |
| 278 | 264 | inline for (decls) |decl| { |
| 279 | 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 | } |
| 283 | 269 | |
| 284 | pub fn declarationInfo(comptime T: type, comptime decl_name: []const u8) Type.Declaration { | |
| 285 | inline for (comptime declarations(T)) |decl| { | |
| 286 | if (comptime mem.eql(u8, decl.name, decl_name)) | |
| 287 | return decl; | |
| 288 | } | |
| 289 | ||
| 290 | @compileError("'" ++ @typeName(T) ++ "' has no declaration '" ++ decl_name ++ "'"); | |
| 291 | } | |
| 292 | ||
| 293 | test declarationInfo { | |
| 294 | const E1 = enum { | |
| 295 | A, | |
| 296 | ||
| 297 | pub fn a() void {} | |
| 298 | }; | |
| 299 | const S1 = struct { | |
| 300 | pub fn a() void {} | |
| 301 | }; | |
| 302 | const U1 = union { | |
| 303 | b: u8, | |
| 304 | ||
| 305 | pub fn a() void {} | |
| 306 | }; | |
| 307 | ||
| 308 | const infos = comptime [_]Type.Declaration{ | |
| 309 | declarationInfo(E1, "a"), | |
| 310 | declarationInfo(S1, "a"), | |
| 311 | declarationInfo(U1, "a"), | |
| 312 | }; | |
| 270 | /// To be removed after Zig 0.17.0 is tagged. | |
| 271 | pub const declarationInfo = @compileError("Deprecated; use '@hasDecl' instead"); | |
| 272 | /// To be removed after Zig 0.17.0 is tagged. | |
| 273 | pub const fields = @compileError("Deprecated; use 'fieldNames' and 'fieldTypes' instead"); | |
| 313 | 274 | |
| 314 | inline for (infos) |info| { | |
| 315 | try testing.expect(comptime mem.eql(u8, info.name, "a")); | |
| 316 | } | |
| 317 | } | |
| 318 | pub inline fn fields(comptime T: type) switch (@typeInfo(T)) { | |
| 319 | .@"struct" => []const Type.StructField, | |
| 320 | .@"union" => []const Type.UnionField, | |
| 321 | .@"enum" => []const Type.EnumField, | |
| 322 | .error_set => []const Type.Error, | |
| 275 | pub fn fieldInfo(comptime T: type, comptime field: FieldEnum(T)) switch (@typeInfo(T)) { | |
| 276 | .@"struct" => struct { name: [:0]const u8, type: type, attrs: Type.Struct.FieldAttributes }, | |
| 277 | .@"union" => struct { name: [:0]const u8, type: type, attrs: Type.Union.FieldAttributes }, | |
| 278 | .@"enum" => struct { name: [:0]const u8, value: comptime_int }, | |
| 279 | .error_set => struct { name: [:0]const u8 }, | |
| 323 | 280 | else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"), |
| 324 | 281 | } { |
| 282 | const idx = @intFromEnum(field); | |
| 325 | 283 | return switch (@typeInfo(T)) { |
| 326 | .@"struct" => |info| info.fields, | |
| 327 | .@"union" => |info| info.fields, | |
| 328 | .@"enum" => |info| info.fields, | |
| 329 | .error_set => |errors| errors.?, // must be non global error set | |
| 284 | .@"struct" => |info| .{ | |
| 285 | .name = info.field_names[idx], | |
| 286 | .type = info.field_types[idx], | |
| 287 | .attrs = info.field_attrs[idx], | |
| 288 | }, | |
| 289 | .@"union" => |info| .{ | |
| 290 | .name = info.field_names[idx], | |
| 291 | .type = info.field_types[idx], | |
| 292 | .attrs = info.field_attrs[idx], | |
| 293 | }, | |
| 294 | .@"enum" => |info| .{ | |
| 295 | .name = info.field_names[idx], | |
| 296 | .value = info.field_values[idx], | |
| 297 | }, | |
| 298 | .error_set => |info| .{ .name = info.error_names.?[idx] }, | |
| 330 | 299 | else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"), |
| 331 | 300 | }; |
| 332 | 301 | } |
| 333 | 302 | |
| 334 | test 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 | ||
| 363 | pub 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 | ||
| 373 | 303 | test fieldInfo { |
| 374 | 304 | const E1 = enum { |
| 375 | 305 | A, |
| ... | ... | @@ -395,13 +325,13 @@ test fieldInfo { |
| 395 | 325 | try testing.expect(comptime uf.type == u8); |
| 396 | 326 | } |
| 397 | 327 | |
| 398 | pub fn fieldNames(comptime T: type) *const [fields(T).len][:0]const u8 { | |
| 399 | return comptime blk: { | |
| 400 | const fieldInfos = fields(T); | |
| 401 | var names: [fieldInfos.len][:0]const u8 = undefined; | |
| 402 | for (&names, fieldInfos) |*name, field| name.* = field.name; | |
| 403 | const final = names; | |
| 404 | break :blk &final; | |
| 328 | pub fn fieldNames(comptime T: type) []const [:0]const u8 { | |
| 329 | return switch (@typeInfo(T)) { | |
| 330 | .@"struct" => |s| s.field_names, | |
| 331 | .@"union" => |u| u.field_names, | |
| 332 | .@"enum" => |e| e.field_names, | |
| 333 | .error_set => |es| es.error_names.?, | |
| 334 | else => @compileError("Expected struct, union, error set or enum type, found '" ++ @typeName(T) ++ "'"), | |
| 405 | 335 | }; |
| 406 | 336 | } |
| 407 | 337 | |
| ... | ... | @@ -433,14 +363,41 @@ test fieldNames { |
| 433 | 363 | try testing.expectEqualSlices(u8, u1names[1], "b"); |
| 434 | 364 | } |
| 435 | 365 | |
| 366 | pub 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 | ||
| 374 | test 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 | 393 | /// Given an enum or error set type, returns a pointer to an array containing all tags for that |
| 437 | 394 | /// enum or error set. |
| 438 | pub fn tags(comptime T: type) *const [fields(T).len]T { | |
| 395 | pub fn tags(comptime T: type) *const [fieldNames(T).len]T { | |
| 439 | 396 | return comptime blk: { |
| 440 | const fieldInfos = fields(T); | |
| 441 | var res: [fieldInfos.len]T = undefined; | |
| 442 | for (fieldInfos, 0..) |field, i| { | |
| 443 | res[i] = @field(T, field.name); | |
| 397 | const field_names = fieldNames(T); | |
| 398 | var res: [field_names.len]T = undefined; | |
| 399 | for (field_names, 0..) |field_name, i| { | |
| 400 | res[i] = @field(T, field_name); | |
| 444 | 401 | } |
| 445 | 402 | const final = res; |
| 446 | 403 | break :blk &final; |
| ... | ... | @@ -491,27 +448,30 @@ fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void { |
| 491 | 448 | // because the language does not guarantee that the slice pointers for field names |
| 492 | 449 | // and decl names will be the same. |
| 493 | 450 | comptime { |
| 494 | const expected_fields = @typeInfo(expected).@"enum".fields; | |
| 495 | const actual_fields = @typeInfo(actual).@"enum".fields; | |
| 496 | if (expected_fields.len != actual_fields.len) return error.FailedTest; | |
| 497 | for (expected_fields, 0..) |expected_field, i| { | |
| 498 | const actual_field = actual_fields[i]; | |
| 499 | try testing.expectEqual(expected_field.value, actual_field.value); | |
| 500 | try testing.expectEqualStrings(expected_field.name, actual_field.name); | |
| 451 | const expected_field_names = @typeInfo(expected).@"enum".field_names; | |
| 452 | const expected_field_values = @typeInfo(expected).@"enum".field_values; | |
| 453 | const actual_field_names = @typeInfo(actual).@"enum".field_names; | |
| 454 | const actual_field_values = @typeInfo(actual).@"enum".field_values; | |
| 455 | if (expected_field_names.len != actual_field_names.len) return error.FailedTest; | |
| 456 | for (expected_field_names, expected_field_values, 0..) |expected_field_name, expected_field_value, i| { | |
| 457 | const actual_field_name = actual_field_names[i]; | |
| 458 | const actual_field_value = actual_field_values[i]; | |
| 459 | try testing.expectEqual(expected_field_value, actual_field_value); | |
| 460 | try testing.expectEqualStrings(expected_field_name, actual_field_name); | |
| 501 | 461 | } |
| 502 | 462 | } |
| 503 | 463 | comptime { |
| 504 | const expected_decls = @typeInfo(expected).@"enum".decls; | |
| 505 | const actual_decls = @typeInfo(actual).@"enum".decls; | |
| 506 | if (expected_decls.len != actual_decls.len) return error.FailedTest; | |
| 507 | for (expected_decls, 0..) |expected_decl, i| { | |
| 508 | const actual_decl = actual_decls[i]; | |
| 509 | try testing.expectEqualStrings(expected_decl.name, actual_decl.name); | |
| 464 | const expected_decl_names = @typeInfo(expected).@"enum".decl_names; | |
| 465 | const actual_decl_names = @typeInfo(actual).@"enum".decl_names; | |
| 466 | if (expected_decl_names.len != actual_decl_names.len) return error.FailedTest; | |
| 467 | for (expected_decl_names, 0..) |expected_decl_name, i| { | |
| 468 | const actual_decl_name = actual_decl_names[i]; | |
| 469 | try testing.expectEqualStrings(expected_decl_name, actual_decl_name); | |
| 510 | 470 | } |
| 511 | 471 | } |
| 512 | 472 | try testing.expectEqual( |
| 513 | @typeInfo(expected).@"enum".is_exhaustive, | |
| 514 | @typeInfo(actual).@"enum".is_exhaustive, | |
| 473 | @typeInfo(expected).@"enum".mode, | |
| 474 | @typeInfo(actual).@"enum".mode, | |
| 515 | 475 | ); |
| 516 | 476 | } |
| 517 | 477 | |
| ... | ... | @@ -534,11 +494,9 @@ test FieldEnum { |
| 534 | 494 | } |
| 535 | 495 | |
| 536 | 496 | pub fn DeclEnum(comptime T: type) type { |
| 537 | const decls = declarations(T); | |
| 538 | var names: [decls.len][]const u8 = undefined; | |
| 539 | for (&names, decls) |*name, decl| name.* = decl.name; | |
| 540 | const IntTag = std.math.IntFittingRange(0, decls.len -| 1); | |
| 541 | return @Enum(IntTag, .exhaustive, &names, &std.simd.iota(IntTag, decls.len)); | |
| 497 | const decl_names = declarations(T); | |
| 498 | const IntTag = std.math.IntFittingRange(0, decl_names.len -| 1); | |
| 499 | return @Enum(IntTag, .exhaustive, decl_names, &std.simd.iota(IntTag, decl_names.len)); | |
| 542 | 500 | } |
| 543 | 501 | |
| 544 | 502 | test DeclEnum { |
| ... | ... | @@ -622,8 +580,8 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool { |
| 622 | 580 | .@"struct" => |info| { |
| 623 | 581 | if (info.layout == .@"packed") return a == b; |
| 624 | 582 | |
| 625 | inline for (info.fields) |field_info| { | |
| 626 | if (!eql(@field(a, field_info.name), @field(b, field_info.name))) return false; | |
| 583 | inline for (info.field_names) |field_name| { | |
| 584 | if (!eql(@field(a, field_name), @field(b, field_name))) return false; | |
| 627 | 585 | } |
| 628 | 586 | return true; |
| 629 | 587 | }, |
| ... | ... | @@ -744,8 +702,8 @@ test eql { |
| 744 | 702 | /// Given a type and a name, return the field index according to source order. |
| 745 | 703 | /// Returns `null` if the field is not found. |
| 746 | 704 | pub fn fieldIndex(comptime T: type, comptime name: []const u8) ?comptime_int { |
| 747 | inline for (fields(T), 0..) |field, i| { | |
| 748 | if (mem.eql(u8, field.name, name)) | |
| 705 | inline for (fieldNames(T), 0..) |field_name, i| { | |
| 706 | if (mem.eql(u8, field_name, name)) | |
| 749 | 707 | return i; |
| 750 | 708 | } |
| 751 | 709 | return null; |
| ... | ... | @@ -782,12 +740,12 @@ pub fn ArgsTuple(comptime Function: type) type { |
| 782 | 740 | @compileError("ArgsTuple expects a function type"); |
| 783 | 741 | |
| 784 | 742 | const function_info = info.@"fn"; |
| 785 | if (function_info.is_var_args) | |
| 743 | if (function_info.attrs.varargs) | |
| 786 | 744 | @compileError("Cannot create ArgsTuple for variadic function"); |
| 787 | 745 | |
| 788 | var argument_field_list: [function_info.params.len]type = undefined; | |
| 789 | inline for (function_info.params, 0..) |arg, i| { | |
| 790 | const T = arg.type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter"); | |
| 746 | var argument_field_list: [function_info.param_types.len]type = undefined; | |
| 747 | inline for (function_info.param_types, 0..) |arg_type, i| { | |
| 748 | const T = arg_type orelse @compileError("cannot create ArgsTuple for function with an 'anytype' parameter"); | |
| 791 | 749 | argument_field_list[i] = T; |
| 792 | 750 | } |
| 793 | 751 | |
| ... | ... | @@ -807,13 +765,15 @@ const TupleTester = struct { |
| 807 | 765 | if (!info.@"struct".is_tuple) |
| 808 | 766 | @compileError("Struct type must be a tuple type"); |
| 809 | 767 | |
| 810 | const fields_list = std.meta.fields(Actual); | |
| 811 | if (expected.len != fields_list.len) | |
| 812 | @compileError("Argument count mismatch"); | |
| 768 | const field_names = info.@"struct".field_names; | |
| 769 | if (expected.len != field_names.len) { | |
| 770 | const msg = std.fmt.comptimePrint("Argument count mismatch: expected {d}, got {d}", .{ expected.len, field_names.len }); | |
| 771 | @compileError(msg); | |
| 772 | } | |
| 813 | 773 | |
| 814 | inline for (fields_list, 0..) |fld, i| { | |
| 815 | if (expected[i] != fld.type) { | |
| 816 | @compileError("Field " ++ fld.name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld.type)); | |
| 774 | inline for (field_names, info.@"struct".field_types, 0..) |fld_name, fld_type, i| { | |
| 775 | if (expected[i] != fld_type) { | |
| 776 | @compileError("Field " ++ fld_name ++ " expected to be type " ++ @typeName(expected[i]) ++ ", but was type " ++ @typeName(fld_type)); | |
| 817 | 777 | } |
| 818 | 778 | } |
| 819 | 779 | } |
| ... | ... | @@ -943,7 +903,7 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool { |
| 943 | 903 | .pointer => |info| info.size != .slice, |
| 944 | 904 | |
| 945 | 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 | 907 | .slice, .c => false, |
| 948 | 908 | .one, .many => true, |
| 949 | 909 | }, |
| ... | ... | @@ -957,10 +917,10 @@ pub inline fn hasUniqueRepresentation(comptime T: type) bool { |
| 957 | 917 | |
| 958 | 918 | var sum_size = @as(usize, 0); |
| 959 | 919 | |
| 960 | inline for (info.fields) |field| { | |
| 961 | if (field.is_comptime) continue; | |
| 962 | if (!hasUniqueRepresentation(field.type)) return false; | |
| 963 | sum_size += @sizeOf(field.type); | |
| 920 | inline for (info.field_attrs, info.field_types) |field_attr, field_type| { | |
| 921 | if (field_attr.@"comptime") continue; | |
| 922 | if (!hasUniqueRepresentation(field_type)) return false; | |
| 923 | sum_size += @sizeOf(field_type); | |
| 964 | 924 | } |
| 965 | 925 | |
| 966 | 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 | 14 | bits: Int, |
| 15 | 15 | |
| 16 | 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; | |
| 18 | 18 | |
| 19 | 19 | pub const FieldEnum = std.meta.FieldEnum(Fields); |
| 20 | 20 | |
| ... | ... | @@ -22,11 +22,18 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 22 | 22 | pub const FieldValues = blk: { |
| 23 | 23 | var field_names: [bit_count][]const u8 = undefined; |
| 24 | 24 | var field_types: [bit_count]type = undefined; |
| 25 | var field_attrs: [bit_count]std.builtin.Type.StructField.Attributes = undefined; | |
| 26 | for (@typeInfo(Fields).@"struct".fields, &field_names, &field_types, &field_attrs) |field, *new_name, *NewType, *new_attrs| { | |
| 27 | new_name.* = field.name; | |
| 28 | NewType.* = ?field.type; | |
| 29 | const default: ?field.type = null; | |
| 25 | var field_attrs: [bit_count]std.builtin.Type.Struct.FieldAttributes = undefined; | |
| 26 | const fields_info = @typeInfo(Fields).@"struct"; | |
| 27 | for ( | |
| 28 | fields_info.field_names, | |
| 29 | fields_info.field_types, | |
| 30 | &field_names, | |
| 31 | &field_types, | |
| 32 | &field_attrs, | |
| 33 | ) |field_name, field_type, *new_name, *NewType, *new_attrs| { | |
| 34 | new_name.* = field_name; | |
| 35 | NewType.* = ?field_type; | |
| 36 | const default: ?field_type = null; | |
| 30 | 37 | new_attrs.* = .{ .default_value_ptr = &default }; |
| 31 | 38 | } |
| 32 | 39 | break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs); |
| ... | ... | @@ -53,8 +60,8 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 53 | 60 | /// `fields` is a boolean struct where each active field is set to `true` |
| 54 | 61 | pub fn init(fields: ActiveFields) Self { |
| 55 | 62 | var self: Self = .{ .bits = 0 }; |
| 56 | inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| { | |
| 57 | if (@field(fields, field.name)) | |
| 63 | inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| { | |
| 64 | if (@field(fields, field_name)) | |
| 58 | 65 | self.bits |= 1 << i; |
| 59 | 66 | } |
| 60 | 67 | return self; |
| ... | ... | @@ -62,8 +69,8 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 62 | 69 | |
| 63 | 70 | /// `fields` is a struct with each field set to an optional value |
| 64 | 71 | pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void { |
| 65 | inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| { | |
| 66 | if (@field(fields, field.name)) |value| | |
| 72 | inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| { | |
| 73 | if (@field(fields, field_name)) |value| | |
| 67 | 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 | 100 | |
| 94 | 101 | pub fn offset(self: Self, comptime field: FieldEnum) usize { |
| 95 | 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 | 104 | const active = (self.bits & (1 << i)) != 0; |
| 98 | 105 | if (i == @intFromEnum(field)) { |
| 99 | 106 | assert(active); |
| 100 | return mem.alignForward(usize, off, @alignOf(field_info.type)); | |
| 107 | return mem.alignForward(usize, off, @alignOf(field_type)); | |
| 101 | 108 | } else if (active) { |
| 102 | off = mem.alignForward(usize, off, @alignOf(field_info.type)); | |
| 103 | off += @sizeOf(field_info.type); | |
| 109 | off = mem.alignForward(usize, off, @alignOf(field_type)); | |
| 110 | off += @sizeOf(field_type); | |
| 104 | 111 | } |
| 105 | 112 | } |
| 106 | 113 | } |
| 107 | 114 | |
| 108 | 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 | } |
| 111 | 118 | |
| 112 | 119 | pub fn sizeInBytes(self: Self) usize { |
| 113 | 120 | var off: usize = 0; |
| 114 | inline for (@typeInfo(Fields).@"struct".fields, 0..) |field, i| { | |
| 115 | if (@sizeOf(field.type) == 0) | |
| 121 | inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| { | |
| 122 | if (@sizeOf(field_type) == 0) | |
| 116 | 123 | continue; |
| 117 | 124 | if ((self.bits & (1 << i)) != 0) { |
| 118 | off = mem.alignForward(usize, off, @alignOf(field.type)); | |
| 119 | off += @sizeOf(field.type); | |
| 125 | off = mem.alignForward(usize, off, @alignOf(field_type)); | |
| 126 | off += @sizeOf(field_type); | |
| 120 | 127 | } |
| 121 | 128 | } |
| 122 | 129 | return off; |
lib/std/multi_array_list.zig+49-57| ... | ... | @@ -44,17 +44,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 44 | 44 | const Elem = switch (@typeInfo(T)) { |
| 45 | 45 | .@"struct" => T, |
| 46 | 46 | .@"union" => |u| struct { |
| 47 | pub const Bare = Bare: { | |
| 48 | var field_names: [u.fields.len][]const u8 = undefined; | |
| 49 | var field_types: [u.fields.len]type = undefined; | |
| 50 | var field_attrs: [u.fields.len]std.builtin.Type.UnionField.Attributes = undefined; | |
| 51 | for (u.fields, &field_names, &field_types, &field_attrs) |field, *name, *Type, *attrs| { | |
| 52 | name.* = field.name; | |
| 53 | Type.* = field.type; | |
| 54 | attrs.* = .{ .@"align" = field.alignment }; | |
| 55 | } | |
| 56 | break :Bare @Union(u.layout, null, &field_names, &field_types, &field_attrs); | |
| 57 | }; | |
| 47 | pub const Bare = @Union(u.layout, null, u.field_names, u.field_types[0..], u.field_attrs[0..]); | |
| 58 | 48 | pub const Tag = |
| 59 | 49 | u.tag_type orelse @compileError("MultiArrayList does not support untagged unions"); |
| 60 | 50 | tags: Tag, |
| ... | ... | @@ -87,7 +77,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 87 | 77 | pub const Slice = struct { |
| 88 | 78 | /// This array is indexed by the field index which can be obtained |
| 89 | 79 | /// by using @intFromEnum() on the Field enum |
| 90 | ptrs: [fields.len][*]u8, | |
| 80 | ptrs: [field_names.len][*]u8, | |
| 91 | 81 | len: usize, |
| 92 | 82 | capacity: usize, |
| 93 | 83 | |
| ... | ... | @@ -116,15 +106,15 @@ pub fn MultiArrayList(comptime T: type) type { |
| 116 | 106 | .@"union" => Elem.fromT(elem), |
| 117 | 107 | else => unreachable, |
| 118 | 108 | }; |
| 119 | inline for (fields, 0..) |field_info, i| { | |
| 120 | self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_info.name); | |
| 109 | inline for (field_names, 0..) |field_name, i| { | |
| 110 | self.items(@as(Field, @enumFromInt(i)))[index] = @field(e, field_name); | |
| 121 | 111 | } |
| 122 | 112 | } |
| 123 | 113 | |
| 124 | 114 | pub fn get(self: Slice, index: usize) T { |
| 125 | 115 | var result: Elem = undefined; |
| 126 | inline for (fields, 0..) |field_info, i| { | |
| 127 | @field(result, field_info.name) = self.items(@as(Field, @enumFromInt(i)))[index]; | |
| 116 | inline for (field_names, 0..) |field_name, i| { | |
| 117 | @field(result, field_name) = self.items(@as(Field, @enumFromInt(i)))[index]; | |
| 128 | 118 | } |
| 129 | 119 | return switch (@typeInfo(T)) { |
| 130 | 120 | .@"struct" => result, |
| ... | ... | @@ -134,9 +124,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 134 | 124 | } |
| 135 | 125 | |
| 136 | 126 | pub fn swap(self: Slice, a: usize, b: usize) void { |
| 137 | inline for (@typeInfo(Field).@"enum".fields) |field| { | |
| 138 | const its = self.items(@field(Field, field.name)); | |
| 139 | std.mem.swap(@FieldType(T, field.name), &its[a], &its[b]); | |
| 127 | inline for (@typeInfo(Field).@"enum".field_names) |field_name| { | |
| 128 | const its = self.items(@field(Field, field_name)); | |
| 129 | std.mem.swap(@FieldType(T, field_name), &its[a], &its[b]); | |
| 140 | 130 | } |
| 141 | 131 | } |
| 142 | 132 | |
| ... | ... | @@ -162,9 +152,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 162 | 152 | /// Asserts that `off + len <= s.len`. |
| 163 | 153 | pub fn subslice(s: Slice, off: usize, len: usize) Slice { |
| 164 | 154 | assert(off + len <= s.len); |
| 165 | var ptrs: [fields.len][*]u8 = undefined; | |
| 166 | inline for (s.ptrs, &ptrs, fields) |in, *out, field| { | |
| 167 | out.* = in + (off * @sizeOf(field.type)); | |
| 155 | var ptrs: [field_names.len][*]u8 = undefined; | |
| 156 | inline for (s.ptrs, &ptrs, field_types) |in, *out, field_type| { | |
| 157 | out.* = in + (off * @sizeOf(field_type)); | |
| 168 | 158 | } |
| 169 | 159 | return .{ |
| 170 | 160 | .ptrs = ptrs, |
| ... | ... | @@ -185,7 +175,9 @@ pub fn MultiArrayList(comptime T: type) type { |
| 185 | 175 | |
| 186 | 176 | const Self = @This(); |
| 187 | 177 | |
| 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 | 181 | /// `sizes.bytes` is an array of @sizeOf each T field. Sorted by alignment, descending. |
| 190 | 182 | /// `sizes.fields` is an array mapping from `sizes.bytes` array index to field index. |
| 191 | 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 | 187 | size_index: usize, |
| 196 | 188 | alignment: usize, |
| 197 | 189 | }; |
| 198 | var data: [fields.len]Data = undefined; | |
| 190 | var data: [field_names.len]Data = undefined; | |
| 199 | 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 | 193 | data[i] = .{ |
| 202 | .size = @sizeOf(field_info.type), | |
| 194 | .size = @sizeOf(f_type), | |
| 203 | 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 | 198 | big_align = @max(big_align, data[i].alignment); |
| 207 | 199 | } |
| ... | ... | @@ -211,10 +203,10 @@ pub fn MultiArrayList(comptime T: type) type { |
| 211 | 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 | 207 | mem.sort(Data, &data, {}, Sort.lessThan); |
| 216 | var sizes_bytes: [fields.len]usize = undefined; | |
| 217 | var field_indexes: [fields.len]usize = undefined; | |
| 208 | var sizes_bytes: [field_names.len]usize = undefined; | |
| 209 | var field_indexes: [field_names.len]usize = undefined; | |
| 218 | 210 | for (data, 0..) |elem, i| { |
| 219 | 211 | sizes_bytes[i] = elem.size; |
| 220 | 212 | field_indexes[i] = elem.size_index; |
| ... | ... | @@ -368,13 +360,13 @@ pub fn MultiArrayList(comptime T: type) type { |
| 368 | 360 | else => unreachable, |
| 369 | 361 | }; |
| 370 | 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 | 364 | const field_slice = slices.items(@as(Field, @enumFromInt(field_index))); |
| 373 | 365 | var i: usize = self.len - 1; |
| 374 | 366 | while (i > index) : (i -= 1) { |
| 375 | 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 | } |
| 380 | 372 | |
| ... | ... | @@ -394,7 +386,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 394 | 386 | /// retain list ordering. |
| 395 | 387 | pub fn swapRemove(self: *Self, index: usize) void { |
| 396 | 388 | const slices = self.slice(); |
| 397 | inline for (fields, 0..) |_, i| { | |
| 389 | inline for (field_names, 0..) |_, i| { | |
| 398 | 390 | const field_slice = slices.items(@as(Field, @enumFromInt(i))); |
| 399 | 391 | field_slice[index] = field_slice[self.len - 1]; |
| 400 | 392 | field_slice[self.len - 1] = undefined; |
| ... | ... | @@ -406,7 +398,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 406 | 398 | /// after it to preserve order. |
| 407 | 399 | pub fn orderedRemove(self: *Self, index: usize) void { |
| 408 | 400 | const slices = self.slice(); |
| 409 | inline for (fields, 0..) |_, field_index| { | |
| 401 | inline for (field_names, 0..) |_, field_index| { | |
| 410 | 402 | const field_slice = slices.items(@as(Field, @enumFromInt(field_index))); |
| 411 | 403 | var i = index; |
| 412 | 404 | while (i < self.len - 1) : (i += 1) { |
| ... | ... | @@ -437,7 +429,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 437 | 429 | if (removed == end) continue; // allows duplicates in `sorted_indexes` |
| 438 | 430 | const start = removed + 1; |
| 439 | 431 | 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 | 433 | const field_slice = slices.items(@enumFromInt(field_index)); |
| 442 | 434 | @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 | 438 | const start = sorted_indexes[sorted_indexes.len - 1] + 1; |
| 447 | 439 | const end = self.len; |
| 448 | 440 | 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 | 442 | const field_slice = slices.items(@enumFromInt(field_index)); |
| 451 | 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 | 463 | |
| 472 | 464 | const other_bytes = gpa.alignedAlloc(u8, sizes.big_align, capacityInBytes(new_len)) catch { |
| 473 | 465 | const self_slice = self.slice(); |
| 474 | inline for (fields, 0..) |field_info, i| { | |
| 475 | if (@sizeOf(field_info.type) != 0) { | |
| 466 | inline for (field_types, 0..) |field_type, i| { | |
| 467 | if (@sizeOf(field_type) != 0) { | |
| 476 | 468 | const field = @as(Field, @enumFromInt(i)); |
| 477 | 469 | const dest_slice = self_slice.items(field)[new_len..]; |
| 478 | 470 | // We use memset here for more efficient codegen in safety-checked, |
| ... | ... | @@ -492,8 +484,8 @@ pub fn MultiArrayList(comptime T: type) type { |
| 492 | 484 | self.len = new_len; |
| 493 | 485 | const self_slice = self.slice(); |
| 494 | 486 | const other_slice = other.slice(); |
| 495 | inline for (fields, 0..) |field_info, i| { | |
| 496 | if (@sizeOf(field_info.type) != 0) { | |
| 487 | inline for (field_types, 0..) |field_type, i| { | |
| 488 | if (@sizeOf(field_type) != 0) { | |
| 497 | 489 | const field = @as(Field, @enumFromInt(i)); |
| 498 | 490 | @memcpy(other_slice.items(field), self_slice.items(field)); |
| 499 | 491 | } |
| ... | ... | @@ -529,7 +521,7 @@ pub fn MultiArrayList(comptime T: type) type { |
| 529 | 521 | |
| 530 | 522 | const init_capacity: comptime_int = init: { |
| 531 | 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 | 525 | break :init @max(1, std.atomic.cache_line / max); |
| 534 | 526 | }; |
| 535 | 527 | |
| ... | ... | @@ -564,8 +556,8 @@ pub fn MultiArrayList(comptime T: type) type { |
| 564 | 556 | }; |
| 565 | 557 | const self_slice = self.slice(); |
| 566 | 558 | const other_slice = other.slice(); |
| 567 | inline for (fields, 0..) |field_info, i| { | |
| 568 | if (@sizeOf(field_info.type) != 0) { | |
| 559 | inline for (field_types, 0..) |field_type, i| { | |
| 560 | if (@sizeOf(field_type) != 0) { | |
| 569 | 561 | const field = @as(Field, @enumFromInt(i)); |
| 570 | 562 | @memcpy(other_slice.items(field), self_slice.items(field)); |
| 571 | 563 | } |
| ... | ... | @@ -583,8 +575,8 @@ pub fn MultiArrayList(comptime T: type) type { |
| 583 | 575 | result.len = self.len; |
| 584 | 576 | const self_slice = self.slice(); |
| 585 | 577 | const result_slice = result.slice(); |
| 586 | inline for (fields, 0..) |field_info, i| { | |
| 587 | if (@sizeOf(field_info.type) != 0) { | |
| 578 | inline for (field_types, 0..) |field_type, i| { | |
| 579 | if (@sizeOf(field_type) != 0) { | |
| 588 | 580 | const field = @as(Field, @enumFromInt(i)); |
| 589 | 581 | @memcpy(result_slice.items(field), self_slice.items(field)); |
| 590 | 582 | } |
| ... | ... | @@ -600,11 +592,11 @@ pub fn MultiArrayList(comptime T: type) type { |
| 600 | 592 | slice: Slice, |
| 601 | 593 | |
| 602 | 594 | pub fn swap(sc: @This(), a_index: usize, b_index: usize) void { |
| 603 | inline for (fields, 0..) |field_info, i| { | |
| 604 | if (@sizeOf(field_info.type) != 0) { | |
| 595 | inline for (field_types, 0..) |field_type, i| { | |
| 596 | if (@sizeOf(field_type) != 0) { | |
| 605 | 597 | const field: Field = @enumFromInt(i); |
| 606 | 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 | 668 | } |
| 677 | 669 | |
| 678 | 670 | const Entry = entry: { |
| 679 | var field_names: [fields.len][]const u8 = undefined; | |
| 680 | var field_types: [fields.len]type = undefined; | |
| 681 | var field_attrs: [fields.len]std.builtin.Type.StructField.Attributes = undefined; | |
| 682 | for (sizes.fields, &field_names, &field_types, &field_attrs) |i, *name, *Type, *attrs| { | |
| 683 | name.* = fields[i].name ++ "_ptr"; | |
| 684 | Type.* = *fields[i].type; | |
| 671 | var entry_field_names: [field_names.len][]const u8 = undefined; | |
| 672 | var entry_field_types: [field_names.len]type = undefined; | |
| 673 | var entry_field_attrs: [field_names.len]std.builtin.Type.Struct.FieldAttributes = undefined; | |
| 674 | for (sizes.fields, &entry_field_names, &entry_field_types, &entry_field_attrs) |i, *name, *Type, *attrs| { | |
| 675 | name.* = field_names[i] ++ "_ptr"; | |
| 676 | Type.* = *field_types[i]; | |
| 685 | 677 | attrs.* = .{ |
| 686 | .@"comptime" = fields[i].is_comptime, | |
| 687 | .@"align" = fields[i].alignment, | |
| 678 | .@"comptime" = field_attrs[i].@"comptime", | |
| 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 | 684 | /// This function is used in the debugger pretty formatters in tools/ to fetch the |
| 693 | 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 | 82 | } |
| 83 | 83 | |
| 84 | 84 | pub fn getDevicePath(self: *const DevicePath) ?uefi.DevicePath { |
| 85 | inline for (@typeInfo(uefi.DevicePath).@"union".fields) |ufield| { | |
| 86 | const enum_value = std.meta.stringToEnum(uefi.DevicePath.Type, ufield.name); | |
| 85 | const u_info = @typeInfo(uefi.DevicePath).@"union"; | |
| 86 | inline for (u_info.field_names, u_info.field_types) |ufield_name, ufield_type| { | |
| 87 | const enum_value = std.meta.stringToEnum(uefi.DevicePath.Type, ufield_name); | |
| 87 | 88 | |
| 88 | 89 | // Got the associated union type for self.type, now |
| 89 | 90 | // we need to initialize it and its subtype |
| 90 | 91 | if (self.type == enum_value) { |
| 91 | const subtype = self.initSubtype(ufield.type); | |
| 92 | const subtype = self.initSubtype(ufield_type); | |
| 92 | 93 | if (subtype) |sb| { |
| 93 | 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 | 104 | const type_info = @typeInfo(TUnion).@"union"; |
| 104 | 105 | const TTag = type_info.tag_type.?; |
| 105 | 106 | |
| 106 | inline for (type_info.fields) |subtype| { | |
| 107 | inline for (type_info.field_names, type_info.field_types) |subtype_name, subtype_type| { | |
| 107 | 108 | // 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)); | |
| 109 | 110 | |
| 110 | 111 | if (self.subtype == tag_val) { |
| 111 | 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 | } |
| 115 | 116 |
lib/std/os/uefi/tables/boot_services.zig+1-1| ... | ... | @@ -1271,7 +1271,7 @@ fn ProtocolInterfaces(HandleType: type, Interfaces: type) type { |
| 1271 | 1271 | @compileError("expected tuple of protocol interfaces, got " ++ @typeName(Interfaces)); |
| 1272 | 1272 | const interfaces_info = interfaces_type_info.@"struct"; |
| 1273 | 1273 | |
| 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 | 1275 | tuple_types[0] = HandleType; |
| 1276 | 1276 | tuple_types[tuple_types.len - 1] = ?*const Guid; |
| 1277 | 1277 |
lib/std/os/windows.zig+9-15| ... | ... | @@ -144,7 +144,7 @@ pub const OBJECT = struct { |
| 144 | 144 | Session = 5, |
| 145 | 145 | _, |
| 146 | 146 | |
| 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 | }; |
| 149 | 149 | |
| 150 | 150 | pub const NAME_INFORMATION = extern struct { |
| ... | ... | @@ -575,7 +575,7 @@ pub const FILE = struct { |
| 575 | 575 | MupProvider = 83, |
| 576 | 576 | _, |
| 577 | 577 | |
| 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 | }; |
| 580 | 580 | |
| 581 | 581 | pub const BASIC_INFORMATION = extern struct { |
| ... | ... | @@ -881,7 +881,7 @@ pub const DIRECTORY = struct { |
| 881 | 881 | NotifyFull = 3, |
| 882 | 882 | _, |
| 883 | 883 | |
| 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 | }; |
| 887 | 887 | |
| ... | ... | @@ -930,14 +930,8 @@ pub const CONSOLE = struct { |
| 930 | 930 | |
| 931 | 931 | pub const Tag = @typeInfo(WITH).@"union".tag_type.?; |
| 932 | 932 | pub const Payload = PAYLOAD: { |
| 933 | const with_fields = @typeInfo(WITH).@"union".fields; | |
| 934 | var field_names: [with_fields.len][]const u8 = undefined; | |
| 935 | var field_types: [with_fields.len]type = undefined; | |
| 936 | for (with_fields, &field_names, &field_types) |field, *field_name, *field_type| { | |
| 937 | field_name.* = field.name; | |
| 938 | field_type.* = field.type; | |
| 939 | } | |
| 940 | break :PAYLOAD @Union(.@"extern", null, &field_names, &field_types, &@splat(.{})); | |
| 933 | const with_info = @typeInfo(WITH).@"union"; | |
| 934 | break :PAYLOAD @Union(.@"extern", null, with_info.field_names, with_info.field_types[0..], &@splat(.{})); | |
| 941 | 935 | }; |
| 942 | 936 | }; |
| 943 | 937 | }; |
| ... | ... | @@ -2122,7 +2116,7 @@ pub const HEAP = opaque { |
| 2122 | 2116 | Custom, |
| 2123 | 2117 | _, |
| 2124 | 2118 | |
| 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 | }; |
| 2127 | 2121 | |
| 2128 | 2122 | pub const VA_CALLBACKS = extern struct { |
| ... | ... | @@ -3369,7 +3363,7 @@ pub const FS_INFORMATION_CLASS = enum(c_int) { |
| 3369 | 3363 | Guid = 15, |
| 3370 | 3364 | _, |
| 3371 | 3365 | |
| 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 | }; |
| 3374 | 3368 | |
| 3375 | 3369 | pub const SECTION_INHERIT = enum(c_int) { |
| ... | ... | @@ -3493,7 +3487,7 @@ pub const MEM = struct { |
| 3493 | 3487 | ImageMachine, |
| 3494 | 3488 | _, |
| 3495 | 3489 | |
| 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 | 4461 | Layer = 5, |
| 4468 | 4462 | _, |
| 4469 | 4463 | |
| 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 | }; |
| 4472 | 4466 | |
| 4473 | 4467 | pub const PARTIAL_INFORMATION = extern struct { |
lib/std/posix/test.zig+2-2| ... | ... | @@ -332,8 +332,8 @@ test "fsync" { |
| 332 | 332 | test "getrlimit and setrlimit" { |
| 333 | 333 | if (posix.system.rlimit_resource == void) return error.SkipZigTest; |
| 334 | 334 | |
| 335 | inline for (@typeInfo(posix.rlimit_resource).@"enum".fields) |field| { | |
| 336 | const resource: posix.rlimit_resource = @enumFromInt(field.value); | |
| 335 | inline for (@typeInfo(posix.rlimit_resource).@"enum".field_values) |field_value| { | |
| 336 | const resource: posix.rlimit_resource = @enumFromInt(field_value); | |
| 337 | 337 | const limit = try posix.getrlimit(resource); |
| 338 | 338 | |
| 339 | 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 | 24 | if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) { |
| 25 | 25 | @export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup }); |
| 26 | 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 | 28 | @export(&DllMain, .{ .name = "DllMain" }); |
| 29 | 29 | } |
| 30 | 30 | } |
| ... | ... | @@ -32,11 +32,11 @@ comptime { |
| 32 | 32 | if (builtin.link_libc and @hasDecl(root, "main")) { |
| 33 | 33 | if (is_wasm) { |
| 34 | 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 | 36 | @export(&main, .{ .name = "main" }); |
| 37 | 37 | } |
| 38 | 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 | 40 | @export(&wWinMain, .{ .name = "wWinMain" }); |
| 41 | 41 | } |
| 42 | 42 | } else if (native_os == .windows) { |
| ... | ... | @@ -728,8 +728,8 @@ var safe_allocator: std.heap.SafeAllocator = .init(std.heap.page_allocator, .{}) |
| 728 | 728 | |
| 729 | 729 | inline fn callMain(args: std.process.Args.Vector, environ: std.process.Environ.Block) u8 { |
| 730 | 730 | const fn_info = @typeInfo(@TypeOf(root.main)).@"fn"; |
| 731 | if (fn_info.params.len == 0) return wrapMain(root.main()); | |
| 732 | if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{ | |
| 731 | if (fn_info.param_types.len == 0) return wrapMain(root.main()); | |
| 732 | if (fn_info.param_types[0].? == std.process.Init.Minimal) return wrapMain(root.main(.{ | |
| 733 | 733 | .args = .{ .vector = args }, |
| 734 | 734 | .environ = .{ .block = environ }, |
| 735 | 735 | })); |
| ... | ... | @@ -809,7 +809,7 @@ inline fn wrapMain(result: anytype) u8 { |
| 809 | 809 | |
| 810 | 810 | fn call_wWinMain() std.os.windows.INT { |
| 811 | 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 | 813 | const hInstance: MAIN_HINSTANCE = @ptrCast(peb.ImageBaseAddress); |
| 814 | 814 | const lpCmdLine: [*:0]u16 = @ptrCast(peb.ProcessParameters.CommandLine.Buffer); |
| 815 | 815 |
lib/std/testing.zig+15-15| ... | ... | @@ -141,16 +141,16 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void { |
| 141 | 141 | }, |
| 142 | 142 | |
| 143 | 143 | .@"struct" => |structType| { |
| 144 | inline for (structType.fields) |field| { | |
| 145 | try expectEqual(@field(expected, field.name), @field(actual, field.name)); | |
| 144 | inline for (structType.field_names) |field_name| { | |
| 145 | try expectEqual(@field(expected, field_name), @field(actual, field_name)); | |
| 146 | 146 | } |
| 147 | 147 | }, |
| 148 | 148 | |
| 149 | 149 | .@"union" => |union_info| { |
| 150 | 150 | if (union_info.tag_type == null) { |
| 151 | const first_size = @bitSizeOf(union_info.fields[0].type); | |
| 152 | inline for (union_info.fields) |field| { | |
| 153 | if (@bitSizeOf(field.type) != first_size) { | |
| 151 | const first_size = @bitSizeOf(union_info.field_types[0]); | |
| 152 | inline for (union_info.field_types) |field_type| { | |
| 153 | if (@bitSizeOf(field_type) != first_size) { | |
| 154 | 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 | 840 | }, |
| 841 | 841 | |
| 842 | 842 | .@"struct" => |structType| { |
| 843 | inline for (structType.fields) |field| { | |
| 844 | expectEqualDeep(@field(expected, field.name), @field(actual, field.name)) catch |e| { | |
| 845 | print("Field {s} incorrect. expected {any}, found {any}\n", .{ field.name, @field(expected, field.name), @field(actual, field.name) }); | |
| 843 | inline for (structType.field_names) |field_name| { | |
| 844 | expectEqualDeep(@field(expected, field_name), @field(actual, field_name)) catch |e| { | |
| 845 | print("Field {s} incorrect. expected {any}, found {any}\n", .{ field_name, @field(expected, field_name), @field(actual, field_name) }); | |
| 846 | 846 | return e; |
| 847 | 847 | }; |
| 848 | 848 | } |
| ... | ... | @@ -1165,14 +1165,14 @@ fn CheckAllAllocationFailuresExtraArgs(comptime TestFn: type) type { |
| 1165 | 1165 | |
| 1166 | 1166 | const ArgsTuple = std.meta.ArgsTuple(TestFn); |
| 1167 | 1167 | |
| 1168 | const fields = @typeInfo(ArgsTuple).@"struct".fields; | |
| 1169 | if (fields.len == 0 or fields[0].type != std.mem.Allocator) { | |
| 1168 | const field_types = @typeInfo(ArgsTuple).@"struct".field_types; | |
| 1169 | if (field_types.len == 0 or field_types[0] != std.mem.Allocator) { | |
| 1170 | 1170 | @compileError("The provided function must have an " ++ @typeName(std.mem.Allocator) ++ " as its first argument"); |
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | var extra_args: [fields.len - 1]type = undefined; | |
| 1174 | for (&extra_args, fields[1..]) |*arg, field| { | |
| 1175 | arg.* = field.type; | |
| 1173 | var extra_args: [field_types.len - 1]type = undefined; | |
| 1174 | for (&extra_args, field_types[1..]) |*arg, field_type| { | |
| 1175 | arg.* = field_type; | |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | return @Tuple(&extra_args); |
| ... | ... | @@ -1204,8 +1204,8 @@ test "checkAllAllocationFailures provide result type to 'extra_args' argument" { |
| 1204 | 1204 | /// Given a type, references all the declarations inside, so that the semantic analyzer sees them. |
| 1205 | 1205 | pub fn refAllDecls(comptime T: type) void { |
| 1206 | 1206 | if (!builtin.is_test) return; |
| 1207 | inline for (comptime std.meta.declarations(T)) |decl| { | |
| 1208 | _ = &@field(T, decl.name); | |
| 1207 | inline for (comptime std.meta.declarations(T)) |decl_name| { | |
| 1208 | _ = &@field(T, decl_name); | |
| 1209 | 1209 | } |
| 1210 | 1210 | } |
| 1211 | 1211 |
lib/std/testing/Smith.zig+35-21| ... | ... | @@ -35,7 +35,12 @@ fn fromExcessK(T: type, x: Backing(T)) T { |
| 35 | 35 | return @as(T, @bitCast(x)) +% std.math.minInt(T); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | fn enumFieldLessThan(_: void, a: std.builtin.Type.EnumField, b: std.builtin.Type.EnumField) bool { | |
| 38 | const EnumField = struct { | |
| 39 | name: [:0]const u8, | |
| 40 | value: comptime_int, | |
| 41 | }; | |
| 42 | ||
| 43 | fn enumFieldLessThan(_: void, a: EnumField, b: EnumField) bool { | |
| 39 | 44 | return a.value < b.value; |
| 40 | 45 | } |
| 41 | 46 | |
| ... | ... | @@ -67,17 +72,26 @@ pub inline fn baselineWeights(T: type) []const Weight { |
| 67 | 72 | baselineWeights(Backing(T)) |
| 68 | 73 | else |
| 69 | 74 | @compileError("non-packed unions cannot be weighted"), |
| 70 | .@"enum" => |e| if (!e.is_exhaustive) | |
| 75 | .@"enum" => |e| if (e.mode == .nonexhaustive) | |
| 71 | 76 | baselineWeights(e.tag_type) |
| 72 | else if (e.fields.len == 0) | |
| 77 | else if (e.field_names.len == 0) | |
| 73 | 78 | // Cannot be included in below branch due to `log2_int_ceil` |
| 74 | 79 | @compileError("exhaustive zero-field enums cannot be weighted") |
| 75 | 80 | else e: { |
| 76 | @setEvalBranchQuota(@intCast(4 * e.fields.len * | |
| 77 | std.math.log2_int_ceil(usize, e.fields.len))); | |
| 78 | ||
| 79 | var sorted_fields = e.fields[0..e.fields.len].*; | |
| 80 | std.mem.sortUnstable(std.builtin.Type.EnumField, &sorted_fields, {}, enumFieldLessThan); | |
| 81 | @setEvalBranchQuota(@intCast(4 * e.field_names.len * | |
| 82 | std.math.log2_int_ceil(usize, e.field_names.len))); | |
| 83 | ||
| 84 | var sorted_fields = blk: { | |
| 85 | var fields: [e.field_names.len]EnumField = undefined; | |
| 86 | for (e.field_names, e.field_values, &fields) |f_name, f_value, *field| { | |
| 87 | field.* = .{ | |
| 88 | .name = f_name, | |
| 89 | .value = f_value, | |
| 90 | }; | |
| 91 | } | |
| 92 | break :blk fields; | |
| 93 | }; | |
| 94 | std.mem.sortUnstable(EnumField, &sorted_fields, {}, enumFieldLessThan); | |
| 81 | 95 | |
| 82 | 96 | var weights: []const Weight = &.{}; |
| 83 | 97 | var seq_first: u64 = sorted_fields[0].value; |
| ... | ... | @@ -316,10 +330,10 @@ fn weightsContain(int: u64, weights: []const Weight) bool { |
| 316 | 330 | inline fn allBitPatternsValid(T: type) bool { |
| 317 | 331 | return comptime switch (@typeInfo(T)) { |
| 318 | 332 | .void, .bool, .int, .float => true, |
| 319 | inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.fields) |f| { | |
| 320 | if (!allBitPatternsValid(f.type)) break false; | |
| 333 | inline .@"struct", .@"union" => |c| c.layout == .@"packed" and for (c.field_types) |f_type| { | |
| 334 | if (!allBitPatternsValid(f_type)) break false; | |
| 321 | 335 | } else true, |
| 322 | .@"enum" => |e| !e.is_exhaustive, | |
| 336 | .@"enum" => |e| e.mode == .nonexhaustive, | |
| 323 | 337 | else => unreachable, |
| 324 | 338 | }; |
| 325 | 339 | } |
| ... | ... | @@ -346,16 +360,16 @@ fn UnionTagWithoutUninitializable(T: type) type { |
| 346 | 360 | const u = @typeInfo(T).@"union"; |
| 347 | 361 | const Tag = u.tag_type orelse @compileError("union must have tag"); |
| 348 | 362 | const e = @typeInfo(Tag).@"enum"; |
| 349 | var field_names: [e.fields.len][]const u8 = undefined; | |
| 350 | var field_values: [e.fields.len]e.tag_type = undefined; | |
| 363 | var field_names: [e.field_names.len][]const u8 = undefined; | |
| 364 | var field_values: [e.field_names.len]e.tag_type = undefined; | |
| 351 | 365 | var n_fields = 0; |
| 352 | for (u.fields) |f| { | |
| 353 | switch (f.type) { | |
| 366 | for (u.field_names, u.field_types) |f_name, f_type| { | |
| 367 | switch (f_type) { | |
| 354 | 368 | noreturn => continue, |
| 355 | 369 | else => {}, |
| 356 | 370 | } |
| 357 | field_names[n_fields] = f.name; | |
| 358 | field_values[n_fields] = @intFromEnum(@field(Tag, f.name)); | |
| 371 | field_names[n_fields] = f_name; | |
| 372 | field_values[n_fields] = @intFromEnum(@field(Tag, f_name)); | |
| 359 | 373 | n_fields += 1; |
| 360 | 374 | } |
| 361 | 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 | 395 | } |
| 382 | 396 | break :full @bitCast(int); |
| 383 | 397 | }, |
| 384 | .@"enum" => |e| if (e.is_exhaustive) v: { | |
| 398 | .@"enum" => |e| if (e.mode == .exhaustive) v: { | |
| 385 | 399 | if (@bitSizeOf(e.tag_type) <= 64) { |
| 386 | 400 | break :v s.valueWeightedWithHash(T, baselineWeights(T), hash); |
| 387 | 401 | } |
| 388 | 402 | 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 | 404 | } else @enumFromInt(s.valueWithHash(e.tag_type, hash)), |
| 391 | 405 | .optional => |o| if (s.valueWithHash(bool, hash)) |
| 392 | 406 | null |
| ... | ... | @@ -406,11 +420,11 @@ pub fn valueWithHash(s: *Smith, T: type, hash: u32) T { |
| 406 | 420 | .@"struct" => |st| if (!allBitPatternsValid(T)) v: { |
| 407 | 421 | var v: T = undefined; |
| 408 | 422 | var rhash = hash; |
| 409 | inline for (st.fields) |f| { | |
| 423 | inline for (st.field_names, st.field_types) |f_name, f_type| { | |
| 410 | 424 | // rhash is incremented in the call so our rhash state is not reused (e.g. with |
| 411 | 425 | // two nested structs. note that xor cannot work for this case as the bit would |
| 412 | 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 | 428 | rhash = std.hash.int(rhash); |
| 415 | 429 | } |
| 416 | 430 | break :v v; |
lib/std/zig.zig+4-4| ... | ... | @@ -736,8 +736,8 @@ pub fn parseTargetQueryOrReportFatalError( |
| 736 | 736 | help: { |
| 737 | 737 | var help_text = std.array_list.Managed(u8).init(allocator); |
| 738 | 738 | defer help_text.deinit(); |
| 739 | inline for (@typeInfo(std.Target.ObjectFormat).@"enum".fields) |field| { | |
| 740 | help_text.print(" {s}\n", .{field.name}) catch break :help; | |
| 739 | inline for (@typeInfo(std.Target.ObjectFormat).@"enum".field_names) |field_name| { | |
| 740 | help_text.print(" {s}\n", .{field_name}) catch break :help; | |
| 741 | 741 | } |
| 742 | 742 | std.log.info("available object formats:\n{s}", .{help_text.items}); |
| 743 | 743 | } |
| ... | ... | @@ -747,8 +747,8 @@ pub fn parseTargetQueryOrReportFatalError( |
| 747 | 747 | help: { |
| 748 | 748 | var help_text = std.array_list.Managed(u8).init(allocator); |
| 749 | 749 | defer help_text.deinit(); |
| 750 | inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".fields) |field| { | |
| 751 | help_text.print(" {s}\n", .{field.name}) catch break :help; | |
| 750 | inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".field_names) |field_name| { | |
| 751 | help_text.print(" {s}\n", .{field_name}) catch break :help; | |
| 752 | 752 | } |
| 753 | 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 | 298 | } |
| 299 | 299 | |
| 300 | 300 | pub fn extraData(tree: Ast, index: ExtraIndex, comptime T: type) T { |
| 301 | const fields = std.meta.fields(T); | |
| 301 | const info = @typeInfo(T).@"struct"; | |
| 302 | 302 | var result: T = undefined; |
| 303 | inline for (fields, 0..) |field, i| { | |
| 304 | @field(result, field.name) = switch (field.type) { | |
| 303 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 304 | @field(result, field_name) = switch (field_type) { | |
| 305 | 305 | Node.Index, |
| 306 | 306 | Node.OptionalIndex, |
| 307 | 307 | OptionalTokenIndex, |
| 308 | 308 | ExtraIndex, |
| 309 | 309 | => @enumFromInt(tree.extra_data[@intFromEnum(index) + i]), |
| 310 | 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 | 314 | return result; |
lib/std/zig/AstGen.zig+42-42| ... | ... | @@ -74,25 +74,25 @@ src_hasher: std.zig.SrcHasher, |
| 74 | 74 | const InnerError = error{ OutOfMemory, AnalysisFail }; |
| 75 | 75 | |
| 76 | 76 | fn addExtra(astgen: *AstGen, extra: anytype) Allocator.Error!u32 { |
| 77 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 78 | try astgen.extra.ensureUnusedCapacity(astgen.gpa, fields.len); | |
| 77 | const field_count = std.meta.fieldNames(@TypeOf(extra)).len; | |
| 78 | try astgen.extra.ensureUnusedCapacity(astgen.gpa, field_count); | |
| 79 | 79 | return addExtraAssumeCapacity(astgen, extra); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | fn 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 | 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 | 86 | setExtra(astgen, extra_index, extra); |
| 87 | 87 | return extra_index; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 91 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 91 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 92 | 92 | var i = index; |
| 93 | inline for (fields) |field| { | |
| 94 | astgen.extra.items[i] = switch (field.type) { | |
| 95 | u32 => @field(extra, field.name), | |
| 93 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 94 | astgen.extra.items[i] = switch (field_type) { | |
| 95 | u32 => @field(extra, field_name), | |
| 96 | 96 | |
| 97 | 97 | Zir.Inst.Ref, |
| 98 | 98 | Zir.Inst.Index, |
| ... | ... | @@ -103,13 +103,13 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 103 | 103 | Ast.OptionalTokenIndex, |
| 104 | 104 | Ast.Node.Index, |
| 105 | 105 | Ast.Node.OptionalIndex, |
| 106 | => @intFromEnum(@field(extra, field.name)), | |
| 106 | => @intFromEnum(@field(extra, field_name)), | |
| 107 | 107 | |
| 108 | 108 | Ast.TokenOffset, |
| 109 | 109 | Ast.OptionalTokenOffset, |
| 110 | 110 | Ast.Node.Offset, |
| 111 | 111 | Ast.Node.OptionalOffset, |
| 112 | => @bitCast(@intFromEnum(@field(extra, field.name))), | |
| 112 | => @bitCast(@intFromEnum(@field(extra, field_name))), | |
| 113 | 113 | |
| 114 | 114 | i32, |
| 115 | 115 | Zir.Inst.Call.Flags, |
| ... | ... | @@ -118,7 +118,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { |
| 118 | 118 | Zir.Inst.FuncFancy.Bits, |
| 119 | 119 | Zir.Inst.Param.Type, |
| 120 | 120 | Zir.Inst.Func.RetTy, |
| 121 | => @bitCast(@field(extra, field.name)), | |
| 121 | => @bitCast(@field(extra, field_name)), | |
| 122 | 122 | |
| 123 | 123 | else => @compileError("bad field type"), |
| 124 | 124 | }; |
| ... | ... | @@ -166,7 +166,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 166 | 166 | try astgen.instructions.ensureTotalCapacity(gpa, tree.nodes.len); |
| 167 | 167 | |
| 168 | 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 | 170 | try astgen.extra.ensureTotalCapacity(gpa, tree.nodes.len + reserved_count); |
| 171 | 171 | astgen.extra.items.len += reserved_count; |
| 172 | 172 | |
| ... | ... | @@ -212,7 +212,7 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 212 | 212 | astgen.extra.items[err_index] = 0; |
| 213 | 213 | } else { |
| 214 | 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); | |
| 216 | 216 | |
| 217 | 217 | astgen.extra.items[err_index] = astgen.addExtraAssumeCapacity(Zir.Inst.CompileErrors{ |
| 218 | 218 | .items_len = @intCast(astgen.compile_errors.items.len), |
| ... | ... | @@ -227,8 +227,8 @@ pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 227 | 227 | if (astgen.imports.count() == 0) { |
| 228 | 228 | astgen.extra.items[imports_index] = 0; |
| 229 | 229 | } else { |
| 230 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Imports).@"struct".fields.len + | |
| 231 | astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).@"struct".fields.len); | |
| 230 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Imports).@"struct".field_names.len + | |
| 231 | astgen.imports.count() * @typeInfo(Zir.Inst.Imports.Item).@"struct".field_names.len); | |
| 232 | 232 | |
| 233 | 233 | astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{ |
| 234 | 234 | .imports_len = @intCast(astgen.imports.count()), |
| ... | ... | @@ -1888,7 +1888,7 @@ fn structInitExprAnon( |
| 1888 | 1888 | .abs_line = astgen.source_line, |
| 1889 | 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 | 1892 | var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size); |
| 1893 | 1893 | |
| 1894 | 1894 | for (struct_init.ast.fields) |field_init| { |
| ... | ... | @@ -1921,7 +1921,7 @@ fn structInitExprTyped( |
| 1921 | 1921 | .abs_line = astgen.source_line, |
| 1922 | 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 | 1925 | var extra_index: usize = try reserveExtra(astgen, struct_init.ast.fields.len * field_size); |
| 1926 | 1926 | |
| 1927 | 1927 | for (struct_init.ast.fields) |field_init| { |
| ... | ... | @@ -3804,7 +3804,7 @@ fn ptrType( |
| 3804 | 3804 | const gpa = gz.astgen.gpa; |
| 3805 | 3805 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 3806 | 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 | 3808 | trailing_count); |
| 3809 | 3809 | |
| 3810 | 3810 | const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.PtrType{ |
| ... | ... | @@ -5096,7 +5096,7 @@ fn tupleDecl( |
| 5096 | 5096 | |
| 5097 | 5097 | const extra_trail = astgen.scratch.items[fields_start..]; |
| 5098 | 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 | 5100 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.TupleDecl{ |
| 5101 | 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 | 5670 | const gpa = astgen.gpa; |
| 5671 | 5671 | const tree = astgen.tree; |
| 5672 | 5672 | |
| 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 | 5674 | var fields_len: usize = 0; |
| 5675 | 5675 | { |
| 5676 | 5676 | var idents: std.AutoHashMapUnmanaged(Zir.NullTerminatedString, Ast.TokenIndex) = .empty; |
| ... | ... | @@ -6332,7 +6332,7 @@ fn setCondBrPayload( |
| 6332 | 6332 | const else_body_len = astgen.countBodyLenAfterFixups(else_body); |
| 6333 | 6333 | try astgen.extra.ensureUnusedCapacity( |
| 6334 | 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 | ); |
| 6337 | 6337 | |
| 6338 | 6338 | const zir_datas = astgen.instructions.items(.data); |
| ... | ... | @@ -6761,7 +6761,7 @@ fn forExpr( |
| 6761 | 6761 | const len: Zir.Inst.Ref = len: { |
| 6762 | 6762 | const all_lens = @as([*]Zir.Inst.Ref, @ptrCast(lens))[0 .. lens.len * 2]; |
| 6763 | 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 | 6765 | const len = try parent_gz.addPlNode(.for_len, node, Zir.Inst.MultiOp{ |
| 6766 | 6766 | .operands_len = lens_len, |
| 6767 | 6767 | }); |
| ... | ... | @@ -7791,7 +7791,7 @@ fn switchExpr( |
| 7791 | 7791 | // by copying our bodies from `payloads` to `extra`, this time in the order |
| 7792 | 7792 | // expected by ZIR consumers. |
| 7793 | 7793 | |
| 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 | 7795 | @intFromBool(multi_cases_len > 0) + // multi_cases_len |
| 7796 | 7796 | @intFromBool(payload_capture_inst_is_placeholder) + // payload_capture_placeholder |
| 7797 | 7797 | @intFromBool(tag_capture_inst_is_placeholder) + // tag_capture_placeholder |
| ... | ... | @@ -8878,7 +8878,7 @@ fn typeOf( |
| 8878 | 8878 | try gz.instructions.append(gpa, typeof_inst); |
| 8879 | 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 | 8882 | const payload_index = try reserveExtra(astgen, payload_size + args.len); |
| 8883 | 8883 | const args_index = payload_index + payload_size; |
| 8884 | 8884 | |
| ... | ... | @@ -11348,7 +11348,7 @@ const GenZir = struct { |
| 11348 | 11348 | const body_len = astgen.countBodyLenAfterFixups(body); |
| 11349 | 11349 | try astgen.extra.ensureUnusedCapacity( |
| 11350 | 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 | 11353 | const zir_datas = astgen.instructions.items(.data); |
| 11354 | 11354 | zir_datas[@intFromEnum(bool_br)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.BoolBr{ |
| ... | ... | @@ -11372,7 +11372,7 @@ const GenZir = struct { |
| 11372 | 11372 | |
| 11373 | 11373 | try astgen.extra.ensureUnusedCapacity( |
| 11374 | 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 | 11377 | const zir_datas = astgen.instructions.items(.data); |
| 11378 | 11378 | zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity( |
| ... | ... | @@ -11395,7 +11395,7 @@ const GenZir = struct { |
| 11395 | 11395 | |
| 11396 | 11396 | try astgen.extra.ensureUnusedCapacity( |
| 11397 | 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 | 11400 | const zir_datas = astgen.instructions.items(.data); |
| 11401 | 11401 | zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity( |
| ... | ... | @@ -11416,7 +11416,7 @@ const GenZir = struct { |
| 11416 | 11416 | const body_len = astgen.countBodyLenAfterFixups(body); |
| 11417 | 11417 | try astgen.extra.ensureUnusedCapacity( |
| 11418 | 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 | 11421 | const zir_datas = astgen.instructions.items(.data); |
| 11422 | 11422 | zir_datas[@intFromEnum(inst)].pl_node.payload_index = astgen.addExtraAssumeCapacity( |
| ... | ... | @@ -11529,7 +11529,7 @@ const GenZir = struct { |
| 11529 | 11529 | inst_info: { |
| 11530 | 11530 | try astgen.extra.ensureUnusedCapacity( |
| 11531 | 11531 | gpa, |
| 11532 | @typeInfo(Zir.Inst.FuncFancy).@"struct".fields.len + | |
| 11532 | @typeInfo(Zir.Inst.FuncFancy).@"struct".field_names.len + | |
| 11533 | 11533 | fancyFnExprExtraLen(astgen, &.{}, cc_body, args.cc_ref) + |
| 11534 | 11534 | fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) + |
| 11535 | 11535 | body_len + src_locs_and_hash.len + |
| ... | ... | @@ -11589,7 +11589,7 @@ const GenZir = struct { |
| 11589 | 11589 | } else inst_info: { |
| 11590 | 11590 | try astgen.extra.ensureUnusedCapacity( |
| 11591 | 11591 | gpa, |
| 11592 | @typeInfo(Zir.Inst.Func).@"struct".fields.len + 1 + | |
| 11592 | @typeInfo(Zir.Inst.Func).@"struct".field_names.len + 1 + | |
| 11593 | 11593 | fancyFnExprExtraLen(astgen, args.ret_param_refs, ret_body, ret_ref) + |
| 11594 | 11594 | body_len + src_locs_and_hash.len, |
| 11595 | 11595 | ); |
| ... | ... | @@ -11777,7 +11777,7 @@ const GenZir = struct { |
| 11777 | 11777 | const param_body = param_gz.instructionsSlice(); |
| 11778 | 11778 | const body_len = gz.astgen.countBodyLenAfterFixupsExtraRefs(param_body, prev_param_insts); |
| 11779 | 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); | |
| 11781 | 11781 | |
| 11782 | 11782 | const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Param{ |
| 11783 | 11783 | .name = name, |
| ... | ... | @@ -11847,7 +11847,7 @@ const GenZir = struct { |
| 11847 | 11847 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 11848 | 11848 | try astgen.extra.ensureUnusedCapacity( |
| 11849 | 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 | ); |
| 11852 | 11852 | |
| 11853 | 11853 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.NodeMultiOp{ |
| ... | ... | @@ -12088,7 +12088,7 @@ const GenZir = struct { |
| 12088 | 12088 | ) !Zir.Inst.Index { |
| 12089 | 12089 | const gpa = gz.astgen.gpa; |
| 12090 | 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); | |
| 12092 | 12092 | |
| 12093 | 12093 | const new_index: Zir.Inst.Index = @enumFromInt(gz.astgen.instructions.len); |
| 12094 | 12094 | gz.astgen.instructions.appendAssumeCapacity(.{ |
| ... | ... | @@ -12211,7 +12211,7 @@ const GenZir = struct { |
| 12211 | 12211 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12212 | 12212 | try astgen.extra.ensureUnusedCapacity( |
| 12213 | 12213 | gpa, |
| 12214 | @typeInfo(Zir.Inst.AllocExtended).@"struct".fields.len + | |
| 12214 | @typeInfo(Zir.Inst.AllocExtended).@"struct".field_names.len + | |
| 12215 | 12215 | @intFromBool(args.type_inst != .none) + |
| 12216 | 12216 | @intFromBool(args.align_inst != .none), |
| 12217 | 12217 | ); |
| ... | ... | @@ -12263,9 +12263,9 @@ const GenZir = struct { |
| 12263 | 12263 | |
| 12264 | 12264 | try gz.instructions.ensureUnusedCapacity(gpa, 1); |
| 12265 | 12265 | try astgen.instructions.ensureUnusedCapacity(gpa, 1); |
| 12266 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Asm).@"struct".fields.len + | |
| 12267 | args.outputs.len * @typeInfo(Zir.Inst.Asm.Output).@"struct".fields.len + | |
| 12268 | args.inputs.len * @typeInfo(Zir.Inst.Asm.Input).@"struct".fields.len); | |
| 12266 | try astgen.extra.ensureUnusedCapacity(gpa, @typeInfo(Zir.Inst.Asm).@"struct".field_names.len + | |
| 12267 | args.outputs.len * @typeInfo(Zir.Inst.Asm.Output).@"struct".field_names.len + | |
| 12268 | args.inputs.len * @typeInfo(Zir.Inst.Asm.Input).@"struct".field_names.len); | |
| 12269 | 12269 | |
| 12270 | 12270 | const payload_index = gz.astgen.addExtraAssumeCapacity(Zir.Inst.Asm{ |
| 12271 | 12271 | .src_node = gz.nodeIndexToRelative(args.node), |
| ... | ... | @@ -12374,7 +12374,7 @@ const GenZir = struct { |
| 12374 | 12374 | |
| 12375 | 12375 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12376 | 12376 | |
| 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 | 12378 | 4 + // `captures_len`, `decls_len`, `fields_len`, `backing_int_type_body_len` |
| 12379 | 12379 | captures_len * 2 + // `capture`, `capture_name` |
| 12380 | 12380 | args.remaining.len); |
| ... | ... | @@ -12441,7 +12441,7 @@ const GenZir = struct { |
| 12441 | 12441 | |
| 12442 | 12442 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12443 | 12443 | |
| 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 | 12445 | 4 + // `captures_len`, `decls_len`, `fields_len`, `arg_type_body_len` |
| 12446 | 12446 | captures_len * 2 + // `capture`, `capture_name` |
| 12447 | 12447 | args.remaining.len); |
| ... | ... | @@ -12509,7 +12509,7 @@ const GenZir = struct { |
| 12509 | 12509 | |
| 12510 | 12510 | const fields_hash_arr: [4]u32 = @bitCast(args.fields_hash); |
| 12511 | 12511 | |
| 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 | 12513 | 4 + // `captures_len`, `decls_len`, `fields_len`, `tag_type_body_len` |
| 12514 | 12514 | captures_len * 2 + // `capture`, `capture_name` |
| 12515 | 12515 | args.remaining.len); |
| ... | ... | @@ -12565,7 +12565,7 @@ const GenZir = struct { |
| 12565 | 12565 | const captures_len: u32 = @intCast(args.captures.len); |
| 12566 | 12566 | assert(args.capture_names.len == captures_len); |
| 12567 | 12567 | |
| 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 | 12569 | 2 + // `captures_len`, `decls_len` |
| 12570 | 12570 | captures_len * 2 + // `capture`, `capture_name` |
| 12571 | 12571 | args.decls.len); |
| ... | ... | @@ -13465,7 +13465,7 @@ fn setDeclaration( |
| 13465 | 13465 | const flags_arr: [2]u32 = @bitCast(flags); |
| 13466 | 13466 | |
| 13467 | 13467 | const need_extra: usize = |
| 13468 | @typeInfo(Zir.Inst.Declaration).@"struct".fields.len + | |
| 13468 | @typeInfo(Zir.Inst.Declaration).@"struct".field_names.len + | |
| 13469 | 13469 | @as(usize, @intFromBool(id.hasName())) + |
| 13470 | 13470 | @as(usize, @intFromBool(id.hasLibName())) + |
| 13471 | 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 | 117 | |
| 118 | 118 | pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex { |
| 119 | 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 | 121 | return @as([]const MessageIndex, @ptrCast(eb.extra[start..][0..notes_len])); |
| 122 | 122 | } |
| 123 | 123 | |
| ... | ... | @@ -128,11 +128,12 @@ pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 { |
| 128 | 128 | /// Returns the requested data, as well as the new index which is at the start of the |
| 129 | 129 | /// trailers for the object. |
| 130 | 130 | fn 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 | 133 | var i: usize = index; |
| 133 | 134 | var result: T = undefined; |
| 134 | inline for (fields) |field| { | |
| 135 | @field(result, field.name) = switch (field.type) { | |
| 135 | inline for (field_names, field_types) |field_name, field_type| { | |
| 136 | @field(result, field_name) = switch (field_type) { | |
| 136 | 137 | u32 => eb.extra[i], |
| 137 | 138 | MessageIndex => @as(MessageIndex, @enumFromInt(eb.extra[i])), |
| 138 | 139 | SourceLocationIndex => @as(SourceLocationIndex, @enumFromInt(eb.extra[i])), |
| ... | ... | @@ -498,7 +499,7 @@ pub const Wip = struct { |
| 498 | 499 | |
| 499 | 500 | pub fn reserveNotes(wip: *Wip, notes_len: u32) !u32 { |
| 500 | 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 | 503 | wip.extra.items.len += notes_len; |
| 503 | 504 | return @intCast(wip.extra.items.len - notes_len); |
| 504 | 505 | } |
| ... | ... | @@ -731,13 +732,13 @@ pub const Wip = struct { |
| 731 | 732 | |
| 732 | 733 | fn addExtra(wip: *Wip, extra: anytype) Allocator.Error!u32 { |
| 733 | 734 | const gpa = wip.gpa; |
| 734 | const fields = @typeInfo(@TypeOf(extra)).@"struct".fields; | |
| 735 | const fields = @typeInfo(@TypeOf(extra)).@"struct".field_names; | |
| 735 | 736 | try wip.extra.ensureUnusedCapacity(gpa, fields.len); |
| 736 | 737 | return addExtraAssumeCapacity(wip, extra); |
| 737 | 738 | } |
| 738 | 739 | |
| 739 | 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 | 742 | const result: u32 = @intCast(wip.extra.items.len); |
| 742 | 743 | wip.extra.items.len += fields.len; |
| 743 | 744 | setExtra(wip, result, extra); |
| ... | ... | @@ -745,13 +746,15 @@ pub const Wip = struct { |
| 745 | 746 | } |
| 746 | 747 | |
| 747 | 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 | 752 | var i = index; |
| 750 | inline for (fields) |field| { | |
| 751 | wip.extra.items[i] = switch (field.type) { | |
| 752 | u32 => @field(extra, field.name), | |
| 753 | MessageIndex => @intFromEnum(@field(extra, field.name)), | |
| 754 | SourceLocationIndex => @intFromEnum(@field(extra, field.name)), | |
| 753 | inline for (field_names, field_types) |field_name, field_type| { | |
| 754 | wip.extra.items[i] = switch (field_type) { | |
| 755 | u32 => @field(extra, field_name), | |
| 756 | MessageIndex => @intFromEnum(@field(extra, field_name)), | |
| 757 | SourceLocationIndex => @intFromEnum(@field(extra, field_name)), | |
| 755 | 758 | else => @compileError("bad field type"), |
| 756 | 759 | }; |
| 757 | 760 | i += 1; |
lib/std/zig/LibCInstallation.zig+11-11| ... | ... | @@ -43,12 +43,13 @@ pub const FindError = error{ |
| 43 | 43 | pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const std.Target) !LibCInstallation { |
| 44 | 44 | var self: LibCInstallation = .{}; |
| 45 | 45 | |
| 46 | const fields = std.meta.fields(LibCInstallation); | |
| 46 | const field_names = comptime std.meta.fieldNames(LibCInstallation); | |
| 47 | 47 | const FoundKey = struct { |
| 48 | 48 | found: bool, |
| 49 | 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 | 53 | errdefer { |
| 53 | 54 | self = .{}; |
| 54 | 55 | for (found_keys) |found_key| { |
| ... | ... | @@ -65,22 +66,22 @@ pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const |
| 65 | 66 | var line_it = std.mem.splitScalar(u8, line, '='); |
| 66 | 67 | const name = line_it.first(); |
| 67 | 68 | const value = line_it.rest(); |
| 68 | inline for (fields, 0..) |field, i| { | |
| 69 | if (std.mem.eql(u8, name, field.name)) { | |
| 69 | inline for (field_names, 0..) |field_name, i| { | |
| 70 | if (std.mem.eql(u8, name, field_name)) { | |
| 70 | 71 | found_keys[i].found = true; |
| 71 | 72 | if (value.len == 0) { |
| 72 | @field(self, field.name) = null; | |
| 73 | @field(self, field_name) = null; | |
| 73 | 74 | } else { |
| 74 | 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 | 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 | 83 | if (!found_keys[i].found) { |
| 83 | log.err("missing field: {s}", .{field.name}); | |
| 84 | log.err("missing field: {s}", .{field_name}); | |
| 84 | 85 | return error.ParseError; |
| 85 | 86 | } |
| 86 | 87 | } |
| ... | ... | @@ -235,9 +236,8 @@ pub fn findNative(gpa: Allocator, io: Io, args: FindNativeOptions) FindError!Lib |
| 235 | 236 | |
| 236 | 237 | /// Must be the same allocator passed to `parse` or `findNative`. |
| 237 | 238 | pub fn deinit(self: *LibCInstallation, allocator: Allocator) void { |
| 238 | const fields = std.meta.fields(LibCInstallation); | |
| 239 | inline for (fields) |field| { | |
| 240 | if (@field(self, field.name)) |payload| { | |
| 239 | inline for (@typeInfo(LibCInstallation).@"struct".field_names) |field_name| { | |
| 240 | if (@field(self, field_name)) |payload| { | |
| 241 | 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 | 89 | } |
| 90 | 90 | |
| 91 | 91 | fn addExtra(p: *Parse, extra: anytype) Allocator.Error!ExtraIndex { |
| 92 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 93 | try p.extra_data.ensureUnusedCapacity(p.gpa, fields.len); | |
| 92 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 93 | try p.extra_data.ensureUnusedCapacity(p.gpa, info.field_names.len); | |
| 94 | 94 | const result: ExtraIndex = @enumFromInt(p.extra_data.items.len); |
| 95 | inline for (fields) |field| { | |
| 96 | const data: u32 = switch (field.type) { | |
| 95 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 96 | const data: u32 = switch (field_type) { | |
| 97 | 97 | Node.Index, |
| 98 | 98 | Node.OptionalIndex, |
| 99 | 99 | OptionalTokenIndex, |
| 100 | 100 | ExtraIndex, |
| 101 | => @intFromEnum(@field(extra, field.name)), | |
| 101 | => @intFromEnum(@field(extra, field_name)), | |
| 102 | 102 | TokenIndex, |
| 103 | => @field(extra, field.name), | |
| 103 | => @field(extra, field_name), | |
| 104 | 104 | else => @compileError("unexpected field type"), |
| 105 | 105 | }; |
| 106 | 106 | p.extra_data.appendAssumeCapacity(data); |
lib/std/zig/Zir.zig+10-10| ... | ... | @@ -68,11 +68,11 @@ fn ExtraData(comptime T: type) type { |
| 68 | 68 | /// Returns the requested data, as well as the new index which is at the start of the |
| 69 | 69 | /// trailers for the object. |
| 70 | 70 | pub 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 | 72 | var i: usize = index; |
| 73 | 73 | var result: T = undefined; |
| 74 | inline for (fields) |field| { | |
| 75 | @field(result, field.name) = switch (field.type) { | |
| 74 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 75 | @field(result, field_name) = switch (field_type) { | |
| 76 | 76 | u32 => code.extra[i], |
| 77 | 77 | |
| 78 | 78 | Inst.Ref, |
| ... | ... | @@ -1877,7 +1877,7 @@ pub const Inst = struct { |
| 1877 | 1877 | |
| 1878 | 1878 | // Uncomment to view how many tag slots are available. |
| 1879 | 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 | }; |
| 1883 | 1883 | |
| ... | ... | @@ -2325,7 +2325,7 @@ pub const Inst = struct { |
| 2325 | 2325 | |
| 2326 | 2326 | _, |
| 2327 | 2327 | |
| 2328 | pub const static_len = @typeInfo(@This()).@"enum".fields.len - 1; | |
| 2328 | pub const static_len = @typeInfo(@This()).@"enum".field_names.len - 1; | |
| 2329 | 2329 | |
| 2330 | 2330 | pub fn toIndex(inst: Ref) ?Index { |
| 2331 | 2331 | assert(inst != .none); |
| ... | ... | @@ -3186,7 +3186,7 @@ pub const Inst = struct { |
| 3186 | 3186 | |
| 3187 | 3187 | pub const ReifySliceArgInfo = enum(u16) { |
| 3188 | 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 | 3190 | type_to_fn_param_attrs, |
| 3191 | 3191 | /// Input element type is `[]const u8`. |
| 3192 | 3192 | /// Output element type is `type`. |
| ... | ... | @@ -3194,10 +3194,10 @@ pub const Inst = struct { |
| 3194 | 3194 | /// Identical to `string_to_struct_field_type` aside from emitting slightly different error messages. |
| 3195 | 3195 | string_to_union_field_type, |
| 3196 | 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 | 3198 | string_to_struct_field_attrs, |
| 3199 | 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 | 3201 | string_to_union_field_attrs, |
| 3202 | 3202 | }; |
| 3203 | 3203 | |
| ... | ... | @@ -4842,7 +4842,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash { |
| 4842 | 4842 | const extra_index = extra.end + |
| 4843 | 4843 | extra.data.ret_ty.body_len + |
| 4844 | 4844 | extra.data.body_len + |
| 4845 | @typeInfo(Inst.Func.SrcLocs).@"struct".fields.len; | |
| 4845 | @typeInfo(Inst.Func.SrcLocs).@"struct".field_names.len; | |
| 4846 | 4846 | return @bitCast([4]u32{ |
| 4847 | 4847 | zir.extra[extra_index + 0], |
| 4848 | 4848 | zir.extra[extra_index + 1], |
| ... | ... | @@ -4869,7 +4869,7 @@ pub fn getAssociatedSrcHash(zir: Zir, inst: Zir.Inst.Index) ?std.zig.SrcHash { |
| 4869 | 4869 | } else extra_index += @intFromBool(bits.has_ret_ty_ref); |
| 4870 | 4870 | extra_index += @intFromBool(bits.has_any_noalias); |
| 4871 | 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 | 4873 | return @bitCast([4]u32{ |
| 4874 | 4874 | zir.extra[extra_index + 0], |
| 4875 | 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 | 199 | } |
| 200 | 200 | }, |
| 201 | 201 | .@"union" => |info| { |
| 202 | inline for (info.fields) |field| { | |
| 203 | if (field.type == SourceType) return @unionInit(DestType, field.name, target); | |
| 202 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 203 | if (field_type == SourceType) return @unionInit(DestType, field_name, target); | |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 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 | 282 | }; |
| 283 | 283 | try state.abbrevs.abbrevs.ensureTotalCapacity( |
| 284 | 284 | bc.allocator, |
| 285 | @typeInfo(Abbrev.Builtin).@"enum".fields.len + abbrevs.len, | |
| 285 | @typeInfo(Abbrev.Builtin).@"enum".field_names.len + abbrevs.len, | |
| 286 | 286 | ); |
| 287 | 287 | |
| 288 | 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 | 318 | .{ .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 | 322 | for (abbrevs) |abbrev| try state.abbrevs.addAbbrevAssumeCapacity(bc.allocator, abbrev); |
| 323 | 323 | } |
| 324 | 324 | |
| ... | ... | @@ -457,7 +457,7 @@ const Abbrev = struct { |
| 457 | 457 | define_abbrev, |
| 458 | 458 | unabbrev_record, |
| 459 | 459 | |
| 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 | 461 | fn toRecordId(builtin: Builtin) u32 { |
| 462 | 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 | 1137 | .no_sanitize_hwaddress, |
| 1138 | 1138 | .sanitize_address_dyninit, |
| 1139 | 1139 | => |kind| { |
| 1140 | const field = comptime blk: { | |
| 1140 | const field_name, const field_type = comptime blk: { | |
| 1141 | 1141 | @setEvalBranchQuota(10_000); |
| 1142 | for (@typeInfo(Attribute).@"union".fields) |field| { | |
| 1143 | if (std.mem.eql(u8, field.name, @tagName(kind))) break :blk field; | |
| 1142 | const info = @typeInfo(Attribute).@"union"; | |
| 1143 | for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1144 | if (std.mem.eql(u8, field_name, @tagName(kind))) break :blk .{ field_name, field_type }; | |
| 1144 | 1145 | } |
| 1145 | 1146 | unreachable; |
| 1146 | 1147 | }; |
| 1147 | comptime assert(std.mem.eql(u8, @tagName(kind), field.name)); | |
| 1148 | return @unionInit(Attribute, field.name, switch (field.type) { | |
| 1148 | comptime assert(std.mem.eql(u8, @tagName(kind), field_name)); | |
| 1149 | return @unionInit(Attribute, field_name, switch (field_type) { | |
| 1149 | 1150 | void => {}, |
| 1150 | 1151 | u32 => storage.value, |
| 1151 | 1152 | Alignment.Lazy, String, Type, UwTable => @enumFromInt(storage.value), |
| 1152 | 1153 | AllocKind, AllocSize, FpClass, Memory, VScaleRange => @bitCast(storage.value), |
| 1153 | else => @compileError("bad payload type: " ++ field.name ++ ": " ++ | |
| 1154 | @typeName(field.type)), | |
| 1154 | else => @compileError("bad payload type: " ++ field_name ++ ": " ++ | |
| 1155 | @typeName(field_type)), | |
| 1155 | 1156 | }); |
| 1156 | 1157 | }, |
| 1157 | 1158 | .string, .none => unreachable, |
| ... | ... | @@ -1258,14 +1259,14 @@ pub const Attribute = union(Kind) { |
| 1258 | 1259 | try w.print(" {s}(", .{@tagName(attribute)}); |
| 1259 | 1260 | var any = false; |
| 1260 | 1261 | var remaining: Int = @bitCast(fpclass); |
| 1261 | inline for (@typeInfo(FpClass).@"struct".decls) |decl| { | |
| 1262 | const pattern: Int = @bitCast(@field(FpClass, decl.name)); | |
| 1262 | inline for (@typeInfo(FpClass).@"struct".decl_names) |decl_name| { | |
| 1263 | const pattern: Int = @bitCast(@field(FpClass, decl_name)); | |
| 1263 | 1264 | if (remaining & pattern == pattern) { |
| 1264 | 1265 | if (!any) { |
| 1265 | 1266 | try w.writeByte(' '); |
| 1266 | 1267 | any = true; |
| 1267 | 1268 | } |
| 1268 | try w.writeAll(decl.name); | |
| 1269 | try w.writeAll(decl_name); | |
| 1269 | 1270 | remaining &= ~pattern; |
| 1270 | 1271 | } |
| 1271 | 1272 | } |
| ... | ... | @@ -1283,14 +1284,14 @@ pub const Attribute = union(Kind) { |
| 1283 | 1284 | .allockind => |allockind| { |
| 1284 | 1285 | try w.print(" {t}(\"", .{attribute}); |
| 1285 | 1286 | var any = false; |
| 1286 | inline for (@typeInfo(AllocKind).@"struct".fields) |field| { | |
| 1287 | if (comptime std.mem.eql(u8, field.name, "_")) continue; | |
| 1288 | if (@field(allockind, field.name)) { | |
| 1287 | inline for (@typeInfo(AllocKind).@"struct".field_names) |field_name| { | |
| 1288 | if (comptime std.mem.eql(u8, field_name, "_")) continue; | |
| 1289 | if (@field(allockind, field_name)) { | |
| 1289 | 1290 | if (!any) { |
| 1290 | 1291 | try w.writeByte(','); |
| 1291 | 1292 | any = true; |
| 1292 | 1293 | } |
| 1293 | try w.writeAll(field.name); | |
| 1294 | try w.writeAll(field_name); | |
| 1294 | 1295 | } |
| 1295 | 1296 | } |
| 1296 | 1297 | try w.writeAll("\")"); |
| ... | ... | @@ -1442,7 +1443,7 @@ pub const Attribute = union(Kind) { |
| 1442 | 1443 | none = maxInt(u32), |
| 1443 | 1444 | _, |
| 1444 | 1445 | |
| 1445 | pub const len = @typeInfo(Kind).@"enum".fields.len - 2; | |
| 1446 | pub const len = @typeInfo(Kind).@"enum".field_names.len - 2; | |
| 1446 | 1447 | |
| 1447 | 1448 | pub fn fromString(str: String) Kind { |
| 1448 | 1449 | assert(!str.isAnon()); |
| ... | ... | @@ -5167,9 +5168,13 @@ pub const Function = struct { |
| 5167 | 5168 | index: Instruction.ExtraIndex, |
| 5168 | 5169 | ) struct { data: T, trail: ExtraDataTrail } { |
| 5169 | 5170 | var result: T = undefined; |
| 5170 | const fields = @typeInfo(T).@"struct".fields; | |
| 5171 | inline for (fields, self.extra[index..][0..fields.len]) |field, value| | |
| 5172 | @field(result, field.name) = switch (field.type) { | |
| 5171 | const info = @typeInfo(T).@"struct"; | |
| 5172 | inline for ( | |
| 5173 | info.field_names, | |
| 5174 | info.field_types, | |
| 5175 | self.extra[index..][0..info.field_names.len], | |
| 5176 | ) |field_name, field_type, value| | |
| 5177 | @field(result, field_name) = switch (field_type) { | |
| 5173 | 5178 | u32 => value, |
| 5174 | 5179 | Alignment, |
| 5175 | 5180 | AtomicOrdering, |
| ... | ... | @@ -5183,11 +5188,11 @@ pub const Function = struct { |
| 5183 | 5188 | Instruction.Alloca.Info, |
| 5184 | 5189 | Instruction.Call.Info, |
| 5185 | 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 | 5193 | return .{ |
| 5189 | 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 | } |
| 5193 | 5198 | |
| ... | ... | @@ -6327,9 +6332,10 @@ pub const WipFunction = struct { |
| 6327 | 6332 | |
| 6328 | 6333 | fn addExtra(wip_extra: *@This(), extra: anytype) Instruction.ExtraIndex { |
| 6329 | 6334 | const result = wip_extra.index; |
| 6330 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| { | |
| 6331 | const value = @field(extra, field.name); | |
| 6332 | wip_extra.items[wip_extra.index] = switch (field.type) { | |
| 6335 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 6336 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 6337 | const value = @field(extra, field_name); | |
| 6338 | wip_extra.items[wip_extra.index] = switch (field_type) { | |
| 6333 | 6339 | u32 => value, |
| 6334 | 6340 | Alignment, |
| 6335 | 6341 | AtomicOrdering, |
| ... | ... | @@ -6343,7 +6349,7 @@ pub const WipFunction = struct { |
| 6343 | 6349 | Instruction.Alloca.Info, |
| 6344 | 6350 | Instruction.Call.Info, |
| 6345 | 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 | 6354 | wip_extra.index += 1; |
| 6349 | 6355 | } |
| ... | ... | @@ -6944,7 +6950,7 @@ pub const WipFunction = struct { |
| 6944 | 6950 | ) Allocator.Error!void { |
| 6945 | 6951 | try self.extra.ensureUnusedCapacity( |
| 6946 | 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 | } |
| 6950 | 6956 | |
| ... | ... | @@ -6983,9 +6989,10 @@ pub const WipFunction = struct { |
| 6983 | 6989 | |
| 6984 | 6990 | fn addExtraAssumeCapacity(self: *WipFunction, extra: anytype) Instruction.ExtraIndex { |
| 6985 | 6991 | const result: Instruction.ExtraIndex = @intCast(self.extra.items.len); |
| 6986 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| { | |
| 6987 | const value = @field(extra, field.name); | |
| 6988 | self.extra.appendAssumeCapacity(switch (field.type) { | |
| 6992 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 6993 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 6994 | const value = @field(extra, field_name); | |
| 6995 | self.extra.appendAssumeCapacity(switch (field_type) { | |
| 6989 | 6996 | u32 => value, |
| 6990 | 6997 | Alignment, |
| 6991 | 6998 | AtomicOrdering, |
| ... | ... | @@ -6999,7 +7006,7 @@ pub const WipFunction = struct { |
| 6999 | 7006 | Instruction.Alloca.Info, |
| 7000 | 7007 | Instruction.Call.Info, |
| 7001 | 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 | 7012 | return result; |
| ... | ... | @@ -7032,9 +7039,13 @@ pub const WipFunction = struct { |
| 7032 | 7039 | index: Instruction.ExtraIndex, |
| 7033 | 7040 | ) struct { data: T, trail: ExtraDataTrail } { |
| 7034 | 7041 | var result: T = undefined; |
| 7035 | const fields = @typeInfo(T).@"struct".fields; | |
| 7036 | inline for (fields, self.extra.items[index..][0..fields.len]) |field, value| | |
| 7037 | @field(result, field.name) = switch (field.type) { | |
| 7042 | const info = @typeInfo(T).@"struct"; | |
| 7043 | inline for ( | |
| 7044 | info.field_names, | |
| 7045 | info.field_types, | |
| 7046 | self.extra.items[index..][0..info.field_names.len], | |
| 7047 | ) |field_name, field_type, value| | |
| 7048 | @field(result, field_name) = switch (field_type) { | |
| 7038 | 7049 | u32 => value, |
| 7039 | 7050 | Alignment, |
| 7040 | 7051 | AtomicOrdering, |
| ... | ... | @@ -7048,11 +7059,11 @@ pub const WipFunction = struct { |
| 7048 | 7059 | Instruction.Alloca.Info, |
| 7049 | 7060 | Instruction.Call.Info, |
| 7050 | 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 | 7064 | return .{ |
| 7054 | 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 | } |
| 7058 | 7069 | |
| ... | ... | @@ -8202,19 +8213,20 @@ pub const Metadata = packed struct(u32) { |
| 8202 | 8213 | |
| 8203 | 8214 | pub fn format(self: DIFlags, w: *Writer) Writer.Error!void { |
| 8204 | 8215 | var need_pipe = false; |
| 8205 | inline for (@typeInfo(DIFlags).@"struct".fields) |field| { | |
| 8206 | switch (@typeInfo(field.type)) { | |
| 8207 | .bool => if (@field(self, field.name)) { | |
| 8216 | const info = @typeInfo(DIFlags).@"struct"; | |
| 8217 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 8218 | switch (@typeInfo(field_type)) { | |
| 8219 | .bool => if (@field(self, field_name)) { | |
| 8208 | 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 | 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), | |
| 8216 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ | |
| 8217 | @typeName(field.type)), | |
| 8227 | .int => assert(@field(self, field_name) == 0), | |
| 8228 | else => @compileError("bad field type: " ++ field_name ++ ": " ++ | |
| 8229 | @typeName(field_type)), | |
| 8218 | 8230 | } |
| 8219 | 8231 | } |
| 8220 | 8232 | if (!need_pipe) try w.writeByte('0'); |
| ... | ... | @@ -8259,19 +8271,20 @@ pub const Metadata = packed struct(u32) { |
| 8259 | 8271 | |
| 8260 | 8272 | pub fn format(self: DISPFlags, w: *Writer) Writer.Error!void { |
| 8261 | 8273 | var need_pipe = false; |
| 8262 | inline for (@typeInfo(DISPFlags).@"struct".fields) |field| { | |
| 8263 | switch (@typeInfo(field.type)) { | |
| 8264 | .bool => if (@field(self, field.name)) { | |
| 8274 | const info = @typeInfo(DISPFlags).@"struct"; | |
| 8275 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 8276 | switch (@typeInfo(field_type)) { | |
| 8277 | .bool => if (@field(self, field_name)) { | |
| 8265 | 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 | 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), | |
| 8273 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ | |
| 8274 | @typeName(field.type)), | |
| 8285 | .int => assert(@field(self, field_name) == 0), | |
| 8286 | else => @compileError("bad field type: " ++ field_name ++ ": " ++ | |
| 8287 | @typeName(field_type)), | |
| 8275 | 8288 | } |
| 8276 | 8289 | } |
| 8277 | 8290 | if (!need_pipe) try w.writeByte('0'); |
| ... | ... | @@ -8567,7 +8580,7 @@ pub const Metadata = packed struct(u32) { |
| 8567 | 8580 | })) |some| switch (@typeInfo(Some)) { |
| 8568 | 8581 | .@"enum" => |enum_info| switch (Some) { |
| 8569 | 8582 | Metadata.String => .{ .string = some }, |
| 8570 | else => if (enum_info.is_exhaustive) | |
| 8583 | else => if (enum_info.mode == .exhaustive) | |
| 8571 | 8584 | .{ .raw = @tagName(some) } |
| 8572 | 8585 | else |
| 8573 | 8586 | @compileError("unknown type to format: " ++ @typeName(Node)), |
| ... | ... | @@ -8763,14 +8776,15 @@ pub fn init(options: Options) Allocator.Error!Builder { |
| 8763 | 8776 | } |
| 8764 | 8777 | |
| 8765 | 8778 | { |
| 8766 | const static_len = @typeInfo(Type).@"enum".fields.len - 1; | |
| 8779 | const static_len = @typeInfo(Type).@"enum".field_names.len - 1; | |
| 8767 | 8780 | try self.type_map.ensureTotalCapacity(self.gpa, static_len); |
| 8768 | 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 | 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 | 8789 | inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits| |
| 8776 | 8790 | assert(self.intTypeAssumeCapacity(bits) == |
| ... | ... | @@ -11016,7 +11030,7 @@ fn ensureUnusedTypeCapacity( |
| 11016 | 11030 | try self.type_items.ensureUnusedCapacity(self.gpa, count); |
| 11017 | 11031 | try self.type_extra.ensureUnusedCapacity( |
| 11018 | 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 | } |
| 11022 | 11036 | |
| ... | ... | @@ -11046,12 +11060,13 @@ fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { n |
| 11046 | 11060 | |
| 11047 | 11061 | fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraIndex { |
| 11048 | 11062 | const result: Type.Item.ExtraIndex = @intCast(self.type_extra.items.len); |
| 11049 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| { | |
| 11050 | const value = @field(extra, field.name); | |
| 11051 | self.type_extra.appendAssumeCapacity(switch (field.type) { | |
| 11063 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 11064 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 11065 | const value = @field(extra, field_name); | |
| 11066 | self.type_extra.appendAssumeCapacity(switch (field_type) { | |
| 11052 | 11067 | u32 => value, |
| 11053 | 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 | 11072 | return result; |
| ... | ... | @@ -11084,16 +11099,20 @@ fn typeExtraDataTrail( |
| 11084 | 11099 | index: Type.Item.ExtraIndex, |
| 11085 | 11100 | ) struct { data: T, trail: TypeExtraDataTrail } { |
| 11086 | 11101 | var result: T = undefined; |
| 11087 | const fields = @typeInfo(T).@"struct".fields; | |
| 11088 | inline for (fields, self.type_extra.items[index..][0..fields.len]) |field, value| | |
| 11089 | @field(result, field.name) = switch (field.type) { | |
| 11102 | const info = @typeInfo(T).@"struct"; | |
| 11103 | inline for ( | |
| 11104 | info.field_names, | |
| 11105 | info.field_types, | |
| 11106 | self.type_extra.items[index..][0..info.field_names.len], | |
| 11107 | ) |field_name, field_type, value| | |
| 11108 | @field(result, field_name) = switch (field_type) { | |
| 11090 | 11109 | u32 => value, |
| 11091 | 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 | 11113 | return .{ |
| 11095 | 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 | } |
| 11099 | 11118 | |
| ... | ... | @@ -11899,7 +11918,7 @@ fn ensureUnusedConstantCapacity( |
| 11899 | 11918 | try self.constant_items.ensureUnusedCapacity(self.gpa, count); |
| 11900 | 11919 | try self.constant_extra.ensureUnusedCapacity( |
| 11901 | 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 | } |
| 11905 | 11924 | |
| ... | ... | @@ -11974,13 +11993,14 @@ fn getOrPutConstantAggregateAssumeCapacity( |
| 11974 | 11993 | |
| 11975 | 11994 | fn addConstantExtraAssumeCapacity(self: *Builder, extra: anytype) Constant.Item.ExtraIndex { |
| 11976 | 11995 | const result: Constant.Item.ExtraIndex = @intCast(self.constant_extra.items.len); |
| 11977 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| { | |
| 11978 | const value = @field(extra, field.name); | |
| 11979 | self.constant_extra.appendAssumeCapacity(switch (field.type) { | |
| 11996 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 11997 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 11998 | const value = @field(extra, field_name); | |
| 11999 | self.constant_extra.appendAssumeCapacity(switch (field_type) { | |
| 11980 | 12000 | u32 => value, |
| 11981 | 12001 | String, Type, Constant, Function.Index, Function.Block.Index => @intFromEnum(value), |
| 11982 | 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 | 12006 | return result; |
| ... | ... | @@ -12013,17 +12033,21 @@ fn constantExtraDataTrail( |
| 12013 | 12033 | index: Constant.Item.ExtraIndex, |
| 12014 | 12034 | ) struct { data: T, trail: ConstantExtraDataTrail } { |
| 12015 | 12035 | var result: T = undefined; |
| 12016 | const fields = @typeInfo(T).@"struct".fields; | |
| 12017 | inline for (fields, self.constant_extra.items[index..][0..fields.len]) |field, value| | |
| 12018 | @field(result, field.name) = switch (field.type) { | |
| 12036 | const info = @typeInfo(T).@"struct"; | |
| 12037 | inline for ( | |
| 12038 | info.field_names, | |
| 12039 | info.field_types, | |
| 12040 | self.constant_extra.items[index..][0..info.field_names.len], | |
| 12041 | ) |field_name, field_type, value| | |
| 12042 | @field(result, field_name) = switch (field_type) { | |
| 12019 | 12043 | u32 => value, |
| 12020 | 12044 | String, Type, Constant, Function.Index, Function.Block.Index => @enumFromInt(value), |
| 12021 | 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 | 12048 | return .{ |
| 12025 | 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 | } |
| 12029 | 12053 | |
| ... | ... | @@ -12041,19 +12065,20 @@ fn ensureUnusedMetadataCapacity( |
| 12041 | 12065 | try self.metadata_items.ensureUnusedCapacity(self.gpa, count); |
| 12042 | 12066 | try self.metadata_extra.ensureUnusedCapacity( |
| 12043 | 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 | } |
| 12047 | 12071 | |
| 12048 | 12072 | fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.ExtraIndex { |
| 12049 | 12073 | const result: Metadata.Item.ExtraIndex = @intCast(self.metadata_extra.items.len); |
| 12050 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields) |field| { | |
| 12051 | const value = @field(extra, field.name); | |
| 12052 | self.metadata_extra.appendAssumeCapacity(switch (field.type) { | |
| 12074 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 12075 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 12076 | const value = @field(extra, field_name); | |
| 12077 | self.metadata_extra.appendAssumeCapacity(switch (field_type) { | |
| 12053 | 12078 | u32 => value, |
| 12054 | 12079 | Metadata.String, Metadata.String.Optional, Variable.Index, Value => @intFromEnum(value), |
| 12055 | 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 | 12084 | return result; |
| ... | ... | @@ -12086,17 +12111,21 @@ fn metadataExtraDataTrail( |
| 12086 | 12111 | index: Metadata.Item.ExtraIndex, |
| 12087 | 12112 | ) struct { data: T, trail: MetadataExtraDataTrail } { |
| 12088 | 12113 | var result: T = undefined; |
| 12089 | const fields = @typeInfo(T).@"struct".fields; | |
| 12090 | inline for (fields, self.metadata_extra.items[index..][0..fields.len]) |field, value| | |
| 12091 | @field(result, field.name) = switch (field.type) { | |
| 12114 | const info = @typeInfo(T).@"struct"; | |
| 12115 | inline for ( | |
| 12116 | info.field_names, | |
| 12117 | info.field_types, | |
| 12118 | self.metadata_extra.items[index..][0..info.field_names.len], | |
| 12119 | ) |field_name, field_type, value| | |
| 12120 | @field(result, field_name) = switch (field_type) { | |
| 12092 | 12121 | u32 => value, |
| 12093 | 12122 | Metadata.String, Metadata.String.Optional, Variable.Index, Value => @enumFromInt(value), |
| 12094 | 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 | 12126 | return .{ |
| 12098 | 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 | } |
| 12102 | 12131 | |
| ... | ... | @@ -12602,8 +12631,8 @@ fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytyp |
| 12602 | 12631 | builder: *const Builder, |
| 12603 | 12632 | pub fn hash(_: @This(), key: Key) u32 { |
| 12604 | 12633 | var hasher = std.hash.Wyhash.init(std.hash.int(@intFromEnum(key.tag))); |
| 12605 | inline for (std.meta.fields(@TypeOf(value))) |field| { | |
| 12606 | hasher.update(std.mem.asBytes(&@field(key.value, field.name))); | |
| 12634 | inline for (comptime std.meta.fieldNames(@TypeOf(value))) |field_name| { | |
| 12635 | hasher.update(std.mem.asBytes(&@field(key.value, field_name))); | |
| 12607 | 12636 | } |
| 12608 | 12637 | return @truncate(hasher.final()); |
| 12609 | 12638 | } |
| ... | ... | @@ -14184,12 +14213,14 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco |
| 14184 | 14213 | const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock; |
| 14185 | 14214 | var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true); |
| 14186 | 14215 | |
| 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 | 14219 | // 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 | 14221 | try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{ |
| 14191 | .id = field.value, | |
| 14192 | .name = field.name, | |
| 14222 | .id = field_value, | |
| 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 | 246 | |
| 247 | 247 | try self.bitcode.writeBits(comptime abbrevId(Abbrev), abbrev_len); |
| 248 | 248 | |
| 249 | const fields = std.meta.fields(Abbrev); | |
| 249 | const field_names = comptime std.meta.fieldNames(Abbrev); | |
| 250 | 250 | |
| 251 | 251 | // This abbreviation might only contain literals |
| 252 | if (fields.len == 0) return; | |
| 252 | if (field_names.len == 0) return; | |
| 253 | 253 | |
| 254 | 254 | comptime var field_index: usize = 0; |
| 255 | 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 | 257 | switch (ty) { |
| 258 | 258 | .literal => continue, |
| 259 | 259 | .fixed => |len| try self.bitcode.writeBits(adapter.get(param), len), |
| ... | ... | @@ -296,7 +296,7 @@ pub fn BitcodeWriter(comptime types: []const type) type { |
| 296 | 296 | }, |
| 297 | 297 | } |
| 298 | 298 | field_index += 1; |
| 299 | if (field_index == fields.len) break; | |
| 299 | if (field_index == field_names.len) break; | |
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 |
lib/std/zig/system.zig+4-4| ... | ... | @@ -973,10 +973,10 @@ fn detectAbiAndDynamicLinker(io: Io, cpu: Target.Cpu, os: Target.Os, query: Targ |
| 973 | 973 | // relying on `builtin.target`. |
| 974 | 974 | const all_abis = comptime blk: { |
| 975 | 975 | assert(@intFromEnum(Target.Abi.none) == 0); |
| 976 | const fields = std.meta.fields(Target.Abi)[1..]; | |
| 977 | var array: [fields.len]Target.Abi = undefined; | |
| 978 | for (fields, 0..) |field, i| { | |
| 979 | array[i] = @field(Target.Abi, field.name); | |
| 976 | const field_names = std.meta.fieldNames(Target.Abi)[1..]; | |
| 977 | var array: [field_names.len]Target.Abi = undefined; | |
| 978 | for (field_names, 0..) |field_name, i| { | |
| 979 | array[i] = @field(Target.Abi, field_name); | |
| 980 | 980 | } |
| 981 | 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 | 60 | @compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType)); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | const fields_info = args_type_info.@"struct".fields; | |
| 63 | const fields_info = args_type_info.@"struct"; | |
| 64 | 64 | |
| 65 | 65 | // Originally, I wanted to issue a single call with a more complex table structure such that we |
| 66 | 66 | // would sequentially visit each CPU#d subkey in the registry and pull the value of interest into |
| 67 | 67 | // a buffer, however, NT seems to be expecting a single buffer per each table meaning we would |
| 68 | 68 | // end up pulling only the last CPU core info, overwriting everything else. |
| 69 | 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 | 71 | var table: [table_size + 1]std.os.windows.RTL_QUERY_REGISTRY_TABLE = undefined; |
| 72 | 72 | |
| 73 | 73 | const topkey = std.unicode.utf8ToUtf16LeStringLiteral("\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor"); |
| ... | ... | @@ -90,11 +90,11 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { |
| 90 | 90 | .DefaultLength = 0, |
| 91 | 91 | }; |
| 92 | 92 | |
| 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; | |
| 94 | 94 | |
| 95 | inline for (fields_info, 0..) |field, i| { | |
| 95 | inline for (fields_info.field_names, 0..) |field_name, i| { | |
| 96 | 96 | const ctx: *anyopaque = blk: { |
| 97 | switch (@field(args, field.name).value_type) { | |
| 97 | switch (@field(args, field_name).value_type) { | |
| 98 | 98 | .SZ, |
| 99 | 99 | .EXPAND_SZ, |
| 100 | 100 | .MULTI_SZ, |
| ... | ... | @@ -119,7 +119,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { |
| 119 | 119 | }; |
| 120 | 120 | |
| 121 | 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 | 123 | key_buf[key_len] = 0; |
| 124 | 124 | |
| 125 | 125 | table[i + 1] = .{ |
| ... | ... | @@ -153,12 +153,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { |
| 153 | 153 | ); |
| 154 | 154 | switch (res) { |
| 155 | 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 | 157 | .SZ, |
| 158 | 158 | .EXPAND_SZ, |
| 159 | 159 | .MULTI_SZ, |
| 160 | 160 | => { |
| 161 | var buf = @field(args, field.name).value_buf; | |
| 161 | var buf = @field(args, field_name).value_buf; | |
| 162 | 162 | const entry: *const std.os.windows.UNICODE_STRING = @ptrCast(table[i + 1].EntryContext); |
| 163 | 163 | const len = try std.unicode.utf16LeToUtf8(buf, entry.slice()); |
| 164 | 164 | buf[len] = 0; |
| ... | ... | @@ -169,12 +169,12 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void { |
| 169 | 169 | .QWORD, |
| 170 | 170 | => { |
| 171 | 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 | 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 | 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 | 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 | 165 | }, |
| 166 | 166 | .@"struct" => |@"struct"| if (@"struct".is_tuple) { |
| 167 | 167 | var container = try self.beginTuple( |
| 168 | .{ .whitespace_style = .{ .fields = @"struct".fields.len } }, | |
| 168 | .{ .whitespace_style = .{ .fields = @"struct".field_names.len } }, | |
| 169 | 169 | ); |
| 170 | 170 | inline for (val) |field_value| { |
| 171 | 171 | try container.fieldArbitraryDepth(field_value, options); |
| ... | ... | @@ -173,15 +173,20 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption |
| 173 | 173 | try container.end(); |
| 174 | 174 | } else { |
| 175 | 175 | // Decide which fields to emit |
| 176 | const fields, const skipped: [@"struct".fields.len]bool = if (options.emit_default_optional_fields) b: { | |
| 177 | break :b .{ @"struct".fields.len, @splat(false) }; | |
| 176 | const fields, const skipped: [@"struct".field_names.len]bool = if (options.emit_default_optional_fields) b: { | |
| 177 | break :b .{ @"struct".field_names.len, @splat(false) }; | |
| 178 | 178 | } else b: { |
| 179 | var fields = @"struct".fields.len; | |
| 180 | var skipped: [@"struct".fields.len]bool = @splat(false); | |
| 181 | inline for (@"struct".fields, &skipped) |field_info, *skip| { | |
| 182 | if (field_info.default_value_ptr) |ptr| { | |
| 183 | const default: *const field_info.type = @ptrCast(@alignCast(ptr)); | |
| 184 | const field_value = @field(val, field_info.name); | |
| 179 | var fields = @"struct".field_names.len; | |
| 180 | var skipped: [@"struct".field_names.len]bool = @splat(false); | |
| 181 | inline for ( | |
| 182 | @"struct".field_names, | |
| 183 | @"struct".field_types, | |
| 184 | @"struct".field_attrs, | |
| 185 | &skipped, | |
| 186 | ) |field_name, field_type, field_attrs, *skip| { | |
| 187 | if (field_attrs.default_value_ptr) |ptr| { | |
| 188 | const default: *const field_type = @ptrCast(@alignCast(ptr)); | |
| 189 | const field_value = @field(val, field_name); | |
| 185 | 190 | if (std.meta.eql(field_value, default.*)) { |
| 186 | 191 | skip.* = true; |
| 187 | 192 | fields -= 1; |
| ... | ... | @@ -195,11 +200,11 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption |
| 195 | 200 | var container = try self.beginStruct( |
| 196 | 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 | 204 | if (!skip) { |
| 200 | 205 | try container.fieldArbitraryDepth( |
| 201 | field_info.name, | |
| 202 | @field(val, field_info.name), | |
| 206 | field_name, | |
| 207 | @field(val, field_name), | |
| 203 | 208 | options, |
| 204 | 209 | ); |
| 205 | 210 | } |
| ... | ... | @@ -713,11 +718,11 @@ fn typeIsRecursiveInner(comptime T: type, comptime prev_visited: []const type) b |
| 713 | 718 | .optional => |optional| typeIsRecursiveInner(optional.child, visited), |
| 714 | 719 | .array => |array| typeIsRecursiveInner(array.child, visited), |
| 715 | 720 | .vector => |vector| typeIsRecursiveInner(vector.child, visited), |
| 716 | .@"struct" => |@"struct"| for (@"struct".fields) |field| { | |
| 717 | if (typeIsRecursiveInner(field.type, visited)) break true; | |
| 721 | .@"struct" => |@"struct"| for (@"struct".field_types) |field_type| { | |
| 722 | if (typeIsRecursiveInner(field_type, visited)) break true; | |
| 718 | 723 | } else false, |
| 719 | .@"union" => |@"union"| inline for (@"union".fields) |field| { | |
| 720 | if (typeIsRecursiveInner(field.type, visited)) break true; | |
| 724 | .@"union" => |@"union"| inline for (@"union".field_types) |field_type| { | |
| 725 | if (typeIsRecursiveInner(field_type, visited)) break true; | |
| 721 | 726 | } else false, |
| 722 | 727 | else => false, |
| 723 | 728 | }; |
| ... | ... | @@ -761,8 +766,8 @@ fn checkValueDepth(val: anytype, depth: usize) error{ExceededMaxDepth}!void { |
| 761 | 766 | .array => for (val) |item| { |
| 762 | 767 | try checkValueDepth(item, child_depth); |
| 763 | 768 | }, |
| 764 | .@"struct" => |@"struct"| inline for (@"struct".fields) |field_info| { | |
| 765 | try checkValueDepth(@field(val, field_info.name), child_depth); | |
| 769 | .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| { | |
| 770 | try checkValueDepth(@field(val, field_name), child_depth); | |
| 766 | 771 | }, |
| 767 | 772 | .@"union" => |@"union"| if (@"union".tag_type == null) { |
| 768 | 773 | return; |
| ... | ... | @@ -851,7 +856,7 @@ fn canSerializeTypeInner( |
| 851 | 856 | .@"opaque", |
| 852 | 857 | => false, |
| 853 | 858 | |
| 854 | .@"enum" => |@"enum"| @"enum".is_exhaustive, | |
| 859 | .@"enum" => |@"enum"| @"enum".mode == .exhaustive, | |
| 855 | 860 | |
| 856 | 861 | .pointer => |pointer| switch (pointer.size) { |
| 857 | 862 | .one => canSerializeTypeInner(pointer.child, visited, parent_is_optional), |
| ... | ... | @@ -870,8 +875,8 @@ fn canSerializeTypeInner( |
| 870 | 875 | .@"struct" => |@"struct"| { |
| 871 | 876 | for (visited) |V| if (T == V) return true; |
| 872 | 877 | const new_visited = visited ++ .{T}; |
| 873 | for (@"struct".fields) |field| { | |
| 874 | if (!canSerializeTypeInner(field.type, new_visited, false)) return false; | |
| 878 | for (@"struct".field_types) |field_type| { | |
| 879 | if (!canSerializeTypeInner(field_type, new_visited, false)) return false; | |
| 875 | 880 | } |
| 876 | 881 | return true; |
| 877 | 882 | }, |
| ... | ... | @@ -879,8 +884,8 @@ fn canSerializeTypeInner( |
| 879 | 884 | for (visited) |V| if (T == V) return true; |
| 880 | 885 | const new_visited = visited ++ .{T}; |
| 881 | 886 | if (@"union".tag_type == null) return false; |
| 882 | for (@"union".fields) |field| { | |
| 883 | if (field.type != void and !canSerializeTypeInner(field.type, new_visited, false)) { | |
| 887 | for (@"union".field_types) |field_type| { | |
| 888 | if (field_type != void and !canSerializeTypeInner(field_type, new_visited, false)) { | |
| 884 | 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 | 437 | const array: [vector.len]vector.child = value; |
| 438 | 438 | freeArray(gpa, @TypeOf(array), &array); |
| 439 | 439 | }, |
| 440 | .@"struct" => |@"struct"| inline for (@"struct".fields) |field| { | |
| 441 | free(gpa, @field(value, field.name)); | |
| 440 | .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| { | |
| 441 | free(gpa, @field(value, field_name)); | |
| 442 | 442 | }, |
| 443 | 443 | .@"union" => |@"union"| if (@"union".tag_type == null) { |
| 444 | 444 | if (comptime requiresAllocator(Value)) unreachable; |
| ... | ... | @@ -464,13 +464,13 @@ fn requiresAllocator(T: type) bool { |
| 464 | 464 | return switch (@typeInfo(T)) { |
| 465 | 465 | .pointer => true, |
| 466 | 466 | .array => |array| return array.len > 0 and requiresAllocator(array.child), |
| 467 | .@"struct" => |@"struct"| inline for (@"struct".fields) |field| { | |
| 468 | if (requiresAllocator(field.type)) { | |
| 467 | .@"struct" => |@"struct"| inline for (@"struct".field_types) |field_type| { | |
| 468 | if (requiresAllocator(field_type)) { | |
| 469 | 469 | break true; |
| 470 | 470 | } |
| 471 | 471 | } else false, |
| 472 | .@"union" => |@"union"| inline for (@"union".fields) |field| { | |
| 473 | if (requiresAllocator(field.type)) { | |
| 472 | .@"union" => |@"union"| inline for (@"union".field_types) |field_type| { | |
| 473 | if (requiresAllocator(field_type)) { | |
| 474 | 474 | break true; |
| 475 | 475 | } |
| 476 | 476 | } else false, |
| ... | ... | @@ -589,9 +589,9 @@ const Parser = struct { |
| 589 | 589 | .one => return self.failExpectedTypeInner(pointer.child, opt, node), |
| 590 | 590 | .slice => { |
| 591 | 591 | if (pointer.child == u8 and |
| 592 | pointer.is_const and | |
| 592 | pointer.attrs.@"const" and | |
| 593 | 593 | (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 | 596 | if (opt) { |
| 597 | 597 | return self.failNode(node, "expected optional string"); |
| ... | ... | @@ -669,10 +669,10 @@ const Parser = struct { |
| 669 | 669 | switch (node.get(self.zoir)) { |
| 670 | 670 | .enum_literal => |field_name| { |
| 671 | 671 | // Create a comptime string map for the enum fields |
| 672 | const enum_fields = @typeInfo(T).@"enum".fields; | |
| 673 | comptime var kvs_list: [enum_fields.len]struct { []const u8, T } = undefined; | |
| 674 | inline for (enum_fields, 0..) |field, i| { | |
| 675 | kvs_list[i] = .{ field.name, @enumFromInt(field.value) }; | |
| 672 | const enum_info = @typeInfo(T).@"enum"; | |
| 673 | comptime var kvs_list: [enum_info.field_names.len]struct { []const u8, T } = undefined; | |
| 674 | inline for (enum_info.field_names, enum_info.field_values, 0..) |enum_field_name, enum_field_value, i| { | |
| 675 | kvs_list[i] = .{ enum_field_name, @enumFromInt(enum_field_value) }; | |
| 676 | 676 | } |
| 677 | 677 | const enum_tags = std.StaticStringMap(T).initComptime(kvs_list); |
| 678 | 678 | |
| ... | ... | @@ -715,9 +715,9 @@ const Parser = struct { |
| 715 | 715 | |
| 716 | 716 | if (pointer.child != u8 or |
| 717 | 717 | pointer.size != .slice or |
| 718 | !pointer.is_const or | |
| 718 | !pointer.attrs.@"const" or | |
| 719 | 719 | (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 | 722 | return error.WrongType; |
| 723 | 723 | } |
| ... | ... | @@ -742,7 +742,7 @@ const Parser = struct { |
| 742 | 742 | const slice = try self.gpa.allocWithOptions( |
| 743 | 743 | pointer.child, |
| 744 | 744 | nodes.len, |
| 745 | .fromByteUnitsOptional(pointer.alignment), | |
| 745 | .fromByteUnitsOptional(pointer.attrs.@"align"), | |
| 746 | 746 | pointer.sentinel(), |
| 747 | 747 | ); |
| 748 | 748 | errdefer self.gpa.free(slice); |
| ... | ... | @@ -808,30 +808,30 @@ const Parser = struct { |
| 808 | 808 | else => return error.WrongType, |
| 809 | 809 | }; |
| 810 | 810 | |
| 811 | const field_infos = @typeInfo(T).@"struct".fields; | |
| 811 | const info = @typeInfo(T).@"struct"; | |
| 812 | 812 | |
| 813 | 813 | // Build a map from field name to index. |
| 814 | 814 | // The special value `comptime_field` indicates that this is actually a comptime field. |
| 815 | 815 | const comptime_field = std.math.maxInt(usize); |
| 816 | 816 | const field_indices: std.StaticStringMap(usize) = comptime b: { |
| 817 | var kvs_list: [field_infos.len]struct { []const u8, usize } = undefined; | |
| 818 | for (&kvs_list, field_infos, 0..) |*kv, field, i| { | |
| 819 | kv.* = .{ field.name, if (field.is_comptime) comptime_field else i }; | |
| 817 | var kvs_list: [info.field_names.len]struct { []const u8, usize } = undefined; | |
| 818 | for (&kvs_list, info.field_names, info.field_attrs, 0..) |*kv, field_name, field_attrs, i| { | |
| 819 | kv.* = .{ field_name, if (field_attrs.@"comptime") comptime_field else i }; | |
| 820 | 820 | } |
| 821 | 821 | break :b .initComptime(kvs_list); |
| 822 | 822 | }; |
| 823 | 823 | |
| 824 | 824 | // Parse the struct |
| 825 | 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); | |
| 827 | 827 | |
| 828 | 828 | // If we fail partway through, free all already initialized fields |
| 829 | 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 | 831 | for (fields.names[0..initialized]) |name_runtime| { |
| 832 | 832 | switch (field_indices.get(name_runtime.get(self.zoir)) orelse continue) { |
| 833 | inline 0...(field_infos.len - 1) => |name_index| { | |
| 834 | const name = field_infos[name_index].name; | |
| 833 | inline 0...(info.field_names.len - 1) => |name_index| { | |
| 834 | const name = info.field_names[name_index]; | |
| 835 | 835 | free(self.gpa, @field(result, name)); |
| 836 | 836 | }, |
| 837 | 837 | else => unreachable, // Can't be out of bounds |
| ... | ... | @@ -856,11 +856,11 @@ const Parser = struct { |
| 856 | 856 | field_found[field_index] = true; |
| 857 | 857 | |
| 858 | 858 | switch (field_index) { |
| 859 | inline 0...(field_infos.len - 1) => |j| { | |
| 860 | if (field_infos[j].is_comptime) unreachable; | |
| 859 | inline 0...(info.field_names.len - 1) => |j| { | |
| 860 | if (info.field_attrs[j].@"comptime") unreachable; | |
| 861 | 861 | |
| 862 | @field(result, field_infos[j].name) = try self.parseExpr( | |
| 863 | field_infos[j].type, | |
| 862 | @field(result, info.field_names[j]) = try self.parseExpr( | |
| 863 | info.field_types[j], | |
| 864 | 864 | fields.vals.at(@intCast(i)), |
| 865 | 865 | ); |
| 866 | 866 | }, |
| ... | ... | @@ -873,15 +873,14 @@ const Parser = struct { |
| 873 | 873 | // Fill in any missing default fields |
| 874 | 874 | inline for (field_found, 0..) |found, i| { |
| 875 | 875 | if (!found) { |
| 876 | const field_info = field_infos[i]; | |
| 877 | if (field_info.default_value_ptr) |default| { | |
| 878 | const typed: *const field_info.type = @ptrCast(@alignCast(default)); | |
| 879 | @field(result, field_info.name) = typed.*; | |
| 876 | const field_attrs = info.field_attrs[i]; | |
| 877 | if (field_attrs.defaultValue(info.field_types[i])) |default| { | |
| 878 | @field(result, info.field_names[i]) = default; | |
| 880 | 879 | } else { |
| 881 | 880 | return self.failNodeFmt( |
| 882 | 881 | node, |
| 883 | 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 | 897 | }; |
| 899 | 898 | |
| 900 | 899 | var result: T = undefined; |
| 901 | const field_infos = @typeInfo(T).@"struct".fields; | |
| 900 | const info = @typeInfo(T).@"struct"; | |
| 902 | 901 | |
| 903 | if (nodes.len > field_infos.len) { | |
| 902 | if (nodes.len > info.field_names.len) { | |
| 904 | 903 | return self.failNodeFmt( |
| 905 | nodes.at(field_infos.len), | |
| 904 | nodes.at(info.field_names.len), | |
| 906 | 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 | } |
| 910 | 909 | |
| 911 | inline for (0..field_infos.len) |i| { | |
| 910 | inline for (0..info.field_names.len) |i| { | |
| 912 | 911 | // Check if we're out of bounds |
| 913 | 912 | if (i >= nodes.len) { |
| 914 | if (field_infos[i].default_value_ptr) |default| { | |
| 915 | const typed: *const field_infos[i].type = @ptrCast(@alignCast(default)); | |
| 916 | @field(result, field_infos[i].name) = typed.*; | |
| 913 | if (info.field_attrs[i].defaultValue(info.field_types[i])) |default| { | |
| 914 | @field(result, info.field_names[i]) = default; | |
| 917 | 915 | } else { |
| 918 | 916 | return self.failNodeFmt(node, "missing tuple field with index {}", .{i}); |
| 919 | 917 | } |
| ... | ... | @@ -926,10 +924,10 @@ const Parser = struct { |
| 926 | 924 | } |
| 927 | 925 | }; |
| 928 | 926 | |
| 929 | if (field_infos[i].is_comptime) { | |
| 927 | if (info.field_attrs[i].@"comptime") { | |
| 930 | 928 | return self.failComptimeField(node, i); |
| 931 | 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 | 937 | |
| 940 | 938 | fn parseUnion(self: *@This(), T: type, node: Zoir.Node.Index) !T { |
| 941 | 939 | const @"union" = @typeInfo(T).@"union"; |
| 942 | const field_infos = @"union".fields; | |
| 943 | 940 | |
| 944 | if (field_infos.len == 0) comptime unreachable; | |
| 941 | if (@"union".field_names.len == 0) comptime unreachable; | |
| 945 | 942 | |
| 946 | 943 | // Gather info on the fields |
| 947 | 944 | const field_indices = b: { |
| 948 | comptime var kvs_list: [field_infos.len]struct { []const u8, usize } = undefined; | |
| 949 | inline for (field_infos, 0..) |field, i| { | |
| 950 | kvs_list[i] = .{ field.name, i }; | |
| 945 | comptime var kvs_list: [@"union".field_names.len]struct { []const u8, usize } = undefined; | |
| 946 | inline for (@"union".field_names, 0..) |field_name, i| { | |
| 947 | kvs_list[i] = .{ field_name, i }; | |
| 951 | 948 | } |
| 952 | 949 | break :b std.StaticStringMap(usize).initComptime(kvs_list); |
| 953 | 950 | }; |
| ... | ... | @@ -970,13 +967,13 @@ const Parser = struct { |
| 970 | 967 | |
| 971 | 968 | // Initialize the union from the given field. |
| 972 | 969 | switch (field_index) { |
| 973 | inline 0...field_infos.len - 1 => |i| { | |
| 970 | inline 0...@"union".field_names.len - 1 => |i| { | |
| 974 | 971 | // Fail if the field is not void |
| 975 | if (field_infos[i].type != void) | |
| 972 | if (@"union".field_types[i] != void) | |
| 976 | 973 | return self.failNode(node, "expected union"); |
| 977 | 974 | |
| 978 | 975 | // Instantiate the union |
| 979 | return @unionInit(T, field_infos[i].name, {}); | |
| 976 | return @unionInit(T, @"union".field_names[i], {}); | |
| 980 | 977 | }, |
| 981 | 978 | else => unreachable, // Can't be out of bounds |
| 982 | 979 | } |
| ... | ... | @@ -994,12 +991,12 @@ const Parser = struct { |
| 994 | 991 | return self.failUnexpected(T, "field", node, 0, field_name_str); |
| 995 | 992 | |
| 996 | 993 | switch (field_index) { |
| 997 | inline 0...field_infos.len - 1 => |i| { | |
| 998 | if (field_infos[i].type == void) { | |
| 994 | inline 0...@"union".field_names.len - 1 => |i| { | |
| 995 | if (@"union".field_types[i] == void) { | |
| 999 | 996 | return self.failNode(field_val, "expected type 'void'"); |
| 1000 | 997 | } else { |
| 1001 | const value = try self.parseExpr(field_infos[i].type, field_val); | |
| 1002 | return @unionInit(T, field_infos[i].name, value); | |
| 998 | const value = try self.parseExpr(@"union".field_types[i], field_val); | |
| 999 | return @unionInit(T, @"union".field_names[i], value); | |
| 1003 | 1000 | } |
| 1004 | 1001 | }, |
| 1005 | 1002 | else => unreachable, // Can't be out of bounds |
| ... | ... | @@ -1106,7 +1103,7 @@ const Parser = struct { |
| 1106 | 1103 | } else self.ast.nodeMainToken(node.getAstNode(self.zoir)); |
| 1107 | 1104 | switch (@typeInfo(T)) { |
| 1108 | 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 | 1107 | break :b .{ |
| 1111 | 1108 | .token = token, |
| 1112 | 1109 | .offset = 0, |
| ... | ... | @@ -1118,9 +1115,9 @@ const Parser = struct { |
| 1118 | 1115 | var buf: std.ArrayList(u8) = try .initCapacity(gpa, 64); |
| 1119 | 1116 | defer buf.deinit(gpa); |
| 1120 | 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 | 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 | 1121 | .allow_primitive = true, |
| 1125 | 1122 | .allow_underscore = true, |
| 1126 | 1123 | })}); |
| ... | ... | @@ -1236,8 +1233,8 @@ fn canParseTypeInner( |
| 1236 | 1233 | .@"struct" => |@"struct"| { |
| 1237 | 1234 | for (visited) |V| if (T == V) return true; |
| 1238 | 1235 | const new_visited = visited ++ .{T}; |
| 1239 | for (@"struct".fields) |field| { | |
| 1240 | if (!field.is_comptime and !canParseTypeInner(field.type, new_visited, false)) { | |
| 1236 | for (@"struct".field_types, @"struct".field_attrs) |field_type, field_attrs| { | |
| 1237 | if (!field_attrs.@"comptime" and !canParseTypeInner(field_type, new_visited, false)) { | |
| 1241 | 1238 | return false; |
| 1242 | 1239 | } |
| 1243 | 1240 | } |
| ... | ... | @@ -1246,8 +1243,8 @@ fn canParseTypeInner( |
| 1246 | 1243 | .@"union" => |@"union"| { |
| 1247 | 1244 | for (visited) |V| if (T == V) return true; |
| 1248 | 1245 | const new_visited = visited ++ .{T}; |
| 1249 | for (@"union".fields) |field| { | |
| 1250 | if (field.type != void and !canParseTypeInner(field.type, new_visited, false)) { | |
| 1246 | for (@"union".field_types) |field_type| { | |
| 1247 | if (field_type != void and !canParseTypeInner(field_type, new_visited, false)) { | |
| 1251 | 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 | 1805 | /// Returns the requested data, as well as the new index which is at the start of the |
| 1806 | 1806 | /// trailers for the object. |
| 1807 | 1807 | pub 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 | 1809 | var i: usize = index; |
| 1810 | 1810 | var result: T = undefined; |
| 1811 | inline for (fields) |field| { | |
| 1812 | @field(result, field.name) = switch (field.type) { | |
| 1811 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1812 | @field(result, field_name) = switch (field_type) { | |
| 1813 | 1813 | u32 => air.extra.items[i], |
| 1814 | 1814 | InternPool.Index, Inst.Ref => @enumFromInt(air.extra.items[i]), |
| 1815 | 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 | 1818 | i += 1; |
| 1819 | 1819 | } |
src/Air/Legalize.zig+8-8| ... | ... | @@ -2635,7 +2635,7 @@ const Block = struct { |
| 2635 | 2635 | .data = .{ .legalize_compiler_rt_call = .{ |
| 2636 | 2636 | .func = func, |
| 2637 | 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 | 2639 | try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_len); |
| 2640 | 2640 | const index = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable; |
| 2641 | 2641 | l.air_extra.appendSliceAssumeCapacity(@ptrCast(args)); |
| ... | ... | @@ -2913,12 +2913,12 @@ fn addInstAssumeCapacity(l: *Legalize, inst: Air.Inst) Air.Inst.Index { |
| 2913 | 2913 | } |
| 2914 | 2914 | |
| 2915 | 2915 | fn addExtra(l: *Legalize, comptime Extra: type, extra: Extra) Error!u32 { |
| 2916 | const extra_fields = @typeInfo(Extra).@"struct".fields; | |
| 2917 | try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_fields.len); | |
| 2918 | defer inline for (extra_fields) |field| l.air_extra.appendAssumeCapacity(switch (field.type) { | |
| 2919 | u32 => @field(extra, field.name), | |
| 2920 | Air.Inst.Ref => @intFromEnum(@field(extra, field.name)), | |
| 2921 | else => @compileError(@typeName(field.type)), | |
| 2916 | const extra_info = @typeInfo(Extra).@"struct"; | |
| 2917 | try l.air_extra.ensureUnusedCapacity(l.pt.zcu.gpa, extra_info.field_names.len); | |
| 2918 | defer inline for (extra_info.field_names, extra_info.field_types) |field_name, field_type| l.air_extra.appendAssumeCapacity(switch (field_type) { | |
| 2919 | u32 => @field(extra, field_name), | |
| 2920 | Air.Inst.Ref => @intFromEnum(@field(extra, field_name)), | |
| 2921 | else => @compileError(@typeName(field_type)), | |
| 2922 | 2922 | }); |
| 2923 | 2923 | return @intCast(l.air_extra.items.len); |
| 2924 | 2924 | } |
| ... | ... | @@ -2954,7 +2954,7 @@ fn compilerRtCall( |
| 2954 | 2954 | const func_ret_ty = func.returnType(); |
| 2955 | 2955 | |
| 2956 | 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 | 2958 | const payload = l.addExtra(Air.Call, .{ .args_len = @intCast(args.len) }) catch unreachable; |
| 2959 | 2959 | l.air_extra.appendSliceAssumeCapacity(@ptrCast(args)); |
| 2960 | 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 | 351 | extra: std.ArrayList(u32), |
| 352 | 352 | |
| 353 | 353 | fn addExtra(a: *Analysis, extra: anytype) Allocator.Error!u32 { |
| 354 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 355 | try a.extra.ensureUnusedCapacity(a.gpa, fields.len); | |
| 354 | const field_count = std.meta.fieldNames(@TypeOf(extra)).len; | |
| 355 | try a.extra.ensureUnusedCapacity(a.gpa, field_count); | |
| 356 | 356 | return addExtraAssumeCapacity(a, extra); |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | fn addExtraAssumeCapacity(a: *Analysis, extra: anytype) u32 { |
| 360 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 360 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 361 | 361 | const result = @as(u32, @intCast(a.extra.items.len)); |
| 362 | inline for (fields) |field| { | |
| 363 | a.extra.appendAssumeCapacity(switch (field.type) { | |
| 364 | u32 => @field(extra, field.name), | |
| 362 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 363 | a.extra.appendAssumeCapacity(switch (field_type) { | |
| 364 | u32 => @field(extra, field_name), | |
| 365 | 365 | else => @compileError("bad field type"), |
| 366 | 366 | }); |
| 367 | 367 | } |
| ... | ... | @@ -1002,7 +1002,7 @@ fn analyzeInstBlock( |
| 1002 | 1002 | const block_scope = data.block_scopes.get(inst).?; |
| 1003 | 1003 | const num_deaths = data.live_set.count() - block_scope.live_set.count(); |
| 1004 | 1004 | |
| 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 | 1006 | const extra_index = a.addExtraAssumeCapacity(Block{ |
| 1007 | 1007 | .death_count = num_deaths, |
| 1008 | 1008 | }); |
| ... | ... | @@ -1265,7 +1265,7 @@ fn analyzeInstCondBr( |
| 1265 | 1265 | // Write the mirrored deaths to `extra` |
| 1266 | 1266 | const then_death_count = @as(u32, @intCast(then_mirrored_deaths.items.len)); |
| 1267 | 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 | 1269 | const extra_index = a.addExtraAssumeCapacity(CondBr{ |
| 1270 | 1270 | .then_death_count = then_death_count, |
| 1271 | 1271 | .else_death_count = else_death_count, |
src/Builtin.zig+3-3| ... | ... | @@ -23,8 +23,8 @@ wasi_exec_model: std.lang.WasiExecModel, |
| 23 | 23 | /// of the resulting file contents. |
| 24 | 24 | pub fn hash(opts: @This()) [std.Build.Cache.bin_digest_len]u8 { |
| 25 | 25 | var h: Cache.Hasher = Cache.hasher_init; |
| 26 | inline for (@typeInfo(@This()).@"struct".fields) |f| { | |
| 27 | if (comptime std.mem.eql(u8, f.name, "target")) { | |
| 26 | inline for (@typeInfo(@This()).@"struct".field_names) |f_name| { | |
| 27 | if (comptime std.mem.eql(u8, f_name, "target")) { | |
| 28 | 28 | // This needs special handling. |
| 29 | 29 | std.hash.autoHash(&h, opts.target.cpu); |
| 30 | 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 | 33 | std.hash.autoHash(&h, opts.target.ofmt); |
| 34 | 34 | std.hash.autoHash(&h, opts.target.dynamic_linker); |
| 35 | 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 | 39 | return h.finalResult(); |
src/Compilation.zig+18-18| ... | ... | @@ -298,15 +298,15 @@ const QueuedJobs = struct { |
| 298 | 298 | ubsan_rt_lib: bool = false, |
| 299 | 299 | ubsan_rt_obj: bool = false, |
| 300 | 300 | fuzzer_lib: bool = false, |
| 301 | musl_crt_file: [@typeInfo(musl.CrtFile).@"enum".fields.len]bool = @splat(false), | |
| 302 | glibc_crt_file: [@typeInfo(glibc.CrtFile).@"enum".fields.len]bool = @splat(false), | |
| 303 | freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".fields.len]bool = @splat(false), | |
| 304 | netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".fields.len]bool = @splat(false), | |
| 305 | openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".fields.len]bool = @splat(false), | |
| 301 | musl_crt_file: [@typeInfo(musl.CrtFile).@"enum".field_names.len]bool = @splat(false), | |
| 302 | glibc_crt_file: [@typeInfo(glibc.CrtFile).@"enum".field_names.len]bool = @splat(false), | |
| 303 | freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".field_names.len]bool = @splat(false), | |
| 304 | netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), | |
| 305 | openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), | |
| 306 | 306 | /// 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 | 308 | /// 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 | 310 | /// all of the glibc shared objects |
| 311 | 311 | glibc_shared_objects: bool = false, |
| 312 | 312 | freebsd_shared_objects: bool = false, |
| ... | ... | @@ -2552,10 +2552,10 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, |
| 2552 | 2552 | error.LibCInstallationMissingCrtDir => return diag.fail(.libc_installation_missing_crt_dir), |
| 2553 | 2553 | }; |
| 2554 | 2554 | |
| 2555 | const fields = @typeInfo(@TypeOf(paths)).@"struct".fields; | |
| 2556 | try comp.oneshot_prelink_tasks.ensureUnusedCapacity(gpa, fields.len + 1); | |
| 2557 | inline for (fields) |field| { | |
| 2558 | if (@field(paths, field.name)) |path| { | |
| 2555 | const field_names = @typeInfo(@TypeOf(paths)).@"struct".field_names; | |
| 2556 | try comp.oneshot_prelink_tasks.ensureUnusedCapacity(gpa, field_names.len + 1); | |
| 2557 | inline for (field_names) |field_name| { | |
| 2558 | if (@field(paths, field_name)) |path| { | |
| 2559 | 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 | 4667 | prelink_group.async(io, buildLibZigC, .{ comp, main_progress_node }); |
| 4668 | 4668 | } |
| 4669 | 4669 | |
| 4670 | for (0..@typeInfo(musl.CrtFile).@"enum".fields.len) |i| { | |
| 4670 | for (0..@typeInfo(musl.CrtFile).@"enum".field_names.len) |i| { | |
| 4671 | 4671 | if (comp.queued_jobs.musl_crt_file[i]) { |
| 4672 | 4672 | const tag: musl.CrtFile = @enumFromInt(i); |
| 4673 | 4673 | prelink_group.async(io, buildMuslCrtFile, .{ comp, tag, main_progress_node }); |
| 4674 | 4674 | } |
| 4675 | 4675 | } |
| 4676 | 4676 | |
| 4677 | for (0..@typeInfo(glibc.CrtFile).@"enum".fields.len) |i| { | |
| 4677 | for (0..@typeInfo(glibc.CrtFile).@"enum".field_names.len) |i| { | |
| 4678 | 4678 | if (comp.queued_jobs.glibc_crt_file[i]) { |
| 4679 | 4679 | const tag: glibc.CrtFile = @enumFromInt(i); |
| 4680 | 4680 | prelink_group.async(io, buildGlibcCrtFile, .{ comp, tag, main_progress_node }); |
| 4681 | 4681 | } |
| 4682 | 4682 | } |
| 4683 | 4683 | |
| 4684 | for (0..@typeInfo(freebsd.CrtFile).@"enum".fields.len) |i| { | |
| 4684 | for (0..@typeInfo(freebsd.CrtFile).@"enum".field_names.len) |i| { | |
| 4685 | 4685 | if (comp.queued_jobs.freebsd_crt_file[i]) { |
| 4686 | 4686 | const tag: freebsd.CrtFile = @enumFromInt(i); |
| 4687 | 4687 | prelink_group.async(io, buildFreeBSDCrtFile, .{ comp, tag, main_progress_node }); |
| 4688 | 4688 | } |
| 4689 | 4689 | } |
| 4690 | 4690 | |
| 4691 | for (0..@typeInfo(netbsd.CrtFile).@"enum".fields.len) |i| { | |
| 4691 | for (0..@typeInfo(netbsd.CrtFile).@"enum".field_names.len) |i| { | |
| 4692 | 4692 | if (comp.queued_jobs.netbsd_crt_file[i]) { |
| 4693 | 4693 | const tag: netbsd.CrtFile = @enumFromInt(i); |
| 4694 | 4694 | prelink_group.async(io, buildNetBSDCrtFile, .{ comp, tag, main_progress_node }); |
| 4695 | 4695 | } |
| 4696 | 4696 | } |
| 4697 | 4697 | |
| 4698 | for (0..@typeInfo(openbsd.CrtFile).@"enum".fields.len) |i| { | |
| 4698 | for (0..@typeInfo(openbsd.CrtFile).@"enum".field_names.len) |i| { | |
| 4699 | 4699 | if (comp.queued_jobs.openbsd_crt_file[i]) { |
| 4700 | 4700 | const tag: openbsd.CrtFile = @enumFromInt(i); |
| 4701 | 4701 | prelink_group.async(io, buildOpenBSDCrtFile, .{ comp, tag, main_progress_node }); |
| 4702 | 4702 | } |
| 4703 | 4703 | } |
| 4704 | 4704 | |
| 4705 | for (0..@typeInfo(wasi_libc.CrtFile).@"enum".fields.len) |i| { | |
| 4705 | for (0..@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len) |i| { | |
| 4706 | 4706 | if (comp.queued_jobs.wasi_libc_crt_file[i]) { |
| 4707 | 4707 | const tag: wasi_libc.CrtFile = @enumFromInt(i); |
| 4708 | 4708 | prelink_group.async(io, buildWasiLibcCrtFile, .{ comp, tag, main_progress_node }); |
| 4709 | 4709 | } |
| 4710 | 4710 | } |
| 4711 | 4711 | |
| 4712 | for (0..@typeInfo(mingw.CrtFile).@"enum".fields.len) |i| { | |
| 4712 | for (0..@typeInfo(mingw.CrtFile).@"enum".field_names.len) |i| { | |
| 4713 | 4713 | if (comp.queued_jobs.mingw_crt_file[i]) { |
| 4714 | 4714 | const tag: mingw.CrtFile = @enumFromInt(i); |
| 4715 | 4715 | prelink_group.async(io, buildMingwCrtFile, .{ comp, tag, main_progress_node }); |
src/InternPool.zig+108-107| ... | ... | @@ -1070,17 +1070,15 @@ const Local = struct { |
| 1070 | 1070 | |
| 1071 | 1071 | fn PtrArrayElem(comptime len: usize) type { |
| 1072 | 1072 | const elem_info = @typeInfo(Elem).@"struct"; |
| 1073 | const elem_fields = elem_info.fields; | |
| 1074 | var new_names: [elem_fields.len][]const u8 = undefined; | |
| 1075 | var new_types: [elem_fields.len]type = undefined; | |
| 1076 | for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| { | |
| 1077 | new_name.* = elem_field.name; | |
| 1078 | NewType.* = *[len]elem_field.type; | |
| 1073 | ||
| 1074 | var new_types: [elem_info.field_types.len]type = undefined; | |
| 1075 | for (&new_types, elem_info.field_types) |*NewType, elem_field_type| { | |
| 1076 | NewType.* = *[len]elem_field_type; | |
| 1079 | 1077 | } |
| 1080 | 1078 | if (elem_info.is_tuple) { |
| 1081 | 1079 | return @Tuple(&new_types); |
| 1082 | 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 | 1084 | fn PtrElem(comptime opts: struct { |
| ... | ... | @@ -1088,17 +1086,14 @@ const Local = struct { |
| 1088 | 1086 | is_const: bool = false, |
| 1089 | 1087 | }) type { |
| 1090 | 1088 | const elem_info = @typeInfo(Elem).@"struct"; |
| 1091 | const elem_fields = elem_info.fields; | |
| 1092 | var new_names: [elem_fields.len][]const u8 = undefined; | |
| 1093 | var new_types: [elem_fields.len]type = undefined; | |
| 1094 | for (elem_fields, &new_names, &new_types) |elem_field, *new_name, *NewType| { | |
| 1095 | new_name.* = elem_field.name; | |
| 1096 | NewType.* = @Pointer(opts.size, .{ .@"const" = opts.is_const }, elem_field.type, null); | |
| 1089 | var new_types: [elem_info.field_types.len]type = undefined; | |
| 1090 | for (&new_types, elem_info.field_types) |*NewType, elem_field_type| { | |
| 1091 | NewType.* = @Pointer(opts.size, .{ .@"const" = opts.is_const }, elem_field_type, null); | |
| 1097 | 1092 | } |
| 1098 | 1093 | if (elem_info.is_tuple) { |
| 1099 | 1094 | return @Tuple(&new_types); |
| 1100 | 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 | } |
| 1104 | 1099 | |
| ... | ... | @@ -4295,48 +4290,51 @@ pub const Index = enum(u32) { |
| 4295 | 4290 | }, |
| 4296 | 4291 | }) void { |
| 4297 | 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 | 4294 | @setEvalBranchQuota(3_000); |
| 4300 | inline for (@typeInfo(Tag).@"enum".fields, 0..) |tag, start| { | |
| 4301 | inline for (0..map_fields.len) |offset| { | |
| 4302 | if (comptime std.mem.eql(u8, tag.name, map_fields[(start + offset) % map_fields.len].name)) break; | |
| 4295 | inline for (@typeInfo(Tag).@"enum".field_names, 0..) |tag_name, start| { | |
| 4296 | inline for (0..map_info.field_names.len) |offset| { | |
| 4297 | if (comptime std.mem.eql(u8, tag_name, map_info.field_names[(start + offset) % map_info.field_names.len])) break; | |
| 4303 | 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 | 4303 | comptime { |
| 4309 | 4304 | if (!builtin.strip_debug_info) switch (builtin.zig_backend) { |
| 4310 | 4305 | .stage2_llvm => _ = &dbHelper, |
| 4311 | .stage2_x86_64 => for (@typeInfo(Tag).@"enum".fields) |tag| { | |
| 4312 | if (!@hasField(@TypeOf(Tag.encodings), tag.name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name); | |
| 4313 | const encoding = @field(Tag.encodings, tag.name); | |
| 4314 | if (@hasField(@TypeOf(encoding), "trailing")) for (@typeInfo(encoding.trailing).@"struct".fields) |field| { | |
| 4315 | struct { | |
| 4316 | fn checkConfig(name: []const u8) void { | |
| 4317 | if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\""); | |
| 4318 | const FieldType = @TypeOf(@field(encoding.config, name)); | |
| 4319 | if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType)); | |
| 4320 | } | |
| 4321 | fn checkField(name: []const u8, Type: type) void { | |
| 4322 | switch (@typeInfo(Type)) { | |
| 4323 | .int => {}, | |
| 4324 | .@"enum" => {}, | |
| 4325 | .@"struct" => |info| assert(info.layout == .@"packed"), | |
| 4326 | .optional => |info| { | |
| 4327 | checkConfig(name ++ ".?"); | |
| 4328 | checkField(name ++ ".?", info.child); | |
| 4329 | }, | |
| 4330 | .pointer => |info| { | |
| 4331 | assert(info.size == .slice); | |
| 4332 | checkConfig(name ++ ".len"); | |
| 4333 | checkField(name ++ "[0]", info.child); | |
| 4334 | }, | |
| 4335 | else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag.name ++ "." ++ name ++ ": " ++ @typeName(Type)), | |
| 4306 | .stage2_x86_64 => for (@typeInfo(Tag).@"enum".field_names) |tag_name| { | |
| 4307 | if (!@hasField(@TypeOf(Tag.encodings), tag_name)) @compileLog("missing: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name); | |
| 4308 | const encoding = @field(Tag.encodings, tag_name); | |
| 4309 | if (@hasField(@TypeOf(encoding), "trailing")) { | |
| 4310 | const trailing_info = @typeInfo(encoding.trailing).@"struct"; | |
| 4311 | for (trailing_info.field_names, trailing_info.field_types) |field_name, field_type| { | |
| 4312 | struct { | |
| 4313 | fn checkConfig(name: []const u8) void { | |
| 4314 | if (!@hasField(@TypeOf(encoding.config), name)) @compileError("missing field: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ ".config.@\"" ++ name ++ "\""); | |
| 4315 | const FieldType = @TypeOf(@field(encoding.config, name)); | |
| 4316 | if (@typeInfo(FieldType) != .enum_literal) @compileError("expected enum literal: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ ".config.@\"" ++ name ++ "\": " ++ @typeName(FieldType)); | |
| 4336 | 4317 | } |
| 4337 | } | |
| 4338 | }.checkField("trailing." ++ field.name, field.type); | |
| 4339 | }; | |
| 4318 | fn checkField(name: []const u8, Type: type) void { | |
| 4319 | switch (@typeInfo(Type)) { | |
| 4320 | .int => {}, | |
| 4321 | .@"enum" => {}, | |
| 4322 | .@"struct" => |info| assert(info.layout == .@"packed"), | |
| 4323 | .optional => |info| { | |
| 4324 | checkConfig(name ++ ".?"); | |
| 4325 | checkField(name ++ ".?", info.child); | |
| 4326 | }, | |
| 4327 | .pointer => |info| { | |
| 4328 | assert(info.size == .slice); | |
| 4329 | checkConfig(name ++ ".len"); | |
| 4330 | checkField(name ++ "[0]", info.child); | |
| 4331 | }, | |
| 4332 | else => @compileError("unsupported type: " ++ @typeName(Tag) ++ ".encodings." ++ tag_name ++ "." ++ name ++ ": " ++ @typeName(Type)), | |
| 4333 | } | |
| 4334 | } | |
| 4335 | }.checkField("trailing." ++ field_name, field_type); | |
| 4336 | } | |
| 4337 | } | |
| 4340 | 4338 | }, |
| 4341 | 4339 | else => {}, |
| 4342 | 4340 | }; |
| ... | ... | @@ -6965,7 +6963,7 @@ fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local. |
| 6965 | 6963 | const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]); |
| 6966 | 6964 | const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]); |
| 6967 | 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 | 6967 | return .{ |
| 6970 | 6968 | .tid = tid, |
| 6971 | 6969 | .ty = ty, |
| ... | ... | @@ -7305,7 +7303,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key: |
| 7305 | 7303 | const names_map = try ip.addMap(gpa, io, tid, names.len); |
| 7306 | 7304 | ip.addStringsToMap(names_map, names); |
| 7307 | 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 | 7307 | items.appendAssumeCapacity(.{ |
| 7310 | 7308 | .tag = .type_error_set, |
| 7311 | 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 | 7859 | .repeated_elem => |elem| elem, |
| 7862 | 7860 | }; |
| 7863 | 7861 | |
| 7864 | try extra.ensureUnusedCapacity(@typeInfo(Repeated).@"struct".fields.len); | |
| 7862 | try extra.ensureUnusedCapacity(@typeInfo(Repeated).@"struct".field_names.len); | |
| 7865 | 7863 | items.appendAssumeCapacity(.{ |
| 7866 | 7864 | .tag = .repeated, |
| 7867 | 7865 | .data = addExtraAssumeCapacity(extra, Repeated{ |
| ... | ... | @@ -7876,7 +7874,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key: |
| 7876 | 7874 | const string_bytes = ip.getLocal(tid).getMutableStringBytes(gpa, io); |
| 7877 | 7875 | const start = string_bytes.mutate.len; |
| 7878 | 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 | 7878 | switch (aggregate.storage) { |
| 7881 | 7879 | .bytes => |bytes| string_bytes.appendSliceAssumeCapacity(.{bytes.toSlice(len, ip)}), |
| 7882 | 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 | 7915 | } |
| 7918 | 7916 | |
| 7919 | 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 | 7920 | items.appendAssumeCapacity(.{ |
| 7923 | 7921 | .tag = .aggregate, |
| ... | ... | @@ -7943,7 +7941,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerThread.Id, key: |
| 7943 | 7941 | |
| 7944 | 7942 | .memoized_call => |memoized_call| { |
| 7945 | 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 | 7945 | memoized_call.arg_values.len); |
| 7948 | 7946 | items.appendAssumeCapacity(.{ |
| 7949 | 7947 | .tag = .memoized_call, |
| ... | ... | @@ -8006,7 +8004,7 @@ pub fn getDeclaredStructType( |
| 8006 | 8004 | .auto => false, |
| 8007 | 8005 | .@"extern" => true, |
| 8008 | 8006 | .@"packed" => { |
| 8009 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".fields.len + | |
| 8007 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".field_names.len + | |
| 8010 | 8008 | ini.captures.len + // capture |
| 8011 | 8009 | ini.fields_len + // field_name |
| 8012 | 8010 | ini.fields_len + // field_type |
| ... | ... | @@ -8053,7 +8051,7 @@ pub fn getDeclaredStructType( |
| 8053 | 8051 | }, |
| 8054 | 8052 | }; |
| 8055 | 8053 | |
| 8056 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".fields.len + | |
| 8054 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".field_names.len + | |
| 8057 | 8055 | 1 + // captures_len |
| 8058 | 8056 | ini.captures.len + // capture |
| 8059 | 8057 | ini.fields_len + // field_name |
| ... | ... | @@ -8150,7 +8148,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe |
| 8150 | 8148 | .auto => false, |
| 8151 | 8149 | .@"extern" => true, |
| 8152 | 8150 | .@"packed" => { |
| 8153 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".fields.len + | |
| 8151 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStructPacked).@"struct".field_names.len + | |
| 8154 | 8152 | 2 + // type_hash |
| 8155 | 8153 | ini.fields_len + // field_name |
| 8156 | 8154 | ini.fields_len + // field_type |
| ... | ... | @@ -8203,7 +8201,7 @@ pub fn getReifiedStructType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Pe |
| 8203 | 8201 | }, |
| 8204 | 8202 | }; |
| 8205 | 8203 | |
| 8206 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".fields.len + | |
| 8204 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeStruct).@"struct".field_names.len + | |
| 8207 | 8205 | 2 + // type_hash |
| 8208 | 8206 | ini.fields_len + // field_name |
| 8209 | 8207 | ini.fields_len + // field_type |
| ... | ... | @@ -8323,7 +8321,7 @@ pub fn getDeclaredUnionType( |
| 8323 | 8321 | .auto => false, |
| 8324 | 8322 | .@"extern" => true, |
| 8325 | 8323 | .@"packed" => { |
| 8326 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".fields.len + | |
| 8324 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len + | |
| 8327 | 8325 | ini.captures.len + // capture |
| 8328 | 8326 | ini.fields_len); // field_type |
| 8329 | 8327 | |
| ... | ... | @@ -8364,7 +8362,7 @@ pub fn getDeclaredUnionType( |
| 8364 | 8362 | }, |
| 8365 | 8363 | }; |
| 8366 | 8364 | |
| 8367 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".fields.len + | |
| 8365 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".field_names.len + | |
| 8368 | 8366 | 1 + // captures_len |
| 8369 | 8367 | ini.captures.len + // capture |
| 8370 | 8368 | ini.fields_len + // field_type |
| ... | ... | @@ -8445,7 +8443,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per |
| 8445 | 8443 | .auto => false, |
| 8446 | 8444 | .@"extern" => true, |
| 8447 | 8445 | .@"packed" => { |
| 8448 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".fields.len + | |
| 8446 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnionPacked).@"struct".field_names.len + | |
| 8449 | 8447 | 2 + // type_hash |
| 8450 | 8448 | ini.fields_len + // reified_field_name |
| 8451 | 8449 | ini.fields_len); // field_type |
| ... | ... | @@ -8490,7 +8488,7 @@ pub fn getReifiedUnionType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.Per |
| 8490 | 8488 | }, |
| 8491 | 8489 | }; |
| 8492 | 8490 | |
| 8493 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".fields.len + | |
| 8491 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeUnion).@"struct".field_names.len + | |
| 8494 | 8492 | 2 + // type_hash |
| 8495 | 8493 | ini.fields_len + // reified_field_name |
| 8496 | 8494 | ini.fields_len + // field_type |
| ... | ... | @@ -8597,7 +8595,7 @@ pub fn getDeclaredEnumType( |
| 8597 | 8595 | const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined; |
| 8598 | 8596 | errdefer local.mutate.maps.len -= @intFromBool(have_values); |
| 8599 | 8597 | |
| 8600 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".fields.len + | |
| 8598 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".field_names.len + | |
| 8601 | 8599 | 1 + // zir_index |
| 8602 | 8600 | ini.captures.len + // capture |
| 8603 | 8601 | @intFromBool(have_values) + // field_value_map |
| ... | ... | @@ -8672,7 +8670,7 @@ pub fn getReifiedEnumType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.PerT |
| 8672 | 8670 | const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined; |
| 8673 | 8671 | errdefer local.mutate.maps.len -= @intFromBool(have_values); |
| 8674 | 8672 | |
| 8675 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".fields.len + | |
| 8673 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".field_names.len + | |
| 8676 | 8674 | 1 + // zir_index |
| 8677 | 8675 | 2 + // type_hash |
| 8678 | 8676 | @intFromBool(have_values) + // field_value_map |
| ... | ... | @@ -8746,7 +8744,7 @@ pub fn getGeneratedEnumTagType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu |
| 8746 | 8744 | const field_value_map = if (have_values) try ip.addMap(gpa, io, tid, ini.fields_len) else undefined; |
| 8747 | 8745 | errdefer local.mutate.maps.len -= @intFromBool(have_values); |
| 8748 | 8746 | |
| 8749 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".fields.len + | |
| 8747 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeEnum).@"struct".field_names.len + | |
| 8750 | 8748 | 1 + // owner_union |
| 8751 | 8749 | @intFromBool(have_values) + // field_value_map |
| 8752 | 8750 | ini.fields_len + // field_name |
| ... | ... | @@ -8805,7 +8803,7 @@ pub fn getDeclaredOpaqueType(ip: *InternPool, gpa: Allocator, io: Io, tid: Zcu.P |
| 8805 | 8803 | const extra = local.getMutableExtra(gpa, io); |
| 8806 | 8804 | try items.ensureUnusedCapacity(1); |
| 8807 | 8805 | |
| 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 | 8807 | const extra_index = addExtraAssumeCapacity(extra, Tag.TypeOpaque{ |
| 8810 | 8808 | .zir_index = ini.zir_index, |
| 8811 | 8809 | .captures_len = @intCast(ini.captures.len), |
| ... | ... | @@ -8938,7 +8936,7 @@ pub fn getTupleType( |
| 8938 | 8936 | |
| 8939 | 8937 | try items.ensureUnusedCapacity(1); |
| 8940 | 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 | ); |
| 8943 | 8941 | |
| 8944 | 8942 | const extra_index = addExtraAssumeCapacity(extra, TypeTuple{ |
| ... | ... | @@ -8996,7 +8994,7 @@ pub fn getFuncType( |
| 8996 | 8994 | const prev_extra_len = extra.mutate.len; |
| 8997 | 8995 | const params_len: u32 = @intCast(key.param_types.len); |
| 8998 | 8996 | |
| 8999 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeFunction).@"struct".fields.len + | |
| 8997 | try extra.ensureUnusedCapacity(@typeInfo(Tag.TypeFunction).@"struct".field_names.len + | |
| 9000 | 8998 | @intFromBool(key.comptime_bits != 0) + |
| 9001 | 8999 | @intFromBool(key.noalias_bits != 0) + |
| 9002 | 9000 | params_len); |
| ... | ... | @@ -9059,7 +9057,7 @@ pub fn getExtern( |
| 9059 | 9057 | const items = local.getMutableItems(gpa, io); |
| 9060 | 9058 | const extra = local.getMutableExtra(gpa, io); |
| 9061 | 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 | 9061 | try local.getMutableNavs(gpa, io).ensureUnusedCapacity(1); |
| 9064 | 9062 | |
| 9065 | 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 | 9136 | // arrays. This is similar to what `getOrPutTrailingString` does. |
| 9139 | 9137 | const prev_extra_len = extra.mutate.len; |
| 9140 | 9138 | |
| 9141 | try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".fields.len); | |
| 9139 | try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".field_names.len); | |
| 9142 | 9140 | |
| 9143 | 9141 | const func_decl_extra_index = addExtraAssumeCapacity(extra, Tag.FuncDecl{ |
| 9144 | 9142 | .analysis = .{ |
| ... | ... | @@ -9225,10 +9223,10 @@ pub fn getFuncDeclIes( |
| 9225 | 9223 | const prev_extra_len = extra.mutate.len; |
| 9226 | 9224 | const params_len: u32 = @intCast(key.param_types.len); |
| 9227 | 9225 | |
| 9228 | try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".fields.len + | |
| 9226 | try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncDecl).@"struct".field_names.len + | |
| 9229 | 9227 | 1 + // inferred_error_set |
| 9230 | @typeInfo(Tag.ErrorUnionType).@"struct".fields.len + | |
| 9231 | @typeInfo(Tag.TypeFunction).@"struct".fields.len + | |
| 9228 | @typeInfo(Tag.ErrorUnionType).@"struct".field_names.len + | |
| 9229 | @typeInfo(Tag.TypeFunction).@"struct".field_names.len + | |
| 9232 | 9230 | @intFromBool(key.comptime_bits != 0) + |
| 9233 | 9231 | @intFromBool(key.noalias_bits != 0) + |
| 9234 | 9232 | params_len); |
| ... | ... | @@ -9364,7 +9362,7 @@ pub fn getErrorSetType( |
| 9364 | 9362 | const local = ip.getLocal(tid); |
| 9365 | 9363 | const items = local.getMutableItems(gpa, io); |
| 9366 | 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); | |
| 9368 | 9366 | |
| 9369 | 9367 | const names_map = try ip.addMap(gpa, io, tid, names.len); |
| 9370 | 9368 | errdefer local.mutate.maps.len -= 1; |
| ... | ... | @@ -9440,7 +9438,7 @@ pub fn getFuncInstance( |
| 9440 | 9438 | const local = ip.getLocal(tid); |
| 9441 | 9439 | const items = local.getMutableItems(gpa, io); |
| 9442 | 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 | 9442 | arg.comptime_args.len); |
| 9445 | 9443 | |
| 9446 | 9444 | assert(arg.comptime_args.len == ip.funcTypeParamsLen(ip.typeOf(generic_owner))); |
| ... | ... | @@ -9524,11 +9522,11 @@ fn getFuncInstanceIes( |
| 9524 | 9522 | const prev_extra_len = extra.mutate.len; |
| 9525 | 9523 | const params_len: u32 = @intCast(arg.param_types.len); |
| 9526 | 9524 | |
| 9527 | try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".fields.len + | |
| 9525 | try extra.ensureUnusedCapacity(@typeInfo(Tag.FuncInstance).@"struct".field_names.len + | |
| 9528 | 9526 | 1 + // inferred_error_set |
| 9529 | 9527 | arg.comptime_args.len + |
| 9530 | @typeInfo(Tag.ErrorUnionType).@"struct".fields.len + | |
| 9531 | @typeInfo(Tag.TypeFunction).@"struct".fields.len + | |
| 9528 | @typeInfo(Tag.ErrorUnionType).@"struct".field_names.len + | |
| 9529 | @typeInfo(Tag.TypeFunction).@"struct".field_names.len + | |
| 9532 | 9530 | @intFromBool(arg.noalias_bits != 0) + |
| 9533 | 9531 | params_len); |
| 9534 | 9532 | |
| ... | ... | @@ -9774,15 +9772,16 @@ fn addInt( |
| 9774 | 9772 | } |
| 9775 | 9773 | |
| 9776 | 9774 | fn addExtra(extra: Local.Extra.Mutable, item: anytype) Allocator.Error!u32 { |
| 9777 | const fields = @typeInfo(@TypeOf(item)).@"struct".fields; | |
| 9778 | try extra.ensureUnusedCapacity(fields.len); | |
| 9775 | const field_count = @typeInfo(@TypeOf(item)).@"struct".field_names.len; | |
| 9776 | try extra.ensureUnusedCapacity(field_count); | |
| 9779 | 9777 | return addExtraAssumeCapacity(extra, item); |
| 9780 | 9778 | } |
| 9781 | 9779 | |
| 9782 | 9780 | fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 { |
| 9783 | 9781 | const result: u32 = extra.mutate.len; |
| 9784 | inline for (@typeInfo(@TypeOf(item)).@"struct".fields) |field| { | |
| 9785 | extra.appendAssumeCapacity(.{switch (field.type) { | |
| 9782 | const info = @typeInfo(@TypeOf(item)).@"struct"; | |
| 9783 | inline for (info.field_types, info.field_names) |field_type, field_name| { | |
| 9784 | extra.appendAssumeCapacity(.{switch (field_type) { | |
| 9786 | 9785 | Index, |
| 9787 | 9786 | Nav.Index, |
| 9788 | 9787 | Nav.Index.Optional, |
| ... | ... | @@ -9797,7 +9796,7 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 { |
| 9797 | 9796 | TrackedInst.Index, |
| 9798 | 9797 | TrackedInst.Index.Optional, |
| 9799 | 9798 | ComptimeAllocIndex, |
| 9800 | => @intFromEnum(@field(item, field.name)), | |
| 9799 | => @intFromEnum(@field(item, field_name)), | |
| 9801 | 9800 | |
| 9802 | 9801 | u32, |
| 9803 | 9802 | i32, |
| ... | ... | @@ -9811,9 +9810,9 @@ fn addExtraAssumeCapacity(extra: Local.Extra.Mutable, item: anytype) u32 { |
| 9811 | 9810 | Tag.TypeStructPacked.Bits, |
| 9812 | 9811 | Tag.TypeUnionPacked.Bits, |
| 9813 | 9812 | Tag.TypeEnum.Bits, |
| 9814 | => @bitCast(@field(item, field.name)), | |
| 9813 | => @bitCast(@field(item, field_name)), | |
| 9815 | 9814 | |
| 9816 | else => @compileError("bad field type: " ++ @typeName(field.type)), | |
| 9815 | else => @compileError("bad field type: " ++ @typeName(field_type)), | |
| 9817 | 9816 | }}); |
| 9818 | 9817 | } |
| 9819 | 9818 | return result; |
| ... | ... | @@ -9826,11 +9825,12 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 9826 | 9825 | else => @compileError("unsupported host"), |
| 9827 | 9826 | } |
| 9828 | 9827 | const result: u32 = @intCast(ip.limbs.items.len); |
| 9829 | inline for (@typeInfo(@TypeOf(extra)).@"struct".fields, 0..) |field, i| { | |
| 9830 | const new: u32 = switch (field.type) { | |
| 9831 | u32 => @field(extra, field.name), | |
| 9832 | Index => @intFromEnum(@field(extra, field.name)), | |
| 9833 | else => @compileError("bad field type: " ++ @typeName(field.type)), | |
| 9828 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 9829 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 9830 | const new: u32 = switch (field_type) { | |
| 9831 | u32 => @field(extra, field_name), | |
| 9832 | Index => @intFromEnum(@field(extra, field_name)), | |
| 9833 | else => @compileError("bad field type: " ++ @typeName(field_type)), | |
| 9834 | 9834 | }; |
| 9835 | 9835 | if (i % 2 == 0) { |
| 9836 | 9836 | ip.limbs.appendAssumeCapacity(new); |
| ... | ... | @@ -9844,10 +9844,11 @@ fn addLimbsExtraAssumeCapacity(ip: *InternPool, extra: anytype) u32 { |
| 9844 | 9844 | fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { data: T, end: u32 } { |
| 9845 | 9845 | const extra_items = extra.view().items(.@"0"); |
| 9846 | 9846 | var result: T = undefined; |
| 9847 | const fields = @typeInfo(T).@"struct".fields; | |
| 9848 | inline for (fields, index..) |field, extra_index| { | |
| 9847 | const field_names = @typeInfo(T).@"struct".field_names; | |
| 9848 | const field_types = @typeInfo(T).@"struct".field_types; | |
| 9849 | inline for (field_names, field_types, index..) |field_name, field_type, extra_index| { | |
| 9849 | 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 | 9852 | Index, |
| 9852 | 9853 | Nav.Index, |
| 9853 | 9854 | Nav.Index.Optional, |
| ... | ... | @@ -9878,12 +9879,12 @@ fn extraDataTrail(extra: Local.Extra, comptime T: type, index: u32) struct { dat |
| 9878 | 9879 | Tag.TypeEnum.Bits, |
| 9879 | 9880 | => @bitCast(extra_item), |
| 9880 | 9881 | |
| 9881 | else => @compileError("bad field type: " ++ @typeName(field.type)), | |
| 9882 | else => @compileError("bad field type: " ++ @typeName(field_type)), | |
| 9882 | 9883 | }; |
| 9883 | 9884 | } |
| 9884 | 9885 | return .{ |
| 9885 | 9886 | .data = result, |
| 9886 | .end = @intCast(index + fields.len), | |
| 9887 | .end = @intCast(index + field_names.len), | |
| 9887 | 9888 | }; |
| 9888 | 9889 | } |
| 9889 | 9890 | |
| ... | ... | @@ -10311,7 +10312,7 @@ fn getCoercedFunc( |
| 10311 | 10312 | const extra = local.getMutableExtra(gpa, io); |
| 10312 | 10313 | |
| 10313 | 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); | |
| 10315 | 10316 | |
| 10316 | 10317 | const extra_index = addExtraAssumeCapacity(extra, Tag.FuncCoerced{ |
| 10317 | 10318 | .ty = ty, |
| ... | ... | @@ -10601,7 +10602,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10601 | 10602 | }, |
| 10602 | 10603 | |
| 10603 | 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 | 10606 | const extra = extraDataTrail(extra_list, Tag.TypeStruct, data); |
| 10606 | 10607 | switch (extra.data.flags.any_captures) { |
| 10607 | 10608 | .reified => n += 2, // type_hash: PackedU64 |
| ... | ... | @@ -10629,7 +10630,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10629 | 10630 | break :b n * @sizeOf(u32); |
| 10630 | 10631 | }, |
| 10631 | 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 | 10634 | const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data); |
| 10634 | 10635 | switch (extra.data.bits.captures_len) { |
| 10635 | 10636 | .reified => n += 2, // type_hash: PackedU64 |
| ... | ... | @@ -10640,7 +10641,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10640 | 10641 | break :b n * @sizeOf(u32); |
| 10641 | 10642 | }, |
| 10642 | 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 | 10645 | const extra = extraDataTrail(extra_list, Tag.TypeStructPacked, data); |
| 10645 | 10646 | switch (extra.data.bits.captures_len) { |
| 10646 | 10647 | .reified => n += 2, // type_hash: PackedU64 |
| ... | ... | @@ -10652,7 +10653,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10652 | 10653 | break :b n * @sizeOf(u32); |
| 10653 | 10654 | }, |
| 10654 | 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 | 10657 | const extra = extraDataTrail(extra_list, Tag.TypeUnion, data); |
| 10657 | 10658 | switch (extra.data.flags.any_captures) { |
| 10658 | 10659 | .reified => n += 2, // type_hash: PackedU64 |
| ... | ... | @@ -10669,7 +10670,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10669 | 10670 | break :b n * @sizeOf(u32); |
| 10670 | 10671 | }, |
| 10671 | 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 | 10674 | const extra = extraDataTrail(extra_list, Tag.TypeUnionPacked, data); |
| 10674 | 10675 | switch (extra.data.bits.captures_len) { |
| 10675 | 10676 | .reified => n += 2, // type_hash: PackedU64 |
| ... | ... | @@ -10679,7 +10680,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10679 | 10680 | break :b n * @sizeOf(u32); |
| 10680 | 10681 | }, |
| 10681 | 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 | 10684 | const extra = extraData(extra_list, Tag.TypeEnum, data); |
| 10684 | 10685 | switch (extra.bits.captures_len) { |
| 10685 | 10686 | .generated_union_tag => n += 1, // owner_union: Index |
| ... | ... | @@ -10696,7 +10697,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10696 | 10697 | break :b n * @sizeOf(u32); |
| 10697 | 10698 | }, |
| 10698 | 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 | 10701 | const extra = extraData(extra_list, Tag.TypeEnum, data); |
| 10701 | 10702 | switch (extra.bits.captures_len) { |
| 10702 | 10703 | .generated_union_tag => n += 1, // owner_union: Index |
| ... | ... | @@ -10715,7 +10716,7 @@ fn dumpStatsFallible(ip: *const InternPool, w: *Io.Writer, arena: Allocator) !vo |
| 10715 | 10716 | break :b n * @sizeOf(u32); |
| 10716 | 10717 | }, |
| 10717 | 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 | 10720 | const extra = extraData(extra_list, Tag.TypeOpaque, data); |
| 10720 | 10721 | n += extra.captures_len; // capture: CaptureValue |
| 10721 | 10722 | break :b n * @sizeOf(u32); |
| ... | ... | @@ -12131,8 +12132,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index { |
| 12131 | 12132 | const func_extra = unwrapped_func.getExtra(ip); |
| 12132 | 12133 | const func_item = unwrapped_func.getItem(ip); |
| 12133 | 12134 | const extra_index = switch (func_item.tag) { |
| 12134 | .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).@"struct".fields.len, | |
| 12135 | .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).@"struct".fields.len, | |
| 12135 | .func_decl => func_item.data + @typeInfo(Tag.FuncDecl).@"struct".field_names.len, | |
| 12136 | .func_instance => func_item.data + @typeInfo(Tag.FuncInstance).@"struct".field_names.len, | |
| 12136 | 12137 | .func_coerced => { |
| 12137 | 12138 | const uncoerced_func_index: Index = @enumFromInt(func_extra.view().items(.@"0")[ |
| 12138 | 12139 | func_item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").? |
| ... | ... | @@ -12141,8 +12142,8 @@ fn funcIesResolvedPtr(ip: *const InternPool, func_index: Index) *Index { |
| 12141 | 12142 | const uncoerced_func_item = unwrapped_uncoerced_func.getItem(ip); |
| 12142 | 12143 | return @ptrCast(&unwrapped_uncoerced_func.getExtra(ip).view().items(.@"0")[ |
| 12143 | 12144 | switch (uncoerced_func_item.tag) { |
| 12144 | .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).@"struct".fields.len, | |
| 12145 | .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).@"struct".fields.len, | |
| 12145 | .func_decl => uncoerced_func_item.data + @typeInfo(Tag.FuncDecl).@"struct".field_names.len, | |
| 12146 | .func_instance => uncoerced_func_item.data + @typeInfo(Tag.FuncInstance).@"struct".field_names.len, | |
| 12146 | 12147 | else => unreachable, |
| 12147 | 12148 | } |
| 12148 | 12149 | ]); |
src/Sema.zig+462-214| ... | ... | @@ -2822,6 +2822,17 @@ fn interpretStdLangType( |
| 2822 | 2822 | }; |
| 2823 | 2823 | } |
| 2824 | 2824 | |
| 2825 | fn uninterpretStdLangType( | |
| 2826 | sema: *Sema, | |
| 2827 | val: anytype, | |
| 2828 | ty: Type, | |
| 2829 | ) !Value { | |
| 2830 | return Value.uninterpret(val, ty, sema.pt) catch |err| switch (err) { | |
| 2831 | error.OutOfMemory => |e| return e, | |
| 2832 | error.TypeMismatch => @panic("std.lang is corrupt"), | |
| 2833 | }; | |
| 2834 | } | |
| 2835 | ||
| 2825 | 2836 | fn zirTupleDecl( |
| 2826 | 2837 | sema: *Sema, |
| 2827 | 2838 | block: *Block, |
| ... | ... | @@ -3934,7 +3945,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3934 | 3945 | _ = try replacement_block.addBr(placeholder_inst, .void_value); |
| 3935 | 3946 | try sema.air_extra.ensureUnusedCapacity( |
| 3936 | 3947 | gpa, |
| 3937 | @typeInfo(Air.Block).@"struct".fields.len + replacement_block.instructions.items.len, | |
| 3948 | @typeInfo(Air.Block).@"struct".field_names.len + replacement_block.instructions.items.len, | |
| 3938 | 3949 | ); |
| 3939 | 3950 | sema.air_instructions.set(@intFromEnum(placeholder_inst), .{ |
| 3940 | 3951 | .tag = .block, |
| ... | ... | @@ -5175,7 +5186,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5175 | 5186 | |
| 5176 | 5187 | try child_block.instructions.append(gpa, loop_inst); |
| 5177 | 5188 | |
| 5178 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + loop_block_len + 1); | |
| 5189 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + loop_block_len + 1); | |
| 5179 | 5190 | sema.air_instructions.items(.data)[@intFromEnum(loop_inst)].ty_pl.payload = sema.addExtraAssumeCapacity( |
| 5180 | 5191 | Air.Block{ .body_len = @intCast(loop_block_len + 1) }, |
| 5181 | 5192 | ); |
| ... | ... | @@ -5274,7 +5285,7 @@ fn resolveBlockBody( |
| 5274 | 5285 | // We need a runtime block for scoping reasons. |
| 5275 | 5286 | _ = try child_block.addBr(merges.block_inst, .void_value); |
| 5276 | 5287 | try parent_block.instructions.append(sema.gpa, merges.block_inst); |
| 5277 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 5288 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 5278 | 5289 | child_block.instructions.items.len); |
| 5279 | 5290 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ |
| 5280 | 5291 | .ty = .void_type, |
| ... | ... | @@ -5350,7 +5361,7 @@ fn resolveAnalyzedBlock( |
| 5350 | 5361 | .dbg_inline_block => { |
| 5351 | 5362 | // Create a block containing all instruction from the body. |
| 5352 | 5363 | try parent_block.instructions.append(gpa, merges.block_inst); |
| 5353 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".fields.len + | |
| 5364 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".field_names.len + | |
| 5354 | 5365 | child_block.instructions.items.len); |
| 5355 | 5366 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ |
| 5356 | 5367 | .ty = .noreturn_type, |
| ... | ... | @@ -5388,7 +5399,7 @@ fn resolveAnalyzedBlock( |
| 5388 | 5399 | try parent_block.instructions.append(gpa, merges.block_inst); |
| 5389 | 5400 | switch (block_tag) { |
| 5390 | 5401 | .block => { |
| 5391 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 5402 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 5392 | 5403 | child_block.instructions.items.len); |
| 5393 | 5404 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ |
| 5394 | 5405 | .ty = .void_type, |
| ... | ... | @@ -5398,7 +5409,7 @@ fn resolveAnalyzedBlock( |
| 5398 | 5409 | } }; |
| 5399 | 5410 | }, |
| 5400 | 5411 | .dbg_inline_block => { |
| 5401 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".fields.len + | |
| 5412 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".field_names.len + | |
| 5402 | 5413 | child_block.instructions.items.len); |
| 5403 | 5414 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ |
| 5404 | 5415 | .ty = .void_type, |
| ... | ... | @@ -5453,7 +5464,7 @@ fn resolveAnalyzedBlock( |
| 5453 | 5464 | const ty_inst = Air.internedToRef(resolved_ty.toIntern()); |
| 5454 | 5465 | switch (block_tag) { |
| 5455 | 5466 | .block => { |
| 5456 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 5467 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 5457 | 5468 | child_block.instructions.items.len); |
| 5458 | 5469 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ |
| 5459 | 5470 | .ty = ty_inst, |
| ... | ... | @@ -5463,7 +5474,7 @@ fn resolveAnalyzedBlock( |
| 5463 | 5474 | } }; |
| 5464 | 5475 | }, |
| 5465 | 5476 | .dbg_inline_block => { |
| 5466 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".fields.len + | |
| 5477 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.DbgInlineBlock).@"struct".field_names.len + | |
| 5467 | 5478 | child_block.instructions.items.len); |
| 5468 | 5479 | sema.air_instructions.items(.data)[@intFromEnum(merges.block_inst)] = .{ .ty_pl = .{ |
| 5469 | 5480 | .ty = ty_inst, |
| ... | ... | @@ -5500,7 +5511,7 @@ fn resolveAnalyzedBlock( |
| 5500 | 5511 | // Convert the br instruction to a block instruction that has the coercion |
| 5501 | 5512 | // and then a new br inside that returns the coerced instruction. |
| 5502 | 5513 | const sub_block_len: u32 = @intCast(coerce_block.instructions.items.len + 1); |
| 5503 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 5514 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 5504 | 5515 | sub_block_len); |
| 5505 | 5516 | try sema.air_instructions.ensureUnusedCapacity(gpa, 1); |
| 5506 | 5517 | const sub_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); |
| ... | ... | @@ -6061,7 +6072,7 @@ fn popErrorReturnTrace( |
| 6061 | 6072 | // The result might be an error. If it is, we leave the error trace alone. If it isn't, we need |
| 6062 | 6073 | // to pop any error trace that may have been propagated from our arguments. |
| 6063 | 6074 | |
| 6064 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len); | |
| 6075 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len); | |
| 6065 | 6076 | const cond_block_inst = try block.addInstAsIndex(.{ |
| 6066 | 6077 | .tag = .block, |
| 6067 | 6078 | .data = .{ |
| ... | ... | @@ -6089,9 +6100,9 @@ fn popErrorReturnTrace( |
| 6089 | 6100 | defer else_block.instructions.deinit(gpa); |
| 6090 | 6101 | _ = try else_block.addBr(cond_block_inst, .void_value); |
| 6091 | 6102 | |
| 6092 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len + | |
| 6103 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len + | |
| 6093 | 6104 | then_block.instructions.items.len + else_block.instructions.items.len + |
| 6094 | @typeInfo(Air.Block).@"struct".fields.len + 1); // +1 for the sole .cond_br instruction in the .block | |
| 6105 | @typeInfo(Air.Block).@"struct".field_names.len + 1); // +1 for the sole .cond_br instruction in the .block | |
| 6095 | 6106 | |
| 6096 | 6107 | const cond_br_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); |
| 6097 | 6108 | try sema.air_instructions.append(gpa, .{ |
| ... | ... | @@ -7008,7 +7019,7 @@ fn analyzeCall( |
| 7008 | 7019 | => unreachable, |
| 7009 | 7020 | }; |
| 7010 | 7021 | |
| 7011 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Call).@"struct".fields.len + runtime_args.len); | |
| 7022 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Call).@"struct".field_names.len + runtime_args.len); | |
| 7012 | 7023 | const call_ref = try block.addInst(.{ |
| 7013 | 7024 | .tag = call_tag, |
| 7014 | 7025 | .data = .{ .pl_op = .{ |
| ... | ... | @@ -9958,7 +9969,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 9958 | 9969 | } |
| 9959 | 9970 | } |
| 9960 | 9971 | |
| 9961 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len + | |
| 9972 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len + | |
| 9962 | 9973 | non_err_block.instructions.items.len + switch_block.instructions.items.len); |
| 9963 | 9974 | const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 9964 | 9975 | .then_body_len = @intCast(non_err_block.instructions.items.len), |
| ... | ... | @@ -10314,7 +10325,7 @@ fn analyzeSwitchBlock( |
| 10314 | 10325 | _ = try sema.analyzeBodyRuntimeBreak(&case_block, body); |
| 10315 | 10326 | } |
| 10316 | 10327 | |
| 10317 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 10328 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 10318 | 10329 | case_block.instructions.items.len); |
| 10319 | 10330 | const payload_index = sema.addExtraAssumeCapacity(Air.Block{ |
| 10320 | 10331 | .body_len = @intCast(case_block.instructions.items.len), |
| ... | ... | @@ -10405,7 +10416,7 @@ fn analyzeSwitchBlock( |
| 10405 | 10416 | |
| 10406 | 10417 | // Replace placeholder with a block. |
| 10407 | 10418 | // No `br` is needed as the block is a switch dispatch so necessarily `noreturn`. |
| 10408 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 10419 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 10409 | 10420 | replacement_block.instructions.items.len); |
| 10410 | 10421 | sema.air_instructions.set(@intFromEnum(placeholder_inst), .{ |
| 10411 | 10422 | .tag = .block, |
| ... | ... | @@ -10508,7 +10519,7 @@ fn finishSwitchBr( |
| 10508 | 10519 | defer branch_hints.bags.deinit(gpa); |
| 10509 | 10520 | |
| 10510 | 10521 | var cases_extra: std.ArrayList(u32) = try .initCapacity(gpa, estimated_cases_len * |
| 10511 | @typeInfo(Air.SwitchBr.Case).@"struct".fields.len); | |
| 10522 | @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len); | |
| 10512 | 10523 | defer cases_extra.deinit(gpa); |
| 10513 | 10524 | |
| 10514 | 10525 | // We will reuse this block for each case. |
| ... | ... | @@ -10598,7 +10609,7 @@ fn finishSwitchBr( |
| 10598 | 10609 | }; |
| 10599 | 10610 | branch_hints.appendAssumeCapacity(prong_hint); |
| 10600 | 10611 | |
| 10601 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len + | |
| 10612 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len + | |
| 10602 | 10613 | 1 + // `item`, no ranges |
| 10603 | 10614 | case_block.instructions.items.len); |
| 10604 | 10615 | cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{ |
| ... | ... | @@ -10685,7 +10696,7 @@ fn finishSwitchBr( |
| 10685 | 10696 | ); |
| 10686 | 10697 | try branch_hints.append(gpa, prong_hint); |
| 10687 | 10698 | |
| 10688 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len + | |
| 10699 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len + | |
| 10689 | 10700 | 1 + // `item`, no ranges |
| 10690 | 10701 | case_block.instructions.items.len); |
| 10691 | 10702 | cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{ |
| ... | ... | @@ -10741,7 +10752,7 @@ fn finishSwitchBr( |
| 10741 | 10752 | }; |
| 10742 | 10753 | try branch_hints.append(gpa, prong_hint); |
| 10743 | 10754 | |
| 10744 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len + | |
| 10755 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len + | |
| 10745 | 10756 | item_refs.len + |
| 10746 | 10757 | 2 * range_refs.len + |
| 10747 | 10758 | case_block.instructions.items.len); |
| ... | ... | @@ -10828,7 +10839,7 @@ fn finishSwitchBr( |
| 10828 | 10839 | }; |
| 10829 | 10840 | try branch_hints.append(gpa, prong_hint); |
| 10830 | 10841 | |
| 10831 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len + | |
| 10842 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len + | |
| 10832 | 10843 | 1 + // `item`, no ranges |
| 10833 | 10844 | case_block.instructions.items.len); |
| 10834 | 10845 | cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{ |
| ... | ... | @@ -10888,11 +10899,11 @@ fn finishSwitchBr( |
| 10888 | 10899 | }; |
| 10889 | 10900 | try branch_hints.append(gpa, prong_hint); |
| 10890 | 10901 | |
| 10891 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".fields.len + | |
| 10902 | try cases_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len + | |
| 10892 | 10903 | (validated_switch.seen_enum_fields.len + 1 - zir_switch.totalItemsLen()) + // +1 because totalItemsLen includes the _ |
| 10893 | 10904 | case_block.instructions.items.len); |
| 10894 | 10905 | const extra_case = cases_extra.addManyAsArrayAssumeCapacity( |
| 10895 | @typeInfo(Air.SwitchBr.Case).@"struct".fields.len, | |
| 10906 | @typeInfo(Air.SwitchBr.Case).@"struct".field_names.len, | |
| 10896 | 10907 | ); |
| 10897 | 10908 | var items_len: u32 = 0; |
| 10898 | 10909 | for (validated_switch.seen_enum_fields, 0..) |seen_field, field_i| { |
| ... | ... | @@ -10985,7 +10996,7 @@ fn finishSwitchBr( |
| 10985 | 10996 | |
| 10986 | 10997 | assert(branch_hints.count == cases_len + 1); // +1 for catch-all hint |
| 10987 | 10998 | |
| 10988 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr).@"struct".fields.len + | |
| 10999 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.SwitchBr).@"struct".field_names.len + | |
| 10989 | 11000 | branch_hints.bags.items.len + |
| 10990 | 11001 | cases_extra.items.len + |
| 10991 | 11002 | catch_all_extra.len); |
| ... | ... | @@ -12356,7 +12367,7 @@ fn analyzeSwitchPayloadCapture( |
| 12356 | 12367 | const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); |
| 12357 | 12368 | _ = try coerce_block.addBr(capture_block_inst, coerced); |
| 12358 | 12369 | |
| 12359 | try cases_extra.ensureUnusedCapacity(@typeInfo(Air.SwitchBr.Case).@"struct".fields.len + | |
| 12370 | try cases_extra.ensureUnusedCapacity(@typeInfo(Air.SwitchBr.Case).@"struct".field_names.len + | |
| 12360 | 12371 | 1 + // `item`, no ranges |
| 12361 | 12372 | coerce_block.instructions.items.len); |
| 12362 | 12373 | cases_extra.appendSliceAssumeCapacity(&payloadToExtraItems(Air.SwitchBr.Case{ |
| ... | ... | @@ -12384,9 +12395,9 @@ fn analyzeSwitchPayloadCapture( |
| 12384 | 12395 | break :len coerce_block.instructions.items.len; |
| 12385 | 12396 | }; |
| 12386 | 12397 | |
| 12387 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.SwitchBr).@"struct".fields.len + | |
| 12398 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.SwitchBr).@"struct".field_names.len + | |
| 12388 | 12399 | cases_extra.items.len + |
| 12389 | @typeInfo(Air.Block).@"struct".fields.len + | |
| 12400 | @typeInfo(Air.Block).@"struct".field_names.len + | |
| 12390 | 12401 | 1); |
| 12391 | 12402 | |
| 12392 | 12403 | const switch_br_inst: u32 = @intCast(sema.air_instructions.len); |
| ... | ... | @@ -15226,7 +15237,7 @@ fn zirAsm( |
| 15226 | 15237 | |
| 15227 | 15238 | var extra_i = extra.end; |
| 15228 | 15239 | var output_type_bits = extra.data.output_type_bits; |
| 15229 | var needed_capacity: usize = @typeInfo(Air.Asm).@"struct".fields.len + outputs_len + inputs_len; | |
| 15240 | var needed_capacity: usize = @typeInfo(Air.Asm).@"struct".field_names.len + outputs_len + inputs_len; | |
| 15230 | 15241 | |
| 15231 | 15242 | const ConstraintName = struct { c: []const u8, n: []const u8 }; |
| 15232 | 15243 | const out_args = try sema.arena.alloc(Air.Inst.Ref, outputs_len); |
| ... | ... | @@ -15988,13 +15999,19 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15988 | 15999 | |
| 15989 | 16000 | .@"fn" => { |
| 15990 | 16001 | const fn_info_ty = try sema.getStdLangType(src, .@"Type.Fn"); |
| 15991 | const param_info_ty = try sema.getStdLangType(src, .@"Type.Fn.Param"); | |
| 16002 | const param_attrs_ty = try sema.getStdLangType(src, .@"Type.Fn.ParamAttributes"); | |
| 16003 | const fn_attr_ty = try sema.getStdLangType(src, .@"Type.Fn.Attributes"); | |
| 15992 | 16004 | |
| 15993 | 16005 | const func_ty_info = zcu.typeToFunc(ty).?; |
| 15994 | const param_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); | |
| 16006 | const param_type_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); | |
| 16007 | const param_attr_vals = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len); | |
| 15995 | 16008 | var func_is_generic = false; |
| 15996 | 16009 | |
| 15997 | for (param_vals, 0..) |*param_val, param_index| { | |
| 16010 | for ( | |
| 16011 | param_type_vals, | |
| 16012 | param_attr_vals, | |
| 16013 | 0.., | |
| 16014 | ) |*param_type_val, *param_attr_val, param_index| { | |
| 15998 | 16015 | const param_ty = func_ty_info.param_types.get(ip)[param_index]; |
| 15999 | 16016 | const is_generic = param_ty == .generic_poison_type; |
| 16000 | 16017 | const is_noalias, const is_comptime = flags: { |
| ... | ... | @@ -16011,25 +16028,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16011 | 16028 | .val = if (is_generic) .none else param_ty, |
| 16012 | 16029 | } }); |
| 16013 | 16030 | |
| 16014 | const param_fields = .{ | |
| 16015 | // is_generic: bool, | |
| 16016 | Value.makeBool(is_generic).toIntern(), | |
| 16017 | // is_noalias: bool, | |
| 16031 | const param_attrs_fields = .{ | |
| 16032 | // @"noalias": bool, | |
| 16018 | 16033 | Value.makeBool(is_noalias).toIntern(), |
| 16019 | // type: ?type, | |
| 16020 | param_ty_val, | |
| 16021 | 16034 | }; |
| 16022 | param_val.* = (try pt.aggregateValue(param_info_ty, &param_fields)).toIntern(); | |
| 16035 | ||
| 16036 | param_type_val.* = param_ty_val; | |
| 16037 | param_attr_val.* = (try pt.aggregateValue(param_attrs_ty, &param_attrs_fields)).toIntern(); | |
| 16023 | 16038 | } |
| 16024 | 16039 | |
| 16025 | const args_val = v: { | |
| 16040 | const param_types_val = v: { | |
| 16026 | 16041 | const new_decl_ty = try pt.arrayType(.{ |
| 16027 | .len = param_vals.len, | |
| 16028 | .child = param_info_ty.toIntern(), | |
| 16042 | .len = param_type_vals.len, | |
| 16043 | .child = try pt.intern(.{ .opt_type = .type_type }), | |
| 16029 | 16044 | }); |
| 16030 | const new_decl_val = (try pt.aggregateValue(new_decl_ty, param_vals)).toIntern(); | |
| 16045 | const new_decl_val = (try pt.aggregateValue(new_decl_ty, param_type_vals)).toIntern(); | |
| 16031 | 16046 | const slice_ty = (try pt.ptrType(.{ |
| 16032 | .child = param_info_ty.toIntern(), | |
| 16047 | .child = try pt.intern(.{ .opt_type = .type_type }), | |
| 16033 | 16048 | .flags = .{ |
| 16034 | 16049 | .size = .slice, |
| 16035 | 16050 | .is_const = true, |
| ... | ... | @@ -16046,7 +16061,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16046 | 16061 | } }, |
| 16047 | 16062 | .byte_offset = 0, |
| 16048 | 16063 | } }), |
| 16049 | .len = (try pt.intValue(.usize, param_vals.len)).toIntern(), | |
| 16064 | .len = (try pt.intValue(.usize, param_type_vals.len)).toIntern(), | |
| 16065 | } }); | |
| 16066 | }; | |
| 16067 | const param_attrs_val = v: { | |
| 16068 | const new_decl_ty = try pt.arrayType(.{ | |
| 16069 | .len = param_attr_vals.len, | |
| 16070 | .child = param_attrs_ty.toIntern(), | |
| 16071 | }); | |
| 16072 | const new_decl_val = (try pt.aggregateValue(new_decl_ty, param_attr_vals)).toIntern(); | |
| 16073 | const slice_ty = (try pt.ptrType(.{ | |
| 16074 | .child = param_attrs_ty.toIntern(), | |
| 16075 | .flags = .{ | |
| 16076 | .size = .slice, | |
| 16077 | .is_const = true, | |
| 16078 | }, | |
| 16079 | })).toIntern(); | |
| 16080 | const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern(); | |
| 16081 | break :v try pt.intern(.{ .slice = .{ | |
| 16082 | .ty = slice_ty, | |
| 16083 | .ptr = try pt.intern(.{ .ptr = .{ | |
| 16084 | .ty = manyptr_ty, | |
| 16085 | .base_addr = .{ .uav = .{ | |
| 16086 | .orig_ty = manyptr_ty, | |
| 16087 | .val = new_decl_val, | |
| 16088 | } }, | |
| 16089 | .byte_offset = 0, | |
| 16090 | } }), | |
| 16091 | .len = (try pt.intValue(.usize, param_attr_vals.len)).toIntern(), | |
| 16050 | 16092 | } }); |
| 16051 | 16093 | }; |
| 16052 | 16094 | |
| ... | ... | @@ -16075,17 +16117,25 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16075 | 16117 | error.OutOfMemory => |e| return e, |
| 16076 | 16118 | }; |
| 16077 | 16119 | |
| 16078 | const field_values: [5]InternPool.Index = .{ | |
| 16079 | // calling_convention: CallingConvention, | |
| 16120 | const fn_attrs_values = .{ | |
| 16121 | // @"callconv": CallingConvention = .auto, | |
| 16080 | 16122 | callconv_val.toIntern(), |
| 16123 | // varargs: bool = false, | |
| 16124 | Value.makeBool(func_ty_info.is_var_args).toIntern(), | |
| 16125 | }; | |
| 16126 | ||
| 16127 | const field_values = .{ | |
| 16128 | // attrs: Attributes, | |
| 16129 | (try pt.aggregateValue(fn_attr_ty, &fn_attrs_values)).toIntern(), | |
| 16081 | 16130 | // is_generic: bool, |
| 16082 | 16131 | Value.makeBool(func_is_generic).toIntern(), |
| 16083 | // is_var_args: bool, | |
| 16084 | Value.makeBool(func_ty_info.is_var_args).toIntern(), | |
| 16085 | 16132 | // return_type: ?type, |
| 16086 | 16133 | ret_ty_opt, |
| 16087 | // args: []const Fn.Param, | |
| 16088 | args_val, | |
| 16134 | ||
| 16135 | // param_types: []const ?type, | |
| 16136 | param_types_val, | |
| 16137 | // param_attrs: []const ParamAttributes, | |
| 16138 | param_attrs_val, | |
| 16089 | 16139 | }; |
| 16090 | 16140 | return Air.internedToRef((try pt.internUnion(.{ |
| 16091 | 16141 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -16139,23 +16189,34 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16139 | 16189 | const addrspace_ty = try sema.getStdLangType(src, .AddressSpace); |
| 16140 | 16190 | const pointer_ty = try sema.getStdLangType(src, .@"Type.Pointer"); |
| 16141 | 16191 | const ptr_size_ty = try sema.getStdLangType(src, .@"Type.Pointer.Size"); |
| 16192 | const ptr_attrs_ty = try sema.getStdLangType(src, .@"Type.Pointer.Attributes"); | |
| 16142 | 16193 | |
| 16143 | const field_values = .{ | |
| 16144 | // size: Size, | |
| 16145 | (try pt.enumValueFieldIndex(ptr_size_ty, @intFromEnum(info.flags.size))).toIntern(), | |
| 16146 | // is_const: bool, | |
| 16194 | const opt_addrspace_val = try pt.intern(.{ .opt = .{ | |
| 16195 | .ty = (try pt.optionalType(addrspace_ty.toIntern())).toIntern(), | |
| 16196 | .val = (try sema.uninterpretStdLangType(info.flags.address_space, addrspace_ty)).toIntern(), | |
| 16197 | } }); | |
| 16198 | ||
| 16199 | const attributes = .{ | |
| 16200 | // @"const": bool = false, | |
| 16147 | 16201 | Value.makeBool(info.flags.is_const).toIntern(), |
| 16148 | // is_volatile: bool, | |
| 16202 | // @"volatile": bool = false, | |
| 16149 | 16203 | Value.makeBool(info.flags.is_volatile).toIntern(), |
| 16150 | // alignment: ?usize, | |
| 16204 | // @"allowzero": bool = false, | |
| 16205 | Value.makeBool(info.flags.is_allowzero).toIntern(), | |
| 16206 | // @"addrspace": ?AddressSpace = null, | |
| 16207 | opt_addrspace_val, | |
| 16208 | // @"align": ?usize = null, | |
| 16151 | 16209 | alignment_val.toIntern(), |
| 16152 | // address_space: AddressSpace | |
| 16153 | (try pt.enumValueFieldIndex(addrspace_ty, @intFromEnum(info.flags.address_space))).toIntern(), | |
| 16210 | }; | |
| 16211 | ||
| 16212 | const field_values = .{ | |
| 16213 | // size: Size, | |
| 16214 | (try pt.enumValueFieldIndex(ptr_size_ty, @intFromEnum(info.flags.size))).toIntern(), | |
| 16215 | // attrs: Attributes | |
| 16216 | (try pt.aggregateValue(ptr_attrs_ty, &attributes)).toIntern(), | |
| 16154 | 16217 | // child: type, |
| 16155 | 16218 | info.child, |
| 16156 | // is_allowzero: bool, | |
| 16157 | Value.makeBool(info.flags.is_allowzero).toIntern(), | |
| 16158 | // sentinel: ?*const anyopaque, | |
| 16219 | // sentinel_ptr: ?*const anyopaque, | |
| 16159 | 16220 | (try sema.optRefValue(switch (info.sentinel) { |
| 16160 | 16221 | .none => null, |
| 16161 | 16222 | else => Value.fromInterned(info.sentinel), |
| ... | ... | @@ -16215,8 +16276,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16215 | 16276 | }))); |
| 16216 | 16277 | }, |
| 16217 | 16278 | .error_set => { |
| 16218 | // Get the Error type | |
| 16219 | const error_field_ty = try sema.getStdLangType(src, .@"Type.Error"); | |
| 16279 | const error_set_ty = try sema.getStdLangType(src, .@"Type.ErrorSet"); | |
| 16220 | 16280 | |
| 16221 | 16281 | // Build our list of Error values |
| 16222 | 16282 | // Optional value is only null if anyerror |
| ... | ... | @@ -16253,20 +16313,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16253 | 16313 | } }); |
| 16254 | 16314 | }; |
| 16255 | 16315 | |
| 16256 | const error_field_fields = .{ | |
| 16257 | // name: [:0]const u8, | |
| 16258 | error_name_val, | |
| 16259 | }; | |
| 16260 | field_val.* = (try pt.aggregateValue(error_field_ty, &error_field_fields)).toIntern(); | |
| 16316 | field_val.* = error_name_val; | |
| 16261 | 16317 | } |
| 16262 | 16318 | |
| 16263 | 16319 | break :blk vals; |
| 16264 | 16320 | }, |
| 16265 | 16321 | }; |
| 16266 | 16322 | |
| 16267 | // Build our ?[]const Error value | |
| 16323 | // Build our ?[]const [:0]const u8 value | |
| 16268 | 16324 | const slice_errors_ty = try pt.ptrType(.{ |
| 16269 | .child = error_field_ty.toIntern(), | |
| 16325 | .child = .slice_const_u8_sentinel_0_type, | |
| 16270 | 16326 | .flags = .{ |
| 16271 | 16327 | .size = .slice, |
| 16272 | 16328 | .is_const = true, |
| ... | ... | @@ -16276,7 +16332,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16276 | 16332 | const errors_payload_val: InternPool.Index = if (error_field_vals) |vals| v: { |
| 16277 | 16333 | const array_errors_ty = try pt.arrayType(.{ |
| 16278 | 16334 | .len = vals.len, |
| 16279 | .child = error_field_ty.toIntern(), | |
| 16335 | .child = .slice_const_u8_sentinel_0_type, | |
| 16280 | 16336 | }); |
| 16281 | 16337 | const new_decl_val = (try pt.aggregateValue(array_errors_ty, vals)).toIntern(); |
| 16282 | 16338 | const manyptr_errors_ty = slice_errors_ty.slicePtrFieldType(zcu).toIntern(); |
| ... | ... | @@ -16298,11 +16354,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16298 | 16354 | .val = errors_payload_val, |
| 16299 | 16355 | } }); |
| 16300 | 16356 | |
| 16357 | const field_values = .{ | |
| 16358 | // error_names: ?[]const [:0]const u8 | |
| 16359 | errors_val, | |
| 16360 | }; | |
| 16361 | ||
| 16301 | 16362 | // Construct Type{ .error_set = errors_val } |
| 16302 | 16363 | return Air.internedToRef((try pt.internUnion(.{ |
| 16303 | 16364 | .ty = type_info_ty.toIntern(), |
| 16304 | 16365 | .tag = (try pt.enumValueFieldIndex(type_info_tag_ty, @intFromEnum(std.lang.TypeId.error_set))).toIntern(), |
| 16305 | .val = errors_val, | |
| 16366 | .val = (try pt.aggregateValue(error_set_ty, &field_values)).toIntern(), | |
| 16306 | 16367 | }))); |
| 16307 | 16368 | }, |
| 16308 | 16369 | .error_union => { |
| ... | ... | @@ -16322,12 +16383,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16322 | 16383 | }, |
| 16323 | 16384 | .@"enum" => { |
| 16324 | 16385 | const enum_obj = ip.loadEnumType(ty.toIntern()); |
| 16325 | const is_exhaustive: Value = .makeBool(!enum_obj.nonexhaustive); | |
| 16326 | 16386 | |
| 16327 | const enum_field_ty = try sema.getStdLangType(src, .@"Type.EnumField"); | |
| 16387 | const enum_mode_ty = try sema.getStdLangType(src, .@"Type.Enum.Mode"); | |
| 16328 | 16388 | |
| 16329 | const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_obj.field_names.len); | |
| 16330 | for (enum_field_vals, 0..) |*field_val, tag_index| { | |
| 16389 | const enum_mode_tag: std.builtin.Type.Enum.Mode = if (enum_obj.nonexhaustive) .nonexhaustive else .exhaustive; | |
| 16390 | ||
| 16391 | const enum_mode: Value = try sema.uninterpretStdLangType(enum_mode_tag, enum_mode_ty); | |
| 16392 | ||
| 16393 | const enum_field_name_vals = try sema.arena.alloc(InternPool.Index, enum_obj.field_names.len); | |
| 16394 | const enum_field_value_vals = try sema.arena.alloc(InternPool.Index, enum_obj.field_names.len); | |
| 16395 | for ( | |
| 16396 | enum_field_name_vals, | |
| 16397 | enum_field_value_vals, | |
| 16398 | 0.., | |
| 16399 | ) |*field_name_val, *field_value_val, tag_index| { | |
| 16331 | 16400 | const value_val = if (enum_obj.field_values.len > 0) |
| 16332 | 16401 | try ip.getCoercedInts( |
| 16333 | 16402 | gpa, |
| ... | ... | @@ -16366,23 +16435,18 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16366 | 16435 | } }); |
| 16367 | 16436 | }; |
| 16368 | 16437 | |
| 16369 | const enum_field_fields = .{ | |
| 16370 | // name: [:0]const u8, | |
| 16371 | name_val, | |
| 16372 | // value: comptime_int, | |
| 16373 | value_val, | |
| 16374 | }; | |
| 16375 | field_val.* = (try pt.aggregateValue(enum_field_ty, &enum_field_fields)).toIntern(); | |
| 16438 | field_name_val.* = name_val; | |
| 16439 | field_value_val.* = value_val; | |
| 16376 | 16440 | } |
| 16377 | 16441 | |
| 16378 | const fields_val = v: { | |
| 16379 | const fields_array_ty = try pt.arrayType(.{ | |
| 16380 | .len = enum_field_vals.len, | |
| 16381 | .child = enum_field_ty.toIntern(), | |
| 16442 | const fields_names_val = v: { | |
| 16443 | const fields_names_array_ty = try pt.arrayType(.{ | |
| 16444 | .len = enum_field_name_vals.len, | |
| 16445 | .child = .slice_const_u8_sentinel_0_type, | |
| 16382 | 16446 | }); |
| 16383 | const new_decl_val = (try pt.aggregateValue(fields_array_ty, enum_field_vals)).toIntern(); | |
| 16447 | const new_decl_val = (try pt.aggregateValue(fields_names_array_ty, enum_field_name_vals)).toIntern(); | |
| 16384 | 16448 | const slice_ty = (try pt.ptrType(.{ |
| 16385 | .child = enum_field_ty.toIntern(), | |
| 16449 | .child = .slice_const_u8_sentinel_0_type, | |
| 16386 | 16450 | .flags = .{ |
| 16387 | 16451 | .size = .slice, |
| 16388 | 16452 | .is_const = true, |
| ... | ... | @@ -16399,23 +16463,55 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16399 | 16463 | } }, |
| 16400 | 16464 | .byte_offset = 0, |
| 16401 | 16465 | } }), |
| 16402 | .len = (try pt.intValue(.usize, enum_field_vals.len)).toIntern(), | |
| 16466 | .len = (try pt.intValue(.usize, enum_field_name_vals.len)).toIntern(), | |
| 16403 | 16467 | } }); |
| 16404 | 16468 | }; |
| 16405 | 16469 | |
| 16406 | const decls_val = try sema.typeInfoDecls(src, ip.loadEnumType(ty.toIntern()).namespace.toOptional()); | |
| 16470 | const fields_values_val = v: { | |
| 16471 | const fields_values_array_ty = try pt.arrayType(.{ | |
| 16472 | .len = enum_field_value_vals.len, | |
| 16473 | .child = .comptime_int_type, | |
| 16474 | }); | |
| 16475 | const new_decl_val = (try pt.aggregateValue(fields_values_array_ty, enum_field_value_vals)).toIntern(); | |
| 16476 | const slice_ty = (try pt.ptrType(.{ | |
| 16477 | .child = .comptime_int_type, | |
| 16478 | .flags = .{ | |
| 16479 | .size = .slice, | |
| 16480 | .is_const = true, | |
| 16481 | }, | |
| 16482 | })).toIntern(); | |
| 16483 | const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern(); | |
| 16484 | break :v try pt.intern(.{ .slice = .{ | |
| 16485 | .ty = slice_ty, | |
| 16486 | .ptr = try pt.intern(.{ .ptr = .{ | |
| 16487 | .ty = manyptr_ty, | |
| 16488 | .base_addr = .{ .uav = .{ | |
| 16489 | .val = new_decl_val, | |
| 16490 | .orig_ty = manyptr_ty, | |
| 16491 | } }, | |
| 16492 | .byte_offset = 0, | |
| 16493 | } }), | |
| 16494 | .len = (try pt.intValue(.usize, enum_field_value_vals.len)).toIntern(), | |
| 16495 | } }); | |
| 16496 | }; | |
| 16497 | ||
| 16498 | const decl_names_val = try sema.typeInfoDecls(ip.loadEnumType(ty.toIntern()).namespace.toOptional()); | |
| 16407 | 16499 | |
| 16408 | 16500 | const type_enum_ty = try sema.getStdLangType(src, .@"Type.Enum"); |
| 16409 | 16501 | |
| 16410 | 16502 | const field_values = .{ |
| 16411 | 16503 | // tag_type: type, |
| 16412 | 16504 | ip.loadEnumType(ty.toIntern()).int_tag_type, |
| 16413 | // fields: []const EnumField, | |
| 16414 | fields_val, | |
| 16415 | // decls: []const Declaration, | |
| 16416 | decls_val, | |
| 16417 | // is_exhaustive: bool, | |
| 16418 | is_exhaustive.toIntern(), | |
| 16505 | // mode: Mode | |
| 16506 | enum_mode.toIntern(), | |
| 16507 | ||
| 16508 | // field_names: []const [:0]const u8, | |
| 16509 | fields_names_val, | |
| 16510 | // field_values: []const comptime_int, | |
| 16511 | fields_values_val, | |
| 16512 | ||
| 16513 | // decl_names: []const [:0]const u8, | |
| 16514 | decl_names_val, | |
| 16419 | 16515 | }; |
| 16420 | 16516 | return Air.internedToRef((try pt.internUnion(.{ |
| 16421 | 16517 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -16425,16 +16521,26 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16425 | 16521 | }, |
| 16426 | 16522 | .@"union" => { |
| 16427 | 16523 | const type_union_ty = try sema.getStdLangType(src, .@"Type.Union"); |
| 16428 | const union_field_ty = try sema.getStdLangType(src, .@"Type.UnionField"); | |
| 16524 | const union_field_attr_ty = try sema.getStdLangType(src, .@"Type.Union.FieldAttributes"); | |
| 16429 | 16525 | |
| 16430 | 16526 | const union_obj = ip.loadUnionType(ty.toIntern()); |
| 16431 | 16527 | const enum_obj = ip.loadEnumType(union_obj.enum_tag_type); |
| 16432 | 16528 | const layout = union_obj.layout; |
| 16433 | 16529 | |
| 16434 | const union_field_vals = try gpa.alloc(InternPool.Index, enum_obj.field_names.len); | |
| 16435 | defer gpa.free(union_field_vals); | |
| 16436 | ||
| 16437 | for (union_field_vals, 0..) |*field_val, field_index| { | |
| 16530 | const union_field_names = try gpa.alloc(InternPool.Index, enum_obj.field_names.len); | |
| 16531 | defer gpa.free(union_field_names); | |
| 16532 | const union_field_attrs = try gpa.alloc(InternPool.Index, enum_obj.field_names.len); | |
| 16533 | defer gpa.free(union_field_attrs); | |
| 16534 | ||
| 16535 | for ( | |
| 16536 | union_field_names, | |
| 16537 | union_field_attrs, | |
| 16538 | 0.., | |
| 16539 | ) | | |
| 16540 | *field_name_val, | |
| 16541 | *field_attr_val, | |
| 16542 | field_index, | |
| 16543 | | { | |
| 16438 | 16544 | const name_val = v: { |
| 16439 | 16545 | const field_name = enum_obj.field_names.get(ip)[field_index]; |
| 16440 | 16546 | const field_name_len = field_name.length(ip); |
| ... | ... | @@ -16461,8 +16567,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16461 | 16567 | } }); |
| 16462 | 16568 | }; |
| 16463 | 16569 | |
| 16464 | const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]); | |
| 16465 | ||
| 16466 | 16570 | const alignment_ty = try pt.optionalType(.usize_type); |
| 16467 | 16571 | const alignment_val: Value = val: { |
| 16468 | 16572 | const a: Alignment = switch (layout) { |
| ... | ... | @@ -16479,25 +16583,52 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16479 | 16583 | } })); |
| 16480 | 16584 | }; |
| 16481 | 16585 | |
| 16482 | const union_field_fields = .{ | |
| 16483 | // name: [:0]const u8, | |
| 16484 | name_val, | |
| 16485 | // type: type, | |
| 16486 | field_ty.toIntern(), | |
| 16586 | field_name_val.* = name_val; | |
| 16587 | const union_field_attr = .{ | |
| 16487 | 16588 | // alignment: ?usize, |
| 16488 | 16589 | alignment_val.toIntern(), |
| 16489 | 16590 | }; |
| 16490 | field_val.* = (try pt.aggregateValue(union_field_ty, &union_field_fields)).toIntern(); | |
| 16591 | ||
| 16592 | field_attr_val.* = (try pt.aggregateValue(union_field_attr_ty, &union_field_attr)).toIntern(); | |
| 16491 | 16593 | } |
| 16492 | 16594 | |
| 16493 | const fields_val = v: { | |
| 16595 | const field_names_val = v: { | |
| 16596 | const array_field_names_ty = try pt.arrayType(.{ | |
| 16597 | .len = union_field_names.len, | |
| 16598 | .child = .slice_const_u8_sentinel_0_type, | |
| 16599 | }); | |
| 16600 | const new_decl_val = (try pt.aggregateValue(array_field_names_ty, union_field_names)).toIntern(); | |
| 16601 | const slice_ty = (try pt.ptrType(.{ | |
| 16602 | .child = .slice_const_u8_sentinel_0_type, | |
| 16603 | .flags = .{ | |
| 16604 | .size = .slice, | |
| 16605 | .is_const = true, | |
| 16606 | }, | |
| 16607 | })).toIntern(); | |
| 16608 | const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern(); | |
| 16609 | break :v try pt.intern(.{ .slice = .{ | |
| 16610 | .ty = slice_ty, | |
| 16611 | .ptr = try pt.intern(.{ .ptr = .{ | |
| 16612 | .ty = manyptr_ty, | |
| 16613 | .base_addr = .{ .uav = .{ | |
| 16614 | .orig_ty = manyptr_ty, | |
| 16615 | .val = new_decl_val, | |
| 16616 | } }, | |
| 16617 | .byte_offset = 0, | |
| 16618 | } }), | |
| 16619 | .len = (try pt.intValue(.usize, union_field_names.len)).toIntern(), | |
| 16620 | } }); | |
| 16621 | }; | |
| 16622 | const field_types_val = v: { | |
| 16623 | const union_field_types = union_obj.field_types.get(ip); | |
| 16624 | ||
| 16494 | 16625 | const array_fields_ty = try pt.arrayType(.{ |
| 16495 | .len = union_field_vals.len, | |
| 16496 | .child = union_field_ty.toIntern(), | |
| 16626 | .len = union_field_types.len, | |
| 16627 | .child = .type_type, | |
| 16497 | 16628 | }); |
| 16498 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, union_field_vals)).toIntern(); | |
| 16629 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, union_field_types)).toIntern(); | |
| 16499 | 16630 | const slice_ty = (try pt.ptrType(.{ |
| 16500 | .child = union_field_ty.toIntern(), | |
| 16631 | .child = .type_type, | |
| 16501 | 16632 | .flags = .{ |
| 16502 | 16633 | .size = .slice, |
| 16503 | 16634 | .is_const = true, |
| ... | ... | @@ -16514,11 +16645,38 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16514 | 16645 | } }, |
| 16515 | 16646 | .byte_offset = 0, |
| 16516 | 16647 | } }), |
| 16517 | .len = (try pt.intValue(.usize, union_field_vals.len)).toIntern(), | |
| 16648 | .len = (try pt.intValue(.usize, union_field_types.len)).toIntern(), | |
| 16649 | } }); | |
| 16650 | }; | |
| 16651 | const field_attrs_val = v: { | |
| 16652 | const array_fields_ty = try pt.arrayType(.{ | |
| 16653 | .len = union_field_attrs.len, | |
| 16654 | .child = union_field_attr_ty.toIntern(), | |
| 16655 | }); | |
| 16656 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, union_field_attrs)).toIntern(); | |
| 16657 | const slice_ty = (try pt.ptrType(.{ | |
| 16658 | .child = union_field_attr_ty.toIntern(), | |
| 16659 | .flags = .{ | |
| 16660 | .size = .slice, | |
| 16661 | .is_const = true, | |
| 16662 | }, | |
| 16663 | })).toIntern(); | |
| 16664 | const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern(); | |
| 16665 | break :v try pt.intern(.{ .slice = .{ | |
| 16666 | .ty = slice_ty, | |
| 16667 | .ptr = try pt.intern(.{ .ptr = .{ | |
| 16668 | .ty = manyptr_ty, | |
| 16669 | .base_addr = .{ .uav = .{ | |
| 16670 | .orig_ty = manyptr_ty, | |
| 16671 | .val = new_decl_val, | |
| 16672 | } }, | |
| 16673 | .byte_offset = 0, | |
| 16674 | } }), | |
| 16675 | .len = (try pt.intValue(.usize, union_field_attrs.len)).toIntern(), | |
| 16518 | 16676 | } }); |
| 16519 | 16677 | }; |
| 16520 | 16678 | |
| 16521 | const decls_val = try sema.typeInfoDecls(src, ty.getNamespaceIndex(zcu).toOptional()); | |
| 16679 | const decl_names_val = try sema.typeInfoDecls(ty.getNamespaceIndex(zcu).toOptional()); | |
| 16522 | 16680 | |
| 16523 | 16681 | const enum_tag_ty_val = try pt.intern(.{ .opt = .{ |
| 16524 | 16682 | .ty = (try pt.optionalType(.type_type)).toIntern(), |
| ... | ... | @@ -16527,16 +16685,32 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16527 | 16685 | |
| 16528 | 16686 | const container_layout_ty = try sema.getStdLangType(src, .@"Type.ContainerLayout"); |
| 16529 | 16687 | |
| 16688 | const backing_integer_val = try pt.intern(.{ .opt = .{ | |
| 16689 | .ty = (try pt.optionalType(.type_type)).toIntern(), | |
| 16690 | .val = if (layout == .@"packed") val: { | |
| 16691 | assert(Type.fromInterned(union_obj.packed_backing_int_type).isInt(zcu)); | |
| 16692 | break :val union_obj.packed_backing_int_type; | |
| 16693 | } else .none, | |
| 16694 | } }); | |
| 16695 | ||
| 16530 | 16696 | const field_values = .{ |
| 16531 | 16697 | // layout: ContainerLayout, |
| 16532 | 16698 | (try pt.enumValueFieldIndex(container_layout_ty, @intFromEnum(layout))).toIntern(), |
| 16533 | 16699 | |
| 16534 | 16700 | // tag_type: ?type, |
| 16535 | 16701 | enum_tag_ty_val, |
| 16536 | // fields: []const UnionField, | |
| 16537 | fields_val, | |
| 16538 | // decls: []const Declaration, | |
| 16539 | decls_val, | |
| 16702 | // backing_integer: ?type, | |
| 16703 | backing_integer_val, | |
| 16704 | ||
| 16705 | // field_names: []const [:0]const u8, | |
| 16706 | field_names_val, | |
| 16707 | // field_types: []const type, | |
| 16708 | field_types_val, | |
| 16709 | // field_attrs: []const FieldAttributes, | |
| 16710 | field_attrs_val, | |
| 16711 | ||
| 16712 | // decl_names: []const [:0]const u8, | |
| 16713 | decl_names_val, | |
| 16540 | 16714 | }; |
| 16541 | 16715 | return Air.internedToRef((try pt.internUnion(.{ |
| 16542 | 16716 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -16546,16 +16720,26 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16546 | 16720 | }, |
| 16547 | 16721 | .@"struct" => { |
| 16548 | 16722 | const type_struct_ty = try sema.getStdLangType(src, .@"Type.Struct"); |
| 16549 | const struct_field_ty = try sema.getStdLangType(src, .@"Type.StructField"); | |
| 16723 | const struct_field_attr_ty = try sema.getStdLangType(src, .@"Type.Struct.FieldAttributes"); | |
| 16550 | 16724 | |
| 16551 | var struct_field_vals: []InternPool.Index = &.{}; | |
| 16552 | defer gpa.free(struct_field_vals); | |
| 16725 | var struct_field_name_vals: []InternPool.Index = &.{}; | |
| 16726 | defer gpa.free(struct_field_name_vals); | |
| 16727 | var struct_field_attr_vals: []InternPool.Index = &.{}; | |
| 16728 | defer gpa.free(struct_field_attr_vals); | |
| 16553 | 16729 | fv: { |
| 16554 | 16730 | const struct_type = switch (ip.indexToKey(ty.toIntern())) { |
| 16555 | 16731 | .tuple_type => |tuple_type| { |
| 16556 | struct_field_vals = try gpa.alloc(InternPool.Index, tuple_type.types.len); | |
| 16557 | for (struct_field_vals, 0..) |*struct_field_val, field_index| { | |
| 16558 | const field_ty = tuple_type.types.get(ip)[field_index]; | |
| 16732 | struct_field_name_vals = try gpa.alloc(InternPool.Index, tuple_type.types.len); | |
| 16733 | struct_field_attr_vals = try gpa.alloc(InternPool.Index, tuple_type.types.len); | |
| 16734 | for ( | |
| 16735 | struct_field_name_vals, | |
| 16736 | struct_field_attr_vals, | |
| 16737 | 0.., | |
| 16738 | ) | | |
| 16739 | *struct_field_name_val, | |
| 16740 | *struct_field_attr_val, | |
| 16741 | field_index, | |
| 16742 | | { | |
| 16559 | 16743 | const field_val = tuple_type.values.get(ip)[field_index]; |
| 16560 | 16744 | const name_val = v: { |
| 16561 | 16745 | const field_name = try ip.getOrPutStringFmt(gpa, io, pt.tid, "{d}", .{field_index}, .no_embedded_nulls); |
| ... | ... | @@ -16587,19 +16771,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16587 | 16771 | const opt_default_val = if (is_comptime) Value.fromInterned(field_val) else null; |
| 16588 | 16772 | const default_val_ptr = try sema.optRefValue(opt_default_val); |
| 16589 | 16773 | |
| 16590 | const struct_field_fields = .{ | |
| 16591 | // name: [:0]const u8, | |
| 16592 | name_val, | |
| 16593 | // type: type, | |
| 16594 | field_ty, | |
| 16595 | // default_value: ?*const anyopaque, | |
| 16596 | default_val_ptr.toIntern(), | |
| 16597 | // is_comptime: bool, | |
| 16774 | const struct_field_attr_fields = .{ | |
| 16775 | // @"comptime": bool, | |
| 16598 | 16776 | Value.makeBool(is_comptime).toIntern(), |
| 16599 | // alignment: ?usize, | |
| 16777 | // @"align": ?usize, | |
| 16600 | 16778 | (try pt.nullValue(try pt.optionalType(.usize_type))).toIntern(), |
| 16779 | // default_value_ptr: ?*const anyopaque, | |
| 16780 | default_val_ptr.toIntern(), | |
| 16601 | 16781 | }; |
| 16602 | struct_field_val.* = (try pt.aggregateValue(struct_field_ty, &struct_field_fields)).toIntern(); | |
| 16782 | ||
| 16783 | struct_field_name_val.* = name_val; | |
| 16784 | struct_field_attr_val.* = (try pt.aggregateValue(struct_field_attr_ty, &struct_field_attr_fields)).toIntern(); | |
| 16603 | 16785 | } |
| 16604 | 16786 | break :fv; |
| 16605 | 16787 | }, |
| ... | ... | @@ -16607,12 +16789,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16607 | 16789 | else => unreachable, |
| 16608 | 16790 | }; |
| 16609 | 16791 | try sema.ensureStructDefaultsResolved(ty, src); // can't do this sooner, since it's not allowed on tuples |
| 16610 | struct_field_vals = try gpa.alloc(InternPool.Index, struct_type.field_types.len); | |
| 16611 | ||
| 16612 | for (struct_field_vals, 0..) |*field_val, field_index| { | |
| 16792 | struct_field_name_vals = try gpa.alloc(InternPool.Index, struct_type.field_types.len); | |
| 16793 | struct_field_attr_vals = try gpa.alloc(InternPool.Index, struct_type.field_types.len); | |
| 16794 | ||
| 16795 | for ( | |
| 16796 | struct_field_name_vals, | |
| 16797 | struct_field_attr_vals, | |
| 16798 | 0.., | |
| 16799 | ) | | |
| 16800 | *field_name_val, | |
| 16801 | *field_attr_val, | |
| 16802 | field_index, | |
| 16803 | | { | |
| 16613 | 16804 | const field_name = struct_type.field_names.get(ip)[field_index]; |
| 16614 | 16805 | const field_name_len = field_name.length(ip); |
| 16615 | const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]); | |
| 16616 | 16806 | const field_default: InternPool.Index = if (struct_type.field_defaults.len > 0) d: { |
| 16617 | 16807 | break :d struct_type.field_defaults.get(ip)[field_index]; |
| 16618 | 16808 | } else .none; |
| ... | ... | @@ -16660,30 +16850,63 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16660 | 16850 | } })); |
| 16661 | 16851 | }; |
| 16662 | 16852 | |
| 16663 | const struct_field_fields = .{ | |
| 16664 | // name: [:0]const u8, | |
| 16665 | name_val, | |
| 16666 | // type: type, | |
| 16667 | field_ty.toIntern(), | |
| 16668 | // default_value: ?*const anyopaque, | |
| 16669 | default_val_ptr.toIntern(), | |
| 16670 | // is_comptime: bool, | |
| 16853 | const struct_field_attr_fields = .{ | |
| 16854 | // @"comptime": bool, | |
| 16671 | 16855 | Value.makeBool(field_is_comptime).toIntern(), |
| 16672 | // alignment: ?usize, | |
| 16856 | // @"align": ?usize, | |
| 16673 | 16857 | alignment_val.toIntern(), |
| 16858 | // default_value_ptr: ?*const anyopaque, | |
| 16859 | default_val_ptr.toIntern(), | |
| 16674 | 16860 | }; |
| 16675 | field_val.* = (try pt.aggregateValue(struct_field_ty, &struct_field_fields)).toIntern(); | |
| 16861 | field_name_val.* = name_val; | |
| 16862 | field_attr_val.* = (try pt.aggregateValue(struct_field_attr_ty, &struct_field_attr_fields)).toIntern(); | |
| 16676 | 16863 | } |
| 16677 | 16864 | } |
| 16678 | 16865 | |
| 16679 | const fields_val = v: { | |
| 16866 | const field_names_val = v: { | |
| 16867 | const array_fields_ty = try pt.arrayType(.{ | |
| 16868 | .len = struct_field_name_vals.len, | |
| 16869 | .child = .slice_const_u8_sentinel_0_type, | |
| 16870 | }); | |
| 16871 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_name_vals)).toIntern(); | |
| 16872 | const slice_ty = (try pt.ptrType(.{ | |
| 16873 | .child = .slice_const_u8_sentinel_0_type, | |
| 16874 | .flags = .{ | |
| 16875 | .size = .slice, | |
| 16876 | .is_const = true, | |
| 16877 | }, | |
| 16878 | })).toIntern(); | |
| 16879 | const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern(); | |
| 16880 | break :v try pt.intern(.{ .slice = .{ | |
| 16881 | .ty = slice_ty, | |
| 16882 | .ptr = try pt.intern(.{ .ptr = .{ | |
| 16883 | .ty = manyptr_ty, | |
| 16884 | .base_addr = .{ .uav = .{ | |
| 16885 | .orig_ty = manyptr_ty, | |
| 16886 | .val = new_decl_val, | |
| 16887 | } }, | |
| 16888 | .byte_offset = 0, | |
| 16889 | } }), | |
| 16890 | .len = (try pt.intValue(.usize, struct_field_name_vals.len)).toIntern(), | |
| 16891 | } }); | |
| 16892 | }; | |
| 16893 | ||
| 16894 | const field_types_val = v: { | |
| 16895 | const struct_field_type_vals = switch (ip.indexToKey(ty.toIntern())) { | |
| 16896 | .tuple_type => |tt| tt.types.get(ip), | |
| 16897 | .struct_type => blk: { | |
| 16898 | const st = ip.loadStructType(ty.toIntern()); | |
| 16899 | break :blk st.field_types.get(ip); | |
| 16900 | }, | |
| 16901 | else => unreachable, | |
| 16902 | }; | |
| 16680 | 16903 | const array_fields_ty = try pt.arrayType(.{ |
| 16681 | .len = struct_field_vals.len, | |
| 16682 | .child = struct_field_ty.toIntern(), | |
| 16904 | .len = struct_field_type_vals.len, | |
| 16905 | .child = .type_type, | |
| 16683 | 16906 | }); |
| 16684 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_vals)).toIntern(); | |
| 16907 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_type_vals)).toIntern(); | |
| 16685 | 16908 | const slice_ty = (try pt.ptrType(.{ |
| 16686 | .child = struct_field_ty.toIntern(), | |
| 16909 | .child = .type_type, | |
| 16687 | 16910 | .flags = .{ |
| 16688 | 16911 | .size = .slice, |
| 16689 | 16912 | .is_const = true, |
| ... | ... | @@ -16700,11 +16923,38 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16700 | 16923 | } }, |
| 16701 | 16924 | .byte_offset = 0, |
| 16702 | 16925 | } }), |
| 16703 | .len = (try pt.intValue(.usize, struct_field_vals.len)).toIntern(), | |
| 16926 | .len = (try pt.intValue(.usize, struct_field_type_vals.len)).toIntern(), | |
| 16927 | } }); | |
| 16928 | }; | |
| 16929 | const field_attrs_val = v: { | |
| 16930 | const array_fields_ty = try pt.arrayType(.{ | |
| 16931 | .len = struct_field_attr_vals.len, | |
| 16932 | .child = struct_field_attr_ty.toIntern(), | |
| 16933 | }); | |
| 16934 | const new_decl_val = (try pt.aggregateValue(array_fields_ty, struct_field_attr_vals)).toIntern(); | |
| 16935 | const slice_ty = (try pt.ptrType(.{ | |
| 16936 | .child = struct_field_attr_ty.toIntern(), | |
| 16937 | .flags = .{ | |
| 16938 | .size = .slice, | |
| 16939 | .is_const = true, | |
| 16940 | }, | |
| 16941 | })).toIntern(); | |
| 16942 | const manyptr_ty = Type.fromInterned(slice_ty).slicePtrFieldType(zcu).toIntern(); | |
| 16943 | break :v try pt.intern(.{ .slice = .{ | |
| 16944 | .ty = slice_ty, | |
| 16945 | .ptr = try pt.intern(.{ .ptr = .{ | |
| 16946 | .ty = manyptr_ty, | |
| 16947 | .base_addr = .{ .uav = .{ | |
| 16948 | .orig_ty = manyptr_ty, | |
| 16949 | .val = new_decl_val, | |
| 16950 | } }, | |
| 16951 | .byte_offset = 0, | |
| 16952 | } }), | |
| 16953 | .len = (try pt.intValue(.usize, struct_field_attr_vals.len)).toIntern(), | |
| 16704 | 16954 | } }); |
| 16705 | 16955 | }; |
| 16706 | 16956 | |
| 16707 | const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu)); | |
| 16957 | const decl_names_val = try sema.typeInfoDecls(ty.getNamespace(zcu)); | |
| 16708 | 16958 | |
| 16709 | 16959 | const backing_integer_val = try pt.intern(.{ .opt = .{ |
| 16710 | 16960 | .ty = (try pt.optionalType(.type_type)).toIntern(), |
| ... | ... | @@ -16719,16 +16969,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16719 | 16969 | const layout = ty.containerLayout(zcu); |
| 16720 | 16970 | |
| 16721 | 16971 | const field_values = [_]InternPool.Index{ |
| 16972 | // is_tuple: bool, | |
| 16973 | Value.makeBool(ty.isTuple(zcu)).toIntern(), | |
| 16722 | 16974 | // layout: ContainerLayout, |
| 16723 | 16975 | (try pt.enumValueFieldIndex(container_layout_ty, @intFromEnum(layout))).toIntern(), |
| 16724 | 16976 | // backing_integer: ?type, |
| 16725 | 16977 | backing_integer_val, |
| 16726 | // fields: []const StructField, | |
| 16727 | fields_val, | |
| 16728 | // decls: []const Declaration, | |
| 16729 | decls_val, | |
| 16730 | // is_tuple: bool, | |
| 16731 | Value.makeBool(ty.isTuple(zcu)).toIntern(), | |
| 16978 | ||
| 16979 | // field_names: []const [:0]const u8, | |
| 16980 | field_names_val, | |
| 16981 | // field_types: []const type, | |
| 16982 | field_types_val, | |
| 16983 | // field_attrs: []const FieldAttributes, | |
| 16984 | field_attrs_val, | |
| 16985 | ||
| 16986 | // decl_names: []const [:0]const u8, | |
| 16987 | decl_names_val, | |
| 16732 | 16988 | }; |
| 16733 | 16989 | return Air.internedToRef((try pt.internUnion(.{ |
| 16734 | 16990 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -16739,11 +16995,11 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16739 | 16995 | .@"opaque" => { |
| 16740 | 16996 | const type_opaque_ty = try sema.getStdLangType(src, .@"Type.Opaque"); |
| 16741 | 16997 | |
| 16742 | const decls_val = try sema.typeInfoDecls(src, ty.getNamespace(zcu)); | |
| 16998 | const decl_names_val = try sema.typeInfoDecls(ty.getNamespace(zcu)); | |
| 16743 | 16999 | |
| 16744 | 17000 | const field_values = .{ |
| 16745 | // decls: []const Declaration, | |
| 16746 | decls_val, | |
| 17001 | // decl_names: []const [:0]const u8, | |
| 17002 | decl_names_val, | |
| 16747 | 17003 | }; |
| 16748 | 17004 | return Air.internedToRef((try pt.internUnion(.{ |
| 16749 | 17005 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -16758,30 +17014,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16758 | 17014 | |
| 16759 | 17015 | fn typeInfoDecls( |
| 16760 | 17016 | sema: *Sema, |
| 16761 | src: LazySrcLoc, | |
| 16762 | 17017 | opt_namespace: InternPool.OptionalNamespaceIndex, |
| 16763 | 17018 | ) CompileError!InternPool.Index { |
| 16764 | 17019 | const pt = sema.pt; |
| 16765 | 17020 | const zcu = pt.zcu; |
| 16766 | 17021 | const gpa = sema.gpa; |
| 16767 | 17022 | |
| 16768 | const declaration_ty = try sema.getStdLangType(src, .@"Type.Declaration"); | |
| 16769 | ||
| 16770 | 17023 | var decl_vals = std.array_list.Managed(InternPool.Index).init(gpa); |
| 16771 | 17024 | defer decl_vals.deinit(); |
| 16772 | 17025 | |
| 16773 | 17026 | var seen_namespaces = std.AutoHashMap(*Namespace, void).init(gpa); |
| 16774 | 17027 | defer seen_namespaces.deinit(); |
| 16775 | 17028 | |
| 16776 | try sema.typeInfoNamespaceDecls(opt_namespace, declaration_ty, &decl_vals, &seen_namespaces); | |
| 17029 | try sema.typeInfoNamespaceDecls(opt_namespace, &decl_vals, &seen_namespaces); | |
| 16777 | 17030 | |
| 16778 | 17031 | const array_decl_ty = try pt.arrayType(.{ |
| 16779 | 17032 | .len = decl_vals.items.len, |
| 16780 | .child = declaration_ty.toIntern(), | |
| 17033 | .child = .slice_const_u8_sentinel_0_type, | |
| 16781 | 17034 | }); |
| 16782 | 17035 | const new_decl_val = (try pt.aggregateValue(array_decl_ty, decl_vals.items)).toIntern(); |
| 16783 | 17036 | const slice_ty = (try pt.ptrType(.{ |
| 16784 | .child = declaration_ty.toIntern(), | |
| 17037 | .child = .slice_const_u8_sentinel_0_type, | |
| 16785 | 17038 | .flags = .{ |
| 16786 | 17039 | .size = .slice, |
| 16787 | 17040 | .is_const = true, |
| ... | ... | @@ -16805,7 +17058,6 @@ fn typeInfoDecls( |
| 16805 | 17058 | fn typeInfoNamespaceDecls( |
| 16806 | 17059 | sema: *Sema, |
| 16807 | 17060 | opt_namespace_index: InternPool.OptionalNamespaceIndex, |
| 16808 | declaration_ty: Type, | |
| 16809 | 17061 | decl_vals: *std.array_list.Managed(InternPool.Index), |
| 16810 | 17062 | seen_namespaces: *std.AutoHashMap(*Namespace, void), |
| 16811 | 17063 | ) !void { |
| ... | ... | @@ -16850,11 +17102,7 @@ fn typeInfoNamespaceDecls( |
| 16850 | 17102 | }, |
| 16851 | 17103 | }); |
| 16852 | 17104 | }; |
| 16853 | const fields = [_]InternPool.Index{ | |
| 16854 | // name: [:0]const u8, | |
| 16855 | name_val, | |
| 16856 | }; | |
| 16857 | try decl_vals.append((try pt.aggregateValue(declaration_ty, &fields)).toIntern()); | |
| 17105 | try decl_vals.append(name_val); | |
| 16858 | 17106 | } |
| 16859 | 17107 | } |
| 16860 | 17108 | |
| ... | ... | @@ -17120,9 +17368,9 @@ fn finishCondBr( |
| 17120 | 17368 | ) !Air.Inst.Ref { |
| 17121 | 17369 | const gpa = sema.gpa; |
| 17122 | 17370 | |
| 17123 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len + | |
| 17371 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len + | |
| 17124 | 17372 | then_block.instructions.items.len + else_block.instructions.items.len + |
| 17125 | @typeInfo(Air.Block).@"struct".fields.len + child_block.instructions.items.len + 1); | |
| 17373 | @typeInfo(Air.Block).@"struct".field_names.len + child_block.instructions.items.len + 1); | |
| 17126 | 17374 | |
| 17127 | 17375 | const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{ |
| 17128 | 17376 | .then_body_len = @intCast(then_block.instructions.items.len), |
| ... | ... | @@ -17331,7 +17579,7 @@ fn zirCondbr( |
| 17331 | 17579 | break :h .unlikely; |
| 17332 | 17580 | } else try sema.analyzeBodyRuntimeBreak(&sub_block, else_body); |
| 17333 | 17581 | |
| 17334 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".fields.len + | |
| 17582 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).@"struct".field_names.len + | |
| 17335 | 17583 | true_instructions.len + sub_block.instructions.items.len); |
| 17336 | 17584 | _ = try parent_block.addInst(.{ |
| 17337 | 17585 | .tag = .cond_br, |
| ... | ... | @@ -17403,7 +17651,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 17403 | 17651 | // The only interesting hint here is `.cold`, which can come from e.g. `errdefer @panic`. |
| 17404 | 17652 | const is_cold = sema.branch_hint == .cold; |
| 17405 | 17653 | |
| 17406 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Try).@"struct".fields.len + | |
| 17654 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Try).@"struct".field_names.len + | |
| 17407 | 17655 | sub_block.instructions.items.len); |
| 17408 | 17656 | const try_inst = try parent_block.addInst(.{ |
| 17409 | 17657 | .tag = if (is_cold) .try_cold else .@"try", |
| ... | ... | @@ -17483,7 +17731,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17483 | 17731 | }, |
| 17484 | 17732 | }); |
| 17485 | 17733 | const res_ty_ref = Air.internedToRef(res_ty.toIntern()); |
| 17486 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".fields.len + | |
| 17734 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".field_names.len + | |
| 17487 | 17735 | sub_block.instructions.items.len); |
| 17488 | 17736 | const try_inst = try parent_block.addInst(.{ |
| 17489 | 17737 | .tag = if (is_cold) .try_ptr_cold else .try_ptr, |
| ... | ... | @@ -17731,9 +17979,9 @@ fn maybePushErrorTrace( |
| 17731 | 17979 | try sema.air_instructions.ensureUnusedCapacity(gpa, 4); |
| 17732 | 17980 | try sema.air_extra.ensureUnusedCapacity( |
| 17733 | 17981 | gpa, |
| 17734 | @typeInfo(Air.Block).@"struct".fields.len + | |
| 17982 | @typeInfo(Air.Block).@"struct".field_names.len + | |
| 17735 | 17983 | 1 + // the main block contains only the `cond_br` |
| 17736 | @typeInfo(Air.CondBr).@"struct".fields.len + | |
| 17984 | @typeInfo(Air.CondBr).@"struct".field_names.len + | |
| 17737 | 17985 | 1 + // the non-error branch contains only a `br` |
| 17738 | 17986 | err_block.instructions.items.len + 1, // the error branch contains the `returnError` call and a `br` |
| 17739 | 17987 | ); |
| ... | ... | @@ -19470,11 +19718,11 @@ fn zirReifySliceArgTy( |
| 19470 | 19718 | |
| 19471 | 19719 | const comptime_reason: std.zig.SimpleComptimeReason, const in_scalar_ty: Type, const out_scalar_ty: Type = switch (info) { |
| 19472 | 19720 | // zig fmt: off |
| 19473 | .type_to_fn_param_attrs => .{ .fn_param_attrs, .type, try sema.getStdLangType(src, .@"Type.Fn.Param.Attributes") }, | |
| 19721 | .type_to_fn_param_attrs => .{ .fn_param_attrs, .type, try sema.getStdLangType(src, .@"Type.Fn.ParamAttributes") }, | |
| 19474 | 19722 | .string_to_struct_field_type => .{ .struct_field_types, .slice_const_u8, .type }, |
| 19475 | 19723 | .string_to_union_field_type => .{ .union_field_types, .slice_const_u8, .type }, |
| 19476 | .string_to_struct_field_attrs => .{ .struct_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.StructField.Attributes") }, | |
| 19477 | .string_to_union_field_attrs => .{ .union_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.UnionField.Attributes") }, | |
| 19724 | .string_to_struct_field_attrs => .{ .struct_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.Struct.FieldAttributes") }, | |
| 19725 | .string_to_union_field_attrs => .{ .union_field_attrs, .slice_const_u8, try sema.getStdLangType(src, .@"Type.Union.FieldAttributes") }, | |
| 19478 | 19726 | // zig fmt: on |
| 19479 | 19727 | }; |
| 19480 | 19728 | |
| ... | ... | @@ -19688,7 +19936,7 @@ fn zirReifyFn( |
| 19688 | 19936 | const ret_ty_src = block.builtinCallArgSrc(extra.node, 2); |
| 19689 | 19937 | const fn_attrs_src = block.builtinCallArgSrc(extra.node, 3); |
| 19690 | 19938 | |
| 19691 | const single_param_attrs_ty = try sema.getStdLangType(param_attrs_src, .@"Type.Fn.Param.Attributes"); | |
| 19939 | const single_param_attrs_ty = try sema.getStdLangType(param_attrs_src, .@"Type.Fn.ParamAttributes"); | |
| 19692 | 19940 | const fn_attrs_ty = try sema.getStdLangType(fn_attrs_src, .@"Type.Fn.Attributes"); |
| 19693 | 19941 | |
| 19694 | 19942 | const param_types_uncoerced = sema.resolveInst(extra.param_types); |
| ... | ... | @@ -19722,7 +19970,7 @@ fn zirReifyFn( |
| 19722 | 19970 | block, |
| 19723 | 19971 | param_attrs_src, |
| 19724 | 19972 | try param_attrs_arr.elemValue(pt, param_idx), |
| 19725 | std.lang.Type.Fn.Param.Attributes, | |
| 19973 | std.lang.Type.Fn.ParamAttributes, | |
| 19726 | 19974 | ); |
| 19727 | 19975 | try sema.checkParamType( |
| 19728 | 19976 | block, |
| ... | ... | @@ -19827,7 +20075,7 @@ fn zirReifyStruct( |
| 19827 | 20075 | }; |
| 19828 | 20076 | |
| 19829 | 20077 | const container_layout_ty = try sema.getStdLangType(layout_src, .@"Type.ContainerLayout"); |
| 19830 | const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.StructField.Attributes"); | |
| 20078 | const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.Struct.FieldAttributes"); | |
| 19831 | 20079 | |
| 19832 | 20080 | const layout_uncoerced = sema.resolveInst(extra.layout); |
| 19833 | 20081 | const layout_coerced = try sema.coerce(block, container_layout_ty, layout_uncoerced, layout_src); |
| ... | ... | @@ -19913,15 +20161,15 @@ fn zirReifyStruct( |
| 19913 | 20161 | const field_name = try sema.sliceToIpString(block, field_names_src, field_name_val, .{ .simple = .struct_field_names }); |
| 19914 | 20162 | |
| 19915 | 20163 | const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex( |
| 19916 | std.lang.Type.StructField.Attributes, | |
| 20164 | std.lang.Type.Struct.FieldAttributes, | |
| 19917 | 20165 | "comptime", |
| 19918 | 20166 | ).?); |
| 19919 | 20167 | const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex( |
| 19920 | std.lang.Type.StructField.Attributes, | |
| 20168 | std.lang.Type.Struct.FieldAttributes, | |
| 19921 | 20169 | "align", |
| 19922 | 20170 | ).?); |
| 19923 | 20171 | const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex( |
| 19924 | std.lang.Type.StructField.Attributes, | |
| 20172 | std.lang.Type.Struct.FieldAttributes, | |
| 19925 | 20173 | "default_value_ptr", |
| 19926 | 20174 | ).?); |
| 19927 | 20175 | |
| ... | ... | @@ -19998,15 +20246,15 @@ fn zirReifyStruct( |
| 19998 | 20246 | wip.field_types.get(ip)[field_idx] = field_ty.toIntern(); |
| 19999 | 20247 | |
| 20000 | 20248 | const field_attr_comptime = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex( |
| 20001 | std.lang.Type.StructField.Attributes, | |
| 20249 | std.lang.Type.Struct.FieldAttributes, | |
| 20002 | 20250 | "comptime", |
| 20003 | 20251 | ).?); |
| 20004 | 20252 | const field_attr_align = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex( |
| 20005 | std.lang.Type.StructField.Attributes, | |
| 20253 | std.lang.Type.Struct.FieldAttributes, | |
| 20006 | 20254 | "align", |
| 20007 | 20255 | ).?); |
| 20008 | 20256 | const field_attr_default_value_ptr = try field_attrs_val.fieldValue(pt, std.meta.fieldIndex( |
| 20009 | std.lang.Type.StructField.Attributes, | |
| 20257 | std.lang.Type.Struct.FieldAttributes, | |
| 20010 | 20258 | "default_value_ptr", |
| 20011 | 20259 | ).?); |
| 20012 | 20260 | |
| ... | ... | @@ -20107,7 +20355,7 @@ fn zirReifyUnion( |
| 20107 | 20355 | }; |
| 20108 | 20356 | |
| 20109 | 20357 | const container_layout_ty = try sema.getStdLangType(layout_src, .@"Type.ContainerLayout"); |
| 20110 | const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.UnionField.Attributes"); | |
| 20358 | const single_field_attrs_ty = try sema.getStdLangType(field_attrs_src, .@"Type.Union.FieldAttributes"); | |
| 20111 | 20359 | |
| 20112 | 20360 | const layout_uncoerced = sema.resolveInst(extra.layout); |
| 20113 | 20361 | const layout_coerced = try sema.coerce(block, container_layout_ty, layout_uncoerced, layout_src); |
| ... | ... | @@ -20196,7 +20444,7 @@ fn zirReifyUnion( |
| 20196 | 20444 | block, |
| 20197 | 20445 | field_attrs_src, |
| 20198 | 20446 | try field_attrs_arr.elemValue(pt, field_idx), |
| 20199 | std.lang.Type.UnionField.Attributes, | |
| 20447 | std.lang.Type.Union.FieldAttributes, | |
| 20200 | 20448 | ); |
| 20201 | 20449 | if (field_attrs.@"align") |bytes| { |
| 20202 | 20450 | if (layout == .@"packed") { |
| ... | ... | @@ -20245,7 +20493,7 @@ fn zirReifyUnion( |
| 20245 | 20493 | block, |
| 20246 | 20494 | .unneeded, |
| 20247 | 20495 | try field_attrs_arr.elemValue(pt, field_idx), |
| 20248 | std.lang.Type.UnionField.Attributes, | |
| 20496 | std.lang.Type.Union.FieldAttributes, | |
| 20249 | 20497 | ); |
| 20250 | 20498 | if (field_attrs.@"align") |bytes| { |
| 20251 | 20499 | // No source location; first loop checked this is valid. |
| ... | ... | @@ -25211,9 +25459,9 @@ fn addSafetyCheckExtra( |
| 25211 | 25459 | |
| 25212 | 25460 | try parent_block.instructions.ensureUnusedCapacity(gpa, 1); |
| 25213 | 25461 | |
| 25214 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".fields.len + | |
| 25462 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).@"struct".field_names.len + | |
| 25215 | 25463 | 1 + // The main block only needs space for the cond_br. |
| 25216 | @typeInfo(Air.CondBr).@"struct".fields.len + | |
| 25464 | @typeInfo(Air.CondBr).@"struct".field_names.len + | |
| 25217 | 25465 | 1 + // The ok branch of the cond_br only needs space for the br. |
| 25218 | 25466 | fail_block.instructions.items.len); |
| 25219 | 25467 | |
| ... | ... | @@ -33021,8 +33269,8 @@ pub fn getTmpAir(sema: Sema) Air { |
| 33021 | 33269 | } |
| 33022 | 33270 | |
| 33023 | 33271 | pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 { |
| 33024 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 33025 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, fields.len); | |
| 33272 | const field_count = std.meta.fieldNames(@TypeOf(extra)).len; | |
| 33273 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, field_count); | |
| 33026 | 33274 | return sema.addExtraAssumeCapacity(extra); |
| 33027 | 33275 | } |
| 33028 | 33276 | |
| ... | ... | @@ -33032,15 +33280,15 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 { |
| 33032 | 33280 | return result; |
| 33033 | 33281 | } |
| 33034 | 33282 | |
| 33035 | fn payloadToExtraItems(data: anytype) [@typeInfo(@TypeOf(data)).@"struct".fields.len]u32 { | |
| 33036 | const fields = @typeInfo(@TypeOf(data)).@"struct".fields; | |
| 33037 | var result: [fields.len]u32 = undefined; | |
| 33038 | inline for (&result, fields) |*val, field| { | |
| 33039 | val.* = switch (field.type) { | |
| 33040 | u32 => @field(data, field.name), | |
| 33041 | i32, Air.CondBr.BranchHints, Air.Asm.Flags => @bitCast(@field(data, field.name)), | |
| 33042 | Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(data, field.name)), | |
| 33043 | else => @compileError("bad field type: " ++ @typeName(field.type)), | |
| 33283 | fn payloadToExtraItems(data: anytype) [@typeInfo(@TypeOf(data)).@"struct".field_names.len]u32 { | |
| 33284 | const info = @typeInfo(@TypeOf(data)).@"struct"; | |
| 33285 | var result: [info.field_names.len]u32 = undefined; | |
| 33286 | inline for (&result, info.field_names, info.field_types) |*val, field_name, field_type| { | |
| 33287 | val.* = switch (field_type) { | |
| 33288 | u32 => @field(data, field_name), | |
| 33289 | i32, Air.CondBr.BranchHints, Air.Asm.Flags => @bitCast(@field(data, field_name)), | |
| 33290 | Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(data, field_name)), | |
| 33291 | else => @compileError("bad field type: " ++ @typeName(field_type)), | |
| 33044 | 33292 | }; |
| 33045 | 33293 | } |
| 33046 | 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 | 2288 | |
| 2289 | 2289 | .@"struct" => |@"struct"| switch (interpret_mode) { |
| 2290 | 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 | 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 | 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 | 2297 | return result; |
| 2298 | 2298 | }, |
| 2299 | 2299 | .by_name => { |
| 2300 | 2300 | const struct_obj = zcu.typeToStruct(ty) orelse return error.TypeMismatch; |
| 2301 | 2301 | var result: T = undefined; |
| 2302 | inline for (@"struct".fields) |field| { | |
| 2303 | const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field.name, .no_embedded_nulls); | |
| 2304 | @field(result, field.name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: { | |
| 2302 | inline for (@"struct".field_names, @"struct".field_types, @"struct".field_attrs) |field_name, field_type, field_attr| { | |
| 2303 | const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field_name, .no_embedded_nulls); | |
| 2304 | @field(result, field_name) = if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| f: { | |
| 2305 | 2305 | const field_val = try val.fieldValue(pt, field_idx); |
| 2306 | break :f try field_val.interpret(field.type, pt); | |
| 2307 | } else (field.defaultValue() orelse return error.TypeMismatch); | |
| 2306 | break :f try field_val.interpret(field_type, pt); | |
| 2307 | } else (field_attr.defaultValue(field_type) orelse return error.TypeMismatch); | |
| 2308 | 2308 | } |
| 2309 | 2309 | return result; |
| 2310 | 2310 | }, |
| ... | ... | @@ -2385,11 +2385,11 @@ pub fn uninterpret(val: anytype, ty: Type, pt: Zcu.PerThread) error{ OutOfMemory |
| 2385 | 2385 | |
| 2386 | 2386 | .@"struct" => |@"struct"| switch (interpret_mode) { |
| 2387 | 2387 | .direct => { |
| 2388 | if (ty.structFieldCount(zcu) != @"struct".fields.len) return error.TypeMismatch; | |
| 2389 | var field_vals: [@"struct".fields.len]InternPool.Index = undefined; | |
| 2390 | inline for (&field_vals, @"struct".fields, 0..) |*field_val, field, field_idx| { | |
| 2388 | if (ty.structFieldCount(zcu) != @"struct".field_names.len) return error.TypeMismatch; | |
| 2389 | var field_vals: [@"struct".field_names.len]InternPool.Index = undefined; | |
| 2390 | inline for (&field_vals, @"struct".field_names, 0..) |*field_val, field_name, field_idx| { | |
| 2391 | 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 | 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 | 2399 | const field_vals = try zcu.gpa.alloc(InternPool.Index, want_fields_len); |
| 2400 | 2400 | defer zcu.gpa.free(field_vals); |
| 2401 | 2401 | @memset(field_vals, .none); |
| 2402 | inline for (@"struct".fields) |field| { | |
| 2403 | const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field.name, .no_embedded_nulls); | |
| 2402 | inline for (@"struct".field_names) |field_name| { | |
| 2403 | const field_name_ip = try ip.getOrPutString(zcu.gpa, io, pt.tid, field_name, .no_embedded_nulls); | |
| 2404 | 2404 | if (struct_obj.nameIndex(ip, field_name_ip)) |field_idx| { |
| 2405 | 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 | 2409 | for (field_vals, 0..) |*field_val, field_idx| { |
src/Zcu.zig+15-25| ... | ... | @@ -48,12 +48,12 @@ const ZonGen = std.zig.ZonGen; |
| 48 | 48 | comptime { |
| 49 | 49 | @setEvalBranchQuota(4000); |
| 50 | 50 | for ( |
| 51 | @typeInfo(Zir.Inst.Ref).@"enum".fields, | |
| 52 | @typeInfo(Air.Inst.Ref).@"enum".fields, | |
| 53 | @typeInfo(InternPool.Index).@"enum".fields, | |
| 54 | ) |zir_field, air_field, ip_field| { | |
| 55 | assert(mem.eql(u8, zir_field.name, ip_field.name)); | |
| 56 | assert(mem.eql(u8, air_field.name, ip_field.name)); | |
| 51 | @typeInfo(Zir.Inst.Ref).@"enum".field_names, | |
| 52 | @typeInfo(Air.Inst.Ref).@"enum".field_names, | |
| 53 | @typeInfo(InternPool.Index).@"enum".field_names, | |
| 54 | ) |zir_field_name, air_field_name, ip_field_name| { | |
| 55 | assert(mem.eql(u8, zir_field_name, ip_field_name)); | |
| 56 | assert(mem.eql(u8, air_field_name, ip_field_name)); | |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| ... | ... | @@ -448,8 +448,7 @@ pub const StdLangDecl = enum { |
| 448 | 448 | |
| 449 | 449 | Type, |
| 450 | 450 | @"Type.Fn", |
| 451 | @"Type.Fn.Param", | |
| 452 | @"Type.Fn.Param.Attributes", | |
| 451 | @"Type.Fn.ParamAttributes", | |
| 453 | 452 | @"Type.Fn.Attributes", |
| 454 | 453 | @"Type.Int", |
| 455 | 454 | @"Type.Float", |
| ... | ... | @@ -459,20 +458,16 @@ pub const StdLangDecl = enum { |
| 459 | 458 | @"Type.Array", |
| 460 | 459 | @"Type.Vector", |
| 461 | 460 | @"Type.Optional", |
| 462 | @"Type.Error", | |
| 463 | 461 | @"Type.ErrorUnion", |
| 464 | @"Type.EnumField", | |
| 462 | @"Type.ErrorSet", | |
| 465 | 463 | @"Type.Enum", |
| 466 | 464 | @"Type.Enum.Mode", |
| 467 | 465 | @"Type.Union", |
| 468 | @"Type.UnionField", | |
| 469 | @"Type.UnionField.Attributes", | |
| 466 | @"Type.Union.FieldAttributes", | |
| 470 | 467 | @"Type.Struct", |
| 471 | @"Type.StructField", | |
| 472 | @"Type.StructField.Attributes", | |
| 468 | @"Type.Struct.FieldAttributes", | |
| 473 | 469 | @"Type.ContainerLayout", |
| 474 | 470 | @"Type.Opaque", |
| 475 | @"Type.Declaration", | |
| 476 | 471 | |
| 477 | 472 | panic, |
| 478 | 473 | @"panic.call", |
| ... | ... | @@ -533,8 +528,7 @@ pub const StdLangDecl = enum { |
| 533 | 528 | |
| 534 | 529 | .Type, |
| 535 | 530 | .@"Type.Fn", |
| 536 | .@"Type.Fn.Param", | |
| 537 | .@"Type.Fn.Param.Attributes", | |
| 531 | .@"Type.Fn.ParamAttributes", | |
| 538 | 532 | .@"Type.Fn.Attributes", |
| 539 | 533 | .@"Type.Int", |
| 540 | 534 | .@"Type.Float", |
| ... | ... | @@ -544,20 +538,16 @@ pub const StdLangDecl = enum { |
| 544 | 538 | .@"Type.Array", |
| 545 | 539 | .@"Type.Vector", |
| 546 | 540 | .@"Type.Optional", |
| 547 | .@"Type.Error", | |
| 548 | 541 | .@"Type.ErrorUnion", |
| 549 | .@"Type.EnumField", | |
| 542 | .@"Type.ErrorSet", | |
| 550 | 543 | .@"Type.Enum", |
| 551 | 544 | .@"Type.Enum.Mode", |
| 552 | 545 | .@"Type.Union", |
| 553 | .@"Type.UnionField", | |
| 554 | .@"Type.UnionField.Attributes", | |
| 546 | .@"Type.Union.FieldAttributes", | |
| 555 | 547 | .@"Type.Struct", |
| 556 | .@"Type.StructField", | |
| 557 | .@"Type.StructField.Attributes", | |
| 548 | .@"Type.Struct.FieldAttributes", | |
| 558 | 549 | .@"Type.ContainerLayout", |
| 559 | 550 | .@"Type.Opaque", |
| 560 | .@"Type.Declaration", | |
| 561 | 551 | => .type, |
| 562 | 552 | |
| 563 | 553 | .panic => .type, |
| ... | ... | @@ -611,7 +601,7 @@ pub const StdLangDecl = enum { |
| 611 | 601 | .VaList => .va_list, |
| 612 | 602 | .assembly, .@"assembly.Clobbers" => .assembly, |
| 613 | 603 | else => { |
| 614 | if (@intFromEnum(decl) <= @intFromEnum(StdLangDecl.@"Type.Declaration")) { | |
| 604 | if (@intFromEnum(decl) <= @intFromEnum(StdLangDecl.@"Type.Opaque")) { | |
| 615 | 605 | return .main; |
| 616 | 606 | } else { |
| 617 | 607 | return .panic; |
src/Zcu/PerThread.zig+2-2| ... | ... | @@ -3344,7 +3344,7 @@ fn analyzeFuncBodyInner( |
| 3344 | 3344 | ip.funcSetHasErrorTrace(io, func_index, fn_ty_info.cc == .auto); |
| 3345 | 3345 | |
| 3346 | 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 | 3348 | try sema.air_extra.ensureTotalCapacity(gpa, reserved_count); |
| 3349 | 3349 | sema.air_extra.items.len += reserved_count; |
| 3350 | 3350 | |
| ... | ... | @@ -3477,7 +3477,7 @@ fn analyzeFuncBodyInner( |
| 3477 | 3477 | } |
| 3478 | 3478 | |
| 3479 | 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 | 3481 | inner_block.instructions.items.len); |
| 3482 | 3482 | const main_block_index = sema.addExtraAssumeCapacity(Air.Block{ |
| 3483 | 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 | 41 | .void, .bool, .int, .float, .pointer, .comptime_float, .comptime_int, .@"enum" => return zon_value, |
| 42 | 42 | .@"struct" => |zon_struct| switch (@typeInfo(Result)) { |
| 43 | 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 | 45 | const elems = comptime blk: { |
| 46 | 46 | var temp_elems: [zon_value.len]result_pointer.child = undefined; |
| 47 | 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 | 52 | .@"struct" => |result_struct| { |
| 53 | 53 | comptime var used_zon_fields = 0; |
| 54 | 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: { | |
| 56 | used_zon_fields += 1; | |
| 57 | break :result zonCast(@FieldType(Result, result_field.name), @field(zon_value, result_field.name), symbols); | |
| 58 | } else result_field.defaultValue() orelse @compileError(std.fmt.comptimePrint("missing zon field '{s}': {} <- {any}", .{ result_field.name, Result, zon_value })); | |
| 59 | if (used_zon_fields != zon_struct.fields.len) @compileError(std.fmt.comptimePrint("unused zon field: {} <- {any}", .{ Result, zon_value })); | |
| 55 | inline for (result_struct.field_names, result_struct.field_types, result_struct.field_attrs) |result_field_name, result_field_type, result_field_attrs| | |
| 56 | @field(result, result_field_name) = if (@hasField(ZonValue, result_field_name)) result: { | |
| 57 | used_zon_fields += 1; | |
| 58 | break :result zonCast(@FieldType(Result, result_field_name), @field(zon_value, result_field_name), symbols); | |
| 59 | } else result_field_attrs.defaultValue(result_field_type) orelse @compileError(std.fmt.comptimePrint("missing zon field '{s}': {} <- {any}", .{ result_field_name, Result, zon_value })); | |
| 60 | if (used_zon_fields != zon_struct.field_names.len) @compileError(std.fmt.comptimePrint("unused zon field: {} <- {any}", .{ Result, zon_value })); | |
| 60 | 61 | return result; |
| 61 | 62 | }, |
| 62 | 63 | .@"union" => { |
| 63 | if (zon_struct.fields.len != 1) @compileError(std.fmt.comptimePrint("{} <- {any}", .{ Result, zon_value })); | |
| 64 | const field_name = zon_struct.fields[0].name; | |
| 64 | if (zon_struct.field_names.len != 1) @compileError(std.fmt.comptimePrint("{} <- {any}", .{ Result, zon_value })); | |
| 65 | const field_name = zon_struct.field_names[0]; | |
| 65 | 66 | return @unionInit( |
| 66 | 67 | Result, |
| 67 | 68 | field_name, |
| ... | ... | @@ -106,12 +107,12 @@ const matchers = matchers: { |
| 106 | 107 | var mut_matchers: [instructions.len]*const fn (as: *Assemble) error{InvalidSyntax}!?Instruction = undefined; |
| 107 | 108 | for (instructions, &mut_matchers) |instruction, *matcher| matcher.* = struct { |
| 108 | 109 | fn match(as: *Assemble) !?Instruction { |
| 109 | comptime for (@typeInfo(@TypeOf(instruction)).@"struct".fields) |field| { | |
| 110 | if (std.mem.eql(u8, field.name, "requires")) continue; | |
| 111 | if (std.mem.eql(u8, field.name, "pattern")) continue; | |
| 112 | if (std.mem.eql(u8, field.name, "symbols")) continue; | |
| 113 | if (std.mem.eql(u8, field.name, "encode")) continue; | |
| 114 | @compileError("unexpected field '" ++ field.name ++ "'"); | |
| 110 | comptime for (@typeInfo(@TypeOf(instruction)).@"struct".field_names) |field_name| { | |
| 111 | if (std.mem.eql(u8, field_name, "requires")) continue; | |
| 112 | if (std.mem.eql(u8, field_name, "pattern")) continue; | |
| 113 | if (std.mem.eql(u8, field_name, "symbols")) continue; | |
| 114 | if (std.mem.eql(u8, field_name, "encode")) continue; | |
| 115 | @compileError("unexpected field '" ++ field_name ++ "'"); | |
| 115 | 116 | }; |
| 116 | 117 | if (@hasField(@TypeOf(instruction), "requires")) _ = zonCast( |
| 117 | 118 | []const std.Target.aarch64.Feature, |
| ... | ... | @@ -119,12 +120,12 @@ const matchers = matchers: { |
| 119 | 120 | .{}, |
| 120 | 121 | ); |
| 121 | 122 | var symbols: Symbols: { |
| 122 | const symbols = @typeInfo(@TypeOf(instruction.symbols)).@"struct".fields; | |
| 123 | var field_names: [symbols.len][]const u8 = undefined; | |
| 124 | var field_types: [symbols.len]type = undefined; | |
| 125 | for (symbols, &field_names, &field_types) |symbol, *field_name, *FieldType| { | |
| 126 | field_name.* = symbol.name; | |
| 127 | FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol.name), .{}).Storage(); | |
| 123 | const symbol_names = @typeInfo(@TypeOf(instruction.symbols)).@"struct".field_names; | |
| 124 | var field_names: [symbol_names.len][]const u8 = undefined; | |
| 125 | var field_types: [symbol_names.len]type = undefined; | |
| 126 | for (symbol_names, &field_names, &field_types) |symbol_name, *field_name, *FieldType| { | |
| 127 | field_name.* = symbol_name; | |
| 128 | FieldType.* = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).Storage(); | |
| 128 | 129 | } |
| 129 | 130 | break :Symbols @Struct(.auto, null, &field_names, &field_types, &@splat(.{})); |
| 130 | 131 | } = undefined; |
| ... | ... | @@ -158,8 +159,8 @@ const matchers = matchers: { |
| 158 | 159 | const encode = @field(Instruction, @tagName(instruction.encode[0])); |
| 159 | 160 | const Encode = @TypeOf(encode); |
| 160 | 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 | arg.* = zonCast(param.type.?, instruction.encode[encode_index], symbols); | |
| 162 | inline for (&args, @typeInfo(Encode).@"fn".param_types, 1..instruction.encode.len) |*arg, param_type, encode_index| | |
| 163 | arg.* = zonCast(param_type.?, instruction.encode[encode_index], symbols); | |
| 163 | 164 | return @call(.auto, encode, args); |
| 164 | 165 | } else if (pattern_token[0] == '<') { |
| 165 | 166 | const symbol_name = comptime pattern_token[1 .. std.mem.indexOfScalarPos(u8, pattern_token, 1, '|') orelse |
| ... | ... | @@ -369,7 +370,7 @@ const SymbolSpec = union(enum) { |
| 369 | 370 | var buf: [ |
| 370 | 371 | max_len: { |
| 371 | 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 | 374 | break :max_len max_len; |
| 374 | 375 | } + 1 |
| 375 | 376 | ]u8 = undefined; |
| ... | ... | @@ -466,7 +467,7 @@ const SymbolSpec = union(enum) { |
| 466 | 467 | var buf: [ |
| 467 | 468 | max_len: { |
| 468 | 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 | 471 | break :max_len max_len; |
| 471 | 472 | } + 1 |
| 472 | 473 | ]u8 = undefined; |
| ... | ... | @@ -487,7 +488,7 @@ const SymbolSpec = union(enum) { |
| 487 | 488 | var buf: [ |
| 488 | 489 | max_len: { |
| 489 | 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 | 492 | break :max_len max_len; |
| 492 | 493 | } + 1 |
| 493 | 494 | ]u8 = undefined; |
| ... | ... | @@ -508,7 +509,7 @@ const SymbolSpec = union(enum) { |
| 508 | 509 | var buf: [ |
| 509 | 510 | max_len: { |
| 510 | 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 | 513 | break :max_len max_len; |
| 513 | 514 | } + 1 |
| 514 | 515 | ]u8 = undefined; |
src/codegen/aarch64/Select.zig+5-17| ... | ... | @@ -8891,14 +8891,8 @@ pub const Value = struct { |
| 8891 | 8891 | |
| 8892 | 8892 | pub const Tag = @typeInfo(Parent).@"union".tag_type.?; |
| 8893 | 8893 | pub const Payload = Payload: { |
| 8894 | const fields = @typeInfo(Parent).@"union".fields; | |
| 8895 | var types: [fields.len]type = undefined; | |
| 8896 | var names: [fields.len][]const u8 = undefined; | |
| 8897 | for (fields, &types, &names) |f, *ty, *name| { | |
| 8898 | ty.* = f.type; | |
| 8899 | name.* = f.name; | |
| 8900 | } | |
| 8901 | break :Payload @Union(.auto, null, &names, &types, &@splat(.{})); | |
| 8894 | const info = @typeInfo(Parent).@"union"; | |
| 8895 | break :Payload @Union(.auto, null, info.field_names, info.field_types[0..], &@splat(.{})); | |
| 8902 | 8896 | }; |
| 8903 | 8897 | }; |
| 8904 | 8898 | |
| ... | ... | @@ -8916,14 +8910,8 @@ pub const Value = struct { |
| 8916 | 8910 | |
| 8917 | 8911 | pub const Tag = @typeInfo(Location).@"union".tag_type.?; |
| 8918 | 8912 | pub const Payload = Payload: { |
| 8919 | const fields = @typeInfo(Location).@"union".fields; | |
| 8920 | var types: [fields.len]type = undefined; | |
| 8921 | var names: [fields.len][]const u8 = undefined; | |
| 8922 | for (fields, &types, &names) |f, *ty, *name| { | |
| 8923 | ty.* = f.type; | |
| 8924 | name.* = f.name; | |
| 8925 | } | |
| 8926 | break :Payload @Union(.auto, null, &names, &types, &@splat(.{})); | |
| 8913 | const info = @typeInfo(Location).@"union"; | |
| 8914 | break :Payload @Union(.auto, null, info.field_names, info.field_types[0..], &@splat(.{})); | |
| 8927 | 8915 | }; |
| 8928 | 8916 | }; |
| 8929 | 8917 | |
| ... | ... | @@ -11257,7 +11245,7 @@ fn dumpValuesInner(isel: *Select, which: WhichValues) !void { |
| 11257 | 11245 | var reverse_live_registers: std.AutoHashMapUnmanaged(Value.Index, Register.Alias) = .empty; |
| 11258 | 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 | 11249 | var live_reg_it = isel.live_registers.iterator(); |
| 11262 | 11250 | while (live_reg_it.next()) |live_reg_entry| switch (live_reg_entry.value.*) { |
| 11263 | 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 | 1271 | if (symbol_it.next() != null) break :encoded; |
| 1272 | 1272 | return .{ .op0 = op0, .op1 = op1, .CRn = CRn, .CRm = CRm, .op2 = op2 }; |
| 1273 | 1273 | } |
| 1274 | inline for (@typeInfo(System).@"struct".decls) |decl| { | |
| 1275 | if (@TypeOf(@field(System, decl.name)) != System) continue; | |
| 1276 | if (toLowerEqlAssertLower(reg, decl.name)) return @field(System, decl.name); | |
| 1274 | inline for (@typeInfo(System).@"struct".decl_names) |decl_name| { | |
| 1275 | if (@TypeOf(@field(System, decl_name)) != System) continue; | |
| 1276 | if (toLowerEqlAssertLower(reg, decl_name)) return @field(System, decl_name); | |
| 1277 | 1277 | } |
| 1278 | 1278 | return null; |
| 1279 | 1279 | } |
| ... | ... | @@ -16561,30 +16561,30 @@ pub const Instruction = packed union { |
| 16561 | 16561 | if (info.layout != .@"packed" or @bitSizeOf(Type) != @bitSizeOf(Backing)) { |
| 16562 | 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 | 16566 | .@"struct" => |info| { |
| 16567 | 16567 | if (info.layout != .@"packed" or info.backing_integer != Backing) { |
| 16568 | 16568 | @compileLog(name ++ " should have u32 abi"); |
| 16569 | 16569 | } |
| 16570 | 16570 | var bit_offset = 0; |
| 16571 | for (info.fields) |field| { | |
| 16572 | if (std.mem.startsWith(u8, field.name, "encoded")) { | |
| 16573 | if (if (std.fmt.parseInt(u5, field.name["encoded".len..], 10)) |encoded_bit_offset| encoded_bit_offset != bit_offset else |_| true) { | |
| 16574 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field.name, bit_offset })); | |
| 16571 | for (info.field_names, info.field_types, info.field_attrs) |field_name, field_type, field_attrs| { | |
| 16572 | if (std.mem.startsWith(u8, field_name, "encoded")) { | |
| 16573 | if (if (std.fmt.parseInt(u5, field_name["encoded".len..], 10)) |encoded_bit_offset| encoded_bit_offset != bit_offset else |_| true) { | |
| 16574 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field_name, bit_offset })); | |
| 16575 | 16575 | } |
| 16576 | if (field.default_value_ptr != null) { | |
| 16577 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field.name, bit_offset })); | |
| 16576 | if (field_attrs.default_value_ptr != null) { | |
| 16577 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field_name, bit_offset })); | |
| 16578 | 16578 | } |
| 16579 | } else if (std.mem.startsWith(u8, field.name, "decoded")) { | |
| 16580 | if (if (std.fmt.parseInt(u5, field.name["decoded".len..], 10)) |decoded_bit_offset| decoded_bit_offset != bit_offset else |_| true) { | |
| 16581 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field.name, bit_offset })); | |
| 16579 | } else if (std.mem.startsWith(u8, field_name, "decoded")) { | |
| 16580 | if (if (std.fmt.parseInt(u5, field_name["decoded".len..], 10)) |decoded_bit_offset| decoded_bit_offset != bit_offset else |_| true) { | |
| 16581 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named decoded{d}", .{ name, field_name, bit_offset })); | |
| 16582 | 16582 | } |
| 16583 | if (field.default_value_ptr == null) { | |
| 16584 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field.name, bit_offset })); | |
| 16583 | if (field_attrs.default_value_ptr == null) { | |
| 16584 | @compileError(std.fmt.comptimePrint("{s}.{s} should be named encoded{d}", .{ name, field_name, bit_offset })); | |
| 16585 | 16585 | } |
| 16586 | 16586 | } |
| 16587 | bit_offset += @bitSizeOf(field.type); | |
| 16587 | bit_offset += @bitSizeOf(field_type); | |
| 16588 | 16588 | } |
| 16589 | 16589 | }, |
| 16590 | 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 | 190 | /// The goal of this function is to return the same ID for `zero` and `x0` but two |
| 191 | 191 | /// seperate IDs for `x0` and `f0`. We will assume that each register set has 32 registers |
| 192 | 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 | 194 | const base = switch (@intFromEnum(reg)) { |
| 195 | 195 | // zig fmt: off |
| 196 | 196 | @intFromEnum(Register.zero) ... @intFromEnum(Register.x31) => @intFromEnum(Register.zero), |
| ... | ... | @@ -251,7 +251,7 @@ pub const FrameIndex = enum(u32) { |
| 251 | 251 | /// Other indices are used for local variable stack slots |
| 252 | 252 | _, |
| 253 | 253 | |
| 254 | pub const named_count = @typeInfo(FrameIndex).@"enum".fields.len; | |
| 254 | pub const named_count = @typeInfo(FrameIndex).@"enum".field_names.len; | |
| 255 | 255 | |
| 256 | 256 | pub fn isNamed(fi: FrameIndex) bool { |
| 257 | 257 | return @intFromEnum(fi) < named_count; |
src/codegen/riscv64/encoding.zig+2-2| ... | ... | @@ -498,8 +498,8 @@ pub const Instruction = union(Lir.Format) { |
| 498 | 498 | extra: u32, |
| 499 | 499 | |
| 500 | 500 | comptime { |
| 501 | for (std.meta.fields(Instruction)) |field| { | |
| 502 | assert(@bitSizeOf(field.type) == 32); | |
| 501 | for (std.meta.fieldTypes(Instruction)) |field_type| { | |
| 502 | assert(@bitSizeOf(field_type) == 32); | |
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 |
src/codegen/sparc64/Mir.zig+3-3| ... | ... | @@ -410,11 +410,11 @@ pub fn emit( |
| 410 | 410 | /// Returns the requested data, as well as the new index which is at the start of the |
| 411 | 411 | /// trailers for the object. |
| 412 | 412 | pub 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 | 414 | var i: usize = index; |
| 415 | 415 | var result: T = undefined; |
| 416 | inline for (fields) |field| { | |
| 417 | @field(result, field.name) = switch (field.type) { | |
| 416 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 417 | @field(result, field_name) = switch (field_type) { | |
| 418 | 418 | u32 => mir.extra[i], |
| 419 | 419 | i32 => @as(i32, @bitCast(mir.extra[i])), |
| 420 | 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 | 102 | } |
| 103 | 103 | |
| 104 | 104 | fn writeOperands(section: *Section, comptime Operands: type, operands: Operands) void { |
| 105 | const fields = switch (@typeInfo(Operands)) { | |
| 106 | .@"struct" => |info| info.fields, | |
| 105 | const info = switch (@typeInfo(Operands)) { | |
| 106 | .@"struct" => |info| info, | |
| 107 | 107 | .void => return, |
| 108 | 108 | else => unreachable, |
| 109 | 109 | }; |
| 110 | inline for (fields) |field| { | |
| 111 | section.writeOperand(field.type, @field(operands, field.name)); | |
| 110 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 111 | section.writeOperand(field_type, @field(operands, field_name)); | |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| ... | ... | @@ -171,12 +171,13 @@ fn writeContextDependentNumber(section: *Section, operand: spec.LiteralContextDe |
| 171 | 171 | |
| 172 | 172 | fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand) void { |
| 173 | 173 | var mask: Word = 0; |
| 174 | inline for (@typeInfo(Operand).@"struct".fields, 0..) |field, bit| { | |
| 175 | switch (@typeInfo(field.type)) { | |
| 176 | .optional => if (@field(operand, field.name) != null) { | |
| 174 | const info = @typeInfo(Operand).@"struct"; | |
| 175 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, bit| { | |
| 176 | switch (@typeInfo(field_type)) { | |
| 177 | .optional => if (@field(operand, field_name) != null) { | |
| 177 | 178 | mask |= 1 << @as(u5, @intCast(bit)); |
| 178 | 179 | }, |
| 179 | .bool => if (@field(operand, field.name)) { | |
| 180 | .bool => if (@field(operand, field_name)) { | |
| 180 | 181 | mask |= 1 << @as(u5, @intCast(bit)); |
| 181 | 182 | }, |
| 182 | 183 | else => unreachable, |
| ... | ... | @@ -185,10 +186,10 @@ fn writeExtendedMask(section: *Section, comptime Operand: type, operand: Operand |
| 185 | 186 | |
| 186 | 187 | section.writeWord(mask); |
| 187 | 188 | |
| 188 | inline for (@typeInfo(Operand).@"struct".fields) |field| { | |
| 189 | switch (@typeInfo(field.type)) { | |
| 190 | .optional => |info| if (@field(operand, field.name)) |child| { | |
| 191 | section.writeOperands(info.child, child); | |
| 189 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 190 | switch (@typeInfo(field_type)) { | |
| 191 | .optional => |opt_info| if (@field(operand, field_name)) |child| { | |
| 192 | section.writeOperands(opt_info.child, child); | |
| 192 | 193 | }, |
| 193 | 194 | .bool => {}, |
| 194 | 195 | else => unreachable, |
| ... | ... | @@ -213,15 +214,15 @@ fn instructionSize(comptime opcode: spec.Opcode, operands: opcode.Operands()) us |
| 213 | 214 | } |
| 214 | 215 | |
| 215 | 216 | fn operandsSize(comptime Operands: type, operands: Operands) usize { |
| 216 | const fields = switch (@typeInfo(Operands)) { | |
| 217 | .@"struct" => |info| info.fields, | |
| 217 | const info = switch (@typeInfo(Operands)) { | |
| 218 | .@"struct" => |info| info, | |
| 218 | 219 | .void => return 0, |
| 219 | 220 | else => unreachable, |
| 220 | 221 | }; |
| 221 | 222 | |
| 222 | 223 | var total: usize = 0; |
| 223 | inline for (fields) |field| { | |
| 224 | total += operandSize(field.type, @field(operands, field.name)); | |
| 224 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 225 | total += operandSize(field_type, @field(operands, field_name)); | |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | 228 | return total; |
| ... | ... | @@ -252,9 +253,9 @@ fn operandSize(comptime Operand: type, operand: Operand) usize { |
| 252 | 253 | if (struct_info.layout == .@"packed") return 1; |
| 253 | 254 | |
| 254 | 255 | var total: usize = 0; |
| 255 | inline for (@typeInfo(Operand).@"struct".fields) |field| { | |
| 256 | switch (@typeInfo(field.type)) { | |
| 257 | .optional => |info| if (@field(operand, field.name)) |child| { | |
| 256 | inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| { | |
| 257 | switch (@typeInfo(field_type)) { | |
| 258 | .optional => |info| if (@field(operand, field_name)) |child| { | |
| 258 | 259 | total += operandsSize(info.child, child); |
| 259 | 260 | }, |
| 260 | 261 | .bool => {}, |
src/codegen/wasm/CodeGen.zig+9-9| ... | ... | @@ -563,24 +563,24 @@ fn addCallIntrinsic(cg: *CodeGen, intrinsic: Mir.Intrinsic) error{OutOfMemory}!v |
| 563 | 563 | /// Appends entries to `mir_extra` based on the type of `extra`. |
| 564 | 564 | /// Returns the index into `mir_extra` |
| 565 | 565 | fn addExtra(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 { |
| 566 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 567 | try cg.mir_extra.ensureUnusedCapacity(cg.gpa, fields.len); | |
| 566 | const field_count = std.meta.fieldNames(@TypeOf(extra)).len; | |
| 567 | try cg.mir_extra.ensureUnusedCapacity(cg.gpa, field_count); | |
| 568 | 568 | return cg.addExtraAssumeCapacity(extra); |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /// Appends entries to `mir_extra` based on the type of `extra`. |
| 572 | 572 | /// Returns the index into `mir_extra` |
| 573 | 573 | fn addExtraAssumeCapacity(cg: *CodeGen, extra: anytype) error{OutOfMemory}!u32 { |
| 574 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 574 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 575 | 575 | const result: u32 = @intCast(cg.mir_extra.items.len); |
| 576 | inline for (fields) |field| { | |
| 577 | cg.mir_extra.appendAssumeCapacity(switch (field.type) { | |
| 578 | u32 => @field(extra, field.name), | |
| 579 | i32 => @bitCast(@field(extra, field.name)), | |
| 576 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 577 | cg.mir_extra.appendAssumeCapacity(switch (field_type) { | |
| 578 | u32 => @field(extra, field_name), | |
| 579 | i32 => @bitCast(@field(extra, field_name)), | |
| 580 | 580 | InternPool.Index, |
| 581 | 581 | InternPool.Nav.Index, |
| 582 | => @intFromEnum(@field(extra, field.name)), | |
| 583 | else => |field_type| @compileError("Unsupported field type " ++ @typeName(field_type)), | |
| 582 | => @intFromEnum(@field(extra, field_name)), | |
| 583 | else => @compileError("Unsupported field type " ++ @typeName(field_type)), | |
| 584 | 584 | }); |
| 585 | 585 | } |
| 586 | 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 | 731 | } |
| 732 | 732 | |
| 733 | 733 | pub 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 | 735 | var i: usize = index; |
| 736 | 736 | var result: T = undefined; |
| 737 | inline for (fields) |field| { | |
| 738 | @field(result, field.name) = switch (field.type) { | |
| 737 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 738 | @field(result, field_name) = switch (field_type) { | |
| 739 | 739 | u32 => self.extra[i], |
| 740 | 740 | i32 => @bitCast(self.extra[i]), |
| 741 | 741 | Wasm.UavsObjIndex, |
| ... | ... | @@ -743,7 +743,7 @@ pub fn extraData(self: *const Mir, comptime T: type, index: usize) struct { data |
| 743 | 743 | InternPool.Nav.Index, |
| 744 | 744 | InternPool.Index, |
| 745 | 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 | 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 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | fn addExtra(self: *CodeGen, extra: anytype) Allocator.Error!u32 { |
| 1217 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 1218 | try self.mir_extra.ensureUnusedCapacity(self.gpa, fields.len); | |
| 1217 | const field_count = std.meta.fieldNames(@TypeOf(extra)).len; | |
| 1218 | try self.mir_extra.ensureUnusedCapacity(self.gpa, field_count); | |
| 1219 | 1219 | return self.addExtraAssumeCapacity(extra); |
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | fn addExtraAssumeCapacity(self: *CodeGen, extra: anytype) u32 { |
| 1223 | const fields = std.meta.fields(@TypeOf(extra)); | |
| 1223 | const info = @typeInfo(@TypeOf(extra)).@"struct"; | |
| 1224 | 1224 | const result: u32 = @intCast(self.mir_extra.items.len); |
| 1225 | inline for (fields) |field| { | |
| 1226 | self.mir_extra.appendAssumeCapacity(switch (field.type) { | |
| 1227 | u32 => @field(extra, field.name), | |
| 1228 | i32, Mir.Memory.Info => @bitCast(@field(extra, field.name)), | |
| 1229 | FrameIndex => @intFromEnum(@field(extra, field.name)), | |
| 1230 | else => @compileError("bad field type: " ++ field.name ++ ": " ++ @typeName(field.type)), | |
| 1225 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1226 | self.mir_extra.appendAssumeCapacity(switch (field_type) { | |
| 1227 | u32 => @field(extra, field_name), | |
| 1228 | i32, Mir.Memory.Info => @bitCast(@field(extra, field_name)), | |
| 1229 | FrameIndex => @intFromEnum(@field(extra, field_name)), | |
| 1230 | else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)), | |
| 1231 | 1231 | }); |
| 1232 | 1232 | } |
| 1233 | 1233 | return result; |
| ... | ... | @@ -177140,7 +177140,7 @@ fn airBr(self: *CodeGen, inst: Air.Inst.Index) !void { |
| 177140 | 177140 | } |
| 177141 | 177141 | |
| 177142 | 177142 | fn 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 | 177144 | const pt = self.pt; |
| 177145 | 177145 | const zcu = pt.zcu; |
| 177146 | 177146 | const unwrapped_asm = self.air.unwrapAsm(inst); |
| ... | ... | @@ -177748,8 +177748,8 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void { |
| 177748 | 177748 | std.mem.reverse(Operand, ops[0..ops_len]); |
| 177749 | 177749 | if (mnem_size.size != .none and !mnem_size.used) { |
| 177750 | 177750 | comptime var max_mnem_len: usize = 0; |
| 177751 | inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".fields) |mnem| | |
| 177752 | max_mnem_len = @max(mnem.name.len, max_mnem_len); | |
| 177751 | inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".field_names) |mnem_name| | |
| 177752 | max_mnem_len = @max(mnem_name.len, max_mnem_len); | |
| 177753 | 177753 | var intel_mnem_buf: [max_mnem_len + 1]u8 = undefined; |
| 177754 | 177754 | const intel_mnem_str = std.fmt.bufPrint(&intel_mnem_buf, "{s}{c}", .{ |
| 177755 | 177755 | @tagName(mnem_tag), |
src/codegen/x86_64/Encoding.zig+1-1| ... | ... | @@ -1028,7 +1028,7 @@ const mnemonic_to_encodings_map = init: { |
| 1028 | 1028 | const Entry = struct { Mnemonic, OpEn, []const Op, []const u8, ModrmExt, Mode, Feature }; |
| 1029 | 1029 | const encodings: []const Entry = @import("encodings.zon"); |
| 1030 | 1030 | |
| 1031 | const mnemonic_count = @typeInfo(Mnemonic).@"enum".fields.len; | |
| 1031 | const mnemonic_count = @typeInfo(Mnemonic).@"enum".field_names.len; | |
| 1032 | 1032 | var mnemonic_map: [mnemonic_count][]Data = @splat(&.{}); |
| 1033 | 1033 | for (encodings) |entry| mnemonic_map[@intFromEnum(entry[0])].len += 1; |
| 1034 | 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 | 425 | lower.result_insts_len += 1; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | const inst_tags_len = @typeInfo(Mir.Inst.Tag).@"enum".fields.len; | |
| 429 | const inst_fixes_len = @typeInfo(Mir.Inst.Fixes).@"enum".fields.len; | |
| 428 | const inst_tags_len = @typeInfo(Mir.Inst.Tag).@"enum".field_names.len; | |
| 429 | const inst_fixes_len = @typeInfo(Mir.Inst.Fixes).@"enum".field_names.len; | |
| 430 | 430 | /// Lookup table, indexed by `@intFromEnum(inst.tag) * inst_fixes_len + @intFromEnum(fixes)`. |
| 431 | 431 | /// The value is the resulting `Mnemonic`, or `null` if the combination is not valid. |
| 432 | 432 | const 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 | 1732 | assert(@sizeOf(Data) == 8); |
| 1733 | 1733 | } |
| 1734 | 1734 | const Mnemonic = @import("Encoding.zig").Mnemonic; |
| 1735 | if (@typeInfo(Mnemonic).@"enum".fields.len != 978 or | |
| 1736 | @typeInfo(Fixes).@"enum".fields.len != 231 or | |
| 1737 | @typeInfo(Tag).@"enum".fields.len != 251) | |
| 1735 | if (@typeInfo(Mnemonic).@"enum".field_names.len != 978 or | |
| 1736 | @typeInfo(Fixes).@"enum".field_names.len != 231 or | |
| 1737 | @typeInfo(Tag).@"enum".field_names.len != 251) | |
| 1738 | 1738 | { |
| 1739 | 1739 | const cond_src = (struct { |
| 1740 | 1740 | fn src() std.lang.SourceLocation { |
| ... | ... | @@ -1742,32 +1742,32 @@ pub const Inst = struct { |
| 1742 | 1742 | } |
| 1743 | 1743 | }).src(); |
| 1744 | 1744 | @setEvalBranchQuota(2_000_000); |
| 1745 | for (@typeInfo(Mnemonic).@"enum".fields) |mnemonic| { | |
| 1746 | if (mnemonic.name[0] == '.') continue; | |
| 1747 | for (@typeInfo(Fixes).@"enum".fields) |fixes| { | |
| 1748 | const pattern = fixes.name[if (std.mem.indexOfScalar(u8, fixes.name, ' ')) |index| index + " ".len else 0..]; | |
| 1745 | for (@typeInfo(Mnemonic).@"enum".field_names) |mnemonic_name| { | |
| 1746 | if (mnemonic_name[0] == '.') continue; | |
| 1747 | for (@typeInfo(Fixes).@"enum".field_names) |fixes_name| { | |
| 1748 | const pattern = fixes_name[if (std.mem.indexOfScalar(u8, fixes_name, ' ')) |index| index + " ".len else 0..]; | |
| 1749 | 1749 | const wildcard_index = std.mem.indexOfScalar(u8, pattern, '_').?; |
| 1750 | 1750 | const mnem_prefix = pattern[0..wildcard_index]; |
| 1751 | 1751 | const mnem_suffix = pattern[wildcard_index + "_".len ..]; |
| 1752 | if (!std.mem.startsWith(u8, mnemonic.name, mnem_prefix)) continue; | |
| 1753 | if (!std.mem.endsWith(u8, mnemonic.name, mnem_suffix)) continue; | |
| 1752 | if (!std.mem.startsWith(u8, mnemonic_name, mnem_prefix)) continue; | |
| 1753 | if (!std.mem.endsWith(u8, mnemonic_name, mnem_suffix)) continue; | |
| 1754 | 1754 | if (@hasField( |
| 1755 | 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 | 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 | 1760 | @compileError(std.fmt.comptimePrint( |
| 1761 | 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} or | |
| 1763 | \\ @typeInfo(Fixes).@"enum".fields.len != {d} or | |
| 1764 | \\ @typeInfo(Tag).@"enum".fields.len != {d}) | |
| 1762 | \\if (@typeInfo(Mnemonic).@"enum".field_names.len != {d} or | |
| 1763 | \\ @typeInfo(Fixes).@"enum".field_names.len != {d} or | |
| 1764 | \\ @typeInfo(Tag).@"enum".field_names.len != {d}) | |
| 1765 | 1765 | , .{ |
| 1766 | 1766 | cond_src.file, |
| 1767 | 1767 | cond_src.line - 6, |
| 1768 | @typeInfo(Mnemonic).@"enum".fields.len, | |
| 1769 | @typeInfo(Fixes).@"enum".fields.len, | |
| 1770 | @typeInfo(Tag).@"enum".fields.len, | |
| 1768 | @typeInfo(Mnemonic).@"enum".field_names.len, | |
| 1769 | @typeInfo(Fixes).@"enum".field_names.len, | |
| 1770 | @typeInfo(Tag).@"enum".field_names.len, | |
| 1771 | 1771 | })); |
| 1772 | 1772 | } |
| 1773 | 1773 | } |
| ... | ... | @@ -2069,15 +2069,15 @@ pub fn emitLazy( |
| 2069 | 2069 | } |
| 2070 | 2070 | |
| 2071 | 2071 | pub 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 | 2073 | var i: u32 = index; |
| 2074 | 2074 | var result: T = undefined; |
| 2075 | inline for (fields) |field| { | |
| 2076 | @field(result, field.name) = switch (field.type) { | |
| 2075 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2076 | @field(result, field_name) = switch (field_type) { | |
| 2077 | 2077 | u32 => mir.extra[i], |
| 2078 | 2078 | i32, Memory.Info => @bitCast(mir.extra[i]), |
| 2079 | 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 | 2082 | i += 1; |
| 2083 | 2083 | } |
src/codegen/x86_64/bits.zig+1-1| ... | ... | @@ -722,7 +722,7 @@ pub const FrameIndex = enum(u32) { |
| 722 | 722 | // Other indices are used for local variable stack slots |
| 723 | 723 | _, |
| 724 | 724 | |
| 725 | pub const named_count = @typeInfo(FrameIndex).@"enum".fields.len; | |
| 725 | pub const named_count = @typeInfo(FrameIndex).@"enum".field_names.len; | |
| 726 | 726 | |
| 727 | 727 | pub fn isNamed(fi: FrameIndex) bool { |
| 728 | 728 | return @intFromEnum(fi) < named_count; |
src/codegen/x86_64/encoder.zig+6-6| ... | ... | @@ -2272,9 +2272,9 @@ const Assembler = struct { |
| 2272 | 2272 | |
| 2273 | 2273 | fn mnemonicFromString(bytes: []const u8) ?Instruction.Mnemonic { |
| 2274 | 2274 | const ti = @typeInfo(Instruction.Mnemonic).@"enum"; |
| 2275 | inline for (ti.fields) |field| { | |
| 2276 | if (std.mem.eql(u8, bytes, field.name)) { | |
| 2277 | return @field(Instruction.Mnemonic, field.name); | |
| 2275 | inline for (ti.field_names) |field_name| { | |
| 2276 | if (std.mem.eql(u8, bytes, field_name)) { | |
| 2277 | return @field(Instruction.Mnemonic, field_name); | |
| 2278 | 2278 | } |
| 2279 | 2279 | } |
| 2280 | 2280 | return null; |
| ... | ... | @@ -2325,9 +2325,9 @@ const Assembler = struct { |
| 2325 | 2325 | |
| 2326 | 2326 | fn registerFromString(bytes: []const u8) ?Register { |
| 2327 | 2327 | const ti = @typeInfo(Register).@"enum"; |
| 2328 | inline for (ti.fields) |field| { | |
| 2329 | if (std.mem.eql(u8, bytes, field.name)) { | |
| 2330 | return @field(Register, field.name); | |
| 2328 | inline for (ti.field_names) |field_name| { | |
| 2329 | if (std.mem.eql(u8, bytes, field_name)) { | |
| 2330 | return @field(Register, field_name); | |
| 2331 | 2331 | } |
| 2332 | 2332 | } |
| 2333 | 2333 | return null; |
src/link.zig+1-1| ... | ... | @@ -52,7 +52,7 @@ pub const Diags = struct { |
| 52 | 52 | alloc_failure_occurred: bool = false, |
| 53 | 53 | |
| 54 | 54 | const Int = blk: { |
| 55 | const bits = @typeInfo(@This()).@"struct".fields.len; | |
| 55 | const bits = @typeInfo(@This()).@"struct".field_names.len; | |
| 56 | 56 | break :blk @Int(.unsigned, bits); |
| 57 | 57 | }; |
| 58 | 58 |
src/link/Coff.zig+5-4| ... | ... | @@ -248,7 +248,7 @@ pub const Node = union(enum) { |
| 248 | 248 | |
| 249 | 249 | pub const Tag = @typeInfo(Node).@"union".tag_type.?; |
| 250 | 250 | |
| 251 | const known_count = @typeInfo(@TypeOf(known)).@"struct".fields.len; | |
| 251 | const known_count = @typeInfo(@TypeOf(known)).@"struct".field_names.len; | |
| 252 | 252 | const known = known: { |
| 253 | 253 | const Known = enum { |
| 254 | 254 | file, |
| ... | ... | @@ -260,8 +260,9 @@ pub const Node = union(enum) { |
| 260 | 260 | section_table, |
| 261 | 261 | }; |
| 262 | 262 | var mut_known: std.enums.EnumFieldStruct(Known, MappedFile.Node.Index, null) = undefined; |
| 263 | for (@typeInfo(Known).@"enum".fields) |field| | |
| 264 | @field(mut_known, field.name) = @enumFromInt(field.value); | |
| 263 | const info = @typeInfo(Known).@"enum"; | |
| 264 | for (info.field_names, info.field_values) |field_name, field_value| | |
| 265 | @field(mut_known, field_name) = @enumFromInt(field_value); | |
| 265 | 266 | break :known mut_known; |
| 266 | 267 | }; |
| 267 | 268 | |
| ... | ... | @@ -387,7 +388,7 @@ pub const Symbol = struct { |
| 387 | 388 | text, |
| 388 | 389 | _, |
| 389 | 390 | |
| 390 | const known_count = @typeInfo(Index).@"enum".fields.len; | |
| 391 | const known_count = @typeInfo(Index).@"enum".field_names.len; | |
| 391 | 392 | |
| 392 | 393 | pub fn get(si: Symbol.Index, coff: *Coff) *Symbol { |
| 393 | 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 | 5110 | } |
| 5111 | 5111 | |
| 5112 | 5112 | fn DeclValEnum(comptime T: type) type { |
| 5113 | const decls = @typeInfo(T).@"struct".decls; | |
| 5114 | @setEvalBranchQuota(10 * decls.len); | |
| 5115 | var field_names: [decls.len][]const u8 = undefined; | |
| 5113 | const decl_names = @typeInfo(T).@"struct".decl_names; | |
| 5114 | @setEvalBranchQuota(10 * decl_names.len); | |
| 5115 | var field_names: [decl_names.len][]const u8 = undefined; | |
| 5116 | 5116 | var fields_len = 0; |
| 5117 | 5117 | var min_value: ?comptime_int = null; |
| 5118 | 5118 | var max_value: ?comptime_int = null; |
| 5119 | for (decls) |decl| { | |
| 5120 | if (std.mem.startsWith(u8, decl.name, "HP_") or std.mem.endsWith(u8, decl.name, "_user")) continue; | |
| 5121 | const value = @field(T, decl.name); | |
| 5122 | field_names[fields_len] = decl.name; | |
| 5119 | for (decl_names) |decl_name| { | |
| 5120 | if (std.mem.startsWith(u8, decl_name, "HP_") or std.mem.endsWith(u8, decl_name, "_user")) continue; | |
| 5121 | const value = @field(T, decl_name); | |
| 5122 | field_names[fields_len] = decl_name; | |
| 5123 | 5123 | fields_len += 1; |
| 5124 | 5124 | if (min_value == null or min_value.? > value) min_value = value; |
| 5125 | 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 | 1194 | // TODO: save this work for later |
| 1195 | 1195 | const nsyms = parsed.symbols.len; |
| 1196 | 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 | 1198 | try so.symbols_resolver.ensureTotalCapacityPrecise(gpa, nsyms); |
| 1199 | 1199 | so.symbols_resolver.appendNTimesAssumeCapacity(0, nsyms); |
| 1200 | 1200 | |
| ... | ... | @@ -2354,9 +2354,9 @@ fn sortPhdrs( |
| 2354 | 2354 | phdr.* = slice[entry.phndx]; |
| 2355 | 2355 | } |
| 2356 | 2356 | |
| 2357 | inline for (@typeInfo(ProgramHeaderIndexes).@"struct".fields) |field| { | |
| 2358 | if (@field(special_indexes, field.name).int()) |special_index| { | |
| 2359 | @field(special_indexes, field.name) = @enumFromInt(backlinks[special_index]); | |
| 2357 | inline for (@typeInfo(ProgramHeaderIndexes).@"struct".field_names) |field_name| { | |
| 2358 | if (@field(special_indexes, field_name).int()) |special_index| { | |
| 2359 | @field(special_indexes, field_name) = @enumFromInt(backlinks[special_index]); | |
| 2360 | 2360 | } |
| 2361 | 2361 | } |
| 2362 | 2362 | |
| ... | ... | @@ -2474,9 +2474,9 @@ pub fn sortShdrs( |
| 2474 | 2474 | } |
| 2475 | 2475 | } |
| 2476 | 2476 | |
| 2477 | inline for (@typeInfo(SectionIndexes).@"struct".fields) |field| { | |
| 2478 | if (@field(section_indexes, field.name)) |special_index| { | |
| 2479 | @field(section_indexes, field.name) = backlinks[special_index]; | |
| 2477 | inline for (@typeInfo(SectionIndexes).@"struct".field_names) |field_name| { | |
| 2478 | if (@field(section_indexes, field_name)) |special_index| { | |
| 2479 | @field(section_indexes, field_name) = backlinks[special_index]; | |
| 2480 | 2480 | } |
| 2481 | 2481 | } |
| 2482 | 2482 |
src/link/Elf/Atom.zig+3-3| ... | ... | @@ -878,9 +878,9 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any |
| 878 | 878 | pub fn addExtra(atom: *Atom, opts: Extra.AsOptionals, elf_file: *Elf) void { |
| 879 | 879 | const file_ptr = atom.file(elf_file).?; |
| 880 | 880 | var extras = file_ptr.atomExtra(atom.extra_index); |
| 881 | inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| { | |
| 882 | if (@field(opts, field.name)) |x| { | |
| 883 | @field(extras, field.name) = x; | |
| 881 | inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| { | |
| 882 | if (@field(opts, field_name)) |x| { | |
| 883 | @field(extras, field_name) = x; | |
| 884 | 884 | } |
| 885 | 885 | } |
| 886 | 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 | 396 | } |
| 397 | 397 | |
| 398 | 398 | pub fn addSymbolExtra(self: *LinkerDefined, allocator: Allocator, extra: Symbol.Extra) !u32 { |
| 399 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 400 | try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 399 | const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len; | |
| 400 | try self.symbols_extra.ensureUnusedCapacity(allocator, field_count); | |
| 401 | 401 | return self.addSymbolExtraAssumeCapacity(extra); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u32 { |
| 405 | 405 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 406 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 407 | inline for (fields) |field| { | |
| 408 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 409 | u32 => @field(extra, field.name), | |
| 406 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 407 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 408 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 409 | u32 => @field(extra, field_name), | |
| 410 | 410 | else => @compileError("bad field type"), |
| 411 | 411 | }); |
| 412 | 412 | } |
| ... | ... | @@ -414,11 +414,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *LinkerDefined, extra: Symbol.Extra) u |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra { |
| 417 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 417 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 418 | 418 | var i: usize = index; |
| 419 | 419 | var result: Symbol.Extra = undefined; |
| 420 | inline for (fields) |field| { | |
| 421 | @field(result, field.name) = switch (field.type) { | |
| 420 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 421 | @field(result, field_name) = switch (field_type) { | |
| 422 | 422 | u32 => self.symbols_extra.items[i], |
| 423 | 423 | else => @compileError("bad field type"), |
| 424 | 424 | }; |
| ... | ... | @@ -428,10 +428,10 @@ pub fn symbolExtra(self: *LinkerDefined, index: u32) Symbol.Extra { |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | pub fn setSymbolExtra(self: *LinkerDefined, index: u32, extra: Symbol.Extra) void { |
| 431 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 432 | inline for (fields, 0..) |field, i| { | |
| 433 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 434 | u32 => @field(extra, field.name), | |
| 431 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 432 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 433 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 434 | u32 => @field(extra, field_name), | |
| 435 | 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 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | pub fn addSymbolExtra(self: *Object, gpa: Allocator, extra: Symbol.Extra) !u32 { |
| 1301 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 1302 | try self.symbols_extra.ensureUnusedCapacity(gpa, fields.len); | |
| 1301 | const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len; | |
| 1302 | try self.symbols_extra.ensureUnusedCapacity(gpa, field_count); | |
| 1303 | 1303 | return self.addSymbolExtraAssumeCapacity(extra); |
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 { |
| 1307 | 1307 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 1308 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 1309 | inline for (fields) |field| { | |
| 1310 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 1311 | u32 => @field(extra, field.name), | |
| 1308 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 1309 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1310 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 1311 | u32 => @field(extra, field_name), | |
| 1312 | 1312 | else => @compileError("bad field type"), |
| 1313 | 1313 | }); |
| 1314 | 1314 | } |
| ... | ... | @@ -1316,11 +1316,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 { |
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | 1318 | pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra { |
| 1319 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 1319 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 1320 | 1320 | var i: usize = index; |
| 1321 | 1321 | var result: Symbol.Extra = undefined; |
| 1322 | inline for (fields) |field| { | |
| 1323 | @field(result, field.name) = switch (field.type) { | |
| 1322 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1323 | @field(result, field_name) = switch (field_type) { | |
| 1324 | 1324 | u32 => self.symbols_extra.items[i], |
| 1325 | 1325 | else => @compileError("bad field type"), |
| 1326 | 1326 | }; |
| ... | ... | @@ -1330,10 +1330,10 @@ pub fn symbolExtra(self: *Object, index: u32) Symbol.Extra { |
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void { |
| 1333 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 1334 | inline for (fields, 0..) |field, i| { | |
| 1335 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 1336 | u32 => @field(extra, field.name), | |
| 1333 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 1334 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 1335 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 1336 | u32 => @field(extra, field_name), | |
| 1337 | 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 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | pub fn addAtomExtra(self: *Object, gpa: Allocator, extra: Atom.Extra) !u32 { |
| 1411 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1412 | try self.atoms_extra.ensureUnusedCapacity(gpa, fields.len); | |
| 1411 | const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len; | |
| 1412 | try self.atoms_extra.ensureUnusedCapacity(gpa, field_count); | |
| 1413 | 1413 | return self.addAtomExtraAssumeCapacity(extra); |
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 { |
| 1417 | 1417 | const index: u32 = @intCast(self.atoms_extra.items.len); |
| 1418 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1419 | inline for (fields) |field| { | |
| 1420 | self.atoms_extra.appendAssumeCapacity(switch (field.type) { | |
| 1421 | u32 => @field(extra, field.name), | |
| 1418 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 1419 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1420 | self.atoms_extra.appendAssumeCapacity(switch (field_type) { | |
| 1421 | u32 => @field(extra, field_name), | |
| 1422 | 1422 | else => @compileError("bad field type"), |
| 1423 | 1423 | }); |
| 1424 | 1424 | } |
| ... | ... | @@ -1426,11 +1426,11 @@ pub fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 { |
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | 1428 | pub fn atomExtra(self: *Object, index: u32) Atom.Extra { |
| 1429 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1429 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 1430 | 1430 | var i: usize = index; |
| 1431 | 1431 | var result: Atom.Extra = undefined; |
| 1432 | inline for (fields) |field| { | |
| 1433 | @field(result, field.name) = switch (field.type) { | |
| 1432 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 1433 | @field(result, field_name) = switch (field_type) { | |
| 1434 | 1434 | u32 => self.atoms_extra.items[i], |
| 1435 | 1435 | else => @compileError("bad field type"), |
| 1436 | 1436 | }; |
| ... | ... | @@ -1440,10 +1440,10 @@ pub fn atomExtra(self: *Object, index: u32) Atom.Extra { |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void { |
| 1443 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1444 | inline for (fields, 0..) |field, i| { | |
| 1445 | self.atoms_extra.items[index + i] = switch (field.type) { | |
| 1446 | u32 => @field(extra, field.name), | |
| 1443 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 1444 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 1445 | self.atoms_extra.items[index + i] = switch (field_type) { | |
| 1446 | u32 => @field(extra, field_name), | |
| 1447 | 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 | 1452 | fn setAtomFields(o: *Object, atom_ptr: *Atom, opts: Atom.Extra.AsOptionals) void { |
| 1453 | 1453 | assert(o.index == atom_ptr.file_index); |
| 1454 | 1454 | var extras = o.atomExtra(atom_ptr.extra_index); |
| 1455 | inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| { | |
| 1456 | if (@field(opts, field.name)) |x| @field(extras, field.name) = x; | |
| 1455 | inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| { | |
| 1456 | if (@field(opts, field_name)) |x| @field(extras, field_name) = x; | |
| 1457 | 1457 | } |
| 1458 | 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 | 498 | |
| 499 | 499 | pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u32 { |
| 500 | 500 | const index: u32 = @intCast(self.symbols_extra.items.len); |
| 501 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 502 | inline for (fields) |field| { | |
| 503 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 504 | u32 => @field(extra, field.name), | |
| 501 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 502 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 503 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 504 | u32 => @field(extra, field_name), | |
| 505 | 505 | else => @compileError("bad field type"), |
| 506 | 506 | }); |
| 507 | 507 | } |
| ... | ... | @@ -509,11 +509,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *SharedObject, extra: Symbol.Extra) u3 |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra { |
| 512 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 512 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 513 | 513 | var i: usize = index; |
| 514 | 514 | var result: Symbol.Extra = undefined; |
| 515 | inline for (fields) |field| { | |
| 516 | @field(result, field.name) = switch (field.type) { | |
| 515 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 516 | @field(result, field_name) = switch (field_type) { | |
| 517 | 517 | u32 => self.symbols_extra.items[i], |
| 518 | 518 | else => @compileError("bad field type"), |
| 519 | 519 | }; |
| ... | ... | @@ -523,10 +523,10 @@ pub fn symbolExtra(self: *SharedObject, index: u32) Symbol.Extra { |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | pub fn setSymbolExtra(self: *SharedObject, index: u32, extra: Symbol.Extra) void { |
| 526 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 527 | inline for (fields, 0..) |field, i| { | |
| 528 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 529 | u32 => @field(extra, field.name), | |
| 526 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 527 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 528 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 529 | u32 => @field(extra, field_name), | |
| 530 | 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 | 259 | |
| 260 | 260 | pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) void { |
| 261 | 261 | var extras = symbol.extra(elf_file); |
| 262 | inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| { | |
| 263 | if (@field(opts, field.name)) |x| { | |
| 264 | @field(extras, field.name) = x; | |
| 262 | inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| { | |
| 263 | if (@field(opts, field_name)) |x| { | |
| 264 | @field(extras, field_name) = x; | |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 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 | 2214 | } |
| 2215 | 2215 | |
| 2216 | 2216 | fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 { |
| 2217 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2218 | try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 2217 | const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len; | |
| 2218 | try self.atoms_extra.ensureUnusedCapacity(allocator, field_count); | |
| 2219 | 2219 | return self.addAtomExtraAssumeCapacity(extra); |
| 2220 | 2220 | } |
| 2221 | 2221 | |
| 2222 | 2222 | fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 { |
| 2223 | 2223 | const index = @as(u32, @intCast(self.atoms_extra.items.len)); |
| 2224 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2225 | inline for (fields) |field| { | |
| 2226 | self.atoms_extra.appendAssumeCapacity(switch (field.type) { | |
| 2227 | u32 => @field(extra, field.name), | |
| 2224 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 2225 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2226 | self.atoms_extra.appendAssumeCapacity(switch (field_type) { | |
| 2227 | u32 => @field(extra, field_name), | |
| 2228 | 2228 | else => @compileError("bad field type"), |
| 2229 | 2229 | }); |
| 2230 | 2230 | } |
| ... | ... | @@ -2232,11 +2232,11 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 { |
| 2232 | 2232 | } |
| 2233 | 2233 | |
| 2234 | 2234 | pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra { |
| 2235 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2235 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 2236 | 2236 | var i: usize = index; |
| 2237 | 2237 | var result: Atom.Extra = undefined; |
| 2238 | inline for (fields) |field| { | |
| 2239 | @field(result, field.name) = switch (field.type) { | |
| 2238 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2239 | @field(result, field_name) = switch (field_type) { | |
| 2240 | 2240 | u32 => self.atoms_extra.items[i], |
| 2241 | 2241 | else => @compileError("bad field type"), |
| 2242 | 2242 | }; |
| ... | ... | @@ -2247,10 +2247,10 @@ pub fn atomExtra(self: ZigObject, index: u32) Atom.Extra { |
| 2247 | 2247 | |
| 2248 | 2248 | pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void { |
| 2249 | 2249 | assert(index > 0); |
| 2250 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2251 | inline for (fields, 0..) |field, i| { | |
| 2252 | self.atoms_extra.items[index + i] = switch (field.type) { | |
| 2253 | u32 => @field(extra, field.name), | |
| 2250 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 2251 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 2252 | self.atoms_extra.items[index + i] = switch (field_type) { | |
| 2253 | u32 => @field(extra, field_name), | |
| 2254 | 2254 | else => @compileError("bad field type"), |
| 2255 | 2255 | }; |
| 2256 | 2256 | } |
| ... | ... | @@ -2286,17 +2286,17 @@ fn addSymbolAssumeCapacity(self: *ZigObject) Symbol.Index { |
| 2286 | 2286 | } |
| 2287 | 2287 | |
| 2288 | 2288 | pub fn addSymbolExtra(self: *ZigObject, allocator: Allocator, extra: Symbol.Extra) !u32 { |
| 2289 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2290 | try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 2289 | const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len; | |
| 2290 | try self.symbols_extra.ensureUnusedCapacity(allocator, field_count); | |
| 2291 | 2291 | return self.addSymbolExtraAssumeCapacity(extra); |
| 2292 | 2292 | } |
| 2293 | 2293 | |
| 2294 | 2294 | pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 { |
| 2295 | 2295 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 2296 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2297 | inline for (fields) |field| { | |
| 2298 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 2299 | u32 => @field(extra, field.name), | |
| 2296 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 2297 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2298 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 2299 | u32 => @field(extra, field_name), | |
| 2300 | 2300 | else => @compileError("bad field type"), |
| 2301 | 2301 | }); |
| 2302 | 2302 | } |
| ... | ... | @@ -2304,11 +2304,11 @@ pub fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 { |
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | 2306 | pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra { |
| 2307 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2307 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 2308 | 2308 | var i: usize = index; |
| 2309 | 2309 | var result: Symbol.Extra = undefined; |
| 2310 | inline for (fields) |field| { | |
| 2311 | @field(result, field.name) = switch (field.type) { | |
| 2310 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2311 | @field(result, field_name) = switch (field_type) { | |
| 2312 | 2312 | u32 => self.symbols_extra.items[i], |
| 2313 | 2313 | else => @compileError("bad field type"), |
| 2314 | 2314 | }; |
| ... | ... | @@ -2318,10 +2318,10 @@ pub fn symbolExtra(self: *ZigObject, index: u32) Symbol.Extra { |
| 2318 | 2318 | } |
| 2319 | 2319 | |
| 2320 | 2320 | pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void { |
| 2321 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2322 | inline for (fields, 0..) |field, i| { | |
| 2323 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 2324 | u32 => @field(extra, field.name), | |
| 2321 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 2322 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 2323 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 2324 | u32 => @field(extra, field_name), | |
| 2325 | 2325 | else => @compileError("bad field type"), |
| 2326 | 2326 | }; |
| 2327 | 2327 | } |
src/link/Elf2.zig+3-3| ... | ... | @@ -6330,10 +6330,10 @@ pub fn printNode( |
| 6330 | 6330 | const pt = elf.targetLoad(&ph.type); |
| 6331 | 6331 | if (std.enums.tagName(std.elf.PT, pt)) |pt_name| |
| 6332 | 6332 | try w.writeAll(pt_name) |
| 6333 | else inline for (@typeInfo(std.elf.PT).@"enum".decls) |decl| { | |
| 6334 | const decl_val = @field(std.elf.PT, decl.name); | |
| 6333 | else inline for (@typeInfo(std.elf.PT).@"enum".decl_names) |decl_name| { | |
| 6334 | const decl_val = @field(std.elf.PT, decl_name); | |
| 6335 | 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 | 6337 | } else try w.print("0x{x}", .{pt}); |
| 6338 | 6338 | try w.writeAll(", "); |
| 6339 | 6339 | const pf = elf.targetLoad(&ph.flags); |
src/link/LdScript.zig+4-4| ... | ... | @@ -97,15 +97,15 @@ const Command = enum { |
| 97 | 97 | as_needed, |
| 98 | 98 | |
| 99 | 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 | 101 | const upper_name = n: { |
| 102 | comptime var buf: [field.name.len]u8 = undefined; | |
| 103 | inline for (field.name, 0..) |c, i| { | |
| 102 | comptime var buf: [field_name.len]u8 = undefined; | |
| 103 | inline for (field_name, 0..) |c, i| { | |
| 104 | 104 | buf[i] = comptime std.ascii.toUpper(c); |
| 105 | 105 | } |
| 106 | 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 | 110 | return null; |
| 111 | 111 | } |
src/link/MachO/Atom.zig+3-3| ... | ... | @@ -129,9 +129,9 @@ const AddExtraOpts = struct { |
| 129 | 129 | pub fn addExtra(atom: *Atom, opts: AddExtraOpts, macho_file: *MachO) void { |
| 130 | 130 | const file = atom.getFile(macho_file); |
| 131 | 131 | var extra = file.getAtomExtra(atom.extra); |
| 132 | inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| { | |
| 133 | if (@field(opts, field.name)) |x| { | |
| 134 | @field(extra, field.name) = x; | |
| 132 | inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| { | |
| 133 | if (@field(opts, field_name)) |x| { | |
| 134 | @field(extra, field_name) = x; | |
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 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 | 627 | } |
| 628 | 628 | |
| 629 | 629 | pub fn addSymbolExtra(self: *Dylib, allocator: Allocator, extra: Symbol.Extra) !u32 { |
| 630 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 631 | try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 630 | const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len; | |
| 631 | try self.symbols_extra.ensureUnusedCapacity(allocator, field_count); | |
| 632 | 632 | return self.addSymbolExtraAssumeCapacity(extra); |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 { |
| 636 | 636 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 637 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 638 | inline for (fields) |field| { | |
| 639 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 640 | u32 => @field(extra, field.name), | |
| 637 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 638 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 639 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 640 | u32 => @field(extra, field_name), | |
| 641 | 641 | else => @compileError("bad field type"), |
| 642 | 642 | }); |
| 643 | 643 | } |
| ... | ... | @@ -645,11 +645,11 @@ fn addSymbolExtraAssumeCapacity(self: *Dylib, extra: Symbol.Extra) u32 { |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra { |
| 648 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 648 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 649 | 649 | var i: usize = index; |
| 650 | 650 | var result: Symbol.Extra = undefined; |
| 651 | inline for (fields) |field| { | |
| 652 | @field(result, field.name) = switch (field.type) { | |
| 651 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 652 | @field(result, field_name) = switch (field_type) { | |
| 653 | 653 | u32 => self.symbols_extra.items[i], |
| 654 | 654 | else => @compileError("bad field type"), |
| 655 | 655 | }; |
| ... | ... | @@ -659,10 +659,10 @@ pub fn getSymbolExtra(self: Dylib, index: u32) Symbol.Extra { |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | pub fn setSymbolExtra(self: *Dylib, index: u32, extra: Symbol.Extra) void { |
| 662 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 663 | inline for (fields, 0..) |field, i| { | |
| 664 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 665 | u32 => @field(extra, field.name), | |
| 662 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 663 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 664 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 665 | u32 => @field(extra, field_name), | |
| 666 | 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 | 708 | } |
| 709 | 709 | |
| 710 | 710 | fn addAtomExtra(self: *InternalObject, allocator: Allocator, extra: Atom.Extra) !u32 { |
| 711 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 712 | try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 711 | const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len; | |
| 712 | try self.atoms_extra.ensureUnusedCapacity(allocator, field_count); | |
| 713 | 713 | return self.addAtomExtraAssumeCapacity(extra); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 { |
| 717 | 717 | const index = @as(u32, @intCast(self.atoms_extra.items.len)); |
| 718 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 719 | inline for (fields) |field| { | |
| 720 | self.atoms_extra.appendAssumeCapacity(switch (field.type) { | |
| 721 | u32 => @field(extra, field.name), | |
| 718 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 719 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 720 | self.atoms_extra.appendAssumeCapacity(switch (field_type) { | |
| 721 | u32 => @field(extra, field_name), | |
| 722 | 722 | else => @compileError("bad field type"), |
| 723 | 723 | }); |
| 724 | 724 | } |
| ... | ... | @@ -726,11 +726,11 @@ fn addAtomExtraAssumeCapacity(self: *InternalObject, extra: Atom.Extra) u32 { |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra { |
| 729 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 729 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 730 | 730 | var i: usize = index; |
| 731 | 731 | var result: Atom.Extra = undefined; |
| 732 | inline for (fields) |field| { | |
| 733 | @field(result, field.name) = switch (field.type) { | |
| 732 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 733 | @field(result, field_name) = switch (field_type) { | |
| 734 | 734 | u32 => self.atoms_extra.items[i], |
| 735 | 735 | else => @compileError("bad field type"), |
| 736 | 736 | }; |
| ... | ... | @@ -741,10 +741,10 @@ pub fn getAtomExtra(self: InternalObject, index: u32) Atom.Extra { |
| 741 | 741 | |
| 742 | 742 | pub fn setAtomExtra(self: *InternalObject, index: u32, extra: Atom.Extra) void { |
| 743 | 743 | assert(index > 0); |
| 744 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 745 | inline for (fields, 0..) |field, i| { | |
| 746 | self.atoms_extra.items[index + i] = switch (field.type) { | |
| 747 | u32 => @field(extra, field.name), | |
| 744 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 745 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 746 | self.atoms_extra.items[index + i] = switch (field_type) { | |
| 747 | u32 => @field(extra, field_name), | |
| 748 | 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 | 789 | } |
| 790 | 790 | |
| 791 | 791 | pub fn addSymbolExtra(self: *InternalObject, allocator: Allocator, extra: Symbol.Extra) !u32 { |
| 792 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 793 | try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 792 | const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len; | |
| 793 | try self.symbols_extra.ensureUnusedCapacity(allocator, field_count); | |
| 794 | 794 | return self.addSymbolExtraAssumeCapacity(extra); |
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32 { |
| 798 | 798 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 799 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 800 | inline for (fields) |field| { | |
| 801 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 802 | u32 => @field(extra, field.name), | |
| 799 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 800 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 801 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 802 | u32 => @field(extra, field_name), | |
| 803 | 803 | else => @compileError("bad field type"), |
| 804 | 804 | }); |
| 805 | 805 | } |
| ... | ... | @@ -807,11 +807,11 @@ fn addSymbolExtraAssumeCapacity(self: *InternalObject, extra: Symbol.Extra) u32 |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra { |
| 810 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 810 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 811 | 811 | var i: usize = index; |
| 812 | 812 | var result: Symbol.Extra = undefined; |
| 813 | inline for (fields) |field| { | |
| 814 | @field(result, field.name) = switch (field.type) { | |
| 813 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 814 | @field(result, field_name) = switch (field_type) { | |
| 815 | 815 | u32 => self.symbols_extra.items[i], |
| 816 | 816 | else => @compileError("bad field type"), |
| 817 | 817 | }; |
| ... | ... | @@ -821,10 +821,10 @@ pub fn getSymbolExtra(self: InternalObject, index: u32) Symbol.Extra { |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | pub fn setSymbolExtra(self: *InternalObject, index: u32, extra: Symbol.Extra) void { |
| 824 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 825 | inline for (fields, 0..) |field, i| { | |
| 826 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 827 | u32 => @field(extra, field.name), | |
| 824 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 825 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 826 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 827 | u32 => @field(extra, field_name), | |
| 828 | 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 | 2478 | } |
| 2479 | 2479 | |
| 2480 | 2480 | fn addAtomExtra(self: *Object, allocator: Allocator, extra: Atom.Extra) !u32 { |
| 2481 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2482 | try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 2481 | const field_count = @typeInfo(Atom.Extra).@"struct".field_names.len; | |
| 2482 | try self.atoms_extra.ensureUnusedCapacity(allocator, field_count); | |
| 2483 | 2483 | return self.addAtomExtraAssumeCapacity(extra); |
| 2484 | 2484 | } |
| 2485 | 2485 | |
| 2486 | 2486 | fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 { |
| 2487 | 2487 | const index = @as(u32, @intCast(self.atoms_extra.items.len)); |
| 2488 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2489 | inline for (fields) |field| { | |
| 2490 | self.atoms_extra.appendAssumeCapacity(switch (field.type) { | |
| 2491 | u32 => @field(extra, field.name), | |
| 2488 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 2489 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2490 | self.atoms_extra.appendAssumeCapacity(switch (field_type) { | |
| 2491 | u32 => @field(extra, field_name), | |
| 2492 | 2492 | else => @compileError("bad field type"), |
| 2493 | 2493 | }); |
| 2494 | 2494 | } |
| ... | ... | @@ -2496,11 +2496,11 @@ fn addAtomExtraAssumeCapacity(self: *Object, extra: Atom.Extra) u32 { |
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | pub fn getAtomExtra(self: Object, index: u32) Atom.Extra { |
| 2499 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2499 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 2500 | 2500 | var i: usize = index; |
| 2501 | 2501 | var result: Atom.Extra = undefined; |
| 2502 | inline for (fields) |field| { | |
| 2503 | @field(result, field.name) = switch (field.type) { | |
| 2502 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2503 | @field(result, field_name) = switch (field_type) { | |
| 2504 | 2504 | u32 => self.atoms_extra.items[i], |
| 2505 | 2505 | else => @compileError("bad field type"), |
| 2506 | 2506 | }; |
| ... | ... | @@ -2511,10 +2511,10 @@ pub fn getAtomExtra(self: Object, index: u32) Atom.Extra { |
| 2511 | 2511 | |
| 2512 | 2512 | pub fn setAtomExtra(self: *Object, index: u32, extra: Atom.Extra) void { |
| 2513 | 2513 | assert(index > 0); |
| 2514 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 2515 | inline for (fields, 0..) |field, i| { | |
| 2516 | self.atoms_extra.items[index + i] = switch (field.type) { | |
| 2517 | u32 => @field(extra, field.name), | |
| 2514 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 2515 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 2516 | self.atoms_extra.items[index + i] = switch (field_type) { | |
| 2517 | u32 => @field(extra, field_name), | |
| 2518 | 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 | 2539 | } |
| 2540 | 2540 | |
| 2541 | 2541 | pub fn addSymbolExtra(self: *Object, allocator: Allocator, extra: Symbol.Extra) !u32 { |
| 2542 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2543 | try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 2542 | const field_count = @typeInfo(Symbol.Extra).@"struct".field_names.len; | |
| 2543 | try self.symbols_extra.ensureUnusedCapacity(allocator, field_count); | |
| 2544 | 2544 | return self.addSymbolExtraAssumeCapacity(extra); |
| 2545 | 2545 | } |
| 2546 | 2546 | |
| 2547 | 2547 | fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 { |
| 2548 | 2548 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 2549 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2550 | inline for (fields) |field| { | |
| 2551 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 2552 | u32 => @field(extra, field.name), | |
| 2549 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 2550 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2551 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 2552 | u32 => @field(extra, field_name), | |
| 2553 | 2553 | else => @compileError("bad field type"), |
| 2554 | 2554 | }); |
| 2555 | 2555 | } |
| ... | ... | @@ -2557,11 +2557,11 @@ fn addSymbolExtraAssumeCapacity(self: *Object, extra: Symbol.Extra) u32 { |
| 2557 | 2557 | } |
| 2558 | 2558 | |
| 2559 | 2559 | pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra { |
| 2560 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2560 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 2561 | 2561 | var i: usize = index; |
| 2562 | 2562 | var result: Symbol.Extra = undefined; |
| 2563 | inline for (fields) |field| { | |
| 2564 | @field(result, field.name) = switch (field.type) { | |
| 2563 | inline for (info.field_names, info.field_types) |field_name, field_type| { | |
| 2564 | @field(result, field_name) = switch (field_type) { | |
| 2565 | 2565 | u32 => self.symbols_extra.items[i], |
| 2566 | 2566 | else => @compileError("bad field type"), |
| 2567 | 2567 | }; |
| ... | ... | @@ -2571,10 +2571,10 @@ pub fn getSymbolExtra(self: Object, index: u32) Symbol.Extra { |
| 2571 | 2571 | } |
| 2572 | 2572 | |
| 2573 | 2573 | pub fn setSymbolExtra(self: *Object, index: u32, extra: Symbol.Extra) void { |
| 2574 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 2575 | inline for (fields, 0..) |field, i| { | |
| 2576 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 2577 | u32 => @field(extra, field.name), | |
| 2574 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 2575 | inline for (info.field_names, info.field_types, 0..) |field_name, field_type, i| { | |
| 2576 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 2577 | u32 => @field(extra, field_name), | |
| 2578 | 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 | 211 | |
| 212 | 212 | pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, macho_file: *MachO) void { |
| 213 | 213 | var extra = symbol.getExtra(macho_file); |
| 214 | inline for (@typeInfo(@TypeOf(opts)).@"struct".fields) |field| { | |
| 215 | if (@field(opts, field.name)) |x| { | |
| 216 | @field(extra, field.name) = x; | |
| 214 | inline for (@typeInfo(@TypeOf(opts)).@"struct".field_names) |field_name| { | |
| 215 | if (@field(opts, field_name)) |x| { | |
| 216 | @field(extra, field_name) = x; | |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 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 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | fn addAtomExtra(self: *ZigObject, allocator: Allocator, extra: Atom.Extra) !u32 { |
| 1573 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1574 | try self.atoms_extra.ensureUnusedCapacity(allocator, fields.len); | |
| 1573 | const field = @typeInfo(Atom.Extra).@"struct".field_names; | |
| 1574 | try self.atoms_extra.ensureUnusedCapacity(allocator, field.len); | |
| 1575 | 1575 | return self.addAtomExtraAssumeCapacity(extra); |
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 { |
| 1579 | 1579 | const index = @as(u32, @intCast(self.atoms_extra.items.len)); |
| 1580 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1581 | inline for (fields) |field| { | |
| 1582 | self.atoms_extra.appendAssumeCapacity(switch (field.type) { | |
| 1583 | u32 => @field(extra, field.name), | |
| 1580 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 1581 | const field_names = info.field_names; | |
| 1582 | const field_types = info.field_types; | |
| 1583 | inline for (field_names, field_types) |field_name, field_type| { | |
| 1584 | self.atoms_extra.appendAssumeCapacity(switch (field_type) { | |
| 1585 | u32 => @field(extra, field_name), | |
| 1584 | 1586 | else => @compileError("bad field type"), |
| 1585 | 1587 | }); |
| 1586 | 1588 | } |
| ... | ... | @@ -1588,11 +1590,13 @@ fn addAtomExtraAssumeCapacity(self: *ZigObject, extra: Atom.Extra) u32 { |
| 1588 | 1590 | } |
| 1589 | 1591 | |
| 1590 | 1592 | pub 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 | 1596 | var i: usize = index; |
| 1593 | 1597 | var result: Atom.Extra = undefined; |
| 1594 | inline for (fields) |field| { | |
| 1595 | @field(result, field.name) = switch (field.type) { | |
| 1598 | inline for (field_names, field_types) |field_name, field_type| { | |
| 1599 | @field(result, field_name) = switch (field_type) { | |
| 1596 | 1600 | u32 => self.atoms_extra.items[i], |
| 1597 | 1601 | else => @compileError("bad field type"), |
| 1598 | 1602 | }; |
| ... | ... | @@ -1603,10 +1607,12 @@ pub fn getAtomExtra(self: ZigObject, index: u32) Atom.Extra { |
| 1603 | 1607 | |
| 1604 | 1608 | pub fn setAtomExtra(self: *ZigObject, index: u32, extra: Atom.Extra) void { |
| 1605 | 1609 | assert(index > 0); |
| 1606 | const fields = @typeInfo(Atom.Extra).@"struct".fields; | |
| 1607 | inline for (fields, 0..) |field, i| { | |
| 1608 | self.atoms_extra.items[index + i] = switch (field.type) { | |
| 1609 | u32 => @field(extra, field.name), | |
| 1610 | const info = @typeInfo(Atom.Extra).@"struct"; | |
| 1611 | const field_names = info.field_names; | |
| 1612 | const field_types = info.field_types; | |
| 1613 | inline for (field_names, field_types, 0..) |field_name, field_type, i| { | |
| 1614 | self.atoms_extra.items[index + i] = switch (field_type) { | |
| 1615 | u32 => @field(extra, field_name), | |
| 1610 | 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 | 1637 | } |
| 1632 | 1638 | |
| 1633 | 1639 | pub 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 | 1641 | try self.symbols_extra.ensureUnusedCapacity(allocator, fields.len); |
| 1636 | 1642 | return self.addSymbolExtraAssumeCapacity(extra); |
| 1637 | 1643 | } |
| 1638 | 1644 | |
| 1639 | 1645 | fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 { |
| 1640 | 1646 | const index = @as(u32, @intCast(self.symbols_extra.items.len)); |
| 1641 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 1642 | inline for (fields) |field| { | |
| 1643 | self.symbols_extra.appendAssumeCapacity(switch (field.type) { | |
| 1644 | u32 => @field(extra, field.name), | |
| 1647 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 1648 | const field_names = info.field_names; | |
| 1649 | const field_types = info.field_types; | |
| 1650 | inline for (field_names, field_types) |field_name, field_type| { | |
| 1651 | self.symbols_extra.appendAssumeCapacity(switch (field_type) { | |
| 1652 | u32 => @field(extra, field_name), | |
| 1645 | 1653 | else => @compileError("bad field type"), |
| 1646 | 1654 | }); |
| 1647 | 1655 | } |
| ... | ... | @@ -1649,11 +1657,13 @@ fn addSymbolExtraAssumeCapacity(self: *ZigObject, extra: Symbol.Extra) u32 { |
| 1649 | 1657 | } |
| 1650 | 1658 | |
| 1651 | 1659 | pub 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 | 1663 | var i: usize = index; |
| 1654 | 1664 | var result: Symbol.Extra = undefined; |
| 1655 | inline for (fields) |field| { | |
| 1656 | @field(result, field.name) = switch (field.type) { | |
| 1665 | inline for (field_names, field_types) |field_name, field_type| { | |
| 1666 | @field(result, field_name) = switch (field_type) { | |
| 1657 | 1667 | u32 => self.symbols_extra.items[i], |
| 1658 | 1668 | else => @compileError("bad field type"), |
| 1659 | 1669 | }; |
| ... | ... | @@ -1663,10 +1673,12 @@ pub fn getSymbolExtra(self: ZigObject, index: u32) Symbol.Extra { |
| 1663 | 1673 | } |
| 1664 | 1674 | |
| 1665 | 1675 | pub fn setSymbolExtra(self: *ZigObject, index: u32, extra: Symbol.Extra) void { |
| 1666 | const fields = @typeInfo(Symbol.Extra).@"struct".fields; | |
| 1667 | inline for (fields, 0..) |field, i| { | |
| 1668 | self.symbols_extra.items[index + i] = switch (field.type) { | |
| 1669 | u32 => @field(extra, field.name), | |
| 1676 | const info = @typeInfo(Symbol.Extra).@"struct"; | |
| 1677 | const field_names = info.field_names; | |
| 1678 | const field_types = info.field_types; | |
| 1679 | inline for (field_names, field_types, 0..) |field_name, field_type, i| { | |
| 1680 | self.symbols_extra.items[index + i] = switch (field_type) { | |
| 1681 | u32 => @field(extra, field_name), | |
| 1670 | 1682 | else => @compileError("bad field type"), |
| 1671 | 1683 | }; |
| 1672 | 1684 | } |
src/link/Wasm.zig+2-2| ... | ... | @@ -2992,8 +2992,8 @@ pub fn createEmpty( |
| 2992 | 2992 | |
| 2993 | 2993 | if (options.object_host_name) |name| wasm.object_host_name = (try wasm.internString(name)).toOptional(); |
| 2994 | 2994 | |
| 2995 | inline for (@typeInfo(PreloadedStrings).@"struct".fields) |field| { | |
| 2996 | @field(wasm.preloaded_strings, field.name) = try wasm.internString(field.name); | |
| 2995 | inline for (@typeInfo(PreloadedStrings).@"struct".field_names) |field_name| { | |
| 2996 | @field(wasm.preloaded_strings, field_name) = try wasm.internString(field_name); | |
| 2997 | 2997 | } |
| 2998 | 2998 | |
| 2999 | 2999 | wasm.entry_name = switch (options.entry) { |
src/link/tapi/yaml.zig+20-20| ... | ... | @@ -214,8 +214,8 @@ pub const Value = union(enum) { |
| 214 | 214 | var list: std.ArrayList(Value) = try .initCapacity(arena); |
| 215 | 215 | defer list.deinit(); |
| 216 | 216 | |
| 217 | inline for (info.fields) |field| { | |
| 218 | if (try encode(arena, @field(input, field.name))) |value| { | |
| 217 | inline for (info.field_names) |field_name| { | |
| 218 | if (try encode(arena, @field(input, field_name))) |value| { | |
| 219 | 219 | list.appendAssumeCapacity(value); |
| 220 | 220 | } |
| 221 | 221 | } |
| ... | ... | @@ -224,11 +224,11 @@ pub const Value = union(enum) { |
| 224 | 224 | } else { |
| 225 | 225 | var map = Map.init(arena); |
| 226 | 226 | errdefer map.deinit(); |
| 227 | try map.ensureTotalCapacity(info.fields.len); | |
| 227 | try map.ensureTotalCapacity(info.field_names.len); | |
| 228 | 228 | |
| 229 | inline for (info.fields) |field| { | |
| 230 | if (try encode(arena, @field(input, field.name))) |value| { | |
| 231 | const key = try arena.dupe(u8, field.name); | |
| 229 | inline for (info.field_names) |field_name| { | |
| 230 | if (try encode(arena, @field(input, field_name))) |value| { | |
| 231 | const key = try arena.dupe(u8, field_name); | |
| 232 | 232 | map.putAssumeCapacityNoClobber(key, value); |
| 233 | 233 | } |
| 234 | 234 | } |
| ... | ... | @@ -237,9 +237,9 @@ pub const Value = union(enum) { |
| 237 | 237 | }, |
| 238 | 238 | |
| 239 | 239 | .@"union" => |info| if (info.tag_type) |tag_type| { |
| 240 | inline for (info.fields) |field| { | |
| 241 | if (@field(tag_type, field.name) == input) { | |
| 242 | return try encode(arena, @field(input, field.name)); | |
| 240 | inline for (info.field_names) |field_name| { | |
| 241 | if (@field(tag_type, field_name) == input) { | |
| 242 | return try encode(arena, @field(input, field_name)); | |
| 243 | 243 | } |
| 244 | 244 | } else unreachable; |
| 245 | 245 | } else return error.UntaggedUnion, |
| ... | ... | @@ -396,9 +396,9 @@ pub const Yaml = struct { |
| 396 | 396 | const union_info = @typeInfo(T).@"union"; |
| 397 | 397 | |
| 398 | 398 | if (union_info.tag_type) |_| { |
| 399 | inline for (union_info.fields) |field| { | |
| 400 | if (self.parseValue(field.type, value)) |u_value| { | |
| 401 | return @unionInit(T, field.name, u_value); | |
| 399 | inline for (union_info.field_names, union_info.field_types) |field_name, field_type| { | |
| 400 | if (self.parseValue(field_type, value)) |u_value| { | |
| 401 | return @unionInit(T, field_name, u_value); | |
| 402 | 402 | } else |err| { |
| 403 | 403 | if (@as(@TypeOf(err) || error{TypeMismatch}, err) != error.TypeMismatch) return err; |
| 404 | 404 | } |
| ... | ... | @@ -418,22 +418,22 @@ pub const Yaml = struct { |
| 418 | 418 | const struct_info = @typeInfo(T).@"struct"; |
| 419 | 419 | var parsed: T = undefined; |
| 420 | 420 | |
| 421 | inline for (struct_info.fields) |field| { | |
| 422 | const value: ?Value = map.get(field.name) orelse blk: { | |
| 423 | const field_name = try mem.replaceOwned(u8, self.arena.allocator(), field.name, "_", "-"); | |
| 424 | break :blk map.get(field_name); | |
| 421 | inline for (struct_info.field_names, struct_info.field_types) |field_name, field_type| { | |
| 422 | const value: ?Value = map.get(field_name) orelse blk: { | |
| 423 | const field_name_ = try mem.replaceOwned(u8, self.arena.allocator(), field_name, "_", "-"); | |
| 424 | break :blk map.get(field_name_); | |
| 425 | 425 | }; |
| 426 | 426 | |
| 427 | if (@typeInfo(field.type) == .optional) { | |
| 428 | @field(parsed, field.name) = try self.parseOptional(field.type, value); | |
| 427 | if (@typeInfo(field_type) == .optional) { | |
| 428 | @field(parsed, field_name) = try self.parseOptional(field_type, value); | |
| 429 | 429 | continue; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 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 | 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 | } |
| 438 | 438 | |
| 439 | 439 | return parsed; |
src/print_env.zig+2-2| ... | ... | @@ -59,8 +59,8 @@ pub fn cmdEnv( |
| 59 | 59 | try root.field("version", build_options.version, .{}); |
| 60 | 60 | try root.field("target", triple, .{}); |
| 61 | 61 | var env = try root.beginStructField("env", .{}); |
| 62 | inline for (@typeInfo(EnvVar).@"enum".fields) |field| { | |
| 63 | try env.field(field.name, @field(EnvVar, field.name).get(environ_map), .{}); | |
| 62 | inline for (@typeInfo(EnvVar).@"enum".field_names) |field_name| { | |
| 63 | try env.field(field_name, @field(EnvVar, field_name).get(environ_map), .{}); | |
| 64 | 64 | } |
| 65 | 65 | try env.end(); |
| 66 | 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 | 5 | |
| 6 | 6 | const bytes_per_node = comptime n: { |
| 7 | 7 | var n: usize = 0; |
| 8 | for (@typeInfo(Zoir.Node.Repr).@"struct".fields) |f| { | |
| 9 | n += @sizeOf(f.type); | |
| 8 | for (@typeInfo(Zoir.Node.Repr).@"struct".field_types) |f_type| { | |
| 9 | n += @sizeOf(f_type); | |
| 10 | 10 | } |
| 11 | 11 | break :n n; |
| 12 | 12 | }; |
stage1/zig.h+24-2| ... | ... | @@ -21,6 +21,8 @@ |
| 21 | 21 | |
| 22 | 22 | #if defined(__aarch64__) || (defined(zig_msvc) && defined(_M_ARM64)) |
| 23 | 23 | #define zig_aarch64 |
| 24 | #elif defined(__alpha__) | |
| 25 | #define zig_alpha | |
| 24 | 26 | #elif defined(__thumb__) || (defined(zig_msvc) && defined(_M_ARM)) |
| 25 | 27 | #define zig_thumb |
| 26 | 28 | #define zig_arm |
| ... | ... | @@ -36,6 +38,10 @@ |
| 36 | 38 | #elif defined(__loongarch64) |
| 37 | 39 | #define zig_loongarch64 |
| 38 | 40 | #define zig_loongarch |
| 41 | #elif defined(__m68k__) | |
| 42 | #define zig_m68k | |
| 43 | #elif defined(__m88k__) | |
| 44 | #define zig_m88k | |
| 39 | 45 | #elif defined(__mips64) |
| 40 | 46 | #define zig_mips64 |
| 41 | 47 | #define zig_mips |
| ... | ... | @@ -79,6 +85,8 @@ |
| 79 | 85 | #elif defined(__I86__) |
| 80 | 86 | #define zig_x86_16 |
| 81 | 87 | #define zig_x86 |
| 88 | #elif defined(__xtensa__) | |
| 89 | #define zig_xtensa | |
| 82 | 90 | #elif defined (__ez80) |
| 83 | 91 | #define zig_ez80 |
| 84 | 92 | #define zig_z80 |
| ... | ... | @@ -390,7 +398,9 @@ |
| 390 | 398 | |
| 391 | 399 | #elif defined(zig_gnuc_asm) |
| 392 | 400 | |
| 393 | #if defined(zig_thumb) | |
| 401 | #if defined(zig_alpha) | |
| 402 | #define zig_trap() __asm__ volatile("call_pal 0x000000") | |
| 403 | #elif defined(zig_thumb) | |
| 394 | 404 | #define zig_trap() __asm__ volatile("udf #0xfe") |
| 395 | 405 | #elif defined(zig_arm) || defined(zig_aarch64) |
| 396 | 406 | #define zig_trap() __asm__ volatile("udf #0xfdee") |
| ... | ... | @@ -398,6 +408,10 @@ |
| 398 | 408 | #define zig_trap() __asm__ volatile("r27:26 = memd(#0xbadc0fee)") |
| 399 | 409 | #elif defined(zig_kvx) || defined(zig_loongarch) || defined(zig_powerpc) |
| 400 | 410 | #define zig_trap() __asm__ volatile(".word 0x0") |
| 411 | #elif defined(zig_m68k) | |
| 412 | #define zig_trap() __asm__ volatile("illegal") | |
| 413 | #elif defined(zig_m88k) | |
| 414 | #define zig_trap() __asm__ volatile("tb0 0, %%r0, 511") | |
| 401 | 415 | #elif defined(zig_mips) |
| 402 | 416 | #define zig_trap() __asm__ volatile(".word 0x3d") |
| 403 | 417 | #elif defined(zig_or1k) |
| ... | ... | @@ -412,6 +426,8 @@ |
| 412 | 426 | #define zig_trap() __asm__ volatile("int $0x3") |
| 413 | 427 | #elif defined(zig_x86) |
| 414 | 428 | #define zig_trap() __asm__ volatile("ud2") |
| 429 | #elif defined(zig_xtensa) | |
| 430 | #define zig_trap() __asm__ volatile("ill") | |
| 415 | 431 | #elif defined(zig_z80) |
| 416 | 432 | #define zig_trap() __asm__ volatile("rst 00h") |
| 417 | 433 | #else |
| ... | ... | @@ -428,7 +444,9 @@ |
| 428 | 444 | #define zig_breakpoint() __debugbreak() |
| 429 | 445 | #elif defined(zig_gnuc_asm) |
| 430 | 446 | |
| 431 | #if defined(zig_arm) | |
| 447 | #if defined(zig_alpha) | |
| 448 | #define zig_breakpoint() __asm__ volatile("call_pal 0x000080") | |
| 449 | #elif defined(zig_arm) | |
| 432 | 450 | #define zig_breakpoint() __asm__ volatile("bkpt #0x0") |
| 433 | 451 | #elif defined(zig_aarch64) |
| 434 | 452 | #define zig_breakpoint() __asm__ volatile("brk #0xf000") |
| ... | ... | @@ -436,6 +454,8 @@ |
| 436 | 454 | #define zig_breakpoint() __asm__ volatile("brkpt") |
| 437 | 455 | #elif defined(zig_kvx) || defined(zig_loongarch) |
| 438 | 456 | #define zig_breakpoint() __asm__ volatile("break 0x0") |
| 457 | #elif defined(zig_m88k) | |
| 458 | #define zig_breakpoint() __asm__ volatile("illop1") | |
| 439 | 459 | #elif defined(zig_mips) |
| 440 | 460 | #define zig_breakpoint() __asm__ volatile("break") |
| 441 | 461 | #elif defined(zig_or1k) |
| ... | ... | @@ -450,6 +470,8 @@ |
| 450 | 470 | #define zig_breakpoint() __asm__ volatile("ta 0x1") |
| 451 | 471 | #elif defined(zig_x86) |
| 452 | 472 | #define zig_breakpoint() __asm__ volatile("int $0x3") |
| 473 | #elif defined(zig_xtensa) | |
| 474 | #define zig_breakpoint() __asm__ volatile("break 1, 1") | |
| 453 | 475 | #else |
| 454 | 476 | #define zig_breakpoint() zig_breakpoint_unavailable |
| 455 | 477 | #endif |
stage1/zig1.wasm| Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ |
test/behavior/align.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ const assert = std.debug.assert; |
| 7 | 7 | var foo: u8 align(4) = 100; |
| 8 | 8 | |
| 9 | 9 | test "global variable alignment" { |
| 10 | comptime assert(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4); | |
| 10 | comptime assert(@typeInfo(@TypeOf(&foo)).pointer.attrs.@"align" == 4); | |
| 11 | 11 | comptime assert(@TypeOf(&foo) == *align(4) u8); |
| 12 | 12 | { |
| 13 | 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 | 1159 | var runtime_zero: usize = 0; |
| 1160 | 1160 | _ = &runtime_zero; |
| 1161 | 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 | } |
| 1164 | 1164 | |
| 1165 | 1165 | fn testSignedCmp(comptime T: type) !void { |
| ... | ... | @@ -1284,8 +1284,8 @@ test "comptime variable initialized with addresses of literals" { |
| 1284 | 1284 | }; |
| 1285 | 1285 | _ = &st; |
| 1286 | 1286 | |
| 1287 | inline for (@typeInfo(@TypeOf(st)).@"struct".fields) |field| { | |
| 1288 | _ = field; | |
| 1287 | inline for (@typeInfo(@TypeOf(st)).@"struct".field_names) |field_name| { | |
| 1288 | _ = field_name; | |
| 1289 | 1289 | } |
| 1290 | 1290 | } |
| 1291 | 1291 |
test/behavior/bitcast.zig+2-2| ... | ... | @@ -359,8 +359,8 @@ test "comptime @bitCast packed struct to int and back" { |
| 359 | 359 | _ = &i; |
| 360 | 360 | const rt_cast = @as(S, @bitCast(i)); |
| 361 | 361 | const ct_cast = comptime @as(S, @bitCast(@as(Int, 0))); |
| 362 | inline for (@typeInfo(S).@"struct".fields) |field| { | |
| 363 | try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name)); | |
| 362 | inline for (@typeInfo(S).@"struct".field_names) |field_name| { | |
| 363 | try expectEqual(@field(rt_cast, field_name), @field(ct_cast, field_name)); | |
| 364 | 364 | } |
| 365 | 365 | } |
| 366 | 366 |
test/behavior/call.zig+2-2| ... | ... | @@ -375,7 +375,7 @@ test "Enum constructed by @Enum passed as generic argument" { |
| 375 | 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 | 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 | 556 | else => unreachable, |
| 557 | 557 | } { |
| 558 | 558 | return switch (@typeInfo(T)) { |
| 559 | .@"struct" => |info| info.fields.len, | |
| 559 | .@"struct" => |info| info.field_names.len, | |
| 560 | 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 | 1042 | const ty = @TypeOf(a, b); |
| 1043 | 1043 | const error_set_info = @typeInfo(ty); |
| 1044 | 1044 | try expect(error_set_info == .error_set); |
| 1045 | try expect(error_set_info.error_set.?.len == 2); | |
| 1046 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1047 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1045 | try expect(error_set_info.error_set.error_names.?.len == 2); | |
| 1046 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1047 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | 1050 | // B superset of A |
| ... | ... | @@ -1052,9 +1052,9 @@ test "peer type resolution: error set supersets" { |
| 1052 | 1052 | const ty = @TypeOf(b, a); |
| 1053 | 1053 | const error_set_info = @typeInfo(ty); |
| 1054 | 1054 | try expect(error_set_info == .error_set); |
| 1055 | try expect(error_set_info.error_set.?.len == 2); | |
| 1056 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1057 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1055 | try expect(error_set_info.error_set.error_names.?.len == 2); | |
| 1056 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1057 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
| 1060 | 1060 | |
| ... | ... | @@ -1070,20 +1070,20 @@ test "peer type resolution: disjoint error sets" { |
| 1070 | 1070 | const ty = @TypeOf(a, b); |
| 1071 | 1071 | const error_set_info = @typeInfo(ty); |
| 1072 | 1072 | try expect(error_set_info == .error_set); |
| 1073 | try expect(error_set_info.error_set.?.len == 3); | |
| 1074 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1075 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1076 | try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three")); | |
| 1073 | try expect(error_set_info.error_set.error_names.?.len == 3); | |
| 1074 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1075 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1076 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three")); | |
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | { |
| 1080 | 1080 | const ty = @TypeOf(b, a); |
| 1081 | 1081 | const error_set_info = @typeInfo(ty); |
| 1082 | 1082 | try expect(error_set_info == .error_set); |
| 1083 | try expect(error_set_info.error_set.?.len == 3); | |
| 1084 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1085 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1086 | try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three")); | |
| 1083 | try expect(error_set_info.error_set.error_names.?.len == 3); | |
| 1084 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1085 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1086 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three")); | |
| 1087 | 1087 | } |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| ... | ... | @@ -1101,10 +1101,10 @@ test "peer type resolution: error union and error set" { |
| 1101 | 1101 | try expect(info == .error_union); |
| 1102 | 1102 | |
| 1103 | 1103 | const error_set_info = @typeInfo(info.error_union.error_set); |
| 1104 | try expect(error_set_info.error_set.?.len == 3); | |
| 1105 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1106 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1107 | try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three")); | |
| 1104 | try expect(error_set_info.error_set.error_names.?.len == 3); | |
| 1105 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1106 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1107 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three")); | |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | { |
| ... | ... | @@ -1113,10 +1113,10 @@ test "peer type resolution: error union and error set" { |
| 1113 | 1113 | try expect(info == .error_union); |
| 1114 | 1114 | |
| 1115 | 1115 | const error_set_info = @typeInfo(info.error_union.error_set); |
| 1116 | try expect(error_set_info.error_set.?.len == 3); | |
| 1117 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1118 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1119 | try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three")); | |
| 1116 | try expect(error_set_info.error_set.error_names.?.len == 3); | |
| 1117 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1118 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1119 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three")); | |
| 1120 | 1120 | } |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| ... | ... | @@ -1135,9 +1135,9 @@ test "peer type resolution: error union after non-error" { |
| 1135 | 1135 | try expect(info.error_union.payload == u32); |
| 1136 | 1136 | |
| 1137 | 1137 | const error_set_info = @typeInfo(info.error_union.error_set); |
| 1138 | try expect(error_set_info.error_set.?.len == 2); | |
| 1139 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1140 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1138 | try expect(error_set_info.error_set.error_names.?.len == 2); | |
| 1139 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1140 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | 1143 | { |
| ... | ... | @@ -1147,9 +1147,9 @@ test "peer type resolution: error union after non-error" { |
| 1147 | 1147 | try expect(info.error_union.payload == u32); |
| 1148 | 1148 | |
| 1149 | 1149 | const error_set_info = @typeInfo(info.error_union.error_set); |
| 1150 | try expect(error_set_info.error_set.?.len == 2); | |
| 1151 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 1152 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 1150 | try expect(error_set_info.error_set.error_names.?.len == 2); | |
| 1151 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 1152 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 1153 | 1153 | } |
| 1154 | 1154 | } |
| 1155 | 1155 | |
| ... | ... | @@ -2552,9 +2552,9 @@ test "peer type resolution: tuples with comptime fields" { |
| 2552 | 2552 | inline for (.{ ti1, ti2 }) |ti| { |
| 2553 | 2553 | const s = ti.@"struct"; |
| 2554 | 2554 | comptime assert(s.is_tuple); |
| 2555 | comptime assert(s.fields.len == 2); | |
| 2556 | comptime assert(s.fields[0].type == u32); | |
| 2557 | comptime assert(s.fields[1].type == i16); | |
| 2555 | comptime assert(s.field_names.len == 2); | |
| 2556 | comptime assert(s.field_types[0] == u32); | |
| 2557 | comptime assert(s.field_types[1] == i16); | |
| 2558 | 2558 | } |
| 2559 | 2559 | |
| 2560 | 2560 | var t = true; |
| ... | ... | @@ -2665,11 +2665,11 @@ test "peer type resolution: pointer attributes are combined correctly" { |
| 2665 | 2665 | const NonAllowZero = comptime blk: { |
| 2666 | 2666 | const ptr = @typeInfo(@TypeOf(r1, r2, r3, r4)).pointer; |
| 2667 | 2667 | break :blk @Pointer(ptr.size, .{ |
| 2668 | .@"const" = ptr.is_const, | |
| 2669 | .@"volatile" = ptr.is_volatile, | |
| 2668 | .@"const" = ptr.attrs.@"const", | |
| 2669 | .@"volatile" = ptr.attrs.@"volatile", | |
| 2670 | 2670 | .@"allowzero" = false, |
| 2671 | .@"align" = ptr.alignment, | |
| 2672 | .@"addrspace" = ptr.address_space, | |
| 2671 | .@"align" = ptr.attrs.@"align", | |
| 2672 | .@"addrspace" = ptr.attrs.@"addrspace", | |
| 2673 | 2673 | }, ptr.child, ptr.sentinel()); |
| 2674 | 2674 | }; |
| 2675 | 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 | 118 | const pResult = @as(*align(1) [array_len]To, @ptrCast(&result)); |
| 119 | 119 | var i: usize = 0; |
| 120 | 120 | while (i < array_len) : (i += 1) { |
| 121 | inline for (@typeInfo(To).@"struct".fields) |f| { | |
| 122 | @field(pResult[i], f.name) = @field(pSource[i], f.name); | |
| 121 | inline for (@typeInfo(To).@"struct".field_names) |f_name| { | |
| 122 | @field(pResult[i], f_name) = @field(pSource[i], f_name); | |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | return result; |
test/behavior/enum.zig+8-6| ... | ... | @@ -644,12 +644,12 @@ test "non-exhaustive enum" { |
| 644 | 644 | else => true, |
| 645 | 645 | }); |
| 646 | 646 | |
| 647 | try expect(@typeInfo(E).@"enum".fields.len == 2); | |
| 647 | try expect(@typeInfo(E).@"enum".field_names.len == 2); | |
| 648 | 648 | e = @as(E, @enumFromInt(12)); |
| 649 | 649 | try expect(@intFromEnum(e) == 12); |
| 650 | 650 | e = @as(E, @enumFromInt(y)); |
| 651 | 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 | 655 | try S.doTheTest(52); |
| ... | ... | @@ -668,8 +668,9 @@ test "empty non-exhaustive enum" { |
| 668 | 668 | }); |
| 669 | 669 | try expect(@intFromEnum(e) == y); |
| 670 | 670 | |
| 671 | try expect(@typeInfo(E).@"enum".fields.len == 0); | |
| 672 | try expect(@typeInfo(E).@"enum".is_exhaustive == false); | |
| 671 | try expect(@typeInfo(E).@"enum".field_names.len == 0); | |
| 672 | try expect(@typeInfo(E).@"enum".field_values.len == 0); | |
| 673 | try expect(@typeInfo(E).@"enum".mode == .nonexhaustive); | |
| 673 | 674 | } |
| 674 | 675 | }; |
| 675 | 676 | try S.doTheTest(42); |
| ... | ... | @@ -704,8 +705,9 @@ test "single field non-exhaustive enum" { |
| 704 | 705 | }); |
| 705 | 706 | |
| 706 | 707 | try expect(@intFromEnum(@as(E, @enumFromInt(y))) == y); |
| 707 | try expect(@typeInfo(E).@"enum".fields.len == 1); | |
| 708 | try expect(@typeInfo(E).@"enum".is_exhaustive == false); | |
| 708 | try expect(@typeInfo(E).@"enum".field_names.len == 1); | |
| 709 | try expect(@typeInfo(E).@"enum".field_values.len == 1); | |
| 710 | try expect(@typeInfo(E).@"enum".mode == .nonexhaustive); | |
| 709 | 711 | } |
| 710 | 712 | }; |
| 711 | 713 | try S.doTheTest(23); |
test/behavior/error.zig+4-4| ... | ... | @@ -206,7 +206,7 @@ const MyErrSet = error{ |
| 206 | 206 | }; |
| 207 | 207 | |
| 208 | 208 | fn testErrorSetType() !void { |
| 209 | try expect(@typeInfo(MyErrSet).error_set.?.len == 2); | |
| 209 | try expect(@typeInfo(MyErrSet).error_set.error_names.?.len == 2); | |
| 210 | 210 | |
| 211 | 211 | const a: MyErrSet!i32 = 5678; |
| 212 | 212 | const b: MyErrSet!i32 = MyErrSet.OutOfMemory; |
| ... | ... | @@ -1125,9 +1125,9 @@ test "@errorCast into own inferred error set" { |
| 1125 | 1125 | try expect(err == error.Bad); |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | const errors = @typeInfo(@typeInfo(@TypeOf(static.foo(false))).error_union.error_set).error_set.?; | |
| 1129 | comptime assert(errors.len == 1); | |
| 1130 | comptime assert(std.mem.eql(u8, errors[0].name, "Bad")); | |
| 1128 | const error_names = @typeInfo(@typeInfo(@TypeOf(static.foo(false))).error_union.error_set).error_set.error_names.?; | |
| 1129 | comptime assert(error_names.len == 1); | |
| 1130 | comptime assert(std.mem.eql(u8, error_names[0], "Bad")); | |
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | test "@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 | 889 | }; |
| 890 | 890 | |
| 891 | 891 | const S = struct { |
| 892 | fn declarations(comptime T: type) []const std.builtin.Type.Declaration { | |
| 893 | return @typeInfo(T).@"enum".decls; | |
| 892 | fn declarations(comptime T: type) []const [:0]const u8 { | |
| 893 | return @typeInfo(T).@"enum".decl_names; | |
| 894 | 894 | } |
| 895 | 895 | }; |
| 896 | 896 | |
| 897 | const decls = comptime [_][]const std.builtin.Type.Declaration{ | |
| 897 | const decls = comptime [_][]const [:0]const u8{ | |
| 898 | 898 | S.declarations(E1), |
| 899 | 899 | }; |
| 900 | 900 | |
| 901 | comptime assert(decls[0][0].name[0] == 'a'); | |
| 901 | comptime assert(decls[0][0][0] == 'a'); | |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | test "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 | 400 | }; |
| 401 | 401 | |
| 402 | 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 | } |
| 405 | 405 | |
| 406 | 406 | test "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 | 175 | |
| 176 | 176 | const S = struct { |
| 177 | 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 | }; |
| 181 | 181 | |
| ... | ... | @@ -255,10 +255,13 @@ test "generic function instantiation turns into comptime call" { |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 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 | 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 | } |
| 263 | 266 | |
| 264 | 267 | pub fn FieldEnum(comptime T: type) type { |
test/behavior/memcpy.zig+3-3| ... | ... | @@ -157,9 +157,9 @@ test "@memcpy with sentinel" { |
| 157 | 157 | |
| 158 | 158 | const S = struct { |
| 159 | 159 | fn doTheTest() void { |
| 160 | const field = @typeInfo(struct { a: u32 }).@"struct".fields[0]; | |
| 161 | var buffer: [field.name.len]u8 = undefined; | |
| 162 | @memcpy(&buffer, field.name); | |
| 160 | const field_name = @typeInfo(struct { a: u32 }).@"struct".field_names[0]; | |
| 161 | var buffer: [field_name.len]u8 = undefined; | |
| 162 | @memcpy(&buffer, field_name); | |
| 163 | 163 | } |
| 164 | 164 | }; |
| 165 | 165 |
test/behavior/packed-struct.zig+2-2| ... | ... | @@ -1040,9 +1040,9 @@ test "packed struct field pointer aligned properly" { |
| 1040 | 1040 | }; |
| 1041 | 1041 | |
| 1042 | 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 | 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 | } |
| 1047 | 1047 | |
| 1048 | 1048 | test "load flag from packed struct in union" { |
test/behavior/pointers.zig+18-18| ... | ... | @@ -291,8 +291,8 @@ test "allowzero pointer and slice" { |
| 291 | 291 | comptime assert(@TypeOf(slice) == []allowzero i32); |
| 292 | 292 | try expect(@intFromPtr(&slice[5]) == 20); |
| 293 | 293 | |
| 294 | comptime assert(@typeInfo(@TypeOf(ptr)).pointer.is_allowzero); | |
| 295 | comptime assert(@typeInfo(@TypeOf(slice)).pointer.is_allowzero); | |
| 294 | comptime assert(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"allowzero"); | |
| 295 | comptime assert(@typeInfo(@TypeOf(slice)).pointer.attrs.@"allowzero"); | |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | test "assign null directly to C pointer and test null equality" { |
| ... | ... | @@ -470,15 +470,15 @@ test "pointer-integer arithmetic affects the alignment" { |
| 470 | 470 | var x: usize = 1; |
| 471 | 471 | _ = .{ &ptr, &x }; |
| 472 | 472 | |
| 473 | try expect(@typeInfo(@TypeOf(ptr)).pointer.alignment == 8); | |
| 473 | try expect(@typeInfo(@TypeOf(ptr)).pointer.attrs.@"align" == 8); | |
| 474 | 474 | 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 | 476 | 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 | 478 | 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 | 480 | 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 | 484 | var ptr: [*]align(8) [3]u8 = undefined; |
| ... | ... | @@ -486,13 +486,13 @@ test "pointer-integer arithmetic affects the alignment" { |
| 486 | 486 | _ = .{ &ptr, &x }; |
| 487 | 487 | |
| 488 | 488 | 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 | 490 | 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 | 492 | 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 | 494 | 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 | } |
| 498 | 498 | |
| ... | ... | @@ -592,7 +592,7 @@ test "pointer to constant decl preserves alignment" { |
| 592 | 592 | const aligned align(8) = @This(){ .a = 3, .b = 4 }; |
| 593 | 593 | }; |
| 594 | 594 | |
| 595 | const alignment = @typeInfo(@TypeOf(&S.aligned)).pointer.alignment; | |
| 595 | const alignment = @typeInfo(@TypeOf(&S.aligned)).pointer.attrs.@"align"; | |
| 596 | 596 | try std.testing.expect(alignment == 8); |
| 597 | 597 | } |
| 598 | 598 | |
| ... | ... | @@ -673,24 +673,24 @@ const Box2 = struct { |
| 673 | 673 | |
| 674 | 674 | fn mutable() !void { |
| 675 | 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); | |
| 677 | 677 | |
| 678 | 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); | |
| 680 | 680 | |
| 681 | 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 | } |
| 684 | 684 | |
| 685 | 685 | fn constant() !void { |
| 686 | 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); | |
| 688 | 688 | |
| 689 | 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); | |
| 691 | 691 | |
| 692 | 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 | } |
| 695 | 695 | |
| 696 | 696 | test "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 | 8 | comptime { |
| 9 | 9 | const info = @typeInfo(@TypeOf(dummy)).@"fn"; |
| 10 | 10 | try expect(info.return_type.? == i32); |
| 11 | try expect(!info.is_var_args); | |
| 12 | try expect(info.params.len == 3); | |
| 13 | try expect(info.params[0].type.? == bool); | |
| 14 | try expect(info.params[1].type.? == i32); | |
| 15 | try expect(info.params[2].type.? == f32); | |
| 11 | try expect(!info.attrs.varargs); | |
| 12 | try expect(info.param_types.len == 3); | |
| 13 | try expect(info.param_types[0].? == bool); | |
| 14 | try expect(info.param_types[1].? == i32); | |
| 15 | try expect(info.param_types[2].? == f32); | |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 |
test/behavior/slice.zig+3-3| ... | ... | @@ -388,9 +388,9 @@ test "empty array to slice" { |
| 388 | 388 | const align_1: []align(1) u8 = empty; |
| 389 | 389 | const align_4: []align(4) u8 = empty; |
| 390 | 390 | const align_16: []align(16) u8 = empty; |
| 391 | try expect(1 == @typeInfo(@TypeOf(align_1)).pointer.alignment); | |
| 392 | try expect(4 == @typeInfo(@TypeOf(align_4)).pointer.alignment); | |
| 393 | try expect(16 == @typeInfo(@TypeOf(align_16)).pointer.alignment); | |
| 391 | try expect(1 == @typeInfo(@TypeOf(align_1)).pointer.attrs.@"align"); | |
| 392 | try expect(4 == @typeInfo(@TypeOf(align_4)).pointer.attrs.@"align"); | |
| 393 | try expect(16 == @typeInfo(@TypeOf(align_16)).pointer.attrs.@"align"); | |
| 394 | 394 | } |
| 395 | 395 | }; |
| 396 | 396 |
test/behavior/struct.zig+1-1| ... | ... | @@ -1627,7 +1627,7 @@ test "packed struct field in anonymous struct" { |
| 1627 | 1627 | try std.testing.expect(countFields(.{ .t = T{} }) == 1); |
| 1628 | 1628 | } |
| 1629 | 1629 | fn countFields(v: anytype) usize { |
| 1630 | return @typeInfo(@TypeOf(v)).@"struct".fields.len; | |
| 1630 | return @typeInfo(@TypeOf(v)).@"struct".field_names.len; | |
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | test "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 | 512 | |
| 513 | 513 | const T = struct { struct {} }; |
| 514 | 514 | const info = @typeInfo(T); |
| 515 | try std.testing.expectEqual(@as(usize, 1), info.@"struct".fields.len); | |
| 516 | try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name); | |
| 517 | try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"struct"); | |
| 515 | try std.testing.expectEqual(@as(usize, 1), info.@"struct".field_names.len); | |
| 516 | try std.testing.expectEqualStrings("0", info.@"struct".field_names[0]); | |
| 517 | try std.testing.expect(@typeInfo(info.@"struct".field_types[0]) == .@"struct"); | |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | test "empty union in tuple" { |
| ... | ... | @@ -524,9 +524,9 @@ test "empty union in tuple" { |
| 524 | 524 | |
| 525 | 525 | const T = struct { union {} }; |
| 526 | 526 | const info = @typeInfo(T); |
| 527 | try std.testing.expectEqual(@as(usize, 1), info.@"struct".fields.len); | |
| 528 | try std.testing.expectEqualStrings("0", info.@"struct".fields[0].name); | |
| 529 | try std.testing.expect(@typeInfo(info.@"struct".fields[0].type) == .@"union"); | |
| 527 | try std.testing.expectEqual(@as(usize, 1), info.@"struct".field_names.len); | |
| 528 | try std.testing.expectEqualStrings("0", info.@"struct".field_names[0]); | |
| 529 | try std.testing.expect(@typeInfo(info.@"struct".field_types[0]) == .@"union"); | |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | test "field pointer of underaligned tuple" { |
| ... | ... | @@ -551,11 +551,11 @@ test "field pointer of underaligned tuple" { |
| 551 | 551 | test "OPV tuple fields aren't comptime" { |
| 552 | 552 | const T = struct { void }; |
| 553 | 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"); | |
| 555 | 555 | |
| 556 | 556 | const T2 = @Tuple(&.{void}); |
| 557 | 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 | } |
| 560 | 560 | |
| 561 | 561 | test "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 | 12 | const T = struct { comptime u32 = 1, []const u8 }; |
| 13 | 13 | const info = @typeInfo(T).@"struct"; |
| 14 | 14 | |
| 15 | try expect(info.is_tuple); | |
| 15 | 16 | try expect(info.layout == .auto); |
| 16 | 17 | try expect(info.backing_integer == null); |
| 17 | try expect(info.fields.len == 2); | |
| 18 | try expect(info.decls.len == 0); | |
| 19 | try expect(info.is_tuple); | |
| 20 | ||
| 21 | try expectEqualStrings(info.fields[0].name, "0"); | |
| 22 | try expect(info.fields[0].type == u32); | |
| 23 | try expect(info.fields[0].defaultValue() == 1); | |
| 24 | try expect(info.fields[0].is_comptime); | |
| 25 | try expect(info.fields[0].alignment == null); | |
| 26 | ||
| 27 | try expectEqualStrings(info.fields[1].name, "1"); | |
| 28 | try expect(info.fields[1].type == []const u8); | |
| 29 | try expect(info.fields[1].defaultValue() == null); | |
| 30 | try expect(!info.fields[1].is_comptime); | |
| 31 | try expect(info.fields[1].alignment == null); | |
| 18 | try expect(info.field_names.len == 2); | |
| 19 | try expect(info.decl_names.len == 0); | |
| 20 | ||
| 21 | try expectEqualStrings(info.field_names[0], "0"); | |
| 22 | try expect(info.field_types[0] == u32); | |
| 23 | try expect(info.field_attrs[0].defaultValue(info.field_types[0]) == 1); | |
| 24 | try expect(info.field_attrs[0].@"comptime"); | |
| 25 | try expect(info.field_attrs[0].@"align" == null); | |
| 26 | ||
| 27 | try expectEqualStrings(info.field_names[1], "1"); | |
| 28 | try expect(info.field_types[1] == []const u8); | |
| 29 | try expect(info.field_attrs[1].defaultValue(info.field_types[1]) == null); | |
| 30 | try expect(!info.field_attrs[1].@"comptime"); | |
| 31 | try expect(info.field_attrs[1].@"align" == null); | |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 |
test/behavior/type.zig+37-49| ... | ... | @@ -57,13 +57,7 @@ test "Type.Pointer" { |
| 57 | 57 | [*c]align(8) volatile u8, [*c]align(8) const volatile u8, |
| 58 | 58 | }) |testType| { |
| 59 | 59 | const ptr = @typeInfo(testType).pointer; |
| 60 | try testing.expect(testType == @Pointer(ptr.size, .{ | |
| 61 | .@"const" = ptr.is_const, | |
| 62 | .@"volatile" = ptr.is_volatile, | |
| 63 | .@"allowzero" = ptr.is_allowzero, | |
| 64 | .@"align" = ptr.alignment, | |
| 65 | .@"addrspace" = ptr.address_space, | |
| 66 | }, ptr.child, ptr.sentinel())); | |
| 60 | try testing.expect(testType == @Pointer(ptr.size, ptr.attrs, ptr.child, ptr.sentinel())); | |
| 67 | 61 | } |
| 68 | 62 | } |
| 69 | 63 | |
| ... | ... | @@ -103,13 +97,7 @@ test "@Pointer on @typeInfo round-trips sentinels" { |
| 103 | 97 | [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8, |
| 104 | 98 | }) |TestType| { |
| 105 | 99 | const ptr = @typeInfo(TestType).pointer; |
| 106 | try testing.expect(TestType == @Pointer(ptr.size, .{ | |
| 107 | .@"const" = ptr.is_const, | |
| 108 | .@"volatile" = ptr.is_volatile, | |
| 109 | .@"allowzero" = ptr.is_allowzero, | |
| 110 | .@"align" = ptr.alignment, | |
| 111 | .@"addrspace" = ptr.address_space, | |
| 112 | }, ptr.child, ptr.sentinel())); | |
| 100 | try testing.expect(TestType == @Pointer(ptr.size, ptr.attrs, ptr.child, ptr.sentinel())); | |
| 113 | 101 | } |
| 114 | 102 | } |
| 115 | 103 | |
| ... | ... | @@ -122,9 +110,9 @@ test "Type.Opaque" { |
| 122 | 110 | const Opaque = opaque {}; |
| 123 | 111 | try testing.expect(Opaque != opaque {}); |
| 124 | 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 | } |
| 130 | 118 | |
| ... | ... | @@ -141,13 +129,13 @@ test "Type.Struct" { |
| 141 | 129 | const A = @Struct(.auto, null, &.{ "x", "y" }, &.{ u8, u32 }, &@splat(.{})); |
| 142 | 130 | const infoA = @typeInfo(A).@"struct"; |
| 143 | 131 | try testing.expectEqual(Type.ContainerLayout.auto, infoA.layout); |
| 144 | try testing.expectEqualSlices(u8, "x", infoA.fields[0].name); | |
| 145 | try testing.expectEqual(u8, infoA.fields[0].type); | |
| 146 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[0].default_value_ptr); | |
| 147 | try testing.expectEqualSlices(u8, "y", infoA.fields[1].name); | |
| 148 | try testing.expectEqual(u32, infoA.fields[1].type); | |
| 149 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.fields[1].default_value_ptr); | |
| 150 | try testing.expectEqualSlices(Type.Declaration, &.{}, infoA.decls); | |
| 132 | try testing.expectEqualSlices(u8, "x", infoA.field_names[0]); | |
| 133 | try testing.expectEqual(u8, infoA.field_types[0]); | |
| 134 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.field_attrs[0].default_value_ptr); | |
| 135 | try testing.expectEqualSlices(u8, "y", infoA.field_names[1]); | |
| 136 | try testing.expectEqual(u32, infoA.field_types[1]); | |
| 137 | try testing.expectEqual(@as(?*const anyopaque, null), infoA.field_attrs[1].default_value_ptr); | |
| 138 | try testing.expectEqualSlices([:0]const u8, &.{}, infoA.decl_names); | |
| 151 | 139 | try testing.expectEqual(@as(bool, false), infoA.is_tuple); |
| 152 | 140 | |
| 153 | 141 | var a = A{ .x = 0, .y = 1 }; |
| ... | ... | @@ -165,13 +153,13 @@ test "Type.Struct" { |
| 165 | 153 | ); |
| 166 | 154 | const infoB = @typeInfo(B).@"struct"; |
| 167 | 155 | try testing.expectEqual(Type.ContainerLayout.@"extern", infoB.layout); |
| 168 | try testing.expectEqualSlices(u8, "x", infoB.fields[0].name); | |
| 169 | try testing.expectEqual(u8, infoB.fields[0].type); | |
| 170 | try testing.expectEqual(@as(?*const anyopaque, null), infoB.fields[0].default_value_ptr); | |
| 171 | try testing.expectEqualSlices(u8, "y", infoB.fields[1].name); | |
| 172 | try testing.expectEqual(u32, infoB.fields[1].type); | |
| 173 | try testing.expectEqual(@as(u32, 5), infoB.fields[1].defaultValue().?); | |
| 174 | try testing.expectEqual(@as(usize, 0), infoB.decls.len); | |
| 156 | try testing.expectEqualSlices(u8, "x", infoB.field_names[0]); | |
| 157 | try testing.expectEqual(u8, infoB.field_types[0]); | |
| 158 | try testing.expectEqual(@as(?*const anyopaque, null), infoB.field_attrs[0].default_value_ptr); | |
| 159 | try testing.expectEqualSlices(u8, "y", infoB.field_names[1]); | |
| 160 | try testing.expectEqual(u32, infoB.field_types[1]); | |
| 161 | try testing.expectEqual(@as(u32, 5), infoB.field_attrs[1].defaultValue(infoB.field_types[1]).?); | |
| 162 | try testing.expectEqual(@as(usize, 0), infoB.decl_names.len); | |
| 175 | 163 | try testing.expectEqual(@as(bool, false), infoB.is_tuple); |
| 176 | 164 | |
| 177 | 165 | const C = @Struct( |
| ... | ... | @@ -186,20 +174,20 @@ test "Type.Struct" { |
| 186 | 174 | ); |
| 187 | 175 | const infoC = @typeInfo(C).@"struct"; |
| 188 | 176 | try testing.expectEqual(Type.ContainerLayout.@"packed", infoC.layout); |
| 189 | try testing.expectEqualSlices(u8, "x", infoC.fields[0].name); | |
| 190 | try testing.expectEqual(u8, infoC.fields[0].type); | |
| 191 | try testing.expectEqual(@as(u8, 3), infoC.fields[0].defaultValue().?); | |
| 192 | try testing.expectEqualSlices(u8, "y", infoC.fields[1].name); | |
| 193 | try testing.expectEqual(u32, infoC.fields[1].type); | |
| 194 | try testing.expectEqual(@as(u32, 5), infoC.fields[1].defaultValue().?); | |
| 195 | try testing.expectEqual(@as(usize, 0), infoC.decls.len); | |
| 177 | try testing.expectEqualSlices(u8, "x", infoC.field_names[0]); | |
| 178 | try testing.expectEqual(u8, infoC.field_types[0]); | |
| 179 | try testing.expectEqual(@as(u8, 3), infoC.field_attrs[0].defaultValue(infoC.field_types[0]).?); | |
| 180 | try testing.expectEqualSlices(u8, "y", infoC.field_names[1]); | |
| 181 | try testing.expectEqual(u32, infoC.field_types[1]); | |
| 182 | try testing.expectEqual(@as(u32, 5), infoC.field_attrs[1].defaultValue(infoC.field_types[1]).?); | |
| 183 | try testing.expectEqual(@as(usize, 0), infoC.decl_names.len); | |
| 196 | 184 | try testing.expectEqual(@as(bool, false), infoC.is_tuple); |
| 197 | 185 | |
| 198 | 186 | // empty struct |
| 199 | 187 | const F = @Struct(.auto, null, &.{}, &.{}, &.{}); |
| 200 | 188 | const infoF = @typeInfo(F).@"struct"; |
| 201 | 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 | 191 | try testing.expectEqual(@as(bool, false), infoF.is_tuple); |
| 204 | 192 | } |
| 205 | 193 | |
| ... | ... | @@ -208,11 +196,11 @@ test "Type.Enum" { |
| 208 | 196 | if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; |
| 209 | 197 | |
| 210 | 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 | 200 | try testing.expectEqual(@as(u8, 1), @intFromEnum(Foo.a)); |
| 213 | 201 | try testing.expectEqual(@as(u8, 5), @intFromEnum(Foo.b)); |
| 214 | 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 | 204 | try testing.expectEqual(@as(u32, 1), @intFromEnum(Bar.a)); |
| 217 | 205 | try testing.expectEqual(@as(u32, 5), @intFromEnum(Bar.b)); |
| 218 | 206 | try testing.expectEqual(@as(u32, 6), @intFromEnum(@as(Bar, @enumFromInt(6)))); |
| ... | ... | @@ -278,13 +266,13 @@ test "Type.Union from regular enum" { |
| 278 | 266 | test "Type.Union from empty regular enum" { |
| 279 | 267 | const E = enum {}; |
| 280 | 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 | } |
| 283 | 271 | |
| 284 | 272 | test "Type.Union from empty Type.Enum" { |
| 285 | 273 | const E = @Enum(u0, .exhaustive, &.{}, &.{}); |
| 286 | 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 | } |
| 289 | 277 | |
| 290 | 278 | test "Type.Fn" { |
| ... | ... | @@ -378,11 +366,11 @@ test "struct field names sliced at comptime from larger string" { |
| 378 | 366 | } |
| 379 | 367 | |
| 380 | 368 | const T = @Struct(.auto, null, field_names, &@splat(usize), &@splat(.{})); |
| 381 | const gen_fields = @typeInfo(T).@"struct".fields; | |
| 382 | try testing.expectEqual(3, gen_fields.len); | |
| 383 | try testing.expectEqualStrings("f1", gen_fields[0].name); | |
| 384 | try testing.expectEqualStrings("f2", gen_fields[1].name); | |
| 385 | try testing.expectEqualStrings("f3", gen_fields[2].name); | |
| 369 | const gen_field_names = @typeInfo(T).@"struct".field_names; | |
| 370 | try testing.expectEqual(3, gen_field_names.len); | |
| 371 | try testing.expectEqualStrings("f1", gen_field_names[0]); | |
| 372 | try testing.expectEqualStrings("f2", gen_field_names[1]); | |
| 373 | try testing.expectEqualStrings("f3", gen_field_names[2]); | |
| 386 | 374 | } |
| 387 | 375 | } |
| 388 | 376 | |
| ... | ... | @@ -431,8 +419,8 @@ test "undefined type value" { |
| 431 | 419 | test "reify struct with zero fields through const arrays" { |
| 432 | 420 | const names: [0][]const u8 = .{}; |
| 433 | 421 | const types: [0]type = .{}; |
| 434 | const attrs: [0]std.builtin.Type.StructField.Attributes = .{}; | |
| 422 | const attrs: [0]std.builtin.Type.Struct.FieldAttributes = .{}; | |
| 435 | 423 | const S = @Struct(.auto, null, &names, &types, &attrs); |
| 436 | 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 | 45 | const ptr_info = @typeInfo([*c]align(4) const i8); |
| 46 | 46 | try expect(ptr_info == .pointer); |
| 47 | 47 | try expect(ptr_info.pointer.size == .c); |
| 48 | try expect(ptr_info.pointer.is_const); | |
| 49 | try expect(!ptr_info.pointer.is_volatile); | |
| 50 | try expect(ptr_info.pointer.alignment == 4); | |
| 48 | try expect(ptr_info.pointer.attrs.@"const"); | |
| 49 | try expect(!ptr_info.pointer.attrs.@"volatile"); | |
| 50 | try expect(ptr_info.pointer.attrs.@"align" == 4); | |
| 51 | 51 | try expect(ptr_info.pointer.child == i8); |
| 52 | 52 | } |
| 53 | 53 | |
| ... | ... | @@ -80,9 +80,9 @@ fn testPointer() !void { |
| 80 | 80 | const u32_ptr_info = @typeInfo(*u32); |
| 81 | 81 | try expect(u32_ptr_info == .pointer); |
| 82 | 82 | try expect(u32_ptr_info.pointer.size == .one); |
| 83 | try expect(u32_ptr_info.pointer.is_const == false); | |
| 84 | try expect(u32_ptr_info.pointer.is_volatile == false); | |
| 85 | try expect(u32_ptr_info.pointer.alignment == null); | |
| 83 | try expect(u32_ptr_info.pointer.attrs.@"const" == false); | |
| 84 | try expect(u32_ptr_info.pointer.attrs.@"volatile" == false); | |
| 85 | try expect(u32_ptr_info.pointer.attrs.@"align" == null); | |
| 86 | 86 | try expect(u32_ptr_info.pointer.child == u32); |
| 87 | 87 | try expect(u32_ptr_info.pointer.sentinel() == null); |
| 88 | 88 | } |
| ... | ... | @@ -96,11 +96,11 @@ fn testUnknownLenPtr() !void { |
| 96 | 96 | const u32_ptr_info = @typeInfo([*]const volatile f64); |
| 97 | 97 | try expect(u32_ptr_info == .pointer); |
| 98 | 98 | try expect(u32_ptr_info.pointer.size == .many); |
| 99 | try expect(u32_ptr_info.pointer.is_const == true); | |
| 100 | try expect(u32_ptr_info.pointer.is_volatile == true); | |
| 101 | try expect(u32_ptr_info.pointer.sentinel() == null); | |
| 102 | try expect(u32_ptr_info.pointer.alignment == null); | |
| 99 | try expect(u32_ptr_info.pointer.attrs.@"const" == true); | |
| 100 | try expect(u32_ptr_info.pointer.attrs.@"volatile" == true); | |
| 101 | try expect(u32_ptr_info.pointer.attrs.@"align" == null); | |
| 103 | 102 | try expect(u32_ptr_info.pointer.child == f64); |
| 103 | try expect(u32_ptr_info.pointer.sentinel() == null); | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | test "type info: null terminated pointer type info" { |
| ... | ... | @@ -112,8 +112,8 @@ fn testNullTerminatedPtr() !void { |
| 112 | 112 | const ptr_info = @typeInfo([*:0]u8); |
| 113 | 113 | try expect(ptr_info == .pointer); |
| 114 | 114 | try expect(ptr_info.pointer.size == .many); |
| 115 | try expect(ptr_info.pointer.is_const == false); | |
| 116 | try expect(ptr_info.pointer.is_volatile == false); | |
| 115 | try expect(ptr_info.pointer.attrs.@"const" == false); | |
| 116 | try expect(ptr_info.pointer.attrs.@"volatile" == false); | |
| 117 | 117 | try expect(ptr_info.pointer.sentinel().? == 0); |
| 118 | 118 | |
| 119 | 119 | try expect(@typeInfo([:0]u8).pointer.sentinel() != null); |
| ... | ... | @@ -128,9 +128,9 @@ fn testSlice() !void { |
| 128 | 128 | const u32_slice_info = @typeInfo([]u32); |
| 129 | 129 | try expect(u32_slice_info == .pointer); |
| 130 | 130 | try expect(u32_slice_info.pointer.size == .slice); |
| 131 | try expect(u32_slice_info.pointer.is_const == false); | |
| 132 | try expect(u32_slice_info.pointer.is_volatile == false); | |
| 133 | try expect(u32_slice_info.pointer.alignment == null); | |
| 131 | try expect(u32_slice_info.pointer.attrs.@"const" == false); | |
| 132 | try expect(u32_slice_info.pointer.attrs.@"volatile" == false); | |
| 133 | try expect(u32_slice_info.pointer.attrs.@"align" == null); | |
| 134 | 134 | try expect(u32_slice_info.pointer.child == u32); |
| 135 | 135 | } |
| 136 | 136 | |
| ... | ... | @@ -175,8 +175,8 @@ fn testErrorSet() !void { |
| 175 | 175 | |
| 176 | 176 | const error_set_info = @typeInfo(TestErrorSet); |
| 177 | 177 | try expect(error_set_info == .error_set); |
| 178 | try expect(error_set_info.error_set.?.len == 3); | |
| 179 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "First")); | |
| 178 | try expect(error_set_info.error_set.error_names.?.len == 3); | |
| 179 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "First")); | |
| 180 | 180 | |
| 181 | 181 | const error_union_info = @typeInfo(TestErrorSet!usize); |
| 182 | 182 | try expect(error_union_info == .error_union); |
| ... | ... | @@ -185,7 +185,7 @@ fn testErrorSet() !void { |
| 185 | 185 | |
| 186 | 186 | const global_info = @typeInfo(anyerror); |
| 187 | 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 | } |
| 190 | 190 | |
| 191 | 191 | test "type info: error set single value" { |
| ... | ... | @@ -197,8 +197,8 @@ test "type info: error set single value" { |
| 197 | 197 | |
| 198 | 198 | const error_set_info = @typeInfo(@TypeOf(TestSet)); |
| 199 | 199 | try expect(error_set_info == .error_set); |
| 200 | try expect(error_set_info.error_set.?.len == 1); | |
| 201 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 200 | try expect(error_set_info.error_set.error_names.?.len == 1); | |
| 201 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | test "type info: error set merged" { |
| ... | ... | @@ -210,10 +210,10 @@ test "type info: error set merged" { |
| 210 | 210 | |
| 211 | 211 | const error_set_info = @typeInfo(TestSet); |
| 212 | 212 | try expect(error_set_info == .error_set); |
| 213 | try expect(error_set_info.error_set.?.len == 3); | |
| 214 | try expect(mem.eql(u8, error_set_info.error_set.?[0].name, "One")); | |
| 215 | try expect(mem.eql(u8, error_set_info.error_set.?[1].name, "Two")); | |
| 216 | try expect(mem.eql(u8, error_set_info.error_set.?[2].name, "Three")); | |
| 213 | try expect(error_set_info.error_set.error_names.?.len == 3); | |
| 214 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[0], "One")); | |
| 215 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[1], "Two")); | |
| 216 | try expect(mem.eql(u8, error_set_info.error_set.error_names.?[2], "Three")); | |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | test "type info: enum info" { |
| ... | ... | @@ -235,11 +235,12 @@ fn testEnum() !void { |
| 235 | 235 | |
| 236 | 236 | const os_info = @typeInfo(Os); |
| 237 | 237 | try expect(os_info == .@"enum"); |
| 238 | try expect(os_info.@"enum".fields.len == 4); | |
| 239 | try expect(mem.eql(u8, os_info.@"enum".fields[1].name, "Macos")); | |
| 240 | try expect(os_info.@"enum".fields[3].value == 3); | |
| 238 | try expect(os_info.@"enum".field_names.len == 4); | |
| 239 | try expect(os_info.@"enum".field_values.len == os_info.@"enum".field_names.len); | |
| 240 | try expect(mem.eql(u8, os_info.@"enum".field_names[1], "Macos")); | |
| 241 | try expect(os_info.@"enum".field_values[3] == 3); | |
| 241 | 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 | } |
| 244 | 245 | |
| 245 | 246 | test "type info: union info" { |
| ... | ... | @@ -252,9 +253,11 @@ fn testUnion() !void { |
| 252 | 253 | try expect(typeinfo_info == .@"union"); |
| 253 | 254 | try expect(typeinfo_info.@"union".layout == .auto); |
| 254 | 255 | try expect(typeinfo_info.@"union".tag_type.? == TypeId); |
| 255 | try expect(typeinfo_info.@"union".fields.len == 24); | |
| 256 | try expect(typeinfo_info.@"union".fields[4].type == @TypeOf(@typeInfo(u8).int)); | |
| 257 | try expect(typeinfo_info.@"union".decls.len == 21); | |
| 256 | try expect(typeinfo_info.@"union".field_names.len == 24); | |
| 257 | try expect(typeinfo_info.@"union".field_names.len == typeinfo_info.@"union".field_types.len); | |
| 258 | try expect(typeinfo_info.@"union".field_names.len == typeinfo_info.@"union".field_attrs.len); | |
| 259 | try expect(typeinfo_info.@"union".field_types[4] == @TypeOf(@typeInfo(u8).int)); | |
| 260 | try expect(typeinfo_info.@"union".decl_names.len == 16); | |
| 258 | 261 | |
| 259 | 262 | const TestNoTagUnion = union { |
| 260 | 263 | Foo: void, |
| ... | ... | @@ -265,10 +268,12 @@ fn testUnion() !void { |
| 265 | 268 | try expect(notag_union_info == .@"union"); |
| 266 | 269 | try expect(notag_union_info.@"union".tag_type == null); |
| 267 | 270 | try expect(notag_union_info.@"union".layout == .auto); |
| 268 | try expect(notag_union_info.@"union".fields.len == 2); | |
| 269 | try expect(notag_union_info.@"union".fields[0].alignment == null); | |
| 270 | try expect(notag_union_info.@"union".fields[1].type == u32); | |
| 271 | try expect(notag_union_info.@"union".fields[1].alignment == null); | |
| 271 | try expect(notag_union_info.@"union".field_names.len == 2); | |
| 272 | try expect(notag_union_info.@"union".field_names.len == notag_union_info.@"union".field_types.len); | |
| 273 | try expect(notag_union_info.@"union".field_names.len == notag_union_info.@"union".field_attrs.len); | |
| 274 | try expect(notag_union_info.@"union".field_attrs[0].@"align" == null); | |
| 275 | try expect(notag_union_info.@"union".field_types[1] == u32); | |
| 276 | try expect(notag_union_info.@"union".field_attrs[1].@"align" == null); | |
| 272 | 277 | |
| 273 | 278 | const TestExternUnion = extern union { |
| 274 | 279 | foo: *anyopaque, |
| ... | ... | @@ -277,7 +282,7 @@ fn testUnion() !void { |
| 277 | 282 | const extern_union_info = @typeInfo(TestExternUnion); |
| 278 | 283 | try expect(extern_union_info.@"union".layout == .@"extern"); |
| 279 | 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 | } |
| 282 | 287 | |
| 283 | 288 | test "type info: struct info" { |
| ... | ... | @@ -292,9 +297,11 @@ fn testStruct() !void { |
| 292 | 297 | const unpacked_struct_info = @typeInfo(TestStruct); |
| 293 | 298 | try expect(unpacked_struct_info.@"struct".is_tuple == false); |
| 294 | 299 | try expect(unpacked_struct_info.@"struct".backing_integer == null); |
| 295 | try expect(unpacked_struct_info.@"struct".fields[0].alignment == null); | |
| 296 | try expect(unpacked_struct_info.@"struct".fields[0].defaultValue().? == 4); | |
| 297 | try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".fields[1].defaultValue().?)); | |
| 300 | try expect(unpacked_struct_info.@"struct".field_attrs[0].@"align" == null); | |
| 301 | const field_0_type = unpacked_struct_info.@"struct".field_types[0]; | |
| 302 | try expect(unpacked_struct_info.@"struct".field_attrs[0].defaultValue(field_0_type).? == 4); | |
| 303 | const field_1_type = unpacked_struct_info.@"struct".field_types[1]; | |
| 304 | try expect(mem.eql(u8, "foobar", unpacked_struct_info.@"struct".field_attrs[1].defaultValue(field_1_type).?)); | |
| 298 | 305 | } |
| 299 | 306 | |
| 300 | 307 | const TestStruct = struct { |
| ... | ... | @@ -313,13 +320,17 @@ fn testPackedStruct() !void { |
| 313 | 320 | try expect(struct_info.@"struct".is_tuple == false); |
| 314 | 321 | try expect(struct_info.@"struct".layout == .@"packed"); |
| 315 | 322 | try expect(struct_info.@"struct".backing_integer == u128); |
| 316 | try expect(struct_info.@"struct".fields.len == 4); | |
| 317 | try expect(struct_info.@"struct".fields[0].alignment == null); | |
| 318 | try expect(struct_info.@"struct".fields[2].type == f32); | |
| 319 | try expect(struct_info.@"struct".fields[2].defaultValue() == null); | |
| 320 | try expect(struct_info.@"struct".fields[3].defaultValue().? == 4); | |
| 321 | try expect(struct_info.@"struct".fields[3].alignment == null); | |
| 322 | try expect(struct_info.@"struct".decls.len == 1); | |
| 323 | try expect(struct_info.@"struct".field_names.len == 4); | |
| 324 | try expect(struct_info.@"struct".field_names.len == struct_info.@"struct".field_types.len); | |
| 325 | try expect(struct_info.@"struct".field_names.len == struct_info.@"struct".field_attrs.len); | |
| 326 | try expect(struct_info.@"struct".field_attrs[0].@"align" == null); | |
| 327 | try expect(struct_info.@"struct".field_types[2] == f32); | |
| 328 | const field_2_type = struct_info.@"struct".field_types[2]; | |
| 329 | try expect(struct_info.@"struct".field_attrs[2].defaultValue(field_2_type) == null); | |
| 330 | const field_3_type = struct_info.@"struct".field_types[3]; | |
| 331 | try expect(struct_info.@"struct".field_attrs[3].defaultValue(field_3_type).? == 4); | |
| 332 | try expect(struct_info.@"struct".field_attrs[3].@"align" == null); | |
| 333 | try expect(struct_info.@"struct".decl_names.len == 1); | |
| 323 | 334 | } |
| 324 | 335 | |
| 325 | 336 | const TestPackedStruct = packed struct { |
| ... | ... | @@ -346,7 +357,7 @@ fn testOpaque() !void { |
| 346 | 357 | }; |
| 347 | 358 | |
| 348 | 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 | } |
| 351 | 362 | |
| 352 | 363 | test "type info: function type info" { |
| ... | ... | @@ -371,18 +382,18 @@ fn testFunction() !void { |
| 371 | 382 | _ = S; |
| 372 | 383 | const foo_fn_type = @TypeOf(typeInfoFoo); |
| 373 | 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 | 386 | try expect(!foo_fn_info.@"fn".is_generic); |
| 376 | try expect(foo_fn_info.@"fn".params.len == 2); | |
| 377 | try expect(foo_fn_info.@"fn".is_var_args); | |
| 387 | try expect(foo_fn_info.@"fn".param_types.len == 2); | |
| 388 | try expect(foo_fn_info.@"fn".attrs.varargs); | |
| 378 | 389 | try expect(foo_fn_info.@"fn".return_type.? == usize); |
| 379 | 390 | const foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFoo)); |
| 380 | 391 | try expect(foo_ptr_fn_info.pointer.size == .one); |
| 381 | try expect(foo_ptr_fn_info.pointer.is_const); | |
| 382 | try expect(!foo_ptr_fn_info.pointer.is_volatile); | |
| 383 | try expect(foo_ptr_fn_info.pointer.address_space == .generic); | |
| 392 | try expect(foo_ptr_fn_info.pointer.attrs.@"const"); | |
| 393 | try expect(!foo_ptr_fn_info.pointer.attrs.@"volatile"); | |
| 394 | try expect(foo_ptr_fn_info.pointer.attrs.@"addrspace" == .generic); | |
| 384 | 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 | 397 | try expect(foo_ptr_fn_info.pointer.sentinel() == null); |
| 387 | 398 | |
| 388 | 399 | // Avoid looking at `typeInfoFooAligned` on targets which don't support function alignment. |
| ... | ... | @@ -397,19 +408,20 @@ fn testFunction() !void { |
| 397 | 408 | |
| 398 | 409 | const aligned_foo_fn_type = @TypeOf(typeInfoFooAligned); |
| 399 | 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 | 412 | try expect(!aligned_foo_fn_info.@"fn".is_generic); |
| 402 | try expect(aligned_foo_fn_info.@"fn".params.len == 2); | |
| 403 | try expect(aligned_foo_fn_info.@"fn".is_var_args); | |
| 413 | try expect(aligned_foo_fn_info.@"fn".param_types.len == 2); | |
| 414 | try expect(aligned_foo_fn_info.@"fn".param_types.len == aligned_foo_fn_info.@"fn".param_attrs.len); | |
| 415 | try expect(aligned_foo_fn_info.@"fn".attrs.varargs); | |
| 404 | 416 | try expect(aligned_foo_fn_info.@"fn".return_type.? == usize); |
| 405 | 417 | const aligned_foo_ptr_fn_info = @typeInfo(@TypeOf(&typeInfoFooAligned)); |
| 406 | 418 | try expect(aligned_foo_ptr_fn_info.pointer.size == .one); |
| 407 | try expect(aligned_foo_ptr_fn_info.pointer.is_const); | |
| 408 | try expect(!aligned_foo_ptr_fn_info.pointer.is_volatile); | |
| 409 | try expect(aligned_foo_ptr_fn_info.pointer.alignment == 4); | |
| 410 | try expect(aligned_foo_ptr_fn_info.pointer.address_space == .generic); | |
| 419 | try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"const"); | |
| 420 | try expect(!aligned_foo_ptr_fn_info.pointer.attrs.@"volatile"); | |
| 421 | try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"align" == 4); | |
| 422 | try expect(aligned_foo_ptr_fn_info.pointer.attrs.@"addrspace" == .generic); | |
| 411 | 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 | 425 | try expect(aligned_foo_ptr_fn_info.pointer.sentinel() == null); |
| 414 | 426 | } |
| 415 | 427 | |
| ... | ... | @@ -418,31 +430,29 @@ extern fn typeInfoFooAligned(a: usize, b: bool, ...) align(4) callconv(.c) usize |
| 418 | 430 | |
| 419 | 431 | test "type info: generic function types" { |
| 420 | 432 | const G1 = @typeInfo(@TypeOf(generic1)); |
| 421 | try expect(G1.@"fn".params.len == 1); | |
| 422 | try expect(G1.@"fn".params[0].is_generic == true); | |
| 423 | try expect(G1.@"fn".params[0].type == null); | |
| 433 | try expect(G1.@"fn".param_types.len == 1); | |
| 434 | try expect(G1.@"fn".param_types.len == G1.@"fn".param_attrs.len); | |
| 435 | try expect(G1.@"fn".param_types[0] == null); | |
| 424 | 436 | try expect(G1.@"fn".return_type == void); |
| 425 | 437 | |
| 426 | 438 | const G2 = @typeInfo(@TypeOf(generic2)); |
| 427 | try expect(G2.@"fn".params.len == 3); | |
| 428 | try expect(G2.@"fn".params[0].is_generic == false); | |
| 429 | try expect(G2.@"fn".params[0].type == type); | |
| 430 | try expect(G2.@"fn".params[1].is_generic == true); | |
| 431 | try expect(G2.@"fn".params[1].type == null); | |
| 432 | try expect(G2.@"fn".params[2].is_generic == false); | |
| 433 | try expect(G2.@"fn".params[2].type == u8); | |
| 439 | try expect(G2.@"fn".param_types.len == 3); | |
| 440 | try expect(G2.@"fn".param_types.len == G2.@"fn".param_attrs.len); | |
| 441 | try expect(G2.@"fn".param_types[0] == type); | |
| 442 | try expect(G2.@"fn".param_types[1] == null); | |
| 443 | try expect(G2.@"fn".param_types[2] == u8); | |
| 434 | 444 | try expect(G2.@"fn".return_type == void); |
| 435 | 445 | |
| 436 | 446 | const G3 = @typeInfo(@TypeOf(generic3)); |
| 437 | try expect(G3.@"fn".params.len == 1); | |
| 438 | try expect(G3.@"fn".params[0].is_generic == true); | |
| 439 | try expect(G3.@"fn".params[0].type == null); | |
| 447 | try expect(G3.@"fn".param_types.len == 1); | |
| 448 | try expect(G3.@"fn".param_types.len == G3.@"fn".param_attrs.len); | |
| 449 | try expect(G3.@"fn".param_types[0] == null); | |
| 440 | 450 | try expect(G3.@"fn".return_type == null); |
| 441 | 451 | |
| 442 | 452 | const G4 = @typeInfo(@TypeOf(generic4)); |
| 443 | try expect(G4.@"fn".params.len == 1); | |
| 444 | try expect(G4.@"fn".params[0].is_generic == true); | |
| 445 | try expect(G4.@"fn".params[0].type == null); | |
| 453 | try expect(G4.@"fn".param_types.len == 1); | |
| 454 | try expect(G4.@"fn".param_types.len == G4.@"fn".param_attrs.len); | |
| 455 | try expect(G4.@"fn".param_types[0] == null); | |
| 446 | 456 | try expect(G4.@"fn".return_type == null); |
| 447 | 457 | } |
| 448 | 458 | |
| ... | ... | @@ -530,7 +540,7 @@ test "@typeInfo does not force declarations into existence" { |
| 530 | 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 | } |
| 535 | 545 | |
| 536 | 546 | fn add(a: i32, b: i32) i32 { |
| ... | ... | @@ -548,12 +558,12 @@ test "Declarations are returned in declaration order" { |
| 548 | 558 | pub const d = 4; |
| 549 | 559 | pub const e = 5; |
| 550 | 560 | }; |
| 551 | const d = @typeInfo(S).@"struct".decls; | |
| 552 | try expect(std.mem.eql(u8, d[0].name, "a")); | |
| 553 | try expect(std.mem.eql(u8, d[1].name, "b")); | |
| 554 | try expect(std.mem.eql(u8, d[2].name, "c")); | |
| 555 | try expect(std.mem.eql(u8, d[3].name, "d")); | |
| 556 | try expect(std.mem.eql(u8, d[4].name, "e")); | |
| 561 | const d = @typeInfo(S).@"struct".decl_names; | |
| 562 | try expect(std.mem.eql(u8, d[0], "a")); | |
| 563 | try expect(std.mem.eql(u8, d[1], "b")); | |
| 564 | try expect(std.mem.eql(u8, d[2], "c")); | |
| 565 | try expect(std.mem.eql(u8, d[3], "d")); | |
| 566 | try expect(std.mem.eql(u8, d[4], "e")); | |
| 557 | 567 | } |
| 558 | 568 | |
| 559 | 569 | test "Struct.is_tuple for anon list literal" { |
| ... | ... | @@ -567,25 +577,27 @@ test "Struct.is_tuple for anon struct literal" { |
| 567 | 577 | |
| 568 | 578 | const info = @typeInfo(@TypeOf(.{ .a = 0 })); |
| 569 | 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 | } |
| 572 | 582 | |
| 573 | 583 | test "StructField.is_comptime" { |
| 574 | 584 | const info = @typeInfo(struct { x: u8 = 3, comptime y: u32 = 5 }).@"struct"; |
| 575 | try expect(!info.fields[0].is_comptime); | |
| 576 | try expect(info.fields[1].is_comptime); | |
| 585 | try expect(!info.field_attrs[0].@"comptime"); | |
| 586 | try expect(info.field_attrs[1].@"comptime"); | |
| 577 | 587 | } |
| 578 | 588 | |
| 579 | 589 | test "value from struct @typeInfo default_value_ptr can be loaded at comptime" { |
| 580 | 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 | 592 | try expect(@as(*const u8, @ptrCast(a)).* == 1); |
| 583 | 593 | } |
| 584 | 594 | } |
| 585 | 595 | |
| 586 | 596 | test "type info of tuple of string literal default value" { |
| 587 | const struct_field = @typeInfo(@TypeOf(.{"hi"})).@"struct".fields[0]; | |
| 588 | const value = struct_field.defaultValue().?; | |
| 597 | const struct_info = @typeInfo(@TypeOf(.{"hi"})).@"struct"; | |
| 598 | const struct_field_attrs = struct_info.field_attrs[0]; | |
| 599 | const struct_field_type = struct_info.field_types[0]; | |
| 600 | const value = struct_field_attrs.defaultValue(struct_field_type).?; | |
| 589 | 601 | comptime std.debug.assert(value[0] == 'h'); |
| 590 | 602 | } |
| 591 | 603 |
test/behavior/union.zig+3-3| ... | ... | @@ -445,7 +445,7 @@ test "global union with single field is correctly initialized" { |
| 445 | 445 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 446 | 446 | |
| 447 | 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 | 450 | try expect(glbl.f.x == 123); |
| 451 | 451 | } |
| ... | ... | @@ -563,8 +563,8 @@ test "tagged union type" { |
| 563 | 563 | const baz = Baz.B; |
| 564 | 564 | |
| 565 | 565 | try expect(baz == Baz.B); |
| 566 | try expect(@typeInfo(TaggedFoo).@"union".fields.len == 3); | |
| 567 | try expect(@typeInfo(Baz).@"enum".fields.len == 4); | |
| 566 | try expect(@typeInfo(TaggedFoo).@"union".field_names.len == 3); | |
| 567 | try expect(@typeInfo(Baz).@"enum".field_names.len == 4); | |
| 568 | 568 | try expect(@sizeOf(TaggedFoo) == @sizeOf(FooNoVoid)); |
| 569 | 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 | 130 | }; |
| 131 | 131 | }, |
| 132 | 132 | }, |
| 133 | .@"struct" => |@"struct"| inline for (@"struct".fields) |field| { | |
| 134 | try checkExpected(@field(expected, field.name), @field(actual, field.name), compare); | |
| 133 | .@"struct" => |@"struct"| inline for (@"struct".field_names) |field_name| { | |
| 134 | try checkExpected(@field(expected, field_name), @field(actual, field_name), compare); | |
| 135 | 135 | } else return, |
| 136 | 136 | }; |
| 137 | 137 | if (switch (@typeInfo(Expected)) { |
test/behavior/zon.zig+8-8| ... | ... | @@ -541,31 +541,31 @@ test "anon" { |
| 541 | 541 | try expectEqual(expected[1], actual[1]); |
| 542 | 542 | const expected_struct = expected[0]; |
| 543 | 543 | const actual_struct = actual[0]; |
| 544 | const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".fields; | |
| 545 | const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".fields; | |
| 544 | const expected_fields = @typeInfo(@TypeOf(expected_struct)).@"struct".field_names; | |
| 545 | const actual_fields = @typeInfo(@TypeOf(actual_struct)).@"struct".field_names; | |
| 546 | 546 | try expectEqual(expected_fields.len, actual_fields.len); |
| 547 | inline for (expected_fields) |field| { | |
| 548 | try expectEqual(@field(expected_struct, field.name), @field(actual_struct, field.name)); | |
| 547 | inline for (expected_fields) |field_name| { | |
| 548 | try expectEqual(@field(expected_struct, field_name), @field(actual_struct, field_name)); | |
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | test "build.zig.zon" { |
| 553 | 553 | const build = @import("zon/build.zig.zon"); |
| 554 | 554 | |
| 555 | try expectEqual(4, @typeInfo(@TypeOf(build)).@"struct".fields.len); | |
| 555 | try expectEqual(4, @typeInfo(@TypeOf(build)).@"struct".field_names.len); | |
| 556 | 556 | try expectEqualStrings("temp", build.name); |
| 557 | 557 | try expectEqualStrings("0.0.0", build.version); |
| 558 | 558 | |
| 559 | 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); | |
| 561 | 561 | |
| 562 | 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 | 564 | try expectEqualStrings("https://example.com/foo.tar.gz", example_0.url); |
| 565 | 565 | try expectEqualStrings("...", example_0.hash); |
| 566 | 566 | |
| 567 | 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 | 569 | try expectEqualStrings("../foo", example_1.path); |
| 570 | 570 | try expectEqual(false, example_1.lazy); |
| 571 | 571 |
test/cases/compile_errors/access_invalid_typeInfo_decl.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | pub const A = B; |
| 2 | 2 | export fn foo() void { |
| 3 | _ = @typeInfo(@This()).@"struct".decls[0]; | |
| 3 | _ = @typeInfo(@This()).@"struct".decl_names[0]; | |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | // 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 | 7 | |
| 8 | 8 | comptime var a = 1; |
| 9 | 9 | const info = @typeInfo(Widget).@"union"; |
| 10 | inline for (info.fields) |field| { | |
| 10 | inline for (info.field_types) |field_type| { | |
| 11 | 11 | if (foo()) { |
| 12 | switch (field.type) { | |
| 12 | switch (field_type) { | |
| 13 | 13 | u0 => a = 2, |
| 14 | 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 | 6 | }; |
| 7 | 7 | |
| 8 | 8 | pub fn main() void { |
| 9 | const section = inline for (@typeInfo(DwarfSection).@"enum".fields) |section| { | |
| 10 | if (std.mem.eql(u8, section.name, "eh_frame")) break section; | |
| 9 | const section = inline for (@typeInfo(DwarfSection).@"enum".field_names) |section_name| { | |
| 10 | if (std.mem.eql(u8, section_name, "eh_frame")) break section_name; | |
| 11 | 11 | }; |
| 12 | 12 | |
| 13 | 13 | _ = section; |
| ... | ... | @@ -16,4 +16,4 @@ pub fn main() void { |
| 16 | 16 | // error |
| 17 | 17 | // 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 | wrong_type: []u8 = "foo", |
| 8 | 8 | }; |
| 9 | 9 | |
| 10 | comptime ignore(@typeInfo(MyStruct).@"struct".fields[0]); | |
| 10 | comptime ignore(@typeInfo(MyStruct).@"struct".field_names[0]); | |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // error |
test/cases/compile_errors/runtime_index_into_comptime_type_slice.zig+2-3| ... | ... | @@ -6,12 +6,11 @@ fn getIndex() usize { |
| 6 | 6 | } |
| 7 | 7 | export fn entry() void { |
| 8 | 8 | const index = getIndex(); |
| 9 | const field = @typeInfo(Struct).@"struct".fields[index]; | |
| 9 | const field = @typeInfo(Struct).@"struct".field_types[index]; | |
| 10 | 10 | _ = field; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // error |
| 14 | 14 | // |
| 15 | // :9:54: error: values of type 'lang.Type.StructField' must be comptime-known, but index value is runtime-known | |
| 16 | // : note: struct requires comptime because of this field | |
| 15 | // :9:59: error: values of type 'type' must be comptime-known, but index value is runtime-known | |
| 17 | 16 | // : 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 | 9 | return 8; |
| 10 | 10 | } |
| 11 | 11 | fn 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 | } |
| 14 | 14 | |
| 15 | 15 | // run |
test/incremental/add_remove_struct_fields+4-4| ... | ... | @@ -11,7 +11,7 @@ pub fn main(init: std.process.Init) !void { |
| 11 | 11 | }; |
| 12 | 12 | } |
| 13 | 13 | fn 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 | } |
| 16 | 16 | fn printOneField(w: *Writer) Writer.Error!void { |
| 17 | 17 | const val: S = .{ .x = 100 }; |
| ... | ... | @@ -34,7 +34,7 @@ pub fn main(init: std.process.Init) !void { |
| 34 | 34 | }; |
| 35 | 35 | } |
| 36 | 36 | fn 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 | } |
| 39 | 39 | fn printOneField(w: *Writer) Writer.Error!void { |
| 40 | 40 | const val: S = .{ .x = 100 }; |
| ... | ... | @@ -57,7 +57,7 @@ pub fn main(init: std.process.Init) !void { |
| 57 | 57 | }; |
| 58 | 58 | } |
| 59 | 59 | fn 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 | } |
| 62 | 62 | fn printOneField(w: *Writer) Writer.Error!void { |
| 63 | 63 | const val: S = .{ .x = 100 }; |
| ... | ... | @@ -81,7 +81,7 @@ pub fn main(init: std.process.Init) !void { |
| 81 | 81 | }; |
| 82 | 82 | } |
| 83 | 83 | fn 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 | } |
| 86 | 86 | fn printOneField(w: *Writer) Writer.Error!void { |
| 87 | 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 | 12 | }; |
| 13 | 13 | } |
| 14 | 14 | fn 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 | } |
| 17 | 17 | fn printOneField(w: *Writer) Writer.Error!void { |
| 18 | 18 | const val: S = .{ .x = 100 }; |
| ... | ... | @@ -37,7 +37,7 @@ pub fn main(init: std.process.Init) !void { |
| 37 | 37 | }; |
| 38 | 38 | } |
| 39 | 39 | fn 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 | } |
| 42 | 42 | fn printOneField(w: *Writer) Writer.Error!void { |
| 43 | 43 | const val: S = .{ .x = 100 }; |
| ... | ... | @@ -60,7 +60,7 @@ pub fn main(init: std.process.Init) !void { |
| 60 | 60 | }; |
| 61 | 61 | } |
| 62 | 62 | fn 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 | } |
| 65 | 65 | fn printOneField(w: *Writer) Writer.Error!void { |
| 66 | 66 | const val: S = .{ .x = 100 }; |
| ... | ... | @@ -84,7 +84,7 @@ pub fn main(init: std.process.Init) !void { |
| 84 | 84 | }; |
| 85 | 85 | } |
| 86 | 86 | fn 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 | } |
| 89 | 89 | fn printOneField(w: *Writer) Writer.Error!void { |
| 90 | 90 | //const val: S = .{ .x = 100 }; |
test/incremental/change_union_tag_type+3-3| ... | ... | @@ -4,7 +4,7 @@ const A = enum(u8) { a }; |
| 4 | 4 | const B = enum(u8) { b }; |
| 5 | 5 | const Foo = union(A) { a: u8 }; |
| 6 | 6 | pub 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 | 8 | var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{}); |
| 9 | 9 | try stdout_writer.interface.print("{s}\n", .{field_name}); |
| 10 | 10 | } |
| ... | ... | @@ -17,7 +17,7 @@ const A = enum(u8) { a }; |
| 17 | 17 | const B = enum(u8) { b }; |
| 18 | 18 | const Foo = union(B) { a: u8 }; |
| 19 | 19 | pub 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 | 21 | var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{}); |
| 22 | 22 | try stdout_writer.interface.print("{s}\n", .{field_name}); |
| 23 | 23 | } |
| ... | ... | @@ -31,7 +31,7 @@ const A = enum(u8) { a }; |
| 31 | 31 | const B = enum(u8) { b }; |
| 32 | 32 | const Foo = union(B) { b: u8 }; |
| 33 | 33 | pub 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 | 35 | var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{}); |
| 36 | 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 | } |
| 8 | 8 | const S = struct { foo: u32, nested: struct { x: u16 } }; |
| 9 | 9 | const U = union(enum) { a, b, c: S }; |
| 10 | const E = enum(u8) { a = @typeInfo(U).@"union".fields.len, b = 0, c }; | |
| 10 | const E = enum(u8) { a = @typeInfo(U).@"union".field_names.len, b = 0, c }; | |
| 11 | 11 | const O = opaque { |
| 12 | 12 | comptime { |
| 13 | 13 | _ = @as(S, undefined); |
| ... | ... | @@ -27,7 +27,7 @@ pub fn main() void { |
| 27 | 27 | } |
| 28 | 28 | const S = struct { foo: u32, nested: struct { x: u16 } }; |
| 29 | 29 | const U = union(enum) { a, b, c: S }; |
| 30 | const E = enum(u8) { a = @typeInfo(U).@"union".fields.len, b = 0, c }; | |
| 30 | const E = enum(u8) { a = @typeInfo(U).@"union".field_names.len, b = 0, c }; | |
| 31 | 31 | const O = opaque { |
| 32 | 32 | comptime { |
| 33 | 33 | _ = @as(S, undefined); |
test/standalone/build.zig+1-2| ... | ... | @@ -85,8 +85,7 @@ pub fn build(b: *std.Build) void { |
| 85 | 85 | if (std.mem.eql(u8, dep_name, "simple")) continue; |
| 86 | 86 | |
| 87 | 87 | const all_pkgs = @import("root").dependencies.packages; |
| 88 | inline for (@typeInfo(all_pkgs).@"struct".decls) |decl| { | |
| 89 | const pkg_hash = decl.name; | |
| 88 | inline for (@typeInfo(all_pkgs).@"struct".decl_names) |pkg_hash| { | |
| 90 | 89 | if (std.mem.eql(u8, dep_hash, pkg_hash)) { |
| 91 | 90 | const pkg = @field(all_pkgs, pkg_hash); |
| 92 | 91 | if (!@hasDecl(pkg, "build_zig")) { |
tools/gen_stubs.zig+16-16| ... | ... | @@ -141,10 +141,10 @@ const Family = enum { |
| 141 | 141 | x86, |
| 142 | 142 | }; |
| 143 | 143 | |
| 144 | const arches: [@typeInfo(Arch).@"enum".fields.len]Arch = blk: { | |
| 145 | var result: [@typeInfo(Arch).@"enum".fields.len]Arch = undefined; | |
| 146 | for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 147 | const arch: Arch = @enumFromInt(field.value); | |
| 144 | const arches: [@typeInfo(Arch).@"enum".field_names.len]Arch = blk: { | |
| 145 | var result: [@typeInfo(Arch).@"enum".field_names.len]Arch = undefined; | |
| 146 | for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 147 | const arch: Arch = @enumFromInt(field_value); | |
| 148 | 148 | result[archIndex(arch)] = arch; |
| 149 | 149 | } |
| 150 | 150 | break :blk result; |
| ... | ... | @@ -160,8 +160,8 @@ const MultiSym = struct { |
| 160 | 160 | |
| 161 | 161 | fn isSingleArch(ms: MultiSym) ?Arch { |
| 162 | 162 | var result: ?Arch = null; |
| 163 | inline for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 164 | const arch: Arch = @enumFromInt(field.value); | |
| 163 | inline for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 164 | const arch: Arch = @enumFromInt(field_value); | |
| 165 | 165 | if (ms.present[archIndex(arch)]) { |
| 166 | 166 | if (result != null) return null; |
| 167 | 167 | result = arch; |
| ... | ... | @@ -172,8 +172,8 @@ const MultiSym = struct { |
| 172 | 172 | |
| 173 | 173 | fn isFamily(ms: MultiSym) ?Family { |
| 174 | 174 | var result: ?Family = null; |
| 175 | inline for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 176 | const arch: Arch = @enumFromInt(field.value); | |
| 175 | inline for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 176 | const arch: Arch = @enumFromInt(field_value); | |
| 177 | 177 | if (ms.present[archIndex(arch)]) { |
| 178 | 178 | const family = arch.family(); |
| 179 | 179 | if (result) |r| if (family != r) return null; |
| ... | ... | @@ -193,8 +193,8 @@ const MultiSym = struct { |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | fn isTime32Only(ms: MultiSym) bool { |
| 196 | inline for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 197 | const arch: Arch = @enumFromInt(field.value); | |
| 196 | inline for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 197 | const arch: Arch = @enumFromInt(field_value); | |
| 198 | 198 | if (ms.present[archIndex(arch)] != arch.isTime32()) { |
| 199 | 199 | return false; |
| 200 | 200 | } |
| ... | ... | @@ -233,8 +233,8 @@ const MultiSym = struct { |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | fn isPtrSize(ms: MultiSym, mult: u16) bool { |
| 236 | inline for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 237 | const arch: Arch = @enumFromInt(field.value); | |
| 236 | inline for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 237 | const arch: Arch = @enumFromInt(field_value); | |
| 238 | 238 | const arch_index = archIndex(arch); |
| 239 | 239 | if (ms.present[arch_index] and ms.size[arch_index] != arch.ptrSize() * mult) { |
| 240 | 240 | return false; |
| ... | ... | @@ -244,8 +244,8 @@ const MultiSym = struct { |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | fn isWeak64(ms: MultiSym) bool { |
| 247 | inline for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 248 | const arch: Arch = @enumFromInt(field.value); | |
| 247 | inline for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 248 | const arch: Arch = @enumFromInt(field_value); | |
| 249 | 249 | const arch_index = archIndex(arch); |
| 250 | 250 | const binding: u4 = switch (arch.ptrSize()) { |
| 251 | 251 | 4 => std.elf.STB_GLOBAL, |
| ... | ... | @@ -260,8 +260,8 @@ const MultiSym = struct { |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | fn isWeakTime64(ms: MultiSym) bool { |
| 263 | inline for (@typeInfo(Arch).@"enum".fields) |field| { | |
| 264 | const arch: Arch = @enumFromInt(field.value); | |
| 263 | inline for (@typeInfo(Arch).@"enum".field_values) |field_value| { | |
| 264 | const arch: Arch = @enumFromInt(field_value); | |
| 265 | 265 | const arch_index = archIndex(arch); |
| 266 | 266 | const binding: u4 = if (arch.isTime32()) std.elf.STB_GLOBAL else std.elf.STB_WEAK; |
| 267 | 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 | 43 | var buffer: [2000]u8 = undefined; |
| 44 | 44 | var stdout_writer = Io.File.stdout().writerStreaming(io, &buffer); |
| 45 | 45 | const w = &stdout_writer.interface; |
| 46 | inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| { | |
| 47 | const c_type: std.Target.CType = @enumFromInt(field.value); | |
| 46 | inline for (@typeInfo(std.Target.CType).@"enum".field_values) |field_value| { | |
| 47 | const c_type: std.Target.CType = @enumFromInt(field_value); | |
| 48 | 48 | try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{ |
| 49 | 49 | cName(c_type), |
| 50 | 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 | 660 | |
| 661 | 661 | var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(arena); |
| 662 | 662 | |
| 663 | inline for (@typeInfo(cpu_targets).@"struct".decls) |decl| { | |
| 664 | const Feature = @field(cpu_targets, decl.name).Feature; | |
| 665 | const all_features = @field(cpu_targets, decl.name).all_features; | |
| 663 | inline for (@typeInfo(cpu_targets).@"struct".decl_names) |decl_name| { | |
| 664 | const Feature = @field(cpu_targets, decl_name).Feature; | |
| 665 | const all_features = @field(cpu_targets, decl_name).all_features; | |
| 666 | 666 | |
| 667 | 667 | for (all_features, 0..) |feat, i| { |
| 668 | 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 | 2436 | try w.print(" @setEvalBranchQuota({d});\n", .{branch_quota}); |
| 2437 | 2437 | } |
| 2438 | 2438 | try w.writeAll( |
| 2439 | \\ const len = @typeInfo(Feature).@"enum".fields.len; | |
| 2439 | \\ const len = @typeInfo(Feature).@"enum".field_names.len; | |
| 2440 | 2440 | \\ std.debug.assert(len <= CpuFeature.Set.needed_bit_count); |
| 2441 | 2441 | \\ var result: [len]CpuFeature = undefined; |
| 2442 | 2442 | \\ |
| ... | ... | @@ -2505,7 +2505,7 @@ fn processOneTargetInner(io: Io, job: Job) !void { |
| 2505 | 2505 | \\ const ti = @typeInfo(Feature); |
| 2506 | 2506 | \\ for (&result, 0..) |*elem, i| { |
| 2507 | 2507 | \\ elem.index = i; |
| 2508 | \\ elem.name = ti.@"enum".fields[i].name; | |
| 2508 | \\ elem.name = ti.@"enum".field_names[i]; | |
| 2509 | 2509 | \\ } |
| 2510 | 2510 | \\ break :blk result; |
| 2511 | 2511 | \\}; |