diff options
| author | Michael Goulet <michael@errs.io> | 2025-06-12 15:53:34 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-06-13 17:57:25 +0000 |
| commit | 73c4863c6db9ad81adb41afcd8ee471ad0d256e9 (patch) | |
| tree | 6e96d6d94c667891a88f7f82730ecabfcea01e8c /compiler/rustc_middle/src/traits | |
| parent | fd50e1012f79eb93f661adc6f276335e4cfb34ea (diff) | |
| download | rust-73c4863c6db9ad81adb41afcd8ee471ad0d256e9.tar.gz rust-73c4863c6db9ad81adb41afcd8ee471ad0d256e9.zip | |
Don't fold ExternalConstraintsData when it's empty
Diffstat (limited to 'compiler/rustc_middle/src/traits')
| -rw-r--r-- | compiler/rustc_middle/src/traits/solve.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index 145561b76c4..ef5223de0e8 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -49,6 +49,13 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> { self, folder: &mut F, ) -> Result<Self, F::Error> { + // Perf testing has found that this check is slightly faster than + // folding and re-interning an empty `ExternalConstraintsData`. + // See: <https://github.com/rust-lang/rust/pull/142430>. + if self.is_empty() { + return Ok(self); + } + Ok(FallibleTypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData { region_constraints: self.region_constraints.clone().try_fold_with(folder)?, opaque_types: self @@ -64,6 +71,13 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> { } fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self { + // Perf testing has found that this check is slightly faster than + // folding and re-interning an empty `ExternalConstraintsData`. + // See: <https://github.com/rust-lang/rust/pull/142430>. + if self.is_empty() { + return self; + } + TypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData { region_constraints: self.region_constraints.clone().fold_with(folder), opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(), |
