about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2024-01-16 23:23:31 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2024-01-16 23:52:30 +0000
commitd59968b5f65c8b703f66913181d30d31df113d70 (patch)
tree4c9c235d38347d0f0c5c1cb8058c62da249569cb
parent20a8a23cb33fbc59fe89d64fa5dd51ccf33df415 (diff)
downloadrust-d59968b5f65c8b703f66913181d30d31df113d70.tar.gz
rust-d59968b5f65c8b703f66913181d30d31df113d70.zip
Simplify BodyId hashing.
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs6
-rw-r--r--compiler/rustc_hir/src/hir.rs2
-rw-r--r--compiler/rustc_hir/src/stable_hash_impls.rs7
-rw-r--r--compiler/rustc_query_system/src/ich/hcx.rs35
-rw-r--r--compiler/rustc_query_system/src/ich/impls_hir.rs22
-rw-r--r--compiler/rustc_query_system/src/ich/impls_syntax.rs2
-rw-r--r--compiler/rustc_query_system/src/ich/mod.rs1
7 files changed, 6 insertions, 69 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 5387880b6e6..057fe65d0af 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -662,9 +662,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         let (opt_hash_including_bodies, attrs_hash) = if self.tcx.needs_crate_hash() {
             self.tcx.with_stable_hashing_context(|mut hcx| {
                 let mut stable_hasher = StableHasher::new();
-                hcx.with_hir_bodies(node.def_id(), &bodies, |hcx| {
-                    node.hash_stable(hcx, &mut stable_hasher)
-                });
+                node.hash_stable(&mut hcx, &mut stable_hasher);
+                // Bodies are stored out of line, so we need to pull them explicitly in the hash.
+                bodies.hash_stable(&mut hcx, &mut stable_hasher);
                 let h1 = stable_hasher.finish();
 
                 let mut stable_hasher = StableHasher::new();
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 309850d04d3..6773f7a4c66 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -1302,7 +1302,7 @@ pub enum UnsafeSource {
     UserProvided,
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
 pub struct BodyId {
     pub hir_id: HirId,
 }
diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs
index 97fa710b354..baa1635f731 100644
--- a/compiler/rustc_hir/src/stable_hash_impls.rs
+++ b/compiler/rustc_hir/src/stable_hash_impls.rs
@@ -12,7 +12,6 @@ use rustc_span::def_id::DefPathHash;
 pub trait HashStableContext:
     rustc_ast::HashStableContext + rustc_target::HashStableContext
 {
-    fn hash_body_id(&mut self, _: BodyId, hasher: &mut StableHasher);
 }
 
 impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for HirId {
@@ -80,12 +79,6 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
     }
 }
 
-impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for BodyId {
-    fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
-        hcx.hash_body_id(*self, hasher)
-    }
-}
-
 // The following implementations of HashStable for `ItemId`, `TraitItemId`, and
 // `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
 // the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
diff --git a/compiler/rustc_query_system/src/ich/hcx.rs b/compiler/rustc_query_system/src/ich/hcx.rs
index eec0433ae68..e7eb9694f47 100644
--- a/compiler/rustc_query_system/src/ich/hcx.rs
+++ b/compiler/rustc_query_system/src/ich/hcx.rs
@@ -1,10 +1,8 @@
 use crate::ich;
 
 use rustc_ast as ast;
-use rustc_data_structures::sorted_map::SortedMap;
 use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHasher};
 use rustc_data_structures::sync::Lrc;
-use rustc_hir as hir;
 use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_hir::definitions::DefPathHash;
 use rustc_session::cstore::Untracked;
@@ -23,7 +21,6 @@ pub struct StableHashingContext<'a> {
     // The value of `-Z incremental-ignore-spans`.
     // This field should only be used by `unstable_opts_incremental_ignore_span`
     incremental_ignore_spans: bool,
-    pub(super) body_resolver: BodyResolver<'a>,
     // Very often, we are hashing something that does not need the
     // `CachingSourceMapView`, so we initialize it lazily.
     raw_source_map: &'a SourceMap,
@@ -31,26 +28,12 @@ pub struct StableHashingContext<'a> {
     hashing_controls: HashingControls,
 }
 
