Skip to content

Commit 8c0f8a2

Browse files
authored
Rollup merge of rust-lang#101985 - RalfJung:generate_stacktrace, r=oli-obk
interpret: expose generate_stacktrace without full InterpCx In Miri we sometimes want to emit diagnostics without having a full `&InterpCx` available. To avoid duplicating code, this adds a way to get a stacktrace from an arbitrary slice of interpreter frames, that Miri can use with access to just a thread manager.
2 parents 33a2242 + 9fa3171 commit 8c0f8a2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
929929
}
930930

931931
#[must_use]
932-
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
932+
pub fn generate_stacktrace_from_stack(
933+
stack: &[Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>],
934+
) -> Vec<FrameInfo<'tcx>> {
933935
let mut frames = Vec::new();
934936
// This deliberately does *not* honor `requires_caller_location` since it is used for much
935937
// more than just panics.
936-
for frame in self.stack().iter().rev() {
938+
for frame in stack.iter().rev() {
937939
let lint_root = frame.current_source_info().and_then(|source_info| {
938940
match &frame.body.source_scopes[source_info.scope].local_data {
939941
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
@@ -947,6 +949,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
947949
trace!("generate stacktrace: {:#?}", frames);
948950
frames
949951
}
952+
953+
#[must_use]
954+
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
955+
Self::generate_stacktrace_from_stack(self.stack())
956+
}
950957
}
951958

952959
#[doc(hidden)]

0 commit comments

Comments
 (0)