diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-09 19:44:55 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-09 19:44:55 +0200 |
| commit | ed3c8e86cbface5f050b8911b0de02c196d840eb (patch) | |
| tree | 38b34ffb2e5ef94189f54e65eea3849a60d36b7a /compiler/rustc_ast_lowering/src/lib.rs | |
| parent | 457de0848777473ddafda998ab9384cbfbf4b87a (diff) | |
| download | rust-ed3c8e86cbface5f050b8911b0de02c196d840eb.tar.gz rust-ed3c8e86cbface5f050b8911b0de02c196d840eb.zip | |
Hash during lowering.
Diffstat (limited to 'compiler/rustc_ast_lowering/src/lib.rs')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 80b95b99b16..f95ad9f3a9b 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -41,7 +41,9 @@ use rustc_ast::visit; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust; use rustc_data_structures::captures::Captures; +use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashSet; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_errors::{struct_span_err, Applicability}; use rustc_hir as hir; @@ -467,7 +469,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - hir::OwnerInfo { node, attrs, bodies, trait_map } + let (hash, node_hash) = self.hash_body(node, &bodies); + + hir::OwnerInfo { hash, node_hash, node, attrs, bodies, trait_map } + } + + /// Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate + /// queries which depend on the full HIR tree and those which only depend on the item signature. + fn hash_body( + &mut self, + node: hir::OwnerNode<'hir>, + bodies: &IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>, + ) -> (Fingerprint, Fingerprint) { + let mut hcx = self.resolver.create_stable_hashing_context(); + let mut stable_hasher = StableHasher::new(); + hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| { + node.hash_stable(hcx, &mut stable_hasher) + }); + let full_hash = stable_hasher.finish(); + let mut stable_hasher = StableHasher::new(); + hcx.with_hir_bodies(false, node.def_id(), bodies, |hcx| { + node.hash_stable(hcx, &mut stable_hasher) + }); + let node_hash = stable_hasher.finish(); + (full_hash, node_hash) } /// This method allocates a new `HirId` for the given `NodeId` and stores it in |
