Open and answer this issue on GitHub.
blocked, solver · opened 2026-11-22 · updated 2026-11-22 · 1 comment
Part of #2474 Found while #2652 After #2711
Within one pass of the bounds walk, a walk past a loop whose complete entry state equals that of an earlier walk in the same pass is not walked again: its outcome and its side effects are replayed. The walk proves exactly what it proves today (owner rule).
bounding_past_loop in crates/nikaia-std/src/compiler/bounds_walk.nika (ADR-361 D10) walks the rest of the body twice past each loop (leaves and again, the second from the invariant facts bounding_loop_invariant found) and keeps again only where it stands. The state saved and restored around the walks is BoundsMark (bounding_mark / bounding_back, same file).BoundsWalk outside BoundsMark that a walk changes: flagged, leaving, settled_loops, turn_rows, assumed_read, self_read, found_read. Fresh names come from the counters entries and codes. Terms live in a logic::TermArena that is not hash-consed, so a term id says nothing of the term’s structure.bounding_past_loop logging a hash kst of the facts, alpha-renamed, plus every BoundsMark field and the written, poisoned and missed-goal sets, and ko of the outcome)Memo key and scope, packages/logic/src/sv_strategy.nika |
Duplicate calls | Calls skipped | Inconsistent outcomes |
|---|---|---|---|
kst, within a pass |
1760 of 7989 | 2537 (32 %) | 0 |
kst, across passes |
6184 | 7117 | 390 |
| facts only, across passes | 3033 | ||
| facts only, within a pass | 25 |
In loopsN (below, N loops) the 2^N − 1 entry states within a pass are all distinct (each again starts from new invariant facts): 0 saved there. In sv 99.2 % of the walks lie at nesting ≥ 3. The invariant searches with the full key (entry facts plus walk state) repeat 1604 of 2106 times in sv (82 % of the proofs asked in searches), nearly all across passes, which the kept-proof issue (#2711) removes in part (measure again after it); within a pass this memo covers them.
fn loops(a: ref Vec[i64], lo: i64, hi: i64) -> Vec[i64] {
assert(0 <= lo)
assert(lo <= hi)
assert(hi <= a.len())
let mut out: Vec[i64] = []
let mut i1 = lo
for j in lo..<hi { if a[j] < 1 { i1 = i1 + 1 } }
out.push(a[i1])
let mut i2 = lo
for j in lo..<hi { if a[j] < 2 { i2 = i2 + 1 } }
out.push(a[i2])
let mut i3 = lo
for j in lo..<hi { if a[j] < 3 { i3 = i3 + 1 } }
out.push(a[i3])
return out
}
fn main() {}
nikaia check --bounds loops3.nika (target/fast, built 2026-11-22, shared checkout; checked with scripts/probe.nika --check --file, exit 0): 6 indexes, 3 proved; 3 operations, 3 proved; the three a[iK] stay checked: a counter the loop on line 7 changes, with no bound tied to its turns or to another counter (ADR-361 D13, #1634), 1.2 s. loopsN below is this program with N loops.
The walk is deterministic: a walk with equal complete input gives equal output. Complete input needs all four: (1) the state outside BoundsMark listed above in the key, or replayed from the entry; (2) the key alpha-renamed over the entries / codes names and the stored outcome renamed back to the current counters; (3) a structural key of the terms, not their ids; (4) the round inputs (context.returns, the summaries of other functions, assumed, assumed_ends, collecting), which the memo held only within one pass keeps fixed. Without (4) the across-pass figure shows 390 inconsistent outcomes; without the walk state, 25 within a pass.
traced for the cost (the calls counted above; 81-84 % of the Ir is the invariant search inside these walks, callgrind on chained and loops6). Which repeat inside a pass gives the 1760 duplicates (the same loop reached by the leaves and again walks of an outer loop with equal state) is suspected; item 1 shows it.
BoundsMark, the outside fields above, the position), behind NIKAIA_BOUNDS_MEMO=count: a stderr line per pass with the duplicates it would skip. Test: tests/compiler/tests/the_walk_memo_counts_repeated_walks.nika with .stdout, .stderr and .bounds (a body of two nested loops each followed by a third loop, so an inner state repeats; the builder writes it and checks with scripts/probe.nika --check). If no repeat inside a pass shows on it or on sv after the kept-proof issue (#2711) landed, stop: Result: blocked, Found: the counts..bounds rows as without the memo on the test of item 1, on loops3 above, and every *.bounds test unchanged.nikaia check --bounds and lower-std --bounds give byte-identical reports before and after, bytes::the_corpus_needs_no_tether passes, and the calls of bounding_past_loop within a pass on sv_strategy.nika fall by the share item 1 measured (32 % at 15c267871); the commit of item 2 carries Fixes #N. The report gives a Found: line per finding.
crates/nikaia-std/src/compiler/bounds_walk.nika and its lowered bounds_walk.rs (output). No new Rust.--bounds row, proofs_answers.nika (the query-key issue’s file, #2696).most_facts() 48 and 256 held facts: the walk is not monotone, so only an exact state repeat may be replayed. The memo is per pass and per body; its size is bounded by the walks of that pass (2^n − 1 entries at most). Time before: check --bounds loops6 27.5 s, sv_strategy.nika 47.7 s (target/fast at 15c267871, wall).Facts: Ledger and bounds proofs, Prover, Measuring
again or cutting the rest of the walk to the loop’s cone: can lose a proof (NOT EXACT); the cone-factorised decision issue covers the exact form.Generated by Claude Code
Driver: not queued, this issue waits for #2695, which is still open (#1819). Set ready again when it is closed.
Generated by Claude Code