| author | |
| committer | |
| log | 73403d897caec40eff16226abb54098fa6623954 |
| tree | cb59ce2d7005096b8c9267f347f5ea2b20b49e83 |
| parent | 75cecef63ccaffda32b7ec2dd2d6cc3cb0b3d23a |
This is useful when debugging stage2 and getting an unexpected compile
error, or when rendering a compile error crashes the compiler.4 files changed, 20 insertions(+), 3 deletions(-)
src/Compilation.zig+5-2| ... | @@ -82,6 +82,9 @@ disable_c_depfile: bool, | ... | @@ -82,6 +82,9 @@ disable_c_depfile: bool, |
| 82 | time_report: bool, | 82 | time_report: bool, |
| 83 | stack_report: bool, | 83 | stack_report: bool, |
| 84 | unwind_tables: bool, | 84 | unwind_tables: bool, |
| 85 | test_evented_io: bool, | ||
| 86 | debug_compiler_runtime_libs: bool, | ||
| 87 | debug_compile_errors: bool, | ||
| 85 | 88 | ||
| 86 | c_source_files: []const CSourceFile, | 89 | c_source_files: []const CSourceFile, |
| 87 | clang_argv: []const []const u8, | 90 | clang_argv: []const []const u8, |
| ... | @@ -138,8 +141,6 @@ mutex: std.Thread.Mutex = .{}, | ... | @@ -138,8 +141,6 @@ mutex: std.Thread.Mutex = .{}, |
| 138 | 141 | ||
| 139 | test_filter: ?[]const u8, | 142 | test_filter: ?[]const u8, |
| 140 | test_name_prefix: ?[]const u8, | 143 | test_name_prefix: ?[]const u8, |
| 141 | test_evented_io: bool, | ||
| 142 | debug_compiler_runtime_libs: bool, | ||
| 143 | 144 | ||
| 144 | emit_asm: ?EmitLoc, | 145 | emit_asm: ?EmitLoc, |
| 145 | emit_llvm_ir: ?EmitLoc, | 146 | emit_llvm_ir: ?EmitLoc, |
| ... | @@ -727,6 +728,7 @@ pub const InitOptions = struct { | ... | @@ -727,6 +728,7 @@ pub const InitOptions = struct { |
| 727 | is_test: bool = false, | 728 | is_test: bool = false, |
| 728 | test_evented_io: bool = false, | 729 | test_evented_io: bool = false, |
| 729 | debug_compiler_runtime_libs: bool = false, | 730 | debug_compiler_runtime_libs: bool = false, |
| 731 | debug_compile_errors: bool = false, | ||
| 730 | /// Normally when you create a `Compilation`, Zig will automatically build | 732 | /// Normally when you create a `Compilation`, Zig will automatically build |
| 731 | /// and link in required dependencies, such as compiler-rt and libc. When | 733 | /// and link in required dependencies, such as compiler-rt and libc. When |
| 732 | /// building such dependencies themselves, this flag must be set to avoid | 734 | /// building such dependencies themselves, this flag must be set to avoid |
| ... | @@ -1471,6 +1473,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1471,6 +1473,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1471 | .test_name_prefix = options.test_name_prefix, | 1473 | .test_name_prefix = options.test_name_prefix, |
| 1472 | .test_evented_io = options.test_evented_io, | 1474 | .test_evented_io = options.test_evented_io, |
| 1473 | .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs, | 1475 | .debug_compiler_runtime_libs = options.debug_compiler_runtime_libs, |
| 1476 | .debug_compile_errors = options.debug_compile_errors, | ||
| 1474 | .work_queue_wait_group = undefined, | 1477 | .work_queue_wait_group = undefined, |
| 1475 | .astgen_wait_group = undefined, | 1478 | .astgen_wait_group = undefined, |
| 1476 | }; | 1479 | }; |
src/Sema.zig+9| ... | @@ -1213,6 +1213,15 @@ pub fn fail( | ... | @@ -1213,6 +1213,15 @@ pub fn fail( |
| 1213 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { | 1213 | fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 1214 | @setCold(true); | 1214 | @setCold(true); |
| 1215 | 1215 | ||
| 1216 | if (crash_report.is_enabled and sema.mod.comp.debug_compile_errors) { | ||
| 1217 | std.debug.print("compile error during Sema: {s}, src: {s}:{}\n", .{ | ||
| 1218 | err_msg.msg, | ||
| 1219 | err_msg.src_loc.file_scope.sub_file_path, | ||
| 1220 | err_msg.src_loc.lazy, | ||
| 1221 | }); | ||
| 1222 | crash_report.compilerPanic("unexpected compile error occurred", null); | ||
| 1223 | } | ||
| 1224 | |||
| 1216 | const mod = sema.mod; | 1225 | const mod = sema.mod; |
| 1217 | 1226 | ||
| 1218 | { | 1227 | { |
src/crash_report.zig+1-1| ... | @@ -151,7 +151,7 @@ fn writeFullyQualifiedDeclWithFile(decl: *Decl, stream: anytype) !void { | ... | @@ -151,7 +151,7 @@ fn writeFullyQualifiedDeclWithFile(decl: *Decl, stream: anytype) !void { |
| 151 | try decl.renderFullyQualifiedDebugName(stream); | 151 | try decl.renderFullyQualifiedDebugName(stream); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { | 154 | pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { |
| 155 | PanicSwitch.preDispatch(); | 155 | PanicSwitch.preDispatch(); |
| 156 | @setCold(true); | 156 | @setCold(true); |
| 157 | const ret_addr = @returnAddress(); | 157 | const ret_addr = @returnAddress(); |
src/main.zig+5| ... | @@ -433,6 +433,7 @@ const usage_build_generic = | ... | @@ -433,6 +433,7 @@ const usage_build_generic = |
| 433 | \\ --verbose-cimport Enable compiler debug output for C imports | 433 | \\ --verbose-cimport Enable compiler debug output for C imports |
| 434 | \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features | 434 | \\ --verbose-llvm-cpu-features Enable compiler debug output for LLVM CPU features |
| 435 | \\ --debug-log [scope] Enable printing debug/info log messages for scope | 435 | \\ --debug-log [scope] Enable printing debug/info log messages for scope |
| 436 | \\ --debug-compile-errors Crash with helpful diagnostics at the first compile error | ||
| 436 | \\ | 437 | \\ |
| 437 | ; | 438 | ; |
| 438 | 439 | ||
| ... | @@ -549,6 +550,7 @@ fn buildOutputType( | ... | @@ -549,6 +550,7 @@ fn buildOutputType( |
| 549 | var single_threaded = false; | 550 | var single_threaded = false; |
| 550 | var function_sections = false; | 551 | var function_sections = false; |
| 551 | var watch = false; | 552 | var watch = false; |
| 553 | var debug_compile_errors = false; | ||
| 552 | var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK"); | 554 | var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK"); |
| 553 | var verbose_cc = std.process.hasEnvVarConstant("ZIG_VERBOSE_CC"); | 555 | var verbose_cc = std.process.hasEnvVarConstant("ZIG_VERBOSE_CC"); |
| 554 | var verbose_air = false; | 556 | var verbose_air = false; |
| ... | @@ -1078,6 +1080,8 @@ fn buildOutputType( | ... | @@ -1078,6 +1080,8 @@ fn buildOutputType( |
| 1078 | linker_allow_shlib_undefined = false; | 1080 | linker_allow_shlib_undefined = false; |
| 1079 | } else if (mem.eql(u8, arg, "-Bsymbolic")) { | 1081 | } else if (mem.eql(u8, arg, "-Bsymbolic")) { |
| 1080 | linker_bind_global_refs_locally = true; | 1082 | linker_bind_global_refs_locally = true; |
| 1083 | } else if (mem.eql(u8, arg, "--debug-compile-errors")) { | ||
| 1084 | debug_compile_errors = true; | ||
| 1081 | } else if (mem.eql(u8, arg, "--verbose-link")) { | 1085 | } else if (mem.eql(u8, arg, "--verbose-link")) { |
| 1082 | verbose_link = true; | 1086 | verbose_link = true; |
| 1083 | } else if (mem.eql(u8, arg, "--verbose-cc")) { | 1087 | } else if (mem.eql(u8, arg, "--verbose-cc")) { |
| ... | @@ -2134,6 +2138,7 @@ fn buildOutputType( | ... | @@ -2134,6 +2138,7 @@ fn buildOutputType( |
| 2134 | .disable_lld_caching = !have_enable_cache, | 2138 | .disable_lld_caching = !have_enable_cache, |
| 2135 | .subsystem = subsystem, | 2139 | .subsystem = subsystem, |
| 2136 | .wasi_exec_model = wasi_exec_model, | 2140 | .wasi_exec_model = wasi_exec_model, |
| 2141 | .debug_compile_errors = debug_compile_errors, | ||
| 2137 | }) catch |err| { | 2142 | }) catch |err| { |
| 2138 | fatal("unable to create compilation: {s}", .{@errorName(err)}); | 2143 | fatal("unable to create compilation: {s}", .{@errorName(err)}); |
| 2139 | }; | 2144 | }; |