-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Change rules for given prioritization #19300
Conversation
This is a test PR, to see what breaks in the CB. |
a796a1f
to
c4c80e0
Compare
8159725
to
d3c3d70
Compare
It turns out nothing broke. I only had to change
So I think we can go ahead with this. What's currently implemented:
In 3.4 we only revert back overloading resolution to be always specializing without flipping contravariant arguments. I believe that was a mistake to do it in the first place. The only use cases for the strange flip came from implicit arguments, there was never a question to extend it to overloading resolutioin. |
The implementation looks good to me, but I believe this will need to be experimental until we go through the SIP process since it's a spec change.
|
That's the problem: The example we got (and handled) was already very specialized. Who wants a monad and a traversable in the same function? But what's much more common is that I have the three classes as defined and I want a Functor! Seems obvious, but so far I could not do it. This PR solves the problem. About going through the SIP process. In theory, yes. But I must admit to myself that I simply don't have the bandwidth to do this. So unless we get a jump in resources and other people going ahead with this, we have to conclude that this will likely not get fixed. I am thinking of creating a separate branch where I do these improvements. Then the SIP committee or anybody else can pick what they think is worthwhile and turn it into a SIP. |
c772d17
to
0852d03
Compare
I think this needs to be merged, and I will not have the bandwidth to make a SIP for this. Are there other opinions how to proceed here? |
@smarter It turns out that Dimi's attempted hylolib port had lots of problems with ambiguities, and they all went away with I suggest we roll this in for 3.5 and run the open community build to see whether there are any breakages that can't be fixed. |
I assume #19395 will have a SIP? If the change to given resolution passes the open community build then it's probably uncontroversial enough that it could be a line item in the larger SIP of #19395. Alternatively, maybe @kyouko-taiga would be interested in making a SIP just for the given resolution changes motivated by examples from hylolib? |
Sorry, I misread. Yes, of course #19395 will be a SIP. I'd be OK with this fix being a line item, except that I think it would be important to roll it in quickly before there is more code that could break. Type inference changes are always tricky, as we know. So I think it's better to treat it as an independent first step. I believe #19395 would take a lot more time to be properly discussed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not opposed to this being merged now, but I do hope we find the time to discuss it in a wider venue nevertheless.
I'm happy to work on a SIP draft for #19395 but it should be clear that I am not the designer of the proposed changes. I merely presented Martin with a list of complaints and let him do the hard work. Maybe something that could make more sense is for me to write a sort of blog post justifying why one would like to write code in the style of hylo-lib. |
You can co-sign with Martin - as you say you have a lot to say in the motivation section |
de97131
to
2d6de6e
Compare
2d6de6e
to
09f6913
Compare
@WojciechMazur We are considering merging this change for 3.5. Can we run an open CB to see what the damage would be? In the small CB it only caused one regression in a Shapeless 3 test, which arguably detected an error in the test. |
I've run the Open CB for this project 2 weeks ago and there were some failures:
I've started a new build using the rebased version of this PR to confirm the results |
Ah yes, thanks for reminding me. I think the results will be similar now.
…On Wed, Apr 17, 2024 at 2:39 PM Wojciech Mazur ***@***.***> wrote:
I've run the Open CB for this project 2 weeks ago and there were some
failures:
Project Version Build URL Notes
7mind/izumi 1.2.7 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8546672779/job/23422651877> No
given instance of
apache/pekko-connectors 1.0.2 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8546672779/job/23417510904> No
given instance of
typelevel/kittens 3.3.0 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8546672779/job/23418739535> No
given instance of
j5ik2o/akka-persistence-s3 1.2.177 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8546672779/job/23417522349> no
member new scala.beans.BeanProperty
kalin-rudnicki/harness 4.1.4 -> 4.1.7 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8552762608/job/23434682090> Recursion
limit exceeded.
dfianthdl/dfiant 0.3.7 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8546672779/job/23418552357> Recursion
limit exceeded
rssh/dotty-cps-async 0.9.19 -> 0.9.21 Open CB logs
<https://github.com/VirtusLab/community-build3/actions/runs/8546672779/job/23417531690>
I've started a new build using the rebased version of this PR to confirm
the results
—
Reply to this email directly, view it on GitHub
<#19300 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCKVROGJXZ3ZAPQ7GRJC3Y5ZUQNAVCNFSM6AAAAABA33VSW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRRGE3DMMJRHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Martin Odersky
Professor, Programming Methods Group (LAMP)
Faculty IC, EPFL
Station 14, Lausanne, Switzerland
|
👍 for RC3 |
There is a conflict between opaqueHandler and userIdOfWriter for UserId Both are sastify for BSONWriter[UserId]. In this case of conflicting, before 3.5 the compiler will pick the more specific type (in this case opaqueHandler: BSONHandler[UserId] because it's more specific than BSONWriter[UserId]). In 3.6 they will flip the priority, a.k.a pic the most general. So, this specific case doesn't really affect us. But removing implicit ambiguity is good anyway I guess. More detail on the implicit resolution change here: scala/scala3#19300
There is a conflict between opaqueHandler and userIdOfWriter for UserId Both are sastify for BSONWriter[UserId]. In this case of conflicting, before 3.5 the compiler will pick the more specific type (in this case opaqueHandler: BSONHandler[UserId] because it's more specific than BSONWriter[UserId]). In 3.6 they will flip the priority, a.k.a pic the most general. So, this specific case doesn't really affect us. But removing implicit ambiguity is good anyway I guess. More detail on the implicit resolution change here: scala/scala3#19300
There is a conflict between opaqueHandler and userIdOfWriter for UserId Both are sastify for BSONWriter[UserId]. In this case of conflicting, before 3.5 the compiler will pick the more specific type (in this case opaqueHandler: BSONHandler[UserId] because it's more specific than BSONWriter[UserId]). In 3.6 they will flip the priority, a.k.a pic the most general. So, this specific case doesn't really affect us. But removing implicit ambiguity is good anyway I guess. More detail on the implicit resolution change here: scala/scala3#19300
There is a conflict between opaqueHandler and userIdOfWriter for UserId Both are sastify for BSONWriter[UserId]. In this case of conflicting, before 3.5 the compiler will pick the more specific type (in this case opaqueHandler: BSONHandler[UserId] because it's more specific than BSONWriter[UserId]). In 3.6 they will flip the priority, a.k.a pic the most general. So, this specific case doesn't really affect us. But removing implicit ambiguity is good anyway I guess. More detail on the implicit resolution change here: scala/scala3#19300
to account for changes in given prioritization from scala#19300 and scala#21226
to apply the logic prioritizing givens over implicits as intended in scala#19300 Fix scala#21212
instead of an `implicit val`, to account for the changes in given prioritization from scala#19300 and scala#21226, which made it ambiguous with the `Completer#creationContext` given.
@odersky Question about this snippet: trait Eq[A]
trait Order[A] extends Eq[A]:
def toOrdering: Ordering[A]
def Test[Element: Eq: Order] = summon[Eq[Element]].toOrdering It compiles fine (in both 3.5 and 3.nightly) unless when using |
The difference is that under -source:future, context bounds become using
clauses, so the new prioritization applies. That's another (hopefully the
last) thing we need to change. Maybe we can change it for 3.6 already, so
that the priority change all happens at once?
…On Tue, Jul 23, 2024 at 11:29 PM Wojciech Mazur ***@***.***> wrote:
@odersky <https://github.com/odersky> Question about this snippet:
trait Eq[A] trait Order[A] extends Eq[A]:
def toOrdering: Ordering[A]
def Test[Element: Eq: Order] = summon[Eq[Element]].toOrdering
It compiles fine (in both 3.5 and 3.nightly) unless when using
-source:future. Bisect points out that it started to fail with value
toOrdering is not a member of Eq[Element] since this change, but there
seems to be nothing specific introduced that might change behaviour under
-source:future.
In general, it seems to be more correct behaviour, although I cannot
understand why it changed and why it behaves like that only in the future
source version.
—
Reply to this email directly, view it on GitHub
<#19300 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCKVSKYJUT4NHJKFDRNJTZN3DLTAVCNFSM6AAAAABA33VSW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBWGM2TAOJSGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Martin Odersky
Professor, Programming Methods Group (LAMP)
Faculty IC, EPFL
Station 14, Lausanne, Switzerland
|
to apply the logic prioritizing givens over implicits as intended in scala#19300 Fix scala#21212
instead of an `implicit val`, to account for the changes in given prioritization from scala#19300 and scala#21226, which made it ambiguous with the `Completer#creationContext` given.
to apply the logic prioritizing givens over implicits as intended in scala#19300 Fix scala#21212
instead of an `implicit val`, to account for the changes in given prioritization from scala#19300 and scala#21226, which made it ambiguous with the `Completer#creationContext` given.
In fact, I think we should do the switch to using clauses also in 3.6. Migration should not be a problem since we warn about the change since 3.4. For instance class Eq[A]
val eq: Eq[Int] = Eq()
def foo[T: Eq]: Eq[T] = ???
val x = foo(eq) gives:
We could make the warning an error in 3.6-migration and switch to the new behavior in 3.6. That would make the implicit priority change more coherent, and avoid a surprising exception. |
Correction: The warning is already an error in 3.5. So we are already covered and all that's needed is to do the switch. |
Was future before. We can roll this out now, since we already made it an error in 3.5 to pass a normal argument to a using clause. It would be good to roll this out now since otherwise context bounds would represent an exception to the implicit priority inversion in #19300. See discussion at the end of #19300 for details.
Also set `-source:3.7` as they delay [new givens prioritization scheme](scala/scala3#19300) to scala 3.7. And We want to keep using this new scheme as We already migrated to this scheme.
blog post about this: scala/scala-lang#1675 (still a draft, at the moment) |
Consider the following program:
With the current rules, this would fail with an ambiguity error between B and C when trying to synthesize the A parameter. This is a problem without an easy remedy.
We can fix this problem by flipping the priority for implicit arguments. Instead of requiring an argument to be most specific, we now require it to be most general while still conforming to the formal parameter.
There are three justifications for this change, which at first glance seems quite drastic:
Comparable
. Instead of this hack, we now do something more principled, by flipping the direction everywhere, preferring general over specific, instead of just flipping contravariant type parameters.