pub fn solve(ctx: &PassCtx<'_>, diff: &mut ASTDiff)Expand description
Pre-match top-level items with large flat descendants (e.g. a Rust macro’s token_tree body,
a big flat argument/element list, …) via Myers O(ND) sequence diff, before anything else in
the pipeline gets a chance to bury them inside a much larger, non-flat comparison.
Originally this only looked for Rust macro_invocation nodes by macro name (see git history:
solve_flat_macro_bodies, since removed - folded into this file). Generalized
(2026-07-17) to any top-level item, in any supported language, whose identity can be
established (either nodes::is_semantically_structural’s cross-language name extraction, or -
preserving the original Rust macro case, which is_semantically_structural does not cover -
the macro’s own callee name) and which contains a large flat descendant anywhere inside it.
Mechanism: for each matched top-level (before, after) pair, BFS both subtrees for the single
largest node with >= FLAT_CONTAINER_MIN_CHILDREN direct children (any kind - not just Rust’s
token_tree). If both sides have one, diff that flat pair directly first (resolve_forest
inside for_nodes detects the flat shape and routes to Myers instead of Zhang-Shasha/APTED),
then diff the top-level pair itself (the flat descendant is already in diff -> pruned by the
postorder indexer, so this second call is cheap regardless of how big the item is).
Deliberately scoped to top-level items only (direct children of the file root), not every
semantically_structural_nodes entry at any depth: that map is populated by a full-tree walk
(methods, nested items, …), and BFS-ing inside every one of those as well would rescan a lot
of already-covered ground for no expected benefit - nested large-flat cases inside an otherwise
deeply-structured item are comparatively rare, and this can be widened later if the benchmark
shows it’s worth it.
A file whose grammar wraps a single anonymous root value (JSON, YAML, …) has no named
top-level item to key off at all, so the name-based matching above finds nothing and this pass
used to do nothing for such files (2026-07-23 gap, since fixed): only_named_child gives the
file’s one real top-level value an implicit identity when there’s exactly one on each side and
nothing already matched by name, so a large flat object/mapping at the very top of the file
still gets the same Myers fast path instead of the whole file falling to the old whole-file final_pass APTED on every
edit (see this pass’s own git history / nodes::is_commutative_container’s doc comment for the
concrete case this fixes).