From 83991efe10d92c4b920d7b7fc75be98ed7854ad7 Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 24 Jan 2025 02:19:28 +0000 Subject: compiler: yet more panic handler changes * `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace. * `root.Panic` -> `root.panic` for the same reason. There are type checks so that we still allow the legacy `pub fn panic` strategy in the 0.14.0 release. * `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason. * `std.debug.NoPanic` -> `std.debug.no_panic`, same reason. * `std.debug.FormattedPanic` is now a function `std.debug.FullPanic` which takes as input a `panicFn` and returns a namespace with all the panic functions. This handles the incredibly common case of just wanting to override how the message is printed, whilst keeping nice formatted panics. * Remove `std.builtin.panic.messages`; now, every safety panic has its own function. This reduces binary bloat, as calls to these functions no longer need to prepare any arguments (aside from the error return trace). * Remove some legacy declarations, since a zig1.wasm update has happened. Most of these were related to the panic handler, but a quick grep for "zig1" brought up a couple more results too. Also, add some missing type checks to Sema. Resolves: #22584 formatted -> full --- lib/std/debug/simple_panic.zig | 154 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 lib/std/debug/simple_panic.zig (limited to 'lib/std/debug/simple_panic.zig') diff --git a/lib/std/debug/simple_panic.zig b/lib/std/debug/simple_panic.zig new file mode 100644 index 0000000000..6a6c12aa2d --- /dev/null +++ b/lib/std/debug/simple_panic.zig @@ -0,0 +1,154 @@ +//! This namespace is the default one used by the Zig compiler to emit various +//! kinds of safety panics, due to the logic in `std.builtin.panic`. +//! +//! Since Zig does not have interfaces, this file serves as an example template +//! for users to provide their own alternative panic handling. +//! +//! As an alternative, see `std.debug.FullPanic`. + +const std = @import("../std.zig"); + +/// Prints the message to stderr without a newline and then traps. +/// +/// Explicit calls to `@panic` lower to calling this function. +pub fn call(msg: []const u8, ert: ?*std.builtin.StackTrace, ra: ?usize) noreturn { + @branchHint(.cold); + _ = ert; + _ = ra; + std.debug.lockStdErr(); + const stderr = std.io.getStdErr(); + stderr.writeAll(msg) catch {}; + @trap(); +} + +pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn { + _ = found; + call("sentinel mismatch", null, null); +} + +pub fn unwrapError(ert: ?*std.builtin.StackTrace, err: anyerror) noreturn { + _ = ert; + _ = &err; + call("attempt to unwrap error", null, null); +} + +pub fn outOfBounds(index: usize, len: usize) noreturn { + _ = index; + _ = len; + call("index out of bounds", null, null); +} + +pub fn startGreaterThanEnd(start: usize, end: usize) noreturn { + _ = start; + _ = end; + call("start index is larger than end index", null, null); +} + +pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn { + _ = accessed; + call("access of inactive union field", null, null); +} + +pub fn reachedUnreachable() noreturn { + call("reached unreachable code", null, null); +} + +pub fn unwrapNull() noreturn { + call("attempt to use null value", null, null); +} + +pub fn castToNull() noreturn { + call("cast causes pointer to be null", null, null); +} + +pub fn incorrectAlignment() noreturn { + call("incorrect alignment", null, null); +} + +pub fn invalidErrorCode() noreturn { + call("invalid error code", null, null); +} + +pub fn castTruncatedData() noreturn { + call("integer cast truncated bits", null, null); +} + +pub fn negativeToUnsigned() noreturn { + call("attempt to cast negative value to unsigned integer", null, null); +} + +pub fn integerOverflow() noreturn { + call("integer overflow", null, null); +} + +pub fn shlOverflow() noreturn { + call("left shift overflowed bits", null, null); +} + +pub fn shrOverflow() noreturn { + call("right shift overflowed bits", null, null); +} + +pub fn divideByZero() noreturn { + call("division by zero", null, null); +} + +pub fn exactDivisionRemainder() noreturn { + call("exact division produced remainder", null, null); +} + +pub fn integerPartOutOfBounds() noreturn { + call("integer part of floating point value out of bounds", null, null); +} + +pub fn corruptSwitch() noreturn { + call("switch on corrupt value", null, null); +} + +pub fn shiftRhsTooBig() noreturn { + call("shift amount is greater than the type size", null, null); +} + +pub fn invalidEnumValue() noreturn { + call("invalid enum value", null, null); +} + +pub fn forLenMismatch() noreturn { + call("for loop over objects with non-equal lengths", null, null); +} + +pub fn memcpyLenMismatch() noreturn { + call("@memcpy arguments have non-equal lengths", null, null); +} + +pub fn memcpyAlias() noreturn { + call("@memcpy arguments alias", null, null); +} + +pub fn noreturnReturned() noreturn { + call("'noreturn' function returned", null, null); +} + +/// To be deleted after zig1.wasm update. +pub const messages = struct { + pub const reached_unreachable = "reached unreachable code"; + pub const unwrap_null = "attempt to use null value"; + pub const cast_to_null = "cast causes pointer to be null"; + pub const incorrect_alignment = "incorrect alignment"; + pub const invalid_error_code = "invalid error code"; + pub const cast_truncated_data = "integer cast truncated bits"; + pub const negative_to_unsigned = "attempt to cast negative value to unsigned integer"; + pub const integer_overflow = "integer overflow"; + pub const shl_overflow = "left shift overflowed bits"; + pub const shr_overflow = "right shift overflowed bits"; + pub const divide_by_zero = "division by zero"; + pub const exact_division_remainder = "exact division produced remainder"; + pub const integer_part_out_of_bounds = "integer part of floating point value out of bounds"; + pub const corrupt_switch = "switch on corrupt value"; + pub const shift_rhs_too_big = "shift amount is greater than the type size"; + pub const invalid_enum_value = "invalid enum value"; + pub const for_len_mismatch = "for loop over objects with non-equal lengths"; + pub const memcpy_len_mismatch = "@memcpy arguments have non-equal lengths"; + pub const memcpy_alias = "@memcpy arguments alias"; + pub const noreturn_returned = "'noreturn' function returned"; +}; -- cgit v1.2.3 From 5a6666db5502079d9800ae3d41b790646238078e Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 24 Jan 2025 04:20:55 +0000 Subject: all: update for `panic.unwrapError` and `panic.call` signature changes --- lib/std/builtin.zig | 7 ++- lib/std/debug.zig | 64 +++++++++++----------- lib/std/debug/no_panic.zig | 4 +- lib/std/debug/simple_panic.zig | 56 +++++++++---------- src/Sema.zig | 2 +- src/crash_report.zig | 4 +- .../compile_errors/bad_panic_call_signature.zig | 9 ++- test/incremental/change_panic_handler | 6 +- test/incremental/change_panic_handler_explicit | 6 +- test/src/Cases.zig | 1 - 10 files changed, 79 insertions(+), 80 deletions(-) (limited to 'lib/std/debug/simple_panic.zig') diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index b2e973aea8..f860f7d891 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -1117,7 +1117,12 @@ pub const PanicFn = fn ([]const u8, ?*StackTrace, ?usize) noreturn; pub const panic: type = p: { if (@hasDecl(root, "panic")) { if (@TypeOf(root.panic) != type) { - break :p std.debug.FullPanic(root.panic); // Deprecated; make `panic` a namespace instead. + // 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; } diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 0ff51a7339..7e68f16ee8 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -27,112 +27,112 @@ pub const no_panic = @import("debug/no_panic.zig"); /// A fully-featured panic handler namespace which lowers all panics to calls to `panicFn`. /// Safety panics will use formatted printing to provide a meaningful error message. /// The signature of `panicFn` should match that of `defaultPanic`. -pub fn FullPanic(comptime panicFn: fn ([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn) type { +pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { return struct { pub const call = panicFn; pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn { @branchHint(.cold); - std.debug.panicExtra(null, @returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ + std.debug.panicExtra(@returnAddress(), "sentinel mismatch: expected {any}, found {any}", .{ expected, found, }); } - pub fn unwrapError(ert: ?*std.builtin.StackTrace, err: anyerror) noreturn { + pub fn unwrapError(err: anyerror) noreturn { @branchHint(.cold); - std.debug.panicExtra(ert, @returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)}); + std.debug.panicExtra(@returnAddress(), "attempt to unwrap error: {s}", .{@errorName(err)}); } pub fn outOfBounds(index: usize, len: usize) noreturn { @branchHint(.cold); - std.debug.panicExtra(null, @returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len }); + std.debug.panicExtra(@returnAddress(), "index out of bounds: index {d}, len {d}", .{ index, len }); } pub fn startGreaterThanEnd(start: usize, end: usize) noreturn { @branchHint(.cold); - std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end }); + std.debug.panicExtra(@returnAddress(), "start index {d} is larger than end index {d}", .{ start, end }); } pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn { @branchHint(.cold); - std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ + std.debug.panicExtra(@returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(accessed), @tagName(active), }); } pub fn reachedUnreachable() noreturn { @branchHint(.cold); - call("reached unreachable code", null, @returnAddress()); + call("reached unreachable code", @returnAddress()); } pub fn unwrapNull() noreturn { @branchHint(.cold); - call("attempt to use null value", null, @returnAddress()); + call("attempt to use null value", @returnAddress()); } pub fn castToNull() noreturn { @branchHint(.cold); - call("cast causes pointer to be null", null, @returnAddress()); + call("cast causes pointer to be null", @returnAddress()); } pub fn incorrectAlignment() noreturn { @branchHint(.cold); - call("incorrect alignment", null, @returnAddress()); + call("incorrect alignment", @returnAddress()); } pub fn invalidErrorCode() noreturn { @branchHint(.cold); - call("invalid error code", null, @returnAddress()); + call("invalid error code", @returnAddress()); } pub fn castTruncatedData() noreturn { @branchHint(.cold); - call("integer cast truncated bits", null, @returnAddress()); + call("integer cast truncated bits", @returnAddress()); } pub fn negativeToUnsigned() noreturn { @branchHint(.cold); - call("attempt to cast negative value to unsigned integer", null, @returnAddress()); + call("attempt to cast negative value to unsigned integer", @returnAddress()); } pub fn integerOverflow() noreturn { @branchHint(.cold); - call("integer overflow", null, @returnAddress()); + call("integer overflow", @returnAddress()); } pub fn shlOverflow() noreturn { @branchHint(.cold); - call("left shift overflowed bits", null, @returnAddress()); + call("left shift overflowed bits", @returnAddress()); } pub fn shrOverflow() noreturn { @branchHint(.cold); - call("right shift overflowed bits", null, @returnAddress()); + call("right shift overflowed bits", @returnAddress()); } pub fn divideByZero() noreturn { @branchHint(.cold); - call("division by zero", null, @returnAddress()); + call("division by zero", @returnAddress()); } pub fn exactDivisionRemainder() noreturn { @branchHint(.cold); - call("exact division produced remainder", null, @returnAddress()); + call("exact division produced remainder", @returnAddress()); } pub fn integerPartOutOfBounds() noreturn { @branchHint(.cold); - call("integer part of floating point value out of bounds", null, @returnAddress()); + call("integer part of floating point value out of bounds", @returnAddress()); } pub fn corruptSwitch() noreturn { @branchHint(.cold); - call("switch on corrupt value", null, @returnAddress()); + call("switch on corrupt value", @returnAddress()); } pub fn shiftRhsTooBig() noreturn { @branchHint(.cold); - call("shift amount is greater than the type size", null, @returnAddress()); + call("shift amount is greater than the type size", @returnAddress()); } pub fn invalidEnumValue() noreturn { @branchHint(.cold); - call("invalid enum value", null, @returnAddress()); + call("invalid enum value", @returnAddress()); } pub fn forLenMismatch() noreturn { @branchHint(.cold); - call("for loop over objects with non-equal lengths", null, @returnAddress()); + call("for loop over objects with non-equal lengths", @returnAddress()); } pub fn memcpyLenMismatch() noreturn { @branchHint(.cold); - call("@memcpy arguments have non-equal lengths", null, @returnAddress()); + call("@memcpy arguments have non-equal lengths", @returnAddress()); } pub fn memcpyAlias() noreturn { @branchHint(.cold); - call("@memcpy arguments alias", null, @returnAddress()); + call("@memcpy arguments alias", @returnAddress()); } pub fn noreturnReturned() noreturn { @branchHint(.cold); - call("'noreturn' function returned", null, @returnAddress()); + call("'noreturn' function returned", @returnAddress()); } /// To be deleted after zig1.wasm update. @@ -531,13 +531,12 @@ pub fn assertReadable(slice: []const volatile u8) void { /// Equivalent to `@panic` but with a formatted message. pub fn panic(comptime format: []const u8, args: anytype) noreturn { @branchHint(.cold); - panicExtra(@errorReturnTrace(), @returnAddress(), format, args); + panicExtra(@returnAddress(), format, args); } /// Equivalent to `@panic` but with a formatted message, and with an explicitly -/// provided `@errorReturnTrace` and return address. +/// provided return address. pub fn panicExtra( - trace: ?*std.builtin.StackTrace, ret_addr: ?usize, comptime format: []const u8, args: anytype, @@ -556,7 +555,7 @@ pub fn panicExtra( break :blk &buf; }, }; - std.builtin.panic.call(msg, trace, ret_addr); + std.builtin.panic.call(msg, ret_addr); } /// Non-zero whenever the program triggered a panic. @@ -570,7 +569,6 @@ threadlocal var panic_stage: usize = 0; /// Dumps a stack trace to standard error, then aborts. pub fn defaultPanic( msg: []const u8, - error_return_trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize, ) noreturn { @branchHint(.cold); @@ -657,7 +655,7 @@ pub fn defaultPanic( } stderr.print("{s}\n", .{msg}) catch posix.abort(); - if (error_return_trace) |t| dumpStackTrace(t.*); + if (@errorReturnTrace()) |t| dumpStackTrace(t.*); dumpCurrentStackTrace(first_trace_addr orelse @returnAddress()); } diff --git a/lib/std/debug/no_panic.zig b/lib/std/debug/no_panic.zig index edd61ab974..690453b62a 100644 --- a/lib/std/debug/no_panic.zig +++ b/lib/std/debug/no_panic.zig @@ -5,7 +5,7 @@ const std = @import("../std.zig"); -pub fn call(_: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +pub fn call(_: []const u8, _: ?usize) noreturn { @branchHint(.cold); @trap(); } @@ -15,7 +15,7 @@ pub fn sentinelMismatch(_: anytype, _: anytype) noreturn { @trap(); } -pub fn unwrapError(_: ?*std.builtin.StackTrace, _: anyerror) noreturn { +pub fn unwrapError(_: anyerror) noreturn { @branchHint(.cold); @trap(); } diff --git a/lib/std/debug/simple_panic.zig b/lib/std/debug/simple_panic.zig index 6a6c12aa2d..aeeba5b1d2 100644 --- a/lib/std/debug/simple_panic.zig +++ b/lib/std/debug/simple_panic.zig @@ -11,9 +11,8 @@ const std = @import("../std.zig"); /// Prints the message to stderr without a newline and then traps. /// /// Explicit calls to `@panic` lower to calling this function. -pub fn call(msg: []const u8, ert: ?*std.builtin.StackTrace, ra: ?usize) noreturn { +pub fn call(msg: []const u8, ra: ?usize) noreturn { @branchHint(.cold); - _ = ert; _ = ra; std.debug.lockStdErr(); const stderr = std.io.getStdErr(); @@ -23,110 +22,109 @@ pub fn call(msg: []const u8, ert: ?*std.builtin.StackTrace, ra: ?usize) noreturn pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn { _ = found; - call("sentinel mismatch", null, null); + call("sentinel mismatch", null); } -pub fn unwrapError(ert: ?*std.builtin.StackTrace, err: anyerror) noreturn { - _ = ert; +pub fn unwrapError(err: anyerror) noreturn { _ = &err; - call("attempt to unwrap error", null, null); + call("attempt to unwrap error", null); } pub fn outOfBounds(index: usize, len: usize) noreturn { _ = index; _ = len; - call("index out of bounds", null, null); + call("index out of bounds", null); } pub fn startGreaterThanEnd(start: usize, end: usize) noreturn { _ = start; _ = end; - call("start index is larger than end index", null, null); + call("start index is larger than end index", null); } pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn { _ = accessed; - call("access of inactive union field", null, null); + call("access of inactive union field", null); } pub fn reachedUnreachable() noreturn { - call("reached unreachable code", null, null); + call("reached unreachable code", null); } pub fn unwrapNull() noreturn { - call("attempt to use null value", null, null); + call("attempt to use null value", null); } pub fn castToNull() noreturn { - call("cast causes pointer to be null", null, null); + call("cast causes pointer to be null", null); } pub fn incorrectAlignment() noreturn { - call("incorrect alignment", null, null); + call("incorrect alignment", null); } pub fn invalidErrorCode() noreturn { - call("invalid error code", null, null); + call("invalid error code", null); } pub fn castTruncatedData() noreturn { - call("integer cast truncated bits", null, null); + call("integer cast truncated bits", null); } pub fn negativeToUnsigned() noreturn { - call("attempt to cast negative value to unsigned integer", null, null); + call("attempt to cast negative value to unsigned integer", null); } pub fn integerOverflow() noreturn { - call("integer overflow", null, null); + call("integer overflow", null); } pub fn shlOverflow() noreturn { - call("left shift overflowed bits", null, null); + call("left shift overflowed bits", null); } pub fn shrOverflow() noreturn { - call("right shift overflowed bits", null, null); + call("right shift overflowed bits", null); } pub fn divideByZero() noreturn { - call("division by zero", null, null); + call("division by zero", null); } pub fn exactDivisionRemainder() noreturn { - call("exact division produced remainder", null, null); + call("exact division produced remainder", null); } pub fn integerPartOutOfBounds() noreturn { - call("integer part of floating point value out of bounds", null, null); + call("integer part of floating point value out of bounds", null); } pub fn corruptSwitch() noreturn { - call("switch on corrupt value", null, null); + call("switch on corrupt value", null); } pub fn shiftRhsTooBig() noreturn { - call("shift amount is greater than the type size", null, null); + call("shift amount is greater than the type size", null); } pub fn invalidEnumValue() noreturn { - call("invalid enum value", null, null); + call("invalid enum value", null); } pub fn forLenMismatch() noreturn { - call("for loop over objects with non-equal lengths", null, null); + call("for loop over objects with non-equal lengths", null); } pub fn memcpyLenMismatch() noreturn { - call("@memcpy arguments have non-equal lengths", null, null); + call("@memcpy arguments have non-equal lengths", null); } pub fn memcpyAlias() noreturn { - call("@memcpy arguments alias", null, null); + call("@memcpy arguments alias", null); } pub fn noreturnReturned() noreturn { - call("'noreturn' function returned", null, null); + call("'noreturn' function returned", null); } /// To be deleted after zig1.wasm update. diff --git a/src/Sema.zig b/src/Sema.zig index f2e52c2170..2c2841f27d 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2584,7 +2584,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Zcu.ErrorMsg std.debug.print("compile error during Sema:\n", .{}); var error_bundle = wip_errors.toOwnedBundle("") catch @panic("out of memory"); error_bundle.renderToStdErr(.{ .ttyconf = .no_color }); - crash_report.compilerPanic("unexpected compile error occurred", null, null); + crash_report.compilerPanic("unexpected compile error occurred", null); } if (block) |start_block| { diff --git a/src/crash_report.zig b/src/crash_report.zig index 26096574d3..431381fce4 100644 --- a/src/crash_report.zig +++ b/src/crash_report.zig @@ -158,12 +158,12 @@ fn writeFilePath(file: *Zcu.File, writer: anytype) !void { try writer.writeAll(file.sub_file_path); } -pub fn compilerPanic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, maybe_ret_addr: ?usize) noreturn { +pub fn compilerPanic(msg: []const u8, maybe_ret_addr: ?usize) noreturn { @branchHint(.cold); PanicSwitch.preDispatch(); const ret_addr = maybe_ret_addr orelse @returnAddress(); const stack_ctx: StackContext = .{ .current = .{ .ret_addr = ret_addr } }; - PanicSwitch.dispatch(error_return_trace, stack_ctx, msg); + PanicSwitch.dispatch(@errorReturnTrace(), stack_ctx, msg); } /// Attaches a global SIGSEGV handler diff --git a/test/cases/compile_errors/bad_panic_call_signature.zig b/test/cases/compile_errors/bad_panic_call_signature.zig index 3536397241..b383ccf651 100644 --- a/test/cases/compile_errors/bad_panic_call_signature.zig +++ b/test/cases/compile_errors/bad_panic_call_signature.zig @@ -1,9 +1,8 @@ const simple_panic = std.debug.simple_panic; pub const panic = struct { - pub fn call(msg: []const u8, bad1: usize, bad2: void) noreturn { + pub fn call(msg: []const u8, bad: usize) noreturn { _ = msg; - _ = bad1; - _ = bad2; + _ = bad; @trap(); } pub const sentinelMismatch = simple_panic.sentinelMismatch; @@ -42,5 +41,5 @@ const std = @import("std"); // error // -// :3:9: error: expected type 'fn ([]const u8, ?*builtin.StackTrace, ?usize) noreturn', found 'fn ([]const u8, usize, void) noreturn' -// :3:9: note: parameter 1 'usize' cannot cast into '?*builtin.StackTrace' +// :3:9: error: expected type 'fn ([]const u8, ?usize) noreturn', found 'fn ([]const u8, usize) noreturn' +// :3:9: note: parameter 1 'usize' cannot cast into '?usize' diff --git a/test/incremental/change_panic_handler b/test/incremental/change_panic_handler index 3e0674a4d9..34a1f32dab 100644 --- a/test/incremental/change_panic_handler +++ b/test/incremental/change_panic_handler @@ -10,7 +10,7 @@ pub fn main() !u8 { return 1; } pub const panic = std.debug.FullPanic(myPanic); -fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +fn myPanic(msg: []const u8, _: ?usize) noreturn { std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {}; std.process.exit(0); } @@ -26,7 +26,7 @@ pub fn main() !u8 { return 1; } pub const panic = std.debug.FullPanic(myPanic); -fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +fn myPanic(msg: []const u8, _: ?usize) noreturn { std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {}; std.process.exit(0); } @@ -42,7 +42,7 @@ pub fn main() !u8 { return 1; } pub const panic = std.debug.FullPanic(myPanicNew); -fn myPanicNew(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +fn myPanicNew(msg: []const u8, _: ?usize) noreturn { std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {}; std.process.exit(0); } diff --git a/test/incremental/change_panic_handler_explicit b/test/incremental/change_panic_handler_explicit index 12258d7ce2..5739c46c1b 100644 --- a/test/incremental/change_panic_handler_explicit +++ b/test/incremental/change_panic_handler_explicit @@ -40,7 +40,7 @@ pub const panic = struct { pub const memcpyAlias = no_panic.memcpyAlias; pub const noreturnReturned = no_panic.noreturnReturned; }; -fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +fn myPanic(msg: []const u8, _: ?usize) noreturn { std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {}; std.process.exit(0); } @@ -86,7 +86,7 @@ pub const panic = struct { pub const memcpyAlias = no_panic.memcpyAlias; pub const noreturnReturned = no_panic.noreturnReturned; }; -fn myPanic(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +fn myPanic(msg: []const u8, _: ?usize) noreturn { std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {}; std.process.exit(0); } @@ -133,7 +133,7 @@ pub const panic = struct { pub const memcpyAlias = no_panic.memcpyAlias; pub const noreturnReturned = no_panic.noreturnReturned; }; -fn myPanicNew(msg: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { +fn myPanicNew(msg: []const u8, _: ?usize) noreturn { std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {}; std.process.exit(0); } diff --git a/test/src/Cases.zig b/test/src/Cases.zig index c49576b2f7..b57a476e89 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -358,7 +358,6 @@ pub fn addFromDir(ctx: *Cases, dir: std.fs.Dir, b: *std.Build) void { var current_file: []const u8 = "none"; ctx.addFromDirInner(dir, ¤t_file, b) catch |err| { std.debug.panicExtra( - @errorReturnTrace(), @returnAddress(), "test harness failed to process file '{s}': {s}\n", .{ current_file, @errorName(err) }, -- cgit v1.2.3 From 3232e59ab99154154631eccc177b7159633acd7f Mon Sep 17 00:00:00 2001 From: mlugg Date: Fri, 24 Jan 2025 05:08:18 +0000 Subject: std: remove old declarations now a zig1 update has happened --- lib/std/builtin.zig | 3 --- lib/std/debug.zig | 3 --- lib/std/debug/no_panic.zig | 24 ------------------------ lib/std/debug/simple_panic.zig | 24 ------------------------ 4 files changed, 54 deletions(-) (limited to 'lib/std/debug/simple_panic.zig') diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index f860f7d891..f1e262012e 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -1135,9 +1135,6 @@ pub const panic: type = p: { break :p std.debug.FullPanic(std.debug.defaultPanic); }; -/// To be deleted after zig1.wasm is updated. -pub const Panic = panic; - pub noinline fn returnError() void { @branchHint(.unlikely); @setRuntimeSafety(false); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 7e68f16ee8..8134194380 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -134,9 +134,6 @@ pub fn FullPanic(comptime panicFn: fn ([]const u8, ?usize) noreturn) type { @branchHint(.cold); call("'noreturn' function returned", @returnAddress()); } - - /// To be deleted after zig1.wasm update. - pub const messages = simple_panic.messages; }; } diff --git a/lib/std/debug/no_panic.zig b/lib/std/debug/no_panic.zig index 690453b62a..1ffae2027b 100644 --- a/lib/std/debug/no_panic.zig +++ b/lib/std/debug/no_panic.zig @@ -134,27 +134,3 @@ pub fn noreturnReturned() noreturn { @branchHint(.cold); @trap(); } - -/// To be deleted after zig1.wasm update. -pub const messages = struct { - pub const reached_unreachable = ""; - pub const unwrap_null = ""; - pub const cast_to_null = ""; - pub const incorrect_alignment = ""; - pub const invalid_error_code = ""; - pub const cast_truncated_data = ""; - pub const negative_to_unsigned = ""; - pub const integer_overflow = ""; - pub const shl_overflow = ""; - pub const shr_overflow = ""; - pub const divide_by_zero = ""; - pub const exact_division_remainder = ""; - pub const integer_part_out_of_bounds = ""; - pub const corrupt_switch = ""; - pub const shift_rhs_too_big = ""; - pub const invalid_enum_value = ""; - pub const for_len_mismatch = ""; - pub const memcpy_len_mismatch = ""; - pub const memcpy_alias = ""; - pub const noreturn_returned = ""; -}; diff --git a/lib/std/debug/simple_panic.zig b/lib/std/debug/simple_panic.zig index aeeba5b1d2..f2c8a0574b 100644 --- a/lib/std/debug/simple_panic.zig +++ b/lib/std/debug/simple_panic.zig @@ -126,27 +126,3 @@ pub fn memcpyAlias() noreturn { pub fn noreturnReturned() noreturn { call("'noreturn' function returned", null); } - -/// To be deleted after zig1.wasm update. -pub const messages = struct { - pub const reached_unreachable = "reached unreachable code"; - pub const unwrap_null = "attempt to use null value"; - pub const cast_to_null = "cast causes pointer to be null"; - pub const incorrect_alignment = "incorrect alignment"; - pub const invalid_error_code = "invalid error code"; - pub const cast_truncated_data = "integer cast truncated bits"; - pub const negative_to_unsigned = "attempt to cast negative value to unsigned integer"; - pub const integer_overflow = "integer overflow"; - pub const shl_overflow = "left shift overflowed bits"; - pub const shr_overflow = "right shift overflowed bits"; - pub const divide_by_zero = "division by zero"; - pub const exact_division_remainder = "exact division produced remainder"; - pub const integer_part_out_of_bounds = "integer part of floating point value out of bounds"; - pub const corrupt_switch = "switch on corrupt value"; - pub const shift_rhs_too_big = "shift amount is greater than the type size"; - pub const invalid_enum_value = "invalid enum value"; - pub const for_len_mismatch = "for loop over objects with non-equal lengths"; - pub const memcpy_len_mismatch = "@memcpy arguments have non-equal lengths"; - pub const memcpy_alias = "@memcpy arguments alias"; - pub const noreturn_returned = "'noreturn' function returned"; -}; -- cgit v1.2.3