33<!-- toc -->
44
55Now that we have [ seen what the compiler does] ( ./overview.md ) , let's take a
6- look at the structure of the contents of the rust-lang/rust repo.
6+ look at the structure of the [ ` rust-lang/rust ` ] repository, where the rustc
7+ source code lives.
8+
9+ [ `rust-lang/rust` ] : https://github.com/rust-lang/rust
10+
11+ > You may find it helpful to read the [ "Overview of the compiler"] ( ./overview.md )
12+ > chapter, which introduces how the compiler works, before this one.
713
814## Workspace structure
915
@@ -16,29 +22,17 @@ The repository consists of three main directories:
1622
1723- ` compiler/ ` contains the source code for ` rustc ` . It consists of many crates
1824 that together make up the compiler.
19-
25+
2026- ` library/ ` contains the standard libraries (` core ` , ` alloc ` , ` std ` ,
2127 ` proc_macro ` , ` test ` ), as well as the Rust runtime (` backtrace ` , ` rtstartup ` ,
2228 ` lang_start ` ).
23-
29+
2430- ` src/ ` contains the source code for rustdoc, clippy, cargo, the build system,
25- language docs, etc.
26-
27- ## Standard library
28-
29- The standard library crates are all in ` library/ ` . They have intuitive names
30- like ` std ` , ` core ` , ` alloc ` , etc. There is also ` proc_macro ` , ` test ` , and
31- other runtime libraries.
32-
33- This code is fairly similar to most other Rust crates except that it must be
34- built in a special way because it can use unstable features.
31+ compiler tests, language docs, etc.
3532
3633## Compiler
3734
38- > You may find it helpful to read [ The Overview Chapter] ( ./overview.md ) first,
39- > which gives an overview of how the compiler works. The crates mentioned in
40- > this section implement the compiler, and are underneath ` compiler/ `
41-
35+ The compiler is implemented in the various ` compiler/ ` crates.
4236The ` compiler/ ` crates all have names starting with ` rustc_* ` . These are a
4337collection of around 50 interdependent crates ranging in size from tiny to
4438huge. There is also the ` rustc ` crate which is the actual binary (i.e. the
@@ -87,7 +81,7 @@ explanation of these crates here.
8781
8882### Big picture
8983
90- The dependency structure is influenced strongly by two main factors:
84+ The dependency structure is influenced by two main factors:
9185
92861 . Organization. The compiler is a _ huge_ codebase; it would be an impossibly
9387 large crate. In part, the dependency structure reflects the code structure
@@ -101,12 +95,11 @@ At the very bottom of the dependency tree are a handful of crates that are used
10195by the whole compiler (e.g. [ ` rustc_span ` ] ). The very early parts of the
10296compilation process (e.g. parsing and the AST) depend on only these.
10397
104- Pretty soon after the AST is constructed, the compiler's [ query system] [ query ]
105- gets set up. The query system is set up in a clever way using function
98+ After the AST is constructed and other early analysis is done , the compiler's [ query system] [ query ]
99+ gets set up. The query system is set up in a clever way using function
106100pointers. This allows us to break dependencies between crates, allowing more
107101parallel compilation.
108-
109- However, since the query system is defined in [ ` rustc_middle ` ] , nearly all
102+ The query system is defined in [ ` rustc_middle ` ] , so nearly all
110103subsequent parts of the compiler depend on this crate. It is a really large
111104crate, leading to long compile times. Some efforts have been made to move stuff
112105out of it with limited success. Another unfortunate side effect is that sometimes
@@ -116,7 +109,7 @@ linting functionality is scattered across earlier parts of the crate,
116109
117110[ `rustc_lint` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/index.html
118111
119- More generally, in an ideal world, it seems like there would be fewer, more
112+ Ideally there would be fewer, more
120113cohesive crates, with incremental and parallel compilation making sure compile
121114times stay reasonable. However, our incremental and parallel compilation haven't
122115gotten good enough for that yet, so breaking things into separate crates has
@@ -180,6 +173,15 @@ from `src/tools/`, such as [`tidy`] or [`compiletest`].
180173
181174[ bootstch ] : ./building/bootstrapping.md
182175
176+ ## Standard library
177+
178+ The standard library crates are all in ` library/ ` . They have intuitive names
179+ like ` std ` , ` core ` , ` alloc ` , etc. There is also ` proc_macro ` , ` test ` , and
180+ other runtime libraries.
181+
182+ This code is fairly similar to most other Rust crates except that it must be
183+ built in a special way because it can use unstable features.
184+
183185## Other
184186
185187There are a lot of other things in the ` rust-lang/rust ` repo that are related
0 commit comments