Skip to main content

Module reconstruct_vec_boxes

Module reconstruct_vec_boxes 

Source
Expand description

Reconstruct rustc’s vec![..] lowering based on Box<MaybeUninit<[T; N]>>.

In inline_selected_functions, we inline the special box_assume_init_into_vec_unsafe function. After that, a vec![elems...] expression ends up looking something like:

let mut box = Box::new_uninit::<[T; N]>();
(((*box).1).0).0 = [elems...];
let box = Box::assume_init(box);
..

The split between assignment and assume_init is for performance. The assume_init call is unsafe, so we rewrite it to use Box::write instead, and even Box::new if possible.

let box_uninit = Box::new_uninit::<[T; N]>();
let arr = [elems...];
let box = Box::write::<[T; N]>(box_uninit, arr);
..

See also: https://github.com/rust-lang/rust/pull/148190

Structs§

AssumeInitTail 🔒
PayloadAssign 🔒
Rewrite 🔒
Transform

Functions§

assume_init_fn_ptr 🔒
box_generics 🔒
box_inner 🔒
branched_before 🔒
find_array_assign 🔒
Given src, find the unique statement of the form src = [elems...] where the rvalue is an array aggregate.
find_assume_init_tail 🔒
find_move_in_block 🔒
find_next_drop 🔒
find_next_move_of 🔒
is_new_uninit_call 🔒
unique_target 🔒