Skip to main content

rustc_const_eval/interpret/
call.rs

1//! Manages calling a concrete function (with known MIR body) with argument passing,
2//! and returning the return value to the caller.
3
4use std::assert_matches;
5use std::borrow::Cow;
6
7use either::{Left, Right};
8use rustc_abi::{self as abi, ExternAbi, FieldIdx, Integer, VariantIdx};
9use rustc_hir::def_id::DefId;
10use rustc_hir::find_attr;
11use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
12use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef};
13use rustc_middle::{bug, mir, span_bug};
14use rustc_target::callconv::{ArgAbi, FnAbi};
15use tracing::field::Empty;
16use tracing::{info, instrument, trace};
17
18use super::{
19    CtfeProvenance, EnteredTraceSpan, FnVal, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine,
20    OpTy, PlaceTy, Projectable, Provenance, RetagMode, ReturnAction, ReturnContinuation, Scalar,
21    interp_ok, throw_ub, throw_ub_format,
22};
23use crate::enter_trace_span;
24
25/// An argument passed to a function.
26#[derive(#[automatically_derived]
impl<'tcx, Prov: ::core::clone::Clone + Provenance> ::core::clone::Clone for
    FnArg<'tcx, Prov> {
    #[inline]
    fn clone(&self) -> FnArg<'tcx, Prov> {
        match self {
            FnArg::Copy(__self_0) =>
                FnArg::Copy(::core::clone::Clone::clone(__self_0)),
            FnArg::InPlace(__self_0) =>
                FnArg::InPlace(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl<'tcx, Prov: ::core::fmt::Debug + Provenance> ::core::fmt::Debug for
    FnArg<'tcx, Prov> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            FnArg::Copy(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Copy",
                    &__self_0),
            FnArg::InPlace(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "InPlace", &__self_0),
        }
    }
}Debug)]
27pub enum FnArg<'tcx, Prov: Provenance = CtfeProvenance> {
28    /// Pass a copy of the given operand.
29    Copy(OpTy<'tcx, Prov>),
30    /// Allow for the argument to be passed in-place: destroy the value originally stored at that
31    /// place and make the place inaccessible for the duration of the function call. This *must* be
32    /// an in-memory place so that we can do the proper alias checks.
33    InPlace(MPlaceTy<'tcx, Prov>),
34}
35
36impl<'tcx, Prov: Provenance> FnArg<'tcx, Prov> {
37    pub fn layout(&self) -> &TyAndLayout<'tcx> {
38        match self {
39            FnArg::Copy(op) => &op.layout,
40            FnArg::InPlace(mplace) => &mplace.layout,
41        }
42    }
43
44    /// Make a copy of the given fn_arg. Any `InPlace` are degenerated to copies, no protection of the
45    /// original memory occurs.
46    pub fn copy_fn_arg(&self) -> OpTy<'tcx, Prov> {
47        match self {
48            FnArg::Copy(op) => op.clone(),
49            FnArg::InPlace(mplace) => mplace.clone().into(),
50        }
51    }
52}
53
54impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
55    /// Make a copy of the given fn_args. Any `InPlace` are degenerated to copies, no protection of the
56    /// original memory occurs.
57    pub fn copy_fn_args(args: &[FnArg<'tcx, M::Provenance>]) -> Vec<OpTy<'tcx, M::Provenance>> {
58        args.iter().map(|fn_arg| fn_arg.copy_fn_arg()).collect()
59    }
60
61    /// Helper function for argument untupling.
62    fn fn_arg_project_field(
63        &self,
64        arg: &FnArg<'tcx, M::Provenance>,
65        field: FieldIdx,
66    ) -> InterpResult<'tcx, FnArg<'tcx, M::Provenance>> {
67        interp_ok(match arg {
68            FnArg::Copy(op) => FnArg::Copy(self.project_field(op, field)?),
69            FnArg::InPlace(mplace) => FnArg::InPlace(self.project_field(mplace, field)?),
70        })
71    }
72
73    /// Find the wrapped inner type of a transparent wrapper.
74    /// Must not be called on 1-ZST (as they don't have a uniquely defined "wrapped field").
75    ///
76    /// We work with `TyAndLayout` here since that makes it much easier to iterate over all fields.
77    fn unfold_transparent(
78        &self,
79        layout: TyAndLayout<'tcx>,
80        may_unfold: impl Fn(AdtDef<'tcx>) -> bool,
81    ) -> TyAndLayout<'tcx> {
82        match layout.ty.kind() {
83            ty::Adt(adt_def, _) if adt_def.repr().transparent() && may_unfold(*adt_def) => {
84                {
    match layout.variants {
        rustc_abi::Variants::Single { .. } => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "rustc_abi::Variants::Single { .. }",
                ::core::option::Option::None);
        }
    }
};assert_matches!(layout.variants, rustc_abi::Variants::Single { .. });
85                // Find the non-1-ZST field, and recurse.
86                let (_, field) = layout.non_1zst_field(self).unwrap();
87                self.unfold_transparent(field, may_unfold)
88            }
89            ty::Pat(base, _) => self.layout_of(*base).expect(
90                "if the layout of a pattern type could be computed, so can the layout of its base",
91            ),
92            // Not a transparent type, no further unfolding.
93            _ => layout,
94        }
95    }
96
97    /// Unwrap types that are guaranteed a null-pointer-optimization
98    fn unfold_npo(&self, layout: TyAndLayout<'tcx>) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
99        // Check if this is an option-like type wrapping some type.
100        let ty::Adt(def, args) = layout.ty.kind() else {
101            // Not an ADT, so definitely no NPO.
102            return interp_ok(layout);
103        };
104        if def.variants().len() != 2 {
105            // Not a 2-variant enum, so no NPO.
106            return interp_ok(layout);
107        }
108        if !def.is_enum() {
    ::core::panicking::panic("assertion failed: def.is_enum()")
};assert!(def.is_enum());
109
110        let all_fields_1zst = |variant: &VariantDef| -> InterpResult<'tcx, _> {
111            for field in &variant.fields {
112                let ty = field.ty(*self.tcx, args).skip_norm_wip();
113                let layout = self.layout_of(ty)?;
114                if !layout.is_1zst() {
115                    return interp_ok(false);
116                }
117            }
118            interp_ok(true)
119        };
120
121        // If one variant consists entirely of 1-ZST, then the other variant
122        // is the only "relevant" one for this check.
123        let var0 = VariantIdx::from_u32(0);
124        let var1 = VariantIdx::from_u32(1);
125        let relevant_variant = if all_fields_1zst(def.variant(var0))? {
126            def.variant(var1)
127        } else if all_fields_1zst(def.variant(var1))? {
128            def.variant(var0)
129        } else {
130            // No variant is all-1-ZST, so no NPO.
131            return interp_ok(layout);
132        };
133        // The "relevant" variant must have exactly one field, and its type is the "inner" type.
134        if relevant_variant.fields.len() != 1 {
135            return interp_ok(layout);
136        }
137        let inner =
138            relevant_variant.fields[FieldIdx::from_u32(0)].ty(*self.tcx, args).skip_norm_wip();
139        let inner = self.layout_of(inner)?;
140
141        // Check if the inner type is one of the NPO-guaranteed ones.
142        // For that we first unpeel transparent *structs* (but not unions).
143        let is_npo =
144            |def: AdtDef<'tcx>| {
        {
            'done:
                {
                for i in
                    ::rustc_hir::attrs::HasAttrs::get_attrs(def.did(),
                        &self.tcx) {
                    #[allow(unused_imports)]
                    use rustc_hir::attrs::AttributeKind::*;
                    let i: &rustc_hir::Attribute = i;
                    match i {
                        rustc_hir::Attribute::Parsed(RustcNonnullOptimizationGuaranteed)
                            => {
                            break 'done Some(());
                        }
                        rustc_hir::Attribute::Unparsed(..) =>
                            {}
                            #[deny(unreachable_patterns)]
                            _ => {}
                    }
                }
                None
            }
        }
    }.is_some()find_attr!(self.tcx, def.did(), RustcNonnullOptimizationGuaranteed);
