| author | |
| committer | |
| log | 363d4a107de3af95620f82e851e8777aa9f576c9 |
| tree | 14a7536caf8366329f0f2f9286fa539d0fab3db2 |
| parent | ed33901218363b9d1baee4c37e85f573dc034e06 |
4 files changed, 38 insertions(+), 19 deletions(-)
lib/std/zig/ErrorBundle.zig+28-1| ... | ... | @@ -32,6 +32,8 @@ pub const SourceLocationIndex = enum(u32) { |
| 32 | 32 | pub const ErrorMessageList = struct { |
| 33 | 33 | len: u32, |
| 34 | 34 | start: u32, |
| 35 | /// null-terminated string index. 0 means no compile log text. | |
| 36 | compile_log_text: u32, | |
| 35 | 37 | }; |
| 36 | 38 | |
| 37 | 39 | /// Trailing: |
| ... | ... | @@ -110,6 +112,10 @@ pub fn getNotes(eb: ErrorBundle, index: MessageIndex) []const MessageIndex { |
| 110 | 112 | return @ptrCast([]const MessageIndex, eb.extra[start..][0..notes_len]); |
| 111 | 113 | } |
| 112 | 114 | |
| 115 | pub fn getCompileLogOutput(eb: ErrorBundle) [:0]const u8 { | |
| 116 | return nullTerminatedString(eb, getErrorMessageList(eb).compile_log_text); | |
| 117 | } | |
| 118 | ||
| 113 | 119 | /// Returns the requested data, as well as the new index which is at the start of the |
| 114 | 120 | /// trailers for the object. |
| 115 | 121 | fn extraData(eb: ErrorBundle, comptime T: type, index: usize) struct { data: T, end: usize } { |
| ... | ... | @@ -145,6 +151,7 @@ pub const RenderOptions = struct { |
| 145 | 151 | ttyconf: std.debug.TTY.Config, |
| 146 | 152 | include_reference_trace: bool = true, |
| 147 | 153 | include_source_line: bool = true, |
| 154 | include_log_text: bool = true, | |
| 148 | 155 | }; |
| 149 | 156 | |
| 150 | 157 | pub fn renderToStdErr(eb: ErrorBundle, options: RenderOptions) void { |
| ... | ... | @@ -158,6 +165,14 @@ pub fn renderToWriter(eb: ErrorBundle, options: RenderOptions, writer: anytype) |
| 158 | 165 | for (eb.getMessages()) |err_msg| { |
| 159 | 166 | try renderErrorMessageToWriter(eb, options, err_msg, writer, "error", .Red, 0); |
| 160 | 167 | } |
| 168 | ||
| 169 | if (options.include_log_text) { | |
| 170 | const log_text = eb.getCompileLogOutput(); | |
| 171 | if (log_text.len != 0) { | |
| 172 | try writer.writeAll("\nCompile Log Output:\n"); | |
| 173 | try writer.writeAll(log_text); | |
| 174 | } | |
| 175 | } | |
| 161 | 176 | } |
| 162 | 177 | |
| 163 | 178 | fn renderErrorMessageToWriter( |
| ... | ... | @@ -314,6 +329,7 @@ pub const Wip = struct { |
| 314 | 329 | assert(0 == try addExtra(wip, ErrorMessageList{ |
| 315 | 330 | .len = 0, |
| 316 | 331 | .start = 0, |
| 332 | .compile_log_text = 0, | |
| 317 | 333 | })); |
| 318 | 334 | } |
| 319 | 335 | |
| ... | ... | @@ -325,9 +341,10 @@ pub const Wip = struct { |
| 325 | 341 | wip.* = undefined; |
| 326 | 342 | } |
| 327 | 343 | |
| 328 | pub fn toOwnedBundle(wip: *Wip) !ErrorBundle { | |
| 344 | pub fn toOwnedBundle(wip: *Wip, compile_log_text: []const u8) !ErrorBundle { | |
| 329 | 345 | const gpa = wip.gpa; |
| 330 | 346 | if (wip.root_list.items.len == 0) { |
| 347 | assert(compile_log_text.len == 0); | |
| 331 | 348 | // Special encoding when there are no errors. |
| 332 | 349 | wip.deinit(); |
| 333 | 350 | wip.* = .{ |
| ... | ... | @@ -338,9 +355,19 @@ pub const Wip = struct { |
| 338 | 355 | }; |
| 339 | 356 | return empty; |
| 340 | 357 | } |
| 358 | ||
| 359 | const compile_log_str_index = if (compile_log_text.len == 0) 0 else str: { | |
| 360 | const str = @intCast(u32, wip.string_bytes.items.len); | |
| 361 | try wip.string_bytes.ensureUnusedCapacity(gpa, compile_log_text.len + 1); | |
| 362 | wip.string_bytes.appendSliceAssumeCapacity(compile_log_text); | |
| 363 | wip.string_bytes.appendAssumeCapacity(0); | |
| 364 | break :str str; | |
| 365 | }; | |
| 366 | ||
| 341 | 367 | wip.setExtra(0, ErrorMessageList{ |
| 342 | 368 | .len = @intCast(u32, wip.root_list.items.len), |
| 343 | 369 | .start = @intCast(u32, wip.extra.items.len), |
| 370 | .compile_log_text = compile_log_str_index, | |
| 344 | 371 | }); |
| 345 | 372 | try wip.extra.appendSlice(gpa, @ptrCast([]const u32, wip.root_list.items)); |
| 346 | 373 | wip.root_list.clearAndFree(gpa); |
src/Compilation.zig+2-6| ... | ... | @@ -2705,7 +2705,8 @@ pub fn getAllErrorsAlloc(self: *Compilation) !ErrorBundle { |
| 2705 | 2705 | |
| 2706 | 2706 | assert(self.totalErrorCount() == bundle.root_list.items.len); |
| 2707 | 2707 | |
| 2708 | return bundle.toOwnedBundle(); | |
| 2708 | const compile_log_text = if (self.bin_file.options.module) |m| m.compile_log_text.items else ""; | |
| 2709 | return bundle.toOwnedBundle(compile_log_text); | |
| 2709 | 2710 | } |
| 2710 | 2711 | |
| 2711 | 2712 | pub const ErrorNoteHashContext = struct { |
| ... | ... | @@ -2954,11 +2955,6 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Module.File) !void { |
| 2954 | 2955 | } |
| 2955 | 2956 | } |
| 2956 | 2957 | |
| 2957 | pub fn getCompileLogOutput(self: *Compilation) []const u8 { | |
| 2958 | const module = self.bin_file.options.module orelse return &[0]u8{}; | |
| 2959 | return module.compile_log_text.items; | |
| 2960 | } | |
| 2961 | ||
| 2962 | 2958 | pub fn performAllTheWork( |
| 2963 | 2959 | comp: *Compilation, |
| 2964 | 2960 | main_progress_node: *std.Progress.Node, |
src/Sema.zig+1-1| ... | ... | @@ -2219,7 +2219,7 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2219 | 2219 | wip_errors.init(gpa) catch unreachable; |
| 2220 | 2220 | Compilation.addModuleErrorMsg(&wip_errors, err_msg.*) catch unreachable; |
| 2221 | 2221 | std.debug.print("compile error during Sema:\n", .{}); |
| 2222 | var error_bundle = wip_errors.toOwnedBundle() catch unreachable; | |
| 2222 | var error_bundle = wip_errors.toOwnedBundle("") catch unreachable; | |
| 2223 | 2223 | error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); |
| 2224 | 2224 | crash_report.compilerPanic("unexpected compile error occurred", null, null); |
| 2225 | 2225 | } |
src/main.zig+7-11| ... | ... | @@ -3886,10 +3886,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void |
| 3886 | 3886 | |
| 3887 | 3887 | if (errors.errorMessageCount() > 0) { |
| 3888 | 3888 | errors.renderToStdErr(renderOptions(comp.color)); |
| 3889 | const log_text = comp.getCompileLogOutput(); | |
| 3890 | if (log_text.len != 0) { | |
| 3891 | std.debug.print("\nCompile Log Output:\n{s}", .{log_text}); | |
| 3892 | } | |
| 3893 | 3889 | return error.SemanticAnalyzeFail; |
| 3894 | 3890 | } else switch (hook) { |
| 3895 | 3891 | .none => {}, |
| ... | ... | @@ -4512,7 +4508,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4512 | 4508 | &all_modules, |
| 4513 | 4509 | ); |
| 4514 | 4510 | if (wip_errors.root_list.items.len > 0) { |
| 4515 | var errors = try wip_errors.toOwnedBundle(); | |
| 4511 | var errors = try wip_errors.toOwnedBundle(""); | |
| 4516 | 4512 | defer errors.deinit(gpa); |
| 4517 | 4513 | errors.renderToStdErr(renderOptions(color)); |
| 4518 | 4514 | process.exit(1); |
| ... | ... | @@ -4775,7 +4771,7 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void |
| 4775 | 4771 | try wip_errors.init(gpa); |
| 4776 | 4772 | defer wip_errors.deinit(); |
| 4777 | 4773 | try Compilation.addZirErrorMessages(&wip_errors, &file); |
| 4778 | var error_bundle = try wip_errors.toOwnedBundle(); | |
| 4774 | var error_bundle = try wip_errors.toOwnedBundle(""); | |
| 4779 | 4775 | defer error_bundle.deinit(gpa); |
| 4780 | 4776 | error_bundle.renderToStdErr(renderOptions(color)); |
| 4781 | 4777 | process.exit(2); |
| ... | ... | @@ -4981,7 +4977,7 @@ fn fmtPathFile( |
| 4981 | 4977 | try wip_errors.init(gpa); |
| 4982 | 4978 | defer wip_errors.deinit(); |
| 4983 | 4979 | try Compilation.addZirErrorMessages(&wip_errors, &file); |
| 4984 | var error_bundle = try wip_errors.toOwnedBundle(); | |
| 4980 | var error_bundle = try wip_errors.toOwnedBundle(""); | |
| 4985 | 4981 | defer error_bundle.deinit(gpa); |
| 4986 | 4982 | error_bundle.renderToStdErr(renderOptions(fmt.color)); |
| 4987 | 4983 | fmt.any_error = true; |
| ... | ... | @@ -5018,7 +5014,7 @@ fn printAstErrorsToStderr(gpa: Allocator, tree: Ast, path: []const u8, color: Co |
| 5018 | 5014 | |
| 5019 | 5015 | try putAstErrorsIntoBundle(gpa, tree, path, &wip_errors); |
| 5020 | 5016 | |
| 5021 | var error_bundle = try wip_errors.toOwnedBundle(); | |
| 5017 | var error_bundle = try wip_errors.toOwnedBundle(""); | |
| 5022 | 5018 | defer error_bundle.deinit(gpa); |
| 5023 | 5019 | error_bundle.renderToStdErr(renderOptions(color)); |
| 5024 | 5020 | } |
| ... | ... | @@ -5622,7 +5618,7 @@ pub fn cmdAstCheck( |
| 5622 | 5618 | try wip_errors.init(gpa); |
| 5623 | 5619 | defer wip_errors.deinit(); |
| 5624 | 5620 | try Compilation.addZirErrorMessages(&wip_errors, &file); |
| 5625 | var error_bundle = try wip_errors.toOwnedBundle(); | |
| 5621 | var error_bundle = try wip_errors.toOwnedBundle(""); | |
| 5626 | 5622 | defer error_bundle.deinit(gpa); |
| 5627 | 5623 | error_bundle.renderToStdErr(renderOptions(color)); |
| 5628 | 5624 | process.exit(1); |
| ... | ... | @@ -5739,7 +5735,7 @@ pub fn cmdChangelist( |
| 5739 | 5735 | try wip_errors.init(gpa); |
| 5740 | 5736 | defer wip_errors.deinit(); |
| 5741 | 5737 | try Compilation.addZirErrorMessages(&wip_errors, &file); |
| 5742 | var error_bundle = try wip_errors.toOwnedBundle(); | |
| 5738 | var error_bundle = try wip_errors.toOwnedBundle(""); | |
| 5743 | 5739 | defer error_bundle.deinit(gpa); |
| 5744 | 5740 | error_bundle.renderToStdErr(renderOptions(color)); |
| 5745 | 5741 | process.exit(1); |
| ... | ... | @@ -5774,7 +5770,7 @@ pub fn cmdChangelist( |
| 5774 | 5770 | try wip_errors.init(gpa); |
| 5775 | 5771 | defer wip_errors.deinit(); |
| 5776 | 5772 | try Compilation.addZirErrorMessages(&wip_errors, &file); |
| 5777 | var error_bundle = try wip_errors.toOwnedBundle(); | |
| 5773 | var error_bundle = try wip_errors.toOwnedBundle(""); | |
| 5778 | 5774 | defer error_bundle.deinit(gpa); |
| 5779 | 5775 | error_bundle.renderToStdErr(renderOptions(color)); |
| 5780 | 5776 | process.exit(1); |