Skip to content

Commit 9fd99a7

Browse files
committed
Rearrange where components live
1 parent 197e4ca commit 9fd99a7

File tree

6 files changed

+30
-34
lines changed

6 files changed

+30
-34
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::sync::atomic::Ordering::Relaxed;
22

33
use either::{Left, Right};
44

5-
use rustc_data_structures::CTRL_C_RECEIVED;
65
use rustc_hir::def::DefKind;
76
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo};
87
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
@@ -25,6 +24,7 @@ use crate::interpret::{
2524
GlobalId, Immediate, InternKind, InterpCx, InterpError, InterpResult, MPlaceTy, MemoryKind,
2625
OpTy, RefTracking, StackPopCleanup,
2726
};
27+
use crate::CTRL_C_RECEIVED;
2828

2929
// Returns a pointer to where the result lives
3030
#[instrument(level = "trace", skip(ecx, body), ret)]

compiler/rustc_const_eval/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub mod interpret;
3131
pub mod transform;
3232
pub mod util;
3333

34+
use std::sync::atomic::AtomicBool;
35+
3436
pub use errors::ReportErrorExt;
3537

3638
use rustc_middle::{ty, util::Providers};
@@ -56,3 +58,8 @@ pub fn provide(providers: &mut Providers) {
5658
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
5759
};
5860
}
61+
62+
/// `rustc_driver::main` installs a handler that will set this to `true` if
63+
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
64+
/// This static lives here because it is only read by the interpreter.
65+
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);

compiler/rustc_data_structures/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ extern crate tracing;
4646
extern crate rustc_macros;
4747

4848
use std::fmt;
49-
use std::sync::atomic::AtomicBool;
5049

5150
pub use rustc_index::static_assert_size;
5251

@@ -162,8 +161,3 @@ macro_rules! external_bitflags_debug {
162161
}
163162
};
164163
}
165-
166-
/// `rustc_driver::main` installs a handler that will set this to `true` if
167-
/// the compiler has been sent a request to shut down, such as by a Ctrl-C.
168-
/// This static is placed here so that it is available to all parts of the compiler.
169-
pub static CTRL_C_RECEIVED: AtomicBool = AtomicBool::new(false);

compiler/rustc_driver_impl/src/lib.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ extern crate tracing;
1919

2020
use rustc_ast as ast;
2121
use rustc_codegen_ssa::{traits::CodegenBackend, CodegenErrors, CodegenResults};
22+
use rustc_const_eval::CTRL_C_RECEIVED;
2223
use rustc_data_structures::profiling::{
2324
get_resident_set_size, print_time_passes_entry, TimePassesFormat,
2425
};
25-
use rustc_data_structures::CTRL_C_RECEIVED;
2626
use rustc_errors::emitter::stderr_destination;
2727
use rustc_errors::registry::Registry;
2828
use rustc_errors::{
@@ -1506,17 +1506,9 @@ pub fn init_logger(early_dcx: &EarlyDiagCtxt, cfg: rustc_log::LoggerConfig) {
15061506
}
15071507
}
15081508

1509-
pub fn main() -> ! {
1510-
let start_time = Instant::now();
1511-
let start_rss = get_resident_set_size();
1512-
1513-
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
1514-
1515-
init_rustc_env_logger(&early_dcx);
1516-
signal_handler::install();
1517-
let mut callbacks = TimePassesCallbacks::default();
1518-
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
1519-
1509+
/// Install our usual `ctrlc` handler, which sets [`rustc_const_eval::CTRL_C_RECEIVED`].
1510+
/// Makign this handler optional lets tools can install a different handler, if they wish.
1511+
pub fn install_ctrlc_handler() {
15201512
ctrlc::set_handler(move || {
15211513
// Indicate that we have been signaled to stop. If we were already signaled, exit
15221514
// immediately. In our interpreter loop we try to consult this value often, but if for
@@ -1528,6 +1520,19 @@ pub fn main() -> ! {
15281520
}
15291521
})
15301522
.expect("Unable to install ctrlc handler");
1523+
}
1524+
1525+
pub fn main() -> ! {
1526+
let start_time = Instant::now();
1527+
let start_rss = get_resident_set_size();
1528+
1529+
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
1530+
1531+
init_rustc_env_logger(&early_dcx);
1532+
signal_handler::install();
1533+
let mut callbacks = TimePassesCallbacks::default();
1534+
let using_internal_features = install_ice_hook(DEFAULT_BUG_REPORT_URL, |_| ());
1535+
install_ctrlc_handler();
15311536

15321537
let exit_code = catch_with_exit_code(|| {
15331538
RunCompiler::new(&args::raw_args(&early_dcx)?, &mut callbacks)

src/tools/miri/src/bin/miri.rs

+3
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ fn main() {
372372
let using_internal_features =
373373
rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ());
374374

375+
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`.
376+
rustc_driver::install_ctrlc_handler();
377+
375378
// Init loggers the Miri way.
376379
init_early_loggers(&early_dcx);
377380

src/tools/miri/src/concurrency/thread.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use std::time::{Duration, SystemTime};
99

1010
use either::Either;
1111

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

0 commit comments

Comments
 (0)