Skip to content

Commit

Permalink
Merge pull request #163 from solson/rustup
Browse files Browse the repository at this point in the history
Rustup to rustc 1.19.0-nightly (2d4ed8e0c 2017-05-03)
  • Loading branch information
eddyb committed May 5, 2017
2 parents f8c8813 + 5f67ba7 commit 1f8aa8d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 75 deletions.
3 changes: 1 addition & 2 deletions benches/helpers/miri_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate rustc;
extern crate rustc_driver;
extern crate test;

use self::miri::{eval_main, run_mir_passes};
use self::miri::eval_main;
use self::rustc::session::Session;
use self::rustc_driver::{driver, CompilerCalls, Compilation};
use std::cell::RefCell;
Expand Down Expand Up @@ -55,7 +55,6 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
.expect("no main or start function found");
let entry_def_id = tcx.map.local_def_id(entry_node_id);

run_mir_passes(tcx);
let memory_size = 100*1024*1024; // 100MB
let step_limit = 1000_000;
let stack_limit = 100;
Expand Down
15 changes: 6 additions & 9 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
state.session.abort_if_errors();

let tcx = state.tcx.unwrap();
miri::run_mir_passes(tcx);
let limits = resource_limits_from_attributes(state);

if std::env::args().any(|arg| arg == "--test") {
Expand All @@ -94,15 +93,13 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
fn visit_impl_item(&mut self, _impl_item: &'hir hir::ImplItem) {}
}
state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(limits, tcx, state));
} else {
if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
miri::eval_main(tcx, entry_def_id, limits);
} else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
miri::eval_main(tcx, entry_def_id, limits);

state.session.abort_if_errors();
} else {
println!("no main function found, assuming auxiliary build");
}
state.session.abort_if_errors();
} else {
println!("no main function found, assuming auxiliary build");
}
}

Expand Down
49 changes: 9 additions & 40 deletions src/eval_context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cell::Ref;
use std::collections::HashMap;
use std::fmt::Write;

Expand All @@ -24,8 +23,6 @@ use memory::{Memory, Pointer};
use operator;
use value::{PrimVal, PrimValKind, Value};

pub type MirRef<'tcx> = Ref<'tcx, mir::Mir<'tcx>>;

pub struct EvalContext<'a, 'tcx: 'a> {
/// The results of the type checker, from rustc.
pub(crate) tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand All @@ -48,7 +45,7 @@ pub struct EvalContext<'a, 'tcx: 'a> {
pub(crate) steps_remaining: u64,

/// Drop glue for arrays and slices
pub(crate) seq_drop_glue: MirRef<'tcx>,
pub(crate) seq_drop_glue: &'tcx mir::Mir<'tcx>,
}

/// A stack frame.
Expand All @@ -58,7 +55,7 @@ pub struct Frame<'tcx> {
////////////////////////////////////////////////////////////////////////////////

/// The MIR for the function called on this frame.
pub mir: MirRef<'tcx>,
pub mir: &'tcx mir::Mir<'tcx>,

/// The def_id and substs of the current function
pub instance: ty::Instance<'tcx>,
Expand Down Expand Up @@ -302,16 +299,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
DUMMY_SP,
);
let seq_drop_glue = tcx.alloc_mir(seq_drop_glue);
// Perma-borrow MIR from shims to prevent mutation.
::std::mem::forget(seq_drop_glue.borrow());
EvalContext {
tcx,
memory: Memory::new(&tcx.data_layout, limits.memory_size),
globals: HashMap::new(),
stack: Vec::new(),
stack_limit: limits.stack_limit,
steps_remaining: limits.step_limit,
seq_drop_glue: seq_drop_glue.borrow(),
seq_drop_glue: seq_drop_glue,
}
}

Expand Down Expand Up @@ -385,10 +380,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
ty.is_sized(self.tcx, &self.tcx.empty_parameter_environment(), DUMMY_SP)
}

pub fn load_mir(&self, instance: ty::InstanceDef<'tcx>) -> EvalResult<'tcx, MirRef<'tcx>> {
pub fn load_mir(&self, instance: ty::InstanceDef<'tcx>) -> EvalResult<'tcx, &'tcx mir::Mir<'tcx>> {
trace!("load mir {:?}", instance);
match instance {
ty::InstanceDef::Item(def_id) => self.tcx.maybe_item_mir(def_id).ok_or_else(|| EvalError::NoMirFor(self.tcx.item_path_str(def_id))),
ty::InstanceDef::Item(def_id) => self.tcx.maybe_optimized_mir(def_id).ok_or_else(|| EvalError::NoMirFor(self.tcx.item_path_str(def_id))),
_ => Ok(self.tcx.instance_mir(instance)),
}
}
Expand Down Expand Up @@ -450,7 +445,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
&mut self,
instance: ty::Instance<'tcx>,
span: codemap::Span,
mir: MirRef<'tcx>,
mir: &'tcx mir::Mir<'tcx>,
return_lvalue: Lvalue<'tcx>,
return_to_block: StackPopCleanup,
) -> EvalResult<'tcx> {
Expand Down Expand Up @@ -1028,7 +1023,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}

