Skip to content

Commit a03c064

Browse files
committed
Auto merge of #111769 - saethlin:ctfe-backtrace-ctrlc, r=RalfJung
Print a backtrace in const eval if interrupted Demo: ```rust #![feature(const_eval_limit)] #![const_eval_limit = "0"] const OW: u64 = { let mut res: u64 = 0; let mut i = 0; while i < u64::MAX { res = res.wrapping_add(i); i += 1; } res }; fn main() { println!("{}", OW); } ``` ``` ╭ ➜ ben@archlinux:~/rust ╰ ➤ rustc +stage1 spin.rs ^Cerror[E0080]: evaluation of constant value failed --> spin.rs:8:33 | 8 | res = res.wrapping_add(i); | ^ Compilation was interrupted note: erroneous constant used --> spin.rs:15:20 | 15 | println!("{}", OW); | ^^ note: erroneous constant used --> spin.rs:15:20 | 15 | println!("{}", OW); | ^^ | = note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. ```
2 parents cfa7239 + a401a45 commit a03c064

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/bin/miri.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,10 @@ fn main() {
364364
let args = rustc_driver::args::raw_args(&early_dcx)
365365
.unwrap_or_else(|_| std::process::exit(rustc_driver::EXIT_FAILURE));
366366

367+
// Install the ctrlc handler that sets `rustc_const_eval::CTRL_C_RECEIVED`, even if
368+
// MIRI_BE_RUSTC is set.
369+
rustc_driver::install_ctrlc_handler();
370+
367371
// If the environment asks us to actually be rustc, then do that.
368372
if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") {
369373
// Earliest rustc setup.

src/concurrency/thread.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
use std::cell::RefCell;
44
use std::collections::hash_map::Entry;
55
use std::num::TryFromIntError;
6-
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
6+
use std::sync::atomic::Ordering::Relaxed;
77
use std::task::Poll;
88
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;
1314
use rustc_hir::def_id::DefId;
1415
use rustc_index::{Idx, IndexVec};
@@ -1045,21 +1046,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10451046
/// Run the core interpreter loop. Returns only when an interrupt occurs (an error or program
10461047
/// termination).
10471048
fn run_threads(&mut self) -> InterpResult<'tcx, !> {
1048-
static SIGNALED: AtomicBool = AtomicBool::new(false);
1049-
ctrlc::set_handler(move || {
1050-
// Indicate that we have ben signaled to stop. If we were already signaled, exit
1051-
// immediately. In our interpreter loop we try to consult this value often, but if for
1052-
// whatever reason we don't get to that check or the cleanup we do upon finding that
1053-
// this bool has become true takes a long time, the exit here will promptly exit the
1054-
// process on the second Ctrl-C.
1055-
if SIGNALED.swap(true, Relaxed) {
1056-
std::process::exit(1);
1057-
}
1058-
})
1059-
.unwrap();
1060-
let this = self.eval_context_mut();
1049+
let this = self.eval_context_mut();
10611050
loop {
1062-
if SIGNALED.load(Relaxed) {
1051+
if CTRL_C_RECEIVED.load(Relaxed) {
10631052
this.machine.handle_abnormal_termination();
10641053
std::process::exit(1);
10651054
}

0 commit comments

Comments
 (0)