Repository navigation
Conversation
The recursive descent parser had no depth limit, so deeply nested input (e.g. ~5000 nested parentheses) overflowed the stack and aborted the process instead of returning an error. A parse depth counter is now tracked in the parser Context and bounded by max_recursion_depth when set (the existing --max-recursion-depth flag now applies to parsing as well as evaluation), otherwise by a new default of 512. Deep input now yields "Operation recursed too deeply." The CLI also evaluates on a worker thread with a larger stack so the configured limit is reached before the real stack limit. Printing results to a closed pipe (e.g. `kalker "1+1" | head -0`) panicked in std::io::stdio. Output is now written via explicit io::Write calls, and a BrokenPipe error exits the process silently with status 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #194.
Bugs
kalkerwith ~5000 nested parens (or deepor/^/unary chains) overflows the native stack and aborts (0xC00000FDon Windows) instead of returning an error. The existing--max-recursion-depthflag only bounds the evaluator; the recursive-descent parser had no limit.kalker "1+1" | head -0(or any early-closing consumer) panics insideprintln!/print!(stdio.rs).Fix (+162/-30, 4 files)
kalk/src/parser.rs:parse_depthcounter onContext, enforced via awith_depthhelper around every genuinely recursive descent (parse_comprehension,parse_or,parse_and,parse_comparison,parse_shift,parse_exponent,parse_unary,parse_primaryparen/vector/brace). Limit =--max-recursion-depthwhen set (the flag now covers parsing too), else newDEFAULT_MAX_PARSE_DEPTH = 512— chosen from measured overflow thresholds (~1,150 parens release / ~250 debug); 500 nests still evaluate fine, and raising the flag lets 5,000 parens parse cleanly.cli/src/main.rs:default_actionruns on a scoped 64 MiB-stack worker so the configured limit is reached before the real stack runs out; help text updated.cli/src/output.rs+repl.rs: output viaio::Write;BrokenPipe→ silentexit(0)(standard CLI convention, same as coreutils); stderr best-effort.Verified (Windows + Linux)
0xC00000FDOperation recursed too deeply., exit 0sum,sqrt(9)+2^3, stdin5*3)1+1 | head -0×8stdio.rs:1166(racy)or/unary/power chainscargo test81/0 incl. newtest_deeply_nested_expression;fmt/clippyclean; windows-gnu build green.Note: a ~20,000-term left-associative chain can still overflow in AST eval traversal — pre-existing, separate from this fix; happy to follow up.