Crate rustc_mir_transform[−][src]

Modules

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.

Check the bodies of consts, statics and const fns for illegal operations.

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.

This pass optimizes the following sequence

Propagates constants for early reporting of statically known assertion failures

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

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

This pass just dumps MIR at a specified point.

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

Inlining pass for MIR functions

Performs various peephole optimizations.

HIR walker for walking the contents of nodes.

Lowers intrinsic calls

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

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

See the docs for RenameReturnPlace.

A pass that promotes borrows of constant rvalues.

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.

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.

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

A pass that simplifies branches when their condition is known.

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

Defines how the compiler represents types internally.

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.

Validates the MIR to ensure that invariants are upheld.

Structs

The lowered representation of a single function.

The result of the mir_const_qualif query.

A DefId identifies a particular definition, by combining a crate index and a def index.

A LocalDefId is equivalent to a DefId with krate == LOCAL_CRATE. Since we encode this information in the type, we can ensure at compile time that no DefIds from upstream crates get thrown into the mix. There are quite a few cases where we know that only DefIds from the local crate are expected and a DefId from a different crate would signify a bug somewhere. This is when LocalDefId comes in handy.

A compressed span.

The Steal struct is intended to used as the value for a query. Specifically, we sometimes have queries (cough MIR cough) where we create a large, complex value that we want to iteratively update (e.g., optimize). We could clone the value for each optimization, but that’d be expensive. And yet we don’t just want to mutate it in place, because that would spoil the idea that queries are these pure functions that produce an immutable value (since if you did the query twice, you could observe the mutations). So instead we have the query produce a &'tcx Steal<mir::Body<'tcx>> (to be very specific). Now we can read from this as much as we want (using borrow()), but you can also steal(). Once you steal, any further attempt to read will panic. Therefore, we know that – assuming no ICE – nobody is observing the fact that the MIR was updated.

An interned string.

The central data structure of the compiler. It stores references to the various arenas and also houses the results of the various compiler queries that have been performed. See the rustc dev guide for more details.

Enums

The various “big phases” that MIR goes through.

Specifies what nested things a visitor wants to visit. The most common choice is OnlyBodies, which will cause the visitor to visit fn bodies for fns that it encounters, but skip over nested item-like things.

Traits

A streamlined trait that you can implement to create a pass; the pass will be named after the type, and it will consist of a main loop that goes over each available MIR and applies run_pass.

This trait is implemented for every type that can be folded. Basically, every type that has a corresponding method in TypeFolder.

Each method of the Visitor trait is a hook to be potentially overridden. Each method’s default implementation recursively visits the substructure of the input via the corresponding walk method; e.g., the visit_mod method by default calls intravisit::walk_mod.

Functions

If the session is properly configured, dumps a human-readable representation of the mir into:

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.

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.

Type Definitions

Type alias for a hashmap using the fx hash algorithm.