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
@luketpeterson

Copy link
Copy Markdown
Collaborator

The current val_count pathway is totally gone, once we merge the new catamorphism trait. So I'd rather not merge the behavior change because it'll just create a conflict.

The test might be fine under the "low bar for a test" philosophy. Also I was thinking I ought to add val_count benchmarks for ACT.

So I'll keep this PR open for the test and the yet-to-be-added benchmarks

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.

2 participants