Issue #2783: bounds walk: a result that is -1 or a position in a list proves the read after a >= 0 test (sv_simplex fractional)

Open and answer this issue on GitHub.

wip, solver · opened 2026-11-23 · updated 2026-11-23 · 3 comments

Split out of “bounds walk: a method’s found facts through self” (#1667) when its third run was accepted (2026-11-23).

Found

Some functions return either -1 or an index into a list. Examples are sv_simplex’s fractional-style searches (site 884 before sv_simplex moved to packages/logic) and the place lookups. The caller tests r >= 0 and then reads xs[r]. The bounds walk keeps that read checked, because the result fact it can state is one linear range, and “-1 or in 0..<xs.len()” is a disjunction.

To build

  1. A result fact of the form result == -1 || (result >= 0 && result < E.len()), derived where every return is either the literal -1 or an index proved in range. After a test r >= 0 (or r != -1) in the caller it narrows to the in-range half. Find the place in ADR-306’s result facts. If a disjunctive fact needs a rule not yet written there, stop and report it (Needs: supervisor decision).
  2. A probe test in tests/compiler/tests/: fn find(xs: Vec[i64], v: i64) -> i64 returning -1 or a loop index, and a caller let r = find(xs, 3); if r >= 0 { xs[r] } is proved.
  3. Map the sv_simplex site(s) of this shape on today’s lines.

Done when

The probe passes under both settings, and the mapped sv_simplex sites print proved, or the report names each site that still does not and why.

Comments

keywan-ghadami, 2026-11-23

Brief queued: issue-2783


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #2783

Your work order is issue #2783, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/2783/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/solver/issue-2783.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-23

Run: issue-2783, Result: done

Tokens: input 210, cache read 8044291, cache write 132514, output 37830 Cost: 3.63 USD, time 11 min 50 s, turns 105

Report

Result: done Files: crates/nikaia-std/src/compiler/bounds_walk.nika crates/nikaia-std/src/compiler/emit_core_calls.nika (+ lowered, tests/compiler/tests/a_minus_one_or_a_position_proves_the_read_after_a_test., a_ref_argument_then_one_that_changes_its_root., prove_call_keeps_untouched_fields.) Commit: b77fdfa3 bounds: a call that only grows a list keeps what held below its length (ADR-391 D2); 552009c9 emit: an argument lent to a ref parameter is bound after a later one that changes its root Body: 552009c9 fixes an emitter defect the bounds change hit (rustc E0502 on f(&w, w.a.bump()), NK1343 on the old binary), test a_ref_argument_then_one_that_changes_its_root; b77fdfa3: at a call, a length the frame lists in lengths but not in falls is snapshotted and len_after >= len_before is pushed, so facts below it survive; newly proved: sv_simplex self.var_col[v] (split), logic_lia lg_indexed at += 1, sharing Slots::join self.parent[one] = other Fixes: #2783 Pushed: local b77fdfa3 Tests: new a_minus_one_or_a_position_proves_the_read_after_a_test passes –both-settings and fails on $NIKAIA_OLD (lines 43, 80 checked there); a_ref_argument_then_one_that_changes_its_root passes, NK1343 on old; prove_call_keeps_untouched_fields re-recorded (row read now proved); all 195 tests/.bounds compared against check –bounds, only that one changed; clippy, fmt, pre-push green Gate: green Deviation: no new result fact was needed: the -1-or-position result is already bounded by the D23 found bound result < len (-1 < len), so no disjunctive rule was built Found: none Needs: none Changelog: Bounds: a value below a list’s length stays below it past a call whose frame only grows that list, so a -1-or-position search’s result proves the read after r >= 0 across such a call; emit: a ref argument followed by one that changes its root no longer draws E0502 Issue: wrong I7: the probe shape already proved on HEAD through D23’s result < len; sv_simplex’s split read was lost at a mut self call that only grows var_col (frame forgot the length), not for lack of a disjunction Comment: #2783 sv_simplex mapping: split self.var_col[v] now proved; x.ks[at] (511) and self.big_rows[r].ks[at] (1771) stay checked: at is a position found in cols and read on ks, which needs a cols/ks equal-length invariant, not this result fact; sv_sat propagate/add_lemma results are passed to calls, never indexed Friction: none Disk freed: none needed; target/nikaia-project-tests 1.8G, / 9.7G free (75%), no new cache entry over 100 MB Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. What cost the most turns: the bootstrap detour. The bounds change produced lowered Rust that rustc refused with E0502 (bounding_push(&walk, …, walk.arena.ge(…))). Fixing that meant reverting my bounds diff, fixing the emitter, running a full cycle, committing, reapplying the diff and running the cycle again. Second was disproving the issue’s disjunction hypothesis: the probe already proved on HEAD, so I had to find the real cause, the frame forgetting a grown length.
  2. What I had to look up:
    • ADR-306 D23, the found bound result < len.
    • ADR-391 D2: the sets in BoundsChanged and what falls means.
    • bounding_entry_value in bounds_walk.nika.
    • emit_call_hoisted and the check-fact sets in emit_core_calls.nika.
    • That --bless does not create a .bounds file.
  3. Checks run: the probe matrix on $NIKAIA_OLD, two lower-std/build cycles, test --both-settings on the three tests, bdiff.sh (all 195 .bounds files, about 2 min), fmt, clippy and pre-push. The first cycle, run before the emitter fix, was wasted.
  4. One change to builder.md: “after a bounds_walk change, diff every tests/*.bounds against check --bounds with one script, and expect lowered std files to flip to proven::*: check that each flip is sound.” That would have saved writing bdiff.sh and the reasoning about it.
  5. What the issue lacked:
    • wrong I7: it assumed a disjunctive rule was missing. D23 already covers -1, and the sv_simplex site was lost at a call that only grows var_col.
    • broke I5: no probe run on HEAD, which would have shown the plain shape already proves.
    • knowledge: Lowering | a call whose first argument is a shared borrow and whose later argument changes the same root drew E0502 until 552009c9.
  6. Traps for the next builder:
    • Fact: Ledger and bounds proofs | nikaia test --bless does not create a missing .bounds file; make it with check --bounds tests/NAME.nika in tests/compiler and cut the " - written without..." tail of the first line.
    • Fact: Lowering | a change to the lowering that std's own lowering needs is built and committed before the code using it is lowered (bootstrap order); revert the user, fix, cycle, reapply.
  7. For the next builder in Ledger and bounds proofs:
    • Fact: Ledger and bounds proofs | the call frame lives in bounding_by_frame in bounds_walk.nika; since b77fdfa3 (2026-11-23) a length in changed.lengths but not in falls keeps len_after >= len_before.
    • Fact: Ledger and bounds proofs | sv_simplex 511 x.ks[at] and 1771 big_rows[r].ks[at] stay checked (b77fdfa3, 2026-11-23): they need a cols/ks equal-length invariant.
    • Fact: Ledger and bounds proofs | the new test a_minus_one_or_a_position_proves_the_read_after_a_test.bounds reads 6 indexes, 5 proved; 5 operations, 3 proved (b77fdfa3, 2026-11-23).

Generated by Claude Code

keywan-ghadami, 2026-11-23

From the report of the run of issue-2783 (#2783):

sv_simplex mapping: split self.var_col[v] now proved; x.ks[at] (511) and self.big_rows[r].ks[at] (1771) stay checked: at is a position found in cols and read on ks, which needs a cols/ks equal-length invariant, not this result fact; sv_sat propagate/add_lemma results are passed to calls, never indexed


Generated by Claude Code

Back to Open Issues