]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #37152 - arielb1:drop-cache, r=pnkfelix
authorbors <bors@rust-lang.org>
Sat, 15 Oct 2016 22:38:52 +0000 (15:38 -0700)
committerGitHub <noreply@github.com>
Sat, 15 Oct 2016 22:38:52 +0000 (15:38 -0700)
add a per-param-env cache to `impls_bound`

There used to be only a global cache, which led to uncached calls to
trait selection when there were type parameters.

This causes a 20% decrease in borrow-checking time and an overall 0.5% performance increase during bootstrapping (as borrow-checking tends to be a tiny part of compilation time).

Fixes #37106 (drop elaboration times are now ~half of borrow checking,
so might still be worthy of optimization, but not critical).

r? @pnkfelix

1  2 
src/librustc/ty/mod.rs
src/librustc_typeck/check/mod.rs

diff --combined src/librustc/ty/mod.rs
index 7108ac89d82bb4f849c62f76d1b67aca7a147c40,82f3c37b7b1a055995a485118a0aa608f402e1d9..d1fa2128842baa1432190564d8436fefc93cfc87
@@@ -34,7 -34,7 +34,7 @@@ use util::nodemap::FnvHashMap
  
  use serialize::{self, Encodable, Encoder};
  use std::borrow::Cow;
- use std::cell::Cell;
+ use std::cell::{Cell, RefCell};
  use std::hash::{Hash, Hasher};
  use std::iter;
  use std::ops::Deref;
@@@ -521,7 -521,7 +521,7 @@@ pub type Ty<'tcx> = &'tcx TyS<'tcx>
  impl<'tcx> serialize::UseSpecializedEncodable for Ty<'tcx> {}
  impl<'tcx> serialize::UseSpecializedDecodable for Ty<'tcx> {}
  
 -/// A wrapper for slices with the additioanl invariant
 +/// A wrapper for slices with the additional invariant
  /// that the slice is interned and no other slice with
  /// the same contents can exist in the same context.
  /// This means we can use pointer + length for both
@@@ -1220,6 -1220,12 +1220,12 @@@ pub struct ParameterEnvironment<'tcx> 
      /// regions don't have this implicit scope and instead introduce
      /// relationships in the environment.
      pub free_id_outlive: CodeExtent,
+     /// A cache for `moves_by_default`.
+     pub is_copy_cache: RefCell<FnvHashMap<Ty<'tcx>, bool>>,
+     /// A cache for `type_is_sized`
+     pub is_sized_cache: RefCell<FnvHashMap<Ty<'tcx>, bool>>,
  }
  
  impl<'a, 'tcx> ParameterEnvironment<'tcx> {
              implicit_region_bound: self.implicit_region_bound,
              caller_bounds: caller_bounds,
              free_id_outlive: self.free_id_outlive,
+             is_copy_cache: RefCell::new(FnvHashMap()),
+             is_sized_cache: RefCell::new(FnvHashMap()),
          }
      }
  
@@@ -2773,7 -2781,9 +2781,9 @@@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, '
              free_substs: Substs::empty(self),
              caller_bounds: Vec::new(),
              implicit_region_bound: self.mk_region(ty::ReEmpty),
-             free_id_outlive: free_id_outlive
+             free_id_outlive: free_id_outlive,
+             is_copy_cache: RefCell::new(FnvHashMap()),
+             is_sized_cache: RefCell::new(FnvHashMap()),
          }
      }
  
              implicit_region_bound: tcx.mk_region(ty::ReScope(free_id_outlive)),
              caller_bounds: predicates,
              free_id_outlive: free_id_outlive,
+             is_copy_cache: RefCell::new(FnvHashMap()),
+             is_sized_cache: RefCell::new(FnvHashMap()),
          };
  
          let cause = traits::ObligationCause::misc(span, free_id_outlive.node_id(&self.region_maps));
index 95d4416ec3327272886832d64983d944987a06bc,4116a84c74641af7efe68377da1b30df443577bb..2224b747210a69b1db5cd9f284ada16e0d70069d
@@@ -87,7 -87,7 +87,7 @@@ use hir::def::{Def, CtorKind, PathResol
  use hir::def_id::{DefId, LOCAL_CRATE};
  use hir::pat_util;
  use rustc::infer::{self, InferCtxt, InferOk, TypeOrigin, TypeTrace, type_variable};
 -use rustc::ty::subst::{Subst, Substs};
 +use rustc::ty::subst::{Kind, Subst, Substs};
  use rustc::traits::{self, Reveal};
  use rustc::ty::{ParamTy, ParameterEnvironment};
  use rustc::ty::{LvaluePreference, NoPreference, PreferMutLvalue};
@@@ -1361,7 -1361,7 +1361,7 @@@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx
  
      fn ty_infer_for_def(&self,
                          ty_param_def: &ty::TypeParameterDef<'tcx>,
 -                        substs: &Substs<'tcx>,
 +                        substs: &[Kind<'tcx>],
                          span: Span) -> Ty<'tcx> {
          self.type_var_for_def(span, ty_param_def, substs)
      }
@@@ -1458,7 -1458,7 +1458,7 @@@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, '
          }
      }
  
-     pub fn param_env(&self) -> &ty::ParameterEnvironment<'tcx> {
+     pub fn param_env(&self) -> &ty::ParameterEnvironment<'gcx> {
          &self.parameter_environment
      }