Scala bomb? (like a zip bomb)

2020-02-23 05:40发布

Please excuse the funny title, I am using it in analogy with "zip bomb". Is it possible to create a scala source file, that will, when compiled, produce a large number of class files (or a very large single class file)? Is there any way the size of the class files could grow faster than linearly with the size of the source file?

1条回答
来,给爷笑一个
2楼-- · 2020-02-23 06:12

Specialization is inherently exponential in the number of type parameters specialized.

class Huge[@specialized A, @specialized B, @specialized C](
  val a: A, val b: B, val c: C
) {} // 730 files, 2.9 MB

class Gigantic[@specialized A, @specialized B, @specialized C, @specialized D](
  val a: A, val b: B, val c: C, val d: D
) {} // 6562 files, 26 MB

Pattern matching can also involve a lot of code duplication for complex cases (though I find it difficult to predict exactly when this will occur).

查看更多
登录 后发表回答