Closed eejbyfeldt closed 1 year ago
Maybe I'm not the only person excited to see escaped quote in an interpolated string in the example code. It represents so many years of labor and frustration.
It works for me. What stack size are we talking? Anyway, easy to reproduce to see the non-tailrec loop.
➜ snips scala -Xlint example-writer.scala
➜ snips scala -Xlint list-test.scala
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, [snip]
➜ snips scala -Xlint -J-Xss256k list-test.scala
Exception in thread "main" java.lang.StackOverflowError
at scala.reflect.internal.tpe.TypeComparers.thirdTry$1(TypeComparers.scala:582)
at scala.reflect.internal.tpe.TypeComparers.secondTry$1(TypeComparers.scala:519)
at scala.reflect.internal.tpe.TypeComparers.firstTry$1(TypeComparers.scala:495)
at scala.reflect.internal.tpe.TypeComparers.isSubType2(TypeComparers.scala:615)
at scala.reflect.internal.tpe.TypeComparers.isSubType1(TypeComparers.scala:347)
at scala.reflect.internal.tpe.TypeComparers.isSubType(TypeComparers.scala:305)
at scala.reflect.internal.tpe.TypeComparers.isSubType$(TypeComparers.scala:267)
at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:28)
at scala.reflect.internal.tpe.TypeComparers.retry$2(TypeComparers.scala:440)
at scala.reflect.internal.tpe.TypeComparers.isSubType2(TypeComparers.scala:443)
at scala.reflect.internal.tpe.TypeComparers.isSubType1(TypeComparers.scala:347)
at scala.reflect.internal.tpe.TypeComparers.isSubType(TypeComparers.scala:305)
at scala.reflect.internal.tpe.TypeComparers.isSubType$(TypeComparers.scala:267)
at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:28)
at scala.reflect.internal.tpe.GlbLubs.$anonfun$elimSub$1(GlbLubs.scala:225)
at scala.reflect.internal.tpe.GlbLubs.$anonfun$elimSub$1$adapted(GlbLubs.scala:225)
at scala.reflect.internal.tpe.GlbLubs.loop$1(GlbLubs.scala:203)
Minimized
import scala.jdk.CollectionConverters._
import java.nio.file.{Files, Path}
object Test extends App {
val header = """|object Test extends App {
| val myStrings: List[String] = List(""".stripMargin.linesIterator
val footer = """| )
| println(myStrings.mkString(","))
|}""".stripMargin.linesIterator
val values = Iterator.tabulate(4000)(i => s" \"$i\",")
val lines = header ++ values ++ footer
Files.write(Path.of("list-test.scala"), lines.to(Iterable).asJava)
}
The stack size it failed for me was 1M
using
$ java --version
openjdk 17.0.6 2023-01-17
OpenJDK Runtime Environment (Red_Hat-17.0.6.0.10-1.fc37) (build 17.0.6+10)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.6.0.10-1.fc37) (build 17.0.6+10, mixed mode, sharing)
Reproduction steps
Using this helper program
create_strings.scala
and compiling the results
Problem
I would expect scala to compile the program with the default jvm stack size.
Some more information
This is only problem in 2.13 both scala 2.12 and scala 3 seems to compile the code without issues. This seems to be lated to literal types I think the overflow seems to happen we call the function
scala.reflect.internal.tpe.GlbLubs.loop$1
with literal types in the collection.Doing the same instead with ints we do not get a stackoverflow. e.g program
create_int.scala
compiles without issues