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    /// Returns whether the given type has trivial ABI.
74    fn has_trivial_abi(&self, layout: TyAndLayout<'tcx>) -> InterpResult<'tcx, bool> {
75        if !layout.is_1zst() {
76            return interp_ok(false);
77        }
78        match *layout.ty.kind() {
79            // Trivially trivial-ABI types (because Rust makes no promises about their ABI).
80            ty::Tuple(..)
81            | ty::Never
82            | ty::FnDef(..)
83            | ty::Closure(..)
84            | ty::Coroutine(..)
85            | ty::CoroutineClosure(..) => interp_ok(true),
86
87            ty::Array(elem, _len) => {
88                // 0-length arrays are in general *not* okay, but arrays of trivial-ABI types are.
89                self.has_trivial_abi(self.layout_of(elem)?)
90            }
91            ty::Adt(adt_def, _args) => {
92                if adt_def.repr().transparent() {
93                    // All fields must have trivial ABI.
94                    (0..layout.fields.count()).try_fold(true, |acc, idx| {
95                        interp_ok(acc && self.has_trivial_abi(layout.field(self, idx))?)
96                    })
97                } else if adt_def.repr().c() {
98                    interp_ok(false)
99                } else {
100                    // Must be repr(Rust).
101                    interp_ok(true)
102                }
103            }
104            // Types that are considered transparent in `unfold_transparent` should also act
105            // like transparent types here.
106            ty::Pat(base, _) => self.has_trivial_abi(self.layout_of(base)?),
107            ty::UnsafeBinder(bound_ty) => {
108                let ty = self.tcx.instantiate_bound_regions_with_erased(bound_ty.into());
109                self.has_trivial_abi(self.layout_of(ty)?)
110            }
111
112            ty::Alias(..) => { ::core::panicking::panic_fmt(format_args!("non-normalized type")); }panic!("non-normalized type"),
113            _ => interp_ok(false),
114        }
115    }
116
117    /// Find the wrapped inner type of a transparent wrapper by going for the unique
118    /// non-trivial-ABI field.
119    ///
120    /// We work with `TyAndLayout` here since that makes it much easier to iterate over all fields.
121    fn unfold_transparent(
122        &self,
123        layout: TyAndLayout<'tcx>,
124        may_unfold: impl Fn(AdtDef<'tcx>) -> bool,
125    ) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
126        match *layout.ty.kind() {
127            ty::Adt(adt_def, _) if adt_def.repr().transparent() && may_unfold(adt_def) => {
128                {
    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 { .. });
129                // Look for non-trivial-ABI field(s).
130                let mut found = None;
131                for idx in 0..layout.fields.count() {
132                    let field = layout.field(self, idx);
133                    if self.has_trivial_abi(field)? {
134                        continue;
135                    }
136                    // Found a non-trivial ABI field!
137                    if found.is_some() {
138                        // There is more than one such field.
139                        // FIXME: we should just panic here. But currently such repr(transparent)
140                        // types are still accepted. We just don't treat them as transparent.
141                        return interp_ok(layout);
142                    }
143                    found = Some(field);
144                }
145                let Some(field) = found else {
146                    // All fields have trivial ABI. That means this type is effectively `()`.
147                    return interp_ok(self.layout_of(self.tcx.types.unit)?);
148                };
149                // Recurse.
150                self.unfold_transparent(field, may_unfold)
151            }
152            ty::Pat(base, _) => self.unfold_transparent(self.layout_of(base)?, may_unfold),
153            ty::UnsafeBinder(bound_ty) => {
154                let ty = self.tcx.instantiate_bound_regions_with_erased(bound_ty.into());
155                self.unfold_transparent(self.layout_of(ty)?, may_unfold)
156            }
157            // Not a transparent type, no further unfolding.
158            _ => interp_ok(layout),
159        }
160    }
161
162    /// Unwrap types that are guaranteed a null-pointer-optimization
163    fn unfold_npo(&self, layout: TyAndLayout<'tcx>) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
164        // Check if this is an option-like type wrapping some type.
165        let ty::Adt(def, args) = layout.ty.kind() else {
166            // Not an ADT, so definitely no NPO.
167            return interp_ok(layout);
168        };
169        if def.variants().len() != 2 {
170            // Not a 2-variant enum, so no NPO.
171            return interp_ok(layout);
172        }
173        if !def.is_enum() {
    ::core::panicking::panic("assertion failed: def.is_enum()")
};assert!(def.is_enum());
174
175        let all_fields_1zst = |variant: &VariantDef| -> InterpResult<'tcx, _> {
176            for field in &variant.fields {
177                let ty = field.ty(*self.tcx, args).skip_norm_wip();
178                let layout = self.layout_of(ty)?;
179                if !layout.is_1zst() {
180                    return interp_ok(false);
181                }
182            }
183            interp_ok(true)
184        };
185
186        // If one variant consists entirely of 1-ZST, then the other variant
187        // is the only "relevant" one for this check.
188        let var0 = VariantIdx::from_u32(0);
189        let var1 = VariantIdx::from_u32(1);
190        let relevant_variant = if all_fields_1zst(def.variant(var0))? {
191            def.variant(var1)
192        } else if all_fields_1zst(def.variant(var1))? {
193            def.variant(var0)
194        } else {
195            // No variant is all-1-ZST, so no NPO.
196            return interp_ok(layout);
197        };
198        // The "relevant" variant must have exactly one field, and its type is the "inner" type.
199        if relevant_variant.fields.len() != 1 {
200            return interp_ok(layout);
201        }
202        let inner =
203            relevant_variant.fields[FieldIdx::from_u32(0)].ty(*self.tcx, args).skip_norm_wip();
204        let inner = self.layout_of(inner)?;
205
206        // Check if the inner type is one of the NPO-guaranteed ones.
207        // For that we first unpeel transparent *structs* (but not unions).
208        let is_npo =
209            |def: AdtDef<'tcx>| {
        {
            'done:
                {
                for i in
                    ::rustc_attr_ir::HasAttrs::get_attrs(def.did(), &self.tcx) {
                    #[allow(unused_imports)]
                    use ::rustc_attr_ir::AttributeKind::*;
                    let i: &::rustc_attr_ir::Attribute = i;
                    match i {
                        ::rustc_attr_ir::Attribute::Parsed(RustcNonnullOptimizationGuaranteed)
                            => {
                            break 'done Some(());
                        }
                        ::rustc_attr_ir::Attribute::Unparsed(..) =>
                            {}
                            #[deny(unreachable_patterns)]
                            _ => {}
                    }
                }
                None
            }
        }
    }.is_some()find_attr!(self.tcx, def.did(), RustcNonnullOptimizationGuaranteed);
