|
1 | 1 | # The On-Demand SLG solver
|
2 | 2 |
|
| 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 | + |
3 | 41 | ## Description of how it works
|
4 | 42 |
|
5 | 43 | The basis of the solver is the `Forest` type. A *forest* stores a
|
|
0 commit comments