Skip to content

Commit 2c54ffb

Browse files
pierwillcamelidJohnTitor
authored
Edit the "Compiler Source Code" chapter (rust-lang#1307)
Co-authored-by: Noah Lev <camelidcamel@gmail.com> Co-authored-by: pierwill <pierwill@users.noreply.github.com> Co-authored-by: Yuki Okushi <jtitor@2k36.org>
1 parent 8912c34 commit 2c54ffb

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/doc/rustc-dev-guide/src/compiler-src.md

+25-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
<!-- toc -->
44

55
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.
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.
4236
The `compiler/` crates all have names starting with `rustc_*`. These are a
4337
collection of around 50 interdependent crates ranging in size from tiny to
4438
huge. 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

9286
1. 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
10195
by the whole compiler (e.g. [`rustc_span`]). The very early parts of the
10296
compilation 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
106100
pointers. This allows us to break dependencies between crates, allowing more
107101
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
110103
subsequent parts of the compiler depend on this crate. It is a really large
111104
crate, leading to long compile times. Some efforts have been made to move stuff
112105
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,
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
120113
cohesive crates, with incremental and parallel compilation making sure compile
121114
times stay reasonable. However, our incremental and parallel compilation haven't
122115
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`].
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

185187
There are a lot of other things in the `rust-lang/rust` repo that are related

0 commit comments

Comments
 (0)