Issue #2782: bounds walk: a struct returned by a call keeps the length facts of its list fields (sv_sat 668, sv_simplex 2834-2836)

Open and answer this issue on GitHub.

ready, 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

When a function returns a struct, the bounds walk keeps no fact about the lengths of the struct’s list fields. A read of that field in the caller therefore stays checked, although the callee plainly builds it non-empty or with a known length.

Sites on develop (nikaia check --bounds packages/logic/src/main.nika):

To build

  1. A result fact about a returned struct’s list field (result.f.len() >= 1, result.f.len() == n), derived in the callee like the found facts of a free function’s result (ADR-306) and carried to the caller’s binding.
  2. A probe test in tests/compiler/tests/: a function returns S { xs: [a] } or pushes once before returning, and the caller’s s.xs[0] is proved; a function that may return S { xs: [] } stays checked.

Done when

The probe test passes under both settings, and the sites above print proved in check --bounds packages/logic/src/main.nika, or the report names each site that still does not and why.

Comments

keywan-ghadami, 2026-11-23

Brief queued: issue-2782


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

Issue #2782

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

Tokens: input 202, cache read 7138256, cache write 152847, output 45401 Cost: 3.75 USD, time 23 min 22 s, turns 101

Report

Result: partial Files: crates/nikaia-std/src/compiler/bounds_walk.nika crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/bounds_walk.rs crates/nikaia-std/src/compiler/lowered/check_core_call_on.rs crates/nikaia-std/src/runtime/lowered.rs crates/nikaia-std/src/runtime/lowered/abort_lines.rs examples/inventory/nikaia.proofs examples/n-body/nikaia.proofs packages/logic/nikaia.proofs packages/yaml/nikaia.proofs tests/build-time/nikaia.proofs tests/compiler/nikaia.proofs tests/language/nikaia.proofs tests/page-examples/nikaia.proofs tests/compiler/tests/a_list_not_empty_is_derived.bounds tests/compiler/tests/a_list_not_empty_is_derived.nika tests/compiler/tests/prove_the_values_a_call_returns_bound_a_read.bounds tests/compiler/tests/a_struct_result_keeps_the_least_length_of_its_list_fields.nika tests/compiler/tests/a_struct_result_keeps_the_least_length_of_its_list_fields.stdout tests/compiler/tests/a_struct_result_keeps_the_least_length_of_its_list_fields.bounds Commit: bounds walk: a struct result keeps the least length of its list fields Body: BoundsReturns gains floors (least length of each list field of a returned struct, asked >= 2 then >= 1, proved at every return, a struct literal’s field read through its value’s path, ADR-306 D23/D35); bounding_measured states len(name.f) >= floor at the caller’s let, also through ?? (nullable struct results); new proofs: a_list_not_empty_is_derived 24, prove_the_values_a_call_returns_bound_a_read 49, check_core_call_on opens[index], abort_lines table[1]; ledgers refreshed: the new floor questions add 9375 entries to packages/logic/nikaia.proofs (82667 to 91413 lines; HEAD’s ledger was current under the HEAD binary, so all are this change’s), 15 yaml, 94 page-examples Part: #2782 Tests: new a_struct_result_keeps_the_least_length_of_its_list_fields passes –both-settings, FAILED on the unfixed compiler ($NIKAIA_OLD, 0 of 6 proved); all 193 tests/compiler .bounds compared old vs new by check –bounds, only the 2 above changed (sound, reblessed, both-settings ok); ledgers –check all current; pre-push green; clippy nikaia-std clean Gate: green Deviation: none Found: a callee in another file of the package gives its struct result no list-field length (sv_simplex 2834-2837 split_l.lits/split_c.lits, callee SvBook.split in sv_proof.nika); traced: found returns are computed per file, bounds_returns in bounds_proven.nika:135 runs over one file’s program, other files reach a body only through beside frames (ADR-391 D1); probe package pk, nikaia.toml [package] name = "pk" version = "0.1.0", src/book.nika pub struct S { pub xs: Vec[i64] } pub struct Book { pub atoms: Vec[i64] } impl Book { pub fn split(mut self, a: i64) -> S? { if a < 0 { return null } self.atoms.push(a) return S { xs: [a, a] } } }, src/main.nika fn first(mut b: Book) -> i64? { let s = b.split(3) ?? return null return s.xs[1] } fn main() throws { let mut b = Book { atoms: [] } println(first(b) ?? 0) }; nikaia check --bounds src/main.nika (HEAD + this change) prints 3 s.xs[1] checked: no fact bounds what it reads, the same two files merged into one print proved (test a_struct_result_keeps_the_least_length_of_its_list_fields line 57); no decision yet whether found returns reach across files Found: a list grown by a for loop loses len >= 1 at the return of a found-returns callee, for a struct field and a returned list alike (sv_sat 668 learned.lits[0], analyze builds lits = [0] and pushes in loops); probe loop2.nika: pub struct S { pub xs: Vec[i64] } pub fn l1(a: i64) -> S { let mut xs: Vec[i64] = [0] for k in 0..<a { xs.push(k) } return S { xs: xs } } pub fn l3(a: i64) -> Vec[i64] { let mut xs: Vec[i64] = [0] for k in 0..<a { xs.push(k) } return xs } pub fn r1(a: i64) -> i64 { let s = l1(a) return s.xs[0] } pub fn r3(a: i64) -> i64 { let s = l3(a) return s[0] } fn main() throws { println(r1(2) + r3(1)) }; nikaia check --bounds loop2.nika prints s.xs[0] checked and s[0] checked, should be proved since a push never shortens a list (Part I: push appends), and the same loop then xs[0] inside one function prints proved; without the loop (xs.push(a)) the caller’s read is proved; cause unknown, suspected: the main walk of bounds_rounds_settled / bounding_pass in bounds_walk.nika forgets the length at a loop’s exit (check: –bounds-trace on the return line of l1) Needs: none Changelog: Bounds: a struct a call returns keeps the least length of its list fields - s.xs[0] after return S { xs: [a] } or one push needs no check (#2782). Issue: ok Owner: none Friction: none Disk freed: 0; target/nikaia-project-tests 1.8G, / 11G free, no new entry over 100 MB Reviewed: 8f18e088913d9fdac841df9d2d78e45525e8f337d1a7ff8107f00a2cdb25cfaa Pushed: local 3389b4ddf0682d7b4159237d919c6906f92c4949 Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. Most turns: finding out why the logic sites stayed checked even though the probes passed. I found two separate causes late: found returns are worked out one file at a time (bounds_proven.nika:135), and the main walk loses len >= 1 after a loop that pushes. I then spent more turns on the loop shape and did not fix it.
  2. Looked up: how BoundsReturns, the rounds and bounding_measured fit together (ADR-306 D23/D25/D34/D35), that found returns are per file, and how a package’s files see each other (no use). I also had to work out probe syntax (ref mut refused, NK1158; mut b: Book works).
  3. Checks:
    • Useful: the old-vs-new check --bounds over all 193 .bounds tests, which found 2 changed tests. Also the --both-settings runs, ledgers --check and --refresh, pre-push and clippy.
    • Wasted: the first dry run, whose report a heredoc mangled by expanding the backticks. Also the probes of the loop shape after the time box was in sight.
  4. One change: the brief should run the issue’s target sites through --bounds-trace and check that each callee is in the same file as its caller. That would have shown the cross-file sites as out of reach before I built anything.
  5. What the issue lacked:
    • broke I7: it named no cause for sv_simplex 2834–2837 and did not say that the callee SvBook.split is in another file, where found returns cannot reach.
    • rules-gap: no rule asks an issue to name the shape of each target site (a list grown in a loop, as in sv_sat 668’s analyze).
    • knowledge: Ledger and bounds proofs | a change to the bounds walk that asks new questions leaves the committed ledgers stale; run ledgers.nika --refresh before committing.
  6. Fact lines for the next builder:
    • Fact: Core | an unquoted heredoc expands the backticks in a report's probe snippets, so write the report with a quoted heredoc ('EOF') or the Write tool.
    • Fact: Ledger and bounds proofs | found returns (ADR-306 D23) are computed per file in bounds_proven.nika:135, so a callee in another file of the package gives its caller no result facts.
  7. Facts for the same work area:
    • Fact: Ledger and bounds proofs | measure a bounds change with check --bounds old vs new over tests/compiler/tests/*.nika that have a .bounds file; on 2026-11-23 at 3389b4dd only 2 of 193 changed, both new correct proofs.
    • Fact: Ledger and bounds proofs | struct-field floors (3389b4dd, 2026-11-23) grew packages/logic/nikaia.proofs from 82667 to 91413 lines (+9375 questions: 3761 proved, 4138 refuted, 1476 unknown).
    • Fact: Ledger and bounds proofs | as of 3389b4dd (2026-11-23), sv_sat 668 is still checked (the length is lost after a for loop that pushes, cause unknown) and sv_simplex 2834–2837 are still checked (callee in another file).

Generated by Claude Code

Back to Open Issues