Skip to content

Add --max-stack / -s flag to limit stack depth#637

Merged
stephenamar-db merged 1 commit intomasterfrom
stack/erro3
Mar 5, 2026
Merged

Add --max-stack / -s flag to limit stack depth#637
stephenamar-db merged 1 commit intomasterfrom
stack/erro3

Conversation

@stephenamar-db
Copy link
Collaborator

Summary

  • Adds a --max-stack / -s CLI flag (default 500) to limit the evaluation stack depth, matching go-jsonnet's -s / --max-stack option.
  • Introduces a stack frame counter in the Evaluator, incremented/decremented at function calls (Apply*, ApplyBuiltin*), object field evaluation (invoke), imports, and default parameter evaluation.
  • When the counter exceeds maxStack, a clear sjsonnet.Error: Max stack frames exceeded. is thrown instead of a raw JVM StackOverflowError.

Test plan

  • JVM tests pass (140/140)
  • WASM tests pass (333/333)
  • New unit tests for recursive functions, mutual recursion, depth within limits, and builtin calls
  • Golden files updated for error.recursive_function_nonterm, error.recursive_import, error.recursive_object_non_term, and error.function_infinite_default
  • CLI flag verified with --max-stack and -s short form

Introduces a stack frame counter in the Evaluator, incremented/decremented
at function calls (Apply*, ApplyBuiltin*), object field evaluation (invoke),
imports, and default parameter evaluation. When the counter exceeds maxStack,
a clear sjsonnet.Error is thrown instead of a JVM StackOverflowError.
@stephenamar-db stephenamar-db merged commit 46e11e8 into master Mar 5, 2026
8 checks passed
@stephenamar-db stephenamar-db deleted the stack/erro3 branch March 5, 2026 21:59
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.

1 participant