-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simplify the panic handler function to be only one function; remove -fformatted-panics
#17969
Comments
Reporting non-scalar sentinels can not work with the solution you have suggested. |
@andrewrk The incompatibility with non-scalar sentinels is this:
|
How about also adding an argument containing the std.builtin.SourceLocation? pub fn panic(cause: PanicCause, error_return_trace: ?*StackTrace, ret_addr: ?usize, source: ?std.builtin.SourceLocation ) noreturn {
// ...
} This would let a basic panic handler at least point to where the panic happened even if you don't want to get into std.debug.DebugInfo and std.debug.dumpStackTrace. |
That is a large additional cost for common checked arithmetic operations, such as addition, subtraction, and multiplication. Each occurrence of these operations in source would probably cost an additional 64 bytes in program segments; 16 in fn useSrcLoc(src: ?zl.builtin.SourceLocation) void {
if (src) |_| {}
}
pub fn main() void {} Simulating just the call with fn useSrcLoc(src: ?zl.builtin.SourceLocation) void {
if (src) |_| {}
}
pub fn main() void {
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
useSrcLoc(@src());
} In a real program the cost would be higher, as the strings for |
Why wouldn't the function name and file be reused? Surely it could be done smartly so its only whatever bytes for the function name and the file name and then per each instance of a call to panic you only need the u32 for line and u32 for column? |
because it wont always be called from the same function and file |
Here is an example of what I mean. This is roughly how the panic could work at the implementation level. Not embedding the full source struct in every panic location. const std = @import("std");
const SourceLocation = std.builtin.SourceLocation;
fn panicImpl(src: SourceLocation) noreturn {
_ = src;
@panic("");
}
fn panic_zig_file(partial: SourceLocation) noreturn {
panicImpl(.{
.file = "main.zig", // One copy only
.fn_name = partial.fn_name,
.column = partial.column,
.line = partial.line,
});
}
fn panic_main_fn(line: u32, column: u32) noreturn {
panic_zig_file(.{
.file = undefined,
.fn_name = "main", // One per function
.column = column,
.line = line,
});
}
pub fn main() !void {
panic_main_fn(30, 5);
panic_main_fn(31, 5);
panic_main_fn(32, 5);
panic_main_fn(33, 5);
panic_main_fn(34, 5);
panic_main_fn(35, 5);
panic_main_fn(36, 5);
panic_main_fn(37, 5);
panic_main_fn(38, 5);
panic_main_fn(39, 5);
panic_main_fn(40, 5);
panic_main_fn(41, 5);
panic_main_fn(42, 5);
panic_main_fn(43, 5);
panic_main_fn(44, 5);
panic_main_fn(45, 5);
} |
@AssortedFantasy Yes, that is the current behaviour and the reason why the cost implied by the example is not realistic. It only shows one All things considered I think what you want is possible and could be useful to some users. But it can not be the default behaviour because most of Zig users rely on debug sections for runtime source locations, and for those users all of the work required to generate the builtin source locations would be redundant. |
I don't think non-scalar sentinels need to block progress on this issue. They can have a simple panic message with no formatted printing. |
If This means that safe builds would still depend on the std lib when Edit:
If this is to be possible, Either it needs to be overridable as a separate function, or |
|
Given that |
Do we make panic return |
remove non-scalar sentinels from the language |
I started working on this a bit here: https://github.com/wooster0/zig/commits/panic/ It's not finished yet. I have some questions:
|
@wooster0 I have already completed the implementation. I am on Discord if you would like to discuss the details. |
@amp-59 I was just wondering, what is the status on your implementation? Do you have any plans to open a PR with your changes? If you don't have any plans to continue working on this it might be a good idea to let us all know so that someone else can pick up where you left off. |
Note that the panic handler is not a single function at least in the initial implementation of this proposal; see the comments on #21520 for details. |
implements ziglang#17969
There should only be 1 panic handler function and it should be possible to override it by only providing one function. Furthermore, it should be the entry point from the language; there should be no other dependencies on the std lib such as formatted printing.
It should look something like this:
This provides complete flexibility to the application overriding the default handler, while keeping it to a single function to be overridden.
The text was updated successfully, but these errors were encountered: