Skip to content

Commit b8ba8e9

Browse files
authored
Merge pull request rust-lang#73 from oli-obk/rustup
rustup to rustc 1.14.0-nightly (7c69b0d 2016-11-01)
2 parents c50c6e5 + 19c44da commit b8ba8e9

File tree

9 files changed

+54
-101
lines changed

9 files changed

+54
-101
lines changed

benches/helpers/miri_helper.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern crate test;
66

77
use self::miri::{eval_main, run_mir_passes};
88
use self::rustc::session::Session;
9-
use self::rustc::mir::mir_map::MirMap;
109
use self::rustc_driver::{driver, CompilerCalls, Compilation};
1110
use std::cell::RefCell;
1211
use std::rc::Rc;

src/bin/miri.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ extern crate syntax;
1111

1212
use miri::{eval_main, run_mir_passes};
1313
use rustc::session::Session;
14-
use rustc::mir::mir_map::MirMap;
1514
use rustc_driver::{driver, CompilerCalls, Compilation};
1615
use syntax::ast::{MetaItemKind, NestedMetaItemKind};
1716

@@ -32,7 +31,6 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
3231
state.session.abort_if_errors();
3332

3433
let tcx = state.tcx.unwrap();
35-
let mir_map = state.mir_map.unwrap();
3634
let (entry_node_id, _) = state.session.entry_fn.borrow()
3735
.expect("no main or start function found");
3836
let entry_def_id = tcx.map.local_def_id(entry_node_id);
@@ -70,12 +68,8 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
7068
}
7169
}
7270

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

8074
state.session.abort_if_errors();
8175
});

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::error::Error;
22
use std::fmt;
3-
use rustc::mir::repr as mir;
3+
use rustc::mir;
44
use rustc::ty::BareFnTy;
55
use memory::Pointer;
66
use rustc_const_math::ConstMathErr;

src/interpreter/mod.rs

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
use rustc::middle::const_val::ConstVal;
22
use rustc::hir::def_id::DefId;
33
use rustc::hir::map::definitions::DefPathData;
4-
use rustc::mir::mir_map::MirMap;
5-
use rustc::mir::repr as mir;
4+
use rustc::mir;
65
use rustc::traits::Reveal;
76
use rustc::ty::layout::{self, Layout, Size};
87
use rustc::ty::subst::{self, Subst, Substs};
98
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
10-
use rustc::util::nodemap::DefIdMap;
119
use rustc_data_structures::indexed_vec::Idx;
12-
use std::cell::RefCell;
13-
use std::ops::Deref;
14-
use std::rc::Rc;
1510
use syntax::codemap::{self, DUMMY_SP};
1611

1712
use error::{EvalError, EvalResult};
@@ -20,44 +15,41 @@ use primval::{self, PrimVal, PrimValKind};
2015
pub use self::value::Value;
2116

2217
use std::collections::HashMap;
18+
use std::cell::Ref;
2319

2420
mod step;
2521
mod terminator;
2622
mod cast;
2723
mod vtable;
2824
mod value;
2925

26+
pub type MirRef<'tcx> = ::std::cell::Ref<'tcx, mir::Mir<'tcx>>;
27+
3028
pub struct EvalContext<'a, 'tcx: 'a> {
3129
/// The results of the type checker, from rustc.
3230
tcx: TyCtxt<'a, 'tcx, 'tcx>,
3331

34-
/// A mapping from NodeIds to Mir, from rustc. Only contains MIR for crate-local items.
35-
mir_map: &'a MirMap<'tcx>,
36-
37-
/// A local cache from DefIds to Mir for non-crate-local items.
38-
mir_cache: RefCell<DefIdMap<Rc<mir::Mir<'tcx>>>>,
39-
4032
/// The virtual memory system.
4133
memory: Memory<'a, 'tcx>,
4234

4335
/// Precomputed statics, constants and promoteds.
4436
globals: HashMap<GlobalId<'tcx>, Global<'tcx>>,
4537

4638
/// The virtual call stack.
47-
stack: Vec<Frame<'a, 'tcx>>,
39+
stack: Vec<Frame<'tcx>>,
4840

4941
/// The maximum number of stack frames allowed
5042
stack_limit: usize,
5143
}
5244

5345
/// A stack frame.
54-
pub struct Frame<'a, 'tcx: 'a> {
46+
pub struct Frame<'tcx> {
5547
////////////////////////////////////////////////////////////////////////////////
5648
// Function and callsite information
5749
////////////////////////////////////////////////////////////////////////////////
5850

5951
/// The MIR for the function called on this frame.
60-
pub mir: CachedMir<'a, 'tcx>,
52+
pub mir: MirRef<'tcx>,
6153

6254
/// The def_id of the current function.
6355
pub def_id: DefId,
@@ -125,12 +117,6 @@ pub enum LvalueExtra {
125117
DowncastVariant(usize),
126118
}
127119

