Skip to content

Commit 01300b5

Browse files
authored
Merge pull request rust-lang#2849 from rust-lang/tshepang/sembr
sembr some files
2 parents 8280340 + ea6d646 commit 01300b5

5 files changed

Lines changed: 68 additions & 45 deletions

File tree

src/building/prerequisites.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,44 @@ See [the `rust-lang/rust` INSTALL](https://github.com/rust-lang/rust/blob/HEAD/I
66

77
## Hardware
88

9-
You will need an internet connection to build. The bootstrapping process
10-
involves updating git submodules and downloading a beta compiler. It doesn't
11-
need to be super fast, but that can help.
9+
You will need an internet connection to build.
10+
The bootstrapping process
11+
involves updating git submodules and downloading a beta compiler.
12+
It doesn't need to be super fast, but that can help.
1213

1314
There are no strict hardware requirements, but building the compiler is
1415
computationally expensive, so a beefier machine will help, and I wouldn't
15-
recommend trying to build on a Raspberry Pi! We recommend the following.
16-
* 30GB+ of free disk space. Otherwise, you will have to keep
17-
clearing incremental caches. More space is better, the compiler is a bit of a
16+
recommend trying to build on a Raspberry Pi!
17+
We recommend the following.
18+
* 30GB+ of free disk space.
19+
Otherwise, you will have to keep clearing incremental caches.
20+
More space is better, the compiler is a bit of a
1821
hog; it's a problem we are aware of.
1922
* 8GB+ RAM
20-
* 2+ cores. Having more cores really helps. 10 or 20 or more is not too many!
23+
* 2+ cores.
24+
Having more cores really helps.
25+
10 or 20 or more is not too many!
2126

22-
Beefier machines will lead to much faster builds. If your machine is not very
23-
powerful, a common strategy is to only use `./x check` on your local machine
27+
Beefier machines will lead to much faster builds.
28+
If your machine is not very powerful,
29+
a common strategy is to only use `./x check` on your local machine
2430
and let the CI build test your changes when you push to a PR branch.
2531

26-
Building the compiler takes more than half an hour on my moderately powerful
27-
laptop. We suggest downloading LLVM from CI so you don't have to build it from source
32+
Building the compiler takes more than half an hour on a moderately powerful
33+
laptop.
34+
We suggest downloading LLVM from CI so you don't have to build it from source
2835
([see here][config]).
2936

30-
Like `cargo`, the build system will use as many cores as possible. Sometimes
31-
this can cause you to run low on memory. You can use `-j` to adjust the number
32-
of concurrent jobs. If a full build takes more than ~45 minutes to an hour, you
37+
Like `cargo`, the build system will use as many cores as possible.
38+
Sometimes this can cause you to run low on memory.
39+
You can use `-j` to adjust the number of concurrent jobs.
40+
If a full build takes more than ~45 minutes to an hour, you
3341
are probably spending most of the time swapping memory in and out; try using
3442
`-j1`.
3543

3644
If you don't have too much free disk space, you may want to turn off
37-
incremental compilation ([see here][config]). This will make compilation take
45+
incremental compilation ([see here][config]).
46+
This will make compilation take
3847
longer (especially after a rebase), but will save a ton of space from the
3948
incremental caches.
4049

src/building/suggested.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ For Neovim users, there are a few options:
154154
#### neoconf.nvim
155155

156156
[neoconf.nvim][neoconf.nvim] allows for project-local configuration
157-
files with the native LSP. The steps for how to use it are below. Note that they require
158-
rust-analyzer to already be configured with Neovim. Steps for this can be
159-
[found here][r-a nvim lsp].
157+
files with the native LSP.
158+
The steps for how to use it are below.
159+
Note that they require rust-analyzer to already be configured with Neovim.
160+
Steps for this can be [found here][r-a nvim lsp].
160161

161162
1. First install the plugin.
162163
This can be done by following the steps in the README.

src/mir/construction.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ list of items:
1111
* Drop code (the `Drop::drop` function is not called directly)
1212
* Drop implementations of types without an explicit `Drop` implementation
1313

14-
The lowering is triggered by calling the [`mir_built`] query. The MIR builder does
15-
not actually use the HIR but operates on the [THIR] instead, processing THIR
16-
expressions recursively.
14+
The lowering is triggered by calling the [`mir_built`] query.
15+
The MIR builder does not actually use the HIR,
16+
but operates on the [THIR] instead,
17+
processing THIR expressions recursively.
1718

1819
The lowering creates local variables for every argument as specified in the signature.
1920
Next, it creates local variables for every binding specified (e.g. `(a, b): (i32, String)`)
20-
produces 3 bindings, one for the argument, and two for the bindings. Next, it generates
21-
field accesses that read the fields from the argument and writes the value to the binding
22-
variable.
21+
produces 3 bindings, one for the argument, and two for the bindings.
22+
Next,
23+
it generates field accesses that read the fields from the argument,
24+
and writes the value to the binding variable.
2325

2426
With this initialization out of the way, the lowering triggers a recursive call
2527
to a function that generates the MIR for the body (a `Block` expression) and
@@ -52,7 +54,8 @@ fn generate_more_mir(&mut self, block: BasicBlock) -> BlockAnd<ResultType> {
5254
```
5355

5456
When you invoke these functions, it is common to have a local variable `block`
55-
that is effectively a "cursor". It represents the point at which we are adding new MIR.
57+
that is effectively a "cursor".
58+
It represents the point at which we are adding new MIR.
5659
When you invoke `generate_more_mir`, you want to update this cursor.
5760
You can do this manually, but it's tedious:
5861

@@ -89,18 +92,21 @@ representations:
8992

9093
We start out with lowering the function body to an `Rvalue` so we can create an
9194
assignment to `RETURN_PLACE`, This `Rvalue` lowering will in turn trigger lowering to
92-
`Operand` for its arguments (if any). `Operand` lowering either produces a `const`
93-
operand, or moves/copies out of a `Place`, thus triggering a `Place` lowering. An
94-
expression being lowered to a `Place` can in turn trigger a temporary to be created
95-
if the expression being lowered contains operations. This is where the snake bites its
95+
`Operand` for its arguments (if any).
96+
`Operand` lowering either produces a `const` operand,
97+
or moves/copies out of a `Place`, thus triggering a `Place` lowering.
98+
An expression being lowered to a `Place` can in turn trigger a temporary to be created
99+
if the expression being lowered contains operations.
100+
This is where the snake bites its
96101
own tail and we need to trigger an `Rvalue` lowering for the expression to be written
97102
into the local.
98103

99104
## Operator lowering
100105

101106
Operators on builtin types are not lowered to function calls (which would end up being
102107
infinite recursion calls, because the trait impls just contain the operation itself
103-
again). Instead there are `Rvalue`s for binary and unary operators and index operations.
108+
again).
109+
Instead there are `Rvalue`s for binary and unary operators and index operations.
104110
These `Rvalue`s later get codegened to llvm primitive operations or llvm intrinsics.
105111

106112
Operators on all other types get lowered to a function call to their `impl` of the
@@ -118,7 +124,8 @@ In [MIR] there is no difference between method calls and function calls anymore.
118124
## Conditions
119125

120126
`if` conditions and `match` statements for `enum`s with variants that have no fields are
121-
lowered to `TerminatorKind::SwitchInt`. Each possible value (so `0` and `1` for `if`
127+
lowered to `TerminatorKind::SwitchInt`.
128+
Each possible value (so `0` and `1` for `if`
122129
conditions) has a corresponding `BasicBlock` to which the code continues.
123130
The argument being branched on is (again) an `Operand` representing the value of
124131
the if condition.
@@ -127,14 +134,14 @@ the if condition.
127134

128135
`match` statements for `enum`s with variants that have fields are lowered to
129136
`TerminatorKind::SwitchInt`, too, but the `Operand` refers to a `Place` where the
130-
discriminant of the value can be found. This often involves reading the discriminant
131-
to a new temporary variable.
137+
discriminant of the value can be found.
138+
This often involves reading the discriminant to a new temporary variable.
132139

133140
## Aggregate construction
134141

135142
Aggregate values of any kind (e.g. structs or tuples) are built via `Rvalue::Aggregate`.
136-
All fields are
137-
lowered to `Operator`s. This is essentially equivalent to one assignment
143+
All fields are lowered to `Operator`s.
144+
This is essentially equivalent to one assignment
138145
statement per aggregate field plus an assignment to the discriminant in the
139146
case of `enum`s.
140147

src/name-resolution.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ files and expanding `macros`.
6262
This phase produces links from all the names in the
6363
source to relevant places where the name was introduced.
6464
It also generates helpful error messages,
65-
like typo suggestions, traits to import or lints about
66-
unused items.
65+
like typo suggestions, traits to import, or lints about unused items.
6766

6867
A successful run of the second phase ([`Resolver::resolve_crate`]) creates kind
6968
of an index the rest of the compilation may use to ask about the present names

src/thir.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,37 @@ the types have been filled in, which is possible after type checking has complet
1515
But it has some other interesting features that distinguish it from the HIR:
1616

1717
- Like the MIR, the THIR only represents bodies, i.e. "executable code"; this includes
18-
function bodies, but also `const` initializers, for example. Specifically, all [body owners] have
19-
THIR created. Consequently, the THIR has no representation for items like `struct`s or `trait`s.
18+
function bodies, but also `const` initializers, for example.
19+
Specifically, all [body owners] have THIR created.
20+
Consequently, the THIR has no representation for items like `struct`s or `trait`s.
2021

2122
- Each body of THIR is only stored temporarily and is dropped as soon as it's no longer
2223
needed, as opposed to being stored until the end of the compilation process (which
2324
is what is done with the HIR).
2425

2526
- Besides making the types of all nodes available, the THIR also has additional
26-
desugaring compared to the HIR. For example, automatic references and dereferences
27+
desugaring compared to the HIR.
28+
For example, automatic references and dereferences
2729
are made explicit, and method calls and overloaded operators are converted into
28-
plain function calls. Destruction scopes are also made explicit.
30+
plain function calls.
31+
Destruction scopes are also made explicit.
2932

30-
- Statements, expressions, match arms, blocks, and parameters are stored separately. For example,
33+
- Statements, expressions, match arms, blocks, and parameters are stored separately.
34+
For example,
3135
statements in the `stmts` array reference expressions by their index (represented as a
3236
[`ExprId`]) in the `exprs` array.
3337

3438
[HIR]: ./hir.md
3539
[`ExprId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/thir/struct.ExprId.html
3640
[body owners]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.BodyOwnerKind.html
3741

38-
The THIR lives in [`rustc_mir_build::thir`][thir-docs]. To construct a [`thir::Expr`],
42+
The THIR lives in [`rustc_mir_build::thir`][thir-docs].
43+
To construct a [`thir::Expr`],
3944
you can use the [`thir_body`] function, passing in the memory arena where the THIR
40-
will be allocated. Dropping this arena will result in the THIR being destroyed,
41-
which is useful to keep peak memory in check. Having a THIR representation of
45+
will be allocated.
46+
Dropping this arena will result in the THIR being destroyed,
47+
which is useful to keep peak memory in check.
48+
Having a THIR representation of
4249
all bodies of a crate in memory at the same time would be very heavy.
4350

4451
You can get a debug representation of the THIR by passing the `-Zunpretty=thir-tree` flag

0 commit comments

Comments
 (0)