use a loop rather than try_fold
This commit is contained in:
parent
ab225ade1e
commit
04b3cd9f7c
@ -524,19 +524,18 @@ pub fn place_to_op(
|
|||||||
/// avoid allocations.
|
/// avoid allocations.
|
||||||
pub fn eval_place_to_op(
|
pub fn eval_place_to_op(
|
||||||
&self,
|
&self,
|
||||||
place: mir::Place<'tcx>,
|
mir_place: mir::Place<'tcx>,
|
||||||
layout: Option<TyAndLayout<'tcx>>,
|
layout: Option<TyAndLayout<'tcx>>,
|
||||||
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
|
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
|
||||||
// Do not use the layout passed in as argument if the base we are looking at
|
// Do not use the layout passed in as argument if the base we are looking at
|
||||||
// here is not the entire place.
|
// here is not the entire place.
|
||||||
let layout = if place.projection.is_empty() { layout } else { None };
|
let layout = if mir_place.projection.is_empty() { layout } else { None };
|
||||||
|
|
||||||
let base_op = self.local_to_op(self.frame(), place.local, layout)?;
|
let mut op = self.local_to_op(self.frame(), mir_place.local, layout)?;
|
||||||
|
// Using `try_fold` turned out to be bad for performance, hence the loop.
|
||||||
let op = place
|
for elem in mir_place.projection.iter() {
|
||||||
.projection
|
op = self.operand_projection(&op, elem)?
|
||||||
.iter()
|
}
|
||||||
.try_fold(base_op, |op, elem| self.operand_projection(&op, elem))?;
|
|
||||||
|
|
||||||
trace!("eval_place_to_op: got {:?}", *op);
|
trace!("eval_place_to_op: got {:?}", *op);
|
||||||
// Sanity-check the type we ended up with.
|
// Sanity-check the type we ended up with.
|
||||||
@ -545,12 +544,12 @@ pub fn eval_place_to_op(
|
|||||||
*self.tcx,
|
*self.tcx,
|
||||||
self.param_env,
|
self.param_env,
|
||||||
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
|
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
|
||||||
place.ty(&self.frame().body.local_decls, *self.tcx).ty
|
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty
|
||||||
)?)?,
|
)?)?,
|
||||||
op.layout,
|
op.layout,
|
||||||
),
|
),
|
||||||
"eval_place of a MIR place with type {:?} produced an interpreter operand with type {:?}",
|
"eval_place of a MIR place with type {:?} produced an interpreter operand with type {:?}",
|
||||||
place.ty(&self.frame().body.local_decls, *self.tcx).ty,
|
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
|
||||||
op.layout.ty,
|
op.layout.ty,
|
||||||
);
|
);
|
||||||
Ok(op)
|
Ok(op)
|
||||||
|
@ -432,31 +432,30 @@ pub fn local_to_place(
|
|||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn eval_place(
|
pub fn eval_place(
|
||||||
&mut self,
|
&mut self,
|
||||||
place: mir::Place<'tcx>,
|
mir_place: mir::Place<'tcx>,
|
||||||
) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
|
) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
|
||||||
let base_place = self.local_to_place(self.frame_idx(), place.local)?;
|
let mut place = self.local_to_place(self.frame_idx(), mir_place.local)?;
|
||||||
|
// Using `try_fold` turned out to be bad for performance, hence the loop.
|
||||||
|
for elem in mir_place.projection.iter() {
|
||||||
|
place = self.place_projection(&place, elem)?
|
||||||
|
}
|
||||||
|
|
||||||
let final_place = place
|
trace!("{:?}", self.dump_place(place.place));
|
||||||
.projection
|
|
||||||
.iter()
|
|
||||||
.try_fold(base_place, |op, elem| self.place_projection(&op, elem))?;
|
|
||||||
|
|
||||||
trace!("{:?}", self.dump_place(final_place.place));
|
|
||||||
// Sanity-check the type we ended up with.
|
// Sanity-check the type we ended up with.
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
mir_assign_valid_types(
|
mir_assign_valid_types(
|
||||||
*self.tcx,
|
*self.tcx,
|
||||||
self.param_env,
|
self.param_env,
|
||||||
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
|
self.layout_of(self.subst_from_current_frame_and_normalize_erasing_regions(
|
||||||
place.ty(&self.frame().body.local_decls, *self.tcx).ty
|
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty
|
||||||
)?)?,
|
)?)?,
|
||||||
final_place.layout,
|
place.layout,
|
||||||
),
|
),
|
||||||
"eval_place of a MIR place with type {:?} produced an interpreter place with type {:?}",
|
"eval_place of a MIR place with type {:?} produced an interpreter place with type {:?}",
|
||||||
place.ty(&self.frame().body.local_decls, *self.tcx).ty,
|
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
|
||||||
final_place.layout.ty,
|
place.layout.ty,
|
||||||
);
|
);
|
||||||
Ok(final_place)
|
Ok(place)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write an immediate to a place
|
/// Write an immediate to a place
|
||||||
|
Loading…
Reference in New Issue
Block a user