Skip to content

#[optimize] does not fully overwrite global opt level in all MIR opts #162360

Description

@RalfJung

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions