1#[macro_use]
4mod error;
5
6mod allocation;
7mod pointer;
8mod queries;
9mod value;
10
11use std::io::{Read, Write};
12use std::num::NonZero;
13use std::{fmt, io};
14
15use rustc_abi::{AddressSpace, Align, Endian, HasDataLayout, Size};
16use rustc_ast::Mutability;
17use rustc_data_structures::fx::FxHashMap;
18use rustc_data_structures::sharded::ShardedHashMap;
19use rustc_data_structures::sync::{AtomicU64, Lock};
20use rustc_hir::def::DefKind;
21use rustc_hir::def_id::{DefId, LocalDefId};
22use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
23use rustc_serialize::{Decodable, Encodable};
24use tracing::{debug, trace};
25pub use {
27 err_exhaust, err_inval, err_machine_stop, err_ub, err_ub_format, err_unsup, err_unsup_format,
28 throw_exhaust, throw_inval, throw_machine_stop, throw_ub, throw_ub_format, throw_unsup,
29 throw_unsup_format,
30};
31
32pub use self::allocation::{
33 AllocBytes, AllocError, AllocInit, AllocRange, AllocResult, Allocation, ConstAllocation,
34 InitChunk, InitChunkIter, alloc_range,
35};
36pub use self::error::{
37 BadBytesAccess, CheckAlignMsg, CheckInAllocMsg, ErrorHandled, EvalStaticInitializerRawResult,
38 EvalToAllocationRawResult, EvalToConstValueResult, EvalToValTreeResult, InterpErrorInfo,
39 InterpErrorKind, InterpResult, InvalidMetaKind, InvalidProgramInfo, MachineStopType,
40 Misalignment, ReportedErrorInfo, ResourceExhaustionInfo, ScalarSizeMismatch,
41 UndefinedBehaviorInfo, UnsupportedOpInfo, ValTreeCreationError, interp_ok,
42};
43pub use self::pointer::{CtfeProvenance, Pointer, PointerArithmetic, Provenance};
44pub use self::value::Scalar;
45use crate::mir;
46use crate::ty::codec::{TyDecoder, TyEncoder};
47use crate::ty::print::with_no_trimmed_paths;
48use crate::ty::{self, Instance, Ty, TyCtxt};
49
50#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for GlobalId<'tcx> { }Copy, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for GlobalId<'tcx> {
#[inline]
fn clone(&self) -> GlobalId<'tcx> {
let _: ::core::clone::AssertParamIsClone<ty::Instance<'tcx>>;
let _: ::core::clone::AssertParamIsClone<Option<mir::Promoted>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for GlobalId<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "GlobalId",
"instance", &self.instance, "promoted", &&self.promoted)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for GlobalId<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<ty::Instance<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Option<mir::Promoted>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for GlobalId<'tcx> {
#[inline]
fn eq(&self, other: &GlobalId<'tcx>) -> bool {
self.instance == other.instance && self.promoted == other.promoted
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for GlobalId<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.instance, state);
::core::hash::Hash::hash(&self.promoted, state)
}
}Hash, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for GlobalId<'tcx> {
fn encode(&self, __encoder: &mut __E) {
match *self {
GlobalId {
instance: ref __binding_0, promoted: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for GlobalId<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
GlobalId {
instance: ::rustc_serialize::Decodable::decode(__decoder),
promoted: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};TyDecodable)]
54#[derive(const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for GlobalId<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
match *self {
GlobalId {
instance: ref __binding_0, promoted: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>
for GlobalId<'tcx> {
fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Result<Self, __F::Error> {
Ok(match self {
GlobalId { instance: __binding_0, promoted: __binding_1 } =>
{
GlobalId {
instance: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_0,
__folder)?,
promoted: ::rustc_middle::ty::TypeFoldable::try_fold_with(__binding_1,
__folder)?,
}
}
})
}
fn fold_with<__F: ::rustc_middle::ty::TypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(self,
__folder: &mut __F) -> Self {
match self {
GlobalId { instance: __binding_0, promoted: __binding_1 } =>
{
GlobalId {
instance: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_0,
__folder),
promoted: ::rustc_middle::ty::TypeFoldable::fold_with(__binding_1,
__folder),
}
}
}
}
}
};TypeFoldable, const _: () =
{
impl<'tcx>
::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>
for GlobalId<'tcx> {
fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(&self,
__visitor: &mut __V) -> __V::Result {
match *self {
GlobalId {
instance: ref __binding_0, promoted: ref __binding_1 } => {
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_0,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
{
match ::rustc_middle::ty::VisitorResult::branch(::rustc_middle::ty::TypeVisitable::visit_with(__binding_1,
__visitor)) {
::core::ops::ControlFlow::Continue(()) => {}
::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::VisitorResult::from_residual(r);
}
}
}
}
}
<__V::Result as ::rustc_middle::ty::VisitorResult>::output()
}
}
};TypeVisitable)]
55pub struct GlobalId<'tcx> {
56 pub instance: ty::Instance<'tcx>,
59
60 pub promoted: Option<mir::Promoted>,
62}
63
64impl<'tcx> GlobalId<'tcx> {
65 pub fn display(self, tcx: TyCtxt<'tcx>) -> String {
66 let instance_name = {
let _guard = NoTrimmedGuard::new();
tcx.def_path_str(self.instance.def.def_id())
}with_no_trimmed_paths!(tcx.def_path_str(self.instance.def.def_id()));
67 if let Some(promoted) = self.promoted {
68 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}::{1:?}", instance_name,
promoted))
})format!("{instance_name}::{promoted:?}")
69 } else {
70 instance_name
71 }
72 }
73}
74
75#[derive(#[automatically_derived]
impl ::core::marker::Copy for AllocId { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AllocId {
#[inline]
fn clone(&self) -> AllocId {
let _: ::core::clone::AssertParamIsClone<NonZero<u64>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::Eq for AllocId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<NonZero<u64>>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for AllocId {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}Hash, #[automatically_derived]
impl ::core::cmp::Ord for AllocId {
#[inline]
fn cmp(&self, other: &AllocId) -> ::core::cmp::Ordering {
::core::cmp::Ord::cmp(&self.0, &other.0)
}
}Ord, #[automatically_derived]
impl ::core::cmp::PartialEq for AllocId {
#[inline]
fn eq(&self, other: &AllocId) -> bool { self.0 == other.0 }
}PartialEq, #[automatically_derived]
impl ::core::cmp::PartialOrd for AllocId {
#[inline]
fn partial_cmp(&self, other: &AllocId)
-> ::core::option::Option<::core::cmp::Ordering> {
::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
}
}PartialOrd)]
76pub struct AllocId(pub NonZero<u64>);
77
78impl fmt::Display for AllocId {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 if f.alternate() { f.write_fmt(format_args!("a{0}", self.0))write!(f, "a{}", self.0) } else { f.write_fmt(format_args!("alloc{0}", self.0))write!(f, "alloc{}", self.0) }
82 }
83}
84
85impl fmt::Debug for AllocId {
88 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89 fmt::Display::fmt(self, f)
91 }
92}
93
94#[derive(const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for AllocDiscriminant {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { AllocDiscriminant::Alloc }
1usize => { AllocDiscriminant::Fn }
2usize => { AllocDiscriminant::VTable }
3usize => { AllocDiscriminant::Static }
4usize => { AllocDiscriminant::Type }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `AllocDiscriminant`, expected 0..5, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for AllocDiscriminant {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
AllocDiscriminant::Alloc => { 0usize }
AllocDiscriminant::Fn => { 1usize }
AllocDiscriminant::VTable => { 2usize }
AllocDiscriminant::Static => { 3usize }
AllocDiscriminant::Type => { 4usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
AllocDiscriminant::Alloc => {}
AllocDiscriminant::Fn => {}
AllocDiscriminant::VTable => {}
AllocDiscriminant::Static => {}
AllocDiscriminant::Type => {}
}
}
}
};TyEncodable)]
95enum AllocDiscriminant {
96 Alloc,
97 Fn,
98 VTable,
99 Static,
100 Type,
101}
102
103pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<'tcx>>(
104 encoder: &mut E,
105 tcx: TyCtxt<'tcx>,
106 alloc_id: AllocId,
107) {
108 match tcx.global_alloc(alloc_id) {
109 GlobalAlloc::Memory(alloc) => {
110 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:110",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(110u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("encoding {0:?} with {1:#?}",
alloc_id, alloc) as &dyn Value))])
});
} else { ; }
};trace!("encoding {:?} with {:#?}", alloc_id, alloc);
111 AllocDiscriminant::Alloc.encode(encoder);
112 alloc.encode(encoder);
113 }
114 GlobalAlloc::Function { instance } => {
115 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:115",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(115u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("encoding {0:?} with {1:#?}",
alloc_id, instance) as &dyn Value))])
});
} else { ; }
};trace!("encoding {:?} with {:#?}", alloc_id, instance);
116 AllocDiscriminant::Fn.encode(encoder);
117 instance.encode(encoder);
118 }
119 GlobalAlloc::VTable(ty, poly_trait_ref) => {
120 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:120",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(120u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("encoding {0:?} with {1:#?}, {2:#?}",
alloc_id, ty, poly_trait_ref) as &dyn Value))])
});
} else { ; }
};trace!("encoding {:?} with {ty:#?}, {poly_trait_ref:#?}", alloc_id);
121 AllocDiscriminant::VTable.encode(encoder);
122 ty.encode(encoder);
123 poly_trait_ref.encode(encoder);
124 }
125 GlobalAlloc::TypeId { ty } => {
126 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:126",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(126u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("encoding {0:?} with {1:#?}",
alloc_id, ty) as &dyn Value))])
});
} else { ; }
};trace!("encoding {alloc_id:?} with {ty:#?}");
127 AllocDiscriminant::Type.encode(encoder);
128 ty.encode(encoder);
129 }
130 GlobalAlloc::Static(did) => {
131 if !!tcx.is_thread_local_static(did) {
::core::panicking::panic("assertion failed: !tcx.is_thread_local_static(did)")
};assert!(!tcx.is_thread_local_static(did));
132 AllocDiscriminant::Static.encode(encoder);
135 Encodable::<E>::encode(&did, encoder);
138 }
139 }
140}
141
142#[derive(#[automatically_derived]
impl ::core::clone::Clone for State {
#[inline]
fn clone(&self) -> State {
match self {
State::Empty => State::Empty,
State::Done(__self_0) =>
State::Done(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
143enum State {
144 Empty,
145 Done(AllocId),
146}
147
148pub struct AllocDecodingState {
149 decoding_state: Vec<Lock<State>>,
151 data_offsets: Vec<u64>,
153}
154
155impl AllocDecodingState {
156 #[inline]
157 pub fn new_decoding_session(&self) -> AllocDecodingSession<'_> {
158 AllocDecodingSession { state: self }
159 }
160
161 pub fn new(data_offsets: Vec<u64>) -> Self {
162 let decoding_state =
163 std::iter::repeat_with(|| Lock::new(State::Empty)).take(data_offsets.len()).collect();
164
165 Self { decoding_state, data_offsets }
166 }
167}
168
169#[derive(#[automatically_derived]
impl<'s> ::core::marker::Copy for AllocDecodingSession<'s> { }Copy, #[automatically_derived]
impl<'s> ::core::clone::Clone for AllocDecodingSession<'s> {
#[inline]
fn clone(&self) -> AllocDecodingSession<'s> {
let _: ::core::clone::AssertParamIsClone<&'s AllocDecodingState>;
*self
}
}Clone)]
170pub struct AllocDecodingSession<'s> {
171 state: &'s AllocDecodingState,
172}
173
174impl<'s> AllocDecodingSession<'s> {
175 pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
177 where
178 D: TyDecoder<'tcx>,
179 {
180 let idx = usize::try_from(decoder.read_u32()).unwrap();
182 let pos = usize::try_from(self.state.data_offsets[idx]).unwrap();
183
184 let (alloc_kind, pos) = decoder.with_position(pos, |decoder| {
187 let alloc_kind = AllocDiscriminant::decode(decoder);
188 (alloc_kind, decoder.position())
189 });
190
191 let mut entry = self.state.decoding_state[idx].lock();
204 if let State::Done(alloc_id) = *entry {
207 return alloc_id;
208 }
209
210 let alloc_id = decoder.with_position(pos, |decoder| match alloc_kind {
212 AllocDiscriminant::Alloc => {
213 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:213",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(213u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("creating memory alloc ID")
as &dyn Value))])
});
} else { ; }
};trace!("creating memory alloc ID");
214 let alloc = <ConstAllocation<'tcx> as Decodable<_>>::decode(decoder);
215 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:215",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(215u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("decoded alloc {0:?}",
alloc) as &dyn Value))])
});
} else { ; }
};trace!("decoded alloc {:?}", alloc);
216 decoder.interner().reserve_and_set_memory_alloc(alloc)
217 }
218 AllocDiscriminant::Fn => {
219 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:219",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(219u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("creating fn alloc ID")
as &dyn Value))])
});
} else { ; }
};trace!("creating fn alloc ID");
220 let instance = ty::Instance::decode(decoder);
221 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:221",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(221u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("decoded fn alloc instance: {0:?}",
instance) as &dyn Value))])
});
} else { ; }
};trace!("decoded fn alloc instance: {:?}", instance);
222 decoder.interner().reserve_and_set_fn_alloc(instance, CTFE_ALLOC_SALT)
223 }
224 AllocDiscriminant::VTable => {
225 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:225",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(225u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("creating vtable alloc ID")
as &dyn Value))])
});
} else { ; }
};trace!("creating vtable alloc ID");
226 let ty = Decodable::decode(decoder);
227 let poly_trait_ref = Decodable::decode(decoder);
228 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:228",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(228u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("decoded vtable alloc instance: {0:?}, {1:?}",
ty, poly_trait_ref) as &dyn Value))])
});
} else { ; }
};trace!("decoded vtable alloc instance: {ty:?}, {poly_trait_ref:?}");
229 decoder.interner().reserve_and_set_vtable_alloc(ty, poly_trait_ref, CTFE_ALLOC_SALT)
230 }
231 AllocDiscriminant::Type => {
232 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:232",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(232u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("creating typeid alloc ID")
as &dyn Value))])
});
} else { ; }
};trace!("creating typeid alloc ID");
233 let ty = Decodable::decode(decoder);
234 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:234",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(234u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("decoded typid: {0:?}",
ty) as &dyn Value))])
});
} else { ; }
};trace!("decoded typid: {ty:?}");
235 decoder.interner().reserve_and_set_type_id_alloc(ty)
236 }
237 AllocDiscriminant::Static => {
238 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:238",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(238u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("creating extern static alloc ID")
as &dyn Value))])
});
} else { ; }
};trace!("creating extern static alloc ID");
239 let did = <DefId as Decodable<D>>::decode(decoder);
240 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:240",
"rustc_middle::mir::interpret", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(240u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("decoded static def-ID: {0:?}",
did) as &dyn Value))])
});
} else { ; }
};trace!("decoded static def-ID: {:?}", did);
241 decoder.interner().reserve_and_set_static_alloc(did)
242 }
243 });
244
245 *entry = State::Done(alloc_id);
246
247 alloc_id
248 }
249}
250
251#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for GlobalAlloc<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
GlobalAlloc::Function { instance: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Function", "instance", &__self_0),
GlobalAlloc::VTable(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "VTable",
__self_0, &__self_1),
GlobalAlloc::Static(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Static",
&__self_0),
GlobalAlloc::Memory(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Memory",
&__self_0),
GlobalAlloc::TypeId { ty: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TypeId", "ty", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for GlobalAlloc<'tcx> {
#[inline]
fn clone(&self) -> GlobalAlloc<'tcx> {
match self {
GlobalAlloc::Function { instance: __self_0 } =>
GlobalAlloc::Function {
instance: ::core::clone::Clone::clone(__self_0),
},
GlobalAlloc::VTable(__self_0, __self_1) =>
GlobalAlloc::VTable(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1)),
GlobalAlloc::Static(__self_0) =>
GlobalAlloc::Static(::core::clone::Clone::clone(__self_0)),
GlobalAlloc::Memory(__self_0) =>
GlobalAlloc::Memory(::core::clone::Clone::clone(__self_0)),
GlobalAlloc::TypeId { ty: __self_0 } =>
GlobalAlloc::TypeId {
ty: ::core::clone::Clone::clone(__self_0),
},
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for GlobalAlloc<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Instance<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
let _:
::core::cmp::AssertParamIsEq<&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>>;
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<ConstAllocation<'tcx>>;
let _: ::core::cmp::AssertParamIsEq<Ty<'tcx>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for GlobalAlloc<'tcx> {
#[inline]
fn eq(&self, other: &GlobalAlloc<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(GlobalAlloc::Function { instance: __self_0 },
GlobalAlloc::Function { instance: __arg1_0 }) =>
__self_0 == __arg1_0,
(GlobalAlloc::VTable(__self_0, __self_1),
GlobalAlloc::VTable(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(GlobalAlloc::Static(__self_0), GlobalAlloc::Static(__arg1_0))
=> __self_0 == __arg1_0,
(GlobalAlloc::Memory(__self_0), GlobalAlloc::Memory(__arg1_0))
=> __self_0 == __arg1_0,
(GlobalAlloc::TypeId { ty: __self_0 }, GlobalAlloc::TypeId {
ty: __arg1_0 }) => __self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::hash::Hash for GlobalAlloc<'tcx> {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
GlobalAlloc::Function { instance: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
GlobalAlloc::VTable(__self_0, __self_1) => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
GlobalAlloc::Static(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
GlobalAlloc::Memory(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
GlobalAlloc::TypeId { ty: __self_0 } =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, const _: () =
{
impl<'tcx, __D: ::rustc_middle::ty::codec::TyDecoder<'tcx>>
::rustc_serialize::Decodable<__D> for GlobalAlloc<'tcx> {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
GlobalAlloc::Function {
instance: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
GlobalAlloc::VTable(::rustc_serialize::Decodable::decode(__decoder),
::rustc_middle::ty::codec::RefDecodable::decode(__decoder))
}
2usize => {
GlobalAlloc::Static(::rustc_serialize::Decodable::decode(__decoder))
}
3usize => {
GlobalAlloc::Memory(::rustc_serialize::Decodable::decode(__decoder))
}
4usize => {
GlobalAlloc::TypeId {
ty: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `GlobalAlloc`, expected 0..5, actual {0}",
n));
}
}
}
}
};TyDecodable, const _: () =
{
impl<'tcx, __E: ::rustc_middle::ty::codec::TyEncoder<'tcx>>
::rustc_serialize::Encodable<__E> for GlobalAlloc<'tcx> {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
GlobalAlloc::Function { instance: ref __binding_0 } => {
0usize
}
GlobalAlloc::VTable(ref __binding_0, __binding_1) => {
1usize
}
GlobalAlloc::Static(ref __binding_0) => { 2usize }
GlobalAlloc::Memory(ref __binding_0) => { 3usize }
GlobalAlloc::TypeId { ty: ref __binding_0 } => { 4usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
GlobalAlloc::Function { instance: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
GlobalAlloc::VTable(ref __binding_0, __binding_1) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
GlobalAlloc::Static(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
GlobalAlloc::Memory(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
GlobalAlloc::TypeId { ty: ref __binding_0 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
}
}
}
};TyEncodable, const _: () =
{
impl<'tcx, '__ctx>
::rustc_data_structures::stable_hasher::HashStable<::rustc_middle::ich::StableHashingContext<'__ctx>>
for GlobalAlloc<'tcx> {
#[inline]
fn hash_stable(&self,
__hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
GlobalAlloc::Function { instance: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
GlobalAlloc::VTable(ref __binding_0, ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
GlobalAlloc::Static(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
GlobalAlloc::Memory(ref __binding_0) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
GlobalAlloc::TypeId { ty: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
}
}
}
};HashStable)]
254pub enum GlobalAlloc<'tcx> {
255 Function { instance: Instance<'tcx> },
257 VTable(Ty<'tcx>, &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>),
262 Static(DefId),
265 Memory(ConstAllocation<'tcx>),
267 TypeId { ty: Ty<'tcx> },
270}
271
272impl<'tcx> GlobalAlloc<'tcx> {
273 #[track_caller]
275 #[inline]
276 pub fn unwrap_memory(&self) -> ConstAllocation<'tcx> {
277 match *self {
278 GlobalAlloc::Memory(mem) => mem,
279 _ => crate::util::bug::bug_fmt(format_args!("expected memory, got {0:?}", self))bug!("expected memory, got {:?}", self),
280 }
281 }
282
283 #[track_caller]
285 #[inline]
286 pub fn unwrap_fn(&self) -> Instance<'tcx> {
287 match *self {
288 GlobalAlloc::Function { instance, .. } => instance,
289 _ => crate::util::bug::bug_fmt(format_args!("expected function, got {0:?}", self))bug!("expected function, got {:?}", self),
290 }
291 }
292
293 #[track_caller]
295 #[inline]
296 pub fn unwrap_vtable(&self) -> (Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>) {
297 match *self {
298 GlobalAlloc::VTable(ty, dyn_ty) => (ty, dyn_ty.principal()),
299 _ => crate::util::bug::bug_fmt(format_args!("expected vtable, got {0:?}", self))bug!("expected vtable, got {:?}", self),
300 }
301 }
302
303 #[inline]
305 pub fn address_space(&self, cx: &impl HasDataLayout) -> AddressSpace {
306 match self {
307 GlobalAlloc::Function { .. } => cx.data_layout().instruction_address_space,
308 GlobalAlloc::TypeId { .. }
309 | GlobalAlloc::Static(..)
310 | GlobalAlloc::Memory(..)
311 | GlobalAlloc::VTable(..) => AddressSpace::ZERO,
312 }
313 }
314
315 pub fn mutability(&self, tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv<'tcx>) -> Mutability {
316 match *self {
318 GlobalAlloc::Static(did) => {
319 let DefKind::Static { safety: _, mutability, nested } = tcx.def_kind(did) else {
320 crate::util::bug::bug_fmt(format_args!("impossible case reached"))bug!()
321 };
322 if nested {
323 if truecfg!(debug_assertions) {
326 let alloc = tcx.eval_static_initializer(did).unwrap();
327 match (&alloc.0.mutability, &mutability) {
(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.0.mutability, mutability);
328 }
329 mutability
330 } else {
331 let mutability = match mutability {
332 Mutability::Not
333 if !tcx
334 .type_of(did)
335 .no_bound_vars()
336 .expect("statics should not have generic parameters")
337 .is_freeze(tcx, typing_env) =>
338 {
339 Mutability::Mut
340 }
341 _ => mutability,
342 };
343 mutability
344 }
345 }
346 GlobalAlloc::Memory(alloc) => alloc.inner().mutability,
347 GlobalAlloc::TypeId { .. } | GlobalAlloc::Function { .. } | GlobalAlloc::VTable(..) => {
348 Mutability::Not
350 }
351 }
352 }
353
354 pub fn size_and_align(
355 &self,
356 tcx: TyCtxt<'tcx>,
357 typing_env: ty::TypingEnv<'tcx>,
358 ) -> (Size, Align) {
359 match *self {
360 GlobalAlloc::Static(def_id) => {
361 let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else {
362 crate::util::bug::bug_fmt(format_args!("GlobalAlloc::Static is not a static"))bug!("GlobalAlloc::Static is not a static")
363 };
364
365 if nested {
366 let alloc = tcx.eval_static_initializer(def_id).unwrap();
371 (alloc.0.size(), alloc.0.align)
372 } else {
373 let ty = tcx
378 .type_of(def_id)
379 .no_bound_vars()
380 .expect("statics should not have generic parameters");
381 let layout = tcx.layout_of(typing_env.as_query_input(ty)).unwrap();
382 if !layout.is_sized() {
::core::panicking::panic("assertion failed: layout.is_sized()")
};assert!(layout.is_sized());
383
384 let align = match tcx.codegen_fn_attrs(def_id).alignment {
386 Some(align_from_attribute) => {
387 Ord::max(align_from_attribute, layout.align.abi)
388 }
389 None => layout.align.abi,
390 };
391
392 (layout.size, align)
393 }
394 }
395 GlobalAlloc::Memory(alloc) => {
396 let alloc = alloc.inner();
397 (alloc.size(), alloc.align)
398 }
399 GlobalAlloc::Function { .. } => (Size::ZERO, Align::ONE),
400 GlobalAlloc::VTable(..) => {
401 (Size::ZERO, tcx.data_layout.pointer_align().abi)
403 }
404 GlobalAlloc::TypeId { .. } => (Size::ZERO, Align::ONE),
406 }
407 }
408}
409
410pub const CTFE_ALLOC_SALT: usize = 0;
411
412pub(crate) struct AllocMap<'tcx> {
413 to_alloc: ShardedHashMap<AllocId, GlobalAlloc<'tcx>>,
421
422 dedup: Lock<FxHashMap<(GlobalAlloc<'tcx>, usize), AllocId>>,
427
428 next_id: AtomicU64,
431}
432
433impl<'tcx> AllocMap<'tcx> {
434 pub(crate) fn new() -> Self {
435 AllocMap {
436 to_alloc: Default::default(),
437 dedup: Default::default(),
438 next_id: AtomicU64::new(1),
439 }
440 }
441 fn reserve(&self) -> AllocId {
442 let next_id = self.next_id.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
446 AllocId(NonZero::new(next_id).unwrap())
447 }
448}
449
450impl<'tcx> TyCtxt<'tcx> {
451 pub fn reserve_alloc_id(self) -> AllocId {
457 self.alloc_map.reserve()
458 }
459
460 fn reserve_and_set_dedup(self, alloc: GlobalAlloc<'tcx>, salt: usize) -> AllocId {
463 if let GlobalAlloc::Memory(mem) = alloc {
464 if mem.inner().mutability.is_mut() {
465 crate::util::bug::bug_fmt(format_args!("trying to dedup-reserve mutable memory"));bug!("trying to dedup-reserve mutable memory");
466 }
467 }
468 let alloc_salt = (alloc, salt);
469 let mut dedup = self.alloc_map.dedup.lock();
471 if let Some(&alloc_id) = dedup.get(&alloc_salt) {
472 return alloc_id;
473 }
474 let id = self.alloc_map.reserve();
475 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_middle/src/mir/interpret/mod.rs:475",
"rustc_middle::mir::interpret", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_middle/src/mir/interpret/mod.rs"),
::tracing_core::__macro_support::Option::Some(475u32),
::tracing_core::__macro_support::Option::Some("rustc_middle::mir::interpret"),
::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!("creating alloc {0:?} with id {1:?}",
alloc_salt.0, id) as &dyn Value))])
});
} else { ; }
};debug!("creating alloc {:?} with id {id:?}", alloc_salt.0);
476 let had_previous = self.alloc_map.to_alloc.insert(id, alloc_salt.0.clone()).is_some();
477 if !!had_previous {
::core::panicking::panic("assertion failed: !had_previous")
};assert!(!had_previous);
479 dedup.insert(alloc_salt, id);
480 id
481 }
482
483 pub fn reserve_and_set_memory_dedup(self, mem: ConstAllocation<'tcx>, salt: usize) -> AllocId {
486 self.reserve_and_set_dedup(GlobalAlloc::Memory(mem), salt)
487 }
488
489 pub fn reserve_and_set_static_alloc(self, static_id: DefId) -> AllocId {
492 let salt = 0; self.reserve_and_set_dedup(GlobalAlloc::Static(static_id), salt)
494 }
495
496 pub fn reserve_and_set_fn_alloc(self, instance: Instance<'tcx>, salt: usize) -> AllocId {
498 self.reserve_and_set_dedup(GlobalAlloc::Function { instance }, salt)
499 }
500
501 pub fn reserve_and_set_vtable_alloc(
503 self,
504 ty: Ty<'tcx>,
505 dyn_ty: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
506 salt: usize,
507 ) -> AllocId {
508 self.reserve_and_set_dedup(GlobalAlloc::VTable(ty, dyn_ty), salt)
509 }
510
511 pub fn reserve_and_set_type_id_alloc(self, ty: Ty<'tcx>) -> AllocId {
513 self.reserve_and_set_dedup(GlobalAlloc::TypeId { ty }, 0)
514 }
515
516 pub fn reserve_and_set_memory_alloc(self, mem: ConstAllocation<'tcx>) -> AllocId {
522 let id = self.reserve_alloc_id();
523 self.set_alloc_id_memory(id, mem);
524 id
525 }
526
527 #[inline]
533 pub fn try_get_global_alloc(self, id: AllocId) -> Option<GlobalAlloc<'tcx>> {
534 self.alloc_map.to_alloc.get(&id)
535 }
536
537 #[inline]
538 #[track_caller]
539 pub fn global_alloc(self, id: AllocId) -> GlobalAlloc<'tcx> {
544 match self.try_get_global_alloc(id) {
545 Some(alloc) => alloc,
546 None => crate::util::bug::bug_fmt(format_args!("could not find allocation for {0:?}",
id))bug!("could not find allocation for {id:?}"),
547 }
548 }
549
550 pub fn set_alloc_id_memory(self, id: AllocId, mem: ConstAllocation<'tcx>) {
553 if let Some(old) = self.alloc_map.to_alloc.insert(id, GlobalAlloc::Memory(mem)) {
554 crate::util::bug::bug_fmt(format_args!("tried to set allocation ID {0:?}, but it was already existing as {1:#?}",
id, old));bug!("tried to set allocation ID {id:?}, but it was already existing as {old:#?}");
555 }
556 }
557
558 pub fn set_nested_alloc_id_static(self, id: AllocId, def_id: LocalDefId) {
561 if let Some(old) =
562 self.alloc_map.to_alloc.insert(id, GlobalAlloc::Static(def_id.to_def_id()))
563 {
564 crate::util::bug::bug_fmt(format_args!("tried to set allocation ID {0:?}, but it was already existing as {1:#?}",
id, old));bug!("tried to set allocation ID {id:?}, but it was already existing as {old:#?}");
565 }
566 }
567}
568
569#[inline]
574pub fn write_target_uint(
575 endianness: Endian,
576 mut target: &mut [u8],
577 data: u128,
578) -> Result<(), io::Error> {
579 match endianness {
582 Endian::Little => target.write(&data.to_le_bytes())?,
583 Endian::Big => target.write(&data.to_be_bytes()[16 - target.len()..])?,
584 };
585 if true {
if !(target.len() == 0) {
::core::panicking::panic("assertion failed: target.len() == 0")
};
};debug_assert!(target.len() == 0); Ok(())
587}
588
589#[inline]
590pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, io::Error> {
591 let mut buf = [0u8; size_of::<u128>()];
593 let uint = match endianness {
595 Endian::Little => {
596 source.read_exact(&mut buf[..source.len()])?;
597 Ok(u128::from_le_bytes(buf))
598 }
599 Endian::Big => {
600 source.read_exact(&mut buf[16 - source.len()..])?;
601 Ok(u128::from_be_bytes(buf))
602 }
603 };
604 if true {
if !(source.len() == 0) {
::core::panicking::panic("assertion failed: source.len() == 0")
};
};debug_assert!(source.len() == 0); uint
606}