Skip to content

Commit cab38bc

Browse files
committed
revisions
1 parent 275468c commit cab38bc

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/compiler-src.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22

33
<!-- toc -->
44

5-
Now that we have [seen what the compiler does](./overview.md), let's take a
5+
Now that we have [seen what the compiler does][orgch], let's take a
66
look at the structure of the [`rust-lang/rust`] repository, where the rustc
77
source code lives.
88

99
[`rust-lang/rust`]: https://github.com/rust-lang/rust
1010

11-
> You may find it helpful to read the ["Overview of the compiler"](./overview.md)
11+
> You may find it helpful to read the ["Overview of the compiler"][orgch]
1212
> chapter, which introduces how the compiler works, before this one.
1313
14+
[orgch]: ./overview.md
15+
1416
## Workspace structure
1517

1618
The [`rust-lang/rust`] repository consists of a single large cargo workspace
1719
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-
tools and submodules for building a full Rust distribution.
20+
[`proc_macro`], [`etc`]), and [`rustdoc`], along with the build system and a
21+
bunch of tools and submodules for building a full Rust distribution.
2022

2123
The repository consists of three main directories:
2224

2325
- [`compiler/`] contains the source code for `rustc`. It consists of many crates
2426
that together make up the compiler.
2527

26-
- [`library/`] contains the standard libraries (`core`, `alloc`, `std`,
27-
`proc_macro`, [`test`]), as well as the Rust runtime ([`backtrace`], [`rtstartup`],
28+
- [`library/`] contains the standard libraries ([`core`], [`alloc`], [`std`],
29+
[`proc_macro`], [`test`]), as well as the Rust runtime ([`backtrace`], [`rtstartup`],
2830
[`lang_start`]).
2931

3032
- [`tests/`] contains the compiler tests.
3133

32-
- [`src/`] contains the source code for `rustdoc`, [`clippy`], [`cargo`], the build system,
34+
- [`src/`] contains the source code for [`rustdoc`], [`clippy`], [`cargo`], the build system,
3335
language docs, etc.
3436

3537
[`alloc`]: https://github.com/rust-lang/rust/tree/master/library/alloc
@@ -85,7 +87,7 @@ something like this:
8587
[`Span`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html
8688
[main]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.main.html
8789

88-
You can see the exact dependencies by reading the `Cargo.toml` for the various
90+
You can see the exact dependencies by reading the [`Cargo.toml`] for the various
8991
crates, just like a normal Rust crate.
9092

9193
One final thing: [`src/llvm-project`] is a submodule for our fork of LLVM.
@@ -98,42 +100,40 @@ explanation of these crates here.
98100

99101
[`compiler/rustc_llvm`]: https://github.com/rust-lang/rust/tree/master/compiler/rustc_llvm
100102
[`src/llvm-project`]: https://github.com/rust-lang/rust/tree/master/src/
103+
[`Cargo.toml`]: https://github.com/rust-lang/rust/blob/master/Cargo.toml
101104

102105
### Big picture
103106

104-
The dependency structure is influenced by two main factors:
107+
The dependency structure of Rust is influenced by two main factors:
105108

106109
1. Organization. The compiler is a _huge_ codebase; it would be an impossibly
107110
large crate. In part, the dependency structure reflects the code structure
108-
of the compiler.
109-
2. Compile time. By breaking the compiler into multiple crates, we can take
111+
of the compiler. Restructuring `rust-lang/rust` as a monorepo is an ongoing
112+
debate with convincing technical and qualitative arguments for and against.
113+
2. Compile-time. By breaking the compiler into multiple crates, we can take
110114
better advantage of incremental/parallel compilation using cargo. In
111115
particular, we try to have as few dependencies between crates as possible so
112116
that we don't have to rebuild as many crates if you change one.
113117

114118
At the very bottom of the dependency tree are a handful of crates that are used
115119
by the whole compiler (e.g. [`rustc_span`]). The very early parts of the
116-
compilation process (e.g. parsing and the AST) depend on only these.
117-
118-
After the AST is constructed and other early analysis is done, the compiler's [query system][query]
119-
gets set up. The query system is set up in a clever way using function
120-
pointers. This allows us to break dependencies between crates, allowing more
121-
parallel compilation.
122-
The query system is defined in [`rustc_middle`], so nearly all
123-
subsequent parts of the compiler depend on this crate. It is a really large
124-
crate, leading to long compile times. Some efforts have been made to move stuff
125-
out of it with varying success. Another side effect is that sometimes
126-
related functionality gets scattered across different crates. For example,
127-
linting functionality is found across earlier parts of the crate,
128-
[`rustc_lint`], [`rustc_middle`], and other places.
129-
130-
[`rustc_lint`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/index.html
131-
132-
Ideally there would be fewer, more
133-
cohesive crates, with incremental and parallel compilation making sure compile
134-
times stay reasonable. However, incremental and parallel compilation haven't
135-
gotten good enough for that yet, so breaking things into separate crates has
136-
been our solution so far.
120+
compilation process (e.g. [parsing and the Abstract Syntax Tree (`AST`)][parser])
121+
depend on only these.
122+
123+
After the `AST` is constructed and other early analysis is done, the compiler's
124+
[query system][query] gets set up. The query system is set up in a clever way
125+
using function pointers. This allows us to break dependencies between crates,
126+
allowing more parallel compilation. The query system is defined in
127+
[`rustc_middle`], so nearly all subsequent parts of the compiler depend on this
128+
crate. It is a really large crate, leading to long compile times. Some efforts
129+
have been made to move stuff out of it with varying success. Another side-effect is that sometimes related functionality gets scattered across different
130+
crates. For example, linting functionality is found across earlier parts of the
131+
crate, [`rustc_lint`], [`rustc_middle`], and other places.
132+
133+
Ideally there would be fewer, more cohesive crates, with incremental and
134+
parallel compilation making sure compile times stay reasonable. However,
135+
incremental and parallel compilation haven't gotten good enough for that yet,
136+
so breaking things into separate crates has been our solution so far.
137137

138138
At the top of the dependency tree is [`rustc_driver`] and [`rustc_interface`]
139139
which is an unstable wrapper around the query system helping drive various
@@ -142,15 +142,16 @@ in different ways (e.g. `rustdoc` or maybe eventually `rust-analyzer`). The
142142
[`rustc_driver`] crate first parses command line arguments and then uses
143143
[`rustc_interface`] to drive the compilation to completion.
144144

145-
[orgch]: ./overview.md
145+
[parser]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/index.html
146+
[`rustc_lint`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/index.html
146147
[query]: ./query.md
147148

148149
## rustdoc
149150

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

153-
There is also JavaScript and CSS for the docs in [`src/tools/rustdoc-js`]
154+
There is also `JavaScript` and `CSS` for the docs in [`src/tools/rustdoc-js`]
154155
and [`src/tools/rustdoc-themes`].
155156

156157
You can read more about `rustdoc` in [this chapter][rustdocch].
@@ -193,17 +194,16 @@ from [`src/tools/`], such as [`tidy`] or [`compiletest`].
193194

194195
The standard library crates are all in `library/`. They have intuitive names
195196
like `std`, `core`, `alloc`, etc. There is also `proc_macro`, `test`, and
196-
other runtime libraries. The standard library is sometimes referred to
197-
formally as `libstd`.
197+
other runtime libraries. The standard library is sometimes referred to as
198+
`libstd`.
198199

199200
This code is fairly similar to most other Rust crates except that it must be
200201
built in a special way because it can use unstable (`nightly`) features.
201202

202203
## Other
203204

204205
There are a lot of other things in the `rust-lang/rust` repo that are related
205-
to building a full Rust distribution. Most of the time you don't need to worry
206-
about them.
206+
to building a full Rust distribution. Most of the time you don't need to worry about them.
207207

208208
These include:
209209
- [`src/ci`]: The CI configuration. This actually quite extensive because we

0 commit comments

Comments
 (0)