1use std::fmt::{self, Write};
8use std::hash::Hash;
9
10use rustc_data_structures::fx::FxHashMap;
11use rustc_data_structures::stable_hash::StableHasher;
12use rustc_hashes::Hash64;
13use rustc_index::IndexVec;
14use rustc_macros::{BlobDecodable, Decodable, Encodable, extension};
15use rustc_span::def_id::LocalDefIdMap;
16use rustc_span::{Symbol, kw, sym};
17use tracing::{debug, instrument};
18
19pub use crate::def_id::DefPathHash;
20use crate::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex, LOCAL_CRATE, LocalDefId, StableCrateId};
21use crate::def_path_hash_map::DefPathHashMap;
22
23#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PerParentDisambiguatorState {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"PerParentDisambiguatorState", "parent", &self.parent, "next",
&&self.next)
}
}Debug, #[automatically_derived]
impl ::core::default::Default for PerParentDisambiguatorState {
#[inline]
fn default() -> PerParentDisambiguatorState {
PerParentDisambiguatorState {
parent: ::core::default::Default::default(),
next: ::core::default::Default::default(),
}
}
}Default, #[automatically_derived]
impl ::core::clone::Clone for PerParentDisambiguatorState {
#[inline]
fn clone(&self) -> PerParentDisambiguatorState {
PerParentDisambiguatorState {
parent: ::core::clone::Clone::clone(&self.parent),
next: ::core::clone::Clone::clone(&self.next),
}
}
}Clone)]
24pub struct PerParentDisambiguatorState {
25 #[cfg(debug_assertions)]
26 parent: Option<LocalDefId>,
27 next: FxHashMap<DefPathData, u32>,
28}
29
30impl PerParentDisambiguatorState {
31 #[inline(always)]
32 pub fn new(_parent: LocalDefId) -> PerParentDisambiguatorState {
33 PerParentDisambiguatorState {
34 #[cfg(debug_assertions)]
35 parent: Some(_parent),
36 next: Default::default(),
37 }
38 }
39}
40
41impl PerParentDisambiguatorsMap for LocalDefIdMap<PerParentDisambiguatorState>
{
fn get_or_create(&mut self, parent: LocalDefId)
-> &mut PerParentDisambiguatorState {
self.entry(parent).or_insert_with(||
PerParentDisambiguatorState::new(parent))
}
}#[extension(pub trait PerParentDisambiguatorsMap)]
42impl LocalDefIdMap<PerParentDisambiguatorState> {
43 fn get_or_create(&mut self, parent: LocalDefId) -> &mut PerParentDisambiguatorState {
44 self.entry(parent).or_insert_with(|| PerParentDisambiguatorState::new(parent))
45 }
46}
47
48#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Definitions {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "Definitions",
"stable_crate_id", &self.stable_crate_id, "def_id_to_key",
&self.def_id_to_key, "def_path_hashes", &self.def_path_hashes,
"def_path_hash_to_index", &&self.def_path_hash_to_index)
}
}Debug)]
49pub struct Definitions {
50 stable_crate_id: StableCrateId,
51 def_id_to_key: IndexVec<LocalDefId, DefKey>,
52 def_path_hashes: IndexVec<LocalDefId, Hash64>,
54 def_path_hash_to_index: DefPathHashMap,
55}
56
57#[derive(#[automatically_derived]
impl ::core::marker::Copy for DefKey { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DefKey {
#[inline]
fn clone(&self) -> DefKey {
let _: ::core::clone::AssertParamIsClone<Option<DefIndex>>;
let _: ::core::clone::AssertParamIsClone<DisambiguatedDefPathData>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for DefKey {
#[inline]
fn eq(&self, other: &DefKey) -> bool {
self.parent == other.parent &&
self.disambiguated_data == other.disambiguated_data
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for DefKey {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "DefKey",
"parent", &self.parent, "disambiguated_data",
&&self.disambiguated_data)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DefKey {
fn encode(&self, __encoder: &mut __E) {
match *self {
DefKey {
parent: ref __binding_0, disambiguated_data: ref __binding_1
} => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
for DefKey {
fn decode(__decoder: &mut __D) -> Self {
DefKey {
parent: ::rustc_serialize::Decodable::decode(__decoder),
disambiguated_data: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};BlobDecodable)]
61pub struct DefKey {
62 pub parent: Option<DefIndex>,
64
65 pub disambiguated_data: DisambiguatedDefPathData,
67}
68
69impl DefKey {
70 pub(crate) fn compute_stable_hash(&self, parent: DefPathHash) -> DefPathHash {
71 let mut hasher = StableHasher::new();
72
73 parent.local_hash().hash(&mut hasher);
76
77 let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data;
78
79 std::mem::discriminant(data).hash(&mut hasher);
80 if let Some(name) = data.hashed_symbol() {
81 name.as_str().hash(&mut hasher);
84 }
85
86 disambiguator.hash(&mut hasher);
87
88 let local_hash = hasher.finish();
89
90 DefPathHash::new(parent.stable_crate_id(), local_hash)
95 }
96
97 #[inline]
98 pub fn get_opt_name(&self) -> Option<Symbol> {
99 self.disambiguated_data.data.get_opt_name()
100 }
101}
102
103#[derive(#[automatically_derived]
impl ::core::marker::Copy for DisambiguatedDefPathData { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DisambiguatedDefPathData {
#[inline]
fn clone(&self) -> DisambiguatedDefPathData {
let _: ::core::clone::AssertParamIsClone<DefPathData>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for DisambiguatedDefPathData {
#[inline]
fn eq(&self, other: &DisambiguatedDefPathData) -> bool {
self.disambiguator == other.disambiguator && self.data == other.data
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for DisambiguatedDefPathData {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DisambiguatedDefPathData", "data", &self.data, "disambiguator",
&&self.disambiguator)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DisambiguatedDefPathData {
fn encode(&self, __encoder: &mut __E) {
match *self {
DisambiguatedDefPathData {
data: ref __binding_0, disambiguator: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
for DisambiguatedDefPathData {
fn decode(__decoder: &mut __D) -> Self {
DisambiguatedDefPathData {
data: ::rustc_serialize::Decodable::decode(__decoder),
disambiguator: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};BlobDecodable)]
110pub struct DisambiguatedDefPathData {
111 pub data: DefPathData,
112 pub disambiguator: u32,
113}
114
115impl DisambiguatedDefPathData {
116 pub fn as_sym(&self, verbose: bool) -> Symbol {
117 match self.data.name() {
118 DefPathDataName::Named(name) => {
119 if verbose && self.disambiguator != 0 {
120 Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}#{1}", name,
self.disambiguator))
})format!("{}#{}", name, self.disambiguator))
121 } else {
122 name
123 }
124 }
125 DefPathDataName::Anon { namespace } => {
126 if let DefPathData::AnonAssocTy(method) = self.data {
127 Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}::{{{1}#{2}}}", method,
namespace, self.disambiguator))
})format!("{}::{{{}#{}}}", method, namespace, self.disambiguator))
128 } else {
129 Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{{{0}#{1}}}", namespace,
self.disambiguator))
})format!("{{{}#{}}}", namespace, self.disambiguator))
130 }
131 }
132 }
133 }
134}
135
136#[derive(#[automatically_derived]
impl ::core::clone::Clone for DefPath {
#[inline]
fn clone(&self) -> DefPath {
DefPath {
data: ::core::clone::Clone::clone(&self.data),
krate: ::core::clone::Clone::clone(&self.krate),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for DefPath {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "DefPath",
"data", &self.data, "krate", &&self.krate)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DefPath {
fn encode(&self, __encoder: &mut __E) {
match *self {
DefPath { data: ref __binding_0, krate: ref __binding_1 } =>
{
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for DefPath {
fn decode(__decoder: &mut __D) -> Self {
DefPath {
data: ::rustc_serialize::Decodable::decode(__decoder),
krate: ::rustc_serialize::Decodable::decode(__decoder),
}
}
}
};Decodable)]
137pub struct DefPath {
138 pub data: Vec<DisambiguatedDefPathData>,
140
141 pub krate: CrateNum,
143}
144
145impl DefPath {
146 pub fn make<FN>(krate: CrateNum, start_index: DefIndex, mut get_key: FN) -> DefPath
147 where
148 FN: FnMut(DefIndex) -> DefKey,
149 {
150 let mut data = ::alloc::vec::Vec::new()vec![];
151 let mut index = Some(start_index);
152 loop {
153 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/definitions.rs:153",
"rustc_hir::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(153u32),
::tracing_core::__macro_support::Option::Some("rustc_hir::definitions"),
::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!("DefPath::make: krate={0:?} index={1:?}",
krate, index) as &dyn Value))])
});
} else { ; }
};debug!("DefPath::make: krate={:?} index={:?}", krate, index);
154 let p = index.unwrap();
155 let key = get_key(p);
156 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/definitions.rs:156",
"rustc_hir::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(156u32),
::tracing_core::__macro_support::Option::Some("rustc_hir::definitions"),
::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!("DefPath::make: key={0:?}",
key) as &dyn Value))])
});
} else { ; }
};debug!("DefPath::make: key={:?}", key);
157 match key.disambiguated_data.data {
158 DefPathData::CrateRoot => {
159 if !key.parent.is_none() {
::core::panicking::panic("assertion failed: key.parent.is_none()")
};assert!(key.parent.is_none());
160 break;
161 }
162 _ => {
163 data.push(key.disambiguated_data);
164 index = key.parent;
165 }
166 }
167 }
168 data.reverse();
169 DefPath { data, krate }
170 }
171
172 pub fn to_string_no_crate_verbose(&self) -> String {
176 let mut s = String::with_capacity(self.data.len() * 16);
177
178 for component in &self.data {
179 s.write_fmt(format_args!("::{0}", component.as_sym(true)))write!(s, "::{}", component.as_sym(true)).unwrap();
180 }
181
182 s
183 }
184
185 pub fn to_filename_friendly_no_crate(&self) -> String {
189 let mut s = String::with_capacity(self.data.len() * 16);
190
191 let mut opt_delimiter = None;
192 for component in &self.data {
193 s.extend(opt_delimiter);
194 opt_delimiter = Some('-');
195 s.write_fmt(format_args!("{0}", component.as_sym(true)))write!(s, "{}", component.as_sym(true)).unwrap();
196 }
197
198 s
199 }
200}
201
202#[derive(#[automatically_derived]
impl ::core::marker::Copy for DefPathData { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DefPathData {
#[inline]
fn clone(&self) -> DefPathData {
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for DefPathData {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
DefPathData::CrateRoot =>
::core::fmt::Formatter::write_str(f, "CrateRoot"),
DefPathData::Impl => ::core::fmt::Formatter::write_str(f, "Impl"),
DefPathData::ForeignMod =>
::core::fmt::Formatter::write_str(f, "ForeignMod"),
DefPathData::Use => ::core::fmt::Formatter::write_str(f, "Use"),
DefPathData::GlobalAsm =>
::core::fmt::Formatter::write_str(f, "GlobalAsm"),
DefPathData::TypeNs(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "TypeNs",
&__self_0),
DefPathData::ValueNs(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ValueNs", &__self_0),
DefPathData::MacroNs(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"MacroNs", &__self_0),
DefPathData::LifetimeNs(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"LifetimeNs", &__self_0),
DefPathData::Closure =>
::core::fmt::Formatter::write_str(f, "Closure"),
DefPathData::Ctor => ::core::fmt::Formatter::write_str(f, "Ctor"),
DefPathData::AnonConst =>
::core::fmt::Formatter::write_str(f, "AnonConst"),
DefPathData::OpaqueTy =>
::core::fmt::Formatter::write_str(f, "OpaqueTy"),
DefPathData::OpaqueLifetime(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"OpaqueLifetime", &__self_0),
DefPathData::AnonAssocTy(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AnonAssocTy", &__self_0),
DefPathData::SyntheticCoroutineBody =>
::core::fmt::Formatter::write_str(f,
"SyntheticCoroutineBody"),
DefPathData::NestedStatic =>
::core::fmt::Formatter::write_str(f, "NestedStatic"),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for DefPathData {
#[inline]
fn eq(&self, other: &DefPathData) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(DefPathData::TypeNs(__self_0), DefPathData::TypeNs(__arg1_0))
=> __self_0 == __arg1_0,
(DefPathData::ValueNs(__self_0),
DefPathData::ValueNs(__arg1_0)) => __self_0 == __arg1_0,
(DefPathData::MacroNs(__self_0),
DefPathData::MacroNs(__arg1_0)) => __self_0 == __arg1_0,
(DefPathData::LifetimeNs(__self_0),
DefPathData::LifetimeNs(__arg1_0)) => __self_0 == __arg1_0,
(DefPathData::OpaqueLifetime(__self_0),
DefPathData::OpaqueLifetime(__arg1_0)) =>
__self_0 == __arg1_0,
(DefPathData::AnonAssocTy(__self_0),
DefPathData::AnonAssocTy(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DefPathData {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for DefPathData {
#[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 {
DefPathData::TypeNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
DefPathData::ValueNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
DefPathData::MacroNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
DefPathData::LifetimeNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
DefPathData::OpaqueLifetime(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
DefPathData::AnonAssocTy(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
_ => {}
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DefPathData {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
DefPathData::CrateRoot => { 0usize }
DefPathData::Impl => { 1usize }
DefPathData::ForeignMod => { 2usize }
DefPathData::Use => { 3usize }
DefPathData::GlobalAsm => { 4usize }
DefPathData::TypeNs(ref __binding_0) => { 5usize }
DefPathData::ValueNs(ref __binding_0) => { 6usize }
DefPathData::MacroNs(ref __binding_0) => { 7usize }
DefPathData::LifetimeNs(ref __binding_0) => { 8usize }
DefPathData::Closure => { 9usize }
DefPathData::Ctor => { 10usize }
DefPathData::AnonConst => { 11usize }
DefPathData::OpaqueTy => { 12usize }
DefPathData::OpaqueLifetime(ref __binding_0) => { 13usize }
DefPathData::AnonAssocTy(ref __binding_0) => { 14usize }
DefPathData::SyntheticCoroutineBody => { 15usize }
DefPathData::NestedStatic => { 16usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
DefPathData::CrateRoot => {}
DefPathData::Impl => {}
DefPathData::ForeignMod => {}
DefPathData::Use => {}
DefPathData::GlobalAsm => {}
DefPathData::TypeNs(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefPathData::ValueNs(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefPathData::MacroNs(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefPathData::LifetimeNs(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefPathData::Closure => {}
DefPathData::Ctor => {}
DefPathData::AnonConst => {}
DefPathData::OpaqueTy => {}
DefPathData::OpaqueLifetime(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefPathData::AnonAssocTy(ref __binding_0) => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
}
DefPathData::SyntheticCoroutineBody => {}
DefPathData::NestedStatic => {}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
for DefPathData {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { DefPathData::CrateRoot }
1usize => { DefPathData::Impl }
2usize => { DefPathData::ForeignMod }
3usize => { DefPathData::Use }
4usize => { DefPathData::GlobalAsm }
5usize => {
DefPathData::TypeNs(::rustc_serialize::Decodable::decode(__decoder))
}
6usize => {
DefPathData::ValueNs(::rustc_serialize::Decodable::decode(__decoder))
}
7usize => {
DefPathData::MacroNs(::rustc_serialize::Decodable::decode(__decoder))
}
8usize => {
DefPathData::LifetimeNs(::rustc_serialize::Decodable::decode(__decoder))
}
9usize => { DefPathData::Closure }
10usize => { DefPathData::Ctor }
11usize => { DefPathData::AnonConst }
12usize => { DefPathData::OpaqueTy }
13usize => {
DefPathData::OpaqueLifetime(::rustc_serialize::Decodable::decode(__decoder))
}
14usize => {
DefPathData::AnonAssocTy(::rustc_serialize::Decodable::decode(__decoder))
}
15usize => { DefPathData::SyntheticCoroutineBody }
16usize => { DefPathData::NestedStatic }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `DefPathData`, expected 0..17, actual {0}",
n));
}
}
}
}
};BlobDecodable)]
204pub enum DefPathData {
205 CrateRoot,
209
210 Impl,
213 ForeignMod,
215 Use,
217 GlobalAsm,
219 TypeNs(Symbol),
221 ValueNs(Symbol),
223 MacroNs(Symbol),
225 LifetimeNs(Symbol),
227 Closure,
229
230 Ctor,
233 AnonConst,
235 OpaqueTy,
238 OpaqueLifetime(Symbol),
240 AnonAssocTy(Symbol),
243 SyntheticCoroutineBody,
245 NestedStatic,
247}
248
249impl Definitions {
250 #[inline(always)]
251 pub fn def_key(&self, id: LocalDefId) -> DefKey {
252 self.def_id_to_key[id]
253 }
254
255 x;#[instrument(level = "trace", skip(self), ret)]
256 #[inline(always)]
257 pub fn def_path_hash(&self, id: LocalDefId) -> DefPathHash {
258 DefPathHash::new(self.stable_crate_id, self.def_path_hashes[id])
259 }
260
261 #[inline]
267 pub fn def_path(&self, id: LocalDefId) -> DefPath {
268 DefPath::make(LOCAL_CRATE, id.local_def_index, |index| {
269 self.def_key(LocalDefId { local_def_index: index })
270 })
271 }
272
273 pub fn new(stable_crate_id: StableCrateId) -> Definitions {
275 let key = DefKey {
276 parent: None,
277 disambiguated_data: DisambiguatedDefPathData {
278 data: DefPathData::CrateRoot,
279 disambiguator: 0,
280 },
281 };
282
283 let def_path_hash =
292 DefPathHash::new(stable_crate_id, Hash64::new(stable_crate_id.as_u64()));
293
294 let mut defs = Definitions {
295 stable_crate_id,
296 def_path_hashes: Default::default(),
297 def_id_to_key: Default::default(),
298 def_path_hash_to_index: Default::default(),
299 };
300
301 let root = defs.allocate(key, def_path_hash);
303 match (&root.local_def_index, &CRATE_DEF_INDEX) {
(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!(root.local_def_index, CRATE_DEF_INDEX);
304
305 defs
306 }
307
308 fn allocate(&mut self, key: DefKey, def_path_hash: DefPathHash) -> LocalDefId {
309 if true {
match (&self.stable_crate_id, &def_path_hash.stable_crate_id()) {
(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);
}
}
};
};debug_assert_eq!(self.stable_crate_id, def_path_hash.stable_crate_id());
311 let local_hash = def_path_hash.local_hash();
312
313 let def_id = self.def_id_to_key.push(key);
314 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/definitions.rs:314",
"rustc_hir::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(314u32),
::tracing_core::__macro_support::Option::Some("rustc_hir::definitions"),
::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!("def_id_to_key.push() - {1:?} <-> {0:?}",
def_id.local_def_index, key) as &dyn Value))])
});
} else { ; }
};debug!("def_id_to_key.push() - {key:?} <-> {:?}", def_id.local_def_index);
315
316 self.def_path_hashes.push(local_hash);
317 if true {
if !(self.def_path_hashes.len() == self.def_id_to_key.len()) {
::core::panicking::panic("assertion failed: self.def_path_hashes.len() == self.def_id_to_key.len()")
};
};debug_assert!(self.def_path_hashes.len() == self.def_id_to_key.len());
318
319 if let Some(existing) =
322 self.def_path_hash_to_index.insert(&local_hash, &def_id.local_def_index)
323 {
324 let def_path1 = self.def_path(LocalDefId { local_def_index: existing });
325 let def_path2 = self.def_path(def_id);
326
327 {
::core::panicking::panic_fmt(format_args!("found DefPathHash collision between {0:#?} and {1:#?}. Compilation cannot continue.",
def_path1, def_path2));
};panic!(
336 "found DefPathHash collision between {def_path1:#?} and {def_path2:#?}. \
337 Compilation cannot continue."
338 );
339 }
340
341 def_id
342 }
343
344 pub fn enumerated_keys_and_path_hashes(
345 &self,
346 ) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator {
347 self.def_id_to_key
348 .iter_enumerated()
349 .map(move |(def_id, key)| (def_id.local_def_index, key, self.def_path_hash(def_id)))
350 }
351
352 pub fn create_def(
358 &mut self,
359 parent: LocalDefId,
360 data: DefPathData,
361 disambiguator: &mut PerParentDisambiguatorState,
362 ) -> LocalDefId {
363 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/definitions.rs:365",
"rustc_hir::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(365u32),
::tracing_core::__macro_support::Option::Some("rustc_hir::definitions"),
::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!("create_def(parent={0}, data={1:?})",
self.def_path(parent).to_string_no_crate_verbose(), data) as
&dyn Value))])
});
} else { ; }
};debug!(
366 "create_def(parent={}, data={data:?})",
367 self.def_path(parent).to_string_no_crate_verbose(),
368 );
369
370 if !(data != DefPathData::CrateRoot) {
::core::panicking::panic("assertion failed: data != DefPathData::CrateRoot")
};assert!(data != DefPathData::CrateRoot);
372
373 let disambiguator = {
375 #[cfg(debug_assertions)]
376 if true {
match (&parent, &disambiguator.parent.expect("must be set")) {
(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!("provided parent and parent in disambiguator must be the same")));
}
}
};
};debug_assert_eq!(
377 parent,
378 disambiguator.parent.expect("must be set"),
379 "provided parent and parent in disambiguator must be the same"
380 );
381
382 let next_disamb = disambiguator.next.entry(data).or_insert(0);
383 let disambiguator = *next_disamb;
384 *next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
385 disambiguator
386 };
387 let key = DefKey {
388 parent: Some(parent.local_def_index),
389 disambiguated_data: DisambiguatedDefPathData { data, disambiguator },
390 };
391
392 let parent_hash = self.def_path_hash(parent);
393 let def_path_hash = key.compute_stable_hash(parent_hash);
394
395 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/definitions.rs:395",
"rustc_hir::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(395u32),
::tracing_core::__macro_support::Option::Some("rustc_hir::definitions"),
::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!("create_def: after disambiguation, key = {0:?}",
key) as &dyn Value))])
});
} else { ; }
};debug!("create_def: after disambiguation, key = {:?}", key);
396
397 self.allocate(key, def_path_hash)
399 }
400
401 #[inline(always)]
402 pub fn local_def_path_hash_to_def_id(&self, hash: DefPathHash) -> Option<LocalDefId> {
408 if true {
if !(hash.stable_crate_id() == self.stable_crate_id) {
::core::panicking::panic("assertion failed: hash.stable_crate_id() == self.stable_crate_id")
};
};debug_assert!(hash.stable_crate_id() == self.stable_crate_id);
409 self.def_path_hash_to_index
410 .get(&hash.local_hash())
411 .map(|local_def_index| LocalDefId { local_def_index })
412 }
413
414 pub fn def_path_hash_to_def_index_map(&self) -> &DefPathHashMap {
415 &self.def_path_hash_to_index
416 }
417
418 pub fn num_definitions(&self) -> usize {
419 self.def_path_hashes.len()
420 }
421}
422
423#[derive(#[automatically_derived]
impl ::core::marker::Copy for DefPathDataName { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DefPathDataName {
#[inline]
fn clone(&self) -> DefPathDataName {
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for DefPathDataName {
#[inline]
fn eq(&self, other: &DefPathDataName) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(DefPathDataName::Named(__self_0),
DefPathDataName::Named(__arg1_0)) => __self_0 == __arg1_0,
(DefPathDataName::Anon { namespace: __self_0 },
DefPathDataName::Anon { namespace: __arg1_0 }) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for DefPathDataName {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
DefPathDataName::Named(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Named",
&__self_0),
DefPathDataName::Anon { namespace: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Anon",
"namespace", &__self_0),
}
}
}Debug)]
424pub enum DefPathDataName {
425 Named(Symbol),
426 Anon { namespace: Symbol },
427}
428
429impl DefPathData {
430 pub fn get_opt_name(&self) -> Option<Symbol> {
431 use self::DefPathData::*;
432 match *self {
433 TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
434 | OpaqueLifetime(name) => Some(name),
435
436 Impl
437 | ForeignMod
438 | CrateRoot
439 | Use
440 | GlobalAsm
441 | Closure
442 | Ctor
443 | AnonConst
444 | OpaqueTy
445 | AnonAssocTy(..)
446 | SyntheticCoroutineBody
447 | NestedStatic => None,
448 }
449 }
450
451 fn hashed_symbol(&self) -> Option<Symbol> {
452 use self::DefPathData::*;
453 match *self {
454 TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name)
455 | OpaqueLifetime(name) => Some(name),
456
457 Impl
458 | ForeignMod
459 | CrateRoot
460 | Use
461 | GlobalAsm
462 | Closure
463 | Ctor
464 | AnonConst
465 | OpaqueTy
466 | SyntheticCoroutineBody
467 | NestedStatic => None,
468 }
469 }
470
471 pub fn name(&self) -> DefPathDataName {
472 use self::DefPathData::*;
473 match *self {
474 TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
475 | OpaqueLifetime(name) => DefPathDataName::Named(name),
476 CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
478 Impl => DefPathDataName::Anon { namespace: kw::Impl },
479 ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
480 Use => DefPathDataName::Anon { namespace: kw::Use },
481 GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
482 Closure => DefPathDataName::Anon { namespace: sym::closure },
483 Ctor => DefPathDataName::Anon { namespace: sym::constructor },
484 AnonConst => DefPathDataName::Anon { namespace: sym::constant },
485 OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
486 AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
487 SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
488 NestedStatic => DefPathDataName::Anon { namespace: sym::nested },
489 }
490 }
491}
492
493impl fmt::Display for DefPathData {
494 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
495 match self.name() {
496 DefPathDataName::Named(name) => f.write_str(name.as_str()),
497 DefPathDataName::Anon { namespace } => f.write_fmt(format_args!("{{{{{0}}}}}", namespace))write!(f, "{{{{{namespace}}}}}"),
499 }
500 }
501}