Skip to main content

rustc_const_eval/interpret/
stack.rs

1//! Manages the low-level pushing and popping of stack frames and the (de)allocation of local variables.
2//! For handling of argument passing and return values, see the `call` module.
3use std::cell::Cell;
4use std::{fmt, mem};
5
6use either::{Either, Left, Right};
7use rustc_hir as hir;
8use rustc_hir::definitions::DefPathData;
9use rustc_index::IndexVec;
10use rustc_middle::ty::layout::TyAndLayout;
11use rustc_middle::ty::{self, Ty, TyCtxt};
12use rustc_middle::{bug, mir};
13use rustc_mir_dataflow::impls::always_storage_live_locals;
14use rustc_span::Span;
15use tracing::field::Empty;
16use tracing::{info_span, instrument, trace};
17
18use super::{
19    AllocId, CtfeProvenance, Immediate, InterpCx, InterpResult, Machine, MemPlace, MemPlaceMeta,
20    MemoryKind, Operand, PlaceTy, Pointer, Provenance, ReturnAction, Scalar, from_known_layout,
21    interp_ok, throw_ub, throw_unsup,
22};
23use crate::{enter_trace_span, errors};
24
25// The Phantomdata exists to prevent this type from being `Send`. If it were sent across a thread
26// boundary and dropped in the other thread, it would exit the span in the other thread.
27struct SpanGuard(tracing::Span, std::marker::PhantomData<*const u8>);
28
29impl SpanGuard {
30    /// By default a `SpanGuard` does nothing.
31    fn new() -> Self {
32        Self(tracing::Span::none(), std::marker::PhantomData)
33    }
34
35    /// If a span is entered, we exit the previous span (if any, normally none) and enter the
36    /// new span. This is mainly so we don't have to use `Option` for the `tracing_span` field of
37    /// `Frame` by creating a dummy span to being with and then entering it once the frame has
38    /// been pushed.
39    fn enter(&mut self, span: tracing::Span) {
40        // This executes the destructor on the previous instance of `SpanGuard`, ensuring that
41        // we never enter or exit more spans than vice versa. Unless you `mem::leak`, then we
42        // can't protect the tracing stack, but that'll just lead to weird logging, no actual
43        // problems.
44        *self = Self(span, std::marker::PhantomData);
45        self.0.with_subscriber(|(id, dispatch)| {
46            dispatch.enter(id);
47        });
48    }
49}
50
51impl Drop for SpanGuard {
52    fn drop(&mut self) {
53        self.0.with_subscriber(|(id, dispatch)| {
54            dispatch.exit(id);
55        });
56    }
57}
58
59/// A stack frame.
60pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> {
61    ////////////////////////////////////////////////////////////////////////////////
62    // Function and callsite information
63    ////////////////////////////////////////////////////////////////////////////////
64    /// The MIR for the function called on this frame.
65    pub(super) body: &'tcx mir::Body<'tcx>,
66
67    /// The def_id and args of the current function.
68    pub(super) instance: ty::Instance<'tcx>,
69
70    /// Extra data for the machine.
71    pub extra: Extra,
72
73    ////////////////////////////////////////////////////////////////////////////////
74    // Return place and locals
75    ////////////////////////////////////////////////////////////////////////////////
76    /// Where to continue when returning from this function.
77    return_cont: ReturnContinuation,
78
79    /// The location where the result of the current stack frame should be written to,
80    /// and its layout in the caller. This place is to be interpreted relative to the
81    /// *caller's* stack frame. We use a `PlaceTy` instead of an `MPlaceTy` since this
82    /// avoids having to move *all* return places into Miri's memory.
83    pub return_place: PlaceTy<'tcx, Prov>,
84
85    /// The list of locals for this stack frame, stored in order as
86    /// `[return_ptr, arguments..., variables..., temporaries...]`.
87    /// The locals are stored as `Option<Value>`s.
88    /// `None` represents a local that is currently dead, while a live local
89    /// can either directly contain `Scalar` or refer to some part of an `Allocation`.
90    ///
91    /// Do *not* access this directly; always go through the machine hook!
92    pub locals: IndexVec<mir::Local, LocalState<'tcx, Prov>>,
93
94    /// The span of the `tracing` crate is stored here.
95    /// When the guard is dropped, the span is exited. This gives us
96    /// a full stack trace on all tracing statements.
97    tracing_span: SpanGuard,
98
99    ////////////////////////////////////////////////////////////////////////////////
100    // Current position within the function
101    ////////////////////////////////////////////////////////////////////////////////
102    /// If this is `Right`, we are not currently executing any particular statement in
103    /// this frame (can happen e.g. during frame initialization, and during unwinding on
104    /// frames without cleanup code).
105    ///
106    /// Needs to be public because ConstProp does unspeakable things to it.
107    pub(super) loc: Either<mir::Location, Span>,
108}
109
110/// Where and how to continue when returning/unwinding from the current function.
111#[derive(#[automatically_derived]
impl ::core::clone::Clone for ReturnContinuation {
    #[inline]
    fn clone(&self) -> ReturnContinuation {
        let _: ::core::clone::AssertParamIsClone<Option<mir::BasicBlock>>;
        let _: ::core::clone::AssertParamIsClone<mir::UnwindAction>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for ReturnContinuation { }Copy, #[automatically_derived]
impl ::core::cmp::Eq for ReturnContinuation {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Option<mir::BasicBlock>>;
        let _: ::core::cmp::AssertParamIsEq<mir::UnwindAction>;
        let _: ::core::cmp::AssertParamIsEq<bool>;
    }
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for ReturnContinuation {
    #[inline]
    fn eq(&self, other: &ReturnContinuation) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (ReturnContinuation::Goto { ret: __self_0, unwind: __self_1 },
                    ReturnContinuation::Goto { ret: __arg1_0, unwind: __arg1_1
                    }) => __self_0 == __arg1_0 && __self_1 == __arg1_1,
                (ReturnContinuation::Stop { cleanup: __self_0 },
                    ReturnContinuation::Stop { cleanup: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for ReturnContinuation {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            ReturnContinuation::Goto { ret: __self_0, unwind: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f, "Goto",
                    "ret", __self_0, "unwind", &__self_1),
            ReturnContinuation::Stop { cleanup: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Stop",
                    "cleanup", &__self_0),
        }
    }
}Debug)] // Miri debug-prints these
112pub enum ReturnContinuation {
113    /// Jump to the next block in the caller, or cause UB if None (that's a function
114    /// that may never return).
115    /// `ret` stores the block we jump to on a normal return, while `unwind`
116    /// stores the block used for cleanup during unwinding.
117    Goto { ret: Option<mir::BasicBlock>, unwind: mir::UnwindAction },
118    /// The root frame of the stack: nowhere else to jump to, so we stop.
119    /// `cleanup` says whether locals are deallocated. Static computation
120    /// wants them leaked to intern what they need (and just throw away
121    /// the entire `ecx` when it is done).
122    Stop { cleanup: bool },
123}
124
125/// Return type of [`InterpCx::pop_stack_frame_raw`].
126pub struct StackPopInfo<'tcx, Prov: Provenance> {
127    /// Additional information about the action to be performed when returning from the popped
128    /// stack frame.
129    pub return_action: ReturnAction,
130
131    /// [`return_cont`](Frame::return_cont) of the popped stack frame.
132    pub return_cont: ReturnContinuation,
133
134    /// [`return_place`](Frame::return_place) of the popped stack frame.
135    pub return_place: PlaceTy<'tcx, Prov>,
136}
137
138/// State of a local variable including a memoized layout
139#[derive(#[automatically_derived]
impl<'tcx, Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
    LocalState<'tcx, Prov> {
    #[inline]
    fn clone(&self) -> LocalState<'tcx, Prov> {
        LocalState {
            value: ::core::clone::Clone::clone(&self.value),
            layout: ::core::clone::Clone::clone(&self.layout),
        }
    }
}Clone)]
140pub struct LocalState<'tcx, Prov: Provenance = CtfeProvenance> {
141    value: LocalValue<Prov>,
142    /// Don't modify if `Some`, this is only used to prevent computing the layout twice.
143    /// Avoids computing the layout of locals that are never actually initialized.
144    layout: Cell<Option<TyAndLayout<'tcx>>>,
145}
146
147impl<Prov: Provenance> std::fmt::Debug for LocalState<'_, Prov> {
148    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
149        f.debug_struct("LocalState")
150            .field("value", &self.value)
151            .field("ty", &self.layout.get().map(|l| l.ty))
152            .finish()
153    }
154}
155
156/// Current value of a local variable
157///
158/// This does not store the type of the local; the type is given by `body.local_decls` and can never
159/// change, so by not storing here we avoid having to maintain that as an invariant.
160#[derive(#[automatically_derived]
impl<Prov: ::core::marker::Copy + Provenance> ::core::marker::Copy for
    LocalValue<Prov> {
}Copy, #[automatically_derived]
impl<Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
    LocalValue<Prov> {
    #[inline]
    fn clone(&self) -> LocalValue<Prov> {
        match self {
            LocalValue::Dead => LocalValue::Dead,
            LocalValue::Live(__self_0) =>
                LocalValue::Live(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl<Prov: ::core::fmt::Debug + Provenance> ::core::fmt::Debug for
    LocalValue<Prov> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            LocalValue::Dead => ::core::fmt::Formatter::write_str(f, "Dead"),
            LocalValue::Live(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Live",
                    &__self_0),
        }
    }
}Debug)] // Miri debug-prints these
161pub(super) enum LocalValue<Prov: Provenance = CtfeProvenance> {
162    /// This local is not currently alive, and cannot be used at all.
163    Dead,
164    /// A normal, live local.
165    /// Mostly for convenience, we re-use the `Operand` type here.
166    /// This is an optimization over just always having a pointer here;
167    /// we can thus avoid doing an allocation when the local just stores
168    /// immediate values *and* never has its address taken.
169    Live(Operand<Prov>),
170}
171
172impl<'tcx, Prov: Provenance> LocalState<'tcx, Prov> {
173    pub fn make_live_uninit(&mut self) {
174        self.value = LocalValue::Live(Operand::Immediate(Immediate::Uninit));
175    }
176
177    /// This is a hack because Miri needs a way to visit all the provenance in a `LocalState`
178    /// without having a layout or `TyCtxt` available, and we want to keep the `Operand` type
179    /// private.
180    pub fn as_mplace_or_imm(
181        &self,
182    ) -> Option<Either<(Pointer<Option<Prov>>, MemPlaceMeta<Prov>), Immediate<Prov>>> {
183        match self.value {
184            LocalValue::Dead => None,
185            LocalValue::Live(Operand::Indirect(mplace)) => Some(Left((mplace.ptr, mplace.meta))),
186            LocalValue::Live(Operand::Immediate(imm)) => Some(Right(imm)),
187        }
188    }
189
190    /// Read the local's value or error if the local is not yet live or not live anymore.
191    #[inline(always)]
192    pub(super) fn access(&self) -> InterpResult<'tcx, &Operand<Prov>> {
193        match &self.value {
194            LocalValue::Dead => do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::DeadLocal)throw_ub!(DeadLocal), // could even be "invalid program"?
195            LocalValue::Live(val) => interp_ok(val),
196        }
197    }
198
199    /// Overwrite the local. If the local can be overwritten in place, return a reference
200    /// to do so; otherwise return the `MemPlace` to consult instead.
201    #[inline(always)]
202    pub(super) fn access_mut(&mut self) -> InterpResult<'tcx, &mut Operand<Prov>> {
203        match &mut self.value {
204            LocalValue::Dead => do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::DeadLocal)throw_ub!(DeadLocal), // could even be "invalid program"?
205            LocalValue::Live(val) => interp_ok(val),
206        }
207    }
208}
209
210/// What we store about a frame in an interpreter backtrace.
211#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for FrameInfo<'tcx> {
    #[inline]
    fn clone(&self) -> FrameInfo<'tcx> {
        FrameInfo {
            instance: ::core::clone::Clone::clone(&self.instance),
            span: ::core::clone::Clone::clone(&self.span),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for FrameInfo<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "FrameInfo",
            "instance", &self.instance, "span", &&self.span)
    }
}Debug)]
212pub struct FrameInfo<'tcx> {
213    pub instance: ty::Instance<'tcx>,
214    pub span: Span,
215}
216
217// FIXME: only used by miri, should be removed once translatable.
218impl<'tcx> fmt::Display for FrameInfo<'tcx> {
219    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
220        ty::tls::with(|tcx| {
221            if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
222                f.write_fmt(format_args!("inside closure"))write!(f, "inside closure")
223            } else {
224                // Note: this triggers a `must_produce_diag` state, which means that if we ever
225                // get here we must emit a diagnostic. We should never display a `FrameInfo` unless
226                // we actually want to emit a warning or error to the user.
227                f.write_fmt(format_args!("inside `{0}`", self.instance))write!(f, "inside `{}`", self.instance)
228            }
229        })
230    }
231}
232
233impl<'tcx> FrameInfo<'tcx> {
234    pub fn as_note(&self, tcx: TyCtxt<'tcx>) -> errors::FrameNote {
235        let span = self.span;
236        if tcx.def_key(self.instance.def_id()).disambiguated_data.data == DefPathData::Closure {
237            errors::FrameNote {
238                where_: "closure",
239                span,
240                instance: String::new(),
241                times: 0,
242                has_label: false,
243            }
244        } else {
245            let instance = ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}", self.instance))
    })format!("{}", self.instance);