210        let inner = self.unfold_transparent(inner, /* may_unfold */ |def| {
211            // Stop at NPO types so that we don't miss that attribute in the check below!
212            def.is_struct() && !is_npo(def)
213        })?;
214        interp_ok(match inner.ty.kind() {
215            ty::Ref(..) | ty::FnPtr(..) => {
216                // Option<&T> behaves like &T, and same for fn()
217                inner
218            }
219            ty::Adt(def, _) if is_npo(*def) => {
220                // Once we found a `nonnull_optimization_guaranteed` type, further strip off
221                // newtype structs from it to find the underlying ABI type.
222                self.unfold_transparent(inner, /* may_unfold */ |def| def.is_struct())?
223            }
224            _ => {
225                // Everything else we do not unfold.
226                layout
227            }
228        })
229    }
230
231    /// Check if these two layouts look like they are fn-ABI-compatible.
232    /// (We also compare the `PassMode`, so this doesn't have to check everything. But it turns out
233    /// that only checking the `PassMode` is insufficient.)
234    fn layout_compat(
235        &self,
236        caller: TyAndLayout<'tcx>,
237        callee: TyAndLayout<'tcx>,
238    ) -> InterpResult<'tcx, bool> {
239        // Fast path: equal types are definitely compatible.
240        if caller.ty == callee.ty {
241            return interp_ok(true);
242        }
243        // Handle trivial-ABI types.
244        if self.has_trivial_abi(caller)? && self.has_trivial_abi(callee)? {
245            return interp_ok(true);
246        }
247        // Unfold newtypes and NPO optimizations.
248        let unfold = |layout: TyAndLayout<'tcx>| {
249            self.unfold_transparent(layout, /* may_unfold */ |_def| true)
250                .and_then(|f| self.unfold_npo(f))
251        };
252        let caller = unfold(caller)?;
253        let callee = unfold(callee)?;
254        // Not-quite-so-fast path: if the types are equal now, they are compatible.
255        if caller.ty == callee.ty {
256            return interp_ok(true);
257        }
258        // Now see if these inner types are compatible.
259
260        // Compatible pointer types. For thin pointers, we have to accept even non-`repr(transparent)`
261        // things as compatible due to `DispatchFromDyn`. For instance, `Rc<i32>` and `*mut i32`
262        // must be compatible. So we just accept everything with Pointer ABI as compatible,
263        // even if this will accept some code that is not stably guaranteed to work.
264        // This also handles function pointers.
265        let thin_pointer = |layout: TyAndLayout<'tcx>| match layout.backend_repr {
266            abi::BackendRepr::Scalar(s) => match s.primitive() {
267                abi::Primitive::Pointer(addr_space) => Some(addr_space),
268                _ => None,
269            },
270            _ => None,
271        };
272        if let (Some(caller), Some(callee)) = (thin_pointer(caller), thin_pointer(callee)) {
273            return interp_ok(caller == callee);
274        }
275        // For wide pointers we have to get the pointee type.
276        let pointee_ty = |ty: Ty<'tcx>| -> InterpResult<'tcx, Option<Ty<'tcx>>> {
277            // We cannot use `builtin_deref` here since we need to reject `Box<T, MyAlloc>`.
278            interp_ok(Some(match ty.kind() {
279                ty::Ref(_, ty, _) => *ty,
280                ty::RawPtr(ty, _) => *ty,
281                // We only accept `Box` with the default allocator.
282                _ if ty.is_box_global(*self.tcx) => ty.expect_boxed_ty(),
283                _ => return interp_ok(None),
284            }))
285        };
286        if let (Some(caller), Some(callee)) = (pointee_ty(caller.ty)?, pointee_ty(callee.ty)?) {
287            // This is okay if they have the same metadata type.
288            let meta_ty = |ty: Ty<'tcx>| {
289                // Even if `ty` is normalized, the search for the unsized tail will project
290                // to fields, which can yield non-normalized types. So we need to provide a
291                // normalization function.
292                let normalize = |ty| self.tcx.normalize_erasing_regions(self.typing_env, ty);
293                ty.ptr_metadata_ty(*self.tcx, normalize)
294            };
295            return interp_ok(meta_ty(caller) == meta_ty(callee));
296        }
297
298        // Compatible integer types (in particular, usize vs ptr-sized-u32/u64).
299        // `char` counts as `u32.`
300        let int_ty = |ty: Ty<'tcx>| {
301            Some(match ty.kind() {
302                ty::Int(ity) => (Integer::from_int_ty(&self.tcx, *ity), /* signed */ true),
303                ty::Uint(uty) => (Integer::from_uint_ty(&self.tcx, *uty), /* signed */ false),
304                ty::Char => (Integer::I32, /* signed */ false),
305                _ => return None,
306            })
307        };
308        if let (Some(caller), Some(callee)) = (int_ty(caller.ty), int_ty(callee.ty)) {
309            // This is okay if they are the same integer type.
310            return interp_ok(caller == callee);
311        }
312
313        // The rest is incompatible.
314        interp_ok(false)
315    }
316
317    /// Returns a `bool` saying whether the two arguments are ABI-compatible.
318    pub fn check_argument_compat(
319        &self,
320        caller_abi: &ArgAbi<'tcx, Ty<'tcx>>,
321        callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
322    ) -> InterpResult<'tcx, bool> {
323        // We do not want to accept things as ABI-compatible that just "happen to be" compatible on the current target,
324        // so we implement a type-based check that reflects the guaranteed rules for ABI compatibility.
325        if self.layout_compat(caller_abi.layout, callee_abi.layout)? {
326            // Ensure that our checks imply actual ABI compatibility for this concrete call.
327            // (This can fail e.g. if `#[rustc_nonnull_optimization_guaranteed]` is used incorrectly.)
328            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));
329            interp_ok(true)
330        } else {
331            {
    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:331",
                        "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(331u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("check_argument_compat: incompatible ABIs:\ncaller: {0:?}\ncallee: {1:?}",
                                                    caller_abi, callee_abi) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!(
332                "check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}",
333                caller_abi, callee_abi
334            );
335            interp_ok(false)
336        }
337    }
338
339    /// Initialize a single callee argument, checking the types for compatibility.
340    fn pass_argument<'x, 'y>(
341        &mut self,
342        caller_args: &mut impl Iterator<
343            Item = (&'x FnArg<'tcx, M::Provenance>, &'y ArgAbi<'tcx, Ty<'tcx>>),
344        >,
345        callee_args_abis: &mut impl Iterator<Item = (usize, &'y ArgAbi<'tcx, Ty<'tcx>>)>,
346        callee_arg: &mir::Place<'tcx>,
347        callee_ty: Ty<'tcx>,
348        already_live: bool,
349    ) -> InterpResult<'tcx>
350    where
351        'tcx: 'x,
352        'tcx: 'y,
353    {
354        // Get next callee arg.
355        let (callee_arg_idx, callee_abi) = callee_args_abis.next().unwrap();
356        {
    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);
357        // Get next caller arg.
358        let Some((caller_arg, caller_abi)) = caller_args.next() else {
359            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");
360        };
361        {
    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);
362        // Sadly we cannot assert that `caller_arg.layout().ty` and `caller_abi.layout.ty` are
363        // equal; in closures the types sometimes differ. We just hope that `caller_abi` is the
364        // right type to print to the user.
365
366        // Check compatibility
367        if !self.check_argument_compat(caller_abi, callee_abi)? {
368            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 {
369                arg_idx: callee_arg_idx,
370                caller_ty: caller_abi.layout.ty,
371                callee_ty: callee_abi.layout.ty
372            });
373        }
374        // We work with a copy of the argument for now; if this is in-place argument passing, we
375        // will later protect the source it comes from. This means the callee cannot observe if we
376        // did in-place of by-copy argument passing, except for pointer equality tests.
377        let caller_arg_copy = caller_arg.copy_fn_arg();
378        if !already_live {
379            let local = callee_arg.as_local().unwrap();
380            let meta = caller_arg_copy.meta();
381            // `check_argument_compat` ensures that if metadata is needed, both have the same type,
382            // so we know they will use the metadata the same way.
383            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);
384
385            self.storage_live_dyn(local, meta)?;
386        }
387        // Now we can finally actually evaluate the callee place.
388        let callee_arg =
389            self.eval_place(*callee_arg, /* skip_validity_for_simple_deref */ false)?;
390        // We allow some transmutes here.
391        // FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
392        // is true for all `copy_op`, but there are a lot of special cases for argument passing
393        // specifically.)
394        self.copy_op_allow_transmute(&caller_arg_copy, &callee_arg)?;
395        // If this was an in-place pass, protect the place it comes from for the duration of the call.
396        if let FnArg::InPlace(mplace) = caller_arg {
397            M::protect_in_place_function_argument(self, mplace)?;
398        }
399        interp_ok(())
400    }
401
402    /// The main entry point for creating a new stack frame: performs ABI checks and initializes
403    /// arguments.
404    #[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(404u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("instance")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("instance");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("body")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("body");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("caller_fn_abi")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("caller_fn_abi");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("args")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("args");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("with_caller_location")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("with_caller_location");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("destination")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("destination");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("cont")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("cont");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instance)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&body)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&caller_fn_abi)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&with_caller_location
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&destination)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cont)
                                                            as &dyn ::tracing::field::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(415u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("step")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("step");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("instance")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("instance");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("tracing_separate_thread")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("tracing_separate_thread");
                                                                    NAME.as_str()
                                                                }], ::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};
                                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"init_stack_frame")
                                                                        as &dyn ::tracing::field::Value)),
                                                            (::tracing::__macro_support::Option::Some(&::tracing::field::display(&instance)
                                                                        as &dyn ::tracing::field::Value)),
                                                            (::tracing::__macro_support::Option::Some(&Empty as
                                                                        &dyn ::tracing::field::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:475",
                                    "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(475u32),
                                    ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::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 ::tracing::field::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:488",
                                    "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(488u32),
                                    ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::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 ::tracing::field::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::Shim(ty::ShimKind::ClosureOnce { .. }) =>
                                    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, false)?;
                                    let mplace = ecx.force_allocation(&place)?;
                                    let varargs =
                                        M::with_retag_mode(ecx, RetagMode::None,
                                                |ecx|
                                                    {
                                                        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")]
405    pub fn init_stack_frame(
406        &mut self,
407        instance: Instance<'tcx>,
408        body: &'tcx mir::Body<'tcx>,
409        caller_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
410        args: &[FnArg<'tcx, M::Provenance>],
411        with_caller_location: bool,
412        destination: &PlaceTy<'tcx, M::Provenance>,
413        mut cont: ReturnContinuation,
414    ) -> InterpResult<'tcx> {
415        let _trace = enter_trace_span!(M, step::init_stack_frame, %instance, tracing_separate_thread = Empty);
416        let def_id = instance.def_id();
417
418        // The first order of business is to figure out the callee signature.
419        // However, that requires the list of variadic arguments.
420        // We use the *caller* information to determine where to split the list of arguments,
421        // and then later check that the callee indeed has the same number of fixed arguments.
422        let extra_tys = if caller_fn_abi.c_variadic {
423            let fixed_count = usize::try_from(caller_fn_abi.fixed_count).unwrap();
424            let extra_tys = args[fixed_count..].iter().map(|arg| arg.layout().ty);
425            self.tcx.mk_type_list_from_iter(extra_tys)
426        } else {
427            ty::List::empty()
428        };
429        let callee_fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, extra_tys)?;
430
431        if caller_fn_abi.conv != callee_fn_abi.conv {
432            throw_ub_format!(
433                "calling a function with calling convention \"{callee_conv}\" using calling convention \"{caller_conv}\"",
434                callee_conv = callee_fn_abi.conv,
435                caller_conv = caller_fn_abi.conv,
436            )
437        }
438
439        if caller_fn_abi.c_variadic != callee_fn_abi.c_variadic {
440            throw_ub!(CVariadicMismatch {
441                caller_is_c_variadic: caller_fn_abi.c_variadic,
442                callee_is_c_variadic: callee_fn_abi.c_variadic,
443            });
444        }
445        if caller_fn_abi.c_variadic && caller_fn_abi.fixed_count != callee_fn_abi.fixed_count {
446            throw_ub!(CVariadicFixedCountMismatch {
447                caller: caller_fn_abi.fixed_count,
448                callee: callee_fn_abi.fixed_count,
449            });
450        }
451
452        // Check that all target features required by the callee (i.e., from
453        // the attribute `#[target_feature(enable = ...)]`) are enabled at
454        // compile time.
455        M::check_fn_target_features(self, instance)?;
456
457        if !callee_fn_abi.can_unwind {
458            // The callee cannot unwind, so force the `Unreachable` unwind handling.
459            match &mut cont {
460                ReturnContinuation::Stop { .. } => {}
461                ReturnContinuation::Goto { unwind, .. } => {
462                    *unwind = mir::UnwindAction::Unreachable;
463                }
464            }
465        }
466
467        // *Before* pushing the new frame, determine whether the return destination is in memory.
468        // Need to use `place_to_op` to be *sure* we get the mplace if there is one.
469        let destination_mplace = self.place_to_op(destination)?.as_mplace_or_imm().left();
470
471        // Push the "raw" frame -- this leaves locals uninitialized.
472        self.push_stack_frame_raw(instance, body, destination, cont)?;
473        let preamble_span = self.frame().loc.unwrap_right(); // the span used for preamble errors
474
475        trace!(
476            "caller ABI: {:#?}, args: {:#?}",
477            caller_fn_abi,
478            args.iter()
479                .map(|arg| (
480                    arg.layout().ty,
481                    match arg {
482                        FnArg::Copy(op) => format!("copy({op:?})"),
483                        FnArg::InPlace(mplace) => format!("in-place({mplace:?})"),
484                    }
485                ))
486                .collect::<Vec<_>>()
487        );
488        trace!(
489            "spread_arg: {:?}, locals: {:#?}",
490            body.spread_arg,
491            body.args_iter()
492                .map(|local| (local, self.layout_of_local(self.frame(), local, None).unwrap().ty))
493                .collect::<Vec<_>>()
494        );
495
496        // Determine whether there is a special VaList argument. This is always the
497        // last argument, and since arguments start at index 1 that's `arg_count`.
498        let va_list_arg = callee_fn_abi.c_variadic.then(|| mir::Local::from_usize(body.arg_count));
499        // Determine whether this is a non-capturing closure. That's relevant as their first
500        // argument can be skipped (and that's the only kind of argument skipping we allow).
501        let is_non_capturing_closure =
502            (matches!(instance.def, ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. }))
503                || self.tcx.is_closure_like(def_id))
504                && {
505                    let arg = &callee_fn_abi.args[0];
506                    matches!(arg.layout.ty.kind(), ty::Closure (_def, closure_args) if {
507                        closure_args.as_closure().upvar_tys().is_empty()
508                    })
509                };
510
511        // In principle, we have two iterators: Where the arguments come from, and where
512        // they go to.
513
514        // The "where they come from" part is easy, we expect the caller to do any special handling
515        // that might be required here (e.g. for untupling).
516        // If `with_caller_location` is set we pretend there is an extra argument (that
517        // we will not pass; our `caller_location` intrinsic implementation walks the stack instead).
518        assert_eq!(
519            args.len() + if with_caller_location { 1 } else { 0 },
520            caller_fn_abi.args.len(),
521            "mismatch between caller ABI and caller arguments",
522        );
523        let mut caller_args = args.iter().zip(caller_fn_abi.args.iter());
524
525        // Now we have to spread them out across the callee's locals,
526        // taking into account the `spread_arg`. If we could write
527        // this is a single iterator (that handles `spread_arg`), then
528        // `pass_argument` would be the loop body.
529        let mut callee_args_abis = callee_fn_abi.args.iter().enumerate();
530        // During argument passing, we want retagging with protectors.
531        M::with_retag_mode(self, RetagMode::FnEntry, |ecx| {
532            for local in body.args_iter() {
533                // Update the span that we show in case of an error to point to this argument.
534                ecx.frame_mut().loc = Right(body.local_decls[local].source_info.span);
535                // Construct the destination place for this argument. At this point all
536                // locals are still dead, so we cannot construct a `PlaceTy`.
537                let dest = mir::Place::from(local);
538                // `layout_of_local` does more than just the instantiation we need to get the
539                // type, but the result gets cached so this avoids calling the instantiation
540                // query *again* the next time this local is accessed.
541                let ty = ecx.layout_of_local(ecx.frame(), local, None)?.ty;
542
543                // Some arguments are special: the first (`self`) argument of a non-capturing
544                // closure; the va_list argument; and the spread_arg.
545                if is_non_capturing_closure && local == mir::Local::arg(0) {
546                    assert!(va_list_arg.is_none());
547                    assert!(Some(local) != body.spread_arg);
548                    // This argument might be missing on the caller side. So just initialize it in
549                    // the callee.
550                    let (callee_arg_idx, callee_abi) = callee_args_abis.next().unwrap();
551                    assert!(callee_abi.layout.is_1zst() && callee_abi.is_ignore());
552                    ecx.storage_live(local)?;
553                    // And skip it in the caller, if present. We can tell whether it is present by
554                    // comparing the number of arguments on the caller and callee side.
555                    if caller_fn_abi.args.len() == callee_fn_abi.args.len() {
556                        let (_caller_arg, caller_abi) = caller_args.next().unwrap();
557                        if !caller_abi.layout.is_1zst() {
558                            // The caller gave us some other, non-ignorable argument.
559                            throw_ub!(AbiMismatchArgument {
560                                arg_idx: callee_arg_idx,
561                                caller_ty: caller_abi.layout.ty,
562                                callee_ty: callee_abi.layout.ty
563                            });
564                        }
565                        assert!(caller_abi.is_ignore());
566                    }
567                } else if Some(local) == va_list_arg {
568                    // This is the last callee-side argument of a variadic function.
569                    // This argument is a VaList holding the remaining caller-side arguments.
570                    ecx.storage_live(local)?;
571
572                    let place =
573                        ecx.eval_place(dest, /* skip_validity_for_simple_deref */ false)?;
574                    let mplace = ecx.force_allocation(&place)?;
575
576                    // Consume the remaining arguments by putting them into the variable argument
577                    // list. We disable retagging to avoid creating protected tags. Protection should
578                    // only use callee-side information, and the varargs have no static callee-side type.
579                    let varargs = M::with_retag_mode(ecx, RetagMode::None, |ecx| {
580                        ecx.allocate_varargs(&mut caller_args, &mut callee_args_abis)
581                    })?;
582
583                    // When the frame is dropped, these variable arguments are deallocated.
584                    ecx.frame_mut().va_list = varargs.clone();
585                    let key = ecx.va_list_ptr(varargs.into());
586
587                    // Zero the VaList, so it is fully initialized.
588                    ecx.write_bytes_ptr(
589                        mplace.ptr(),
590                        (0..mplace.layout.size.bytes()).map(|_| 0u8),
591                    )?;
592
593                    // Store the "key" pointer in the right field.
594                    let key_mplace = ecx.va_list_key_field(&mplace)?;
595                    ecx.write_pointer(key, &key_mplace)?;
596                } else if Some(local) == body.spread_arg {
597                    // Make the local live once, then fill in the value field by field.
598                    ecx.storage_live(local)?;
599                    // Must be a tuple
600                    let ty::Tuple(fields) = ty.kind() else {
601                        span_bug!(ecx.cur_span(), "non-tuple type for `spread_arg`: {ty}")
602                    };
603                    for (i, field_ty) in fields.iter().enumerate() {
604                        let dest = dest.project_deeper(
605                            &[mir::ProjectionElem::Field(FieldIdx::from_usize(i), field_ty)],
606                            *ecx.tcx,
607                        );
608                        ecx.pass_argument(
609                            &mut caller_args,
610                            &mut callee_args_abis,
611                            &dest,
612                            field_ty,
613                            /* already_live */ true,
614                        )?;
615                    }
616                } else {
617                    // Normal argument. Cannot mark it as live yet, it might be unsized!
618                    ecx.pass_argument(
619                        &mut caller_args,
620                        &mut callee_args_abis,
621                        &dest,
622                        ty,
623                        /* already_live */ false,
624                    )?;
625                }
626            }
627            interp_ok(())
628        })?;
629
630        // Don't forget to check the return type!
631        self.frame_mut().loc = Right(body.local_decls[mir::RETURN_PLACE].source_info.span);
632        if !self.check_argument_compat(&caller_fn_abi.ret, &callee_fn_abi.ret)? {
633            throw_ub!(AbiMismatchReturn {
634                caller_ty: caller_fn_abi.ret.layout.ty,
635                callee_ty: callee_fn_abi.ret.layout.ty
636            });
637        }
638        // Protect return place for in-place return value passing.
639        // We only need to protect anything if this is actually an in-memory place.
640        if let Some(mplace) = destination_mplace {
641            M::protect_in_place_function_argument(self, &mplace)?;
642        }
643
644        // For the final checks, use same span as preamble since it is unclear what else to do.
645        self.frame_mut().loc = Right(preamble_span);
646        // If the callee needs a caller location, pretend we consume one more argument from the ABI.
647        if instance.def.requires_caller_location(*self.tcx) {
648            callee_args_abis.next().unwrap();
649        }
650        // Now we should have no more caller args or callee arg ABIs.
651        assert!(
652            callee_args_abis.next().is_none(),
653            "mismatch between callee ABI and callee body arguments"
654        );
655        if caller_args.next().is_some() {
656            throw_ub_format!("calling a function with more arguments than it expected");
657        }
658
659        // Done!
660        self.push_stack_frame_done()
661    }
662
663    /// Initiate a call to this function -- pushing the stack frame and initializing the arguments.
664    ///
665    /// `caller_fn_abi` is used to determine if all the arguments are passed the proper way.
666    /// However, we also need `caller_abi` to determine if we need to do untupling of arguments.
667    ///
668    /// `with_caller_location` indicates whether the caller passed a caller location. Miri
669    /// implements caller locations without argument passing, but to match `FnAbi` we need to know
670    /// when those arguments are present.
671    pub(super) fn init_fn_call(
672        &mut self,
673        fn_val: FnVal<'tcx, M::ExtraFnVal>,
674        (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx, Ty<'tcx>>),
675        args: &[FnArg<'tcx, M::Provenance>],
676        with_caller_location: bool,
677        destination: &PlaceTy<'tcx, M::Provenance>,
678        target: Option<mir::BasicBlock>,
679        unwind: mir::UnwindAction,
680    ) -> InterpResult<'tcx> {
681        let _trace =
682            <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(682u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("step")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("step");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("tracing_separate_thread")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("tracing_separate_thread");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("fn_val")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("fn_val");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"init_fn_call")
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&Empty as
                                                        &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_val)
                                                        as &dyn ::tracing::field::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)
