Memory Diagnostics
Miri manages memory for you, which means a reference-counting mistake is a compiler bug rather than yours. These tools exist to catch such bugs — they are how the standard library above was brought to a provably leak-free state, and running your own program under them costs you nothing but a rebuild.
| Tool | How | What it reports |
|---|---|---|
| Shadow heap | MIRI_HEAP_GUARD=1 | An ASan-style shadow heap that traps use-after-free and double-free at the moment they happen, and attributes each leak to the allocation site. Silent on a correct program. |
| Allocation count | MIRI_ALLOC_COUNT=1 | Exact allocation totals for the run, split by category, so a change in allocation behaviour is measurable rather than guessed at. |
| RC verifier | --verify-mir | A path-sensitive check of the reference-counting invariants after the Perceus transform. Reports any imbalance as a hard error. |
The verifier also honours the MIRI_VERIFY_MIR environment variable, which is how it runs across the compiler's own test suite on every change.