1
Fork 0

Print a backtrace in const eval if interrupted

This commit is contained in:
Ben Kimock 2023-05-19 16:03:35 -04:00
parent a0c20d52e0
commit 9e0d1a3284
13 changed files with 56 additions and 18 deletions

View file

@ -146,6 +146,8 @@ const_eval_intern_kind = {$kind ->
*[other] {""}
}
const_eval_interrupted = compilation was interrupted
const_eval_invalid_align_details =
invalid align passed to `{$name}`: {$align} is {$err_kind ->
[not_power_of_two] not a power of 2

View file

@ -1,3 +1,5 @@
use std::sync::atomic::Ordering::Relaxed;
use either::{Left, Right};
use rustc_hir::def::DefKind;
@ -22,6 +24,7 @@ use crate::interpret::{
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))]
@ -79,7 +82,11 @@ fn eval_body_using_ecx<'mir, 'tcx, R: InterpretationResult<'tcx>>(
ecx.storage_live_for_always_live_locals()?;
// The main interpreter loop.
while ecx.step()? {}
while ecx.step()? {
if CTRL_C_RECEIVED.load(Relaxed) {
throw_exhaust!(Interrupted);
}
}
// Intern the result
intern_const_alloc_recursive(ecx, intern_kind, &ret)?;

View file

@ -884,6 +884,7 @@ impl ReportErrorExt for ResourceExhaustionInfo {
ResourceExhaustionInfo::StackFrameLimitReached => const_eval_stack_frame_limit_reached,
ResourceExhaustionInfo::MemoryExhausted => const_eval_memory_exhausted,
ResourceExhaustionInfo::AddressSpaceFull => const_eval_address_space_full,
ResourceExhaustionInfo::Interrupted => const_eval_interrupted,
}
}
fn add_args<G: EmissionGuarantee>(self, _: &mut Diag<'_, G>) {}

View file

@ -32,6 +32,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};
@ -57,3 +59,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);