authorgravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-02-13 19:06:47+01:00
committergravatar for carl@astholm.seCarl Åstholm <carl@astholm.se> 2024-04-07 14:47:11+02:00
log4c393c7468a4f6a62ba8251cdeeddc47b5b2b73d
treeb33be9336c6351c68ea13381b1283a078d1666a7
parentd8e7eda5f4a894fe8fec8c53f7bcc3d475dd55c9

Update usages of `fmtId`/`isValidId`

`{}` for decls `{p}` for enum fields `{p_}` for struct fields and in contexts following a `.` Elsewhere, `{p}` was used since it's equivalent to the old behavior.

11 files changed, 77 insertions(+), 78 deletions(-)

lib/compiler/aro_translate_c/ast.zig+3-3
...@@ -828,7 +828,7 @@ const Context = struct {...@@ -828,7 +828,7 @@ const Context = struct {
828 fn addIdentifier(c: *Context, bytes: []const u8) Allocator.Error!TokenIndex {828 fn addIdentifier(c: *Context, bytes: []const u8) Allocator.Error!TokenIndex {
829 if (std.zig.primitives.isPrimitive(bytes))829 if (std.zig.primitives.isPrimitive(bytes))
830 return c.addTokenFmt(.identifier, "@\"{s}\"", .{bytes});830 return c.addTokenFmt(.identifier, "@\"{s}\"", .{bytes});
831 return c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(bytes)});831 return c.addTokenFmt(.identifier, "{p}", .{std.zig.fmtId(bytes)});
832 }832 }
833833
834 fn listToSpan(c: *Context, list: []const NodeIndex) Allocator.Error!NodeSubRange {834 fn listToSpan(c: *Context, list: []const NodeIndex) Allocator.Error!NodeSubRange {
...@@ -2106,7 +2106,7 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex {...@@ -2106,7 +2106,7 @@ fn renderRecord(c: *Context, node: Node) !NodeIndex {
2106 members[1] = 0;2106 members[1] = 0;
21072107
2108 for (payload.fields, 0..) |field, i| {2108 for (payload.fields, 0..) |field, i| {
2109 const name_tok = try c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(field.name)});2109 const name_tok = try c.addTokenFmt(.identifier, "{p}", .{std.zig.fmtId(field.name)});
2110 _ = try c.addToken(.colon, ":");2110 _ = try c.addToken(.colon, ":");
2111 const type_expr = try renderNode(c, field.type);2111 const type_expr = try renderNode(c, field.type);
21122112
...@@ -2199,7 +2199,7 @@ fn renderFieldAccess(c: *Context, lhs: NodeIndex, field_name: []const u8) !NodeI...@@ -2199,7 +2199,7 @@ fn renderFieldAccess(c: *Context, lhs: NodeIndex, field_name: []const u8) !NodeI
2199 .main_token = try c.addToken(.period, "."),2199 .main_token = try c.addToken(.period, "."),
2200 .data = .{2200 .data = .{
2201 .lhs = lhs,2201 .lhs = lhs,
2202 .rhs = try c.addTokenFmt(.identifier, "{s}", .{std.zig.fmtId(field_name)}),2202 .rhs = try c.addTokenFmt(.identifier, "{p}", .{std.zig.fmtId(field_name)}),
2203 },2203 },
2204 });2204 });
2205}2205}
lib/std/Build/Step/Options.zig+6-6
...@@ -234,7 +234,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u...@@ -234,7 +234,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u
234 try printEnum(self, out, T, info, indent);234 try printEnum(self, out, T, info, indent);
235235
236 if (name) |some| {236 if (name) |some| {
237 try out.print("pub const {}: {s} = .{s};\n", .{237 try out.print("pub const {}: {} = .{p_};\n", .{
238 std.zig.fmtId(some),238 std.zig.fmtId(some),
239 std.zig.fmtId(@typeName(T)),239 std.zig.fmtId(@typeName(T)),
240 std.zig.fmtId(@tagName(value)),240 std.zig.fmtId(@tagName(value)),
...@@ -246,7 +246,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u...@@ -246,7 +246,7 @@ fn printType(self: *Options, out: anytype, comptime T: type, value: T, indent: u
246 try printStruct(self, out, T, info, indent);246 try printStruct(self, out, T, info, indent);
247247
248 if (name) |some| {248 if (name) |some| {
249 try out.print("pub const {}: {s} = ", .{249 try out.print("pub const {}: {} = ", .{
250 std.zig.fmtId(some),250 std.zig.fmtId(some),
251 std.zig.fmtId(@typeName(T)),251 std.zig.fmtId(@typeName(T)),
252 });252 });
...@@ -279,7 +279,7 @@ fn printEnum(self: *Options, out: anytype, comptime T: type, comptime val: std.b...@@ -279,7 +279,7 @@ fn printEnum(self: *Options, out: anytype, comptime T: type, comptime val: std.b
279279
280 inline for (val.fields) |field| {280 inline for (val.fields) |field| {
281 try out.writeByteNTimes(' ', indent);281 try out.writeByteNTimes(' ', indent);
282 try out.print(" {} = {d},\n", .{ std.zig.fmtId(field.name), field.value });282 try out.print(" {p} = {d},\n", .{ std.zig.fmtId(field.name), field.value });
283 }283 }
284284
285 if (!val.is_exhaustive) {285 if (!val.is_exhaustive) {
...@@ -313,9 +313,9 @@ fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std...@@ -313,9 +313,9 @@ fn printStruct(self: *Options, out: anytype, comptime T: type, comptime val: std
313313
314 // If the type name doesn't contains a '.' the type is from zig builtins.314 // If the type name doesn't contains a '.' the type is from zig builtins.
315 if (std.mem.containsAtLeast(u8, type_name, 1, ".")) {315 if (std.mem.containsAtLeast(u8, type_name, 1, ".")) {
316 try out.print(" {}: {}", .{ std.zig.fmtId(field.name), std.zig.fmtId(type_name) });316 try out.print(" {p_}: {}", .{ std.zig.fmtId(field.name), std.zig.fmtId(type_name) });
317 } else {317 } else {
318 try out.print(" {}: {s}", .{ std.zig.fmtId(field.name), type_name });318 try out.print(" {p_}: {s}", .{ std.zig.fmtId(field.name), type_name });
319 }319 }
320320
321 if (field.default_value != null) {321 if (field.default_value != null) {
...@@ -355,7 +355,7 @@ fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.built...@@ -355,7 +355,7 @@ fn printStructValue(self: *Options, out: anytype, comptime struct_val: std.built
355 } else {355 } else {
356 inline for (struct_val.fields) |field| {356 inline for (struct_val.fields) |field| {
357 try out.writeByteNTimes(' ', indent);357 try out.writeByteNTimes(' ', indent);
358 try out.print(" .{} = ", .{std.zig.fmtId(field.name)});358 try out.print(" .{p_} = ", .{std.zig.fmtId(field.name)});
359359
360 const field_name = @field(val, field.name);360 const field_name = @field(val, field.name);
361 switch (@typeInfo(@TypeOf(field_name))) {361 switch (@typeInfo(@TypeOf(field_name))) {
lib/std/zig/render.zig+2-2
...@@ -2847,8 +2847,8 @@ fn renderIdentifier(r: *Render, token_index: Ast.TokenIndex, space: Space, quote...@@ -2847,8 +2847,8 @@ fn renderIdentifier(r: *Render, token_index: Ast.TokenIndex, space: Space, quote
2847 return renderQuotedIdentifier(r, token_index, space, false);2847 return renderQuotedIdentifier(r, token_index, space, false);
2848 }2848 }
28492849
2850 // Special case for _ which would incorrectly be rejected by isValidId below.2850 // Special case for _.
2851 if (contents.len == 1 and contents[0] == '_') switch (quote) {2851 if (std.zig.isUnderscore(contents)) switch (quote) {
2852 .eagerly_unquote => return renderQuotedIdentifier(r, token_index, space, true),2852 .eagerly_unquote => return renderQuotedIdentifier(r, token_index, space, true),
2853 .eagerly_unquote_except_underscore,2853 .eagerly_unquote_except_underscore,
2854 .preserve_when_shadowing,2854 .preserve_when_shadowing,
src/Builtin.zig+14-15
...@@ -35,17 +35,17 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {...@@ -35,17 +35,17 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {
35 \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.35 \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
36 \\pub const zig_version = std.SemanticVersion.parse(zig_version_string) catch unreachable;36 \\pub const zig_version = std.SemanticVersion.parse(zig_version_string) catch unreachable;
37 \\pub const zig_version_string = "{s}";37 \\pub const zig_version_string = "{s}";
38 \\pub const zig_backend = std.builtin.CompilerBackend.{};38 \\pub const zig_backend = std.builtin.CompilerBackend.{p_};
39 \\39 \\
40 \\pub const output_mode = std.builtin.OutputMode.{};40 \\pub const output_mode = std.builtin.OutputMode.{p_};
41 \\pub const link_mode = std.builtin.LinkMode.{};41 \\pub const link_mode = std.builtin.LinkMode.{p_};
42 \\pub const is_test = {};42 \\pub const is_test = {};
43 \\pub const single_threaded = {};43 \\pub const single_threaded = {};
44 \\pub const abi = std.Target.Abi.{};44 \\pub const abi = std.Target.Abi.{p_};
45 \\pub const cpu: std.Target.Cpu = .{{45 \\pub const cpu: std.Target.Cpu = .{{
46 \\ .arch = .{},46 \\ .arch = .{p_},
47 \\ .model = &std.Target.{}.cpu.{},47 \\ .model = &std.Target.{p_}.cpu.{p_},
48 \\ .features = std.Target.{}.featureSet(&[_]std.Target.{}.Feature{{48 \\ .features = std.Target.{p_}.featureSet(&[_]std.Target.{p_}.Feature{{
49 \\49 \\
50 , .{50 , .{
51 build_options.version,51 build_options.version,
...@@ -66,14 +66,14 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {...@@ -66,14 +66,14 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {
66 const index = @as(std.Target.Cpu.Feature.Set.Index, @intCast(index_usize));66 const index = @as(std.Target.Cpu.Feature.Set.Index, @intCast(index_usize));
67 const is_enabled = target.cpu.features.isEnabled(index);67 const is_enabled = target.cpu.features.isEnabled(index);
68 if (is_enabled) {68 if (is_enabled) {
69 try buffer.writer().print(" .{},\n", .{std.zig.fmtId(feature.name)});69 try buffer.writer().print(" .{p_},\n", .{std.zig.fmtId(feature.name)});
70 }70 }
71 }71 }
72 try buffer.writer().print(72 try buffer.writer().print(
73 \\ }}),73 \\ }}),
74 \\}};74 \\}};
75 \\pub const os = std.Target.Os{{75 \\pub const os = std.Target.Os{{
76 \\ .tag = .{},76 \\ .tag = .{p_},
77 \\ .version_range = .{{77 \\ .version_range = .{{
78 ,78 ,
79 .{std.zig.fmtId(@tagName(target.os.tag))},79 .{std.zig.fmtId(@tagName(target.os.tag))},
...@@ -180,8 +180,8 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {...@@ -180,8 +180,8 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {
180 const link_libc = opts.link_libc;180 const link_libc = opts.link_libc;
181181
182 try buffer.writer().print(182 try buffer.writer().print(
183 \\pub const object_format = std.Target.ObjectFormat.{};183 \\pub const object_format = std.Target.ObjectFormat.{p_};
184 \\pub const mode = std.builtin.OptimizeMode.{};184 \\pub const mode = std.builtin.OptimizeMode.{p_};
185 \\pub const link_libc = {};185 \\pub const link_libc = {};
186 \\pub const link_libcpp = {};186 \\pub const link_libcpp = {};
187 \\pub const have_error_return_tracing = {};187 \\pub const have_error_return_tracing = {};
...@@ -190,7 +190,7 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {...@@ -190,7 +190,7 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {
190 \\pub const position_independent_code = {};190 \\pub const position_independent_code = {};
191 \\pub const position_independent_executable = {};191 \\pub const position_independent_executable = {};
192 \\pub const strip_debug_info = {};192 \\pub const strip_debug_info = {};
193 \\pub const code_model = std.builtin.CodeModel.{};193 \\pub const code_model = std.builtin.CodeModel.{p_};
194 \\pub const omit_frame_pointer = {};194 \\pub const omit_frame_pointer = {};
195 \\195 \\
196 , .{196 , .{
...@@ -209,11 +209,10 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {...@@ -209,11 +209,10 @@ pub fn append(opts: @This(), buffer: *std.ArrayList(u8)) Allocator.Error!void {
209 });209 });
210210
211 if (target.os.tag == .wasi) {211 if (target.os.tag == .wasi) {
212 const wasi_exec_model_fmt = std.zig.fmtId(@tagName(opts.wasi_exec_model));
213 try buffer.writer().print(212 try buffer.writer().print(
214 \\pub const wasi_exec_model = std.builtin.WasiExecModel.{};213 \\pub const wasi_exec_model = std.builtin.WasiExecModel.{p_};
215 \\214 \\
216 , .{wasi_exec_model_fmt});215 , .{std.zig.fmtId(@tagName(opts.wasi_exec_model))});
217 }216 }
218217
219 if (opts.is_test) {218 if (opts.is_test) {
src/InternPool.zig+1-1
...@@ -488,7 +488,7 @@ pub const NullTerminatedString = enum(u32) {...@@ -488,7 +488,7 @@ pub const NullTerminatedString = enum(u32) {
488 if (comptime std.mem.eql(u8, specifier, "")) {488 if (comptime std.mem.eql(u8, specifier, "")) {
489 try writer.writeAll(s);489 try writer.writeAll(s);
490 } else if (comptime std.mem.eql(u8, specifier, "i")) {490 } else if (comptime std.mem.eql(u8, specifier, "i")) {
491 try writer.print("{}", .{std.zig.fmtId(s)});491 try writer.print("{p}", .{std.zig.fmtId(s)});
492 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");492 } else @compileError("invalid format string '" ++ specifier ++ "' for '" ++ @typeName(NullTerminatedString) ++ "'");
493 }493 }
494494
src/main.zig+1-1
...@@ -6943,7 +6943,7 @@ fn cmdFetch(...@@ -6943,7 +6943,7 @@ fn cmdFetch(
6943 std.zig.fmtEscapes(&hex_digest),6943 std.zig.fmtEscapes(&hex_digest),
6944 });6944 });
69456945
6946 const new_node_text = try std.fmt.allocPrint(arena, ".{} = {s},\n", .{6946 const new_node_text = try std.fmt.allocPrint(arena, ".{p_} = {s},\n", .{
6947 std.zig.fmtId(name), new_node_init,6947 std.zig.fmtId(name), new_node_init,
6948 });6948 });
69496949
src/print_zir.zig+8-8
...@@ -1005,7 +1005,7 @@ const Writer = struct {...@@ -1005,7 +1005,7 @@ const Writer = struct {
1005 const decl_name = self.code.nullTerminatedString(extra.decl_name);1005 const decl_name = self.code.nullTerminatedString(extra.decl_name);
10061006
1007 try self.writeInstRef(stream, extra.namespace);1007 try self.writeInstRef(stream, extra.namespace);
1008 try stream.print(", {}, ", .{std.zig.fmtId(decl_name)});1008 try stream.print(", {p}, ", .{std.zig.fmtId(decl_name)});
1009 try self.writeInstRef(stream, extra.options);1009 try self.writeInstRef(stream, extra.options);
1010 try stream.writeAll(") ");1010 try stream.writeAll(") ");
1011 try self.writeSrc(stream, inst_data.src());1011 try self.writeSrc(stream, inst_data.src());
...@@ -1243,7 +1243,7 @@ const Writer = struct {...@@ -1243,7 +1243,7 @@ const Writer = struct {
12431243
1244 const name = self.code.nullTerminatedString(output.data.name);1244 const name = self.code.nullTerminatedString(output.data.name);
1245 const constraint = self.code.nullTerminatedString(output.data.constraint);1245 const constraint = self.code.nullTerminatedString(output.data.constraint);
1246 try stream.print("output({}, \"{}\", ", .{1246 try stream.print("output({p}, \"{}\", ", .{
1247 std.zig.fmtId(name), std.zig.fmtEscapes(constraint),1247 std.zig.fmtId(name), std.zig.fmtEscapes(constraint),
1248 });1248 });
1249 try self.writeFlag(stream, "->", is_type);1249 try self.writeFlag(stream, "->", is_type);
...@@ -1262,7 +1262,7 @@ const Writer = struct {...@@ -1262,7 +1262,7 @@ const Writer = struct {
12621262
1263 const name = self.code.nullTerminatedString(input.data.name);1263 const name = self.code.nullTerminatedString(input.data.name);
1264 const constraint = self.code.nullTerminatedString(input.data.constraint);1264 const constraint = self.code.nullTerminatedString(input.data.constraint);
1265 try stream.print("input({}, \"{}\", ", .{1265 try stream.print("input({p}, \"{}\", ", .{
1266 std.zig.fmtId(name), std.zig.fmtEscapes(constraint),1266 std.zig.fmtId(name), std.zig.fmtEscapes(constraint),
1267 });1267 });
1268 try self.writeInstRef(stream, input.data.operand);1268 try self.writeInstRef(stream, input.data.operand);
...@@ -1278,7 +1278,7 @@ const Writer = struct {...@@ -1278,7 +1278,7 @@ const Writer = struct {
1278 const str_index = self.code.extra[extra_i];1278 const str_index = self.code.extra[extra_i];
1279 extra_i += 1;1279 extra_i += 1;
1280 const clobber = self.code.nullTerminatedString(@enumFromInt(str_index));1280 const clobber = self.code.nullTerminatedString(@enumFromInt(str_index));
1281 try stream.print("{}", .{std.zig.fmtId(clobber)});1281 try stream.print("{p}", .{std.zig.fmtId(clobber)});
1282 if (i + 1 < clobbers_len) {1282 if (i + 1 < clobbers_len) {
1283 try stream.writeAll(", ");1283 try stream.writeAll(", ");
1284 }1284 }
...@@ -1559,7 +1559,7 @@ const Writer = struct {...@@ -1559,7 +1559,7 @@ const Writer = struct {
1559 try self.writeFlag(stream, "comptime ", field.is_comptime);1559 try self.writeFlag(stream, "comptime ", field.is_comptime);
1560 if (field.name != .empty) {1560 if (field.name != .empty) {
1561 const field_name = self.code.nullTerminatedString(field.name);1561 const field_name = self.code.nullTerminatedString(field.name);
1562 try stream.print("{}: ", .{std.zig.fmtId(field_name)});1562 try stream.print("{p}: ", .{std.zig.fmtId(field_name)});
1563 } else {1563 } else {
1564 try stream.print("@\"{d}\": ", .{i});1564 try stream.print("@\"{d}\": ", .{i});
1565 }1565 }
...@@ -1738,7 +1738,7 @@ const Writer = struct {...@@ -1738,7 +1738,7 @@ const Writer = struct {
17381738
1739 try self.writeDocComment(stream, doc_comment_index);1739 try self.writeDocComment(stream, doc_comment_index);
1740 try stream.writeByteNTimes(' ', self.indent);1740 try stream.writeByteNTimes(' ', self.indent);
1741 try stream.print("{}", .{std.zig.fmtId(field_name)});1741 try stream.print("{p}", .{std.zig.fmtId(field_name)});
17421742
1743 if (has_type) {1743 if (has_type) {
1744 const field_type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));1744 const field_type = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
...@@ -1891,7 +1891,7 @@ const Writer = struct {...@@ -1891,7 +1891,7 @@ const Writer = struct {
1891 try self.writeDocComment(stream, doc_comment_index);1891 try self.writeDocComment(stream, doc_comment_index);
18921892
1893 try stream.writeByteNTimes(' ', self.indent);1893 try stream.writeByteNTimes(' ', self.indent);
1894 try stream.print("{}", .{std.zig.fmtId(field_name)});1894 try stream.print("{p}", .{std.zig.fmtId(field_name)});
18951895
1896 if (has_tag_value) {1896 if (has_tag_value) {
1897 const tag_value_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));1897 const tag_value_ref = @as(Zir.Inst.Ref, @enumFromInt(self.code.extra[extra_index]));
...@@ -1986,7 +1986,7 @@ const Writer = struct {...@@ -1986,7 +1986,7 @@ const Writer = struct {
1986 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index + 1]);1986 const doc_comment_index: Zir.NullTerminatedString = @enumFromInt(self.code.extra[extra_index + 1]);
1987 try self.writeDocComment(stream, doc_comment_index);1987 try self.writeDocComment(stream, doc_comment_index);
1988 try stream.writeByteNTimes(' ', self.indent);1988 try stream.writeByteNTimes(' ', self.indent);
1989 try stream.print("{},\n", .{std.zig.fmtId(name)});1989 try stream.print("{p},\n", .{std.zig.fmtId(name)});
1990 }1990 }
19911991
1992 self.indent -= 2;1992 self.indent -= 2;
tools/gen_spirv_spec.zig+20-20
...@@ -311,7 +311,7 @@ fn renderInstructionSet(...@@ -311,7 +311,7 @@ fn renderInstructionSet(
311 );311 );
312312
313 for (extensions) |ext| {313 for (extensions) |ext| {
314 try writer.print("{},\n", .{std.zig.fmtId(ext.name)});314 try writer.print("{p},\n", .{std.zig.fmtId(ext.name)});
315 }315 }
316316
317 try writer.writeAll(317 try writer.writeAll(
...@@ -344,7 +344,7 @@ fn renderInstructionsCase(...@@ -344,7 +344,7 @@ fn renderInstructionsCase(
344 // but there aren't so many total aliases and that would add more overhead in total. We will344 // but there aren't so many total aliases and that would add more overhead in total. We will
345 // just filter those out when needed.345 // just filter those out when needed.
346346
347 try writer.print(".{} => &[_]Instruction{{\n", .{std.zig.fmtId(set_name)});347 try writer.print(".{p_} => &[_]Instruction{{\n", .{std.zig.fmtId(set_name)});
348348
349 for (instructions) |inst| {349 for (instructions) |inst| {
350 try writer.print(350 try writer.print(
...@@ -366,7 +366,7 @@ fn renderInstructionsCase(...@@ -366,7 +366,7 @@ fn renderInstructionsCase(
366366
367 const kind = all_operand_kinds.get(.{ set_name, operand.kind }) orelse367 const kind = all_operand_kinds.get(.{ set_name, operand.kind }) orelse
368 all_operand_kinds.get(.{ "core", operand.kind }).?;368 all_operand_kinds.get(.{ "core", operand.kind }).?;
369 try writer.print(".{{.kind = .{}, .quantifier = .{s}}},\n", .{ std.zig.fmtId(kind.kind), quantifier });369 try writer.print(".{{.kind = .{p_}, .quantifier = .{s}}},\n", .{ std.zig.fmtId(kind.kind), quantifier });
370 }370 }
371371
372 try writer.writeAll(372 try writer.writeAll(
...@@ -423,7 +423,7 @@ fn renderOperandKind(writer: anytype, operands: []const OperandKind) !void {...@@ -423,7 +423,7 @@ fn renderOperandKind(writer: anytype, operands: []const OperandKind) !void {
423 \\423 \\
424 );424 );
425 for (operands) |operand| {425 for (operands) |operand| {
426 try writer.print("{},\n", .{std.zig.fmtId(operand.kind)});426 try writer.print("{p},\n", .{std.zig.fmtId(operand.kind)});
427 }427 }
428 try writer.writeAll(428 try writer.writeAll(
429 \\429 \\
...@@ -440,7 +440,7 @@ fn renderOperandKind(writer: anytype, operands: []const OperandKind) !void {...@@ -440,7 +440,7 @@ fn renderOperandKind(writer: anytype, operands: []const OperandKind) !void {
440 .Literal => "literal",440 .Literal => "literal",
441 .Composite => "composite",441 .Composite => "composite",
442 };442 };
443 try writer.print(".{} => .{s},\n", .{ std.zig.fmtId(operand.kind), cat });443 try writer.print(".{p_} => .{s},\n", .{ std.zig.fmtId(operand.kind), cat });
444 }444 }
445 try writer.writeAll(445 try writer.writeAll(
446 \\ };446 \\ };
...@@ -454,12 +454,12 @@ fn renderOperandKind(writer: anytype, operands: []const OperandKind) !void {...@@ -454,12 +454,12 @@ fn renderOperandKind(writer: anytype, operands: []const OperandKind) !void {
454 switch (operand.category) {454 switch (operand.category) {
455 .BitEnum, .ValueEnum => {},455 .BitEnum, .ValueEnum => {},
456 else => {456 else => {
457 try writer.print(".{} => unreachable,\n", .{std.zig.fmtId(operand.kind)});457 try writer.print(".{p_} => unreachable,\n", .{std.zig.fmtId(operand.kind)});
458 continue;458 continue;
459 },459 },
460 }460 }
461461
462 try writer.print(".{} => &[_]Enumerant{{", .{std.zig.fmtId(operand.kind)});462 try writer.print(".{p_} => &[_]Enumerant{{", .{std.zig.fmtId(operand.kind)});
463 for (operand.enumerants.?) |enumerant| {463 for (operand.enumerants.?) |enumerant| {
464 if (enumerant.value == .bitflag and std.mem.eql(u8, enumerant.enumerant, "None")) {464 if (enumerant.value == .bitflag and std.mem.eql(u8, enumerant.enumerant, "None")) {
465 continue;465 continue;
...@@ -483,7 +483,7 @@ fn renderEnumerant(writer: anytype, enumerant: Enumerant) !void {...@@ -483,7 +483,7 @@ fn renderEnumerant(writer: anytype, enumerant: Enumerant) !void {
483 if (i != 0)483 if (i != 0)
484 try writer.writeAll(", ");484 try writer.writeAll(", ");
485 // Note, param.quantifier will always be one.485 // Note, param.quantifier will always be one.
486 try writer.print(".{}", .{std.zig.fmtId(param.kind)});486 try writer.print(".{p_}", .{std.zig.fmtId(param.kind)});
487 }487 }
488 try writer.writeAll("}}");488 try writer.writeAll("}}");
489}489}
...@@ -529,7 +529,7 @@ fn renderOpcodes(...@@ -529,7 +529,7 @@ fn renderOpcodes(
529 try writer.writeAll("pub const Opcode = enum(u16) {\n");529 try writer.writeAll("pub const Opcode = enum(u16) {\n");
530 for (instructions_indices) |i| {530 for (instructions_indices) |i| {
531 const inst = instructions[i];531 const inst = instructions[i];
532 try writer.print("{} = {},\n", .{ std.zig.fmtId(inst.opname), inst.opcode });532 try writer.print("{p} = {},\n", .{ std.zig.fmtId(inst.opname), inst.opcode });
533 }533 }
534534
535 try writer.writeAll(535 try writer.writeAll(
...@@ -537,7 +537,7 @@ fn renderOpcodes(...@@ -537,7 +537,7 @@ fn renderOpcodes(
537 );537 );
538538
539 for (aliases.items) |alias| {539 for (aliases.items) |alias| {
540 try writer.print("pub const {} = Opcode.{};\n", .{540 try writer.print("pub const {} = Opcode.{p_};\n", .{
541 std.zig.fmtId(instructions[alias.inst].opname),541 std.zig.fmtId(instructions[alias.inst].opname),
542 std.zig.fmtId(instructions[alias.alias].opname),542 std.zig.fmtId(instructions[alias.alias].opname),
543 });543 });
...@@ -565,7 +565,7 @@ fn renderOpcodes(...@@ -565,7 +565,7 @@ fn renderOpcodes(
565565
566 for (instructions_indices) |i| {566 for (instructions_indices) |i| {
567 const inst = instructions[i];567 const inst = instructions[i];
568 try writer.print(".{} => .", .{std.zig.fmtId(inst.opname)});568 try writer.print(".{p_} => .", .{std.zig.fmtId(inst.opname)});
569 try renderInstructionClass(writer, inst.class.?);569 try renderInstructionClass(writer, inst.class.?);
570 try writer.writeAll(",\n");570 try writer.writeAll(",\n");
571 }571 }
...@@ -636,22 +636,22 @@ fn renderValueEnum(...@@ -636,22 +636,22 @@ fn renderValueEnum(
636636
637 const enum_indices = enum_map.values();637 const enum_indices = enum_map.values();
638638
639 try writer.print("pub const {s} = enum(u32) {{\n", .{std.zig.fmtId(enumeration.kind)});639 try writer.print("pub const {} = enum(u32) {{\n", .{std.zig.fmtId(enumeration.kind)});
640640
641 for (enum_indices) |i| {641 for (enum_indices) |i| {
642 const enumerant = enumerants[i];642 const enumerant = enumerants[i];
643 // if (enumerant.value != .int) return error.InvalidRegistry;643 // if (enumerant.value != .int) return error.InvalidRegistry;
644644
645 switch (enumerant.value) {645 switch (enumerant.value) {
646 .int => |value| try writer.print("{} = {},\n", .{ std.zig.fmtId(enumerant.enumerant), value }),646 .int => |value| try writer.print("{p} = {},\n", .{ std.zig.fmtId(enumerant.enumerant), value }),
647 .bitflag => |value| try writer.print("{} = {s},\n", .{ std.zig.fmtId(enumerant.enumerant), value }),647 .bitflag => |value| try writer.print("{p} = {s},\n", .{ std.zig.fmtId(enumerant.enumerant), value }),
648 }648 }
649 }649 }
650650
651 try writer.writeByte('\n');651 try writer.writeByte('\n');
652652
653 for (aliases.items) |alias| {653 for (aliases.items) |alias| {
654 try writer.print("pub const {} = {}.{};\n", .{654 try writer.print("pub const {} = {}.{p_};\n", .{
655 std.zig.fmtId(enumerants[alias.enumerant].enumerant),655 std.zig.fmtId(enumerants[alias.enumerant].enumerant),
656 std.zig.fmtId(enumeration.kind),656 std.zig.fmtId(enumeration.kind),
657 std.zig.fmtId(enumerants[alias.alias].enumerant),657 std.zig.fmtId(enumerants[alias.alias].enumerant),
...@@ -679,7 +679,7 @@ fn renderBitEnum(...@@ -679,7 +679,7 @@ fn renderBitEnum(
679 enumeration: OperandKind,679 enumeration: OperandKind,
680 extended_structs: ExtendedStructSet,680 extended_structs: ExtendedStructSet,
681) !void {681) !void {
682 try writer.print("pub const {s} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)});682 try writer.print("pub const {} = packed struct {{\n", .{std.zig.fmtId(enumeration.kind)});
683683
684 var flags_by_bitpos = [_]?usize{null} ** 32;684 var flags_by_bitpos = [_]?usize{null} ** 32;
685 const enumerants = enumeration.enumerants orelse return error.InvalidRegistry;685 const enumerants = enumeration.enumerants orelse return error.InvalidRegistry;
...@@ -719,7 +719,7 @@ fn renderBitEnum(...@@ -719,7 +719,7 @@ fn renderBitEnum(
719719
720 for (flags_by_bitpos, 0..) |maybe_flag_index, bitpos| {720 for (flags_by_bitpos, 0..) |maybe_flag_index, bitpos| {
721 if (maybe_flag_index) |flag_index| {721 if (maybe_flag_index) |flag_index| {
722 try writer.print("{}", .{std.zig.fmtId(enumerants[flag_index].enumerant)});722 try writer.print("{p_}", .{std.zig.fmtId(enumerants[flag_index].enumerant)});
723 } else {723 } else {
724 try writer.print("_reserved_bit_{}", .{bitpos});724 try writer.print("_reserved_bit_{}", .{bitpos});
725 }725 }
...@@ -730,7 +730,7 @@ fn renderBitEnum(...@@ -730,7 +730,7 @@ fn renderBitEnum(
730 try writer.writeByte('\n');730 try writer.writeByte('\n');
731731
732 for (aliases.items) |alias| {732 for (aliases.items) |alias| {
733 try writer.print("pub const {}: {} = .{{.{} = true}};\n", .{733 try writer.print("pub const {}: {} = .{{.{p_} = true}};\n", .{
734 std.zig.fmtId(enumerants[alias.flag].enumerant),734 std.zig.fmtId(enumerants[alias.flag].enumerant),
735 std.zig.fmtId(enumeration.kind),735 std.zig.fmtId(enumeration.kind),
736 std.zig.fmtId(enumerants[flags_by_bitpos[alias.alias].?].enumerant),736 std.zig.fmtId(enumerants[flags_by_bitpos[alias.alias].?].enumerant),
...@@ -858,7 +858,7 @@ fn renderFieldName(writer: anytype, operands: []const Operand, field_index: usiz...@@ -858,7 +858,7 @@ fn renderFieldName(writer: anytype, operands: []const Operand, field_index: usiz
858 }858 }
859859
860 // Assume there are no duplicate 'name' fields.860 // Assume there are no duplicate 'name' fields.
861 try writer.print("{}", .{std.zig.fmtId(name_buffer.items)});861 try writer.print("{p_}", .{std.zig.fmtId(name_buffer.items)});
862 return;862 return;
863 }863 }
864864
...@@ -876,7 +876,7 @@ fn renderFieldName(writer: anytype, operands: []const Operand, field_index: usiz...@@ -876,7 +876,7 @@ fn renderFieldName(writer: anytype, operands: []const Operand, field_index: usiz
876 }876 }
877 }877 }
878878
879 try writer.print("{}", .{std.zig.fmtId(name_buffer.items)});879 try writer.print("{p_}", .{std.zig.fmtId(name_buffer.items)});
880880
881 // For fields derived from type name, there could be any amount.881 // For fields derived from type name, there could be any amount.
882 // Simply check against all other fields, and if another similar one exists, add a number.882 // Simply check against all other fields, and if another similar one exists, add a number.
tools/generate_linux_syscalls.zig+12-12
...@@ -61,7 +61,7 @@ pub fn main() !void {...@@ -61,7 +61,7 @@ pub fn main() !void {
61 _ = fields.next() orelse return error.Incomplete;61 _ = fields.next() orelse return error.Incomplete;
62 const name = fields.next() orelse return error.Incomplete;62 const name = fields.next() orelse return error.Incomplete;
6363
64 try writer.print(" {s} = {s},\n", .{ zig.fmtId(name), number });64 try writer.print(" {p} = {s},\n", .{ zig.fmtId(name), number });
65 }65 }
6666
67 try writer.writeAll("};\n\n");67 try writer.writeAll("};\n\n");
...@@ -82,7 +82,7 @@ pub fn main() !void {...@@ -82,7 +82,7 @@ pub fn main() !void {
82 const name = fields.next() orelse return error.Incomplete;82 const name = fields.next() orelse return error.Incomplete;
8383
84 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;84 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;
85 try writer.print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });85 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
86 }86 }
8787
88 try writer.writeAll("};\n\n");88 try writer.writeAll("};\n\n");
...@@ -107,7 +107,7 @@ pub fn main() !void {...@@ -107,7 +107,7 @@ pub fn main() !void {
107 const name = fields.next() orelse return error.Incomplete;107 const name = fields.next() orelse return error.Incomplete;
108108
109 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;109 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;
110 try writer.print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });110 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
111 }111 }
112112
113 // TODO: maybe extract these from arch/arm/include/uapi/asm/unistd.h113 // TODO: maybe extract these from arch/arm/include/uapi/asm/unistd.h
...@@ -137,7 +137,7 @@ pub fn main() !void {...@@ -137,7 +137,7 @@ pub fn main() !void {
137 if (mem.eql(u8, abi, "32")) continue;137 if (mem.eql(u8, abi, "32")) continue;
138 const name = fields.next() orelse return error.Incomplete;138 const name = fields.next() orelse return error.Incomplete;
139139
140 try writer.print(" {s} = {s},\n", .{ zig.fmtId(name), number });140 try writer.print(" {p} = {s},\n", .{ zig.fmtId(name), number });
141 }141 }
142142
143 try writer.writeAll("};\n\n");143 try writer.writeAll("};\n\n");
...@@ -162,7 +162,7 @@ pub fn main() !void {...@@ -162,7 +162,7 @@ pub fn main() !void {
162 const name = fields.next() orelse return error.Incomplete;162 const name = fields.next() orelse return error.Incomplete;
163 if (mem.startsWith(u8, name, "unused")) continue;163 if (mem.startsWith(u8, name, "unused")) continue;
164164
165 try writer.print(" {s} = Linux + {s},\n", .{ zig.fmtId(name), number });165 try writer.print(" {p} = Linux + {s},\n", .{ zig.fmtId(name), number });
166 }166 }
167167
168 try writer.writeAll("};\n\n");168 try writer.writeAll("};\n\n");
...@@ -187,7 +187,7 @@ pub fn main() !void {...@@ -187,7 +187,7 @@ pub fn main() !void {
187 const name = fields.next() orelse return error.Incomplete;187 const name = fields.next() orelse return error.Incomplete;
188 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;188 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;
189189
190 try writer.print(" {s} = Linux + {s},\n", .{ zig.fmtId(fixed_name), number });190 try writer.print(" {p} = Linux + {s},\n", .{ zig.fmtId(fixed_name), number });
191 }191 }
192192
193 try writer.writeAll("};\n\n");193 try writer.writeAll("};\n\n");
...@@ -210,12 +210,12 @@ pub fn main() !void {...@@ -210,12 +210,12 @@ pub fn main() !void {
210 if (mem.eql(u8, abi, "spu")) {210 if (mem.eql(u8, abi, "spu")) {
211 continue;211 continue;
212 } else if (mem.eql(u8, abi, "32")) {212 } else if (mem.eql(u8, abi, "32")) {
213 try writer.print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });213 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
214 } else if (mem.eql(u8, abi, "64")) {214 } else if (mem.eql(u8, abi, "64")) {
215 try list_64.writer().print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });215 try list_64.writer().print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
216 } else { // common/nospu216 } else { // common/nospu
217 try writer.print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });217 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
218 try list_64.writer().print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });218 try list_64.writer().print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
219 }219 }
220 }220 }
221221
...@@ -291,7 +291,7 @@ pub fn main() !void {...@@ -291,7 +291,7 @@ pub fn main() !void {
291 if (mem.eql(u8, name, "syscalls")) break :loop;291 if (mem.eql(u8, name, "syscalls")) break :loop;
292292
293 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;293 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;
294 try writer.print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });294 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
295 }295 }
296296
297 try writer.writeAll("};\n\n");297 try writer.writeAll("};\n\n");
...@@ -352,7 +352,7 @@ pub fn main() !void {...@@ -352,7 +352,7 @@ pub fn main() !void {
352 if (mem.eql(u8, name, "syscalls")) break :loop;352 if (mem.eql(u8, name, "syscalls")) break :loop;
353353
354 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;354 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;
355 try writer.print(" {s} = {s},\n", .{ zig.fmtId(fixed_name), number });355 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
356 }356 }
357357
358 try writer.writeAll(358 try writer.writeAll(
tools/update_cpu_features.zig+5-5
...@@ -1314,7 +1314,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -1314,7 +1314,7 @@ fn processOneTarget(job: Job) anyerror!void {
1314 );1314 );
13151315
1316 for (all_features.items) |feature| {1316 for (all_features.items) |feature| {
1317 try w.print(" {},\n", .{std.zig.fmtId(feature.zig_name)});1317 try w.print(" {p},\n", .{std.zig.fmtId(feature.zig_name)});
1318 }1318 }
13191319
1320 try w.writeAll(1320 try w.writeAll(
...@@ -1341,7 +1341,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -1341,7 +1341,7 @@ fn processOneTarget(job: Job) anyerror!void {
1341 for (all_features.items) |feature| {1341 for (all_features.items) |feature| {
1342 if (feature.llvm_name) |llvm_name| {1342 if (feature.llvm_name) |llvm_name| {
1343 try w.print(1343 try w.print(
1344 \\ result[@intFromEnum(Feature.{})] = .{{1344 \\ result[@intFromEnum(Feature.{p_})] = .{{
1345 \\ .llvm_name = "{}",1345 \\ .llvm_name = "{}",
1346 \\ .description = "{}",1346 \\ .description = "{}",
1347 \\ .dependencies = featureSet(&[_]Feature{{1347 \\ .dependencies = featureSet(&[_]Feature{{
...@@ -1354,7 +1354,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -1354,7 +1354,7 @@ fn processOneTarget(job: Job) anyerror!void {
1354 );1354 );
1355 } else {1355 } else {
1356 try w.print(1356 try w.print(
1357 \\ result[@intFromEnum(Feature.{})] = .{{1357 \\ result[@intFromEnum(Feature.{p_})] = .{{
1358 \\ .llvm_name = null,1358 \\ .llvm_name = null,
1359 \\ .description = "{}",1359 \\ .description = "{}",
1360 \\ .dependencies = featureSet(&[_]Feature{{1360 \\ .dependencies = featureSet(&[_]Feature{{
...@@ -1388,7 +1388,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -1388,7 +1388,7 @@ fn processOneTarget(job: Job) anyerror!void {
1388 } else {1388 } else {
1389 try w.writeAll("\n");1389 try w.writeAll("\n");
1390 for (dependencies.items) |dep| {1390 for (dependencies.items) |dep| {
1391 try w.print(" .{},\n", .{std.zig.fmtId(dep)});1391 try w.print(" .{p_},\n", .{std.zig.fmtId(dep)});
1392 }1392 }
1393 try w.writeAll(1393 try w.writeAll(
1394 \\ }),1394 \\ }),
...@@ -1454,7 +1454,7 @@ fn processOneTarget(job: Job) anyerror!void {...@@ -1454,7 +1454,7 @@ fn processOneTarget(job: Job) anyerror!void {
1454 } else {1454 } else {
1455 try w.writeAll("\n");1455 try w.writeAll("\n");
1456 for (cpu_features.items) |feature_zig_name| {1456 for (cpu_features.items) |feature_zig_name| {
1457 try w.print(" .{},\n", .{std.zig.fmtId(feature_zig_name)});1457 try w.print(" .{p_},\n", .{std.zig.fmtId(feature_zig_name)});
1458 }1458 }
1459 try w.writeAll(1459 try w.writeAll(
1460 \\ }),1460 \\ }),
tools/update_spirv_features.zig+5-5
...@@ -112,11 +112,11 @@ pub fn main() !void {...@@ -112,11 +112,11 @@ pub fn main() !void {
112 }112 }
113113
114 for (extensions) |ext| {114 for (extensions) |ext| {
115 try w.print(" {},\n", .{std.zig.fmtId(ext)});115 try w.print(" {p},\n", .{std.zig.fmtId(ext)});
116 }116 }
117117
118 for (capabilities) |cap| {118 for (capabilities) |cap| {
119 try w.print(" {},\n", .{std.zig.fmtId(cap.enumerant)});119 try w.print(" {p},\n", .{std.zig.fmtId(cap.enumerant)});
120 }120 }
121121
122 try w.writeAll(122 try w.writeAll(
...@@ -163,7 +163,7 @@ pub fn main() !void {...@@ -163,7 +163,7 @@ pub fn main() !void {
163 // TODO: Extension dependencies.163 // TODO: Extension dependencies.
164 for (extensions) |ext| {164 for (extensions) |ext| {
165 try w.print(165 try w.print(
166 \\ result[@intFromEnum(Feature.{s})] = .{{166 \\ result[@intFromEnum(Feature.{p_})] = .{{
167 \\ .llvm_name = null,167 \\ .llvm_name = null,
168 \\ .description = "SPIR-V extension {s}",168 \\ .description = "SPIR-V extension {s}",
169 \\ .dependencies = featureSet(&[_]Feature{{}}),169 \\ .dependencies = featureSet(&[_]Feature{{}}),
...@@ -178,7 +178,7 @@ pub fn main() !void {...@@ -178,7 +178,7 @@ pub fn main() !void {
178 // TODO: Capability extension dependencies.178 // TODO: Capability extension dependencies.
179 for (capabilities) |cap| {179 for (capabilities) |cap| {
180 try w.print(180 try w.print(
181 \\ result[@intFromEnum(Feature.{s})] = .{{181 \\ result[@intFromEnum(Feature.{p_})] = .{{
182 \\ .llvm_name = null,182 \\ .llvm_name = null,
183 \\ .description = "Enable SPIR-V capability {s}",183 \\ .description = "Enable SPIR-V capability {s}",
184 \\ .dependencies = featureSet(&[_]Feature{{184 \\ .dependencies = featureSet(&[_]Feature{{
...@@ -196,7 +196,7 @@ pub fn main() !void {...@@ -196,7 +196,7 @@ pub fn main() !void {
196 }196 }
197197
198 for (cap.capabilities) |cap_dep| {198 for (cap.capabilities) |cap_dep| {
199 try w.print(" .{},\n", .{std.zig.fmtId(cap_dep)});199 try w.print(" .{p_},\n", .{std.zig.fmtId(cap_dep)});
200 }200 }
201201
202 try w.writeAll(202 try w.writeAll(