Contracts with a ladder of checks, an end-of-turn gate, retrospectives and shared lessons, time-to-delivery measurement, a library of 140 verification techniques and 20 recipes, personal data kept outside the clone, and releases with rollback. Standard library only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
3.0 KiB
id, title, answers, rung, section, languages, kinds, cost, detect, ran_here, verified
| id | title | answers | rung | section | languages | kinds | cost | detect | ran_here | verified |
|---|---|---|---|---|---|---|---|---|---|---|
| flux-refinement-types | Flux refinement types for Rust | Can my Rust signatures carry value constraints (positive, in range, indexes in bounds) that the compiler checks? | 1 | prove | rust | general | medium | command -v cargo-flux | no | docs |
Use when
- The properties are small value constraints on arguments and results: an index below a length, a non-zero divisor, a sum within a bound.
- You want checking close to type checking, with little proof effort, and mostly automatic inference of loop invariants.
Do not use when
- The property is relational or complex (sorted, permutation, money laws). Use
verus,lean4-proofsorkani. - You cannot use Flux's pinned nightly toolchain.
Set up
From the Flux book ("Installing and Running Flux"): the only way to use Flux is to build it from source. Requirements: rustup, liquid-fixpoint (nightly binaries on its GitHub releases) and z3 4.15 or later, both on PATH. Then either curl -fsSL https://raw.githubusercontent.com/flux-rs/flux/main/install.sh | bash, or:
git clone https://github.com/flux-rs/flux && cd flux
cargo xtask install # installs `flux` and `cargo-flux`, and the sysroot in ~/.flux/sysroot
The repository's rust-toolchain.toml pins the nightly. To use it in a Cargo package, add to Cargo.toml:
[package.metadata.flux]
enabled = true
[dependencies]
flux-rs = { git = "https://github.com/flux-rs/flux.git" }
Not installed here, so the example was not run.
Minimal example
use flux_rs::attrs::*;
#[spec(fn(x: i32{x > 0}) -> i32{v: v > x})]
fn bump(x: i32) -> i32 { x + 1 }
On a single file run with the standalone flux binary, write the attribute as #[flux::spec(...)] instead. Overflow of x + 1 is checked only if you switch on check-overflow in the [package.metadata.flux] section (default none; see the book's "Checking Overflows"); this example passes without it.
Run
cargo flux (a package), or flux --crate-type=lib path/to/file.rs (one file; it accepts the same flags as rustc).
Passing looks like: no errors reported. Failure: the book's example shows error[FLUX]: postcondition might not hold with the source location (a wrong body such as x - 1). The book does not state the exit status; the driver is a rustc wrapper and should exit non-zero on errors, but confirm with a deliberately wrong body.
As a contract check
{"id": "prove-bump-flux", "claim": "bump returns a value greater than its positive argument", "kind": "general", "rung": 1, "cmd": "cargo flux", "expect": {"exit": 0}, "timeout_s": 900, "tier": "deep"}
What a pass does not prove
- Only the refinements stated in signatures; unannotated code gets default (weak) types.
#[flux_rs::trusted](#[flux::trusted]on a single file) skips checking. - Annotations are written by you; a trivially true refinement verifies trivially.
- Not run here; commands and messages come from the Flux book. Check the check: change the body to
x - 1and confirmcargo fluxfails.