Put miri const eval checking behind -Zmiri
diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 631c9f7..30afd52 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -246,6 +246,9 @@
// 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 ee780d1..eee403d 100644
--- a/src/bootstrap/check.rs
+++ b/src/bootstrap/check.rs
@@ -769,6 +769,7 @@
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 0dcd3e8..e6138b3 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -1141,6 +1141,8 @@
"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<Sanitizer> = (None, parse_sanitizer, [TRACKED],
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs
index f400380..95b6dc8 100644
--- a/src/librustc_const_eval/eval.rs
+++ b/src/librustc_const_eval/eval.rs
@@ -729,27 +729,31 @@
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
}
}