Skip to content

Commit 69848f3

Browse files
mark-i-mCentril
andauthored
Apply Centril suggestions
Co-Authored-By: Mazdak Farrokhzad <[email protected]>
1 parent 744d7dc commit 69848f3

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/overview.md

+13-14
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ we'll talk about that later.
5050
doesn't seem to be able to optimize the pattern the [`simplify_try`] mir
5151
opt looks for.
5252
- Rust code is _monomorphized_, which means making copies of all the generic
53-
code with the type parameters replaced by concrete types. In order to do
53+
code with the type parameters replaced by concrete types. To do
5454
this, we need to collect a list of what concrete types to generate code for.
5555
This is called _monomorphization collection_.
5656
- We then begin what is vaguely called _code generation_ or _codegen_.
@@ -105,7 +105,7 @@ satisfy/optimize for. For example,
105105
- Compiler compilation speed: how long does it take to compile the compiler?
106106
This impacts contributors and compiler maintenance.
107107
- Compiler implementation complexity: building a compiler is one of the hardest
108-
things a person/group can do, and rust is not a very simple language, so how
108+
things a person/group can do, and Rust is not a very simple language, so how
109109
do we make the compiler's code base manageable?
110110
- Compiler correctness: the binaries produced by the compiler should do what
111111
the input programs says they do, and should continue to do so despite the
@@ -119,14 +119,13 @@ satisfy/optimize for. For example,
119119
always going on to its implementation.
120120
- Limitations of other tools: rustc uses LLVM in its backend, and LLVM has some
121121
strengths we leverage and some limitations/weaknesses we need to work around.
122-
- And others that I'm probably forgetting.
123122

124123
So, as you read through the rest of the guide, keep these things in mind. They
125124
will often inform decisions that we make.
126125

127126
### Constant change
128127

129-
One thing to keep in mind is that `rustc` is a real production-quality product.
128+
Keep in mind that `rustc` is a real production-quality product.
130129
As such, it has its fair share of codebase churn and technical debt. A lot of
131130
the designs discussed throughout this guide are idealized designs that are not
132131
fully realized yet. And things keep changing so that it is hard to keep this
@@ -139,19 +138,19 @@ to keep up with the requirements above.
139138

140139
As with most compilers, `rustc` uses some intermediate representations (IRs) to
141140
facilitate computations. In general, working directly with the source code is
142-
extremely inconvenient. Source code is designed to be human-friendly while at
141+
extremely inconvenient and error-prone. Source code is designed to be human-friendly while at
143142
the same time being unambiguous, but it's less convenient for doing something
144143
like, say, type checking.
145144

146145
Instead most compilers, including `rustc`, build some sort of IR out of the
147146
source code which is easier to analyze. `rustc` has a few IRs, each optimized
148-
for different things:
147+
for different purposes:
149148

150149
- Abstract Syntax Tree (AST): the abstract syntax tree is built from the stream
151150
of tokens produced by the lexer directly from the source code. It represents
152151
pretty much exactly what the user wrote. It helps to do some syntactic sanity
153152
checking (e.g. checking that a type is expected where the user wrote one).
154-
- High-level IR (HIR): This is a sort of very desugared AST. It's still close
153+
- High-level IR (HIR): This is a sort of desugared AST. It's still close
155154
to what the user wrote syntactically, but it includes some implicit things
156155
such as some elided lifetimes, etc. This IR is amenable to type checking.
157156
- HAIR: This is an intermediate between HIR and MIR. This only exists to make
@@ -160,13 +159,13 @@ for different things:
160159
is a type of diagram that shows the basic blocks of a program and how control
161160
flow can go between them. Likewise, MIR also has a bunch of basic blocks with
162161
simple typed statements inside them (e.g. assignment, simple computations,
163-
dropping values, etc). MIR is used for borrow checking and a bunch of other
162+
dropping values, etc). MIR is used for borrow checking and other
164163
important dataflow based checks, such as checking for uninitialized values.
165164
It is also used for a bunch of optimizations and for constant evaluation (via
166165
MIRI). Because MIR is still generic, we can do a lot of analyses here more
167166
efficiently than after monomorphization.
168167
- LLVM IR: This is the standard form of all input to the LLVM compiler. LLVM IR
169-
is basically a sort of typed assembly language with lots of annotations. It's
168+
is a sort of typed assembly language with lots of annotations. It's
170169
a standard format that is used by all compilers that use LLVM (e.g. the clang
171170
C compiler also outputs LLVM IR). LLVM IR is designed to be easy for other
172171
compilers to emit and also rich enough for LLVM to run a bunch of
@@ -181,9 +180,9 @@ compiler does this to make incremental compilation possible -- that is, if the
181180
user makes a change to their program and recompiles, we want to do as little
182181
redundant work as possible to produce the new binary.
183182

184-
In rustc, all the major steps above are organized as a bunch of queries that
183+
In `rustc`, all the major steps above are organized as a bunch of queries that
185184
call each other. For example, there is a query to ask for the type of something
186-
and another to ask for the optimized MIR of a function, and so on. These
185+
and another to ask for the optimized MIR of a function. These
187186
queries can call each other and are all tracked through the query system, and
188187
the results of the queries are cached on disk so that we can tell which
189188
queries' results changed from the last compilation and only redo those. This is
@@ -209,7 +208,7 @@ to remain to ensure that unreachable functions still have their errors emitted.
209208

210209
Moreover, the compiler wasn't originally built to use a query system; the query
211210
system has been retrofitted into the compiler, so parts of it are not
212-
query-fied yet. Also, LLVM isn't our code, so obviously that isn't querified
211+
query-fied yet. Also, LLVM isn't our code, so that isn't querified
213212
either. The plan is to eventually query-fy all of the steps listed in the
214213
previous section, but as of this writing, only the steps between HIR and
215214
LLVM-IR are query-fied. That is, lexing and parsing are done all at once for
@@ -239,8 +238,8 @@ Oh, and also the `rustc::ty` module defines the `TyCtxt` struct we mentioned bef
239238

240239
### Parallelism
241240

242-
Compiler performance is a problem that we would very much like to improve on
243-
(and are always working on). One aspect of that is attempting to parallelize
241+
Compiler performance is a problem that we would like to improve on
242+
(and are always working on). One aspect of that is parallelizing
244243
`rustc` itself.
245244

246245
Currently, there is only one part of rustc that is already parallel: codegen.

0 commit comments

Comments
 (0)