Rustup to rustc 1.28.0-nightly (2a0062974 2018-06-09)

This commit is contained in:
bjorn3 2018-06-10 11:23:56 +02:00
parent 0755fd6429
commit 60669cbdfd
3 changed files with 46 additions and 39 deletions

View file

@ -5,8 +5,7 @@ extern crate rustc_driver;
extern crate test;
use self::miri::eval_main;
use self::rustc::session::Session;
use self::rustc_driver::{driver, CompilerCalls, Compilation};
use self::rustc_driver::{driver, Compilation};
use std::cell::RefCell;
use std::rc::Rc;
use test::Bencher;
@ -36,37 +35,26 @@ pub fn run(filename: &str, bencher: &mut Bencher) {
"--sysroot".to_string(),
find_sysroot(),
];
let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher)));
rustc_driver::run_compiler(args, compiler_calls, None, None);
}
let bencher = RefCell::new(bencher);
impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
fn build_controller(
&mut self,
_: &Session,
_: &getopts::Matches,
) -> driver::CompileController<'a> {
let mut control: driver::CompileController<'a> = driver::CompileController::basic();
let mut control = driver::CompileController::basic();
let bencher = self.0.clone();
control.after_analysis.stop = Compilation::Stop;
control.after_analysis.callback = Box::new(move |state| {
state.session.abort_if_errors();
control.after_analysis.stop = Compilation::Stop;
control.after_analysis.callback = Box::new(move |state| {
state.session.abort_if_errors();
let tcx = state.tcx.unwrap();
let (entry_node_id, _, _) = state.session.entry_fn.borrow().expect(
"no main or start function found",
);
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
let tcx = state.tcx.unwrap();
let (entry_node_id, _, _) = state.session.entry_fn.borrow().expect(
"no main or start function found",
);
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
bencher.borrow_mut().iter(|| {
eval_main(tcx, entry_def_id, None);
});
state.session.abort_if_errors();
bencher.borrow_mut().iter(|| {
eval_main(tcx, entry_def_id, None);
});
control
}
state.session.abort_if_errors();
});
rustc_driver::run_compiler(args, Box::new(control), None, None);
}

View file

@ -23,7 +23,7 @@ use syntax::ast;
use std::path::PathBuf;
struct MiriCompilerCalls {
default: RustcDefaultCalls,
default: Box<RustcDefaultCalls>,
/// Whether to begin interpretation at the start_fn lang item or not
///
/// If false, the interpretation begins at the `main` function
@ -78,13 +78,14 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
self.default.late_callback(codegen_backend, matches, sess, cstore, input, odir, ofile)
}
fn build_controller(
&mut self,
self: Box<Self>,
sess: &Session,
matches: &getopts::Matches,
) -> CompileController<'a> {
let mut control = self.default.build_controller(sess, matches);
let this = *self;
let mut control = this.default.build_controller(sess, matches);
control.after_hir_lowering.callback = Box::new(after_hir_lowering);
let start_fn = self.start_fn;
let start_fn = this.start_fn;
control.after_analysis.callback = Box::new(move |state| after_analysis(state, start_fn));
if sess.target.target != sess.host {
// only fully compile targets on the host. linking will fail for cross-compilation.
@ -234,8 +235,8 @@ fn main() {
// Make sure we always have all the MIR (e.g. for auxilary builds in unit tests).
args.push("-Zalways-encode-mir".to_owned());
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls {
default: RustcDefaultCalls,
rustc_driver::run_compiler(&args, Box::new(MiriCompilerCalls {
default: Box::new(RustcDefaultCalls),
start_fn,
}, None, None);
}), None, None);
}

View file

@ -24,6 +24,7 @@ use rustc::ty::layout::{TyLayout, LayoutOf, Size};
use rustc::ty::subst::Subst;
use rustc::hir::def_id::DefId;
use rustc::mir;
use rustc::middle::const_val;
use syntax::ast::Mutability;
use syntax::codemap::Span;
@ -253,9 +254,26 @@ pub fn eval_main<'a, 'tcx: 'a>(
//tcx.sess.err("the evaluated program leaked memory");
}
}
Err(mut e) => {
ecx.tcx.sess.err(&e.to_string());
ecx.report(&mut e, true, None);
Err(e) => {
if let Some(frame) = ecx.stack().last() {
let block = &frame.mir.basic_blocks()[frame.block];
let span = if frame.stmt < block.statements.len() {
block.statements[frame.stmt].source_info.span
} else {
block.terminator().source_info.span
};
let mut err = const_val::struct_error(ecx.tcx.tcx.at(span), "constant evaluation error");
let (frames, span) = ecx.generate_stacktrace(None);
err.span_label(span, e.to_string());
for const_val::FrameInfo { span, location, .. } in frames {
err.span_note(span, &format!("inside call to `{}`", location));
}
err.emit();
} else {
ecx.tcx.sess.err(&e.to_string());
}
for (i, frame) in ecx.stack().iter().enumerate() {
trace!("-------------------");
trace!("Frame {}", i);