ADR-prover-walk-v1: The Compiler Walks Each Body Forward and Keeps the Linear Facts That Hold — Names, Paths, Lengths and the Goals It Asks

Status: Accepted Date: November 29, 2026 (the consolidation, #1790; the decisions themselves October 3 to November 15, 2026) History: the records this one replaces are archived in docs/history/adr; read them only for how the decision was reached Answers: which facts the compiler knows where it asks whether an index, an operation or a shift can fail, how it gathers them, and how it asks the solver Supersedes / Related: takes the decisions on the walk from the numbered records now in the history, with new numbers; ADR-prover-checks-v1 (what is done with a proof), ADR-prover-found-facts-v1 (what the compiler finds about data and across calls), ADR-prover-refusals-v1 (what a build refuses) · ADR-269 D5 (a precondition is an assert at the top), D9-D10 (what the prover reads), ADR-270 D1 (Fourier-Motzkin in the logic layer), D5 (a check is dropped only on a certificate its checker accepts), D19-D23 (nikaia.proofs), ADR-collections-v4 D13 (an assignment’s value is computed before the place it writes), ADR-314 (ensures), ADR-375 D5 (ensures_each; “other searches take the same entry when a program needs it”), ADR-361 D13 (a for counts its turns), Part I 2.2 (a length is an i64), Part III 14.2 and the optimization paragraph of 30-nikaia-tooling.md (what a proof reads)

1. Question

An index, an operation on whole numbers and a shift each have a goal: 0 <= i < xs.len(), a result inside its type, a count below the width. The solver answers a goal only from the facts it is given. Which facts does the walk keep, where does it learn and forget them, and which does it hand the solver for each goal?

Two of the gaps it had (#1053): while i < xs.len() { i += 1 } is proved where xs’s elements take space and left checked where they do not (Vec[Z] with struct Z {}), although i < xs.len() alone keeps i + 1 inside i64. And let parts: Vec[ref String] = path.split(".").collect() followed by parts[0] is left checked, although split never yields nothing. About 160 indexes of constant position and many counters in tools/*.nika stopped at these two (D13, D14).

How others do it, and the options weighed, are ADR-prover-checks-v1 §2 and §3: the walk is the range-check elimination of HotSpot C1 and RyuJIT, widened to the facts a program’s own guards give.

2. Decision

D1 — aggressive: the solver, from the facts a forward walk keeps.

Each function body is walked forward, keeping the linear facts that hold at each point, over whole numbers and the lengths of std’s lists, text and maps:

Polarity decides what a condition says. A condition is read as a formula it implies: of a && b, what is known of either half; of a || b, something only where both halves are known. Its denial is read the other way round: a || b false says what is known of either half false, and a && b false says something only where both halves can be denied. Reading a && b as a under a negation would prove what does not hold.

A conversion keeps its value or stops the program (Part III A.2), and so does arithmetic: a fact about x as i64, or about 2 * v + 1, is a fact about the number, wherever the program goes on.

The walk follows the order the lowering runs things in. An assignment’s value is walked before the index it writes at, because the value is computed first (ADR-collections-v4 D13): in xs[2] = xs.pop() ?? 0 the list is shorter by the time the write happens. A call’s receiver comes before its arguments, and its effect after both.

A match arm starts with nothing known. Its pattern may bind a name that hides an outer one.

At a loop’s head, every fact about a name the body changes is forgotten, and what holds of it everywhere - never negative - is said again. A name a lambda, a task, an overlap branch or a select arm changes has no facts at all. A question is asked with at most 48 facts, so a long body costs the solver what a short one does; which 48 is D7.

The goal 0 <= i && i < xs.len() is asked of Fourier-Motzkin (ADR-270 D1); a check is dropped only where the answer is proved and its certificate passes the checker (ADR-270 D5). x.len() is a number of the proof only where the checker typed x as a std list, text, map or set: a len() a program writes for its own type may say anything.

D2 — The walk’s answers are recorded in nikaia.proofs.

Every answer a build uses is recorded there with its evidence (ADR-270 D19-D23), the walk’s as much as a claim’s: a build is a function of the sources and the committed file, whatever the solver’s search does.

D3 — A field is a name of the walk while nothing can change it.

A path of fields from a name, t.slots, p.end, self.at, is read as a name of its own: a number at the path is one, and t.slots.len() is a length (D11) as a list binding’s is. A fact about a path holds from where it is learned until something may change the path:

A precondition (ADR-269 D5) may read a path from a parameter, and a caller proves it as it proves any other.

Scanners keep a cursor and a buffer in one value (self.at + 1 < self.c.len()), tables keep their slots in a field, and work is cut into pieces that carry their bounds: the field is where such a program keeps the numbers a check is about, and a walk that forgets them at the dot proves none of it. Copying each field into a let first is the same proof with a line per field, asked of every program.

D4 — A path through one element is a name of the walk too.

October 22, 2026, #781.

t.slots[at].sum, a path of fields through one element of a list that is itself a path (D3), indexed by a name, is a name of the walk as t.used is: unsafe { assume(t.slots[at].sum <= B) } bounds it, and t.slots[at].sum += v is proved from that. What is known of it holds until

A write to another field of the same element keeps it: t.slots[at].min = v cannot change t.slots[at].sum. An index that is not a name makes no path; a write through it drops what is known of every element.

An aggregation loop keeps its sums in the elements of a table, and the bound that keeps them from overflowing is about the element the row lands in: a walk that knows fields only from a name proves none of the four writes a row makes.

D5 — An element is a name of the walk as a field through one is (supervisor, 2026-11-14, #1596).

xs[c], one element of a list that is a name or a path (D3), indexed by a name or an integer literal, is a name of the walk as t.slots[at].sum is (D4): a number at it is one, xs[c] += k asks its overflow goal (ADR-prover-checks-v1 D2, ADR-prover-refusals-v1 D1), and xs[c] / d reads it as a term. A list literal bound by a let or a let mut gives what it holds at each literal index (let mut xs = [2147483647, 0] gives xs[0] == 2147483647). What is known of xs[c] holds until what D4 lists for t.slots[at].sum with xs for t.slots and c for at: c may change, a write to any element of xs (the walk does not tell indexes apart, literal or not), a method that may change an element or the length, and anything D3 lists for xs itself. An index that is neither a name nor a literal makes no name, and a write through it drops what is known of every element.

D4 already follows t.slots[at].sum; an element with no field after it is the same path one step shorter, and leaving it out let xs[0] += k overflow at run time where x += k beside it is refused (#1586, #1594).

Decided by the supervisor as obvious under the language principles (docs/supervisor.md, Language decisions): D4’s rule without the field, no written form.

D6 — A shift’s count is a goal of the walk, as an index is.

if dot > 28 { throw BadRow {} }
let digits = (w & keep) << (28 - dot)      // 0 <= 28 - dot < 64: no check

A shift whose count is not a literal, x << k and x >> k, asks 0 <= k < w, w the width of x’s type, as an index asks 0 <= i < len. Where the walk proves it, remove-overflow-checks:on writes the shift without its check; where it does not, the shift is checked as Part I says, and a count it shows outside is an error as ADR-prover-refusals-v1 D1 says.

Why. A shift by more places than its type is wide stops the program (Part I), so the count is checked at every such shift, and the checks a program writes before it - a guard on a value it read - prove it as they prove an index. Without the goal, the only way to lose the check is a wrapping_shl, which turns a wrong count into a wrong value without a word, against what the check is for; an assert does not help, because nothing reads it as the shift’s goal. Rejected: masking the count as Rust’s release build and Java do, which gives a value where the program means a stop; a switch of its own, for a goal of the same kind as +, - and *’s.

D7 — A question gets the facts that concern it, not merely the newest (supervisor, 2026-11-09, #1500).

The cap of 48 facts kept the newest facts of a point and dropped the oldest without a word. A body that keeps many lists (a builder filling thirteen fields in one loop, sv_walk_start) pushed two turn facts per list per loop and lost the length facts its later reads need, though no question ever read the facts that pushed them out (#1470, step 4).

So the cap moves from the point to the question. A point keeps up to 256 facts (newest first; past that the oldest go, and the --bounds-trace count of evicted facts says so). Each question takes from them the facts connected to its goal, nearest first: a fact sharing a name with the goal or with a fact already taken is next, and a name that many facts share costs as many steps as facts name it (every turn fact of a loop names that loop’s turn, so the turn alone joins every list the loop grows); among equals the newest go first, and the first 48 are asked. Below 48 held facts all are asked (#1500). A dropped fact can only fail to prove, never prove wrongly, so the choice is free; the connected facts are the ones the goal can use.

The cost of a question stays bounded by 48 facts; selecting them is linear in the facts held. A slower walk slows every lower-std (ADR-prover-checks-v1 D12), so the build is measured against the binary before it: check --bounds of the slowest tool file within 1.2 times its time before, and the --bounds figures of the toolchain not lower at any site.

Not chosen: raising the cap (every question pays for it), a cap per root (a goal over two roots needs both), and moving length rules beside the facts like element rules (ADR-prover-found-facts-v1 D7): a length rule does not hold between two writes in a method that grows the lists, an element rule does.

D8 — A product of two unknowns is bounded by interval arithmetic (supervisor, 2026-11-10, #1516).

The walk left xi * y[j] open. Fourier-Motzkin reasons about linear facts only; a product of two values neither of which is a constant is not one. The walk bounds it beside Fourier-Motzkin by interval arithmetic: each operand’s interval is what the walk has found for it (a range check, a match on digits, a found bound of ADR-prover-found-facts-v1 D1, D2 or D5, the operand’s type when nothing narrower is found), and the product lies between the least and the greatest of the four products of the ends. That interval is a fact about the result for the rest of the walk, and the overflow check of the * is proved when it lies within the type (hex_value * 16 with the value in 0..=15, value * radix with the radix in 2..=16 and the value proved below i64::MAX / 16). A product whose interval is not within the type stays checked (ADR-prover-checks-v1 D2).

Decided by the supervisor as obvious under the language principles (docs/supervisor.md, Language decisions): the answer the open question already named, no written form.

D9 — x % n is a bound.

Where x is not negative and n is a positive term, 0 <= x % n < n; for an unsigned x, always. Where the sign of x is not known, 1 - n <= x % n <= n - 1 (the remainder takes the sign of x; recorded 2026-11-15, #1643).

D10 — A loop that pushes once per turn adds its count to the length.

for _ in lo..<hi { … xs.push(v) … }, with exactly one push on every path through the body and no other change to xs, leaves xs.len() larger by hi - lo where lo <= hi.

D11 — A length whose elements take space is below 2^60.

Added October 4, 2026 (#383).

let mut row = Vec[i64]()
for i in 0..<line.len() + 1 { row.push(i) }   // line.len() + 1 is proved

len() of a list, text, Bytes, map or set whose elements take at least one byte is a fact of the walk: below 2^60, the same on every target. It is read where the walk reads len(), as a callee’s promise is read (ADR-314 D3), and a tighter bound the program gives replaces it.

Why memory and not the language below. Rust promises an allocation of at most isize::MAX bytes, 2^63 - 1, the edge of an i64: that proves nothing about len() + 1. The machine promises more: no target this compiler builds for addresses more than 2^57 bytes (x86-64 with five-level paging; aarch64 2^52; wasm32 2^32). 2^60 leaves a factor of eight, and holds x.len() + 1, a.len() + b.len() and c.len() - w.len() - 1 inside an i64.

Why one number for every target. What a program means does not depend on the target (ADR-037 D1), and which checks it carries should not either: a bound per target would make wasm32 prove products that x86_64 checks. A target that addresses more than 2^60 bytes reopens this.

What it buys. With the bound, a product of two lengths still reaches 2^120 and stays checked; without it, nothing past a literal offset is proved, and those are about a quarter of the overflow checks the corpus keeps (docs/solver-workload.md §8.4).

D12 — A list whose elements take no space is bounded only by how it was built.

enum One { Only } takes no space, and neither does a tuple or a struct of such parts or an Array[T, 0]. A Vec[One] holds as many as resize(n, …) asks for in one step, without a byte of memory, so D11 is not true of it and is not read. Whether a type takes space is a structural walk, as whether it compares is (ADR-204 D1). Its length is what the walk already reads off how it was built (D1, D10): [] is 0, resize(n, …) is n, a push per counted turn adds the count, extend adds the other’s length; anything else leaves it unknown, and the check stays. A run-time limit on such a list was the other way: it would cost a check at every resize and extend of every list, to cover a list that takes no memory.

As built (#383, #444): the walk reads D11 as 0 <= len(x) <= 2^60 for every len() whose container’s elements take space, and D12’s structural walk answers *no for a type variable, a function, or a type nothing here declares. A proof states its goal inside ±2^62 where the type is wider: the solver counts in i64 and refuses on overflow, so term <= i64::MAX (negated, 2^63) was never decided, and no i64 or u64 operation had been proved. Over the repository’s .nika files, the checks left standing at aggressive went from 551 to 442 (docs/solver-workload.md §8.5).*

D13 — Every length is at most i64’s greatest value

The length of a list, text, Bytes, map or set, and the number of turns a for takes, is a fact 0 <= n <= 2^63 - 1 for every proof, whether or not its elements take space: len() hands back an i64 (Part I 2.2). D11’s tighter n < 2^60 stays where elements take space. So i < xs.len() proves i + 1, and a counter that grows by one a turn in a for over xs is below xs.len() before it grows (ADR-361 D13), for every element type.

Why. It is what the type says; leaving it out made the proof depend on the element type for a bound that does not.

D14 — A std sequence’s ledger entry may state its count

A ledger entry whose result is a Seq may carry ensures_count, facts over count (the number of items the sequence yields), self and the entry’s parameters, as ensures does over a result (ADR-314) and ensures_each over each item (ADR-375 D5). The walk reads them where the count becomes a length: the list a collect() written right after the producer binds, the value of .count(), and the turns of a for over it. They hold only where no write to self stands between the call and the use, as ADR-375 D5’s do.

std states, from Rust’s behaviour, which the lowering keeps:

Entry ensures_count
str::split, str::rsplit 1 <= count, count <= self.len() + 1
String::chars count <= self.len(), self.len() <= 4 * count
String::bytes count == self.len()

Others take the entry when a program needs it. splitn does not yet: what it yields for n <= 0 is not specified.

Why. The count is what the producer means, like find_all’s positions; an assert(parts.len() >= 1) would put a run-time check where none is needed, and is checked at every call. Rust leaves parts[0] checked. Rejected: an assert in the program; a special rule for split in the walk (a fact belongs to the ledger entry that states the producer’s other promises, so a package’s own sequences can state theirs the same way).

3. Consequences

This site is open source. Improve this page.