rustc_const_eval/interpret/
step.rs

1//! This module contains the `InterpCx` methods for executing a single step of the interpreter.
2//!
3//! The main entry point is the `step` method.
4
5use std::iter;
6
7use either::Either;
8use rustc_abi::{FIRST_VARIANT, FieldIdx};
9use rustc_data_structures::fx::FxHashSet;
10use rustc_index::IndexSlice;
11use rustc_middle::ty::{self, Instance, Ty};
12use rustc_middle::{bug, mir, span_bug};
13use rustc_span::source_map::Spanned;
14use rustc_target::callconv::FnAbi;
15use tracing::field::Empty;
16use tracing::{info, instrument, trace};
17
18use super::{
19    FnArg, FnVal, ImmTy, Immediate, InterpCx, InterpResult, Machine, MemPlaceMeta, PlaceTy,
20    Projectable, interp_ok, throw_ub, throw_unsup_format,
21};
22use crate::interpret::EnteredTraceSpan;
23use crate::{enter_trace_span, util};
24
25struct EvaluatedCalleeAndArgs<'tcx, M: Machine<'tcx>> {
26    callee: FnVal<'tcx, M::ExtraFnVal>,
27    args: Vec<FnArg<'tcx, M::Provenance>>,
28    fn_sig: ty::FnSig<'tcx>,
29    fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
30    /// True if the function is marked as `#[track_caller]` ([`ty::InstanceKind::requires_caller_location`])
31    with_caller_location: bool,
32}
33
34impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
35    /// Returns `true` as long as there are more things to do.
36    ///
37    /// This is used by [priroda](https://github.com/oli-obk/priroda)
38    ///
39    /// This is marked `#inline(always)` to work around adversarial codegen when `opt-level = 3`
40    #[inline(always)]
41    pub fn step(&mut self) -> InterpResult<'tcx, bool> {
42        if self.stack().is_empty() {
43            return interp_ok(false);
44        }
45
46        let Either::Left(loc) = self.frame().loc else {
47            // We are unwinding and this fn has no cleanup code.
48            // Just go on unwinding.
49            trace!("unwinding: skipping frame");
50            self.return_from_current_stack_frame(/* unwinding */ true)?;
51            return interp_ok(true);
52        };
53        let basic_block = &self.body().basic_blocks[loc.block];
54
55        if let Some(stmt) = basic_block.statements.get(loc.statement_index) {
56            let old_frames = self.frame_idx();
57            self.eval_statement(stmt)?;
58            // Make sure we are not updating `statement_index` of the wrong frame.
59            assert_eq!(old_frames, self.frame_idx());
60            // Advance the program counter.
61            self.frame_mut().loc.as_mut().left().unwrap().statement_index += 1;
62            return interp_ok(true);
63        }
64
65        M::before_terminator(self)?;
66
67        let terminator = basic_block.terminator();
68        self.eval_terminator(terminator)?;
69        if !self.stack().is_empty() {
70            if let Either::Left(loc) = self.frame().loc {
71                info!("// executing {:?}", loc.block);
72            }
73        }
74        interp_ok(true)
75    }
76
77    /// Runs the interpretation logic for the given `mir::Statement` at the current frame and
78    /// statement counter.
79    ///
80    /// This does NOT move the statement counter forward, the caller has to do that!
81    pub fn eval_statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> {
82        let _trace = enter_trace_span!(
83            M,
84            step::eval_statement,
85            stmt = ?stmt.kind,
86            span = ?stmt.source_info.span,
87            tracing_separate_thread = Empty,
88        )
89        .or_if_tracing_disabled(|| info!(stmt = ?stmt.kind));
90
91        use rustc_middle::mir::StatementKind::*;
92
93        match &stmt.kind {
94            Assign(box (place, rvalue)) => self.eval_rvalue_into_place(rvalue, *place)?,
95
96            SetDiscriminant { place, variant_index } => {
97                let dest = self.eval_place(**place)?;
98                self.write_discriminant(*variant_index, &dest)?;
99            }
100
101            // Mark locals as alive
102            StorageLive(local) => {
103                self.storage_live(*local)?;
104            }
105
106            // Mark locals as dead
107            StorageDead(local) => {
108                self.storage_dead(*local)?;
109            }
110
111            // No dynamic semantics attached to `FakeRead`; MIR
112            // interpreter is solely intended for borrowck'ed code.
113            FakeRead(..) => {}
114
115            // Stacked Borrows.
116            Retag(kind, place) => {
117                let dest = self.eval_place(**place)?;
118                M::retag_place_contents(self, *kind, &dest)?;
119            }
120
121            Intrinsic(box intrinsic) => self.eval_nondiverging_intrinsic(intrinsic)?,
122
123            // Evaluate the place expression, without reading from it.
124            PlaceMention(box place) => {
125                let _ = self.eval_place(*place)?;
126            }
127
128            // This exists purely to guide borrowck lifetime inference, and does not have
129            // an operational effect.
130            AscribeUserType(..) => {}
131
132            // Currently, Miri discards Coverage statements. Coverage statements are only injected
133            // via an optional compile time MIR pass and have no side effects. Since Coverage
134            // statements don't exist at the source level, it is safe for Miri to ignore them, even
135            // for undefined behavior (UB) checks.
136            //
137            // A coverage counter inside a const expression (for example, a counter injected in a
138            // const function) is discarded when the const is evaluated at compile time. Whether
139            // this should change, and/or how to implement a const eval counter, is a subject of the
140            // following issue:
141            //
142            // FIXME(#73156): Handle source code coverage in const eval
143            Coverage(..) => {}
144
145            ConstEvalCounter => {
146                M::increment_const_eval_counter(self)?;
147            }
148
149            // Defined to do nothing. These are added by optimization passes, to avoid changing the
150            // size of MIR constantly.
151            Nop => {}
152
153            // Only used for temporary lifetime lints
154            BackwardIncompatibleDropHint { .. } => {}
155        }
156
157        interp_ok(())
158    }
159
160    /// Evaluate an assignment statement.
161    ///
162    /// There is no separate `eval_rvalue` function. Instead, the code for handling each rvalue
163    /// type writes its results directly into the memory specified by the place.
164    pub fn eval_rvalue_into_place(
165        &mut self,
166        rvalue: &mir::Rvalue<'tcx>,
167        place: mir::Place<'tcx>,
168    ) -> InterpResult<'tcx> {
169        let dest = self.eval_place(place)?;
170        // FIXME: ensure some kind of non-aliasing between LHS and RHS?
171        // Also see https://github.com/rust-lang/rust/issues/68364.
172
173        use rustc_middle::mir::Rvalue::*;
174        match *rvalue {
175            ThreadLocalRef(did) => {
176                let ptr = M::thread_local_static_pointer(self, did)?;
177                self.write_pointer(ptr, &dest)?;
178            }
179
180            Use(ref operand) => {
181                // Avoid recomputing the layout
182                let op = self.eval_operand(operand, Some(dest.layout))?;
183                self.copy_op(&op, &dest)?;
184            }
185
186            CopyForDeref(_) => bug!("`CopyForDeref` in runtime MIR"),
187
188            BinaryOp(bin_op, box (ref left, ref right)) => {
189                let layout = util::binop_left_homogeneous(bin_op).then_some(dest.layout);
190                let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
191                let layout = util::binop_right_homogeneous(bin_op).then_some(left.layout);
192                let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
193                let result = self.binary_op(bin_op, &left, &right)?;
194                assert_eq!(result.layout, dest.layout, "layout mismatch for result of {bin_op:?}");
195                self.write_immediate(*result, &dest)?;
196            }
197
198            UnaryOp(un_op, ref operand) => {
199                // The operand always has the same type as the result.
200                let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?;
201                let result = self.unary_op(un_op, &val)?;
202                assert_eq!(result.layout, dest.layout, "layout mismatch for result of {un_op:?}");
203                self.write_immediate(*result, &dest)?;
204            }
205
206            NullaryOp(null_op) => {
207                let val = self.nullary_op(null_op)?;
208                self.write_immediate(*val, &dest)?;
209            }
210
211            Aggregate(box ref kind, ref operands) => {
212                self.write_aggregate(kind, operands, &dest)?;
213            }
214
215            Repeat(ref operand, _) => {
216                self.write_repeat(operand, &dest)?;
217            }
218
219            Ref(_, borrow_kind, place) => {
220                let src = self.eval_place(place)?;
221                let place = self.force_allocation(&src)?;
222                let val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
223                // A fresh reference was created, make sure it gets retagged.
224                let val = M::retag_ptr_value(
225                    self,
226                    if borrow_kind.allows_two_phase_borrow() {
227                        mir::RetagKind::TwoPhase
228                    } else {
229                        mir::RetagKind::Default
230                    },
231                    &val,
232                )?;
233                self.write_immediate(*val, &dest)?;
234            }
235
236            RawPtr(kind, place) => {
237                // Figure out whether this is an addr_of of an already raw place.
238                let place_base_raw = if place.is_indirect_first_projection() {
239                    let ty = self.frame().body.local_decls[place.local].ty;
240                    ty.is_raw_ptr()
241                } else {
242                    // Not a deref, and thus not raw.
243                    false
244                };
245
246                let src = self.eval_place(place)?;
247                let place = self.force_allocation(&src)?;
248                let mut val = ImmTy::from_immediate(place.to_ref(self), dest.layout);
249                if !place_base_raw && !kind.is_fake() {
250                    // If this was not already raw, it needs retagging -- except for "fake"
251                    // raw borrows whose defining property is that they do not get retagged.
252                    val = M::retag_ptr_value(self, mir::RetagKind::Raw, &val)?;
253                }
254                self.write_immediate(*val, &dest)?;
255            }
256
257            ShallowInitBox(ref operand, _) => {
258                let src = self.eval_operand(operand, None)?;
259                let v = self.read_immediate(&src)?;
260                self.write_immediate(*v, &dest)?;
261            }
262
263            Cast(cast_kind, ref operand, cast_ty) => {
264                let src = self.eval_operand(operand, None)?;
265                let cast_ty =
266                    self.instantiate_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
267                self.cast(&src, cast_kind, cast_ty, &dest)?;
268            }
269
270            Discriminant(place) => {
271                let op = self.eval_place_to_op(place, None)?;
272                let variant = self.read_discriminant(&op)?;
273                let discr = self.discriminant_for_variant(op.layout.ty, variant)?;
274                self.write_immediate(*discr, &dest)?;
275            }
276
277            WrapUnsafeBinder(ref op, _ty) => {
278                // Constructing an unsafe binder acts like a transmute
279                // since the operand's layout does not change.
280                let op = self.eval_operand(op, None)?;
281                self.copy_op_allow_transmute(&op, &dest)?;
282            }
283        }
284
285        trace!("{:?}", self.dump_place(&dest));
286
287        interp_ok(())
288    }
289
290    /// Writes the aggregate to the destination.
291    #[instrument(skip(self), level = "trace")]
292    fn write_aggregate(
293        &mut self,
294        kind: &mir::AggregateKind<'tcx>,
295        operands: &IndexSlice<FieldIdx, mir::Operand<'tcx>>,
296        dest: &PlaceTy<'tcx, M::Provenance>,
297    ) -> InterpResult<'tcx> {
298        let (variant_index, variant_dest, active_field_index) = match *kind {
299            mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
300                let variant_dest = self.project_downcast(dest, variant_index)?;
301                (variant_index, variant_dest, active_field_index)
302            }
303            mir::AggregateKind::RawPtr(..) => {
304                // Pointers don't have "fields" in the normal sense, so the
305                // projection-based code below would either fail in projection
306                // or in type mismatches. Instead, build an `Immediate` from
307                // the parts and write that to the destination.
308                let [data, meta] = &operands.raw else {
309                    bug!("{kind:?} should have 2 operands, had {operands:?}");
310                };
311                let data = self.eval_operand(data, None)?;
312                let data = self.read_pointer(&data)?;
313                let meta = self.eval_operand(meta, None)?;
314                let meta = if meta.layout.is_zst() {
315                    MemPlaceMeta::None
316                } else {
317                    MemPlaceMeta::Meta(self.read_scalar(&meta)?)
318                };
319                let ptr_imm = Immediate::new_pointer_with_meta(data, meta, self);
320                let ptr = ImmTy::from_immediate(ptr_imm, dest.layout);
321                self.copy_op(&ptr, dest)?;
322                return interp_ok(());
323            }
324            _ => (FIRST_VARIANT, dest.clone(), None),
325        };
326        if active_field_index.is_some() {
327            assert_eq!(operands.len(), 1);
328        }
329        for (field_index, operand) in operands.iter_enumerated() {
330            let field_index = active_field_index.unwrap_or(field_index);
331            let field_dest = self.project_field(&variant_dest, field_index)?;
332            let op = self.eval_operand(operand, Some(field_dest.layout))?;
333            // We validate manually below so we don't have to do it here.
334            self.copy_op_no_validate(&op, &field_dest, /*allow_transmute*/ false)?;
335        }
336        self.write_discriminant(variant_index, dest)?;
337        // Validate that the entire thing is valid, and reset padding that might be in between the
338        // fields.
339        if M::enforce_validity(self, dest.layout()) {
340            self.validate_operand(
341                dest,
342                M::enforce_validity_recursively(self, dest.layout()),
343                /*reset_provenance_and_padding*/ true,
344            )?;
345        }
346        interp_ok(())
347    }
348
349    /// Repeats `operand` into the destination. `dest` must have array type, and that type
350    /// determines how often `operand` is repeated.
351    fn write_repeat(
352        &mut self,
353        operand: &mir::Operand<'tcx>,
354        dest: &PlaceTy<'tcx, M::Provenance>,
355    ) -> InterpResult<'tcx> {
356        let src = self.eval_operand(operand, None)?;
357        assert!(src.layout.is_sized());
358        let dest = self.force_allocation(&dest)?;
359        let length = dest.len(self)?;
360
361        if length == 0 {
362            // Nothing to copy... but let's still make sure that `dest` as a place is valid.
363            self.get_place_alloc_mut(&dest)?;
364        } else {
365            // Write the src to the first element.
366            let first = self.project_index(&dest, 0)?;
367            self.copy_op(&src, &first)?;
368
369            // This is performance-sensitive code for big static/const arrays! So we
370            // avoid writing each operand individually and instead just make many copies
371            // of the first element.
372            let elem_size = first.layout.size;
373            let first_ptr = first.ptr();
374            let rest_ptr = first_ptr.wrapping_offset(elem_size, self);
375            // No alignment requirement since `copy_op` above already checked it.
376            self.mem_copy_repeatedly(
377                first_ptr,
378                rest_ptr,
379                elem_size,
380                length - 1,
381                /*nonoverlapping:*/ true,
382            )?;
383        }
384
385        interp_ok(())
386    }
387
388    /// Evaluate the arguments of a function call
389    fn eval_fn_call_argument(
390        &mut self,
391        op: &mir::Operand<'tcx>,
392        move_definitely_disjoint: bool,
393    ) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>> {
394        interp_ok(match op {
395            mir::Operand::Copy(_) | mir::Operand::Constant(_) => {
396                // Make a regular copy.
397                let op = self.eval_operand(op, None)?;
398                FnArg::Copy(op)
399            }
400            mir::Operand::Move(place) => {
401                let place = self.eval_place(*place)?;
402                if move_definitely_disjoint {
403                    // We still have to ensure that no *other* pointers are used to access this place,
404                    // so *if* it is in memory then we have to treat it as `InPlace`.
405                    // Use `place_to_op` to guarantee that we notice it being in memory.
406                    let op = self.place_to_op(&place)?;
407                    match op.as_mplace_or_imm() {
408                        Either::Left(mplace) => FnArg::InPlace(mplace),
409                        Either::Right(_imm) => FnArg::Copy(op),
410                    }
411                } else {
412                    // We have to force this into memory to detect aliasing among `Move` arguments.
413                    FnArg::InPlace(self.force_allocation(&place)?)
414                }
415            }
416        })
417    }
418
419    /// Shared part of `Call` and `TailCall` implementation — finding and evaluating all the
420    /// necessary information about callee and arguments to make a call.
421    fn eval_callee_and_args(
422        &mut self,
423        terminator: &mir::Terminator<'tcx>,
424        func: &mir::Operand<'tcx>,
425        args: &[Spanned<mir::Operand<'tcx>>],
426        dest: &mir::Place<'tcx>,
427    ) -> InterpResult<'tcx, EvaluatedCalleeAndArgs<'tcx, M>> {
428        let func = self.eval_operand(func, None)?;
429
430        // Evaluating function call arguments. The tricky part here is dealing with `Move`
431        // arguments: we have to ensure no two such arguments alias. This would be most easily done
432        // by just forcing them all into memory and then doing the usual in-place argument
433        // protection, but then we'd force *a lot* of arguments into memory. So we do some syntactic
434        // pre-processing here where if all `move` arguments are syntactically distinct local
435        // variables (and none is indirect), we can skip the in-memory forcing.
436        // We have to include `dest` in that list so that we can detect aliasing of an in-place
437        // argument with the return place.
438        let move_definitely_disjoint = 'move_definitely_disjoint: {
439            let mut previous_locals = FxHashSet::<mir::Local>::default();
440            for place in args
441                .iter()
442                .filter_map(|a| {
443                    // We only have to care about `Move` arguments.
444                    if let mir::Operand::Move(place) = &a.node { Some(place) } else { None }
445                })
446                .chain(iter::once(dest))
447            {
448                if place.is_indirect_first_projection() {
449                    // An indirect in-place argument could alias with anything else...
450                    break 'move_definitely_disjoint false;
451                }
452                if !previous_locals.insert(place.local) {
453                    // This local is the base for two arguments! They might overlap.
454                    break 'move_definitely_disjoint false;
455                }
456            }
457            // We found no violation so they are all definitely disjoint.
458            true
459        };
460        let args = args
461            .iter()
462            .map(|arg| self.eval_fn_call_argument(&arg.node, move_definitely_disjoint))
463            .collect::<InterpResult<'tcx, Vec<_>>>()?;
464
465        let fn_sig_binder = {
466            let _trace = enter_trace_span!(M, "fn_sig", ty = ?func.layout.ty.kind());
467            func.layout.ty.fn_sig(*self.tcx)
468        };
469        let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.typing_env, fn_sig_binder);
470        let extra_args = &args[fn_sig.inputs().len()..];
471        let extra_args =
472            self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout().ty));
473
474        let (callee, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
475            ty::FnPtr(..) => {
476                let fn_ptr = self.read_pointer(&func)?;
477                let fn_val = self.get_ptr_fn(fn_ptr)?;
478                (fn_val, self.fn_abi_of_fn_ptr(fn_sig_binder, extra_args)?, false)
479            }
480            ty::FnDef(def_id, args) => {
481                let instance = self.resolve(def_id, args)?;
482                (
483                    FnVal::Instance(instance),
484                    self.fn_abi_of_instance(instance, extra_args)?,
485                    instance.def.requires_caller_location(*self.tcx),
486                )
487            }
488            _ => {
489                span_bug!(terminator.source_info.span, "invalid callee of type {}", func.layout.ty)
490            }
491        };
492
493        interp_ok(EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location })
494    }
495
496    fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> {
497        let _trace = enter_trace_span!(
498            M,
499            step::eval_terminator,
500            terminator = ?terminator.kind,
501            span = ?terminator.source_info.span,
502            tracing_separate_thread = Empty,
503        )
504        .or_if_tracing_disabled(|| info!(terminator = ?terminator.kind));
505
506        use rustc_middle::mir::TerminatorKind::*;
507        match terminator.kind {
508            Return => {
509                self.return_from_current_stack_frame(/* unwinding */ false)?
510            }
511
512            Goto { target } => self.go_to_block(target),
513
514            SwitchInt { ref discr, ref targets } => {
515                let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
516                trace!("SwitchInt({:?})", *discr);
517
518                // Branch to the `otherwise` case by default, if no match is found.
519                let mut target_block = targets.otherwise();
520
521                for (const_int, target) in targets.iter() {
522                    // Compare using MIR BinOp::Eq, to also support pointer values.
523                    // (Avoiding `self.binary_op` as that does some redundant layout computation.)
524                    let res = self.binary_op(
525                        mir::BinOp::Eq,
526                        &discr,
527                        &ImmTy::from_uint(const_int, discr.layout),
528                    )?;
529                    if res.to_scalar().to_bool()? {
530                        target_block = target;
531                        break;
532                    }
533                }
534
535                self.go_to_block(target_block);
536            }
537
538            Call {
539                ref func,
540                ref args,
541                destination,
542                target,
543                unwind,
544                call_source: _,
545                fn_span: _,
546            } => {
547                let old_stack = self.frame_idx();
548                let old_loc = self.frame().loc;
549
550                let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =
551                    self.eval_callee_and_args(terminator, func, args, &destination)?;
552
553                let destination = self.eval_place(destination)?;
554                self.init_fn_call(
555                    callee,
556                    (fn_sig.abi, fn_abi),
557                    &args,
558                    with_caller_location,
559                    &destination,
560                    target,
561                    if fn_abi.can_unwind { unwind } else { mir::UnwindAction::Unreachable },
562                )?;
563                // Sanity-check that `eval_fn_call` either pushed a new frame or
564                // did a jump to another block.
565                if self.frame_idx() == old_stack && self.frame().loc == old_loc {
566                    span_bug!(terminator.source_info.span, "evaluating this call made no progress");
567                }
568            }
569
570            TailCall { ref func, ref args, fn_span: _ } => {
571                let old_frame_idx = self.frame_idx();
572
573                let EvaluatedCalleeAndArgs { callee, args, fn_sig, fn_abi, with_caller_location } =
574                    self.eval_callee_and_args(terminator, func, args, &mir::Place::return_place())?;
575
576                self.init_fn_tail_call(callee, (fn_sig.abi, fn_abi), &args, with_caller_location)?;
577
578                if self.frame_idx() != old_frame_idx {
579                    span_bug!(
580                        terminator.source_info.span,
581                        "evaluating this tail call pushed a new stack frame"
582                    );
583                }
584            }
585
586            Drop { place, target, unwind, replace: _, drop, async_fut } => {
587                assert!(
588                    async_fut.is_none() && drop.is_none(),
589                    "Async Drop must be expanded or reset to sync in runtime MIR"
590                );
591                let place = self.eval_place(place)?;
592                let instance = {
593                    let _trace =
594                        enter_trace_span!(M, resolve::resolve_drop_in_place, ty = ?place.layout.ty);
595                    Instance::resolve_drop_in_place(*self.tcx, place.layout.ty)
596                };
597                if let ty::InstanceKind::DropGlue(_, None) = instance.def {
598                    // This is the branch we enter if and only if the dropped type has no drop glue
599                    // whatsoever. This can happen as a result of monomorphizing a drop of a
600                    // generic. In order to make sure that generic and non-generic code behaves
601                    // roughly the same (and in keeping with Mir semantics) we do nothing here.
602                    self.go_to_block(target);
603                    return interp_ok(());
604                }
605                trace!("TerminatorKind::drop: {:?}, type {}", place, place.layout.ty);
606                self.init_drop_in_place_call(&place, instance, target, unwind)?;
607            }
608
609            Assert { ref cond, expected, ref msg, target, unwind } => {
610                let ignored =
611                    M::ignore_optional_overflow_checks(self) && msg.is_optional_overflow_check();
612                let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
613                if ignored || expected == cond_val {
614                    self.go_to_block(target);
615                } else {
616                    M::assert_panic(self, msg, unwind)?;
617                }
618            }
619
620            UnwindTerminate(reason) => {
621                M::unwind_terminate(self, reason)?;
622            }
623
624            // When we encounter Resume, we've finished unwinding
625            // cleanup for the current stack frame. We pop it in order
626            // to continue unwinding the next frame
627            UnwindResume => {
628                trace!("unwinding: resuming from cleanup");
629                // By definition, a Resume terminator means
630                // that we're unwinding
631                self.return_from_current_stack_frame(/* unwinding */ true)?;
632                return interp_ok(());
633            }
634
635            // It is UB to ever encounter this.
636            Unreachable => throw_ub!(Unreachable),
637
638            // These should never occur for MIR we actually run.
639            FalseEdge { .. } | FalseUnwind { .. } | Yield { .. } | CoroutineDrop => span_bug!(
640                terminator.source_info.span,
641                "{:#?} should have been eliminated by MIR pass",
642                terminator.kind
643            ),
644
645            InlineAsm { .. } => {
646                throw_unsup_format!("inline assembly is not supported");
647            }
648        }
649
650        interp_ok(())
651    }
652}