Closed
Description
Rustc used to be able to replace vec![1, 2, 3].iter().sum::<i32>()
with a constant when optimizing, not at the moment. It simply looks like a Layout method that is not inlinable.
(This is a regression strictly speaking — stable & beta can do this optimization, but not nightly.)
Code to reproduce:
pub fn sum_me() -> i32 {
vec![1, 2, 3].iter().sum::<i32>()
}
Activity
nodakai commentedon Jul 17, 2017
Are there any ways to write automated tests to check for "regressions" like this? Assertions against LLVM bitcode?
kennytm commentedon Jul 17, 2017
@nodakai Yes
codegen
tests can be used for this, e.g. https://github.com/rust-lang/rust/blob/master/src/test/codegen/alloc-optimisation.rs. Assuming this is run against the bitcode after optimization, that is.Mark-Simulacrum commentedon Jul 27, 2017
cc @arielb1 -- seems LLVM related
arielb1 commentedon Jul 27, 2017
Nope. Just
Layout::repeat
(rust/src/liballoc/allocator.rs
Line 210 in 0565653
arielb1 commentedon Jul 27, 2017
cc @alexcrichton
arielb1 commentedon Jul 27, 2017
I didn't confirm that making Layout::repeat as inline fixes this, so please confirm that/add a test before closing.
Layout::repeat
as#[inline]
#43513Rollup merge of rust-lang#43513 - alexcrichton:inline-repeat, r=Burnt…
Rollup merge of rust-lang#43513 - alexcrichton:inline-repeat, r=Burnt…
std: Mark `Layout::repeat` as `#[inline]`