Struct rustc_middle::mir::Body[][src]

pub struct Body<'tcx> {
    basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
    pub phase: MirPhase,
    pub source: MirSource<'tcx>,
    pub source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
    pub yield_ty: Option<Ty<'tcx>>,
    pub generator_drop: Option<Box<Body<'tcx>>>,
    pub generator_layout: Option<GeneratorLayout<'tcx>>,
    pub generator_kind: Option<GeneratorKind>,
    pub local_decls: LocalDecls<'tcx>,
    pub user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
    pub arg_count: usize,
    pub spread_arg: Option<Local>,
    pub var_debug_info: Vec<VarDebugInfo<'tcx>>,
    pub span: Span,
    pub required_consts: Vec<Constant<'tcx>>,
    pub is_polymorphic: bool,
    predecessor_cache: PredecessorCache,
    is_cyclic: GraphIsCyclicCache,

The lowered representation of a single function.


basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>

A list of basic blocks. References to basic block use a newtyped index type BasicBlock that indexes into this vector.

phase: MirPhase

Records how far through the “desugaring and optimization” process this particular MIR has traversed. This is particularly useful when inlining, since in that context we instantiate the promoted constants and add them to our promoted vector – but those promoted items have already been optimized, whereas ours have not. This field allows us to see the difference and forego optimization on the inlined promoted items.

source: MirSource<'tcx>source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>

A list of source scopes; these are referenced by statements and used for debuginfo. Indexed by a SourceScope.

yield_ty: Option<Ty<'tcx>>

The yield type of the function, if it is a generator.

generator_drop: Option<Box<Body<'tcx>>>

Generator drop glue.

generator_layout: Option<GeneratorLayout<'tcx>>

The layout of a generator. Produced by the state transformation.

generator_kind: Option<GeneratorKind>

If this is a generator then record the type of source expression that caused this generator to be created.

local_decls: LocalDecls<'tcx>

Declarations of locals.

The first local is the return value pointer, followed by arg_count locals for the function arguments, followed by any user-declared variables and temporaries.

user_type_annotations: CanonicalUserTypeAnnotations<'tcx>

User type annotations.

arg_count: usize

The number of arguments this function takes.

Starting at local 1, arg_count locals will be provided by the caller and can be assumed to be initialized.

If this MIR was built for a constant, this will be 0.

spread_arg: Option<Local>

Mark an argument local (which must be a tuple) as getting passed as its individual components at the LLVM level.

This is used for the “rust-call” ABI.

var_debug_info: Vec<VarDebugInfo<'tcx>>

Debug information pertaining to user variables, including captures.

span: Span

A span representing this MIR, for error reporting.

required_consts: Vec<Constant<'tcx>>

Constants that are required to evaluate successfully for this MIR to be well-formed. We hold in this field all the constants we are not able to evaluate yet.

is_polymorphic: bool

Does this body use generic parameters. This is used for the ConstEvaluatable check.

Note that this does not actually mean that this body is not computable right now. The repeat count in the following example is polymorphic, but can still be evaluated without knowing anything about the type parameter T.

