Skip to content

Commit 9283d59

Browse files
committed
Auto merge of #151389 - scottmcm:vec-repeat, r=joboet
Use `repeat_packed` when calculating layouts in `RawVec` Seeing whether this helps the icounts seen in #148769 (comment)
2 parents 1655912 + c3f309e commit 9283d59

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

library/alloc/src/raw_vec/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,13 @@ const fn handle_error(e: TryReserveError) -> ! {
865865
#[inline]
866866
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
867867
const fn layout_array(cap: usize, elem_layout: Layout) -> Result<Layout, TryReserveError> {
868+
// This is only used with `elem_layout`s which are those of real rust types,
869+
// which lets us use the much-simpler `repeat_packed`.
870+
debug_assert!(elem_layout.size() == elem_layout.pad_to_align().size());
871+
868872
// FIXME(const-hack) return to using `map` and `map_err` once `const_closures` is implemented
869-
match elem_layout.repeat(cap) {
870-
Ok((layout, _pad)) => Ok(layout),
873+
match elem_layout.repeat_packed(cap) {
874+
Ok(layout) => Ok(layout),
871875
Err(_) => Err(CapacityOverflow.into()),
872876
}
873877
}

tests/codegen-llvm/iter-repeat-n-trivial-drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn iter_repeat_n_next(it: &mut std::iter::RepeatN<NotCopy>) -> Option<NotCop
4747
#[no_mangle]
4848
// CHECK-LABEL: @vec_extend_via_iter_repeat_n
4949
pub fn vec_extend_via_iter_repeat_n() -> Vec<u8> {
50-
// CHECK: %[[ADDR:.+]] = tail call {{(noalias )?}}noundef dereferenceable_or_null(1234) ptr @{{.*}}__rust_alloc(i64 noundef {{(range\(i64 1, 0\) )?}}1234, i64 noundef {{(range\(i64 1, -9223372036854775807\) )?}}1)
50+
// CHECK: %[[ADDR:.+]] = tail call {{(noalias )?}}noundef dereferenceable_or_null(1234) ptr @{{.*}}__rust_alloc(i64 noundef {{(range\(i64 0, -9223372036854775808\) )?}}1234, i64 noundef {{(range\(i64 1, -9223372036854775807\) )?}}1)
5151
// CHECK: tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1234) %[[ADDR]], i8 42, i64 1234,
5252

5353
let n = 1234_usize;

0 commit comments

Comments
 (0)