decreases only where the guess fails, endless loops marked)?Open and answer this issue on GitHub.
ready · opened 2026-11-12 · updated 2026-11-30 · 1 comment
An outside consultancy made suggestions to the owner on 2026-11-12. This is one of them: Dafny’s termination proof, but with the measure guessed automatically, a decreases clause written only where the guess fails, and loops meant to run forever marked explicitly. No ADR and no issue covers termination yet.
A program terminates when every call returns and every loop ends. Today the Nikaia compiler proves facts about values: indexes, divisors, overflow and asserts (ADR-269, ADR-306, ADR-395, ADR-396). It proves nothing about whether a loop or a recursion ends. A while whose condition never turns false, or a recursion that never reaches its base case, builds without complaint and hangs at run time.
The usual proof of termination is a measure: a number that is never negative and that every loop iteration or recursive call makes smaller, such as xs.len() - i, or n in f(n - 1). Such a number cannot shrink forever, so the loop ends. Dafny asks for the measure in a decreases clause, and guesses it for simple cases.
The question: should Nikaia prove termination? If so, how is the measure found? Where is a decreases written? How is a loop marked that is meant to run forever, such as a server loop, an event loop or a task that waits on a channel? And what happens to a function the prover cannot show to terminate: refused, a warning, or only reported?
while true is the one unconditional loop. That is already a visible mark for “meant to run forever”.These facts are from memory, not checked.
| Language | Rule |
|---|---|
| Dafny | every loop and recursion must terminate. A decreases measure is guessed (the parameters in order, or the loop bound) and written where the guess fails. decreases * marks a method that may run forever, and it can only be called from other decreases * methods |
| Lean, Agda, Idris | total by default. Structural recursion is accepted automatically, others need a well-founded measure. partial (Lean) and covering (Idris) mark the rest |
| F* | Tot versus Div effects: a function that may diverge says so in its type |
| Vera | contracts on every function. Whether it proves termination is unknown to me |
| AILANG, Boruna, Mojo | no termination proof that I know of |
| Rust, Go | none. loop {} marks the intended endless loop, but nothing proves the others end |
--bounds / --asserts, or a new --termination, lists each loop and recursion as proved to end, meant to run forever (while true), or unknown. Nothing is refused.
decreases, or is marked as endless (while true, or a function-level mark that spreads to its callers like Dafny’s decreases *). Otherwise the build refuses it under unproved-claims.
decreases, a function mark). Some code the prover cannot handle needs a written measure, for example loops on data read from outside, or while loops over a linked structure. The count is unknown.deterministic or pure. Terminating is required where it matters most, for meta and comptime code and for #1435’s derived properties, and reported elsewhere.
Option 2 first, then decide between 3 and 4 on the count. Build the measure search on ADR-361’s machinery: a ranking function is checked like an invariant. Treat while true as the existing endless mark, so no new keyword is needed for it. Take a decreases keyword and a function-level “may not terminate” mark only if the count shows the guess fails often enough to need them.
while true as the endless mark), ADR-321 D7 (the build-time step budget), ADR-269 D10.crates/nikaia-std/src/tools/bounds_*.nika), and a report flag in Part III (30-nikaia-tooling.md).decreases or a function mark is taken.Owner’s answer, 2026-11-30: option 2 now, option 3 the aim.
while true, ADR-276) or unknown. Nothing is refused.decreases only where the search fails) is decided on the count option 2 gives.Recorded in ADR-termination-v1 (D1-D5) and Part III 14.2 (--terminates), commit 234d5685.
To build
asserts and a proposer; two queries with certificates (bounded below where a turn or call begins, strictly smaller every turn, way back to the head and recursive call); a measure that passes is kept in nikaia.proofs with its origin (ADR-termination-v1 D1, D2).--terminates report on nikaia build, check, lower and lower-std: every loop and recursion by line as ends (measure and origin), meant to run forever (while true) or unknown (the loop or cycle of calls and the names it changes), with the counts; the build is the same with or without the flag (D3, D4). Tests as .nika programs in tests/compiler/tests/ with their .stdout: a counted while, a for, a recursion on n - 1, a while true, and a loop over a linked structure that stays unknown.lower-std --terminates over std and the compiler’s Nikaia code, the unknown loops and recursions by shape, as a comment here; it decides the next version of the record (D5).--terminates reports the five test shapes as above, lower-std --terminates runs to the end on develop and its counts are a comment on this issue; the commit that adds the report carries Fixes #1577.
Generated by Claude Code