Skip to content

Commit

Permalink
Rearrange where components live
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Mar 10, 2024
1 parent 197e4ca commit 9fd99a7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::sync::atomic::Ordering::Relaxed;

use either::{Left, Right};

use rustc_data_structures::CTRL_C_RECEIVED;
use rustc_hir::def::DefKind;
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo};
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
Expand All @@ -25,6 +24,7 @@ use crate::interpret::{
GlobalId, Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind,
OpTy, RefTracking, StackPopCleanup,
};
use crate::CTRL_C_RECEIVED;

// Returns a pointer to where the result lives
#[instrument(level = "trace", skip(ecx, body), ret)]
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_const_eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub mod interpret;
pub mod transform;
pub mod util;

use std::sync::atomic::AtomicBool;

pub use errors::ReportErrorExt;

use rustc_middle::{ty, util::Providers};
Expand All @@ -56,3 +58,8 @@ pub fn provide(providers: &mut Providers) {
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
};
}

/// `rustc_driver::main` installs a handler that will set this to `true` if
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
/// This static lives here because it is only read by the interpreter.
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);
6 changes: 0 additions & 6 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ extern crate tracing;
extern crate rustc_macros;

use std::fmt;
use std::sync::atomic::AtomicBool;

pub use rustc_index::static_assert_size;

Expand Down Expand Up @@ -162,8 +161,3 @@ macro_rules! external_bitflags_debug {
}
};
}

/// `rustc_driver::main` installs a handler that will set this to `true` if
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
/// This static is placed here so that it is available to all parts of the compiler.
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);
29 changes: 17 additions & 12 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ extern crate tracing;

use rustc_ast as ast;
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
use rustc_const_eval::CTRL_C_RECEIVED;
use rustc_data_structures::profiling::{
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
};
use rustc_data_structures::CTRL_C_RECEIVED;
use rustc_errors::emitter::stderr_destination;
use rustc_errors::registry::Registry;
use rustc_errors::{
Expand Down Expand Up @@ -1506,17 +1506,9 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
}
}

pub fn main() -> ! {
let start_time = Instant::now();
let start_rss = get_resident_set_size();

let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());

init_rustc_env_logger(&early_dcx);
signal_handler::install();
let mut callbacks = TimePassesCallbacks::default();
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());

/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
/// Makign this handler optional lets tools can install a different handler, if they wish.
pub fn install_ctrlc_handler() {
ctrlc::set_handler(move || {
// Indicate that we have been signaled to stop. If we were already signaled, exit
// immediately. In our interpreter loop we try to consult this value often, but if for
Expand All @@ -1528,6 +1520,19 @@ pub fn main() -> ! {
}
})
.expect("Unable to install ctrlc handler");
}

pub fn main() -> ! {
let start_time = Instant::now();
let start_rss = get_resident_set_size();

let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());

init_rustc_env_logger(&early_dcx);
signal_handler::install();
let mut callbacks = TimePassesCallbacks::default();
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
install_ctrlc_handler();

let exit_code = catch_with_exit_code(|| {
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)
Expand Down
3 changes: 3 additions & 0 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ fn main() {
let using_internal_features =
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());

// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`.
rustc_driver::install_ctrlc_handler();

// Init loggers the Miri way.
init_early_loggers(&early_dcx);

Expand Down
17 changes: 2 additions & 15 deletions src/tools/miri/src/concurrency/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::time::{Duration, SystemTime};

use either::Either;

use rustc_const_eval::CTRL_C_RECEIVED;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::CTRL_C_RECEIVED;
use rustc_hir::def_id::DefId;
use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::Mutability;
Expand Down Expand Up @@ -1046,20 +1046,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
/// Run the core interpreter loop. Returns only when an interrupt occurs (an error or program
/// termination).
fn run_threads(&mut self) -> InterpResult<'tcx, !> {
// In normal rustc, rustc_driver::main installs this handler. But we don't use that
// function, see src/bin/miri.rs.
ctrlc::set_handler(move || {
// Indicate that we have been signaled to stop. If we were already signaled, exit
// immediately. In our interpreter loop we try to consult this value often, but if for
// whatever reason we don't get to that check or the cleanup we do upon finding that
// this bool has become true takes a long time, the exit here will promptly exit the
// process on the second Ctrl-C.
if CTRL_C_RECEIVED.swap(true, Relaxed) {
std::process::exit(1);
}
})
.expect("Unable to install ctrlc handler");
let this = self.eval_context_mut();
let this = self.eval_context_mut();
loop {
if CTRL_C_RECEIVED.load(Relaxed) {
this.machine.handle_abnormal_termination();
Expand Down

0 comments on commit 9fd99a7

Please sign in to comment.