1use std::borrow::{Borrow, Cow};
2use std::hash::Hash;
3use std::{fmt, mem};
4
5use rustc_abi::{Align, FIRST_VARIANT, FieldIdx, Size, VariantIdx};
6use rustc_ast::Mutability;
7use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
8use rustc_hir::def_id::{DefId, LocalDefId};
9use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem, find_attr};
10use rustc_middle::mir::AssertMessage;
11use rustc_middle::mir::interpret::ReportedErrorInfo;
12use rustc_middle::query::TyCtxtAt;
13use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout, ValidityRequirement};
14use rustc_middle::ty::{self, FieldInfo, ScalarInt, Ty, TyCtxt};
15use rustc_middle::{bug, mir, span_bug};
16use rustc_span::{Span, Symbol, sym};
17use rustc_target::callconv::FnAbi;
18use tracing::debug;
19
20use super::error::*;
21use crate::diagnostics::{LongRunning, LongRunningWarn};
22use crate::interpret::{
23 self, AllocId, AllocInit, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame,
24 GlobalAlloc, ImmTy, InterpCx, InterpResult, OpTy, PlaceTy, Pointer, RangeSet, RetagMode,
25 Scalar, compile_time_machine, ensure_monomorphic_enough, err_inval, interp_ok, throw_exhaust,
26 throw_inval, throw_ub, throw_ub_format, throw_unsup, throw_unsup_format,
27 type_implements_dyn_trait,
28};
29
30const LINT_TERMINATOR_LIMIT: usize = 2_000_000;
34const TINY_LINT_TERMINATOR_LIMIT: usize = 20;
37const PROGRESS_INDICATOR_START: usize = 4_000_000;
40
41pub struct CompileTimeMachine<'tcx> {
46 pub(super) num_evaluated_steps: usize,
51
52 pub(super) stack: Vec<Frame<'tcx>>,
54
55 pub(super) can_access_mut_global: CanAccessMutGlobal,
59
60 pub(super) check_alignment: CheckAlignment,
62
63 pub(crate) static_root_ids: Option<(AllocId, LocalDefId)>,
67
68 union_data_ranges: FxHashMap<Ty<'tcx>, RangeSet>,
70
71 retag_mode: RetagMode,
73}
74
75#[derive(#[automatically_derived]
impl ::core::marker::Copy for CheckAlignment { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CheckAlignment {
#[inline]
fn clone(&self) -> CheckAlignment { *self }
}Clone)]
76pub enum CheckAlignment {
77 No,
80 Error,
82}
83
84#[derive(#[automatically_derived]
impl ::core::marker::Copy for CanAccessMutGlobal { }Copy, #[automatically_derived]
impl ::core::clone::Clone for CanAccessMutGlobal {
#[inline]
fn clone(&self) -> CanAccessMutGlobal { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for CanAccessMutGlobal {
#[inline]
fn eq(&self, other: &CanAccessMutGlobal) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq)]
85pub(crate) enum CanAccessMutGlobal {
86 No,
87 Yes,
88}
89
90impl From<bool> for CanAccessMutGlobal {
91 fn from(value: bool) -> Self {
92 if value { Self::Yes } else { Self::No }
93 }
94}
95
96impl<'tcx> CompileTimeMachine<'tcx> {
97 pub(crate) fn new(
98 can_access_mut_global: CanAccessMutGlobal,
99 check_alignment: CheckAlignment,
100 ) -> Self {
101 CompileTimeMachine {
102 num_evaluated_steps: 0,
103 stack: Vec::new(),
104 can_access_mut_global,
105 check_alignment,
106 static_root_ids: None,
107 union_data_ranges: FxHashMap::default(),
108 retag_mode: RetagMode::Default,
109 }
110 }
111}
112
113impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxIndexMap<K, V> {
114 #[inline(always)]
115 fn contains_key<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> bool
116 where
117 K: Borrow<Q>,
118 {
119 FxIndexMap::contains_key(self, k)
120 }
121
122 #[inline(always)]
123 fn contains_key_ref<Q: ?Sized + Hash + Eq>(&self, k: &Q) -> bool
124 where
125 K: Borrow<Q>,
126 {
127 FxIndexMap::contains_key(self, k)
128 }
129
130 #[inline(always)]
131 fn insert(&mut self, k: K, v: V) -> Option<V> {
132 FxIndexMap::insert(self, k, v)
133 }
134
135 #[inline(always)]
136 fn remove<Q: ?Sized + Hash + Eq>(&mut self, k: &Q) -> Option<V>
137 where
138 K: Borrow<Q>,
139 {
140 FxIndexMap::swap_remove(self, k)
142 }
143
144 #[inline(always)]
145 fn filter_map_collect<T>(&self, mut f: impl FnMut(&K, &V) -> Option<T>) -> Vec<T> {
146 self.iter().filter_map(move |(k, v)| f(k, v)).collect()
147 }
148
149 #[inline(always)]
150 fn get_or<E>(&self, k: K, vacant: impl FnOnce() -> Result<V, E>) -> Result<&V, E> {
151 match self.get(&k) {
152 Some(v) => Ok(v),
153 None => {
154 vacant()?;
155 ::rustc_middle::util::bug::bug_fmt(format_args!("The CTFE machine shouldn\'t ever need to extend the alloc_map when reading"))bug!("The CTFE machine shouldn't ever need to extend the alloc_map when reading")
156 }
157 }
158 }
159
160 #[inline(always)]
161 fn get_mut_or<E>(&mut self, k: K, vacant: impl FnOnce() -> Result<V, E>) -> Result<&mut V, E> {
162 match self.entry(k) {
163 IndexEntry::Occupied(e) => Ok(e.into_mut()),
164 IndexEntry::Vacant(e) => {
165 let v = vacant()?;
166 Ok(e.insert(v))
167 }
168 }
169 }
170}
171
172pub type CompileTimeInterpCx<'tcx> = InterpCx<'tcx, CompileTimeMachine<'tcx>>;
173
174#[derive(#[automatically_derived]
impl ::core::fmt::Debug for MemoryKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
MemoryKind::Heap { was_made_global: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Heap",
"was_made_global", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for MemoryKind {
#[inline]
fn eq(&self, other: &MemoryKind) -> bool {
match (self, other) {
(MemoryKind::Heap { was_made_global: __self_0 },
MemoryKind::Heap { was_made_global: __arg1_0 }) =>
__self_0 == __arg1_0,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for MemoryKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for MemoryKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for MemoryKind {
#[inline]
fn clone(&self) -> MemoryKind {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone)]
175pub enum MemoryKind {
176 Heap {
177 was_made_global: bool,
180 },
181}
182
183impl fmt::Display for MemoryKind {
184 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
185 match self {
186 MemoryKind::Heap { was_made_global } => {
187 f.write_fmt(format_args!("heap allocation{0}",
if *was_made_global { " (made global)" } else { "" }))write!(f, "heap allocation{}", if *was_made_global { " (made global)" } else { "" })
188 }
189 }
190 }
191}
192
193impl interpret::MayLeak for MemoryKind {
194 #[inline(always)]
195 fn may_leak(self) -> bool {
196 match self {
197 MemoryKind::Heap { was_made_global } => was_made_global,
198 }
199 }
200}
201
202impl interpret::MayLeak for ! {
203 #[inline(always)]
204 fn may_leak(self) -> bool {
205 self
207 }
208}
209
210impl<'tcx> CompileTimeInterpCx<'tcx> {
211 fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
212 let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
213 let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
214
215 use rustc_span::RemapPathScopeComponents;
216 (
217 Symbol::intern(
218 &caller.file.name.display(RemapPathScopeComponents::DIAGNOSTICS).to_string_lossy(),
219 ),
220 u32::try_from(caller.line).unwrap(),
221 u32::try_from(caller.col_display).unwrap().checked_add(1).unwrap(),
222 )
223 }
224
225 fn hook_special_const_fn(
231 &mut self,
232 instance: ty::Instance<'tcx>,
233 args: &[FnArg<'tcx>],
234 _dest: &PlaceTy<'tcx>,
235 _ret: Option<mir::BasicBlock>,
236 ) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
237 let def_id = instance.def_id();
238
239 if self.tcx.is_lang_item(def_id, LangItem::PanicDisplay)
240 || self.tcx.is_lang_item(def_id, LangItem::BeginPanic)
241 {
242 let args = Self::copy_fn_args(args);
243 if !(args.len() == 1) {
::core::panicking::panic("assertion failed: args.len() == 1")
};assert!(args.len() == 1);
245
246 let mut msg_place = self.deref_pointer(&args[0])?;
247 while msg_place.layout.ty.is_ref() {
248 msg_place = self.deref_pointer(&msg_place)?;
249 }
250
251 let msg = Symbol::intern(self.read_str(&msg_place)?);
252 let span = self.find_closest_untracked_caller_location();
253 let (file, line, col) = self.location_triple_for_span(span);
254 return Err(ConstEvalErrKind::Panic { msg, file, line, col }).into();
255 } else if self.tcx.is_lang_item(def_id, LangItem::PanicFmt) {
256 let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, self.tcx.span);
258 let new_instance = ty::Instance::expect_resolve(
259 *self.tcx,
260 self.typing_env(),
261 const_def_id,
262 instance.args,
263 self.cur_span(),
264 );
265
266 return interp_ok(Some(new_instance));
267 }
268 interp_ok(Some(instance))
269 }
270
271 fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8> {
279 interp_ok(match (a, b) {
280 (Scalar::Int(a), Scalar::Int(b)) => (a == b) as u8,
282 (Scalar::Int(int), Scalar::Ptr(ptr, _)) | (Scalar::Ptr(ptr, _), Scalar::Int(int)) => {
285 let int = int.to_target_usize(*self.tcx);
286 let offset_ptr = ptr.wrapping_offset(Size::from_bytes(int.wrapping_neg()), self);
289 if !self.scalar_may_be_null(Scalar::from_pointer(offset_ptr, self))? {
290 0
292 } else {
293 2
296 }
297 }
298 (Scalar::Ptr(a, _), Scalar::Ptr(b, _)) => {
299 let (a_prov, a_offset) = a.prov_and_relative_offset();
300 let (b_prov, b_offset) = b.prov_and_relative_offset();
301 let a_allocid = a_prov.alloc_id();
302 let b_allocid = b_prov.alloc_id();
303 let a_info = self.get_alloc_info(a_allocid);
304 let b_info = self.get_alloc_info(b_allocid);
305
306 if a_info.align > Align::ONE && b_info.align > Align::ONE {
308 let min_align = Ord::min(a_info.align.bytes(), b_info.align.bytes());
309 let a_residue = a_offset.bytes() % min_align;
310 let b_residue = b_offset.bytes() % min_align;
311 if a_residue != b_residue {
312 return interp_ok(0);
315 }
316 }
319
320 if let (Some(GlobalAlloc::Static(a_did)), Some(GlobalAlloc::Static(b_did))) = (
321 self.tcx.try_get_global_alloc(a_allocid),
322 self.tcx.try_get_global_alloc(b_allocid),
323 ) {
324 if a_allocid == b_allocid {
325 if true {
{
match (&a_did, &b_did) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("different static item DefIds had same AllocId? {0:?} == {1:?}, {2:?} != {3:?}",
a_allocid, b_allocid, a_did, b_did)));
}
}
}
};
};debug_assert_eq!(
326 a_did, b_did,
327 "different static item DefIds had same AllocId? {a_allocid:?} == {b_allocid:?}, {a_did:?} != {b_did:?}"
328 );
329 (a_offset == b_offset) as u8
334 } else {
335 if true {
{
match (&(a_did), &(b_did)) {
(left_val, right_val) => {
if *left_val == *right_val {
let kind = ::core::panicking::AssertKind::Ne;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val,
::core::option::Option::Some(format_args!("same static item DefId had two different AllocIds? {0:?} != {1:?}, {2:?} == {3:?}",
a_allocid, b_allocid, a_did, b_did)));
}
}
}
};
};debug_assert_ne!(
336 a_did, b_did,
337 "same static item DefId had two different AllocIds? {a_allocid:?} != {b_allocid:?}, {a_did:?} == {b_did:?}"
338 );
339 if a_offset < a_info.size && b_offset < b_info.size {
350 0
351 } else {
352 2
358 }
359 }
360 } else {
361 2
384 }
385 }
386 })
387 }
388}
389
390impl<'tcx> CompileTimeMachine<'tcx> {
391 #[inline(always)]
392 pub fn best_lint_scope(&self, tcx: TyCtxt<'tcx>) -> hir::HirId {
395 self.stack.iter().find_map(|frame| frame.lint_root(tcx)).unwrap_or(CRATE_HIR_ID)
396 }
397}
398
399impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
400 type Provenance = CtfeProvenance;
type ProvenanceExtra = bool;
type ExtraFnVal = !;
type MemoryKind = crate::const_eval::MemoryKind;
type MemoryMap =
rustc_data_structures::fx::FxIndexMap<AllocId,
(MemoryKind<Self::MemoryKind>, Allocation)>;
const GLOBAL_KIND: Option<Self::MemoryKind> = None;
type AllocExtra = ();
type FrameExtra = ();
type Bytes = Box<[u8]>;
#[inline(always)]
fn ignore_optional_overflow_checks(_ecx: &InterpCx<'tcx, Self>) -> bool {
false
}
#[inline(always)]
fn unwind_terminate(_ecx: &mut InterpCx<'tcx, Self>,
_reason: mir::UnwindTerminateReason) -> InterpResult<'tcx> {
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unwinding cannot happen during compile-time evaluation")));
}
}
#[inline(always)]
fn check_fn_target_features(_ecx: &InterpCx<'tcx, Self>,
_instance: ty::Instance<'tcx>) -> InterpResult<'tcx> {
interp_ok(())
}
#[inline(always)]
fn call_extra_fn(_ecx: &mut InterpCx<'tcx, Self>, fn_val: !,
_abi: &FnAbi<'tcx, Ty<'tcx>>, _args: &[FnArg<'tcx>],
_destination: &PlaceTy<'tcx, Self::Provenance>,
_target: Option<mir::BasicBlock>, _unwind: mir::UnwindAction)
-> InterpResult<'tcx> {
match fn_val {}
}
#[inline(always)]
fn float_fuse_mul_add(_ecx: &InterpCx<'tcx, Self>) -> bool { true }
#[inline(always)]
fn adjust_global_allocation<'b>(_ecx: &InterpCx<'tcx, Self>, _id: AllocId,
alloc: &'b Allocation)
-> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance>>> {
interp_ok(Cow::Borrowed(alloc))
}
fn init_local_allocation(_ecx: &InterpCx<'tcx, Self>, _id: AllocId,
_kind: MemoryKind<Self::MemoryKind>, _size: Size, _align: Align)
-> InterpResult<'tcx, Self::AllocExtra> {
interp_ok(())
}
fn extern_static_pointer(ecx: &InterpCx<'tcx, Self>, def_id: DefId)
-> InterpResult<'tcx, Pointer> {
interp_ok(Pointer::new(ecx.tcx.reserve_and_set_static_alloc(def_id).into(),
Size::ZERO))
}
#[inline(always)]
fn adjust_alloc_root_pointer(_ecx: &InterpCx<'tcx, Self>,
ptr: Pointer<CtfeProvenance>, _kind: Option<MemoryKind<Self::MemoryKind>>)
-> InterpResult<'tcx, Pointer<CtfeProvenance>> {
interp_ok(ptr)
}
#[inline(always)]
fn ptr_from_addr_cast(_ecx: &InterpCx<'tcx, Self>, addr: u64)
-> InterpResult<'tcx, Pointer<Option<CtfeProvenance>>> {
interp_ok(Pointer::without_provenance(addr))
}
#[inline(always)]
fn ptr_get_alloc(_ecx: &InterpCx<'tcx, Self>, ptr: Pointer<CtfeProvenance>,
_size: i64) -> Option<(AllocId, Size, Self::ProvenanceExtra)> {
let (prov, offset) = ptr.prov_and_relative_offset();
Some((prov.alloc_id(), offset, prov.immutable()))
}
#[inline(always)]
fn get_global_alloc_salt(_ecx: &InterpCx<'tcx, Self>,
_instance: Option<ty::Instance<'tcx>>) -> usize {
CTFE_ALLOC_SALT
}compile_time_machine!(<'tcx>);
401
402 const PANIC_ON_ALLOC_FAIL: bool = false; #[inline(always)]
405 fn enforce_alignment(ecx: &InterpCx<'tcx, Self>) -> bool {
406 #[allow(non_exhaustive_omitted_patterns)] match ecx.machine.check_alignment {
CheckAlignment::Error => true,
_ => false,
}matches!(ecx.machine.check_alignment, CheckAlignment::Error)
407 }
408
409 #[inline(always)]
410 fn enforce_validity(ecx: &InterpCx<'tcx, Self>, layout: TyAndLayout<'tcx>) -> bool {
411 ecx.tcx.sess.opts.unstable_opts.extra_const_ub_checks || layout.is_uninhabited()
412 }
413
414 fn load_mir(
415 ecx: &InterpCx<'tcx, Self>,
416 instance: ty::InstanceKind<'tcx>,
417 ) -> &'tcx mir::Body<'tcx> {
418 match instance {
419 ty::InstanceKind::Item(def) => ecx.tcx.mir_for_ctfe(def),
420 _ => ecx.tcx.instance_mir(instance),
421 }
422 }
423
424 fn find_mir_or_eval_fn(
425 ecx: &mut InterpCx<'tcx, Self>,
426 orig_instance: ty::Instance<'tcx>,
427 _abi: &FnAbi<'tcx, Ty<'tcx>>,
428 args: &[FnArg<'tcx>],
429 dest: &PlaceTy<'tcx>,
430 ret: Option<mir::BasicBlock>,
431 _unwind: mir::UnwindAction, ) -> InterpResult<'tcx, Option<(&'tcx mir::Body<'tcx>, ty::Instance<'tcx>)>> {
433 {
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/machine.rs:433",
"rustc_const_eval::const_eval::machine",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_const_eval/src/const_eval/machine.rs"),
::tracing_core::__macro_support::Option::Some(433u32),
::tracing_core::__macro_support::Option::Some("rustc_const_eval::const_eval::machine"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("find_mir_or_eval_fn: {0:?}",
orig_instance) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("find_mir_or_eval_fn: {:?}", orig_instance);
434
435 let Some(instance) = ecx.hook_special_const_fn(orig_instance, args, dest, ret)? else {
437 return interp_ok(None);
439 };
440
441 if let ty::InstanceKind::Item(def) = instance.def {
443 if !ecx.tcx.is_const_fn(def) || {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def, &ecx.tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcDoNotConstCheck) => {
break 'done Some(());
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some()find_attr!(ecx.tcx, def, RustcDoNotConstCheck) {
448 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::Unsupported(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("calling non-const function `{0}`",
instance))
})))throw_unsup_format!("calling non-const function `{}`", instance)
451 }
452 }
453
454 interp_ok(Some((ecx.load_mir(instance.def, None)?, orig_instance)))
458 }
459
460 fn panic_nounwind(ecx: &mut InterpCx<'tcx, Self>, msg: &str) -> InterpResult<'tcx> {
461 let msg = Symbol::intern(msg);
462 let span = ecx.find_closest_untracked_caller_location();
463 let (file, line, col) = ecx.location_triple_for_span(span);
464 Err(ConstEvalErrKind::Panic { msg, file, line, col }).into()
465 }
466
467 fn call_intrinsic(
468 ecx: &mut InterpCx<'tcx, Self>,
469 instance: ty::Instance<'tcx>,
470 args: &[OpTy<'tcx>],
471 dest: &PlaceTy<'tcx, Self::Provenance>,
472 target: Option<mir::BasicBlock>,
473 _unwind: mir::UnwindAction,
474 ) -> InterpResult<'tcx, Option<ty::Instance<'tcx>>> {
475 if ecx.eval_intrinsic(instance, args, dest, target)? {
477 return interp_ok(None);
478 }
479 let intrinsic_name = ecx.tcx.item_name(instance.def_id());
480
481 match intrinsic_name {
483 sym::ptr_guaranteed_cmp => {
484 let a = ecx.read_scalar(&args[0])?;
485 let b = ecx.read_scalar(&args[1])?;
486 let cmp = ecx.guaranteed_cmp(a, b)?;
487 ecx.write_scalar(Scalar::from_u8(cmp), dest)?;
488 }
489 sym::const_allocate => {
490 let size = ecx.read_scalar(&args[0])?.to_target_usize(ecx)?;
491 let align = ecx.read_scalar(&args[1])?.to_target_usize(ecx)?;
492
493 let align = match Align::from_bytes(align) {
494 Ok(a) => a,
495 Err(err) => {
496 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("invalid align passed to `const_allocate`: {0}",
err))
})))throw_ub_format!("invalid align passed to `const_allocate`: {err}")
497 }
498 };
499
500 let ptr = ecx.allocate_ptr(
501 Size::from_bytes(size),
502 align,
503 interpret::MemoryKind::Machine(MemoryKind::Heap { was_made_global: false }),
504 AllocInit::Uninit,
505 )?;
506 ecx.write_pointer(ptr, dest)?;
507 }
508 sym::const_deallocate => {
509 let ptr = ecx.read_pointer(&args[0])?;
510 let size = ecx.read_scalar(&args[1])?.to_target_usize(ecx)?;
511 let align = ecx.read_scalar(&args[2])?.to_target_usize(ecx)?;
512
513 let size = Size::from_bytes(size);
514 let align = match Align::from_bytes(align) {
515 Ok(a) => a,
516 Err(err) => {
517 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::Ub(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("invalid align passed to `const_deallocate`: {0}",
err))
})))throw_ub_format!("invalid align passed to `const_deallocate`: {err}")
518 }
519 };
520
521 let (alloc_id, _, _) = ecx.ptr_get_alloc_id(ptr, 0)?;
524 let is_allocated_in_another_const = #[allow(non_exhaustive_omitted_patterns)] match ecx.tcx.try_get_global_alloc(alloc_id)
{
Some(interpret::GlobalAlloc::Memory(_)) => true,
_ => false,
}matches!(
525 ecx.tcx.try_get_global_alloc(alloc_id),
526 Some(interpret::GlobalAlloc::Memory(_))
527 );
528
529 if !is_allocated_in_another_const {
530 ecx.deallocate_ptr(
531 ptr,
532 Some((size, align)),
533 interpret::MemoryKind::Machine(MemoryKind::Heap { was_made_global: false }),
534 )?;
535 }
536 }
537
538 sym::const_make_global => {
539 let ptr = ecx.read_pointer(&args[0])?;
540 ecx.make_const_heap_ptr_global(ptr)?;
541 ecx.write_pointer(ptr, dest)?;
542 }
543
544 sym::is_val_statically_known => ecx.write_scalar(Scalar::from_bool(false), dest)?,
549
550 sym::assert_inhabited
552 | sym::assert_zero_valid
553 | sym::assert_mem_uninitialized_valid => {
554 let ty = instance.args.type_at(0);
555 let requirement = ValidityRequirement::from_intrinsic(intrinsic_name).unwrap();
556
557 let should_panic = !ecx
558 .tcx
559 .check_validity_requirement((requirement, ecx.typing_env().as_query_input(ty)))
560 .map_err(|_| ::rustc_middle::mir::interpret::InterpErrorKind::InvalidProgram(::rustc_middle::mir::interpret::InvalidProgramInfo::TooGeneric)err_inval!(TooGeneric))?;
561
562 if should_panic {
563 let layout = ecx.layout_of(ty)?;
564
565 let msg = match requirement {
566 _ if layout.is_uninhabited() => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("aborted execution: attempted to instantiate uninhabited type `{0}`",
ty))
})format!(
569 "aborted execution: attempted to instantiate uninhabited type `{ty}`"
570 ),
571 ValidityRequirement::Inhabited => ::rustc_middle::util::bug::bug_fmt(format_args!("handled earlier"))bug!("handled earlier"),
572 ValidityRequirement::Zero => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("aborted execution: attempted to zero-initialize type `{0}`, which is invalid",
ty))
})format!(
573 "aborted execution: attempted to zero-initialize type `{ty}`, which is invalid"
574 ),
575 ValidityRequirement::UninitMitigated0x01Fill => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("aborted execution: attempted to leave type `{0}` uninitialized, which is invalid",
ty))
})format!(
576 "aborted execution: attempted to leave type `{ty}` uninitialized, which is invalid"
577 ),
578 ValidityRequirement::Uninit => ::rustc_middle::util::bug::bug_fmt(format_args!("assert_uninit_valid doesn\'t exist"))bug!("assert_uninit_valid doesn't exist"),
579 };
580
581 Self::panic_nounwind(ecx, &msg)?;
582 return interp_ok(None);
584 }
585 }
586
587 sym::type_id_vtable => {
588 let tp_ty = ecx.read_type_id(&args[0])?;
589 let result_ty = ecx.read_type_id(&args[1])?;
590
591 let (implements_trait, preds) = type_implements_dyn_trait(ecx, tp_ty, result_ty)?;
592
593 if implements_trait {
594 let vtable_ptr = ecx.get_vtable_ptr(tp_ty, preds)?;
595 ecx.write_pointer(vtable_ptr, dest)?;
597 } else {
598 ecx.write_discriminant(FIRST_VARIANT, dest)?;
600 }
601 }
602
603 sym::type_of => {
604 let ty = ecx.read_type_id(&args[0])?;
605 ecx.write_type_info(ty, dest)?;
606 }
607
608 sym::size_of_type_id => {
609 let ty = ecx.read_type_id(&args[0])?;
610 let layout = ecx.layout_of(ty)?;
611 let variant_index = if layout.is_sized() {
612 let (variant, variant_place) = ecx.project_downcast_named(dest, sym::Some)?;
613 let size_field_place = ecx.project_field(&variant_place, FieldIdx::ZERO)?;
614 ecx.write_scalar(
615 ScalarInt::try_from_target_usize(layout.size.bytes(), ecx.tcx.tcx).unwrap(),
616 &size_field_place,
617 )?;
618 variant
619 } else {
620 ecx.project_downcast_named(dest, sym::None)?.0
621 };
622 ecx.write_discriminant(variant_index, dest)?;
623 }
624
625 sym::type_id_fields => {
626 let ty = ecx.read_type_id(&args[0])?;
627 let variant_idx = ecx.read_target_usize(&args[1])? as usize;
628
629 let variants_num =
630 ty.ty_adt_def().map(|adt_def| adt_def.variants().len()).unwrap_or(1);
631 if variant_idx >= variants_num {
632 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::BoundsCheckFailed {
len: variants_num as u64,
index: variant_idx as u64,
});throw_ub!(BoundsCheckFailed {
633 len: variants_num as u64,
634 index: variant_idx as u64
635 });
636 }
637
638 let fields_num = match ty.kind() {
639 ty::Adt(adt_def, _) => {
640 let variant_def = &adt_def.variants()[VariantIdx::from_usize(variant_idx)];
641 variant_def.fields.len()
642 }
643 ty::Tuple(fields) => fields.len(),
644 _ => 0, };
646
647 ecx.write_scalar(Scalar::from_target_usize(fields_num as u64, ecx), dest)?;
648 }
649
650 sym::type_id_field_representing_type => {
651 let ty = ecx.read_type_id(&args[0])?;
652 let variant_idx = ecx.read_target_usize(&args[1])? as usize;
653 let field_idx = ecx.read_target_usize(&args[2])? as usize;
654
655 let variants_num =
656 ty.ty_adt_def().map(|adt_def| adt_def.variants().len()).unwrap_or(1);
657 if variant_idx >= variants_num {
658 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::BoundsCheckFailed {
len: variants_num as u64,
index: variant_idx as u64,
});throw_ub!(BoundsCheckFailed {
659 len: variants_num as u64,
660 index: variant_idx as u64
661 });
662 }
663
664 let fields_num = match ty.kind() {
665 ty::Adt(adt_def, _) => {
666 let variant_def = &adt_def.variants()[VariantIdx::from_usize(variant_idx)];
667 variant_def.fields.len()
668 }
669 ty::Tuple(fields) => fields.len(),
670 _ => 0, };
672 if field_idx >= fields_num {
673 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::BoundsCheckFailed {
len: fields_num as u64,
index: field_idx as u64,
});throw_ub!(BoundsCheckFailed {
674 len: fields_num as u64,
675 index: field_idx as u64
676 });
677 }
678
679 let frt = Ty::new_field_representing_type(
680 *ecx.tcx,
681 ty,
682 VariantIdx::from_usize(variant_idx),
683 FieldIdx::from_usize(field_idx),
684 );
685 ecx.write_type_id(frt, dest)?;
686 }
687
688 sym::type_id_variants => {
689 let ty = ecx.read_type_id(&args[0])?;
690 let variants_num = ty.ty_adt_def().map(|def| def.variants().len()).unwrap_or(1);
691 ecx.write_scalar(Scalar::from_target_usize(variants_num as u64, ecx), dest)?;
692 }
693
694 sym::field_offset => {
695 let frt_ty = instance.args.type_at(0);
696 ensure_monomorphic_enough(frt_ty)?;
697
698 let (ty, variant, field) = if let ty::Adt(def, args) = frt_ty.kind()
699 && let Some(FieldInfo { base, variant_idx, field_idx, .. }) =
700 def.field_representing_type_info(ecx.tcx.tcx, args)
701 {
702 (base, variant_idx, field_idx)
703 } else {
704 ::rustc_middle::util::bug::span_bug_fmt(ecx.cur_span(),
format_args!("expected field representing type, got {0}", frt_ty))span_bug!(ecx.cur_span(), "expected field representing type, got {frt_ty}")
705 };
706 let layout = ecx.layout_of(ty)?;
707 let cx = ty::layout::LayoutCx::new(ecx.tcx.tcx, ecx.typing_env());
708
709 let layout = layout.for_variant(&cx, variant);
710 let offset = layout.fields.offset(field.index()).bytes();
711
712 ecx.write_scalar(Scalar::from_target_usize(offset, ecx), dest)?;
713 }
714
715 sym::field_representing_type_actual_type_id => {
716 let frt_ty = ecx.read_type_id(&args[0])?;
717
718 let field_ty = if let ty::Adt(def, args) = frt_ty.kind()
719 && let Some(FieldInfo { ty, .. }) =
720 def.field_representing_type_info(ecx.tcx.tcx, args)
721 {
722 ecx.tcx.erase_and_anonymize_regions(ty)
723 } else {
724 ::rustc_middle::util::bug::span_bug_fmt(ecx.cur_span(),
format_args!("expected field representing type, got {0}", frt_ty))span_bug!(ecx.cur_span(), "expected field representing type, got {frt_ty}")
725 };
726 ecx.write_type_id(field_ty, dest)?;
727 }
728
729 _ => {
730 if ecx.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
732 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::Unsupported(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("intrinsic `{0}` is not supported at compile-time",
intrinsic_name))
})));throw_unsup_format!(
733 "intrinsic `{intrinsic_name}` is not supported at compile-time"
734 );
735 }
736 return interp_ok(Some(ty::Instance {
737 def: ty::InstanceKind::Item(instance.def_id()),
738 args: instance.args,
739 }));
740 }
741 }
742
743 ecx.return_to_block(target)?;
745 interp_ok(None)
746 }
747
748 fn call_llvm_intrinsic(
749 ecx: &mut InterpCx<'tcx, Self>,
750 instance: ty::Instance<'tcx>,
751 _args: &[OpTy<'tcx>],
752 _dest: &PlaceTy<'tcx, Self::Provenance>,
753 _target: Option<mir::BasicBlock>,
754 ) -> InterpResult<'tcx> {
755 let intrinsic_name = ecx.tcx.codegen_fn_attrs(instance.def_id()).symbol_name.unwrap();
756
757 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::Unsupported(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("LLVM intrinsic `{0}` is not supported at compile-time",
intrinsic_name))
})));throw_unsup_format!("LLVM intrinsic `{intrinsic_name}` is not supported at compile-time");
758 }
759
760 fn assert_panic(
761 ecx: &mut InterpCx<'tcx, Self>,
762 msg: &AssertMessage<'tcx>,
763 _unwind: mir::UnwindAction,
764 ) -> InterpResult<'tcx> {
765 use rustc_middle::mir::AssertKind::*;
766 let eval_to_int =
768 |op| ecx.read_immediate(&ecx.eval_operand(op, None)?).map(|x| x.to_const_int());
769 let err = match msg {
770 BoundsCheck { len, index } => {
771 let len = eval_to_int(len)?;
772 let index = eval_to_int(index)?;
773 BoundsCheck { len, index }
774 }
775 Overflow(op, l, r) => Overflow(*op, eval_to_int(l)?, eval_to_int(r)?),
776 OverflowNeg(op) => OverflowNeg(eval_to_int(op)?),
777 DivisionByZero(op) => DivisionByZero(eval_to_int(op)?),
778 RemainderByZero(op) => RemainderByZero(eval_to_int(op)?),
779 ResumedAfterReturn(coroutine_kind) => ResumedAfterReturn(*coroutine_kind),
780 ResumedAfterPanic(coroutine_kind) => ResumedAfterPanic(*coroutine_kind),
781 ResumedAfterDrop(coroutine_kind) => ResumedAfterDrop(*coroutine_kind),
782 MisalignedPointerDereference { required, found } => MisalignedPointerDereference {
783 required: eval_to_int(required)?,
784 found: eval_to_int(found)?,
785 },
786 NullPointerDereference => NullPointerDereference,
787 NullReferenceConstructed => NullReferenceConstructed,
788 InvalidEnumConstruction(source) => InvalidEnumConstruction(eval_to_int(source)?),
789 };
790 Err(ConstEvalErrKind::AssertFailure(err)).into()
791 }
792
793 #[inline(always)]
794 fn runtime_checks(
795 _ecx: &InterpCx<'tcx, Self>,
796 _r: mir::RuntimeChecks,
797 ) -> InterpResult<'tcx, bool> {
798 interp_ok(true)
801 }
802
803 fn binary_ptr_op(
804 _ecx: &InterpCx<'tcx, Self>,
805 _bin_op: mir::BinOp,
806 _left: &ImmTy<'tcx>,
807 _right: &ImmTy<'tcx>,
808 ) -> InterpResult<'tcx, ImmTy<'tcx>> {
809 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::Unsupported(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("pointer arithmetic or comparison is not supported at compile-time"))
})));throw_unsup_format!("pointer arithmetic or comparison is not supported at compile-time");
810 }
811
812 fn increment_const_eval_counter(ecx: &mut InterpCx<'tcx, Self>) -> InterpResult<'tcx> {
813 if let Some(new_steps) = ecx.machine.num_evaluated_steps.checked_add(1) {
816 let (limit, start) = if ecx.tcx.sess.opts.unstable_opts.tiny_const_eval_limit {
817 (TINY_LINT_TERMINATOR_LIMIT, TINY_LINT_TERMINATOR_LIMIT)
818 } else {
819 (LINT_TERMINATOR_LIMIT, PROGRESS_INDICATOR_START)
820 };
821
822 ecx.machine.num_evaluated_steps = new_steps;
823 if new_steps == limit {
828 let hir_id = ecx.machine.best_lint_scope(*ecx.tcx);
832 let is_error = ecx
833 .tcx
834 .lint_level_spec_at_node(
835 rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
836 hir_id,
837 )
838 .level()
839 .is_error();
840 let span = ecx.cur_span();
841 ecx.tcx.emit_node_span_lint(
842 rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
843 hir_id,
844 span,
845 LongRunning { item_span: ecx.tcx.span },
846 );
847 if is_error {
849 let guard = ecx
850 .tcx
851 .dcx()
852 .span_delayed_bug(span, "The deny lint should have already errored");
853 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::InvalidProgram(::rustc_middle::mir::interpret::InvalidProgramInfo::AlreadyReported(ReportedErrorInfo::allowed_in_infallible(guard)));throw_inval!(AlreadyReported(ReportedErrorInfo::allowed_in_infallible(guard)));
854 }
855 } else if new_steps > start && new_steps.is_power_of_two() {
856 let span = ecx.cur_span();
860 let mut warn =
861 ecx.tcx.dcx().create_warn(LongRunningWarn { span, item_span: ecx.tcx.span });
862 warn.arg("force_duplicate", new_steps);
866 warn.emit();
867 }
868 }
869
870 interp_ok(())
871 }
872
873 #[inline(always)]
874 fn expose_provenance(
875 _ecx: &InterpCx<'tcx, Self>,
876 _provenance: Self::Provenance,
877 ) -> InterpResult<'tcx> {
878 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::Unsupported(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("exposing pointers is not possible at compile-time"))
})))throw_unsup_format!("exposing pointers is not possible at compile-time")
880 }
881
882 #[inline(always)]
883 fn init_frame(
884 ecx: &mut InterpCx<'tcx, Self>,
885 frame: Frame<'tcx>,
886 ) -> InterpResult<'tcx, Frame<'tcx>> {
887 if !ecx.recursion_limit.value_within_limit(ecx.stack().len() + 1) {
889 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::ResourceExhaustion(::rustc_middle::mir::interpret::ResourceExhaustionInfo::StackFrameLimitReached)throw_exhaust!(StackFrameLimitReached)
890 } else {
891 interp_ok(frame)
892 }
893 }
894
895 #[inline(always)]
896 fn stack<'a>(
897 ecx: &'a InterpCx<'tcx, Self>,
898 ) -> &'a [Frame<'tcx, Self::Provenance, Self::FrameExtra>] {
899 &ecx.machine.stack
900 }
901
902 #[inline(always)]
903 fn stack_mut<'a>(
904 ecx: &'a mut InterpCx<'tcx, Self>,
905 ) -> &'a mut Vec<Frame<'tcx, Self::Provenance, Self::FrameExtra>> {
906 &mut ecx.machine.stack
907 }
908
909 fn before_access_global(
910 _tcx: TyCtxtAt<'tcx>,
911 machine: &Self,
912 alloc_id: AllocId,
913 alloc: ConstAllocation<'tcx>,
914 _static_def_id: Option<DefId>,
915 is_write: bool,
916 ) -> InterpResult<'tcx> {
917 let alloc = alloc.inner();
918 if is_write {
919 match alloc.mutability {
921 Mutability::Not => do yeet ::rustc_middle::mir::interpret::InterpErrorKind::UndefinedBehavior(::rustc_middle::mir::interpret::UndefinedBehaviorInfo::WriteToReadOnly(alloc_id))throw_ub!(WriteToReadOnly(alloc_id)),
922 Mutability::Mut => Err(ConstEvalErrKind::ModifiedGlobal).into(),
923 }
924 } else {
925 if machine.can_access_mut_global == CanAccessMutGlobal::Yes {
927 interp_ok(())
929 } else if alloc.mutability == Mutability::Mut {
930 Err(ConstEvalErrKind::ConstAccessesMutGlobal).into()
933 } else {
934 {
match (&alloc.mutability, &Mutability::Not) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(alloc.mutability, Mutability::Not);
936 interp_ok(())
937 }
938 }
939 }
940
941 fn retag_ptr_value(
942 ecx: &mut InterpCx<'tcx, Self>,
943 val: &ImmTy<'tcx, CtfeProvenance>,
944 _ty: Ty<'tcx>,
945 ) -> InterpResult<'tcx, Option<ImmTy<'tcx, CtfeProvenance>>> {
946 if #[allow(non_exhaustive_omitted_patterns)] match ecx.machine.retag_mode {
RetagMode::None | RetagMode::Raw => true,
_ => false,
}matches!(ecx.machine.retag_mode, RetagMode::None | RetagMode::Raw) {
947 return interp_ok(None);
948 }
949 if let ty::Ref(_, ty, mutbl) = val.layout.ty.kind()
952 && *mutbl == Mutability::Not
953 && val
954 .to_scalar_and_meta()
955 .0
956 .to_pointer(ecx)?
957 .provenance
958 .is_some_and(|p| !p.immutable())
959 {
960 let is_immutable = ty.is_freeze(*ecx.tcx, ecx.typing_env());
962 let place = ecx.imm_ptr_to_mplace(val)?;
963 let new_place = if is_immutable {
964 place.map_provenance(CtfeProvenance::as_immutable)
965 } else {
966 place.map_provenance(CtfeProvenance::as_shared_ref)
971 };
972 interp_ok(Some(ImmTy::from_immediate(new_place.to_ref(ecx), val.layout)))
973 } else {
974 interp_ok(None)
975 }
976 }
977
978 fn with_retag_mode<T>(
979 ecx: &mut InterpCx<'tcx, Self>,
980 mode: RetagMode,
981 f: impl FnOnce(&mut InterpCx<'tcx, Self>) -> InterpResult<'tcx, T>,
982 ) -> InterpResult<'tcx, T> {
983 let old_mode = mem::replace(&mut ecx.machine.retag_mode, mode);
984 let ret = f(ecx);
985 ecx.machine.retag_mode = old_mode;
986 ret
987 }
988
989 fn before_memory_write(
990 _tcx: TyCtxtAt<'tcx>,
991 _machine: &mut Self,
992 _alloc_extra: &mut Self::AllocExtra,
993 _ptr: Pointer<Option<Self::Provenance>>,
994 (_alloc_id, immutable): (AllocId, bool),
995 range: AllocRange,
996 ) -> InterpResult<'tcx> {
997 if range.size == Size::ZERO {
998 return interp_ok(());
1000 }
1001 if immutable {
1003 return Err(ConstEvalErrKind::WriteThroughImmutablePointer).into();
1004 }
1005 interp_ok(())
1007 }
1008
1009 fn before_alloc_access(
1010 tcx: TyCtxtAt<'tcx>,
1011 machine: &Self,
1012 alloc_id: AllocId,
1013 ) -> InterpResult<'tcx> {
1014 if machine.stack.is_empty() {
1015 return interp_ok(());
1017 }
1018 if Some(alloc_id) == machine.static_root_ids.map(|(id, _)| id) {
1020 return Err(ConstEvalErrKind::RecursiveStatic).into();
1021 }
1022 if machine.static_root_ids.is_some() {
1025 if let Some(GlobalAlloc::Static(def_id)) = tcx.try_get_global_alloc(alloc_id) {
1026 if tcx.is_foreign_item(def_id) {
1027 do yeet ::rustc_middle::mir::interpret::InterpErrorKind::Unsupported(::rustc_middle::mir::interpret::UnsupportedOpInfo::ExternStatic(def_id));throw_unsup!(ExternStatic(def_id));
1028 }
1029 tcx.eval_static_initializer(def_id)?;
1030 }
1031 }
1032 interp_ok(())
1033 }
1034
1035 fn cached_union_data_range<'e>(
1036 ecx: &'e mut InterpCx<'tcx, Self>,
1037 ty: Ty<'tcx>,
1038 compute_range: impl FnOnce() -> RangeSet,
1039 ) -> Cow<'e, RangeSet> {
1040 if ecx.tcx.sess.opts.unstable_opts.extra_const_ub_checks {
1041 Cow::Borrowed(ecx.machine.union_data_ranges.entry(ty).or_insert_with(compute_range))
1042 } else {
1043 Cow::Owned(compute_range())
1045 }
1046 }
1047
1048 fn get_default_alloc_params(&self) -> <Self::Bytes as mir::interpret::AllocBytes>::AllocParams {
1049 }
1050}
1051
1052