for loop loses len >= 1 at the return of a…Open and answer this issue on GitHub.
wip, bugs · opened 2026-11-23 · updated 2026-12-01 · 2 comments
Filed by the driver from the Found: of the run of issue-2782 (#2782) (owner, 2026-11-06).
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)
develop first: the run that wrote it may have used a binary older than the tip, so it may be fixed already (#1822: #1788 was filed from a probe a fix under #1754 had already made pass). A probe that passes there names the commit that fixed it (git log -400 --grep by topic, since a fix often lands under another issue’s number), and the run builds only a tests/compiler/tests/ test that pins it (docs/issues.md I13).std defect with a probe (nikaia run scripts/probe.nika -- SNIPPET; a lowered file that differs, with an uncached lower-std of a git archive HEAD copy, NIKAIA_LOWER_CACHE_SALT fresh and --sysroot COPY/crates, its lowered/ diffed against the copy’s, never the shared working tree’s, #1793), a defect in docs/, guide/, website/ or scripts/ (a stale example, a wrong rule) with the command or check that shows it; a behaviour the code does on purpose (name the function or ADR) closes it as by design. The Found line may lack them (#1710): the commit message, or the report’s Body: when closed, gives the probe or check with its expected output, the ADR or Part I-III section that says so, and its actual output (docs/issues.md I5, I6), and the cause, file and function, traced or suspected (I7).std defect in the compiler, a stale page example or rule in its page or docs/ file, a script defect in the script. Add a test in tests/compiler/tests/ unless a check that already runs turns red on it (name it: pre-push’s page-examples for guide/ and website/, check-adr-refs.nika for a docs citation).The probe or check gives the expected output the first item names from its ADR or Part I-III section, and a tests/compiler/tests/ test (or the named check) that failed on the unfixed tree is green; or the probe already passes on develop and a test pins it, naming the commit that fixed it; or the issue is closed as by design, naming the function or ADR.
Generated by Claude Code
Brief queued: issue-2826
agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —
Your work order is issue #2826, 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/2826/comments -F body=@file,
ending with the Claude Code footer), rule I13.
develop in the main checkout; other agents’ uncommitted files are not yours: never touch or stage them.target/fast/nikaia run scripts/commit.nika -- REPORT (it adds exactly the report’s Files:); the driver pushes.cargo build --profile fast -p nikaia, lower-std and its fixpoint when a tools/*.nika changed, cargo fmt, cargo clippy --all-targets -- -D warnings, nikaia run scripts/pre-push.nika, the tests the issue names and the ones your change touches.CHANGELOG.md, badges and NK codes are the supervisor’s. New tests in Nikaia only: a Rust test file an older issue names is built as a tests/compiler/tests/ program, no Deviation: and no Issue: point (I9, #1671).Body:. Found: is only for what lies outside the area, cannot be fixed this run or needs a decision; the driver files it as an issue.std or the toolchain lacks stops the work, unless an ADR or Part I-III refuses it (name it): Result: blocked, Found: the gap with a probe, Needs: supervisor decision.NIKAIA_CACHE_LIMIT=2G; at the end delete your own clone’s target/ and target/release/nikaia-scratch.suspected, or does not mark (docs/issues.md I7), is a hypothesis: run the check that settles it (nikaia run scripts/where.nika -- NAME, the probe with a trace, callgrind for a cost) before you build on it (owner, 2026-11-16). Shown false: say so in Issue: as wrong I7: <what the check showed> (the driver comments it on the issue) and follow the real cause.Result: partial with what you ruled out, the probe, and the suspected file and function./home/user/Nikaia/docs/briefs/bugs/issue-2826.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.
Result:, Gate: (green or red <check>), Deviation:, Found: and the other fields with nothing to say hold the bare word: done, none. Anything after it reads as content.Result: done only when the issue’s Done when holds; partial with the items left otherwise.Deviation: only for an item of the issue built otherwise than written, or not built. Found: only for a defect outside your area, or one this run cannot fix: one defect per Found: line, with its probe and the output it gives, only the shapes that fail today, and the suspected file and function or cause unknown (#1695); a by-design behaviour is none (#1677). A correct program your own change refuses (a fail-closed check’s false refusal) is no Deviation: but one Found: line per shape, with its probe (#1680). Everything else goes into Body:; how you verified goes into Tests:.Issue: by docs/issues.md, How a run judges its issue: complete, or broke I<n>: ..., rules-gap: ..., wrong I<n>: ..., joined with ;; a point your own commit built gets (built) after its kind (rules-gap (built): ...), and the driver does not file it. complete is the bare word: prose after it (complete; the earlier runs ...) is filed as an improvement issue (#1931); history or a note for your own issue goes into Body: or Comment: #N <text>.done <sha>, report <path> (or BLOCKED: ... / PUSH REJECTED ...).Generated by Claude Code
Run: issue-2826, Result: done
Tokens: input 342, cache read 10150319, cache write 238417, output 73549 Cost: 5.71 USD, time 0 min 55 s, turns 171
Result: done
Files: crates/nikaia-std/src/compiler/bounds_walk.nika crates/nikaia-std/src/compiler/lowered/bounds_walk.rs crates/nikaia-std/src/compiler/lowered.rs crates/nikaia-std/src/compiler/lowered/cexport.rs crates/nikaia-std/src/compiler/lowered/project_features.rs tests/compiler/tests/a_list_started_from_a_literal_is_not_empty_at_the_call.nika tests/compiler/tests/a_list_started_from_a_literal_is_not_empty_at_the_call.stdout tests/compiler/tests/a_list_started_from_a_literal_is_not_empty_at_the_call.bounds tests/compiler/tests/a_list_not_empty_is_derived.nika tests/compiler/tests/a_list_not_empty_is_derived.bounds tests/compiler/tests/prove_the_values_a_call_returns_bound_a_read.bounds
Commit: A list a callee returns started from a literal and only pushed to is not empty at the call, as a returned list and as a struct’s list field (–bounds)
Body: found returns get a filled measure set (len() >= 1 proved at every return, in an unguarded walk where the measuring walk took parameters at zero or more), stated unguarded at the call; a for over a range that may run no turn now keeps what held of its pushed lists’ lengths where it was reached (len >= reached), and a struct literal field given a name is as long as that name (S { xs: xs }). Four more reads of std are proved now (lowered cexport.rs, project_features.rs: crossing/core read inside), and two tests’ reads turn proved (a_list_not_empty_is_derived line 24, prove_the_values_a_call_returns_bound_a_read line 49), both sound by their callees.
Fixes: #2826
Pushed: local 69e21888d56386c5ff94d0d10cc3e648d4e64ffc
Tests: new a_list_started_from_a_literal_is_not_empty_at_the_call (fails on unfixed 840fd710e: all four reads checked; now 3 proved, the may-be-empty callee’s read checked); nikaia test –both-settings of it, a_list_not_empty_is_derived, prove_the_values_a_call_returns_bound_a_read, a_returned_list_lengths_are_found_facts: 4 ok; every tests/compiler/tests/*.bounds compared to check –bounds: only the two updated differ; lower-std fixpoint clean; cargo fmt, clippy, pre-push
Gate: green
Deviation: none
Found: none
Needs: none
Changelog: A list a function returns that starts from a literal and is only pushed to, by a loop or not, is known not empty at the call: --bounds proves xs[0] of it, and of such a list field of a returned struct (#2826).
Issue: wrong I7: without the loop the caller’s read was checked too (return [0, 1] drew a checked s[0] on 840fd710e): returned-length facts only related lengths to parameters, and a struct field given a name (S { xs: xs }) held nothing of its length
Owner: none
Comment: none
Friction: none
Disk freed: none (cache target/nikaia-project-tests 2.0G at its limit, / 11G free; no new cache entry over 100 MB)
Reviewed: f0d3309ae373c4ff044332c94c098bcb1ffc89428d2419f859eaabdb605b1913
Attribution:
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01UVxJDutPTwP5Xj5HkGuidk
for k in 0..<a with a: i64. Several 5–10 minute debug builds went into finding why the list’s pre-loop length facts were lost:
xs.len()#N sat under the list’s name, so the element check rejected it.The struct form then needed one more debug build. It turned out a struct literal field given a name stated nothing about its length.
BoundsReturns, the measuring walk, guards);bounding_built / bounding_for in bounds_walk.nika;TermArena.mentions (an exact name match);.bounds file format;eprintln inside the compiler needs catch {}.A pointer to bounding_return_lengths and to bounding_measured (the call side) would have saved several reads.
.bounds against check --bounds;eprintln without catch;others hypothesis (I wrongly assumed mentions matches by prefix).walk.arena.text). --bounds-trace LINE shows only the facts at the caller’s read.wrong I7: it says the read is proved without the loop; on 840fd710e return [0, 1] also drew a checked s[0] at the caller.broke I7: it named no suspected function (bounding_return_lengths, bounding_built).| Fact: Ledger and bounds proofs | A fresh prover name made of a list’s length plus a suffix (xs.len()#N) is treated as one of that list’s places, so the loop’s element check drops facts stated in it; name it apart (#reachedN). |
| Fact: Core | eprintln in a compiler .nika draws NK2605 at lower-std unless written eprintln(...) catch {}. |
| Fact: Ledger and bounds proofs | --bounds-trace LINE shows only the facts at the read on LINE, never a callee’s return walk; debug those with prints in bounding_return_lengths. |
| Fact: Ledger and bounds proofs | Found returns: bounding_returns_round (measuring and plain walk), bounding_return_lengths (callee side), bounding_measured (call side) in bounds_walk.nika; a struct literal field’s length comes from bounding_built. |
| Fact: Ledger and bounds proofs | Compare all expectations quickly: run check --bounds on each tests/compiler/tests/*.nika that has a .bounds, from tests/compiler, and diff it with the suffix ` - written without their check: …` stripped (195 files, a few minutes, 2026-12-01, commit 69e21888d). |
Generated by Claude Code