5 use syntax::source_map::{self, Span, DUMMY_SP};
6 use rustc::hir::def_id::DefId;
7 use rustc::hir::def::DefKind;
9 use rustc::ty::layout::{
10 self, Size, Align, HasDataLayout, LayoutOf, TyLayout
12 use rustc::ty::subst::{Subst, SubstsRef};
13 use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
14 use rustc::ty::query::TyCtxtAt;
15 use rustc_data_structures::indexed_vec::IndexVec;
16 use rustc::mir::interpret::{
18 GlobalId, Scalar, Pointer, FrameInfo, AllocId,
19 InterpResult, truncate, sign_extend,
21 use rustc_data_structures::fx::FxHashMap;
24 Immediate, Operand, MemPlace, MPlaceTy, Place, PlaceTy, ScalarMaybeUndef,
28 pub struct InterpCx<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
29 /// Stores the `Machine` instance.
32 /// The results of the type checker, from rustc.
33 pub tcx: TyCtxtAt<'tcx>,
35 /// Bounds in scope for polymorphic evaluations.
36 pub(crate) param_env: ty::ParamEnv<'tcx>,
38 /// The virtual memory system.
39 pub(crate) memory: Memory<'mir, 'tcx, M>,
41 /// The virtual call stack.
42 pub(crate) stack: Vec<Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>>,
44 /// A cache for deduplicating vtables
46 FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), Pointer<M::PointerTag>>,
51 pub struct Frame<'mir, 'tcx, Tag=(), Extra=()> {
52 ////////////////////////////////////////////////////////////////////////////////
53 // Function and callsite information
54 ////////////////////////////////////////////////////////////////////////////////
55 /// The MIR for the function called on this frame.
56 pub body: &'mir mir::Body<'tcx>,
58 /// The def_id and substs of the current function.
59 pub instance: ty::Instance<'tcx>,
61 /// The span of the call site.
62 pub span: source_map::Span,
64 ////////////////////////////////////////////////////////////////////////////////
65 // Return place and locals
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Work to perform when returning from this function.
68 pub return_to_block: StackPopCleanup,
70 /// The location where the result of the current stack frame should be written to,
71 /// and its layout in the caller.
72 pub return_place: Option<PlaceTy<'tcx, Tag>>,
74 /// The list of locals for this stack frame, stored in order as
75 /// `[return_ptr, arguments..., variables..., temporaries...]`.
76 /// The locals are stored as `Option<Value>`s.
77 /// `None` represents a local that is currently dead, while a live local
78 /// can either directly contain `Scalar` or refer to some part of an `Allocation`.
79 pub locals: IndexVec<mir::Local, LocalState<'tcx, Tag>>,
81 ////////////////////////////////////////////////////////////////////////////////
82 // Current position within the function
83 ////////////////////////////////////////////////////////////////////////////////
84 /// The block that is currently executed (or will be executed after the above call stacks
86 pub block: mir::BasicBlock,
88 /// The index of the currently evaluated statement.
91 /// Extra data for the machine.
95 #[derive(Clone, Debug, Eq, PartialEq, Hash)]
96 pub enum StackPopCleanup {
97 /// Jump to the next block in the caller, or cause UB if None (that's a function
98 /// that may never return). Also store layout of return place so
99 /// we can validate it at that layout.
100 Goto(Option<mir::BasicBlock>),
101 /// Just do nohing: Used by Main and for the box_alloc hook in miri.
102 /// `cleanup` says whether locals are deallocated. Static computation
103 /// wants them leaked to intern what they need (and just throw away
104 /// the entire `ecx` when it is done).
105 None { cleanup: bool },
108 /// State of a local variable including a memoized layout
109 #[derive(Clone, PartialEq, Eq)]
110 pub struct LocalState<'tcx, Tag=(), Id=AllocId> {
111 pub value: LocalValue<Tag, Id>,
112 /// Don't modify if `Some`, this is only used to prevent computing the layout twice
113 pub layout: Cell<Option<TyLayout<'tcx>>>,
116 /// Current value of a local variable
117 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
118 pub enum LocalValue<Tag=(), Id=AllocId> {
119 /// This local is not currently alive, and cannot be used at all.
121 /// This local is alive but not yet initialized. It can be written to
122 /// but not read from or its address taken. Locals get initialized on
123 /// first write because for unsized locals, we do not know their size
126 /// A normal, live local.
127 /// Mostly for convenience, we re-use the `Operand` type here.
128 /// This is an optimization over just always having a pointer here;
129 /// we can thus avoid doing an allocation when the local just stores
130 /// immediate values *and* never has its address taken.
131 Live(Operand<Tag, Id>),
134 impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
135 pub fn access(&self) -> InterpResult<'tcx, Operand<Tag>> {
137 LocalValue::Dead => throw_unsup!(DeadLocal),
138 LocalValue::Uninitialized =>
139 bug!("The type checker should prevent reading from a never-written local"),
140 LocalValue::Live(val) => Ok(val),
144 /// Overwrite the local. If the local can be overwritten in place, return a reference
145 /// to do so; otherwise return the `MemPlace` to consult instead.
148 ) -> InterpResult<'tcx, Result<&mut LocalValue<Tag>, MemPlace<Tag>>> {
150 LocalValue::Dead => throw_unsup!(DeadLocal),
151 LocalValue::Live(Operand::Indirect(mplace)) => Ok(Err(mplace)),
152 ref mut local @ LocalValue::Live(Operand::Immediate(_)) |
153 ref mut local @ LocalValue::Uninitialized => {
160 impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> HasDataLayout for InterpCx<'mir, 'tcx, M> {
162 fn data_layout(&self) -> &layout::TargetDataLayout {
163 &self.tcx.data_layout
167 impl<'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for InterpCx<'mir, 'tcx, M>
169 M: Machine<'mir, 'tcx>,
172 fn tcx(&self) -> TyCtxt<'tcx> {
177 impl<'mir, 'tcx, M> layout::HasParamEnv<'tcx> for InterpCx<'mir, 'tcx, M>
179 M: Machine<'mir, 'tcx>,
181 fn param_env(&self) -> ty::ParamEnv<'tcx> {
186 impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for InterpCx<'mir, 'tcx, M> {
188 type TyLayout = InterpResult<'tcx, TyLayout<'tcx>>;
191 fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout {
193 .layout_of(self.param_env.and(ty))
194 .map_err(|layout| err_inval!(Layout(layout)).into())
198 impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
201 param_env: ty::ParamEnv<'tcx>,
203 memory_extra: M::MemoryExtra,
209 memory: Memory::new(tcx, memory_extra),
211 vtables: FxHashMap::default(),
216 pub fn memory(&self) -> &Memory<'mir, 'tcx, M> {
221 pub fn memory_mut(&mut self) -> &mut Memory<'mir, 'tcx, M> {
228 scalar: Scalar<M::PointerTag>,
229 ) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
230 self.memory.force_ptr(scalar)
236 scalar: Scalar<M::PointerTag>,
238 ) -> InterpResult<'tcx, u128> {
239 self.memory.force_bits(scalar, size)
243 pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
244 self.memory.tag_static_base_pointer(ptr)
248 pub fn stack(&self) -> &[Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>] {
253 pub fn cur_frame(&self) -> usize {
254 assert!(self.stack.len() > 0);
259 pub fn frame(&self) -> &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra> {
260 self.stack.last().expect("no call frames exist")
264 pub fn frame_mut(&mut self) -> &mut Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra> {
265 self.stack.last_mut().expect("no call frames exist")
269 pub(super) fn body(&self) -> &'mir mir::Body<'tcx> {
274 pub fn sign_extend(&self, value: u128, ty: TyLayout<'_>) -> u128 {
275 assert!(ty.abi.is_signed());
276 sign_extend(value, ty.size)
280 pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 {
281 truncate(value, ty.size)
285 pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
286 ty.is_sized(self.tcx, self.param_env)
290 pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
291 ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
294 pub(super) fn subst_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
297 ) -> InterpResult<'tcx, T> {
298 match self.stack.last() {
299 Some(frame) => Ok(self.tcx.subst_and_normalize_erasing_regions(
300 frame.instance.substs,
304 None => if substs.needs_subst() {
305 throw_inval!(TooGeneric)
312 pub(super) fn resolve(
315 substs: SubstsRef<'tcx>
316 ) -> InterpResult<'tcx, ty::Instance<'tcx>> {
317 trace!("resolve: {:?}, {:#?}", def_id, substs);
318 trace!("param_env: {:#?}", self.param_env);
319 let substs = self.subst_and_normalize_erasing_regions(substs)?;
320 trace!("substs: {:#?}", substs);
321 ty::Instance::resolve(
326 ).ok_or_else(|| err_inval!(TooGeneric).into())
331 instance: ty::InstanceDef<'tcx>,
332 ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
333 // do not continue if typeck errors occurred (can only occur in local crate)
334 let did = instance.def_id();
336 && self.tcx.has_typeck_tables(did)
337 && self.tcx.typeck_tables_of(did).tainted_by_errors
339 throw_inval!(TypeckError)
341 trace!("load mir {:?}", instance);
343 ty::InstanceDef::Item(def_id) => if self.tcx.is_mir_available(did) {
344 Ok(self.tcx.optimized_mir(did))
346 throw_unsup!(NoMirFor(self.tcx.def_path_str(def_id)))
348 _ => Ok(self.tcx.instance_mir(instance)),
352 pub(super) fn monomorphize<T: TypeFoldable<'tcx> + Subst<'tcx>>(
355 ) -> InterpResult<'tcx, T> {
356 match self.stack.last() {
357 Some(frame) => Ok(self.monomorphize_with_substs(t, frame.instance.substs)?),
358 None => if t.needs_subst() {
359 throw_inval!(TooGeneric)
366 fn monomorphize_with_substs<T: TypeFoldable<'tcx> + Subst<'tcx>>(
369 substs: SubstsRef<'tcx>
370 ) -> InterpResult<'tcx, T> {
371 // miri doesn't care about lifetimes, and will choke on some crazy ones
372 // let's simply get rid of them
373 let substituted = t.subst(*self.tcx, substs);
375 if substituted.needs_subst() {
376 throw_inval!(TooGeneric)
379 Ok(self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substituted))
382 pub fn layout_of_local(
384 frame: &Frame<'mir, 'tcx, M::PointerTag, M::FrameExtra>,
386 layout: Option<TyLayout<'tcx>>,
387 ) -> InterpResult<'tcx, TyLayout<'tcx>> {
388 match frame.locals[local].layout.get() {
390 let layout = crate::interpret::operand::from_known_layout(layout, || {
391 let local_ty = frame.body.local_decls[local].ty;
392 let local_ty = self.monomorphize_with_substs(local_ty, frame.instance.substs)?;
393 self.layout_of(local_ty)
395 // Layouts of locals are requested a lot, so we cache them.
396 frame.locals[local].layout.set(Some(layout));
399 Some(layout) => Ok(layout),
403 /// Returns the actual dynamic size and alignment of the place at the given type.
404 /// Only the "meta" (metadata) part of the place matters.
405 /// This can fail to provide an answer for extern types.
406 pub(super) fn size_and_align_of(
408 metadata: Option<Scalar<M::PointerTag>>,
409 layout: TyLayout<'tcx>,
410 ) -> InterpResult<'tcx, Option<(Size, Align)>> {
411 if !layout.is_unsized() {
412 return Ok(Some((layout.size, layout.align.abi)));
414 match layout.ty.sty {
415 ty::Adt(..) | ty::Tuple(..) => {
416 // First get the size of all statically known fields.
417 // Don't use type_of::sizing_type_of because that expects t to be sized,
418 // and it also rounds up to alignment, which we want to avoid,
419 // as the unsized field's alignment could be smaller.
420 assert!(!layout.ty.is_simd());
421 trace!("DST layout: {:?}", layout);
423 let sized_size = layout.fields.offset(layout.fields.count() - 1);
424 let sized_align = layout.align.abi;
426 "DST {} statically sized prefix size: {:?} align: {:?}",
432 // Recurse to get the size of the dynamically sized field (must be
433 // the last field). Can't have foreign types here, how would we
434 // adjust alignment and size for them?
435 let field = layout.field(self, layout.fields.count() - 1)?;
436 let (unsized_size, unsized_align) = match self.size_and_align_of(metadata, field)? {
437 Some(size_and_align) => size_and_align,
439 // A field with extern type. If this field is at offset 0, we behave
440 // like the underlying extern type.
441 // FIXME: Once we have made decisions for how to handle size and alignment
442 // of `extern type`, this should be adapted. It is just a temporary hack
443 // to get some code to work that probably ought to work.
444 if sized_size == Size::ZERO {
447 bug!("Fields cannot be extern types, unless they are at offset 0")
452 // FIXME (#26403, #27023): We should be adding padding
453 // to `sized_size` (to accommodate the `unsized_align`
454 // required of the unsized field that follows) before
455 // summing it with `sized_size`. (Note that since #26403
456 // is unfixed, we do not yet add the necessary padding
457 // here. But this is where the add would go.)
459 // Return the sum of sizes and max of aligns.
460 let size = sized_size + unsized_size;
462 // Choose max of two known alignments (combined value must
463 // be aligned according to more restrictive of the two).
464 let align = sized_align.max(unsized_align);
466 // Issue #27023: must add any necessary padding to `size`
467 // (to make it a multiple of `align`) before returning it.
469 // Namely, the returned size should be, in C notation:
471 // `size + ((size & (align-1)) ? align : 0)`
473 // emulated via the semi-standard fast bit trick:
475 // `(size + (align-1)) & -align`
477 Ok(Some((size.align_to(align), align)))
480 let vtable = metadata.expect("dyn trait fat ptr must have vtable");
481 // the second entry in the vtable is the dynamic size of the object.
482 Ok(Some(self.read_size_and_align_from_vtable(vtable)?))
485 ty::Slice(_) | ty::Str => {
486 let len = metadata.expect("slice fat ptr must have vtable").to_usize(self)?;
487 let elem = layout.field(self, 0)?;
488 Ok(Some((elem.size * len, elem.align.abi)))
495 _ => bug!("size_and_align_of::<{:?}> not supported", layout.ty),
499 pub fn size_and_align_of_mplace(
501 mplace: MPlaceTy<'tcx, M::PointerTag>
502 ) -> InterpResult<'tcx, Option<(Size, Align)>> {
503 self.size_and_align_of(mplace.meta, mplace.layout)
506 pub fn push_stack_frame(
508 instance: ty::Instance<'tcx>,
509 span: source_map::Span,
510 body: &'mir mir::Body<'tcx>,
511 return_place: Option<PlaceTy<'tcx, M::PointerTag>>,
512 return_to_block: StackPopCleanup,
513 ) -> InterpResult<'tcx> {
514 if self.stack.len() > 0 {
515 info!("PAUSING({}) {}", self.cur_frame(), self.frame().instance);
517 ::log_settings::settings().indentation += 1;
519 // first push a stack frame so we have access to the local substs
520 let extra = M::stack_push(self)?;
521 self.stack.push(Frame {
523 block: mir::START_BLOCK,
526 // empty local array, we fill it in below, after we are inside the stack frame and
527 // all methods actually know about the frame
528 locals: IndexVec::new(),
535 // don't allocate at all for trivial constants
536 if body.local_decls.len() > 1 {
537 // Locals are initially uninitialized.
538 let dummy = LocalState {
539 value: LocalValue::Uninitialized,
540 layout: Cell::new(None),
542 let mut locals = IndexVec::from_elem(dummy, &body.local_decls);
543 // Return place is handled specially by the `eval_place` functions, and the
544 // entry in `locals` should never be used. Make it dead, to be sure.
545 locals[mir::RETURN_PLACE].value = LocalValue::Dead;
546 // Now mark those locals as dead that we do not want to initialize
547 match self.tcx.def_kind(instance.def_id()) {
548 // statics and constants don't have `Storage*` statements, no need to look for them
549 Some(DefKind::Static)
550 | Some(DefKind::Const)
551 | Some(DefKind::AssocConst) => {},
553 trace!("push_stack_frame: {:?}: num_bbs: {}", span, body.basic_blocks().len());
554 for block in body.basic_blocks() {
555 for stmt in block.statements.iter() {
556 use rustc::mir::StatementKind::{StorageDead, StorageLive};
559 StorageDead(local) => {
560 locals[local].value = LocalValue::Dead;
569 self.frame_mut().locals = locals;
572 info!("ENTERING({}) {}", self.cur_frame(), self.frame().instance);
574 if self.stack.len() > self.tcx.sess.const_eval_stack_frame_limit {
575 throw_exhaust!(StackFrameLimitReached)
581 pub(super) fn pop_stack_frame(&mut self) -> InterpResult<'tcx> {
582 info!("LEAVING({}) {}", self.cur_frame(), self.frame().instance);
583 ::log_settings::settings().indentation -= 1;
584 let frame = self.stack.pop().expect(
585 "tried to pop a stack frame, but there were none",
587 M::stack_pop(self, frame.extra)?;
588 // Abort early if we do not want to clean up: We also avoid validation in that case,
589 // because this is CTFE and the final value will be thoroughly validated anyway.
590 match frame.return_to_block {
591 StackPopCleanup::Goto(_) => {},
592 StackPopCleanup::None { cleanup } => {
594 assert!(self.stack.is_empty(), "only the topmost frame should ever be leaked");
595 // Leak the locals, skip validation.
600 // Deallocate all locals that are backed by an allocation.
601 for local in frame.locals {
602 self.deallocate_local(local.value)?;
604 // Validate the return value. Do this after deallocating so that we catch dangling
606 if let Some(return_place) = frame.return_place {
607 if M::enforce_validity(self) {
608 // Data got changed, better make sure it matches the type!
609 // It is still possible that the return place held invalid data while
610 // the function is running, but that's okay because nobody could have
611 // accessed that same data from the "outside" to observe any broken
612 // invariant -- that is, unless a function somehow has a ptr to
613 // its return place... but the way MIR is currently generated, the
614 // return place is always a local and then this cannot happen.
615 self.validate_operand(
616 self.place_to_op(return_place)?,
622 // Uh, that shouldn't happen... the function did not intend to return
623 throw_ub!(Unreachable)
625 // Jump to new block -- *after* validation so that the spans make more sense.
626 match frame.return_to_block {
627 StackPopCleanup::Goto(block) => {
628 self.goto_block(block)?;
630 StackPopCleanup::None { .. } => {}
633 if self.stack.len() > 0 {
634 info!("CONTINUING({}) {}", self.cur_frame(), self.frame().instance);
640 /// Mark a storage as live, killing the previous content and returning it.
641 /// Remember to deallocate that!
645 ) -> InterpResult<'tcx, LocalValue<M::PointerTag>> {
646 assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
647 trace!("{:?} is now live", local);
649 let local_val = LocalValue::Uninitialized;
650 // StorageLive *always* kills the value that's currently stored.
651 // However, we do not error if the variable already is live;
652 // see <https://github.com/rust-lang/rust/issues/42371>.
653 Ok(mem::replace(&mut self.frame_mut().locals[local].value, local_val))
656 /// Returns the old value of the local.
657 /// Remember to deallocate that!
658 pub fn storage_dead(&mut self, local: mir::Local) -> LocalValue<M::PointerTag> {
659 assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
660 trace!("{:?} is now dead", local);
662 mem::replace(&mut self.frame_mut().locals[local].value, LocalValue::Dead)
665 pub(super) fn deallocate_local(
667 local: LocalValue<M::PointerTag>,
668 ) -> InterpResult<'tcx> {
669 // FIXME: should we tell the user that there was a local which was never written to?
670 if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
671 trace!("deallocating local");
672 let ptr = ptr.to_ptr()?;
673 self.memory.dump_alloc(ptr.alloc_id);
674 self.memory.deallocate_local(ptr)?;
679 pub fn const_eval_raw(
682 ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
683 // FIXME(oli-obk): make this check an assertion that it's not a static here
684 // FIXME(RalfJ, oli-obk): document that `Place::Static` can never be anything but a static
685 // and `ConstValue::Unevaluated` can never be a static
686 let param_env = if self.tcx.is_static(gid.instance.def_id()) {
687 ty::ParamEnv::reveal_all()
691 // We use `const_eval_raw` here, and get an unvalidated result. That is okay:
692 // Our result will later be validated anyway, and there seems no good reason
693 // to have to fail early here. This is also more consistent with
694 // `Memory::get_static_alloc` which has to use `const_eval_raw` to avoid cycles.
695 let val = self.tcx.const_eval_raw(param_env.and(gid)).map_err(|err| {
697 ErrorHandled::Reported =>
698 err_inval!(ReferencedConstant),
699 ErrorHandled::TooGeneric =>
700 err_inval!(TooGeneric),
703 self.raw_const_to_mplace(val)
706 pub fn dump_place(&self, place: Place<M::PointerTag>) {
708 if !log_enabled!(::log::Level::Trace) {
712 Place::Local { frame, local } => {
713 let mut allocs = Vec::new();
714 let mut msg = format!("{:?}", local);
715 if frame != self.cur_frame() {
716 write!(msg, " ({} frames up)", self.cur_frame() - frame).unwrap();
718 write!(msg, ":").unwrap();
720 match self.stack[frame].locals[local].value {
721 LocalValue::Dead => write!(msg, " is dead").unwrap(),
722 LocalValue::Uninitialized => write!(msg, " is uninitialized").unwrap(),
723 LocalValue::Live(Operand::Indirect(mplace)) => {
725 Scalar::Ptr(ptr) => {
726 write!(msg, " by align({}){} ref:",
727 mplace.align.bytes(),
729 Some(meta) => format!(" meta({:?})", meta),
730 None => String::new()
733 allocs.push(ptr.alloc_id);
735 ptr => write!(msg, " by integral ref: {:?}", ptr).unwrap(),
738 LocalValue::Live(Operand::Immediate(Immediate::Scalar(val))) => {
739 write!(msg, " {:?}", val).unwrap();
740 if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val {
741 allocs.push(ptr.alloc_id);
744 LocalValue::Live(Operand::Immediate(Immediate::ScalarPair(val1, val2))) => {
745 write!(msg, " ({:?}, {:?})", val1, val2).unwrap();
746 if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val1 {
747 allocs.push(ptr.alloc_id);
749 if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val2 {
750 allocs.push(ptr.alloc_id);
756 self.memory.dump_allocs(allocs);
758 Place::Ptr(mplace) => {
760 Scalar::Ptr(ptr) => {
761 trace!("by align({}) ref:", mplace.align.bytes());
762 self.memory.dump_alloc(ptr.alloc_id);
764 ptr => trace!(" integral by ref: {:?}", ptr),
770 pub fn generate_stacktrace(&self, explicit_span: Option<Span>) -> Vec<FrameInfo<'tcx>> {
771 let mut last_span = None;
772 let mut frames = Vec::new();
773 for &Frame { instance, span, body, block, stmt, .. } in self.stack().iter().rev() {
774 // make sure we don't emit frames that are duplicates of the previous
775 if explicit_span == Some(span) {
776 last_span = Some(span);
779 if let Some(last) = last_span {
784 last_span = Some(span);
786 let block = &body.basic_blocks()[block];
787 let source_info = if stmt < block.statements.len() {
788 block.statements[stmt].source_info
790 block.terminator().source_info
792 let lint_root = match body.source_scope_local_data {
793 mir::ClearCrossCrate::Set(ref ivs) => Some(ivs[source_info.scope].lint_root),
794 mir::ClearCrossCrate::Clear => None,
796 frames.push(FrameInfo { call_site: span, instance, lint_root });
798 trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);