diff --git a/sjsonnet/src/sjsonnet/DebugStats.scala b/sjsonnet/src/sjsonnet/DebugStats.scala index 3204733a..cadbd7e2 100644 --- a/sjsonnet/src/sjsonnet/DebugStats.scala +++ b/sjsonnet/src/sjsonnet/DebugStats.scala @@ -16,6 +16,9 @@ final class DebugStats { var functionCalls: Long = 0 var builtinCalls: Long = 0 + // -- Stack -- + var maxStackDepth: Int = 0 + // -- Comprehensions -- var arrayCompIterations: Long = 0 var objectCompIterations: Long = 0 @@ -39,6 +42,7 @@ final class DebugStats { sb.append(formatLine("lazy_created", lazyCreated)) sb.append(formatLine("function_calls", functionCalls)) sb.append(formatLine("builtin_calls", builtinCalls)) + sb.append(formatLine("max_stack_depth", maxStackDepth)) sb.append(formatLine("array_comp_iterations", arrayCompIterations)) sb.append(formatLine("object_comp_iterations", objectCompIterations)) sb.append(formatLine("files_parsed", filesParsed)) diff --git a/sjsonnet/src/sjsonnet/Evaluator.scala b/sjsonnet/src/sjsonnet/Evaluator.scala index 5b1cf0bd..cb9cf669 100644 --- a/sjsonnet/src/sjsonnet/Evaluator.scala +++ b/sjsonnet/src/sjsonnet/Evaluator.scala @@ -33,6 +33,8 @@ class Evaluator( @inline private[sjsonnet] final def checkStackDepth(pos: Position): Unit = { stackDepth += 1 + if (debugStats != null && stackDepth > debugStats.maxStackDepth) + debugStats.maxStackDepth = stackDepth if (stackDepth > maxStack) Error.fail("Max stack frames exceeded.", pos) }