Categories
Tags
algorithms APIT arm assembly asynchronous base64 Blogging box c clang-format cmake compiler concurrency const_fn contravariant cos covariant cpp Customization cybersecurity DataStructure db Demo deserialization discrete doc DP Dynamic Example FFI flat_map FP Functional functions futures Fuwari GATs gccrs generics gitignore GUI hacking hashmap haskell heap interop invariant iterator justfile kernel LaTeX LFU linux MachineLearning Markdown math ML OnceLock optimization OS parallels perf physics pin postgresql release RPIT rust science Science serialization shift sin SmallProjects std String surrealdb swisstable synchronous tan traits triangulation utf16 utf8 Video x86_64 xilem zig
337 words
2 minutes
Big_Picture_Rust_Compilation_Pipeline
link
Big Picture: Rust Compilation Pipeline
Rust source code
│
▼
AST (parser)
│
▼
HIR (High-level IR)
│
▼
MIR (Mid-level IR)
│
▼
LLVM IR
│
▼
Machine codeRust does not go directly from AST → LLVM.
Why?
- Rust has ownership, borrowing, lifetimes, traits, generics
- LLVM does not understand any of these
- Rust needs its own semantic IRs to prove correctness before codegen
녹은 AST → LLVM에서 직접 발생하지 않습니다.
왜요?
- 녹은 소유권, 차입, 수명, 특성, 제네릭을 가지고 있습니다
- LLVM은 다음 중 어느 것도 이해하지 못합니다
- Rust는 코드 생성 전에 정확성을 증명하기 위해 자체 의미론적 IR이 필요합니다
How They Fit Together (Most Important)
- 그들이 함께 어울리는 방법 (가장 중요한 것)
HIR : Understand Rust
MIR : Prove Rust is safe
LLVM : Make it fast- Responsibility Split
- 책임 분할
| Layer | Responsibility |
|---|---|
| HIR | Rust syntax + semantics |
| MIR | Ownership + borrowing |
| LLVM | Optimization + codegen |
🧠 One-Line Intuition (Very Useful)
- HIR: “What does this Rust code mean?”
- MIR: “Is this Rust code legal and safe?”
- LLVM: “How do I make this fast machine code?”
- 🧠 한 줄 직관 (매우 유용)
- HIR: “이 러스트 코드는 무엇을 의미하나요?”
- MIR: “이 러스트 코드는 합법적이고 안전한가요?”
- LLVM: “이 빠른 기계 코드는 어떻게 만드나요?”
- 🧠 한 줄 직관 (매우 유용)
📚 How to Study This Practically (Recommended Path)
- Since you like real source walkthroughs, I recommend:
Step 1 – HIR
rustc_hirLook at:
ExprKindStmtKind
Study desugaring (
for,match,?)
Step 2 – MIR (most time here)
rustc_middle::mirStudy:
BodyBasicBlockPlaceOperand
Then:
- borrow checker (
rustc_borrowck)
- borrow checker (
Step 3 – LLVM
- Use:
rustc -O --emit=llvm-ir- Compare:
- MIR vs LLVM
- where drops become calls
Big_Picture_Rust_Compilation_Pipeline
https://younghakim7.github.io/blog/posts/big_picture_rust_compilation_pipeline/