-/// The `BodyResolver` allows mapping a `BodyId` to the corresponding `hir::Body`.
-/// We could also just store a plain reference to the `hir::Crate` but we want
-/// to avoid that the crate is used to get untracked access to all of the HIR.
-#[derive(Clone, Copy)]
-pub(super) enum BodyResolver<'tcx> {
-    Forbidden,
-    Ignore,
-    Traverse {
-        owner: hir::OwnerId,
-        bodies: &'tcx SortedMap<hir::ItemLocalId, &'tcx hir::Body<'tcx>>,
-    },
-}
-
 impl<'a> StableHashingContext<'a> {
     #[inline]
     pub fn new(sess: &'a Session, untracked: &'a Untracked) -> Self {
         let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans;
 
         StableHashingContext {
-            body_resolver: BodyResolver::Forbidden,
             untracked,
             incremental_ignore_spans: sess.opts.unstable_opts.incremental_ignore_spans,
             caching_source_map: None,
@@ -60,24 +43,6 @@ impl<'a> StableHashingContext<'a> {
     }
 
     #[inline]
-    pub fn without_hir_bodies(&mut self, f: impl FnOnce(&mut StableHashingContext<'_>)) {
-        f(&mut StableHashingContext { body_resolver: BodyResolver::Ignore, ..self.clone() });
-    }
-
-    #[inline]
-    pub fn with_hir_bodies(
-        &mut self,
-        owner: hir::OwnerId,
-        bodies: &SortedMap<hir::ItemLocalId, &hir::Body<'_>>,
-        f: impl FnOnce(&mut StableHashingContext<'_>),
-    ) {
-        f(&mut StableHashingContext {
-            body_resolver: BodyResolver::Traverse { owner, bodies },
-            ..self.clone()
-        });
-    }
-
-    #[inline]
     pub fn while_hashing_spans<F: FnOnce(&mut Self)>(&mut self, hash_spans: bool, f: F) {
         let prev_hash_spans = self.hashing_controls.hash_spans;
         self.hashing_controls.hash_spans = hash_spans;
diff --git a/compiler/rustc_query_system/src/ich/impls_hir.rs b/compiler/rustc_query_system/src/ich/impls_hir.rs
deleted file mode 100644
index aa008d404c3..00000000000
--- a/compiler/rustc_query_system/src/ich/impls_hir.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-//! This module contains `HashStable` implementations for various HIR data
-//! types in no particular order.
-
-use crate::ich::hcx::BodyResolver;
-use crate::ich::StableHashingContext;
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
-use rustc_hir as hir;
-
-impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {
-    #[inline]
-    fn hash_body_id(&mut self, id: hir::BodyId, hasher: &mut StableHasher) {
-        let hcx = self;
-        match hcx.body_resolver {
-            BodyResolver::Forbidden => panic!("Hashing HIR bodies is forbidden."),
-            BodyResolver::Ignore => {}
-            BodyResolver::Traverse { owner, bodies } => {
-                assert_eq!(id.hir_id.owner, owner);
-                bodies[&id.hir_id.local_id].hash_stable(hcx, hasher);
-            }
-        }
-    }
-}
diff --git a/compiler/rustc_query_system/src/ich/impls_syntax.rs b/compiler/rustc_query_system/src/ich/impls_syntax.rs
index d170cd36ca6..5bd4fe04848 100644
--- a/compiler/rustc_query_system/src/ich/impls_syntax.rs
+++ b/compiler/rustc_query_system/src/ich/impls_syntax.rs
@@ -57,6 +57,8 @@ impl<'ctx> rustc_ast::HashStableContext for StableHashingContext<'ctx> {
     }
 }
 
+impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> {}
+
 impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
     fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
         let SourceFile {
diff --git a/compiler/rustc_query_system/src/ich/mod.rs b/compiler/rustc_query_system/src/ich/mod.rs
index 0a1c350b2db..86e3ecb1edd 100644
--- a/compiler/rustc_query_system/src/ich/mod.rs
+++ b/compiler/rustc_query_system/src/ich/mod.rs
@@ -4,7 +4,6 @@ pub use self::hcx::StableHashingContext;
 use rustc_span::symbol::{sym, Symbol};
 
 mod hcx;
-mod impls_hir;
 mod impls_syntax;
 
 pub const IGNORED_ATTRIBUTES: &[Symbol] = &[