1
1
An informal guide to reading and working on the rustc compiler.
2
2
==================================================================
3
3
4
- If you wish to expand on this document, or have one of the
5
- slightly-more-familiar authors add anything else to it, please get in
6
- touch or file a bug. Your concerns are probably the same as someone
7
- else's.
4
+ If you wish to expand on this document, or have a more experienced
5
+ Rust contributor add anything else to it, please get in touch:
6
+
7
+ https://github.com/mozilla/rust/wiki/Note-development-policy
8
+ ("Communication" subheading)
9
+
10
+ or file a bug:
11
+
12
+ https://github.com/mozilla/rust/issues
13
+
14
+ Your concerns are probably the same as someone else's.
8
15
9
16
10
17
High-level concepts
11
18
===================
12
19
13
20
Rustc consists of the following subdirectories:
14
21
15
- syntax/ - pure syntax concerns: lexer, parser, AST.
16
22
front/ - front-end: attributes, conditional compilation
17
- middle/ - middle-end: resolving, typechecking, translating
23
+ middle/ - middle-end: resolving, typechecking, generating LLVM code
18
24
back/ - back-end: linking and ABI
25
+ metadata/ - serializer and deserializer for data required by
26
+ separate compilation
19
27
driver/ - command-line processing, main() entrypoint
20
28
util/ - ubiquitous types and helper functions
21
29
lib/ - bindings to LLVM
22
- pretty/ - pretty-printing
30
+
31
+ The files concerned purely with syntax -- that is, the AST, parser,
32
+ pretty-printer, lexer, macro expander, and utilities for traversing
33
+ ASTs -- are in a separate crate called "rustsyntax", whose files are
34
+ in ./../librustsyntax if the parent directory of front/, middle/,
35
+ back/, and so on is . .
23
36
24
37
The entry-point for the compiler is main() in driver/rustc.rs, and
25
38
this file sequences the various parts together.
@@ -28,10 +41,9 @@ this file sequences the various parts together.
28
41
The 3 central data structures:
29
42
------------------------------
30
43
31
- #1: syntax/ast.rs defines the AST. The AST is treated as immutable
32
- after parsing despite containing some mutable types (hashtables
33
- and such). There are three interesting details to know about this
34
- structure:
44
+ #1: ../librustsyntax/ast.rs defines the AST. The AST is treated as immutable
45
+ after parsing, but it depends on mutable context data structures
46
+ (mainly hash maps) to give it meaning.
35
47
36
48
- Many -- though not all -- nodes within this data structure are
37
49
wrapped in the type spanned<T>, meaning that the front-end has
@@ -55,7 +67,7 @@ The 3 central data structures:
55
67
56
68
#3: lib/llvm.rs defines the exported types ValueRef, TypeRef,
57
69
BasicBlockRef, and several others. Each of these is an opaque
58
- pointer to an LLVM type, manipulated through the lib. llvm
70
+ pointer to an LLVM type, manipulated through the lib:: llvm
59
71
interface.
60
72
61
73
@@ -65,13 +77,16 @@ Control and information flow within the compiler:
65
77
- main() in driver/rustc.rs assumes control on startup. Options are
66
78
parsed, platform is detected, etc.
67
79
68
- - front/parser.rs is driven over the input files.
80
+ - librustsyntax/parse/parser.rs parses the input files and produces an
81
+ AST that represents the input crate.
69
82
70
- - Multiple middle-end passes (middle/resolve.rs, middle/typeck.rs) are
71
- run over the resulting AST. Each pass generates new information
72
- about the AST which is stored in various side data structures.
83
+ - Multiple middle-end passes (middle/resolve.rs, middle/typeck.rs)
84
+ analyze the semantics of the resulting AST. Each pass generates new
85
+ information about the AST and stores it in various environment data
86
+ structures. The driver is in charge of passing the correct
87
+ environments to each compiler pass that needs to refer to them.
73
88
74
- - Finally middle/trans.rs is applied to the AST, which performs a
75
- type-directed translation to LLVM-ese . When it's finished
76
- synthesizing LLVM values, rustc asks LLVM to write them out in some
77
- form (.bc, .o) and possibly run the system linker.
89
+ - Finally middle/trans.rs translates the Rust AST to LLVM bitcode in a
90
+ type-directed way . When it's finished synthesizing LLVM values,
91
+ rustc asks LLVM to write them out in some form (.bc, .o) and
92
+ possibly run the system linker.
0 commit comments