From 8c2ec689c159e7f021d5913efb991aff875be967 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 11 Dec 2017 22:27:32 +0100 Subject: [PATCH] Put miri const eval checking behind -Zmiri --- src/bootstrap/bin/rustc.rs | 3 +++ src/bootstrap/check.rs | 1 + src/librustc/session/config.rs | 2 ++ src/librustc_const_eval/eval.rs | 44 ++++++++++++++++++--------------- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 631c9f72f3500..30afd52f44824 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -246,6 +246,9 @@ fn main() { // When running miri tests, we need to generate MIR for all libraries if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") { cmd.arg("-Zalways-encode-mir"); + if stage != "0" { + cmd.arg("-Zmiri"); + } cmd.arg("-Zmir-emit-validate=1"); } diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index ee780d1245ed8..eee403dcbe3e7 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -769,6 +769,7 @@ impl Step for Compiletest { if build.config.rust_debuginfo_tests { flags.push("-g".to_string()); } + flags.push("-Zmiri -Zunstable-options".to_string()); if let Some(linker) = build.linker(target) { cmd.arg("--linker").arg(linker); diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 0dcd3e8081080..e6138b34c8084 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1141,6 +1141,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "print some statistics about MIR"), always_encode_mir: bool = (false, parse_bool, [TRACKED], "encode MIR of all functions into the crate metadata"), + miri: bool = (false, parse_bool, [TRACKED], + "check the miri const evaluator against the old ctfe"), osx_rpath_install_name: bool = (false, parse_bool, [TRACKED], "pass `-install_name @rpath/...` to the macOS linker"), sanitizer: Option = (None, parse_sanitizer, [TRACKED], diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index f400380536ea3..95b6dc80b14a0 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -729,27 +729,31 @@ pub(crate) fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trace!("running old const eval"); let old_result = ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value); trace!("old const eval produced {:?}", old_result); - let instance = ty::Instance::new(def_id, substs); - trace!("const eval instance: {:?}, {:?}", instance, key.param_env); - let miri_result = ::rustc::mir::interpret::eval_body(tcx, instance, key.param_env); - match (miri_result, old_result) { - ((Err(err), ecx), Ok(ok)) => { - trace!("miri failed, ctfe returned {:?}", ok); - tcx.sess.span_warn( - tcx.def_span(key.value.0), - "miri failed to eval, while ctfe succeeded", - ); - let () = unwrap_miri(&ecx, Err(err)); - Ok(ok) - }, - ((Ok(_), _), Err(err)) => { - Err(err) - }, - ((Err(_), _), Err(err)) => Err(err), - ((Ok((miri_val, miri_ty)), mut ecx), Ok(ctfe)) => { - check_ctfe_against_miri(&mut ecx, miri_val, miri_ty, ctfe.val); - Ok(ctfe) + if tcx.sess.opts.debugging_opts.miri { + let instance = ty::Instance::new(def_id, substs); + trace!("const eval instance: {:?}, {:?}", instance, key.param_env); + let miri_result = ::rustc::mir::interpret::eval_body(tcx, instance, key.param_env); + match (miri_result, old_result) { + ((Err(err), ecx), Ok(ok)) => { + trace!("miri failed, ctfe returned {:?}", ok); + tcx.sess.span_warn( + tcx.def_span(key.value.0), + "miri failed to eval, while ctfe succeeded", + ); + let () = unwrap_miri(&ecx, Err(err)); + Ok(ok) + }, + ((Ok(_), _), Err(err)) => { + Err(err) + }, + ((Err(_), _), Err(err)) => Err(err), + ((Ok((miri_val, miri_ty)), mut ecx), Ok(ctfe)) => { + check_ctfe_against_miri(&mut ecx, miri_val, miri_ty, ctfe.val); + Ok(ctfe) + } } + } else { + old_result } }