authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-08 23:49:17+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:55+02:00
logd1484bf4b96177135183916b95198de25dc63356
tree5c61b9dc2dc00d03bdbd851548ebc8ee068afe0b
parent979b4102588fbb0d066060a5a6b6e10f584158ac
signaturelock-open Commit is signed but in an unrecognized format.

spirv: emit nonsemantic info with zig errors

In order to be able to report nice errors in the test runner, and in order to check SkipZigTest errors, we need to pass the error names to the consumer. This kind of information can be passed via nonsemantic instructions - using OpSourceExtension here. All errors are concatenated into a single string, starting with 'zig_errors:' for identification, separated by a colon (:). To ensure that we can represent all error codes, even those which contain a colon, the error names are URI- escaped. URI-escaping, rather than base64, allows us to see the error names when viewing disassembled SPIR-V code.

1 files changed, 21 insertions(+), 0 deletions(-)

src/link/SpirV.zig+21
......@@ -181,6 +181,27 @@ pub fn flushModule(self: *SpirV, comp: *Compilation, prog_node: *std.Progress.No
181181 try writeCapabilities(&self.spv, target);
182182 try writeMemoryModel(&self.spv, target);
183183
184 // We need to export the list of error names somewhere so that we can pretty-print them in the
185 // executor. This is not really an important thing though, so we can just dump it in any old
186 // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name.
187
188 var error_info = std.ArrayList(u8).init(self.spv.arena);
189 try error_info.appendSlice("zig_errors");
190 const module = self.base.options.module.?;
191 for (module.error_name_list.items) |name| {
192 // Errors can contain pretty much any character - to encode them in a string we must escape
193 // them somehow. Easiest here is to use some established scheme, one which also preseves the
194 // name if it contains no strange characters is nice for debugging. URI encoding fits the bill.
195 // We're using : as separator, which is a reserved character.
196
197 const escaped_name = try std.Uri.escapeString(self.base.allocator, name);
198 defer self.base.allocator.free(escaped_name);
199 try error_info.writer().print(":{s}", .{escaped_name});
200 }
201 try self.spv.sections.debug_strings.emit(self.spv.gpa, .OpSourceExtension, .{
202 .extension = error_info.items,
203 });
204
184205 try self.spv.flush(self.base.file.?);
185206}
186207