Put miri const eval checking behind -Zmiri
This commit is contained in:
parent
7e5583b7f8
commit
8c2ec689c1
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Sanitizer> = (None, parse_sanitizer, [TRACKED],
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue