Skip to content

Commit 90716dc

Browse files
committed
Add section on chalk structure
1 parent 74e2af2 commit 90716dc

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/traits/chalk-overview.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,71 @@ existing, somewhat ad-hoc implementation into something far more principled and
1616
expressive, which should behave better in corner cases, and be much easier to
1717
extend.
1818

19+
## Chalk Structure
20+
Chalk has two main "products". The first of these is the
21+
[`chalk_engine`][doc-chalk-engine] crate, which defines the core [SLG
22+
solver][slg]. This is the part rustc uses.
23+
24+
The rest of chalk can be considered an elaborate testing harness. Chalk is
25+
capable of parsing Rust-like "programs", lowering them to logic, and
26+
performing queries on them.
27+
28+
Here's a sample session in the chalk repl, chalki. After feeding it our
29+
program, we perform some queries on it.
30+
31+
```rust,ignore
32+
?- program
33+
Enter a program; press Ctrl-D when finished
34+
| struct Foo { }
35+
| struct Bar { }
36+
| struct Vec<T> { }
37+
| trait Clone { }
38+
| impl<T> Clone for Vec<T> where T: Clone { }
39+
| impl Clone for Foo { }
40+
41+
?- Vec<Foo>: Clone
42+
Unique; substitution [], lifetime constraints []
43+
44+
?- Vec<Bar>: Clone
45+
No possible solution.
46+
47+
?- exists<T> { Vec<T>: Clone }
48+
Ambiguous; no inference guidance
49+
```
50+
51+
You can see more examples of programs and queries in the [unit tests][chalk-tests].
52+
53+
[chalk-tests]: https://github.com/rust-lang-nursery/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L115
54+
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+
1984
## Resources
2085

2186
* [Chalk Source Code](https://github.com/rust-lang-nursery/chalk)

0 commit comments

Comments
 (0)