Skip to content

(bug fix): Grow the stack in recursive passes instead of overflowing on deeply nested code. - #10460

Open
orizi wants to merge 1 commit into
mainfrom
orizi/sufficient-stack
Open

orizi wants to merge 1 commit into
mainfrom
orizi/sufficient-stack

Conversation

@orizi

@orizi orizi commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Adds with_sufficient_stack (based on stacker) and uses it at the
recursion roots of the parser, semantic computation, usage analysis,
lowering, remapping optimization and formatter. Fixes #9755.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com


Stack created with GitHub Stacks CLI • Give Feedback 💬

@cursor

cursor Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches hot recursive paths across parse, semantic analysis, lowering, and formatting; incorrect stack handling could affect reliability or performance on edge-case inputs.

Overview
Prevents stack overflow on pathologically deep user code by introducing with_sufficient_stack in cairo-lang-utils (via the stacker crate), which grows the stack when remaining space drops below a red zone.

That wrapper is applied at the recursion entry points of the formatter (format_node), parser (try_parse_expr_limited, try_parse_type_expr, try_parse_pattern), semantic pipeline (maybe_compute_expr_semantic, compute_pattern_semantic, maybe_resolve_type, usage handle_expr), lowering (lower_expr), and remapping optimization (set_used_impl, map_var_id_impl).

A new test_deeply_nested_expressions test runs lowering on a 1 MiB thread stack for several 3000-deep nesting patterns to ensure the fix holds under tight stack limits.

Reviewed by Cursor Bugbot for commit b665019. Bugbot is set up for automated code reviews on this repo. Configure here.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@orizi
orizi force-pushed the orizi/sufficient-stack branch from 687e1d7 to db56673 Compare October 21, 2026 11:26
@orizi
orizi force-pushed the orizi/sufficient-stack branch from db56673 to 0e3d710 Compare November 5, 2026 13:36
…on deeply nested code.

Adds `with_sufficient_stack` (based on `stacker`) and uses it at the
recursion roots of the parser, semantic computation, usage analysis,
lowering, remapping optimization and formatter. Fixes #9755.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@orizi
orizi force-pushed the orizi/sufficient-stack branch from 0e3d710 to b665019 Compare November 11, 2026 12:22

This branch has not been deployed

No deployments
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.

bug: Compiler stack overflow crash on deeply nested expressions (~450+ levels)

2 participants