683                .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:683",
                        "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(683u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("init_fn_call: {0:#?}",
                                                    fn_val) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
}trace!("init_fn_call: {:#?}", fn_val));
684
685        let instance = match fn_val {
686            FnVal::Instance(instance) => instance,
687            FnVal::Other(extra) => {
688                return M::call_extra_fn(
689                    self,
690                    extra,
691                    caller_fn_abi,
692                    args,
693                    destination,
694                    target,
695                    unwind,
696                );
697            }
698        };
699
700        match instance.def {
701            ty::InstanceKind::Intrinsic(def_id) => {
702                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());
703                // FIXME: Should `InPlace` arguments be reset to uninit?
704                if let Some(fallback) = M::call_intrinsic(
705                    self,
706                    instance,
707                    &Self::copy_fn_args(args),
708                    destination,
709                    target,
710                    unwind,
711                )? {
712                    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);
713                    {
    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(_));
714                    return self.init_fn_call(
715                        FnVal::Instance(fallback),
716                        (caller_abi, caller_fn_abi),
717                        args,
718                        with_caller_location,
719                        destination,
720                        target,
721                        unwind,
722                    );
723                } else {
724                    interp_ok(())
725                }
726            }
727            ty::InstanceKind::LlvmIntrinsic(_) => {
728                // FIXME: Should `InPlace` arguments be reset to uninit?
729                M::call_llvm_intrinsic(
730                    self,
731                    instance,
732                    &Self::copy_fn_args(args),
733                    destination,
734                    target,
735                )
736            }
737            ty::InstanceKind::Shim(ty::ShimKind::VTable(..))
738            | ty::InstanceKind::Shim(ty::ShimKind::Reify(..))
739            | ty::InstanceKind::Shim(ty::ShimKind::ClosureOnce { .. })
740            | ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure { .. })
741            | ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..))
742            | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..))
743            | ty::InstanceKind::Shim(ty::ShimKind::Clone(..))
744            | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(..))
745            | ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..))
746            | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(..))
747            | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(..))
748            | ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(..))
749            | ty::InstanceKind::Item(_) => {
750                // We need MIR for this fn.
751                // Note that this can be an intrinsic, if we are executing its fallback body.
752                let Some((body, instance)) = M::find_mir_or_eval_fn(
753                    self,
754                    instance,
755                    caller_fn_abi,
756                    args,
757                    destination,
758                    target,
759                    unwind,
760                )?
761                else {
762                    return interp_ok(());
763                };
764
765                // Special handling for the closure ABI: untuple the last argument.
766                // FIXME(splat): un-tuple splatted arguments that were tupled in typecheck
767                let args: Cow<'_, [FnArg<'tcx, M::Provenance>]> =
768                    if caller_abi == ExternAbi::RustCall && !args.is_empty() {
769                        // Untuple
770                        let (untuple_arg, args) = args.split_last().unwrap();
771                        let ty::Tuple(untuple_fields) = untuple_arg.layout().ty.kind() else {
772                            ::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")
773                        };
774                        {
    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:774",
                        "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(774u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("init_fn_call: Will pass last argument by untupling")
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!("init_fn_call: Will pass last argument by untupling");
775                        Cow::from(
776                            args.iter()
777                                // The regular arguments.
778                                .map(|a| interp_ok(a.clone()))
779                                // The fields of the untupled argument.
780                                .chain((0..untuple_fields.len()).map(|i| {
781                                    self.fn_arg_project_field(untuple_arg, FieldIdx::from_usize(i))
782                                }))
783                                .collect::<InterpResult<'_, Vec<_>>>()?,
784                        )
785                    } else {
786                        // Plain arg passing
787                        Cow::from(args)
788                    };
789
790                self.init_stack_frame(
791                    instance,
792                    body,
793                    caller_fn_abi,
794                    &args,
795                    with_caller_location,
796                    destination,
797                    ReturnContinuation::Goto { ret: target, unwind },
798                )
799            }
800            // `InstanceKind::Virtual` does not have callable MIR. Calls to `Virtual` instances must be
801            // codegen'd / interpreted as virtual calls through the vtable.
802            ty::InstanceKind::Virtual(def_id, idx) => {
803                let mut args = args.to_vec();
804                // We have to implement all "dyn-compatible receivers". So we have to go search for a
805                // pointer or `dyn Trait` type, but it could be wrapped in newtypes. So recursively
806                // unwrap those newtypes until we are there.
807                // An `InPlace` does nothing here, we keep the original receiver intact. We can't
808                // really pass the argument in-place anyway, and we are constructing a new
809                // `Immediate` receiver.
810                let mut receiver = args[0].copy_fn_arg();
811                let receiver_place = loop {
812                    match receiver.layout.ty.kind() {
813                        ty::Ref(..) | ty::RawPtr(..) => {
814                            // We do *not* use `deref_pointer` here: we don't want to conceptually
815                            // create a place that must be dereferenceable, since the receiver might
816                            // be a raw pointer and (for `*const dyn Trait`) we don't need to
817                            // actually access memory to resolve this method.
818                            // Also see <https://github.com/rust-lang/miri/issues/2786>.
819                            let val = self.read_immediate(&receiver)?;
820                            break self.imm_ptr_to_mplace(&val)?;
821                        }
822                        ty::Dynamic(..) => break receiver.assert_mem_place(), // no immediate unsized values
823                        _ => {
824                            // Not there yet, search for the only non-ZST field.
825                            // (The rules for `DispatchFromDyn` ensure there's exactly one such field.)
826                            let (idx, _) = receiver.layout.non_1zst_field(self).expect(
827                                "not exactly one non-1-ZST field in a `DispatchFromDyn` type",
828                            );
829                            receiver = self.project_field(&receiver, idx)?;
830                        }
831                    }
832                };
833
834                // Obtain the underlying trait we are working on, and the adjusted receiver argument.
835                // Doesn't have to be a `dyn Trait`, but the unsized tail must be `dyn Trait`.
836                // (For that reason we also cannot use `unpack_dyn_trait`.)
837                let receiver_tail =
838                    self.tcx.struct_tail_for_codegen(receiver_place.layout.ty, self.typing_env);
839                let ty::Dynamic(receiver_trait, _) = receiver_tail.kind() else {
840                    ::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)
841                };
842                if !receiver_place.layout.is_unsized() {
    ::core::panicking::panic("assertion failed: receiver_place.layout.is_unsized()")
};assert!(receiver_place.layout.is_unsized());
843
844                // Get the required information from the vtable.
845                let vptr = receiver_place.meta().unwrap_meta().to_pointer(self)?;
846                let dyn_ty = self.get_ptr_vtable_ty(vptr, Some(receiver_trait))?;
847                let adjusted_recv = receiver_place.ptr();
848
849                // Now determine the actual method to call. Usually we use the easy way of just
850                // looking up the method at index `idx`.
851                let vtable_entries = self.vtable_entries(receiver_trait.principal(), dyn_ty);
852                let Some(ty::VtblEntry::Method(fn_inst)) = vtable_entries.get(idx).copied() else {
853                    // FIXME(fee1-dead) these could be variants of the UB info enum instead of this
854                    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");
855                };
856                {
    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:856",
                        "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(856u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Virtual call dispatches to {0:#?}",
                                                    fn_inst) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!("Virtual call dispatches to {fn_inst:#?}");
