diff options
| author | bors <bors@rust-lang.org> | 2018-04-16 23:19:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-04-16 23:19:41 +0000 |
| commit | 3809bbf47c8557bd149b3e52ceb47434ca8378d5 (patch) | |
| tree | cb1af67dda415a8c9c9b31ea64100725dafa3221 /src/libcore/panic.rs | |
| parent | 4a3ab8b234cd848b673b64758e4d94bc690f98e0 (diff) | |
| parent | 46d16b66e0b017430eb50b247926ea447c60ef07 (diff) | |
| download | rust-3809bbf47c8557bd149b3e52ceb47434ca8378d5.tar.gz rust-3809bbf47c8557bd149b3e52ceb47434ca8378d5.zip | |
Auto merge of #49488 - alexcrichton:small-wasm-panic, r=sfackler
std: Minimize size of panicking on wasm This commit applies a few code size optimizations for the wasm target to the standard library, namely around panics. We notably know that in most configurations it's impossible for us to print anything in wasm32-unknown-unknown so we can skip larger portions of panicking that are otherwise simply informative. This allows us to get quite a nice size reduction. Finally we can also tweak where the allocation happens for the `Box<Any>` that we panic with. By only allocating once unwinding starts we can reduce the size of a panicking wasm module from 44k to 350 bytes.
Diffstat (limited to 'src/libcore/panic.rs')
| -rw-r--r-- | src/libcore/panic.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index 1720c9d8c60..27ec4aaac75 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -49,11 +49,17 @@ impl<'a> PanicInfo<'a> { and related macros", issue = "0")] #[doc(hidden)] - pub fn internal_constructor(payload: &'a (Any + Send), - message: Option<&'a fmt::Arguments<'a>>, + #[inline] + pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, location: Location<'a>) -> Self { - PanicInfo { payload, location, message } + PanicInfo { payload: &(), location, message } + } + + #[doc(hidden)] + #[inline] + pub fn set_payload(&mut self, info: &'a (Any + Send)) { + self.payload = info; } /// Returns the payload associated with the panic. @@ -251,3 +257,13 @@ impl<'a> fmt::Display for Location<'a> { write!(formatter, "{}:{}:{}", self.file, self.line, self.col) } } + +/// An internal trait used by libstd to pass data from libstd to `panic_unwind` +/// and other panic runtimes. Not intended to be stabilized any time soon, do +/// not use. +#[unstable(feature = "std_internals", issue = "0")] +#[doc(hidden)] +pub unsafe trait BoxMeUp { + fn box_me_up(&mut self) -> *mut (Any + Send); + fn get(&mut self) -> &(Any + Send); +} |
