From 83d63c089db3ee84a340cd16a007817be63e22a3 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Wed, 9 Sep 2026 14:36:38 +0200 Subject: [PATCH 1/2] fix perf regression from abby canonical form --- compiler/rustc_type_ir/src/region_constraint.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_type_ir/src/region_constraint.rs b/compiler/rustc_type_ir/src/region_constraint.rs index 815acb11b9955..38477cb56e927 100644 --- a/compiler/rustc_type_ir/src/region_constraint.rs +++ b/compiler/rustc_type_ir/src/region_constraint.rs @@ -240,7 +240,7 @@ impl Or { } impl Or { pub fn new_true() -> Self { - Self(Box::new([And::new([])])) + Self(Box::new([And::new_true()])) } pub fn is_true(&self) -> bool { @@ -323,6 +323,10 @@ impl And { } } impl And { + pub fn new_true() -> Self { + Self(Box::new([])) + } + pub fn new(i: impl IntoIterator>) -> Self { let mut seen = IndexSet::new(); And(i @@ -406,7 +410,7 @@ impl RegionConst })); Self { - and_constraint: if or_constraint.is_false() { And::new([]) } else { and_constraint }, + and_constraint: if or_constraint.is_false() { And::new_true() } else { and_constraint }, or_constraint, } } @@ -422,7 +426,7 @@ impl RegionConst let or_constraint = Or::build_and(a.or_constraint, b.or_constraint); Self { - and_constraint: if or_constraint.is_false() { And::new([]) } else { and_constraint }, + and_constraint: if or_constraint.is_false() { And::new_true() } else { and_constraint }, or_constraint, } } @@ -432,7 +436,7 @@ impl RegionConst } pub fn new_true() -> Self { - Self { and_constraint: And::new([]), or_constraint: Or::new_true() } + Self { and_constraint: And::new_true(), or_constraint: Or::new_true() } } pub fn is_true(&self) -> bool { @@ -440,7 +444,7 @@ impl RegionConst } pub fn new_false() -> Self { - Self { and_constraint: And::new([]), or_constraint: Or::new_false() } + Self { and_constraint: And::new_true(), or_constraint: Or::new_false() } } pub fn is_false(&self) -> bool { From a8f5602587693ee0bef99da56950f31131f8fd6a Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Thu, 10 Sep 2026 10:55:03 +0200 Subject: [PATCH 2/2] lazily init SolverRegionConstraintStorage on access --- .../src/infer/solver_region_constraints.rs | 11 +++++++---- compiler/rustc_type_ir/src/region_constraint.rs | 6 ------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_infer/src/infer/solver_region_constraints.rs b/compiler/rustc_infer/src/infer/solver_region_constraints.rs index 09baae2ca8a42..03363c9f57a94 100644 --- a/compiler/rustc_infer/src/infer/solver_region_constraints.rs +++ b/compiler/rustc_infer/src/infer/solver_region_constraints.rs @@ -6,20 +6,23 @@ pub type SolverRegionConstraint<'tcx> = rustc_type_ir::region_constraint::RegionConstraint, Span>; #[derive(Clone, Debug)] -pub(crate) struct SolverRegionConstraintStorage<'tcx>(SolverRegionConstraint<'tcx>); +pub(crate) struct SolverRegionConstraintStorage<'tcx>(Option>); impl<'tcx> SolverRegionConstraintStorage<'tcx> { pub(crate) fn new() -> Self { - Self(SolverRegionConstraint::new_true()) + Self(None) } pub(crate) fn get_constraint(&self) -> SolverRegionConstraint<'tcx> { - self.0.clone() + match &self.0 { + Some(v) => v.clone(), + None => SolverRegionConstraint::new_true(), + } } #[instrument(level = "debug", skip(self))] pub(crate) fn overwrite(&mut self, constraint: SolverRegionConstraint<'tcx>) { - self.0 = constraint; + self.0 = Some(constraint); } } diff --git a/compiler/rustc_type_ir/src/region_constraint.rs b/compiler/rustc_type_ir/src/region_constraint.rs index 38477cb56e927..0dd79d8d0449e 100644 --- a/compiler/rustc_type_ir/src/region_constraint.rs +++ b/compiler/rustc_type_ir/src/region_constraint.rs @@ -481,12 +481,6 @@ impl RegionConst } } -impl Default for RegionConstraint { - fn default() -> Self { - Self::new_true() - } -} - impl LeafRegionConstraint { pub fn is_ambig(&self) -> bool { matches!(self, Self::Ambiguity(_))