Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
d11f739
Removing the `graft_root_vals` feature, because the question about th…
luketpeterson Oct 9, 2026
15fa373
Updating join_into and join_into_take, to include focus values for ht…
luketpeterson Oct 9, 2026
5bfbdae
Updating WriteZipper::restrict to match PathMap::restrict
luketpeterson Oct 9, 2026
21b3f8f
Making drop_head aka join_k_path treat values the same way that meet_…
luketpeterson Oct 10, 2026
b507e16
Updating meet_2 to include focus values. https://github.com/Adam-Van…
luketpeterson Oct 10, 2026
99701fd
Fixing prune bug exposed by behavior changes to alg-ops
luketpeterson Oct 10, 2026
16a560f
Making insert_prefix shift the focus value down, and eliminating inco…
luketpeterson Oct 10, 2026
61ec008
Updating remove_prefix for consistent handling of focus value, roundi…
luketpeterson Oct 10, 2026
2393ae6
Adding exception to correctly classify meet + dangling issue, which i…
luketpeterson Oct 10, 2026
3672abd
Fixing meet_k_path_into edge cases, including replacing root value, p…
luketpeterson Oct 28, 2026
6fc39cd
Fix merkleize with several dangling paths
imlvts Sep 17, 2026
9e6a268
Fix ACTZipper::val_count and ProductZipper::val_count counting from t…
imlvts Oct 29, 2026
c3753d2
Make meet and join value bias independent of node layout
imlvts Sep 15, 2026
00faf42
Drop an emptied child beside a value in a list-node meet
imlvts Oct 27, 2026
9e957e2
Fix a join reporting an empty result for a non-empty byte node
imlvts Oct 27, 2026
f29eef7
Fix graft_child_maps and graft_masked_branches grafting nothing
imlvts Oct 29, 2026
2b34dc4
Make join_map_into, take_map and restricting ignore empty materialise…
imlvts Oct 29, 2026
8fa13d4
Return Identity from integer psubtract of unequal values
imlvts Oct 29, 2026
fd746a1
Fix graft_masked_branches merging into a node above the focus
imlvts Oct 29, 2026
7170151
Meet: prune leaves no dangling path below the focus; status follows v…
imlvts Oct 30, 2026
c81c1e3
Bring the PathMapModel and harness up to the fvc meet rule
imlvts Nov 9, 2026
83ab2bd
Differential harness: pluggable read sources and write targets
imlvts Nov 9, 2026
cc8a1e3
Map-level differential fuzzer skeleton (--source map)
imlvts Nov 9, 2026
ab1551d
Read sources may lack val_count: fingerprint prints n? (Caps.valCount)
imlvts Nov 9, 2026
a5bab44
Map fuzzer: PathMap surface (ops 0-19) and whole-map lattice ops (20-28)
imlvts Nov 9, 2026
f615bad
Overlay and DiffZipper read sources with Lean models
imlvts Nov 9, 2026
675766c
differential.py: tag which zipper a divergence is on; key ascend_unti…
imlvts Nov 9, 2026
83828af
DependentProductZipperG read source with a Lean model
imlvts Nov 9, 2026
f02ce7a
dependent-lazy: one KNOWN entry for the D1/D2 replays
imlvts Nov 9, 2026
dddcdab
differential.py: a ret-only divergence is tagged neither READ-SIDE no…
imlvts Nov 9, 2026
8175f38
Map fuzzer: serialization round trips (ops 30-33) and ArenaCompactTre…
imlvts Nov 9, 2026
02b4055
Findings for the map-serial workstream
imlvts Nov 9, 2026
bbe66f5
Op 75 trie_ref_probe; head and owned sources with Lean models
imlvts Nov 26, 2026
b5951d8
head-owned findings: TrieRefOwned empty node, owned clone focus; stal…
imlvts Nov 9, 2026
3e5bf56
findings: map-core (PathMap surface, whole-map lattice ops)
imlvts Nov 9, 2026
d148524
shrink.py: one scratch file per process, so shrinks can run in parallel
imlvts Nov 9, 2026
9007656
Read source: EmptyZipper (--source empty)
imlvts Nov 9, 2026
5a9c6bf
Read source: PrefixZipper (--source prefix)
imlvts Nov 9, 2026
60d81d4
PrefixZipper: corpus inputs for the bugs found; tighter join_map_into…
imlvts Nov 9, 2026
8b605a0
Findings for the prefix workstream (PrefixZipper, EmptyZipper)
imlvts Nov 9, 2026
0cdcd74
ProductZipper and ProductZipperG read sources with a Lean model
imlvts Nov 9, 2026
d8505c0
Product sources: findings, standalone reproducers, skip guards
imlvts Nov 9, 2026
d2f4f66
product findings: framework hooks
imlvts Nov 9, 2026
fbe86e7
product: KNOWN entries first; campaign results
imlvts Nov 9, 2026
2d7f3ad
Map fuzzer ops 50-56: catamorphisms and anamorphisms against a Lean m…
imlvts Nov 9, 2026
43afbfd
Map fuzzer op 60: ZipperHead sessions against a Lean model (WIP)
imlvts Nov 9, 2026
f857250
Head sessions: skips for three crate bugs, rebuild after a session, l…
imlvts Nov 9, 2026
a29ce33
Morph/Head: #guard fixtures and findings (five ZipperHead bugs)
imlvts Nov 9, 2026
3bcc7a5
Head: skip pruning removes at an absent writer focus (stump bug H4 in…
imlvts Nov 9, 2026
f608241
Findings index for the coverage-models fuzzers; README section on rea…
imlvts Nov 9, 2026
0490907
Fingerprint: compare is_val, child_mask and depth on every step
imlvts Nov 9, 2026
b53cc67
Constructor variants: PathTracker::new, EmptyZipper::new (empty-new),…
imlvts Nov 9, 2026
7448f3d
README and findings index: tracker new, empty-new, diff-product, ctor…
imlvts Nov 9, 2026
ce57a6f
Map op 1: long tail of 48 bytes (KEY_BYTES_CNT is 42 with slim_ptrs),…
imlvts Nov 9, 2026
813b8be
findings/ctors.md: decisions, campaigns, the round-2 function list
imlvts Nov 9, 2026
1bd623d
Prefix trees: map ops 57/58 serialize a view with each catamorphism f…
imlvts Nov 9, 2026
c5b3cdd
PrefixTree: prove flatten (toBytes T) = T and flatten (toLines T) = T…
imlvts Nov 9, 2026
646b2e2
PrefixTree: prove toBytes (flatten P) = P and toLines (flatten P) = P…
imlvts Nov 9, 2026
3f742af
PrefixTree: side-effecting folds return the cached folds' result; ana…
imlvts Nov 9, 2026
e7e259d
PrefixTree: with no dangling leaf, ana of an unfolded canonical tree …
imlvts Nov 9, 2026
ab74bba
Map op 59: SplitCata builds the byte tree, SplitCataJumping counts an…
imlvts Nov 9, 2026
071ed72
Zipper ops 76-81: drop_head, join_into_take, get_focus_at/try_borrow_…
imlvts Nov 26, 2026
63dfd4b
ops: findings (O1 write-zipper try_borrow_focus, O2 PrefixZipper focu…
imlvts Nov 9, 2026
91f43cd
ops: focus_probe tags its side; O3 finding and corpus; campaign results
imlvts Nov 9, 2026
0eedf4d
findings/ptree.md: prefix-tree round trips, PT1 graft_at_byte on a le…
imlvts Nov 9, 2026
56a300f
findings/ptree.md: campaign results
imlvts Nov 9, 2026
f1a25dd
findings/BUGS.md: every crate bug found, deduplicated and grouped
imlvts Nov 9, 2026
81c8398
Value-level fuzzer skeleton (--source util)
imlvts Nov 9, 2026
f921380
Util ops 0-28: ByteMask and BitMask as a set of bytes, checked agains…
imlvts Nov 9, 2026
7e0ed90
Util ops 30-59: ring.rs lattice impls, AlgebraicResult/Status, SetLat…
imlvts Nov 9, 2026
9b5c29f
findings/u-lattice.md: ring.rs model, campaigns, L1 SetLattice meet s…
imlvts Nov 9, 2026
a93a9ed
Util fuzzer: utils/ints.rs (ops 60-79): bob/weave encodings and gen_i…
imlvts Nov 9, 2026
5f1ce54
Util fuzzer: sort_paths and sort_paths_par (ops 80-84) against the so…
imlvts Nov 9, 2026
20a1b24
Util fuzzer: viz_maps (ops 85-87); enable the viz, random and counter…
imlvts Nov 9, 2026
deb448c
Util fuzzer: random (ops 88-92) and counters (ops 93-94) modules
imlvts Nov 9, 2026
1ea8820
findings/u-ints.md: ints, sorters, viz, random, counters; DrawConfig:…
imlvts Nov 9, 2026
64bd762
differential.py: source-keyed KNOWN filter matches keys with or witho…
imlvts Nov 9, 2026
21e6c76
Product: the stated graft spec, map(PZ(x, y)) = values(x).map(wz.desc…
imlvts Nov 10, 2026
8373f3e
Map op 41: open_mmap rejects a file shorter than the ACT header
imlvts Nov 26, 2026
afa2772
PrefixTree: keep the word sorry out of the header, CI greps for it
imlvts Nov 26, 2026
190c9eb
Prune by whether the focus exists, not by whether its node is empty
imlvts Nov 30, 2026
d5b6d32
Answer None from try_borrow_focus below a dangling path held as an em…
imlvts Nov 30, 2026
9c9a584
Keep a TrieRefOwned valid at a location with nothing below it
imlvts Nov 30, 2026
57baa4e
Map fuzzer: drop the ZipperHead workarounds for H4 and H5
imlvts Nov 30, 2026
e692913
Make OverlayZipper's ascend_until and descend_until stop where the ov…
imlvts Nov 30, 2026
6f6d8ca
Rewind EmptyZipper::to_next_val to the root
imlvts Nov 30, 2026
9a4ca2a
Fuzzers: drop the KNOWN entries for the overlay until-moves and Empty…
imlvts Nov 30, 2026
5503788
PrefixZipper: subtries on and off the prefix
imlvts Nov 30, 2026
412a34a
PrefixZipper: moves at the seam and one byte off the prefix
imlvts Nov 30, 2026
9e39d04
Fuzzers: drop the PrefixZipper KNOWN entries and the merge-from-the-p…
imlvts Nov 30, 2026
8e369cd
Merge branch 'spec/map-head-no-rebuild' into spec/coverage-models
imlvts Nov 30, 2026
c0776d5
Merge branch 'spec/overlay-empty-no-known' into spec/coverage-models
imlvts Nov 30, 2026
167b537
Merge branch 'spec/prefix-no-known' into spec/coverage-models
imlvts Nov 30, 2026
0d00dc5
ByteMask: inclusive bit-range edits change nothing for an empty range
imlvts Nov 30, 2026
0a146bd
Util fuzzer: drop the KNOWN entry for the exhausted-range ByteMask edits
imlvts Nov 30, 2026
e17493a
ByteMask inclusive bit-range edits: keep them const; fuzz only ranges…
imlvts Nov 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fast-slice-utils = { version = "0.1.2", features=[] }
distr-combinators = { version = "0.1.0", optional = true }

[features]
default = ["graft_root_vals", "slim_ptrs", "serialization"]
default = ["slim_ptrs", "serialization"]
heavy_tests = [] # Run with `cargo test` Enables slow thorough tests that are tedious for quick test runs
nightly = ["fast-slice-utils/nightly"] # Uses features in the nightly tool chain for better performance, and the allocator and coroutine APIs
jemalloc = ["dep:tikv-jemallocator"] # Enables [jemalloc](https://jemalloc.net/) as the default allocator. This dramatically improves scaling for write-heavy workloads and is generally recommended. The only reason it is not the default is to avoid interference with the host application allocator.
Expand All @@ -49,7 +49,6 @@ bridge_nodes = [] # Enable the experimental BridgeNode type. Incompatible with
old_cursor = [] # Enables an old deprecated traversal object that predates the zippers, WILL BE REMOVED EVENTUALLY
random = ["dep:rand", "dep:rand_distr", "dep:distr-combinators"] # Used for creating random paths, tries, and zipper movements
counters = [] # Enable features to inspect performance properties of tries. Mainly useful when tuning performance of the PathMap internals.
graft_root_vals = [] # Enables an experimental change in behavior that causes `graft`, `graft_map`, `make_map`, `take_map`, and `join_map` to treat the value at the focus as part of the operation
slim_ptrs = [] # Enables use of a 64-bit inter-node pointer type (TrieNodeODRc)
slim_dispatch = [] # Experiment. Enables the 64-bit pointers to back the TaggedNodeRef and TaggedNodeRefMut types, WILL BE REMOVED EVENTUALLY
act_counters = ["arena_compact"] # LP: Question: Why isn't this code enabled by just counters + arena_compact???
Expand Down
5 changes: 4 additions & 1 deletion differential/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ publish = false
description = "The Rust side of the differential fuzzing harness for pathmap's zipper API; the Lean model in ../lean is the oracle"

[dependencies]
pathmap = { path = "..", features = ["arena_compact", "zipper_alg"] }
pathmap = { path = "..", features = ["arena_compact", "zipper_alg", "viz", "random", "counters"] }
# Seeded RNGs for the `random` module ops (util fuzzer, ops 88-92); the same
# rand 0.9 that pathmap uses.
rand = "0.9"
12 changes: 7 additions & 5 deletions differential/src/act.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use pathmap::zipper::*;
use crate::harness::*;

impl<'t, S: AsRef<[u8]>> ReadSource for ACTZipper<'t, S, u64> {
fn dump_fork(&self) -> String {
dump_fork(self)
const SKIP: &'static str = SKIP_ACT;
fn dump_fork(&self) -> Option<String> {
Some(dump_fork(self))
}
/// ACT implements `ZipperSubtries` only for `Value = ()`, and
/// `ZipperInfallibleSubtries` not at all, so a subtrie cannot be
Expand All @@ -20,10 +21,10 @@ impl<'t, S: AsRef<[u8]>> ReadSource for ACTZipper<'t, S, u64> {
None
}
/// ACT does implement `ZipperReadOnlyValues`, so this probe applies.
fn get_val_probe(&self, path: &[u8]) -> (Option<u64>, Option<u64>, bool) {
fn get_val_probe(&self, path: &[u8]) -> Option<(Option<u64>, Option<u64>, bool)> {
let (g, ga) = (self.get_val().copied(), self.get_val_at(path).copied());
let agree = g == self.val().copied() && ga == self.val_at(path).copied();
(g, ga, agree)
Some((g, ga, agree))
}
/// ACT does *not* implement `ZipperReadOnlyIteration`, so this one is
/// unavailable and the harness emits `skip`.
Expand All @@ -46,7 +47,8 @@ pub fn run_act(bytes: &[u8], check: bool) -> String {
let mut out = String::new();
{
let mut rz = act.read_zipper_at_path_u64(&root1);
run_ops(&mut d, &mut out, &mut map0, &root0, &mut rz, &root1, check);
let mut wz = map0.write_zipper_at_path(&root0);
run_ops(&mut d, &mut out, &mut wz, &root0, &mut rz, &root1, check);
}
let _ = writeln!(out, "MAP0 {}", dump(&mut map0.read_zipper()));
// Dumped from the ACT, not from map1, so `from_zipper` is under test too.
Expand Down
87 changes: 87 additions & 0 deletions differential/src/bin/dependent_repros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//! Standalone reproducers for the `DependentProductZipperG` findings in
//! `lean/findings/dependent.md`. Each prints what it observes and what would
//! hold if the zipper presented a fixed trie.
//!
//! `cargo run --release -p differential --bin dependent_repros`

use pathmap::zipper::*;
use pathmap::PathMap;

fn d1_root_joint() {
// A primary rooted at a leaf (here: an empty map), and a closure that
// returns a factor there.
let primary = PathMap::<u64>::new();
let mut factor = PathMap::<u64>::new();
factor.set_val_at([1u8], 7);
let enroll = |_: (), _p: &[u8], n: usize| ((), if n == 0 { Some(factor.read_zipper()) } else { None });
let mut z = DependentProductZipperG::new_enroll(primary.read_zipper(), (), enroll);
let fresh = (z.child_count(), z.clone().to_next_val());
z.descend_to(&[] as &[u8]);
let after_empty_descend = (z.child_count(), z.clone().to_next_val());
z.reset();
let after_reset = z.child_count();
println!("D1 root joint: (child_count, to_next_val) fresh {fresh:?}, after descend_to([]) \
{after_empty_descend:?}, child_count after reset {after_reset}");
println!(" expected: the same at all three (the root has not moved)");
}

fn d2_empty_factor() {
// At the joint [0] the closure returns an empty factor, then (asked again,
// since the joint is still a leaf) one holding [2].
let mut a = PathMap::<u64>::new();
a.set_val_at([0u8], 1);
let empty = PathMap::<u64>::new();
let mut b = PathMap::<u64>::new();
b.set_val_at([2u8], 2);
let enroll = |_: (), _p: &[u8], n: usize| {
((), match n { 0 => Some(empty.read_zipper()), 1 => Some(b.read_zipper()), _ => None })
};
let mut z = DependentProductZipperG::new_enroll(a.read_zipper(), (), enroll);
z.descend_to_byte(0);
let before = z.child_count();
z.descend_to(&[] as &[u8]);
let after = z.child_count();
let mut z = DependentProductZipperG::new_enroll(a.read_zipper(), (), enroll);
let mut vals = vec![];
while z.to_next_val() {
vals.push((z.path().to_vec(), z.val().copied()));
}
println!("D2 empty factor: child_count at [0] {before}, after descend_to([]) {after}; \
to_next_val walk {vals:?}");
println!(" expected: child_count 1 both times; walk [([0], Some(1)), ([0, 2], Some(2))]");
}

fn d3_val_at() {
// Primary {[0]: 0}; at the joint [0] the factor is the primary again.
let mut a = PathMap::<u64>::new();
a.set_val_at([0u8], 0);
let enroll = |_: (), _p: &[u8], n: usize| ((), if n == 0 { Some(a.read_zipper()) } else { None });
let z = DependentProductZipperG::new_enroll(a.read_zipper(), (), enroll);
let at = z.val_at([0u8, 0]).copied();
let get_at = z.get_val_at([0u8, 0]).copied();
let mut moved = z.clone();
moved.descend_to([0u8, 0]);
let mut joint = z.clone();
joint.descend_to_byte(0);
println!("D3 val_at across a joint: val_at([0,0]) {at:?}, get_val_at([0,0]) {get_at:?}, \
descend_to([0,0]) then val() {:?}; from [0], val_at([0]) {:?}",
moved.val().copied(), joint.val_at([0u8]).copied());
println!(" expected: all four Some(0)");
}

fn d4_path_indices() {
let mut a = PathMap::<u64>::new();
a.set_val_at([0u8], 0);
let enroll = |_: (), _p: &[u8], n: usize| ((), if n == 0 { Some(a.read_zipper()) } else { None });
let mut z = DependentProductZipperG::new_enroll(a.read_zipper(), (), enroll);
z.descend_to_byte(0);
println!("D4 at the joint [0]: focus_factor {}, path_indices {:?}", z.focus_factor(), z.path_indices());
println!(" documented: path_indices().len() == focus_factor()");
}

fn main() {
d1_root_joint();
d2_empty_factor();
d3_val_at();
d4_path_indices();
}
19 changes: 17 additions & 2 deletions differential/src/bin/pathmap_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
let check = args.iter().any(|a| a == "--check");
// Resident mode: one process, many inputs over stdin. See `serve`.
// `--source NAME` picks the read source / write target (see `sources`).
let source = args
.iter()
.position(|a| a == "--source")
.and_then(|i| args.get(i + 1))
.cloned()
.unwrap_or_else(|| "native".to_string());
let runner = sources::runner(&source).unwrap_or_else(|| {
let names: Vec<&str> = sources::SOURCES.iter().map(|(n, _)| *n).collect();
eprintln!("unknown --source {source}; known: {}", names.join(" "));
std::process::exit(2)
});
if args.iter().any(|a| a == "--server") {
serve(check, run);
serve(check, runner);
return;
}
// `--repro [--upto N] FILE` prints a standalone Rust program for the input
Expand All @@ -28,6 +40,9 @@ fn main() {
.unwrap_or(MAX_STEPS);
let file = args
.iter()
.enumerate()
.filter(|(i, _)| *i == 0 || args[i - 1] != "--source")
.map(|(_, a)| a)
.filter(|a| !a.starts_with("--"))
.find(|a| a.parse::<usize>().is_err())
.cloned();
Expand All @@ -43,7 +58,7 @@ fn main() {
if repro {
print!("{}", emit_repro(&bytes, upto));
} else {
print!("{}", run(&bytes, check));
print!("{}", runner(&bytes, check));
}
}

137 changes: 137 additions & 0 deletions differential/src/bin/product_repros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//! Standalone reproducers for the `ProductZipper` / `ProductZipperG` findings
//! in `lean/findings/product.md`. Each prints what the crate does and what the
//! model (`lean/PathMapModel/Sources/Product.lean`) says it should do.
//!
//! `cargo run --release -p differential --bin product_repros`

use pathmap::zipper::*;
use pathmap::PathMap;

fn m(ps: &[&[u8]]) -> PathMap<u64> {
let mut m = PathMap::new();
for p in ps {
m.set_val_at(p, 1);
}
m
}

fn mask<Z: Zipper>(z: &Z) -> Vec<u8> {
z.child_mask().iter().collect()
}

fn report(name: &str, ok: bool, got: String, want: &str) {
println!("{} {name}\n crate: {got}\n model: {want}", if ok { "ok " } else { "BUG " });
}

fn main() {
let empty = PathMap::<u64>::new();
let x = m(&[b"x"]);
let a = m(&[b"a"]);
let c = m(&[b"c"]);
let bc = m(&[b"bc"]);

// P1: a childless primary root is a joint, but neither type enters the
// next factor on construction; ProductZipper enters it as a side effect of
// a failed descend_first_byte, and reset forgets it again.
{
let mut z = ProductZipper::new(empty.read_zipper(), [x.read_zipper()]);
let before = mask(&z);
let d = z.descend_first_byte();
let after = mask(&z);
z.reset();
let reset = mask(&z);
report("P1 ProductZipper: childless primary root",
before == [b'x'] && after == [b'x'] && reset == [b'x'],
format!("root mask {before:?}; descend_first_byte() = {d:?}, then mask {after:?}; after reset {reset:?}"),
"root mask [120] throughout; descend_first_byte() = Some(120)");
}
{
let mut z = ProductZipperG::new(empty.read_zipper(), [x.read_zipper()]);
let before = mask(&z);
z.descend_to(b"x");
let exists = z.path_exists();
report("P1 ProductZipperG: childless primary root",
before == [b'x'],
format!("root mask {before:?}, yet descend_to(x) gives path_exists = {exists}"),
"root mask [120]; descend_to(x) exists");
}

// P2: a factor with no children at its root is transparent in the model;
// ProductZipper never enters the factor after it, ProductZipperG only on a
// later call at the same place.
{
let mut z = ProductZipper::new(a.read_zipper(), [empty.read_zipper(), c.read_zipper()]);
z.descend_to(b"a");
let mk = mask(&z);
z.descend_to(b"c");
let e = z.path_exists();
report("P2 ProductZipper: empty middle factor", mk == [b'c'] && e,
format!("at a: mask {mk:?}; descend_to(c) exists = {e}"),
"at a: mask [99]; descend_to(c) exists");
}
{
let mut z = ProductZipperG::new(a.read_zipper(), [empty.read_zipper(), c.read_zipper()]);
z.descend_to(b"a");
let mk = mask(&z);
z.descend_to(b"c");
let e = z.path_exists();
report("P2 ProductZipperG: empty middle factor", mk == [b'c'],
format!("at a: mask {mk:?}, yet descend_to(c) exists = {e}"),
"at a: mask [99]; descend_to(c) exists");
}

// P3: val_at does not follow a path across a joint.
{
let mut z = ProductZipperG::new(a.read_zipper(), [bc.read_zipper()]);
let va = z.val_at(b"abc").copied();
z.descend_to(b"abc");
let v = z.val().copied();
report("P3 ProductZipperG: val_at across a joint", va == v,
format!("val_at(abc) = {va:?}, descend_to(abc); val() = {v:?}"), "both Some(1)");
let mut z = ProductZipper::new(a.read_zipper(), [bc.read_zipper()]);
let va = z.val_at(b"abc").copied();
z.descend_to(b"abc");
let v = z.val().copied();
report("P3 ProductZipper: val_at across a joint", va == v,
format!("val_at(abc) = {va:?}, descend_to(abc); val() = {v:?}"), "both Some(1)");
}

// P4: ProductZipper::val_at panics with the focus at a joint or inside the
// first node of a secondary factor.
{
let b2 = m(&[b"bcd", b"bce"]);
for path in [&b"a"[..], b"ab"] {
let mut z = ProductZipper::new(a.read_zipper(), [b2.read_zipper()]);
z.descend_to(path);
let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| z.val_at(b"").copied()));
let want = z.val().copied();
report(&format!("P4 ProductZipper: val_at([]) at {:?}", std::str::from_utf8(path).unwrap()),
matches!(r, Ok(v) if v == want),
match r { Ok(v) => format!("{v:?}"), Err(_) => "panic (focus_parent unwrap)".to_string() },
&format!("{want:?} (= val())"));
}
}

// P5: ProductZipper::descend_to_check(&[]) at a missing focus.
{
let mut z = ProductZipper::new(a.read_zipper(), [bc.read_zipper()]);
z.descend_to(b"q");
let r = z.descend_to_check(b"");
report("P5 ProductZipper: descend_to_check([]) at a missing focus", !r,
format!("{r} (path_exists = {})", z.path_exists()), "false, as the native read zipper");
}

// P6: path_indices() at a joint has one more entry than focus_factor().
{
let mut z = ProductZipper::new(a.read_zipper(), [bc.read_zipper()]);
z.descend_to(b"a");
let (ff, pi) = (z.focus_factor(), z.path_indices().to_vec());
report("P6 ProductZipper: path_indices at a joint", pi.len() == ff,
format!("focus_factor = {ff}, path_indices = {pi:?}"), "path_indices().len() == focus_factor() (trait doc)");
let mut z = ProductZipperG::new(a.read_zipper(), [bc.read_zipper()]);
z.descend_to(b"a");
let (ff, pi) = (z.focus_factor(), z.path_indices().to_vec());
report("P6 ProductZipperG: path_indices at a joint", pi.len() == ff,
format!("focus_factor = {ff}, path_indices = {pi:?}"), "path_indices().len() == focus_factor() (trait doc)");
}
}
Loading