Skip to content

Commit 11b3409

Browse files
committed
Remove FingerprintEncoder/Decoder.
1 parent 09a6388 commit 11b3409

File tree

4 files changed

+10
-83
lines changed

4 files changed

+10
-83
lines changed

compiler/rustc_data_structures/src/fingerprint.rs

+10-56
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use crate::stable_hasher;
2-
use rustc_serialize::{
3-
opaque::{self, EncodeResult, FileEncodeResult},
4-
Decodable, Decoder, Encodable, Encoder,
5-
};
2+
use rustc_serialize::{Decodable, Encodable};
63
use std::hash::{Hash, Hasher};
74
use std::mem::{self, MaybeUninit};
85

@@ -63,16 +60,6 @@ impl Fingerprint {
6360
pub fn to_hex(&self) -> String {
6461
format!("{:x}{:x}", self.0, self.1)
6562
}
66-
67-
pub fn decode_opaque(decoder: &mut opaque::Decoder<'_>) -> Result<Fingerprint, String> {
68-
let mut bytes: [MaybeUninit<u8>; 16] = MaybeUninit::uninit_array();
69-
70-
decoder.read_raw_bytes(&mut bytes)?;
71-
72-
let [l, r]: [u64; 2] = unsafe { mem::transmute(bytes) };
73-
74-
Ok(Fingerprint(u64::from_le(l), u64::from_le(r)))
75-
}
7663
}
7764

7865
impl std::fmt::Display for Fingerprint {
@@ -130,55 +117,22 @@ impl stable_hasher::StableHasherResult for Fingerprint {
130117
impl_stable_hash_via_hash!(Fingerprint);
131118

132119
impl<E: rustc_serialize::Encoder> Encodable<E> for Fingerprint {
120+
#[inline]
133121
fn encode(&self, s: &mut E) -> Result<(), E::Error> {
134-
s.encode_fingerprint(self)
122+
let bytes: [u8; 16] = unsafe { mem::transmute([self.0.to_le(), self.1.to_le()]) };
123+
s.emit_raw_bytes(&bytes)?;
124+
Ok(())
135125
}
136126
}
137127

138128
impl<D: rustc_serialize::Decoder> Decodable<D> for Fingerprint {
129+
#[inline]
139130
fn decode(d: &mut D) -> Result<Self, D::Error> {
140-
d.decode_fingerprint()
141-
}
142-
}
143-
144-
pub trait FingerprintEncoder: rustc_serialize::Encoder {
145-
fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), Self::Error>;
146-
}
147-
148-
pub trait FingerprintDecoder: rustc_serialize::Decoder {
149-
fn decode_fingerprint(&mut self) -> Result<Fingerprint, Self::Error>;
150-
}
151-
152-
impl<E: rustc_serialize::Encoder> FingerprintEncoder for E {
153-
default fn encode_fingerprint(&mut self, _: &Fingerprint) -> Result<(), E::Error> {
154-
panic!("Cannot encode `Fingerprint` with `{}`", std::any::type_name::<E>());
155-
}
156-
}
157-
158-
impl FingerprintEncoder for opaque::Encoder {
159-
fn encode_fingerprint(&mut self, f: &Fingerprint) -> EncodeResult {
160-
let bytes: [u8; 16] = unsafe { mem::transmute([f.0.to_le(), f.1.to_le()]) };
161-
self.emit_raw_bytes(&bytes)?;
162-
Ok(())
163-
}
164-
}
165-
166-
impl FingerprintEncoder for opaque::FileEncoder {
167-
fn encode_fingerprint(&mut self, f: &Fingerprint) -> FileEncodeResult {
168-
let bytes: [u8; 16] = unsafe { mem::transmute([f.0.to_le(), f.1.to_le()]) };
169-
self.emit_raw_bytes(&bytes)
170-
}
171-
}
172-
173-
impl<D: rustc_serialize::Decoder> FingerprintDecoder for D {
174-
default fn decode_fingerprint(&mut self) -> Result<Fingerprint, D::Error> {
175-
panic!("Cannot decode `Fingerprint` with `{}`", std::any::type_name::<D>());
176-
}
177-
}
131+
let mut bytes: [MaybeUninit<u8>; 16] = MaybeUninit::uninit_array();
132+
d.read_raw_bytes(&mut bytes)?;
178133

179-
impl FingerprintDecoder for opaque::Decoder<'_> {
180-
fn decode_fingerprint(&mut self) -> Result<Fingerprint, String> {
181-
Fingerprint::decode_opaque(self)
134+
let [l, r]: [u64; 2] = unsafe { mem::transmute(bytes) };
135+
Ok(Fingerprint(u64::from_le(l), u64::from_le(r)))
182136
}
183137
}
184138

