Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename rustc_serialize::opaque::Encoder as MemEncoder. #98083

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
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};
Expand Down Expand Up @@ -2488,11 +2488,11 @@ rustc_index::newtype_index! {
}
}

impl<S: Encoder> rustc_serialize::Encodable<S> for AttrId {
impl<S: Encoder> Encodable<S> for AttrId {
fn encode(&self, _s: &mut S) {}
}

impl<D: Decoder> rustc_serialize::Decodable<D> for AttrId {
impl<D: Decoder> Decodable<D> for AttrId {
fn decode(_: &mut D) -> AttrId {
crate::attr::mk_attr_id()
}
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use rustc_middle::dep_graph::WorkProduct;
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;
Expand Down Expand Up @@ -203,7 +204,7 @@ const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION");

impl CodegenResults {
pub fn serialize_rlink(codegen_results: &CodegenResults) -> Vec<u8> {
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`.
Expand All @@ -230,7 +231,7 @@ impl CodegenResults {
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 {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_data_structures/src/fingerprint.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -142,14 +142,14 @@ impl stable_hasher::StableHasherResult for Fingerprint {

impl_stable_hash_via_hash!(Fingerprint);

impl<E: rustc_serialize::Encoder> Encodable<E> for Fingerprint {
impl<E: Encoder> Encodable<E> for Fingerprint {
#[inline]
fn encode(&self, s: &mut E) {
s.emit_raw_bytes(&self.to_le_bytes());
}
}

impl<D: rustc_serialize::Decoder> Decodable<D> for Fingerprint {
impl<D: Decoder> Decodable<D> for Fingerprint {
#[inline]
fn decode(d: &mut D) -> Self {
Fingerprint::from_le_bytes(d.read_raw_bytes(16).try_into().unwrap())
Expand Down Expand Up @@ -184,7 +184,7 @@ impl std::fmt::Display for PackedFingerprint {
}
}

impl<E: rustc_serialize::Encoder> Encodable<E> for PackedFingerprint {
impl<E: Encoder> Encodable<E> for PackedFingerprint {
#[inline]
fn encode(&self, s: &mut E) {
// Copy to avoid taking reference to packed field.
Expand All @@ -193,7 +193,7 @@ impl<E: rustc_serialize::Encoder> Encodable<E> for PackedFingerprint {
}
}

impl<D: rustc_serialize::Decoder> Decodable<D> for PackedFingerprint {
impl<D: Decoder> Decodable<D> for PackedFingerprint {
#[inline]
fn decode(d: &mut D) -> Self {
Self(Fingerprint::decode(d))
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_data_structures::fx::FxHashMap;
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;
Expand Down Expand Up @@ -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<SerializedWorkProduct> =
Decodable::decode(&mut work_product_decoder);

Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use rustc_middle::ty::codec::TyDecoder;
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,
};
Expand Down Expand Up @@ -154,7 +155,7 @@ struct ImportedSourceFile {
}

pub(super) struct DecodeContext<'a, 'tcx> {
opaque: opaque::Decoder<'a>,
opaque: MemDecoder<'a>,
cdata: Option<CrateMetadataRef<'a>>,
blob: &'a MetadataBlob,
sess: Option<&'tcx Session>,
Expand Down Expand Up @@ -186,7 +187,7 @@ pub(super) trait Metadata<'a, 'tcx>: Copy {
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)),
Expand Down Expand Up @@ -418,7 +419,7 @@ impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> {
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);
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use rustc_middle::ty::codec::TyEncoder;
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};
Expand All @@ -43,7 +44,7 @@ use std::num::NonZeroUsize;
use tracing::{debug, trace};

pub(super) struct EncodeContext<'a, 'tcx> {
opaque: opaque::Encoder,
opaque: MemEncoder,
tcx: TyCtxt<'tcx>,
feat: &'tcx rustc_feature::Features,

Expand Down Expand Up @@ -93,8 +94,8 @@ macro_rules! encoder_methods {
}

impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> {
type Ok = <opaque::Encoder as Encoder>::Ok;
type Err = <opaque::Encoder as Encoder>::Err;
type Ok = <MemEncoder as Encoder>::Ok;
type Err = <MemEncoder as Encoder>::Err;

encoder_methods! {
emit_usize(usize);
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType;
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;
Expand Down Expand Up @@ -323,7 +323,7 @@ macro_rules! define_tables {
}

impl TableBuilders {
fn encode(&self, buf: &mut Encoder) -> LazyTables {
fn encode(&self, buf: &mut MemEncoder) -> LazyTables {
LazyTables {
$($name: self.$name.encode(buf)),+
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/rmeta/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use rustc_data_structures::fingerprint::Fingerprint;
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;
Expand Down Expand Up @@ -281,7 +281,7 @@ where
Some(value).write_to_bytes(&mut self.blocks[i]);
}

pub(crate) fn encode<const N: usize>(&self, buf: &mut Encoder) -> LazyTable<I, T>
pub(crate) fn encode<const N: usize>(&self, buf: &mut MemEncoder) -> LazyTable<I, T>
where
Option<T>: FixedSizeEncoding<ByteArray = [u8; N]>,
{
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/mir/graph_cyclic_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc_data_structures::graph::{
};
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)]
Expand Down Expand Up @@ -36,17 +36,17 @@ impl GraphIsCyclicCache {
}
}

impl<S: serialize::Encoder> serialize::Encodable<S> for GraphIsCyclicCache {
impl<S: Encoder> Encodable<S> for GraphIsCyclicCache {
#[inline]
fn encode(&self, s: &mut S) {
serialize::Encodable::encode(&(), s);
Encodable::encode(&(), s);
}
}

impl<D: serialize::Decoder> serialize::Decodable<D> for GraphIsCyclicCache {
impl<D: Decoder> Decodable<D> for GraphIsCyclicCache {
#[inline]
fn decode(d: &mut D) -> Self {
let () = serialize::Decodable::decode(d);
let () = Decodable::decode(d);
Self::new()
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/predecessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -54,12 +54,12 @@ impl PredecessorCache {
}
}

impl<S: serialize::Encoder> serialize::Encodable<S> for PredecessorCache {
impl<S: Encoder> Encodable<S> for PredecessorCache {
#[inline]
fn encode(&self, _s: &mut S) {}
}

impl<D: serialize::Decoder> serialize::Decodable<D> for PredecessorCache {
impl<D: Decoder> Decodable<D> for PredecessorCache {
#[inline]
fn decode(_: &mut D) -> Self {
Self::new()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/switch_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
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};
Expand Down Expand Up @@ -54,12 +54,12 @@ impl SwitchSourceCache {
}
}

impl<S: serialize::Encoder> serialize::Encodable<S> for SwitchSourceCache {
impl<S: Encoder> Encodable<S> for SwitchSourceCache {
#[inline]
fn encode(&self, _s: &mut S) {}
}

impl<D: serialize::Decoder> serialize::Decodable<D> for SwitchSourceCache {
impl<D: Decoder> Decodable<D> for SwitchSourceCache {
#[inline]
fn decode(_: &mut D) -> Self {
Self::new()
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/traversal.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -365,12 +365,12 @@ impl PostorderCache {
}
}

impl<S: serialize::Encoder> serialize::Encodable<S> for PostorderCache {
impl<S: Encoder> Encodable<S> for PostorderCache {
#[inline]
fn encode(&self, _s: &mut S) {}
}

impl<D: serialize::Decoder> serialize::Decodable<D> for PostorderCache {
impl<D: Decoder> Decodable<D> for PostorderCache {
#[inline]
fn decode(_: &mut D) -> Self {
Self::new()
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_query_impl/src/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
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;
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {

// 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.
Expand Down Expand Up @@ -437,7 +437,7 @@ impl<'sess> OnDiskCache<'sess> {
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,
Expand All @@ -458,7 +458,7 @@ impl<'sess> OnDiskCache<'sess> {
/// 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<FxHashMap<SourceFileIndex, Lrc<SourceFile>>>,
file_index_to_stable_id: &'a FxHashMap<SourceFileIndex, EncodedSourceFileId>,
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -586,7 +586,7 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
{
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;
Expand Down
Loading