Skip to content

Commit

Permalink
rustc_metadata: use a table for impl_trait_ref.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Oct 22, 2019
1 parent 7a80a11 commit 371cc39
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
Expand All @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(..) |
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_metadata/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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>)>,
}


Expand Down

0 comments on commit 371cc39

Please sign in to comment.