Comment

Comment by steveklabnik

I haven't been paying close attention lately, but for the last few years, compilation looked something vaguely like this:

* AST - abstract syntax tree, created from lexing/parsing

* HIR - high level IR

* THIR - typed high level IR

* MIR - mid-level IR (this is the one that enabled non-lexical lifetimes)

* LLVM IR - given to LLVM to generate the final binary.

If you want to learn more, the rustc dev guide has a bunch of details https://rustc-dev-guide.rust-lang.org/hir.html

> I would've thought rustc outputs only 1 IR?

Yeah, I mean these are in stages. One goes to the next goes to the next, and there's only one output, but that doesn't mean there aren't a bunch in the middle.

Different IRs are good at different things. MIR is based around the control-flow graph, which is also what non-lexical lifetimes are based on, so it's much easier to implement against MIR than it would have been against HIR.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton