Issue #2784: bounds walk: facts about a nullable result (-> i64?) hold for the value after the null test (sv_simplex form_var)

Open and answer this issue on GitHub.

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

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

Found

form_var -> i64? in sv_simplex (sites 973/987 before sv_simplex moved to packages/logic) returns null or an index that is in range at every return. In the caller, after the value is matched or tested non-null, the bounds walk does not carry the callee’s range fact to it, so the read through it stays checked.

To build

  1. A result fact derived for the non-null value of a T? result, the same way as for a plain i64 result (ADR-306). It holds on the bound value in the non-null arm of match, after ?? continue / ?? return, and after if x != null.
  2. A probe test in tests/compiler/tests/: fn at(xs: Vec[i64], v: i64) -> i64? returning null or a loop index, and a caller’s let i = at(xs, 3) ?? return; xs[i] is proved.
  3. Map the sv_simplex sites of this shape on today’s lines.

Done when

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

Comments

keywan-ghadami, 2026-11-23

Brief queued: issue-2784


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

Issue #2784

Your work order is issue #2784, 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/2784/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-2784.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-2784, Result: done

Tokens: input 46, cache read 855773, cache write 37363, output 10112 Cost: 0.71 USD, time 3 min 9 s, turns 23

Report

Result: done Files: tests/compiler/tests/a_methods_nullable_result_holds_its_found_facts_through_self.nika tests/compiler/tests/a_methods_nullable_result_holds_its_found_facts_through_self.stdout tests/compiler/tests/a_methods_nullable_result_holds_its_found_facts_through_self.bounds Commit: bounds: a method’s nullable result holds its found facts through self, pinned (ADR-306 D23, D34) Body: Items 1-2 were already built by “bounds: found facts through a nullable result, read through the unwrap (ADR-306 D23)” (#1758), whose test found_facts_through_a_nullable_result is the issue’s probe (free function; ?? return, match, != null, ?? 0 all proved). This commit pins the method form (self as an extra argument, D34 with D23): find/grow -> i64? through ?? return, match, != null, and handed on to a parameter, all proved. Item 3 mapped: form_var’s result reaches sv_simplex only at line 835 (passed to tighten at 843, 858) and 1598 (stored in SvLitView.var); tighten’s reads at 866-899 (self.upper/lower/touched/bound_at/row_of/big_values/values[v]) stay checked under ADR-391 D1, because form_var has no found fact to hand on: two of its returns are map values (known ?? 0 from self.col_var.get in column_var and from self.slack_of.get), of which the walk knows no fact (#797, #798), and tighten indexes lists other than var_col that new_var keeps as long as it by invariant only. The null test is not the cause. Fixes: #2784 Tests: new test passes under target/fast/nikaia test –both-settings –filter a_methods_nullable_result; it passes on the unfixed compiler too (it pins existing behaviour, no compiler change); pre-push green Gate: green Deviation: none Found: sv_simplex form_var (packages/logic/src/sv_simplex.nika:630) results stay unbounded: a method returning a map value that is always a position in a list field (let known: i64? = self.of.get(k); if known != null { return known ?? 0 } next to self.xs.push(k); let v = self.xs.len() - 1; self.of.insert(k, v); return v) leaves the caller’s let i = self.var(3) ?? return 0; self.xs[i] checked: “no fact bounds what it reads” (nikaia check –bounds, single file, HEAD build); a rule that a map’s values stay below a list field’s length (a type invariant over a map) is not specified, no decision yet; cause traced: bounds_walk knows no fact of a map element (#797, #798) Needs: none Changelog: none Issue: wrong I7: the issue says the walk does not carry a nullable result’s fact to the unwrapped value; that already works (#1758, found_facts_through_a_nullable_result) for free functions and methods; the sv_simplex sites stay checked because form_var returns map values, which have no fact Owner: none Comment: none Friction: none Disk freed: none Reviewed: a07cefa3dec10a2f3ca42d7e1d24ba491d6d21069002f32ebfd2083bafd8ad0e Pushed: local 1823bdbba1e25a637538baca7f2b3d811efacfb4 Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. Most turns: small things around the probes. My HashMap probe failed three times: use collections::HashMap drew NK1337, use collections in a single file drew NK1339, and a bare HashMap drew NK1135. It took one more try to see that the --bounds table prints anyway. A .bounds file is blessed only if it already exists, which cost another turn.
  2. Looked up: the existing test found_facts_through_a_nullable_result and its commit (#1758, ADR-306 D23), which had already built items 1–2. I also had to find how a .bounds expectation file gets created, and how to run --bounds on one package file (cd packages/logic && nikaia check --bounds src/F.nika; it prints every file of the package).
  3. Checks: the probes p1 (free function), p2 (method) and p3 (map value) on HEAD’s build, one --bounds run of sv_simplex, the new test under both settings, and pre-push. None was wasted, apart from the three failed HashMap probe tries.
  4. One change: the driver could run the issue’s probe on HEAD before starting a builder and put the result in the brief. A probe that already passes would mark the issue as a possible duplicate in turn one.
  5. What the issue lacked:
    • wrong I7: it puts the cause in carrying a fact across the null test. Facts already carry across it; the real cause is form_var returning map values.
    • broke I5: its sites are line numbers from before sv_simplex moved, given without a probe of the real shape.
    • rules-gap: no rule asks the filer to search tests/compiler/tests for an existing test of the shape before filing a split-out issue.
  6. Fact lines:
    • Fact: Probes | A test's .bounds expectation is blessed only when the file already exists: touch NAME.bounds, then nikaia test --filter NAME --bless.
    • Fact: Probes | A single-file probe cannot use collections (NK1339); a bare HashMap draws NK1135, but check --bounds still prints its table before the error.
  7. Fact lines for Ledger and bounds proofs:
    • Fact: Ledger and bounds proofs | Facts on the value inside a T? result already carry through ?? return, match, != null and ??, for free functions and methods (tests found_facts_through_a_nullable_result and a_methods_nullable_result_holds_its_found_facts_through_self, 2026-11-23, 1823bdbb).
    • Fact: Ledger and bounds proofs | cd packages/logic && nikaia check --bounds src/sv_simplex.nika: 417 indexes, 149 proved; 143 operations, 67 proved (2026-11-23, a4fc8f059).
    • Fact: Ledger and bounds proofs | A method result that comes from a map value (col_var.get, slack_of.get) has no fact, so the sv_simplex tighten reads at 866-899 stay ADR-391 D1 (2026-11-23, a4fc8f059).

Generated by Claude Code

Back to Open Issues