@@ -17,6 +17,8 @@ So first, let's look at what the compiler does to your code. For now, we will
17
17
avoid mentioning how the compiler implements these steps except as needed;
18
18
we'll talk about that later.
19
19
20
+ ### Invokation
21
+
20
22
- The compile process begins when a user writes a Rust source program in text
21
23
and invokes the ` rustc ` compiler on it. The work that the compiler needs to
22
24
perform is defined by command-line options. For example, it is possible to
@@ -26,6 +28,9 @@ we'll talk about that later.
26
28
- Command line argument parsing occurs in the [ ` rustc_driver ` ] . This crate
27
29
defines the compile configuration that is requested by the user and passes it
28
30
to the rest of the compilation process as a [ ` rustc_interface::Config ` ] .
31
+
32
+ ### Lexing and parsing
33
+
29
34
- The raw Rust source text is analyzed by a low-level lexer located in
30
35
[ ` rustc_lexer ` ] . At this stage, the source text is turned into a stream of
31
36
atomic source code units known as _ tokens_ . The lexer supports the
@@ -66,6 +71,9 @@ we'll talk about that later.
66
71
- The parser uses the standard ` DiagnosticBuilder ` API for error handling, but we
67
72
try to recover, parsing a superset of Rust's grammar, while also emitting an error.
68
73
- ` rustc_ast::ast::{Crate, Mod, Expr, Pat, ...} ` AST nodes are returned from the parser.
74
+
75
+ ### HIR lowering
76
+
69
77
- We then take the AST and [ convert it to High-Level Intermediate
70
78
Representation (HIR)] [ hir ] . This is a compiler-friendly representation of the
71
79
AST. This involves a lot of desugaring of things like loops and ` async fn ` .
@@ -77,6 +85,9 @@ we'll talk about that later.
77
85
into the internal representation used by the compiler (` Ty<'tcx> ` ),
78
86
and using that information to verify the type safety, correctness and
79
87
coherence of the types used in the program).
88
+
89
+ ### MIR lowering
90
+
80
91
- The HIR is then [ lowered to Mid-Level Intermediate Representation (MIR)] [ mir ] .
81
92
- Along the way, we construct the THIR, which is an even more desugared HIR.
82
93
THIR is used for pattern and exhaustiveness checking. It is also more
@@ -93,6 +104,9 @@ we'll talk about that later.
93
104
code with the type parameters replaced by concrete types. To do
94
105
this, we need to collect a list of what concrete types to generate code for.
95
106
This is called _ monomorphization collection_ .
107
+
108
+ ### Code generation
109
+
96
110
- We then begin what is vaguely called _ code generation_ or _ codegen_ .
97
111
- The [ code generation stage (codegen)] [ codegen ] is when higher level
98
112
representations of source are turned into an executable binary. ` rustc `
0 commit comments