Make naming more explicit.

This commit is contained in:
Camille GILLOT 2021-10-11 22:36:37 +02:00
parent 04ed86757a
commit 12b39e5912
4 changed files with 20 additions and 15 deletions

View File

@ -102,7 +102,9 @@ struct LoweringContext<'a, 'hir: 'a> {
/// The items being lowered are collected here.
owners: IndexVec<LocalDefId, Option<hir::OwnerInfo<'hir>>>,
/// Bodies inside the owner being lowered.
bodies: IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>,
/// Attributes inside the owner being lowered.
attrs: BTreeMap<hir::ItemLocalId, &'hir [Attribute]>,
generator_kind: Option<hir::GeneratorKind>,
@ -418,6 +420,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc(krate)
}
/// Compute the hash for the HIR of the full crate.
/// This hash will then be part of the crate_hash which is stored in the metadata.
fn compute_hir_hash(&mut self) -> Fingerprint {
let definitions = self.resolver.definitions();
let mut hir_body_nodes: Vec<_> = self
@ -493,10 +497,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
let (hash, node_hash) = self.hash_body(node, &bodies);
let (hash_including_bodies, hash_without_bodies) = self.hash_owner(node, &bodies);
let (nodes, parenting) =
index::index_hir(self.sess, self.resolver.definitions(), node, &bodies);
let nodes = hir::OwnerNodes { hash, node_hash, nodes, bodies };
let nodes = hir::OwnerNodes { hash_including_bodies, hash_without_bodies, nodes, bodies };
let attrs = {
let mut hcx = self.resolver.create_stable_hashing_context();
let mut stable_hasher = StableHasher::new();
@ -510,7 +514,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// 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(
fn hash_owner(
&mut self,
node: hir::OwnerNode<'hir>,
bodies: &IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>,
@ -520,13 +524,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| {
node.hash_stable(hcx, &mut stable_hasher)
});
let full_hash = stable_hasher.finish();
let hash_including_bodies = 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)
let hash_without_bodies = stable_hasher.finish();
(hash_including_bodies, hash_without_bodies)
}
/// This method allocates a new `HirId` for the given `NodeId` and stores it in

View File

@ -692,9 +692,9 @@ impl<'tcx> AttributeMap<'tcx> {
#[derive(Debug)]
pub struct OwnerNodes<'tcx> {
/// Pre-computed hash of the full HIR.
pub hash: Fingerprint,
/// Pre-computed hash of the top node.
pub node_hash: Fingerprint,
pub hash_including_bodies: Fingerprint,
/// Pre-computed hash of the item signature, sithout recursing into the body.
pub hash_without_bodies: Fingerprint,
/// Full HIR for the current owner.
// The zeroth node's parent is trash, but is never accessed.
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,

View File

@ -215,8 +215,9 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
// We ignore the `nodes` and `bodies` fields since these refer to information included in
// `hash` which is hashed in the collector and used for the crate hash.
let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self;
hash.hash_stable(hcx, hasher);
let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } =
*self;
hash_including_bodies.hash_stable(hcx, hasher);
}
}

View File

@ -23,14 +23,14 @@ use rustc_span::DUMMY_SP;
#[derive(Copy, Clone, Debug)]
pub struct Owner<'tcx> {
node: OwnerNode<'tcx>,
node_hash: Fingerprint,
hash_without_bodies: Fingerprint,
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
#[inline]
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let Owner { node: _, node_hash } = self;
node_hash.hash_stable(hcx, hasher)
let Owner { node: _, hash_without_bodies } = self;
hash_without_bodies.hash_stable(hcx, hasher)
}
}
@ -67,7 +67,7 @@ pub fn provide(providers: &mut Providers) {
providers.hir_owner = |tcx, id| {
let owner = tcx.hir_crate(()).owners[id].as_ref()?;
let node = owner.node();
Some(Owner { node, node_hash: owner.nodes.node_hash })
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
};
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|i| &i.nodes);
providers.hir_owner_parent = |tcx, id| {