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.
This commit is contained in:
parent
723028f308
commit
cb1ff24425
9 changed files with 81 additions and 62 deletions
|
@ -11,8 +11,7 @@
|
||||||
use ty;
|
use ty;
|
||||||
|
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
use serialize::{self, Encoder, Decoder, Decodable, Encodable};
|
use serialize;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
|
@ -65,17 +64,8 @@ impl fmt::Display for CrateNum {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serialize::UseSpecializedEncodable for CrateNum {
|
impl serialize::UseSpecializedEncodable for CrateNum {}
|
||||||
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
impl serialize::UseSpecializedDecodable for CrateNum {}
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
/// A DefIndex is an index into the hir-map for a crate, identifying a
|
||||||
/// particular definition. It should really be considered an interned
|
/// particular definition. It should really be considered an interned
|
||||||
|
@ -151,19 +141,8 @@ impl DefIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serialize::UseSpecializedEncodable for DefIndex {
|
impl serialize::UseSpecializedEncodable for DefIndex {}
|
||||||
#[inline]
|
impl serialize::UseSpecializedDecodable for DefIndex {}
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub enum DefIndexAddressSpace {
|
pub enum DefIndexAddressSpace {
|
||||||
|
@ -225,31 +204,8 @@ impl DefId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serialize::UseSpecializedEncodable for DefId {
|
impl serialize::UseSpecializedEncodable for DefId {}
|
||||||
#[inline]
|
impl serialize::UseSpecializedDecodable for DefId {}
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
use hir;
|
use hir;
|
||||||
use hir::def;
|
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 as hir_map;
|
||||||
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
|
use hir::map::definitions::{Definitions, DefKey, DefPathTable};
|
||||||
use hir::svh::Svh;
|
use hir::svh::Svh;
|
||||||
|
@ -180,7 +180,7 @@ impl EncodedMetadata {
|
||||||
/// upstream crate.
|
/// upstream crate.
|
||||||
#[derive(Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
|
#[derive(Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
|
||||||
pub struct EncodedMetadataHash {
|
pub struct EncodedMetadataHash {
|
||||||
pub def_index: DefIndex,
|
pub def_index: u32,
|
||||||
pub hash: ich::Fingerprint,
|
pub hash: ich::Fingerprint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1042,7 +1042,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
||||||
"enable incremental compilation (experimental)"),
|
"enable incremental compilation (experimental)"),
|
||||||
incremental_cc: bool = (false, parse_bool, [UNTRACKED],
|
incremental_cc: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"enable cross-crate incremental compilation (even more experimental)"),
|
"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)"),
|
"enable incremental compilation support for queries (experimental)"),
|
||||||
incremental_info: bool = (false, parse_bool, [UNTRACKED],
|
incremental_info: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"print high-level information about incremental reuse (or the lack thereof)"),
|
"print high-level information about incremental reuse (or the lack thereof)"),
|
||||||
|
|
|
@ -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>
|
impl<'enc, 'a, 'tcx, E> ty_codec::TyEncoder for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn position(&self) -> usize {
|
fn position(&self) -> usize {
|
||||||
self.encoder.position()
|
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>
|
impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::Ty<'tcx>> for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn specialized_encode(&mut self, ty: &ty::Ty<'tcx>) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, ty: &ty::Ty<'tcx>) -> Result<(), Self::Error> {
|
||||||
ty_codec::encode_with_shorthand(self, ty,
|
ty_codec::encode_with_shorthand(self, ty,
|
||||||
|encoder| &mut encoder.type_shorthands)
|
|encoder| &mut encoder.type_shorthands)
|
||||||
|
@ -577,6 +588,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<ty::GenericPredicates<'tcx>>
|
||||||
for CacheEncoder<'enc, 'a, 'tcx, E>
|
for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn specialized_encode(&mut self,
|
fn specialized_encode(&mut self,
|
||||||
predicates: &ty::GenericPredicates<'tcx>)
|
predicates: &ty::GenericPredicates<'tcx>)
|
||||||
-> Result<(), Self::Error> {
|
-> 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>
|
impl<'enc, 'a, 'tcx, E> SpecializedEncoder<hir::HirId> for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn specialized_encode(&mut self, id: &hir::HirId) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, id: &hir::HirId) -> Result<(), Self::Error> {
|
||||||
let hir::HirId {
|
let hir::HirId {
|
||||||
owner,
|
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>
|
impl<'enc, 'a, 'tcx, E> SpecializedEncoder<DefId> for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn specialized_encode(&mut self, id: &DefId) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, id: &DefId) -> Result<(), Self::Error> {
|
||||||
let def_path_hash = self.tcx.def_path_hash(*id);
|
let def_path_hash = self.tcx.def_path_hash(*id);
|
||||||
def_path_hash.encode(self)
|
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>
|
impl<'enc, 'a, 'tcx, E> SpecializedEncoder<LocalDefId> for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn specialized_encode(&mut self, id: &LocalDefId) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, id: &LocalDefId) -> Result<(), Self::Error> {
|
||||||
id.to_def_id().encode(self)
|
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>
|
impl<'enc, 'a, 'tcx, E> SpecializedEncoder<NodeId> for CacheEncoder<'enc, 'a, 'tcx, E>
|
||||||
where E: 'enc + ty_codec::TyEncoder
|
where E: 'enc + ty_codec::TyEncoder
|
||||||
{
|
{
|
||||||
|
#[inline]
|
||||||
fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, node_id: &NodeId) -> Result<(), Self::Error> {
|
||||||
let hir_id = self.tcx.hir.node_to_hir_id(*node_id);
|
let hir_id = self.tcx.hir.node_to_hir_id(*node_id);
|
||||||
hir_id.encode(self)
|
hir_id.encode(self)
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
//! The data that we will serialize and deserialize.
|
//! The data that we will serialize and deserialize.
|
||||||
|
|
||||||
use rustc::dep_graph::{WorkProduct, WorkProductId};
|
use rustc::dep_graph::{WorkProduct, WorkProductId};
|
||||||
use rustc::hir::def_id::DefIndex;
|
|
||||||
use rustc::hir::map::DefPathHash;
|
use rustc::hir::map::DefPathHash;
|
||||||
use rustc::middle::cstore::EncodedMetadataHash;
|
use rustc::middle::cstore::EncodedMetadataHash;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
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
|
/// is only populated if -Z query-dep-graph is specified. It will be
|
||||||
/// empty otherwise. Importing crates are perfectly happy with just having
|
/// empty otherwise. Importing crates are perfectly happy with just having
|
||||||
/// the DefIndex.
|
/// the DefIndex.
|
||||||
pub index_map: FxHashMap<DefIndex, DefPathHash>
|
pub index_map: FxHashMap<u32, DefPathHash>
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use rustc::dep_graph::{DepGraph, DepKind};
|
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::hir::svh::Svh;
|
||||||
use rustc::ich::Fingerprint;
|
use rustc::ich::Fingerprint;
|
||||||
use rustc::middle::cstore::EncodedMetadataHashes;
|
use rustc::middle::cstore::EncodedMetadataHashes;
|
||||||
|
@ -270,11 +270,11 @@ fn encode_metadata_hashes(tcx: TyCtxt,
|
||||||
|
|
||||||
if tcx.sess.opts.debugging_opts.query_dep_graph {
|
if tcx.sess.opts.debugging_opts.query_dep_graph {
|
||||||
for serialized_hash in &serialized_hashes.entry_hashes {
|
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
|
// Store entry in the index_map
|
||||||
let def_path_hash = tcx.def_path_hash(def_id);
|
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
|
// Record hash in current_metadata_hashes
|
||||||
current_metadata_hashes.insert(def_id, serialized_hash.hash);
|
current_metadata_hashes.insert(def_id, serialized_hash.hash);
|
||||||
|
|
|
@ -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> {
|
impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
|
||||||
fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
|
fn specialized_decode(&mut self) -> Result<Span, Self::Error> {
|
||||||
let lo = BytePos::decode(self)?;
|
let lo = BytePos::decode(self)?;
|
||||||
|
|
|
@ -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> {
|
impl<'a, 'tcx> SpecializedEncoder<Ty<'tcx>> for EncodeContext<'a, 'tcx> {
|
||||||
fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> {
|
fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> {
|
||||||
ty_codec::encode_with_shorthand(self, ty, |ecx| &mut ecx.type_shorthands)
|
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 {
|
if let Some(fingerprint) = fingerprint {
|
||||||
this.metadata_hashes.hashes.push(EncodedMetadataHash {
|
this.metadata_hashes.hashes.push(EncodedMetadataHash {
|
||||||
def_index,
|
def_index: def_index.as_u32(),
|
||||||
hash: fingerprint,
|
hash: fingerprint,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -395,7 +422,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
let total_bytes = self.position();
|
let total_bytes = self.position();
|
||||||
|
|
||||||
self.metadata_hashes.hashes.push(EncodedMetadataHash {
|
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())
|
hash: Fingerprint::from_smaller_hash(link_meta.crate_hash.as_u64())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {
|
||||||
let (fingerprint, ecx) = entry_builder.finish();
|
let (fingerprint, ecx) = entry_builder.finish();
|
||||||
if let Some(hash) = fingerprint {
|
if let Some(hash) = fingerprint {
|
||||||
ecx.metadata_hashes.hashes.push(EncodedMetadataHash {
|
ecx.metadata_hashes.hashes.push(EncodedMetadataHash {
|
||||||
def_index: id.index,
|
def_index: id.index.as_u32(),
|
||||||
hash,
|
hash,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue