Skip to content

Fix ACTZipper::val_count counting from the zipper root, not the focus - #80

Open
imlvts wants to merge 1 commit into
Adam-Vandervorst:masterfrom
imlvts:bugfix/act-val-count-from-focus
Open

Fix ACTZipper::val_count counting from the zipper root, not the focus#80
imlvts wants to merge 1 commit into
Adam-Vandervorst:masterfrom
imlvts:bugfix/act-val-count-from-focus

Conversation

@imlvts

@imlvts imlvts commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

val_count opened with zipper.reset(). ZipperValues::val_count counts the values at and below the focus, so this returned the count for the whole subtrie under the zipper's root wherever the focus was, and was right only when the focus happened to be at the root.

Removing the reset is not quite enough: to_next_val walks the zipper's entire subtrie rather than the part below the focus, so the walk has to stop when it leaves. Depth-first order visits everything below the focus before anything outside it, so the first path that no longer starts with the focus ends the count.

Regression test: act_zipper_val_count_counts_from_the_focus, against the PathMap zipper at six foci from the map root and three from a zipper rooted below it. Fails before this change.

lean/FINDINGS.md ACT finding "val_count_ignores_focus" on the lean-fuzzer-restage branch.

`val_count` opened with `zipper.reset()`.  `ZipperValues::val_count`
counts the values at and below the *focus*, so this returned the count
for the whole subtrie under the zipper's root wherever the focus was,
and was right only when the focus happened to be at the root.

Removing the reset is not quite enough: `to_next_val` walks the zipper's
entire subtrie rather than the part below the focus, so the walk has to
stop when it leaves.  Depth-first order visits everything below the
focus before anything outside it, so the first path that no longer
starts with the focus ends the count.

Regression test: `act_zipper_val_count_counts_from_the_focus`, against
the PathMap zipper at six foci from the map root and three from a zipper
rooted below it.  Fails before this change.

lean/FINDINGS.md ACT finding "val_count_ignores_focus" on the
lean-fuzzer-restage branch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZmoASqM5FUuzvJeJaYQjR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant