Normalise before returning at the root in ascend_until and ascend_until_branch - #73
Open
imlvts wants to merge 1 commit into
Open
Normalise before returning at the root in ascend_until and ascend_until_branch#73imlvts wants to merge 1 commit into
imlvts wants to merge 1 commit into
Conversation
…il_branch
Both methods checked `at_root()` and returned *before* the step that
closes out a spent node key:
ascended += self.ascend_within_node();
if self.at_root() { return ascended; } // <- returned here
if self.key.node_key().len() == 0 { self.ascend_across_nodes(); }
`ascend` right above them does it the other way round, normalise first
and then decide whether it is done, and does not have the bug. So the
zipper could come back at its root still holding a node key it had
already ascended past. At the root `val()` and `set_val` read
`root_val` rather than the focus node, so the zipper denied its own root
value and `set_val` unwrapped a `None`:
map.insert(&[2, 2, 0, 2], 52);
let mut wz = map.write_zipper_at_path(&[2, 1]);
wz.get_val_or_set_mut_with(|| 198);
wz.move_to_path(&[2, 2, 1, 1]);
wz.create_path();
wz.ascend_until();
// wz.val() was None; map.get_val_at(&[2,1]) is Some(198)
Swapping the two, so both match `ascend`, fixes it. On the bugfixes
branch this also removed the `root_val` unwrap panics at the two
`set_val`/`remove_val` sites entirely, which were downstream of it: the
same field, unusable for the same reason.
Regression test: `write_zipper_ascend_until_normalises_at_the_root`, for
both methods, reading and then writing at the root afterwards. Fails
before this change.
lean/FINDINGS.md finding 9 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
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.
Both methods checked
at_root()and returned before the step that closes out a spent node key:ascendright above them does it the other way round, normalise first and then decide whether it is done, and does not have the bug. So the zipper could come back at its root still holding a node key it had already ascended past. At the rootval()andset_valreadroot_valrather than the focus node, so the zipper denied its own root value andset_valunwrapped aNone:Swapping the two, so both match
ascend, fixes it. On the bugfixes branch this also removed theroot_valunwrap panics at the twoset_val/remove_valsites entirely, which were downstream of it: the same field, unusable for the same reason.Regression test:
write_zipper_ascend_until_normalises_at_the_root, for both methods, reading and then writing at the root afterwards. Fails before this change.lean/FINDINGS.md finding 9 on the lean-fuzzer-restage branch.