145        let inner = self.unfold_transparent(inner, /* may_unfold */ |def| {
146            // Stop at NPO types so that we don't miss that attribute in the check below!
147            def.is_struct() && !is_npo(def)
148        });
149        interp_ok(match inner.ty.kind() {
150            ty::Ref(..) | ty::FnPtr(..) => {
151                // Option<&T> behaves like &T, and same for fn()
152                inner
153            }
154            ty::Adt(def, _) if is_npo(*def) => {
155                // Once we found a `nonnull_optimization_guaranteed` type, further strip off
156                // newtype structs from it to find the underlying ABI type.
157                self.unfold_transparent(inner, /* may_unfold */ |def| def.is_struct())
158            }
159            _ => {
160                // Everything else we do not unfold.
161                layout
162            }
163        })
164    }
165
166    /// Check if these two layouts look like they are fn-ABI-compatible.
167    /// (We also compare the `PassMode`, so this doesn't have to check everything. But it turns out
168    /// that only checking the `PassMode` is insufficient.)
169    fn layout_compat(
170        &self,
171        caller: TyAndLayout<'tcx>,
172        callee: TyAndLayout<'tcx>,
173    ) -> InterpResult<'tcx, bool> {
174        // Fast path: equal types are definitely compatible.
175        if caller.ty == callee.ty {
176            return interp_ok(true);
177        }
178        // 1-ZST are compatible with all 1-ZST (and with nothing else).
179        if caller.is_1zst() || callee.is_1zst() {
180            return interp_ok(caller.is_1zst() && callee.is_1zst());
181        }
182        // Unfold newtypes and NPO optimizations.
183        let unfold = |layout: TyAndLayout<'tcx>| {
184            self.unfold_npo(self.unfold_transparent(layout, /* may_unfold */ |_def| true))
185        };
186        let caller = unfold(caller)?;
187        let callee = unfold(callee)?;
188        // Now see if these inner types are compatible.
189
190        // Compatible pointer types. For thin pointers, we have to accept even non-`repr(transparent)`
191        // things as compatible due to `DispatchFromDyn`. For instance, `Rc<i32>` and `*mut i32`
192        // must be compatible. So we just accept everything with Pointer ABI as compatible,
193        // even if this will accept some code that is not stably guaranteed to work.
194        // This also handles function pointers.
195        let thin_pointer = |layout: TyAndLayout<'tcx>| match layout.backend_repr {
196            abi::BackendRepr::Scalar(s) => match s.primitive() {
197                abi::Primitive::Pointer(addr_space) => Some(addr_space),
198                _ => None,
199            },
200            _ => None,
201        };
202        if let (Some(caller), Some(callee)) = (thin_pointer(caller), thin_pointer(callee)) {
203            return interp_ok(caller == callee);
204        }
205        // For wide pointers we have to get the pointee type.
206        let pointee_ty = |ty: Ty<'tcx>| -> InterpResult<'tcx, Option<Ty<'tcx>>> {
207            // We cannot use `builtin_deref` here since we need to reject `Box<T, MyAlloc>`.
208            interp_ok(Some(match ty.kind() {
209                ty::Ref(_, ty, _) => *ty,
210                ty::RawPtr(ty, _) => *ty,
211                // We only accept `Box` with the default allocator.
212                _ if ty.is_box_global(*self.tcx) => ty.expect_boxed_ty(),
213                _ => return interp_ok(None),
214            }))
215        };
216        if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
217            // This is okay if they have the same metadata type.
218            let meta_ty = |ty: Ty<'tcx>| {
219                // Even if `ty` is normalized, the search for the unsized tail will project
220                // to fields, which can yield non-normalized types. So we need to provide a
221                // normalization function.
222                let normalize = |ty| self.tcx.normalize_erasing_regions(self.typing_env, ty);
223                ty.ptr_metadata_ty(*self.tcx, normalize)
224            };
225            return interp_ok(meta_ty(caller) == meta_ty(callee));
226        }
227
228        // Compatible integer types (in particular, usize vs ptr-sized-u32/u64).
229        // `char` counts as `u32.`
230        let int_ty = |ty: Ty<'tcx>| {
231            Some(match ty.kind() {
232                ty::Int(ity) => (Integer::from_int_ty(&self.tcx, *ity), /* signed */ true),
233                ty::Uint(uty) => (Integer::from_uint_ty(&self.tcx, *uty), /* signed */ false),
234                ty::Char => (Integer::I32, /* signed */ false),
235                _ => return None,
236            })
237        };
238        if let (Some(caller), Some(callee)) = (int_ty(caller.ty), int_ty(callee.ty)) {
239            // This is okay if they are the same integer type.
240            return interp_ok(caller == callee);
241        }
242
243        // Fall back to exact equality.
244        interp_ok(caller == callee)
245    }
246
247    /// Returns a `bool` saying whether the two arguments are ABI-compatible.
248    pub fn check_argument_compat(
249        &self,
250        caller_abi: &ArgAbi<'tcx, Ty<'tcx>>,
251        callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
252    ) -> InterpResult<'tcx, bool> {
253        // We do not want to accept things as ABI-compatible that just "happen to be" compatible on the current target,
254        // so we implement a type-based check that reflects the guaranteed rules for ABI compatibility.
255        if self.layout_compat(caller_abi.layout, callee_abi.layout)? {
256            // Ensure that our checks imply actual ABI compatibility for this concrete call.
257            // (This can fail e.g. if `#[rustc_nonnull_optimization_guaranteed]` is used incorrectly.)
258            if !caller_abi.eq_abi(callee_abi) {
    ::core::panicking::panic("assertion failed: caller_abi.eq_abi(callee_abi)")
};assert!(caller_abi.eq_abi(callee_abi));
259            interp_ok(true)
260        } else {
261            {
    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/call.rs:261",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(261u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("check_argument_compat: incompatible ABIs:\ncaller: {0:?}\ncallee: {1:?}",
                                                    caller_abi, callee_abi) as &dyn Value))])
            });
    } else { ; }
};trace!(
262                "check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}",
263                caller_abi, callee_abi
264            );
265            interp_ok(false)
266        }
267    }
268
269    /// Initialize a single callee argument, checking the types for compatibility.
270    fn pass_argument<'x, 'y>(
271        &mut self,
272        caller_args: &mut impl Iterator<
273            Item = (&'x FnArg<'tcx, M::Provenance>, &'y ArgAbi<'tcx, Ty<'tcx>>),
274        >,
275        callee_args_abis: &mut impl Iterator<Item = (usize, &'y ArgAbi<'tcx, Ty<'tcx>>)>,
276        callee_arg: &mir::Place<'tcx>,
277        callee_ty: Ty<'tcx>,
278        already_live: bool,
279    ) -> InterpResult<'tcx>
280    where
281        'tcx: 'x,
282        'tcx: 'y,
283    {
284        // Get next callee arg.
285        let (callee_arg_idx, callee_abi) = callee_args_abis.next().unwrap();
286        match (&callee_ty, &callee_abi.layout.ty) {
    (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);
        }
    }
};assert_eq!(callee_ty, callee_abi.layout.ty);
287        // Get next caller arg.
288        let Some((caller_arg, caller_abi)) = caller_args.next() else {
289            do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("calling a function with fewer arguments than it requires"))
                })));throw_ub_format!("calling a function with fewer arguments than it requires");
