]> git.lizzy.rs Git - rust.git/commitdiff
Treat NodeIs as pure values for incremental compilation
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sun, 9 Feb 2020 14:08:31 +0000 (15:08 +0100)
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>
Sat, 15 Feb 2020 16:50:11 +0000 (17:50 +0100)
src/librustc/ich/hcx.rs
src/librustc/ty/query/on_disk_cache.rs
src/libsyntax/node_id.rs

index 76e4b5f01b775cd4c099ccac8f6c7e6c938e9bd2..e0e8470fe4730f7b240802d50bedf2891959e724 100644 (file)
@@ -219,28 +219,12 @@ fn to_stable_hash_key(
     }
 }
 
-impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
-    fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
-        match hcx.node_id_hashing_mode {
-            NodeIdHashingMode::Ignore => {
-                // Don't do anything.
-            }
-            NodeIdHashingMode::HashDefPath => {
-                hcx.definitions.node_to_hir_id(*self).hash_stable(hcx, hasher);
-            }
-        }
-    }
-}
-
 impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::NodeId {
-    type KeyType = (DefPathHash, hir::ItemLocalId);
+    type KeyType = Self;
 
     #[inline]
-    fn to_stable_hash_key(
-        &self,
-        hcx: &StableHashingContext<'a>,
-    ) -> (DefPathHash, hir::ItemLocalId) {
-        hcx.definitions.node_to_hir_id(*self).to_stable_hash_key(hcx)
+    fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> Self {
+        *self
     }
 }
 
index 01f684dc65c30998b1959e262ae98e10fd3412bb..45d95e97a9cf06480eae036686e205f6e871a5c2 100644 (file)
@@ -22,7 +22,7 @@
 use rustc_span::source_map::{SourceMap, StableSourceFileId};
 use rustc_span::{BytePos, SourceFile, Span, DUMMY_SP};
 use std::mem;
-use syntax::ast::{Ident, NodeId};
+use syntax::ast::Ident;
 
 const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
 
@@ -680,16 +680,6 @@ fn specialized_decode(&mut self) -> Result<hir::HirId, Self::Error> {
     }
 }
 
-// `NodeId`s are not stable across compilation sessions, so we store them in their
-// `HirId` representation. This allows use to map them to the current `NodeId`.
-impl<'a, 'tcx> SpecializedDecoder<NodeId> for CacheDecoder<'a, 'tcx> {
-    #[inline]
-    fn specialized_decode(&mut self) -> Result<NodeId, Self::Error> {
-        let hir_id = hir::HirId::decode(self)?;
-        Ok(self.tcx().hir().hir_to_node_id(hir_id))
-    }
-}
-
 impl<'a, 'tcx> SpecializedDecoder<Fingerprint> for CacheDecoder<'a, 'tcx> {
     fn specialized_decode(&mut self) -> Result<Fingerprint, Self::Error> {
         Fingerprint::decode_opaque(&mut self.opaque)
@@ -928,19 +918,6 @@ fn specialized_encode(&mut self, _: &DefIndex) -> Result<(), Self::Error> {
     }
 }
 
-// `NodeId`s are not stable across compilation sessions, so we store them in their
-// `HirId` representation. This allows use to map them to the current `NodeId`.
-impl<'a, 'tcx, E> SpecializedEncoder<NodeId> for CacheEncoder<'a, 'tcx, E>
-where
-    E: 'a + 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)
-    }
-}
-
 impl<'a, 'tcx> SpecializedEncoder<Fingerprint> for CacheEncoder<'a, 'tcx, opaque::Encoder> {
     fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> {
         f.encode_opaque(&mut self.encoder)
index 58d2334a7b148ccf150bd0acb04d04489b582710..430d8f30421ef2bb8128873878a3b374c45b9658 100644 (file)
@@ -1,8 +1,10 @@
+use rustc_macros::HashStable_Generic;
 use rustc_serialize::{Decoder, Encoder};
 use rustc_span::ExpnId;
 use std::fmt;
 
 rustc_index::newtype_index! {
+    #[derive(HashStable_Generic)]
     pub struct NodeId {
         ENCODABLE = custom
         DEBUG_FORMAT = "NodeId({})"