diff options
| author | The8472 <git@infinite-source.de> | 2021-11-14 23:49:57 +0100 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2021-11-14 23:49:57 +0100 |
| commit | 78b5f2d2faf490ab8799188a8e8bf9ead4906490 (patch) | |
| tree | 732db4adbf457f3a63ef198242d951de7efa3119 | |
| parent | ad442399756573dccacb314b6bf8079964bcc72a (diff) | |
| download | rust-78b5f2d2faf490ab8799188a8e8bf9ead4906490.tar.gz rust-78b5f2d2faf490ab8799188a8e8bf9ead4906490.zip | |
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.
| -rw-r--r-- | compiler/rustc_middle/src/traits/mod.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 245df636107..49071e7995b 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -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}; @@ -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, @@ -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( |
