Skip to content

Commit 5b751d7

Browse files
Rollup merge of #144822 - Zalathar:hash-owner-nodes, r=compiler-errors
Return a struct with named fields from `hash_owner_nodes` While looking through this code for other reasons, I noticed a nice opportunity to return a struct with named fields instead of a tuple. The first patch also introduces an early-return to flatten the rest of `hash_owner_nodes`. There are further changes that could potentially be made here (renaming things, `Option<Hashes>` instead of optional fields), but I'm not deeply familiar with this code so I didn't want to disturb the calling code too much.
2 parents 7100b2d + d3e597a commit 5b751d7

3 files changed

Lines changed: 44 additions & 28 deletions

File tree

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
675675
let bodies = SortedMap::from_presorted_elements(bodies);
676676

677677
// Don't hash unless necessary, because it's expensive.
678-
let(opt_hash_including_bodies, attrs_hash, delayed_lints_hash) =
678+
letrustc_middle::hir::Hashes{opt_hash_including_bodies, attrs_hash, delayed_lints_hash} =
679679
self.tcx.hash_owner_nodes(node,&bodies,&attrs,&delayed_lints, define_opaque);
680680
let num_nodes = self.item_local_id_counter.as_usize();
681681
let(nodes, parenting) = index::index_hir(self.tcx, node,&bodies, num_nodes);

‎compiler/rustc_middle/src/hir/mod.rs‎

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -174,36 +174,52 @@ impl<'tcx> TyCtxt<'tcx> {
174174
attrs:&SortedMap<ItemLocalId,&[Attribute]>,
175175
delayed_lints:&[DelayedLint],
176176
define_opaque:Option<&[(Span,LocalDefId)]>,
177-
) -> (Option<Fingerprint>,Option<Fingerprint>,Option<Fingerprint>){
178-
ifself.needs_crate_hash(){
179-
self.with_stable_hashing_context(|mut hcx| {
180-
letmut stable_hasher = StableHasher::new();
181-
node.hash_stable(&mut hcx,&mut stable_hasher);
182-
// Bodies are stored out of line, so we need to pull them explicitly in the hash.
183-
bodies.hash_stable(&mut hcx,&mut stable_hasher);
184-
let h1 = stable_hasher.finish();
185-
186-
letmut stable_hasher = StableHasher::new();
187-
attrs.hash_stable(&mut hcx,&mut stable_hasher);
188-
189-
// Hash the defined opaque types, which are not present in the attrs.
190-
define_opaque.hash_stable(&mut hcx,&mut stable_hasher);
191-
192-
let h2 = stable_hasher.finish();
193-
194-
// hash lints emitted during ast lowering
195-
letmut stable_hasher = StableHasher::new();
196-
delayed_lints.hash_stable(&mut hcx,&mut stable_hasher);
197-
let h3 = stable_hasher.finish();
198-
199-
(Some(h1),Some(h2),Some(h3))
200-
})
201-
}else{
202-
(None,None,None)
177+
) -> Hashes{
178+
if !self.needs_crate_hash(){
179+
returnHashes{
180+
opt_hash_including_bodies:None,
181+
attrs_hash:None,
182+
delayed_lints_hash:None,
183+
};
203184
}
185+
186+
self.with_stable_hashing_context(|mut hcx| {
187+
letmut stable_hasher = StableHasher::new();
188+
node.hash_stable(&mut hcx,&mut stable_hasher);
189+
// Bodies are stored out of line, so we need to pull them explicitly in the hash.
190+
bodies.hash_stable(&mut hcx,&mut stable_hasher);
191+
let h1 = stable_hasher.finish();
192+
193+
letmut stable_hasher = StableHasher::new();
194+
attrs.hash_stable(&mut hcx,&mut stable_hasher);
195+
196+
// Hash the defined opaque types, which are not present in the attrs.
197+
define_opaque.hash_stable(&mut hcx,&mut stable_hasher);
198+
199+
let h2 = stable_hasher.finish();
200+
201+
// hash lints emitted during ast lowering
202+
letmut stable_hasher = StableHasher::new();
203+
delayed_lints.hash_stable(&mut hcx,&mut stable_hasher);
204+
let h3 = stable_hasher.finish();
205+
206+
Hashes{
207+
opt_hash_including_bodies:Some(h1),
208+
attrs_hash:Some(h2),
209+
delayed_lints_hash:Some(h3),
210+
}
211+
})
204212
}
205213
}
206214

215+
/// Hashes computed by [`TyCtxt::hash_owner_nodes`] if necessary.
216+
#[derive(Clone,Copy,Debug)]
217+
pubstructHashes{
218+
pubopt_hash_including_bodies:Option<Fingerprint>,
219+
pubattrs_hash:Option<Fingerprint>,
220+
pubdelayed_lints_hash:Option<Fingerprint>,
221+
}
222+
207223
pubfnprovide(providers:&mutProviders){
208224
providers.hir_crate_items = map::hir_crate_items;
209225
providers.crate_hash = map::crate_hash;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
13811381
let bodies = Default::default();
13821382
let attrs = hir::AttributeMap::EMPTY;
13831383

1384-
let(opt_hash_including_bodies,_, _) =
1384+
letrustc_middle::hir::Hashes{opt_hash_including_bodies,.. } =
13851385
self.tcx.hash_owner_nodes(node,&bodies,&attrs.map,&[], attrs.define_opaque);
13861386
let node = node.into();
13871387
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes{

0 commit comments

Comments
 (0)