857                // We can also do the lookup based on `def_id` and `dyn_ty`, and check that that
858                // produces the same result.
859                self.assert_virtual_instance_matches_concrete(dyn_ty, def_id, instance, fn_inst);
860
861                // Adjust receiver argument. Layout can be any (thin) ptr.
862                let receiver_ty = Ty::new_mut_ptr(self.tcx.tcx, dyn_ty);
863                args[0] = FnArg::Copy(
864                    ImmTy::from_immediate(
865                        Scalar::from_maybe_pointer(adjusted_recv, self).into(),
866                        self.layout_of(receiver_ty)?,
867                    )
868                    .into(),
869                );
870                {
    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:870",
                        "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(870u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Patched receiver operand to {0:#?}",
                                                    args[0]) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!("Patched receiver operand to {:#?}", args[0]);
871                // Need to also adjust the type in the ABI. Strangely, the layout there is actually
872                // already fine! Just the type is bogus. This is due to what `force_thin_self_ptr`
873                // does in `fn_abi_new_uncached`; supposedly, codegen relies on having the bogus
874                // type, so we just patch this up locally.
875                let mut caller_fn_abi = caller_fn_abi.clone();
876                caller_fn_abi.args[0].layout.ty = receiver_ty;
877
878                // recurse with concrete function
879                self.init_fn_call(
880                    FnVal::Instance(fn_inst),
881                    (caller_abi, &caller_fn_abi),
882                    &args,
883                    with_caller_location,
884                    destination,
885                    target,
886                    unwind,
887                )
888            }
889        }
890    }
891
892    fn assert_virtual_instance_matches_concrete(
893        &self,
894        dyn_ty: Ty<'tcx>,
895        def_id: DefId,
896        virtual_instance: ty::Instance<'tcx>,
897        concrete_instance: ty::Instance<'tcx>,
898    ) {
899        let tcx = *self.tcx;
900
901        let trait_def_id = tcx.parent(def_id);
902        let virtual_trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, virtual_instance.args);
903        let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
904        let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
905
906        let concrete_method = {
907            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(907u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("resolve")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("resolve");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("def_id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("def_id");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"expect_resolve_for_vtable")
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&def_id)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        })enter_trace_span!(M, resolve::expect_resolve_for_vtable, ?def_id);
908            Instance::expect_resolve_for_vtable(
909                tcx,
910                self.typing_env,
911                def_id,
912                virtual_instance.args.rebase_onto(tcx, trait_def_id, concrete_trait_ref.args),
913                self.cur_span(),
914            )
915        };
916        {
    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);
