Skip to content

Commit 371cc39

Browse files
committed
rustc_metadata: use a table for impl_trait_ref.
1 parent 7a80a11 commit 371cc39

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/librustc_metadata/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl<'a, 'tcx> CrateMetadata {
711711
}
712712
}
713713

714-
fn get_impl_data(&self, id: DefIndex) -> ImplData<'tcx> {
714+
fn get_impl_data(&self, id: DefIndex) -> ImplData {
715715
match self.kind(id) {
716716
EntryKind::Impl(data) => data.decode(self),
717717
_ => bug!(),
@@ -738,7 +738,7 @@ impl<'a, 'tcx> CrateMetadata {
738738
}
739739

740740
crate fn get_impl_trait(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Option<ty::TraitRef<'tcx>> {
741-
self.get_impl_data(id).trait_ref.map(|tr| tr.decode((self, tcx)))
741+
self.root.per_def.impl_trait_ref.get(self, id).map(|tr| tr.decode((self, tcx)))
742742
}
743743

744744
/// Iterates over all the stability attributes in the given crate.

src/librustc_metadata/encoder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct PerDefTables<'tcx> {
7272

7373
ty: PerDefTable<Lazy<Ty<'tcx>>>,
7474
fn_sig: PerDefTable<Lazy<ty::PolyFnSig<'tcx>>>,
75+
impl_trait_ref: PerDefTable<Lazy<ty::TraitRef<'tcx>>>,
7576
inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
7677
variances: PerDefTable<Lazy<[ty::Variance]>>,
7778
generics: PerDefTable<Lazy<ty::Generics>>,
@@ -511,6 +512,7 @@ impl<'tcx> EncodeContext<'tcx> {
511512

512513
ty: self.per_def.ty.encode(&mut self.opaque),
513514
fn_sig: self.per_def.fn_sig.encode(&mut self.opaque),
515+
impl_trait_ref: self.per_def.impl_trait_ref.encode(&mut self.opaque),
514516
inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
515517
variances: self.per_def.variances.encode(&mut self.opaque),
516518
generics: self.per_def.generics.encode(&mut self.opaque),
@@ -1152,7 +1154,6 @@ impl EncodeContext<'tcx> {
11521154
defaultness,
11531155
parent_impl: parent,
11541156
coerce_unsized_info,
1155-
trait_ref: trait_ref.map(|trait_ref| self.lazy(trait_ref)),
11561157
};
11571158

11581159
EntryKind::Impl(self.lazy(data))
@@ -1226,6 +1227,11 @@ impl EncodeContext<'tcx> {
12261227
if let hir::ItemKind::Fn(..) = item.kind {
12271228
record!(self.per_def.fn_sig[def_id] <- tcx.fn_sig(def_id));
12281229
}
1230+
if let hir::ItemKind::Impl(..) = item.kind {
1231+
if let Some(trait_ref) = self.tcx.impl_trait_ref(def_id) {
1232+
record!(self.per_def.impl_trait_ref[def_id] <- trait_ref);
1233+
}
1234+
}
12291235
self.encode_inherent_implementations(def_id);
12301236
match item.kind {
12311237
hir::ItemKind::Enum(..) |

src/librustc_metadata/schema.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ crate struct LazyPerDefTables<'tcx> {
239239

240240
pub ty: Lazy!(PerDefTable<Lazy!(Ty<'tcx>)>),
241241
pub fn_sig: Lazy!(PerDefTable<Lazy!(ty::PolyFnSig<'tcx>)>),
242+
pub impl_trait_ref: Lazy!(PerDefTable<Lazy!(ty::TraitRef<'tcx>)>),
242243
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
243244
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
244245
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
@@ -276,7 +277,7 @@ crate enum EntryKind<'tcx> {
276277
Closure,
277278
Generator(Lazy!(GeneratorData<'tcx>)),
278279
Trait(Lazy<TraitData>),
279-
Impl(Lazy!(ImplData<'tcx>)),
280+
Impl(Lazy<ImplData>),
280281
Method(Lazy<MethodData>),
281282
AssocType(AssocContainer),
282283
AssocOpaqueTy(AssocContainer),
@@ -330,14 +331,14 @@ crate struct TraitData {
330331
}
331332

332333
#[derive(RustcEncodable, RustcDecodable)]
333-
crate struct ImplData<'tcx> {
334+
crate struct ImplData {
334335
pub polarity: ty::ImplPolarity,
335336
pub defaultness: hir::Defaultness,
336337
pub parent_impl: Option<DefId>,
337338

338339
/// This is `Some` only for impls of `CoerceUnsized`.
340+
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
339341
pub coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
340-
pub trait_ref: Option<Lazy!(ty::TraitRef<'tcx>)>,
341342
}
342343

343344

0 commit comments

Comments
 (0)