-
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
Fix specifity comparison for extensions in polymorphic givens #13509
Conversation
- Add Context#withTyperState - Add a committable parameter to TyperState#fresh
Previously, the code in the closure passed to `comparing` could have been using the wrong context. I don't think this happened in practice so far because comparingCtx was always equal to ctx but it will matter in the next commit.
When we compare polymorphic methods for specificity, we replace their type parameters by type variables constrained in the current context (see isAsSpecific), but for extension methods in polymorphic givens, the comparison was done with a constraint set that does not include the type parameters of the givens, this lead to ambiguity errors as experienced in typelevel/spotted-leopards#2. We fix this by ensuring the TyperState we use for the comparison contains any additional constraint specific to the TyperState of either alternative. This required generalizing TyperState#mergeConstraintWith to handle `this` not being committable (because in that case `this` does not need to take ownership of the type variables owned by `that`, therefore `that` itself is allowed to be committable).
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.
Looks reasonable to me
test performance please |
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.
LGTM, with just a question about performance implications.
// alternatives correctly we need a TyperState that includes | ||
// constraints from both sides, see | ||
// tests/*/extension-specificity2.scala for test cases. | ||
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint |
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.
Is constraintsIn1/2
expected to be rarely true? So, no performance implications?
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'd expect this codepath to be rarely hit since it's already in a fallback path and will only concern polymorphic givens with matching extension methods.
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit https://dotty-bench.epfl.ch/13509/ to see the changes. Benchmarks is based on merging with master (8d9542c) |
When we compare polymorphic methods for specificity, we replace their
type parameters by type variables constrained in the current
context (see isAsSpecific), but for extension methods in polymorphic
givens, the comparison was done with a constraint set that does not
include the type parameters of the givens, this lead to ambiguity errors
as experienced in
typelevel/spotted-leopards#2.
We fix this by ensuring the TyperState we use for the comparison
contains any additional constraint specific to the TyperState of either
alternative. This required generalizing TyperState#mergeConstraintWith
to handle
this
not being committable (because in that casethis
doesnot need to take ownership of the type variables owned by
that
,therefore
that
itself is allowed to be committable).