mir-transform: Treat optimize(none) the same as opt-level=0 - #160524
mir-transform: Treat optimize(none) the same as opt-level=0#160524clubby789 wants to merge 1 commit into
optimize(none) the same as opt-level=0#160524Conversation
354d5d9 to
e4742bc
Compare
|
Typo error caused an ICE in drop elaboration - optimizations.0 >= min_level
+ optimizations.0 < min_levelwhich seems a bit surprising EDIT: Seems like some other opts rely on |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
Note that this now fails because #[optimize(none)]
pub fn const_branch() -> i32 {
if true { 1 } else { 0 }
}produces |
| /// e.g. if it just adds extra debug checks that one can turn off. | ||
| optimization: bool, | ||
| /// If this is an optimization pass, define the minimum optimization level to enable | ||
| /// the pass. |
There was a problem hiding this comment.
| /// the pass. | |
| /// the pass. If this is `Some(n)`, the pass only runs if `min_optimization_level` is true *and* | |
| /// mir-opt-level is at least n. |
| fn policy(&self, sess: &rustc_session::Session) -> PassPolicy { | ||
| // If `inline_mir` is specified, return that. | ||
| // Otherwise, enable when either: | ||
| // - mir-opt-level == 2 && opt-level >= 2 && !incremental, OR |
There was a problem hiding this comment.
I was about to say, I am not sure that we can represent all intended policies with a new field in PassPolicy. The alternative is to replace the sess argument by something that provides the current mir-opt-level (and forwards everything else to Session).
I am also quite surprised that this checks both mir-opt-level and opt-level. @wesleywiser @saethlin do you know why?
What do you mean by "rely" here and why does this become more of a problem with this PR? |
I didn't look into it deeply, but a few passes seemed to ICE if they ran with dead BBs.
It doesn't; I just made a typo during implementation which exposed this and I was unsure if that was intentional/known. |
We'd have to ask the people that wrote the passes, so it'd help if you had a concrete example and backtrace. I presume this can be reproduced with |
cc @RalfJung
This is a quick initial sketch of a solution and the API will need some refining. The idea is that optimisations have a general condition under which they're enabled (i.e. some compiler option is enabled, we're not on some incompatible target) and a minimum MIR opt level. When we then decide whether or not to run a pass, we calculate an MIR opt level from, in order:
#[optimize(none)](1 if present)-Zmir-opt-level-Copt-level(2 if opt-level >= 2, 1 otherwise)