2016-05-30 07:05:50 -05:00
|
|
|
extern crate rustc_driver;
|
2020-01-06 13:53:41 -06:00
|
|
|
extern crate rustc_hir;
|
2019-02-01 16:26:42 -06:00
|
|
|
extern crate rustc_interface;
|
2016-05-30 07:05:50 -05:00
|
|
|
|
2020-01-06 13:53:41 -06:00
|
|
|
use rustc_hir::def_id::LOCAL_CRATE;
|
2019-07-19 10:36:25 -05:00
|
|
|
use rustc_driver::Compilation;
|
2019-12-23 05:56:23 -06:00
|
|
|
use rustc_interface::{interface, Queries};
|
2019-02-01 16:26:42 -06:00
|
|
|
|
2020-03-30 04:07:32 -05:00
|
|
|
use crate::test::Bencher;
|
|
|
|
|
2019-02-01 16:26:42 -06:00
|
|
|
struct MiriCompilerCalls<'a> {
|
|
|
|
bencher: &'a mut Bencher,
|
|
|
|
}
|
2019-02-08 13:07:49 -06:00
|
|
|
|
2019-02-01 16:26:42 -06:00
|
|
|
impl rustc_driver::Callbacks for MiriCompilerCalls<'_> {
|
2019-12-23 05:56:23 -06:00
|
|
|
fn after_analysis<'tcx>(
|
|
|
|
&mut self,
|
|
|
|
compiler: &interface::Compiler,
|
|
|
|
queries: &'tcx Queries<'tcx>,
|
|
|
|
) -> Compilation {
|
2019-02-01 16:26:42 -06:00
|
|
|
compiler.session().abort_if_errors();
|
2019-02-08 13:07:49 -06:00
|
|
|
|
2019-11-30 03:19:00 -06:00
|
|
|
queries.global_ctxt().unwrap().peek_mut().enter(|tcx| {
|
2019-12-23 05:56:23 -06:00
|
|
|
let (entry_def_id, _) =
|
|
|
|
tcx.entry_fn(LOCAL_CRATE).expect("no main or start function found");
|
2016-05-30 07:05:50 -05:00
|
|
|
|
2019-02-01 16:26:42 -06:00
|
|
|
self.bencher.iter(|| {
|
2020-03-06 02:06:23 -06:00
|
|
|
let config = miri::MiriConfig::default();
|
2020-04-28 03:30:21 -05:00
|
|
|
miri::eval_main(tcx, entry_def_id.to_def_id(), config);
|
2019-02-01 16:26:42 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
compiler.session().abort_if_errors();
|
|
|
|
|
2019-07-19 10:36:25 -05:00
|
|
|
Compilation::Stop
|
2019-02-01 16:26:42 -06:00
|
|
|
}
|
|
|
|
}
|
2016-05-30 07:05:50 -05:00
|
|
|
|
2016-06-17 22:35:37 -05:00
|
|
|
fn find_sysroot() -> String {
|
|
|
|
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
|
|
|
|
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
|
|
|
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
|
|
|
match (home, toolchain) {
|
|
|
|
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
|
2019-12-23 05:56:23 -06:00
|
|
|
_ => option_env!("RUST_SYSROOT")
|
|
|
|
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
|
|
|
|
.to_owned(),
|
2016-06-17 22:35:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 07:05:50 -05:00
|
|
|
pub fn run(filename: &str, bencher: &mut Bencher) {
|
2016-06-17 22:35:37 -05:00
|
|
|
let args = &[
|
|
|
|
"miri".to_string(),
|
2016-06-17 23:35:34 -05:00
|
|
|
format!("benches/helpers/{}.rs", filename),
|
2016-06-17 22:35:37 -05:00
|
|
|
"--sysroot".to_string(),
|
2017-08-10 10:48:38 -05:00
|
|
|
find_sysroot(),
|
2016-06-17 22:35:37 -05:00
|
|
|
];
|
2020-10-11 16:05:40 -05:00
|
|
|
rustc_driver::RunCompiler::new(args, &mut MiriCompilerCalls { bencher }).run().unwrap()
|
2016-05-30 07:05:50 -05:00
|
|
|
}
|