Skip to content

[CI only] Attempt a fix to a potential problem in RecursionOverflow #5862

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

Conversation

abgruszecki
Copy link
Contributor

This is an attempt at a fix to the potential problem that causes #5860. The stack overflow looks as follows:

java.lang.StackOverflowError while compiling /tmp/1/tests/neg/i4371b.scala
java.lang.StackOverflowError
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
	at dotty.tools.dotc.core.RecursionOverflow.recursions(TypeErrors.scala:49)
...

I cannot replicate the problem locally in a simple way, even if I add a test like this:

compileFile("tests/neg/i4371b.scala", defaultOptions).times(10000)

Seems triggering it depends in some way on current VM state. I'll try to run the CI a few times and see if I can catch the issue.

@abgruszecki abgruszecki force-pushed the ci/recursion-of-recursions branch from c23d5fc to c0a4ed0 Compare February 6, 2019 13:53
Copy link
Contributor

@Blaisorblade Blaisorblade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not this is the bug, the change to recursions look very reasonable: the current definition is not tail-recursive, so it has no business being invoked in stack-overflow-related code. Notice the code in handleRecursive creating the RecursionOverflow chain uses a while loop for the same reason.

Not sure if we can re-enable the flaky test, more fixes might be needed.

val result = ListBuffer.empty[RecursionOverflow]
@annotation.tailrec def loop(throwable: Throwable): List[RecursionOverflow] = throwable match {
case ro: RecursionOverflow =>
if (result.contains(ro)) println("caught the issue")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’d be very surprising if the RecursionOverflow chain was cyclic. However, the length of the chain is proportional to the stack depth, so it’s best traversed in constant stack size. To see why, you need to see how RecursionOverflow is created by handleRecursive and how that’s used in certain recursive methods in Typer (I can explain in person if desired).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure if the RecursionOverflow chain can actually be cyclic. If it's really proportional to stack depth, then it makes sense to construct recursions in a loop. How about I simply open a separate PR with that change and we merge it on its own?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead!

@abgruszecki
Copy link
Contributor Author

Closing, as I could not replicate the mysterious StackOverflow.

@abgruszecki abgruszecki closed this Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants