Skip to content

Commit 275468c

Browse files
author
Tbkhi
authored
Update compiler-src.md
Various link additions and minor edits for clarity.
1 parent 7b0ef5b commit 275468c

File tree

1 file changed

+56
-41
lines changed

1 file changed

+56
-41
lines changed

src/compiler-src.md

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,51 @@ source code lives.
1313
1414
## Workspace structure
1515

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
1919
tools and submodules for building a full Rust distribution.
2020

2121
The repository consists of three main directories:
2222

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
2424
that together make up the compiler.
2525

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`]).
2929

30-
- `tests/` contains the compiler tests.
30+
- [`tests/`] contains the compiler tests.
3131

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,
3333
language docs, etc.
3434

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+
3553
## Compiler
3654

3755
The compiler is implemented in the various `compiler/` crates.
3856
The `compiler/` crates all have names starting with `rustc_*`. These are a
3957
collection of around 50 interdependent crates ranging in size from tiny to
4058
huge. There is also the `rustc` crate which is the actual binary (i.e. the
4159
`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
4361
crates.
4462

4563
The dependency structure of these crates is complex, but roughly it is
@@ -58,14 +76,14 @@ something like this:
5876
[`Span`]), or error reporting: [`rustc_data_structures`],
5977
[`rustc_span`], [`rustc_errors`], etc.
6078

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
6280
[`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
6382
[`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html
6483
[`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
6684
[`rustc_span`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/index.html
6785
[`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
6987

7088
You can see the exact dependencies by reading the `Cargo.toml` for the various
7189
crates, just like a normal Rust crate.
@@ -78,8 +96,8 @@ compiler can interface with it.
7896
Most of this book is about the compiler, so we won't have any further
7997
explanation of these crates here.
8098

81-
[`src/llvm-project`]: https://github.com/rust-lang/rust/tree/master/src/
8299
[`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/
83101

84102
### Big picture
85103

@@ -104,85 +122,82 @@ parallel compilation.
104122
The query system is defined in [`rustc_middle`], so nearly all
105123
subsequent parts of the compiler depend on this crate. It is a really large
106124
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
108126
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,
110128
[`rustc_lint`], [`rustc_middle`], and other places.
111129

112130
[`rustc_lint`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/index.html
113131

114132
Ideally there would be fewer, more
115133
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
117135
gotten good enough for that yet, so breaking things into separate crates has
118136
been our solution so far.
119137

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.
129144

130145
[orgch]: ./overview.md
146+
[query]: ./query.md
131147

132148
## rustdoc
133149

134150
The bulk of `rustdoc` is in [`librustdoc`]. However, the `rustdoc` binary
135151
itself is [`src/tools/rustdoc`], which does nothing except call [`rustdoc::main`].
136152

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`]
138154
and [`src/tools/rustdoc-themes`].
139155

140-
You can read more about rustdoc in [this chapter][rustdocch].
156+
You can read more about `rustdoc` in [this chapter][rustdocch].
141157

142158
[`librustdoc`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/index.html
143159
[`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
145160
[`src/tools/rustdoc-js`]: https://github.com/rust-lang/rust/tree/master/src/tools/rustdoc-js
146161
[`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
148163
[rustdocch]: ./rustdoc.md
149164

150165
## Tests
151166

152167
The test suite for all of the above is in [`tests/`]. You can read more
153168
about the test suite [in this chapter][testsch].
154169

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`].
158171

159-
[`tests/`]: https://github.com/rust-lang/rust/tree/master/tests
160172
[`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
161175

162176
## Build System
163177

164178
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
166180
distribution, etc.
167181

168182
One of the primary tools is [`src/bootstrap`]. You can read more about
169183
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`].
171185

186+
[`compiletest`]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest
172187
[`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
173189
[`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-
176190
[bootstch]: ./building/bootstrapping.md
177191

178-
## Standard library
192+
## Standard library (`libstd`)
179193

180194
The standard library crates are all in `library/`. They have intuitive names
181195
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`.
183198

184199
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.
186201

187202
## Other
188203

0 commit comments

Comments
 (0)