Skip to content

Commit

Permalink
run full mono-item collection on all MIRI_BE_RUSTC builds
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 19, 2024
1 parent b00696b commit 010d1d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
let out_filename = out_filename.expect("rustdoc must pass `-o`");

cmd.args(&args);
cmd.env("MIRI_BE_RUSTC", "rustdoc");
cmd.env("MIRI_BE_RUSTC", "target");

if verbose > 0 {
eprintln!(
Expand Down
44 changes: 13 additions & 31 deletions src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,14 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
enum MiriBeRustcMode {
Target,
Host,
Rustdoc,
}

impl MiriBeRustcMode {
fn target_crate(self) -> bool {
use MiriBeRustcMode::*;
match self {
Target | Rustdoc => true,
Host => false,
}
}
}

struct MiriBeRustCompilerCalls {
mode: MiriBeRustcMode,
target_crate: bool,
}

impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
#[allow(rustc::potential_query_instability)] // rustc_codegen_ssa (where this code is copied from) also allows this lint
fn config(&mut self, config: &mut Config) {
if config.opts.prints.is_empty() && self.mode == MiriBeRustcMode::Target {
if config.opts.prints.is_empty() && self.target_crate {
// Queries overridden here affect the data stored in `rmeta` files of dependencies,
// which will be used later in non-`MIRI_BE_RUSTC` mode.
config.override_queries = Some(|_, local_providers| {
Expand Down Expand Up @@ -203,11 +186,9 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
queries: &'tcx rustc_interface::Queries<'tcx>,
) -> Compilation {
queries.global_ctxt().unwrap().enter(|tcx| {
// Make sure compile_fail tests with post-monomorphization const-eval errors work as
// intended in rustdoc mode.
if self.mode == MiriBeRustcMode::Rustdoc {
let _ = tcx.collect_and_partition_mono_items(());
}
// We are emulating regular rustc builds, which would perform post-mono const-eval.
// So let's also do that here, even if we might be running with `--emit=metadata`.
let _ = tcx.collect_and_partition_mono_items(());
});
Compilation::Continue
}
Expand Down Expand Up @@ -383,18 +364,19 @@ fn main() {
rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ());
rustc_driver::init_rustc_env_logger(&early_dcx);

let mode = match crate_kind.to_str().unwrap_or_default() {
"target" => MiriBeRustcMode::Target,
"rustdoc" => MiriBeRustcMode::Rustdoc,
"host" => MiriBeRustcMode::Host,
_ => panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}"),
let target_crate = if crate_kind == "target" {
true
} else if crate_kind == "host" {
false
} else {
panic!("invalid `MIRI_BE_RUSTC` value: {crate_kind:?}")
};

// We cannot use `rustc_driver::main` as we need to adjust the CLI arguments.
run_compiler(
args,
mode.target_crate(),
&mut MiriBeRustCompilerCalls { mode },
target_crate,
&mut MiriBeRustCompilerCalls { target_crate },
using_internal_features,
)
}
Expand Down

0 comments on commit 010d1d7

Please sign in to comment.