Skip to content

Commit e2c96e4

Browse files
Rollup merge of #165774 - jdonszelmann:better-auto-traits, r=fmease
Auto trait finder: Avoid recomputing `ParamEnv` if nothing changed r? @fmease > [!NOTE] > <table> > <tr><td> > > ![ai:0](https://github.com/jdonszelmann/0rwx.com/blob/main/static/50x50/AI-0-50x50.png?raw=true) > > </td><td> > > [I've not used an LLM for any part of this PR, or any other PR I make. This includes any related work like research.](https://0rwx.com/.) > > </td></tr> > </table>
2 parents e2867c9 + 2a137d3 commit e2c96e4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎compiler/rustc_trait_selection/src/traits/auto_trait.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
346346
param_env.caller_bounds().all_clauses(infcx.tcx).iter().collect::<Vec<_>>();
347347
let mut user_computed_clauses: FxIndexSet<_> =
348348
user_env.caller_bounds().all_clauses(infcx.tcx).iter().collect();
349+
let mut prev_user_computed_clauses = None::<FxIndexSet<_>>;
349350

350351
let mut new_env = param_env;
351352
let dummy_cause = ObligationCause::dummy();
@@ -418,6 +419,16 @@ impl<'tcx> AutoTraitFinder<'tcx> {
418419
_ => panic!("Unexpected error for '{ty:?}': {result:?}"),
419420
};
420421

422+
// `computed_clauses` doesn't change, only `user_computed_clauses` does.
423+
// except not always! If it didn't, we can stop here.
424+
if prev_user_computed_clauses
425+
.as_ref()
426+
.is_some_and(|prev| prev == &user_computed_clauses)
427+
{
428+
continue;
429+
}
430+
prev_user_computed_clauses = Some(user_computed_clauses.clone());
431+
421432
let normalized_preds = elaborate(
422433
tcx,
423434
computed_clauses.iter().copied().chain(user_computed_clauses.iter().cloned()),

0 commit comments

Comments
 (0)