Skip to content

Commit e1e7dc8

Browse files
committed
Restructure some chapters
1 parent 7998734 commit e1e7dc8

File tree

5 files changed

+84
-75
lines changed

5 files changed

+84
-75
lines changed

book/src/SUMMARY.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
- [What is Chalk?](./what_is_chalk.md)
44
- [Crates](./what_is_chalk/crates.md)
5+
- [REPL](./what_is_chalk/repl.md)
56
- [Contribution guide](./contribution_guide.md)
6-
- [REPL](./repl.md)
7-
- [Representing and manipulating Rust types](./types.md)
8-
- [The role of the `Interner`](./types/role_of_interner.md)
9-
- [Controlling representation with `Interner`](./types/how_to_control_repr.md)
7+
- [Representing and manipulating types](./types.md)
8+
- [The `Interner`](./types/role_of_interner.md)
109
- [Rust types](./types/rust_types.md)
1110
- [Application types](./types/rust_types/application_ty.md)
1211
- [Rust lifetimes](./types/rust_lifetimes.md)
@@ -21,7 +20,7 @@
2120
- [Well-formedness checking](./clauses/wf.md)
2221
- [Canonical queries](./canonical_queries.md)
2322
- [Canonicalization](./canonical_queries/canonicalization.md)
24-
- [How does the engine work](./engine.md)
23+
- [Chalk engine](./engine.md)
2524
- [Major concepts](./engine/major_concepts.md)
2625
- [Logic](./engine/logic.md)
2726
- [Coinduction](./engine/logic/coinduction.md)

book/src/types/how_to_control_repr.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

book/src/types/role_of_interner.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Most everything in the IR is parameterized by the [`Interner`] trait:
55
[`Interner`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html
66

77
```rust,ignore
8-
trait Interner: Copy + Clone + Debug + Eq + Ord {
8+
trait Interner: Copy + Clone + Debug + Eq + Ord {
99
..
1010
}
1111
```
@@ -16,3 +16,72 @@ the interner is defined by the embedded and can be used to control
1616
other things in memory. For example, the `Interner` trait could be
1717
used to intern all the types, as rustc does, or it could be used to
1818
`Box` them instead, as the chalk testing harness currently does.
19+
20+
### Controlling representation with `Interner`
21+
22+
The purpose of the [`Interner`] trait is to give control over how
23+
types and other bits of chalk-ir are represented in memory. This is
24+
done via an "indirection" strategy. We'll explain that strategy here
25+
in terms of [`Ty`] and [`TyData`], the two types used to represent
26+
Rust types, but the same pattern is repeated for many other things.
27+
28+
[`Interner`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html
29+
[`Ty`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Ty.html
30+
[`TyData`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyData.html
31+
32+
Types are represented by a [`Ty<I>`] type and the [`TyData<I>`] enum.
33+
There is no *direct* connection between them. The link is rather made
34+
by the [`Interner`] trait, via the [`InternedTy`] associated type:
35+
36+
[`Ty<I>`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Ty.html
37+
[`TyData<I>`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TyData.html
38+
[`InternedTy`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html#associatedtype.InternedType
39+
40+
```rust,ignore
41+
struct Ty<I: Interner>(I::InternedTy);
42+
enum TyData<I: Interner> { .. }
43+
```
44+
45+
The way this works is that the [`Interner`] trait has an associated
46+
type [`InternedTy`] and two related methods, [`intern_ty`] and [`ty_data`]:
47+
48+
[`intern_ty`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html#tymethod.intern_ty
49+
[`ty_data`]: http://rust-lang.github.io/chalk/chalk_ir/interner/trait.Interner.html#tymethod.ty_data
50+
51+
```rust,ignore
52+
trait Interner {
53+
type InternedTy;
54+
55+
fn intern_ty(&self, data: &TyData<Self>) -> Self::InternedTy;
56+
fn ty_data(data: &Self::InternedTy) -> &TyData<Self>;
57+
}
58+
```
59+
60+
However, as a user you are not meant to use these directly. Rather,
61+
they are encapsulated in methods on the [`Ty`] and [`TyData`] types:
62+
63+
```rust,ignore
64+
impl<I: Interner> Ty<I> {
65+
fn data(&self) -> &TyData<I> {
66+
I::lookup_ty(self)
67+
}
68+
}
69+
```
70+
71+
and
72+
73+
```rust,ignore
74+
impl<I: Interner> TyData<I> {
75+
fn intern(&self, I: &I) -> Ty<I> {
76+
Ty(i.intern_ty(self))
77+
}
78+
}
79+
```
80+
81+
Note that there is an assumption here that [`ty_data`] needs no
82+
context. This effectively constrains the [`InternedTy`] representation
83+
to be a `Box` or `&` type. To be more general, at the cost of some
84+
convenience, we could make that a method as well, so that one would
85+
invoke `ty.data(i)` instead of just `ty.data()`. This would permit us
86+
to use (for example) integers to represent interned types, which might
87+
be nice (e.g., to permit using generational indices).

book/src/what_is_chalk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Likewise, lowering tests use the [`lowering_success!` and
206206
## More Resources
207207

208208
* [Chalk Source Code](https://github.com/rust-lang/chalk)
209-
* [Chalk Glossary](https://github.com/rust-lang/chalk/blob/master/GLOSSARY.md)
209+
* [Chalk Glossary](glossary.md)
210210

211211
[goals-and-clauses]: ./clauses/goals_and_clauses.html
212212
[HIR]: https://rustc-dev-guide.rust-lang.org/hir.html

book/src/what_is_chalk/repl.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# REPL
2+
3+
There is a repl mainly for debugging purposes which can be run by `cargo run`. Some basic examples are in [libstd.chalk](https://github.com/rust-lang/chalk/blob/master/libstd.chalk):
4+
```bash
5+
$ cargo run
6+
?- load libstd.chalk
7+
?- Vec<Box<i32>>: Clone
8+
Unique; substitution [], lifetime constraints []
9+
```

0 commit comments

Comments
 (0)