1
Fork 0

rustc_metadata: Stop passing CrateMetadataRef by reference

It's already a (fat) reference.
Double referencing it creates lifetime issues for its methods that want to return iterators.
This commit is contained in:
Vadim Petrochenkov 2021-12-24 14:34:30 +08:00
parent e19ca1d946
commit c4471b0b9c

View file

@ -218,40 +218,40 @@ impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a MetadataBlob, &'tcx Session) {
} }
} }
impl<'a, 'tcx> Metadata<'a, 'tcx> for &'a CrateMetadataRef<'a> { impl<'a, 'tcx> Metadata<'a, 'tcx> for CrateMetadataRef<'a> {
#[inline] #[inline]
fn blob(self) -> &'a MetadataBlob { fn blob(self) -> &'a MetadataBlob {
&self.blob &self.cdata.blob
} }
#[inline] #[inline]
fn cdata(self) -> Option<CrateMetadataRef<'a>> { fn cdata(self) -> Option<CrateMetadataRef<'a>> {
Some(*self) Some(self)
} }
} }
impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadataRef<'a>, &'tcx Session) { impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, &'tcx Session) {
#[inline] #[inline]
fn blob(self) -> &'a MetadataBlob { fn blob(self) -> &'a MetadataBlob {
&self.0.blob &self.0.cdata.blob
} }
#[inline] #[inline]
fn cdata(self) -> Option<CrateMetadataRef<'a>> { fn cdata(self) -> Option<CrateMetadataRef<'a>> {
Some(*self.0) Some(self.0)
} }
#[inline] #[inline]
fn sess(self) -> Option<&'tcx Session> { fn sess(self) -> Option<&'tcx Session> {
Some(&self.1) Some(self.1)
} }
} }
impl<'a, 'tcx> Metadata<'a, 'tcx> for (&'a CrateMetadataRef<'a>, TyCtxt<'tcx>) { impl<'a, 'tcx> Metadata<'a, 'tcx> for (CrateMetadataRef<'a>, TyCtxt<'tcx>) {
#[inline] #[inline]
fn blob(self) -> &'a MetadataBlob { fn blob(self) -> &'a MetadataBlob {
&self.0.blob &self.0.cdata.blob
} }
#[inline] #[inline]
fn cdata(self) -> Option<CrateMetadataRef<'a>> { fn cdata(self) -> Option<CrateMetadataRef<'a>> {
Some(*self.0) Some(self.0)
} }
#[inline] #[inline]
fn tcx(self) -> Option<TyCtxt<'tcx>> { fn tcx(self) -> Option<TyCtxt<'tcx>> {
@ -414,9 +414,9 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
Ok(cdata Ok(cdata
.root .root
.syntax_contexts .syntax_contexts
.get(&cdata, id) .get(cdata, id)
.unwrap_or_else(|| panic!("Missing SyntaxContext {:?} for crate {:?}", id, cname)) .unwrap_or_else(|| panic!("Missing SyntaxContext {:?} for crate {:?}", id, cname))
.decode((&cdata, sess))) .decode((cdata, sess)))
}) })
} }
} }
@ -442,15 +442,15 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
let expn_data = crate_data let expn_data = crate_data
.root .root
.expn_data .expn_data
.get(&crate_data, index) .get(crate_data, index)
.unwrap() .unwrap()
.decode((&crate_data, sess)); .decode((crate_data, sess));
let expn_hash = crate_data let expn_hash = crate_data
.root .root
.expn_hashes .expn_hashes
.get(&crate_data, index) .get(crate_data, index)
.unwrap() .unwrap()
.decode((&crate_data, sess)); .decode((crate_data, sess));
(expn_data, expn_hash) (expn_data, expn_hash)
}); });
Ok(expn_id) Ok(expn_id)
@ -706,7 +706,7 @@ impl CrateRoot<'_> {
} }
impl<'a, 'tcx> CrateMetadataRef<'a> { impl<'a, 'tcx> CrateMetadataRef<'a> {
fn raw_proc_macro(&self, id: DefIndex) -> &ProcMacro { fn raw_proc_macro(self, id: DefIndex) -> &'a ProcMacro {
// DefIndex's in root.proc_macro_data have a one-to-one correspondence // DefIndex's in root.proc_macro_data have a one-to-one correspondence
// with items in 'raw_proc_macros'. // with items in 'raw_proc_macros'.
let pos = self let pos = self
@ -721,7 +721,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
&self.raw_proc_macros.unwrap()[pos] &self.raw_proc_macros.unwrap()[pos]
} }
fn opt_item_ident(&self, item_index: DefIndex, sess: &Session) -> Option<Ident> { fn opt_item_ident(self, item_index: DefIndex, sess: &Session) -> Option<Ident> {
let name = self.def_key(item_index).disambiguated_data.data.get_opt_name()?; let name = self.def_key(item_index).disambiguated_data.data.get_opt_name()?;
let span = match self.root.tables.ident_span.get(self, item_index) { let span = match self.root.tables.ident_span.get(self, item_index) {
Some(lazy_span) => lazy_span.decode((self, sess)), Some(lazy_span) => lazy_span.decode((self, sess)),
@ -737,15 +737,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
Some(Ident::new(name, span)) Some(Ident::new(name, span))
} }
fn item_ident(&self, item_index: DefIndex, sess: &Session) -> Ident { fn item_ident(self, item_index: DefIndex, sess: &Session) -> Ident {
self.opt_item_ident(item_index, sess).expect("no encoded ident for item") self.opt_item_ident(item_index, sess).expect("no encoded ident for item")
} }
fn maybe_kind(&self, item_id: DefIndex) -> Option<EntryKind> { fn maybe_kind(self, item_id: DefIndex) -> Option<EntryKind> {
self.root.tables.kind.get(self, item_id).map(|k| k.decode(self)) self.root.tables.kind.get(self, item_id).map(|k| k.decode(self))
} }
fn kind(&self, item_id: DefIndex) -> EntryKind { fn kind(self, item_id: DefIndex) -> EntryKind {
self.maybe_kind(item_id).unwrap_or_else(|| { self.maybe_kind(item_id).unwrap_or_else(|| {
bug!( bug!(
"CrateMetadata::kind({:?}): id not found, in crate {:?} with number {}", "CrateMetadata::kind({:?}): id not found, in crate {:?} with number {}",
@ -756,7 +756,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}) })
} }
fn def_kind(&self, item_id: DefIndex) -> DefKind { fn def_kind(self, item_id: DefIndex) -> DefKind {
self.root.tables.def_kind.get(self, item_id).map(|k| k.decode(self)).unwrap_or_else(|| { self.root.tables.def_kind.get(self, item_id).map(|k| k.decode(self)).unwrap_or_else(|| {
bug!( bug!(
"CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}", "CrateMetadata::def_kind({:?}): id not found, in crate {:?} with number {}",
@ -767,7 +767,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}) })
} }
fn get_span(&self, index: DefIndex, sess: &Session) -> Span { fn get_span(self, index: DefIndex, sess: &Session) -> Span {
self.root self.root
.tables .tables
.span .span
@ -776,7 +776,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, sess)) .decode((self, sess))
} }
fn load_proc_macro(&self, id: DefIndex, sess: &Session) -> SyntaxExtension { fn load_proc_macro(self, id: DefIndex, sess: &Session) -> SyntaxExtension {
let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) { let (name, kind, helper_attrs) = match *self.raw_proc_macro(id) {
ProcMacro::CustomDerive { trait_name, attributes, client } => { ProcMacro::CustomDerive { trait_name, attributes, client } => {
let helper_attrs = let helper_attrs =
@ -807,7 +807,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
) )
} }
fn get_trait_def(&self, item_id: DefIndex, sess: &Session) -> ty::TraitDef { fn get_trait_def(self, item_id: DefIndex, sess: &Session) -> ty::TraitDef {
match self.kind(item_id) { match self.kind(item_id) {
EntryKind::Trait(data) => { EntryKind::Trait(data) => {
let data = data.decode((self, sess)); let data = data.decode((self, sess));
@ -837,7 +837,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_variant( fn get_variant(
&self, self,
kind: &EntryKind, kind: &EntryKind,
index: DefIndex, index: DefIndex,
parent_did: DefId, parent_did: DefId,
@ -886,7 +886,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
) )
} }
fn get_adt_def(&self, item_id: DefIndex, tcx: TyCtxt<'tcx>) -> &'tcx ty::AdtDef { fn get_adt_def(self, item_id: DefIndex, tcx: TyCtxt<'tcx>) -> &'tcx ty::AdtDef {
let kind = self.kind(item_id); let kind = self.kind(item_id);
let did = self.local_def_id(item_id); let did = self.local_def_id(item_id);
@ -914,7 +914,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_explicit_predicates( fn get_explicit_predicates(
&self, self,
item_id: DefIndex, item_id: DefIndex,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> { ) -> ty::GenericPredicates<'tcx> {
@ -922,7 +922,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_inferred_outlives( fn get_inferred_outlives(
&self, self,
item_id: DefIndex, item_id: DefIndex,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> &'tcx [(ty::Predicate<'tcx>, Span)] { ) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
@ -935,7 +935,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_super_predicates( fn get_super_predicates(
&self, self,
item_id: DefIndex, item_id: DefIndex,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> ty::GenericPredicates<'tcx> { ) -> ty::GenericPredicates<'tcx> {
@ -943,7 +943,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_explicit_item_bounds( fn get_explicit_item_bounds(
&self, self,
item_id: DefIndex, item_id: DefIndex,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> &'tcx [(ty::Predicate<'tcx>, Span)] { ) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
@ -955,11 +955,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.unwrap_or_default() .unwrap_or_default()
} }
fn get_generics(&self, item_id: DefIndex, sess: &Session) -> ty::Generics { fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics {
self.root.tables.generics.get(self, item_id).unwrap().decode((self, sess)) self.root.tables.generics.get(self, item_id).unwrap().decode((self, sess))
} }
fn get_type(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { fn get_type(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
self.root self.root
.tables .tables
.ty .ty
@ -968,63 +968,63 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, tcx)) .decode((self, tcx))
} }
fn get_stability(&self, id: DefIndex) -> Option<attr::Stability> { fn get_stability(self, id: DefIndex) -> Option<attr::Stability> {
self.root.tables.stability.get(self, id).map(|stab| stab.decode(self)) self.root.tables.stability.get(self, id).map(|stab| stab.decode(self))
} }
fn get_const_stability(&self, id: DefIndex) -> Option<attr::ConstStability> { fn get_const_stability(self, id: DefIndex) -> Option<attr::ConstStability> {
self.root.tables.const_stability.get(self, id).map(|stab| stab.decode(self)) self.root.tables.const_stability.get(self, id).map(|stab| stab.decode(self))
} }
fn get_deprecation(&self, id: DefIndex) -> Option<attr::Deprecation> { fn get_deprecation(self, id: DefIndex) -> Option<attr::Deprecation> {
self.root.tables.deprecation.get(self, id).map(|depr| depr.decode(self)) self.root.tables.deprecation.get(self, id).map(|depr| depr.decode(self))
} }
fn get_visibility(&self, id: DefIndex) -> ty::Visibility { fn get_visibility(self, id: DefIndex) -> ty::Visibility {
self.root.tables.visibility.get(self, id).unwrap().decode(self) self.root.tables.visibility.get(self, id).unwrap().decode(self)
} }
fn get_impl_data(&self, id: DefIndex) -> ImplData { fn get_impl_data(self, id: DefIndex) -> ImplData {
match self.kind(id) { match self.kind(id) {
EntryKind::Impl(data) => data.decode(self), EntryKind::Impl(data) => data.decode(self),
_ => bug!(), _ => bug!(),
} }
} }
fn get_parent_impl(&self, id: DefIndex) -> Option<DefId> { fn get_parent_impl(self, id: DefIndex) -> Option<DefId> {
self.get_impl_data(id).parent_impl self.get_impl_data(id).parent_impl
} }
fn get_impl_polarity(&self, id: DefIndex) -> ty::ImplPolarity { fn get_impl_polarity(self, id: DefIndex) -> ty::ImplPolarity {
self.get_impl_data(id).polarity self.get_impl_data(id).polarity
} }
fn get_impl_defaultness(&self, id: DefIndex) -> hir::Defaultness { fn get_impl_defaultness(self, id: DefIndex) -> hir::Defaultness {
self.get_impl_data(id).defaultness self.get_impl_data(id).defaultness
} }
fn get_impl_constness(&self, id: DefIndex) -> hir::Constness { fn get_impl_constness(self, id: DefIndex) -> hir::Constness {
self.get_impl_data(id).constness self.get_impl_data(id).constness
} }
fn get_trait_item_def_id(&self, id: DefIndex) -> Option<DefId> { fn get_trait_item_def_id(self, id: DefIndex) -> Option<DefId> {
self.root.tables.trait_item_def_id.get(self, id).map(|d| d.decode(self)) self.root.tables.trait_item_def_id.get(self, id).map(|d| d.decode(self))
} }
fn get_coerce_unsized_info(&self, id: DefIndex) -> Option<ty::adjustment::CoerceUnsizedInfo> { fn get_coerce_unsized_info(self, id: DefIndex) -> Option<ty::adjustment::CoerceUnsizedInfo> {
self.get_impl_data(id).coerce_unsized_info self.get_impl_data(id).coerce_unsized_info
} }
fn get_impl_trait(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> { fn get_impl_trait(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> {
self.root.tables.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx))) self.root.tables.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
} }
fn get_expn_that_defined(&self, id: DefIndex, sess: &Session) -> ExpnId { fn get_expn_that_defined(self, id: DefIndex, sess: &Session) -> ExpnId {
self.root.tables.expn_that_defined.get(self, id).unwrap().decode((self, sess)) self.root.tables.expn_that_defined.get(self, id).unwrap().decode((self, sess))
} }
fn get_const_param_default( fn get_const_param_default(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
id: DefIndex, id: DefIndex,
) -> rustc_middle::ty::Const<'tcx> { ) -> rustc_middle::ty::Const<'tcx> {
@ -1032,14 +1032,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
/// Iterates over all the stability attributes in the given crate. /// Iterates over all the stability attributes in the given crate.
fn get_lib_features(&self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Option<Symbol>)] { fn get_lib_features(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Option<Symbol>)] {
// FIXME: For a proc macro crate, not sure whether we should return the "host" // FIXME: For a proc macro crate, not sure whether we should return the "host"
// features or an empty Vec. Both don't cause ICEs. // features or an empty Vec. Both don't cause ICEs.
tcx.arena.alloc_from_iter(self.root.lib_features.decode(self)) tcx.arena.alloc_from_iter(self.root.lib_features.decode(self))
} }
/// Iterates over the language items in the given crate. /// Iterates over the language items in the given crate.
fn get_lang_items(&self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] { fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
if self.root.is_proc_macro_crate() { if self.root.is_proc_macro_crate() {
// Proc macro crates do not export any lang-items to the target. // Proc macro crates do not export any lang-items to the target.
&[] &[]
@ -1054,7 +1054,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
/// Iterates over the diagnostic items in the given crate. /// Iterates over the diagnostic items in the given crate.
fn get_diagnostic_items(&self) -> DiagnosticItems { fn get_diagnostic_items(self) -> DiagnosticItems {
if self.root.is_proc_macro_crate() { if self.root.is_proc_macro_crate() {
// Proc macro crates do not export any diagnostic-items to the target. // Proc macro crates do not export any diagnostic-items to the target.
Default::default() Default::default()
@ -1079,7 +1079,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
/// Module here is understood in name resolution sense - it can be a `mod` item, /// Module here is understood in name resolution sense - it can be a `mod` item,
/// or a crate root, or an enum, or a trait. /// or a crate root, or an enum, or a trait.
fn for_each_module_child( fn for_each_module_child(
&self, self,
id: DefIndex, id: DefIndex,
mut callback: impl FnMut(ModChild), mut callback: impl FnMut(ModChild),
sess: &Session, sess: &Session,
@ -1177,15 +1177,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn is_ctfe_mir_available(&self, id: DefIndex) -> bool { fn is_ctfe_mir_available(self, id: DefIndex) -> bool {
self.root.tables.mir_for_ctfe.get(self, id).is_some() self.root.tables.mir_for_ctfe.get(self, id).is_some()
} }
fn is_item_mir_available(&self, id: DefIndex) -> bool { fn is_item_mir_available(self, id: DefIndex) -> bool {
self.root.tables.mir.get(self, id).is_some() self.root.tables.mir.get(self, id).is_some()
} }
fn module_expansion(&self, id: DefIndex, sess: &Session) -> ExpnId { fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
match self.kind(id) { match self.kind(id) {
EntryKind::Mod(_) | EntryKind::Enum(_) | EntryKind::Trait(_) => { EntryKind::Mod(_) | EntryKind::Enum(_) | EntryKind::Trait(_) => {
self.get_expn_that_defined(id, sess) self.get_expn_that_defined(id, sess)
@ -1194,7 +1194,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> { fn get_optimized_mir(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
self.root self.root
.tables .tables
.mir .mir
@ -1205,7 +1205,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, tcx)) .decode((self, tcx))
} }
fn get_mir_for_ctfe(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> { fn get_mir_for_ctfe(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> Body<'tcx> {
self.root self.root
.tables .tables
.mir_for_ctfe .mir_for_ctfe
@ -1217,7 +1217,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_thir_abstract_const( fn get_thir_abstract_const(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
id: DefIndex, id: DefIndex,
) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> { ) -> Result<Option<&'tcx [thir::abstract_const::Node<'tcx>]>, ErrorReported> {
@ -1228,7 +1228,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx))))) .map_or(Ok(None), |v| Ok(Some(v.decode((self, tcx)))))
} }
fn get_unused_generic_params(&self, id: DefIndex) -> FiniteBitSet<u32> { fn get_unused_generic_params(self, id: DefIndex) -> FiniteBitSet<u32> {
self.root self.root
.tables .tables
.unused_generic_params .unused_generic_params
@ -1237,7 +1237,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.unwrap_or_default() .unwrap_or_default()
} }
fn get_promoted_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec<Promoted, Body<'tcx>> { fn get_promoted_mir(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> IndexVec<Promoted, Body<'tcx>> {
self.root self.root
.tables .tables
.promoted_mir .promoted_mir
@ -1248,7 +1248,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, tcx)) .decode((self, tcx))
} }
fn mir_const_qualif(&self, id: DefIndex) -> mir::ConstQualifs { fn mir_const_qualif(self, id: DefIndex) -> mir::ConstQualifs {
match self.kind(id) { match self.kind(id) {
EntryKind::AnonConst(qualif, _) EntryKind::AnonConst(qualif, _)
| EntryKind::Const(qualif, _) | EntryKind::Const(qualif, _)
@ -1263,14 +1263,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_fn_has_self_parameter(&self, id: DefIndex) -> bool { fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
match self.kind(id) { match self.kind(id) {
EntryKind::AssocFn(data) => data.decode(self).has_self, EntryKind::AssocFn(data) => data.decode(self).has_self,
_ => false, _ => false,
} }
} }
fn get_associated_item_def_ids(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [DefId] { fn get_associated_item_def_ids(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [DefId] {
if let Some(children) = self.root.tables.children.get(self, id) { if let Some(children) = self.root.tables.children.get(self, id) {
tcx.arena.alloc_from_iter( tcx.arena.alloc_from_iter(
children.decode((self, tcx.sess)).map(|child_index| self.local_def_id(child_index)), children.decode((self, tcx.sess)).map(|child_index| self.local_def_id(child_index)),
@ -1280,7 +1280,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_associated_item(&self, id: DefIndex, sess: &Session) -> ty::AssocItem { fn get_associated_item(self, id: DefIndex, sess: &Session) -> ty::AssocItem {
let def_key = self.def_key(id); let def_key = self.def_key(id);
let parent = self.local_def_id(def_key.parent.unwrap()); let parent = self.local_def_id(def_key.parent.unwrap());
let ident = self.item_ident(id, sess); let ident = self.item_ident(id, sess);
@ -1307,11 +1307,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_item_variances(&'a self, id: DefIndex) -> impl Iterator<Item = ty::Variance> + 'a { fn get_item_variances(self, id: DefIndex) -> impl Iterator<Item = ty::Variance> + 'a {
self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self) self.root.tables.variances.get(self, id).unwrap_or_else(Lazy::empty).decode(self)
} }
fn get_ctor_def_id_and_kind(&self, node_id: DefIndex) -> Option<(DefId, CtorKind)> { fn get_ctor_def_id_and_kind(self, node_id: DefIndex) -> Option<(DefId, CtorKind)> {
match self.kind(node_id) { match self.kind(node_id) {
EntryKind::Struct(data, _) | EntryKind::Variant(data) => { EntryKind::Struct(data, _) | EntryKind::Variant(data) => {
let vdata = data.decode(self); let vdata = data.decode(self);
@ -1322,7 +1322,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_item_attrs( fn get_item_attrs(
&'a self, self,
id: DefIndex, id: DefIndex,
sess: &'a Session, sess: &'a Session,
) -> impl Iterator<Item = ast::Attribute> + 'a { ) -> impl Iterator<Item = ast::Attribute> + 'a {
@ -1346,7 +1346,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, sess)) .decode((self, sess))
} }
fn get_struct_field_names(&self, id: DefIndex, sess: &Session) -> Vec<Spanned<Symbol>> { fn get_struct_field_names(self, id: DefIndex, sess: &Session) -> Vec<Spanned<Symbol>> {
self.root self.root
.tables .tables
.children .children
@ -1357,7 +1357,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.collect() .collect()
} }
fn get_struct_field_visibilities(&self, id: DefIndex) -> Vec<Visibility> { fn get_struct_field_visibilities(self, id: DefIndex) -> Vec<Visibility> {
self.root self.root
.tables .tables
.children .children
@ -1369,7 +1369,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_inherent_implementations_for_type( fn get_inherent_implementations_for_type(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
id: DefIndex, id: DefIndex,
) -> &'tcx [DefId] { ) -> &'tcx [DefId] {
@ -1384,20 +1384,20 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
) )
} }
fn get_traits(&'a self) -> impl Iterator<Item = DefId> + 'a { fn get_traits(self) -> impl Iterator<Item = DefId> + 'a {
self.root.traits.decode(self).map(|index| self.local_def_id(index)) self.root.traits.decode(self).map(move |index| self.local_def_id(index))
} }
fn get_trait_impls(&'a self) -> impl Iterator<Item = (DefId, Option<SimplifiedType>)> + 'a { fn get_trait_impls(self) -> impl Iterator<Item = (DefId, Option<SimplifiedType>)> + 'a {
self.trait_impls.values().flat_map(move |impls| { self.cdata.trait_impls.values().flat_map(move |impls| {
impls impls
.decode(self) .decode(self)
.map(|(idx, simplified_self_ty)| (self.local_def_id(idx), simplified_self_ty)) .map(move |(idx, simplified_self_ty)| (self.local_def_id(idx), simplified_self_ty))
}) })
} }
fn get_implementations_of_trait( fn get_implementations_of_trait(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
trait_def_id: DefId, trait_def_id: DefId,
) -> &'tcx [(DefId, Option<SimplifiedType>)] { ) -> &'tcx [(DefId, Option<SimplifiedType>)] {
@ -1424,7 +1424,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_trait_of_item(&self, id: DefIndex) -> Option<DefId> { fn get_trait_of_item(self, id: DefIndex) -> Option<DefId> {
let def_key = self.def_key(id); let def_key = self.def_key(id);
match def_key.disambiguated_data.data { match def_key.disambiguated_data.data {
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) => (), DefPathData::TypeNs(..) | DefPathData::ValueNs(..) => (),
@ -1437,7 +1437,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}) })
} }
fn get_native_libraries(&self, sess: &Session) -> Vec<NativeLib> { fn get_native_libraries(self, sess: &Session) -> Vec<NativeLib> {
if self.root.is_proc_macro_crate() { if self.root.is_proc_macro_crate() {
// Proc macro crates do not have any *target* native libraries. // Proc macro crates do not have any *target* native libraries.
vec![] vec![]
@ -1446,7 +1446,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_proc_macro_quoted_span(&self, index: usize, sess: &Session) -> Span { fn get_proc_macro_quoted_span(self, index: usize, sess: &Session) -> Span {
self.root self.root
.tables .tables
.proc_macro_quoted_spans .proc_macro_quoted_spans
@ -1455,7 +1455,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode((self, sess)) .decode((self, sess))
} }
fn get_foreign_modules(&self, tcx: TyCtxt<'tcx>) -> Lrc<FxHashMap<DefId, ForeignModule>> { fn get_foreign_modules(self, tcx: TyCtxt<'tcx>) -> Lrc<FxHashMap<DefId, ForeignModule>> {
if self.root.is_proc_macro_crate() { if self.root.is_proc_macro_crate() {
// Proc macro crates do not have any *target* foreign modules. // Proc macro crates do not have any *target* foreign modules.
Lrc::new(FxHashMap::default()) Lrc::new(FxHashMap::default())
@ -1467,7 +1467,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn get_dylib_dependency_formats( fn get_dylib_dependency_formats(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> &'tcx [(CrateNum, LinkagePreference)] { ) -> &'tcx [(CrateNum, LinkagePreference)] {
tcx.arena.alloc_from_iter( tcx.arena.alloc_from_iter(
@ -1478,7 +1478,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
) )
} }
fn get_missing_lang_items(&self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangItem] { fn get_missing_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [lang_items::LangItem] {
if self.root.is_proc_macro_crate() { if self.root.is_proc_macro_crate() {
// Proc macro crates do not depend on any target weak lang-items. // Proc macro crates do not depend on any target weak lang-items.
&[] &[]
@ -1487,7 +1487,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_fn_param_names(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] { fn get_fn_param_names(self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] {
let param_names = match self.kind(id) { let param_names = match self.kind(id) {
EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names, EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names,
EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names, EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names,
@ -1497,7 +1497,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
fn exported_symbols( fn exported_symbols(
&self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
if self.root.is_proc_macro_crate() { if self.root.is_proc_macro_crate() {
@ -1509,7 +1509,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_rendered_const(&self, id: DefIndex) -> String { fn get_rendered_const(self, id: DefIndex) -> String {
match self.kind(id) { match self.kind(id) {
EntryKind::AnonConst(_, data) EntryKind::AnonConst(_, data)
| EntryKind::Const(_, data) | EntryKind::Const(_, data)
@ -1518,7 +1518,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn get_macro(&self, id: DefIndex, sess: &Session) -> MacroDef { fn get_macro(self, id: DefIndex, sess: &Session) -> MacroDef {
match self.kind(id) { match self.kind(id) {
EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)), EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)),
_ => bug!(), _ => bug!(),
@ -1527,7 +1527,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
// This replicates some of the logic of the crate-local `is_const_fn_raw` query, because we // This replicates some of the logic of the crate-local `is_const_fn_raw` query, because we
// don't serialize constness for tuple variant and tuple struct constructors. // don't serialize constness for tuple variant and tuple struct constructors.
fn is_const_fn_raw(&self, id: DefIndex) -> bool { fn is_const_fn_raw(self, id: DefIndex) -> bool {
let constness = match self.kind(id) { let constness = match self.kind(id) {
EntryKind::AssocFn(data) => data.decode(self).fn_data.constness, EntryKind::AssocFn(data) => data.decode(self).fn_data.constness,
EntryKind::Fn(data) => data.decode(self).constness, EntryKind::Fn(data) => data.decode(self).constness,
@ -1538,7 +1538,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
constness == hir::Constness::Const constness == hir::Constness::Const
} }
fn asyncness(&self, id: DefIndex) -> hir::IsAsync { fn asyncness(self, id: DefIndex) -> hir::IsAsync {
match self.kind(id) { match self.kind(id) {
EntryKind::Fn(data) => data.decode(self).asyncness, EntryKind::Fn(data) => data.decode(self).asyncness,
EntryKind::AssocFn(data) => data.decode(self).fn_data.asyncness, EntryKind::AssocFn(data) => data.decode(self).fn_data.asyncness,
@ -1547,7 +1547,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn is_foreign_item(&self, id: DefIndex) -> bool { fn is_foreign_item(self, id: DefIndex) -> bool {
match self.kind(id) { match self.kind(id) {
EntryKind::ForeignImmStatic | EntryKind::ForeignMutStatic | EntryKind::ForeignFn(_) => { EntryKind::ForeignImmStatic | EntryKind::ForeignMutStatic | EntryKind::ForeignFn(_) => {
true true
@ -1556,7 +1556,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn static_mutability(&self, id: DefIndex) -> Option<hir::Mutability> { fn static_mutability(self, id: DefIndex) -> Option<hir::Mutability> {
match self.kind(id) { match self.kind(id) {
EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Some(hir::Mutability::Not), EntryKind::ImmStatic | EntryKind::ForeignImmStatic => Some(hir::Mutability::Not),
EntryKind::MutStatic | EntryKind::ForeignMutStatic => Some(hir::Mutability::Mut), EntryKind::MutStatic | EntryKind::ForeignMutStatic => Some(hir::Mutability::Mut),
@ -1564,19 +1564,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} }
fn generator_kind(&self, id: DefIndex) -> Option<hir::GeneratorKind> { fn generator_kind(self, id: DefIndex) -> Option<hir::GeneratorKind> {
match self.kind(id) { match self.kind(id) {
EntryKind::Generator(data) => Some(data), EntryKind::Generator(data) => Some(data),
_ => None, _ => None,
} }
} }
fn fn_sig(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> { fn fn_sig(self, id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
self.root.tables.fn_sig.get(self, id).unwrap().decode((self, tcx)) self.root.tables.fn_sig.get(self, id).unwrap().decode((self, tcx))
} }
#[inline] #[inline]
fn def_key(&self, index: DefIndex) -> DefKey { fn def_key(self, index: DefIndex) -> DefKey {
*self *self
.def_key_cache .def_key_cache
.lock() .lock()
@ -1585,13 +1585,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
// Returns the path leading to the thing with this `id`. // Returns the path leading to the thing with this `id`.
fn def_path(&self, id: DefIndex) -> DefPath { fn def_path(self, id: DefIndex) -> DefPath {
debug!("def_path(cnum={:?}, id={:?})", self.cnum, id); debug!("def_path(cnum={:?}, id={:?})", self.cnum, id);
DefPath::make(self.cnum, id, |parent| self.def_key(parent)) DefPath::make(self.cnum, id, |parent| self.def_key(parent))
} }
fn def_path_hash_unlocked( fn def_path_hash_unlocked(
&self, self,
index: DefIndex, index: DefIndex,
def_path_hashes: &mut FxHashMap<DefIndex, DefPathHash>, def_path_hashes: &mut FxHashMap<DefIndex, DefPathHash>,
) -> DefPathHash { ) -> DefPathHash {
@ -1601,17 +1601,17 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
#[inline] #[inline]
fn def_path_hash(&self, index: DefIndex) -> DefPathHash { fn def_path_hash(self, index: DefIndex) -> DefPathHash {
let mut def_path_hashes = self.def_path_hash_cache.lock(); let mut def_path_hashes = self.def_path_hash_cache.lock();
self.def_path_hash_unlocked(index, &mut def_path_hashes) self.def_path_hash_unlocked(index, &mut def_path_hashes)
} }
#[inline] #[inline]
fn def_path_hash_to_def_index(&self, hash: DefPathHash) -> DefIndex { fn def_path_hash_to_def_index(self, hash: DefPathHash) -> DefIndex {
self.def_path_hash_map.def_path_hash_to_def_index(&hash) self.def_path_hash_map.def_path_hash_to_def_index(&hash)
} }
fn expn_hash_to_expn_id(&self, sess: &Session, index_guess: u32, hash: ExpnHash) -> ExpnId { fn expn_hash_to_expn_id(self, sess: &Session, index_guess: u32, hash: ExpnHash) -> ExpnId {
debug_assert_eq!(ExpnId::from_hash(hash), None); debug_assert_eq!(ExpnId::from_hash(hash), None);
let index_guess = ExpnIndex::from_u32(index_guess); let index_guess = ExpnIndex::from_u32(index_guess);
let old_hash = self.root.expn_hashes.get(self, index_guess).map(|lazy| lazy.decode(self)); let old_hash = self.root.expn_hashes.get(self, index_guess).map(|lazy| lazy.decode(self));
@ -1669,7 +1669,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
/// ///
/// Proc macro crates don't currently export spans, so this function does not have /// Proc macro crates don't currently export spans, so this function does not have
/// to work for them. /// to work for them.
fn imported_source_files(&self, sess: &Session) -> &'a [ImportedSourceFile] { fn imported_source_files(self, sess: &Session) -> &'a [ImportedSourceFile] {
// Translate the virtual `/rustc/$hash` prefix back to a real directory // Translate the virtual `/rustc/$hash` prefix back to a real directory
// that should hold actual sources, where possible. // that should hold actual sources, where possible.
// //