From 82f57c16b7f362c8f6509b9c334403d81a11beed Mon Sep 17 00:00:00 2001 From: Kyle Matsuda Date: Fri, 14 Apr 2023 09:59:03 -0600 Subject: [PATCH] use EarlyBinder in tcx.(try_)subst_mir_and_normalize_erasing_regions --- compiler/rustc_codegen_cranelift/src/common.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 +- .../rustc_const_eval/src/interpret/eval_context.rs | 6 +++++- compiler/rustc_middle/src/ty/instance.rs | 12 ++++++------ compiler/rustc_mir_transform/src/inline.rs | 2 +- compiler/rustc_mir_transform/src/inline/cycle.rs | 6 +++++- compiler/rustc_monomorphize/src/collector.rs | 2 +- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 264b95e7abd..ccb3a0c4f27 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -361,7 +361,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { self.instance.subst_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), - value, + ty::EarlyBinder(value), ) } diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index f706ecea975..1204c99e533 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.instance.subst_mir_and_normalize_erasing_regions( self.cx.tcx(), ty::ParamEnv::reveal_all(), - value, + ty::EarlyBinder(value), ) } } diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 361ce123c78..b2197a0aabb 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -495,7 +495,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> Result> { frame .instance - .try_subst_mir_and_normalize_erasing_regions(*self.tcx, self.param_env, value) + .try_subst_mir_and_normalize_erasing_regions( + *self.tcx, + self.param_env, + ty::EarlyBinder(value), + ) .map_err(|_| err_inval!(TooGeneric)) } diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index be584148595..808f46bb2bb 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -594,15 +594,15 @@ impl<'tcx> Instance<'tcx> { &self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - v: T, + v: EarlyBinder, ) -> T where T: TypeFoldable> + Clone, { if let Some(substs) = self.substs_for_mir_body() { - tcx.subst_and_normalize_erasing_regions(substs, param_env, ty::EarlyBinder(v)) + tcx.subst_and_normalize_erasing_regions(substs, param_env, v) } else { - tcx.normalize_erasing_regions(param_env, v) + tcx.normalize_erasing_regions(param_env, v.subst_identity()) } } @@ -611,15 +611,15 @@ impl<'tcx> Instance<'tcx> { &self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - v: T, + v: EarlyBinder, ) -> Result> where T: TypeFoldable> + Clone, { if let Some(substs) = self.substs_for_mir_body() { - tcx.try_subst_and_normalize_erasing_regions(substs, param_env, ty::EarlyBinder(v)) + tcx.try_subst_and_normalize_erasing_regions(substs, param_env, v) } else { - tcx.try_normalize_erasing_regions(param_env, v) + tcx.try_normalize_erasing_regions(param_env, v.subst_identity()) } } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 71bdfd5aae1..95978946c4d 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -180,7 +180,7 @@ impl<'tcx> Inliner<'tcx> { let Ok(callee_body) = callsite.callee.try_subst_mir_and_normalize_erasing_regions( self.tcx, self.param_env, - callee_body.clone(), + ty::EarlyBinder(callee_body.clone()), ) else { return Err("failed to normalize callee body"); }; diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index 6046c3876be..1ccf06f6153 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -44,7 +44,11 @@ pub(crate) fn mir_callgraph_reachable<'tcx>( ) -> bool { trace!(%caller); for &(callee, substs) in tcx.mir_inliner_callees(caller.def) { - let Ok(substs) = caller.try_subst_mir_and_normalize_erasing_regions(tcx, param_env, substs) else { + let Ok(substs) = caller.try_subst_mir_and_normalize_erasing_regions( + tcx, + param_env, + ty::EarlyBinder(substs), + ) else { trace!(?caller, ?param_env, ?substs, "cannot normalize, skipping"); continue; }; diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 65162477b7b..55c937b305a 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -677,7 +677,7 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> { self.instance.subst_mir_and_normalize_erasing_regions( self.tcx, ty::ParamEnv::reveal_all(), - value, + ty::EarlyBinder(value), ) } }