diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-03-29 14:59:13 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2018-04-13 07:03:00 -0700 |
| commit | c3a5d6b130e27d7d7587f56581247d5b08c38594 (patch) | |
| tree | d9ebfea2bd391be55bb43eb732114c0d46286a8d /src/libstd/sys/wasm | |
| parent | 99d4886ead646da864cff7963f540a44acd4af05 (diff) | |
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/libstd/sys/wasm')
| -rw-r--r-- | src/libstd/sys/wasm/rwlock.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/wasm/stdio.rs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/libstd/sys/wasm/rwlock.rs b/src/libstd/sys/wasm/rwlock.rs index 8b06f541674..6516010af47 100644 --- a/src/libstd/sys/wasm/rwlock.rs +++ b/src/libstd/sys/wasm/rwlock.rs @@ -30,7 +30,7 @@ impl RWLock { if *mode >= 0 { *mode += 1; } else { - panic!("rwlock locked for writing"); + rtabort!("rwlock locked for writing"); } } @@ -51,7 +51,7 @@ impl RWLock { if *mode == 0 { *mode = -1; } else { - panic!("rwlock locked for reading") + rtabort!("rwlock locked for reading") } } diff --git a/src/libstd/sys/wasm/stdio.rs b/src/libstd/sys/wasm/stdio.rs index beb19c0ed2c..023f29576a2 100644 --- a/src/libstd/sys/wasm/stdio.rs +++ b/src/libstd/sys/wasm/stdio.rs @@ -69,3 +69,7 @@ pub const STDIN_BUF_SIZE: usize = 0; pub fn is_ebadf(_err: &io::Error) -> bool { true } + +pub fn stderr_prints_nothing() -> bool { + !cfg!(feature = "wasm_syscall") +} |
