Skip to content

Commit ee83d9a

Browse files
committed
Auto merge of #116707 - cjgillot:slice-id, r=oli-obk,RalfJung
Create an `AllocId` for `ConstValue::Slice`. This PR modifies `ConstValue::Slice` to use an `AllocId` instead of directly manipulating the allocation. This was originally proposed by rust-lang/rust#115764 but was a perf regression. Almost 2 years later, enough code has changed to make this a perf improvement: rust-lang/rust#116707 (comment)
2 parents cac43c1 + 441ef93 commit ee83d9a

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/constant.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
7474
pub(crate) fn eval_mir_constant<'tcx>(
7575
fx: &FunctionCx<'_, '_, 'tcx>,
7676
constant: &ConstOperand<'tcx>,
77-
) -> (ConstValue<'tcx>, Ty<'tcx>) {
77+
) -> (ConstValue, Ty<'tcx>) {
7878
let cv = fx.monomorphize(constant.const_);
7979
// This cannot fail because we checked all required_consts in advance.
8080
let val = cv
@@ -93,7 +93,7 @@ pub(crate) fn codegen_constant_operand<'tcx>(
9393

9494
pub(crate) fn codegen_const_value<'tcx>(
9595
fx: &mut FunctionCx<'_, '_, 'tcx>,
96-
const_val: ConstValue<'tcx>,
96+
const_val: ConstValue,
9797
ty: Ty<'tcx>,
9898
) -> CValue<'tcx> {
9999
let layout = fx.layout_of(ty);
@@ -210,8 +210,7 @@ pub(crate) fn codegen_const_value<'tcx>(
210210
.offset_i64(fx, i64::try_from(offset.bytes()).unwrap()),
211211
layout,
212212
),
213-
ConstValue::Slice { data, meta } => {
214-
let alloc_id = fx.tcx.reserve_and_set_memory_alloc(data);
213+
ConstValue::Slice { alloc_id, meta } => {
215214
let ptr = pointer_for_allocation(fx, alloc_id).get_addr(fx);
216215
let len = fx.bcx.ins().iconst(fx.pointer_type, meta as i64);
217216
CValue::by_val_pair(ptr, len, layout)

0 commit comments

Comments
 (0)