pub(super) fn operand_ty(&self, operand: &mir::Operand<'tcx>) -> Ty<'tcx> {
self.monomorphize(operand.ty(&self.mir(), self.tcx), self.substs())
self.monomorphize(operand.ty(self.mir(), self.tcx), self.substs())
}

fn copy(&mut self, src: Pointer, dest: Pointer, ty: Ty<'tcx>) -> EvalResult<'tcx> {
Expand Down Expand Up @@ -1445,8 +1440,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
self.stack.last_mut().expect("no call frames exist")
}

pub(super) fn mir(&self) -> MirRef<'tcx> {
Ref::clone(&self.frame().mir)
pub(super) fn mir(&self) -> &'tcx mir::Mir<'tcx> {
self.frame().mir
}

pub(super) fn substs(&self) -> &'tcx Substs<'tcx> {
Expand Down Expand Up @@ -1734,32 +1729,6 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
err.emit();
}

pub fn run_mir_passes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let mut passes = ::rustc::mir::transform::Passes::new();
passes.push_hook(Box::new(::rustc_mir::transform::dump_mir::DumpMir));
passes.push_pass(Box::new(::rustc_mir::transform::no_landing_pads::NoLandingPads));
passes.push_pass(Box::new(::rustc_mir::transform::simplify::SimplifyCfg::new("no-landing-pads")));

// From here on out, regions are gone.
passes.push_pass(Box::new(::rustc_mir::transform::erase_regions::EraseRegions));

passes.push_pass(Box::new(::rustc_mir::transform::add_call_guards::AddCallGuards));
passes.push_pass(Box::new(::rustc_borrowck::ElaborateDrops));
passes.push_pass(Box::new(::rustc_mir::transform::no_landing_pads::NoLandingPads));
passes.push_pass(Box::new(::rustc_mir::transform::simplify::SimplifyCfg::new("elaborate-drops")));

// No lifetime analysis based on borrowing can be done from here on out.
passes.push_pass(Box::new(::rustc_mir::transform::instcombine::InstCombine::new()));
passes.push_pass(Box::new(::rustc_mir::transform::deaggregator::Deaggregator));
passes.push_pass(Box::new(::rustc_mir::transform::copy_prop::CopyPropagation));

passes.push_pass(Box::new(::rustc_mir::transform::simplify::SimplifyLocals));
passes.push_pass(Box::new(::rustc_mir::transform::add_call_guards::AddCallGuards));
passes.push_pass(Box::new(::rustc_mir::transform::dump_mir::Marker("PreMiri")));

passes.run_passes(tcx);
}

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

pub(super) trait IntegerExt {
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ extern crate log;
extern crate log_settings;
#[macro_use]
extern crate rustc;
extern crate rustc_borrowck;
extern crate rustc_const_math;
extern crate rustc_data_structures;
extern crate rustc_mir;
extern crate syntax;

// From crates.io.
Expand Down Expand Up @@ -40,7 +38,6 @@ pub use eval_context::{
ResourceLimits,
StackPopCleanup,
eval_main,
run_mir_passes,
};

pub use lvalue::{
Expand Down
2 changes: 1 addition & 1 deletion src/lvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}

pub(super) fn lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> {
self.monomorphize(lvalue.ty(&self.mir(), self.tcx).to_ty(self.tcx), self.substs())
self.monomorphize(lvalue.ty(self.mir(), self.tcx).to_ty(self.tcx), self.substs())
}
}
13 changes: 5 additions & 8 deletions src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//!
//! The main entry point is the `step` method.

use std::cell::Ref;

use rustc::hir::def_id::DefId;
use rustc::hir;
use rustc::mir::visit::{Visitor, LvalueContext};
Expand All @@ -12,7 +10,7 @@ use rustc::ty::layout::Layout;
use rustc::ty::{subst, self};

use error::{EvalResult, EvalError};
use eval_context::{EvalContext, StackPopCleanup, MirRef};
use eval_context::{EvalContext, StackPopCleanup};
use lvalue::{Global, GlobalId, Lvalue};
use value::{Value, PrimVal};
use syntax::codemap::Span;
Expand Down Expand Up @@ -47,7 +45,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
span: stmt.source_info.span,
instance: self.frame().instance,
ecx: self,
mir: Ref::clone(&mir),
mir,
new_constants: &mut new,
}.visit_statement(block, stmt, mir::Location { block, statement_index: stmt_id });
if new? == 0 {
Expand All @@ -64,7 +62,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
span: terminator.source_info.span,
instance: self.frame().instance,
ecx: self,
mir: Ref::clone(&mir),
mir,
new_constants: &mut new,
}.visit_terminator(block, terminator, mir::Location { block, statement_index: stmt_id });
if new? == 0 {
Expand Down Expand Up @@ -142,7 +140,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
struct ConstantExtractor<'a, 'b: 'a, 'tcx: 'b> {
span: Span,
ecx: &'a mut EvalContext<'b, 'tcx>,
mir: MirRef<'tcx>,
mir: &'tcx mir::Mir<'tcx>,
instance: ty::Instance<'tcx>,
new_constants: &'a mut EvalResult<'tcx, u64>,
}
Expand Down Expand Up @@ -209,8 +207,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'tcx> {
if self.ecx.globals.contains_key(&cid) {
return;
}
let mir = Ref::clone(&self.mir);
let mir = Ref::map(mir, |mir| &mir.promoted[index]);
let mir = &self.mir.promoted[index];
self.try(|this| {
let ty = this.ecx.monomorphize(mir.return_ty, this.instance.substs);
this.ecx.globals.insert(cid, Global::uninitialized(ty));
Expand Down
4 changes: 2 additions & 2 deletions src/terminator/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
_ => bug!("expected thin ptr, got {:?}", arg),
};
arg = Value::ByValPair(PrimVal::Ptr(ptr), PrimVal::Bytes(n as u128));
::eval_context::MirRef::clone(&self.seq_drop_glue)
self.seq_drop_glue
},
ty::TySlice(elem) => {
instance.substs = self.tcx.mk_substs([
Kind::from(elem),
].iter().cloned());
::eval_context::MirRef::clone(&self.seq_drop_glue)
self.seq_drop_glue
},
_ => self.load_mir(instance.def)?,
};
Expand Down
18 changes: 8 additions & 10 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::Write;

