-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Specialize generics for value classes #2073
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
Comments
The line as given is compiled fine by dotty. Is there something else that does not work? |
I've added a test that will make sure that this code keep compiling. |
I just tested this with: final case class Fix[F[_]](unfix: F[Fix[F]]) extends AnyVal
sealed trait Calc[+A]
case class Num(n: Int) extends Calc[Nothing]
case class Add[A](a: A, b: A) extends Calc[A]
object X {
def c: Fix[Calc] =
Fix[Calc](Add(
Fix[Calc](Num(1)),
Fix[Calc](Num(3))))
} and the bytecode is:
The value class is being instantiated.
|
@odersky @DarkDimius should we reopen this ticket for the above, or should I create a separate one? |
@japgolly, The feature that your example needs to compile to efficient code is value-class specialization of Currently, without value-class specialization, your optimized code has different semantics. case class Add[A](a: A, b: A) extends Calc[A]{
println(a.toString) // change
}
final case class Fix[F[_]](unfix: F[Fix[F]]) extends AnyVal {
def toString() = "fix" // change
} Which toString should Add call? in the bytecode you're suggesting the constructor argument of Add |
@DarkDimius Ah of course, I didn't even think about specialisation! So this will most likely be solved by Linker and WPO later? |
Closing with stat:revisit since specialization isn't likely to come to Dotty soon. |
Using a fixpoint types, every node in the tree becomes boxed.
It would be great if
Fix
could be made a value class.The text was updated successfully, but these errors were encountered: