Skip to content

Commit e915cf4

Browse files
committed
Pass OpTy by reference not value
1 parent 6c9d7fb commit e915cf4

16 files changed

+193
-193
lines changed

compiler/rustc_mir/src/const_eval/eval_queries.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(super) fn mk_eval_cx<'mir, 'tcx>(
105105
/// type system.
106106
pub(super) fn op_to_const<'tcx>(
107107
ecx: &CompileTimeEvalContext<'_, 'tcx>,
108-
op: OpTy<'tcx>,
108+
op: &OpTy<'tcx>,
109109
) -> ConstValue<'tcx> {
110110
// We do not have value optimizations for everything.
111111
// Only scalars and slices, since they are very common.
@@ -201,7 +201,7 @@ fn turn_into_const_value<'tcx>(
201201
"the `eval_to_const_value_raw` query should not be used for statics, use `eval_to_allocation` instead"
202202
);
203203
// Turn this into a proper constant.
204-
op_to_const(&ecx, mplace.into())
204+
op_to_const(&ecx, &mplace.into())
205205
}
206206

207207
pub fn eval_to_const_value_raw_provider<'tcx>(
@@ -348,7 +348,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
348348
Some(_) => CtfeValidationMode::Regular, // a `static`
349349
None => CtfeValidationMode::Const { inner, allow_static_ptrs: false },
350350
};
351-
ecx.const_validate_operand(mplace.into(), path, &mut ref_tracking, mode)?;
351+
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)?;
352352
inner = true;
353353
}
354354
};

compiler/rustc_mir/src/const_eval/machine.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
3939
// &str
4040
assert!(args.len() == 1);
4141

