Skip to content

Commit 69d42aa

Browse files
committed
SLG: Add intro
1 parent 76a2c5e commit 69d42aa

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/traits/slg.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
11
# The On-Demand SLG solver
22

3+
Given a set of program clauses (provided by our [lowering rules][lowering])
4+
and a query, we need to return the result of the query and the value of any
5+
type variables we can determine. This is the job of the solver.
6+
7+
For example, `exists<T> { Vec<T>: FromIterator<u32> }` has one solution, so
8+
its result is `Unique; substitution [?T := u32]`. A solution also comes with
9+
a set of region constraints, which we'll ignore in this introduction.
10+
11+
[lowering]: ./lowering-rules.html
12+
13+
## Goals of the Solver
14+
15+
### On demand
16+
17+
There are often many, or even infinitely many, solutions to a query. For
18+
example, say we want to prove that `exists<T> { Vec<T>: Debug }` for _some_
19+
type `?T`. Our solver should be capable of iterating over each answer one at
20+
a time, say `?T = u32`, then `?T = i32`, and so on, rather than iterating
21+
over every type in the type system. If we need more answers, we can request
22+
more until we are done. This is similar to how Prolog works.
23+
24+
*See also: [The traditional, interactive Prolog query][pq]*
25+
26+
[pq]: ./canonical-queries.html#the-traditional-interactive-prolog-query
27+
28+
### Breadth-first
29+
30+
`Vec<?T>: Debug` is true if `?T: Debug`. This leads to a cycle: `[Vec<u32> ,
31+
Vec<Vec<u32>>, Vec<Vec<Vec<u32>>>]`, and so on all implement `Debug`. Our
32+
solver ought to be breadth first and consider answers like `[Vec<u32>: Debug,
33+
Vec<i32>: Debug, ...]` before it recurses, or we may never find the answer
34+
we're looking for.
35+
36+
### Cache friendly
37+
38+
To speed up compilation, we need to cache results, including partial results
39+
left over from past solver queries.
40+
341
## Description of how it works
442

543
The basis of the solver is the `Forest` type. A *forest* stores a

0 commit comments

Comments
 (0)