From 0eb1e0c30a4f143dfcb15b4c6a01ec9c566dc39f Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 13 Feb 2026 12:28:03 -0500 Subject: [PATCH] crash_report: finish reverting panic changes better I missed that the types were `pub`. --- src/crash_report.zig | 28 +++++++++++++++++++++++----- src/main.zig | 8 ++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/crash_report.zig b/src/crash_report.zig index f58a7cef7a..b177af3bb6 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -1,13 +1,18 @@ +pub const enabled = switch (build_options.io_mode) { + .threaded => build_options.enable_debug_extensions, + .evented => false, // would use threadlocals in a way incompatible with evented +}; + /// We override the panic implementation to our own one, so we can print our own information before /// calling the default panic handler. This declaration must be re-exposed from `@import("root")`. -pub const panic = std.debug.FullPanic(panicImpl); +pub const panic = std.debug.FullPanic(if (enabled) panicImpl else std.debug.defaultPanic); /// We let std install its segfault handler, but we override the target-agnostic handler it calls, /// so we can print our own information before calling the default segfault logic. This declaration /// must be re-exposed from `@import("root")`. -pub const debug = struct { +pub const debug = if (enabled) struct { pub const handleSegfault = handleSegfaultImpl; -}; +} else struct {}; /// Printed in panic messages when suggesting a command to run, allowing copy-pasting the command. /// 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 { std.debug.defaultPanic(msg, first_trace_addr orelse @returnAddress()); } -pub const AnalyzeBody = struct { +pub const AnalyzeBody = if (enabled) struct { parent: ?*AnalyzeBody, sema: *Sema, block: *Sema.Block, @@ -52,9 +57,15 @@ pub const AnalyzeBody = struct { std.debug.assert(current.? == ab); // `Sema.analyzeBodyInner` did not match push/pop calls current = ab.parent; } +} else struct { + const current: ?noreturn = null; + // Dummy implementation, with functions marked `inline` to avoid interfering with tail calls. + pub inline fn push(_: AnalyzeBody, _: *Sema, _: *Sema.Block, _: []const Zir.Inst.Index) void {} + pub inline fn pop(_: AnalyzeBody) void {} + pub inline fn setBodyIndex(_: @This(), _: usize) void {} }; -pub const CodegenFunc = struct { +pub const CodegenFunc = if (enabled) struct { zcu: *const Zcu, func_index: InternPool.Index, threadlocal var current: ?CodegenFunc = null; @@ -66,6 +77,11 @@ pub const CodegenFunc = struct { std.debug.assert(current.?.func_index == func_index); current = null; } +} else struct { + const current: ?noreturn = null; + // Dummy implementation + pub fn start(_: *const Zcu, _: InternPool.Index) void {} + pub fn stop(_: InternPool.Index) void {} }; fn dumpCrashContext() Io.Writer.Error!void { @@ -172,3 +188,5 @@ const Zcu = @import("Zcu.zig"); const InternPool = @import("InternPool.zig"); const dev = @import("dev.zig"); const print_zir = @import("print_zir.zig"); + +const build_options = @import("build_options"); diff --git a/src/main.zig b/src/main.zig index 89a24559ed..1b9fe7b299 100644 --- a/src/main.zig +++ b/src/main.zig @@ -52,12 +52,8 @@ pub const std_options: std.Options = .{ }; pub const std_options_cwd = if (native_os == .wasi) wasi_cwd else null; -const crash_report_enabled = switch (build_options.io_mode) { - .threaded => build_options.enable_debug_extensions, - .evented => false, // would use threadlocals in a way incompatible with evented -}; -pub const panic = if (crash_report_enabled) crash_report.panic else std.debug.FullPanic(std.debug.defaultPanic); -pub const debug = if (crash_report_enabled) crash_report.debug else struct {}; +pub const panic = crash_report.panic; +pub const debug = crash_report.debug; var preopens: std.process.Preopens = .empty; pub fn wasi_cwd() Io.Dir {