Skip to content

Commit d14ed92

Browse files
committed
Avoid hashing when creating a DepNode from a HirId
Instead, combine the already-present DefPathHash with the 32-bit ItemLocalIndex. Should fix #44323.
1 parent 2f1ef9e commit d14ed92

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/librustc/dep_graph/dep_node.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
6363
use hir::def_id::{CrateNum, DefId};
6464
use hir::map::DefPathHash;
65-
use hir::HirId;
65+
use hir::{HirId, ItemLocalId};
6666

6767
use ich::Fingerprint;
6868
use ty::{TyCtxt, Instance, InstanceDef};
@@ -638,6 +638,25 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIdList
638638
}
639639
}
640640

641+
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (HirId,) {
642+
const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
643+
644+
// We actually would not need to specialize the implementation of this
645+
// method but it's faster to combine the hashes than to instantiate a full
646+
// hashing context and stable-hashing state.
647+
fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
648+
let (HirId {
649+
owner,
650+
local_id: ItemLocalId(local_id),
651+
},) = *self;
652+
653+
let def_path_hash = tcx.def_path_hash(DefId::local(owner));
654+
let local_id = Fingerprint::from_smaller_hash(local_id as u64);
655+
656+
def_path_hash.0.combine(local_id)
657+
}
658+
}
659+
641660
/// A "work product" corresponds to a `.o` (or other) file that we
642661
/// save in between runs. These ids do not have a DefId but rather
643662
/// some independent path or string that persists between runs without

0 commit comments

Comments
 (0)