forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#111634 - marc0246:arc-new-uninit-bloat, r=thomcc
Fix duplicate `arcinner_layout_for_value_layout` calls when using the uninit `Arc` constructors What this fixes is the duplicate calls to `arcinner_layout_for_value_layout` seen here: https://godbolt.org/z/jr5Gxozhj The issue was discovered alongside rust-lang#111603 but is otherwise unrelated to the duplicate `alloca`s, which remain unsolved. Everything I tried to solve said main issue has failed. As for the duplicate layout calculations, I also tried slapping `#[inline]` and `#[inline(always)]` on everything in sight but the only thing that worked in the end is to dedup the calls by hand.
- Loading branch information
Showing
2 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
#![feature(get_mut_unchecked, new_uninit)] | ||
|
||
use std::sync::Arc; | ||
|
||
// CHECK-LABEL: @new_uninit | ||
#[no_mangle] | ||
pub fn new_uninit(x: u64) -> Arc<[u64; 1000]> { | ||
// CHECK: call alloc::sync::arcinner_layout_for_value_layout | ||
// CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout | ||
let mut arc = Arc::new_uninit(); | ||
unsafe { Arc::get_mut_unchecked(&mut arc) }.write([x; 1000]); | ||
unsafe { arc.assume_init() } | ||
} | ||
|
||
// CHECK-LABEL: @new_uninit_slice | ||
#[no_mangle] | ||
pub fn new_uninit_slice(x: u64) -> Arc<[u64]> { | ||
// CHECK: call alloc::sync::arcinner_layout_for_value_layout | ||
// CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout | ||
let mut arc = Arc::new_uninit_slice(1000); | ||
for elem in unsafe { Arc::get_mut_unchecked(&mut arc) } { | ||
elem.write(x); | ||
} | ||
unsafe { arc.assume_init() } | ||
} |