From 0b6e3494177d436c64bb80e71662ea54ad2aeaa9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 19 Oct 2018 10:07:17 +0200 Subject: [PATCH] automalically use start-fn if we have all the MIR --- .travis.yml | 4 ++-- src/bin/miri-rustc-tests.rs | 4 ++-- src/bin/miri.rs | 25 +++---------------------- src/lib.rs | 14 +++++++++----- tests/compiletest.rs | 3 --- 5 files changed, 16 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b4f75ab29..d2315c7e95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,9 +50,9 @@ script: # test `cargo miri` cd cargo-miri-test && if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - cargo miri -q -- -Zmiri-start-fn + cargo miri -q else - cargo miri -q -- -Zmiri-start-fn >stdout.real 2>stderr.real && + cargo miri -q >stdout.real 2>stderr.real && cat stdout.real stderr.real && # Test `cargo miri` output. Not on mac because output redirecting doesn't # work. There is no error. It just stops CI. diff --git a/src/bin/miri-rustc-tests.rs b/src/bin/miri-rustc-tests.rs index 73a8d19c30..fb3b231d41 100644 --- a/src/bin/miri-rustc-tests.rs +++ b/src/bin/miri-rustc-tests.rs @@ -95,7 +95,7 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) { if i.attrs.iter().any(|attr| attr.name() == "test") { let did = self.0.hir.body_owner_def_id(body_id); println!("running test: {}", self.0.def_path_debug_str(did)); - miri::eval_main(self.0, did, None, /*validate*/true); + miri::eval_main(self.0, did, /*validate*/true); self.1.session.abort_if_errors(); } } @@ -106,7 +106,7 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) { state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(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, None, /*validate*/true); + miri::eval_main(tcx, entry_def_id, /*validate*/true); state.session.abort_if_errors(); } else { diff --git a/src/bin/miri.rs b/src/bin/miri.rs index d7207da0b3..d4494a8388 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -26,11 +26,6 @@ use std::path::PathBuf; struct MiriCompilerCalls { default: Box, - /// Whether to begin interpretation at the start_fn lang item or not. - /// - /// If false, the interpretation begins at the `main` function. - start_fn: bool, - /// Whether to enforce the validity invariant. validate: bool, } @@ -90,10 +85,9 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls { 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 = this.start_fn; let validate = this.validate; control.after_analysis.callback = - Box::new(move |state| after_analysis(state, start_fn, validate)); + Box::new(move |state| after_analysis(state, validate)); control.after_analysis.stop = Compilation::Stop; control } @@ -109,7 +103,6 @@ fn after_hir_lowering(state: &mut CompileState) { fn after_analysis<'a, 'tcx>( state: &mut CompileState<'a, 'tcx>, - use_start_fn: bool, validate: bool, ) { state.session.abort_if_errors(); @@ -134,7 +127,7 @@ fn after_analysis<'a, 'tcx>( "running test: {}", self.tcx.def_path_debug_str(did), ); - miri::eval_main(self.tcx, did, None, self.validate); + miri::eval_main(self.tcx, did, self.validate); self.state.session.abort_if_errors(); } } @@ -147,13 +140,7 @@ fn after_analysis<'a, 'tcx>( ); } else if let Some((entry_node_id, _, _)) = *state.session.entry_fn.borrow() { let entry_def_id = tcx.hir.local_def_id(entry_node_id); - // Use start_fn lang item if we have -Zmiri-start-fn set - let start_wrapper = if use_start_fn { - Some(tcx.lang_items().start_fn().unwrap()) - } else { - None - }; - miri::eval_main(tcx, entry_def_id, start_wrapper, validate); + miri::eval_main(tcx, entry_def_id, validate); state.session.abort_if_errors(); } else { @@ -231,14 +218,9 @@ fn main() { args.push(find_sysroot()); } - let mut start_fn = false; let mut validate = true; args.retain(|arg| { match arg.as_str() { - "-Zmiri-start-fn" => { - start_fn = true; - false - }, "-Zmiri-disable-validation" => { validate = false; false @@ -251,7 +233,6 @@ fn main() { let result = rustc_driver::run(move || { rustc_driver::run_compiler(&args, Box::new(MiriCompilerCalls { default: Box::new(RustcDefaultCalls), - start_fn, validate, }), None, None) }); diff --git a/src/lib.rs b/src/lib.rs index ec2bc4a69f..eba88a8848 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,6 @@ use mono_hash_map::MonoHashMap; pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>( tcx: TyCtxt<'a, 'tcx, 'tcx>, main_id: DefId, - start_wrapper: Option, validate: bool, ) -> EvalResult<'tcx, EvalContext<'a, 'mir, 'tcx, Evaluator<'tcx>>> { let mut ecx = EvalContext::new( @@ -70,8 +69,14 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>( )); } - if let Some(start_id) = start_wrapper { - let main_ret_ty = ecx.tcx.fn_sig(main_id).output(); + let libstd_has_mir = { + let rustc_panic = ecx.resolve_path(&["std", "panicking", "rust_panic"])?; + ecx.load_mir(rustc_panic.def).is_ok() + }; + + if libstd_has_mir { + let start_id = tcx.lang_items().start_fn().unwrap(); + let main_ret_ty = tcx.fn_sig(main_id).output(); let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap(); let start_instance = ty::Instance::resolve( ecx.tcx.tcx, @@ -146,10 +151,9 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>( pub fn eval_main<'a, 'tcx: 'a>( tcx: TyCtxt<'a, 'tcx, 'tcx>, main_id: DefId, - start_wrapper: Option, validate: bool, ) { - let mut ecx = create_ecx(tcx, main_id, start_wrapper, validate).expect("Couldn't create ecx"); + let mut ecx = create_ecx(tcx, main_id, validate).expect("Couldn't create ecx"); let res: EvalResult = (|| { ecx.run()?; diff --git a/tests/compiletest.rs b/tests/compiletest.rs index b240fb31d2..fa57df94da 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -100,9 +100,6 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: let mut flags = Vec::new(); flags.push(format!("--sysroot {}", sysroot.display())); flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs - if have_fullmir() { - flags.push("-Zmiri-start-fn".to_owned()); - } if opt { // FIXME: Using level 1 (instead of 3) for now, as the optimizer is pretty broken // and crashes...