1
Fork 0

Can't use EncodableWithShorthand for Predicate

This commit is contained in:
Jack Huey 2021-01-16 19:17:59 -05:00
parent dcad9f1893
commit f2ed9a3a8c
4 changed files with 2 additions and 35 deletions

View file

@ -46,7 +46,6 @@ pub(super) struct EncodeContext<'a, 'tcx> {
lazy_state: LazyState, lazy_state: LazyState,
type_shorthands: FxHashMap<Ty<'tcx>, usize>, type_shorthands: FxHashMap<Ty<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
interpret_allocs: FxIndexSet<interpret::AllocId>, interpret_allocs: FxIndexSet<interpret::AllocId>,
@ -328,10 +327,6 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
&mut self.type_shorthands &mut self.type_shorthands
} }
fn predicate_shorthands(&mut self) -> &mut FxHashMap<rustc_middle::ty::Predicate<'tcx>, usize> {
&mut self.predicate_shorthands
}
fn encode_alloc_id( fn encode_alloc_id(
&mut self, &mut self,
alloc_id: &rustc_middle::mir::interpret::AllocId, alloc_id: &rustc_middle::mir::interpret::AllocId,
@ -2151,7 +2146,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
tables: Default::default(), tables: Default::default(),
lazy_state: LazyState::NoNode, lazy_state: LazyState::NoNode,
type_shorthands: Default::default(), type_shorthands: Default::default(),
predicate_shorthands: Default::default(),
source_file_cache, source_file_cache,
interpret_allocs: Default::default(), interpret_allocs: Default::default(),
required_source_files, required_source_files,

View file

@ -43,19 +43,11 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
} }
} }
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
type Variant = ty::Binder<ty::PredicateKind<'tcx>>;
fn variant(&self) -> &Self::Variant {
self.kind_ref()
}
}
pub trait TyEncoder<'tcx>: Encoder { pub trait TyEncoder<'tcx>: Encoder {
const CLEAR_CROSS_CRATE: bool; const CLEAR_CROSS_CRATE: bool;
fn position(&self) -> usize; fn position(&self) -> usize;
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize>; fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize>;
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::Predicate<'tcx>, usize>;
fn encode_alloc_id(&mut self, alloc_id: &AllocId) -> Result<(), Self::Error>; fn encode_alloc_id(&mut self, alloc_id: &AllocId) -> Result<(), Self::Error>;
} }
@ -120,7 +112,7 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Ty<'tcx> {
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Predicate<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Predicate<'tcx> {
fn encode(&self, e: &mut E) -> Result<(), E::Error> { fn encode(&self, e: &mut E) -> Result<(), E::Error> {
encode_with_shorthand(e, self, TyEncoder::predicate_shorthands) self.kind().encode(e)
} }
} }
@ -220,16 +212,7 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Ty<'tcx> {
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> {
fn decode(decoder: &mut D) -> Result<ty::Predicate<'tcx>, D::Error> { fn decode(decoder: &mut D) -> Result<ty::Predicate<'tcx>, D::Error> {
// Handle shorthands first, if we have an usize > 0x80. let predicate_kind = Decodable::decode(decoder)?;
let predicate_kind = if decoder.positioned_at_shorthand() {
let pos = decoder.read_usize()?;
assert!(pos >= SHORTHAND_OFFSET);
let shorthand = pos - SHORTHAND_OFFSET;
decoder.with_position(shorthand, ty::Binder::<ty::PredicateKind<'tcx>>::decode)
} else {
ty::Binder::<ty::PredicateKind<'tcx>>::decode(decoder)
}?;
let predicate = decoder.tcx().mk_predicate(predicate_kind); let predicate = decoder.tcx().mk_predicate(predicate_kind);
Ok(predicate) Ok(predicate)
} }

View file

@ -1064,11 +1064,6 @@ impl<'tcx> Predicate<'tcx> {
pub fn kind(self) -> Binder<PredicateKind<'tcx>> { pub fn kind(self) -> Binder<PredicateKind<'tcx>> {
self.inner.kind self.inner.kind
} }
/// Like `kind` but returns a reference. Only needed because of encoding.
pub(super) fn kind_ref(self) -> &'tcx Binder<PredicateKind<'tcx>> {
&self.inner.kind
}
} }
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> { impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {

View file

@ -293,7 +293,6 @@ impl<'sess> OnDiskCache<'sess> {
tcx, tcx,
encoder, encoder,
type_shorthands: Default::default(), type_shorthands: Default::default(),
predicate_shorthands: Default::default(),
interpret_allocs: Default::default(), interpret_allocs: Default::default(),
source_map: CachingSourceMapView::new(tcx.sess.source_map()), source_map: CachingSourceMapView::new(tcx.sess.source_map()),
file_to_file_index, file_to_file_index,
@ -989,7 +988,6 @@ struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
encoder: &'a mut E, encoder: &'a mut E,
type_shorthands: FxHashMap<Ty<'tcx>, usize>, type_shorthands: FxHashMap<Ty<'tcx>, usize>,
predicate_shorthands: FxHashMap<ty::Predicate<'tcx>, usize>,
interpret_allocs: FxIndexSet<interpret::AllocId>, interpret_allocs: FxIndexSet<interpret::AllocId>,
source_map: CachingSourceMapView<'tcx>, source_map: CachingSourceMapView<'tcx>,
file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>, file_to_file_index: FxHashMap<*const SourceFile, SourceFileIndex>,
@ -1103,9 +1101,6 @@ where
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> { fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize> {
&mut self.type_shorthands &mut self.type_shorthands
} }
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::Predicate<'tcx>, usize> {
&mut self.predicate_shorthands
}
fn encode_alloc_id(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> { fn encode_alloc_id(&mut self, alloc_id: &interpret::AllocId) -> Result<(), Self::Error> {
let (index, _) = self.interpret_allocs.insert_full(*alloc_id); let (index, _) = self.interpret_allocs.insert_full(*alloc_id);