Skip to content

Commit 45cf3cf

Browse files
committed
Update for changes in rustc.
1 parent 90c2470 commit 45cf3cf

File tree

7 files changed

+121
-108
lines changed

7 files changed

+121
-108
lines changed

Cargo.lock

Lines changed: 32 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/miri.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
3333

3434
let tcx = state.tcx.unwrap();
3535
let mir_map = state.mir_map.unwrap();
36-
let (node_id, _) = state.session.entry_fn.borrow()
36+
let (entry_node_id, _) = state.session.entry_fn.borrow()
3737
.expect("no main or start function found");
38+
let entry_def_id = tcx.map.local_def_id(entry_node_id);
3839

3940
let krate = state.hir_crate.as_ref().unwrap();
4041
let mut memory_size = 100*1024*1024; // 100MB
@@ -66,9 +67,12 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
6667
}
6768
}
6869

69-
let mut mir_map = MirMap { map: mir_map.map.clone() };
70-
run_mir_passes(tcx, &mut mir_map);
71-
eval_main(tcx, &mir_map, node_id, memory_size, step_limit, stack_limit);
70+
let mut mir_map_copy = MirMap::new(tcx.dep_graph.clone());
71+
for def_id in mir_map.map.keys() {
72+
mir_map_copy.map.insert(def_id, mir_map.map.get(&def_id).unwrap().clone());
73+
}
74+
run_mir_passes(tcx, &mut mir_map_copy);
75+
eval_main(tcx, &mir_map_copy, entry_def_id, memory_size, step_limit, stack_limit);
7276

7377
state.session.abort_if_errors();
7478
});

src/interpreter/mod.rs

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc::middle::const_val;
22
use rustc::hir::def_id::DefId;
33
use rustc::mir::mir_map::MirMap;
44
use rustc::mir::repr as mir;
5-
use rustc::traits::ProjectionMode;
5+
use rustc::traits::Reveal;
66
use rustc::ty::layout::{self, Layout, Size};
77
use rustc::ty::subst::{self, Subst, Substs};
88
use rustc::ty::{self, Ty, TyCtxt};
@@ -12,7 +12,6 @@ use std::cell::RefCell;
1212
use std::ops::Deref;
1313
use std::rc::Rc;
1414
use std::iter;
15-
use syntax::ast;
1615
use syntax::codemap::{self, DUMMY_SP};
1716

1817
use error::{EvalError, EvalResult};
@@ -148,15 +147,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
148147
}
149148
}
150149

