Skip to content

Commit 30d03d0

Browse files
bugadaniJoshua Nelson
and
Joshua Nelson
committed
Link to the -Zmir-opt-level proposal
I was confused about what the different levels mean. This PR adds a paragraph that shortly explains the rationale behind different mir-opt-levels and links to the current proposal where there's some information about them. Let me know if I wrote something unreasonable or incorrect. Co-authored-by: Joshua Nelson <[email protected]>
1 parent 22b096b commit 30d03d0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/mir/optimizations.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ implemented in its own submodule of the [`rustc_mir::transform`][trans] module.
3636

3737
[rop]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/fn.run_optimization_passes.html
3838
[`MirPass`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/trait.MirPass.html
39-
[trans]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/index.html
39+
[trans]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/index.html
4040

4141
Some examples of passes are:
4242
- `CleanupNonCodegenStatements`: remove some of the info that is only needed for
@@ -47,3 +47,16 @@ You can see the ["Implementors" section of the `MirPass` rustdocs][impl] for mor
4747

4848
[impl]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/trait.MirPass.html#implementors
4949
[constprop]: https://en.wikipedia.org/wiki/Constant_folding#Constant_propagation
50+
51+
## MIR optimization levels
52+
53+
MIR optimizations can come in various levels of readiness. Experimental
54+
optimizations may cause miscompilations, or slow down compile times.
55+
These passes are still included in nightly builds to gather feedback and make it easier to modify
56+
the pass. To enable working with slow or otherwise experimental optimization passes,
57+
you can specify the `-Z mir-opt-level` debug flag. You can find the
58+
definitions of the levels in the [compiler MCP]. If you are developing a MIR pass and
59+
want to query whether your optimization pass should run, you can check the
60+
current level using `tcx.sess.opts.debugging_opts.mir_opt_level`.
61+
62+
[compiler MCP]: https://github.com/rust-lang/compiler-team/issues/319

0 commit comments

Comments
 (0)