Commit b35fa8a
authored
Adapt types according to read-only status (#23332)
Extend type adaptation to read-only status.
Two big improvements:
- we also adapt if the target type is a mutable type with a read-only
capture set. So the following compiles:
```scala
class Ref extends Mutable { ... }
val x: Ref^{cap.rd} = Ref()
```
- we also adapt deeply inside a type. So the following compiles:
```scala
val refs = List(Ref(), Ref())
val rdrs: List[Ref^{cap.rd}] = refs
```
We even try to track arguments through base types, so the following also
compiles:
```scala
val rdrs2: Seq[Ref^{cap.rd}] = refs
```
But there are some limits, correlating actual and expected type through
base types and as-seen-from is hard.
In the end I had to abandon the original idea to roll everyhting into
subtyping. I got the basics to work, but the problem then was that we
use deep capture sets in separation checking, and those were not
adapted. To do this, we'd have to somehow figure out what a dcs relative
to an expected type is. This looks deeply non-trivial, and would
probably in the end come down to techniques similar to the adaptation in
this PR. So the benefit of also adding and inferring qualifiers to
capture sets are not clear.
EDIT: We do need qualifiers for soundness as @Linyxus example below
shows. It's now in `ro-mut-conformance.scala`.
So the adaptation commit has been rebased on the mutability qualifiers
branch.File tree
26 files changed
+560
-94
lines changed- compiler/src/dotty/tools/dotc
- cc
- core
- printing
- scala2-library-cc/src/scala/collection
- tests
- neg-custom-args/captures
- pending/pos-custom-args/captures
- pos-custom-args/captures
26 files changed
+560
-94
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
333 | 339 | | |
334 | 340 | | |
335 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
0 commit comments