Skip to content

Commit 71766d9

Browse files
lcnrcompiler-errors
authored andcommitted
review
1 parent 167d22c commit 71766d9

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/solve/coinduction.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ unique `impl` which should be used.
4949

5050
## How to implement coinduction
5151

52-
While our implementation can not check for coninduction by trying to construct an infinite
53-
tree as that would take infinite ressources, it still makes sense to think of coinduction
52+
While our implementation can not check for coinduction by trying to construct an infinite
53+
tree as that would take infinite resources, it still makes sense to think of coinduction
5454
from this perspective.
5555

5656
As we cannot check for infinite trees, we instead search for patterns for which we know that
@@ -70,7 +70,7 @@ where
7070
{}
7171
```
7272
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
73+
`?0` to `Wrapper<?1>` and then requires `Wrapper<?1>: Foo`. Due to canonicalization this would be
7474
detected as a cycle.
7575

7676
The idea to solve is to return a *provisional result* whenever we detect a cycle and repeatedly
@@ -112,8 +112,8 @@ impl<T: Clone> Clone for List<T> {
112112
```
113113

114114
We are using `tail.clone()` in this impl. For this we have to prove `Box<List<T>>: Clone`
115-
which requires `List<T>: Clone` but that relies on the currently impl which we are currently
116-
checking. By adding that requirement to the `where`-clauses of the impl, which is what we would
115+
which requires `List<T>: Clone` but that relies on the impl which we are currently checking.
116+
By adding that requirement to the `where`-clauses of the impl, which is what we would
117117
do with [perfect derive], we move that cycle into the trait solver and [get an error][ex1].
118118

119119
### Recursive data types
@@ -163,12 +163,12 @@ The issues here are not relevant for the current solver.
163163

164164
#### Implied super trait bounds
165165

166-
Our trait system currectly treats super traits, e.g. `trait Trait: SuperTrait`,
166+
Our trait system currently treats super traits, e.g. `trait Trait: SuperTrait`,
167167
by 1) requiring that `SuperTrait` has to hold for all types which implement `Trait`,
168168
and 2) assuming `SuperTrait` holds if `Trait` holds.
169169

170170
Relying on 2) while proving 1) is unsound. This can only be observed in case of
171-
coinductive cycles. Without a cycles, whenever we rely on 2) we must have also
171+
coinductive cycles. Without cycles, whenever we rely on 2) we must have also
172172
proven 1) without relying on 2) for the used impl of `Trait`.
173173

174174
```rust

src/solve/trait-solving.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ Also add issues where each of these rules have been broken in the past
5252

5353
This means that we must never return *success* for goals for which no `impl` exists. That would
5454
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.
55+
from the `where`-bounds, the `impl` will be proved by the user of the item.
5656

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

5959
Pretty much: If we successfully typecheck a generic function concrete instantiations
6060
of that function should also typeck. We should not get errors post-monomorphization.
61-
We can however get overflow.
61+
We can however get overflow as in the following snippet:
62+
63+
```rust
64+
fn foo<T: Trait>(x: )
65+
```
6266

6367
### 3. Trait goals in empty environments are proven by a unique impl.
6468

@@ -71,7 +75,15 @@ An exception here are *marker traits* which are allowed to overlap.
7175
### 4. Normalization in empty environments results in a unique type
7276

7377
Normalization for alias types/consts has a unique result. Otherwise we can easily implement
74-
transmute in safe code.
78+
transmute in safe code. Given the following function, we have to make sure that the input and
79+
output types always get normalized to the same concrete type.
80+
```rust
81+
fn foo<T: Trait>(
82+
x: <T as Trait>::Assoc
83+
) -> <T as Trait>::Assoc {
84+
x
85+
}
86+
```
7587

7688
### 5. During coherence trait solving has to be complete
7789

0 commit comments

Comments
 (0)