42-
let msg_place = self.deref_operand(args[0])?;
42+
let msg_place = self.deref_operand(&args[0])?;
4343
let msg = Symbol::intern(self.read_str(msg_place)?);
4444
let span = self.find_closest_untracked_caller_location();
4545
let (file, line, col) = self.location_triple_for_span(span);
@@ -284,8 +284,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
284284
};
285285
match intrinsic_name {
286286
sym::ptr_guaranteed_eq | sym::ptr_guaranteed_ne => {
287-
let a = ecx.read_immediate(args[0])?.to_scalar()?;
288-
let b = ecx.read_immediate(args[1])?.to_scalar()?;
287+
let a = ecx.read_immediate(&args[0])?.to_scalar()?;
288+
let b = ecx.read_immediate(&args[1])?.to_scalar()?;
289289
let cmp = if intrinsic_name == sym::ptr_guaranteed_eq {
290290
ecx.guaranteed_eq(a, b)
291291
} else {
@@ -294,8 +294,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
294294
ecx.write_scalar(Scalar::from_bool(cmp), dest)?;
295295
}
296296
sym::const_allocate => {
297-
let size = ecx.read_scalar(args[0])?.to_machine_usize(ecx)?;
298-
let align = ecx.read_scalar(args[1])?.to_machine_usize(ecx)?;
297+
let size = ecx.read_scalar(&args[0])?.to_machine_usize(ecx)?;
298+
let align = ecx.read_scalar(&args[1])?.to_machine_usize(ecx)?;
299299

300300
let align = match Align::from_bytes(align) {
301301
Ok(a) => a,
@@ -330,7 +330,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
330330
use rustc_middle::mir::AssertKind::*;
331331
// Convert `AssertKind<Operand>` to `AssertKind<Scalar>`.
332332
let eval_to_int =
333-
|op| ecx.read_immediate(ecx.eval_operand(op, None)?).map(|x| x.to_const_int());
333+
|op| ecx.read_immediate(&ecx.eval_operand(op, None)?).map(|x| x.to_const_int());
334334
let err = match msg {
335335
BoundsCheck { ref len, ref index } => {
336336
let len = eval_to_int(len)?;
@@ -358,8 +358,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
358358
fn binary_ptr_op(
359359
_ecx: &InterpCx<'mir, 'tcx, Self>,
360360
_bin_op: mir::BinOp,
361-
_left: ImmTy<'tcx>,
362-
_right: ImmTy<'tcx>,
361+
_left: &ImmTy<'tcx>,
362+
_right: &ImmTy<'tcx>,
363363
) -> InterpResult<'tcx, (Scalar, bool, Ty<'tcx>)> {
364364
Err(ConstEvalErrKind::NeedsRfc("pointer arithmetic or comparison".to_string()).into())
365365
}

compiler/rustc_mir/src/const_eval/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ pub(crate) fn destructure_const<'tcx>(
5555
return mir::DestructuredConst { variant: None, fields: &[] };
5656
}
5757
ty::Adt(def, _) => {
58-
let variant = ecx.read_discriminant(op).unwrap().1;
59-
let down = ecx.operand_downcast(op, variant).unwrap();
58+
let variant = ecx.read_discriminant(&op).unwrap().1;
59+
let down = ecx.operand_downcast(&op, variant).unwrap();
6060
(def.variants[variant].fields.len(), Some(variant), down)
6161
}
6262
ty::Tuple(substs) => (substs.len(), None, op),
6363
_ => bug!("cannot destructure constant {:?}", val),
6464
};
6565

6666
let fields_iter = (0..field_count).map(|i| {
67-
let field_op = ecx.operand_field(down, i).unwrap();
68-
let val = op_to_const(&ecx, field_op);
67+
let field_op = ecx.operand_field(&down, i).unwrap();
68+
let val = op_to_const(&ecx, &field_op);
6969
ty::Const::from_value(tcx, val, field_op.layout.ty)
7070
});
7171
let fields = tcx.arena.alloc_from_iter(fields_iter);
@@ -81,7 +81,7 @@ pub(crate) fn deref_const<'tcx>(
8181
trace!("deref_const: {:?}", val);
8282
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
8383
let op = ecx.const_to_op(val, None).unwrap();
84-
let mplace = ecx.deref_operand(op).unwrap();
84+
let mplace = ecx.deref_operand(&op).unwrap();
8585
if let Scalar::Ptr(ptr) = mplace.ptr {
8686
assert_eq!(
8787
ecx.memory.get_raw(ptr.alloc_id).unwrap().mutability,
@@ -106,5 +106,5 @@ pub(crate) fn deref_const<'tcx>(
106106
},
107107
};
108108

109-
tcx.mk_const(ty::Const { val: ty::ConstKind::Value(op_to_const(&ecx, mplace.into())), ty })
109+
tcx.mk_const(ty::Const { val: ty::ConstKind::Value(op_to_const(&ecx, &mplace.into())), ty })
110110
}

compiler/rustc_mir/src/interpret/cast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::{
1717
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1818
pub fn cast(
1919
&mut self,
20-
src: OpTy<'tcx, M::PointerTag>,
20+
src: &OpTy<'tcx, M::PointerTag>,
2121
cast_kind: CastKind,
2222
cast_ty: Ty<'tcx>,
2323
dest: PlaceTy<'tcx, M::PointerTag>,
@@ -259,7 +259,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
259259

260260
fn unsize_into_ptr(
261261
&mut self,
262-
src: OpTy<'tcx, M::PointerTag>,
262+
src: &OpTy<'tcx, M::PointerTag>,
263263
dest: PlaceTy<'tcx, M::PointerTag>,
264264
// The pointee types
265265
source_ty: Ty<'tcx>,
@@ -300,7 +300,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
300300

301301
fn unsize_into(
302302
&mut self,
303-
src: OpTy<'tcx, M::PointerTag>,
303+
src: &OpTy<'tcx, M::PointerTag>,
304304
cast_ty: TyAndLayout<'tcx>,
305305
dest: PlaceTy<'tcx, M::PointerTag>,
306306
) -> InterpResult<'tcx> {
@@ -340,9 +340,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
340340
let src_field = self.operand_field(src, i)?;
341341
let dst_field = self.place_field(dest, i)?;
342342
if src_field.layout.ty == cast_ty_field.ty {
343-
self.copy_op(src_field, dst_field)?;
343+
self.copy_op(&src_field, dst_field)?;
344344
} else {
345-
self.unsize_into(src_field, cast_ty_field, dst_field)?;
345+
self.unsize_into(&src_field, cast_ty_field, dst_field)?;
346346
}
347347
}
348348
Ok(())

compiler/rustc_mir/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
779779
// Copy the return value to the caller's stack frame.
780780
if let Some(return_place) = frame.return_place {
781781
let op = self.access_local(&frame, mir::RETURN_PLACE, None)?;
782-
self.copy_op_transmute(op, return_place)?;
782+
self.copy_op_transmute(&op, return_place)?;
783783
trace!("{:?}", self.dump_place(*return_place));
784784
} else {
785785
throw_ub!(Unreachable);

compiler/rustc_mir/src/interpret/intern.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
167167

168168
fn visit_aggregate(
169169
&mut self,
170-
mplace: MPlaceTy<'tcx>,
170+
mplace: &MPlaceTy<'tcx>,
171171
fields: impl Iterator<Item = InterpResult<'tcx, Self::V>>,
172172
) -> InterpResult<'tcx> {
173173
// ZSTs cannot contain pointers, so we can skip them.
@@ -191,13 +191,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
191191
self.walk_aggregate(mplace, fields)
192192
}
193193

194-
fn visit_value(&mut self, mplace: MPlaceTy<'tcx>) -> InterpResult<'tcx> {
194+
fn visit_value(&mut self, mplace: &MPlaceTy<'tcx>) -> InterpResult<'tcx> {
195195
// Handle Reference types, as these are the only relocations supported by const eval.
196196
// Raw pointers (and boxes) are handled by the `leftover_relocations` logic.
197197
let tcx = self.ecx.tcx;
198198
let ty = mplace.layout.ty;
199199
if let ty::Ref(_, referenced_ty, ref_mutability) = *ty.kind() {
200-
let value = self.ecx.read_immediate(mplace.into())?;
200+
let value = self.ecx.read_immediate(&(*mplace).into())?;
201201
let mplace = self.ecx.ref_to_mplace(value)?;
202202
assert_eq!(mplace.layout.ty, referenced_ty);
203203
// Handle trait object vtables.
@@ -338,7 +338,7 @@ where
338338
leftover_allocations,
339339
inside_unsafe_cell: false,
340340
}
341-
.visit_value(mplace);
341+
.visit_value(&mplace);
342342
// We deliberately *ignore* interpreter errors here. When there is a problem, the remaining
343343
// references are "leftover"-interned, and later validation will show a proper error
344344
// and point at the right part of the value causing the problem.

0 commit comments

Comments
 (0)