Skip to content

Commit cd7cbaa

Browse files
committed
rustc_metadata: replace predicates_defined_on with explicit_predicates_of and inferred_outlives_of.
1 parent 71eacef commit cd7cbaa

File tree

4 files changed

+50
-19
lines changed

4 files changed

+50
-19
lines changed

src/librustc_metadata/cstore_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
9595
generics_of => {
9696
tcx.arena.alloc(cdata.get_generics(def_id.index, tcx.sess))
9797
}
98-
predicates_defined_on => { cdata.get_predicates_defined_on(def_id.index, tcx) }
98+
explicit_predicates_of => { cdata.get_explicit_predicates(def_id.index, tcx) }
99+
inferred_outlives_of => { cdata.get_inferred_outlives(def_id.index, tcx) }
99100
super_predicates_of => { cdata.get_super_predicates(def_id.index, tcx) }
100101
trait_def => {
101102
tcx.arena.alloc(cdata.get_trait_def(def_id.index, tcx.sess))

src/librustc_metadata/decoder.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,20 @@ impl<'a, 'tcx> CrateMetadata {
658658
tcx.alloc_adt_def(did, adt_kind, variants, repr)
659659
}
660660

661-
crate fn get_predicates_defined_on(
661+
crate fn get_explicit_predicates(
662662
&self,
663663
item_id: DefIndex,
664664
tcx: TyCtxt<'tcx>,
665665
) -> ty::GenericPredicates<'tcx> {
666-
self.root.per_def.predicates_defined_on.get(self, item_id).unwrap().decode((self, tcx))
666+
self.root.per_def.explicit_predicates.get(self, item_id).unwrap().decode((self, tcx))
667+
}
668+
669+
crate fn get_inferred_outlives(
670+
&self,
671+
item_id: DefIndex,
672+
tcx: TyCtxt<'tcx>,
673+
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
674+
self.root.per_def.inferred_outlives.get(self, item_id).unwrap().decode((self, tcx))
667675
}
668676

669677
crate fn get_super_predicates(

src/librustc_metadata/encoder.rs

+32-15
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct PerDefTables<'tcx> {
7676
inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
7777
variances: PerDefTable<Lazy<[ty::Variance]>>,
7878
generics: PerDefTable<Lazy<ty::Generics>>,
79-
predicates_defined_on: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
79+
explicit_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
80+
inferred_outlives: PerDefTable<Lazy<&'tcx [(ty::Predicate<'tcx>, Span)]>>,
8081
super_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
8182

8283
mir: PerDefTable<Lazy<mir::Body<'tcx>>>,
@@ -523,7 +524,8 @@ impl<'tcx> EncodeContext<'tcx> {
523524
inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
524525
variances: self.per_def.variances.encode(&mut self.opaque),
525526
generics: self.per_def.generics.encode(&mut self.opaque),
526-
predicates_defined_on: self.per_def.predicates_defined_on.encode(&mut self.opaque),
527+
explicit_predicates: self.per_def.explicit_predicates.encode(&mut self.opaque),
528+
inferred_outlives: self.per_def.inferred_outlives.encode(&mut self.opaque),
527529
super_predicates: self.per_def.super_predicates.encode(&mut self.opaque),
528530

529531
mir: self.per_def.mir.encode(&mut self.opaque),
@@ -674,7 +676,8 @@ impl EncodeContext<'tcx> {
674676
self.encode_variances_of(def_id);
675677
}
676678
self.encode_generics(def_id);
677-
self.encode_predicates_defined_on(def_id);
679+
self.encode_explicit_predicates(def_id);
680+
self.encode_inferred_outlives(def_id);
678681
self.encode_optimized_mir(def_id);
679682
self.encode_promoted_mir(def_id);
680683
}
@@ -717,7 +720,8 @@ impl EncodeContext<'tcx> {
717720
self.encode_variances_of(def_id);
718721
}
719722
self.encode_generics(def_id);
720-
self.encode_predicates_defined_on(def_id);
723+
self.encode_explicit_predicates(def_id);
724+
self.encode_inferred_outlives(def_id);
721725
self.encode_optimized_mir(def_id);
722726
self.encode_promoted_mir(def_id);
723727
}
@@ -775,7 +779,8 @@ impl EncodeContext<'tcx> {
775779
self.encode_deprecation(def_id);
776780
self.encode_item_type(def_id);
777781
self.encode_generics(def_id);
778-
self.encode_predicates_defined_on(def_id);
782+
self.encode_explicit_predicates(def_id);
783+
self.encode_inferred_outlives(def_id);
779784
}
780785

