diff options
| author | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-01-25 04:10:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-25 04:10:55 +0000 |
| commit | 8ba3812eeedec643dd045e0fecb8a6697f6253db (patch) | |
| tree | 00c47f03ccef1a0398163b5af7063501860d18fe /lib/std/builtin.zig | |
| parent | 921725427efeae591793f49291807a41112ccbf9 (diff) | |
| parent | b6726913d31f9273317ab56c4d33096aee0a588f (diff) | |
| download | zig-8ba3812eeedec643dd045e0fecb8a6697f6253db.tar.gz zig-8ba3812eeedec643dd045e0fecb8a6697f6253db.zip | |
Merge pull request #22594 from mlugg/panic-stuff
compiler: yet more panic handler changes
Diffstat (limited to 'lib/std/builtin.zig')
| -rw-r--r-- | lib/std/builtin.zig | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 73a47fa3af..f1e262012e 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -1110,46 +1110,31 @@ pub const TestFn = struct { /// Deprecated, use the `Panic` namespace instead. /// To be deleted after 0.14.0 is released. pub const PanicFn = fn ([]const u8, ?*StackTrace, ?usize) noreturn; -/// Deprecated, use the `Panic` namespace instead. -/// To be deleted after 0.14.0 is released. -pub const panic: PanicFn = Panic.call; /// This namespace is used by the Zig compiler to emit various kinds of safety -/// panics. These can be overridden by making a public `Panic` namespace in the +/// panics. These can be overridden by making a public `panic` namespace in the /// root source file. -pub const Panic: type = if (@hasDecl(root, "Panic")) - root.Panic -else if (@hasDecl(root, "panic")) // Deprecated, use `Panic` instead. - DeprecatedPanic -else if (builtin.zig_backend == .stage2_riscv64) - std.debug.SimplePanic // https://github.com/ziglang/zig/issues/21519 -else - std.debug.FormattedPanic; - -/// To be deleted after 0.14.0 is released. -const DeprecatedPanic = struct { - pub const call = root.panic; - pub const sentinelMismatch = std.debug.FormattedPanic.sentinelMismatch; - pub const unwrapError = std.debug.FormattedPanic.unwrapError; - pub const outOfBounds = std.debug.FormattedPanic.outOfBounds; - pub const startGreaterThanEnd = std.debug.FormattedPanic.startGreaterThanEnd; - pub const inactiveUnionField = std.debug.FormattedPanic.inactiveUnionField; - pub const messages = std.debug.FormattedPanic.messages; +pub const panic: type = p: { + if (@hasDecl(root, "panic")) { + if (@TypeOf(root.panic) != type) { + // Deprecated; make `panic` a namespace instead. + break :p std.debug.FullPanic(struct { + fn panic(msg: []const u8, ra: ?usize) noreturn { + root.panic(msg, @errorReturnTrace(), ra); + } + }.panic); + } + break :p root.panic; + } + if (@hasDecl(root, "Panic")) { + break :p root.Panic; // Deprecated; use `panic` instead. + } + if (builtin.zig_backend == .stage2_riscv64) { + break :p std.debug.simple_panic; + } + break :p std.debug.FullPanic(std.debug.defaultPanic); }; -/// To be deleted after zig1.wasm is updated. -pub const panicSentinelMismatch = Panic.sentinelMismatch; -/// To be deleted after zig1.wasm is updated. -pub const panicUnwrapError = Panic.unwrapError; -/// To be deleted after zig1.wasm is updated. -pub const panicOutOfBounds = Panic.outOfBounds; -/// To be deleted after zig1.wasm is updated. -pub const panicStartGreaterThanEnd = Panic.startGreaterThanEnd; -/// To be deleted after zig1.wasm is updated. -pub const panicInactiveUnionField = Panic.inactiveUnionField; -/// To be deleted after zig1.wasm is updated. -pub const panic_messages = Panic.messages; - pub noinline fn returnError() void { @branchHint(.unlikely); @setRuntimeSafety(false); |
