Remove FingerprintEncoder/Decoder.
This commit is contained in:
parent
09a638820e
commit
11b3409b5d
4 changed files with 11 additions and 84 deletions
|
@ -1,8 +1,5 @@
|
||||||
use crate::stable_hasher;
|
use crate::stable_hasher;
|
||||||
use rustc_serialize::{
|
use rustc_serialize::{Decodable, Encodable};
|
||||||
opaque::{self, EncodeResult, FileEncodeResult},
|
|
||||||
Decodable, Decoder, Encodable, Encoder,
|
|
||||||
};
|
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::mem::{self, MaybeUninit};
|
use std::mem::{self, MaybeUninit};
|
||||||
|
|
||||||
|
@ -63,16 +60,6 @@ impl Fingerprint {
|
||||||
pub fn to_hex(&self) -> String {
|
pub fn to_hex(&self) -> String {
|
||||||
format!("{:x}{:x}", self.0, self.1)
|
format!("{:x}{:x}", self.0, self.1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode_opaque(decoder: &mut opaque::Decoder<'_>) -> Result<Fingerprint, String> {
|
|
||||||
let mut bytes: [MaybeUninit<u8>; 16] = MaybeUninit::uninit_array();
|
|
||||||
|
|
||||||
decoder.read_raw_bytes(&mut bytes)?;
|
|
||||||
|
|
||||||
let [l, r]: [u64; 2] = unsafe { mem::transmute(bytes) };
|
|
||||||
|
|
||||||
Ok(Fingerprint(u64::from_le(l), u64::from_le(r)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Fingerprint {
|
impl std::fmt::Display for Fingerprint {
|
||||||
|
@ -130,55 +117,22 @@ impl stable_hasher::StableHasherResult for Fingerprint {
|
||||||
impl_stable_hash_via_hash!(Fingerprint);
|
impl_stable_hash_via_hash!(Fingerprint);
|
||||||
|
|
||||||
impl<E: rustc_serialize::Encoder> Encodable<E> for Fingerprint {
|
impl<E: rustc_serialize::Encoder> Encodable<E> for Fingerprint {
|
||||||
|
#[inline]
|
||||||
fn encode(&self, s: &mut E) -> Result<(), E::Error> {
|
fn encode(&self, s: &mut E) -> Result<(), E::Error> {
|
||||||
s.encode_fingerprint(self)
|
let bytes: [u8; 16] = unsafe { mem::transmute([self.0.to_le(), self.1.to_le()]) };
|
||||||
}
|
s.emit_raw_bytes(&bytes)?;
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: rustc_serialize::Decoder> Decodable<D> for Fingerprint {
|
|
||||||
fn decode(d: &mut D) -> Result<Self, D::Error> {
|
|
||||||
d.decode_fingerprint()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FingerprintEncoder: rustc_serialize::Encoder {
|
|
||||||
fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), Self::Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FingerprintDecoder: rustc_serialize::Decoder {
|
|
||||||
fn decode_fingerprint(&mut self) -> Result<Fingerprint, Self::Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: rustc_serialize::Encoder> FingerprintEncoder for E {
|
|
||||||
default fn encode_fingerprint(&mut self, _: &Fingerprint) -> Result<(), E::Error> {
|
|
||||||
panic!("Cannot encode `Fingerprint` with `{}`", std::any::type_name::<E>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FingerprintEncoder for opaque::Encoder {
|
|
||||||
fn encode_fingerprint(&mut self, f: &Fingerprint) -> EncodeResult {
|
|
||||||
let bytes: [u8; 16] = unsafe { mem::transmute([f.0.to_le(), f.1.to_le()]) };
|
|
||||||
self.emit_raw_bytes(&bytes)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FingerprintEncoder for opaque::FileEncoder {
|
impl<D: rustc_serialize::Decoder> Decodable<D> for Fingerprint {
|
||||||
fn encode_fingerprint(&mut self, f: &Fingerprint) -> FileEncodeResult {
|
#[inline]
|
||||||
let bytes: [u8; 16] = unsafe { mem::transmute([f.0.to_le(), f.1.to_le()]) };
|
fn decode(d: &mut D) -> Result<Self, D::Error> {
|
||||||
self.emit_raw_bytes(&bytes)
|
let mut bytes: [MaybeUninit<u8>; 16] = MaybeUninit::uninit_array();
|
||||||
}
|
d.read_raw_bytes(&mut bytes)?;
|
||||||
}
|
|
||||||
|
|
||||||
impl<D: rustc_serialize::Decoder> FingerprintDecoder for D {
|
let [l, r]: [u64; 2] = unsafe { mem::transmute(bytes) };
|
||||||
default fn decode_fingerprint(&mut self) -> Result<Fingerprint, D::Error> {
|
Ok(Fingerprint(u64::from_le(l), u64::from_le(r)))
|
||||||
panic!("Cannot decode `Fingerprint` with `{}`", std::any::type_name::<D>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FingerprintDecoder for opaque::Decoder<'_> {
|
|
||||||
fn decode_fingerprint(&mut self) -> Result<Fingerprint, String> {
|
|
||||||
Fingerprint::decode_opaque(self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::rmeta::*;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_attr as attr;
|
use rustc_attr as attr;
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::svh::Svh;
|
use rustc_data_structures::svh::Svh;
|
||||||
use rustc_data_structures::sync::{Lock, LockGuard, Lrc, OnceCell};
|
use rustc_data_structures::sync::{Lock, LockGuard, Lrc, OnceCell};
|
||||||
|
@ -351,12 +350,6 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for DefIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> FingerprintDecoder for DecodeContext<'a, 'tcx> {
|
|
||||||
fn decode_fingerprint(&mut self) -> Result<Fingerprint, String> {
|
|
||||||
Fingerprint::decode_opaque(&mut self.opaque)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
|
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
|
||||||
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Result<SyntaxContext, String> {
|
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Result<SyntaxContext, String> {
|
||||||
let cdata = decoder.cdata();
|
let cdata = decoder.cdata();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::rmeta::table::{FixedSizeEncoding, TableBuilder};
|
use crate::rmeta::table::{FixedSizeEncoding, TableBuilder};
|
||||||
use crate::rmeta::*;
|
use crate::rmeta::*;
|
||||||
|
|
||||||
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintEncoder};
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
use rustc_data_structures::sync::{join, par_iter, Lrc, ParallelIterator};
|
use rustc_data_structures::sync::{join, par_iter, Lrc, ParallelIterator};
|
||||||
|
@ -308,12 +307,6 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Span {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> FingerprintEncoder for EncodeContext<'a, 'tcx> {
|
|
||||||
fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), Self::Error> {
|
|
||||||
self.opaque.encode_fingerprint(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
|
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
|
||||||
const CLEAR_CROSS_CRATE: bool = true;
|
const CLEAR_CROSS_CRATE: bool = true;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::mir::{self, interpret};
|
||||||
use crate::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
|
use crate::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
|
||||||
use crate::ty::context::TyCtxt;
|
use crate::ty::context::TyCtxt;
|
||||||
use crate::ty::{self, Ty};
|
use crate::ty::{self, Ty};
|
||||||
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder, FingerprintEncoder};
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
||||||
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, OnceCell};
|
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, OnceCell};
|
||||||
use rustc_data_structures::thin_vec::ThinVec;
|
use rustc_data_structures::thin_vec::ThinVec;
|
||||||
|
@ -913,12 +912,6 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for DefId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> FingerprintDecoder for CacheDecoder<'a, 'tcx> {
|
|
||||||
fn decode_fingerprint(&mut self) -> Result<Fingerprint, Self::Error> {
|
|
||||||
Fingerprint::decode_opaque(&mut self.opaque)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashSet<LocalDefId> {
|
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashSet<LocalDefId> {
|
||||||
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result<Self, String> {
|
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result<Self, String> {
|
||||||
RefDecodable::decode(d)
|
RefDecodable::decode(d)
|
||||||
|
@ -1011,12 +1004,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx, E: OpaqueEncoder> FingerprintEncoder for CacheEncoder<'a, 'tcx, E> {
|
|
||||||
fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), E::Error> {
|
|
||||||
self.encoder.encode_fingerprint(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx, E> Encodable<CacheEncoder<'a, 'tcx, E>> for SyntaxContext
|
impl<'a, 'tcx, E> Encodable<CacheEncoder<'a, 'tcx, E>> for SyntaxContext
|
||||||
where
|
where
|
||||||
E: 'a + OpaqueEncoder,
|
E: 'a + OpaqueEncoder,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue