From 6106bd51514257f78de6d0b3288ffbe4bbd437b4 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Thu, 24 Oct 2024 23:25:55 -0400 Subject: [PATCH] Pass a ParamEnv to passes instead of looking it up everywhere --- .../src/abort_unwinding_calls.rs | 4 +- .../src/add_call_guards.rs | 4 +- .../src/add_moves_for_packed_drops.rs | 6 +-- compiler/rustc_mir_transform/src/add_retag.rs | 6 +-- .../src/add_subtyping_projections.rs | 4 +- .../src/check_alignment.rs | 3 +- .../src/cleanup_post_borrowck.rs | 4 +- compiler/rustc_mir_transform/src/copy_prop.rs | 5 +-- compiler/rustc_mir_transform/src/coroutine.rs | 12 ++++-- .../rustc_mir_transform/src/coverage/mod.rs | 9 +++- .../rustc_mir_transform/src/ctfe_limit.rs | 4 +- .../src/dataflow_const_prop.rs | 14 +++--- .../src/dead_store_elimination.rs | 4 +- .../src/deduplicate_blocks.rs | 4 +- .../src/deref_separator.rs | 4 +- compiler/rustc_mir_transform/src/dest_prop.rs | 4 +- compiler/rustc_mir_transform/src/dump_mir.rs | 4 +- .../src/early_otherwise_branch.rs | 4 +- .../src/elaborate_box_derefs.rs | 4 +- .../src/elaborate_drops.rs | 6 +-- compiler/rustc_mir_transform/src/gvn.rs | 5 +-- compiler/rustc_mir_transform/src/inline.rs | 7 ++- .../rustc_mir_transform/src/instsimplify.rs | 8 +--- .../rustc_mir_transform/src/jump_threading.rs | 6 +-- .../rustc_mir_transform/src/large_enums.rs | 4 +- compiler/rustc_mir_transform/src/lib.rs | 43 ++++++++++++++++--- .../src/lower_intrinsics.rs | 4 +- .../src/lower_slice_len.rs | 4 +- .../rustc_mir_transform/src/match_branches.rs | 3 +- .../src/mentioned_items.rs | 4 +- .../src/multiple_return_terminators.rs | 4 +- compiler/rustc_mir_transform/src/nrvo.rs | 4 +- .../rustc_mir_transform/src/pass_manager.rs | 39 +++++++++++------ compiler/rustc_mir_transform/src/prettify.rs | 6 +-- .../rustc_mir_transform/src/promote_consts.rs | 5 ++- compiler/rustc_mir_transform/src/ref_prop.rs | 13 +++--- .../src/remove_noop_landing_pads.rs | 4 +- .../src/remove_place_mention.rs | 4 +- .../src/remove_storage_markers.rs | 4 +- .../src/remove_uninit_drops.rs | 3 +- .../src/remove_unneeded_drops.rs | 5 +-- .../rustc_mir_transform/src/remove_zsts.rs | 5 +-- .../rustc_mir_transform/src/reveal_all.rs | 5 +-- compiler/rustc_mir_transform/src/shim.rs | 2 + compiler/rustc_mir_transform/src/simplify.rs | 6 +-- .../src/simplify_branches.rs | 5 +-- .../src/simplify_comparison_integral.rs | 5 +-- .../src/single_use_consts.rs | 4 +- compiler/rustc_mir_transform/src/sroa.rs | 5 +-- .../src/unreachable_enum_branching.rs | 8 ++-- .../src/unreachable_prop.rs | 6 +-- compiler/rustc_mir_transform/src/validate.rs | 2 +- 52 files changed, 191 insertions(+), 150 deletions(-) diff --git a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index 84c8a91b08252..57652ce7c98db 100644 --- a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -1,7 +1,7 @@ use rustc_ast::InlineAsmOptions; use rustc_middle::mir::*; use rustc_middle::span_bug; -use rustc_middle::ty::{self, TyCtxt, layout}; +use rustc_middle::ty::{self, ParamEnv, TyCtxt, layout}; use rustc_target::spec::PanicStrategy; use rustc_target::spec::abi::Abi; @@ -23,7 +23,7 @@ use rustc_target::spec::abi::Abi; pub(super) struct AbortUnwindingCalls; impl<'tcx> crate::MirPass<'tcx> for AbortUnwindingCalls { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id(); let kind = tcx.def_kind(def_id); diff --git a/compiler/rustc_mir_transform/src/add_call_guards.rs b/compiler/rustc_mir_transform/src/add_call_guards.rs index 24c955c0c78c6..94b9605b36c29 100644 --- a/compiler/rustc_mir_transform/src/add_call_guards.rs +++ b/compiler/rustc_mir_transform/src/add_call_guards.rs @@ -1,6 +1,6 @@ use rustc_index::{Idx, IndexVec}; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::debug; #[derive(PartialEq)] @@ -31,7 +31,7 @@ pub(super) use self::AddCallGuards::*; */ impl<'tcx> crate::MirPass<'tcx> for AddCallGuards { - fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let mut pred_count: IndexVec<_, _> = body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect(); pred_count[START_BLOCK] += 1; diff --git a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs index 559df222a5040..fc635d7733495 100644 --- a/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs +++ b/compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs @@ -1,6 +1,6 @@ use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::debug; use crate::util; @@ -38,12 +38,10 @@ use crate::util; pub(super) struct AddMovesForPackedDrops; impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!("add_moves_for_packed_drops({:?} @ {:?})", body.source, body.span); - let def_id = body.source.def_id(); let mut patch = MirPatch::new(body); - let param_env = tcx.param_env(def_id); for (bb, data) in body.basic_blocks.iter_enumerated() { let loc = Location { block: bb, statement_index: data.statements.len() }; diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index 53176eec9bcb9..2da38f7636d5d 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -6,7 +6,7 @@ use rustc_hir::LangItem; use rustc_middle::mir::*; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; pub(super) struct AddRetag; @@ -53,9 +53,9 @@ impl<'tcx> crate::MirPass<'tcx> for AddRetag { sess.opts.unstable_opts.mir_emit_retag } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // We need an `AllCallEdges` pass before we can do any work. - super::add_call_guards::AllCallEdges.run_pass(tcx, body); + super::add_call_guards::AllCallEdges.run_pass(tcx, param_env, body); let basic_blocks = body.basic_blocks.as_mut(); let local_decls = &body.local_decls; diff --git a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs index e585e338613d8..c524517c37037 100644 --- a/compiler/rustc_mir_transform/src/add_subtyping_projections.rs +++ b/compiler/rustc_mir_transform/src/add_subtyping_projections.rs @@ -1,7 +1,7 @@ use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; pub(super) struct Subtyper; @@ -52,7 +52,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> { // let temp: rval_ty = rval; // let place: place_ty = temp as place_ty; impl<'tcx> crate::MirPass<'tcx> for Subtyper { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let patch = MirPatch::new(body); let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls }; diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index a9600f77c0b6e..d0ce4d7041b67 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -18,7 +18,7 @@ impl<'tcx> crate::MirPass<'tcx> for CheckAlignment { sess.ub_checks() } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // This pass emits new panics. If for whatever reason we do not have a panic // implementation, running this pass may cause otherwise-valid code to not compile. if tcx.lang_items().get(LangItem::PanicImpl).is_none() { @@ -27,7 +27,6 @@ impl<'tcx> crate::MirPass<'tcx> for CheckAlignment { let basic_blocks = body.basic_blocks.as_mut(); let local_decls = &mut body.local_decls; - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); // This pass inserts new blocks. Each insertion changes the Location for all // statements/blocks after. Iterating or visiting the MIR in order would require updating diff --git a/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs index 6a22a58470c95..75b763e423b59 100644 --- a/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs +++ b/compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs @@ -18,13 +18,13 @@ use rustc_middle::mir::coverage::CoverageKind; use rustc_middle::mir::{Body, BorrowKind, CastKind, Rvalue, StatementKind, TerminatorKind}; -use rustc_middle::ty::TyCtxt; use rustc_middle::ty::adjustment::PointerCoercion; +use rustc_middle::ty::{ParamEnv, TyCtxt}; pub(super) struct CleanupPostBorrowck; impl<'tcx> crate::MirPass<'tcx> for CleanupPostBorrowck { - fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { for basic_block in body.basic_blocks.as_mut() { for statement in basic_block.statements.iter_mut() { match statement.kind { diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index 7d6ae9843b15f..73f2bcbd1db8a 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -2,7 +2,7 @@ use rustc_index::IndexSlice; use rustc_index::bit_set::BitSet; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::{debug, instrument}; use crate::ssa::SsaLocals; @@ -25,10 +25,9 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { } #[instrument(level = "trace", skip(self, tcx, body))] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); let ssa = SsaLocals::new(tcx, body, param_env); let fully_moved = fully_moved_locals(&ssa, body); diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index cd29105897778..0e275b6fe2fb6 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -64,7 +64,7 @@ use rustc_index::{Idx, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::{ - self, CoroutineArgs, CoroutineArgsExt, GenericArgsRef, InstanceKind, Ty, TyCtxt, + self, CoroutineArgs, CoroutineArgsExt, GenericArgsRef, InstanceKind, ParamEnv, Ty, TyCtxt, }; use rustc_middle::{bug, span_bug}; use rustc_mir_dataflow::Analysis; @@ -1361,7 +1361,13 @@ fn create_coroutine_resume_function<'tcx>( // unrelated code from the drop part of the function simplify::remove_dead_blocks(body); - pm::run_passes_no_validate(tcx, body, &[&abort_unwinding_calls::AbortUnwindingCalls], None); + pm::run_passes_no_validate( + tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), + body, + &[&abort_unwinding_calls::AbortUnwindingCalls], + None, + ); dump_mir(tcx, false, "coroutine_resume", &0, body, |_, _| Ok(())); } @@ -1526,7 +1532,7 @@ fn check_field_tys_sized<'tcx>( } impl<'tcx> crate::MirPass<'tcx> for StateTransform { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let Some(old_yield_ty) = body.yield_ty() else { // This only applies to coroutines return; diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 2e4c503f3ce5b..87d581e77a9ee 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -19,7 +19,7 @@ use rustc_middle::mir::{ self, BasicBlock, BasicBlockData, SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, }; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_span::def_id::LocalDefId; use rustc_span::source_map::SourceMap; use rustc_span::{BytePos, Pos, RelativeBytePos, Span, Symbol}; @@ -39,7 +39,12 @@ impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage { sess.instrument_coverage() } - fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) { + fn run_pass( + &self, + tcx: TyCtxt<'tcx>, + _param_env: ParamEnv<'tcx>, + mir_body: &mut mir::Body<'tcx>, + ) { let mir_source = mir_body.source; // This pass runs after MIR promotion, but before promoted MIR starts to diff --git a/compiler/rustc_mir_transform/src/ctfe_limit.rs b/compiler/rustc_mir_transform/src/ctfe_limit.rs index bd58b1b668997..8c357a63d9da0 100644 --- a/compiler/rustc_mir_transform/src/ctfe_limit.rs +++ b/compiler/rustc_mir_transform/src/ctfe_limit.rs @@ -5,14 +5,14 @@ use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::mir::{ BasicBlock, BasicBlockData, Body, Statement, StatementKind, TerminatorKind, }; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::instrument; pub(super) struct CtfeLimit; impl<'tcx> crate::MirPass<'tcx> for CtfeLimit { #[instrument(skip(self, _tcx, body))] - fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let doms = body.basic_blocks.dominators(); let indices: Vec = body .basic_blocks diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 002216f50f2d1..9214ca8d79e03 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -13,7 +13,7 @@ use rustc_middle::mir::interpret::{InterpResult, Scalar}; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::layout::{HasParamEnv, LayoutOf}; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; use rustc_mir_dataflow::lattice::FlatSet; use rustc_mir_dataflow::value_analysis::{ Map, PlaceIndex, State, TrackElem, ValueAnalysis, ValueAnalysisWrapper, ValueOrPlace, @@ -36,7 +36,7 @@ impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp { } #[instrument(skip_all level = "debug")] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); if tcx.sess.mir_opt_level() < 4 && body.basic_blocks.len() > BLOCK_LIMIT { debug!("aborted dataflow const prop due too many basic blocks"); @@ -57,7 +57,7 @@ impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp { let map = Map::new(tcx, body, place_limit); // Perform the actual dataflow analysis. - let analysis = ConstAnalysis::new(tcx, body, map); + let analysis = ConstAnalysis::new(tcx, param_env, body, map); let mut results = debug_span!("analyze") .in_scope(|| analysis.wrap().into_engine(tcx, body).iterate_to_fixpoint()); @@ -337,8 +337,12 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> { } impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { - fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map<'tcx>) -> Self { - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); + fn new( + tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, + body: &'a Body<'tcx>, + map: Map<'tcx>, + ) -> Self { Self { map, tcx, diff --git a/compiler/rustc_mir_transform/src/dead_store_elimination.rs b/compiler/rustc_mir_transform/src/dead_store_elimination.rs index edffe6ce78f67..6b8314b1c1a2f 100644 --- a/compiler/rustc_mir_transform/src/dead_store_elimination.rs +++ b/compiler/rustc_mir_transform/src/dead_store_elimination.rs @@ -15,7 +15,7 @@ use rustc_middle::bug; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::debuginfo::debuginfo_locals; use rustc_mir_dataflow::impls::{ @@ -144,7 +144,7 @@ impl<'tcx> crate::MirPass<'tcx> for DeadStoreElimination { sess.mir_opt_level() >= 2 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { eliminate(tcx, body); } } diff --git a/compiler/rustc_mir_transform/src/deduplicate_blocks.rs b/compiler/rustc_mir_transform/src/deduplicate_blocks.rs index 26b28c8c4870e..5eaf867878b3f 100644 --- a/compiler/rustc_mir_transform/src/deduplicate_blocks.rs +++ b/compiler/rustc_mir_transform/src/deduplicate_blocks.rs @@ -8,7 +8,7 @@ use std::iter; use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::debug; use super::simplify::simplify_cfg; @@ -20,7 +20,7 @@ impl<'tcx> crate::MirPass<'tcx> for DeduplicateBlocks { sess.mir_opt_level() >= 4 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!("Running DeduplicateBlocks on `{:?}`", body.source); let duplicates = find_duplicates(body); let has_opts_to_apply = !duplicates.is_empty(); diff --git a/compiler/rustc_mir_transform/src/deref_separator.rs b/compiler/rustc_mir_transform/src/deref_separator.rs index ad7ccef4976aa..60b2382e07dab 100644 --- a/compiler/rustc_mir_transform/src/deref_separator.rs +++ b/compiler/rustc_mir_transform/src/deref_separator.rs @@ -2,7 +2,7 @@ use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::visit::NonUseContext::VarDebugInfo; use rustc_middle::mir::visit::{MutVisitor, PlaceContext}; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; pub(super) struct Derefer; @@ -78,7 +78,7 @@ pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { } impl<'tcx> crate::MirPass<'tcx> for Derefer { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { deref_finder(tcx, body); } } diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index ad83c0295baec..f6cda095fcf54 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -140,7 +140,7 @@ use rustc_middle::mir::{ Body, HasLocalDecls, InlineAsmOperand, Local, LocalKind, Location, Operand, PassWhere, Place, Rvalue, Statement, StatementKind, TerminatorKind, dump_mir, traversal, }; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::impls::MaybeLiveLocals; use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex, save_as_intervals}; @@ -161,7 +161,7 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation { sess.mir_opt_level() >= 3 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id(); let mut candidates = Candidates::default(); let mut write_info = WriteInfo::default(); diff --git a/compiler/rustc_mir_transform/src/dump_mir.rs b/compiler/rustc_mir_transform/src/dump_mir.rs index 5dd84975b88ed..066ccfc715d78 100644 --- a/compiler/rustc_mir_transform/src/dump_mir.rs +++ b/compiler/rustc_mir_transform/src/dump_mir.rs @@ -4,7 +4,7 @@ use std::fs::File; use std::io; use rustc_middle::mir::{Body, write_mir_pretty}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_session::config::{OutFileName, OutputType}; pub(super) struct Marker(pub &'static str); @@ -14,7 +14,7 @@ impl<'tcx> crate::MirPass<'tcx> for Marker { self.0 } - fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {} + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, _body: &mut Body<'tcx>) {} } pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> { diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index 704ed508b22a8..5405035e99826 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use tracing::trace; use super::simplify::simplify_cfg; @@ -97,7 +97,7 @@ impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { sess.mir_opt_level() >= 2 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("running EarlyOtherwiseBranch on {:?}", body.source); let mut should_cleanup = false; diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index 57f7a9ef7f5fc..2b7ab7949caa6 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -7,7 +7,7 @@ use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; use rustc_middle::span_bug; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_target::abi::FieldIdx; /// Constructs the types used when accessing a Box's pointer @@ -91,7 +91,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> { pub(super) struct ElaborateBoxDerefs; impl<'tcx> crate::MirPass<'tcx> for ElaborateBoxDerefs { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // If box is not present, this pass doesn't need to do anything. let Some(def_id) = tcx.lang_items().owned_box() else { return }; diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index 30e1ac05e039c..7ff1f069b5158 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -4,7 +4,7 @@ use rustc_index::IndexVec; use rustc_index::bit_set::BitSet; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, TyCtxt}; use rustc_mir_dataflow::elaborate_drops::{ DropElaborator, DropFlagMode, DropFlagState, DropStyle, Unwind, elaborate_drop, }; @@ -51,11 +51,9 @@ pub(super) struct ElaborateDrops; impl<'tcx> crate::MirPass<'tcx> for ElaborateDrops { #[instrument(level = "trace", skip(self, tcx, body))] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!("elaborate_drops({:?} @ {:?})", body.source, body.span); - let def_id = body.source.def_id(); - let param_env = tcx.param_env_reveal_all_normalized(def_id); // For types that do not need dropping, the behaviour is trivial. So we only need to track // init/uninit for types that do need dropping. let move_data = MoveData::gather_moves(body, tcx, |ty| ty.needs_drop(tcx, param_env)); diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index f507690317913..bdb7c1734c6cb 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -101,7 +101,7 @@ use rustc_middle::mir::interpret::GlobalAlloc; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::layout::{HasParamEnv, LayoutOf}; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_span::{DUMMY_SP, sym}; use rustc_target::abi::{self, Abi, FIRST_VARIANT, FieldIdx, Primitive, Size, VariantIdx}; @@ -128,10 +128,9 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { } #[instrument(level = "trace", skip(self, tcx, body))] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); let ssa = SsaLocals::new(tcx, body, param_env); // Clone dominators because we need them while mutating the body. let dominators = body.basic_blocks.dominators().clone(); diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index c9f24764cc2a1..143f8f38d767e 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -67,10 +67,10 @@ impl<'tcx> crate::MirPass<'tcx> for Inline { } } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let span = trace_span!("inline", body = %tcx.def_path_str(body.source.def_id())); let _guard = span.enter(); - if inline(tcx, body) { + if inline(tcx, param_env, body) { debug!("running simplify cfg on {:?}", body.source); simplify_cfg(body); deref_finder(tcx, body); @@ -78,7 +78,7 @@ impl<'tcx> crate::MirPass<'tcx> for Inline { } } -fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { +fn inline<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) -> bool { let def_id = body.source.def_id().expect_local(); // Only do inlining into fn bodies. @@ -95,7 +95,6 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { return false; } - let param_env = tcx.param_env_reveal_all_normalized(def_id); let codegen_fn_attrs = tcx.codegen_fn_attrs(def_id); let mut this = Inliner { diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index 11609e7652c52..b2c9b08142a00 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -32,12 +32,8 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let ctx = InstSimplifyContext { - tcx, - local_decls: &body.local_decls, - param_env: tcx.param_env_reveal_all_normalized(body.source.def_id()), - }; + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { + let ctx = InstSimplifyContext { tcx, local_decls: &body.local_decls, param_env }; let preserve_ub_checks = attr::contains_name(tcx.hir().krate_attrs(), sym::rustc_preserve_ub_checks); for block in body.basic_blocks.as_mut() { diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 9b9b0b705bfec..85a3c597969c3 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -46,7 +46,7 @@ use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::*; use rustc_middle::ty::layout::LayoutOf; -use rustc_middle::ty::{self, ScalarInt, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, ScalarInt, TyCtxt}; use rustc_mir_dataflow::lattice::HasBottom; use rustc_mir_dataflow::value_analysis::{Map, PlaceIndex, State, TrackElem}; use rustc_span::DUMMY_SP; @@ -67,7 +67,7 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading { } #[instrument(skip_all level = "debug")] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id(); debug!(?def_id); @@ -77,8 +77,6 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading { return; } - let param_env = tcx.param_env_reveal_all_normalized(def_id); - let arena = &DroplessArena::default(); let mut finder = TOFinder { tcx, diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index 3e263aa406774..a68626aac2d35 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -34,13 +34,11 @@ impl<'tcx> crate::MirPass<'tcx> for EnumSizeOpt { sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // NOTE: This pass may produce different MIR based on the alignment of the target // platform, but it will still be valid. let mut alloc_cache = FxHashMap::default(); - let body_did = body.source.def_id(); - let param_env = tcx.param_env_reveal_all_normalized(body_did); let blocks = body.basic_blocks.as_mut(); let local_decls = &mut body.local_decls; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 084a9e72c3ca4..69c62105151fb 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -294,6 +294,7 @@ fn mir_built(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal> { pm::run_passes( tcx, + tcx.param_env(body.source.def_id()), &mut body, &[ // MIR-level lints. @@ -355,6 +356,7 @@ fn mir_promoted( let promote_pass = promote_consts::PromoteTemps::default(); pm::run_passes( tcx, + tcx.param_env(body.source.def_id()), &mut body, &[&promote_pass, &simplify::SimplifyCfg::PromoteConsts, &coverage::InstrumentCoverage], Some(MirPhase::Analysis(AnalysisPhase::Initial)), @@ -389,7 +391,13 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> { }; let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::Const); - pm::run_passes(tcx, &mut body, &[&ctfe_limit::CtfeLimit], None); + pm::run_passes( + tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), + &mut body, + &[&ctfe_limit::CtfeLimit], + None, + ); body } @@ -488,6 +496,7 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' if check_consts::post_drop_elaboration::checking_enabled(&ConstCx::new(tcx, body)) { pm::run_passes( tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), body, &[ &remove_uninit_drops::RemoveUninitDrops, @@ -518,7 +527,13 @@ fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &deref_separator::Derefer, ]; - pm::run_passes(tcx, body, passes, Some(MirPhase::Analysis(AnalysisPhase::PostCleanup))); + pm::run_passes( + tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), // FIXME: Unused + body, + passes, + Some(MirPhase::Analysis(AnalysisPhase::PostCleanup)), + ); } /// Returns the sequence of passes that lowers analysis to runtime MIR. @@ -545,7 +560,13 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &coroutine::StateTransform, &Lint(known_panics_lint::KnownPanicsLint), ]; - pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial))); + pm::run_passes_no_validate( + tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), + body, + passes, + Some(MirPhase::Runtime(RuntimePhase::Initial)), + ); } /// Returns the sequence of passes that do the initial cleanup of runtime MIR. @@ -556,7 +577,13 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &simplify::SimplifyCfg::PreOptimizations, ]; - pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup))); + pm::run_passes( + tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), // FIXME: Unused + body, + passes, + Some(MirPhase::Runtime(RuntimePhase::PostCleanup)), + ); // Clear this by anticipation. Optimizations and runtime MIR have no reason to look // into this information, which is meant for borrowck diagnostics. @@ -573,6 +600,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // The main optimizations that we do on MIR. pm::run_passes( tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), body, &[ // Add some UB checks before any UB gets optimized away. @@ -673,7 +701,11 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { // Before doing anything, remember which items are being mentioned so that the set of items // visited does not depend on the optimization level. // We do not use `run_passes` for this as that might skip the pass if `injection_phase` is set. - mentioned_items::MentionedItems.run_pass(tcx, &mut body); + mentioned_items::MentionedItems.run_pass( + tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), + &mut body, + ); // If `mir_drops_elaborated_and_const_checked` found that the current body has unsatisfiable // predicates, it will shrink the MIR to a single `unreachable` terminator. @@ -713,6 +745,7 @@ pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> B pm::run_passes( tcx, + ty::ParamEnv::reveal_all(), &mut body, &[ // Validation calls layout::fn_can_unwind to figure out if a function can unwind, which diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index 6d635606687a9..a2131ae2efe79 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -1,7 +1,7 @@ //! Lowers intrinsic calls use rustc_middle::mir::*; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_span::symbol::sym; @@ -10,7 +10,7 @@ use crate::take_array; pub(super) struct LowerIntrinsics; impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let local_decls = &body.local_decls; for block in body.basic_blocks.as_mut() { let terminator = block.terminator.as_mut().unwrap(); diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs index 420661f29c8cf..9e9052558b7dd 100644 --- a/compiler/rustc_mir_transform/src/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; pub(super) struct LowerSliceLenCalls; @@ -12,7 +12,7 @@ impl<'tcx> crate::MirPass<'tcx> for LowerSliceLenCalls { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let language_items = tcx.lang_items(); let Some(slice_len_fn_item_def_id) = language_items.slice_len_fn() else { // there is no lang item to compare to :) diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index ad3126f66a67e..e51226218c768 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -17,9 +17,8 @@ impl<'tcx> crate::MirPass<'tcx> for MatchBranchSimplification { sess.mir_opt_level() >= 1 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id(); - let param_env = tcx.param_env_reveal_all_normalized(def_id); let mut should_cleanup = false; for i in 0..body.basic_blocks.len() { diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs index cf5c5f85a9ff6..eb2e8a07e9048 100644 --- a/compiler/rustc_mir_transform/src/mentioned_items.rs +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -1,7 +1,7 @@ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{self, Location, MentionedItem}; use rustc_middle::ty::adjustment::PointerCoercion; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, TyCtxt}; use rustc_session::Session; use rustc_span::source_map::Spanned; @@ -22,7 +22,7 @@ impl<'tcx> crate::MirPass<'tcx> for MentionedItems { true } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut mir::Body<'tcx>) { let mut visitor = MentionedItemsVisitor { tcx, body, mentioned_items: Vec::new() }; visitor.visit_body(body); body.set_mentioned_items(visitor.mentioned_items); diff --git a/compiler/rustc_mir_transform/src/multiple_return_terminators.rs b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs index b6d6ef5de1da9..c38b9dadadd7e 100644 --- a/compiler/rustc_mir_transform/src/multiple_return_terminators.rs +++ b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs @@ -3,7 +3,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use crate::simplify; @@ -14,7 +14,7 @@ impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators { sess.mir_opt_level() >= 4 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // find basic blocks with no statement and a return terminator let mut bbs_simple_returns = BitSet::new_empty(body.basic_blocks.len()); let def_id = body.source.def_id(); diff --git a/compiler/rustc_mir_transform/src/nrvo.rs b/compiler/rustc_mir_transform/src/nrvo.rs index 98fa149e2bc71..f3b0118003ac0 100644 --- a/compiler/rustc_mir_transform/src/nrvo.rs +++ b/compiler/rustc_mir_transform/src/nrvo.rs @@ -5,7 +5,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::bug; use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{self, BasicBlock, Local, Location}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::{debug, trace}; /// This pass looks for MIR that always copies the same local into the return place and eliminates @@ -38,7 +38,7 @@ impl<'tcx> crate::MirPass<'tcx> for RenameReturnPlace { sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut mir::Body<'tcx>) { let def_id = body.source.def_id(); let Some(returned_local) = local_eligible_for_nrvo(body) else { debug!("`{:?}` was ineligible for NRVO", def_id); diff --git a/compiler/rustc_mir_transform/src/pass_manager.rs b/compiler/rustc_mir_transform/src/pass_manager.rs index 309bf27fdd28f..b603b30f20398 100644 --- a/compiler/rustc_mir_transform/src/pass_manager.rs +++ b/compiler/rustc_mir_transform/src/pass_manager.rs @@ -3,7 +3,7 @@ use std::collections::hash_map::Entry; use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase}; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_session::Session; use tracing::trace; @@ -78,7 +78,7 @@ pub(super) trait MirPass<'tcx> { true } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>); + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>); fn is_mir_dump_enabled(&self) -> bool { true @@ -120,7 +120,7 @@ where self.0.is_enabled(sess) } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { self.0.run_lint(tcx, body) } @@ -143,8 +143,8 @@ where sess.mir_opt_level() >= self.0 as usize } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - self.1.run_pass(tcx, body) + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { + self.1.run_pass(tcx, param_env, body) } } @@ -152,21 +152,23 @@ where /// validated at the end. pub(super) fn run_passes_no_validate<'tcx>( tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>], phase_change: Option, ) { - run_passes_inner(tcx, body, passes, phase_change, false); + run_passes_inner(tcx, param_env, body, passes, phase_change, false); } /// The optional `phase_change` is applied after executing all the passes, if present pub(super) fn run_passes<'tcx>( tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>], phase_change: Option, ) { - run_passes_inner(tcx, body, passes, phase_change, true); + run_passes_inner(tcx, param_env, body, passes, phase_change, true); } pub(super) fn should_run_pass<'tcx, P>(tcx: TyCtxt<'tcx>, pass: &P) -> bool @@ -190,6 +192,7 @@ where fn run_passes_inner<'tcx>( tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>], phase_change: Option, @@ -221,16 +224,16 @@ fn run_passes_inner<'tcx>( tcx.sess .prof .generic_activity_with_arg(pass.profiler_name(), &**prof_arg) - .run(|| pass.run_pass(tcx, body)); + .run(|| pass.run_pass(tcx, param_env, body)); } else { - pass.run_pass(tcx, body); + pass.run_pass(tcx, param_env, body); } if dump_enabled { dump_mir_for_pass(tcx, body, name, true); } if validate { - validate_body(tcx, body, format!("after pass {name}")); + validate_body(tcx, param_env, body, format!("after pass {name}")); } if lint { lint_body(tcx, body, format!("after pass {name}")); @@ -258,7 +261,12 @@ fn run_passes_inner<'tcx>( ); let lint = tcx.sess.opts.unstable_opts.lint_mir & !body.should_skip(); if validate { - validate_body(tcx, body, format!("after phase change to {}", new_phase.name())); + validate_body( + tcx, + param_env, + body, + format!("after phase change to {}", new_phase.name()), + ); } if lint { lint_body(tcx, body, format!("after phase change to {}", new_phase.name())); @@ -268,8 +276,13 @@ fn run_passes_inner<'tcx>( } } -fn validate_body<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, when: String) { - validate::Validator { when, mir_phase: body.phase }.run_pass(tcx, body); +fn validate_body<'tcx>( + tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, + body: &mut Body<'tcx>, + when: String, +) { + validate::Validator { when, mir_phase: body.phase }.run_pass(tcx, param_env, body); } fn dump_mir_for_pass<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, pass_name: &str, is_after: bool) { diff --git a/compiler/rustc_mir_transform/src/prettify.rs b/compiler/rustc_mir_transform/src/prettify.rs index 937c207776b35..f6295d9a4c8b1 100644 --- a/compiler/rustc_mir_transform/src/prettify.rs +++ b/compiler/rustc_mir_transform/src/prettify.rs @@ -8,7 +8,7 @@ use rustc_index::bit_set::BitSet; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_session::Session; /// Rearranges the basic blocks into a *reverse post-order*. @@ -22,7 +22,7 @@ impl<'tcx> crate::MirPass<'tcx> for ReorderBasicBlocks { false } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let rpo: IndexVec = body.basic_blocks.reverse_postorder().iter().copied().collect(); if rpo.iter().is_sorted() { @@ -50,7 +50,7 @@ impl<'tcx> crate::MirPass<'tcx> for ReorderLocals { false } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let mut finder = LocalFinder { map: IndexVec::new(), seen: BitSet::new_empty(body.local_decls.len()) }; diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 86c4b241a2b4d..ef95799e188f1 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -21,7 +21,7 @@ use rustc_hir as hir; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::{self, GenericArgs, List, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, GenericArgs, List, ParamEnv, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, mir, span_bug}; use rustc_span::Span; use rustc_span::source_map::Spanned; @@ -40,8 +40,9 @@ pub(super) struct PromoteTemps<'tcx> { pub promoted_fragments: Cell>>, } +// FIXME: We get a ParamEnv from somewhere... we should use the passed-in one. impl<'tcx> crate::MirPass<'tcx> for PromoteTemps<'tcx> { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // There's not really any point in promoting errorful MIR. // // This does not include MIR that failed const-checking, which we still try to promote. diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index 53e53d9d5ba8b..30818344bef54 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -6,7 +6,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::bug; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::impls::MaybeStorageDead; use rustc_mir_dataflow::storage::always_storage_live_locals; @@ -78,14 +78,17 @@ impl<'tcx> crate::MirPass<'tcx> for ReferencePropagation { } #[instrument(level = "trace", skip(self, tcx, body))] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); - while propagate_ssa(tcx, body) {} + while propagate_ssa(tcx, param_env, body) {} } } -fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); +fn propagate_ssa<'tcx>( + tcx: TyCtxt<'tcx>, + param_env: ParamEnv<'tcx>, + body: &mut Body<'tcx>, +) -> bool { let ssa = SsaLocals::new(tcx, body, param_env); let mut replacer = compute_replacement(tcx, body, &ssa); diff --git a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs index 55394e93a5cb7..e850343a14d29 100644 --- a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -1,7 +1,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_target::spec::PanicStrategy; use tracing::debug; @@ -15,7 +15,7 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveNoopLandingPads { sess.panic_strategy() != PanicStrategy::Abort } - fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let def_id = body.source.def_id(); debug!(?def_id); diff --git a/compiler/rustc_mir_transform/src/remove_place_mention.rs b/compiler/rustc_mir_transform/src/remove_place_mention.rs index 71399eb72f004..6d92ecba85883 100644 --- a/compiler/rustc_mir_transform/src/remove_place_mention.rs +++ b/compiler/rustc_mir_transform/src/remove_place_mention.rs @@ -1,7 +1,7 @@ //! This pass removes `PlaceMention` statement, which has no effect at codegen. use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::trace; pub(super) struct RemovePlaceMention; @@ -11,7 +11,7 @@ impl<'tcx> crate::MirPass<'tcx> for RemovePlaceMention { !sess.opts.unstable_opts.mir_keep_place_mention } - fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("Running RemovePlaceMention on {:?}", body.source); for data in body.basic_blocks.as_mut_preserves_cfg() { data.statements.retain(|statement| match statement.kind { diff --git a/compiler/rustc_mir_transform/src/remove_storage_markers.rs b/compiler/rustc_mir_transform/src/remove_storage_markers.rs index 3ecb4a8994f5f..c575632f2a47a 100644 --- a/compiler/rustc_mir_transform/src/remove_storage_markers.rs +++ b/compiler/rustc_mir_transform/src/remove_storage_markers.rs @@ -1,7 +1,7 @@ //! This pass removes storage markers if they won't be emitted during codegen. use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::trace; pub(super) struct RemoveStorageMarkers; @@ -11,7 +11,7 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveStorageMarkers { sess.mir_opt_level() > 0 && !sess.emit_lifetime_markers() } - fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("Running RemoveStorageMarkers on {:?}", body.source); for data in body.basic_blocks.as_mut_preserves_cfg() { data.statements.retain(|statement| match statement.kind { diff --git a/compiler/rustc_mir_transform/src/remove_uninit_drops.rs b/compiler/rustc_mir_transform/src/remove_uninit_drops.rs index 09969a4c7cc7f..8ea7962d79564 100644 --- a/compiler/rustc_mir_transform/src/remove_uninit_drops.rs +++ b/compiler/rustc_mir_transform/src/remove_uninit_drops.rs @@ -17,8 +17,7 @@ use rustc_target::abi::FieldIdx; pub(super) struct RemoveUninitDrops; impl<'tcx> crate::MirPass<'tcx> for RemoveUninitDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let param_env = tcx.param_env(body.source.def_id()); + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let move_data = MoveData::gather_moves(body, tcx, |ty| ty.needs_drop(tcx, param_env)); let mut maybe_inits = MaybeInitializedPlaces::new(tcx, body, &move_data) diff --git a/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs index 28925ba1beb13..ac1fd6071a93e 100644 --- a/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs +++ b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs @@ -5,7 +5,7 @@ //! `Reveal::All` to provide more precise type information. use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::{debug, trace}; use super::simplify::simplify_cfg; @@ -13,11 +13,10 @@ use super::simplify::simplify_cfg; pub(super) struct RemoveUnneededDrops; impl<'tcx> crate::MirPass<'tcx> for RemoveUnneededDrops { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("Running RemoveUnneededDrops on {:?}", body.source); let did = body.source.def_id(); - let param_env = tcx.param_env_reveal_all_normalized(did); let mut should_simplify = false; for block in body.basic_blocks.as_mut() { diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs index f13bb1c5993d5..3fa34c2eee72d 100644 --- a/compiler/rustc_mir_transform/src/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -2,7 +2,7 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; pub(super) struct RemoveZsts; @@ -11,7 +11,7 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveZsts { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // Avoid query cycles (coroutines require optimized MIR for layout). if tcx.type_of(body.source.def_id()).instantiate_identity().is_coroutine() { return; @@ -21,7 +21,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveZsts { return; } - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); let local_decls = &body.local_decls; let mut replacer = Replacer { tcx, param_env, local_decls }; for var_debug_info in &mut body.var_debug_info { diff --git a/compiler/rustc_mir_transform/src/reveal_all.rs b/compiler/rustc_mir_transform/src/reveal_all.rs index f3b2f78b31c3a..0743b32073b0f 100644 --- a/compiler/rustc_mir_transform/src/reveal_all.rs +++ b/compiler/rustc_mir_transform/src/reveal_all.rs @@ -2,13 +2,12 @@ use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; pub(super) struct RevealAll; impl<'tcx> crate::MirPass<'tcx> for RevealAll { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { RevealAllVisitor { tcx, param_env }.visit_body_preserves_cfg(body); } } diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index e872878a751ed..938b6c94b9099 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -112,6 +112,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body< pm::run_passes( tcx, + tcx.param_env_reveal_all_normalized(body.source.def_id()), &mut body, &[ &mentioned_items::MentionedItems, @@ -147,6 +148,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body< // This causes validation errors when TAITs are involved. pm::run_passes_no_validate( tcx, + tcx.param_env_reveal_all_normalized(instance.def_id()), &mut result, &[ &mentioned_items::MentionedItems, diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index 451eb008536cf..bd95991d633f4 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -30,7 +30,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_span::DUMMY_SP; use smallvec::SmallVec; use tracing::{debug, trace}; @@ -81,7 +81,7 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyCfg { self.name() } - fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, _tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!("SimplifyCfg({:?}) - simplifying {:?}", self.name(), body.source); simplify_cfg(body); } @@ -381,7 +381,7 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyLocals { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("running SimplifyLocals on {:?}", body.source); // First, we're going to get a count of *actual* uses for every `Local`. diff --git a/compiler/rustc_mir_transform/src/simplify_branches.rs b/compiler/rustc_mir_transform/src/simplify_branches.rs index 4e0f87760490b..b63716e930a73 100644 --- a/compiler/rustc_mir_transform/src/simplify_branches.rs +++ b/compiler/rustc_mir_transform/src/simplify_branches.rs @@ -1,5 +1,5 @@ use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; use tracing::trace; pub(super) enum SimplifyConstCondition { @@ -18,9 +18,8 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyConstCondition { } } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("Running SimplifyConstCondition on {:?}", body.source); - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); 'blocks: for block in body.basic_blocks_mut() { for stmt in block.statements.iter_mut() { // Simplify `assume` of a known value: either a NOP or unreachable. diff --git a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs index 26496b7f3fe19..7d96e90fbe227 100644 --- a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs +++ b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs @@ -6,7 +6,7 @@ use rustc_middle::mir::{ BasicBlock, BinOp, Body, Operand, Place, Rvalue, Statement, StatementKind, SwitchTargets, TerminatorKind, }; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use tracing::trace; /// Pass to convert `if` conditions on integrals into switches on the integral. @@ -30,14 +30,13 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("Running SimplifyComparisonIntegral on {:?}", body.source); let helper = OptimizationFinder { body }; let opts = helper.find_optimizations(); let mut storage_deads_to_insert = vec![]; let mut storage_deads_to_remove: Vec<(usize, BasicBlock)> = vec![]; - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); for opt in opts { trace!("SUCCESS: Applying {:?}", opt); // replace terminator with a switchInt that switches on the integer directly diff --git a/compiler/rustc_mir_transform/src/single_use_consts.rs b/compiler/rustc_mir_transform/src/single_use_consts.rs index 277a33c031152..b0f50e020052f 100644 --- a/compiler/rustc_mir_transform/src/single_use_consts.rs +++ b/compiler/rustc_mir_transform/src/single_use_consts.rs @@ -3,7 +3,7 @@ use rustc_index::bit_set::BitSet; use rustc_middle::bug; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::TyCtxt; +use rustc_middle::ty::{ParamEnv, TyCtxt}; /// Various parts of MIR building introduce temporaries that are commonly not needed. /// @@ -26,7 +26,7 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let mut finder = SingleUseConstsFinder { ineligible_locals: BitSet::new_empty(body.local_decls.len()), locations: IndexVec::from_elem(LocationPair::new(), &body.local_decls), diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index 2de0059bc7fd7..b6c4ba63934b6 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -6,7 +6,7 @@ use rustc_middle::bug; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; use rustc_mir_dataflow::value_analysis::{excluded_locals, iter_fields}; use rustc_target::abi::{FIRST_VARIANT, FieldIdx}; use tracing::{debug, instrument}; @@ -19,7 +19,7 @@ impl<'tcx> crate::MirPass<'tcx> for ScalarReplacementOfAggregates { } #[instrument(level = "debug", skip(self, tcx, body))] - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { debug!(def_id = ?body.source.def_id()); // Avoid query cycles (coroutines require optimized MIR for layout). @@ -28,7 +28,6 @@ impl<'tcx> crate::MirPass<'tcx> for ScalarReplacementOfAggregates { } let mut excluded = excluded_locals(body); - let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id()); loop { debug!(?excluded); let escaping = escaping_locals(tcx, param_env, &excluded, body); diff --git a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs index 5612e779d6bca..7403986d71599 100644 --- a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs +++ b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs @@ -8,7 +8,7 @@ use rustc_middle::mir::{ TerminatorKind, }; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; use rustc_target::abi::{Abi, Variants}; use tracing::trace; @@ -77,7 +77,7 @@ impl<'tcx> crate::MirPass<'tcx> for UnreachableEnumBranching { sess.mir_opt_level() > 0 } - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { trace!("UnreachableEnumBranching starting for {:?}", body.source); let mut unreachable_targets = Vec::new(); @@ -92,9 +92,7 @@ impl<'tcx> crate::MirPass<'tcx> for UnreachableEnumBranching { let Some(discriminant_ty) = get_switched_on_type(bb_data, tcx, body) else { continue }; - let layout = tcx.layout_of( - tcx.param_env_reveal_all_normalized(body.source.def_id()).and(discriminant_ty), - ); + let layout = tcx.layout_of(param_env.and(discriminant_ty)); let mut allowed_variants = if let Ok(layout) = layout { // Find allowed variants based on uninhabited. diff --git a/compiler/rustc_mir_transform/src/unreachable_prop.rs b/compiler/rustc_mir_transform/src/unreachable_prop.rs index f3dafd13824f3..ae3c9dfbf8da5 100644 --- a/compiler/rustc_mir_transform/src/unreachable_prop.rs +++ b/compiler/rustc_mir_transform/src/unreachable_prop.rs @@ -7,18 +7,18 @@ use rustc_middle::bug; use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::patch::MirPatch; use rustc_middle::mir::*; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, TyCtxt}; use rustc_target::abi::Size; pub(super) struct UnreachablePropagation; -impl crate::MirPass<'_> for UnreachablePropagation { +impl<'tcx> crate::MirPass<'tcx> for UnreachablePropagation { fn is_enabled(&self, sess: &rustc_session::Session) -> bool { // Enable only under -Zmir-opt-level=2 as this can make programs less debuggable. sess.mir_opt_level() >= 2 } - fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { let mut patch = MirPatch::new(body); let mut unreachable_blocks = FxHashSet::default(); diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 49e5ad7fbefa6..603cec8fc2f35 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -40,7 +40,7 @@ pub(super) struct Validator { } impl<'tcx> crate::MirPass<'tcx> for Validator { - fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + fn run_pass(&self, tcx: TyCtxt<'tcx>, _param_env: ParamEnv<'tcx>, body: &mut Body<'tcx>) { // FIXME(JakobDegen): These bodies never instantiated in codegend anyway, so it's not // terribly important that they pass the validator. However, I think other passes might // still see them, in which case they might be surprised. It would probably be better if we