917    }
918
919    /// Initiate a tail call to this function -- popping the current stack frame, pushing the new
920    /// stack frame and initializing the arguments.
921    pub(super) fn init_fn_tail_call(
922        &mut self,
923        fn_val: FnVal<'tcx, M::ExtraFnVal>,
924        (caller_abi, caller_fn_abi): (ExternAbi, &FnAbi<'tcx, Ty<'tcx>>),
925        args: &[FnArg<'tcx, M::Provenance>],
926        with_caller_location: bool,
927    ) -> InterpResult<'tcx> {
928        {
    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:928",
                        "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(928u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("init_fn_tail_call: {0:#?}",
                                                    fn_val) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!("init_fn_tail_call: {:#?}", fn_val);
929        // This is the "canonical" implementation of tails calls,
930        // a pop of the current stack frame, followed by a normal call
931        // which pushes a new stack frame, with the return address from
932        // the popped stack frame.
933        //
934        // Note that we cannot use `return_from_current_stack_frame`,
935        // as that "executes" the goto to the return block, but we don't want to,
936        // only the tail called function should return to the current return block.
937
938        // The arguments need to all be copied since the current stack frame will be removed
939        // before the callee even starts executing.
940        // FIXME(explicit_tail_calls,#144855): does this match what codegen does?
941        let args = args.iter().map(|fn_arg| FnArg::Copy(fn_arg.copy_fn_arg())).collect::<Vec<_>>();
942        // Remove the frame from the stack.
943        let frame = self.pop_stack_frame_raw()?;
944        // Remember where this frame would have returned to.
945        let ReturnContinuation::Goto { ret, unwind } = frame.return_cont() else {
946            ::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");
947        };
948        // There's no return value to deal with! Instead, we forward the old return place
949        // to the new function.
950        // FIXME(explicit_tail_calls):
951        //   we should check if both caller&callee can/n't unwind,
952        //   see <https://github.com/rust-lang/rust/pull/113128#issuecomment-1614979803>
953
954        // Now push the new stack frame.
955        self.init_fn_call(
956            fn_val,
957            (caller_abi, caller_fn_abi),
958            &*args,
959            with_caller_location,
960            frame.return_place(),
961            ret,
962            unwind,
963        )?;
964
965        // Finally, clear the local variables. Has to be done after pushing to support
966        // non-scalar arguments.
967        // FIXME(explicit_tail_calls,#144855): revisit this once codegen supports indirect
968        // arguments, to ensure the semantics are compatible.
969        let return_action = self.cleanup_stack_frame(/* unwinding */ false, frame)?;
970        {
    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);
971
972        interp_ok(())
973    }
974
975    pub(super) fn init_drop_in_place_call(
976        &mut self,
977        place: &PlaceTy<'tcx, M::Provenance>,
978        instance: ty::Instance<'tcx>,
979        target: mir::BasicBlock,
980        unwind: mir::UnwindAction,
981    ) -> InterpResult<'tcx> {
982        {
    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:982",
                        "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(982u32),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("init_drop_in_place_call: {0:?},\n  instance={1:?}",
                                                    place, instance) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!("init_drop_in_place_call: {:?},\n  instance={:?}", place, instance);
983        // We take the address of the object. This may well be unaligned, which is fine
984        // for us here. However, unaligned accesses will probably make the actual drop
985        // implementation fail -- a problem shared by rustc.
986        let place = self.force_allocation(place)?;
987
988        // We behave a bit different from codegen here.
989        // Codegen creates an `InstanceKind::Virtual` with index 0 (the slot of the drop method) and
990        // then dispatches that to the normal call machinery. However, our call machinery currently
991        // only supports calling `VtblEntry::Method`; it would choke on a `MetadataDropInPlace`. So
992        // instead we do the virtual call stuff ourselves. It's easier here than in `eval_fn_call`
993        // since we can just get a place of the underlying type and use `mplace_to_imm_ptr`.
994        let place = match place.layout.ty.kind() {
995            ty::Dynamic(data, _) => {
996                // Dropping a trait object. Need to find actual drop fn.
997                self.unpack_dyn_trait(&place, data)?
998            }
999            _ => {
1000                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!(
1001                    instance,
1002                    ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
1003                );
1004                place
1005            }
1006        };
1007
1008        let instance = {
1009            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(1009u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("resolve")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("resolve");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("ty")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("ty");
                                                    NAME.as_str()
                                                }], ::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};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::display(&"resolve_drop_glue")
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place.layout.ty)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        })enter_trace_span!(M, resolve::resolve_drop_glue, ty = ?place.layout.ty);
1010            ty::Instance::resolve_drop_glue(*self.tcx, place.layout.ty)
1011        };
1012        let fn_abi = self.fn_abi_of_instance_no_deduced_attrs(instance, ty::List::empty())?;
1013
1014        let ref_ty = Ty::new_mut_ref(self.tcx.tcx, self.tcx.lifetimes.re_erased, place.layout.ty);
1015        let arg = self.mplace_to_imm_ptr(&place, Some(ref_ty))?;
1016
1017        let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?);
1018
1019        self.init_fn_call(
1020            FnVal::Instance(instance),
1021            (ExternAbi::Rust, fn_abi),
1022            &[FnArg::Copy(arg.into())],
1023            false,
1024            &ret.into(),
1025            Some(target),
1026            unwind,
1027        )
1028    }
1029
1030    /// Pops the current frame from the stack, copies the return value to the caller, deallocates
1031    /// the memory for allocated locals, and jumps to an appropriate place.
1032    ///
1033    /// If `unwinding` is `false`, then we are performing a normal return
1034    /// from a function. In this case, we jump back into the frame of the caller,
1035    /// and continue execution as normal.
1036    ///
1037    /// If `unwinding` is `true`, then we are in the middle of a panic,
1038    /// and need to unwind this frame. In this case, we jump to the
1039    /// `cleanup` block for the function, which is responsible for running
1040    /// `Drop` impls for any locals that have been initialized at this point.
1041    /// The cleanup block ends with a special `Resume` terminator, which will
1042    /// cause us to continue unwinding.
1043    #[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(1043u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::interpret::call"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("unwinding")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("unwinding");
                                                        NAME.as_str()
                                                    }], ::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};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&unwinding
                                                            as &dyn ::tracing::field::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:1048",
                                    "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(1048u32),
                                    ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("popping stack frame ({0})",
                                                                if unwinding {
                                                                    "during unwinding"
                                                                } else { "returning from function" }) as
                                                        &dyn ::tracing::field::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:1074",
                                        "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(1074u32),
                                        ::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};
                                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("return value: {0:?}",
                                                                    self.dump_place(frame.return_place())) as
                                                            &dyn ::tracing::field::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")]
