]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #53025 - ljedrz:debug_asserts_limited, r=varkor
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sun, 12 Aug 2018 21:26:50 +0000 (23:26 +0200)
committerGitHub <noreply@github.com>
Sun, 12 Aug 2018 21:26:50 +0000 (23:26 +0200)
Consider changing assert! to debug_assert! when it calls visit_with

The perf run from #52956 revealed that there were 3 benchmarks that benefited most from changing `assert!`s to `debug_assert!`s:

- issue #46449: avg -4.7% for -check
- deeply-nested (AKA #38528): avg -3.4% for -check
- regression #31157: avg -3.2% for -check

I analyzed their fixing PRs and decided to look for potentially heavy assertions in the files they modified. I noticed that all of the non-trivial ones contained indirect calls to `visit_with()`.

It might be a good idea to consider changing `assert!` to `debug_assert!` in those places in order to get the performance wins shown by the benchmarks.

src/librustc/traits/fulfill.rs
src/librustc/traits/project.rs
src/librustc/traits/select.rs
src/librustc/ty/layout.rs
src/librustc/ty/sty.rs

index b7d3ad76588f7253a8d596a4412eb76b675e8ce2..5113f3cde32843b588faee72e8e485fd5d0e2677 100644 (file)
@@ -146,7 +146,7 @@ fn normalize_projection_type<'a, 'gcx>(&mut self,
         debug!("normalize_projection_type(projection_ty={:?})",
                projection_ty);
 
-        assert!(!projection_ty.has_escaping_regions());
+        debug_assert!(!projection_ty.has_escaping_regions());
 
         // FIXME(#20304) -- cache
 
index 1ce60d8f05599e630905b5cf04fa5571106c8492..8d03f532660963e733c0a73a5b27387adb3fefa3 100644 (file)
@@ -1142,7 +1142,7 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
                 if !is_default {
                     true
                 } else if obligation.param_env.reveal == Reveal::All {
-                    assert!(!poly_trait_ref.needs_infer());
+                    debug_assert!(!poly_trait_ref.needs_infer());
                     if !poly_trait_ref.needs_subst() {
                         true
                     } else {
index 1e3fe70535bcc591e4206a1c7d678d317a91aaec..fbd12c9fe8ecaf796a8f2be66c3c5944fa69d979 100644 (file)
@@ -563,7 +563,7 @@ fn commit_if_ok<T, E, F>(&mut self, f: F) -> Result<T, E> where
     pub fn select(&mut self, obligation: &TraitObligation<'tcx>)
                   -> SelectionResult<'tcx, Selection<'tcx>> {
         debug!("select({:?})", obligation);
-        assert!(!obligation.predicate.has_escaping_regions());
+        debug_assert!(!obligation.predicate.has_escaping_regions());
 
         let stack = self.push_stack(TraitObligationStackList::empty(), obligation);
 
@@ -662,7 +662,7 @@ fn evaluate_predicate_recursively<'o>(&mut self,
 
         match obligation.predicate {
             ty::Predicate::Trait(ref t) => {
-                assert!(!t.has_escaping_regions());
+                debug_assert!(!t.has_escaping_regions());
                 let obligation = obligation.with(t.clone());
                 self.evaluate_trait_predicate_recursively(previous_stack, obligation)
             }
@@ -1076,7 +1076,7 @@ fn candidate_from_obligation<'o>(&mut self,
         debug!("candidate_from_obligation(cache_fresh_trait_pred={:?}, obligation={:?})",
                cache_fresh_trait_pred,
                stack);
-        assert!(!stack.obligation.predicate.has_escaping_regions());
+        debug_assert!(!stack.obligation.predicate.has_escaping_regions());
 
         if let Some(c) = self.check_candidate_cache(stack.obligation.param_env,
                                                     &cache_fresh_trait_pred) {
@@ -1586,7 +1586,7 @@ fn match_projection(&mut self,
                         snapshot: &infer::CombinedSnapshot<'cx, 'tcx>)
                         -> bool
     {
-        assert!(!skol_trait_ref.has_escaping_regions());
+        debug_assert!(!skol_trait_ref.has_escaping_regions());
         if self.infcx.at(&obligation.cause, obligation.param_env)
                      .sup(ty::Binder::dummy(skol_trait_ref), trait_bound).is_err() {
             return false;
index 81cc897232ab05da5b11bfc8f0885a56971a890b..0da4d5ddea2f264a5bea4abb08f7d51866f6ef1a 100644 (file)
@@ -466,7 +466,7 @@ enum StructKind {
         let univariant = |fields: &[TyLayout], repr: &ReprOptions, kind| {
             Ok(tcx.intern_layout(univariant_uninterned(fields, repr, kind)?))
         };
-        assert!(!ty.has_infer_types());
+        debug_assert!(!ty.has_infer_types());
 
         Ok(match ty.sty {
             // Basic scalars.
@@ -1283,7 +1283,7 @@ pub fn compute(ty: Ty<'tcx>,
                    tcx: TyCtxt<'a, 'tcx, 'tcx>,
                    param_env: ty::ParamEnv<'tcx>)
                    -> Result<SizeSkeleton<'tcx>, LayoutError<'tcx>> {
-        assert!(!ty.has_infer_types());
+        debug_assert!(!ty.has_infer_types());
 
         // First try computing a static layout.
         let err = match tcx.layout_of(param_env.and(ty)) {
@@ -1300,7 +1300,7 @@ pub fn compute(ty: Ty<'tcx>,
                 let tail = tcx.struct_tail(pointee);
                 match tail.sty {
                     ty::TyParam(_) | ty::TyProjection(_) => {
-                        assert!(tail.has_param_types() || tail.has_self_ty());
+                        debug_assert!(tail.has_param_types() || tail.has_self_ty());
                         Ok(SizeSkeleton::Pointer {
                             non_zero,
                             tail: tcx.erase_regions(&tail)
index 96b4edce86b30f5603b33af3f259b4bd62ce213e..65e31f21792d209fc42d3fddbbff94f98db1d094 100644 (file)
@@ -708,7 +708,7 @@ pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>,
     pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self_ty: Ty<'tcx>)
         -> ty::TraitRef<'tcx>  {
         // otherwise the escaping regions would be captured by the binder
-        assert!(!self_ty.has_escaping_regions());
+        debug_assert!(!self_ty.has_escaping_regions());
 
         ty::TraitRef {
             def_id: self.def_id,
@@ -753,7 +753,7 @@ impl<T> Binder<T> {
     pub fn dummy<'tcx>(value: T) -> Binder<T>
         where T: TypeFoldable<'tcx>
     {
-        assert!(!value.has_escaping_regions());
+        debug_assert!(!value.has_escaping_regions());
         Binder(value)
     }
 
@@ -1247,7 +1247,7 @@ pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
                         -> ty::ProjectionPredicate<'tcx>
     {
         // otherwise the escaping regions would be captured by the binders
-        assert!(!self_ty.has_escaping_regions());
+        debug_assert!(!self_ty.has_escaping_regions());
 
         ty::ProjectionPredicate {
             projection_ty: ty::ProjectionTy {