Categories
Tags
3d algorithms alignment analyze APIT Arc Architecture arm ascii assembly asynchronous base64 BitHacks Blogging box c c23 clang clang-format client clippy cmake compiler Computer concat concurrency const_fn constexpr contravariant cos covariant cpp cpu crate CS Customization cybersecurity DataStructure db debugging Demo deserialization discrete doc DP drawio dtruss Dynamic emulator example Example FFI flamegraph flat_map fold format FP fsanitize Functional FunctionalProgramming functions futures Fuwari game GATs gcc gccrs generics gitignore glibc GUI hacking hashmap haskell heap hyperfine Imperative interop invariant iterator join justfile kernel LaTeX leak LFU linux lto MachineLearning macOS map Markdown math ML mmap mod nc OnceLock optimization OS ownership panic parallels perf physics pin postgresql product profiling pub radare2 rayon release reverse RPIT rust sanitizer Science science serialization server shift sin size SmallProjects socket std strace String StringView strip strlen struct sum super surrealdb SWAR swisstable synchronous tan thread time toml tracing traits triangulation uint32_t UnsafeRust utf16 utf8 Video vulkan wsl 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/