Skip to content

Commit 41ad383

Browse files
committed
Remove DefId from ConstraintCategory::Predicate
This shirnks the size of `ConstraintCategory`, hopefully fixing a performance regression.
1 parent 93ab12e commit 41ad383

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ConstraintDescription for ConstraintCategory {
4040
ConstraintCategory::OpaqueType => "opaque type ",
4141
ConstraintCategory::ClosureUpvar(_) => "closure capture ",
4242
ConstraintCategory::Usage => "this usage ",
43-
ConstraintCategory::Predicate(_, _)
43+
ConstraintCategory::Predicate(_)
4444
| ConstraintCategory::Boring
4545
| ConstraintCategory::BoringNoLocation
4646
| ConstraintCategory::Internal => "",

compiler/rustc_borrowck/src/region_infer/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::binary_search_util;
55
use rustc_data_structures::frozen::Frozen;
66
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_data_structures::graph::scc::Sccs;
8-
use rustc_hir::def_id::DefId;
8+
use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
99
use rustc_hir::CRATE_HIR_ID;
1010
use rustc_index::vec::IndexVec;
1111
use rustc_infer::infer::canonical::QueryOutlivesConstraint;
@@ -2000,8 +2000,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20002000
let cause_code = path
20012001
.iter()
20022002
.find_map(|constraint| {
2003-
if let ConstraintCategory::Predicate(def_id, predicate_span) = constraint.category {
2004-
Some(ObligationCauseCode::BindingObligation(def_id, predicate_span))
2003+
if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
2004+
// We currentl'y doesn't store the `DefId` in the `ConstraintCategory`
2005+
// for perforamnce reasons. The error reporting code used by NLL only
2006+
// uses the span, so this doesn't cause any problems at the moment.
2007+
Some(ObligationCauseCode::BindingObligation(
2008+
CRATE_DEF_ID.to_def_id(),
2009+
predicate_span,
2010+
))
20052011
} else {
20062012
None
20072013
}
@@ -2106,7 +2112,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21062112
| ConstraintCategory::Boring
21072113
| ConstraintCategory::BoringNoLocation
21082114
| ConstraintCategory::Internal
2109-
| ConstraintCategory::Predicate(_, _) => false,
2115+
| ConstraintCategory::Predicate(_) => false,
21102116
ConstraintCategory::TypeAnnotation
21112117
| ConstraintCategory::Return(_)
21122118
| ConstraintCategory::Yield => true,
@@ -2118,7 +2124,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21182124
| ConstraintCategory::Boring
21192125
| ConstraintCategory::BoringNoLocation
21202126
| ConstraintCategory::Internal
2121-
| ConstraintCategory::Predicate(_, _) => false,
2127+
| ConstraintCategory::Predicate(_) => false,
21222128
_ => true,
21232129
}
21242130
}

compiler/rustc_borrowck/src/type_check/canonical.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
101101

102102
pub(super) fn normalize_and_prove_instantiated_predicates(
103103
&mut self,
104-
def_id: DefId,
104+
// Keep this parameter for now, in case we start using
105+
// it in `ConstraintCategory` at some point.
106+
_def_id: DefId,
105107
instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
106108
locations: Locations,
107109
) {
@@ -111,7 +113,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
111113
.zip(instantiated_predicates.spans.into_iter())
112114
{
113115
let predicate = self.normalize(predicate, locations);
114-
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(def_id, span));
116+
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
115117
}
116118
}
117119

compiler/rustc_middle/src/mir/query.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ pub struct ClosureOutlivesRequirement<'tcx> {
309309
pub category: ConstraintCategory,
310310
}
311311

312+
// Make sure this enum doesn't unintentionally grow
313+
rustc_data_structures::static_assert_size!(ConstraintCategory, 12);
314+
312315
/// Outlives-constraints can be categorized to determine whether and why they
313316
/// are interesting (for error reporting). Order of variants indicates sort
314317
/// order of the category, thereby influencing diagnostic output.
@@ -341,7 +344,7 @@ pub enum ConstraintCategory {
341344
/// A constraint from a user-written predicate
342345
/// with the provided span, written on the item
343346
/// with the given `DefId`
344-
Predicate(DefId, Span),
347+
Predicate(Span),
345348

346349
/// A "boring" constraint (caused by the given location) is one that
347350
/// the user probably doesn't want to see described in diagnostics,

0 commit comments

Comments
 (0)