fn compile_fail(sysroot: &Path) {
let flags = format!("--sysroot {} -Dwarnings", sysroot.to_str().expect("non utf8 path"));
for_all_targets(&sysroot, |target| {
for_all_targets(sysroot, |target| {
let mut config = compiletest::default_config();
config.host_rustcflags = Some(flags.clone());
config.mode = "compile-fail".parse().expect("Invalid mode");
Expand Down Expand Up @@ -79,8 +79,8 @@ fn compile_test() {
.expect("rustc not found for -vV")
.stdout;
let host = std::str::from_utf8(&host).expect("sysroot is not utf8");
let host = host.split("\nhost: ").skip(1).next().expect("no host: part in rustc -vV");
let host = host.split("\n").next().expect("no \n after host");
let host = host.split("\nhost: ").nth(1).expect("no host: part in rustc -vV");
let host = host.split('\n').next().expect("no \n after host");

if let Ok(path) = std::env::var("MIRI_RUSTC_TEST") {
let mut mir_not_found = Vec::new();
Expand Down Expand Up @@ -148,10 +148,8 @@ fn compile_test() {
abi.push(text[abi_s.len()..end].to_string());
} else if text.starts_with(limit_s) {
limits.push(text[limit_s.len()..end].to_string());
} else {
if text.find("aborting").is_none() {
failed.push(text[..end].to_string());
}
} else if text.find("aborting").is_none() {
failed.push(text[..end].to_string());
}
}
writeln!(stderr.lock(), "FAILED with exit code {:?}", output.status.code()).unwrap();
Expand Down Expand Up @@ -196,10 +194,10 @@ fn compile_test() {
panic!("ran miri on rustc test suite. Test failing for convenience");
} else {
run_pass();
for_all_targets(&sysroot, |target| {
for_all_targets(sysroot, |target| {
miri_pass("tests/run-pass", &target, host);
});
compile_fail(&sysroot);
compile_fail(sysroot);
}
}

Expand All @@ -218,7 +216,7 @@ fn vec_to_hist<T: PartialEq + Ord>(mut v: Vec<T>) -> Vec<(usize, T)> {
let mut current = v.next();
'outer: while let Some(current_val) = current {
let mut n = 1;
while let Some(next) = v.next() {
for next in &mut v {
if next == current_val {
n += 1;
} else {
Expand Down

0 comments on commit 1f8aa8d

Please sign in to comment.