Make ACTZipper::reset return to an off-trie root instead of a real ancestor - #72
Open
imlvts wants to merge 1 commit into
Open
Make ACTZipper::reset return to an off-trie root instead of a real ancestor#72imlvts wants to merge 1 commit into
imlvts wants to merge 1 commit into
Conversation
…cestor
A zipper can be *rooted* at a path that does not exist: `fork_read_zipper`
at an off-trie focus makes one, and so does `read_zipper_at_path` with
such a path. `reset` put the path back but then cleared `invalid`
unconditionally, so the zipper came back believing it was rooted on the
trie, at whatever real node the stack still pointed at, its deepest
existing ancestor. It then answered `val()` with that ancestor's value:
trie: root=38, [1,0,2]=22, [1,1]=72
fork at [1,1,3] (does not exist): val None -> after reset(): Some(72)
fork at [9] (does not exist): val None -> after reset(): Some(38)
The zipper knew where its root was (`origin_depth`, `origin_node_depth`)
but not how far off the trie it was, so `reset` had nothing to restore.
`origin_invalid` records that, `with_root_here` captures it when a fork
takes the focus as its root, and `reset` restores it.
Regression test: `act_zipper_reset_returns_to_an_off_trie_root`, forks at
three off-trie paths and a zipper created at one. Fails before this
change.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A zipper can be rooted at a path that does not exist:
fork_read_zipperat an off-trie focus makes one, and so doesread_zipper_at_pathwith such a path.resetput the path back but then clearedinvalidunconditionally, so the zipper came back believing it was rooted on the trie, at whatever real node the stack still pointed at, its deepest existing ancestor. It then answeredval()with that ancestor's value:The zipper knew where its root was (
origin_depth,origin_node_depth) but not how far off the trie it was, soresethad nothing to restore.origin_invalidrecords that,with_root_herecaptures it when a fork takes the focus as its root, andresetrestores it.Regression test:
act_zipper_reset_returns_to_an_off_trie_root, forks at three off-trie paths and a zipper created at one. Fails before this change.