Skip to content

Commit

Permalink
Put miri const eval checking behind -Zmiri
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 12, 2017
1 parent 7e5583b commit 8c2ec68
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
44 changes: 24 additions & 20 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 8c2ec68

Please sign in to comment.