290        };
291        match (&caller_arg.layout().layout, &caller_abi.layout.layout) {
    (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);
        }
    }
};assert_eq!(caller_arg.layout().layout, caller_abi.layout.layout);
292        // Sadly we cannot assert that `caller_arg.layout().ty` and `caller_abi.layout.ty` are
293        // equal; in closures the types sometimes differ. We just hope that `caller_abi` is the
294        // right type to print to the user.
295
296        // Check compatibility
297        if !self.check_argument_compat(caller_abi, callee_abi)? {
298            do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::AbiMismatchArgument {
            arg_idx: callee_arg_idx,
            caller_ty: caller_abi.layout.ty,
            callee_ty: callee_abi.layout.ty,
        });throw_ub!(AbiMismatchArgument {
299                arg_idx: callee_arg_idx,
300                caller_ty: caller_abi.layout.ty,
301                callee_ty: callee_abi.layout.ty
302            });
303        }
304        // We work with a copy of the argument for now; if this is in-place argument passing, we
305        // will later protect the source it comes from. This means the callee cannot observe if we
306        // did in-place of by-copy argument passing, except for pointer equality tests.
307        let caller_arg_copy = caller_arg.copy_fn_arg();
308        if !already_live {
309            let local = callee_arg.as_local().unwrap();
310            let meta = caller_arg_copy.meta();
311            // `check_argument_compat` ensures that if metadata is needed, both have the same type,
312            // so we know they will use the metadata the same way.
313            if !(!meta.has_meta() || caller_arg_copy.layout.ty == callee_ty) {
    ::core::panicking::panic("assertion failed: !meta.has_meta() || caller_arg_copy.layout.ty == callee_ty")
};assert!(!meta.has_meta() || caller_arg_copy.layout.ty == callee_ty);
314
315            self.storage_live_dyn(local, meta)?;
316        }
317        // Now we can finally actually evaluate the callee place.
318        let callee_arg = self.eval_place(*callee_arg)?;
319        // We allow some transmutes here.
320        // FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
321        // is true for all `copy_op`, but there are a lot of special cases for argument passing
322        // specifically.)
323        self.copy_op_allow_transmute(&caller_arg_copy, &callee_arg)?;
324        // If this was an in-place pass, protect the place it comes from for the duration of the call.
325        if let FnArg::InPlace(mplace) = caller_arg {
326            M::protect_in_place_function_argument(self, mplace)?;
327        }
328        interp_ok(())
329    }
330
331    /// The main entry point for creating a new stack frame: performs ABI checks and initializes
332    /// arguments.
333    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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("init_stack_frame",
                                    "rustc_const_eval::interpret::call",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                    ::tracing_core::__macro_support::Option::Some(333u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::tracing_core::field::FieldSet::new(&["instance", "body",
                                                    "caller_fn_abi", "args", "with_caller_location",
                                                    "destination", "cont"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::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)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&body)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&caller_fn_abi)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&with_caller_location
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&destination)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cont)
                                                            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;
        }
        {
            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("step",
                                                "rustc_const_eval::interpret::call", ::tracing::Level::INFO,
                                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                                ::tracing_core::__macro_support::Option::Some(344u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                                ::tracing_core::field::FieldSet::new(&["step", "instance",
                                                                "tracing_separate_thread"],
                                                    ::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(&"init_stack_frame")
                                                                        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)),
                                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                                ::tracing::__macro_support::Option::Some(&Empty as
                                                                        &dyn Value))])
                                        })
                            } else {
                                let span =
                                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                                {};
                                span
                            }
                        });
            let def_id = instance.def_id();
            let extra_tys =
                if caller_fn_abi.c_variadic {
                    let fixed_count =
                        usize::try_from(caller_fn_abi.fixed_count).unwrap();
                    let extra_tys =
                        args[fixed_count..].iter().map(|arg| arg.layout().ty);
                    self.tcx.mk_type_list_from_iter(extra_tys)
                } else { ty::List::empty() };
            let callee_fn_abi =
                self.fn_abi_of_instance_no_deduced_attrs(instance,
                        extra_tys)?;
            if caller_fn_abi.conv != callee_fn_abi.conv {
                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("calling a function with calling convention \"{0}\" using calling convention \"{1}\"",
                                            callee_fn_abi.conv, caller_fn_abi.conv))
                                })))
            }
            if caller_fn_abi.c_variadic != callee_fn_abi.c_variadic {
                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::CVariadicMismatch {
                            caller_is_c_variadic: caller_fn_abi.c_variadic,
                            callee_is_c_variadic: callee_fn_abi.c_variadic,
                        });
            }
            if caller_fn_abi.c_variadic &&
                    caller_fn_abi.fixed_count != callee_fn_abi.fixed_count {
                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::CVariadicFixedCountMismatch {
                            caller: caller_fn_abi.fixed_count,
                            callee: callee_fn_abi.fixed_count,
                        });
            }
            M::check_fn_target_features(self, instance)?;
            if !callee_fn_abi.can_unwind {
                match &mut cont {
                    ReturnContinuation::Stop { .. } => {}
                    ReturnContinuation::Goto { unwind, .. } => {
                        *unwind = mir::UnwindAction::Unreachable;
                    }
                }
            }
            let destination_mplace =
                self.place_to_op(destination)?.as_mplace_or_imm().left();
            self.push_stack_frame_raw(instance, body, destination, cont)?;
            let preamble_span = self.frame().loc.unwrap_right();
            {
                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/call.rs:404",
                                    "rustc_const_eval::interpret::call",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                    ::tracing_core::__macro_support::Option::Some(404u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::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!("caller ABI: {0:#?}, args: {1:#?}",
                                                                caller_fn_abi,
                                                                args.iter().map(|arg|
                                                                            (arg.layout().ty,
                                                                                match arg {
                                                                                    FnArg::Copy(op) =>
                                                                                        ::alloc::__export::must_use({
                                                                                                ::alloc::fmt::format(format_args!("copy({0:?})", op))
                                                                                            }),
                                                                                    FnArg::InPlace(mplace) =>
                                                                                        ::alloc::__export::must_use({
                                                                                                ::alloc::fmt::format(format_args!("in-place({0:?})",
                                                                                                        mplace))
                                                                                            }),
                                                                                })).collect::<Vec<_>>()) as &dyn Value))])
                        });
                } else { ; }
            };
            {
                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/call.rs:417",
                                    "rustc_const_eval::interpret::call",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                    ::tracing_core::__macro_support::Option::Some(417u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::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!("spread_arg: {0:?}, locals: {1:#?}",
                                                                body.spread_arg,
                                                                body.args_iter().map(|local|
                                                                            (local,
                                                                                self.layout_of_local(self.frame(), local,
                                                                                            None).unwrap().ty)).collect::<Vec<_>>()) as &dyn Value))])
                        });
                } else { ; }
            };
            let va_list_arg =
                callee_fn_abi.c_variadic.then(||
                        mir::Local::from_usize(body.arg_count));
            let is_non_capturing_closure =
                (#[allow(non_exhaustive_omitted_patterns)] match instance.def
                                {
                                ty::InstanceKind::ClosureOnceShim { .. } => true,
                                _ => false,
                            } || self.tcx.is_closure_like(def_id)) &&
                    {
                        let arg = &callee_fn_abi.args[0];

                        #[allow(non_exhaustive_omitted_patterns)]
                        match arg.layout.ty.kind() {
                            ty::Closure(_def, closure_args) if
                                { closure_args.as_closure().upvar_tys().is_empty() } =>
                                true,
                            _ => false,
                        }
                    };
            match (&(args.len() + if with_caller_location { 1 } else { 0 }),
                    &caller_fn_abi.args.len()) {
                (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::Some(format_args!("mismatch between caller ABI and caller arguments")));
                    }
                }
            };
            let mut caller_args = args.iter().zip(caller_fn_abi.args.iter());
            let mut callee_args_abis = callee_fn_abi.args.iter().enumerate();
            M::with_retag_mode(self, RetagMode::FnEntry,
                    |ecx|
                        {
                            for local in body.args_iter() {
                                ecx.frame_mut().loc =
                                    Right(body.local_decls[local].source_info.span);
                                let dest = mir::Place::from(local);
                                let ty = ecx.layout_of_local(ecx.frame(), local, None)?.ty;
                                if is_non_capturing_closure && local == mir::Local::arg(0) {
                                    if !va_list_arg.is_none() {
                                        ::core::panicking::panic("assertion failed: va_list_arg.is_none()")
                                    };
                                    if !(Some(local) != body.spread_arg) {
                                        ::core::panicking::panic("assertion failed: Some(local) != body.spread_arg")
                                    };
                                    let (callee_arg_idx, callee_abi) =
                                        callee_args_abis.next().unwrap();
                                    if !(callee_abi.layout.is_1zst() && callee_abi.is_ignore())
                                        {
                                        ::core::panicking::panic("assertion failed: callee_abi.layout.is_1zst() && callee_abi.is_ignore()")
                                    };
                                    ecx.storage_live(local)?;
                                    if caller_fn_abi.args.len() == callee_fn_abi.args.len() {
                                        let (_caller_arg, caller_abi) = caller_args.next().unwrap();
                                        if !caller_abi.layout.is_1zst() {
                                            do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::AbiMismatchArgument {
                                                        arg_idx: callee_arg_idx,
                                                        caller_ty: caller_abi.layout.ty,
                                                        callee_ty: callee_abi.layout.ty,
                                                    });
                                        }
                                        if !caller_abi.is_ignore() {
                                            ::core::panicking::panic("assertion failed: caller_abi.is_ignore()")
                                        };
                                    }
                                } else if Some(local) == va_list_arg {
                                    ecx.storage_live(local)?;
                                    let place = ecx.eval_place(dest)?;
                                    let mplace = ecx.force_allocation(&place)?;
                                    let varargs =
                                        ecx.allocate_varargs(&mut caller_args,
                                                &mut callee_args_abis)?;
                                    ecx.frame_mut().va_list = varargs.clone();
                                    let key = ecx.va_list_ptr(varargs.into());
                                    ecx.write_bytes_ptr(mplace.ptr(),
                                            (0..mplace.layout.size.bytes()).map(|_| 0u8))?;
                                    let key_mplace = ecx.va_list_key_field(&mplace)?;
                                    ecx.write_pointer(key, &key_mplace)?;
                                } else if Some(local) == body.spread_arg {
                                    ecx.storage_live(local)?;
                                    let ty::Tuple(fields) =
                                        ty.kind() else {
                                            ::rustc_middle::util::bug::span_bug_fmt(ecx.cur_span(),
                                                format_args!("non-tuple type for `spread_arg`: {0}", ty))
                                        };
                                    for (i, field_ty) in fields.iter().enumerate() {
                                        let dest =
                                            dest.project_deeper(&[mir::ProjectionElem::Field(FieldIdx::from_usize(i),
                                                                field_ty)], *ecx.tcx);
                                        ecx.pass_argument(&mut caller_args, &mut callee_args_abis,
                                                &dest, field_ty, true)?;
                                    }
                                } else {
                                    ecx.pass_argument(&mut caller_args, &mut callee_args_abis,
                                            &dest, ty, false)?;
                                }
                            }
                            interp_ok(())
                        })?;
            self.frame_mut().loc =
                Right(body.local_decls[mir::RETURN_PLACE].source_info.span);
            if !self.check_argument_compat(&caller_fn_abi.ret,
                            &callee_fn_abi.ret)? {
                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::AbiMismatchReturn {
                            caller_ty: caller_fn_abi.ret.layout.ty,
                            callee_ty: callee_fn_abi.ret.layout.ty,
                        });
            }
            if let Some(mplace) = destination_mplace {
                M::protect_in_place_function_argument(self, &mplace)?;
            }
            self.frame_mut().loc = Right(preamble_span);
            if instance.def.requires_caller_location(*self.tcx) {
                callee_args_abis.next().unwrap();
            }
            if !callee_args_abis.next().is_none() {
                {
                    ::core::panicking::panic_fmt(format_args!("mismatch between callee ABI and callee body arguments"));
                }
            };
            if caller_args.next().is_some() {
                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("calling a function with more arguments than it expected"))
                                })));
            }
            self.push_stack_frame_done()
        }
    }
}#[instrument(skip(self), level = "trace")]
334    pub fn init_stack_frame(
335        &mut self,
336        instance: Instance<'tcx>,
337        body: &'tcx mir::Body<'tcx>,
338        caller_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
339        args: &[FnArg<'tcx, M::Provenance>],
340        with_caller_location: bool,
341        destination: &PlaceTy<'tcx, M::Provenance>,
342        mut cont: ReturnContinuation,
343    ) -> InterpResult<'tcx> {
344        let _trace = enter_trace_span!(M, step::init_stack_frame, %instance, tracing_separate_thread = Empty);
345        let def_id = instance.def_id();
346
347        // The first order of business is to figure out the callee signature.
348        // However, that requires the list of variadic arguments.
349        // We use the *caller* information to determine where to split the list of arguments,
350        // and then later check that the callee indeed has the same number of fixed arguments.
351        let extra_tys = if caller_fn_abi.c_variadic {
352            let fixed_count = usize::try_from(caller_fn_abi.fixed_count).unwrap();
353            let extra_tys = args[fixed_count..].iter().map(|arg| arg.layout().ty);
354            self.tcx.mk_type_list_from_iter(extra_tys)
355        } else {
356            ty::List::empty()
357        };
358        let callee_fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, extra_tys)?;
359
360        if caller_fn_abi.conv != callee_fn_abi.conv {
361            throw_ub_format!(
362                "calling a function with calling convention \"{callee_conv}\" using calling convention \"{caller_conv}\"",
363                callee_conv = callee_fn_abi.conv,
364                caller_conv = caller_fn_abi.conv,
365            )
366        }
367
368        if caller_fn_abi.c_variadic != callee_fn_abi.c_variadic {
369            throw_ub!(CVariadicMismatch {
370                caller_is_c_variadic: caller_fn_abi.c_variadic,
371                callee_is_c_variadic: callee_fn_abi.c_variadic,
372            });
373        }
374        if caller_fn_abi.c_variadic && caller_fn_abi.fixed_count != callee_fn_abi.fixed_count {
375            throw_ub!(CVariadicFixedCountMismatch {
376                caller: caller_fn_abi.fixed_count,
377                callee: callee_fn_abi.fixed_count,
378            });
379        }
380
381        // Check that all target features required by the callee (i.e., from
382        // the attribute `#[target_feature(enable = ...)]`) are enabled at
383        // compile time.
384        M::check_fn_target_features(self, instance)?;
385
386        if !callee_fn_abi.can_unwind {
387            // The callee cannot unwind, so force the `Unreachable` unwind handling.
388            match &mut cont {
389                ReturnContinuation::Stop { .. } => {}
390                ReturnContinuation::Goto { unwind, .. } => {
391                    *unwind = mir::UnwindAction::Unreachable;
392                }
393            }
394        }
395
396        // *Before* pushing the new frame, determine whether the return destination is in memory.
397        // Need to use `place_to_op` to be *sure* we get the mplace if there is one.
398        let destination_mplace = self.place_to_op(destination)?.as_mplace_or_imm().left();
399
400        // Push the "raw" frame -- this leaves locals uninitialized.
401        self.push_stack_frame_raw(instance, body, destination, cont)?;
402        let preamble_span = self.frame().loc.unwrap_right(); // the span used for preamble errors
403
404        trace!(
405            "caller ABI: {:#?}, args: {:#?}",
406            caller_fn_abi,
407            args.iter()
408                .map(|arg| (
409                    arg.layout().ty,
410                    match arg {
411                        FnArg::Copy(op) => format!("copy({op:?})"),
412                        FnArg::InPlace(mplace) => format!("in-place({mplace:?})"),
413                    }
414                ))
415                .collect::<Vec<_>>()
416        );
417        trace!(
418            "spread_arg: {:?}, locals: {:#?}",
419            body.spread_arg,
420            body.args_iter()
421                .map(|local| (local, self.layout_of_local(self.frame(), local, None).unwrap().ty))
422                .collect::<Vec<_>>()
423        );
424
425        // Determine whether there is a special VaList argument. This is always the
426        // last argument, and since arguments start at index 1 that's `arg_count`.
427        let va_list_arg = callee_fn_abi.c_variadic.then(|| mir::Local::from_usize(body.arg_count));
428        // Determine whether this is a non-capturing closure. That's relevant as their first
429        // argument can be skipped (and that's the only kind of argument skipping we allow).
430        let is_non_capturing_closure =
431            (matches!(instance.def, ty::InstanceKind::ClosureOnceShim { .. })
432                || self.tcx.is_closure_like(def_id))
433                && {
434                    let arg = &callee_fn_abi.args[0];
435                    matches!(arg.layout.ty.kind(), ty::Closure (_def, closure_args) if {
436                        closure_args.as_closure().upvar_tys().is_empty()
437                    })
438                };
439
440        // In principle, we have two iterators: Where the arguments come from, and where
441        // they go to.
442
443        // The "where they come from" part is easy, we expect the caller to do any special handling
444        // that might be required here (e.g. for untupling).
445        // If `with_caller_location` is set we pretend there is an extra argument (that
446        // we will not pass; our `caller_location` intrinsic implementation walks the stack instead).
447        assert_eq!(
448            args.len() + if with_caller_location { 1 } else { 0 },
449            caller_fn_abi.args.len(),
450            "mismatch between caller ABI and caller arguments",
451        );
452        let mut caller_args = args.iter().zip(caller_fn_abi.args.iter());
453
454        // Now we have to spread them out across the callee's locals,
455        // taking into account the `spread_arg`. If we could write
456        // this is a single iterator (that handles `spread_arg`), then
457        // `pass_argument` would be the loop body.
458        let mut callee_args_abis = callee_fn_abi.args.iter().enumerate();
459        // During argument passing, we want retagging with protectors.
460        M::with_retag_mode(self, RetagMode::FnEntry, |ecx| {
461            for local in body.args_iter() {
462                // Update the span that we show in case of an error to point to this argument.
463                ecx.frame_mut().loc = Right(body.local_decls[local].source_info.span);
464                // Construct the destination place for this argument. At this point all
465                // locals are still dead, so we cannot construct a `PlaceTy`.
466                let dest = mir::Place::from(local);
467                // `layout_of_local` does more than just the instantiation we need to get the
468                // type, but the result gets cached so this avoids calling the instantiation
469                // query *again* the next time this local is accessed.
470                let ty = ecx.layout_of_local(ecx.frame(), local, None)?.ty;
471
472                // Some arguments are special: the first (`self`) argument of a non-capturing
473                // closure; the va_list argument; and the spread_arg.
474                if is_non_capturing_closure && local == mir::Local::arg(0) {
475                    assert!(va_list_arg.is_none());
476                    assert!(Some(local) != body.spread_arg);
477                    // This argument might be missing on the caller side. So just initialize it in
478                    // the callee.
479                    let (callee_arg_idx, callee_abi) = callee_args_abis.next().unwrap();
480                    assert!(callee_abi.layout.is_1zst() && callee_abi.is_ignore());
481                    ecx.storage_live(local)?;
482                    // And skip it in the caller, if present. We can tell whether it is present by
483                    // comparing the number of arguments on the caller and callee side.
484                    if caller_fn_abi.args.len() == callee_fn_abi.args.len() {
485                        let (_caller_arg, caller_abi) = caller_args.next().unwrap();
486                        if !caller_abi.layout.is_1zst() {
487                            // The caller gave us some other, non-ignorable argument.
488                            throw_ub!(AbiMismatchArgument {
489                                arg_idx: callee_arg_idx,
490                                caller_ty: caller_abi.layout.ty,
491                                callee_ty: callee_abi.layout.ty
492                            });
493                        }
494                        assert!(caller_abi.is_ignore());
495                    }
496                } else if Some(local) == va_list_arg {
497                    // This is the last callee-side argument of a variadic function.
498                    // This argument is a VaList holding the remaining caller-side arguments.
499                    ecx.storage_live(local)?;
500
501                    let place = ecx.eval_place(dest)?;
502                    let mplace = ecx.force_allocation(&place)?;
503
504                    // Consume the remaining arguments by putting them into the variable argument
505                    // list.
506                    let varargs = ecx.allocate_varargs(&mut caller_args, &mut callee_args_abis)?;
507                    // When the frame is dropped, these variable arguments are deallocated.
508                    ecx.frame_mut().va_list = varargs.clone();
509                    let key = ecx.va_list_ptr(varargs.into());
510
511                    // Zero the VaList, so it is fully initialized.
512                    ecx.write_bytes_ptr(
513                        mplace.ptr(),
514                        (0..mplace.layout.size.bytes()).map(|_| 0u8),
515                    )?;
516
517                    // Store the "key" pointer in the right field.
518                    let key_mplace = ecx.va_list_key_field(&mplace)?;
519                    ecx.write_pointer(key, &key_mplace)?;
520                } else if Some(local) == body.spread_arg {
521                    // Make the local live once, then fill in the value field by field.
522                    ecx.storage_live(local)?;
523                    // Must be a tuple
524                    let ty::Tuple(fields) = ty.kind() else {
525                        span_bug!(ecx.cur_span(), "non-tuple type for `spread_arg`: {ty}")
526                    };
527                    for (i, field_ty) in fields.iter().enumerate() {
528                        let dest = dest.project_deeper(
529                            &[mir::ProjectionElem::Field(FieldIdx::from_usize(i), field_ty)],
530                            *ecx.tcx,
531                        );
532                        ecx.pass_argument(
533                            &mut caller_args,
534                            &mut callee_args_abis,
535                            &dest,
536                            field_ty,
537                            /* already_live */ true,
538                        )?;
539                    }
540                } else {
541                    // Normal argument. Cannot mark it as live yet, it might be unsized!
542                    ecx.pass_argument(
543                        &mut caller_args,
544                        &mut callee_args_abis,
545                        &dest,
546                        ty,
547                        /* already_live */ false,
548                    )?;
549                }
550            }
551            interp_ok(())
552        })?;
553
554        // Don't forget to check the return type!
555        self.frame_mut().loc = Right(body.local_decls[mir::RETURN_PLACE].source_info.span);
556        if !self.check_argument_compat(&caller_fn_abi.ret, &callee_fn_abi.ret)? {
557            throw_ub!(AbiMismatchReturn {
558                caller_ty: caller_fn_abi.ret.layout.ty,
559                callee_ty: callee_fn_abi.ret.layout.ty
560            });
561        }
562        // Protect return place for in-place return value passing.
563        // We only need to protect anything if this is actually an in-memory place.
564        if let Some(mplace) = destination_mplace {
565            M::protect_in_place_function_argument(self, &mplace)?;
566        }
567
568        // For the final checks, use same span as preamble since it is unclear what else to do.
569        self.frame_mut().loc = Right(preamble_span);
570        // If the callee needs a caller location, pretend we consume one more argument from the ABI.
571        if instance.def.requires_caller_location(*self.tcx) {
572            callee_args_abis.next().unwrap();
573        }
574        // Now we should have no more caller args or callee arg ABIs.
575        assert!(
576            callee_args_abis.next().is_none(),
577            "mismatch between callee ABI and callee body arguments"
578        );
579        if caller_args.next().is_some() {
580            throw_ub_format!("calling a function with more arguments than it expected");
581        }
582
583        // Done!
584        self.push_stack_frame_done()
585    }
586
587    /// Initiate a call to this function -- pushing the stack frame and initializing the arguments.
588    ///
589    /// `caller_fn_abi` is used to determine if all the arguments are passed the proper way.
590    /// However, we also need `caller_abi` to determine if we need to do untupling of arguments.
591    ///
592    /// `with_caller_location` indicates whether the caller passed a caller location. Miri
593    /// implements caller locations without argument passing, but to match `FnAbi` we need to know
594    /// when those arguments are present.
595    pub(super) fn init_fn_call(
596        &mut self,
597        fn_val: FnVal<'tcx, M::ExtraFnVal>,
598        (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx, Ty<'tcx>>),
599        args: &[FnArg<'tcx, M::Provenance>],
600        with_caller_location: bool,
601        destination: &PlaceTy<'tcx, M::Provenance>,
602        target: Option<mir::BasicBlock>,
603        unwind: mir::UnwindAction,
604    ) -> InterpResult<'tcx> {
605        let _trace =
606            <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("step",
                                "rustc_const_eval::interpret::call", ::tracing::Level::INFO,
                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                ::tracing_core::__macro_support::Option::Some(606u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                ::tracing_core::field::FieldSet::new(&["step",
                                                "tracing_separate_thread", "fn_val"],
                                    ::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(&"init_fn_call")
                                                        as &dyn Value)),
                                            (&::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(&debug(&fn_val) as
                                                        &dyn Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        })enter_trace_span!(M, step::init_fn_call, tracing_separate_thread = Empty, ?fn_val)
607                .or_if_tracing_disabled(|| {
    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/call.rs:607",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(607u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("init_fn_call: {0:#?}",
                                                    fn_val) as &dyn Value))])
            });
    } else { ; }
}trace!("init_fn_call: {:#?}", fn_val));
608
609        let instance = match fn_val {
610            FnVal::Instance(instance) => instance,
611            FnVal::Other(extra) => {
612                return M::call_extra_fn(
613                    self,
614                    extra,
615                    caller_fn_abi,
616                    args,
617                    destination,
618                    target,
619                    unwind,
620                );
621            }
622        };
623
624        match instance.def {
625            ty::InstanceKind::Intrinsic(def_id) => {
626                if !self.tcx.intrinsic(def_id).is_some() {
    ::core::panicking::panic("assertion failed: self.tcx.intrinsic(def_id).is_some()")
};assert!(self.tcx.intrinsic(def_id).is_some());
627                // FIXME: Should `InPlace` arguments be reset to uninit?
628                if let Some(fallback) = M::call_intrinsic(
629                    self,
630                    instance,
631                    &Self::copy_fn_args(args),
632                    destination,
633                    target,
634                    unwind,
635                )? {
636                    if !!self.tcx.intrinsic(fallback.def_id()).unwrap().must_be_overridden {
    ::core::panicking::panic("assertion failed: !self.tcx.intrinsic(fallback.def_id()).unwrap().must_be_overridden")
};assert!(!self.tcx.intrinsic(fallback.def_id()).unwrap().must_be_overridden);
637                    {
    match fallback.def {
        ty::InstanceKind::Item(_) => {}
        ref left_val => {
            ::core::panicking::assert_matches_failed(left_val,
                "ty::InstanceKind::Item(_)", ::core::option::Option::None);
        }
    }
};assert_matches!(fallback.def, ty::InstanceKind::Item(_));
638                    return self.init_fn_call(
639                        FnVal::Instance(fallback),
640                        (caller_abi, caller_fn_abi),
641                        args,
642                        with_caller_location,
643                        destination,
644                        target,
645                        unwind,
646                    );
647                } else {
648                    interp_ok(())
649                }
650            }
651            ty::InstanceKind::VTableShim(..)
652            | ty::InstanceKind::ReifyShim(..)
653            | ty::InstanceKind::ClosureOnceShim { .. }
654            | ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
655            | ty::InstanceKind::FnPtrShim(..)
656            | ty::InstanceKind::DropGlue(..)
657            | ty::InstanceKind::CloneShim(..)
658            | ty::InstanceKind::FnPtrAddrShim(..)
659            | ty::InstanceKind::ThreadLocalShim(..)
660            | ty::InstanceKind::AsyncDropGlueCtorShim(..)
661            | ty::InstanceKind::AsyncDropGlue(..)
662            | ty::InstanceKind::FutureDropPollShim(..)
663            | ty::InstanceKind::Item(_) => {
664                // We need MIR for this fn.
665                // Note that this can be an intrinsic, if we are executing its fallback body.
666                let Some((body, instance)) = M::find_mir_or_eval_fn(
667                    self,
668                    instance,
669                    caller_fn_abi,
670                    args,
671                    destination,
672                    target,
673                    unwind,
674                )?
675                else {
676                    return interp_ok(());
677                };
678
679                // Special handling for the closure ABI: untuple the last argument.
680                let args: Cow<'_, [FnArg<'tcx, M::Provenance>]> =
681                    if caller_abi == ExternAbi::RustCall && !args.is_empty() {
682                        // Untuple
683                        let (untuple_arg, args) = args.split_last().unwrap();
684                        let ty::Tuple(untuple_fields) = untuple_arg.layout().ty.kind() else {
685                            ::rustc_middle::util::bug::span_bug_fmt(self.cur_span(),
    format_args!("untuple argument must be a tuple"))span_bug!(self.cur_span(), "untuple argument must be a tuple")
686                        };
687                        {
    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/call.rs:687",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(687u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("init_fn_call: Will pass last argument by untupling")
                                            as &dyn Value))])
            });
    } else { ; }
};trace!("init_fn_call: Will pass last argument by untupling");
688                        Cow::from(
689                            args.iter()
690                                // The regular arguments.
691                                .map(|a| interp_ok(a.clone()))
692                                // The fields of the untupled argument.
693                                .chain((0..untuple_fields.len()).map(|i| {
694                                    self.fn_arg_project_field(untuple_arg, FieldIdx::from_usize(i))
695                                }))
696                                .collect::<InterpResult<'_, Vec<_>>>()?,
697                        )
698                    } else {
699                        // Plain arg passing
700                        Cow::from(args)
701                    };
702
703                self.init_stack_frame(
704                    instance,
705                    body,
706                    caller_fn_abi,
707                    &args,
708                    with_caller_location,
709                    destination,
710                    ReturnContinuation::Goto { ret: target, unwind },
711                )
712            }
713            // `InstanceKind::Virtual` does not have callable MIR. Calls to `Virtual` instances must be
714            // codegen'd / interpreted as virtual calls through the vtable.
715            ty::InstanceKind::Virtual(def_id, idx) => {
716                let mut args = args.to_vec();
717                // We have to implement all "dyn-compatible receivers". So we have to go search for a
718                // pointer or `dyn Trait` type, but it could be wrapped in newtypes. So recursively
719                // unwrap those newtypes until we are there.
720                // An `InPlace` does nothing here, we keep the original receiver intact. We can't
721                // really pass the argument in-place anyway, and we are constructing a new
722                // `Immediate` receiver.
723                let mut receiver = args[0].copy_fn_arg();
724                let receiver_place = loop {
725                    match receiver.layout.ty.kind() {
726                        ty::Ref(..) | ty::RawPtr(..) => {
727                            // We do *not* use `deref_pointer` here: we don't want to conceptually
728                            // create a place that must be dereferenceable, since the receiver might
729                            // be a raw pointer and (for `*const dyn Trait`) we don't need to
730                            // actually access memory to resolve this method.
731                            // Also see <https://github.com/rust-lang/miri/issues/2786>.
732                            let val = self.read_immediate(&receiver)?;
733                            break self.imm_ptr_to_mplace(&val)?;
734                        }
735                        ty::Dynamic(..) => break receiver.assert_mem_place(), // no immediate unsized values
736                        _ => {
737                            // Not there yet, search for the only non-ZST field.
738                            // (The rules for `DispatchFromDyn` ensure there's exactly one such field.)
739                            let (idx, _) = receiver.layout.non_1zst_field(self).expect(
740                                "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
741                            );
742                            receiver = self.project_field(&receiver, idx)?;
743                        }
744                    }
745                };
746
747                // Obtain the underlying trait we are working on, and the adjusted receiver argument.
748                // Doesn't have to be a `dyn Trait`, but the unsized tail must be `dyn Trait`.
749                // (For that reason we also cannot use `unpack_dyn_trait`.)
750                let receiver_tail =
751                    self.tcx.struct_tail_for_codegen(receiver_place.layout.ty, self.typing_env);
752                let ty::Dynamic(receiver_trait, _) = receiver_tail.kind() else {
753                    ::rustc_middle::util::bug::span_bug_fmt(self.cur_span(),
    format_args!("dynamic call on non-`dyn` type {0}", receiver_tail))span_bug!(self.cur_span(), "dynamic call on non-`dyn` type {}", receiver_tail)
754                };
755                if !receiver_place.layout.is_unsized() {
    ::core::panicking::panic("assertion failed: receiver_place.layout.is_unsized()")
};assert!(receiver_place.layout.is_unsized());
756
757                // Get the required information from the vtable.
758                let vptr = receiver_place.meta().unwrap_meta().to_pointer(self)?;
759                let dyn_ty = self.get_ptr_vtable_ty(vptr, Some(receiver_trait))?;
760                let adjusted_recv = receiver_place.ptr();
761
762                // Now determine the actual method to call. Usually we use the easy way of just
763                // looking up the method at index `idx`.
764                let vtable_entries = self.vtable_entries(receiver_trait.principal(), dyn_ty);
765                let Some(ty::VtblEntry::Method(fn_inst)) = vtable_entries.get(idx).copied() else {
766                    // FIXME(fee1-dead) these could be variants of the UB info enum instead of this
767                    do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("`dyn` call trying to call something that is not a method"))
                })));throw_ub_format!("`dyn` call trying to call something that is not a method");
