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