Skip to content

Commit

Permalink
rustc: Avoid HashStable for DefIndex queries
Browse files Browse the repository at this point in the history
I'm not 100% familiar with this trait and this location, but it looks like
there's a default implementation of `DepNodeParams` for anything that implements
`HashStable`, but types like `DefId` which have precalculated hashes bypass this
default implementation for a speedier one.

This commit applies what I believe is the same optimization to `DefIndex`,
looking up the local hash for it rather than going through the full `HashStable`
rigamarole

cc rust-lang#44575
  • Loading branch information
alexcrichton committed Sep 19, 2017
1 parent 0701b37 commit fffb99e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,18 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,
}
}

impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,) {
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;

fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
tcx.hir.definitions().def_path_hash(self.0).0
}

fn to_debug_str(&self, _tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
format!("{:?}", *self)
}
}

impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
const CAN_RECONSTRUCT_QUERY_KEY: bool = false;

Expand Down

0 comments on commit fffb99e

Please sign in to comment.