Repository navigation
Commit 03d93cc
Declare the variance of iterator, generator and tagged template types (#8981)
Why:
The iterator family's type parameters were invariant, so a generator
of `[#A]` could not be coerced to one of `[#A | #B]`, and values of
library types built on `Generator.t` were not generalised under the
relaxed value restriction. Yields and return values only flow out of
an iterator and resume values only flow in. Needed for generators
(#8934).
Typing modified (coercion):
Example:
let g: Generator.t<[#A], int, [#X | #Y]> = gen()
let h = (g :> Generator.t<[#A | #B], int, [#X]>)
Before (rule):
t<y, r, n> ≤ t<y', r', n'> only if y = y', r = r', n = n'
After (rule):
y ≤ y' r ≤ r' n' ≤ n
───────────────────────── (Iterator variance)
t<y, r, n> ≤ t<y', r', n'>
t ∈ {Iterator, AsyncIterator, Generator, AsyncGenerator, IterableIterator, AsyncIterableIterator, IteratorObject}
rawResult<+y, +r> arrayLike<+a> taggedTemplate<-param, +output>
Review: Is `+'return` sound when `Generator.returnValue` takes a `'return`? Only up to a contrived case: a generator shared under two types, resumed through `returnValue` while a `finally` block yields, hands the wider value to the narrower reference. TypeScript's `Generator` has the same hole.
Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent f62f83c commit 03d93cc
22 files changed
Lines changed: 221 additions & 21 deletions
File tree
- changes
- compiler/ml
- packages/@rescript/runtime
- tests
- build_tests/super_errors
- expected
- fixtures
- tests/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | | - | |
| 370 | + | |
| 371 | + | |
371 | 372 | | |
372 | 373 | | |
373 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
0 commit comments