1044    pub(super) fn return_from_current_stack_frame(
1045        &mut self,
1046        unwinding: bool,
1047    ) -> InterpResult<'tcx> {
1048        info!(
1049            "popping stack frame ({})",
1050            if unwinding { "during unwinding" } else { "returning from function" }
1051        );
1052
1053        // Check `unwinding`.
1054        assert_eq!(
1055            unwinding,
1056            match self.frame().loc {
1057                Left(loc) => self.body().basic_blocks[loc.block].is_cleanup,
1058                Right(_) => true,
1059            }
1060        );
1061        if unwinding && self.frame_idx() == 0 {
1062            throw_ub_format!("unwinding past the topmost frame of the stack");
1063        }
1064
1065        // Get out the return value. Must happen *before* the frame is popped as we have to get the
1066        // local's value out.
1067        let return_op =
1068            self.local_to_op(mir::RETURN_PLACE, None).expect("return place should always be live");
1069        // Remove the frame from the stack.
1070        let frame = self.pop_stack_frame_raw()?;
1071        // Copy the return value and remember the return continuation.
1072        if !unwinding {
1073            self.copy_op_allow_transmute(&return_op, frame.return_place())?;
1074            trace!("return value: {:?}", self.dump_place(frame.return_place()));
1075        }
1076        let return_cont = frame.return_cont();
1077        // Finish popping the stack frame.
1078        let return_action = self.cleanup_stack_frame(unwinding, frame)?;
1079        // Jump to the next block.
1080        match return_action {
1081            ReturnAction::Normal => {}
1082            ReturnAction::NoJump => {
1083                // The hook already did everything.
1084                return interp_ok(());
1085            }
1086            ReturnAction::NoCleanup => {
1087                // If we are not doing cleanup, also skip everything else.
1088                assert!(self.stack().is_empty(), "only the topmost frame should ever be leaked");
1089                assert!(!unwinding, "tried to skip cleanup during unwinding");
1090                // Don't jump anywhere.
1091                return interp_ok(());
1092            }
1093        }
1094
1095        // Normal return, figure out where to jump.
1096        if unwinding {
1097            // Follow the unwind edge.
1098            match return_cont {
1099                ReturnContinuation::Goto { unwind, .. } => {
1100                    // This must be the very last thing that happens, since it can in fact push a new stack frame.
1101                    self.unwind_to_block(unwind)
1102                }
1103                ReturnContinuation::Stop { .. } => {
1104                    panic!("encountered ReturnContinuation::Stop when unwinding!")
1105                }
1106            }
1107        } else {
1108            // Follow the normal return edge.
1109            match return_cont {
1110                ReturnContinuation::Goto { ret, .. } => self.return_to_block(ret),
1111                ReturnContinuation::Stop { .. } => {
1112                    assert!(
1113                        self.stack().is_empty(),
1114                        "only the bottommost frame can have ReturnContinuation::Stop"
1115                    );
1116                    interp_ok(())
1117                }
1118            }
1119        }
1120    }
1121}