diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2017-11-16 17:13:39 +0100 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2017-11-16 17:13:39 +0100 |
| commit | cb1ff24425c37835b5d746a22d68047ff2cb807b (patch) | |
| tree | 991a3e76240b23158f8d68fe6d639c0d3448e782 | |
| parent | 723028f3086b4d5a8eec95962ac5728af4e271b4 (diff) | |
| download | rust-cb1ff24425c37835b5d746a22d68047ff2cb807b.tar.gz rust-cb1ff24425c37835b5d746a22d68047ff2cb807b.zip | |
incr.comp.: Remove default serialization implementations for things in rustc::hir::def_id so that we get an ICE instead of silently doing the wrong thing.
| -rw-r--r-- | src/librustc/hir/def_id.rs | 58 | ||||
| -rw-r--r-- | src/librustc/middle/cstore.rs | 4 | ||||
| -rw-r--r-- | src/librustc/session/config.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/maps/on_disk_cache.rs | 16 | ||||
| -rw-r--r-- | src/librustc_incremental/persist/data.rs | 3 | ||||
| -rw-r--r-- | src/librustc_incremental/persist/save.rs | 6 | ||||
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 21 | ||||
| -rw-r--r-- | src/librustc_metadata/encoder.rs | 31 | ||||
| -rw-r--r-- | src/librustc_metadata/index_builder.rs | 2 |
9 files changed, 81 insertions, 62 deletions
diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs index f34022993de..05d021ac6d2 100644 --- a/src/librustc/hir/def_id.rs +++ b/src/librustc/hir/def_id.rs @@ -11,8 +11,7 @@ use ty; use rustc_data_structures::indexed_vec::Idx; -use serialize::{self, Encoder, Decoder, Decodable, Encodable}; - +use serialize; use std::fmt; use std::u32; @@ -65,17 +64,8 @@ impl fmt::Display for CrateNum { } } -impl serialize::UseSpecializedEncodable for CrateNum { - fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_u32(self.0) - } -} - -impl serialize::UseSpecializedDecodable for CrateNum { - fn default_decode<D: Decoder>(d: &mut D) -> Result<CrateNum, D::Error> { - d.read_u32().map(CrateNum) - } -} +impl serialize::UseSpecializedEncodable for CrateNum {} +impl serialize::UseSpecializedDecodable for CrateNum {} /// A DefIndex is an index into the hir-map for a crate, identifying a /// particular definition. It should really be considered an interned @@ -151,19 +141,8 @@ impl DefIndex { } } -impl serialize::UseSpecializedEncodable for DefIndex { - #[inline] - fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_u32(self.0) - } -} - -impl serialize::UseSpecializedDecodable for DefIndex { - #[inline] - fn default_decode<D: Decoder>(d: &mut D) -> Result<DefIndex, D::Error> { - d.read_u32().map(DefIndex) - } -} +impl serialize::UseSpecializedEncodable for DefIndex {} +impl serialize::UseSpecializedDecodable for DefIndex {} #[derive(Copy, Clone, Eq, PartialEq, Hash)] pub enum DefIndexAddressSpace { @@ -225,31 +204,8 @@ impl DefId { } } -impl serialize::UseSpecializedEncodable for DefId { - #[inline] - fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - let DefId { - krate, - index, - } = *self; - - krate.encode(s)?; - index.encode(s) - } -} - -impl serialize::UseSpecializedDecodable for DefId { - #[inline] - fn default_decode<D: Decoder>(d: &mut D) -> Result<DefId, D::Error> { - let krate = CrateNum::decode(d)?; - let index = DefIndex::decode(d)?; - - Ok(DefId { - krate, - index - }) - } -} +impl serialize::UseSpecializedEncodable for DefId {} +impl serialize::UseSpecializedDecodable for DefId {} #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 628538b41c5..5d7141949e3 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -24,7 +24,7 @@ use hir; use hir::def; -use hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE}; +use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use hir::map as hir_map; use hir::map::definitions::{Definitions, DefKey, DefPathTable}; use hir::svh::Svh; @@ -180,7 +180,7 @@ impl EncodedMetadata { /// upstream crate. #[derive(Debug, RustcEncodable, RustcDecodable, Copy, Clone)] pub struct EncodedMetadataHash { - pub def_index: DefIndex, + pub def_index: u32, pub hash: ich::Fingerprint, } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 2857d50fc87..b7abcc03132 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1042,7 +1042,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "enable incremental compilation (experimental)"), incremental_cc: bool = (false, parse_bool, [UNTRACKED], "enable cross-crate incremental compilation (even more experimental)"), - incremental_queries: bool = (false, parse_bool, [UNTRACKED], + incremental_queries: bool = (true, parse_bool, [UNTRACKED], "enable incremental compilation support for queries (experimental)"), incremental_info: bool = (false, parse_bool, [UNTRACKED], "print high-level information about incremental reuse (or the lack thereof)"), diff --git a/src/librustc/ty/maps/on_disk_cache.rs b/src/librustc/ty/maps/on_disk_cache.rs index 8c234e632e9..53ca9b3851d 100644 --- a/src/librustc/ty/maps/on_disk_cache.rs +++ b/src/librustc/ty/maps/on_disk_cache.rs @@ -559,14 +559,25 @@ impl<'enc, 'a, 'tcx, E> CacheEncoder<'enc, 'a, 'tcx, E> impl<'enc, 'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn position(&self) -> usize { self.encoder.position() } } +impl<'enc, 'a, 'tcx, E> SpecializedEncoder<CrateNum> for CacheEncoder<'enc, 'a, 'tcx, E> + where E: 'enc + ty_codec::TyEncoder +{ + #[inline] + fn specialized_encode(&mut self, cnum: &CrateNum) -> Result<(), Self::Error> { + self.emit_u32(cnum.as_u32()) + } +} + impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::Ty<'tcx>> for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn specialized_encode(&mut self, ty: &ty::Ty<'tcx>) -> Result<(), Self::Error> { ty_codec::encode_with_shorthand(self, ty, |encoder| &mut encoder.type_shorthands) @@ -577,6 +588,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>> for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn specialized_encode(&mut self, predicates: &ty::GenericPredicates<'tcx>) -> Result<(), Self::Error> { @@ -588,6 +600,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>> impl<'enc, 'a, 'tcx, E> SpecializedEncoder<hir::HirId> for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn specialized_encode(&mut self, id: &hir::HirId) -> Result<(), Self::Error> { let hir::HirId { owner, @@ -605,6 +618,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<hir::HirId> for CacheEncoder<'enc, 'a impl<'enc, 'a, 'tcx, E> SpecializedEncoder<DefId> for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn specialized_encode(&mut self, id: &DefId) -> Result<(), Self::Error> { let def_path_hash = self.tcx.def_path_hash(*id); def_path_hash.encode(self) @@ -614,6 +628,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<DefId> for CacheEncoder<'enc, 'a, 'tc impl<'enc, 'a, 'tcx, E> SpecializedEncoder<LocalDefId> for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn specialized_encode(&mut self, id: &LocalDefId) -> Result<(), Self::Error> { id.to_def_id().encode(self) } @@ -632,6 +647,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<DefIndex> for CacheEncoder<'enc, 'a, impl<'enc, 'a, 'tcx, E> SpecializedEncoder<NodeId> for CacheEncoder<'enc, 'a, 'tcx, E> where E: 'enc + ty_codec::TyEncoder { + #[inline] fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> { let hir_id = self.tcx.hir.node_to_hir_id(*node_id); hir_id.encode(self) diff --git a/src/librustc_incremental/persist/data.rs b/src/librustc_incremental/persist/data.rs index fc417851b88..08f9dba2ba1 100644 --- a/src/librustc_incremental/persist/data.rs +++ b/src/librustc_incremental/persist/data.rs @@ -11,7 +11,6 @@ //! The data that we will serialize and deserialize. use rustc::dep_graph::{WorkProduct, WorkProductId}; -use rustc::hir::def_id::DefIndex; use rustc::hir::map::DefPathHash; use rustc::middle::cstore::EncodedMetadataHash; use rustc_data_structures::fx::FxHashMap; @@ -58,5 +57,5 @@ pub struct SerializedMetadataHashes { /// is only populated if -Z query-dep-graph is specified. It will be /// empty otherwise. Importing crates are perfectly happy with just having /// the DefIndex. - pub index_map: FxHashMap<DefIndex, DefPathHash> + pub index_map: FxHashMap<u32, DefPathHash> } diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs index 63038f1b93a..b6dabf99be7 100644 --- a/src/librustc_incremental/persist/save.rs +++ b/src/librustc_incremental/persist/save.rs @@ -9,7 +9,7 @@ // except according to those terms. use rustc::dep_graph::{DepGraph, DepKind}; -use rustc::hir::def_id::DefId; +use rustc::hir::def_id::{DefId, DefIndex}; use rustc::hir::svh::Svh; use rustc::ich::Fingerprint; use rustc::middle::cstore::EncodedMetadataHashes; @@ -270,11 +270,11 @@ fn encode_metadata_hashes(tcx: TyCtxt, if tcx.sess.opts.debugging_opts.query_dep_graph { for serialized_hash in &serialized_hashes.entry_hashes { - let def_id = DefId::local(serialized_hash.def_index); + let def_id = DefId::local(DefIndex::from_u32(serialized_hash.def_index)); // Store entry in the index_map let def_path_hash = tcx.def_path_hash(def_id); - serialized_hashes.index_map.insert(def_id.index, def_path_hash); + serialized_hashes.index_map.insert(def_id.index.as_u32(), def_path_hash); // Record hash in current_metadata_hashes current_metadata_hashes.insert(def_id, serialized_hash.hash); diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index ddc8b6abfac..0dd1b9e500c 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -246,6 +246,27 @@ impl<'a, 'tcx, T> SpecializedDecoder<LazySeq<T>> for DecodeContext<'a, 'tcx> { } } + +impl<'a, 'tcx> SpecializedDecoder<DefId> for DecodeContext<'a, 'tcx> { + #[inline] + fn specialized_decode(&mut self) -> Result<DefId, Self::Error> { + let krate = CrateNum::decode(self)?; + let index = DefIndex::decode(self)?; + + Ok(DefId { + krate, + index, + }) + } +} + +impl<'a, 'tcx> SpecializedDecoder<DefIndex> for DecodeContext<'a, 'tcx> { + #[inline] + fn specialized_decode(&mut self) -> Result<DefIndex, Self::Error> { + Ok(DefIndex::from_u32(self.read_u32()?)) + } +} + impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> { fn specialized_decode(&mut self) -> Result<Span, Self::Error> { let lo = BytePos::decode(self)?; diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index d5eee14bf50..19d0de73346 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -116,6 +116,33 @@ impl<'a, 'tcx, T> SpecializedEncoder<LazySeq<T>> for EncodeContext<'a, 'tcx> { } } +impl<'a, 'tcx> SpecializedEncoder<CrateNum> for EncodeContext<'a, 'tcx> { + #[inline] + fn specialized_encode(&mut self, cnum: &CrateNum) -> Result<(), Self::Error> { + self.emit_u32(cnum.as_u32()) + } +} + +impl<'a, 'tcx> SpecializedEncoder<DefId> for EncodeContext<'a, 'tcx> { + #[inline] + fn specialized_encode(&mut self, def_id: &DefId) -> Result<(), Self::Error> { + let DefId { + krate, + index, + } = *def_id; + + krate.encode(self)?; + index.encode(self) + } +} + +impl<'a, 'tcx> SpecializedEncoder<DefIndex> for EncodeContext<'a, 'tcx> { + #[inline] + fn specialized_encode(&mut self, def_index: &DefIndex) -> Result<(), Self::Error> { + self.emit_u32(def_index.as_u32()) + } +} + impl<'a, 'tcx> SpecializedEncoder<Ty<'tcx>> for EncodeContext<'a, 'tcx> { fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> { ty_codec::encode_with_shorthand(self, ty, |ecx| &mut ecx.type_shorthands) @@ -213,7 +240,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { if let Some(fingerprint) = fingerprint { this.metadata_hashes.hashes.push(EncodedMetadataHash { - def_index, + def_index: def_index.as_u32(), hash: fingerprint, }) } @@ -395,7 +422,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let total_bytes = self.position(); self.metadata_hashes.hashes.push(EncodedMetadataHash { - def_index: global_metadata_def_index(GlobalMetaDataKind::Krate), + def_index: global_metadata_def_index(GlobalMetaDataKind::Krate).as_u32(), hash: Fingerprint::from_smaller_hash(link_meta.crate_hash.as_u64()) }); diff --git a/src/librustc_metadata/index_builder.rs b/src/librustc_metadata/index_builder.rs index 1d2b6cc33d4..46706bba96d 100644 --- a/src/librustc_metadata/index_builder.rs +++ b/src/librustc_metadata/index_builder.rs @@ -136,7 +136,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { let (fingerprint, ecx) = entry_builder.finish(); if let Some(hash) = fingerprint { ecx.metadata_hashes.hashes.push(EncodedMetadataHash { - def_index: id.index, + def_index: id.index.as_u32(), hash, }); } |
