-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for RFC 2070: stable mechanism to specify the behavior of panic! in no-std applications #44489
Comments
As someone with a working unwinding implementation in a no_std environment (not with a Rust personality function though), I can answer this if someone summarizes the feature for me. I kind of lost track and I don't have time to get into every minor detail at the moment. |
Sorry to bring this off topic so soon, but could you explain this? I was under the impression that unless you wanted to implement unwinding in an ad-hoc way (e.g. doing unwinding during panic by explicitly calling some function) you had to implement the |
I use unwinding in a language runtime. The language has exceptions (and so unwinding), however Rust frames are never unwound, and so there's no need for the personality function. |
I would like the |
We should also support no location information at all, and abstract location information (for example just an identifying number which can be used to find the relevant information in some external source). |
I did not notice that |
I'm really not a fan of using the same API for payloads and messages. I'd rather |
I kind of prefer a One problem with mixing the payload and the message is that we can't strip panic messages from the binary without changing the meaning of programs relying on payloads. |
#47687 does part of the implementation. I think after that what’s needed is:
Note however that CC @japaric |
@Zoxc We can still propose changing RFC 2070, but a
|
@SimonSapin We could just pass a |
RFC 2070 part 1: PanicInfo and Location API changes This implements part of https://rust-lang.github.io/rfcs/2070-panic-implementation.html Tracking issue: #44489 * Move `std::panic::PanicInfo` and `std::panic::Location` to a new `core::panic` module. The two types and the `std` module were already `#[stable]` and stay that way, the new `core` module is `#[unstable]`. * Add a new `PanicInfo::message(&self) -> Option<&fmt::Arguments>` method, which is `#[unstable]`. * Implement `Display` for `PanicInfo` and `Location`
From what I can tell, the RFC still does not address removal of unnecessary panic information directly, however it is an extremely easy thing to do that does not require much extra design past what was already accepted. Consider for example this scenario: #[panic_implementation]
fn my_panic_impl(pi: &PanicInfo) -> ! {
abort()
} This is a case, where it is entirely within the power of compiler to not keep any strings, line numbers, etc. pertaining to panic locations. However as soon as the panic implementation uses any information: #[panic_implementation]
fn my_panic_impl(pi: &PanicInfo) -> ! {
abort_with_line(pi.location(),map(|l| l.line()));
} the compiler is forced to keep all the panic information, despite the fact that only the line numbers are of any interest for that particular implementation of panicking. I want to propose a following change (benefits of which are laid out at the end of this comment): struct AnyConcreteTypeMayGoHere { line: Option<u64> }
impl ::core::panic::PanicInfoCtr for AnyConcreteTypeMayGoHere {
const fn new_v1(message: Option<&fmt::Arguments>, location: Option<Location>, ...etc) -> Self {
AnyConcreteTypeMayGoHere { line: location.map(|l| l.line()) }
}
}
#[panic_implementation]
fn my_panic_impl(pi: &AnyConcreteTypeMayGoHere) -> ! { abort_with_line(pi.line) } and at the location of panic rust would generate code similar to this (with static PANIC_INFO: _ = <_ as ::core::panic::PanicInfoCtr>::new_v1(args, loc, ...);
my_panic_impl(&PANIC_INFO); Benefits of this approach are:
¹: there were a few issues about this, but I can’t find them anymore. |
Status update: I realised above cannot work without being very unwieldy. Namely, the proposal above would require the |
There is an issue that IMHO, a stable mechanism for panic! in no-std applications should take into account: for at least two reasons, you can only set the panic handler in leaf crates. One of them is issue #48661, where the linker simply removes the panic handler if it's in its own crate. The second of them is that the
and there is no way for such a crate to be built differently for |
This may be a problem short term but custom test framework will become available this year and with those it will be possible to write test runners than don't rely on unwinding (e.g. unit tests return Err to indicate failure) which will make it possible to test targets (e.g. thumbv7m-none-eabi) that don't have a panic implementation that unwinds.
This is probably a bad idea but would it be possible to store all panic!s in MIR format and defer the actual generation of the static variable (and the llvm-ir) until the user defined PanicInfo struct is known? |
Yeah, without overthinking the idea too much, I think that would be possible, however it has a hard prerequisite on MIR-only (r)libs. |
@japaric: there are other reasons than unwinding to want to use std for tests on otherwise no_std crates. If your panic function is in a crate that contains nothing else, maybe a |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
…imulacrum stabilize #[panic_handler] closes rust-lang#44489 ### Update(2018-09-07) This was proposed for stabilization in rust-lang#44489 (comment) and its FCP with disposition to merge / accept is nearly over. The summary of what's being stabilized can be found in rust-lang#44489 (comment) Documentation PRs: - Reference. rust-lang/reference#362 - Nomicon. rust-lang/nomicon#75 --- `#[panic_implementation]` was implemented recently in rust-lang#50338. `#[panic_implementation]` is basically the old `panic_fmt` language item but in a less error prone (\*) shape. There are still some issues and questions to sort out around this feature (cf. rust-lang#44489) but this PR is meant to start a discussion about those issues / questions with the language team. (\*) `panic_fmt` was not type checked; changes in its function signature caused serious, silent binary size regressions like the one observed in rust-lang#43054 Some unresolved questions from rust-lang#44489: > Should the Display of PanicInfo format the panic information as "panicked at 'reason', > src/main.rs:27:4", as "'reason', src/main.rs:27:4", or simply as "reason". The current implementation formats `PanicInfo` as the first alternative, which is how panic messages are formatted by the `std` panic handler. The `Display` implementation is more than a convenience: `PanicInfo.message` is unstable so it's not possible to replicate the `Display` implementation on stable. > Is this design compatible, or can it be extended to work, with unwinding implementations for > no-std environments? I believe @whitequark made more progress with unwinding in no-std since their last comment in rust-lang#44489. Perhaps they can give us an update? --- Another unresolved question is where this feature should be documented. The feature currently doesn't have any documentation. cc @rust-lang/lang cc @jackpot51 @alevy @phil-opp
stabilize #[panic_handler] closes #44489 ### Update(2018-09-07) This was proposed for stabilization in #44489 (comment) and its FCP with disposition to merge / accept is nearly over. The summary of what's being stabilized can be found in #44489 (comment) Documentation PRs: - Reference. rust-lang/reference#362 - Nomicon. rust-lang/nomicon#75 --- `#[panic_implementation]` was implemented recently in #50338. `#[panic_implementation]` is basically the old `panic_fmt` language item but in a less error prone (\*) shape. There are still some issues and questions to sort out around this feature (cf. #44489) but this PR is meant to start a discussion about those issues / questions with the language team. (\*) `panic_fmt` was not type checked; changes in its function signature caused serious, silent binary size regressions like the one observed in #43054 Some unresolved questions from #44489: > Should the Display of PanicInfo format the panic information as "panicked at 'reason', > src/main.rs:27:4", as "'reason', src/main.rs:27:4", or simply as "reason". The current implementation formats `PanicInfo` as the first alternative, which is how panic messages are formatted by the `std` panic handler. The `Display` implementation is more than a convenience: `PanicInfo.message` is unstable so it's not possible to replicate the `Display` implementation on stable. > Is this design compatible, or can it be extended to work, with unwinding implementations for > no-std environments? I believe @whitequark made more progress with unwinding in no-std since their last comment in #44489. Perhaps they can give us an update? --- Another unresolved question is where this feature should be documented. The feature currently doesn't have any documentation. cc @rust-lang/lang cc @jackpot51 @alevy @phil-opp
panic_implemenation was renamed to panic_handler: rust-lang/rust#44489 (comment) panic_handler was stablized: rust-lang/rust#51366 `cargo check` now succeeds without warnings
panic_implemenation was renamed to panic_handler: rust-lang/rust#44489 (comment) panic_handler was stablized: rust-lang/rust#51366 `cargo check` now succeeds without warnings
@Centril: Can you please update the OP with the current status (stabilization etc.)? |
@sanmai-NL I will defer this to @japaric since they are most up to date as to the status. |
@Centril: I saw at the end of this thread a very clear status indication, so I considered it a management thing requiring no involvement in the effort. |
@sanmai-NL ok, I ticked some boxes which seemed fulfilled; but I don't have the time to do a more in-depth review right now. :) |
panic_implemenation was renamed to panic_handler: rust-lang/rust#44489 (comment) panic_handler was stablized: rust-lang/rust#51366 `cargo check` now succeeds without warnings
panic_implemenation was renamed to panic_handler: rust-lang/rust#44489 (comment) panic_handler was stablized: rust-lang/rust#51366 `cargo check` now succeeds without warnings
Hey, I got to this issue because it is linked to the Is there another recommended way to get the panic information? I was also thinking about replacing the panic_hook with catch_unwind but we might get into problems if the external crates that we are using are implementing panic with abort. |
Lol thanks! |
It's not even the bot (@bors) closing the issue, this is a GitHub feature. @curiousleo I think the problem there is the unstable feature Also a bit surprised that @andreeaflorescu didn't get a reply in almost a year... |
rust-lang#44489 was closed when the `#[panic_handler]` attribute was stabilized.
Update(2018-08-28)
This is a tracking issue for the RFC "stable mechanism to specify the behavior of panic! in no-std applications " (rust-lang/rfcs#2070).
Steps:
rust_begin_panic
Unresolved questions:
fmt::Display
Should the
Display
ofPanicInfo
format the panic information as"panicked at 'reason', src/main.rs:27:4"
, as"'reason', src/main.rs:27:4"
, or simply as"reason"
.Unwinding in no-std
Is this design compatible, or can it be extended to work, with unwinding
implementations for no-std environments?
Issues to solve before stabilization
rust_begin_unwind
not emitted when crate-type = binrust_begin_unwind
not emitted when crate-type = bin #51671The text was updated successfully, but these errors were encountered: