Skip to content

Commit 7827d55

Browse files
committed
Auto merge of #142430 - compiler-errors:external-constraints, r=lcnr
Don't fold `ExternalConstraintsData` when it's empty Probably useless, but let's see. r? lcnr
2 parents 75e7cf5 + 73c4863 commit 7827d55

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

compiler/rustc_middle/src/traits/solve.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
4949
self,
5050
folder: &mut F,
5151
) -> Result<Self, F::Error> {
52+
// Perf testing has found that this check is slightly faster than
53+
// folding and re-interning an empty `ExternalConstraintsData`.
54+
// See: <https://github.com/rust-lang/rust/pull/142430>.
55+
if self.is_empty() {
56+
return Ok(self);
57+
}
58+
5259
Ok(FallibleTypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData {
5360
region_constraints: self.region_constraints.clone().try_fold_with(folder)?,
5461
opaque_types: self
@@ -64,6 +71,13 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
6471
}
6572

6673
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
74+
// Perf testing has found that this check is slightly faster than
75+
// folding and re-interning an empty `ExternalConstraintsData`.
76+
// See: <https://github.com/rust-lang/rust/pull/142430>.
77+
if self.is_empty() {
78+
return self;
79+
}
80+
6781
TypeFolder::cx(folder).mk_external_constraints(ExternalConstraintsData {
6882
region_constraints: self.region_constraints.clone().fold_with(folder),
6983
opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),

compiler/rustc_type_ir/src/solve/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ pub struct ExternalConstraintsData<I: Interner> {
236236
pub normalization_nested_goals: NestedNormalizationGoals<I>,
237237
}
238238

239+
impl<I: Interner> ExternalConstraintsData<I> {
240+
pub fn is_empty(&self) -> bool {
241+
self.region_constraints.is_empty()
242+
&& self.opaque_types.is_empty()
243+
&& self.normalization_nested_goals.is_empty()
244+
}
245+
}
246+
239247
#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)]
240248
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
241249
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]

0 commit comments

Comments
 (0)