Skip to content

Commit

Permalink
Rollup merge of #101985 - RalfJung:generate_stacktrace, r=oli-obk
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthiaskrgr authored Sep 19, 2022
2 parents 33a2242 + 9fa3171 commit 8c0f8a2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}

#[must_use]
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
pub fn generate_stacktrace_from_stack(
stack: &[Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>],
) -> Vec<FrameInfo<'tcx>> {
let mut frames = Vec::new();
// This deliberately does *not* honor `requires_caller_location` since it is used for much
// more than just panics.
for frame in self.stack().iter().rev() {
for frame in stack.iter().rev() {
let lint_root = frame.current_source_info().and_then(|source_info| {
match &frame.body.source_scopes[source_info.scope].local_data {
mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
Expand All @@ -947,6 +949,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
trace!("generate stacktrace: {:#?}", frames);
frames
}

#[must_use]
pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
Self::generate_stacktrace_from_stack(self.stack())
}
}

#[doc(hidden)]
Expand Down

0 comments on commit 8c0f8a2

Please sign in to comment.