Skip to content

Stack overflow when processing many command line arguments #12588

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

Closed
oyvindberg opened this issue May 24, 2021 · 2 comments · Fixed by #12589
Closed

Stack overflow when processing many command line arguments #12588

oyvindberg opened this issue May 24, 2021 · 2 comments · Fixed by #12589
Milestone

Comments

@oyvindberg
Copy link

Hey there.

I noticed the compiler fails with a StackOverflowError after around 6000 arguments. I had a quick look, and the problem seems to be non stack safe recursive method. I didn't have time to fix it myself, but I did come up with a failling test.

I happened upon this because I setup compilation with bloop, which somewhere along the way produces a list of all input files, for hashing purposes it seems. All these file names are then passed to the compiler as command line arguments.

Compiler version

3.0.0

Failing test case

--- a/compiler/test/dotty/tools/dotc/SettingsTests.scala
+++ b/compiler/test/dotty/tools/dotc/SettingsTests.scala
@@ -54,6 +54,13 @@ class SettingsTests {
       assertEquals(1, Settings.bar.value)
     }
 
+  @Test def `dont crash on many files`: Unit =
+    inContext {
+      val args = List.fill(6000)("file.scala")
+      val summary = new config.ScalaSettings().processArguments(args, true)
+      assertEquals(Nil, summary.errors)
+    }
+
   @Test def validateChoices: Unit =
     object Settings extends SettingGroup:
       val foo = ChoiceSetting("-foo", "foo", "Foo", List("a", "b"), "a")

Output

java.lang.StackOverflowError
	at scala.collection.immutable.List.equals(List.scala:612)
	at dotty.tools.dotc.config.Settings$SettingGroup.processArguments(Settings.scala:227)
	at dotty.tools.dotc.config.Settings$SettingGroup.processArguments(Settings.scala:242)
	at dotty.tools.dotc.config.Settings$SettingGroup.processArguments(Settings.scala:242)

Expectation

@som-snytt
Copy link
Contributor

Thanks for the test case. It turns out you did have time to DYI, but I appreciate the opportunity to remember how to run a test in dotty. Just adding final was sufficient, even though other calls are not tailrec.

What took so long was that you add tailrec, it says it can't because not final, so you add final, then it says it can't because of the other calls, then you remove tailrec, and the test passes and you think you must have broken the test, or sbt didn't run it or incremental compilation is broken.

@oyvindberg
Copy link
Author

Great! I started down that path too, but didn't notice the test started passing. Started rewriting the entire thing and figured somebody else would be able to jump in and fix it with a smaller change. Happy I was proved right :)

oyvindberg added a commit to ScalablyTyped/Converter that referenced this issue May 29, 2021
oyvindberg added a commit to ScalablyTyped/Converter that referenced this issue Jul 5, 2021
oyvindberg added a commit to ScalablyTyped/Converter that referenced this issue Jul 5, 2021
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants