Impl EncodableWithShorthand for PredicateKind
This commit is contained in:
parent
f2ed9a3a8c
commit
674735b109
4 changed files with 43 additions and 1 deletions
|
@ -46,6 +46,7 @@ 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::PredicateKind<'tcx>, usize>,
|
||||||
|
|
||||||
interpret_allocs: FxIndexSet<interpret::AllocId>,
|
interpret_allocs: FxIndexSet<interpret::AllocId>,
|
||||||
|
|
||||||
|
@ -327,6 +328,10 @@ impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
|
||||||
&mut self.type_shorthands
|
&mut self.type_shorthands
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'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,
|
||||||
|
@ -2146,6 +2151,7 @@ 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,
|
||||||
|
|
|
@ -43,11 +43,21 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::PredicateKind<'tcx> {
|
||||||
|
type Variant = ty::PredicateKind<'tcx>;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn variant(&self) -> &Self::Variant {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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::PredicateKind<'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>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +120,12 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Ty<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::PredicateKind<'tcx> {
|
||||||
|
fn encode(&self, e: &mut E) -> Result<(), E::Error> {
|
||||||
|
encode_with_shorthand(e, self, TyEncoder::predicate_shorthands)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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> {
|
||||||
self.kind().encode(e)
|
self.kind().encode(e)
|
||||||
|
@ -210,6 +226,21 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Ty<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::PredicateKind<'tcx> {
|
||||||
|
fn decode(decoder: &mut D) -> Result<ty::PredicateKind<'tcx>, D::Error> {
|
||||||
|
// 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::PredicateKind::decode)
|
||||||
|
} else {
|
||||||
|
Ok(ty::PredicateKind::decode(decoder)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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> {
|
||||||
let predicate_kind = Decodable::decode(decoder)?;
|
let predicate_kind = Decodable::decode(decoder)?;
|
||||||
|
|
|
@ -1081,7 +1081,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
#[derive(HashStable, TypeFoldable)]
|
#[derive(HashStable, TypeFoldable)]
|
||||||
pub enum PredicateKind<'tcx> {
|
pub enum PredicateKind<'tcx> {
|
||||||
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
|
/// Corresponds to `where Foo: Bar<A, B, C>`. `Foo` here would be
|
||||||
|
|
|
@ -293,6 +293,7 @@ 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,
|
||||||
|
@ -988,6 +989,7 @@ 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::PredicateKind<'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>,
|
||||||
|
@ -1101,6 +1103,9 @@ 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::PredicateKind<'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);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue