Why use MIR?

October 18, 2024 ยท View on GitHub

MIRAI analyzes the Mid-level Intermediate Representation produced by the Rust compiler in preparation for code generation.

Possible alternatives would be to use higher level representations such as the AST, the High-Level Intermediate Representation or the Typed High-Level Intermediate Representation.

All of these approaches would require some form of lowering in order to perform an analysis of the execution of the project of interest. This would provide flexibility and more control, but it also involves a substantial amount of largely duplicated work (see also).

There is another consideration: Unlike the AST, HIR and THIR, MIR is serialized into the compiler output for dependencies. Since MIRAI does a top-down analysis (see also), the convenience and performance benefit of not re-compiling every dependency, are factors of overriding importance.