128-
#[derive(Clone)]
129-
pub enum CachedMir<'mir, 'tcx: 'mir> {
130-
Ref(&'mir mir::Mir<'tcx>),
131-
Owned(Rc<mir::Mir<'tcx>>)
132-
}
133-
134120
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
135121
/// Uniquely identifies a specific constant or static
136122
pub struct GlobalId<'tcx> {
@@ -176,11 +162,9 @@ pub enum StackPopCleanup {
176162
}
177163

178164
impl<'a, 'tcx> EvalContext<'a, 'tcx> {
179-
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>, memory_size: usize, stack_limit: usize) -> Self {
165+
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, memory_size: usize, stack_limit: usize) -> Self {
180166
EvalContext {
181167
tcx: tcx,
182-
mir_map: mir_map,
183-
mir_cache: RefCell::new(DefIdMap()),
184168
memory: Memory::new(&tcx.data_layout, memory_size),
185169
globals: HashMap::new(),
186170
stack: Vec::new(),
@@ -211,7 +195,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
211195
&mut self.memory
212196
}
213197

214-
pub fn stack(&self) -> &[Frame<'a, 'tcx>] {
198+
pub fn stack(&self) -> &[Frame<'tcx>] {
215199
&self.stack
216200
}
217201

@@ -292,25 +276,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
292276
ty.is_sized(self.tcx, &self.tcx.empty_parameter_environment(), DUMMY_SP)
293277
}
294278

295-
pub fn load_mir(&self, def_id: DefId) -> EvalResult<'tcx, CachedMir<'a, 'tcx>> {
279+
pub fn load_mir(&self, def_id: DefId) -> EvalResult<'tcx, MirRef<'tcx>> {
296280
trace!("load mir {:?}", def_id);
297-
if def_id.is_local() {
298-
Ok(CachedMir::Ref(self.mir_map.map.get(&def_id).unwrap()))
281+
if def_id.is_local() || self.tcx.sess.cstore.is_item_mir_available(def_id) {
282+
Ok(self.tcx.item_mir(def_id))
299283
} else {
300-
let mut mir_cache = self.mir_cache.borrow_mut();
301-
if let Some(mir) = mir_cache.get(&def_id) {
302-
return Ok(CachedMir::Owned(mir.clone()));
303-
}
304-
305-
let cs = &self.tcx.sess.cstore;
306-
match cs.maybe_get_item_mir(self.tcx, def_id) {
307-
Some(mir) => {
308-
let cached = Rc::new(mir);
309-
mir_cache.insert(def_id, cached.clone());
310-
Ok(CachedMir::Owned(cached))
311-
},
312-
None => Err(EvalError::NoMirFor(self.tcx.item_path_str(def_id))),
313-
}
284+
Err(EvalError::NoMirFor(self.tcx.item_path_str(def_id)))
314285
}
315286
}
316287

@@ -358,7 +329,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
358329
&mut self,
359330
def_id: DefId,
360331
span: codemap::Span,
361-
mir: CachedMir<'a, 'tcx>,
332+
mir: MirRef<'tcx>,
362333
substs: &'tcx Substs<'tcx>,
363334
return_lvalue: Lvalue<'tcx>,
364335
return_to_block: StackPopCleanup,
@@ -371,7 +342,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
371342
let locals = vec![None; num_locals];
372343

373344
self.stack.push(Frame {
374-
mir: mir.clone(),
345+
mir: mir,
375346
block: mir::START_BLOCK,
376347
return_to_block: return_to_block,
377348
return_lvalue: return_lvalue,
@@ -483,7 +454,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
483454
let dest_ty = self.lvalue_ty(lvalue);
484455
let dest_layout = self.type_layout(dest_ty);
485456

486-
use rustc::mir::repr::Rvalue::*;
457+
use rustc::mir::Rvalue::*;
487458
match *rvalue {
488459
Use(ref operand) => {
489460
let value = self.eval_operand(operand)?;
@@ -653,7 +624,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
653624

654625
Cast(kind, ref operand, cast_ty) => {
655626
debug_assert_eq!(self.monomorphize(cast_ty, self.substs()), dest_ty);
656-
use rustc::mir::repr::CastKind::*;
627+
use rustc::mir::CastKind::*;
657628
match kind {
658629
Unsize => {
659630
let src = self.eval_operand(operand)?;
@@ -812,12 +783,12 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
812783
}
813784

814785
fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<'tcx, Value> {
815-
use rustc::mir::repr::Operand::*;
786+
use rustc::mir::Operand::*;
816787
match *op {
817788
Consume(ref lvalue) => self.eval_and_read_lvalue(lvalue),
818789

819790
Constant(mir::Constant { ref literal, ty, .. }) => {
820-
use rustc::mir::repr::Literal;
791+
use rustc::mir::Literal;
821792
let value = match *literal {
822793
Literal::Value { ref value } => self.const_to_value(value)?,
823794

@@ -883,7 +854,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
883854
}
884855

885856
fn eval_lvalue(&mut self, mir_lvalue: &mir::Lvalue<'tcx>) -> EvalResult<'tcx, Lvalue<'tcx>> {
886-
use rustc::mir::repr::Lvalue::*;
857+
use rustc::mir::Lvalue::*;
887858
let lvalue = match *mir_lvalue {
888859
Local(mir::RETURN_POINTER) => self.frame().return_lvalue,
889860

@@ -922,7 +893,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
922893
let base_ty = self.lvalue_ty(&proj.base);
923894
let base_layout = self.type_layout(base_ty);
924895

925-
use rustc::mir::repr::ProjectionElem::*;
896+
use rustc::mir::ProjectionElem::*;
926897
let (ptr, extra) = match proj.elem {
927898
Field(field, field_ty) => {
928899
// FIXME(solson)
@@ -1462,16 +1433,16 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
14621433
Ok(Value::ByVal(val))
14631434
}
14641435

1465-
fn frame(&self) -> &Frame<'a, 'tcx> {
1436+
fn frame(&self) -> &Frame<'tcx> {
14661437
self.stack.last().expect("no call frames exist")
14671438
}
14681439

1469-
pub fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> {
1440+
pub fn frame_mut(&mut self) -> &mut Frame<'tcx> {
14701441
self.stack.last_mut().expect("no call frames exist")
14711442
}
14721443

1473-
fn mir(&self) -> CachedMir<'a, 'tcx> {
1474-
self.frame().mir.clone()
1444+
fn mir(&self) -> MirRef<'tcx> {
1445+
Ref::clone(&self.frame().mir)
14751446
}
14761447

14771448
fn substs(&self) -> &'tcx Substs<'tcx> {
@@ -1583,7 +1554,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
15831554
}
15841555
}
15851556

1586-
impl<'a, 'tcx: 'a> Frame<'a, 'tcx> {
1557+
impl<'tcx> Frame<'tcx> {
15871558
pub fn get_local(&self, local: mir::Local) -> Option<Value> {
15881559
// Subtract 1 because we don't store a value for the ReturnPointer, the local with index 0.
15891560
self.locals[local.index() - 1]
@@ -1630,34 +1601,23 @@ impl<'tcx> Lvalue<'tcx> {
16301601
}
16311602
}
16321603

1633-
impl<'mir, 'tcx: 'mir> Deref for CachedMir<'mir, 'tcx> {
1634-
type Target = mir::Mir<'tcx>;
1635-
fn deref(&self) -> &mir::Mir<'tcx> {
1636-
match *self {
1637-
CachedMir::Ref(r) => r,
1638-
CachedMir::Owned(ref rc) => rc,
1639-
}
1640-
}
1641-
}
1642-
16431604
pub fn eval_main<'a, 'tcx: 'a>(
16441605
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1645-
mir_map: &'a MirMap<'tcx>,
16461606
def_id: DefId,
16471607
memory_size: usize,
16481608
step_limit: u64,
16491609
stack_limit: usize,
16501610
) {
1651-
let mir = mir_map.map.get(&def_id).expect("no mir for main function");
1652-
let mut ecx = EvalContext::new(tcx, mir_map, memory_size, stack_limit);
1611+
let mut ecx = EvalContext::new(tcx, memory_size, stack_limit);
1612+
let mir = ecx.load_mir(def_id).expect("main function's MIR not found");
16531613

16541614
ecx.push_stack_frame(
16551615
def_id,
16561616
mir.span,
1657-
CachedMir::Ref(mir),
1617+
mir,
16581618
tcx.intern_substs(&[]),
16591619
Lvalue::from_ptr(Pointer::zst_ptr()),
1660-
StackPopCleanup::None
1620+
StackPopCleanup::None,
16611621
).expect("could not allocate first stack frame");
16621622

16631623
for _ in 0..step_limit {
@@ -1695,15 +1655,15 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
16951655
impl<'tcx> ::std::panic::RefUnwindSafe for Instance<'tcx> {}
16961656
impl<'tcx> fmt::Display for Instance<'tcx> {
16971657
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1698-
ppaux::parameterized(f, self.1, self.0, ppaux::Ns::Value, &[])
1658+
ppaux::parameterized(f, self.1, self.0, &[])
16991659
}
17001660
}
17011661
err.span_note(span, &format!("inside call to {}", Instance(def_id, substs)));
17021662
}
17031663
err.emit();
17041664
}
17051665

1706-
pub fn run_mir_passes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &mut MirMap<'tcx>) {
1666+
pub fn run_mir_passes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
17071667
let mut passes = ::rustc::mir::transform::Passes::new();
17081668
passes.push_hook(Box::new(::rustc_mir::transform::dump_mir::DumpMir));
17091669
passes.push_pass(Box::new(::rustc_mir::transform::no_landing_pads::NoLandingPads));
@@ -1716,7 +1676,7 @@ pub fn run_mir_passes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &mut MirMa
17161676
passes.push_pass(Box::new(::rustc_mir::transform::simplify_cfg::SimplifyCfg::new("elaborate-drops")));
17171677
passes.push_pass(Box::new(::rustc_mir::transform::dump_mir::Marker("PreMiri")));
17181678

1719-
passes.run_passes(tcx, mir_map);
1679+
passes.run_passes(tcx);
17201680
}
17211681

17221682
// TODO(solson): Upstream these methods into rustc::ty::layout.

0 commit comments

Comments
 (0)