Skip to content
La3 Docs
Browse docs

MIR

Control-flow graphs, locals, places, rvalues, terminators, match trees, and ownership lowering.

MIR shape

MIR is a Rust-style control-flow graph with typed locals and explicit temporaries.

  • Functions contain basic blocks.
  • Blocks contain statements and end in one terminator.
  • _0 is the return slot.
  • Places identify locals plus field, index, deref, or downcast projections.
  • Rvalues describe computations that assign into places.

Control flow

Branches, loops, returns, calls, and matches become explicit block edges.

Lowering to MIR replaces nested syntax with a graph. That graph is where later passes can reason about reachability, liveness, drops, and borrow precision without guessing how source syntax might execute.

  • if becomes conditional terminators and join blocks.
  • Loops become back-edges.
  • break value writes to a loop result place.
  • Function calls become call terminators with success continuations.

Match lowering

Pattern matching lowers into decision trees of tests, switches, downcasts, and bindings.

  • Literals and booleans can lower to switch-like tests.
  • Ranges become comparison chains.
  • Enum variants read discriminants and downcast payloads.
  • Guards run after a structural match succeeds.
  • Unsupported patterns should bail honestly until implemented.

Ownership lowering

MIR is where moves and drops become explicit operations.

  • Consuming reads become Move operands.
  • Borrowing reads remain non-consuming.
  • Owned locals get drops at scope exits.
  • Moved-out locals are skipped so values are not dropped twice.
  • Conditional moves and partial moves need later drop-flag precision.