@@ -60,3 +60,24 @@ want to query whether your optimization pass should run, you can check the
60
60
current level using ` tcx.sess.opts.debugging_opts.mir_opt_level ` .
61
61
62
62
[ compiler MCP ] : https://github.com/rust-lang/compiler-team/issues/319
63
+
64
+ ## Optimization fuel
65
+
66
+ Optimization fuel is a compiler option (` -Z fuel=<crate>=<value> ` ) that allows for fine grained
67
+ control over which optimizations can be applied during compilation: each optimization reduces
68
+ fuel by 1, and when fuel reaches 0 no more optimizations are applied. This can help with debugging
69
+ and identifying problems with optimizations.
70
+
71
+ MIR optimizations respect fuel, and in general each pass should check fuel by calling
72
+ [ ` tcx.consider_optimizing ` ] [ consideroptimizing ] and skipping the optimization if fuel
73
+ is empty. There are a few considerations:
74
+
75
+ 1 . If the pass is considered "guaranteed" (for example, it should always be run because it is
76
+ needed for correctness), then fuel should not be used. An example of this is ` PromoteTemps ` .
77
+ 2 . In some cases, an initial pass is performed to gather candidates, which are then iterated to
78
+ perform optimizations. In these situations, we should allow for the initial gathering pass
79
+ and then check fuel as close to the mutation as possible. This allows for the best
80
+ debugging experience, because we can determine where in the list of candidates an optimization
81
+ may have been misapplied. Examples of this are ` InstCombine ` and ` ConstantPropagation ` .
82
+
83
+ [ consideroptimizing ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.consider_optimizing
0 commit comments