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::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)),
}
}
}
}#[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 ty::RawPtr(_, _) => {
115 let val = ecx.read_immediate(place).report_err()?;
120 if matches!(val.layout.backend_repr, BackendRepr::ScalarPair(..)) {
123 return Err(ValTreeCreationError::NonSupportedType(ty));
124 }
125 let val = val.to_scalar();
126 let Ok(val) = val.try_to_scalar_int() else {
129 return Err(ValTreeCreationError::NonSupportedType(ty));
130 };
131 Ok(ty::ValTree::from_scalar_int(tcx, val))
133 }
134
135 ty::FnPtr(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
138
139 ty::Ref(_, _, _) => {
140 let derefd_place = ecx.deref_pointer(place).report_err()?;
141 const_to_valtree_inner(ecx, &derefd_place, num_nodes)
142 }
143
144 ty::Str | ty::Slice(_) | ty::Array(_, _) => slice_branches(ecx, place, num_nodes),
145 ty::Dynamic(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
150
151 ty::Tuple(elem_tys) => branches(ecx, place, elem_tys.len(), None, num_nodes),
152
153 ty::Adt(def, _) => {
154 if def.is_union() {
155 return Err(ValTreeCreationError::NonSupportedType(ty));
156 } else if def.variants().is_empty() {
157 bug!("uninhabited types should have errored and never gotten converted to valtree")
158 }
159
160 let variant = ecx.read_discriminant(place).report_err()?;
161 branches(
162 ecx,
163 place,
164 def.variant(variant).fields.len(),
165 def.is_enum().then_some(variant),
166 num_nodes,
167 )
168 }
169
170 ty::Alias(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
172
173 ty::Closure(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
175
176 ty::Never
177 | ty::Error(_)
178 | ty::Foreign(..)
179 | ty::Infer(ty::FreshIntTy(_))
180 | ty::Infer(ty::FreshFloatTy(_))
181 | ty::Param(_)
182 | ty::Bound(..)
183 | ty::Placeholder(..)
184 | ty::Infer(_)
185 | ty::CoroutineClosure(..)
186 | ty::Coroutine(..)
187 | ty::CoroutineWitness(..)
188 | ty::UnsafeBinder(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
189 }
190}
191
192fn reconstruct_place_meta<'tcx>(
195 layout: TyAndLayout<'tcx>,
196 valtree: ty::ValTree<'tcx>,
197 tcx: TyCtxt<'tcx>,
198) -> MemPlaceMeta {
199 if layout.is_sized() {
200 return MemPlaceMeta::None;
201 }
202
203 let mut last_valtree = valtree;
204 let tail = tcx.struct_tail_raw(
208 layout.ty,
209 &ObligationCause::dummy(),
210 |ty| ty.skip_norm_wip(),
211 || {
212 let branches = last_valtree.to_branch();
213 last_valtree = branches.last().unwrap().to_value().valtree;
214 {
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:214",
"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(214u32),
::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);
215 },
216 );
217 match tail.kind() {
219 ty::Slice(..) | ty::Str => {}
220 _ => ::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"),
221 };
222
223 let num_elems = last_valtree.to_branch().len();
225 MemPlaceMeta::Meta(Scalar::from_target_usize(num_elems as u64, &tcx))
226}
227
228x;#[instrument(skip(ecx), level = "debug", ret)]
229fn create_valtree_place<'tcx>(
230 ecx: &mut CompileTimeInterpCx<'tcx>,
231 layout: TyAndLayout<'tcx>,
232 valtree: ty::ValTree<'tcx>,
233) -> MPlaceTy<'tcx> {
234 let meta = reconstruct_place_meta(layout, valtree, ecx.tcx.tcx);
235 ecx.allocate_dyn(layout, MemoryKind::Stack, meta).unwrap()
236}
237
238pub(crate) fn eval_to_valtree<'tcx>(
240 tcx: TyCtxt<'tcx>,
241 typing_env: ty::TypingEnv<'tcx>,
242 cid: GlobalId<'tcx>,
243) -> EvalToValTreeResult<'tcx> {
244 if truecfg!(debug_assertions) {
245 match typing_env.typing_mode().assert_not_erased() {
246 ty::TypingMode::PostAnalysis => {}
247 ty::TypingMode::Coherence
248 | ty::TypingMode::Analysis { .. }
249 | ty::TypingMode::Borrowck { .. }
250 | ty::TypingMode::PostBorrowckAnalysis { .. } => {
251 ::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!(
252 "Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details."
253 )
254 }
255 }
256 }
257 let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(cid))?;
258
259 let ecx = mk_eval_cx_to_read_const_val(
261 tcx,
262 DUMMY_SP,
263 typing_env,
264 CanAccessMutGlobal::No,
267 );
268 let place = ecx.raw_const_to_mplace(const_alloc).unwrap();
269 {
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:269",
"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(269u32),
::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);
270
271 let mut num_nodes = 0;
272 const_to_valtree_inner(&ecx, &place, &mut num_nodes)
273}
274
275x;#[instrument(skip(tcx), level = "debug", ret)]
279pub fn valtree_to_const_value<'tcx>(
280 tcx: TyCtxt<'tcx>,
281 typing_env: ty::TypingEnv<'tcx>,
282 cv: ty::Value<'tcx>,
283) -> mir::ConstValue {
284 match *cv.ty.kind() {
291 ty::FnDef(..) => {
292 assert!(cv.valtree.is_zst());
293 mir::ConstValue::ZeroSized
294 }
295 ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(_, _) => {
296 mir::ConstValue::Scalar(Scalar::Int(cv.to_leaf()))
297 }
298 ty::Pat(ty, _) => {
299 let cv = ty::Value { valtree: cv.valtree, ty };
300 valtree_to_const_value(tcx, typing_env, cv)
301 }
302 ty::Ref(_, inner_ty, _) => {
303 let mut ecx =
304 mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env, CanAccessMutGlobal::No);
305 let imm = valtree_to_ref(&mut ecx, cv.valtree, inner_ty);
306 let imm = ImmTy::from_immediate(
307 imm,
308 tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap(),
309 );
310 op_to_const(&ecx, &imm.into(), false)
311 }
312 ty::Tuple(_) | ty::Array(_, _) | ty::Adt(..) => {
313 let layout = tcx.layout_of(typing_env.as_query_input(cv.ty)).unwrap();
314 if layout.is_zst() {
315 return mir::ConstValue::ZeroSized;
317 }
318 if layout.backend_repr.is_scalar()
319 && (matches!(cv.ty.kind(), ty::Tuple(_))
320 || matches!(cv.ty.kind(), ty::Adt(def, _) if def.is_struct()))
321 {
322 let branches = cv.to_branch();
324 for (i, &inner_valtree) in branches.iter().enumerate() {
326 let field = layout.field(&LayoutCx::new(tcx, typing_env), i);
327 if !field.is_zst() {
328 let cv =
329 ty::Value { valtree: inner_valtree.to_value().valtree, ty: field.ty };
330 return valtree_to_const_value(tcx, typing_env, cv);
331 }
332 }
333 bug!("could not find non-ZST field during in {layout:#?}");
334 }
335
336 let mut ecx =
337 mk_eval_cx_to_read_const_val(tcx, DUMMY_SP, typing_env, CanAccessMutGlobal::No);
338
339 let place = create_valtree_place(&mut ecx, layout, cv.valtree);
341
342 valtree_into_mplace(&mut ecx, &place, cv.valtree);
343 dump_place(&ecx, &place);
344 intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &place).unwrap();
345
346 op_to_const(&ecx, &place.into(), false)
347 }
348 ty::Never
349 | ty::Error(_)
350 | ty::Foreign(..)
351 | ty::Infer(ty::FreshIntTy(_))
352 | ty::Infer(ty::FreshFloatTy(_))
353 | ty::Alias(..)
354 | ty::Param(_)
355 | ty::Bound(..)
356 | ty::Placeholder(..)
357 | ty::Infer(_)
358 | ty::Closure(..)
359 | ty::CoroutineClosure(..)
360 | ty::Coroutine(..)
361 | ty::CoroutineWitness(..)
362 | ty::FnPtr(..)
363 | ty::Str
364 | ty::Slice(_)
365 | ty::Dynamic(..)
366 | ty::UnsafeBinder(_) => {
367 bug!("no ValTree should have been created for type {:?}", cv.ty.kind())
368 }
369 }
370}
371
372fn valtree_to_ref<'tcx>(
374 ecx: &mut CompileTimeInterpCx<'tcx>,
375 valtree: ty::ValTree<'tcx>,
376 pointee_ty: Ty<'tcx>,
377) -> Immediate {
378 let pointee_place = create_valtree_place(ecx, ecx.layout_of(pointee_ty).unwrap(), valtree);
379 {
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:379",
"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(379u32),
::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);
380
381 valtree_into_mplace(ecx, &pointee_place, valtree);
382 dump_place(ecx, &pointee_place);
383 intern_const_alloc_recursive(ecx, InternKind::Constant, &pointee_place).unwrap();
384
385 pointee_place.to_ref(&ecx.tcx)
386}
387
388#[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(388u32),
::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: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(&["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:410",
"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(410u32),
::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:423",
"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(423u32),
::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: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(&["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:438",
"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(438u32),
::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: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(&["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:452",
"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(452u32),
::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:460",
"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(460u32),
::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")]
389fn valtree_into_mplace<'tcx>(
390 ecx: &mut CompileTimeInterpCx<'tcx>,
391 place: &MPlaceTy<'tcx>,
392 valtree: ty::ValTree<'tcx>,
393) {
394 let ty = place.layout.ty;
398
399 match ty.kind() {
400 ty::FnDef(_, _) => {
401 }
403 ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(..) => {
404 let scalar_int = valtree.to_leaf();
405 debug!("writing trivial valtree {:?} to place {:?}", scalar_int, place);
406 ecx.write_immediate(Immediate::Scalar(scalar_int.into()), place).unwrap();
407 }
408 ty::Ref(_, inner_ty, _) => {
409 let imm = valtree_to_ref(ecx, valtree, *inner_ty);
410 debug!(?imm);
411 ecx.write_immediate(imm, place).unwrap();
412 }
413 ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Str | ty::Slice(_) => {
414 let branches = valtree.to_branch();
415
416 let (place_adjusted, branches, variant_idx) = match ty.kind() {
418 ty::Adt(def, _) if def.is_enum() => {
419 let scalar_int = branches[0].to_leaf();
421 let variant_idx = VariantIdx::from_u32(scalar_int.to_u32());
422 let variant = def.variant(variant_idx);
423 debug!(?variant);
424
425 (
426 ecx.project_downcast(place, variant_idx).unwrap(),
427 &branches[1..],
428 Some(variant_idx),
429 )
430 }
431 _ => (place.clone(), branches.as_slice(), None),
432 };
433 debug!(?place_adjusted, ?branches);
434
435 for (i, inner_valtree) in branches.iter().enumerate() {
438 debug!(?i, ?inner_valtree);
439
440 let place_inner = match ty.kind() {
441 ty::Str | ty::Slice(_) | ty::Array(..) => {
442 ecx.project_index(place, i as u64).unwrap()
443 }
444 _ => ecx.project_field(&place_adjusted, FieldIdx::from_usize(i)).unwrap(),
445 };
446
447 debug!(?place_inner);
448 valtree_into_mplace(ecx, &place_inner, inner_valtree.to_value().valtree);
449 dump_place(ecx, &place_inner);
450 }
451
452 debug!("dump of place_adjusted:");
453 dump_place(ecx, &place_adjusted);
454
455 if let Some(variant_idx) = variant_idx {
456 ecx.write_discriminant(variant_idx, place).unwrap();
458 }
459
460 debug!("dump of place after writing discriminant:");
461 dump_place(ecx, place);
462 }
463 _ => bug!("shouldn't have created a ValTree for {:?}", ty),
464 }
465}
466
467fn dump_place<'tcx>(ecx: &CompileTimeInterpCx<'tcx>, place: &MPlaceTy<'tcx>) {
468 {
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:468",
"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(468u32),
::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())));
469}