diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index e5a28d1b66c8c..afdee88a1a966 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -49,8 +49,8 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b } impl<'tcx> crate::MirPass<'tcx> for AddRetag { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.opts.unstable_opts.mir_emit_retag + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.opts.unstable_opts.mir_emit_retag } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index 8f88613b79f35..4abe24489b759 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -4,15 +4,14 @@ use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::visit::PlaceContext; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; -use rustc_session::Session; use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers}; pub(super) struct CheckAlignment; impl<'tcx> crate::MirPass<'tcx> for CheckAlignment { - fn is_enabled(&self, sess: &Session) -> bool { - sess.ub_checks() + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.ub_checks() } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/check_null.rs b/compiler/rustc_mir_transform/src/check_null.rs index ad74e335bd9eb..f473f53bc3d06 100644 --- a/compiler/rustc_mir_transform/src/check_null.rs +++ b/compiler/rustc_mir_transform/src/check_null.rs @@ -2,15 +2,14 @@ use rustc_index::IndexVec; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext}; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; -use rustc_session::Session; use crate::check_pointers::{BorrowedFieldProjectionMode, PointerCheck, check_pointers}; pub(super) struct CheckNull; impl<'tcx> crate::MirPass<'tcx> for CheckNull { - fn is_enabled(&self, sess: &Session) -> bool { - sess.ub_checks() + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.ub_checks() } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index 27af5818982d0..c8ebfe250874f 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -5,7 +5,8 @@ use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; use tracing::{debug, instrument}; -use crate::ssa::SsaLocals; +use crate::pass_manager as pm; +use crate::ssa::{SsaAnalysis, SsaLocals}; /// Unify locals that copy each other. /// @@ -17,11 +18,27 @@ use crate::ssa::SsaLocals; /// where each of the locals is only assigned once. /// /// We want to replace all those locals by `_a`, either copied or moved. -pub(super) struct CopyProp; +pub(super) enum CopyProp { + Partial, + Full, +} impl<'tcx> crate::MirPass<'tcx> for CopyProp { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 1 + fn name(&self) -> &'static str { + match self { + CopyProp::Partial => "CopyProp-partial", + CopyProp::Full => "CopyProp", + } + } + + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + match self { + CopyProp::Partial => { + tcx.sess.mir_opt_level() == 1 + && !pm::should_run_pass(tcx, &CopyProp::Full, pm::Optimizations::Allowed) + } + CopyProp::Full => tcx.sess.mir_opt_level() >= 2, + } } #[instrument(level = "trace", skip(self, tcx, body))] @@ -29,7 +46,11 @@ impl<'tcx> crate::MirPass<'tcx> for CopyProp { debug!(def_id = ?body.source.def_id()); let typing_env = body.typing_env(tcx); - let ssa = SsaLocals::new(tcx, body, typing_env); + let ssa_analysis = match self { + CopyProp::Partial => SsaAnalysis::Partial, + CopyProp::Full => SsaAnalysis::Full, + }; + let ssa = SsaLocals::new(tcx, body, typing_env, ssa_analysis); let fully_moved = fully_moved_locals(&ssa, body); debug!(?fully_moved); diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index f2e8f9e1bcd66..b9d5d1620d14f 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -29,8 +29,8 @@ use crate::coverage::mappings::ExtractedMappings; pub(super) struct InstrumentCoverage; impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.instrument_coverage() + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.instrument_coverage() } fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index a2103a004d2d1..e7d516fb46b3f 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -35,8 +35,8 @@ const PLACE_LIMIT: usize = 100; pub(super) struct DataflowConstProp; impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 3 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 3 } #[instrument(skip_all level = "debug")] diff --git a/compiler/rustc_mir_transform/src/dead_store_elimination.rs b/compiler/rustc_mir_transform/src/dead_store_elimination.rs index eea2b0990d730..2736049bd8c68 100644 --- a/compiler/rustc_mir_transform/src/dead_store_elimination.rs +++ b/compiler/rustc_mir_transform/src/dead_store_elimination.rs @@ -140,8 +140,8 @@ impl<'tcx> crate::MirPass<'tcx> for DeadStoreElimination { } } - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 2 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index 7395ad496dbdf..b7d6da7df6773 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -149,7 +149,7 @@ use tracing::{debug, trace}; pub(super) struct DestinationPropagation; impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { // For now, only run at MIR opt level 3. Two things need to be changed before this can be // turned on by default: // 1. Because of the overeager removal of storage statements, this can cause stack space @@ -158,7 +158,7 @@ impl<'tcx> crate::MirPass<'tcx> for DestinationPropagation { // 2. Despite being an overall perf improvement, this still causes a 30% regression in // keccak. We can temporarily fix this by bounding function size, but in the long term // we should fix this by being smarter about invalidating analysis results. - sess.mir_opt_level() >= 3 + tcx.sess.mir_opt_level() >= 3 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs index c7feb9e949b4d..93d229a4029e4 100644 --- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs +++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs @@ -93,8 +93,8 @@ use crate::patch::MirPatch; pub(super) struct EarlyOtherwiseBranch; impl<'tcx> crate::MirPass<'tcx> for EarlyOtherwiseBranch { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 2 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 8b8d1efbbd2e0..93ea03317f23a 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -109,13 +109,30 @@ use rustc_span::def_id::DefId; use smallvec::SmallVec; use tracing::{debug, instrument, trace}; -use crate::ssa::SsaLocals; +use crate::pass_manager as pm; +use crate::ssa::{SsaAnalysis, SsaLocals}; -pub(super) struct GVN; +pub(super) enum GVN { + Partial, + Full, +} impl<'tcx> crate::MirPass<'tcx> for GVN { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + fn name(&self) -> &'static str { + match self { + GVN::Partial => "GVN-partial", + GVN::Full => "GVN", + } + } + + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + match self { + GVN::Partial => { + tcx.sess.mir_opt_level() == 1 + && !pm::should_run_pass(tcx, &GVN::Full, pm::Optimizations::Allowed) + } + GVN::Full => tcx.sess.mir_opt_level() >= 2, + } } #[instrument(level = "trace", skip(self, tcx, body))] @@ -123,7 +140,11 @@ impl<'tcx> crate::MirPass<'tcx> for GVN { debug!(def_id = ?body.source.def_id()); let typing_env = body.typing_env(tcx); - let ssa = SsaLocals::new(tcx, body, typing_env); + let ssa_analysis = match self { + GVN::Partial => SsaAnalysis::Partial, + GVN::Full => SsaAnalysis::Full, + }; + let ssa = SsaLocals::new(tcx, body, typing_env, ssa_analysis); // 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 9785c039d539b..258488d62e703 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -43,16 +43,17 @@ struct CallSite<'tcx> { pub struct Inline; impl<'tcx> crate::MirPass<'tcx> for Inline { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - if let Some(enabled) = sess.opts.unstable_opts.inline_mir { + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + let opts = &tcx.sess.opts; + if let Some(enabled) = opts.unstable_opts.inline_mir { return enabled; } - match sess.mir_opt_level() { + match tcx.sess.mir_opt_level() { 0 | 1 => false, 2 => { - (sess.opts.optimize == OptLevel::More || sess.opts.optimize == OptLevel::Aggressive) - && sess.opts.incremental == None + (opts.optimize == OptLevel::More || opts.optimize == OptLevel::Aggressive) + && opts.incremental == None } _ => true, } @@ -82,7 +83,7 @@ impl ForceInline { } impl<'tcx> crate::MirPass<'tcx> for ForceInline { - fn is_enabled(&self, _: &rustc_session::Session) -> bool { + fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool { true } diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index 5f0c55ddc092d..1eb416486d2e5 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -24,8 +24,8 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify { } } - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index ada2c0b76cf70..ad766373c1314 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -61,8 +61,8 @@ const MAX_COST: usize = 100; const MAX_PLACES: usize = 100; impl<'tcx> crate::MirPass<'tcx> for JumpThreading { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 2 } #[instrument(skip_all level = "debug")] diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index 47cb478fe33ee..3cf606bb7072c 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -4,7 +4,6 @@ use rustc_middle::mir::interpret::AllocId; use rustc_middle::mir::*; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; -use rustc_session::Session; use crate::patch::MirPatch; @@ -29,11 +28,11 @@ pub(super) struct EnumSizeOpt { } impl<'tcx> crate::MirPass<'tcx> for EnumSizeOpt { - fn is_enabled(&self, sess: &Session) -> bool { + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { // There are some differences in behavior on wasm and ARM that are not properly // understood, so we conservatively treat this optimization as unsound: // https://github.com/rust-lang/rust/pull/85158#issuecomment-1101836457 - sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3 + tcx.sess.opts.unstable_opts.unsound_mir_opts || tcx.sess.mir_opt_level() >= 3 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 24f4c11a66d69..675325a973c33 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -129,7 +129,10 @@ declare_passes! { // This pass is public to allow external drivers to perform MIR cleanup pub mod cleanup_post_borrowck : CleanupPostBorrowck; - mod copy_prop : CopyProp; + mod copy_prop : CopyProp { + Partial, + Full + }; mod coroutine : StateTransform; mod coverage : InstrumentCoverage; mod ctfe_limit : CtfeLimit; @@ -145,7 +148,10 @@ declare_passes! { mod elaborate_box_derefs : ElaborateBoxDerefs; mod elaborate_drops : ElaborateDrops; mod function_item_references : FunctionItemReferences; - mod gvn : GVN; + mod gvn : GVN { + Partial, + Full + }; // Made public so that `mir_drops_elaborated_and_const_checked` can be overridden // by custom rustc drivers, running all the steps by themselves. See #114628. pub mod inline : Inline, ForceInline; @@ -709,7 +715,8 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &instsimplify::InstSimplify::AfterSimplifyCfg, &simplify::SimplifyLocals::BeforeConstProp, &dead_store_elimination::DeadStoreElimination::Initial, - &gvn::GVN, + &gvn::GVN::Full, + &gvn::GVN::Partial, &simplify::SimplifyLocals::AfterGVN, &dataflow_const_prop::DataflowConstProp, &single_use_consts::SingleUseConsts, @@ -723,7 +730,8 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &o1(simplify::SimplifyCfg::Final), // After the last SimplifyCfg, because this wants one-block functions. &strip_debuginfo::StripDebugInfo, - ©_prop::CopyProp, + ©_prop::CopyProp::Full, + ©_prop::CopyProp::Partial, &dead_store_elimination::DeadStoreElimination::Final, &nrvo::RenameReturnPlace, &simplify::SimplifyLocals::Final, diff --git a/compiler/rustc_mir_transform/src/lower_slice_len.rs b/compiler/rustc_mir_transform/src/lower_slice_len.rs index aca80e36e339d..634b88ffe9389 100644 --- a/compiler/rustc_mir_transform/src/lower_slice_len.rs +++ b/compiler/rustc_mir_transform/src/lower_slice_len.rs @@ -8,8 +8,8 @@ use rustc_middle::ty::TyCtxt; pub(super) struct LowerSliceLenCalls; impl<'tcx> crate::MirPass<'tcx> for LowerSliceLenCalls { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index b37241185c935..fc9008f48008a 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -13,8 +13,8 @@ use crate::patch::MirPatch; pub(super) struct MatchBranchSimplification; impl<'tcx> crate::MirPass<'tcx> for MatchBranchSimplification { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 1 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 1 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs index 9fd8d81d64a26..913b96318912a 100644 --- a/compiler/rustc_mir_transform/src/mentioned_items.rs +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -2,7 +2,6 @@ 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_session::Session; use rustc_span::source_map::Spanned; pub(super) struct MentionedItems; @@ -14,7 +13,7 @@ struct MentionedItemsVisitor<'a, 'tcx> { } impl<'tcx> crate::MirPass<'tcx> for MentionedItems { - fn is_enabled(&self, _sess: &Session) -> bool { + fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool { // If this pass is skipped the collector assume that nothing got mentioned! We could // potentially skip it in opt-level 0 if we are sure that opt-level will never *remove* uses // of anything, but that still seems fragile. Furthermore, even debug builds use level 1, so diff --git a/compiler/rustc_mir_transform/src/multiple_return_terminators.rs b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs index f59b849e85c62..43ea3dffe5601 100644 --- a/compiler/rustc_mir_transform/src/multiple_return_terminators.rs +++ b/compiler/rustc_mir_transform/src/multiple_return_terminators.rs @@ -10,8 +10,8 @@ use crate::simplify; pub(super) struct MultipleReturnTerminators; impl<'tcx> crate::MirPass<'tcx> for MultipleReturnTerminators { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 4 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 4 } fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/nrvo.rs b/compiler/rustc_mir_transform/src/nrvo.rs index 965002aae04c7..6c0b389dde375 100644 --- a/compiler/rustc_mir_transform/src/nrvo.rs +++ b/compiler/rustc_mir_transform/src/nrvo.rs @@ -33,9 +33,9 @@ use tracing::{debug, trace}; pub(super) struct RenameReturnPlace; impl<'tcx> crate::MirPass<'tcx> for RenameReturnPlace { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { // unsound: #111005 - sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts + tcx.sess.mir_opt_level() > 0 && tcx.sess.opts.unstable_opts.unsound_mir_opts } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/pass_manager.rs b/compiler/rustc_mir_transform/src/pass_manager.rs index 7a8d3ba1ff1fa..f5471065b4e63 100644 --- a/compiler/rustc_mir_transform/src/pass_manager.rs +++ b/compiler/rustc_mir_transform/src/pass_manager.rs @@ -4,7 +4,6 @@ use std::collections::hash_map::Entry; use rustc_data_structures::fx::{FxHashMap, FxIndexSet}; use rustc_middle::mir::{self, Body, MirPhase, RuntimePhase}; use rustc_middle::ty::TyCtxt; -use rustc_session::Session; use tracing::trace; use crate::lint::lint_body; @@ -75,7 +74,7 @@ pub(super) trait MirPass<'tcx> { } /// Returns `true` if this pass is enabled with the current combination of compiler flags. - fn is_enabled(&self, _sess: &Session) -> bool { + fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool { true } @@ -109,7 +108,7 @@ pub(super) trait MirLint<'tcx> { } } - fn is_enabled(&self, _sess: &Session) -> bool { + fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool { true } @@ -128,8 +127,8 @@ where self.0.name() } - fn is_enabled(&self, sess: &Session) -> bool { - self.0.is_enabled(sess) + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + self.0.is_enabled(tcx) } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { @@ -155,8 +154,8 @@ where self.1.name() } - fn is_enabled(&self, sess: &Session) -> bool { - sess.mir_opt_level() >= self.0 as usize + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= self.0 as usize } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { @@ -210,7 +209,7 @@ where let name = pass.name(); if !pass.can_be_overridden() { - return pass.is_enabled(tcx.sess); + return pass.is_enabled(tcx); } let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes; @@ -224,7 +223,7 @@ where *polarity }); let suppressed = !pass.is_required() && matches!(optimizations, Optimizations::Suppressed); - overridden.unwrap_or_else(|| !suppressed && pass.is_enabled(tcx.sess)) + overridden.unwrap_or_else(|| !suppressed && pass.is_enabled(tcx)) } fn run_passes_inner<'tcx>( diff --git a/compiler/rustc_mir_transform/src/prettify.rs b/compiler/rustc_mir_transform/src/prettify.rs index 8ccfbe2f194b4..beb78b3dd8b0c 100644 --- a/compiler/rustc_mir_transform/src/prettify.rs +++ b/compiler/rustc_mir_transform/src/prettify.rs @@ -9,7 +9,6 @@ use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; -use rustc_session::Session; /// Rearranges the basic blocks into a *reverse post-order*. /// @@ -18,7 +17,7 @@ use rustc_session::Session; pub(super) struct ReorderBasicBlocks; impl<'tcx> crate::MirPass<'tcx> for ReorderBasicBlocks { - fn is_enabled(&self, _session: &Session) -> bool { + fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool { false } @@ -50,7 +49,7 @@ impl<'tcx> crate::MirPass<'tcx> for ReorderBasicBlocks { pub(super) struct ReorderLocals; impl<'tcx> crate::MirPass<'tcx> for ReorderLocals { - fn is_enabled(&self, _session: &Session) -> bool { + fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool { false } diff --git a/compiler/rustc_mir_transform/src/ref_prop.rs b/compiler/rustc_mir_transform/src/ref_prop.rs index 368d5340ac34f..3f3d0b441d0c5 100644 --- a/compiler/rustc_mir_transform/src/ref_prop.rs +++ b/compiler/rustc_mir_transform/src/ref_prop.rs @@ -11,7 +11,7 @@ use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::impls::{MaybeStorageDead, always_storage_live_locals}; use tracing::{debug, instrument}; -use crate::ssa::{SsaLocals, StorageLiveLocals}; +use crate::ssa::{SsaAnalysis, SsaLocals, StorageLiveLocals}; /// Propagate references using SSA analysis. /// @@ -72,8 +72,8 @@ use crate::ssa::{SsaLocals, StorageLiveLocals}; pub(super) struct ReferencePropagation; impl<'tcx> crate::MirPass<'tcx> for ReferencePropagation { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 2 } #[instrument(level = "trace", skip(self, tcx, body))] @@ -89,7 +89,7 @@ impl<'tcx> crate::MirPass<'tcx> for ReferencePropagation { fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool { let typing_env = body.typing_env(tcx); - let ssa = SsaLocals::new(tcx, body, typing_env); + let ssa = SsaLocals::new(tcx, body, typing_env, SsaAnalysis::Full); let mut replacer = compute_replacement(tcx, body, &ssa); debug!(?replacer.targets); 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 1dd34005d6641..bef25a4596347 100644 --- a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -12,8 +12,8 @@ use crate::patch::MirPatch; pub(super) struct RemoveNoopLandingPads; impl<'tcx> crate::MirPass<'tcx> for RemoveNoopLandingPads { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.panic_strategy() != PanicStrategy::Abort + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.panic_strategy() != PanicStrategy::Abort } fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/remove_place_mention.rs b/compiler/rustc_mir_transform/src/remove_place_mention.rs index cb598ceb4dfea..6abbc6f5ac3ba 100644 --- a/compiler/rustc_mir_transform/src/remove_place_mention.rs +++ b/compiler/rustc_mir_transform/src/remove_place_mention.rs @@ -7,8 +7,8 @@ use tracing::trace; pub(super) struct RemovePlaceMention; impl<'tcx> crate::MirPass<'tcx> for RemovePlaceMention { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - !sess.opts.unstable_opts.mir_preserve_ub + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + !tcx.sess.opts.unstable_opts.mir_preserve_ub } fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/remove_storage_markers.rs b/compiler/rustc_mir_transform/src/remove_storage_markers.rs index 1ae33c0096875..3690f569a816a 100644 --- a/compiler/rustc_mir_transform/src/remove_storage_markers.rs +++ b/compiler/rustc_mir_transform/src/remove_storage_markers.rs @@ -7,8 +7,8 @@ use tracing::trace; pub(super) struct RemoveStorageMarkers; impl<'tcx> crate::MirPass<'tcx> for RemoveStorageMarkers { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 && !sess.emit_lifetime_markers() + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 && !tcx.sess.emit_lifetime_markers() } fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs index c4dc8638b26ab..4d2d113552966 100644 --- a/compiler/rustc_mir_transform/src/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -7,8 +7,8 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; pub(super) struct RemoveZsts; impl<'tcx> crate::MirPass<'tcx> for RemoveZsts { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index 4f2cce8ac1049..56eb77059856a 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -396,8 +396,8 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyLocals { } } - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs index bd00823073139..f2fba5281dec0 100644 --- a/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs +++ b/compiler/rustc_mir_transform/src/simplify_comparison_integral.rs @@ -26,8 +26,8 @@ use tracing::trace; pub(super) struct SimplifyComparisonIntegral; impl<'tcx> crate::MirPass<'tcx> for SimplifyComparisonIntegral { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/single_use_consts.rs b/compiler/rustc_mir_transform/src/single_use_consts.rs index 02caa92ad3fc8..b564b5244e55e 100644 --- a/compiler/rustc_mir_transform/src/single_use_consts.rs +++ b/compiler/rustc_mir_transform/src/single_use_consts.rs @@ -22,8 +22,8 @@ use rustc_middle::ty::TyCtxt; pub(super) struct SingleUseConsts; impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index 7c6ccc89c4f30..077a33d9c9f3e 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -15,8 +15,8 @@ use crate::patch::MirPatch; pub(super) struct ScalarReplacementOfAggregates; impl<'tcx> crate::MirPass<'tcx> for ScalarReplacementOfAggregates { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() >= 2 } #[instrument(level = "debug", skip(self, tcx, body))] diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index edd0cabca49a4..f412e2976c1b6 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -32,11 +32,17 @@ pub(super) struct SsaLocals { borrowed_locals: DenseBitSet, } +pub(super) enum SsaAnalysis { + Full, + Partial, +} + impl SsaLocals { pub(super) fn new<'tcx>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, typing_env: ty::TypingEnv<'tcx>, + analysis: SsaAnalysis, ) -> SsaLocals { let assignment_order = Vec::with_capacity(body.local_decls.len()); @@ -73,9 +79,15 @@ impl SsaLocals { // borrows, we need to check the types. For raw pointers and mutable borrows, the locals // have already been marked as non-SSA. debug!(?visitor.borrowed_locals); + for local in visitor.borrowed_locals.iter() { - if !body.local_decls[local].ty.is_freeze(tcx, typing_env) { - visitor.assignments[local] = Set1::Many; + match analysis { + SsaAnalysis::Full => { + if !body.local_decls[local].ty.is_freeze(tcx, typing_env) { + visitor.assignments[local] = Set1::Many; + } + } + SsaAnalysis::Partial => visitor.assignments[local] = Set1::Many, } } diff --git a/compiler/rustc_mir_transform/src/strip_debuginfo.rs b/compiler/rustc_mir_transform/src/strip_debuginfo.rs index 9ede8aa79c44a..97659b7a1741d 100644 --- a/compiler/rustc_mir_transform/src/strip_debuginfo.rs +++ b/compiler/rustc_mir_transform/src/strip_debuginfo.rs @@ -9,8 +9,8 @@ use rustc_session::config::MirStripDebugInfo; pub(super) struct StripDebugInfo; impl<'tcx> crate::MirPass<'tcx> for StripDebugInfo { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.opts.unstable_opts.mir_strip_debuginfo != MirStripDebugInfo::None + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.opts.unstable_opts.mir_strip_debuginfo != MirStripDebugInfo::None } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs index 6ccec5b6f2129..d05b6c2d9c0e8 100644 --- a/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs +++ b/compiler/rustc_mir_transform/src/unreachable_enum_branching.rs @@ -78,8 +78,8 @@ fn variant_discriminants<'tcx>( } impl<'tcx> crate::MirPass<'tcx> for UnreachableEnumBranching { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool { + tcx.sess.mir_opt_level() > 0 } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/compiler/rustc_mir_transform/src/unreachable_prop.rs b/compiler/rustc_mir_transform/src/unreachable_prop.rs index 13fb5b3e56f2f..cc763b443040c 100644 --- a/compiler/rustc_mir_transform/src/unreachable_prop.rs +++ b/compiler/rustc_mir_transform/src/unreachable_prop.rs @@ -14,9 +14,9 @@ use crate::patch::MirPatch; pub(super) struct UnreachablePropagation; impl crate::MirPass<'_> for UnreachablePropagation { - fn is_enabled(&self, sess: &rustc_session::Session) -> bool { + fn is_enabled(&self, tcx: TyCtxt<'_>) -> bool { // Enable only under -Zmir-opt-level=2 as this can make programs less debuggable. - sess.mir_opt_level() >= 2 + tcx.sess.mir_opt_level() >= 2 } fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { diff --git a/tests/mir-opt/const_prop/control_flow_simplification.rs b/tests/mir-opt/const_prop/control_flow_simplification.rs index 64605ca11c2cc..91fcf6f2c0feb 100644 --- a/tests/mir-opt/const_prop/control_flow_simplification.rs +++ b/tests/mir-opt/const_prop/control_flow_simplification.rs @@ -1,7 +1,7 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY //@ test-mir-pass: GVN -//@ compile-flags: -Zmir-opt-level=1 +//@ compile-flags: -Zmir-opt-level=1 -Zmir-enable-passes=-CopyProp-partial trait NeedsDrop: Sized { const NEEDS: bool = std::mem::needs_drop::(); diff --git a/tests/mir-opt/simplify_locals_fixedpoint.rs b/tests/mir-opt/simplify_locals_fixedpoint.rs index 0b6c95630c0a7..f98d87a342f73 100644 --- a/tests/mir-opt/simplify_locals_fixedpoint.rs +++ b/tests/mir-opt/simplify_locals_fixedpoint.rs @@ -1,6 +1,6 @@ // skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -//@ compile-flags: -Zmir-opt-level=1 +//@ compile-flags: -Zmir-opt-level=1 -Zmir-enable-passes=-CopyProp-partial,-GVN-partial fn foo() { if let (Some(a), None) = (Option::::None, Option::::None) { diff --git a/tests/run-make/const_fn_mir/dump.mir b/tests/run-make/const_fn_mir/dump.mir index 2b5c684bbef00..6a2d65e277116 100644 --- a/tests/run-make/const_fn_mir/dump.mir +++ b/tests/run-make/const_fn_mir/dump.mir @@ -3,15 +3,9 @@ // HINT: See also -Z dump-mir for MIR at specific points during compilation. fn foo() -> i32 { let mut _0: i32; - let mut _1: (i32, bool); bb0: { - _1 = AddWithOverflow(const 5_i32, const 6_i32); - assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> [success: bb1, unwind continue]; - } - - bb1: { - _0 = move (_1.0: i32); + _0 = const 11_i32; return; } } @@ -31,16 +25,3 @@ fn foo() -> i32 { return; } } - -fn main() -> () { - let mut _0: (); - let _1: i32; - - bb0: { - _1 = foo() -> [return: bb1, unwind continue]; - } - - bb1: { - return; - } -} diff --git a/tests/run-make/const_fn_mir/lib.rs b/tests/run-make/const_fn_mir/lib.rs new file mode 100644 index 0000000000000..e957ce97f7b20 --- /dev/null +++ b/tests/run-make/const_fn_mir/lib.rs @@ -0,0 +1,8 @@ +// emit-mir +//@ check-pass + +#![crate_type = "lib"] + +pub const fn foo() -> i32 { + 5 + 6 +} diff --git a/tests/run-make/const_fn_mir/main.rs b/tests/run-make/const_fn_mir/main.rs deleted file mode 100644 index f3f7dc576dd91..0000000000000 --- a/tests/run-make/const_fn_mir/main.rs +++ /dev/null @@ -1,10 +0,0 @@ -// emit-mir -//@ check-pass - -const fn foo() -> i32 { - 5 + 6 -} - -fn main() { - foo(); -} diff --git a/tests/run-make/const_fn_mir/rmake.rs b/tests/run-make/const_fn_mir/rmake.rs index 0c33b1ce34ef9..70ad9fbfaee5b 100644 --- a/tests/run-make/const_fn_mir/rmake.rs +++ b/tests/run-make/const_fn_mir/rmake.rs @@ -1,10 +1,9 @@ -// The `needs-unwind -Cpanic=abort` gives a different MIR output. - -//@ needs-unwind +//! This test is supposed to check that --emit=mir emits both optimized_mir and mir_for_ctfe for a +//! const fn. use run_make_support::{diff, rustc}; fn main() { - rustc().input("main.rs").emit("mir").output("dump-actual.mir").run(); + rustc().input("lib.rs").emit("mir").output("dump-actual.mir").run(); diff().expected_file("dump.mir").actual_file("dump-actual.mir").run(); } diff --git a/tests/ui-fulldeps/stable-mir/check_allocation.rs b/tests/ui-fulldeps/stable-mir/check_allocation.rs index 692c24f054451..635a6ec8b68a7 100644 --- a/tests/ui-fulldeps/stable-mir/check_allocation.rs +++ b/tests/ui-fulldeps/stable-mir/check_allocation.rs @@ -221,6 +221,7 @@ fn main() { generate_input(&path).unwrap(); let args = &[ "rustc".to_string(), + "-Zmir-enable-passes=-GVN-partial".to_string(), "--edition=2021".to_string(), "--crate-name".to_string(), CRATE_NAME.to_string(), diff --git a/tests/ui-fulldeps/stable-mir/projections.rs b/tests/ui-fulldeps/stable-mir/projections.rs index 103c97bc48e17..e16e8debedd5a 100644 --- a/tests/ui-fulldeps/stable-mir/projections.rs +++ b/tests/ui-fulldeps/stable-mir/projections.rs @@ -148,6 +148,7 @@ fn main() { generate_input(&path).unwrap(); let args = &[ "rustc".to_string(), + "-Zmir-enable-passes=-GVN-partial".to_string(), "--crate-type=lib".to_string(), "--crate-name".to_string(), CRATE_NAME.to_string(), diff --git a/tests/ui/async-await/future-sizes/large-arg.stdout b/tests/ui/async-await/future-sizes/large-arg.stdout index 67168a3d6ef74..27c87bdcfc91d 100644 --- a/tests/ui/async-await/future-sizes/large-arg.stdout +++ b/tests/ui/async-await/future-sizes/large-arg.stdout @@ -58,3 +58,8 @@ print-type-size variant `Returned`: 1024 bytes print-type-size upvar `.t`: 1024 bytes print-type-size variant `Panicked`: 1024 bytes print-type-size upvar `.t`: 1024 bytes +print-type-size type: `std::task::Poll<()>`: 1 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Ready`: 0 bytes +print-type-size field `.0`: 0 bytes +print-type-size variant `Pending`: 0 bytes diff --git a/tests/ui/consts/const-eval/issue-50814.stderr b/tests/ui/consts/const-eval/issue-50814.stderr index 5b23c48e450de..59162138d30c0 100644 --- a/tests/ui/consts/const-eval/issue-50814.stderr +++ b/tests/ui/consts/const-eval/issue-50814.stderr @@ -10,6 +10,14 @@ note: erroneous constant encountered LL | &Sum::::MAX | ^^^^^^^^^^^^^^^^^^ +note: erroneous constant encountered + --> $DIR/issue-50814.rs:22:6 + | +LL | &Sum::::MAX + | ^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0080]: evaluation of ` as Unsigned>::MAX` failed --> $DIR/issue-50814.rs:16:21 | diff --git a/tests/ui/consts/mono-reachable-invalid-const.rs b/tests/ui/consts/mono-reachable-invalid-const.rs index aabdb071bc9fb..353c0046fe179 100644 --- a/tests/ui/consts/mono-reachable-invalid-const.rs +++ b/tests/ui/consts/mono-reachable-invalid-const.rs @@ -6,6 +6,7 @@ impl Bar { const ASSERT: bool = { let b = std::convert::identity(1); ["oops"][b]; //~ ERROR evaluation of `Bar::<0>::ASSERT` failed + //~^ ERROR evaluation of `Bar::::ASSERT` failed true }; diff --git a/tests/ui/consts/mono-reachable-invalid-const.stderr b/tests/ui/consts/mono-reachable-invalid-const.stderr index 6b7b25b59b821..9a7256498d87e 100644 --- a/tests/ui/consts/mono-reachable-invalid-const.stderr +++ b/tests/ui/consts/mono-reachable-invalid-const.stderr @@ -1,3 +1,23 @@ +error[E0080]: evaluation of `Bar::::ASSERT` failed + --> $DIR/mono-reachable-invalid-const.rs:8:9 + | +LL | ["oops"][b]; + | ^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1 + +note: erroneous constant encountered + --> $DIR/mono-reachable-invalid-const.rs:8:9 + | +LL | ["oops"][b]; + | ^^^^^^^^^^^ + +note: erroneous constant encountered + --> $DIR/mono-reachable-invalid-const.rs:8:9 + | +LL | ["oops"][b]; + | ^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0080]: evaluation of `Bar::<0>::ASSERT` failed --> $DIR/mono-reachable-invalid-const.rs:8:9 | @@ -5,13 +25,13 @@ LL | ["oops"][b]; | ^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1 note: erroneous constant encountered - --> $DIR/mono-reachable-invalid-const.rs:13:19 + --> $DIR/mono-reachable-invalid-const.rs:14:19 | LL | let val = Self::ASSERT; | ^^^^^^^^^^^^ note: erroneous constant encountered - --> $DIR/mono-reachable-invalid-const.rs:13:19 + --> $DIR/mono-reachable-invalid-const.rs:14:19 | LL | let val = Self::ASSERT; | ^^^^^^^^^^^^ @@ -19,11 +39,11 @@ LL | let val = Self::ASSERT; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` note: the above error was encountered while instantiating `fn Bar::<0>::assert` - --> $DIR/mono-reachable-invalid-const.rs:22:5 + --> $DIR/mono-reachable-invalid-const.rs:23:5 | LL | Bar::<0>::assert(); | ^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-promoted-const.noopt.stderr b/tests/ui/consts/required-consts/collect-in-promoted-const.noopt.stderr index c5f3b0009f541..6f36aaf314da2 100644 --- a/tests/ui/consts/required-consts/collect-in-promoted-const.noopt.stderr +++ b/tests/ui/consts/required-consts/collect-in-promoted-const.noopt.stderr @@ -1,3 +1,15 @@ +error[E0080]: evaluation of `Fail::::C` failed + --> $DIR/collect-in-promoted-const.rs:9:19 + | +LL | const C: () = panic!(); + | ^^^^^^^^ evaluation panicked: explicit panic + +note: erroneous constant encountered + --> $DIR/collect-in-promoted-const.rs:20:21 + | +LL | let _val = &Fail::::C; + | ^^^^^^^^^^^^ + error[E0080]: evaluation of `Fail::::C` failed --> $DIR/collect-in-promoted-const.rs:9:19 | @@ -9,6 +21,8 @@ note: erroneous constant encountered | LL | let _val = &Fail::::C; | ^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` note: the above error was encountered while instantiating `fn f::` --> $DIR/collect-in-promoted-const.rs:25:5 @@ -16,6 +30,6 @@ note: the above error was encountered while instantiating `fn f::` LL | f::(); | ^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/required-consts/collect-in-promoted-const.rs b/tests/ui/consts/required-consts/collect-in-promoted-const.rs index 4a3ce92e8f90d..f51cfd442d93e 100644 --- a/tests/ui/consts/required-consts/collect-in-promoted-const.rs +++ b/tests/ui/consts/required-consts/collect-in-promoted-const.rs @@ -7,7 +7,7 @@ struct Fail(T); impl Fail { const C: () = panic!(); //~ERROR evaluation of `Fail::::C` failed - //[opt]~^ ERROR evaluation of `Fail::::C` failed + //~^ ERROR evaluation of `Fail::::C` failed // (Not sure why optimizations lead to this being emitted twice, but as long as compilation // fails either way it's fine.) } diff --git a/tests/ui/lint/large_assignments/inline_mir.rs b/tests/ui/lint/large_assignments/inline_mir.rs index fc27b8ff244d1..156e6e8d6f26d 100644 --- a/tests/ui/lint/large_assignments/inline_mir.rs +++ b/tests/ui/lint/large_assignments/inline_mir.rs @@ -20,5 +20,6 @@ pub fn main() { let data = [10u8; 9999]; let cell = std::cell::UnsafeCell::new(data); //~ ERROR large_assignments + #[allow(large_assignments)] std::hint::black_box(cell); } diff --git a/tests/ui/lint/large_assignments/move_into_fn.rs b/tests/ui/lint/large_assignments/move_into_fn.rs index 73ec08fa23a74..3f6f212025656 100644 --- a/tests/ui/lint/large_assignments/move_into_fn.rs +++ b/tests/ui/lint/large_assignments/move_into_fn.rs @@ -16,7 +16,8 @@ fn main() { // Looking at llvm-ir output, we can see that there is no memcpy involved in // this function call. Instead, just a pointer is passed to the function. So // the lint shall not trigger here. - take_data(data); + take_data(data); //~ ERROR large_assignments + // FIXME: uh-oh, the test says we shouldn't get a lint here and we do. } fn take_data(data: Data) {} diff --git a/tests/ui/lint/large_assignments/move_into_fn.stderr b/tests/ui/lint/large_assignments/move_into_fn.stderr index 92a0489e472f9..19ec6a51d2e74 100644 --- a/tests/ui/lint/large_assignments/move_into_fn.stderr +++ b/tests/ui/lint/large_assignments/move_into_fn.stderr @@ -11,5 +11,13 @@ note: the lint level is defined here LL | #![deny(large_assignments)] | ^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: moving 9999 bytes + --> $DIR/move_into_fn.rs:19:15 + | +LL | take_data(data); + | ^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: aborting due to 2 previous errors diff --git a/tests/ui/print_type_sizes/coroutine_discr_placement.stdout b/tests/ui/print_type_sizes/coroutine_discr_placement.stdout index 4ce1ce46f6e82..4cacb4d7d00d6 100644 --- a/tests/ui/print_type_sizes/coroutine_discr_placement.stdout +++ b/tests/ui/print_type_sizes/coroutine_discr_placement.stdout @@ -15,3 +15,9 @@ print-type-size type: `std::mem::MaybeUninit`: 4 bytes, alignment: 4 bytes print-type-size variant `MaybeUninit`: 4 bytes print-type-size field `.uninit`: 0 bytes print-type-size field `.value`: 4 bytes +print-type-size type: `std::ops::CoroutineState<(), ()>`: 1 bytes, alignment: 1 bytes +print-type-size discriminant: 1 bytes +print-type-size variant `Yielded`: 0 bytes +print-type-size field `.0`: 0 bytes +print-type-size variant `Complete`: 0 bytes +print-type-size field `.0`: 0 bytes diff --git a/tests/ui/stable-mir-print/async-closure.stdout b/tests/ui/stable-mir-print/async-closure.stdout index 12e7a5530ace6..8fb6136206e5b 100644 --- a/tests/ui/stable-mir-print/async-closure.stdout +++ b/tests/ui/stable-mir-print/async-closure.stdout @@ -19,7 +19,7 @@ fn foo::{closure#0}(_1: &{async closure@$DIR/async-closure.rs:9:13: 9:21}) -> {a let mut _2: &i32; debug y => (*((*_1).0: &i32)); bb0: { - _2 = CopyForDeref(((*_1).0: &i32)); + _2 = ((*_1).0: &i32); _0 = {coroutine@$DIR/async-closure.rs:9:22: 11:6}(_2); return; } @@ -30,23 +30,19 @@ fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-clo let mut _4: &i32; let mut _5: u32; let mut _6: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _7: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _8: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; debug _task_context => _2; debug y => (*((*(_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})).0: &i32)); debug y => _3; bb0: { - _6 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); + _6 = (_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}); _5 = discriminant((*_6)); switchInt(move _5) -> [0: bb1, 1: bb2, otherwise: bb3]; } bb1: { - _7 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - _4 = CopyForDeref(((*_7).0: &i32)); + _4 = ((*_6).0: &i32); _3 = (*_4); - _0 = std::task::Poll::Ready(()); - _8 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - discriminant((*_8) = 1; + _0 = Poll::<()>::Ready(()); + discriminant((*_6) = 1; return; } bb2: { @@ -62,23 +58,19 @@ fn foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-c let mut _4: &i32; let mut _5: u32; let mut _6: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _7: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _8: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; debug _task_context => _2; debug y => (*((*(_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})).0: &i32)); debug y => _3; bb0: { - _6 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); + _6 = (_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}); _5 = discriminant((*_6)); switchInt(move _5) -> [0: bb1, 1: bb2, otherwise: bb3]; } bb1: { - _7 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - _4 = CopyForDeref(((*_7).0: &i32)); + _4 = ((*_6).0: &i32); _3 = (*_4); - _0 = std::task::Poll::Ready(()); - _8 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - discriminant((*_8) = 1; + _0 = Poll::<()>::Ready(()); + discriminant((*_6) = 1; return; } bb2: { diff --git a/tests/ui/stable-mir-print/operands.stdout b/tests/ui/stable-mir-print/operands.stdout index c3b1151ae24a3..8cbd8c030582a 100644 --- a/tests/ui/stable-mir-print/operands.stdout +++ b/tests/ui/stable-mir-print/operands.stdout @@ -4,184 +4,133 @@ fn operands(_1: u8) -> () { let mut _0: (); let _2: [u8; 10]; let _3: u8; - let _4: usize; - let mut _5: bool; - let _6: u8; - let _7: usize; - let mut _8: (usize, bool); - let mut _9: bool; - let mut _10: (&u8, &u8); - let mut _11: &u8; - let mut _12: &u8; - let _13: &u8; - let _14: &u8; - let mut _15: bool; - let mut _16: u8; + let _4: u8; + let mut _5: &u8; + let mut _6: &u8; + let mut _7: bool; + let mut _8: u8; + let mut _9: u8; + let _10: !; + let mut _11: Option>; + let _12: &u8; + let _13: u8; + let mut _14: &u8; + let mut _15: &u8; + let mut _16: bool; let mut _17: u8; - let _18: core::panicking::AssertKind; + let mut _18: u8; let _19: !; let mut _20: Option>; - let _21: &u8; - let _22: u8; - let mut _23: (&u8, &u8); - let mut _24: &u8; - let mut _25: &u8; - let _26: &u8; - let _27: &u8; + let _21: (u8, u8); + let mut _22: u8; + let mut _23: u8; + let _24: u8; + let _25: u8; + let mut _26: &u8; + let mut _27: &u8; let mut _28: bool; let mut _29: u8; let mut _30: u8; - let _31: core::panicking::AssertKind; - let _32: !; - let mut _33: Option>; - let _34: (u8, u8); - let _35: u8; - let _36: u8; - let mut _37: (&u8, &u8); - let mut _38: &u8; - let mut _39: &u8; - let _40: &u8; - let _41: &u8; - let mut _42: bool; - let mut _43: u8; - let mut _44: u8; - let _45: core::panicking::AssertKind; - let _46: !; - let mut _47: Option>; - let _48: usize; - let mut _49: &[u8]; - let mut _50: &[u8; 10]; - let _51: usize; - let _52: &usize; - let mut _53: (&usize, &usize); - let mut _54: &usize; - let mut _55: &usize; - let _56: &usize; - let _57: &usize; - let mut _58: bool; - let mut _59: usize; - let mut _60: usize; - let _61: core::panicking::AssertKind; - let _62: !; - let mut _63: Option>; + let _31: !; + let mut _32: Option>; + let _33: usize; + let _34: usize; + let _35: &usize; + let mut _36: &usize; + let mut _37: &usize; + let mut _38: bool; + let mut _39: usize; + let mut _40: usize; + let _41: !; + let mut _42: Option>; debug val => _1; debug array => _2; debug first => _3; - debug last => _6; - debug left_val => _13; - debug right_val => _14; - debug kind => _18; - debug reference => _21; - debug dereferenced => _22; + debug last => _4; + debug left_val => _5; + debug right_val => _6; + debug kind => core::panicking::AssertKind::Eq; + debug reference => _12; + debug dereferenced => _13; + debug left_val => _14; + debug right_val => _15; + debug kind => core::panicking::AssertKind::Eq; + debug tuple => _21; + debug first_again => _24; + debug first_again_again => _25; debug left_val => _26; debug right_val => _27; - debug kind => _31; - debug tuple => _34; - debug first_again => _35; - debug first_again_again => _36; - debug left_val => _40; - debug right_val => _41; - debug kind => _45; - debug length => _48; - debug size_of => _51; - debug left_val => _56; - debug right_val => _57; - debug kind => _61; + debug kind => core::panicking::AssertKind::Eq; + debug length => _33; + debug size_of => _34; + debug left_val => _36; + debug right_val => _37; + debug kind => core::panicking::AssertKind::Eq; bb0: { _2 = [_1; 10]; - _4 = 0_usize; - _5 = Lt(_4, 10_usize); - assert(move _5, "index out of bounds: the length is {} but the index is {}", 10_usize, _4) -> [success: bb1, unwind unreachable]; + _3 = _2[0 of 1]; + _4 = _2[9 of 10]; + _5 = &_3; + _6 = &_4; + _8 = (*_5); + _9 = (*_6); + _7 = Eq(move _8, move _9); + switchInt(move _7) -> [0: bb2, otherwise: bb1]; } bb1: { - _3 = _2[_4]; - _8 = CheckedSub(10_usize, 1_usize); - assert(!move (_8.1: bool), "attempt to compute `{} - {}`, which would overflow", 10_usize, 1_usize) -> [success: bb2, unwind unreachable]; + _12 = &_3; + _13 = (*_12); + _14 = &_13; + _15 = &_3; + _17 = (*_14); + _18 = (*_15); + _16 = Eq(move _17, move _18); + switchInt(move _16) -> [0: bb4, otherwise: bb3]; } bb2: { - _7 = move (_8.0: usize); - _9 = Lt(_7, 10_usize); - assert(move _9, "index out of bounds: the length is {} but the index is {}", 10_usize, _7) -> [success: bb3, unwind unreachable]; + _11 = std::option::Option::None; + _10 = core::panicking::assert_failed::(core::panicking::AssertKind::Eq, _5, _6, move _11) -> unwind unreachable; } bb3: { - _6 = _2[_7]; - _11 = &_3; - _12 = &_6; - _10 = (move _11, move _12); - _13 = (_10.0: &u8); - _14 = (_10.1: &u8); - _16 = (*_13); - _17 = (*_14); - _15 = Eq(move _16, move _17); - switchInt(move _15) -> [0: bb5, otherwise: bb4]; - } - bb4: { - _21 = &_3; - _22 = (*_21); - _24 = &_22; - _25 = &_3; - _23 = (move _24, move _25); - _26 = (_23.0: &u8); - _27 = (_23.1: &u8); + _22 = _3; + _23 = _4; + _21 = (_22, move _23); + _24 = _22; + _25 = _22; + _26 = &_24; + _27 = &_25; _29 = (*_26); _30 = (*_27); _28 = Eq(move _29, move _30); - switchInt(move _28) -> [0: bb7, otherwise: bb6]; + switchInt(move _28) -> [0: bb6, otherwise: bb5]; } - bb5: { - _18 = core::panicking::AssertKind::Eq; + bb4: { _20 = std::option::Option::None; - _19 = core::panicking::assert_failed::(move _18, _13, _14, move _20) -> unwind unreachable; + _19 = core::panicking::assert_failed::(core::panicking::AssertKind::Eq, _14, _15, move _20) -> unwind unreachable; + } + bb5: { + _33 = 10_usize; + _35 = &_33; + _34 = std::mem::size_of_val::(_35) -> [return: bb7, unwind unreachable]; } bb6: { - _34 = (_3, _6); - _35 = (_34.0: u8); - _36 = (_34.0: u8); - _38 = &_35; - _39 = &_36; - _37 = (move _38, move _39); - _40 = (_37.0: &u8); - _41 = (_37.1: &u8); - _43 = (*_40); - _44 = (*_41); - _42 = Eq(move _43, move _44); - switchInt(move _42) -> [0: bb9, otherwise: bb8]; + _32 = std::option::Option::None; + _31 = core::panicking::assert_failed::(core::panicking::AssertKind::Eq, _26, _27, move _32) -> unwind unreachable; } bb7: { - _31 = core::panicking::AssertKind::Eq; - _33 = std::option::Option::None; - _32 = core::panicking::assert_failed::(move _31, _26, _27, move _33) -> unwind unreachable; + _36 = &_33; + _37 = &_34; + _39 = (*_36); + _40 = (*_37); + _38 = Eq(move _39, move _40); + switchInt(move _38) -> [0: bb9, otherwise: bb8]; } bb8: { - _50 = &_2; - _49 = move _50 as &[u8]; - _48 = PtrMetadata(move _49); - _52 = &_48; - _51 = std::mem::size_of_val::(_52) -> [return: bb10, unwind unreachable]; - } - bb9: { - _45 = core::panicking::AssertKind::Eq; - _47 = std::option::Option::None; - _46 = core::panicking::assert_failed::(move _45, _40, _41, move _47) -> unwind unreachable; - } - bb10: { - _54 = &_48; - _55 = &_51; - _53 = (move _54, move _55); - _56 = (_53.0: &usize); - _57 = (_53.1: &usize); - _59 = (*_56); - _60 = (*_57); - _58 = Eq(move _59, move _60); - switchInt(move _58) -> [0: bb12, otherwise: bb11]; - } - bb11: { return; } - bb12: { - _61 = core::panicking::AssertKind::Eq; - _63 = std::option::Option::None; - _62 = core::panicking::assert_failed::(move _61, _56, _57, move _63) -> unwind unreachable; + bb9: { + _42 = std::option::Option::None; + _41 = core::panicking::assert_failed::(core::panicking::AssertKind::Eq, _36, _37, move _42) -> unwind unreachable; } } fn operands::{constant#0}() -> usize { @@ -193,20 +142,18 @@ fn operands::{constant#0}() -> usize { } fn more_operands() -> [Ctors; 3] { let mut _0: [Ctors; 3]; - let _1: Dummy; + let _1: Ctors; let _2: Ctors; let _3: Ctors; - let _4: Ctors; - debug dummy => _1; - debug unit => _2; - debug struct_like => _3; - debug tup_like => _4; + debug dummy => Dummy {{ c: 'a', i: i32::MIN }}; + debug unit => _1; + debug struct_like => _2; + debug tup_like => _3; bb0: { - _1 = Dummy('a', core::num::::MIN); - _2 = Ctors::Unit; - _3 = Ctors::StructLike(move _1); - _4 = Ctors::TupLike(false); - _0 = [move _2, move _3, move _4]; + _1 = Ctors::Unit; + _2 = Ctors::StructLike(Dummy {{ c: 'a', i: i32::MIN }}); + _3 = Ctors::TupLike(false); + _0 = [_1, _2, _3]; return; } }