Skip to content

Make ProductZipper::val_at follow the path like descend_to - #204

Open
imlvts wants to merge 3 commits into
Adam-Vandervorst:masterfrom
imlvts:fix/product-zipper-val-at-panic
Open

imlvts wants to merge 3 commits into
Adam-Vandervorst:masterfrom
imlvts:fix/product-zipper-val-at-panic

Conversation

@imlvts

@imlvts imlvts commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

This also refactors and speeds up a bunch of things (walk_node_val_at).
Perhaps it belongs as a method on the node?

val_at went through ReadZipperCore::get_val_at, which reaches the focus via the node below it on the stack. A secondary factor's root is pushed onto the stack without being that node's child, so with the focus on a joint or in the first node of a secondary factor it panicked (focus_parent unwrap) or looked in an unrelated node, and a path that crossed a joint was never followed into the next factor.

Walk the trie nodes from the focus instead, without moving or copying the core. Where the walk stops at a leaf it reached by at least one step, it enters the next factor's root, as descend_to_existing does, so val_at(p) is descend_to(p) then val(). A value found inside the focus's factor returns straight away.

val_at went through ReadZipperCore::get_val_at, which reaches the focus via the
node below it on the stack. A secondary factor's root is pushed onto the stack
without being that node's child, so with the focus on a joint or in the first
node of a secondary factor it panicked (focus_parent unwrap) or looked in an
unrelated node, and a path that crossed a joint was never followed into the
next factor.

Walk the trie nodes from the focus instead, without moving or copying the
core. Where the walk stops at a leaf it reached by at least one step, it
enters the next factor's root, as descend_to_existing does, so val_at(p) is
descend_to(p) then val(). A value found inside the focus's factor returns
straight away.
Extract walk_node_val_at / node_val_at in src/trie_node.rs to walk a
non-empty path directly from (TaggedNodeRef, node_key) without going
through focus_parent(), throwaway TrieRefBorrowed construction, or
lifetime transmutes.

- ReadZipperCore::get_val_at walks from *self.focus_node directly,
  fixing the root cause of the focus_parent() panic and removing the
  transmute and allocator clone.
- ProductZipper::val_at loops over factors via walk_node_val_at::<true>,
  replacing its inline node-walking loop.
- WriteZipperCore::val_at, TrieRefBorrowed::get_val_at,
  TrieRefOwned::val_at, and PathMap::val_at all share node_val_at.
@imlvts
imlvts marked this pull request as ready for review November 30, 2026 08:20
…h across joints

Both asked only the zipper of the factor whose value the focus shows.  So
val_at / get_val_at answered None for any path that crosses a factor joint.
At a joint itself they asked the earlier factor's leaf, not the factor entered
there.

Both now replay their own descend_to on read zippers forked from the factors,
entering the next factor wherever the walk stands on a leaf.  That includes
the last step of descend_to, which enters at most one more factor and takes
the rest of the path there.  A value inside the focus's factor returns
straight away, so lookups that stay inside it cost the same as before.

ProductZipperG reads the value from its own factor zipper.  Its val_at and
get_val_at now require ZipperForking of the factors.

DependentProductZipperG has its later factors made by the enroll function,
so the walk calls it on a copy of the payload, which requires C: Clone.  Such
a factor zipper is dropped after the walk, so val_at needs factors whose
values outlive them: val_at now has get_val_at's bounds
(ZipperReadOnlyValues<'trie>, plus ZipperForking and C: Clone).  A
DependentProductZipperG over owned factors, such as the ExprFactor test enum,
no longer has val_at.  ExprFactor's PolyZipperExplicit list drops
ZipperValuesAt, and its val_at test block goes.

Tests compare val_at and get_val_at with descend_to then val/get_val, at and
across joints, with long keys, with fixed factors, and with enroll functions
that depend on the path and the payload.
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