MirPatch in rustc_mir_transform::patch - Rust (original) (raw)
pub(crate) struct MirPatch<'tcx> {
term_patch_map: IndexVec<BasicBlock, Option<TerminatorKind<'tcx>>>,
new_blocks: Vec<BasicBlockData<'tcx>>,
new_statements: Vec<(Location, StatementKind<'tcx>)>,
new_locals: Vec<LocalDecl<'tcx>>,
resume_block: Option<BasicBlock>,
unreachable_cleanup_block: Option<BasicBlock>,
unreachable_no_cleanup_block: Option<BasicBlock>,
terminate_block: Option<(BasicBlock, UnwindTerminateReason)>,
body_span: Span,
next_local: usize,
}
Expand description
This struct lets you “patch” a MIR body, i.e. modify it. You can queue up various changes, such as the addition of new statements and basic blocks and replacement of terminators, and then apply the queued changes all at once with apply
. This is useful for MIR transformation passes.
§body_span: [Span](../../rustc%5Fspan/span%5Fencoding/struct.Span.html "struct rustc_span::span_encoding::Span")
Creates a new, empty patch.
Has a replacement of this block’s terminator been queued in this patch?
Universal getter for block data, either it is in ‘old’ blocks or in patched ones
Queues the addition of a new temporary with additional local info.
Queues the addition of a new temporary.
Returns the type of a local that’s newly-added in the patch.
Queues the addition of a new basic block.
Queues the replacement of a block’s terminator.
Queues the insertion of a statement at a given location. The statement currently at that location, and all statements that follow, are shifted down. If multiple statements are queued for addition at the same location, the final statement order after calling apply
will match the queue insertion order.
E.g. if we have s0
at location loc
and do these calls:
p.add_statement(loc, s1); p.add_statement(loc, s2); p.apply(body);
then the final order will be s1, s2, s0
, with s1
at loc
.
Like add_statement
, but specialized for assignments.
Applies the queued changes.
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 136 bytes