-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Сompiler can't remove panic locations if they are not used in panic handler #129330
Comments
Related to #129080 |
@StackOverflowExcept1on can you please elaborate about the longer build times you mention? Can you provide some numbers? thanks |
@apiraino we use the gear-wasm-builder utility to build our smart contracts. It is quite suboptimal because we have about 30-35 demo crates in the workspace, but only 1 crate can be built at a time. We had problem gear-tech/gear#2890, when the test build time increased from 45 sec to 9 minutes. But we'd like to solve the problem described above, rather than using |
@StackOverflowExcept1on thanks for the reply. I'm sorry to ask again, I still fail to see some data about increased build times. Do you have some CI logs? Some public code? A reproducible that shows a before and an after? Thanks again for your patience. |
Does using |
@bjorn3 it works, but it's not what we want. Previously, no build flags were needed, only the |
? It shouldn't affect build times at all. |
@apiraino remapping was added to the gear-wasm-builder utility here: https://github.com/gear-tech/gear/pull/2865/files. I also want to show how to reproduce slow build with
|
It may be the case that RUSTFLAGS was forgotten to be set somewhere, causing unnecessary rebuilds that cause the total build time to be higher. |
@bjorn3 |
Ok, I probably found the reason #129330 (comment). The thing is that #115974 passes rust/library/core/src/panicking.rs Lines 88 to 123 in eef00c8
Here is my fix. I'll put this in the PR and it would be nice to run some benchmarks on this patch. diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs
index e4d0c897b65..af2c83b5460 100644
--- a/library/core/src/panic/panic_info.rs
+++ b/library/core/src/panic/panic_info.rs
@@ -12,7 +12,7 @@
#[stable(feature = "panic_hooks", since = "1.10.0")]
#[derive(Debug)]
pub struct PanicInfo<'a> {
- message: fmt::Arguments<'a>,
+ message: &'a fmt::Arguments<'a>,
location: &'a Location<'a>,
can_unwind: bool,
force_no_backtrace: bool,
@@ -26,13 +26,13 @@ pub struct PanicInfo<'a> {
/// See [`PanicInfo::message`].
#[stable(feature = "panic_info_message", since = "1.81.0")]
pub struct PanicMessage<'a> {
- message: fmt::Arguments<'a>,
+ message: &'a fmt::Arguments<'a>,
}
impl<'a> PanicInfo<'a> {
#[inline]
pub(crate) fn new(
- message: fmt::Arguments<'a>,
+ message: &'a fmt::Arguments<'a>,
location: &'a Location<'a>,
can_unwind: bool,
force_no_backtrace: bool,
@@ -146,7 +146,7 @@ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("panicked at ")?;
self.location.fmt(formatter)?;
formatter.write_str(":\n")?;
- formatter.write_fmt(self.message)?;
+ formatter.write_fmt(*self.message)?;
Ok(())
}
}
@@ -177,7 +177,7 @@ pub const fn as_str(&self) -> Option<&'static str> {
impl Display for PanicMessage<'_> {
#[inline]
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
- formatter.write_fmt(self.message)
+ formatter.write_fmt(*self.message)
}
}
@@ -185,6 +185,6 @@ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
impl fmt::Debug for PanicMessage<'_> {
#[inline]
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
- formatter.write_fmt(self.message)
+ formatter.write_fmt(*self.message)
}
}
diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs
index 7affe638257..87eb9eefb54 100644
--- a/library/core/src/panicking.rs
+++ b/library/core/src/panicking.rs
@@ -64,7 +64,7 @@ pub const fn panic_fmt(fmt: fmt::Arguments<'_>) -> ! {
}
let pi = PanicInfo::new(
- fmt,
+ &fmt,
Location::caller(),
/* can_unwind */ true,
/* force_no_backtrace */ false,
@@ -102,7 +102,7 @@ fn runtime(fmt: fmt::Arguments<'_>, force_no_backtrace: bool) -> ! {
// PanicInfo with the `can_unwind` flag set to false forces an abort.
let pi = PanicInfo::new(
- fmt,
+ &fmt,
Location::caller(),
/* can_unwind */ false,
force_no_backtrace, |
@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged |
Pass `fmt::Arguments` by reference to `PanicInfo` and `PanicMessage` Resolves rust-lang#129330 For some reason after rust-lang#115974 and rust-lang#126732 optimizations applied to panic handler became worse and compiler stopped removing panic locations if they are not used in the panic message. This PR fixes that and maybe we can merge it into beta before rust 1.81 is released. Note: optimization only works with `lto = "fat"`. r? libs-api
@rustbot modify labels: -regression-from-stable-to-beta +regression-from-stable-to-stable |
Code
Code is minimized as much as possible and here is a demo repository: https://github.com/StackOverflowExcept1on/rust-regression
program
- this is smart contract that panics and terminates with an errorproject
- some intermediate directory that is generated by our utilitygit clone https://github.com/StackOverflowExcept1on/rust-regression.git cd rust-regression/project ./check.sh
I expected to see this happen:
/home/user/...
removed from wasmInstead, this happened:
/home/user/...
is not removed from wasmWe want
/home/user/...
to always be removed from smart contracts, otherwise it reveals some information about creator name and also increases cost of uploading to blockchain. We tried using--remap-path-prefix
, but it results in longer build times. On the old version, rustc compiler was so smart that it figured out how to remove all panic locations from the binary file.Maybe related to #115974, but I haven't checked every commit. Although it is worth noting that #115974 is very useful as we can get panic message and remove panic location in stable rust.
Version it worked on
It most recently worked on:
nightly-2024-06-12
Version with regression
Starting from
nightly-2024-06-13
, behavior has changedThe text was updated successfully, but these errors were encountered: