diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 4e2495ab14c9ada093e2ca319646730e8b3b6900..e5b61d7000a32c1d1d56b463ec2c97e2007003cf 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -31,7 +31,7 @@ use rustc_data_structures::sync::Lrc; use rustc_data_structures::thin_vec::ThinVec; use rustc_macros::HashStable_Generic; -use rustc_serialize::{self, Decoder, Encoder}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -2488,11 +2488,11 @@ pub struct AttrId { } } -impl rustc_serialize::Encodable for AttrId { +impl Encodable for AttrId { fn encode(&self, _s: &mut S) {} } -impl rustc_serialize::Decodable for AttrId { +impl Decodable for AttrId { fn decode(_: &mut D) -> AttrId { crate::attr::mk_attr_id() } diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 771157dcad95493a9c412549fb852f661412b620..750432b0b26530450f0a999762cb6d9751716c2c 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -29,7 +29,8 @@ use rustc_middle::middle::dependency_format::Dependencies; use rustc_middle::middle::exported_symbols::SymbolExportKind; use rustc_middle::ty::query::{ExternProviders, Providers}; -use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder}; +use rustc_serialize::opaque::{MemDecoder, MemEncoder}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT}; use rustc_session::cstore::{self, CrateSource}; use rustc_session::utils::NativeLibKind; @@ -203,7 +204,7 @@ pub fn looks_like_rust_object_file(filename: &str) -> bool { impl CodegenResults { pub fn serialize_rlink(codegen_results: &CodegenResults) -> Vec { - let mut encoder = opaque::Encoder::new(); + let mut encoder = MemEncoder::new(); encoder.emit_raw_bytes(RLINK_MAGIC); // `emit_raw_bytes` is used to make sure that the version representation does not depend on // Encoder's inner representation of `u32`. @@ -230,7 +231,7 @@ pub fn deserialize_rlink(data: Vec) -> Result { return Err(".rlink file was produced with encoding version {version_array}, but the current version is {RLINK_VERSION}".to_string()); } - let mut decoder = opaque::Decoder::new(&data[4..], 0); + let mut decoder = MemDecoder::new(&data[4..], 0); let rustc_version = decoder.read_str(); let current_version = RUSTC_VERSION.unwrap(); if rustc_version != current_version { diff --git a/compiler/rustc_data_structures/src/fingerprint.rs b/compiler/rustc_data_structures/src/fingerprint.rs index a032b039f34ef234f980dddd4de6ab7c02ffaf8c..5ff2d18dd2be375bd77725bb8f217b25110840cf 100644 --- a/compiler/rustc_data_structures/src/fingerprint.rs +++ b/compiler/rustc_data_structures/src/fingerprint.rs @@ -1,5 +1,5 @@ use crate::stable_hasher; -use rustc_serialize::{Decodable, Encodable}; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use std::convert::TryInto; use std::hash::{Hash, Hasher}; @@ -142,14 +142,14 @@ fn finish(hasher: stable_hasher::StableHasher) -> Self { impl_stable_hash_via_hash!(Fingerprint); -impl Encodable for Fingerprint { +impl Encodable for Fingerprint { #[inline] fn encode(&self, s: &mut E) { s.emit_raw_bytes(&self.to_le_bytes()); } } -impl Decodable for Fingerprint { +impl Decodable for Fingerprint { #[inline] fn decode(d: &mut D) -> Self { Fingerprint::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap()) @@ -184,7 +184,7 @@ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { } } -impl Encodable for PackedFingerprint { +impl Encodable for PackedFingerprint { #[inline] fn encode(&self, s: &mut E) { // Copy to avoid taking reference to packed field. @@ -193,7 +193,7 @@ fn encode(&self, s: &mut E) { } } -impl Decodable for PackedFingerprint { +impl Decodable for PackedFingerprint { #[inline] fn decode(d: &mut D) -> Self { Self(Fingerprint::decode(d)) diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 9de14950aa8d33d23ad9bd353261e5d1eff99bf6..9c325faae80588ec57b9a3496e86a8a7309dbad6 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -4,7 +4,7 @@ use rustc_data_structures::memmap::Mmap; use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId}; use rustc_middle::ty::OnDiskCache; -use rustc_serialize::opaque::Decoder; +use rustc_serialize::opaque::MemDecoder; use rustc_serialize::Decodable; use rustc_session::config::IncrementalStateAssertion; use rustc_session::Session; @@ -156,7 +156,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture { if let LoadResult::Ok { data: (work_products_data, start_pos) } = load_result { // Decode the list of work_products - let mut work_product_decoder = Decoder::new(&work_products_data[..], start_pos); + let mut work_product_decoder = MemDecoder::new(&work_products_data[..], start_pos); let work_products: Vec = Decodable::decode(&mut work_product_decoder); @@ -193,7 +193,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture { LoadResult::DataOutOfDate => LoadResult::DataOutOfDate, LoadResult::Error { message } => LoadResult::Error { message }, LoadResult::Ok { data: (bytes, start_pos) } => { - let mut decoder = Decoder::new(&bytes, start_pos); + let mut decoder = MemDecoder::new(&bytes, start_pos); let prev_commandline_args_hash = u64::decode(&mut decoder); if prev_commandline_args_hash != expected_hash { diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 186031d4586aa0893f292e7527b31e10a2f9b4e0..c1ded99a25af56fd51bd35c24ce6f6bfbe4cd6f7 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -26,7 +26,8 @@ use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::GeneratorDiagnosticData; use rustc_middle::ty::{self, ParameterizedOverTcx, Ty, TyCtxt, Visibility}; -use rustc_serialize::{opaque, Decodable, Decoder}; +use rustc_serialize::opaque::MemDecoder; +use rustc_serialize::{Decodable, Decoder}; use rustc_session::cstore::{ CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, }; @@ -154,7 +155,7 @@ struct ImportedSourceFile { } pub(super) struct DecodeContext<'a, 'tcx> { - opaque: opaque::Decoder<'a>, + opaque: MemDecoder<'a>, cdata: Option>, blob: &'a MetadataBlob, sess: Option<&'tcx Session>, @@ -186,7 +187,7 @@ fn tcx(self) -> Option> { fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> { let tcx = self.tcx(); DecodeContext { - opaque: opaque::Decoder::new(self.blob(), pos), + opaque: MemDecoder::new(self.blob(), pos), cdata: self.cdata(), blob: self.blob(), sess: self.sess().or(tcx.map(|tcx| tcx.sess)), @@ -418,7 +419,7 @@ fn with_position(&mut self, pos: usize, f: F) -> R where F: FnOnce(&mut Self) -> R, { - let new_opaque = opaque::Decoder::new(self.opaque.data, pos); + let new_opaque = MemDecoder::new(self.opaque.data, pos); let old_opaque = mem::replace(&mut self.opaque, new_opaque); let old_state = mem::replace(&mut self.lazy_state, LazyState::NoNode); let r = f(self); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 50c09aaf8d445d848233b74eb08fcca0a9aaa398..26fb21020008a712fcaefe98c930f4476570522f 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -27,7 +27,8 @@ use rustc_middle::ty::fast_reject::{self, SimplifiedType, TreatParams}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt}; -use rustc_serialize::{opaque, Encodable, Encoder}; +use rustc_serialize::opaque::MemEncoder; +use rustc_serialize::{Encodable, Encoder}; use rustc_session::config::CrateType; use rustc_session::cstore::{ForeignModule, LinkagePreference, NativeLib}; use rustc_span::hygiene::{ExpnIndex, HygieneEncodeContext, MacroKind}; @@ -43,7 +44,7 @@ use tracing::{debug, trace}; pub(super) struct EncodeContext<'a, 'tcx> { - opaque: opaque::Encoder, + opaque: MemEncoder, tcx: TyCtxt<'tcx>, feat: &'tcx rustc_feature::Features, @@ -93,8 +94,8 @@ pub(super) struct EncodeContext<'a, 'tcx> { } impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> { - type Ok = ::Ok; - type Err = ::Err; + type Ok = ::Ok; + type Err = ::Err; encoder_methods! { emit_usize(usize); @@ -2180,7 +2181,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { } fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata { - let mut encoder = opaque::Encoder::new(); + let mut encoder = MemEncoder::new(); encoder.emit_raw_bytes(METADATA_HEADER); // Will be filled with the root position after encoding everything. diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index fb2ffe1d73d96b46c514112537e2139d48cdd772..04f0847f5cccc4d1a0c01cc67aabf0445ac2219b 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -22,7 +22,7 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, ReprOptions, Ty}; use rustc_middle::ty::{GeneratorDiagnosticData, ParameterizedOverTcx, TyCtxt}; -use rustc_serialize::opaque::Encoder; +use rustc_serialize::opaque::MemEncoder; use rustc_session::config::SymbolManglingVersion; use rustc_session::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib}; use rustc_span::edition::Edition; @@ -323,7 +323,7 @@ struct TableBuilders { } impl TableBuilders { - fn encode(&self, buf: &mut Encoder) -> LazyTables { + fn encode(&self, buf: &mut MemEncoder) -> LazyTables { LazyTables { $($name: self.$name.encode(buf)),+ } diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 8baa67a8f9fcf91cddcd8568e36b7fe44996276b..5ab4269ae99ade6d44f21fba1b2b1af707b5ef86 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -4,8 +4,8 @@ use rustc_hir::def::{CtorKind, CtorOf}; use rustc_index::vec::Idx; use rustc_middle::ty::ParameterizedOverTcx; -use rustc_serialize::opaque::Encoder; -use rustc_serialize::Encoder as _; +use rustc_serialize::opaque::MemEncoder; +use rustc_serialize::Encoder; use rustc_span::hygiene::MacroKind; use std::convert::TryInto; use std::marker::PhantomData; @@ -281,7 +281,7 @@ pub(crate) fn set(&mut self, i: I, value: T) Some(value).write_to_bytes(&mut self.blocks[i]); } - pub(crate) fn encode(&self, buf: &mut Encoder) -> LazyTable + pub(crate) fn encode(&self, buf: &mut MemEncoder) -> LazyTable where Option: FixedSizeEncoding, { diff --git a/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs b/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs index 096bf8cbc158a1a996b58d8979c3e0aa13cb7687..1279f5aee369194446ff1705cabb0151528db50a 100644 --- a/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs +++ b/compiler/rustc_middle/src/mir/graph_cyclic_cache.rs @@ -3,7 +3,7 @@ }; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::OnceCell; -use rustc_serialize as serialize; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; /// Helper type to cache the result of `graph::is_cyclic`. #[derive(Clone, Debug)] @@ -36,17 +36,17 @@ pub(super) fn invalidate(&mut self) { } } -impl serialize::Encodable for GraphIsCyclicCache { +impl Encodable for GraphIsCyclicCache { #[inline] fn encode(&self, s: &mut S) { - serialize::Encodable::encode(&(), s); + Encodable::encode(&(), s); } } -impl serialize::Decodable for GraphIsCyclicCache { +impl Decodable for GraphIsCyclicCache { #[inline] fn decode(d: &mut D) -> Self { - let () = serialize::Decodable::decode(d); + let () = Decodable::decode(d); Self::new() } } diff --git a/compiler/rustc_middle/src/mir/predecessors.rs b/compiler/rustc_middle/src/mir/predecessors.rs index 9bc0cb1138ff1ac0ee39eac77283817bc4f402fa..620cf7e336ba47274f0521d7e13e114305fcc6c8 100644 --- a/compiler/rustc_middle/src/mir/predecessors.rs +++ b/compiler/rustc_middle/src/mir/predecessors.rs @@ -3,7 +3,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::OnceCell; use rustc_index::vec::IndexVec; -use rustc_serialize as serialize; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use smallvec::SmallVec; use crate::mir::{BasicBlock, BasicBlockData}; @@ -54,12 +54,12 @@ pub(super) fn compute( } } -impl serialize::Encodable for PredecessorCache { +impl Encodable for PredecessorCache { #[inline] fn encode(&self, _s: &mut S) {} } -impl serialize::Decodable for PredecessorCache { +impl Decodable for PredecessorCache { #[inline] fn decode(_: &mut D) -> Self { Self::new() diff --git a/compiler/rustc_middle/src/mir/switch_sources.rs b/compiler/rustc_middle/src/mir/switch_sources.rs index 4872a7835e3fadea4e2cc066be0997cb74f9cfa6..99d13fcfef43e32e2d326e898b6c5813b08e3d4b 100644 --- a/compiler/rustc_middle/src/mir/switch_sources.rs +++ b/compiler/rustc_middle/src/mir/switch_sources.rs @@ -5,7 +5,7 @@ use rustc_data_structures::stable_map::FxHashMap; use rustc_data_structures::sync::OnceCell; use rustc_index::vec::IndexVec; -use rustc_serialize as serialize; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use smallvec::SmallVec; use crate::mir::{BasicBlock, BasicBlockData, Terminator, TerminatorKind}; @@ -54,12 +54,12 @@ pub(super) fn compute( } } -impl serialize::Encodable for SwitchSourceCache { +impl Encodable for SwitchSourceCache { #[inline] fn encode(&self, _s: &mut S) {} } -impl serialize::Decodable for SwitchSourceCache { +impl Decodable for SwitchSourceCache { #[inline] fn decode(_: &mut D) -> Self { Self::new() diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index f745e55307ae23a661b1e16528e84c65b0772c61..7228e3f33b126e5bcf16e882c94b536e8cc92e06 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -1,7 +1,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::OnceCell; use rustc_index::bit_set::BitSet; -use rustc_serialize as serialize; +use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use super::*; @@ -365,12 +365,12 @@ pub(super) fn compute(&self, body: &Body<'_>) -> &[BasicBlock] { } } -impl serialize::Encodable for PostorderCache { +impl Encodable for PostorderCache { #[inline] fn encode(&self, _s: &mut S) {} } -impl serialize::Decodable for PostorderCache { +impl Decodable for PostorderCache { #[inline] fn decode(_: &mut D) -> Self { Self::new() diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index c2c876f7f1a128756128d4707d90b9535f9aa33e..d7327ca4bc60200f56dfb477856ef61f1bc78379 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -15,7 +15,7 @@ use rustc_query_system::dep_graph::DepContext; use rustc_query_system::query::{QueryCache, QueryContext, QuerySideEffects}; use rustc_serialize::{ - opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize}, + opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder}, Decodable, Decoder, Encodable, Encoder, }; use rustc_session::Session; @@ -158,7 +158,7 @@ fn new(sess: &'sess Session, data: Mmap, start_pos: usize) -> Self { // Wrap in a scope so we can borrow `data`. let footer: Footer = { - let mut decoder = opaque::Decoder::new(&data, start_pos); + let mut decoder = MemDecoder::new(&data, start_pos); // Decode the *position* of the footer, which can be found in the // last 8 bytes of the file. @@ -437,7 +437,7 @@ fn with_decoder<'a, 'tcx, T, F: for<'s> FnOnce(&mut CacheDecoder<'s, 'tcx>) -> T let serialized_data = self.serialized_data.read(); let mut decoder = CacheDecoder { tcx, - opaque: opaque::Decoder::new(serialized_data.as_deref().unwrap_or(&[]), pos.to_usize()), + opaque: MemDecoder::new(serialized_data.as_deref().unwrap_or(&[]), pos.to_usize()), source_map: self.source_map, file_index_to_file: &self.file_index_to_file, file_index_to_stable_id: &self.file_index_to_stable_id, @@ -458,7 +458,7 @@ fn with_decoder<'a, 'tcx, T, F: for<'s> FnOnce(&mut CacheDecoder<'s, 'tcx>) -> T /// will also handle things that contain `Ty` instances. pub struct CacheDecoder<'a, 'tcx> { tcx: TyCtxt<'tcx>, - opaque: opaque::Decoder<'a>, + opaque: MemDecoder<'a>, source_map: &'a SourceMap, file_index_to_file: &'a Lock>>, file_index_to_stable_id: &'a FxHashMap, @@ -510,7 +510,7 @@ trait DecoderWithPosition: Decoder { fn position(&self) -> usize; } -impl<'a> DecoderWithPosition for opaque::Decoder<'a> { +impl<'a> DecoderWithPosition for MemDecoder<'a> { fn position(&self) -> usize { self.position() } @@ -586,7 +586,7 @@ fn with_position(&mut self, pos: usize, f: F) -> R { debug_assert!(pos < self.opaque.data.len()); - let new_opaque = opaque::Decoder::new(self.opaque.data, pos); + let new_opaque = MemDecoder::new(self.opaque.data, pos); let old_opaque = mem::replace(&mut self.opaque, new_opaque); let r = f(self); self.opaque = old_opaque; diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index 7fde9c0119b855e30c588e376ec148e240d08523..d583b45698ac4160b50f852adc91f781b3bebcc4 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -19,7 +19,7 @@ use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sync::Lock; use rustc_index::vec::{Idx, IndexVec}; -use rustc_serialize::opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize}; +use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use smallvec::SmallVec; use std::convert::TryInto; @@ -96,11 +96,11 @@ pub fn node_count(&self) -> usize { } } -impl<'a, K: DepKind + Decodable>> Decodable> +impl<'a, K: DepKind + Decodable>> Decodable> for SerializedDepGraph { #[instrument(level = "debug", skip(d))] - fn decode(d: &mut opaque::Decoder<'a>) -> SerializedDepGraph { + fn decode(d: &mut MemDecoder<'a>) -> SerializedDepGraph { let start_position = d.position(); // The last 16 bytes are the node count and edge count. diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index b2dbf937eb75a7155448945ebb2c3e6c7e03e10a..f828c0b71063d85c1966e47bcef5eae2ef379996 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -1,5 +1,5 @@ use crate::leb128::{self, max_leb128_len}; -use crate::serialize::{self, Decoder as _, Encoder as _}; +use crate::serialize::{Decodable, Decoder, Encodable, Encoder}; use std::convert::TryInto; use std::fs::File; use std::io::{self, Write}; @@ -11,13 +11,13 @@ // Encoder // ----------------------------------------------------------------------------- -pub struct Encoder { +pub struct MemEncoder { pub data: Vec, } -impl Encoder { - pub fn new() -> Encoder { - Encoder { data: vec![] } +impl MemEncoder { + pub fn new() -> MemEncoder { + MemEncoder { data: vec![] } } #[inline] @@ -53,7 +53,7 @@ pub fn position(&self) -> usize { /// [utf8]: https://en.wikipedia.org/w/index.php?title=UTF-8&oldid=1058865525#Codepage_layout const STR_SENTINEL: u8 = 0xC1; -impl serialize::Encoder for Encoder { +impl Encoder for MemEncoder { type Ok = Vec; type Err = !; @@ -161,7 +161,7 @@ fn finish(self) -> Result { // `FileEncoder` encodes data to file via fixed-size buffer. // // When encoding large amounts of data to a file, using `FileEncoder` may be -// preferred over using `Encoder` to encode to a `Vec`, and then writing the +// preferred over using `MemEncoder` to encode to a `Vec`, and then writing the // `Vec` to file, as the latter uses as much memory as there is encoded data, // while the former uses the fixed amount of memory allocated to the buffer. // `FileEncoder` also has the advantage of not needing to reallocate as data @@ -425,7 +425,7 @@ fn drop(&mut self) { }}; } -impl serialize::Encoder for FileEncoder { +impl Encoder for FileEncoder { type Ok = usize; type Err = io::Error; @@ -535,15 +535,15 @@ fn finish(mut self) -> Result { // Decoder // ----------------------------------------------------------------------------- -pub struct Decoder<'a> { +pub struct MemDecoder<'a> { pub data: &'a [u8], position: usize, } -impl<'a> Decoder<'a> { +impl<'a> MemDecoder<'a> { #[inline] - pub fn new(data: &'a [u8], position: usize) -> Decoder<'a> { - Decoder { data, position } + pub fn new(data: &'a [u8], position: usize) -> MemDecoder<'a> { + MemDecoder { data, position } } #[inline] @@ -566,7 +566,7 @@ pub fn advance(&mut self, bytes: usize) { ($dec:expr, $fun:ident) => {{ leb128::$fun($dec.data, &mut $dec.position) }}; } -impl<'a> serialize::Decoder for Decoder<'a> { +impl<'a> Decoder for MemDecoder<'a> { #[inline] fn read_u128(&mut self) -> u128 { read_leb128!(self, read_u128_leb128) @@ -688,25 +688,25 @@ fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] { // Specialize encoding byte slices. This specialization also applies to encoding `Vec`s, etc., // since the default implementations call `encode` on their slices internally. -impl serialize::Encodable for [u8] { - fn encode(&self, e: &mut Encoder) { - serialize::Encoder::emit_usize(e, self.len()); +impl Encodable for [u8] { + fn encode(&self, e: &mut MemEncoder) { + Encoder::emit_usize(e, self.len()); e.emit_raw_bytes(self); } } -impl serialize::Encodable for [u8] { +impl Encodable for [u8] { fn encode(&self, e: &mut FileEncoder) { - serialize::Encoder::emit_usize(e, self.len()); + Encoder::emit_usize(e, self.len()); e.emit_raw_bytes(self); } } // Specialize decoding `Vec`. This specialization also applies to decoding `Box<[u8]>`s, etc., // since the default implementations call `decode` to produce a `Vec` internally. -impl<'a> serialize::Decodable> for Vec { - fn decode(d: &mut Decoder<'a>) -> Self { - let len = serialize::Decoder::read_usize(d); +impl<'a> Decodable> for Vec { + fn decode(d: &mut MemDecoder<'a>) -> Self { + let len = Decoder::read_usize(d); d.read_raw_bytes(len).to_owned() } } @@ -718,9 +718,9 @@ impl IntEncodedWithFixedSize { pub const ENCODED_SIZE: usize = 8; } -impl serialize::Encodable for IntEncodedWithFixedSize { +impl Encodable for IntEncodedWithFixedSize { #[inline] - fn encode(&self, e: &mut Encoder) { + fn encode(&self, e: &mut MemEncoder) { let _start_pos = e.position(); e.emit_raw_bytes(&self.0.to_le_bytes()); let _end_pos = e.position(); @@ -728,7 +728,7 @@ fn encode(&self, e: &mut Encoder) { } } -impl serialize::Encodable for IntEncodedWithFixedSize { +impl Encodable for IntEncodedWithFixedSize { #[inline] fn encode(&self, e: &mut FileEncoder) { let _start_pos = e.position(); @@ -738,9 +738,9 @@ fn encode(&self, e: &mut FileEncoder) { } } -impl<'a> serialize::Decodable> for IntEncodedWithFixedSize { +impl<'a> Decodable> for IntEncodedWithFixedSize { #[inline] - fn decode(decoder: &mut Decoder<'a>) -> IntEncodedWithFixedSize { + fn decode(decoder: &mut MemDecoder<'a>) -> IntEncodedWithFixedSize { let _start_pos = decoder.position(); let bytes = decoder.read_raw_bytes(IntEncodedWithFixedSize::ENCODED_SIZE); let value = u64::from_le_bytes(bytes.try_into().unwrap()); diff --git a/compiler/rustc_serialize/tests/opaque.rs b/compiler/rustc_serialize/tests/opaque.rs index 703b7f5e7a5f468f217b70466949c5ede51713cc..4eafb6fabde8e683028a261249f25484744468f2 100644 --- a/compiler/rustc_serialize/tests/opaque.rs +++ b/compiler/rustc_serialize/tests/opaque.rs @@ -1,7 +1,7 @@ #![allow(rustc::internal)] use rustc_macros::{Decodable, Encodable}; -use rustc_serialize::opaque::{Decoder, Encoder}; +use rustc_serialize::opaque::{MemDecoder, MemEncoder}; use rustc_serialize::{Decodable, Encodable, Encoder as EncoderTrait}; use std::fmt::Debug; @@ -28,16 +28,18 @@ struct Struct { q: Option, } -fn check_round_trip + for<'a> Decodable> + PartialEq + Debug>( +fn check_round_trip< + T: Encodable + for<'a> Decodable> + PartialEq + Debug, +>( values: Vec, ) { - let mut encoder = Encoder::new(); + let mut encoder = MemEncoder::new(); for value in &values { Encodable::encode(value, &mut encoder); } let data = encoder.finish().unwrap(); - let mut decoder = Decoder::new(&data[..], 0); + let mut decoder = MemDecoder::new(&data[..], 0); for value in values { let decoded = Decodable::decode(&mut decoder); diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index d7e2f621065f03e0e7758152080e59ac577d9e79..5d3d56b1e66998d4f3e1b9557a5be051ed561751 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -1911,13 +1911,13 @@ fn sub(self, rhs: $ident) -> $ident { pub struct CharPos(pub usize); } -impl Encodable for BytePos { +impl Encodable for BytePos { fn encode(&self, s: &mut S) { s.emit_u32(self.0); } } -impl Decodable for BytePos { +impl Decodable for BytePos { fn decode(d: &mut D) -> BytePos { BytePos(d.read_u32()) } diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index a6a0d02c8ba992caf9acb36ce7cc6c19d0dbba63..9407218439993f71fa2b0e2f109e403e055b81ff 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -14,7 +14,7 @@ use self::TyKind::*; use rustc_data_structures::stable_hasher::HashStable; -use rustc_serialize::{Decodable, Encodable}; +use rustc_serialize::{Decodable, Decoder, Encodable}; /// Defines the kinds of types used by the type system. /// @@ -833,56 +833,34 @@ impl> Decodable for TyKind I::AllocId: Decodable, { fn decode(d: &mut D) -> Self { - match rustc_serialize::Decoder::read_usize(d) { + match Decoder::read_usize(d) { 0 => Bool, 1 => Char, - 2 => Int(rustc_serialize::Decodable::decode(d)), - 3 => Uint(rustc_serialize::Decodable::decode(d)), - 4 => Float(rustc_serialize::Decodable::decode(d)), - 5 => Adt(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d)), - 6 => Foreign(rustc_serialize::Decodable::decode(d)), + 2 => Int(Decodable::decode(d)), + 3 => Uint(Decodable::decode(d)), + 4 => Float(Decodable::decode(d)), + 5 => Adt(Decodable::decode(d), Decodable::decode(d)), + 6 => Foreign(Decodable::decode(d)), 7 => Str, - 8 => { - Array(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d)) - } - 9 => Slice(rustc_serialize::Decodable::decode(d)), - 10 => RawPtr(rustc_serialize::Decodable::decode(d)), - 11 => Ref( - rustc_serialize::Decodable::decode(d), - rustc_serialize::Decodable::decode(d), - rustc_serialize::Decodable::decode(d), - ), - 12 => { - FnDef(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d)) - } - 13 => FnPtr(rustc_serialize::Decodable::decode(d)), - 14 => Dynamic( - rustc_serialize::Decodable::decode(d), - rustc_serialize::Decodable::decode(d), - ), - 15 => Closure( - rustc_serialize::Decodable::decode(d), - rustc_serialize::Decodable::decode(d), - ), - 16 => Generator( - rustc_serialize::Decodable::decode(d), - rustc_serialize::Decodable::decode(d), - rustc_serialize::Decodable::decode(d), - ), - 17 => GeneratorWitness(rustc_serialize::Decodable::decode(d)), + 8 => Array(Decodable::decode(d), Decodable::decode(d)), + 9 => Slice(Decodable::decode(d)), + 10 => RawPtr(Decodable::decode(d)), + 11 => Ref(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), + 12 => FnDef(Decodable::decode(d), Decodable::decode(d)), + 13 => FnPtr(Decodable::decode(d)), + 14 => Dynamic(Decodable::decode(d), Decodable::decode(d)), + 15 => Closure(Decodable::decode(d), Decodable::decode(d)), + 16 => Generator(Decodable::decode(d), Decodable::decode(d), Decodable::decode(d)), + 17 => GeneratorWitness(Decodable::decode(d)), 18 => Never, - 19 => Tuple(rustc_serialize::Decodable::decode(d)), - 20 => Projection(rustc_serialize::Decodable::decode(d)), - 21 => { - Opaque(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d)) - } - 22 => Param(rustc_serialize::Decodable::decode(d)), - 23 => { - Bound(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d)) - } - 24 => Placeholder(rustc_serialize::Decodable::decode(d)), - 25 => Infer(rustc_serialize::Decodable::decode(d)), - 26 => Error(rustc_serialize::Decodable::decode(d)), + 19 => Tuple(Decodable::decode(d)), + 20 => Projection(Decodable::decode(d)), + 21 => Opaque(Decodable::decode(d), Decodable::decode(d)), + 22 => Param(Decodable::decode(d)), + 23 => Bound(Decodable::decode(d), Decodable::decode(d)), + 24 => Placeholder(Decodable::decode(d)), + 25 => Infer(Decodable::decode(d)), + 26 => Error(Decodable::decode(d)), _ => panic!( "{}", format!( diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index 242f926967c937201b83318c18b55e895f44d3ec..da09ae9dd0662152c3efbceef17496fd157e4734 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -17,7 +17,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, TyCtxt}; use rustc_serialize::{ - opaque::{Decoder, FileEncoder}, + opaque::{FileEncoder, MemDecoder}, Decodable, Encodable, Encoder, }; use rustc_session::getopts; @@ -336,7 +336,7 @@ pub(crate) fn load_call_locations( let mut all_calls: AllCallLocations = FxHashMap::default(); for path in with_examples { let bytes = fs::read(&path).map_err(|e| format!("{} (for path {})", e, path))?; - let mut decoder = Decoder::new(&bytes, 0); + let mut decoder = MemDecoder::new(&bytes, 0); let calls = AllCallLocations::decode(&mut decoder); for (function, fn_calls) in calls.into_iter() { diff --git a/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs b/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs index a09deeec4f182f6c1cdc136f65d2820d5d75cb68..4ad4ef60a5294728fef1b8d20bbb089bb2cb2695 100644 --- a/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs +++ b/src/test/ui-fulldeps/deriving-encodable-decodable-box.rs @@ -7,7 +7,7 @@ extern crate rustc_serialize; use rustc_macros::{Decodable, Encodable}; -use rustc_serialize::opaque; +use rustc_serialize::opaque::{MemDecoder, MemEncoder}; use rustc_serialize::{Decodable, Encodable, Encoder}; #[derive(Encodable, Decodable)] @@ -18,11 +18,11 @@ struct A { fn main() { let obj = A { foo: Box::new([true, false]) }; - let mut encoder = opaque::Encoder::new(); + let mut encoder = MemEncoder::new(); obj.encode(&mut encoder); let data = encoder.finish().unwrap(); - let mut decoder = opaque::Decoder::new(&data, 0); + let mut decoder = MemDecoder::new(&data, 0); let obj2 = A::decode(&mut decoder); assert_eq!(obj.foo, obj2.foo); diff --git a/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs b/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs index 9b6fb0e580621ee2f7572ad6ae3aa9828b447e3c..3ac3abae692afc4ef605fe6d96d6ed050cb3151e 100644 --- a/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs +++ b/src/test/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs @@ -9,7 +9,7 @@ extern crate rustc_serialize; use rustc_macros::{Decodable, Encodable}; -use rustc_serialize::opaque; +use rustc_serialize::opaque::{MemDecoder, MemEncoder}; use rustc_serialize::{Decodable, Encodable, Encoder}; use std::cell::{Cell, RefCell}; @@ -27,11 +27,11 @@ struct B { fn main() { let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) }; - let mut encoder = opaque::Encoder::new(); + let mut encoder = MemEncoder::new(); obj.encode(&mut encoder); let data = encoder.finish().unwrap(); - let mut decoder = opaque::Decoder::new(&data, 0); + let mut decoder = MemDecoder::new(&data, 0); let obj2 = B::decode(&mut decoder); assert_eq!(obj.foo.get(), obj2.foo.get()); diff --git a/src/test/ui-fulldeps/issue-14021.rs b/src/test/ui-fulldeps/issue-14021.rs index 4241456367e46fe0a25377aa58eb4a5029ebe1c4..b7b6e1b860d358c6b7f512766f88ed0b58f26013 100644 --- a/src/test/ui-fulldeps/issue-14021.rs +++ b/src/test/ui-fulldeps/issue-14021.rs @@ -8,7 +8,7 @@ extern crate rustc_serialize; use rustc_macros::{Decodable, Encodable}; -use rustc_serialize::opaque; +use rustc_serialize::opaque::{MemDecoder, MemEncoder}; use rustc_serialize::{Decodable, Encodable, Encoder}; #[derive(Encodable, Decodable, PartialEq, Debug)] @@ -17,11 +17,11 @@ pub fn main() { let obj = UnitLikeStruct; - let mut encoder = opaque::Encoder::new(); + let mut encoder = MemEncoder::new(); obj.encode(&mut encoder); let data = encoder.finish().unwrap(); - let mut decoder = opaque::Decoder::new(&data, 0); + let mut decoder = MemDecoder::new(&data, 0); let obj2 = UnitLikeStruct::decode(&mut decoder); assert_eq!(obj, obj2);