-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
scala/scala
#9886Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)performancetyper
Milestone
Description
reproduction steps
using Scala 2.13.5,
// Note: Removing `+` here has no effect on the issue:
type ~[+A, +B] = (A, B)
// Dummy type to allow us to map + pattern match
trait A[T] { def map[U](fn: T => U): A[U] = new A[U] {} }
// 25 nested Int's, both the same type
type B = ((((((((((((((((((((((((Int, Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int), Int)
type C = Int ~ Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int ~Int~Int
val ab = new A[B] {}
val ac = new A[C] {}
// Instant compile time:
ab.map { case ((((((((((((((((((((((((_, _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _) => 7 }
// Exponential compile time:
ac.map { case ((((((((((((((((((((((((_, _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _) => 7 }problem
Deconstructing a simple alias for a type in a case match causes exponentially increasing compile times, dependent on the depth of the deconstruction.
In the code above, type B and type C are the same, but C is constructed through aliases. Deconstructing type C takes vastly longer than deconstructing type B.
I would expect that ab.map... and ac.map... should take the same length of time to compile.
jbwheatley and plokhotnyuk
Metadata
Metadata
Assignees
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)performancetyper