Skip to content

Commit

Permalink
Simplify ObligationCauseData hash to skip ObligationCauseCode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the8472 committed Nov 14, 2021
1 parent ad44239 commit 78b5f2d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/rustc_middle/src/traits/mod.rs
Expand Up @@ -23,6 +23,7 @@ use smallvec::SmallVec;

use std::borrow::Cow;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::ops::Deref;

pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
Expand Down Expand Up @@ -108,7 +109,7 @@ impl Deref for ObligationCause<'tcx> {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
#[derive(Clone, Debug, PartialEq, Eq, Lift)]
pub struct ObligationCauseData<'tcx> {
pub span: Span,

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

impl Hash for ObligationCauseData<'_> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.body_id.hash(state);
self.span.hash(state);
std::mem::discriminant(&self.code).hash(state);
}
}

impl<'tcx> ObligationCause<'tcx> {
#[inline]
pub fn new(
Expand Down

0 comments on commit 78b5f2d

Please sign in to comment.