-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Proper constraints on CC types in collections #7504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
(The context for these commits is #6728) |
c7c9872 to
022208f
Compare
This also provides a nice solution for AnyConstr (see scala#7077 and scala#7072): We simply don’t need it anymore. We really want to constrain both IterableCC and MapCC to Iterable (the latter because it’s needed for MapView) but that causes collisions after erasure, so we have to go back to IterableOnce for IterableCC. Using something more specific (like MapOps with Iterable) for MapCC is not possible because in MapView the MapCC is not actually MapView but only View.
022208f to
73188f0
Compare
It’s not clear to me what the benefits of this PR are, given that it doesn’t fix scala/bug#11188. Can you also summarize them? It seems to me that it essentially adds narrower bounds on type parameters, which I think adds more constraints to the use site. |
|
I think it should be possible to get rid of some |
|
The new constraints have no effect on users. For example, |
It might make it harder to abstract over That being said, we could argue that |
|
@szeiger needs rebase after rebase, should we run the 2.13 community build on this before merging? |
|
@SethTisue @julienrf - I'm leaving this one to you guys (and @szeiger of course) to get over the finish line. |
|
If the PR allows us to remove unnecessary calls to |
|
More constrained = more correct. But it's getting too late for such a big change and we still can't get the constraints exactly right so there's not a huge benefit. |
I started this in the hope of eventually fixing scala/bug#11188 but after 2 days I'm giving up. This part here appears to be useful enough on its own. The type constraints are better than before and we don't need
AnyConstranymore.I ran into several problems trying to take this further:
CC[X] <: Seq[X]inSeqOps. The worst case isMapOpswhich requiresCCto be not justMapViewbut even a tupled anonymous type function onView.SortedMapinstead of onlyMapinSortedMapOps.C <: CC[A](and similar ones for other kinds ofCC) but this is not possible because of variance. We needCC[+_]for+AbutCC[_]forA. This becomes a problem when we get to mutable (and therefore invariant) collection types that extend generic (covariant) collection types. We can't tie the knot anymore because the variance changes.MapOpsuses aCCtype constraint to coax the compiler into producing methods with return types that don't clash after erasure with inherited methods fromIterableOpsandSeqOps. Adding the "correct" constraints break this.colland some casts but it quickly gets very verbose because the compiler requires some excessive repetition of self types (in some cases but not others; this might be a bug) even when extending this type directly (so it should automatically be part of the self type).