Skip to content

Commit 74db3e8

Browse files
committed
rustc_metadata: use a table for super_predicates.
1 parent 50ffa79 commit 74db3e8

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/librustc_metadata/decoder.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'tcx> EntryKind<'tcx> {
448448
EntryKind::Mod(_) => DefKind::Mod,
449449
EntryKind::Variant(_) => DefKind::Variant,
450450
EntryKind::Trait(_) => DefKind::Trait,
451-
EntryKind::TraitAlias(_) => DefKind::TraitAlias,
451+
EntryKind::TraitAlias => DefKind::TraitAlias,
452452
EntryKind::Enum(..) => DefKind::Enum,
453453
EntryKind::MacroDef(_) => DefKind::Macro(MacroKind::Bang),
454454
EntryKind::ForeignType => DefKind::ForeignTy,
@@ -575,7 +575,7 @@ impl<'a, 'tcx> CrateMetadata {
575575
data.is_marker,
576576
self.def_path_table.def_path_hash(item_id))
577577
},
578-
EntryKind::TraitAlias(_) => {
578+
EntryKind::TraitAlias => {
579579
ty::TraitDef::new(self.local_def_id(item_id),
580580
hir::Unsafety::Normal,
581581
false,
@@ -680,13 +680,7 @@ impl<'a, 'tcx> CrateMetadata {
680680
item_id: DefIndex,
681681
tcx: TyCtxt<'tcx>,
682682
) -> ty::GenericPredicates<'tcx> {
683-
let super_predicates = match self.kind(item_id) {
684-
EntryKind::Trait(data) => data.decode(self).super_predicates,
685-
EntryKind::TraitAlias(data) => data.decode(self).super_predicates,
686-
_ => bug!("def-index does not refer to trait or trait alias"),
687-
};
688-
689-
super_predicates.decode((self, tcx))
683+
self.root.per_def.super_predicates.get(self, item_id).unwrap().decode((self, tcx))
690684
}
691685

692686
crate fn get_generics(&self, item_id: DefIndex, sess: &Session) -> ty::Generics {
@@ -1118,7 +1112,7 @@ impl<'a, 'tcx> CrateMetadata {
11181112
def_key.parent.and_then(|parent_index| {
11191113
match self.kind(parent_index) {
11201114
EntryKind::Trait(_) |
1121-
EntryKind::TraitAlias(_) => Some(self.local_def_id(parent_index)),
1115+
EntryKind::TraitAlias => Some(self.local_def_id(parent_index)),
11221116
_ => None,
11231117
}
11241118
})

src/librustc_metadata/encoder.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct PerDefTables<'tcx> {
7676
generics: PerDefTable<Lazy<ty::Generics>>,
7777
predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
7878
predicates_defined_on: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
79+
super_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
7980

8081
mir: PerDefTable<Lazy<mir::Body<'tcx>>>,
8182
promoted_mir: PerDefTable<Lazy<IndexVec<mir::Promoted, mir::Body<'tcx>>>>,
@@ -513,6 +514,7 @@ impl<'tcx> EncodeContext<'tcx> {
513514
generics: self.per_def.generics.encode(&mut self.opaque),
514515
predicates: self.per_def.predicates.encode(&mut self.opaque),
515516
predicates_defined_on: self.per_def.predicates_defined_on.encode(&mut self.opaque),
517+
super_predicates: self.per_def.super_predicates.encode(&mut self.opaque),
516518

517519
mir: self.per_def.mir.encode(&mut self.opaque),
518520
promoted_mir: self.per_def.promoted_mir.encode(&mut self.opaque),
@@ -835,6 +837,11 @@ impl EncodeContext<'tcx> {
835837
self.tcx.predicates_defined_on(def_id))
836838
}
837839

840+
fn encode_super_predicates(&mut self, def_id: DefId) {
841+
debug!("EncodeContext::encode_super_predicates({:?})", def_id);
842+
record!(self.per_def.super_predicates[def_id] <- self.tcx.super_predicates_of(def_id));
843+
}
844+
838845
fn encode_info_for_trait_item(&mut self, def_id: DefId) {
839846
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
840847
let tcx = self.tcx;
@@ -1166,18 +1173,11 @@ impl EncodeContext<'tcx> {
11661173
paren_sugar: trait_def.paren_sugar,
11671174
has_auto_impl: self.tcx.trait_is_auto(def_id),
11681175
is_marker: trait_def.is_marker,
1169-
super_predicates: self.lazy(tcx.super_predicates_of(def_id)),
11701176
};
11711177

11721178
EntryKind::Trait(self.lazy(data))
11731179
}
1174-
hir::ItemKind::TraitAlias(..) => {
1175-
let data = TraitAliasData {
1176-
super_predicates: self.lazy(tcx.super_predicates_of(def_id)),
1177-
};
1178-
1179-
EntryKind::TraitAlias(self.lazy(data))
1180-
}
1180+
hir::ItemKind::TraitAlias(..) => EntryKind::TraitAlias,
11811181
hir::ItemKind::ExternCrate(_) |
11821182
hir::ItemKind::Use(..) => bug!("cannot encode info for item {:?}", item),
11831183
});
@@ -1269,6 +1269,13 @@ impl EncodeContext<'tcx> {
12691269
}
12701270
_ => {} // not *wrong* for other kinds of items, but not needed
12711271
}
1272+
match item.kind {
1273+
hir::ItemKind::Trait(..) |
1274+
hir::ItemKind::TraitAlias(..) => {
1275+
self.encode_super_predicates(def_id);
1276+
}
1277+
_ => {}
1278+
}
12721279

