@@ -16,17 +16,17 @@ Your concerns are probably the same as someone else's.
16
16
The crates of rustc
17
17
===================
18
18
19
- Rustc consists of four crates altogether: `libsyntax`, `librustc `,
20
- `librustc_back`, and `librustc_trans` (the names and divisions are not
21
- set in stone and may change; in general, a finer-grained division of
22
- crates is preferable):
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
23
24
- - `libsyntax` contains those things concerned purely with syntax --
24
+ - `libsyntax` contains those things concerned purely with syntax –
25
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 current
28
- directory (that is, the parent directory of front/, middle/, back /,
29
- and so on).
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
30
31
31
- `librustc` (the current directory) contains the high-level analysis
32
32
passes, such as the type checker, borrow checker, and so forth.
@@ -41,66 +41,70 @@ crates is preferable):
41
41
of miscellany. In general it contains code that runs towards the
42
42
end of the compilation process.
43
43
44
+ - `librustc_driver` invokes the compiler from `libsyntax`, then the
45
+ analysis phases from `librustc`, and finally the lowering and
46
+ codegen passes from `librustc_trans`.
47
+
44
48
Roughly speaking the "order" of the three crates is as follows:
45
49
46
50
libsyntax -> librustc -> librustc_trans
47
51
| |
48
52
+-----------------+-------------------+
49
53
|
50
- librustc_trans/driver
54
+ librustc_driver
51
55
52
- Here the role of `librustc_trans/driver` is to invoke the compiler
53
- from libsyntax, then the analysis phases from librustc, and finally
54
- the lowering and codegen passes from librustc_trans.
55
56
56
57
Modules in the rustc crate
57
58
==========================
58
59
59
- The rustc crate itself consists of the following subdirectories
60
+ The rustc crate itself consists of the following submodules
60
61
(mostly, but not entirely, in their own directories):
61
62
62
- session - options and data that pertain to the compilation session as a whole
63
- middle - middle-end: name resolution, typechecking, LLVM code
64
- generation
65
- metadata - encoder and decoder for data required by
66
- separate compilation
67
- util - ubiquitous types and helper functions
68
- lib - bindings to LLVM
63
+ - session: options and data that pertain to the compilation session as
64
+ a whole
65
+ - middle: middle-end: name resolution, typechecking, LLVM code
66
+ generation
67
+ - metadata: encoder and decoder for data required by separate
68
+ compilation
69
+ - plugin: infrastructure for compiler plugins
70
+ - lint: infrastructure for compiler warnings
71
+ - util: ubiquitous types and helper functions
72
+ - lib: bindings to LLVM
69
73
70
74
The entry-point for the compiler is main() in the librustc_trans
71
75
crate.
72
76
73
77
The 3 central data structures:
74
78
------------------------------
75
79
76
- #1: ./../libsyntax/ast.rs defines the AST. The AST is treated as immutable
77
- after parsing, but it depends on mutable context data structures
78
- (mainly hash maps) to give it meaning.
80
+ 1. ` ./../libsyntax/ast.rs` defines the AST. The AST is treated as
81
+ immutable after parsing, but it depends on mutable context data
82
+ structures (mainly hash maps) to give it meaning.
79
83
80
- - Many -- though not all -- nodes within this data structure are
81
- wrapped in the type `spanned<T>`, meaning that the front-end has
82
- marked the input coordinates of that node. The member . node is
83
- the data itself, the member . span is the input location (file,
84
- line, column; both low and high).
84
+ - Many – though not all – nodes within this data structure are
85
+ wrapped in the type `spanned<T>`, meaning that the front-end has
86
+ marked the input coordinates of that node. The member ` node` is
87
+ the data itself, the member ` span` is the input location (file,
88
+ line, column; both low and high).
85
89
86
- - Many other nodes within this data structure carry a
87
- def_id. These nodes represent the 'target' of some name
88
- reference elsewhere in the tree. When the AST is resolved, by
89
- middle/resolve.rs, all names wind up acquiring a def that they
90
- point to. So anything that can be pointed-to by a name winds
91
- up with a def_id.
90
+ - Many other nodes within this data structure carry a
91
+ ` def_id` . These nodes represent the 'target' of some name
92
+ reference elsewhere in the tree. When the AST is resolved, by
93
+ ` middle/resolve.rs` , all names wind up acquiring a def that they
94
+ point to. So anything that can be pointed-to by a name winds
95
+ up with a ` def_id` .
92
96
93
- #2: middle/ty.rs defines the datatype sty. This is the type that
94
- represents types after they have been resolved and normalized by
95
- the middle-end. The typeck phase converts every ast type to a
96
- ty::sty, and the latter is used to drive later phases of
97
- compilation. Most variants in the ast::ty tag have a
98
- corresponding variant in the ty::sty tag.
97
+ 2. ` middle/ty.rs` defines the datatype ` sty`. This is the type that
98
+ represents types after they have been resolved and normalized by
99
+ the middle-end. The typeck phase converts every ast type to a
100
+ ` ty::sty` , and the latter is used to drive later phases of
101
+ compilation. Most variants in the ` ast::ty` tag have a
102
+ corresponding variant in the ` ty::sty` tag.
99
103
100
- #3: lib/llvm.rs (in librustc_trans) defines the exported types
101
- ValueRef, TypeRef, BasicBlockRef, and several others. Each of
102
- these is an opaque pointer to an LLVM type, manipulated through
103
- the lib::llvm interface.
104
+ 3. `./../librustc_llvm/lib.rs` defines the exported types
105
+ ` ValueRef`, ` TypeRef`, ` BasicBlockRef` , and several others.
106
+ Each of these is an opaque pointer to an LLVM type,
107
+ manipulated through the ` lib::llvm` interface.
104
108
105
109
106
110
Control and information flow within the compiler:
@@ -109,10 +113,10 @@ Control and information flow within the compiler:
109
113
- main() in lib.rs assumes control on startup. Options are
110
114
parsed, platform is detected, etc.
111
115
112
- - ./../libsyntax/parse/parser.rs parses the input files and produces an AST
113
- that represents the input crate.
116
+ - ` ./../libsyntax/parse/parser.rs` parses the input files and produces
117
+ an AST that represents the input crate.
114
118
115
- - Multiple middle-end passes (middle/resolve.rs, middle/typeck.rs)
119
+ - Multiple middle-end passes (` middle/resolve.rs`, ` middle/typeck.rs` )
116
120
analyze the semantics of the resulting AST. Each pass generates new
117
121
information about the AST and stores it in various environment data
118
122
structures. The driver passes environments to each compiler pass
@@ -121,4 +125,4 @@ Control and information flow within the compiler:
121
125
- Finally, the `trans` module in `librustc_trans` translates the Rust
122
126
AST to LLVM bitcode in a type-directed way. When it's finished
123
127
synthesizing LLVM values, rustc asks LLVM to write them out in some
124
- form (.bc, .o ) and possibly run the system linker.
128
+ form (` .bc`, `.o` ) and possibly run the system linker.
0 commit comments