@@ -13,33 +13,51 @@ source code lives.
13
13
14
14
## Workspace structure
15
15
16
- The ` rust-lang/rust ` repository consists of a single large cargo workspace
17
- containing the compiler, the standard libraries (` core ` , ` alloc ` , ` std ` ,
18
- ` proc_macro ` , etc), and ` rustdoc ` , along with the build system and a bunch of
16
+ The [ ` rust-lang/rust ` ] repository consists of a single large cargo workspace
17
+ containing the compiler, the standard libraries ([ ` core ` ] , [ ` alloc ` ] , [ ` std ` ] ,
18
+ [ ` proc_macro ` ] , [ ` etc ` ] ), and [ ` rustdoc ` ] , along with the build system and a bunch of
19
19
tools and submodules for building a full Rust distribution.
20
20
21
21
The repository consists of three main directories:
22
22
23
- - ` compiler/ ` contains the source code for ` rustc ` . It consists of many crates
23
+ - [ ` compiler/ ` ] contains the source code for ` rustc ` . It consists of many crates
24
24
that together make up the compiler.
25
25
26
- - ` library/ ` contains the standard libraries (` core ` , ` alloc ` , ` std ` ,
27
- ` proc_macro ` , ` test ` ), as well as the Rust runtime (` backtrace ` , ` rtstartup ` ,
28
- ` lang_start ` ).
26
+ - [ ` library/ ` ] contains the standard libraries (` core ` , ` alloc ` , ` std ` ,
27
+ ` proc_macro ` , [ ` test ` ] ), as well as the Rust runtime ([ ` backtrace ` ] , [ ` rtstartup ` ] ,
28
+ [ ` lang_start ` ] ).
29
29
30
- - ` tests/ ` contains the compiler tests.
30
+ - [ ` tests/ ` ] contains the compiler tests.
31
31
32
- - ` src/ ` contains the source code for rustdoc, clippy, cargo, the build system,
32
+ - [ ` src/ ` ] contains the source code for ` rustdoc ` , [ ` clippy ` ] , [ ` cargo ` ] , the build system,
33
33
language docs, etc.
34
34
35
+ [ `alloc` ] : https://github.com/rust-lang/rust/tree/master/library/alloc
36
+ [ `backtrace` ] : https://github.com/rust-lang/backtrace-rs/
37
+ [ `cargo` ] : https://github.com/rust-lang/cargo
38
+ [ `clippy` ] : https://github.com/rust-lang/rust/tree/master/src/tools/clippy
39
+ [ `compiler/` ] : https://github.com/rust-lang/rust/tree/master/compiler
40
+ [ `core` ] : https://github.com/rust-lang/rust/tree/master/library/core
41
+ [ `etc` ] : https://github.com/rust-lang/rust/tree/master/src/etc
42
+ [ `lang_start` ] : https://github.com/rust-lang/rust/blob/master/library/std/src/rt.rs
43
+ [ `library/` ] : https://github.com/rust-lang/rust/tree/master/library
44
+ [ `proc_macro` ] : https://github.com/rust-lang/rust/tree/master/library/proc_macro
45
+ [ `rtstartup` ] : https://github.com/rust-lang/rust/tree/master/library/rtstartup
46
+ [ `rust-lang/rust` ] : https://github.com/rust-lang/rust
47
+ [ `rustdoc` ] : https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc
48
+ [ `src/` ] : https://github.com/rust-lang/rust/tree/master/src
49
+ [ `std` ] : https://github.com/rust-lang/rust/tree/master/library/std
50
+ [ `test` ] : https://github.com/rust-lang/rust/tree/master/library/test
51
+ [ `tests/` ] : https://github.com/rust-lang/rust/tree/master/tests
52
+
35
53
## Compiler
36
54
37
55
The compiler is implemented in the various ` compiler/ ` crates.
38
56
The ` compiler/ ` crates all have names starting with ` rustc_* ` . These are a
39
57
collection of around 50 interdependent crates ranging in size from tiny to
40
58
huge. There is also the ` rustc ` crate which is the actual binary (i.e. the
41
59
` main ` function); it doesn't actually do anything besides calling the
42
- ` rustc_driver ` crate, which drives the various parts of compilation in other
60
+ [ ` rustc_driver ` ] crate, which drives the various parts of compilation in other
43
61
crates.
44
62
45
63
The dependency structure of these crates is complex, but roughly it is
@@ -58,14 +76,14 @@ something like this:
58
76
[ ` Span ` ] ), or error reporting: [ ` rustc_data_structures ` ] ,
59
77
[ ` rustc_span ` ] , [ ` rustc_errors ` ] , etc.
60
78
61
- [ main ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.main .html
79
+ [ `rustc_data_structures` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/index .html
62
80
[ `rustc_driver` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/index.html
81
+ [ `rustc_errors` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/index.html
63
82
[ `rustc_interface` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
64
83
[ `rustc_middle` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/index.html
65
- [ `rustc_data_structures` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_data_structures/index.html
66
84
[ `rustc_span` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/index.html
67
85
[ `Span` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html
68
- [ `rustc_errors` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/index .html
86
+ [ main ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.main .html
69
87
70
88
You can see the exact dependencies by reading the ` Cargo.toml ` for the various
71
89
crates, just like a normal Rust crate.
@@ -78,8 +96,8 @@ compiler can interface with it.
78
96
Most of this book is about the compiler, so we won't have any further
79
97
explanation of these crates here.
80
98
81
- [ `src/llvm-project` ] : https://github.com/rust-lang/rust/tree/master/src/
82
99
[ `compiler/rustc_llvm` ] : https://github.com/rust-lang/rust/tree/master/compiler/rustc_llvm
100
+ [ `src/llvm-project` ] : https://github.com/rust-lang/rust/tree/master/src/
83
101
84
102
### Big picture
85
103
@@ -104,85 +122,82 @@ parallel compilation.
104
122
The query system is defined in [ ` rustc_middle ` ] , so nearly all
105
123
subsequent parts of the compiler depend on this crate. It is a really large
106
124
crate, leading to long compile times. Some efforts have been made to move stuff
107
- out of it with limited success. Another unfortunate side effect is that sometimes
125
+ out of it with varying success. Another side effect is that sometimes
108
126
related functionality gets scattered across different crates. For example,
109
- linting functionality is scattered across earlier parts of the crate,
127
+ linting functionality is found across earlier parts of the crate,
110
128
[ ` rustc_lint ` ] , [ ` rustc_middle ` ] , and other places.
111
129
112
130
[ `rustc_lint` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/index.html
113
131
114
132
Ideally there would be fewer, more
115
133
cohesive crates, with incremental and parallel compilation making sure compile
116
- times stay reasonable. However, our incremental and parallel compilation haven't
134
+ times stay reasonable. However, incremental and parallel compilation haven't
117
135
gotten good enough for that yet, so breaking things into separate crates has
118
136
been our solution so far.
119
137
120
- At the top of the dependency tree are the [ ` rustc_interface ` ] and
121
- [ ` rustc_driver ` ] crates. [ ` rustc_interface ` ] is an unstable wrapper around the
122
- query system that helps to drive the various stages of compilation. Other
123
- consumers of the compiler may use this interface in different ways (e.g.
124
- rustdoc or maybe eventually rust-analyzer). The [ ` rustc_driver ` ] crate first
125
- parses command line arguments and then uses [ ` rustc_interface ` ] to drive the
126
- compilation to completion.
127
-
128
- [ query ] : ./query.md
138
+ At the top of the dependency tree is [ ` rustc_driver ` ] and [ ` rustc_interface ` ]
139
+ which is an unstable wrapper around the query system helping drive various
140
+ stages of compilation. Other consumers of the compiler may use this interface
141
+ in different ways (e.g. ` rustdoc ` or maybe eventually ` rust-analyzer ` ). The
142
+ [ ` rustc_driver ` ] crate first parses command line arguments and then uses
143
+ [ ` rustc_interface ` ] to drive the compilation to completion.
129
144
130
145
[ orgch ] : ./overview.md
146
+ [ query ] : ./query.md
131
147
132
148
## rustdoc
133
149
134
150
The bulk of ` rustdoc ` is in [ ` librustdoc ` ] . However, the ` rustdoc ` binary
135
151
itself is [ ` src/tools/rustdoc ` ] , which does nothing except call [ ` rustdoc::main ` ] .
136
152
137
- There is also javascript and CSS for the rustdocs in [ ` src/tools/rustdoc-js ` ]
153
+ There is also JavaScript and CSS for the docs in [ ` src/tools/rustdoc-js ` ]
138
154
and [ ` src/tools/rustdoc-themes ` ] .
139
155
140
- You can read more about rustdoc in [ this chapter] [ rustdocch ] .
156
+ You can read more about ` rustdoc ` in [ this chapter] [ rustdocch ] .
141
157
142
158
[ `librustdoc` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/index.html
143
159
[ `rustdoc::main` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/fn.main.html
144
- [ `src/tools/rustdoc` ] : https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc
145
160
[ `src/tools/rustdoc-js` ] : https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc-js
146
161
[ `src/tools/rustdoc-themes` ] : https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc-themes
147
-
162
+ [ `src/tools/rustdoc` ] : https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc
148
163
[ rustdocch ] : ./rustdoc.md
149
164
150
165
## Tests
151
166
152
167
The test suite for all of the above is in [ ` tests/ ` ] . You can read more
153
168
about the test suite [ in this chapter] [ testsch ] .
154
169
155
- The test harness itself is in [ ` src/tools/compiletest ` ] .
156
-
157
- [ testsch ] : ./tests/intro.md
170
+ The test harness is in [ ` src/tools/compiletest ` ] .
158
171
159
- [ `tests/` ] : https://github.com/rust-lang/rust/tree/master/tests
160
172
[ `src/tools/compiletest` ] : https://github.com/rust-lang/rust/tree/master/src/tools/compiletest
173
+ [ `tests/` ] : https://github.com/rust-lang/rust/tree/master/tests
174
+ [ testsch ] : ./tests/intro.md
161
175
162
176
## Build System
163
177
164
178
There are a number of tools in the repository just for building the compiler,
165
- standard library, rustdoc, etc, along with testing, building a full Rust
179
+ standard library, ` rustdoc ` , etc, along with testing, building a full Rust
166
180
distribution, etc.
167
181
168
182
One of the primary tools is [ ` src/bootstrap ` ] . You can read more about
169
183
bootstrapping [ in this chapter] [ bootstch ] . The process may also use other tools
170
- from ` src/tools/ ` , such as [ ` tidy ` ] or [ ` compiletest ` ] .
184
+ from [ ` src/tools/ ` ] , such as [ ` tidy ` ] or [ ` compiletest ` ] .
171
185
186
+ [ `compiletest` ] : https://github.com/rust-lang/rust/tree/master/src/tools/compiletest
172
187
[ `src/bootstrap` ] : https://github.com/rust-lang/rust/tree/master/src/bootstrap
188
+ [ `src/tools/` ] : https://github.com/rust-lang/rust/tree/master/src/tools
173
189
[ `tidy` ] : https://github.com/rust-lang/rust/tree/master/src/tools/tidy
174
- [ `compiletest` ] : https://github.com/rust-lang/rust/tree/master/src/tools/compiletest
175
-
176
190
[ bootstch ] : ./building/bootstrapping.md
177
191
178
- ## Standard library
192
+ ## Standard library ( ` libstd ` )
179
193
180
194
The standard library crates are all in ` library/ ` . They have intuitive names
181
195
like ` std ` , ` core ` , ` alloc ` , etc. There is also ` proc_macro ` , ` test ` , and
182
- other runtime libraries.
196
+ other runtime libraries. The standard library is sometimes referred to
197
+ formally as ` libstd ` .
183
198
184
199
This code is fairly similar to most other Rust crates except that it must be
185
- built in a special way because it can use unstable features.
200
+ built in a special way because it can use unstable ( ` nightly ` ) features.
186
201
187
202
## Other
188
203
0 commit comments