Expand description
The AST depth gate — “parsed ⇒ bounded”.
Every consumer downstream of the parser (optimizer, codegen, tree-walker,
VM compiler, transpiler) walks the AST recursively; a tree nested
thousands of levels deep (a 10,000-term 1+1+… chain, a parenthesis
tower, a generated block pyramid) overflows their stacks and aborts the
process — on every surface at once (CLI, REPL, LSP, web Studio).
The gate enforces one contract at the single choke point
(Parser::parse_program): any program that parses has
nesting depth ≤ the enforced limit (max_ast_depth), so downstream
recursion is bounded by construction. Programs past the limit get a graceful
AstTooDeep diagnostic with
a Socratic fix (split into Let bindings).
The walker itself is iterative (an explicit work stack) — measuring the depth must never be the thing that overflows. Its matches are exhaustive with no wildcard: adding an AST variant with children fails compilation here, forcing the author to classify the new children — the ratchet that keeps the gate honest as the language grows.
Boxed noun-phrase payloads (Categorical, Relation, NeoEvent,
comparatives) carry Terms whose nesting is
bounded by English sentence structure, not by program size — they count
as one level.
Enums§
- Visited
- A node
for_each_nodehands its visitor. - Walk
- Whether a
walk_nodesvisitor goes on into the children of the node it was handed.
Constants§
- DEFAULT_
MAX_ AST_ DEPTH - The DEFAULT maximum AST nesting depth.
- MIN_
AST_ DEPTH - The smallest limit the override accepts — below this, ordinary programs stop parsing.
Functions§
- expr_
children - The expressions an expression evaluates directly — its operands, arguments, elements — in the same exhaustive enumeration the depth gate walks. A closure’s body is not among them: it runs when the closure is called, not when the closure expression is evaluated.
- for_
each_ node - Visit every statement and expression in
stmts, each once — the same exhaustive child enumeration the depth gate walks, so a new variant’s children are reached here the moment the gate reaches them. Iterative, like the gate: visiting must never be what overflows. - limit_
from - Pure resolution of the override value (unit-testable without touching
process environment): a parseable value is clamped to at least
MIN_AST_DEPTH; anything else falls back to the default. - max_
ast_ depth - The EFFECTIVE depth limit:
DEFAULT_MAX_AST_DEPTHunless theLOGOS_MAX_AST_DEPTHenvironment variable overrides it. - max_
parse_ recursion - The parse-time recursion budget: an EIGHTH of the AST limit (min the floor).
- program_
depth - Measure the maximum nesting depth of a parsed program, iteratively.
- stmt_
expr_ children - The expressions a statement evaluates directly (its value, condition, target, arguments — not the statements of its nested blocks).
- validate_
program_ depth - Validate a parsed program against the effective limit
(
max_ast_depth). - walk_
nodes for_each_node, with the visitor answering for each statement and expression whether the walk goes on into its children. Exhaustive in the same way: a child is left unvisited only because a visitor said so, never because the walk does not know the kind of node it is in.