From: Oliver Schneider Date: Fri, 10 Jun 2016 10:34:15 +0000 (+0200) Subject: simplify the stepper interface X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=3b804942fdcc8858644218a570e034062021c7a4;p=rust.git simplify the stepper interface --- diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index a7a57a79601..2673f560903 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -24,7 +24,7 @@ mod stepper; -struct GlobalEvalContext<'a, 'tcx: 'a> { +pub struct GlobalEvalContext<'a, 'tcx: 'a> { /// The results of the type checker, from rustc. tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -335,12 +335,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { err.emit(); } - fn run(&mut self) -> EvalResult<()> { - let mut stepper = stepper::Stepper::new(self); - while stepper.step()? {} - Ok(()) - } - fn push_stack_frame(&mut self, def_id: DefId, span: codemap::Span, mir: CachedMir<'a, 'tcx>, substs: &'tcx Substs<'tcx>, return_ptr: Option) { @@ -1414,14 +1408,22 @@ pub fn interpret_start_points<'a, 'tcx>( gecx.push_stack_frame(tcx.map.local_def_id(id), mir.span, CachedMir::Ref(mir), substs, return_ptr); - match (gecx.run(), return_ptr) { - (Ok(()), Some(ptr)) => if log_enabled!(::log::LogLevel::Debug) { + loop { match (stepper::step(&mut gecx), return_ptr) { + (Ok(true), _) => {}, + (Ok(false), Some(ptr)) => if log_enabled!(::log::LogLevel::Debug) { gecx.memory.dump(ptr.alloc_id); + break; + }, + (Ok(false), None) => { + warn!("diverging function returned"); + break; }, - (Ok(()), None) => warn!("diverging function returned"), // FIXME: diverging functions can end up here in some future miri - (Err(e), _) => gecx.report(e), - } + (Err(e), _) => { + gecx.report(e); + break; + }, + } } } } } diff --git a/src/interpreter/stepper.rs b/src/interpreter/stepper.rs index 47ee9874ad6..10145bdce27 100644 --- a/src/interpreter/stepper.rs +++ b/src/interpreter/stepper.rs @@ -12,12 +12,16 @@ use syntax::codemap::Span; use std::rc::Rc; -pub struct Stepper<'fncx, 'a: 'fncx, 'tcx: 'a>{ +struct Stepper<'fncx, 'a: 'fncx, 'tcx: 'a>{ gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>, } +pub fn step<'fncx, 'a: 'fncx, 'tcx: 'a>(gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>) -> EvalResult { + Stepper::new(gecx).step() +} + impl<'fncx, 'a, 'tcx> Stepper<'fncx, 'a, 'tcx> { - pub(super) fn new(gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>) -> Self { + fn new(gecx: &'fncx mut GlobalEvalContext<'a, 'tcx>) -> Self { Stepper { gecx: gecx, } @@ -43,7 +47,7 @@ fn terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> EvalResult<()> { } // returns true as long as there are more things to do - pub fn step(&mut self) -> EvalResult { + fn step(&mut self) -> EvalResult { if self.gecx.stack.is_empty() { return Ok(false); }