Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e1c6cf

Browse files
committed
Precompute hash for OwnerInfo too.
1 parent c135761 commit 5e1c6cf

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use rustc_ast::visit::{self, Visitor};
4545
use rustc_ast::{self as ast, *};
4646
use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
4747
use rustc_data_structures::sorted_map::SortedMap;
48+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
4849
use rustc_data_structures::tagged_ptr::TaggedRef;
4950
use rustc_data_structures::unord::ExtendUnord;
5051
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
@@ -679,16 +680,32 @@ impl<'hir> LoweringContext<'hir> {
679680
let bodies = SortedMap::from_presorted_elements(bodies);
680681

681682
// Don't hash unless necessary, because it's expensive.
682-
let (opt_hash_including_bodies, attrs_hash, delayed_lints_hash) =
683+
let (bodies_hash, attrs_hash, delayed_lints_hash) =
683684
self.tcx.hash_owner_nodes(node, &bodies, &attrs, &delayed_lints, define_opaque);
684685
let num_nodes = self.item_local_id_counter.as_usize();
685686
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
686-
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
687+
let nodes = hir::OwnerNodes { opt_hash: bodies_hash, nodes, bodies };
687688
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
688689
let delayed_lints =
689690
hir::lints::DelayedLints { lints: delayed_lints, opt_hash: delayed_lints_hash };
690691

692+
let opt_hash = if self.tcx.needs_crate_hash() {
693+
Some(self.tcx.with_stable_hashing_context(|mut hcx| {
694+
let mut stable_hasher = StableHasher::new();
695+
nodes.hash_stable(&mut hcx, &mut stable_hasher);
696+
parenting.hash_stable(&mut hcx, &mut stable_hasher);
697+
attrs.hash_stable(&mut hcx, &mut stable_hasher);
698+
trait_map.hash_stable(&mut hcx, &mut stable_hasher);
699+
delayed_lints.hash_stable(&mut hcx, &mut stable_hasher);
700+
children.hash_stable(&mut hcx, &mut stable_hasher);
701+
stable_hasher.finish()
702+
}))
703+
} else {
704+
None
705+
};
706+
691707
self.arena.alloc(hir::OwnerInfo {
708+
opt_hash,
692709
nodes,
693710
parenting,
694711
attrs,

‎compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ impl<'tcx> AttributeMap<'tcx> {
14821482
pub struct OwnerNodes<'tcx> {
14831483
/// Pre-computed hash of the full HIR. Used in the crate hash. Only present
14841484
/// when incr. comp. is enabled.
1485-
pub opt_hash_including_bodies: Option<Fingerprint>,
1485+
pub opt_hash: Option<Fingerprint>,
14861486
/// Full HIR for the current owner.
14871487
// The zeroth node's parent should never be accessed: the owner's parent is computed by the
14881488
// hir_owner_parent query. It is set to `ItemLocalId::INVALID` to force an ICE if accidentally
@@ -1515,13 +1515,13 @@ impl fmt::Debug for OwnerNodes<'_> {
15151515
}),
15161516
)
15171517
.field("bodies", &self.bodies)
1518-
.field("opt_hash_including_bodies", &self.opt_hash_including_bodies)
1518+
.field("opt_hash", &self.opt_hash)
15191519
.finish()
15201520
}
15211521
}
15221522

15231523
/// Full information resulting from lowering an AST node.
1524-
#[derive(Debug,HashStable_Generic)]
1524+
#[derive(Debug)]
15251525
pub struct OwnerInfo<'hir> {
15261526
/// Contents of the HIR.
15271527
pub nodes: OwnerNodes<'hir>,
@@ -1537,6 +1537,8 @@ pub struct OwnerInfo<'hir> {
15371537
pub delayed_lints: DelayedLints,
15381538
/// Owners generated as side-effect by lowering.
15391539
pub children: UnordMap<LocalDefId, MaybeOwner<'hir>>,
1540+
// Only present when the crate hash is needed.
1541+
pub opt_hash: Option<Fingerprint>,
15401542
}
15411543

