Skip to main content

MAX_AST_SERIALIZE_DEPTH

Constant MAX_AST_SERIALIZE_DEPTH 

Source
pub const MAX_AST_SERIALIZE_DEPTH: usize = 512;
Expand description

Greatest AST depth AstNode will serialize.

An AstNode tree is as deep as the parsed expression nesting, which a caller controls directly — 100 000 levels fit in a 200 KB payload, well inside bca-web’s body cap. serde cannot emit a tree without one native stack frame per level, and overflowing that stack aborts the process rather than raising a catchable panic (#1056), so the depth is bounded: a deeper tree fails serialization with an ordinary serializer error naming the limit.

The bound is set well clear of real source: the deepest AST across the ~8 000-file corpus under tests/repositories (TensorFlow, serde, DeepSpeech, …) is 188 levels. It is also set well clear of the stack: the earliest measured overflow of any emitted format was 2 000 levels on a debug build’s default 2 MiB thread.