Even after #160524, some passes still use sess.opt_level/sess.mir_opt_level, which means they do not properly honor #[optimize]:
- The inliner has a very special policy where on mir-opt-level 2, behavior depends on the
-Copt-level. This is because -Copt-levels 1..=3 all map to the same mir-opt-level but the inliner does not want to behave the same for all of them. I assume we want to preserve this distinction between -Copt-level=1 and higher values (@wesleywiser @cjgillot I think you added this logic in d1d9092, would be good to hear your thoughts on this). If so, we can either just accept that the attribute is not fully equivalent to changing the global opt level, or we could do it properly: map -Copt-level=1 to a different mir-opt-level than the higher -Copt-level values (but is that worth it if the inliner is the only pass making a distinction between the two?).
- dataflow_const_prop passes checks
sess.mir_opt_level inside the actual pass to be more or less aggressive. #[optimize] only affects whether the pass is enabled, but then we don't use the attribute later when the pass runs to determine how aggressive it is. See here, here. Not sure what the best way is to deal with this. Maybe we just accept this?
Cc @clubby789 @veluca93 @rust-lang/wg-mir-opt
Tracking issue: #54882
Even after #160524, some passes still use
sess.opt_level/sess.mir_opt_level, which means they do not properly honor#[optimize]:-Copt-level. This is because -Copt-levels 1..=3 all map to the same mir-opt-level but the inliner does not want to behave the same for all of them. I assume we want to preserve this distinction between -Copt-level=1 and higher values (@wesleywiser @cjgillot I think you added this logic in d1d9092, would be good to hear your thoughts on this). If so, we can either just accept that the attribute is not fully equivalent to changing the global opt level, or we could do it properly: map -Copt-level=1 to a different mir-opt-level than the higher -Copt-level values (but is that worth it if the inliner is the only pass making a distinction between the two?).sess.mir_opt_levelinside the actual pass to be more or less aggressive.#[optimize]only affects whether the pass is enabled, but then we don't use the attribute later when the pass runs to determine how aggressive it is. See here, here. Not sure what the best way is to deal with this. Maybe we just accept this?Cc @clubby789 @veluca93 @rust-lang/wg-mir-opt
Tracking issue: #54882