kernel: walkers iterate children with kids()/named_kids() instead of index loops

Merged
BO
2mo ago
+514-807

Item A-Q10 of the code-quality review. Output is unchanged. Net −315 lines.

The walkers had about 420 child-iteration loops written as for i in 0..n.named_child_count() { if let Some(c) = n.named_child(i) { … } } or (0..n.named_child_count()).filter_map(|i| n.named_child(i)). There was no shared helper, and Dart, Lua and Scala used a third style.

  • walker::kids(node) and named_kids(node) yield the same sequence as child(0..child_count()) and named_child(0..named_child_count()).
  • 269 loops whose body never uses the index were converted. The 148 left either use the index (for example, sibling walks backwards) or have a different shape, and they stay as they are.
  • child(i) scans from the first child, so the index loops were quadratic in a node's child count. kids walks wide nodes (16 or more children) with one cursor. For narrow nodes, which are most of them, it keeps the index lookups: a first version that always used a cursor paid for an allocation on every call.

Gate: dump-graph byte-identical against the #112 kernel on all 15 corpora. Parse-loop time is neutral: discourse, three alternating runs, averaged 7,604 ms before and 7,694 ms after, with one run faster after. Also: kernel unit tests 34/34; clippy -D warnings; ast-grep rules; full suite 303 files, 5,178 tests.