Skip to content

Commit fe0c46d

Browse files
committed
Pass PlaceTy by reference not value
1 parent e915cf4 commit fe0c46d

File tree

13 files changed

+91
-87
lines changed

13 files changed

+91
-87
lines changed

compiler/rustc_mir/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
5656
ecx.push_stack_frame(
5757
cid.instance,
5858
body,
59-
Some(ret.into()),
59+
Some(&ret.into()),
6060
StackPopCleanup::None { cleanup: false },
6161
)?;
6262

compiler/rustc_mir/src/const_eval/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
222222
instance: ty::Instance<'tcx>,
223223
_abi: Abi,
224224
args: &[OpTy<'tcx>],
225-
_ret: Option<(PlaceTy<'tcx>, mir::BasicBlock)>,
225+
_ret: Option<(&PlaceTy<'tcx>, mir::BasicBlock)>,
226226
_unwind: Option<mir::BasicBlock>, // unwinding is not supported in consts
227227
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
228228
debug!("find_mir_or_eval_fn: {:?}", instance);
@@ -262,7 +262,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
262262
ecx: &mut InterpCx<'mir, 'tcx, Self>,
263263
instance: ty::Instance<'tcx>,
264264
args: &[OpTy<'tcx>],
265-
ret: Option<(PlaceTy<'tcx>, mir::BasicBlock)>,
265+
ret: Option<(&PlaceTy<'tcx>, mir::BasicBlock)>,
266266
_unwind: Option<mir::BasicBlock>,
267267
) -> InterpResult<'tcx> {
268268
// Shared intrinsics.
@@ -366,7 +366,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
366366

367367
fn box_alloc(
368368
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
369-
_dest: PlaceTy<'tcx>,
369+
_dest: &PlaceTy<'tcx>,
370370
) -> InterpResult<'tcx> {
371371
Err(ConstEvalErrKind::NeedsRfc("heap allocations via `box` keyword".to_string()).into())
372372
}

compiler/rustc_mir/src/interpret/cast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2020
src: &OpTy<'tcx, M::PointerTag>,
2121
cast_kind: CastKind,
2222
cast_ty: Ty<'tcx>,
23-
dest: PlaceTy<'tcx, M::PointerTag>,
23+
dest: &PlaceTy<'tcx, M::PointerTag>,
2424
) -> InterpResult<'tcx> {
2525
use rustc_middle::mir::CastKind::*;
2626
// FIXME: In which cases should we trigger UB when the source is uninit?
@@ -260,7 +260,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
260260
fn unsize_into_ptr(
261261
&mut self,
262262
src: &OpTy<'tcx, M::PointerTag>,
263-
dest: PlaceTy<'tcx, M::PointerTag>,
263+
dest: &PlaceTy<'tcx, M::PointerTag>,
264264
// The pointee types
265265
source_ty: Ty<'tcx>,
266266
cast_ty: Ty<'tcx>,
@@ -302,7 +302,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
302302
&mut self,
303303
src: &OpTy<'tcx, M::PointerTag>,
304304
cast_ty: TyAndLayout<'tcx>,
305-
dest: PlaceTy<'tcx, M::PointerTag>,
305+
dest: &PlaceTy<'tcx, M::PointerTag>,
306306
) -> InterpResult<'tcx> {
307307
trace!("Unsizing {:?} of type {} into {:?}", *src, src.layout.ty, cast_ty.ty);
308308
match (&src.layout.ty.kind(), &cast_ty.ty.kind()) {
@@ -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

+4-4
Original file line numberDiff line numberDiff line change
@@ -654,15 +654,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
654654
&mut self,
655655
instance: ty::Instance<'tcx>,
656656
body: &'mir mir::Body<'tcx>,
657-
return_place: Option<PlaceTy<'tcx, M::PointerTag>>,
657+
return_place: Option<&PlaceTy<'tcx, M::PointerTag>>,
658658
return_to_block: StackPopCleanup,
659659
) -> InterpResult<'tcx> {
660660
// first push a stack frame so we have access to the local substs
661661
let pre_frame = Frame {
662662
body,
663663
loc: Err(body.span), // Span used for errors caused during preamble.
664664
return_to_block,
665-
return_place,
665+
return_place: return_place.copied(),
666666
// empty local array, we fill it in below, after we are inside the stack frame and
667667
// all methods actually know about the frame
668668
locals: IndexVec::new(),
@@ -777,10 +777,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
777777

778778
if !unwinding {
779779
// Copy the return value to the caller's stack frame.
780-
if let Some(return_place) = frame.return_place {
780+
if let Some(ref return_place) = frame.return_place {
781781
let op = self.access_local(&frame, mir::RETURN_PLACE, None)?;
782782
self.copy_op_transmute(&op, return_place)?;
783-
trace!("{:?}", self.dump_place(*return_place));
783+
trace!("{:?}", self.dump_place(**return_place));
784784
} else {
785785
throw_ub!(Unreachable);
786786
}

compiler/rustc_mir/src/interpret/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
115115
&mut self,
116116
instance: ty::Instance<'tcx>,
117117
args: &[OpTy<'tcx, M::PointerTag>],
118-
ret: Option<(PlaceTy<'tcx, M::PointerTag>, mir::BasicBlock)>,
118+
ret: Option<(&PlaceTy<'tcx, M::PointerTag>, mir::BasicBlock)>,
119119
) -> InterpResult<'tcx, bool> {
120120
let substs = instance.substs;
121121
let intrinsic_name = self.tcx.item_name(instance.def_id());
@@ -459,7 +459,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
459459
for i in 0..len {
460460
let place = self.place_index(dest, i)?;
461461
let value = if i == index { *elem } else { self.operand_index(input, i)? };
462-
self.copy_op(&value, place)?;
462+
self.copy_op(&value, &place)?;
463463
}
464464
}
465465
sym::simd_extract => {
@@ -492,7 +492,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
492492
_ => return Ok(false),
493493
}
494494

495-
trace!("{:?}", self.dump_place(*dest));
495+
trace!("{:?}", self.dump_place(**dest));
496496
self.go_to_block(ret);
497497
Ok(true)
498498
}
@@ -501,7 +501,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
501501
&mut self,
502502
a: &ImmTy<'tcx, M::PointerTag>,
503503
b: &ImmTy<'tcx, M::PointerTag>,
504-
dest: PlaceTy<'tcx, M::PointerTag>,
504+
dest: &PlaceTy<'tcx, M::PointerTag>,
505505
) -> InterpResult<'tcx> {
506506
// Performs an exact division, resulting in undefined behavior where
507507
// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`.

compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9292
let location = self.allocate(loc_layout, MemoryKind::CallerLocation);
9393

9494
// Initialize fields.
95-
self.write_immediate(file.to_ref(), self.mplace_field(location, 0).unwrap().into())
95+
self.write_immediate(file.to_ref(), &self.mplace_field(location, 0).unwrap().into())
9696
.expect("writing to memory we just allocated cannot fail");
97-
self.write_scalar(line, self.mplace_field(location, 1).unwrap().into())
97+
self.write_scalar(line, &self.mplace_field(location, 1).unwrap().into())
9898
.expect("writing to memory we just allocated cannot fail");
99-
self.write_scalar(col, self.mplace_field(location, 2).unwrap().into())
99+
self.write_scalar(col, &self.mplace_field(location, 2).unwrap().into())
100100
.expect("writing to memory we just allocated cannot fail");
101101

102102
location

compiler/rustc_mir/src/interpret/machine.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
157157
instance: ty::Instance<'tcx>,
158158
abi: Abi,
159159
args: &[OpTy<'tcx, Self::PointerTag>],
160-
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
160+
ret: Option<(&PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
161161
unwind: Option<mir::BasicBlock>,
162162
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>>;
163163

@@ -168,7 +168,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
168168
fn_val: Self::ExtraFnVal,
169169
abi: Abi,
170170
args: &[OpTy<'tcx, Self::PointerTag>],
171-
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
171+
ret: Option<(&PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
172172
unwind: Option<mir::BasicBlock>,
173173
) -> InterpResult<'tcx>;
174174

@@ -178,7 +178,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
178178
ecx: &mut InterpCx<'mir, 'tcx, Self>,
179179
instance: ty::Instance<'tcx>,
180180
args: &[OpTy<'tcx, Self::PointerTag>],
181-
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
181+
ret: Option<(&PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
182182
unwind: Option<mir::BasicBlock>,
183183
) -> InterpResult<'tcx>;
184184

@@ -207,7 +207,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
207207
/// Heap allocations via the `box` keyword.
208208
fn box_alloc(
209209
ecx: &mut InterpCx<'mir, 'tcx, Self>,
210-
dest: PlaceTy<'tcx, Self::PointerTag>,
210+
dest: &PlaceTy<'tcx, Self::PointerTag>,
211211
) -> InterpResult<'tcx>;
212212

213213
/// Called to read the specified `local` from the `frame`.
@@ -327,7 +327,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
327327
fn retag(
328328
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
329329
_kind: mir::RetagKind,
330-
_place: PlaceTy<'tcx, Self::PointerTag>,
330+
_place: &PlaceTy<'tcx, Self::PointerTag>,
331331
) -> InterpResult<'tcx> {
332332
Ok(())
333333
}
@@ -420,7 +420,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
420420
fn_val: !,
421421
_abi: Abi,
422422
_args: &[OpTy<$tcx>],
423-
_ret: Option<(PlaceTy<$tcx>, mir::BasicBlock)>,
423+
_ret: Option<(&PlaceTy<$tcx>, mir::BasicBlock)>,
424424
_unwind: Option<mir::BasicBlock>,
425425
) -> InterpResult<$tcx> {
426426
match fn_val {}

compiler/rustc_mir/src/interpret/operand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
462462
#[inline(always)]
463463
pub fn place_to_op(
464464
&self,
465-
place: PlaceTy<'tcx, M::PointerTag>,
465+
place: &PlaceTy<'tcx, M::PointerTag>,
466466
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
467-
let op = match *place {
467+
let op = match **place {
468468
Place::Ptr(mplace) => Operand::Indirect(mplace),
469469
Place::Local { frame, local } => {
470470
*self.access_local(&self.stack()[frame], local, None)?

compiler/rustc_mir/src/interpret/operator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
1616
op: mir::BinOp,
1717
left: &ImmTy<'tcx, M::PointerTag>,
1818
right: &ImmTy<'tcx, M::PointerTag>,
19-
dest: PlaceTy<'tcx, M::PointerTag>,
19+
dest: &PlaceTy<'tcx, M::PointerTag>,
2020
) -> InterpResult<'tcx> {
2121
let (val, overflowed, ty) = self.overflowing_binary_op(op, &left, &right)?;
2222
debug_assert_eq!(
@@ -36,7 +36,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3636
op: mir::BinOp,
3737
left: &ImmTy<'tcx, M::PointerTag>,
3838
right: &ImmTy<'tcx, M::PointerTag>,
39-
dest: PlaceTy<'tcx, M::PointerTag>,
39+
dest: &PlaceTy<'tcx, M::PointerTag>,
4040
) -> InterpResult<'tcx> {
4141
let (val, _overflowed, ty) = self.overflowing_binary_op(op, left, right)?;
4242
assert_eq!(ty, dest.layout.ty, "type mismatch for result of {:?}", op);

0 commit comments

Comments
 (0)