151-
pub fn alloc_ret_ptr(&mut self, output_ty: ty::FnOutput<'tcx>, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, Option<Pointer>> {
152-
match output_ty {
153-
ty::FnConverging(ty) => {
154-
let size = self.type_size_with_substs(ty, substs);
155-
let align = self.type_align_with_substs(ty, substs);
156-
self.memory.allocate(size, align).map(Some)
157-
}
158-
ty::FnDiverging => Ok(None),
159-
}
150+
pub fn alloc_ret_ptr(&mut self, ty: Ty<'tcx>, substs: &'tcx Substs<'tcx>) -> EvalResult<'tcx, Pointer> {
151+
let size = self.type_size_with_substs(ty, substs);
152+
let align = self.type_align_with_substs(ty, substs);
153+
self.memory.allocate(size, align)
160154
}
161155

162156
pub fn memory(&self) -> &Memory<'a, 'tcx> {
@@ -251,22 +245,21 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
251245
}
252246

253247
pub fn load_mir(&self, def_id: DefId) -> CachedMir<'a, 'tcx> {
254-
match self.tcx.map.as_local_node_id(def_id) {
255-
Some(node_id) => CachedMir::Ref(self.mir_map.map.get(&node_id).unwrap()),
256-
None => {
257-
let mut mir_cache = self.mir_cache.borrow_mut();
258-
if let Some(mir) = mir_cache.get(&def_id) {
259-
return CachedMir::Owned(mir.clone());
260-
}
261-
262-
let cs = &self.tcx.sess.cstore;
263-
let mir = cs.maybe_get_item_mir(self.tcx, def_id).unwrap_or_else(|| {
264-
panic!("no mir for `{}`", self.tcx.item_path_str(def_id));
265-
});
266-
let cached = Rc::new(mir);
267-
mir_cache.insert(def_id, cached.clone());
268-
CachedMir::Owned(cached)
248+
if def_id.is_local() {
249+
CachedMir::Ref(self.mir_map.map.get(&def_id).unwrap())
250+
} else {
251+
let mut mir_cache = self.mir_cache.borrow_mut();
252+
if let Some(mir) = mir_cache.get(&def_id) {
253+
return CachedMir::Owned(mir.clone());
269254
}
255+
256+
let cs = &self.tcx.sess.cstore;
257+
let mir = cs.maybe_get_item_mir(self.tcx, def_id).unwrap_or_else(|| {
258+
panic!("no mir for `{}`", self.tcx.item_path_str(def_id));
259+
});
260+
let cached = Rc::new(mir);
261+
mir_cache.insert(def_id, cached.clone());
262+
CachedMir::Owned(cached)
270263
}
271264
}
272265

@@ -299,7 +292,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
299292
// TODO(solson): Is this inefficient? Needs investigation.
300293
let ty = self.monomorphize(ty, substs);
301294

302-
self.tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| {
295+
self.tcx.normalizing_infer_ctxt(Reveal::All).enter(|infcx| {
303296
// TODO(solson): Report this error properly.
304297
ty.layout(&infcx).unwrap()
305298
})
@@ -755,7 +748,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
755748
Temp(i) => self.frame().locals[self.frame().temp_offset + i.index()],
756749

757750
Static(def_id) => {
758-
let substs = self.tcx.mk_substs(subst::Substs::empty());
751+
let substs = subst::Substs::empty(self.tcx);
759752
let cid = ConstantId {
760753
def_id: def_id,
761754
substs: substs,
@@ -846,11 +839,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
846839
}
847840

848841
fn lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> {
849-
self.monomorphize(self.mir().lvalue_ty(self.tcx, lvalue).to_ty(self.tcx), self.substs())
842+
self.monomorphize(lvalue.ty(&self.mir(), self.tcx).to_ty(self.tcx), self.substs())
850843
}
851844

852845
fn operand_ty(&self, operand: &mir::Operand<'tcx>) -> Ty<'tcx> {
853-
self.monomorphize(self.mir().operand_ty(self.tcx, operand), self.substs())
846+
self.monomorphize(operand.ty(&self.mir(), self.tcx), self.substs())
854847
}
855848

856849
fn move_(&mut self, src: Pointer, dest: Pointer, ty: Ty<'tcx>) -> EvalResult<'tcx, ()> {
@@ -961,21 +954,19 @@ impl<'mir, 'tcx: 'mir> Deref for CachedMir<'mir, 'tcx> {
961954
pub fn eval_main<'a, 'tcx: 'a>(
962955
tcx: TyCtxt<'a, 'tcx, 'tcx>,
963956
mir_map: &'a MirMap<'tcx>,
964-
node_id: ast::NodeId,
957+
def_id: DefId,
965958
memory_size: usize,
966959
step_limit: u64,
967960
stack_limit: usize,
968961
) {
969-
let mir = mir_map.map.get(&node_id).expect("no mir for main function");
970-
let def_id = tcx.map.local_def_id(node_id);
962+
let mir = mir_map.map.get(&def_id).expect("no mir for main function");
971963
let mut ecx = EvalContext::new(tcx, mir_map, memory_size, stack_limit);
972-
let substs = tcx.mk_substs(subst::Substs::empty());
964+
let substs = subst::Substs::empty(tcx);
973965
let return_ptr = ecx.alloc_ret_ptr(mir.return_ty, substs)
974-
.expect("should at least be able to allocate space for the main function's return value")
975-
.expect("main function should not be diverging");
966+
.expect("should at least be able to allocate space for the main function's return value");
976967

977968
ecx.push_stack_frame(def_id, mir.span, CachedMir::Ref(mir), substs, Some(return_ptr))
978-
.expect("could not allocate first stack frame");
969+
.expect("could not allocate first stack frame");
979970

980971
if mir.arg_decls.len() == 2 {
981972
// start function
@@ -1018,8 +1009,7 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
10181009
struct Instance<'tcx>(DefId, &'tcx subst::Substs<'tcx>);
10191010
impl<'tcx> fmt::Display for Instance<'tcx> {
10201011
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1021-
ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[],
1022-
|tcx| Some(tcx.lookup_item_type(self.0).generics))
1012+
ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[])
10231013
}
10241014
}
10251015
err.span_note(span, &format!("inside call to {}", Instance(def_id, substs)));

src/interpreter/step.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
6666

6767
fn statement(&mut self, stmt: &mir::Statement<'tcx>) -> EvalResult<'tcx, ()> {
6868
trace!("{:?}", stmt);
69-
let mir::StatementKind::Assign(ref lvalue, ref rvalue) = stmt.kind;
70-
self.eval_assignment(lvalue, rvalue)?;
69+
70+
use rustc::mir::repr::StatementKind::*;
71+
match stmt.kind {
72+
Assign(ref lvalue, ref rvalue) => self.eval_assignment(lvalue, rvalue)?,
73+
SetDiscriminant { .. } => unimplemented!(),
74+
75+
// Miri can safely ignore these. Only translation needs them.
76+
StorageLive(_) | StorageDead(_) => {}
77+
}
78+
7179
self.frame_mut().stmt += 1;
7280
Ok(())
7381
}
@@ -110,7 +118,6 @@ impl<'a, 'b, 'tcx> ConstantExtractor<'a, 'b, 'tcx> {
110118
let mir = self.ecx.load_mir(def_id);
111119
self.try(|this| {
112120
let ptr = this.ecx.alloc_ret_ptr(mir.return_ty, substs)?;
113-
let ptr = ptr.expect("there's no such thing as an unreachable static");
114121
this.ecx.statics.insert(cid.clone(), ptr);
115122
this.ecx.push_stack_frame(def_id, span, mir, substs, Some(ptr))
116123
});
@@ -155,7 +162,6 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'tcx> {
155162
let return_ty = mir.return_ty;
156163
self.try(|this| {
157164
let return_ptr = this.ecx.alloc_ret_ptr(return_ty, cid.substs)?;
158-
let return_ptr = return_ptr.expect("there's no such thing as an unreachable static");
159165
let mir = CachedMir::Owned(Rc::new(mir));
160166
this.ecx.statics.insert(cid.clone(), return_ptr);
161167
this.ecx.push_stack_frame(this.def_id, constant.span, mir, this.substs, Some(return_ptr))
@@ -167,7 +173,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'tcx> {
167173
fn visit_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>, context: LvalueContext) {
168174
self.super_lvalue(lvalue, context);
169175
if let mir::Lvalue::Static(def_id) = *lvalue {
170-
let substs = self.ecx.tcx.mk_substs(subst::Substs::empty());
176+
let substs = subst::Substs::empty(self.ecx.tcx);
171177
let span = self.span;
172178
self.global_item(def_id, substs, span);
173179
}

0 commit comments

Comments
 (0)