authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-02-13 12:28:03-05:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-02-13 12:29:40-05:00
log0eb1e0c30a4f143dfcb15b4c6a01ec9c566dc39f
tree5b95c582d2e3d7bc726b8a494318440a3d29fe7d
parent2fa1a784914c536e45fdfaba9e357d0ef4f4f133

crash_report: finish reverting panic changes better

I missed that the types were `pub`.

2 files changed, 25 insertions(+), 11 deletions(-)

src/crash_report.zig+23-5
......@@ -1,13 +1,18 @@
1pub const enabled = switch (build_options.io_mode) {
2 .threaded => build_options.enable_debug_extensions,
3 .evented => false, // would use threadlocals in a way incompatible with evented
4};
5
16/// We override the panic implementation to our own one, so we can print our own information before
27/// calling the default panic handler. This declaration must be re-exposed from `@import("root")`.
3pub const panic = std.debug.FullPanic(panicImpl);
8pub const panic = std.debug.FullPanic(if (enabled) panicImpl else std.debug.defaultPanic);
49
510/// We let std install its segfault handler, but we override the target-agnostic handler it calls,
611/// so we can print our own information before calling the default segfault logic. This declaration
712/// must be re-exposed from `@import("root")`.
8pub const debug = struct {
13pub const debug = if (enabled) struct {
914 pub const handleSegfault = handleSegfaultImpl;
10};
15} else struct {};
1116
1217/// Printed in panic messages when suggesting a command to run, allowing copy-pasting the command.
1318/// Set by `main` as soon as arguments are known. The value here is a default in case we somehow
......@@ -25,7 +30,7 @@ fn panicImpl(msg: []const u8, first_trace_addr: ?usize) noreturn {
2530 std.debug.defaultPanic(msg, first_trace_addr orelse @returnAddress());
2631}
2732
28pub const AnalyzeBody = struct {
33pub const AnalyzeBody = if (enabled) struct {
2934 parent: ?*AnalyzeBody,
3035 sema: *Sema,
3136 block: *Sema.Block,
......@@ -52,9 +57,15 @@ pub const AnalyzeBody = struct {
5257 std.debug.assert(current.? == ab); // `Sema.analyzeBodyInner` did not match push/pop calls
5358 current = ab.parent;
5459 }
60} else struct {
61 const current: ?noreturn = null;
62 // Dummy implementation, with functions marked `inline` to avoid interfering with tail calls.
63 pub inline fn push(_: AnalyzeBody, _: *Sema, _: *Sema.Block, _: []const Zir.Inst.Index) void {}
64 pub inline fn pop(_: AnalyzeBody) void {}
65 pub inline fn setBodyIndex(_: @This(), _: usize) void {}
5566};
5667
57pub const CodegenFunc = struct {
68pub const CodegenFunc = if (enabled) struct {
5869 zcu: *const Zcu,
5970 func_index: InternPool.Index,
6071 threadlocal var current: ?CodegenFunc = null;
......@@ -66,6 +77,11 @@ pub const CodegenFunc = struct {
6677 std.debug.assert(current.?.func_index == func_index);
6778 current = null;
6879 }
80} else struct {
81 const current: ?noreturn = null;
82 // Dummy implementation
83 pub fn start(_: *const Zcu, _: InternPool.Index) void {}
84 pub fn stop(_: InternPool.Index) void {}
6985};
7086
7187fn dumpCrashContext() Io.Writer.Error!void {
......@@ -172,3 +188,5 @@ const Zcu = @import("Zcu.zig");
172188const InternPool = @import("InternPool.zig");
173189const dev = @import("dev.zig");
174190const print_zir = @import("print_zir.zig");
191
192const build_options = @import("build_options");
src/main.zig+2-6
......@@ -52,12 +52,8 @@ pub const std_options: std.Options = .{
5252};
5353pub const std_options_cwd = if (native_os == .wasi) wasi_cwd else null;
5454
55const crash_report_enabled = switch (build_options.io_mode) {
56 .threaded => build_options.enable_debug_extensions,
57 .evented => false, // would use threadlocals in a way incompatible with evented
58};
59pub const panic = if (crash_report_enabled) crash_report.panic else std.debug.FullPanic(std.debug.defaultPanic);
60pub const debug = if (crash_report_enabled) crash_report.debug else struct {};
55pub const panic = crash_report.panic;
56pub const debug = crash_report.debug;
6157
6258var preopens: std.process.Preopens = .empty;
6359pub fn wasi_cwd() Io.Dir {