fn test<T>() {
    let _ = [0; std::mem::size_of::<*mut T>()];

WARNING: Do not change this flags after the MIR was originally created, even if an optimization removed the last mention of all generic params. We do not want to rely on optimizations and potentially allow things like [u8; std::mem::size_of::<T>() * 0] due to this.

predecessor_cache: PredecessorCacheis_cyclic: GraphIsCyclicCache


impl<'tcx> Body<'tcx>[src]

pub fn new(
    source: MirSource<'tcx>,
    basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
    source_scopes: IndexVec<SourceScope, SourceScopeData<'tcx>>,
    local_decls: LocalDecls<'tcx>,
    user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
    arg_count: usize,
    var_debug_info: Vec<VarDebugInfo<'tcx>>,
    span: Span,
    generator_kind: Option<GeneratorKind>
) -> Self

pub fn new_cfg_only(
    basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>
) -> Self

Returns a partially initialized MIR body containing only a list of basic blocks.

The returned MIR contains no LocalDecls (even for the return place) or source scopes. It is only useful for testing but cannot be #[cfg(test)] because it is used in a different crate.

pub fn basic_blocks(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>>[src]

pub fn basic_blocks_mut(
    &mut self
) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>>

pub fn basic_blocks_and_local_decls_mut(
    &mut self
) -> (&mut IndexVec<BasicBlock, BasicBlockData<'tcx>>, &mut LocalDecls<'tcx>)

pub fn basic_blocks_local_decls_mut_and_var_debug_info(
    &mut self
) -> (&mut IndexVec<BasicBlock, BasicBlockData<'tcx>>, &mut LocalDecls<'tcx>, &mut Vec<VarDebugInfo<'tcx>>)

pub fn is_cfg_cyclic(&self) -> bool[src]

Returns true if a cycle exists in the control-flow graph that is reachable from the START_BLOCK.

pub fn local_kind(&self, local: Local) -> LocalKind[src]

pub fn temps_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a[src]

Returns an iterator over all temporaries.

pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a[src]

Returns an iterator over all user-declared locals.

pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a[src]

Returns an iterator over all user-declared mutable locals.

pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a[src]

Returns an iterator over all user-declared mutable arguments and locals.

pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator[src]

Returns an iterator over all function arguments.

pub fn vars_and_temps_iter(
) -> impl DoubleEndedIterator<Item = Local> + ExactSizeIterator

Returns an iterator over all user-defined variables and compiler-generated temporaries (all locals that are neither arguments nor the return place).

pub fn make_statement_nop(&mut self, location: Location)[src]

Changes a statement to a nop. This is both faster than deleting instructions and avoids invalidating statement indices in Locations.

pub fn source_info(&self, location: Location) -> &SourceInfo[src]

Returns the source info associated with location.

pub fn return_ty(&self) -> Ty<'tcx>[src]

Returns the return type; it always return first element from local_decls array.

pub fn terminator_loc(&self, bb: BasicBlock) -> Location[src]

Gets the location of the terminator for the given block.

pub fn predecessors(
) -> impl Deref<Target = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>> + '_

pub fn dominators(&self) -> Dominators<BasicBlock>[src]

Trait Implementations

impl<'tcx> ArenaAllocatable<'tcx, Body<'tcx>> for Body<'tcx>[src]

impl<'tcx> Clone for Body<'tcx>[src]

impl<'tcx> Debug for Body<'tcx>[src]

impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for &'tcx Body<'tcx>[src]

impl<'tcx, __D: TyDecoder<'tcx>> Decodable<__D> for Body<'tcx>[src]

impl<'tcx> DirectedGraph for Body<'tcx>[src]

impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for &'tcx Body<'tcx>[src]

impl<'tcx, __E: TyEncoder<'tcx>> Encodable<__E> for Body<'tcx>[src]

impl<'graph, 'tcx> GraphPredecessors<'graph> for Body<'tcx>[src]

type Item = BasicBlock

type Iter = IntoIter<[BasicBlock; 4]>

impl<'a, 'b> GraphSuccessors<'b> for Body<'a>[src]

impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx>[src]

impl<'tcx, '__ctx> HashStable<StableHashingContext<'__ctx>> for Body<'tcx>[src]

impl<'tcx> Index<BasicBlock> for Body<'tcx>[src]

type Output = BasicBlockData<'tcx>

The returned type after indexing.

impl<'tcx> IndexMut<BasicBlock> for Body<'tcx>[src]

impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for Body<'tcx>[src]

impl<'tcx> TypeFoldable<'tcx> for Body<'tcx>[src]

impl<'tcx> WithNumNodes for Body<'tcx>[src]

impl<'tcx> WithPredecessors for Body<'tcx>[src]

impl<'tcx> WithStartNode for Body<'tcx>[src]

impl<'tcx> WithSuccessors for Body<'tcx>[src]

Auto Trait Implementations

impl<'tcx> !RefUnwindSafe for Body<'tcx>

impl<'tcx> !Send for Body<'tcx>

impl<'tcx> !Sync for Body<'tcx>

impl<'tcx> Unpin for Body<'tcx>

impl<'tcx> !UnwindSafe for Body<'tcx>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<'a, T> Captures<'a> for T where
    T: ?Sized

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> MaybeResult<T> for T[src]

type Error = !

impl<'tcx, T> Subst<'tcx> for T where
    T: TypeFoldable<'tcx>, 

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]