Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes and refactorings #20

Merged
merged 12 commits into from
Jun 10, 2016
26 changes: 14 additions & 12 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::collections::HashMap;

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>,

Expand Down Expand Up @@ -335,12 +335,6 @@ impl<'a, 'tcx> GlobalEvalContext<'a, 'tcx> {
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<Pointer>)
{
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: split this up into two lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

On Fri, 10 Jun 2016 07:30:36 -0700
Scott Olson [email protected] wrote:

@@ -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) {

Nit: split this up into two lines


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/solson/miri/pull/20/files/8c3a066d8d6fec4720c171130816c97ed209ce95..3b804942fdcc8858644218a570e034062021c7a4#r66622654

(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;
},
} }
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/interpreter/stepper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ use rustc::mir::visit::{Visitor, LvalueContext};
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<bool> {
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,
}
Expand All @@ -43,7 +47,7 @@ impl<'fncx, 'a, 'tcx> Stepper<'fncx, 'a, 'tcx> {
}

// returns true as long as there are more things to do
pub fn step(&mut self) -> EvalResult<bool> {
fn step(&mut self) -> EvalResult<bool> {
if self.gecx.stack.is_empty() {
return Ok(false);
}
Expand Down