From 099cb5ad8ab622451a3cd67276522a2a79b8608f Mon Sep 17 00:00:00 2001 From: Ze'ev Maor Date: Tue, 5 Jul 2022 23:38:52 +0300 Subject: [PATCH 1/2] only enable ConstProp on opt level 2 --- compiler/rustc_mir_transform/src/const_prop.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 36844d5f6cfae..05d59a7acf447 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -60,11 +60,8 @@ macro_rules! throw_machine_stop_str { pub struct ConstProp; impl<'tcx> MirPass<'tcx> for ConstProp { - fn is_enabled(&self, _sess: &rustc_session::Session) -> bool { - // FIXME(#70073): Unlike the other passes in "optimizations", this one emits errors, so it - // runs even when MIR optimizations are disabled. We should separate the lint out from the - // transform and move the lint as early in the pipeline as possible. - true + fn is_enabled(&self, sess: &rustc_session::Session) -> bool { + sess.mir_opt_level() >= 2 } #[instrument(skip(self, tcx), level = "debug")] @@ -786,12 +783,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { /// Returns `true` if and only if this `op` should be const-propagated into. fn should_const_prop(&mut self, op: &OpTy<'tcx>) -> bool { - let mir_opt_level = self.tcx.sess.mir_opt_level(); - - if mir_opt_level == 0 { - return false; - } - if !self.tcx.consider_optimizing(|| format!("ConstantPropagation - OpTy: {:?}", op)) { return false; } From 728fb05f1fc3d4ab4db5764395fc9ac34efc45f0 Mon Sep 17 00:00:00 2001 From: Ze'ev Maor Date: Wed, 6 Jul 2022 00:03:32 +0300 Subject: [PATCH 2/2] enable on opt level 1 --- compiler/rustc_mir_transform/src/const_prop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 05d59a7acf447..2408d38be7dcb 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -61,7 +61,7 @@ pub struct ConstProp; impl<'tcx> MirPass<'tcx> for ConstProp { fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() >= 2 + sess.mir_opt_level() >= 1 } #[instrument(skip(self, tcx), level = "debug")]