8000 Normalize function type during validation by tmiasko · Pull Request #78969 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Normalize function type during validation #78969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Always use param_env_reveal_all_normalized in validator
  • Loading branch information
tmiasko committed Nov 12, 2020
commit 99be78d135e73197e04221c139a219ea6436e72a
17 changes: 7 additions & 10 deletions compiler/rustc_mir/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pub struct Validator {
impl<'tcx> MirPass<'tcx> for Validator {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let def_id = body.source.def_id();
let param_env = tcx.param_env(def_id);
// We need to param_env_reveal_all_normalized, as some optimizations
// change types in ways that require unfolding opaque types.
let param_env = tcx.param_env_reveal_all_normalized(def_id);
let mir_phase = self.mir_phase;

let always_live_locals = AlwaysLiveLocals::new(body);
Expand Down Expand Up @@ -79,7 +81,6 @@ pub fn equal_up_to_regions(
}

// Normalize lifetimes away on both sides, then compare.
let param_env = param_env.with_reveal_all_normalized(tcx);
let normalize = |ty: Ty<'tcx>| {
tcx.normalize_erasing_regions(
param_env,
Expand Down Expand Up @@ -167,17 +168,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
return true;
}
// Normalize projections and things like that.
// FIXME: We need to reveal_all, as some optimizations change types in ways
// that require unfolding opaque types.
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
let src = self.tcx.normalize_erasing_regions(param_env, src);
let dest = self.tcx.normalize_erasing_regions(param_env, dest);
let src = self.tcx.normalize_erasing_regions(self.param_env, src);
let dest = self.tcx.normalize_erasing_regions(self.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)
equal_up_to_regions(self.tcx, self.param_env, src, dest)
}
}

Expand Down Expand Up @@ -357,9 +355,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
}
TerminatorKind::Call { func, args, destination, cleanup, .. } => {
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
let func_ty = func.ty(&self.body.local_decls, self.tcx);
let func_ty = self.tcx.normalize_erasing_regions(param_env, func_ty);
let func_ty = self.tcx.normalize_erasing_regions(self.param_env, func_ty);
match func_ty.kind() {
ty::FnPtr(..) | ty::FnDef(..) => {}
_ => self.fail(
Expand Down
0