mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
all: update for panic.unwrapError and panic.call signature changes
This commit is contained in:
parent
dd334d5ee5
commit
5a6666db55
@ -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;
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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| {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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) },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user