about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-09-27 10:45:34 -0500
committerAaron Hill <aa1ronham@gmail.com>2021-09-27 10:45:34 -0500
commit41ad383e111423ba3f3062ede1354da4e0673e3d (patch)
treefc67e63dc4f919913569a8c4544e3c7b73d269d3
parent93ab12eeaba2c0cb02d4c89d95ddbc5eb38e1448 (diff)
Remove `DefId` from `ConstraintCategory::Predicate`
This shirnks the size of `ConstraintCategory`, hopefully
fixing a performance regression.
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_errors.rs2
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs16
-rw-r--r--compiler/rustc_borrowck/src/type_check/canonical.rs6
-rw-r--r--compiler/rustc_middle/src/mir/query.rs5
4 files changed, 20 insertions, 9 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
index b127330efa2..d05cfebc5f0 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
@@ -40,7 +40,7 @@ impl ConstraintDescription for ConstraintCategory {
             ConstraintCategory::OpaqueType => "opaque type ",
             ConstraintCategory::ClosureUpvar(_) => "closure capture ",
             ConstraintCategory::Usage => "this usage ",
-            ConstraintCategory::Predicate(_, _)
+            ConstraintCategory::Predicate(_)
             | ConstraintCategory::Boring
             | ConstraintCategory::BoringNoLocation
             | ConstraintCategory::Internal => "",
diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs
index cb1b0e0c934..917d69a5c86 100644
--- a/compiler/rustc_borrowck/src/region_infer/mod.rs
+++ b/compiler/rustc_borrowck/src/region_infer/mod.rs
@@ -5,7 +5,7 @@ use rustc_data_structures::binary_search_util;
 use rustc_data_structures::frozen::Frozen;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::graph::scc::Sccs;
-use rustc_hir::def_id::DefId;
+use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
 use rustc_hir::CRATE_HIR_ID;
 use rustc_index::vec::IndexVec;
 use rustc_infer::infer::canonical::QueryOutlivesConstraint;
@@ -2000,8 +2000,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         let cause_code = path
             .iter()
             .find_map(|constraint| {
-                if let ConstraintCategory::Predicate(def_id, predicate_span) = constraint.category {
-                    Some(ObligationCauseCode::BindingObligation(def_id, predicate_span))
+                if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
+                    // We currentl'y doesn't store the `DefId` in the `ConstraintCategory`
+                    // for perforamnce reasons. The error reporting code used by NLL only
+                    // uses the span, so this doesn't cause any problems at the moment.
+                    Some(ObligationCauseCode::BindingObligation(
+                        CRATE_DEF_ID.to_def_id(),
+                        predicate_span,
+                    ))
                 } else {
                     None
                 }
@@ -2106,7 +2112,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
                     | ConstraintCategory::Boring
                     | ConstraintCategory::BoringNoLocation
                     | ConstraintCategory::Internal
-                    | ConstraintCategory::Predicate(_, _) => false,
+                    | ConstraintCategory::Predicate(_) => false,
                     ConstraintCategory::TypeAnnotation
                     | ConstraintCategory::Return(_)
                     | ConstraintCategory::Yield => true,
@@ -2118,7 +2124,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
                     | ConstraintCategory::Boring
                     | ConstraintCategory::BoringNoLocation
                     | ConstraintCategory::Internal
-                    | ConstraintCategory::Predicate(_, _) => false,
+                    | ConstraintCategory::Predicate(_) => false,
                     _ => true,
                 }
             }
diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs
index 7ff74e4b96e..df28fb6e28e 100644
--- a/compiler/rustc_borrowck/src/type_check/canonical.rs
+++ b/compiler/rustc_borrowck/src/type_check/canonical.rs
@@ -101,7 +101,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
 
     pub(super) fn normalize_and_prove_instantiated_predicates(
         &mut self,
-        def_id: DefId,
+        // Keep this parameter for now, in case we start using
+        // it in `ConstraintCategory` at some point.
+        _def_id: DefId,
         instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
         locations: Locations,
     ) {
@@ -111,7 +113,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
             .zip(instantiated_predicates.spans.into_iter())
         {
             let predicate = self.normalize(predicate, locations);
-            self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(def_id, span));
+            self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
         }
     }
 
diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs
index 8d206d3eb1d..d5541d7890c 100644
--- a/compiler/rustc_middle/src/mir/query.rs
+++ b/compiler/rustc_middle/src/mir/query.rs
@@ -309,6 +309,9 @@ pub struct ClosureOutlivesRequirement<'tcx> {
     pub category: ConstraintCategory,
 }
 
+// Make sure this enum doesn't unintentionally grow
+rustc_data_structures::static_assert_size!(ConstraintCategory, 12);
+
 /// Outlives-constraints can be categorized to determine whether and why they
 /// are interesting (for error reporting). Order of variants indicates sort
 /// order of the category, thereby influencing diagnostic output.
@@ -341,7 +344,7 @@ pub enum ConstraintCategory {
     /// A constraint from a user-written predicate
     /// with the provided span, written on the item
     /// with the given `DefId`
-    Predicate(DefId, Span),
+    Predicate(Span),
 
     /// A "boring" constraint (caused by the given location) is one that
     /// the user probably doesn't want to see described in diagnostics,