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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,22 @@ class MissingType(pre: Type, name: Name) extends TypeError {
}
}

class RecursionOverflow(val op: String, details: => String, previous: Throwable, val weight: Int) extends TypeError {
class RecursionOverflow(val op: String, details: => String, val previous: Throwable, val weight: Int) extends TypeError {

def explanation: String = s"$op $details"

private def recursions: List[RecursionOverflow] = {
val nested = previous match {
case previous: RecursionOverflow => previous.recursions
case _ => Nil
import scala.collection.mutable.ListBuffer
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!

result += ro
loop(ro.previous)
case _ => result.toList

}
this :: nested
loop(this)
}

def opsString(rs: List[RecursionOverflow])(implicit ctx: Context): String = {
Expand Down
File renamed without changes.