Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 12b39e5

Browse files
committed
Make naming more explicit.
1 parent 04ed867 commit 12b39e5

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ struct LoweringContext<'a, 'hir: 'a> {
102102

103103
/// The items being lowered are collected here.
104104
owners: IndexVec<LocalDefId, Option<hir::OwnerInfo<'hir>>>,
105+
/// Bodies inside the owner being lowered.
105106
bodies: IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>,
107+
/// Attributes inside the owner being lowered.
106108
attrs: BTreeMap<hir::ItemLocalId, &'hir [Attribute]>,
107109

108110
generator_kind: Option<hir::GeneratorKind>,
@@ -418,6 +420,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
418420
self.arena.alloc(krate)
419421
}
420422

423+
/// Compute the hash for the HIR of the full crate.
424+
/// This hash will then be part of the crate_hash which is stored in the metadata.
421425
fn compute_hir_hash(&mut self) -> Fingerprint {
422426
let definitions = self.resolver.definitions();
423427
let mut hir_body_nodes: Vec<_> = self
@@ -493,10 +497,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
493497
}
494498
}
495499

496-
let (hash, node_hash) = self.hash_body(node, &bodies);
500+
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
497501
let (nodes, parenting) =
498502
index::index_hir(self.sess, self.resolver.definitions(), node, &bodies);
499-
let nodes = hir::OwnerNodes { hash, node_hash, nodes, bodies };
503+
let nodes = hir::OwnerNodes { hash_including_bodies, hash_without_bodies, nodes, bodies };
500504
let attrs = {
501505
let mut hcx = self.resolver.create_stable_hashing_context();
502506
let mut stable_hasher = StableHasher::new();
@@ -510,7 +514,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
510514

511515
/// Hash the HIR node twice, one deep and one shallow hash. This allows to differentiate
512516
/// queries which depend on the full HIR tree and those which only depend on the item signature.
513-
fn hash_body(
517+
fn hash_owner(
514518
&mut self,
515519
node: hir::OwnerNode<'hir>,
516520
bodies: &IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>,
@@ -520,13 +524,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
520524
hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| {
521525
node.hash_stable(hcx, &mut stable_hasher)
522526
});
523-
let full_hash = stable_hasher.finish();
527+
let hash_including_bodies = stable_hasher.finish();
524528
let mut stable_hasher = StableHasher::new();
525529
hcx.with_hir_bodies(false, node.def_id(), bodies, |hcx| {
526530
node.hash_stable(hcx, &mut stable_hasher)
527531
});
528-
let node_hash = stable_hasher.finish();
529-
(full_hash, node_hash)
532+
let hash_without_bodies = stable_hasher.finish();
533+
(hash_including_bodies, hash_without_bodies)
530534
}
531535

532536
/// This method allocates a new `HirId` for the given `NodeId` and stores it in

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,9 @@ impl<'tcx> AttributeMap<'tcx> {
692692
#[derive(Debug)]
693693
pub struct OwnerNodes<'tcx> {
694694
/// Pre-computed hash of the full HIR.
695-
pub hash: Fingerprint,
696-
/// Pre-computed hash of the top node.
697-
pub node_hash: Fingerprint,
695+
pub hash_including_bodies: Fingerprint,
696+
/// Pre-computed hash of the item signature, sithout recursing into the body.
697+
pub hash_without_bodies: Fingerprint,
698698
/// Full HIR for the current owner.
699699
// The zeroth node's parent is trash, but is never accessed.
700700
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,

compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
215215
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
216216
// We ignore the `nodes` and `bodies` fields since these refer to information included in
217217
// `hash` which is hashed in the collector and used for the crate hash.
218-
let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self;
219-
hash.hash_stable(hcx, hasher);
218+
let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } =
219+
*self;
220+
hash_including_bodies.hash_stable(hcx, hasher);
220221
}
221222
}
222223

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ use rustc_span::DUMMY_SP;
2323
#[derive(Copy, Clone, Debug)]
2424
pub struct Owner<'tcx> {
2525
node: OwnerNode<'tcx>,
26-
node_hash: Fingerprint,
26+
hash_without_bodies: Fingerprint,
2727
}
2828

2929
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
3030
#[inline]
3131
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
32-
let Owner { node: _, node_hash } = self;
33-
node_hash.hash_stable(hcx, hasher)
32+
let Owner { node: _, hash_without_bodies } = self;
33+
hash_without_bodies.hash_stable(hcx, hasher)
3434
}
3535
}
3636

@@ -67,7 +67,7 @@ pub fn provide(providers: &mut Providers) {
6767
providers.hir_owner = |tcx, id| {
6868
let owner = tcx.hir_crate(()).owners[id].as_ref()?;
6969
let node = owner.node();
70-
Some(Owner { node, node_hash: owner.nodes.node_hash })
70+
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
7171
};
7272
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|i| &i.nodes);
7373
providers.hir_owner_parent = |tcx, id| {

0 commit comments

Comments
 (0)