Skip to content

Commit 31e13b6

Browse files
authored
Rollup merge of rust-lang#156092 - susitsm:needs-hir-hash, r=petrochenkov
Clean up `TyCtxt::needs_crate_hash` usage and rename it to `needs_hir_hash`. While reviewing `crate_hash` query usage for rust-lang#155871, the `needs_crate_hash` function turned out to be the cause of unnecessary calls to the query. The `needs_crate_hash` name is easy to mistake for the functionality of "needs the crate_hash query". This PR removes the usage of `needs_crate_hash` where it was not appropriate and renames the function to `needs_hir_hash` which better reflects its functionality.
2 parents d2cd0b7 + 5313fb1 commit 31e13b6

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> {
562562

563563
// Don't hash unless necessary, because it's expensive.
564564
let opt_hir_hash =
565-
if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
565+
if tcx.needs_hir_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
566566

567567
let delayed_resolver = Steal::new((resolver, krate));
568568
mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash)

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Linker {
3636
Linker {
3737
dep_graph: tcx.dep_graph.clone(),
3838
output_filenames: Arc::clone(tcx.output_filenames(())),
39-
crate_hash: if tcx.needs_crate_hash() {
39+
crate_hash: if tcx.sess.opts.incremental.is_some() {
4040
Some(tcx.crate_hash(LOCAL_CRATE))
4141
} else {
4242
None

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'tcx> TyCtxt<'tcx> {
237237
attrs: &SortedMap<ItemLocalId, &[Attribute]>,
238238
define_opaque: Option<&[(Span, LocalDefId)]>,
239239
) -> Hashes {
240-
if !self.needs_crate_hash() {
240+
if !self.needs_hir_hash() {
241241
return Hashes { opt_hash_including_bodies: None, attrs_hash: None };
242242
}
243243

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,12 +1127,12 @@ impl<'tcx> TyCtxt<'tcx> {
11271127
})
11281128
}
11291129

1130-
pub fn needs_crate_hash(self) -> bool {
1131-
// Why is the crate hash needed for these configurations?
1130+
pub fn needs_hir_hash(self) -> bool {
1131+
// Why is the hir hash needed for these configurations?
11321132
// - debug_assertions: for the "fingerprint the result" check in
11331133
// `rustc_query_impl::execution::execute_job`.
11341134
// - incremental: for query lookups.
1135-
// - needs_metadata: for putting into crate metadata.
1135+
// - needs_metadata: it is included in the crate metadata through the crate_hash query
11361136
// - instrument_coverage: for putting into coverage data (see
11371137
// `hash_mir_source`).
11381138
// - metrics_dir: metrics use the strict version hash in the filenames

0 commit comments

Comments
 (0)