about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-15 06:33:48 +0000
committerbors <bors@rust-lang.org>2018-04-15 06:33:48 +0000
commit56109dbf709c2e4f6ca27d79feba2155b7f66e03 (patch)
tree1b79b0ea110c5fa582712185642a32bc6279d3c9 /src/rustllvm/RustWrapper.cpp
parentbc001fa07f1e44f88b59c74290a2dd916824d33c (diff)
parent68e555b7d03eefe4a226e6a0ae3fd13a118cb27e (diff)
downloadrust-56109dbf709c2e4f6ca27d79feba2155b7f66e03.tar.gz
rust-56109dbf709c2e4f6ca27d79feba2155b7f66e03.zip
Auto merge of #49884 - alexcrichton:less-unwrap, r=Mark-Simulacrum
core: Remove panics from some `Layout` methods

`Layout` is often used at the core of allocation APIs and is as a result pretty
sensitive to codegen in various circumstances. I was profiling `-C opt-level=z`
with a wasm project recently and noticed that the `unwrap()` wasn't removed
inside of `Layout`, causing the program to be much larger than it otherwise
would be. If inlining were more aggressive LLVM would have figured out that the
panic could be eliminated, but in general the methods here can't panic in the
first place!

As a result this commit makes the following tweaks:

* Removes `unwrap()` and replaces it with `unsafe` in `Layout::new` and
  `Layout::for_value`. For posterity though a debug assertion was left behind.
* Removes an `unwrap()` in favor of `?` in the `repeat` method. The comment
  indicating that the function call couldn't panic wasn't quite right in that if
  `alloc_size` becomes too large and if `align` is high enough it could indeed
  cause a panic.

This'll hopefully mean that panics never get introduced into code in the first
place, ensuring that `opt-level=z` is closer to `opt-level=s` in this regard.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions