Skip to content

Commit

Permalink
Auto merge of #59789 - eddyb:typeck-reverts, r=<try>
Browse files Browse the repository at this point in the history
Revert two unapproved changes to rustc_typeck.

There was a breakdown in process (#59004 (comment), #58894 (comment)) and two changes were made to `rustc_typeck`'s "collect" queries, for rustdoc, that were neither needed *nor* correct.
I'm reverting them here, and will fix up rustdoc *somehow*, if necessary.

cc @rust-lang/compiler How do we ensure this doesn't happen again?

r? @nikomatsakis or @oli-obk
  • Loading branch information
bors committed Apr 9, 2019
2 parents 3750348 + 76166f6 commit b2e5868
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 141 deletions.
61 changes: 54 additions & 7 deletions src/librustc/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,26 @@ pub fn encode_with_shorthand<E, T, M>(encoder: &mut E,
Ok(())
}

pub fn encode_predicates<'tcx, E, C>(encoder: &mut E,
predicates: &ty::GenericPredicates<'tcx>,
cache: C)
-> Result<(), E::Error>
pub fn encode_predicates<'tcx, E, C>(
encoder: &mut E,
predicates: &[ty::Predicate<'tcx>],
cache: C,
) -> Result<(), E::Error>
where E: TyEncoder,
C: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<ty::Predicate<'tcx>, usize>,
{
predicates.len().encode(encoder)?;
for predicate in predicates {
encode_with_shorthand(encoder, predicate, &cache)?;
}
Ok(())
}

pub fn encode_generic_predicates<'tcx, E, C>(
encoder: &mut E,
predicates: &ty::GenericPredicates<'tcx>,
cache: C,
) -> Result<(), E::Error>
where E: TyEncoder,
C: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<ty::Predicate<'tcx>, usize>,
{
Expand Down Expand Up @@ -160,8 +176,31 @@ pub fn decode_ty<'a, 'tcx, D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
}

#[inline]
pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
-> Result<ty::GenericPredicates<'tcx>, D::Error>
pub fn decode_predicates<'a, 'tcx, D>(
decoder: &mut D,
) -> Result<Vec<ty::Predicate<'tcx>>, D::Error>
where D: TyDecoder<'a, 'tcx>,
'tcx: 'a,
{
(0..decoder.read_usize()?).map(|_| {
// Handle shorthands first, if we have an usize > 0x80.
if decoder.positioned_at_shorthand() {
let pos = decoder.read_usize()?;
assert!(pos >= SHORTHAND_OFFSET);
let shorthand = pos - SHORTHAND_OFFSET;

decoder.with_position(shorthand, ty::Predicate::decode)
} else {
ty::Predicate::decode(decoder)
}
})
.collect()
}

#[inline]
pub fn decode_generic_predicates<'a, 'tcx, D>(
decoder: &mut D,
) -> Result<ty::GenericPredicates<'tcx>, D::Error>
where D: TyDecoder<'a, 'tcx>,
'tcx: 'a,
{
Expand Down Expand Up @@ -336,11 +375,19 @@ macro_rules! implement_ty_decoder {
}
}

impl<$($typaram),*> SpecializedDecoder<Vec<ty::Predicate<'tcx>>>
for $DecoderName<$($typaram),*> {
fn specialized_decode(&mut self)
-> Result<Vec<ty::Predicate<'tcx>>, Self::Error> {
decode_predicates(self)
}
}

impl<$($typaram),*> SpecializedDecoder<ty::GenericPredicates<'tcx>>
for $DecoderName<$($typaram),*> {
fn specialized_decode(&mut self)
-> Result<ty::GenericPredicates<'tcx>, Self::Error> {
decode_predicates(self)
decode_generic_predicates(self)
}
}

Expand Down
15 changes: 14 additions & 1 deletion src/librustc/ty/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,19 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::Ty<'tcx>> for CacheEncoder<'enc,
}
}

