3
3
<!-- toc -->
4
4
5
5
Now 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.
7
13
8
14
## Workspace structure
9
15
@@ -16,29 +22,17 @@ The repository consists of three main directories:
16
22
17
23
- ` compiler/ ` contains the source code for ` rustc ` . It consists of many crates
18
24
that together make up the compiler.
19
-
25
+
20
26
- ` library/ ` contains the standard libraries (` core ` , ` alloc ` , ` std ` ,
21
27
` proc_macro ` , ` test ` ), as well as the Rust runtime (` backtrace ` , ` rtstartup ` ,
22
28
` lang_start ` ).
23
-
29
+
24
30
- ` 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.
35
32
36
33
## Compiler
37
34
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.
42
36
The ` compiler/ ` crates all have names starting with ` rustc_* ` . These are a
43
37
collection of around 50 interdependent crates ranging in size from tiny to
44
38
huge. There is also the ` rustc ` crate which is the actual binary (i.e. the
@@ -87,7 +81,7 @@ explanation of these crates here.
87
81
88
82
### Big picture
89
83
90
- The dependency structure is influenced strongly by two main factors:
84
+ The dependency structure is influenced by two main factors:
91
85
92
86
1 . Organization. The compiler is a _ huge_ codebase; it would be an impossibly
93
87
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
101
95
by the whole compiler (e.g. [ ` rustc_span ` ] ). The very early parts of the
102
96
compilation process (e.g. parsing and the AST) depend on only these.
103
97
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
106
100
pointers. This allows us to break dependencies between crates, allowing more
107
101
parallel 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
110
103
subsequent parts of the compiler depend on this crate. It is a really large
111
104
crate, leading to long compile times. Some efforts have been made to move stuff
112
105
out 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,
116
109
117
110
[ `rustc_lint` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/index.html
118
111
119
- More generally, in an ideal world, it seems like there would be fewer, more
112
+ Ideally there would be fewer, more
120
113
cohesive crates, with incremental and parallel compilation making sure compile
121
114
times stay reasonable. However, our incremental and parallel compilation haven't
122
115
gotten good enough for that yet, so breaking things into separate crates has
@@ -180,6 +173,15 @@ from `src/tools/`, such as [`tidy`] or [`compiletest`].
180
173
181
174
[ bootstch ] : ./building/bootstrapping.md
182
175
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
+
183
185
## Other
184
186
185
187
There are a lot of other things in the ` rust-lang/rust ` repo that are related
0 commit comments