Skip to content

Commit 39164b8

Browse files
committed
Auto merge of #116826 - nnethercote:fix-116780-116797, r=compiler-errors
Fix a performance regression in obligation deduplication. Commit 8378487 from #114611 changed the location of an obligation deduplication step in `opt_normalize_projection_type`. This meant that deduplication stopped happening on one path where it was still necessary, causing a couple of drastic performance regressions. This commit moves the deduplication back to the old location. The good news is that #114611 had four commits and 8378487 was of minimal importance, so the perf benefits from that PR remain. Fixes #116780, #116797. r? `@compiler-errors`
2 parents 6433879 + 91f2fbc commit 39164b8

File tree

1 file changed

+4
-4
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+4
-4
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
12331233

12341234
let projected_term = selcx.infcx.resolve_vars_if_possible(projected_term);
12351235

1236-
let result = if projected_term.has_projections() {
1236+
let mut result = if projected_term.has_projections() {
12371237
let mut normalizer = AssocTypeNormalizer::new(
12381238
selcx,
12391239
param_env,
@@ -1243,14 +1243,14 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
12431243
);
12441244
let normalized_ty = normalizer.fold(projected_term);
12451245

1246-
let mut deduped = SsoHashSet::with_capacity(projected_obligations.len());
1247-
projected_obligations.retain(|obligation| deduped.insert(obligation.clone()));
1248-
12491246
Normalized { value: normalized_ty, obligations: projected_obligations }
12501247
} else {
12511248
Normalized { value: projected_term, obligations: projected_obligations }
12521249
};
12531250

1251+
let mut deduped = SsoHashSet::with_capacity(result.obligations.len());
1252+
result.obligations.retain(|obligation| deduped.insert(obligation.clone()));
1253+
12541254
if use_cache {
12551255
infcx.inner.borrow_mut().projection_cache().insert_term(cache_key, result.clone());
12561256
}

0 commit comments

Comments
 (0)