-
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
Instantiate argument type vars before implicit search #19096
Conversation
This looks actually quite promising. The one failure in libretto is probably due to the fact that a type variable is not instantiated to a singleton type. So we might have had a constraint
and proceeded to instantiate to |
That is indeed exactly what happens ! Here is the minimisation I got to: case class Val[T](t: T)
trait Ev[T]
given Ev[String] = ???
given Ev["ping"] = ???
given[T: Ev]: Ev[Val[T]] = ???
def f[T: Ev](v: T): Unit = ???
def g[U](u: U)(using U =:= Val["ping"]): Unit = ???
def main =
val v /*: Val3[String] */ = Val("ping")
f(v) // before changes ✅; after changes ✅
f(Val("ping")) // before changes ❌; after changes ✅
g(v) // before changes ❌; after changes ❌
g(Val("ping")) // before changes ✅; after changes ❌ The instantiation of |
Instead of fully instantiating the type variables, an another possibility we considered is to add the approximation computed for the instantiation as an upper bound constraint. E.g. This does fix the issue with |
0e8a518
to
700fa5e
Compare
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.
Otherwise LGTM. The breakage in Libretto is unfortunate (/cc @TomasMikula) but having played with that code I haven't found an alternative that avoided that. It's possible something akin to scala/improvement-proposals#48 will allow for APIs that can control inference better in the future.
@tailrec def boundVars(tree: Tree, acc: List[TypeVar]): List[TypeVar] = tree match { | ||
case Apply(fn, _) => boundVars(fn, acc) | ||
def boundVars(tree: Tree, acc: List[TypeVar]): List[TypeVar] = tree match { | ||
case Apply(fn, args) => |
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 think the documentation comment of tvarsInParams
needs to be updated to account for these changes.
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.
Indeed !
Thanks for the heads up, @smarter. The breakage from this change is rather minor. I have added a definition transparent inline def constVal[A]: Done -⚬ Val[A] =
constVal(scala.compiletime.constValue[A]) so that the diff to fix the broken code is then just changing Though before I even got this breakage, I had to resolve a couple of different breakages (one of them reported as #19570). The thing is, the community build is using an old version of Libretto. Last time I tried to update (#17044), the community build did not support Java 9 required by Libretto. Would be good to get it resolved so that both you and me get breakage notifications earlier. |
There is one more failure in the Open CB found in @Ichoran /kse3 - build logs class Anon[A](val value: A)
class Mu[A]
object Mu:
final class MuAny[A](v: A) extends Mu[A]
trait Typed[A]
def typed[A]: Typed[A] = ???
class Labeled[A](v: A):
def ====[B](t: Typed[B])(using B =:= A): Unit = {}
@main def Test =
Labeled(Anon(new Mu.MuAny("foo"))) ==== typed[Anon[Mu[String]]]
// After typer:
// In 3.4.0
// new Labeled[Anon[Mu[String]]](
// new Anon[Mu[String]](new Mu.MuAny[String]("cod"))).====[
// Anon[Mu[String]]](typed[Anon[Mu[String]]])(<:<.refl[Anon[Mu[String]]])
// }
// In 3.4.1-RC1 and 3.4.2-RC1-nightly
// new Labeled[Anon[Mu.MuAny[String]]](
// new Anon[Mu.MuAny[String]](new Mu.MuAny[String]("cod"))).====[
// Anon[Mu[String]]](typed[Anon[Mu[String]]])(
// /* missing */summon[Anon[Mu[String]] =:= Anon[Mu.MuAny[String]]])
|
This PR caused the regression #20053 |
Wait, you added kse3 to the CB?! That's lovely! Um! I'll be a little less cavalier about pushing nonsense into it then! 😆 I agree that kse3 is the one who is wrong here: the types are supposed to match exactly, but don't. So the new behavior is an improvement because it catches the bug in how the test is written! 👍 |
@WojciechMazur - Sorry for not noticing your message initially! You're correct that this was (from my perspective) a bug in my test suite that 3.4.1 correctly caught, and I've now fixed it in main. |
No description provided.