compiler/rustc_metadata/src/rmeta/decoder.rs

-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::rmeta::*;
77
use rustc_ast as ast;
88
use rustc_attr as attr;
99
use rustc_data_structures::captures::Captures;
10-
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder};
1110
use rustc_data_structures::fx::FxHashMap;
1211
use rustc_data_structures::svh::Svh;
1312
use rustc_data_structures::sync::{Lock, LockGuard, Lrc, OnceCell};
@@ -351,12 +350,6 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for DefIndex {
351350
}
352351
}
353352

354-
impl<'a, 'tcx> FingerprintDecoder for DecodeContext<'a, 'tcx> {
355-
fn decode_fingerprint(&mut self) -> Result<Fingerprint, String> {
356-
Fingerprint::decode_opaque(&mut self.opaque)
357-
}
358-
}
359-
360353
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
361354
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> Result<SyntaxContext, String> {
362355
let cdata = decoder.cdata();

compiler/rustc_metadata/src/rmeta/encoder.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::rmeta::table::{FixedSizeEncoding, TableBuilder};
22
use crate::rmeta::*;
33

4-
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintEncoder};
54
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
65
use rustc_data_structures::stable_hasher::StableHasher;
76
use rustc_data_structures::sync::{join, par_iter, Lrc, ParallelIterator};
@@ -308,12 +307,6 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for Span {
308307
}
309308
}
310309

311-
impl<'a, 'tcx> FingerprintEncoder for EncodeContext<'a, 'tcx> {
312-
fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), Self::Error> {
313-
self.opaque.encode_fingerprint(f)
314-
}
315-
}
316-
317310
impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
318311
const CLEAR_CROSS_CRATE: bool = true;
319312

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::mir::{self, interpret};
44
use crate::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
55
use crate::ty::context::TyCtxt;
66
use crate::ty::{self, Ty};
7-
use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder, FingerprintEncoder};
87
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
98
use rustc_data_structures::sync::{HashMapExt, Lock, Lrc, OnceCell};
109
use rustc_data_structures::thin_vec::ThinVec;
@@ -913,12 +912,6 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for DefId {
913912
}
914913
}
915914

916-
impl<'a, 'tcx> FingerprintDecoder for CacheDecoder<'a, 'tcx> {
917-
fn decode_fingerprint(&mut self) -> Result<Fingerprint, Self::Error> {
918-
Fingerprint::decode_opaque(&mut self.opaque)
919-
}
920-
}
921-
922915
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx FxHashSet<LocalDefId> {
923916
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Result<Self, String> {
924917
RefDecodable::decode(d)
@@ -1011,12 +1004,6 @@ where
10111004
}
10121005
}
10131006

1014-
impl<'a, 'tcx, E: OpaqueEncoder> FingerprintEncoder for CacheEncoder<'a, 'tcx, E> {
1015-
fn encode_fingerprint(&mut self, f: &Fingerprint) -> Result<(), E::Error> {
1016-
self.encoder.encode_fingerprint(f)
1017-
}
1018-
}
1019-
10201007
impl<'a, 'tcx, E> Encodable<CacheEncoder<'a, 'tcx, E>> for SyntaxContext
10211008
where
10221009
E: 'a + OpaqueEncoder,

0 commit comments

Comments
 (0)