768                };
769                {
    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/call.rs:769",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(769u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("Virtual call dispatches to {0:#?}",
                                                    fn_inst) as &dyn Value))])
            });
    } else { ; }
};trace!("Virtual call dispatches to {fn_inst:#?}");
770                // We can also do the lookup based on `def_id` and `dyn_ty`, and check that that
771                // produces the same result.
772                self.assert_virtual_instance_matches_concrete(dyn_ty, def_id, instance, fn_inst);
773
774                // Adjust receiver argument. Layout can be any (thin) ptr.
775                let receiver_ty = Ty::new_mut_ptr(self.tcx.tcx, dyn_ty);
776                args[0] = FnArg::Copy(
777                    ImmTy::from_immediate(
778                        Scalar::from_maybe_pointer(adjusted_recv, self).into(),
779                        self.layout_of(receiver_ty)?,
780                    )
781                    .into(),
782                );
783                {
    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/call.rs:783",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(783u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("Patched receiver operand to {0:#?}",
                                                    args[0]) as &dyn Value))])
            });
    } else { ; }
};trace!("Patched receiver operand to {:#?}", args[0]);
784                // Need to also adjust the type in the ABI. Strangely, the layout there is actually
785                // already fine! Just the type is bogus. This is due to what `force_thin_self_ptr`
786                // does in `fn_abi_new_uncached`; supposedly, codegen relies on having the bogus
787                // type, so we just patch this up locally.
788                let mut caller_fn_abi = caller_fn_abi.clone();
789                caller_fn_abi.args[0].layout.ty = receiver_ty;
790
791                // recurse with concrete function
792                self.init_fn_call(
793                    FnVal::Instance(fn_inst),
794                    (caller_abi, &caller_fn_abi),
795                    &args,
796                    with_caller_location,
797                    destination,
798                    target,
799                    unwind,
800                )
801            }
802        }
803    }
804
805    fn assert_virtual_instance_matches_concrete(
806        &self,
807        dyn_ty: Ty<'tcx>,
808        def_id: DefId,
809        virtual_instance: ty::Instance<'tcx>,
810        concrete_instance: ty::Instance<'tcx>,
811    ) {
812        let tcx = *self.tcx;
813
814        let trait_def_id = tcx.parent(def_id);
815        let virtual_trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, virtual_instance.args);
816        let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
817        let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
818
819        let concrete_method = {
820            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("resolve",
                                "rustc_const_eval::interpret::call", ::tracing::Level::INFO,
                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                ::tracing_core::__macro_support::Option::Some(820u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                ::tracing_core::field::FieldSet::new(&["resolve", "def_id"],
                                    ::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(&"expect_resolve_for_vtable")
                                                        as &dyn Value)),
                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&def_id) as
                                                        &dyn Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        })enter_trace_span!(M, resolve::expect_resolve_for_vtable, ?def_id);
