Skip to content

Commit 9656b8c

Browse files
lcnrcompiler-errors
authored andcommitted
review
1 parent 15bd9e4 commit 9656b8c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/solve/coinduction.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,26 @@ As we cannot check for infinite trees, we instead search for patterns for which
5757
they would result in an infinite proof tree. The currently pattern we detect are (canonical)
5858
cycles. If `T: Send` relies on `T: Send` then it's pretty clear that this will just go on forever.
5959

60-
With cycles we have to be careful with caching. Due to canonicalization of regions and inference
61-
variables we also have to rerun queries until the provisional result returned when hitting the cycle
62-
is equal to the final result.
60+
With cycles we have to be careful with caching. Because of canonicalization of regions and
61+
inference variables encountering a cycle doesn't mean that we would get an infinite proof tree.
62+
Looking at the following example:
63+
```rust
64+
trait Foo {}
65+
struct Wrapper<T>(T);
66+
67+
impl<T> Foo for Wrapper<Wrapper<T>>
68+
where
69+
Wrapper<T>: Foo
70+
{}
71+
```
72+
Proving `Wrapper<?0>: Foo` uses the impl `impl<T> Foo for Wrapper<Wrapper<T>>` which constrains
73+
`?0` to `Vec<?1>` and then requires `Wrapper<?1>: Foo`. Due to canonicalization this would be
74+
detected as a cycle.
75+
76+
The idea to solve is to return a *provisional result* whenever we detect a cycle and repeatedly
77+
retry goals until the *provisional result* is equal to the final result of that goal. We
78+
start out by using `Yes` with no constraints as the result and then update it to the result of
79+
the previous iteration whenever we have to rerun.
6380

6481
TODO: elaborate here. We use the same approach as chalk for coinductive cycles.
6582
Note that the treatment for inductive cycles currently differs by simply returning `Overflow`.

src/solve/trait-solving.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Also add issues where each of these rules have been broken in the past
5151
### 1. The trait solver has to be *sound*
5252

5353
This means that we must never return *success* for goals for which no `impl` exists. That would
54-
simply be unsound by assuming a trait is implemented even though it is not.
54+
simply be unsound by assuming a trait is implemented even though it is not. When using predicates
55+
from the `where`-bounds, the `impl` whill be proved by the user of the item.
5556

5657
### 2. If type checker solves generic goal concrete instantiations of that goal have the same result
5758

0 commit comments

Comments
 (0)