Skip to content

Commit 78b5f2d

Browse files
committed
Simplify ObligationCauseData hash to skip ObligationCauseCode
selection deduplicates obligations through a hashset at some point, computing the hashes for ObligationCauseCode appears to dominate the hashing cost. bodyid + span + discriminant hash hopefully will sufficiently unique unique enough.
1 parent ad44239 commit 78b5f2d

File tree

1 file changed

+10
-1
lines changed
  • compiler/rustc_middle/src/traits

1 file changed

+10
-1
lines changed

compiler/rustc_middle/src/traits/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use smallvec::SmallVec;
2323

2424
use std::borrow::Cow;
2525
use std::fmt;
26+
use std::hash::{Hash, Hasher};
2627
use std::ops::Deref;
2728

2829
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
@@ -108,7 +109,7 @@ impl Deref for ObligationCause<'tcx> {
108109
}
109110
}
110111

111-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
112+
#[derive(Clone, Debug, PartialEq, Eq, Lift)]
112113
pub struct ObligationCauseData<'tcx> {
113114
pub span: Span,
114115

@@ -123,6 +124,14 @@ pub struct ObligationCauseData<'tcx> {
123124
pub code: ObligationCauseCode<'tcx>,
124125
}
125126

127+
impl Hash for ObligationCauseData<'_> {
128+
fn hash<H: Hasher>(&self, state: &mut H) {
129+
self.body_id.hash(state);
130+
self.span.hash(state);
131+
std::mem::discriminant(&self.code).hash(state);
132+
}
133+
}
134+
126135
impl<'tcx> ObligationCause<'tcx> {
127136
#[inline]
128137
pub fn new(

0 commit comments

Comments
 (0)