@@ -13,49 +13,82 @@ https://github.com/rust-lang/rust/issues
13
13
14
14
Your concerns are probably the same as someone else's.
15
15
16
- The crates of rustc
17
- ===================
18
-
19
- Rustc consists of a number of crates, including ` libsyntax ` ,
20
- ` librustc ` , ` librustc_back ` , ` librustc_trans ` , and ` librustc_driver `
21
- (the names and divisions are not set in stone and may change;
22
- in general, a finer-grained division of crates is preferable):
23
-
24
- - [ ` libsyntax ` ] [ libsyntax ] contains those things concerned purely with syntax –
25
- that is, the AST, parser, pretty-printer, lexer, macro expander, and
26
- utilities for traversing ASTs – are in a separate crate called
27
- "syntax", whose files are in ` ./../libsyntax ` , where ` . ` is the
28
- current directory (that is, the parent directory of front/, middle/,
29
- back/, and so on).
30
-
31
- - ` librustc ` (the current directory) contains the high-level analysis
32
- passes, such as the type checker, borrow checker, and so forth.
33
- It is the heart of the compiler.
34
-
35
- - [ ` librustc_back ` ] [ back ] contains some very low-level details that are
36
- specific to different LLVM targets and so forth.
16
+ You may also be interested in the
17
+ [ Rust Forge] ( https://forge.rust-lang.org/ ) , which includes a number of
18
+ interesting bits of information.
37
19
38
- - [ ` librustc_trans ` ] [ trans ] contains the code to convert from Rust IR into LLVM
39
- IR, and then from LLVM IR into machine code, as well as the main
40
- driver that orchestrates all the other passes and various other bits
41
- of miscellany. In general it contains code that runs towards the
42
- end of the compilation process.
43
-
44
- - [ ` librustc_driver ` ] [ driver ] invokes the compiler from
45
- [ ` libsyntax ` ] [ libsyntax ] , then the analysis phases from ` librustc ` , and
46
- finally the lowering and codegen passes from [ ` librustc_trans ` ] [ trans ] .
47
-
48
- Roughly speaking the "order" of the three crates is as follows:
49
-
50
- librustc_driver
51
- |
52
- +-----------------+-------------------+
53
- | |
54
- libsyntax -> librustc -> librustc_trans
20
+ Finally, at the end of this file is a GLOSSARY defining a number of
21
+ common (and not necessarily obvious!) names that are used in the Rust
22
+ compiler code. If you see some funky name and you'd like to know what
23
+ it stands for, check there!
55
24
25
+ The crates of rustc
26
+ ===================
56
27
57
- The compiler process:
58
- =====================
28
+ Rustc consists of a number of crates, including ` syntax ` ,
29
+ ` rustc ` , ` rustc_back ` , ` rustc_trans ` , ` rustc_driver ` , and
30
+ many more. The source for each crate can be found in a directory
31
+ like ` src/libXXX ` , where ` XXX ` is the crate name.
32
+
33
+ (NB. The names and divisions of these crates are not set in
34
+ stone and may change over time -- for the time being, we tend towards
35
+ a finer-grained division to help with compilation time, though as
36
+ incremental improves that may change.)
37
+
38
+ The dependency structure of these crates is roughly a diamond:
39
+
40
+ ````
41
+ rustc_driver
42
+ / | \
43
+ / | \
44
+ / | \
45
+ / v \
46
+ rustc_trans rustc_borrowck ... rustc_metadata
47
+ \ | /
48
+ \ | /
49
+ \ | /
50
+ \ v /
51
+ rustc
52
+ |
53
+ v
54
+ syntax
55
+ / \
56
+ / \
57
+ syntax_pos syntax_ext
58
+ ```
59
+
60
+
61
+ The idea is that `rustc_driver`, at the top of this lattice, basically
62
+ defines the overall control-flow of the compiler. It doesn't have much
63
+ "real code", but instead ties together all of the code defined in the
64
+ other crates and defines the overall flow of execution.
65
+
66
+ At the other extreme, the `rustc` crate defines the common and
67
+ pervasive data structures that all the rest of the compiler uses
68
+ (e.g., how to represent types, traits, and the program itself). It
69
+ also contains some amount of the compiler itself, although that is
70
+ relatively limited.
71
+
72
+ Finally, all the crates in the bulge in the middle define the bulk of
73
+ the compiler -- they all depend on `rustc`, so that they can make use
74
+ of the various types defined there, and they export public routines
75
+ that `rustc_driver` will invoke as needed (more and more, what these
76
+ crates export are "query definitions", but those are covered later
77
+ on).
78
+
79
+ Below `rustc` lie various crates that make up the parser and error
80
+ reporting mechanism. For historical reasons, these crates do not have
81
+ the `rustc_` prefix, but they are really just as much an internal part
82
+ of the compiler and not intended to be stable (though they do wind up
83
+ getting used by some crates in the wild; a practice we hope to
84
+ gradually phase out).
85
+
86
+ Each crate has a `README.md` file that describes, at a high-level,
87
+ what it contains, and tries to give some kind of explanation (some
88
+ better than others).
89
+
90
+ The compiler process
91
+ ====================
59
92
60
93
The Rust compiler is comprised of six main compilation phases.
61
94
@@ -172,3 +205,29 @@ The 3 central data structures:
172
205
[back]: https://github.com/rust-lang/rust/tree/master/src/librustc_back/
173
206
[rustc]: https://github.com/rust-lang/rust/tree/master/src/librustc/
174
207
[driver]: https://github.com/rust-lang/rust/tree/master/src/librustc_driver
208
+
209
+ Glossary
210
+ ========
211
+
212
+ The compiler uses a number of...idiosyncratic abbreviations and
213
+ things. This glossary attempts to list them and give you a few
214
+ pointers for understanding them better.
215
+
216
+ - AST -- the **abstract syntax tree** produced the `syntax` crate; reflects user syntax
217
+ very closely.
218
+ - cx -- we tend to use "cx" as an abbrevation for context. See also tcx, infcx, etc.
219
+ - HIR -- the **High-level IR**, created by lowering and desugaring the AST. See `librustc/hir`.
220
+ - `'gcx` -- the lifetime of the global arena (see `librustc/ty`).
221
+ - generics -- the set of generic type parameters defined on a type or item
222
+ - infcx -- the inference context (see `librustc/infer`)
223
+ - MIR -- the **Mid-level IR** that is created after type-checking for use by borrowck and trans.
224
+ Defined in the `src/librustc/mir/` module, but much of the code that manipulates it is
225
+ found in `src/librustc_mir`.
226
+ - obligation -- something that must be proven by the trait system.
227
+ - sess -- the **compiler session**, which stores global data used throughout compilation
228
+ - substs -- the **substitutions** for a given generic type or item
229
+ (e.g., the `i32, u32` in `HashMap<i32, u32>`)
230
+ - tcx -- the "typing context", main data structure of the compiler (see `librustc/ty`).
231
+ - trans -- the code to **translate** MIR into LLVM IR.
232
+ - trait reference -- a trait and values for its type parameters (see `librustc/ty`).
233
+ - ty -- the internal representation of a **type** (see `librustc/ty`).
0 commit comments