821            Instance::expect_resolve_for_vtable(
822                tcx,
823                self.typing_env,
824                def_id,
825                virtual_instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args),
826                self.cur_span(),
827            )
828        };
829        match (&concrete_instance, &concrete_method) {
    (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);
        }
    }
};assert_eq!(concrete_instance, concrete_method);
830    }
831
832    /// Initiate a tail call to this function -- popping the current stack frame, pushing the new
833    /// stack frame and initializing the arguments.
834    pub(super) fn init_fn_tail_call(
835        &mut self,
836        fn_val: FnVal<'tcx, M::ExtraFnVal>,
837        (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx, Ty<'tcx>>),
838        args: &[FnArg<'tcx, M::Provenance>],
839        with_caller_location: bool,
840    ) -> InterpResult<'tcx> {
841        {
    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/call.rs:841",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(841u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("init_fn_tail_call: {0:#?}",
                                                    fn_val) as &dyn Value))])
            });
    } else { ; }
};trace!("init_fn_tail_call: {:#?}", fn_val);
842        // This is the "canonical" implementation of tails calls,
843        // a pop of the current stack frame, followed by a normal call
844        // which pushes a new stack frame, with the return address from
845        // the popped stack frame.
846        //
847        // Note that we cannot use `return_from_current_stack_frame`,
848        // as that "executes" the goto to the return block, but we don't want to,
849        // only the tail called function should return to the current return block.
850
851        // The arguments need to all be copied since the current stack frame will be removed
852        // before the callee even starts executing.
853        // FIXME(explicit_tail_calls,#144855): does this match what codegen does?
854        let args = args.iter().map(|fn_arg| FnArg::Copy(fn_arg.copy_fn_arg())).collect::<Vec<_>>();
855        // Remove the frame from the stack.
856        let frame = self.pop_stack_frame_raw()?;
857        // Remember where this frame would have returned to.
858        let ReturnContinuation::Goto { ret, unwind } = frame.return_cont() else {
859            ::rustc_middle::util::bug::bug_fmt(format_args!("can\'t tailcall as root of the stack"));bug!("can't tailcall as root of the stack");
860        };
861        // There's no return value to deal with! Instead, we forward the old return place
862        // to the new function.
863        // FIXME(explicit_tail_calls):
864        //   we should check if both caller&callee can/n't unwind,
865        //   see <https://github.com/rust-lang/rust/pull/113128#issuecomment-1614979803>
866
867        // Now push the new stack frame.
868        self.init_fn_call(
869            fn_val,
870            (caller_abi, caller_fn_abi),
871            &*args,
872            with_caller_location,
873            frame.return_place(),
874            ret,
875            unwind,
876        )?;
877
878        // Finally, clear the local variables. Has to be done after pushing to support
879        // non-scalar arguments.
880        // FIXME(explicit_tail_calls,#144855): revisit this once codegen supports indirect
881        // arguments, to ensure the semantics are compatible.
882        let return_action = self.cleanup_stack_frame(/* unwinding */ false, frame)?;
883        match (&return_action, &ReturnAction::Normal) {
    (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);
        }
    }
};assert_eq!(return_action, ReturnAction::Normal);
884
885        interp_ok(())
886    }
887
888    pub(super) fn init_drop_in_place_call(
889        &mut self,
890        place: &PlaceTy<'tcx, M::Provenance>,
891        instance: ty::Instance<'tcx>,
892        target: mir::BasicBlock,
893        unwind: mir::UnwindAction,
894    ) -> InterpResult<'tcx> {
895        {
    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/call.rs:895",
                        "rustc_const_eval::interpret::call",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                        ::tracing_core::__macro_support::Option::Some(895u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                        ::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!("init_drop_in_place_call: {0:?},\n  instance={1:?}",
                                                    place, instance) as &dyn Value))])
            });
    } else { ; }
};trace!("init_drop_in_place_call: {:?},\n  instance={:?}", place, instance);
896        // We take the address of the object. This may well be unaligned, which is fine
897        // for us here. However, unaligned accesses will probably make the actual drop
898        // implementation fail -- a problem shared by rustc.
899        let place = self.force_allocation(place)?;
900
901        // We behave a bit different from codegen here.
902        // Codegen creates an `InstanceKind::Virtual` with index 0 (the slot of the drop method) and
903        // then dispatches that to the normal call machinery. However, our call machinery currently
904        // only supports calling `VtblEntry::Method`; it would choke on a `MetadataDropInPlace`. So
905        // instead we do the virtual call stuff ourselves. It's easier here than in `eval_fn_call`
906        // since we can just get a place of the underlying type and use `mplace_to_imm_ptr`.
907        let place = match place.layout.ty.kind() {
908            ty::Dynamic(data, _) => {
909                // Dropping a trait object. Need to find actual drop fn.
910                self.unpack_dyn_trait(&place, data)?
911            }
912            _ => {
913                if true {
    match (&instance,
            &ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty)) {
        (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);
            }
        }
    };
};debug_assert_eq!(
914                    instance,
915                    ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
916                );
917                place
918            }
919        };
920
921        let instance = {
922            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("resolve",
                                "rustc_const_eval::interpret::call", ::tracing::Level::INFO,
                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                ::tracing_core::__macro_support::Option::Some(922u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                ::tracing_core::field::FieldSet::new(&["resolve", "ty"],
                                    ::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(&"resolve_drop_glue")
                                                        as &dyn Value)),
                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&place.layout.ty)
                                                        as &dyn Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        })enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty);
