Skip to content

Commit 2040fb2

Browse files
committed
Preload handleRecursive to prevent nested stackoverflows
Thanks `@smarter` for guidance.
1 parent ec460a1 commit 2040fb2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

compiler/src/dotty/tools/dotc/core/TypeErrors.scala

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class RecursionOverflow(val op: String, details: => String, previous: Throwable,
7575
override def getStackTrace() = previous.getStackTrace()
7676
}
7777

78+
/** Post-process exceptions that might result from StackOverflow to add
79+
* tracing information while unwalking the stack.
80+
*/
81+
// Beware: Since this object is only used when handling a StackOverflow, this code
82+
// cannot consume significant amounts of stack.
7883
object handleRecursive {
7984
def apply(op: String, details: => String, exc: Throwable, weight: Int = 1): Nothing = exc match {
8085
case _: RecursionOverflow =>

compiler/src/dotty/tools/package.scala

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ package object tools {
55
class sharable extends Annotation
66
class unshared extends Annotation
77

8+
// Ensure this object is already classloaded, since it's only actually used
9+
// when handling stack overflows and every operation (including class loading)
10+
// risks failing.
11+
dotty.tools.dotc.core.handleRecursive
12+
813
val ListOfNil = Nil :: Nil
914

1015
/** True if two lists have the same length. Since calling length on linear sequences

0 commit comments

Comments
 (0)