15421544
impl<'tcx> OwnerInfo<'tcx> {

‎compiler/rustc_hir/src/stable_hash_impls.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_span::def_id::DefPathHash;
33

44
use crate::HashIgnoredAttrId;
55
use crate::hir::{
6-
AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId,
6+
AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerInfo,OwnerNodes, TraitItemId,
77
};
88
use crate::hir_id::{HirId, ItemLocalId};
99
use crate::lints::DelayedLints;
@@ -92,25 +92,25 @@ impl<HirCtx: crate::HashStableContext> ToStableHashKey<HirCtx> for ForeignItemId
9292
// in "DefPath Mode".
9393

9494
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerNodes<'tcx> {
95+
#[inline]
9596
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
96-
// We ignore the `nodes` and `bodies` fields since these refer to information included in
97-
// `hash` which is hashed in the collector and used for the crate hash.
98-
// `local_id_to_def_id` is also ignored because is dependent on the body, then just hashing
99-
// the body satisfies the condition of two nodes being different have different
100-
// `hash_stable` results.
101-
let OwnerNodes { opt_hash_including_bodies, nodes: _, bodies: _ } = *self;
102-
opt_hash_including_bodies.unwrap().hash_stable(hcx, hasher);
97+
// We ignore the other fields since these refer to information included in
98+
// `opt_hash` which is hashed in the collector and used for the crate hash.
99+
let OwnerNodes { opt_hash, .. } = *self;
100+
opt_hash.unwrap().hash_stable(hcx, hasher);
103101
}
104102
}
105103

106104
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for DelayedLints {
105+
#[inline]
107106
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
108107
let DelayedLints { opt_hash, .. } = *self;
109108
opt_hash.unwrap().hash_stable(hcx, hasher);
110109
}
111110
}
112111

113112
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap<'tcx> {
113+
#[inline]
114114
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
115115
// We ignore the `map` since it refers to information included in `opt_hash` which is
116116
// hashed in the collector and used for the crate hash.
@@ -119,6 +119,16 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for AttributeMap
119119
}
120120
}
121121

122+
impl<'tcx, HirCtx: crate::HashStableContext> HashStable<HirCtx> for OwnerInfo<'tcx> {
123+
#[inline]
124+
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
125+
// We ignore the rest since it refers to information included in `opt_hash` which is
126+
// hashed in the collector and used for the crate hash.
127+
let OwnerInfo { opt_hash, .. } = *self;
128+
opt_hash.unwrap().hash_stable(hcx, hasher);
129+
}
130+
}
131+
122132
impl<HirCtx: crate::HashStableContext> HashStable<HirCtx> for HashIgnoredAttrId {
123133
fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) {
124134
hcx.hash_attr_id(self, hasher)

‎compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,11 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
13601360
let bodies = Default::default();
13611361
let attrs = hir::AttributeMap::EMPTY;
13621362

1363-
let (opt_hash_including_bodies, _, _) =
1363+
let (opt_hash, _, _) =
13641364
self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, &[], attrs.define_opaque);
13651365
let node = node.into();
13661366
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
1367-
opt_hash_including_bodies,
1367+
opt_hash,
13681368
nodes: IndexVec::from_elem_n(
13691369
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
13701370
1,

‎compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn extract_hir_info<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> ExtractedHir
327327
fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx hir::Body<'tcx>) -> u64 {
328328
// FIXME(cjgillot) Stop hashing HIR manually here.
329329
let owner = hir_body.id().hir_id.owner;
330-
tcx.hir_owner_nodes(owner).opt_hash_including_bodies.unwrap().to_smaller_hash().as_u64()
330+
tcx.hir_owner_nodes(owner).opt_hash.unwrap().to_smaller_hash().as_u64()
331331
}
332332

333333
fn extract_hole_spans_from_hir<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &hir::Body<'tcx>) -> Vec<Span> {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /