I have opened this issue for discussing how to move #[rustc_box] (introduced by #97293) to something more simpler. My original proposal (reproduced below) was to use builtin # syntax for it, but through the discussion, it was brought up that there used to be a move_val_init intrinsic which would have been a good fit. Initial tests, both with a builtin # ptr_write and move_val_init directly showed promising results: it can deliver the same codegen as #[rustc_box] can, which means that one could switch the vec![] macro from using #[rustc_box] towards Box::new_uninit_slice, then writing into the pointer with move_val_init, then calling asusme_init on it.
Right now, #[rustc_box] desugars to THIR ExprKind::Box, which desugars to code calling exchange_malloc, followed by ShallowInitBox, a construct specifically added to support box syntax, and then followed by something equivalent to move_val_init: a write into the pointer without putting the value into a local first.
A move to using move_val_init directly would simplify the code that desugars #[rustc_box] at the cost of the code in the vec![] macro. To me that seems like a win because it would make the code around creating boxes less special.
Original proposal:
Details
I have opened this issue for discussing how to move #[rustc_box] (introduced by #97293) to builtin# syntax (#110680).
My original proposal was here, to introduce builtin#ptr_write, but I made that proposal while being unaware of ShallowInitBox. So maybe we'd need both builtin#ptr_write and builtin#shallow_init_box.
The options I see:
- Add
builtin#box instead of #[rustc_box], replacing it 1:1.
- Add
builtin#ptr_write and builtin#shallow_init_box, first doing latter and then writing into it doing former. But what would the latter return on a type level? A Box<T>?
- Add
builtin#ptr_write to then do in the Vec macro: first Box::new_uninit_slice, then builtin#ptr_write, then call assume_init on it. This mirrors the proposal by oli-obk but the issue seems to be very poor codegen (new godbolt example based on the one linked in the ShallowInitBox MCP). The issue might just be due to the .write call though.
- Only add
builtin#shallow_init_box. I'm not sure this will work though as the magic seems to hide in the pointer writing.
Maybe one could first add builtin#ptr_write without touching #[rustc_box] and then check if the godbolt example still has that behaviour?
cc @nbdd0121 @drmeepster @clubby789 @oli-obk
Earlier discussion: #110694 (comment)
I have opened this issue for discussing how to move
#[rustc_box](introduced by #97293) to something more simpler. My original proposal (reproduced below) was to usebuiltin #syntax for it, but through the discussion, it was brought up that there used to be amove_val_initintrinsic which would have been a good fit. Initial tests, both with abuiltin # ptr_writeandmove_val_initdirectly showed promising results: it can deliver the same codegen as#[rustc_box]can, which means that one could switch thevec![]macro from using#[rustc_box]towardsBox::new_uninit_slice, then writing into the pointer withmove_val_init, then callingasusme_initon it.Right now,
#[rustc_box]desugars to THIRExprKind::Box, which desugars to code callingexchange_malloc, followed byShallowInitBox, a construct specifically added to supportboxsyntax, and then followed by something equivalent tomove_val_init: a write into the pointer without putting the value into a local first.A move to using
move_val_initdirectly would simplify the code that desugars#[rustc_box]at the cost of the code in thevec![]macro. To me that seems like a win because it would make the code around creating boxes less special.Original proposal:
Details
I have opened this issue for discussing how to move
#[rustc_box](introduced by #97293) tobuiltin#syntax (#110680).My original proposal was here, to introduce
builtin#ptr_write, but I made that proposal while being unaware ofShallowInitBox. So maybe we'd need bothbuiltin#ptr_writeandbuiltin#shallow_init_box.The options I see:
builtin#boxinstead of#[rustc_box], replacing it 1:1.builtin#ptr_writeandbuiltin#shallow_init_box, first doing latter and then writing into it doing former. But what would the latter return on a type level? ABox<T>?builtin#ptr_writeto then do in the Vec macro: firstBox::new_uninit_slice, thenbuiltin#ptr_write, then callassume_initon it. This mirrors the proposal by oli-obk but the issue seems to be very poor codegen (new godbolt example based on the one linked in the ShallowInitBox MCP). The issue might just be due to the.writecall though.builtin#shallow_init_box. I'm not sure this will work though as the magic seems to hide in the pointer writing.Maybe one could first add
builtin#ptr_writewithout touching#[rustc_box]and then check if the godbolt example still has that behaviour?cc @nbdd0121 @drmeepster @clubby789 @oli-obk
Earlier discussion: #110694 (comment)