@@ -17,6 +17,7 @@ expressive, which should behave better in corner cases, and be much easier to
17
17
extend.
18
18
19
19
## Chalk Structure
20
+
20
21
Chalk has two main "products". The first of these is the
21
22
[ ` chalk_engine ` ] [ doc-chalk-engine ] crate, which defines the core [ SLG
22
23
solver] [ slg ] . This is the part rustc uses.
@@ -52,37 +53,9 @@ You can see more examples of programs and queries in the [unit tests][chalk-test
52
53
53
54
Next we'll go through each stage required to produce the output above.
54
55
55
- ### Crates
56
- - [ ** chalk_engine** ] [ doc-chalk-engine ] : Defines the core [ SLG solver] [ slg ] .
57
- - [ ** chalk_ir** ] [ doc-chalk-ir ] : Defines chalk's internal representation of
58
- types, lifetimes, and goals.
59
- - [ ** chalk_solve** ] [ doc-chalk-solve ] : Combines ` chalk_ir ` and ` chalk_engine ` ,
60
- effectively.
61
- - [ ` chalk_engine::context ` ] [ engine-context ] provides the necessary hooks.
62
- - [ ** chalk_parse** ] [ doc-chalk-parse ] : Defines the raw AST and a parser.
63
- - [ ** chalk** ] [ doc-chalk ] : Brings everything together. Defines the following
64
- modules:
65
- - [ ` rust_ir ` ] [ doc-chalk-rust-ir ] , containing the "HIR-like" form of the AST
66
- - ` rust_ir::lowering ` , which converts AST to ` rust_ir `
67
- - ` rules ` , which implements logic rules
68
- converting ` rust_ir ` to ` chalk_ir `
69
- - ` coherence ` , which implements coherence rules
70
- - Also includes [ chalki] [ doc-chalki ] , chalk's REPL.
71
-
72
- [ Browse source on GitHub] ( https://github.com/rust-lang-nursery/chalk )
73
-
74
- [ engine-context ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_engine/context/index.html
75
-
76
- [ doc-chalk-engine ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_engine/index.html
77
- [ doc-chalk-ir ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_ir/index.html
78
- [ doc-chalk-solve ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_solve/index.html
79
- [ doc-chalk-parse ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_parse/index.html
80
- [ doc-chalk ] : https://rust-lang-nursery.github.io/chalk/doc/chalk/index.html
81
- [ doc-chalk-rust-ir ] : https://rust-lang-nursery.github.io/chalk/doc/chalk/rules/index.html
82
- [ doc-chalki ] : https://rust-lang-nursery.github.io/chalk/doc/chalki/index.html
83
56
[ chalk-tests ] : https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L115
84
57
85
- ## Parsing
58
+ ### Parsing
86
59
87
60
Chalk is designed to be incorporated with the Rust compiler, so the syntax and
88
61
concepts it deals with heavily borrow from Rust. It is convenient for the sake
@@ -98,7 +71,7 @@ impls, and struct definitions. Parsing is often the first "phase" of
98
71
transformation that a program goes through in order to become a format that
99
72
chalk can understand.
100
73
101
- ## Lowering
74
+ ### Lowering
102
75
103
76
After parsing, there is a "lowering" phase. This aims to convert traits/impls
104
77
into "program clauses". A [ ` ProgramClause ` (source code)] [ programclause ] is
@@ -136,15 +109,15 @@ forall<T> { (Vec<T>: Clone) :- (T: Clone) }
136
109
This rule dictates that ` Vec<T>: Clone ` is only satisfied if ` T: Clone ` is also
137
110
satisfied (i.e. "provable").
138
111
139
- ### Well-formedness checks
112
+ #### Well-formedness checks
140
113
141
114
As part of lowering from the AST to the internal IR, we also do some "well
142
115
formedness" checks. See the [ source code] [ well-formedness-checks ] for where
143
116
those are done. The call to ` record_specialization_priorities ` checks
144
117
"coherence" which means that it ensures that two impls of the same trait for the
145
118
same type cannot exist.
146
119
147
- ## Intermediate Representation (IR)
120
+ ### Intermediate Representation (IR)
148
121
149
122
The second intermediate representation in chalk is called, well, the "ir". :)
150
123
The [ IR source code] [ ir-code ] contains the complete definition. The
@@ -159,14 +132,48 @@ In addition to `ir::Program` which has "rust-like things", there is also
159
132
` program_clauses ` which contains the ` ProgramClause ` s that we generated
160
133
previously.
161
134
162
- ## Rules
135
+ ### Rules
163
136
164
137
The ` rules ` module works by iterating over every trait, impl, etc. and emitting
165
138
the rules that come from each one. See [ Lowering Rules] [ lowering-rules ] for the
166
139
most up-to-date reference on that.
167
140
168
141
The ` ir::ProgramEnvironment ` is created [ in this module] [ rules-environment ] .
169
142
143
+ ### Solver
144
+
145
+ See [ The SLG Solver] [ slg ] .
146
+
147
+ ## Crates
148
+
149
+ Chalk's functionality is broken up into the following crates:
150
+ - [ ** chalk_engine** ] [ doc-chalk-engine ] : Defines the core [ SLG solver] [ slg ] .
151
+ - [ ** chalk_ir** ] [ doc-chalk-ir ] : Defines chalk's internal representation of
152
+ types, lifetimes, and goals.
153
+ - [ ** chalk_solve** ] [ doc-chalk-solve ] : Combines ` chalk_ir ` and ` chalk_engine ` ,
154
+ effectively.
155
+ - [ ` chalk_engine::context ` ] [ engine-context ] provides the necessary hooks.
156
+ - [ ** chalk_parse** ] [ doc-chalk-parse ] : Defines the raw AST and a parser.
157
+ - [ ** chalk** ] [ doc-chalk ] : Brings everything together. Defines the following
158
+ modules:
159
+ - [ ` rust_ir ` ] [ doc-chalk-rust-ir ] , containing the "HIR-like" form of the AST
160
+ - ` rust_ir::lowering ` , which converts AST to ` rust_ir `
161
+ - ` rules ` , which implements logic rules converting ` rust_ir ` to ` chalk_ir `
162
+ - ` coherence ` , which implements coherence rules
163
+ - Also includes [ chalki] [ doc-chalki ] , chalk's REPL.
164
+
165
+ [ Browse source on GitHub] ( https://github.com/rust-lang-nursery/chalk )
166
+
167
+ [ engine-context ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_engine/context/index.html
168
+
169
+ [ doc-chalk-engine ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_engine/index.html
170
+ [ doc-chalk-ir ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_ir/index.html
171
+ [ doc-chalk-solve ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_solve/index.html
172
+ [ doc-chalk-parse ] : https://rust-lang-nursery.github.io/chalk/doc/chalk_parse/index.html
173
+ [ doc-chalk ] : https://rust-lang-nursery.github.io/chalk/doc/chalk/index.html
174
+ [ doc-chalk-rust-ir ] : https://rust-lang-nursery.github.io/chalk/doc/chalk/rules/index.html
175
+ [ doc-chalki ] : https://rust-lang-nursery.github.io/chalk/doc/chalki/index.html
176
+
170
177
## Testing
171
178
172
179
TODO: Basically, [ there is a macro] ( https://github.com/rust-lang-nursery/chalk/blob/94a1941a021842a5fcb35cd043145c8faae59f08/src/solve/test.rs#L112-L148 )
0 commit comments