prove-through-loops switch (ADR-361 D14)Open and answer this issue on GitHub.
enhancement, blocked, briefs · opened 2026-11-08 · updated 2026-11-10 · 7 comments
Part of #1053. Found while answering the owner’s question on 2026-11-08 (whether to remove prove-through-loops). Governing decision: ADR-361 D14 (text only, committed with this issue; supersedes D10’s default).
Every build asks an index’s, an overflow’s and a shift’s check that a loop leaves open through the loop, the way prove-through-loops:on does today. The switch goes away. The search runs once, its invariant is an entry of the committed nikaia.proofs (ADR-270 D4), and later builds only check it.
tests/compiler/tests/mut_list_length_kept_across_call.nika, built as a project:
on: 355 M instructions;on (with nikaia.proofs), 313-314 M off.check --bounds FILE): +0.6 % for cexport_model.nika, +18 % for project_features.nika.lower-std --bounds, on against off: +1 index (cexport_model.nika:397 declared[index]) and +4 operations proved (lends.nika:264 position += 1, project_features.nika:224 at += 1, project_tests.nika:922 x2), all of reason a counter a loop changes. In test programs: quicksort’s a[i] after the partition loop (line 23).The second run built steps 1-3 and 5 as a draft, saved on branch wip/issue-1473-draft (fa719267, one commit on 16eb0884; apply with git diff HEAD...wip/issue-1473-draft | git apply). All 45 .bounds programs pass with it, 3 re-blessed (more proofs only), mut_list_length_kept_across_call 10 of 10; the Rust tests in crates/nikaia/tests/it were not run. It stopped on the cold cost: lower-std without cache 7m25s to 9m50s user (+33 %), 3m41s to 5m13s wall (+42 %), two interleaved rounds, identical lowered output.
Decision (supervisor, 2026-11-09): the cold cost is accepted. The search runs once per changed function and its invariant goes into nikaia.proofs (ADR-361 D14, ADR-270 D4); a rebuild with the entries present measured no cost (313-317 M against 313-314 M instructions). So the limit is on the warm run every edit pays, not on the cold one. Step 4 still waits for the compiler session’s lane.
No build, check, test or lower-std run has a setting under which a check is not asked through its loop. optimization = "prove-through-loops:..." is refused with a message naming ADR-361 D14. No *.loops.bounds file remains in tests/.
prove_through_loops in crates/nikaia-std/src/tools/project_settings.nika returns true for any words.prove_through_loops: false defaults in crates/nikaia/src/emit/mod.rs:121,143 become true. These are existing Rust lines; a one-word change, no new Rust.lower-std runs on.tests/compiler/tests/mut_list_length_kept_across_call.bounds re-blessed. It must show 23 a[i] proved and 10 indexes, 10 proved. Every other NAME.bounds that changes is re-blessed, and the commit lists them.lower-std (cache present, one line of tools/project_features.nika changed), on against off, user time with the bash time keyword, two interleaved rounds, both binaries built from the same source (the off twin differs only in the default of emit/mod.rs). Limit: at most 1.1 times off; over it, stop with the figure. The cold run is measured once for the record and has no limit (decided 2026-11-09, below). Not callgrind: a whole lower-std under callgrind takes hours here.NIKAIA_LOWER_CACHE_SALT set, and a --sysroot copy laid out as X/crates with X/packages beside it.project_tests.nika (around lines 74-77, 328, 659-663) computes one --bounds report, not two.tests/**/*.loops.bounds files: each one’s content becomes its NAME.bounds (it is the on report), and the .loops.bounds file is deleted..loops.bounds is an error naming ADR-361 D14..loops.bounds beside a program, with its .stderr.project_settings.nika (the "skip-free-at-exit" | "prove-through-loops" arm, line ~110) refuses prove-through-loops with a message naming ADR-361 D14.choices_key drops /prove-through-loops:on from the cache key.nikaia.toml names it, with .stderr.through_loops / prove_through_loops parameter from crates/nikaia/src/{sysroot,emit/mod,project,bounds,main,bounds_report,check/mod}.rs and from bounds_walk.nika (the on-only branches become unconditional).crates/nikaia/tests/it/prove_through_loops.rs (its cases move to .nika tests if any are not yet covered).30-nikaia-tooling.md: the optimization paragraph (line ~70, “All four are off by default”), line ~111, line ~464 (.loops.bounds), and line ~492 (“Both settings”).prove-through-loops:on” as “in every build”.Every place that reads the setting is listed in step 4 (found with grep -rn "through_loops" crates --include=*.rs --include=*.nika, without lowered/).
project_settings.nika, project_tests.nika, two default lines in emit/mod.rs and test files.crates/nikaia/tests/it/prove_through_loops.rs and facts_at_calls.rs (kept passing, CLAUDE.md), and benches/brc/brc.sh with its README.md.tests/compiler/nikaia.contracts, nikaia.derived, nikaia.proofs or docs/tokenspeed.md.remove-bounds-checks / remove-overflow-checks is on. It keeps two settings of what is proved, a cache-key part and two expectations per test, for a cost the proof file already removes (ADR-361 D14).Generated by Claude Code
Brief queued: issue-1473
agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —
Your work order is issue #1473, 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/1473/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.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.Result: partial with what you ruled out, the probe, and the suspected file and function./home/user/Nikaia/docs/briefs/issue-1473.md.report.md)Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), 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. 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 ;.done <sha>, report <path> (or BLOCKED: ... / PUSH REJECTED ...).Generated by Claude Code
Run: issue-1473, Result: blocked
Tokens: input 156, cache read 6328802, cache write 136429, output 43498 Cost: 6.77 USD, time 65 min 13 s, turns 78
Result: blocked Files: none (draft of steps 1-3 and 5 saved as docs/briefs/issue-1473.draft.patch, applies cleanly to the tree with git apply) Commit: none Fixes: none committed; Part: #1473 Pushed: none Tests: draft verified: all 45 tests/compiler programs with a .bounds pass (3 re-blessed, more proofs only, mut_list_length_kept_across_call 10/10 as the issue requires); bounds_expectation_guards_a_proof and new prove_through_loops_in_the_manifest_is_refused blessed and pass; cargo check –tests clean; lower-std fixpoint clean; Rust it tests not run Gate: red Deviation: measured with time and wall clock rather than callgrind, because callgrind of a whole lower-std takes hours here; A/B used two binaries built from the same source (emit default off vs on) on uncached sysroot copies Found: prove-through-loops always on raises cold lower-std from 7m25s to 9m50s user CPU (+33%) and from 3m41s to 5m13s wall (+42%), 2 interleaved rounds each with identical lowered output; this is over the issue’s 25% limit Needs: supervisor decision (accept the cost, or first make the through-loops search cheaper); the draft patch then finishes steps 1-3 and 5, and step 4 (the Rust parameter) is still open Changelog: none (nothing committed) Issue: I-fit mostly; its Measure line asks for callgrind of lower-std, which is not feasible here; To build leaves out that steps 1-3 break the Rust it tests prove_through_loops.rs and facts_at_calls.rs and benches/brc/brc.sh (the draft updates all three); project.rs:2881 comment still names .loops.bounds Owner: none Disk freed: scratch sysroot copies removed; target/nikaia-project-tests 3.8G, / 4.7G free; no new cache entries over 100 MB Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff
../packages. Comparing the old binary with the new one gave a backwards result (9m40s vs 7m11s), so I built a same-source off twin and ran interleaved rounds. That took about 40 minutes of wall time. I also lost a turn when tail --pid waited on a PID I had guessed wrong..loops.bounds stems; that the Rust it tests and benches/brc pass the word; how to run lower-std uncached (NIKAIA_LOWER_CACHE_SALT plus a --sysroot copy laid out as crates/ with packages/ beside it).lower-std cycles, cargo check --tests, all 45 .bounds programs, the 2 blessed tests, and 2+2 cold A/B runs. Wasted: the old-vs-new comparison (different trees) and the first partial A/B, which a cargo check overlapped. Since the run ended blocked, building the full draft before measuring was also wasted. I should have measured first: changing one default in emit/mod.rs was enough for the A/B.lower-std A/B (twin binaries from the same source).lower-std, which takes hours here: wrong I8.brc.sh that steps 1–3 break: broke I4.lower-std: rules-gap.red): rules-gap.My report’s Issue: field (“I-fit mostly”) was too vague; the items above are the precise version.
| Fact: Core | An uncached lower-std A/B needs NIKAIA_LOWER_CACHE_SALT and a --sysroot copy laid out as X/crates with X/packages beside it, and both binaries built from the same source (a copy of the old binary may come from another tree). |
| Fact: Core | Callgrind on a whole lower-std is not feasible here; measure CPU with time on interleaved cold rounds, or callgrind one file. |
| Fact: Core | cargo fmt -- FILE fails with “Failed to find targets”; run cargo fmt from the repo root, or rustfmt --edition 2024 FILE. |
Generated by Claude Code
Decision (supervisor): the cold cost of prove-through-loops in every build (+33 % user, +42 % wall on an uncached lower-std) is accepted. The search runs once per changed function and its invariant is kept in nikaia.proofs; a rebuild with the entries present measured no cost. The limit moves to the warm run every edit pays: at most 1.1 times off, measured before building the rest. The draft of steps 1-3 and 5 is on wip/issue-1473-draft; the body now names the Rust tests and benches/brc/brc.sh that pass the word, and the recipe for an uncached run. Step 4 still waits for the compiler lane.
Generated by Claude Code
Brief queued: issue-1473
agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —
Your work order is issue #1473, 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/1473/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.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.Result: partial with what you ruled out, the probe, and the suspected file and function./home/user/Nikaia/docs/briefs/issue-1473.md.report.md)Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), 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. 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 ;.done <sha>, report <path> (or BLOCKED: ... / PUSH REJECTED ...).Generated by Claude Code
Run: issue-1473, Result: partial (step 4 left: removing the internal through_loops parameter waits for the compiler lane, as the issue says)
Tokens: input 90, cache read 2875272, cache write 86054, output 18590 Cost: 3.31 USD, time 12 min 21 s, turns 45
Result: partial (step 4 left: removing the internal through_loops parameter waits for the compiler lane, as the issue says) Files: benches/brc/README.md benches/brc/brc.sh crates/nikaia-std/src/tools/lowered/project_settings.rs crates/nikaia-std/src/tools/lowered/project_tests.rs crates/nikaia-std/src/tools/project_settings.nika crates/nikaia-std/src/tools/project_tests.nika crates/nikaia/src/emit/mod.rs crates/nikaia/src/main.rs crates/nikaia/tests/it/facts_at_calls.rs crates/nikaia/tests/it/prove_through_loops.rs docs/builder-facts-lookup.md docs/specification/30-nikaia-tooling.md docs/specification/adr/adr-361.md guide/prover.md tests/compiler/tests/bounds_expectation_guards_a_proof.nika tests/compiler/tests/bounds_expectation_guards_a_proof.stdout tests/compiler/tests/length_of_zero_size_elements.loops.bounds tests/compiler/tests/mut_list_length_kept_across_call.bounds tests/compiler/tests/prove_a_builders_lengths.bounds tests/compiler/tests/prove_a_checked_read_bounds_its_position.loops.bounds tests/compiler/tests/prove_a_checked_read_of_a_typed_list.loops.bounds tests/compiler/tests/prove_a_position_of_a_list_grown_in_a_loop_bounds_a_read.bounds tests/compiler/tests/prove_call_keeps_untouched_fields.loops.bounds tests/compiler/tests/prove_check_after_loop.bounds tests/compiler/tests/prove_check_after_loop.loops.bounds tests/compiler/tests/prove_check_after_loop.nika tests/compiler/tests/prove_derived_precondition.loops.bounds tests/compiler/tests/prove_derived_precondition_call_sites.loops.bounds tests/compiler/tests/prove_derived_precondition_methods.loops.bounds tests/compiler/tests/prove_derived_precondition_methods_none.loops.bounds tests/compiler/tests/prove_derived_precondition_one_caller_over.loops.bounds tests/compiler/tests/prove_element_bound_end.loops.bounds tests/compiler/tests/prove_element_bound_field.loops.bounds tests/compiler/tests/prove_element_bound_field_over.loops.bounds tests/compiler/tests/prove_element_bound_grows.loops.bounds tests/compiler/tests/prove_element_bound_one_caller_over.loops.bounds tests/compiler/tests/prove_element_bound_parameter.loops.bounds tests/compiler/tests/prove_element_bound_popped.loops.bounds tests/compiler/tests/prove_element_bound_pub_field.loops.bounds tests/compiler/tests/prove_for_counts_its_turns.loops.bounds tests/compiler/tests/prove_in_loop_assert_bounds.loops.bounds tests/compiler/tests/prove_loop_counter_bounds.loops.bounds tests/compiler/tests/prove_outer_counter_over_inner_loop.loops.bounds tests/compiler/tests/prove_own_length_broken_by_a_write.loops.bounds tests/compiler/tests/prove_own_length_union_find.loops.bounds tests/compiler/tests/prove_struct_rule_candidates.loops.bounds tests/compiler/tests/prove_struct_rule_parallel_and_arena.loops.bounds tests/compiler/tests/prove_while_counter_relative.loops.bounds tests/compiler/tests/prove_while_name_only_falls.loops.bounds tests/compiler/tests/prove_through_loops_in_the_manifest_is_refused.nika tests/compiler/tests/prove_through_loops_in_the_manifest_is_refused.stdout Commit: bounds: every build proves through loops; prove-through-loops refused, one .bounds per test (ADR-361 D14) Body: Steps 1-3 and 5 from wip/issue-1473-draft, checked whole: prove_through_loops() is true for any words and both Build defaults are true, so lower-std, build, check and test all ask through loops; the word prove-through-loops is refused naming ADR-361 D14 (manifest and –optimization); choices_key drops /prove-through-loops:on; project_tests computes one –bounds report; the 28 .loops.bounds are gone (their on report is now NAME.bounds) and a leftover one is refused naming D14; Part III, ADR-361 D11 heading, guide/prover.md, brc.sh/README and builder-facts-lookup updated; it tests prove_through_loops.rs and facts_at_calls.rs kept passing (the off case and the on-or-off word test became the refused-word test). Re-blessed (more proofs only): mut_list_length_kept_across_call (23 a[i] proved, 10 of 10), prove_a_builders_lengths, prove_a_position_of_a_list_grown_in_a_loop_bounds_a_read, prove_check_after_loop (its comment reworded). Rust touched: two default words in emit/mod.rs and a doc comment in main.rs. Part: #1473 Pushed: local 80f1fee3814405872fe0d92e2e5702a25c899242 Tests: warm lower-std A/B (one comment line of project_features.nika changed per run, twin binaries differing only in the emit/mod.rs default, two interleaved rounds, user time): on 196.7 s / 190.1 s, off 204.9 s / 199.3 s, ratio 0.96 (limit 1.1); cold for the record (fresh salt, sysroot copy): on 9m47s user / 5m10s wall, off 7m29s / 3m41s (+31 % user); lowered output identical to the checkout; lower-std fixpoint clean; nikaia test –both-settings: all 45 .bounds programs + bounds_expectation_guards_a_proof + prove_through_loops_in_the_manifest_is_refused, 51 passed; on a binary built from HEAD’s sources those last two and mut_list_length_kept_across_call FAILED (3 of 3); it prove_through_loops:: facts_at_calls:: prove:: bounds 122 passed, optimization assert:: assume:: 21 passed; lib emit:: 1, project:: 10 passed; clippy, fmt, pre-push green Gate: green Deviation: step 4 (remove the through_loops/prove_through_loops parameter from the Rust and bounds_walk.nika, delete it/prove_through_loops.rs) not built: the issue gates it on the compiler session’s lane; bounds_frame.nika’s frame context keeps through_loops: false (internal, a call’s frame search), for step 4 to decide Found: none Needs: step 4 as its own run once the compiler lane allows it Changelog: Every build proves through loops (ADR-361 D14): an index’s, overflow’s or shift’s check a loop leaves open is asked through the loop’s invariant in every build, lower-std included; the optimization word prove-through-loops is refused naming D14, and a test program has one –bounds expectation (NAME.bounds; a NAME.loops.bounds is an error) Issue: complete Owner: none Disk freed: 139M scratch (twin binaries, sysroot copy); target/nikaia-project-tests 3.9G, / 4.3G free; new cache entry over 100 MB: run-bundle/df470de966285daf 298 MB Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff
lower-std runs that warmed each binary’s cache (5 and 4 minutes of wall time) before the timed rounds. Each warm round still took about 2 minutes. The most turns went on the fails-before run. The target/fast/nikaia I copied at the start had already been built from the draft, so the run had to be redone with a binary built from HEAD’s sources.--sysroot takes X/crates, not X (the facts say “a copy laid out as X/crates”, which reads as X); that lower-std uses Build::default() (so the off twin needs only the emit/mod.rs change); and that the cache key holds {build:?}, so on and off never share cache entries.lower-std fixpoint; 51 test programs; the fails-before run on the HEAD build; it filters (122 + 21 passed); --lib emit:: and project::; fmt, clippy and pre-push. Wasted: the first A/B launch (wrong --sysroot) and the fails-before run on the stale copy.git checkout HEAD -- <own files>, build, git apply the saved patch). Copying target/fast/nikaia does not give a before binary.wrong I11: the recipe says “pass --sysroot a copy laid out as X/crates”, but the argument is X/crates itself.rules-gap: the Done when is reachable without step 4, which is gated on another lane, so it is unclear whether Result should be done or partial.broke I10: bounds_frame.nika:160 through_loops: false is not in step 4’s list of places that read the setting.| Fact: Core | lower-std --sysroot takes the crates directory of the copy (X/crates); given X it fails at once with “reading X/nikaia-std/src”. |
| Fact: Core | When a wip draft was built before your run, target/fast/nikaia already holds it; build the before binary by checking out HEAD’s version of only your own files, building, then git apply your saved patch. |
| Fact: Core | The lower-std cache key includes the Build settings, so an A/B of two settings needs a warm-up run for each binary; the first run with a fresh salt is the cold figure. |
Generated by Claude Code
Steps 1-3 and 5 are built (80f1fee3): every build proves through loops, prove-through-loops in a manifest is refused, one .bounds per test. Measured: warm lower-std on/off 0.96 (limit 1.1); cold +31 % user, accepted above. Left: step 4, removing the internal through_loops parameter from the Rust and bounds_walk.nika (and bounds_frame.nika’s through_loops: false for a call’s frame search, to be decided there), once the compiler session’s lane allows.
Generated by Claude Code
Status: blocked. Steps 1-3 and 5 are built (80f1fee3, now on develop). Step 4 removes the internal through_loops parameter, and it waits for the compiler lane, which changes the same code.
Generated by Claude Code