From 78b5f2d2faf490ab8799188a8e8bf9ead4906490 Mon Sep 17 00:00:00 2001 From: The8472 Date: Sun, 14 Nov 2021 23:49:57 +0100 Subject: [PATCH] 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. --- compiler/rustc_middle/src/traits/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 245df6361076f..49071e7995b4c 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(&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(