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.
This commit is contained in:
commit
3809bbf47c
22 changed files with 296 additions and 72 deletions
17
src/test/run-make/wasm-panic-small/Makefile
Normal file
17
src/test/run-make/wasm-panic-small/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
-include ../../run-make-fulldeps/tools.mk
|
||||
|
||||
ifeq ($(TARGET),wasm32-unknown-unknown)
|
||||
all:
|
||||
$(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown --cfg a
|
||||
wc -c < $(TMPDIR)/foo.wasm
|
||||
[ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "1024" ]
|
||||
$(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown --cfg b
|
||||
wc -c < $(TMPDIR)/foo.wasm
|
||||
[ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "5120" ]
|
||||
$(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown --cfg c
|
||||
wc -c < $(TMPDIR)/foo.wasm
|
||||
[ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "5120" ]
|
||||
else
|
||||
all:
|
||||
endif
|
||||
|
||||
29
src/test/run-make/wasm-panic-small/foo.rs
Normal file
29
src/test/run-make/wasm-panic-small/foo.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![crate_type = "cdylib"]
|
||||
|
||||
#[no_mangle]
|
||||
#[cfg(a)]
|
||||
pub fn foo() {
|
||||
panic!("test");
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[cfg(b)]
|
||||
pub fn foo() {
|
||||
panic!("{}", 1);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
#[cfg(c)]
|
||||
pub fn foo() {
|
||||
panic!("{}", "a");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue