Skip to content

Commit 8c2ec68

Browse files
committed
Put miri const eval checking behind -Zmiri
1 parent 7e5583b commit 8c2ec68

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

src/bootstrap/bin/rustc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ fn main() {
246246
// When running miri tests, we need to generate MIR for all libraries
247247
if env::var("TEST_MIRI").ok().map_or(false, |val| val == "true") {
248248
cmd.arg("-Zalways-encode-mir");
249+
if stage != "0" {
250+
cmd.arg("-Zmiri");
251+
}
249252
cmd.arg("-Zmir-emit-validate=1");
250253
}
251254

src/bootstrap/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ impl Step for Compiletest {
769769
if build.config.rust_debuginfo_tests {
770770
flags.push("-g".to_string());
771771
}
772+
flags.push("-Zmiri -Zunstable-options".to_string());
772773

773774
if let Some(linker) = build.linker(target) {
774775
cmd.arg("--linker").arg(linker);

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
11411141
"print some statistics about MIR"),
11421142
always_encode_mir: bool = (false, parse_bool, [TRACKED],
11431143
"encode MIR of all functions into the crate metadata"),
1144+
miri: bool = (false, parse_bool, [TRACKED],
1145+
"check the miri const evaluator against the old ctfe"),
11441146
osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
11451147
"pass `-install_name @rpath/...` to the macOS linker"),
11461148
sanitizer: Option<Sanitizer> = (None, parse_sanitizer, [TRACKED],

src/librustc_const_eval/eval.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -729,27 +729,31 @@ pub(crate) fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
729729
trace!("running old const eval");
730730
let old_result = ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value);
731731
trace!("old const eval produced {:?}", old_result);
732-
let instance = ty::Instance::new(def_id, substs);
733-
trace!("const eval instance: {:?}, {:?}", instance, key.param_env);
734-
let miri_result = ::rustc::mir::interpret::eval_body(tcx, instance, key.param_env);
735-
match (miri_result, old_result) {
736-
((Err(err), ecx), Ok(ok)) => {
737-
trace!("miri failed, ctfe returned {:?}", ok);
738-
tcx.sess.span_warn(
739-
tcx.def_span(key.value.0),
740-
"miri failed to eval, while ctfe succeeded",
741-
);
742-
let () = unwrap_miri(&ecx, Err(err));
743-
Ok(ok)
744-
},
745-
((Ok(_), _), Err(err)) => {
746-
Err(err)
747-
},
748-
((Err(_), _), Err(err)) => Err(err),
749-
((Ok((miri_val, miri_ty)), mut ecx), Ok(ctfe)) => {
750-
check_ctfe_against_miri(&mut ecx, miri_val, miri_ty, ctfe.val);
751-
Ok(ctfe)
732+
if tcx.sess.opts.debugging_opts.miri {
733+
let instance = ty::Instance::new(def_id, substs);
734+
trace!("const eval instance: {:?}, {:?}", instance, key.param_env);
735+
let miri_result = ::rustc::mir::interpret::eval_body(tcx, instance, key.param_env);
736+
match (miri_result, old_result) {
737+
((Err(err), ecx), Ok(ok)) => {
738+
trace!("miri failed, ctfe returned {:?}", ok);
739+
tcx.sess.span_warn(
740+
tcx.def_span(key.value.0),
741+
"miri failed to eval, while ctfe succeeded",
742+
);
743+
let () = unwrap_miri(&ecx, Err(err));
744+
Ok(ok)
745+
},
746+
((Ok(_), _), Err(err)) => {
747+
Err(err)
748+
},
749+
((Err(_), _), Err(err)) => Err(err),
750+
((Ok((miri_val, miri_ty)), mut ecx), Ok(ctfe)) => {
751+
check_ctfe_against_miri(&mut ecx, miri_val, miri_ty, ctfe.val);
752+
Ok(ctfe)
753+
}
752754
}
755+
} else {
756+
old_result
753757
}
754758
}
755759

0 commit comments

Comments
 (0)