1use rustc_abi::{BackendRepr, FieldIdx, VariantIdx};
2use rustc_data_structures::stack::ensure_sufficient_stack;
3use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId, ValTreeCreationError};
4use rustc_middle::traits::ObligationCause;
5use rustc_middle::ty::layout::{LayoutCx, TyAndLayout};
6use rustc_middle::ty::{self, Ty, TyCtxt};
7use rustc_middle::{bug, mir};
8use rustc_span::DUMMY_SP;
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("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(&["place",
"field_count", "variant", "num_nodes"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&field_count as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&variant)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&num_nodes as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:32",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(32u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&place) as
&dyn 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)).unwrap();
let valtree = const_to_valtree_inner(ecx, &field, num_nodes)?;
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), 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) -> EvalToValTreeResult<'tcx> {
28 let place = match variant {
29 Some(variant) => ecx.project_downcast(place, variant).unwrap(),
30 None => place.clone(),
31 };
32 debug!(?place);
33
34 let mut branches = Vec::with_capacity(field_count + variant.is_some() as usize);
35
36 if let Some(variant) = variant {
39 branches.push(ty::Const::new_value(
40 *ecx.tcx,
41 ty::ValTree::from_scalar_int(*ecx.tcx, variant.as_u32().into()),
42 ecx.tcx.types.u32,
43 ));
44 }
45
46 for i in 0..field_count {
47 let field = ecx.project_field(&place, FieldIdx::from_usize(i)).unwrap();
48 let valtree = const_to_valtree_inner(ecx, &field, num_nodes)?;
49 branches.push(ty::Const::new_value(*ecx.tcx, valtree, field.layout.ty));
50 }
51
52 if branches.len() == 0 {
54 *num_nodes += 1;
55 }
56
57 Ok(ty::ValTree::from_branches(*ecx.tcx, branches))
58}
59
60#[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("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(60u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place",
"num_nodes"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&num_nodes as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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)?;
elems.push(ty::Const::new_value(*ecx.tcx, valtree,
place_elem.layout.ty));
}
Ok(ty::ValTree::from_branches(*ecx.tcx, elems))
}
}
}#[instrument(skip(ecx), level = "debug")]
61fn slice_branches<'tcx>(
62 ecx: &CompileTimeInterpCx<'tcx>,
63 place: &MPlaceTy<'tcx>,
64 num_nodes: &mut usize,
65) -> EvalToValTreeResult<'tcx> {
66 let n = place.len(ecx).unwrap_or_else(|_| panic!("expected to use len of place {place:?}"));
67
68 let mut elems = Vec::with_capacity(n as usize);
69 for i in 0..n {
70 let place_elem = ecx.project_index(place, i).unwrap();
71 let valtree = const_to_valtree_inner(ecx, &place_elem, num_nodes)?;
72 elems.push(ty::Const::new_value(*ecx.tcx, valtree, place_elem.layout.ty));
73 }
74
75 Ok(ty::ValTree::from_branches(*ecx.tcx, elems))
76}
77
78#[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("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(78u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place",
"num_nodes"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&num_nodes as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:86",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(86u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("ty kind: {0:?}",
ty.kind()) as &dyn Value))])
});
} else { ; }
};
if *num_nodes >= VALTREE_MAX_NODES {
return Err(ValTreeCreationError::NodesOverflow);
}
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();
ensure_sufficient_stack(||
const_to_valtree_inner(ecx, &place, num_nodes))
}
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,
} {
return Err(ValTreeCreationError::NonSupportedType(ty));
}
let val = val.to_scalar();
let Ok(val) =
val.try_to_scalar_int() else {
return Err(ValTreeCreationError::NonSupportedType(ty));
};
Ok(ty::ValTree::from_scalar_int(tcx, val))
}
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)
}
ty::Str | ty::Slice(_) | ty::Array(_, _) => {
slice_branches(ecx, place, num_nodes)
}
ty::Dynamic(..) =>
Err(ValTreeCreationError::NonSupportedType(ty)),
ty::Tuple(elem_tys) => {
branches(ecx, place, elem_tys.len(), None, num_nodes)
}
ty::Adt(def, _) => {
if def.is_union() {
return Err(ValTreeCreationError::NonSupportedType(ty));
} else if def.variants().is_empty() {
::rustc_middle::util::bug::bug_fmt(format_args!("uninhabited types should have errored and never gotten converted to valtree"))
}
let variant = ecx.read_discriminant(place).report_err()?;
branches(ecx, place, def.variant(variant).fields.len(),
def.is_enum().then_some(variant), num_nodes)
}
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::UnsafeBinder(_) =>
Err(ValTreeCreationError::NonSupportedType(ty)),
}
}
}
}#[instrument(skip(ecx), level = "debug")]
79fn const_to_valtree_inner<'tcx>(
80 ecx: &CompileTimeInterpCx<'tcx>,
81 place: &MPlaceTy<'tcx>,
82 num_nodes: &mut usize,
83) -> EvalToValTreeResult<'tcx> {
84 let tcx = *ecx.tcx;
85 let ty = place.layout.ty;
86 debug!("ty kind: {:?}", ty.kind());
87
88 if *num_nodes >= VALTREE_MAX_NODES {
89 return Err(ValTreeCreationError::NodesOverflow);
90 }
91
92 match ty.kind() {
93 ty::FnDef(..) => {
94 *num_nodes += 1;
95 Ok(ty::ValTree::zst(tcx))
96 }
97 ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => {
98 let val = ecx.read_immediate(place).report_err()?;
99 let val = val.to_scalar_int().unwrap();
100 *num_nodes += 1;
101
102 Ok(ty::ValTree::from_scalar_int(tcx, val))
103 }
104
105 ty::Pat(base, ..) => {
106 let mut place = place.clone();
107 place.layout = ecx.layout_of(*base).unwrap();
111 ensure_sufficient_stack(|| const_to_valtree_inner(ecx, &place, num_nodes))
112 },
113
114
115 ty::RawPtr(_, _) => {
116 let val = ecx.read_immediate(place).report_err()?;
121 if matches!(val.layout.backend_repr, BackendRepr::ScalarPair(..)) {
124 return Err(ValTreeCreationError::NonSupportedType(ty));
125 }
126 let val = val.to_scalar();
127 let Ok(val) = val.try_to_scalar_int() else {
130 return Err(ValTreeCreationError::NonSupportedType(ty));
131 };
132 Ok(ty::ValTree::from_scalar_int(tcx, val))
134 }
135
136 ty::FnPtr(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
139
140 ty::Ref(_, _, _) => {
141 let derefd_place = ecx.deref_pointer(place).report_err()?;
142 const_to_valtree_inner(ecx, &derefd_place, num_nodes)
143 }
144
145 ty::Str | ty::Slice(_) | ty::Array(_, _) => {
146 slice_branches(ecx, place, num_nodes)
147 }
148 ty::Dynamic(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
153
154 ty::Tuple(elem_tys) => {
155 branches(ecx, place, elem_tys.len(), None, num_nodes)
156 }
157
158 ty::Adt(def, _) => {
159 if def.is_union() {
160 return Err(ValTreeCreationError::NonSupportedType(ty));
161 } else if def.variants().is_empty() {
162 bug!("uninhabited types should have errored and never gotten converted to valtree")
163 }
164
165 let variant = ecx.read_discriminant(place).report_err()?;
166 branches(ecx, place, def.variant(variant).fields.len(), def.is_enum().then_some(variant), num_nodes)
167 }
168
169 ty::Never
170 | ty::Error(_)
171 | ty::Foreign(..)
172 | ty::Infer(ty::FreshIntTy(_))
173 | ty::Infer(ty::FreshFloatTy(_))
174 | ty::Alias(..)
176 | ty::Param(_)
177 | ty::Bound(..)
178 | ty::Placeholder(..)
179 | ty::Infer(_)
180 | ty::Closure(..)
182 | ty::CoroutineClosure(..)
183 | ty::Coroutine(..)
184 | ty::CoroutineWitness(..)
185 | ty::UnsafeBinder(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
186 }
187}
188
189fn reconstruct_place_meta<'tcx>(
192 layout: TyAndLayout<'tcx>,
193 valtree: ty::ValTree<'tcx>,
194 tcx: TyCtxt<'tcx>,
195) -> MemPlaceMeta {
196 if layout.is_sized() {
197 return MemPlaceMeta::None;
198 }
199
200 let mut last_valtree = valtree;
201 let tail = tcx.struct_tail_raw(
203 layout.ty,
204 &ObligationCause::dummy(),
205 |ty| ty,
206 || {
207 let branches = last_valtree.to_branch();
208 last_valtree = branches.last().unwrap().to_value().valtree;
209 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/const_eval/valtrees.rs:209",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(209u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["branches",
"last_valtree"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&branches)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&last_valtree)
as &dyn Value))])
});
} else { ; }
};debug!(?branches, ?last_valtree);
210 },
211 );
212 match tail.kind() {
214 ty::Slice(..) | ty::Str => {}
215 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unsized tail of a valtree must be Slice or Str"))bug!("unsized tail of a valtree must be Slice or Str"),
216 };
217
218 let num_elems = last_valtree.to_branch().len();
220 MemPlaceMeta::Meta(Scalar::from_target_usize(num_elems as u64, &tcx))
221}
222
223x;#[instrument(skip(ecx), level = "debug", ret)]
224fn create_valtree_place<'tcx>(
225 ecx: &mut CompileTimeInterpCx<'tcx>,
226 layout: TyAndLayout<'tcx>,
227 valtree: ty::ValTree<'tcx>,
228) -> MPlaceTy<'tcx> {
229 let meta = reconstruct_place_meta(layout, valtree, ecx.tcx.tcx);
230 ecx.allocate_dyn(layout, MemoryKind::Stack, meta).unwrap()
231}
232
233pub(crate) fn eval_to_valtree<'tcx>(
235 tcx: TyCtxt<'tcx>,
236 typing_env: ty::TypingEnv<'tcx>,
237 cid: GlobalId<'tcx>,
238) -> EvalToValTreeResult<'tcx> {
239 if truecfg!(debug_assertions) {
240 match typing_env.typing_mode() {
241 ty::TypingMode::PostAnalysis => {}
242 ty::TypingMode::Coherence
243 | ty::TypingMode::Analysis { .. }
244 | ty::TypingMode::Borrowck { .. }
245 | ty::TypingMode::PostBorrowckAnalysis { .. } => {
246 ::rustc_middle::util::bug::bug_fmt(format_args!("Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details."))bug!(
247 "Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details."
248 )
249 }
250 }
251 }
252 let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(cid))?;
253
254 let ecx = mk_eval_cx_to_read_const_val(
256 tcx,
257 DUMMY_SP,
258 typing_env,
259 CanAccessMutGlobal::No,
262 );
263 let place = ecx.raw_const_to_mplace(const_alloc).unwrap();
264 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/const_eval/valtrees.rs:264",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(264u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&place) as
&dyn Value))])
});
} else { ; }
};debug!(?place);
265
266 let mut num_nodes = 0;
267 const_to_valtree_inner(&ecx, &place, &mut num_nodes)
268}
269
270x;#[instrument(skip(tcx), level = "debug", ret)]
274pub fn valtree_to_const_value<'tcx>(
275 tcx: TyCtxt<'tcx>,
276 typing_env: ty::TypingEnv<'tcx>,
277 cv: ty::Value<'tcx>,
278) -> mir::ConstValue {
279 match *cv.ty.kind() {
286 ty::FnDef(..) => {
287 assert!(cv.valtree.is_zst());
288 mir::ConstValue::ZeroSized
289 }
290 ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(_, _) => {
291 mir::ConstValue::Scalar(Scalar::Int(cv.to_leaf()))
292 }
293 ty::Pat(ty, _) => {
294 let cv = ty::Value { valtree: cv.valtree, ty };
295 valtree_to_const_value(tcx, typing_env, cv)
296 }
297 ty::Ref(_, inner_ty, _) => {
298 let mut ecx =
299 mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env, CanAccessMutGlobal::No);
300 let imm = valtree_to_ref(&mut ecx, cv.valtree, inner_ty);
301 let imm = ImmTy::from_immediate(
302 imm,
303 tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap(),
304 );
305 op_to_const(&ecx, &imm.into(), false)
306 }
307 ty::Tuple(_) | ty::Array(_, _) | ty::Adt(..) => {
308 let layout = tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap();
309 if layout.is_zst() {
310 return mir::ConstValue::ZeroSized;
312 }
313 if layout.backend_repr.is_scalar()
314 && (matches!(cv.ty.kind(), ty::Tuple(_))
315 || matches!(cv.ty.kind(), ty::Adt(def, _) if def.is_struct()))
316 {
317 let branches = cv.to_branch();
319 for (i, &inner_valtree) in branches.iter().enumerate() {
321 let field = layout.field(&LayoutCx::new(tcx, typing_env), i);
322 if !field.is_zst() {
323 let cv =
324 ty::Value { valtree: inner_valtree.to_value().valtree, ty: field.ty };
325 return valtree_to_const_value(tcx, typing_env, cv);
326 }
327 }
328 bug!("could not find non-ZST field during in {layout:#?}");
329 }
330
331 let mut ecx =
332 mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env, CanAccessMutGlobal::No);
333
334 let place = create_valtree_place(&mut ecx, layout, cv.valtree);
336
337 valtree_into_mplace(&mut ecx, &place, cv.valtree);
338 dump_place(&ecx, &place);
339 intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &place).unwrap();
340
341 op_to_const(&ecx, &place.into(), false)
342 }
343 ty::Never
344 | ty::Error(_)
345 | ty::Foreign(..)
346 | ty::Infer(ty::FreshIntTy(_))
347 | ty::Infer(ty::FreshFloatTy(_))
348 | ty::Alias(..)
349 | ty::Param(_)
350 | ty::Bound(..)
351 | ty::Placeholder(..)
352 | ty::Infer(_)
353 | ty::Closure(..)
354 | ty::CoroutineClosure(..)
355 | ty::Coroutine(..)
356 | ty::CoroutineWitness(..)
357 | ty::FnPtr(..)
358 | ty::Str
359 | ty::Slice(_)
360 | ty::Dynamic(..)
361 | ty::UnsafeBinder(_) => {
362 bug!("no ValTree should have been created for type {:?}", cv.ty.kind())
363 }
364 }
365}
366
367fn valtree_to_ref<'tcx>(
369 ecx: &mut CompileTimeInterpCx<'tcx>,
370 valtree: ty::ValTree<'tcx>,
371 pointee_ty: Ty<'tcx>,
372) -> Immediate {
373 let pointee_place = create_valtree_place(ecx, ecx.layout_of(pointee_ty).unwrap(), valtree);
374 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/const_eval/valtrees.rs:374",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(374u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["pointee_place"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&pointee_place)
as &dyn Value))])
});
} else { ; }
};debug!(?pointee_place);
375
376 valtree_into_mplace(ecx, &pointee_place, valtree);
377 dump_place(ecx, &pointee_place);
378 intern_const_alloc_recursive(ecx, InternKind::Constant, &pointee_place).unwrap();
379
380 pointee_place.to_ref(&ecx.tcx)
381}
382
383#[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("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(383u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place", "valtree"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&place)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&valtree)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:400",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(400u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("writing trivial valtree {0:?} to place {1:?}",
scalar_int, place) as &dyn 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:405",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(405u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["imm"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&imm) as
&dyn 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:418",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(418u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["variant"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&variant) as
&dyn 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:428",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(428u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place_adjusted",
"branches"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&place_adjusted)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&branches)
as &dyn 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:433",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(433u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["i",
"inner_valtree"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&i) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&inner_valtree)
as &dyn 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:442",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(442u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::valtrees"),
::tracing_core::field::FieldSet::new(&["place_inner"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&place_inner)
as &dyn 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 compiler/rustc_const_eval/src/const_eval/valtrees.rs:447",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(447u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("dump of place_adjusted:")
as &dyn 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 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("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(&["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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("dump of place after writing discriminant:")
as &dyn Value))])
});
} else { ; }
};
dump_place(ecx, place);
}
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("shouldn\'t have created a ValTree for {0:?}",
ty)),
}
}
}
}#[instrument(skip(ecx), level = "debug")]
384fn valtree_into_mplace<'tcx>(
385 ecx: &mut CompileTimeInterpCx<'tcx>,
386 place: &MPlaceTy<'tcx>,
387 valtree: ty::ValTree<'tcx>,
388) {
389 let ty = place.layout.ty;
393
394 match ty.kind() {
395 ty::FnDef(_, _) => {
396 }
398 ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(..) => {
399 let scalar_int = valtree.to_leaf();
400 debug!("writing trivial valtree {:?} to place {:?}", scalar_int, place);
401 ecx.write_immediate(Immediate::Scalar(scalar_int.into()), place).unwrap();
402 }
403 ty::Ref(_, inner_ty, _) => {
404 let imm = valtree_to_ref(ecx, valtree, *inner_ty);
405 debug!(?imm);
406 ecx.write_immediate(imm, place).unwrap();
407 }
408 ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Str | ty::Slice(_) => {
409 let branches = valtree.to_branch();
410
411 let (place_adjusted, branches, variant_idx) = match ty.kind() {
413 ty::Adt(def, _) if def.is_enum() => {
414 let scalar_int = branches[0].to_leaf();
416 let variant_idx = VariantIdx::from_u32(scalar_int.to_u32());
417 let variant = def.variant(variant_idx);
418 debug!(?variant);
419
420 (
421 ecx.project_downcast(place, variant_idx).unwrap(),
422 &branches[1..],
423 Some(variant_idx),
424 )
425 }
426 _ => (place.clone(), branches.as_slice(), None),
427 };
428 debug!(?place_adjusted, ?branches);
429
430 for (i, inner_valtree) in branches.iter().enumerate() {
433 debug!(?i, ?inner_valtree);
434
435 let place_inner = match ty.kind() {
436 ty::Str | ty::Slice(_) | ty::Array(..) => {
437 ecx.project_index(place, i as u64).unwrap()
438 }
439 _ => ecx.project_field(&place_adjusted, FieldIdx::from_usize(i)).unwrap(),
440 };
441
442 debug!(?place_inner);
443 valtree_into_mplace(ecx, &place_inner, inner_valtree.to_value().valtree);
444 dump_place(ecx, &place_inner);
445 }
446
447 debug!("dump of place_adjusted:");
448 dump_place(ecx, &place_adjusted);
449
450 if let Some(variant_idx) = variant_idx {
451 ecx.write_discriminant(variant_idx, place).unwrap();
453 }
454
455 debug!("dump of place after writing discriminant:");
456 dump_place(ecx, place);
457 }
458 _ => bug!("shouldn't have created a ValTree for {:?}", ty),
459 }
460}
461
462fn dump_place<'tcx>(ecx: &CompileTimeInterpCx<'tcx>, place: &MPlaceTy<'tcx>) {
463 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_const_eval/src/const_eval/valtrees.rs:463",
"rustc_const_eval::const_eval::valtrees",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/valtrees.rs"),
::tracing_core::__macro_support::Option::Some(463u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("{0:?}",
ecx.dump_place(&PlaceTy::from(place.clone()))) as
&dyn Value))])
});
} else { ; }
};trace!("{:?}", ecx.dump_place(&PlaceTy::from(place.clone())));
464}