diff options
Diffstat (limited to 'compiler/rustc_middle/src/ty/codec.rs')
| -rw-r--r-- | compiler/rustc_middle/src/ty/codec.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 380fb8172a7..0aaba81819b 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -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 { const CLEAR_CROSS_CRATE: bool; fn position(&self) -> 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>; } @@ -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> { fn encode(&self, e: &mut E) -> Result<(), E::Error> { 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> { fn decode(decoder: &mut D) -> Result<ty::Predicate<'tcx>, D::Error> { let predicate_kind = Decodable::decode(decoder)?; |
