From 371cc39b256d0fa5ec0da3193e0ec6f9377bd903 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 19 Oct 2019 01:10:58 +0300 Subject: [PATCH] rustc_metadata: use a table for impl_trait_ref. --- src/librustc_metadata/decoder.rs | 4 ++-- src/librustc_metadata/encoder.rs | 8 +++++++- src/librustc_metadata/schema.rs | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 9c7b721fb7f63..1333e3fb3ce3e 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -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> { - 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. diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index e3ad1c5e197b5..0dc9f91ae00e1 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -72,6 +72,7 @@ struct PerDefTables<'tcx> { ty: PerDefTable>>, fn_sig: PerDefTable>>, + impl_trait_ref: PerDefTable>>, inherent_impls: PerDefTable>, variances: PerDefTable>, generics: PerDefTable>, @@ -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(..) | diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index 03754c92252a3..ad39aa34fd5c8 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -239,6 +239,7 @@ crate struct LazyPerDefTables<'tcx> { pub ty: Lazy!(PerDefTable)>), pub fn_sig: Lazy!(PerDefTable)>), + pub impl_trait_ref: Lazy!(PerDefTable)>), pub inherent_impls: Lazy!(PerDefTable>), pub variances: Lazy!(PerDefTable>), pub generics: Lazy!(PerDefTable>), @@ -276,7 +277,7 @@ crate enum EntryKind<'tcx> { Closure, Generator(Lazy!(GeneratorData<'tcx>)), Trait(Lazy), - Impl(Lazy!(ImplData<'tcx>)), + Impl(Lazy), Method(Lazy), 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, /// This is `Some` only for impls of `CoerceUnsized`. + // FIXME(eddyb) perhaps compute this on the fly if cheap enough? pub coerce_unsized_info: Option, - pub trait_ref: Option)>, }