impl<'enc, 'a, 'tcx, E> SpecializedEncoder<Vec<ty::Predicate<'tcx>>>
for CacheEncoder<'enc, 'a, 'tcx, E>
where E: 'enc + ty_codec::TyEncoder
{
#[inline]
fn specialized_encode(&mut self,
predicates: &Vec<ty::Predicate<'tcx>>)
-> Result<(), Self::Error> {
ty_codec::encode_predicates(self, predicates,
|encoder| &mut encoder.predicate_shorthands)
}
}

impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>>
for CacheEncoder<'enc, 'a, 'tcx, E>
where E: 'enc + ty_codec::TyEncoder
Expand All @@ -899,7 +912,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>>
fn specialized_encode(&mut self,
predicates: &ty::GenericPredicates<'tcx>)
-> Result<(), Self::Error> {
ty_codec::encode_predicates(self, predicates,
ty_codec::encode_generic_predicates(self, predicates,
|encoder| &mut encoder.predicate_shorthands)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
generics_of => {
tcx.alloc_generics(cdata.get_generics(def_id.index, tcx.sess))
}
predicates_of => { Lrc::new(cdata.get_predicates(def_id.index, tcx)) }
predicates_defined_on => { Lrc::new(cdata.get_predicates_defined_on(def_id.index, tcx)) }
explicit_predicates_of => { Lrc::new(cdata.get_explicit_predicates(def_id.index, tcx)) }
inferred_outlives_of => { Lrc::new(cdata.get_inferred_outlives(def_id.index, tcx)) }
super_predicates_of => { Lrc::new(cdata.get_super_predicates(def_id.index, tcx)) }
trait_def => {
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index, tcx.sess))
Expand Down
22 changes: 12 additions & 10 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,18 +617,20 @@ impl<'a, 'tcx> CrateMetadata {
tcx.alloc_adt_def(did, kind, variants, repr)
}

pub fn get_predicates(&self,
item_id: DefIndex,
tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> ty::GenericPredicates<'tcx> {
self.entry(item_id).predicates.unwrap().decode((self, tcx))
pub fn get_explicit_predicates(
&self,
item_id: DefIndex,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
) -> ty::GenericPredicates<'tcx> {
self.entry(item_id).explicit_predicates.unwrap().decode((self, tcx))
}

pub fn get_predicates_defined_on(&self,
item_id: DefIndex,
tcx: TyCtxt<'a, 'tcx, 'tcx>)
-> ty::GenericPredicates<'tcx> {
self.entry(item_id).predicates_defined_on.unwrap().decode((self, tcx))
pub fn get_inferred_outlives(
&self,
item_id: DefIndex,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
) -> Vec<ty::Predicate<'tcx>> {
self.entry(item_id).inferred_outlives.unwrap().decode((self, tcx))
}

pub fn get_super_predicates(&self,
Expand Down
95 changes: 53 additions & 42 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,19 @@ impl<'a, 'tcx> SpecializedEncoder<interpret::AllocId> for EncodeContext<'a, 'tcx
}
}

impl<'a, 'tcx> SpecializedEncoder<Vec<ty::Predicate<'tcx>>> for EncodeContext<'a, 'tcx> {
fn specialized_encode(&mut self,
predicates: &Vec<ty::Predicate<'tcx>>)
-> Result<(), Self::Error> {
ty_codec::encode_predicates(self, predicates, |ecx| &mut ecx.predicate_shorthands)
}
}

impl<'a, 'tcx> SpecializedEncoder<ty::GenericPredicates<'tcx>> for EncodeContext<'a, 'tcx> {
fn specialized_encode(&mut self,
predicates: &ty::GenericPredicates<'tcx>)
-> Result<(), Self::Error> {
ty_codec::encode_predicates(self, predicates, |ecx| &mut ecx.predicate_shorthands)
ty_codec::encode_generic_predicates(self, predicates, |ecx| &mut ecx.predicate_shorthands)
}
}

Expand Down Expand Up @@ -613,8 +621,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
LazySeq::empty()
},
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: self.encode_optimized_mir(def_id),
}
Expand Down Expand Up @@ -669,8 +677,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
LazySeq::empty()
},
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: self.encode_optimized_mir(def_id),
}
Expand Down Expand Up @@ -707,8 +715,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: None,
predicates: None,
predicates_defined_on: None,
explicit_predicates: None,
inferred_outlives: None,

mir: None
}
Expand Down Expand Up @@ -748,8 +756,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: None,
}
Expand Down Expand Up @@ -808,8 +816,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
LazySeq::empty()
},
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: self.encode_optimized_mir(def_id),
}
Expand All @@ -821,16 +829,16 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
self.lazy(tcx.generics_of(def_id))
}

