# Understanding the compiler

**URL:** <https://internals.rust-lang.org/t/understanding-the-compiler/5012>\
**Category:** compiler\
**Created:** [March 28, 2017, 9:15am UTC](https://internals.rust-lang.org/t/understanding-the-compiler/5012 "2017-03-28T09:15:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmatos](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pmatos/32/1894_2.png) [@pmatos](https://internals.rust-lang.org/u/pmatos)\
**Post date:** [March 28, 2017, 9:15am UTC](https://internals.rust-lang.org/t/understanding-the-compiler/5012/1 "2017-03-28T09:15:02Z")

</div>

Hello,

I am interested in understanding and learning how the compiler works. I am a compiler engineer and I am currently writing this from EuroLLVM. I am surprised that nobody here has mentioned Rust. I have heard uses LLVM so I am quite surprised no presentations exist discussion how Rust uses LLVM and if there are any specific Rust optimizations, plugins, etc.

Where can I find internals documentation on rustc?

---

<div class="post-metadata">

**Author:** ![killercup](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/killercup/32/3256_2.png) [@killercup](https://internals.rust-lang.org/u/killercup)\
**Post date:** [March 28, 2017, 6:36pm UTC](https://internals.rust-lang.org/t/understanding-the-compiler/5012/2 "2017-03-28T18:36:06Z")

</div>

I’m not a compiler dev, but can provide some links:

- Interesting commits of Rust’s LLVM fork: [https://github.com/rust-lang/llvm/commits/rust-llvm-2016-10-29](https://github.com/rust-lang/llvm/commits/rust-llvm-2016-10-29)
- LLVM stuff in rustc’s repo: [https://github.com/rust-lang/rust/tree/master/src/rustllvm](https://github.com/rust-lang/rust/tree/master/src/rustllvm)
- Rust LLVM bindings: [https://github.com/rust-lang/rust/tree/master/src/librustc\_llvm](https://github.com/rust-lang/rust/tree/master/src/librustc_llvm)

---

<div class="post-metadata">

**Author:** ![hanna-kruppe](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hanna-kruppe/32/6540_2.png) [@hanna-kruppe](https://internals.rust-lang.org/u/hanna-kruppe)\
**Post date:** [March 30, 2017, 8:36pm UTC](https://internals.rust-lang.org/t/understanding-the-compiler/5012/4 "2017-03-30T20:36:26Z")

</div>

The reason for Rust’s absence at LLVM conferences might be that there’s not a lot of _interesting_ interaction between rustc and LLVM, relative to the size of the Rust project. We mostly just generate IR straightforwardly and then run the standard optimization passes on it. While this heavily relies on LLVM as a library, there’s no fancy plugins, no custom optimizations, no complicated encoding of language-specific data in the IR, or anything like that. And while feedback from front ends is obviously important for LLVM, I can’t think of many requirements or complications on top of what any other front end (e.g., clang) faces.

That’s not to say we couldn’t benefit from more interaction with the LLVM community, of course. I’m actually a bit saddened by the state of affairs, but ¯\_(ツ)\_/¯

As for documentation, in addition to what @killercup posted, there’s [the readme of librustc](https://github.com/rust-lang/rust/blob/master/src/librustc/README.md), which sketches a 50,000 feet view of the compiler, and [https://forge.rust-lang.org/](https://forge.rust-lang.org/). Other than that and a couple of blog posts (many of which are very high-level or long outdated), I can’t think of much documentation going into rustc internals. There’s doc comments in the source code, but even those are sparse. It’s quite unfortunate, but in my experience the best source of knowledge about rustc internals is reading the source and asking many, many questions on IRC. (One can also pick up a lot by lurking on the issue tracker, in RFC threads, etc. but this is no way to get up to speed quickly.)

---

<div class="post-metadata">

**Author:** ![tshepang](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tshepang/32/179_2.png) [@tshepang](https://internals.rust-lang.org/u/tshepang)\
**Post date:** [March 6, 2018, 4:55am UTC](https://internals.rust-lang.org/t/understanding-the-compiler/5012/5 "2018-03-06T04:55:15Z")

</div>

There is now [a guide](https://rust-lang-nursery.github.io/rustc-guide).

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:28am UTC](https://internals.rust-lang.org/t/understanding-the-compiler/5012/6 "2019-03-25T08:28:15Z")

</div>

Closed on March 25, 2019, 8:28am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
