Skip to main content

rustc_const_eval/const_eval/
valtrees.rs

1use rustc_abi::{BackendRepr, FieldIdx, VariantIdx};
2use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3use rustc_middle::mir;
4use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId, ValTreeCreationError};
5use rustc_middle::traits::ObligationCause;
6use rustc_middle::ty::layout::{LayoutCx, TyAndLayout};
7use rustc_middle::ty::{self, Ty, TyCtxt};
8use rustc_span::{DUMMY_SP, bug};
9use tracing::{debug, instrument, trace};
10
11use super::VALTREE_MAX_NODES;
12use super::eval_queries::{mk_eval_cx_to_read_const_val, op_to_const};
13use super::machine::CompileTimeInterpCx;
14use crate::const_eval::CanAccessMutGlobal;
15use crate::interpret::{
16    ImmTy, Immediate, InternKind, MPlaceTy, MemPlaceMeta, MemoryKind, PlaceTy, Projectable, Scalar,
17    intern_const_alloc_recursive,
18};
19
20{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("branches",
                                    "rustc_const_eval::const_eval::valtrees",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                    ::tracing_core::__macro_support::Option::Some(20u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("place")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("place");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("field_count")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("field_count");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("variant")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("variant");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("num_nodes")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("num_nodes");
                                                        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::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&field_count as
                                                            &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&variant)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&num_nodes 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: EvalToValTreeResult<'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let place =
                match variant {
                    Some(variant) =>
                        ecx.project_downcast(place, variant).unwrap(),
                    None => place.clone(),
                };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:34",
                                    "rustc_const_eval::const_eval::valtrees",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                    ::tracing_core::__macro_support::Option::Some(34u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("place")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("place");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::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(&::tracing::field::debug(&place)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut branches =
                Vec::with_capacity(field_count + variant.is_some() as usize);
            if let Some(variant) = variant {
                branches.push(ty::Const::new_value(*ecx.tcx,
                        ty::ValTree::from_scalar_int(*ecx.tcx,
                            variant.as_u32().into()), ecx.tcx.types.u32));
            }
            for i in 0..field_count {
                let field =
                    ecx.project_field(&place,
                                FieldIdx::from_usize(i)).report_err()?;
                let valtree =
                    const_to_valtree_inner(ecx, &field, num_nodes, visited,
                            settled)?;
                branches.push(ty::Const::new_value(*ecx.tcx, valtree,
                        field.layout.ty));
            }
            if branches.len() == 0 { *num_nodes += 1; }
            Ok(ty::ValTree::from_branches(*ecx.tcx, branches))
        }
    }
}#[instrument(skip(ecx, visited, settled), level = "debug")]
21fn branches<'tcx>(
22    ecx: &CompileTimeInterpCx<'tcx>,
23    place: &MPlaceTy<'tcx>,
24    field_count: usize,
25    variant: Option<VariantIdx>,
26    num_nodes: &mut usize,
27    visited: &mut FxHashSet<MPlaceTy<'tcx>>,
28    settled: &mut FxHashMap<MPlaceTy<'tcx>, EvalToValTreeResult<'tcx>>,
29) -> EvalToValTreeResult<'tcx> {
30    let place = match variant {
31        Some(variant) => ecx.project_downcast(place, variant).unwrap(),
32        None => place.clone(),
33    };
34    debug!(?place);
35
36    let mut branches = Vec::with_capacity(field_count + variant.is_some() as usize);
37
38    // For enums, we prepend their variant index before the variant's fields so we can figure out
39    // the variant again when just seeing a valtree.
40    if let Some(variant) = variant {
41        branches.push(ty::Const::new_value(
42            *ecx.tcx,
43            ty::ValTree::from_scalar_int(*ecx.tcx, variant.as_u32().into()),
44            ecx.tcx.types.u32,
45        ));
46    }
47
48    for i in 0..field_count {
49        let field = ecx.project_field(&place, FieldIdx::from_usize(i)).report_err()?;
50        let valtree = const_to_valtree_inner(ecx, &field, num_nodes, visited, settled)?;
51        branches.push(ty::Const::new_value(*ecx.tcx, valtree, field.layout.ty));
52    }
53
54    // Have to account for ZSTs here
55    if branches.len() == 0 {
56        *num_nodes += 1;
57    }
58
59    Ok(ty::ValTree::from_branches(*ecx.tcx, branches))
60}
61
62{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("slice_branches",
                                    "rustc_const_eval::const_eval::valtrees",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                    ::tracing_core::__macro_support::Option::Some(62u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("place")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("place");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("num_nodes")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("num_nodes");
                                                        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::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&num_nodes 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: EvalToValTreeResult<'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let n =
                place.len(ecx).unwrap_or_else(|_|
                        {
                            ::core::panicking::panic_fmt(format_args!("expected to use len of place {0:?}",
                                    place));
                        });
            let mut elems = Vec::with_capacity(n as usize);
            for i in 0..n {
                let place_elem = ecx.project_index(place, i).unwrap();
                let valtree =
                    const_to_valtree_inner(ecx, &place_elem, num_nodes, visited,
                            settled)?;
                elems.push(ty::Const::new_value(*ecx.tcx, valtree,
                        place_elem.layout.ty));
            }
            Ok(ty::ValTree::from_branches(*ecx.tcx, elems))
        }
    }
}#[instrument(skip(ecx, visited, settled), level = "debug")]
63fn slice_branches<'tcx>(
64    ecx: &CompileTimeInterpCx<'tcx>,
65    place: &MPlaceTy<'tcx>,
66    num_nodes: &mut usize,
67    visited: &mut FxHashSet<MPlaceTy<'tcx>>,
68    settled: &mut FxHashMap<MPlaceTy<'tcx>, EvalToValTreeResult<'tcx>>,
69) -> EvalToValTreeResult<'tcx> {
70    let n = place.len(ecx).unwrap_or_else(|_| panic!("expected to use len of place {place:?}"));
71
72    let mut elems = Vec::with_capacity(n as usize);
73    for i in 0..n {
74        let place_elem = ecx.project_index(place, i).unwrap();
75        let valtree = const_to_valtree_inner(ecx, &place_elem, num_nodes, visited, settled)?;
76        elems.push(ty::Const::new_value(*ecx.tcx, valtree, place_elem.layout.ty));
77    }
78
79    Ok(ty::ValTree::from_branches(*ecx.tcx, elems))
80}
81
82{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("const_to_valtree_inner",
                                    "rustc_const_eval::const_eval::valtrees",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                    ::tracing_core::__macro_support::Option::Some(82u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("place")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("place");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("num_nodes")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("num_nodes");
                                                        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::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&num_nodes 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: EvalToValTreeResult<'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            let tcx = *ecx.tcx;
            let ty = place.layout.ty;
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:92",
                                    "rustc_const_eval::const_eval::valtrees",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                    ::tracing_core::__macro_support::Option::Some(92u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                    ::tracing_core::field::FieldSet::new(&["message"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::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!("ty kind: {0:?}",
                                                                ty.kind()) as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            if let Some(&result) = settled.get(place) { return result; }
            if visited.contains(place) {
                return Err(ValTreeCreationError::CyclicConst);
            }
            if *num_nodes >= VALTREE_MAX_NODES {
                return Err(ValTreeCreationError::NodesOverflow);
            }
            visited.insert(place.clone());
            let result =
                match ty.kind() {
                    ty::FnDef(..) => {
                        *num_nodes += 1;
                        Ok(ty::ValTree::zst(tcx))
                    }
                    ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) |
                        ty::Char => {
                        let val = ecx.read_immediate(place).report_err()?;
                        let val = val.to_scalar_int().unwrap();
                        *num_nodes += 1;
                        Ok(ty::ValTree::from_scalar_int(tcx, val))
                    }
                    ty::Pat(base, ..) => {
                        let mut place = place.clone();
                        place.layout = ecx.layout_of(*base).unwrap();
                        const_to_valtree_inner(ecx, &place, num_nodes, visited,
                            settled)
                    }
                    ty::RawPtr(_, _) => {
                        let val = ecx.read_immediate(place).report_err()?;
                        if #[allow(non_exhaustive_omitted_patterns)] match val.layout.backend_repr
                                {
                                BackendRepr::ScalarPair { .. } => true,
                                _ => false,
                            } {
                            Err(ValTreeCreationError::NonSupportedType(ty))
                        } else {
                            let val = val.to_scalar();
                            match val.try_to_scalar_int() {
                                Ok(val) => Ok(ty::ValTree::from_scalar_int(tcx, val)),
                                Err(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
                            }
                        }
                    }
                    ty::FnPtr(..) =>
                        Err(ValTreeCreationError::NonSupportedType(ty)),
                    ty::Ref(_, _, _) => {
                        let derefd_place = ecx.deref_pointer(place).report_err()?;
                        const_to_valtree_inner(ecx, &derefd_place, num_nodes,
                            visited, settled)
                    }
                    ty::Str | ty::Slice(_) | ty::Array(_, _) => {
                        slice_branches(ecx, place, num_nodes, visited, settled)
                    }
                    ty::Dynamic(..) =>
                        Err(ValTreeCreationError::NonSupportedType(ty)),
                    ty::Tuple(elem_tys) => {
                        branches(ecx, place, elem_tys.len(), None, num_nodes,
                            visited, settled)
                    }
                    ty::Adt(def, _) => {
                        if def.is_union() {
                            Err(ValTreeCreationError::NonSupportedType(ty))
                        } else if def.variants().is_empty() {
                            ::rustc_span::macros::bug_impl(None,
                                format_args!("uninhabited types should have errored and never gotten converted to valtree"),
                                Location::caller())
                        } else {
                            let variant = ecx.read_discriminant(place).report_err()?;
                            branches(ecx, place, def.variant(variant).fields.len(),
                                def.is_enum().then_some(variant), num_nodes, visited,
                                settled)
                        }
                    }
                    ty::Alias(..) =>
                        Err(ValTreeCreationError::NonSupportedType(ty)),
                    ty::Closure(..) =>
                        Err(ValTreeCreationError::NonSupportedType(ty)),
                    ty::Never | ty::Error(_) | ty::Foreign(..) |
                        ty::Infer(ty::FreshIntTy(_)) |
                        ty::Infer(ty::FreshFloatTy(_)) | ty::Param(_) |
                        ty::Bound(..) | ty::Placeholder(..) | ty::Infer(_) |
                        ty::CoroutineClosure(..) | ty::Coroutine(..) |
                        ty::CoroutineWitness(..) | ty::UnsafeBinder(_) =>
                        Err(ValTreeCreationError::NonSupportedType(ty)),
                    ty::View(..) =>
                        ::core::panicking::unimplemented_default_msg(),
                };
            visited.remove(place);
            settled.insert(place.clone(), result);
            result
        }
    }
}#[instrument(skip(ecx, visited, settled), level = "debug")]
83fn const_to_valtree_inner<'tcx>(
84    ecx: &CompileTimeInterpCx<'tcx>,
85    place: &MPlaceTy<'tcx>,
86    num_nodes: &mut usize,
87    visited: &mut FxHashSet<MPlaceTy<'tcx>>,
88    settled: &mut FxHashMap<MPlaceTy<'tcx>, EvalToValTreeResult<'tcx>>,
89) -> EvalToValTreeResult<'tcx> {
90    let tcx = *ecx.tcx;
91    let ty = place.layout.ty;
92    debug!("ty kind: {:?}", ty.kind());
93
94    if let Some(&result) = settled.get(place) {
95        return result;
96    }
97
98    if visited.contains(place) {
99        return Err(ValTreeCreationError::CyclicConst);
100    }
101
102    if *num_nodes >= VALTREE_MAX_NODES {
103        return Err(ValTreeCreationError::NodesOverflow);
104    }
105
106    visited.insert(place.clone());
107
108    let result = match ty.kind() {
109        ty::FnDef(..) => {
110            *num_nodes += 1;
111            Ok(ty::ValTree::zst(tcx))
112        }
113        ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => {
114            let val = ecx.read_immediate(place).report_err()?;
115            let val = val.to_scalar_int().unwrap();
116            *num_nodes += 1;
117
118            Ok(ty::ValTree::from_scalar_int(tcx, val))
119        }
120
121        ty::Pat(base, ..) => {
122            let mut place = place.clone();
123            // The valtree of the base type is the same as the valtree of the pattern type.
124            // Since the returned valtree does not contain the type or layout, we can just
125            // switch to the base type.
126            place.layout = ecx.layout_of(*base).unwrap();
127            const_to_valtree_inner(ecx, &place, num_nodes, visited, settled)
128        }
129
130        ty::RawPtr(_, _) => {
131            // Not all raw pointers are allowed, as we cannot properly test them for
132            // equality at compile-time (see `ptr_guaranteed_cmp`).
133            // However we allow those that are just integers in disguise.
134            // First, get the pointer. Remember it might be wide!
135            let val = ecx.read_immediate(place).report_err()?;
136            // We could allow wide raw pointers where both sides are integers in the future,
137            // but for now we reject them.
138            if matches!(val.layout.backend_repr, BackendRepr::ScalarPair { .. }) {
139                Err(ValTreeCreationError::NonSupportedType(ty))
140            } else {
141                let val = val.to_scalar();
142                // We are in the CTFE machine, so ptr-to-int casts will fail.
143                // This can only be `Ok` if `val` already is an integer.
144                match val.try_to_scalar_int() {
145                    Ok(val) => Ok(ty::ValTree::from_scalar_int(tcx, val)),
146                    Err(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
147                }
148            }
149        }
150
151        // Technically we could allow function pointers (represented as `ty::Instance`), but this is not guaranteed to
152        // agree with runtime equality tests.
153        ty::FnPtr(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
154
155        ty::Ref(_, _, _) => {
156            let derefd_place = ecx.deref_pointer(place).report_err()?;
157            const_to_valtree_inner(ecx, &derefd_place, num_nodes, visited, settled)
158        }
159
160        ty::Str | ty::Slice(_) | ty::Array(_, _) => {
161            slice_branches(ecx, place, num_nodes, visited, settled)
162        }
163        // Trait objects are not allowed in type level constants, as we have no concept for
164        // resolving their backing type, even if we can do that at const eval time. We may
165        // hypothetically be able to allow `dyn StructuralPartialEq` trait objects in the future,
166        // but it is unclear if this is useful.
167        ty::Dynamic(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
168
169        ty::Tuple(elem_tys) => {
170            branches(ecx, place, elem_tys.len(), None, num_nodes, visited, settled)
171        }
172
173        ty::Adt(def, _) => {
174            if def.is_union() {
175                Err(ValTreeCreationError::NonSupportedType(ty))
176            } else if def.variants().is_empty() {
177                bug!("uninhabited types should have errored and never gotten converted to valtree")
178            } else {
179                let variant = ecx.read_discriminant(place).report_err()?;
180                branches(
181                    ecx,
182                    place,
183                    def.variant(variant).fields.len(),
184                    def.is_enum().then_some(variant),
185                    num_nodes,
186                    visited,
187                    settled,
188                )
189            }
190        }
191
192        // FIXME(oli-obk): we could look behind opaque types
193        ty::Alias(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
194
195        // FIXME(oli-obk): we can probably encode closures just like structs
196        ty::Closure(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
197
198        ty::Never
199        | ty::Error(_)
200        | ty::Foreign(..)
201        | ty::Infer(ty::FreshIntTy(_))
202        | ty::Infer(ty::FreshFloatTy(_))
203        | ty::Param(_)
204        | ty::Bound(..)
205        | ty::Placeholder(..)
206        | ty::Infer(_)
207        | ty::CoroutineClosure(..)
208        | ty::Coroutine(..)
209        | ty::CoroutineWitness(..)
210        | ty::UnsafeBinder(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
211
212        // FIXME(scrabsha)
213        ty::View(..) => unimplemented!(),
214    };
215
216    visited.remove(place);
217    settled.insert(place.clone(), result);
218    result
219}
220
221/// Valtrees don't store the `MemPlaceMeta` that all dynamically sized values have in the interpreter.
222/// This function reconstructs it.
223fn reconstruct_place_meta<'tcx>(
224    layout: TyAndLayout<'tcx>,
225    valtree: ty::ValTree<'tcx>,
226    tcx: TyCtxt<'tcx>,
227) -> MemPlaceMeta {
228    if layout.is_sized() {
229        return MemPlaceMeta::None;
230    }
231
232    let mut last_valtree = valtree;
233    // Traverse the type, and update `last_valtree` as we go.
234    //
235    // FIXME(#155345): Missing normalization call
236    let tail = tcx.struct_tail_raw(
237        layout.ty,
238        &ObligationCause::dummy(),
239        |ty| ty.skip_norm_wip(),
240        || {
241            let branches = last_valtree.to_branch();
242            last_valtree = branches.last().unwrap().to_value().valtree;
243            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:243",
                        "rustc_const_eval::const_eval::valtrees",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                        ::tracing_core::__macro_support::Option::Some(243u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("branches")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("branches");
                                            NAME.as_str()
                                        },
                                        {
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("last_valtree")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("last_valtree");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::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(&::tracing::field::debug(&branches)
                                            as &dyn ::tracing::field::Value)),
                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&last_valtree)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?branches, ?last_valtree);
244        },
245    );
246    // Sanity-check that we got a tail we support.
247    match tail.kind() {
248        ty::Slice(..) | ty::Str => {}
249        _ => ::rustc_span::macros::bug_impl(None,
    format_args!("unsized tail of a valtree must be Slice or Str"),
    Location::caller())bug!("unsized tail of a valtree must be Slice or Str"),
250    };
251
252    // Get the number of elements in the unsized field.
253    let num_elems = last_valtree.to_branch().len();
254    MemPlaceMeta::Meta(Scalar::from_target_usize(num_elems as u64, &tcx))
255}
256
257{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("create_valtree_place",
                                "rustc_const_eval::const_eval::valtrees",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                ::tracing_core::__macro_support::Option::Some(257u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("layout")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("layout");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("valtree")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("valtree");
                                                    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::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&layout)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&valtree)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: MPlaceTy<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let meta =
                            reconstruct_place_meta(layout, valtree, ecx.tcx.tcx);
                        ecx.allocate_dyn(layout, MemoryKind::Stack, meta).unwrap()
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:257",
                        "rustc_const_eval::const_eval::valtrees",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                        ::tracing_core::__macro_support::Option::Some(257u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::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(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(skip(ecx), level = "debug", ret)]
258fn create_valtree_place<'tcx>(
259    ecx: &mut CompileTimeInterpCx<'tcx>,
260    layout: TyAndLayout<'tcx>,
261    valtree: ty::ValTree<'tcx>,
262) -> MPlaceTy<'tcx> {
263    let meta = reconstruct_place_meta(layout, valtree, ecx.tcx.tcx);
264    ecx.allocate_dyn(layout, MemoryKind::Stack, meta).unwrap()
265}
266
267/// Evaluates a constant and turns it into a type-level constant value.
268pub(crate) fn eval_to_valtree<'tcx>(
269    tcx: TyCtxt<'tcx>,
270    typing_env: ty::TypingEnv<'tcx>,
271    cid: GlobalId<'tcx>,
272) -> EvalToValTreeResult<'tcx> {
273    crate::assert_typing_mode(typing_env.typing_mode());
274    let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(cid))?;
275
276    // FIXME Need to provide a span to `eval_to_valtree`
277    let ecx = mk_eval_cx_to_read_const_val(
278        tcx,
279        DUMMY_SP,
280        typing_env,
281        // It is absolutely crucial for soundness that
282        // we do not read from mutable memory.
283        CanAccessMutGlobal::No,
284    );
285    let place = ecx.raw_const_to_mplace(const_alloc).unwrap();
286    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:286",
                        "rustc_const_eval::const_eval::valtrees",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                        ::tracing_core::__macro_support::Option::Some(286u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("place")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("place");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::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(&::tracing::field::debug(&place)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?place);
287
288    let mut num_nodes = 0;
289    let mut visited = FxHashSet::default();
290    let mut settled = FxHashMap::default();
291    const_to_valtree_inner(&ecx, &place, &mut num_nodes, &mut visited, &mut settled)
292}
293
294/// Converts a `ValTree` to a `ConstValue`, which is needed after mir
295/// construction has finished.
296// FIXME(valtrees): Merge `valtree_to_const_value` and `valtree_into_mplace` into one function
297{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("valtree_to_const_value",
                                "rustc_const_eval::const_eval::valtrees",
                                ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                ::tracing_core::__macro_support::Option::Some(297u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("typing_env")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("typing_env");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("cv")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("cv");
                                                    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::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cv)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[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: mir::ConstValue = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        match *cv.ty.kind() {
                            ty::FnDef(..) => {
                                if !cv.valtree.is_zst() {
                                    ::core::panicking::panic("assertion failed: cv.valtree.is_zst()")
                                };
                                mir::ConstValue::ZeroSized
                            }
                            ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) |
                                ty::Char | ty::RawPtr(_, _) => {
                                mir::ConstValue::Scalar(Scalar::Int(cv.to_leaf()))
                            }
                            ty::Pat(ty, _) => {
                                let cv = ty::Value { valtree: cv.valtree, ty };
                                valtree_to_const_value(tcx, typing_env, cv)
                            }
                            ty::Ref(_, inner_ty, _) => {
                                let mut ecx =
                                    mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env,
                                        CanAccessMutGlobal::No);
                                let imm = valtree_to_ref(&mut ecx, cv.valtree, inner_ty);
                                let imm =
                                    ImmTy::from_immediate(imm,
                                        tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap());
                                op_to_const(&ecx, &imm.into(), false)
                            }
                            ty::Tuple(_) | ty::Array(_, _) | ty::Adt(..) => {
                                let layout =
                                    tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap();
                                if layout.is_zst() { return mir::ConstValue::ZeroSized; }
                                if layout.backend_repr.is_scalar() &&
                                        (#[allow(non_exhaustive_omitted_patterns)] match cv.ty.kind()
                                                    {
                                                    ty::Tuple(_) => true,
                                                    _ => false,
                                                } ||
                                                #[allow(non_exhaustive_omitted_patterns)] match cv.ty.kind()
                                                    {
                                                    ty::Adt(def, _) if def.is_struct() => true,
                                                    _ => false,
                                                }) {
                                    let branches = cv.to_branch();
                                    for (i, &inner_valtree) in branches.iter().enumerate() {
                                        let field =
                                            layout.field(&LayoutCx::new(tcx, typing_env), i);
                                        if !field.is_zst() {
                                            let cv =
                                                ty::Value {
                                                    valtree: inner_valtree.to_value().valtree,
                                                    ty: field.ty,
                                                };
                                            return valtree_to_const_value(tcx, typing_env, cv);
                                        }
                                    }
                                    ::rustc_span::macros::bug_impl(None,
                                        format_args!("could not find non-ZST field during in {0:#?}",
                                            layout), Location::caller());
                                }
                                let mut ecx =
                                    mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env,
                                        CanAccessMutGlobal::No);
                                let place =
                                    create_valtree_place(&mut ecx, layout, cv.valtree);
                                valtree_into_mplace(&mut ecx, &place, cv.valtree);
                                dump_place(&ecx, &place);
                                intern_const_alloc_recursive(&mut ecx, InternKind::Constant,
                                        &place).unwrap();
                                op_to_const(&ecx, &place.into(), false)
                            }
                            ty::Never | ty::Error(_) | ty::Foreign(..) |
                                ty::Infer(ty::FreshIntTy(_)) |
                                ty::Infer(ty::FreshFloatTy(_)) | ty::Alias(..) |
                                ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) |
                                ty::Infer(_) | ty::Closure(..) | ty::CoroutineClosure(..) |
                                ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::FnPtr(..)
                                | ty::Str | ty::Slice(_) | ty::Dynamic(..) |
                                ty::UnsafeBinder(_) => {
                                ::rustc_span::macros::bug_impl(None,
                                    format_args!("no ValTree should have been created for type {0:?}",
                                        cv.ty.kind()), Location::caller())
                            }
                            ty::View(..) =>
                                ::core::panicking::unimplemented_default_msg(),
                        }
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:297",
                        "rustc_const_eval::const_eval::valtrees",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                        ::tracing_core::__macro_support::Option::Some(297u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::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(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(skip(tcx), level = "debug", ret)]
298pub fn valtree_to_const_value<'tcx>(
299    tcx: TyCtxt<'tcx>,
300    typing_env: ty::TypingEnv<'tcx>,
301    cv: ty::Value<'tcx>,
302) -> mir::ConstValue {
303    // Basic idea: We directly construct `Scalar` values from trivial `ValTree`s
304    // (those for constants with type bool, int, uint, float or char).
305    // For all other types we create an `MPlace` and fill that by walking
306    // the `ValTree` and using `place_projection` and `place_field` to
307    // create inner `MPlace`s which are filled recursively.
308    // FIXME: Does this need an example?
309    match *cv.ty.kind() {
310        ty::FnDef(..) => {
311            assert!(cv.valtree.is_zst());
312            mir::ConstValue::ZeroSized
313        }
314        ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(_, _) => {
315            mir::ConstValue::Scalar(Scalar::Int(cv.to_leaf()))
316        }
317        ty::Pat(ty, _) => {
318            let cv = ty::Value { valtree: cv.valtree, ty };
319            valtree_to_const_value(tcx, typing_env, cv)
320        }
321        ty::Ref(_, inner_ty, _) => {
322            let mut ecx =
323                mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env, CanAccessMutGlobal::No);
324            let imm = valtree_to_ref(&mut ecx, cv.valtree, inner_ty);
325            let imm = ImmTy::from_immediate(
326                imm,
327                tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap(),
328            );
329            op_to_const(&ecx, &imm.into(), /* for diagnostics */ false)
330        }
331        ty::Tuple(_) | ty::Array(_, _) | ty::Adt(..) => {
332            let layout = tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap();
333            if layout.is_zst() {
334                // Fast path to avoid some allocations.
335                return mir::ConstValue::ZeroSized;
336            }
337            if layout.backend_repr.is_scalar()
338                && (matches!(cv.ty.kind(), ty::Tuple(_))
339                    || matches!(cv.ty.kind(), ty::Adt(def, _) if def.is_struct()))
340            {
341                // A Scalar tuple/struct; we can avoid creating an allocation.
342                let branches = cv.to_branch();
343                // Find the non-ZST field. (There can be aligned ZST!)
344                for (i, &inner_valtree) in branches.iter().enumerate() {
345                    let field = layout.field(&LayoutCx::new(tcx, typing_env), i);
346                    if !field.is_zst() {
347                        let cv =
348                            ty::Value { valtree: inner_valtree.to_value().valtree, ty: field.ty };
349                        return valtree_to_const_value(tcx, typing_env, cv);
350                    }
351                }
352                bug!("could not find non-ZST field during in {layout:#?}");
353            }
354
355            let mut ecx =
356                mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env, CanAccessMutGlobal::No);
357
358            // Need to create a place for this valtree.
359            let place = create_valtree_place(&mut ecx, layout, cv.valtree);
360
361            valtree_into_mplace(&mut ecx, &place, cv.valtree);
362            dump_place(&ecx, &place);
363            intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &place).unwrap();
364
365            op_to_const(&ecx, &place.into(), /* for diagnostics */ false)
366        }
367        ty::Never
368        | ty::Error(_)
369        | ty::Foreign(..)
370        | ty::Infer(ty::FreshIntTy(_))
371        | ty::Infer(ty::FreshFloatTy(_))
372        | ty::Alias(..)
373        | ty::Param(_)
374        | ty::Bound(..)
375        | ty::Placeholder(..)
376        | ty::Infer(_)
377        | ty::Closure(..)
378        | ty::CoroutineClosure(..)
379        | ty::Coroutine(..)
380        | ty::CoroutineWitness(..)
381        | ty::FnPtr(..)
382        | ty::Str
383        | ty::Slice(_)
384        | ty::Dynamic(..)
385        | ty::UnsafeBinder(_) => {
386            bug!("no ValTree should have been created for type {:?}", cv.ty.kind())
387        }
388
389        // FIXME(scrabsha)
390        ty::View(..) => unimplemented!(),
391    }
392}
393
394/// Put a valtree into memory and return a reference to that.
395fn valtree_to_ref<'tcx>(
396    ecx: &mut CompileTimeInterpCx<'tcx>,
397    valtree: ty::ValTree<'tcx>,
398    pointee_ty: Ty<'tcx>,
399) -> Immediate {
400    let pointee_place = create_valtree_place(ecx, ecx.layout_of(pointee_ty).unwrap(), valtree);
401    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:401",
                        "rustc_const_eval::const_eval::valtrees",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                        ::tracing_core::__macro_support::Option::Some(401u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("pointee_place")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("pointee_place");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::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(&::tracing::field::debug(&pointee_place)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(?pointee_place);
402
403    valtree_into_mplace(ecx, &pointee_place, valtree);
404    dump_place(ecx, &pointee_place);
405    intern_const_alloc_recursive(ecx, InternKind::Constant, &pointee_place).unwrap();
406
407    pointee_place.to_ref(&ecx.tcx)
408}
409
410{}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("valtree_into_mplace",
                                    "rustc_const_eval::const_eval::valtrees",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                    ::tracing_core::__macro_support::Option::Some(410u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("place")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("place");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("valtree")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("valtree");
                                                        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::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&valtree)
                                                            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: () = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let ty = place.layout.ty;
            match ty.kind() {
                ty::FnDef(_, _) => {}
                ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char
                    | ty::RawPtr(..) => {
                    let scalar_int = valtree.to_leaf();
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:427",
                                            "rustc_const_eval::const_eval::valtrees",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                            ::tracing_core::__macro_support::Option::Some(427u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::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!("writing trivial valtree {0:?} to place {1:?}",
                                                                        scalar_int, place) as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    ecx.write_immediate(Immediate::Scalar(scalar_int.into()),
                            place).unwrap();
                }
                ty::Ref(_, inner_ty, _) => {
                    let imm = valtree_to_ref(ecx, valtree, *inner_ty);
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:432",
                                            "rustc_const_eval::const_eval::valtrees",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                            ::tracing_core::__macro_support::Option::Some(432u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("imm")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("imm");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::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(&::tracing::field::debug(&imm)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    ecx.write_immediate(imm, place).unwrap();
                }
                ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Str |
                    ty::Slice(_) => {
                    let branches = valtree.to_branch();
                    let (place_adjusted, branches, variant_idx) =
                        match ty.kind() {
                            ty::Adt(def, _) if def.is_enum() => {
                                let scalar_int = branches[0].to_leaf();
                                let variant_idx = VariantIdx::from_u32(scalar_int.to_u32());
                                let variant = def.variant(variant_idx);
                                {
                                    use ::tracing::__macro_support::Callsite as _;
                                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                        {
                                            static META: ::tracing::Metadata<'static> =
                                                {
                                                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:445",
                                                        "rustc_const_eval::const_eval::valtrees",
                                                        ::tracing::Level::DEBUG,
                                                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                                        ::tracing_core::__macro_support::Option::Some(445u32),
                                                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                                        ::tracing_core::field::FieldSet::new(&[{
                                                                            const NAME:
                                                                                ::tracing::__macro_support::FieldName<{
                                                                                    ::tracing::__macro_support::FieldName::len("variant")
                                                                                }> =
                                                                                ::tracing::__macro_support::FieldName::new("variant");
                                                                            NAME.as_str()
                                                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                        ::tracing::metadata::Kind::EVENT)
                                                };
                                            ::tracing::callsite::DefaultCallsite::new(&META)
                                        };
                                    let enabled =
                                        ::tracing::Level::DEBUG <=
                                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                ::tracing::Level::DEBUG <=
                                                    ::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(&::tracing::field::debug(&variant)
                                                                            as &dyn ::tracing::field::Value))])
                                            });
                                    } else { ; }
                                };
                                (ecx.project_downcast(place, variant_idx).unwrap(),
                                    &branches[1..], Some(variant_idx))
                            }
                            _ => (place.clone(), branches.as_slice(), None),
                        };
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:455",
                                            "rustc_const_eval::const_eval::valtrees",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                            ::tracing_core::__macro_support::Option::Some(455u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("place_adjusted")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("place_adjusted");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("branches")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("branches");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::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(&::tracing::field::debug(&place_adjusted)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&branches)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    for (i, inner_valtree) in branches.iter().enumerate() {
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:460",
                                                "rustc_const_eval::const_eval::valtrees",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                                ::tracing_core::__macro_support::Option::Some(460u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("i")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("i");
                                                                    NAME.as_str()
                                                                },
                                                                {
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("inner_valtree")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("inner_valtree");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::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(&::tracing::field::debug(&i)
                                                                    as &dyn ::tracing::field::Value)),
                                                        (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&inner_valtree)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        let place_inner =
                            match ty.kind() {
                                ty::Str | ty::Slice(_) | ty::Array(..) => {
                                    ecx.project_index(place, i as u64).unwrap()
                                }
                                _ =>
                                    ecx.project_field(&place_adjusted,
                                            FieldIdx::from_usize(i)).unwrap(),
                            };
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:469",
                                                "rustc_const_eval::const_eval::valtrees",
                                                ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                                ::tracing_core::__macro_support::Option::Some(469u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("place_inner")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("place_inner");
                                                                    NAME.as_str()
                                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::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(&::tracing::field::debug(&place_inner)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        valtree_into_mplace(ecx, &place_inner,
                            inner_valtree.to_value().valtree);
                        dump_place(ecx, &place_inner);
                    }
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:474",
                                            "rustc_const_eval::const_eval::valtrees",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                            ::tracing_core::__macro_support::Option::Some(474u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::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!("dump of place_adjusted:")
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    dump_place(ecx, &place_adjusted);
                    if let Some(variant_idx) = variant_idx {
                        ecx.write_discriminant(variant_idx, place).unwrap();
                    }
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:482",
                                            "rustc_const_eval::const_eval::valtrees",
                                            ::tracing::Level::DEBUG,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                                            ::tracing_core::__macro_support::Option::Some(482u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                                            ::tracing_core::field::FieldSet::new(&["message"],
                                                ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::DEBUG <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::DEBUG <=
                                        ::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!("dump of place after writing discriminant:")
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    dump_place(ecx, place);
                }
                _ =>
                    ::rustc_span::macros::bug_impl(None,
                        format_args!("shouldn\'t have created a ValTree for {0:?}",
                            ty), Location::caller()),
            }
        }
    }
}#[instrument(skip(ecx), level = "debug")]
411fn valtree_into_mplace<'tcx>(
412    ecx: &mut CompileTimeInterpCx<'tcx>,
413    place: &MPlaceTy<'tcx>,
414    valtree: ty::ValTree<'tcx>,
415) {
416    // This will match on valtree and write the value(s) corresponding to the ValTree
417    // inside the place recursively.
418
419    let ty = place.layout.ty;
420
421    match ty.kind() {
422        ty::FnDef(_, _) => {
423            // Zero-sized type, nothing to do.
424        }
425        ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(..) => {
426            let scalar_int = valtree.to_leaf();
427            debug!("writing trivial valtree {:?} to place {:?}", scalar_int, place);
428            ecx.write_immediate(Immediate::Scalar(scalar_int.into()), place).unwrap();
429        }
430        ty::Ref(_, inner_ty, _) => {
431            let imm = valtree_to_ref(ecx, valtree, *inner_ty);
432            debug!(?imm);
433            ecx.write_immediate(imm, place).unwrap();
434        }
435        ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Str | ty::Slice(_) => {
436            let branches = valtree.to_branch();
437
438            // Need to downcast place for enums
439            let (place_adjusted, branches, variant_idx) = match ty.kind() {
440                ty::Adt(def, _) if def.is_enum() => {
441                    // First element of valtree corresponds to variant
442                    let scalar_int = branches[0].to_leaf();
443                    let variant_idx = VariantIdx::from_u32(scalar_int.to_u32());
444                    let variant = def.variant(variant_idx);
445                    debug!(?variant);
446
447                    (
448                        ecx.project_downcast(place, variant_idx).unwrap(),
449                        &branches[1..],
450                        Some(variant_idx),
451                    )
452                }
453                _ => (place.clone(), branches.as_slice(), None),
454            };
455            debug!(?place_adjusted, ?branches);
456
457            // Create the places (by indexing into `place`) for the fields and fill
458            // them recursively
459            for (i, inner_valtree) in branches.iter().enumerate() {
460                debug!(?i, ?inner_valtree);
461
462                let place_inner = match ty.kind() {
463                    ty::Str | ty::Slice(_) | ty::Array(..) => {
464                        ecx.project_index(place, i as u64).unwrap()
465                    }
466                    _ => ecx.project_field(&place_adjusted, FieldIdx::from_usize(i)).unwrap(),
467                };
468
469                debug!(?place_inner);
470                valtree_into_mplace(ecx, &place_inner, inner_valtree.to_value().valtree);
471                dump_place(ecx, &place_inner);
472            }
473
474            debug!("dump of place_adjusted:");
475            dump_place(ecx, &place_adjusted);
476
477            if let Some(variant_idx) = variant_idx {
478                // don't forget filling the place with the discriminant of the enum
479                ecx.write_discriminant(variant_idx, place).unwrap();
480            }
481
482            debug!("dump of place after writing discriminant:");
483            dump_place(ecx, place);
484        }
485        _ => bug!("shouldn't have created a ValTree for {:?}", ty),
486    }
487}
488
489fn dump_place<'tcx>(ecx: &CompileTimeInterpCx<'tcx>, place: &MPlaceTy<'tcx>) {
490    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs:490",
                        "rustc_const_eval::const_eval::valtrees",
                        ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/c82ce15637153c025d29abbaff6035a177361788/compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
                        ::tracing_core::__macro_support::Option::Some(490u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
                        ::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!("{0:?}",
                                                    ecx.dump_place(&PlaceTy::from(place.clone()))) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};trace!("{:?}", ecx.dump_place(&PlaceTy::from(place.clone())));
491}