fn encode_predicates(&mut self, def_id: DefId) -> Lazy<ty::GenericPredicates<'tcx>> {
debug!("IsolatedEncoder::encode_predicates({:?})", def_id);
fn encode_explicit_predicates(&mut self, def_id: DefId) -> Lazy<ty::GenericPredicates<'tcx>> {
debug!("IsolatedEncoder::encode_explicit_predicates({:?})", def_id);
let tcx = self.tcx;
self.lazy(&tcx.predicates_of(def_id))
self.lazy(&tcx.explicit_predicates_of(def_id))
}

fn encode_predicates_defined_on(&mut self, def_id: DefId) -> Lazy<ty::GenericPredicates<'tcx>> {
debug!("IsolatedEncoder::encode_predicates_defined_on({:?})", def_id);
fn encode_inferred_outlives(&mut self, def_id: DefId) -> Lazy<Vec<ty::Predicate<'tcx>>> {
debug!("IsolatedEncoder::encode_inferred_outlives({:?})", def_id);
let tcx = self.tcx;
self.lazy(&tcx.predicates_defined_on(def_id))
self.lazy(&tcx.inferred_outlives_of(def_id))
}

fn encode_info_for_trait_item(&mut self, def_id: DefId) -> Entry<'tcx> {
Expand Down Expand Up @@ -924,8 +932,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
LazySeq::empty()
},
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: self.encode_optimized_mir(def_id),
}
Expand Down Expand Up @@ -1023,8 +1031,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
LazySeq::empty()
},
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: if mir { self.encode_optimized_mir(def_id) } else { None },
}
Expand Down Expand Up @@ -1280,7 +1288,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
hir::ItemKind::TraitAlias(..) => Some(self.encode_generics(def_id)),
_ => None,
},
predicates: match item.node {
explicit_predicates: match item.node {
hir::ItemKind::Static(..) |
hir::ItemKind::Const(..) |
hir::ItemKind::Fn(..) |
Expand All @@ -1291,19 +1299,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
hir::ItemKind::Impl(..) |
hir::ItemKind::Existential(..) |
hir::ItemKind::Trait(..) |
hir::ItemKind::TraitAlias(..) => Some(self.encode_predicates(def_id)),
hir::ItemKind::TraitAlias(..) => Some(self.encode_explicit_predicates(def_id)),
_ => None,
},

// The only time that `predicates_defined_on` is used (on
// an external item) is for traits, during chalk lowering,
// so only encode it in that case as an efficiency
// hack. (No reason not to expand it in the future if
// necessary.)
predicates_defined_on: match item.node {
inferred_outlives: match item.node {
hir::ItemKind::Static(..) |
hir::ItemKind::Const(..) |
hir::ItemKind::Fn(..) |
hir::ItemKind::Ty(..) |
hir::ItemKind::Enum(..) |
hir::ItemKind::Struct(..) |
hir::ItemKind::Union(..) |
hir::ItemKind::Impl(..) |
hir::ItemKind::Existential(..) |
hir::ItemKind::Trait(..) |
hir::ItemKind::TraitAlias(..) => Some(self.encode_predicates_defined_on(def_id)),
_ => None, // not *wrong* for other kinds of items, but not needed
hir::ItemKind::TraitAlias(..) => Some(self.encode_inferred_outlives(def_id)),
_ => None,
},

mir: match item.node {
Expand Down Expand Up @@ -1352,8 +1363,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: None,
predicates: None,
predicates_defined_on: None,
explicit_predicates: None,
inferred_outlives: None,
mir: None,
}
}
Expand All @@ -1377,8 +1388,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: None,
predicates: None,
predicates_defined_on: None,
explicit_predicates: None,
inferred_outlives: None,

mir: None,
}
Expand Down Expand Up @@ -1437,8 +1448,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: Some(self.encode_generics(def_id)),
predicates: None,
predicates_defined_on: None,
explicit_predicates: None,
inferred_outlives: None,

mir: self.encode_optimized_mir(def_id),
}
Expand All @@ -1465,8 +1476,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: self.encode_optimized_mir(def_id),
}
Expand Down Expand Up @@ -1668,8 +1679,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
_ => LazySeq::empty(),
},
generics: Some(self.encode_generics(def_id)),
predicates: Some(self.encode_predicates(def_id)),
predicates_defined_on: None,
explicit_predicates: Some(self.encode_explicit_predicates(def_id)),
inferred_outlives: Some(self.encode_inferred_outlives(def_id)),

mir: None,
}
Expand Down
Loading

0 comments on commit b2e5868

Please sign in to comment.