core: Remove panics from some Layout methods#49884
Merged
bors merged 1 commit intorust-lang:masterfrom Apr 15, 2018
Merged
Conversation
Contributor
|
(rust_highfive has picked a reviewer for you, use r? to override) |
Mark-Simulacrum
approved these changes
Apr 11, 2018
src/libcore/heap.rs
Outdated
Member
There was a problem hiding this comment.
Could we add a comment here as to why we have this unsafe code? Otherwise I worry someone will remove it down the line since it feels unnecessary.
Either way, I feel like it's unfortunate we have to do this :/
2790b64 to
ec3bccb
Compare
Member
Author
|
@bors: r=Mark-Simulacrum |
Collaborator
|
📌 Commit ec3bccb has been approved by |
kennytm
added a commit
to kennytm/rust
that referenced
this pull request
Apr 13, 2018
…mulacrum 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.
Collaborator
|
☔ The latest upstream changes (presumably #49669) made this pull request unmergeable. Please resolve the merge conflicts. |
`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.
ec3bccb to
68e555b
Compare
Member
Author
|
@bors: r=Mark-Simulacrum |
Collaborator
|
📌 Commit 68e555b has been approved by |
Collaborator
bors
added a commit
that referenced
this pull request
Apr 15, 2018
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.
Collaborator
|
☀️ Test successful - status-appveyor, status-travis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Layoutis often used at the core of allocation APIs and is as a result prettysensitive to codegen in various circumstances. I was profiling
-C opt-level=zwith a wasm project recently and noticed that the
unwrap()wasn't removedinside of
Layout, causing the program to be much larger than it otherwisewould 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:
unwrap()and replaces it withunsafeinLayout::newandLayout::for_value. For posterity though a debug assertion was left behind.unwrap()in favor of?in therepeatmethod. The commentindicating that the function call couldn't panic wasn't quite right in that if
alloc_sizebecomes too large and ifalignis high enough it could indeedcause a panic.
This'll hopefully mean that panics never get introduced into code in the first
place, ensuring that
opt-level=zis closer toopt-level=sin this regard.