You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parser: add a depth guard mirroring the type-checker's MAX_EXPR_DEPTH #15
The type-checker now bails out cleanly on overly-deep expressions (MAX_EXPR_DEPTH = 256, see crates/my-lang/src/checker.rs). The parser, however, is recursive-descent and has no such guard: on similarly pathological inputs, parse_expr recurses through every precedence level (parse_or_expr → … → parse_postfix_expr → parse_primary_expr → parse_paren_expr → parse_expr again) and overflows the thread stack with a SIGABRT ("has overflowed its stack, aborting") before the checker ever sees the AST.
This was demonstrated incidentally while writing the regression test for #12: parsing a depth-528 str_concat(...) chain SIGABRTs the test runner. The fix in PR #12 sidesteps it by constructing the AST programmatically.
What to do
Add a MAX_PARSE_EXPR_DEPTH constant (suggested: same as the checker's, or slightly higher, but well below stack-overflow territory for cargo test defaults).
Track recursion depth in the Parser struct (a usize counter, incremented at the entry of parse_expr and decremented on exit).
When exceeded, emit a single ParseError::ExpressionTooDeep { line, column, limit } and stop recursing — let the existing error-recovery machinery (test_error_recovery_*) handle the rest of the file.
Add a regression test that feeds in a generated depth-N source and asserts the parse fails with the new error variant instead of SIGABRT.
Switching the parser to iterative precedence parsing (Pratt / shunting yard). That's a larger refactor; the depth guard is the cheap, safe intermediate step.
Activity
feat(parser): add MAX_PARSE_EXPR_DEPTH guard + recover partial AST (c…