VirtusLab / using_directives

12 stars 8 forks source link

StackOverflowException in Scanner.getIdentRest #57

Open JD557 opened 1 year ago

JD557 commented 1 year ago

I'm getting a StackOverflowException on https://github.com/VirtusLab/using_directives/blob/8a431a5f91d6fdb226395516d289dfa709792b4e/src/main/java/com/virtuslab/using_directives/custom/Scanner.java#L343 when trying to load markdown gist on scala-cli.

java.lang.StackOverflowError
  com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError0(StackOverflowCheckImpl.java:333)
  com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError(StackOverflowCheckImpl.java:329)
  com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.throwNewStackOverflowError(StackOverflowCheckImpl.java:309)
  com.virtuslab.using_directives.custom.CustomCharArrayReader.skipCR(CustomCharArrayReader.java:85)
  com.virtuslab.using_directives.custom.CustomCharArrayReader.nextChar(CustomCharArrayReader.java:33)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:342)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  [...]

I assume Java does not apply TCO and that needs to be rewritten as a while loop?

tgodzik commented 1 year ago

Thanks for reporting!

I assume Java does not apply TCO and that needs to be rewritten as a while loop?

Looks like it, could you send us the using directives it breaks on?

JD557 commented 1 year ago

I'm using the following directives:

//> using jvm "adopt:11"
//> using scala "3.3.0"
//> using toolkit latest
//> using lib "eu.joaocosta::minart::0.5.2"
//> using lib "eu.joaocosta::interim::0.1.3-SNAPSHOT"

You can see the problematic gist here: https://gist.github.com/JD557/4bd5b7acd53a08e8a9a306a2bde57a97.

Note that:

tgodzik commented 1 year ago

https://github.com/VirtusLab/using_directives/pull/58 should help though I can't see anyr eason this would fail :thinking:

What is the command you are using exactly?

JD557 commented 1 year ago

Here's the command (with the verbose flag) and results:

PS D:\> scala-cli version
Scala CLI version: 1.0.1
Scala version (default): 3.3.0
PS D:\> scala-cli --power -v https://gist.github.com/JD557/4bd5b7acd53a08e8a9a306a2bde57a97 --enable-markdown
The `--enable-markdown` option is experimental.
Please bear in mind that non-ideal user experience should be expected.
If you encounter any bugs or have feedback to share, make sure to reach out to the maintenance team at https://github.com/VirtusLab/scala-cli
https://gist.github.com/JD557/4bd5b7acd53a08e8a9a306a2bde57a97/download
  No modified time in response
Error: java.lang.StackOverflowError
For more details, please see 'C:\Users\JOO~1\AppData\Local\Temp\3919656078737004835\.scala-build\stacktraces\1689000521-7998460890380378253.log'

Also, the stack overflow message was slightly different this time, but I'm not sure if that helps:

java.lang.StackOverflowError
  com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError0(StackOverflowCheckImpl.java:333)
  com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.newStackOverflowError(StackOverflowCheckImpl.java:329)
  com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.throwNewStackOverflowError(StackOverflowCheckImpl.java:309)
  java.base@17.0.6/java.lang.Character.isWhitespace(Character.java:10896)
  java.base@17.0.6/java.lang.Character.isWhitespace(Character.java:10865)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:340)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  com.virtuslab.using_directives.custom.Scanner.getIdentRest(Scanner.java:343)
  [...]
JD557 commented 1 year ago

I cannot reproduce the error anymore... I wonder if something got fixed in the latest version of scala-cli (since looks like this wasn't merged yet).

I did change the binary files, though, and I think the preprocessor is running on binary files as well (see https://github.com/VirtusLab/scala-cli/issues/2306)

tgodzik commented 1 year ago

I didn't yet merge it since I wanted to reproduce it first, but that seems it might be hard. It's probably good to merge anyway.