Modules

add_retag 🔒

This pass adds validation calls (AcquireValid, ReleaseValid) where appropriate. It has to be run really early, before transformations like inlining, because introducing these calls adds UB – so, conceptually, this pass is actually part of MIR building, and only after this pass we think of the program has having the normal MIR semantics.

This module provides a pass to replacing the following statements with Nops

Finds locals which are assigned once to a const and unused except for debuginfo and converts their debuginfo to use the const directly, allowing the local to be removed.

const_goto 🔒

This pass optimizes the following sequence

const_prop 🔒

Propagates constants for early reporting of statically known assertion failures

Propagates constants for early reporting of statically known assertion failures

coverage 🔒

This pass finds basic blocks that are completely equal, and replaces all uses with just one of them.

dest_prop 🔒

Propagates assignment destinations backwards in the CFG to eliminate redundant assignments.

This pass just dumps MIR at a specified point.

generator 🔒

This is the implementation of the pass which transforms generators into state machines.

inline 🔒

Inlining pass for MIR functions

Performs various peephole optimizations.

Lowers intrinsic calls

This pass lowers calls to core::slice::len to just Len op. It should run before inlining!

marker 🔒

This pass removes jumps to basic blocks containing only a return, and replaces them with a return instead.

This pass eliminates casting of arrays into slices when their length is taken using .len() method. Handy to preserve information in MIR for const prop

nrvo 🔒

See the docs for RenameReturnPlace.

This pass removes storage markers if they won’t be emitted during codegen.

This pass replaces a drop of a type that does not need dropping, with a goto.

Removes assignments to ZST places.

reveal_all 🔒

Normalizes MIR in RevealAll mode.

A pass that duplicates switch-terminated blocks into a new copy for each predecessor, provided the predecessor sets the value being switched over to a constant.

shim 🔒

A number of passes which remove various redundancies in the CFG.

The general point of the optimizations provided here is to simplify something like:

A pass that eliminates branches on uninhabited enum variants.

A pass that propagates the unreachable terminator of a block to its predecessors when all of their successors are unreachable. This is achieved through a post-order traversal of the blocks.

Functions

mir_const 🔒

Make MIR ready for const evaluation. This is run on all MIR, not just on consts!

Obtain just the main MIR (no promoteds) and run some cleanups on it. This also runs mir borrowck before doing so in order to ensure that borrowck can be run and doesn’t end up missing the source MIR due to stealing happening.

Compute the MIR that is used during CTFE (and thus has no optimizations run on it)

Same as mir_for_ctfe, but used to get the MIR of a const generic parameter. The docs on WithOptConstParam explain this a bit more, but the TLDR is that we’d get cycle errors with mir_for_ctfe, because typeck would need to typeck the const parameter while type checking the main body, which in turn would try to type check the main body again.

mir_keys 🔒

Finds the full set of DefIds within the current crate that have MIR associated with them.

Compute the main MIR body and the list of MIR bodies of the promoteds.

Optimize the MIR and prepare it for codegen.

Fetch all the promoteds of an item and prepare their MIR bodies to be ready for constant evaluation once all substitutions become known.

After this series of passes, no lifetime analysis based on borrowing can be done.