246            // Note: this triggers a `must_produce_diag` state, which means that if we ever get
247            // here we must emit a diagnostic. We should never display a `FrameInfo` unless we
248            // actually want to emit a warning or error to the user.
249            errors::FrameNote { where_: "instance", span, instance, times: 0, has_label: false }
250        }
251    }
252}
253
254impl<'tcx, Prov: Provenance> Frame<'tcx, Prov> {
255    pub fn with_extra<Extra>(self, extra: Extra) -> Frame<'tcx, Prov, Extra> {
256        Frame {
257            body: self.body,
258            instance: self.instance,
259            return_cont: self.return_cont,
260            return_place: self.return_place,
261            locals: self.locals,
262            loc: self.loc,
263            extra,
264            tracing_span: self.tracing_span,
265        }
266    }
267}
268
269impl<'tcx, Prov: Provenance, Extra> Frame<'tcx, Prov, Extra> {
270    /// Get the current location within the Frame.
271    ///
272    /// If this is `Right`, we are not currently executing any particular statement in
273    /// this frame (can happen e.g. during frame initialization, and during unwinding on
274    /// frames without cleanup code).
275    ///
276    /// Used by [priroda](https://github.com/oli-obk/priroda).
277    pub fn current_loc(&self) -> Either<mir::Location, Span> {
278        self.loc
279    }
280
281    pub fn body(&self) -> &'tcx mir::Body<'tcx> {
282        self.body
283    }
284
285    pub fn instance(&self) -> ty::Instance<'tcx> {
286        self.instance
287    }
288
289    /// Return the `SourceInfo` of the current instruction.
290    pub fn current_source_info(&self) -> Option<&mir::SourceInfo> {
291        self.loc.left().map(|loc| self.body.source_info(loc))
292    }
293
294    pub fn current_span(&self) -> Span {
295        match self.loc {
296            Left(loc) => self.body.source_info(loc).span,
297            Right(span) => span,
298        }
299    }
300
301    pub fn lint_root(&self, tcx: TyCtxt<'tcx>) -> Option<hir::HirId> {
302        // We first try to get a HirId via the current source scope,
303        // and fall back to `body.source`.
304        self.current_source_info()
305            .and_then(|source_info| match &self.body.source_scopes[source_info.scope].local_data {
306                mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
307                mir::ClearCrossCrate::Clear => None,
308            })
309            .or_else(|| {
310                let def_id = self.body.source.def_id().as_local();
311                def_id.map(|def_id| tcx.local_def_id_to_hir_id(def_id))
312            })
313    }
314
315    /// Returns the address of the buffer where the locals are stored. This is used by `Place` as a
316    /// sanity check to detect bugs where we mix up which stack frame a place refers to.
317    #[inline(always)]
318    pub(super) fn locals_addr(&self) -> usize {
319        self.locals.raw.as_ptr().addr()
320    }
321
322    #[must_use]
323    pub fn generate_stacktrace_from_stack(stack: &[Self]) -> Vec<FrameInfo<'tcx>> {
324        let mut frames = Vec::new();
325        // This deliberately does *not* honor `requires_caller_location` since it is used for much
326        // more than just panics.
327        for frame in stack.iter().rev() {
328            let span = match frame.loc {
329                Left(loc) => {
330                    // If the stacktrace passes through MIR-inlined source scopes, add them.
331                    let mir::SourceInfo { mut span, scope } = *frame.body.source_info(loc);
332                    let mut scope_data = &frame.body.source_scopes[scope];
333                    while let Some((instance, call_span)) = scope_data.inlined {
334                        frames.push(FrameInfo { span, instance });
335                        span = call_span;
336                        scope_data = &frame.body.source_scopes[scope_data.parent_scope.unwrap()];
337                    }
338                    span
339                }
340                Right(span) => span,
341            };
342            frames.push(FrameInfo { span, instance: frame.instance });
343        }
344        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/interpret/stack.rs:344",
                        "rustc_const_eval::interpret::stack",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                        ::tracing_core::__macro_support::Option::Some(344u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("generate stacktrace: {0:#?}",
                                                    frames) as &dyn Value))])
            });
    } else { ; }
};trace!("generate stacktrace: {:#?}", frames);
345        frames
346    }
347}
348
349impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
350    /// Very low-level helper that pushes a stack frame without initializing
351    /// the arguments or local variables.
352    ///
353    /// The high-level version of this is `init_stack_frame`.
354    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("push_stack_frame_raw",
                                    "rustc_const_eval::interpret::stack",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                                    ::tracing_core::__macro_support::Option::Some(354u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                                    ::tracing_core::field::FieldSet::new(&["instance"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: InterpResult<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/interpret/stack.rs:362",
                                    "rustc_const_eval::interpret::stack",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                                    ::tracing_core::__macro_support::Option::Some(362u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        {
                            let interest = __CALLSITE.interest();
                            !interest.is_never() &&
                                ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                    interest)
                        };
                if enabled {
                    (|value_set: ::tracing::field::ValueSet|
                                {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Event::dispatch(meta, &value_set);
                                    ;
                                })({
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("body: {0:#?}",
                                                                body) as &dyn Value))])
                        });
                } else { ; }
            };
            if true {
                match (&self.stack().is_empty(),
                        &#[allow(non_exhaustive_omitted_patterns)] match return_cont
                                {
                                ReturnContinuation::Stop { .. } => true,
                                _ => false,
                            }) {
                    (left_val, right_val) => {
                        if !(*left_val == *right_val) {
                            let kind = ::core::panicking::AssertKind::Eq;
                            ::core::panicking::assert_failed(kind, &*left_val,
                                &*right_val, ::core::option::Option::None);
                        }
                    }
                };
            };
            let dead_local =
                LocalState {
                    value: LocalValue::Dead,
                    layout: Cell::new(None),
                };
            let locals = IndexVec::from_elem(dead_local, &body.local_decls);
            let pre_frame =
                Frame {
                    body,
                    loc: Right(body.span),
                    return_cont,
                    return_place: return_place.clone(),
                    locals,
                    instance,
                    tracing_span: SpanGuard::new(),
                    extra: (),
                };
            let frame = M::init_frame(self, pre_frame)?;
            self.stack_mut().push(frame);
            for &const_ in body.required_consts() {
                let _trace =
                    <M as
                            crate::interpret::Machine>::enter_trace_span(||
                            {
                                use ::tracing::__macro_support::Callsite as _;
                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                    {
                                        static META: ::tracing::Metadata<'static> =
                                            {
                                                ::tracing_core::metadata::Metadata::new("const_eval",
                                                    "rustc_const_eval::interpret::stack",
                                                    ::tracing::Level::INFO,
                                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                                                    ::tracing_core::__macro_support::Option::Some(391u32),
                                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                                                    ::tracing_core::field::FieldSet::new(&["const_eval",
                                                                    "const_.const_"],
                                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                    ::tracing::metadata::Kind::SPAN)
                                            };
                                        ::tracing::callsite::DefaultCallsite::new(&META)
                                    };
                                let mut interest = ::tracing::subscriber::Interest::never();
                                if ::tracing::Level::INFO <=
                                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                ::tracing::Level::INFO <=
                                                    ::tracing::level_filters::LevelFilter::current() &&
                                            { interest = __CALLSITE.interest(); !interest.is_never() }
                                        &&
                                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                            interest) {
                                    let meta = __CALLSITE.metadata();
                                    ::tracing::Span::new(meta,
                                        &{
                                                #[allow(unused_imports)]
                                                use ::tracing::field::{debug, display, Value};
                                                let mut iter = meta.fields().iter();
                                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                                    ::tracing::__macro_support::Option::Some(&display(&"required_consts")
                                                                            as &dyn Value)),
                                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                                    ::tracing::__macro_support::Option::Some(&debug(&const_.const_)
                                                                            as &dyn Value))])
                                            })
                                } else {
                                    let span =
                                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                                    {};
                                    span
                                }
                            });
                let c =
                    self.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
                c.eval(*self.tcx, self.typing_env,
                            const_.span).map_err(|err|
                            { err.emit_note(*self.tcx); err })?;
            }
            M::after_stack_push(self)?;
            self.frame_mut().loc = Left(mir::Location::START);
            let span =
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("frame",
                                        "rustc_const_eval::interpret::stack",
                                        ::tracing::Level::INFO,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                                        ::tracing_core::__macro_support::Option::Some(407u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                                        ::tracing_core::field::FieldSet::new(&["tracing_separate_thread",
                                                        "frame"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::SPAN)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let mut interest = ::tracing::subscriber::Interest::never();
                    if ::tracing::Level::INFO <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::INFO <=
                                        ::tracing::level_filters::LevelFilter::current() &&
                                { interest = __CALLSITE.interest(); !interest.is_never() }
                            &&
                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                interest) {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Span::new(meta,
                            &{
                                    #[allow(unused_imports)]
                                    use ::tracing::field::{debug, display, Value};
                                    let mut iter = meta.fields().iter();
                                    meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                        ::tracing::__macro_support::Option::Some(&Empty as
                                                                &dyn Value)),
                                                    (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                        ::tracing::__macro_support::Option::Some(&display(&instance)
                                                                as &dyn Value))])
                                })
                    } else {
                        let span =
                            ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                        {};
                        span
                    }
                };
            self.frame_mut().tracing_span.enter(span);
            interp_ok(())
        }
    }
}#[instrument(skip(self, body, return_place, return_cont), level = "debug")]
355    pub(crate) fn push_stack_frame_raw(
356        &mut self,
357        instance: ty::Instance<'tcx>,
358        body: &'tcx mir::Body<'tcx>,
359        return_place: &PlaceTy<'tcx, M::Provenance>,
360        return_cont: ReturnContinuation,
361    ) -> InterpResult<'tcx> {
362        trace!("body: {:#?}", body);
363
364        // We can push a `Root` frame if and only if the stack is empty.
365        debug_assert_eq!(
366            self.stack().is_empty(),
367            matches!(return_cont, ReturnContinuation::Stop { .. })
368        );
369
370        // First push a stack frame so we have access to `instantiate_from_current_frame` and other
371        // `self.frame()`-based functions.
372        let dead_local = LocalState { value: LocalValue::Dead, layout: Cell::new(None) };
373        let locals = IndexVec::from_elem(dead_local, &body.local_decls);
374        let pre_frame = Frame {
375            body,
376            loc: Right(body.span), // Span used for errors caused during preamble.
377            return_cont,
378            return_place: return_place.clone(),
379            locals,
380            instance,
381            tracing_span: SpanGuard::new(),
382            extra: (),
383        };
384        let frame = M::init_frame(self, pre_frame)?;
385        self.stack_mut().push(frame);
386
387        // Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
388        for &const_ in body.required_consts() {
389            // We can't use `eval_mir_constant` here as that assumes that all required consts have
390            // already been checked, so we need a separate tracing call.
391            let _trace = enter_trace_span!(M, const_eval::required_consts, ?const_.const_);
392            let c =
393                self.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
394            c.eval(*self.tcx, self.typing_env, const_.span).map_err(|err| {
395                err.emit_note(*self.tcx);
396                err
397            })?;
398        }
399
400        // Finish things up.
401        M::after_stack_push(self)?;
402        self.frame_mut().loc = Left(mir::Location::START);
403        // `tracing_separate_thread` is used to instruct the tracing_chrome [tracing::Layer] in Miri
404        // to put the "frame" span on a separate trace thread/line than other spans, to make the
405        // visualization in <https://ui.perfetto.dev> easier to interpret. It is set to a value of
406        // [tracing::field::Empty] so that other tracing layers (e.g. the logger) will ignore it.
407        let span = info_span!("frame", tracing_separate_thread = Empty, frame = %instance);
408        self.frame_mut().tracing_span.enter(span);
409
410        interp_ok(())
411    }
412
413    /// Low-level helper that pops a stack frame from the stack and returns some information about
414    /// it.
415    ///
416    /// This also deallocates locals, if necessary.
417    /// `copy_ret_val` gets called after the frame has been taken from the stack but before the locals have been deallocated.
418    ///
419    /// [`M::before_stack_pop`] and [`M::after_stack_pop`] are called by this function
420    /// automatically.
421    ///
422    /// The high-level version of this is `return_from_current_stack_frame`.
423    ///
424    /// [`M::before_stack_pop`]: Machine::before_stack_pop
425    /// [`M::after_stack_pop`]: Machine::after_stack_pop
426    pub(super) fn pop_stack_frame_raw(
427        &mut self,
428        unwinding: bool,
429        copy_ret_val: impl FnOnce(&mut Self, &PlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx>,
430    ) -> InterpResult<'tcx, StackPopInfo<'tcx, M::Provenance>> {
431        M::before_stack_pop(self)?;
432        let frame =
433            self.stack_mut().pop().expect("tried to pop a stack frame, but there were none");
434
435        // Copy return value (unless we are unwinding).
436        if !unwinding {
437            copy_ret_val(self, &frame.return_place)?;
438        }
439
440        let return_cont = frame.return_cont;
441        let return_place = frame.return_place.clone();
442
443        // Cleanup: deallocate locals.
444        // Usually we want to clean up (deallocate locals), but in a few rare cases we don't.
445        // We do this while the frame is still on the stack, so errors point to the callee.
446        let cleanup = match return_cont {
447            ReturnContinuation::Goto { .. } => true,
448            ReturnContinuation::Stop { cleanup, .. } => cleanup,
449        };
450
451        let return_action = if cleanup {
452            // We need to take the locals out, since we need to mutate while iterating.
453            for local in &frame.locals {
454                self.deallocate_local(local.value)?;
455            }
456
457            // Call the machine hook, which determines the next steps.
458            let return_action = M::after_stack_pop(self, frame, unwinding)?;
459            match (&return_action, &ReturnAction::NoCleanup) {
    (left_val, right_val) => {
        if *left_val == *right_val {
            let kind = ::core::panicking::AssertKind::Ne;
            ::core::panicking::assert_failed(kind, &*left_val, &*right_val,
                ::core::option::Option::None);
        }
    }
};assert_ne!(return_action, ReturnAction::NoCleanup);
460            return_action
461        } else {
462            // We also skip the machine hook when there's no cleanup. This not a real "pop" anyway.
463            ReturnAction::NoCleanup
464        };
465
466        interp_ok(StackPopInfo { return_action, return_cont, return_place })
467    }
468
469    /// In the current stack frame, mark all locals as live that are not arguments and don't have
470    /// `Storage*` annotations (this includes the return place).
471    pub(crate) fn storage_live_for_always_live_locals(&mut self) -> InterpResult<'tcx> {
472        self.storage_live(mir::RETURN_PLACE)?;
473
474        let body = self.body();
475        let always_live = always_storage_live_locals(body);
476        for local in body.vars_and_temps_iter() {
477            if always_live.contains(local) {
478                self.storage_live(local)?;
479            }
480        }
481        interp_ok(())
482    }
483
484    pub fn storage_live_dyn(
485        &mut self,
486        local: mir::Local,
487        meta: MemPlaceMeta<M::Provenance>,
488    ) -> InterpResult<'tcx> {
489        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/interpret/stack.rs:489",
                        "rustc_const_eval::interpret::stack",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                        ::tracing_core::__macro_support::Option::Some(489u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("{0:?} is now live",
                                                    local) as &dyn Value))])
            });
    } else { ; }
};trace!("{:?} is now live", local);
490
491        // We avoid `ty.is_trivially_sized` since that does something expensive for ADTs.
492        fn is_very_trivially_sized(ty: Ty<'_>) -> bool {
493            match ty.kind() {
494                ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
495                | ty::Uint(_)
496                | ty::Int(_)
497                | ty::Bool
498                | ty::Float(_)
499                | ty::FnDef(..)
500                | ty::FnPtr(..)
501                | ty::RawPtr(..)
502                | ty::Char
503                | ty::Ref(..)
504                | ty::Coroutine(..)
505                | ty::CoroutineWitness(..)
506                | ty::Array(..)
507                | ty::Closure(..)
508                | ty::CoroutineClosure(..)
509                | ty::Never
510                | ty::Error(_) => true,
511
512                ty::Str | ty::Slice(_) | ty::Dynamic(_, _) | ty::Foreign(..) => false,
513
514                ty::Tuple(tys) => tys.last().is_none_or(|ty| is_very_trivially_sized(*ty)),
515
516                ty::Pat(ty, ..) => is_very_trivially_sized(*ty),
517
518                // We don't want to do any queries, so there is not much we can do with ADTs.
519                ty::Adt(..) => false,
520
521                ty::UnsafeBinder(ty) => is_very_trivially_sized(ty.skip_binder()),
522
523                ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
524
525                ty::Infer(ty::TyVar(_)) => false,
526
527                ty::Bound(..)
528                | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
529                    ::rustc_middle::util::bug::bug_fmt(format_args!("`is_very_trivially_sized` applied to unexpected type: {0}",
        ty))bug!("`is_very_trivially_sized` applied to unexpected type: {}", ty)
530                }
531            }
532        }
533
534        // This is a hot function, we avoid computing the layout when possible.
535        // `unsized_` will be `None` for sized types and `Some(layout)` for unsized types.
536        let unsized_ = if is_very_trivially_sized(self.body().local_decls[local].ty) {
537            None
538        } else {
539            // We need the layout.
540            let layout = self.layout_of_local(self.frame(), local, None)?;
541            if layout.is_sized() { None } else { Some(layout) }
542        };
543
544        let local_val = LocalValue::Live(if let Some(layout) = unsized_ {
545            if !meta.has_meta() {
546                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::UnsizedLocal);throw_unsup!(UnsizedLocal);
547            }
548            // Need to allocate some memory, since `Immediate::Uninit` cannot be unsized.
549            let dest_place = self.allocate_dyn(layout, MemoryKind::Stack, meta)?;
550            Operand::Indirect(*dest_place.mplace())
551        } else {
552            // Just make this an efficient immediate.
553            if !!meta.has_meta() {
    ::core::panicking::panic("assertion failed: !meta.has_meta()")
};assert!(!meta.has_meta()); // we're dropping the metadata
554            // Make sure the machine knows this "write" is happening. (This is important so that
555            // races involving local variable allocation can be detected by Miri.)
556            M::after_local_write(self, local, /*storage_live*/ true)?;
557            // Note that not calling `layout_of` here does have one real consequence:
558            // if the type is too big, we'll only notice this when the local is actually initialized,
559            // which is a bit too late -- we should ideally notice this already here, when the memory
560            // is conceptually allocated. But given how rare that error is and that this is a hot function,
561            // we accept this downside for now.
562            Operand::Immediate(Immediate::Uninit)
563        });
564
565        // If the local is already live, deallocate its old memory.
566        let old = mem::replace(&mut self.frame_mut().locals[local].value, local_val);
567        self.deallocate_local(old)?;
568        interp_ok(())
569    }
570
571    /// Mark a storage as live, killing the previous content.
572    #[inline(always)]
573    pub fn storage_live(&mut self, local: mir::Local) -> InterpResult<'tcx> {
574        self.storage_live_dyn(local, MemPlaceMeta::None)
575    }
576
577    pub fn storage_dead(&mut self, local: mir::Local) -> InterpResult<'tcx> {
578        if !(local != mir::RETURN_PLACE) {
    {
        ::core::panicking::panic_fmt(format_args!("Cannot make return place dead"));
    }
};assert!(local != mir::RETURN_PLACE, "Cannot make return place dead");
579        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/interpret/stack.rs:579",
                        "rustc_const_eval::interpret::stack",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                        ::tracing_core::__macro_support::Option::Some(579u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("{0:?} is now dead",
                                                    local) as &dyn Value))])
            });
    } else { ; }
};trace!("{:?} is now dead", local);
580
581        // If the local is already dead, this is a NOP.
582        let old = mem::replace(&mut self.frame_mut().locals[local].value, LocalValue::Dead);
583        self.deallocate_local(old)?;
584        interp_ok(())
585    }
586
587    fn deallocate_local(&mut self, local: LocalValue<M::Provenance>) -> InterpResult<'tcx> {
588        if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
589            // All locals have a backing allocation, even if the allocation is empty
590            // due to the local having ZST type. Hence we can `unwrap`.
591            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/interpret/stack.rs:591",
                        "rustc_const_eval::interpret::stack",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/stack.rs"),
                        ::tracing_core::__macro_support::Option::Some(591u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::stack"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("deallocating local {0:?}: {1:?}",
                                                    local,
                                                    self.dump_alloc(ptr.provenance.unwrap().get_alloc_id().unwrap()))
                                            as &dyn Value))])
            });
    } else { ; }
};trace!(
592                "deallocating local {:?}: {:?}",
593                local,
594                // Locals always have a `alloc_id` (they are never the result of a int2ptr).
595                self.dump_alloc(ptr.provenance.unwrap().get_alloc_id().unwrap())
596            );
597            self.deallocate_ptr(ptr, None, MemoryKind::Stack)?;
598        };
599        interp_ok(())
600    }
601
602    /// This is public because it is used by [Aquascope](https://github.com/cognitive-engineering-lab/aquascope/)
603    /// to analyze all the locals in a stack frame.
604    #[inline(always)]
605    pub fn layout_of_local(
606        &self,
607        frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
608        local: mir::Local,
609        layout: Option<TyAndLayout<'tcx>>,
610    ) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
611        let state = &frame.locals[local];
612        if let Some(layout) = state.layout.get() {
613            return interp_ok(layout);
614        }
615
616        let layout = from_known_layout(self.tcx, self.typing_env, layout, || {
617            let local_ty = frame.body.local_decls[local].ty;
618            let local_ty =
619                self.instantiate_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
620            self.layout_of(local_ty).into()
621        })?;
622
623        // Layouts of locals are requested a lot, so we cache them.
624        state.layout.set(Some(layout));
625        interp_ok(layout)
626    }
627}
628
629impl<'tcx, Prov: Provenance> LocalState<'tcx, Prov> {
630    pub(super) fn print(
631        &self,
632        allocs: &mut Vec<Option<AllocId>>,
633        fmt: &mut std::fmt::Formatter<'_>,
634    ) -> std::fmt::Result {
635        match self.value {
636            LocalValue::Dead => fmt.write_fmt(format_args!(" is dead"))write!(fmt, " is dead")?,
637            LocalValue::Live(Operand::Immediate(Immediate::Uninit)) => {
638                fmt.write_fmt(format_args!(" is uninitialized"))write!(fmt, " is uninitialized")?
639            }
640            LocalValue::Live(Operand::Indirect(mplace)) => {
641                fmt.write_fmt(format_args!(" by {0} ref {1:?}:",
        match mplace.meta {
            MemPlaceMeta::Meta(meta) =>
                ::alloc::__export::must_use({
                        ::alloc::fmt::format(format_args!(" meta({0:?})", meta))
                    }),
            MemPlaceMeta::None => String::new(),
        }, mplace.ptr))write!(
642                    fmt,
643                    " by {} ref {:?}:",
644                    match mplace.meta {
645                        MemPlaceMeta::Meta(meta) => format!(" meta({meta:?})"),
646                        MemPlaceMeta::None => String::new(),
647                    },
648                    mplace.ptr,
649                )?;
650                allocs.extend(mplace.ptr.provenance.map(Provenance::get_alloc_id));
651            }
652            LocalValue::Live(Operand::Immediate(Immediate::Scalar(val))) => {
653                fmt.write_fmt(format_args!(" {0:?}", val))write!(fmt, " {val:?}")?;
654                if let Scalar::Ptr(ptr, _size) = val {
655                    allocs.push(ptr.provenance.get_alloc_id());
656                }
657            }
658            LocalValue::Live(Operand::Immediate(Immediate::ScalarPair(val1, val2))) => {
659                fmt.write_fmt(format_args!(" ({0:?}, {1:?})", val1, val2))write!(fmt, " ({val1:?}, {val2:?})")?;
660                if let Scalar::Ptr(ptr, _size) = val1 {
661                    allocs.push(ptr.provenance.get_alloc_id());
662                }
663                if let Scalar::Ptr(ptr, _size) = val2 {
664                    allocs.push(ptr.provenance.get_alloc_id());
665                }
666            }
667        }
668
669        Ok(())
670    }
671}