未验证 提交 41ad383e 编写于 作者: A Aaron Hill

Remove `DefId` from `ConstraintCategory::Predicate`

This shirnks the size of `ConstraintCategory`, hopefully
fixing a performance regression.
上级 93ab12ee
...@@ -40,7 +40,7 @@ fn description(&self) -> &'static str { ...@@ -40,7 +40,7 @@ fn description(&self) -> &'static str {
ConstraintCategory::OpaqueType => "opaque type ", ConstraintCategory::OpaqueType => "opaque type ",
ConstraintCategory::ClosureUpvar(_) => "closure capture ", ConstraintCategory::ClosureUpvar(_) => "closure capture ",
ConstraintCategory::Usage => "this usage ", ConstraintCategory::Usage => "this usage ",
ConstraintCategory::Predicate(_, _) ConstraintCategory::Predicate(_)
| ConstraintCategory::Boring | ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation | ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal => "", | ConstraintCategory::Internal => "",
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
use rustc_data_structures::frozen::Frozen; use rustc_data_structures::frozen::Frozen;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::scc::Sccs; 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_hir::CRATE_HIR_ID;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_infer::infer::canonical::QueryOutlivesConstraint; use rustc_infer::infer::canonical::QueryOutlivesConstraint;
...@@ -2000,8 +2000,14 @@ fn check_member_constraints( ...@@ -2000,8 +2000,14 @@ fn check_member_constraints(
let cause_code = path let cause_code = path
.iter() .iter()
.find_map(|constraint| { .find_map(|constraint| {
if let ConstraintCategory::Predicate(def_id, predicate_span) = constraint.category { if let ConstraintCategory::Predicate(predicate_span) = constraint.category {
Some(ObligationCauseCode::BindingObligation(def_id, predicate_span)) // 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 { } else {
None None
} }
...@@ -2106,7 +2112,7 @@ fn check_member_constraints( ...@@ -2106,7 +2112,7 @@ fn check_member_constraints(
| ConstraintCategory::Boring | ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation | ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal | ConstraintCategory::Internal
| ConstraintCategory::Predicate(_, _) => false, | ConstraintCategory::Predicate(_) => false,
ConstraintCategory::TypeAnnotation ConstraintCategory::TypeAnnotation
| ConstraintCategory::Return(_) | ConstraintCategory::Return(_)
| ConstraintCategory::Yield => true, | ConstraintCategory::Yield => true,
...@@ -2118,7 +2124,7 @@ fn check_member_constraints( ...@@ -2118,7 +2124,7 @@ fn check_member_constraints(
| ConstraintCategory::Boring | ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation | ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal | ConstraintCategory::Internal
| ConstraintCategory::Predicate(_, _) => false, | ConstraintCategory::Predicate(_) => false,
_ => true, _ => true,
} }
} }
......
...@@ -101,7 +101,9 @@ pub(super) fn prove_trait_ref( ...@@ -101,7 +101,9 @@ pub(super) fn prove_trait_ref(
pub(super) fn normalize_and_prove_instantiated_predicates( pub(super) fn normalize_and_prove_instantiated_predicates(
&mut self, &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>, instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
locations: Locations, locations: Locations,
) { ) {
...@@ -111,7 +113,7 @@ pub(super) fn normalize_and_prove_instantiated_predicates( ...@@ -111,7 +113,7 @@ pub(super) fn normalize_and_prove_instantiated_predicates(
.zip(instantiated_predicates.spans.into_iter()) .zip(instantiated_predicates.spans.into_iter())
{ {
let predicate = self.normalize(predicate, locations); let predicate = self.normalize(predicate, locations);
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(def_id, span)); self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
} }
} }
......
...@@ -309,6 +309,9 @@ pub struct ClosureOutlivesRequirement<'tcx> { ...@@ -309,6 +309,9 @@ pub struct ClosureOutlivesRequirement<'tcx> {
pub category: ConstraintCategory, 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 /// Outlives-constraints can be categorized to determine whether and why they
/// are interesting (for error reporting). Order of variants indicates sort /// are interesting (for error reporting). Order of variants indicates sort
/// order of the category, thereby influencing diagnostic output. /// order of the category, thereby influencing diagnostic output.
...@@ -341,7 +344,7 @@ pub enum ConstraintCategory { ...@@ -341,7 +344,7 @@ pub enum ConstraintCategory {
/// A constraint from a user-written predicate /// A constraint from a user-written predicate
/// with the provided span, written on the item /// with the provided span, written on the item
/// with the given `DefId` /// with the given `DefId`
Predicate(DefId, Span), Predicate(Span),
/// A "boring" constraint (caused by the given location) is one that /// A "boring" constraint (caused by the given location) is one that
/// the user probably doesn't want to see described in diagnostics, /// the user probably doesn't want to see described in diagnostics,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册