781786
fn encode_struct_ctor(&mut self, adt_def_id: DefId, def_id: DefId) {
@@ -818,7 +823,8 @@ impl EncodeContext<'tcx> {
818823
self.encode_variances_of(def_id);
819824
}
820825
self.encode_generics(def_id);
821-
self.encode_predicates_defined_on(def_id);
826+
self.encode_explicit_predicates(def_id);
827+
self.encode_inferred_outlives(def_id);
822828
self.encode_optimized_mir(def_id);
823829
self.encode_promoted_mir(def_id);
824830
}
@@ -828,10 +834,16 @@ impl EncodeContext<'tcx> {
828834
record!(self.per_def.generics[def_id] <- self.tcx.generics_of(def_id));
829835
}
830836

831-
fn encode_predicates_defined_on(&mut self, def_id: DefId) {
832-
debug!("EncodeContext::encode_predicates_defined_on({:?})", def_id);
833-
record!(self.per_def.predicates_defined_on[def_id] <-
834-
self.tcx.predicates_defined_on(def_id))
837+
fn encode_explicit_predicates(&mut self, def_id: DefId) {
838+
debug!("EncodeContext::encode_explicit_predicates({:?})", def_id);
839+
record!(self.per_def.explicit_predicates[def_id] <-
840+
self.tcx.explicit_predicates_of(def_id));
841+
}
842+
843+
fn encode_inferred_outlives(&mut self, def_id: DefId) {
844+
debug!("EncodeContext::encode_inferred_outlives({:?})", def_id);
845+
record!(self.per_def.inferred_outlives[def_id] <-
846+
self.tcx.inferred_outlives_of(def_id));
835847
}
836848

837849
fn encode_super_predicates(&mut self, def_id: DefId) {
@@ -913,7 +925,8 @@ impl EncodeContext<'tcx> {
913925
self.encode_variances_of(def_id);
914926
}
915927
self.encode_generics(def_id);
916-
self.encode_predicates_defined_on(def_id);
928+
self.encode_explicit_predicates(def_id);
929+
self.encode_inferred_outlives(def_id);
917930
self.encode_optimized_mir(def_id);
918931
self.encode_promoted_mir(def_id);
919932
}
@@ -980,7 +993,8 @@ impl EncodeContext<'tcx> {
980993
self.encode_variances_of(def_id);
981994
}
982995
self.encode_generics(def_id);
983-
self.encode_predicates_defined_on(def_id);
996+
self.encode_explicit_predicates(def_id);
997+
self.encode_inferred_outlives(def_id);
984998
let mir = match ast_item.kind {
985999
hir::ImplItemKind::Const(..) => true,
9861000
hir::ImplItemKind::Method(ref sig, _) => {
@@ -1254,7 +1268,8 @@ impl EncodeContext<'tcx> {
12541268
hir::ItemKind::Trait(..) |
12551269
hir::ItemKind::TraitAlias(..) => {
12561270
self.encode_generics(def_id);
1257-
self.encode_predicates_defined_on(def_id);
1271+
self.encode_explicit_predicates(def_id);
1272+
self.encode_inferred_outlives(def_id);
12581273
}
12591274
_ => {}
12601275
}
@@ -1359,7 +1374,8 @@ impl EncodeContext<'tcx> {
13591374
record!(self.per_def.span[def_id] <- self.tcx.def_span(def_id));
13601375
self.encode_item_type(def_id);
13611376
self.encode_generics(def_id);
1362-
self.encode_predicates_defined_on(def_id);
1377+
self.encode_explicit_predicates(def_id);
1378+
self.encode_inferred_outlives(def_id);
13631379
self.encode_optimized_mir(def_id);
13641380
self.encode_promoted_mir(def_id);
13651381
}
@@ -1570,7 +1586,8 @@ impl EncodeContext<'tcx> {
15701586
self.encode_variances_of(def_id);
15711587
}
15721588
self.encode_generics(def_id);
1573-
self.encode_predicates_defined_on(def_id);
1589+
self.encode_explicit_predicates(def_id);
1590+
self.encode_inferred_outlives(def_id);
15741591
}
15751592
}
15761593

src/librustc_metadata/schema.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,12 @@ crate struct LazyPerDefTables<'tcx> {
244244
pub inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
245245
pub variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
246246
pub generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
247-
pub predicates_defined_on: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
247+
pub explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
248+
// FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
249+
// doesn't handle shorthands in its own (de)serialization impls,
250+
// as it's an `enum` for which we want to derive (de)serialization,
251+
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
252+
pub inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
248253
pub super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
249254

250255
pub mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),

0 commit comments

Comments
 (0)