Skip to content

Commit

Permalink
Make eval_place_to_op iterate instead of recurse
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed May 24, 2019
1 parent 6d7a362 commit e38b399
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,23 +467,34 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
mir_place: &mir::Place<'tcx>,
layout: Option<TyLayout<'tcx>>,
) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::Place::*;
use rustc::mir::Place;
use rustc::mir::PlaceBase;
let op = match mir_place {
Base(PlaceBase::Local(mir::RETURN_PLACE)) => return err!(ReadFromReturnPointer),
Base(PlaceBase::Local(local)) => self.access_local(self.frame(), *local, layout)?,
Base(PlaceBase::Static(place_static)) => {
self.eval_static_to_mplace(place_static)?.into()
}

Projection(proj) => {
let op = self.eval_place_to_op(&proj.base, None)?;
self.operand_projection(op, &proj.elem)?
mir_place.iterate(|place_base, place_projection| {
let mut op = match place_base {
PlaceBase::Local(mir::RETURN_PLACE) => return err!(ReadFromReturnPointer),
PlaceBase::Local(local) => {
// FIXME use place_projection.is_empty() when is available
let layout = if let Place::Base(_) = mir_place {
layout
} else {
None
};

self.access_local(self.frame(), *local, layout)?
}
PlaceBase::Static(place_static) => {
self.eval_static_to_mplace(place_static)?.into()
}
};

for proj in place_projection {
op = self.operand_projection(op, &proj.elem)?
}
};

trace!("eval_place_to_op: got {:?}", *op);
Ok(op)
trace!("eval_place_to_op: got {:?}", *op);
Ok(op)
})
}

/// Evaluate the operand, returning a place where you can then find the data.
Expand Down

0 comments on commit e38b399

Please sign in to comment.