-
Notifications
You must be signed in to change notification settings - Fork 1.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
RFC: Introduce panic_thin, a fmtless alternative to panic_fmt #2305
Conversation
Has there been discussion or effort made recently to see if we can reduce the size of |
I think if we are comfortable constraining format strings to strings and integers we probably could make a quite tiny A good question is what is the variety in all of Rusts (libcore + libstd + friends) panics? It might be possible that internally we could not use anything but primitive formats and thus unless a user explicitly uses an advanced format they get a very tiny This route probably is the best for everyone, however it depends on how much existing Rust code would have to be changed and might require a bit more work. |
text/0000-thin-panic.md
Outdated
|
||
## Getting static strings from existing format strings | ||
|
||
It is not reasonable to have multiple panic messages for every panic usa, thus it is important that there is backwards compatibility with old panics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/usa/use/ ?
In RFC 2070 |
@SimonSapin LLVM should be able to remove the code. If we had MIR-only rlibs, the code wouldn't even be generated in the first place. |
@Zoxc what do you mean by stripping all panic information? Like having I'm a bit concerned with relying on optimizations to fix this issue as there are always chances for slight regressions when changes are made to compiler internals. It just seems dangerously close to breaking at any moment. In fact, the changes in LTO is what caused this to be an issue for me in my project in the first place. |
I want panics to be able to reduce to a single
I think this could be solved by adding a test to the compiler. |
Does the standard library need to be recompiled to switch from |
Thanks for the RFC @gamozolabs! I'd personally be sort of hesitant to add more panic infastructure before we understand what we already have, though. For example RFC 2070 I think would provide a way where, if unused, panic information would be stripped out during LTO. It doesn't contain the feature where you can extract a Perhaps we should hold off on RFCs like this until 2070 is implemented? |
Sadly, the 2070 by itself does not provide means to strip out unnecessary panic information, but a fairly small extension to it would allow that. |
I commented at rust-lang/rust#44489 (comment) but should have done it here as well. The stated goal of this RFC is to avoid the code size cost of using #[panic_implementation]
fn panic(info: &core::panic::PanicInfo) -> ! {
if let Some(s) = info.payload().downcast_ref::<&'static str>() {
print(s)
}
abort_or_something()
}
fn print(s: &str) {…}
fn abort_or_something() -> {…} Creating a (At the moment I think that this downcast to @gamozolabs How does this sound? (Note that there is a push to stabilize rust-lang/rust#44489 soon~ish.) |
This RFC exactly as proposed is somewhat in contradiction with #2070 / rust-lang/rust#44489 which is already implemented and about to be stabilized. However I believe that the goal of not including the So I’d like to propose to close this RFC as postponed: @rfcbot fcp postpone When rust-lang/rust#44489 is stabilized we can see how far full LTO gets us, and later consider supporting different signatures (including possibly a panic handler that takes no argument at all). |
Team member @SimonSapin has proposed to postpone this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I'm fine with this, the current panic implementation has been great for my requirements. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to postpone, as per the review above, is now complete. By the power vested in me by Rust, I hereby postpone this RFC. |
This RFC is meant to make it easier to create applications that do not use
fmt
allowing for smaller program sizes while still getting some level of panic information. This RFC proposes a solution that does not require changes to current Rust programming styles, nor require writing of new panic messages.This was inspired by a lot of my work on a bootloader which is restricted to 32 KiB. Any time
core::fmt
gets introduced to the codebase the code almost always goes over the size limit. To get around this I have had to remove uses ofcore::fmt
by not using themsg
argument topanic_fmt
and building my bootloader with fat LTO.Recently there has been a lot of talk on this such as: rust-lang/rust#47409, rust-lang/rust#47526, rustwasm/team#19
Rendered
-B