Repository navigation
feat: let specifications call recursive spec functions (stage 11d) - #102
Merged
Merged
Conversation
Stage 11d (#83) adds spec functions: callable only from specifications, recursive with decreases, defined for every input and absent from the generated TypeScript. These cases fix the expected outcomes before the compiler code: proofs through a recursive spec function, planted faults in a caller, in a spec function's index and in its measure, a requires that needs one unfolding, and the declarations to reject. Refs #83
Specifications need recursive definitions the solvers can unfold: the semver port states its comparator's contract through a first-difference function (syntax decision 11, #83). A spec fn is called only from specifications, has mathematical integers, no contract of its own, and obligations that hold for every input. It is encoded as the 2026-11-13 measurement settled: a fuel-limited uninterpreted function with unfolding and fuel-irrelevance axioms written once per list a script names, never quantified over a sequence, since cvc5 1.4.2 recurses without bound on such a quantifier (cvc5/cvc5#13161); and a call-site reveal for each recursive call a requires makes. A spec function's own obligations don't assume its definition, so an inconsistent one can't prove itself. The interpreter runs spec functions inside contracts so models still replay, and a caller's identity covers the bodies of the spec functions its contracts reach. Refs #83
Two cases passed an i32 to an i64 parameter, which the checker rejects before any obligation. The planted fault in find's contract stays undecided: neither solver finds a model of the fuel axioms, as the measurement's part B predicted, so it waits for refutation by a replayed input (11e); its example still catches it. A refused build is a diagnostic, not a case without out/, so that case moves to the build refusal test. Refs #83
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The semver port (11h) states its comparator's contract through a recursive definition, the first index where two lists differ, and until now a specification couldn't call any function. Slice 11d of stage 11 (#83) adds
spec fn, per syntax decision 11 and decisions 1 and 2 of the 2026-11-13 second set. The conformance cases come in their own commit, before the compiler code; a second commit corrects three of them that running showed wrong.Where to start reading:
crates/accord/src/obligation/specs.rs(the encoding), thencheck/calls.rsandcheck.rs(the rules).What it adds
spec fn name(params) -> Type body: called only fromrequires,ensures,decreasesand other spec functions' bodies; never from code, never in an example, never written as TypeScript. Its integers are mathematical, so its arithmetic carries no range obligation.requires,ensuresoropen when. Its own obligations (index in range, and termination at each call to itself) assume nothing of its parameters.docs/design/measurements/2026-11-13-semver-contract/(B2, ground + reveal):f.fuel, reached through adefine-funthat gives it one unit of fuel, with its body asf.unfold;ground_specs, which runs besidelimit_lengthsin the solver);requiresmakes outside any quantifier also gets one ground step of its unfolding;f.unfoldfor it, so its calls to itself are uninterpreted: an inconsistent definition, such asf(n) = f(n) + 1, can't prove its own termination.broken,meets,covered,admitted) now takes the program's functions.(spec).Decisions taken within the slice
define-fun, exact, with no fuel.pub spec fn; a spec function returning a type that holds a list; a call to itself that changes a parameter holding a list (the solvers unfold only at lists the obligation names; the measurement's "a spec function whose recursion changes a sequence argument gets no axiom"); a call to a spec function from a machine's clauses;accord buildof arequiresthat calls one (the TypeScript boundary would have to run it).accord diffreports a contract that calls a spec function as undecided: each revision's spec functions are normalized apart, so one name could stand for two definitions.Verification
On Windows with the pinned Z3 5.3.3 and cvc5 1.4.2:
cargo fmt --all --check: passed.cargo clippy --workspace --all-targets --locked -- -D warnings: passed.cargo test --workspace --locked: 118 passed, 0 failed, 1 ignored (already ignored on main).score.py --self-testandmaterials.py target/debug/accord: passed; review hashes unchanged.find(undecided, its example fails; below). 12 rejections, each confirmed by hand to fail for the reason it states.conformance/typescript/spec-fnmatches byte for byte; its expected module was written before the code, from the same program without the spec function, which the generator already wrote.spec fnand afnwith one body differ;accord buildrefuses arequiresthat calls a spec function. The differential test confirmed that refusal is needed: a module written past it threw aReferenceError.full-ci).Not established
spec-fn-recursive-fault, Z3 and cvc5 both answerunknownwithin 10 s on theensures(no model satisfies the quantified axioms), as the measurement's part B found; the case expectsundecidedand its failing example catches the fault. Refutation by a replayed input is 11e.scripts/check-*.shintegrations weren't run; no existing program usesspec fn.Risk note
Two-way door: a language addition behind conformance cases; the receipt schema doesn't change. Contract evaluation now takes the program's functions, an internal signature. Blast radius: programs without
spec fnwrite the same scripts (nof.unfold, soground_specsreturns them unchanged) and keep their outcomes, identities and TypeScript; the full suite shows no change to them. Evidence: the checks above.Refs #83
Atrium: 01a1e409-d7af-75da-ba16-29e2cf249547