923            ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
924        };
925        let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?;
926
927        let ref_ty = Ty::new_mut_ref(self.tcx.tcx, self.tcx.lifetimes.re_erased, place.layout.ty);
928        let arg = self.mplace_to_imm_ptr(&place, Some(ref_ty))?;
929
930        let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?);
931
932        self.init_fn_call(
933            FnVal::Instance(instance),
934            (ExternAbi::Rust, fn_abi),
935            &[FnArg::Copy(arg.into())],
936            false,
937            &ret.into(),
938            Some(target),
939            unwind,
940        )
941    }
942
943    /// Pops the current frame from the stack, copies the return value to the caller, deallocates
944    /// the memory for allocated locals, and jumps to an appropriate place.
945    ///
946    /// If `unwinding` is `false`, then we are performing a normal return
947    /// from a function. In this case, we jump back into the frame of the caller,
948    /// and continue execution as normal.
949    ///
950    /// If `unwinding` is `true`, then we are in the middle of a panic,
951    /// and need to unwind this frame. In this case, we jump to the
952    /// `cleanup` block for the function, which is responsible for running
953    /// `Drop` impls for any locals that have been initialized at this point.
954    /// The cleanup block ends with a special `Resume` terminator, which will
955    /// cause us to continue unwinding.
956    #[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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("return_from_current_stack_frame",
                                    "rustc_const_eval::interpret::call",
                                    ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                    ::tracing_core::__macro_support::Option::Some(956u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::tracing_core::field::FieldSet::new(&["unwinding"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::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(&unwinding 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/call.rs:961",
                                    "rustc_const_eval::interpret::call", ::tracing::Level::INFO,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                    ::tracing_core::__macro_support::Option::Some(961u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::INFO <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::INFO <=
                                ::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!("popping stack frame ({0})",
                                                                if unwinding {
                                                                    "during unwinding"
                                                                } else { "returning from function" }) as &dyn Value))])
                        });
                } else { ; }
            };
            match (&unwinding,
                    &match self.frame().loc {
                            Left(loc) => self.body().basic_blocks[loc.block].is_cleanup,
                            Right(_) => true,
                        }) {
                (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);
                    }
                }
            };
            if unwinding && self.frame_idx() == 0 {
                do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
                                    ::alloc::fmt::format(format_args!("unwinding past the topmost frame of the stack"))
                                })));
            }
            let return_op =
                self.local_to_op(mir::RETURN_PLACE,
                        None).expect("return place should always be live");
            let frame = self.pop_stack_frame_raw()?;
            if !unwinding {
                self.copy_op_allow_transmute(&return_op,
                        frame.return_place())?;
                {
                    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/call.rs:987",
                                        "rustc_const_eval::interpret::call",
                                        ::tracing::Level::TRACE,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/interpret/call.rs"),
                                        ::tracing_core::__macro_support::Option::Some(987u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                        ::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!("return value: {0:?}",
                                                                    self.dump_place(frame.return_place())) as &dyn Value))])
                            });
                    } else { ; }
                };
            }
            let return_cont = frame.return_cont();
            let return_action = self.cleanup_stack_frame(unwinding, frame)?;
            match return_action {
                ReturnAction::Normal => {}
                ReturnAction::NoJump => { return interp_ok(()); }
                ReturnAction::NoCleanup => {
                    if !self.stack().is_empty() {
                        {
                            ::core::panicking::panic_fmt(format_args!("only the topmost frame should ever be leaked"));
                        }
                    };
                    if !!unwinding {
                        {
                            ::core::panicking::panic_fmt(format_args!("tried to skip cleanup during unwinding"));
                        }
                    };
                    return interp_ok(());
                }
            }
            if unwinding {
                match return_cont {
                    ReturnContinuation::Goto { unwind, .. } => {
                        self.unwind_to_block(unwind)
                    }
                    ReturnContinuation::Stop { .. } => {
                        {
                            ::core::panicking::panic_fmt(format_args!("encountered ReturnContinuation::Stop when unwinding!"));
                        }
                    }
                }
            } else {
                match return_cont {
                    ReturnContinuation::Goto { ret, .. } =>
                        self.return_to_block(ret),
                    ReturnContinuation::Stop { .. } => {
                        if !self.stack().is_empty() {
                            {
                                ::core::panicking::panic_fmt(format_args!("only the bottommost frame can have ReturnContinuation::Stop"));
                            }
                        };
                        interp_ok(())
                    }
                }
            }
        }
    }
}#[instrument(skip(self), level = "trace")]
957    pub(super) fn return_from_current_stack_frame(
958        &mut self,
959        unwinding: bool,
960    ) -> InterpResult<'tcx> {
961        info!(
962            "popping stack frame ({})",
963            if unwinding { "during unwinding" } else { "returning from function" }
964        );
965
966        // Check `unwinding`.
967        assert_eq!(
968            unwinding,
969            match self.frame().loc {
970                Left(loc) => self.body().basic_blocks[loc.block].is_cleanup,
971                Right(_) => true,
972            }
973        );
974        if unwinding && self.frame_idx() == 0 {
975            throw_ub_format!("unwinding past the topmost frame of the stack");
976        }
977
978        // Get out the return value. Must happen *before* the frame is popped as we have to get the
979        // local's value out.
980        let return_op =
981            self.local_to_op(mir::RETURN_PLACE, None).expect("return place should always be live");
982        // Remove the frame from the stack.
983        let frame = self.pop_stack_frame_raw()?;
984        // Copy the return value and remember the return continuation.
985        if !unwinding {
986            self.copy_op_allow_transmute(&return_op, frame.return_place())?;
987            trace!("return value: {:?}", self.dump_place(frame.return_place()));
988        }
989        let return_cont = frame.return_cont();
990        // Finish popping the stack frame.
991        let return_action = self.cleanup_stack_frame(unwinding, frame)?;
992        // Jump to the next block.
993        match return_action {
994            ReturnAction::Normal => {}
995            ReturnAction::NoJump => {
996                // The hook already did everything.
997                return interp_ok(());
998            }
999            ReturnAction::NoCleanup => {
1000                // If we are not doing cleanup, also skip everything else.
1001                assert!(self.stack().is_empty(), "only the topmost frame should ever be leaked");
1002                assert!(!unwinding, "tried to skip cleanup during unwinding");
1003                // Don't jump anywhere.
1004                return interp_ok(());
1005            }
1006        }
1007
1008        // Normal return, figure out where to jump.
1009        if unwinding {
1010            // Follow the unwind edge.
1011            match return_cont {
1012                ReturnContinuation::Goto { unwind, .. } => {
1013                    // This must be the very last thing that happens, since it can in fact push a new stack frame.
1014                    self.unwind_to_block(unwind)
1015                }
1016                ReturnContinuation::Stop { .. } => {
1017                    panic!("encountered ReturnContinuation::Stop when unwinding!")
1018                }
1019            }
1020        } else {
1021            // Follow the normal return edge.
1022            match return_cont {
1023                ReturnContinuation::Goto { ret, .. } => self.return_to_block(ret),
1024                ReturnContinuation::Stop { .. } => {
1025                    assert!(
1026                        self.stack().is_empty(),
1027                        "only the bottommost frame can have ReturnContinuation::Stop"
1028                    );
1029                    interp_ok(())
1030                }
1031            }
1032        }
1033    }
1034}