rustc_metadata: use a table for impl_trait_ref.

This commit is contained in:
Eduard-Mihai Burtescu 2019-10-19 01:10:58 +03:00
parent 7a80a11a83
commit 371cc39b25
3 changed files with 13 additions and 6 deletions

View file

@ -711,7 +711,7 @@ impl<'a, 'tcx> CrateMetadata {
}
}
fn get_impl_data(&self, id: DefIndex) -> ImplData<'tcx> {
fn get_impl_data(&self, id: DefIndex) -> ImplData {
match self.kind(id) {
EntryKind::Impl(data) => data.decode(self),
_ => bug!(),
@ -738,7 +738,7 @@ impl<'a, 'tcx> CrateMetadata {
}
crate fn get_impl_trait(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> {
self.get_impl_data(id).trait_ref.map(|tr| tr.decode((self, tcx)))
self.root.per_def.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
}
/// Iterates over all the stability attributes in the given crate.

View file

@ -72,6 +72,7 @@ struct PerDefTables<'tcx> {
ty: PerDefTable<Lazy<Ty<'tcx>>>,
fn_sig: PerDefTable<Lazy<ty::PolyFnSig<'tcx>>>,
impl_trait_ref: PerDefTable<Lazy<ty::TraitRef<'tcx>>>,
inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
variances: PerDefTable<Lazy<[ty::Variance]>>,
generics: PerDefTable<Lazy<ty::Generics>>,
@ -511,6 +512,7 @@ impl<'tcx> EncodeContext<'tcx> {
ty: self.per_def.ty.encode(&mut self.opaque),
fn_sig: self.per_def.fn_sig.encode(&mut self.opaque),
impl_trait_ref: self.per_def.impl_trait_ref.encode(&mut self.opaque),
inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
variances: self.per_def.variances.encode(&mut self.opaque),
generics: self.per_def.generics.encode(&mut self.opaque),
@ -1152,7 +1154,6 @@ impl EncodeContext<'tcx> {
defaultness,
parent_impl: parent,
coerce_unsized_info,
trait_ref: trait_ref.map(|trait_ref| self.lazy(trait_ref)),
};
EntryKind::Impl(self.lazy(data))
@ -1226,6 +1227,11 @@ impl EncodeContext<'tcx> {
if let hir::ItemKind::Fn(..) = item.kind {
record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id));
}
if let hir::ItemKind::Impl(..) = item.kind {
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
record!(self.per_def.impl_trait_ref[def_id] <- trait_ref);
}
}
self.encode_inherent_implementations(def_id);
match item.kind {
hir::ItemKind::Enum(..) |

View file

@ -239,6 +239,7 @@ crate struct LazyPerDefTables<'tcx> {
pub ty: Lazy!(PerDefTable<Lazy!(Ty<'tcx>)>),
pub fn_sig: Lazy!(PerDefTable<Lazy!(ty::PolyFnSig<'tcx>)>),
pub impl_trait_ref: Lazy!(PerDefTable<Lazy!(ty::TraitRef<'tcx>)>),
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
@ -276,7 +277,7 @@ crate enum EntryKind<'tcx> {
Closure,
Generator(Lazy!(GeneratorData<'tcx>)),
Trait(Lazy<TraitData>),
Impl(Lazy!(ImplData<'tcx>)),
Impl(Lazy<ImplData>),
Method(Lazy<MethodData>),
AssocType(AssocContainer),
AssocOpaqueTy(AssocContainer),
@ -330,14 +331,14 @@ crate struct TraitData {
}
#[derive(RustcEncodable, RustcDecodable)]
crate struct ImplData<'tcx> {
crate struct ImplData {
pub polarity: ty::ImplPolarity,
pub defaultness: hir::Defaultness,
pub parent_impl: Option<DefId>,
/// This is `Some` only for impls of `CoerceUnsized`.
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
pub coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
pub trait_ref: Option<Lazy!(ty::TraitRef<'tcx>)>,
}