Make naming more explicit.
This commit is contained in:
parent
04ed86757a
commit
12b39e5912
4 changed files with 20 additions and 15 deletions
|
@ -102,7 +102,9 @@ struct LoweringContext<'a, 'hir: 'a> {
|
||||||
|
|
||||||
/// The items being lowered are collected here.
|
/// The items being lowered are collected here.
|
||||||
owners: IndexVec<LocalDefId, Option<hir::OwnerInfo<'hir>>>,
|
owners: IndexVec<LocalDefId, Option<hir::OwnerInfo<'hir>>>,
|
||||||
|
/// Bodies inside the owner being lowered.
|
||||||
bodies: IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>,
|
bodies: IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'hir>>>,
|
||||||
|
/// Attributes inside the owner being lowered.
|
||||||
attrs: BTreeMap<hir::ItemLocalId, &'hir [Attribute]>,
|
attrs: BTreeMap<hir::ItemLocalId, &'hir [Attribute]>,
|
||||||
|
|
||||||
generator_kind: Option<hir::GeneratorKind>,
|
generator_kind: Option<hir::GeneratorKind>,
|
||||||
|
@ -418,6 +420,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||||
self.arena.alloc(krate)
|
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 {
|
fn compute_hir_hash(&mut self) -> Fingerprint {
|
||||||
let definitions = self.resolver.definitions();
|
let definitions = self.resolver.definitions();
|
||||||
let mut hir_body_nodes: Vec<_> = self
|
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) =
|
let (nodes, parenting) =
|
||||||
index::index_hir(self.sess, self.resolver.definitions(), node, &bodies);
|
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 attrs = {
|
||||||
let mut hcx = self.resolver.create_stable_hashing_context();
|
let mut hcx = self.resolver.create_stable_hashing_context();
|
||||||
let mut stable_hasher = StableHasher::new();
|
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
|
/// 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.
|
/// 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,
|
&mut self,
|
||||||
node: hir::OwnerNode<'hir>,
|
node: hir::OwnerNode<'hir>,
|
||||||
bodies: &IndexVec<hir::ItemLocalId, Option<&'hir hir::Body<'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| {
|
hcx.with_hir_bodies(true, node.def_id(), bodies, |hcx| {
|
||||||
node.hash_stable(hcx, &mut stable_hasher)
|
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();
|
let mut stable_hasher = StableHasher::new();
|
||||||
hcx.with_hir_bodies(false, node.def_id(), bodies, |hcx| {
|
hcx.with_hir_bodies(false, node.def_id(), bodies, |hcx| {
|
||||||
node.hash_stable(hcx, &mut stable_hasher)
|
node.hash_stable(hcx, &mut stable_hasher)
|
||||||
});
|
});
|
||||||
let node_hash = stable_hasher.finish();
|
let hash_without_bodies = stable_hasher.finish();
|
||||||
(full_hash, node_hash)
|
(hash_including_bodies, hash_without_bodies)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method allocates a new `HirId` for the given `NodeId` and stores it in
|
/// This method allocates a new `HirId` for the given `NodeId` and stores it in
|
||||||
|
|
|
@ -692,9 +692,9 @@ impl<'tcx> AttributeMap<'tcx> {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct OwnerNodes<'tcx> {
|
pub struct OwnerNodes<'tcx> {
|
||||||
/// Pre-computed hash of the full HIR.
|
/// Pre-computed hash of the full HIR.
|
||||||
pub hash: Fingerprint,
|
pub hash_including_bodies: Fingerprint,
|
||||||
/// Pre-computed hash of the top node.
|
/// Pre-computed hash of the item signature, sithout recursing into the body.
|
||||||
pub node_hash: Fingerprint,
|
pub hash_without_bodies: Fingerprint,
|
||||||
/// Full HIR for the current owner.
|
/// Full HIR for the current owner.
|
||||||
// The zeroth node's parent is trash, but is never accessed.
|
// The zeroth node's parent is trash, but is never accessed.
|
||||||
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
|
pub nodes: IndexVec<ItemLocalId, Option<ParentedNode<'tcx>>>,
|
||||||
|
|
|
@ -215,8 +215,9 @@ impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
|
||||||
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
|
||||||
// We ignore the `nodes` and `bodies` fields since these refer to information included in
|
// 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.
|
// `hash` which is hashed in the collector and used for the crate hash.
|
||||||
let OwnerNodes { hash, node_hash: _, nodes: _, bodies: _ } = *self;
|
let OwnerNodes { hash_including_bodies, hash_without_bodies: _, nodes: _, bodies: _ } =
|
||||||
hash.hash_stable(hcx, hasher);
|
*self;
|
||||||
|
hash_including_bodies.hash_stable(hcx, hasher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,14 @@ use rustc_span::DUMMY_SP;
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Owner<'tcx> {
|
pub struct Owner<'tcx> {
|
||||||
node: OwnerNode<'tcx>,
|
node: OwnerNode<'tcx>,
|
||||||
node_hash: Fingerprint,
|
hash_without_bodies: Fingerprint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
|
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Owner<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||||
let Owner { node: _, node_hash } = self;
|
let Owner { node: _, hash_without_bodies } = self;
|
||||||
node_hash.hash_stable(hcx, hasher)
|
hash_without_bodies.hash_stable(hcx, hasher)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
providers.hir_owner = |tcx, id| {
|
providers.hir_owner = |tcx, id| {
|
||||||
let owner = tcx.hir_crate(()).owners[id].as_ref()?;
|
let owner = tcx.hir_crate(()).owners[id].as_ref()?;
|
||||||
let node = owner.node();
|
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_nodes = |tcx, id| tcx.hir_crate(()).owners[id].as_ref().map(|i| &i.nodes);
|
||||||
providers.hir_owner_parent = |tcx, id| {
|
providers.hir_owner_parent = |tcx, id| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue