From a7db5051d14994474c641328333884aeba70ca25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 9 Feb 2020 15:08:31 +0100 Subject: [PATCH 1/2] Treat NodeIs as pure values for incremental compilation --- src/librustc/ich/hcx.rs | 22 +++------------------- src/librustc/ty/query/on_disk_cache.rs | 25 +------------------------ src/libsyntax/node_id.rs | 2 ++ 3 files changed, 6 insertions(+), 43 deletions(-) diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 76e4b5f01b775..e0e8470fe4730 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -219,28 +219,12 @@ impl<'a> ToStableHashKey> for hir::HirId { } } -impl<'a> HashStable> 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> 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 } } diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 01f684dc65c30..45d95e97a9cf0 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -22,7 +22,7 @@ use rustc_span::hygiene::{ExpnId, SyntaxContext}; 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 @@ impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { } } -// `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 for CacheDecoder<'a, 'tcx> { - #[inline] - fn specialized_decode(&mut self) -> Result { - let hir_id = hir::HirId::decode(self)?; - Ok(self.tcx().hir().hir_to_node_id(hir_id)) - } -} - impl<'a, 'tcx> SpecializedDecoder for CacheDecoder<'a, 'tcx> { fn specialized_decode(&mut self) -> Result { Fingerprint::decode_opaque(&mut self.opaque) @@ -928,19 +918,6 @@ where } } -// `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 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 for CacheEncoder<'a, 'tcx, opaque::Encoder> { fn specialized_encode(&mut self, f: &Fingerprint) -> Result<(), Self::Error> { f.encode_opaque(&mut self.encoder) diff --git a/src/libsyntax/node_id.rs b/src/libsyntax/node_id.rs index 58d2334a7b148..430d8f30421ef 100644 --- a/src/libsyntax/node_id.rs +++ b/src/libsyntax/node_id.rs @@ -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({})" From 8a37811e2c3b89beb135cf96dcb5d887a6262751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 15 Feb 2020 18:07:17 +0100 Subject: [PATCH 2/2] Panic when hashing node IDs --- src/librustc/ich/hcx.rs | 9 +++------ src/libsyntax/node_id.rs | 2 -- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index e0e8470fe4730..9e2db35dc6db8 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -219,12 +219,9 @@ impl<'a> ToStableHashKey> for hir::HirId { } } -impl<'a> ToStableHashKey> for ast::NodeId { - type KeyType = Self; - - #[inline] - fn to_stable_hash_key(&self, _: &StableHashingContext<'a>) -> Self { - *self +impl<'a> HashStable> for ast::NodeId { + fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) { + panic!("Node IDs should not appear in incremental state"); } } diff --git a/src/libsyntax/node_id.rs b/src/libsyntax/node_id.rs index 430d8f30421ef..58d2334a7b148 100644 --- a/src/libsyntax/node_id.rs +++ b/src/libsyntax/node_id.rs @@ -1,10 +1,8 @@ -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({})"