You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Change `tracked` inference to simpler heuristic: always infer `tracked`
for a parameter if its type has an abstract type member.
Tested it with `modularity` turned on and the only bug I noticed was
eager typing of annotations, which I patched by not inferring `tracked`
for annotated parameters.
For instance, tracked `would` be inferred for the `SetFunctor` class
128
+
we defined before, so we can also write it like this:
129
+
```scala
130
+
classSetFunctor(valord:Ordering):
131
+
typeSet=List[ord.T]
132
+
...
135
133
```
136
-
In the example above, `ord` is referenced in the signatures of the public
137
-
members of `OrdSet`, so a `tracked` modifier will be inserted automatically.
134
+
The `tracked` modifier on the `ord` parameter is inferred here, since `ord` is of type `Ordering`, which defines an abstract type member `T`.
138
135
139
136
Another common case is when a context bound has an associated type (i.e. an abstract type member) e.g.
140
137
```scala 3
@@ -145,7 +142,7 @@ trait TC:
145
142
classKlass[A: {TCastc}]
146
143
```
147
144
148
-
Here, `tc` is a context bound with an associated type `T`, so `tracked` will be inferred for `tc`.
145
+
Here, `tc` is a context bound with an associated type `T`, so `tracked val` will be inferred for `tc` and the parameter will be represented as a field.
149
146
150
147
### Discussion
151
148
@@ -160,10 +157,10 @@ If we assume `tracked` for parameter `x` (which is implicitly a `val`),
160
157
then `foo` would get inferred type `Foo { val x: 1 }`, so it could not
161
158
be reassigned to a value of type `Foo { val x: 2 }` on the next line.
162
159
163
-
Another approach might be to assume `tracked` for a`val`parameter `x`
164
-
only if the class refers to a type member of `x`. But it turns out that this
165
-
scheme is unimplementable since it would quickly lead to cyclic references
166
-
when typechecking recursive class graphs. So an explicit `tracked`looks like the best available option.
160
+
Another concern is that using tracked for all`val`parameters, including
161
+
parameters of case classes could lead to large refinement types.
162
+
163
+
Therefore, inferring tracked only for parameters with types that define abstract members is a usable compromise. After all, if we did not infer `tracked`for these types, any references to the abstract type via a path would likely produce compilation errors.
0 commit comments