Ignore cause
and recursion_depth
in Obligation::{eq,hash}
.
This gives massive (~7x) compile time and memory usage reductions for the trait system stress test in https://github.com/rust-lang/rustc-perf/pull/1680.
This commit is contained in:
parent
8378487f27
commit
698f0e39e1
1 changed files with 23 additions and 1 deletions
|
@ -9,6 +9,7 @@ mod structural_impls;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
use hir::def_id::LocalDefId;
|
use hir::def_id::LocalDefId;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -36,7 +37,7 @@ pub use rustc_middle::traits::*;
|
||||||
/// either identifying an `impl` (e.g., `impl Eq for i32`) that
|
/// either identifying an `impl` (e.g., `impl Eq for i32`) that
|
||||||
/// satisfies the obligation, or else finding a bound that is in
|
/// satisfies the obligation, or else finding a bound that is in
|
||||||
/// scope. The eventual result is usually a `Selection` (defined below).
|
/// scope. The eventual result is usually a `Selection` (defined below).
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
#[derive(Clone)]
|
||||||
pub struct Obligation<'tcx, T> {
|
pub struct Obligation<'tcx, T> {
|
||||||
/// The reason we have to prove this thing.
|
/// The reason we have to prove this thing.
|
||||||
pub cause: ObligationCause<'tcx>,
|
pub cause: ObligationCause<'tcx>,
|
||||||
|
@ -55,6 +56,27 @@ pub struct Obligation<'tcx, T> {
|
||||||
pub recursion_depth: usize,
|
pub recursion_depth: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, T: PartialEq> PartialEq<Obligation<'tcx, T>> for Obligation<'tcx, T> {
|
||||||
|
#[inline]
|
||||||
|
fn eq(&self, other: &Obligation<'tcx, T>) -> bool {
|
||||||
|
// Ignore `cause` and `recursion_depth`. This is a small performance
|
||||||
|
// win for a few crates, and a huge performance win for the crate in
|
||||||
|
// https://github.com/rust-lang/rustc-perf/pull/1680, which greatly
|
||||||
|
// stresses the trait system.
|
||||||
|
self.param_env == other.param_env && self.predicate == other.predicate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Eq> Eq for Obligation<'_, T> {}
|
||||||
|
|
||||||
|
impl<T: Hash> Hash for Obligation<'_, T> {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) -> () {
|
||||||
|
// See the comment on `Obligation::eq`.
|
||||||
|
self.param_env.hash(state);
|
||||||
|
self.predicate.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
|
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
|
||||||
fn from(value: Obligation<'tcx, P>) -> Self {
|
fn from(value: Obligation<'tcx, P>) -> Self {
|
||||||
solve::Goal { param_env: value.param_env, predicate: value.predicate }
|
solve::Goal { param_env: value.param_env, predicate: value.predicate }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue