Skip to main content

MAX_COMMENTED_DEPTH

Constant MAX_COMMENTED_DEPTH 

Source
pub const MAX_COMMENTED_DEPTH: usize = 1;
Expand description

How deeply a form may nest a commented-out children block — a { … } belonging to a node a /- has commented out.

Its own limit because neither MAX_SOURCE nor MAX_DEPTH bounds it in any useful way. kdl takes time that doubles with every level of one of these inside another: twenty levels is about a hundred bytes and twenty seconds, thirty is six hours, and the sixty-four MAX_DEPTH would permit is longer than the universe has been running. Found by the fuzz target parse_form, which kept reporting three-kilobyte inputs that took a second and a half to fail on.

One level is kept, because commenting a widget and its children out is a real thing to do while editing. Two is refused, because a block commented out inside a block that is already commented out changes nothing about what the file means — the fix is deleting an inner /- that was doing no work — and every one of the slow inputs the fuzzer found is past this line while every form in this repository is nowhere near it.

This bounds the shapes that have been found, and it is not a bound on the parser: kdl 6.7.1 has more exponential corners than this one. The bound on the parser is a clock, and it belongs to the caller — Form::parse_within is it. See fuzz/README.md.