Skip to content

Commit

Permalink
Only normalize once in mir validator typechecker
Browse files Browse the repository at this point in the history
Before, it called `normalize_erasing_regions` twice since
`equal_up_to_regions` called it as well for both types.
  • Loading branch information
Noratrieb committed Aug 29, 2022
1 parent 81a583c commit 96d4137
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,22 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
return true;
}

let try_equal_with_param_env = |param_env| {
let src = self.tcx.normalize_erasing_regions(param_env, src);
let dest = self.tcx.normalize_erasing_regions(param_env, dest);
// Type-changing assignments can happen when subtyping is used. While
// all normal lifetimes are erased, higher-ranked types with their
// late-bound lifetimes are still around and can lead to type
// differences. So we compare ignoring lifetimes.
equal_up_to_regions(self.tcx, param_env, src, dest)
};

// Normalize projections and things like that.
// Type-changing assignments can happen when subtyping is used. While
// all normal lifetimes are erased, higher-ranked types with their
// late-bound lifetimes are still around and can lead to type
// differences. So we compare ignoring lifetimes.

// First, try with reveal_all. This might not work in some cases, as the predicates
// can be cleared in reveal_all mode. We try the reveal first anyways as it is used
// by some other passes like inlining as well.
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
if try_equal_with_param_env(param_env) {
true
} else {
// If this fails, we can try it without the reveal.
try_equal_with_param_env(self.param_env)
if equal_up_to_regions(self.tcx, param_env, src, dest) {
return true;
}

// If this fails, we can try it without the reveal.
equal_up_to_regions(self.tcx, self.param_env, src, dest)
}
}

Expand Down

0 comments on commit 96d4137

Please sign in to comment.