12731280
let mir = match item.kind {
12741281
hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => true,

src/librustc_metadata/schema.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ crate struct LazyPerDefTables<'tcx> {
243243
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
244244
pub predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
245245
pub predicates_defined_on: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
246+
pub super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
246247

247248
pub mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),
248249
pub promoted_mir: Lazy!(PerDefTable<Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>),
@@ -273,13 +274,13 @@ crate enum EntryKind<'tcx> {
273274
MacroDef(Lazy<MacroDef>),
274275
Closure(Lazy!(ClosureData<'tcx>)),
275276
Generator(Lazy!(GeneratorData<'tcx>)),
276-
Trait(Lazy!(TraitData<'tcx>)),
277+
Trait(Lazy<TraitData>),
277278
Impl(Lazy!(ImplData<'tcx>)),
278279
Method(Lazy!(MethodData<'tcx>)),
279280
AssocType(AssocContainer),
280281
AssocOpaqueTy(AssocContainer),
281282
AssocConst(AssocContainer, ConstQualif, Lazy<RenderedConst>),
282-
TraitAlias(Lazy!(TraitAliasData<'tcx>)),
283+
TraitAlias,
283284
}
284285

285286
/// Additional data for EntryKind::Const and EntryKind::AssocConst
@@ -324,17 +325,11 @@ crate struct VariantData<'tcx> {
324325
}
325326

326327
#[derive(RustcEncodable, RustcDecodable)]
327-
crate struct TraitData<'tcx> {
328+
crate struct TraitData {
328329
pub unsafety: hir::Unsafety,
329330
pub paren_sugar: bool,
330331
pub has_auto_impl: bool,
331332
pub is_marker: bool,
332-
pub super_predicates: Lazy!(ty::GenericPredicates<'tcx>),
333-
}
334-
335-
#[derive(RustcEncodable, RustcDecodable)]
336-
crate struct TraitAliasData<'tcx> {
337-
pub super_predicates: Lazy!(ty::GenericPredicates<'tcx>),
338333
}
339334

340335
#[derive(RustcEncodable, RustcDecodable)]

0 commit comments

Comments
 (0)