Alpha. Vary is under active development and not ready for production use. Syntax, APIs, performance, and behaviour may change between releases.

Supported language features

Values and types

TypeWhat is supportedNotes
IntArithmetic, comparisons, // and % with JVM rulesModelled as an unbounded integer, with an overflow check on each operation. See Solvers for the exact 64-bit model
BoolAll operators
StrLiterals, len, ==, !=, +With Z3 or cvc5 also indexing, slices, startswith, endswith, strip, lower, upper, contains, find, replace. split and join are opaque, with length facts
FloatPassing a value through unchangedArithmetic needs --solver z3 or --solver cvc5, where it follows IEEE 754, including NaN. On the bundled solver it is reported unsupported with a hint
Decimaladd, subtract, multiply, negate, abs, comparisons, sign tests, from_int, parse of a literal, and round, quantize, divide with a literal scaleModelled by its exact value. The scale it carries is not modelled. A product of two unknown decimals can need Z3
T?Int?, Bool?, objects, data valuesNarrowing by is not None, != None, and, or, not and an early return, and !! on None, are checked
EnumsParameters, locals, return values, match on a variableA wrong claim is refuted with a named variant such as Color.Green. Variants can carry any modelled value
data typesFields of any modelled typeCompared by field
ClassesFields, nested objects, optional fields, aliasing, invariants, modifiesHeld in a heap model, never as plain values, because they are mutable and compared by reference
TuplesReturned from a function, read by a constant index, unpacked with let (a, b) = ..., compared with ==Cannot be stored in a list or a field, or used in arithmetic

Collections

TypeWhat is supported
List[T]Elements of Int, Bool, Str, data or enum. Lists of lists to any depth. len, indexing (an out-of-range index is a checked obligation), slices (also of lists of lists), + (a literal or another list), in, not in, ==, !=, xs != None, sum, map, filter and sorted with lambdas, and [f(x) for x in xs if c] over a range or a list of Int or Bool. is_permutation(a, b) from collections says two List[Int] hold the same values the same number of times
Changing a listxs[i] = v, append and pop, on a list nothing else can see: a let or mut list made in the function, or the only list parameter of a function (which then belongs in modifies). A call to such a function gives the caller's own list a new value that satisfies the callee's out and post. See Advanced proof techniques
Dict[K, V]Int or Str keys. Values that are scalars, Str, classes, lists or data. d[k] (the key must be present, which is checked), k in d, k not in d, len(d), d.get(k), d.keys()
Set[T]in, add, remove, len, union, intersection, difference, and {e for x in xs if c} over a range or a list of Int, so len({...}) works in a contract
forall and existsOver a range or directly over a list. The body can call a predicate or nest another quantifier

sum is exact: its total is described by a running-total recurrence, so a contract about it holds for lists of any length when a loop invariant states the running total. The total must fit in 64 bits, which is a checked obligation.

Control flow and errors

ConstructBehaviour
if, elif, else, while, forSupported. Loops need an invariant to prove anything about what they compute
RecursionCalls are checked against the function contract. A decreases measure proves termination; without one, the result promise can still be proven while termination remains unknown
break, continueSupported
matchChecked for every variant
Result[T, E]Ok, Err, is_ok, is_err, unwrap, unwrap_err, unwrap_or and the ? operator. Each ? is a possible early return, and the out clause is checked on every one
raiseEnds its path. out and post describe normal returns, so they are not checked on it. Class invariants and the frame still are
assertAlways checked
tryA raise in the body continues into the handlers; a call that may raise also enters them from before the try; finally runs on every path
spawn, task_groupChecked task by task against the contract of the spawned function of the program; two tasks that may write the same field are refuted as "concurrent writes"; a task_group with a timeout may end by TimeoutError. Nothing is claimed about every schedule
ChannelsOpaque. Treated as calls the prover can't enter

Proof constructs

ConstructWhat it does
in, out, post, old(...)State preconditions and result or state promises. Calls use the callee's contract; old(...) refers to state at function entry
invariant, decreasesEstablish loop facts and termination. The prover can infer common decreases clauses, but checks them like written clauses
Class invariant, modifiesCheck object state and limit which fields a method may change. Missing modifies clauses can be inferred and reported
lemma, ghost let, ghost mutSupply facts and proof-only state. They are checked and erased from compiled code
Quantifier triggersGuide the solver when a forall proof is slow or undecided

See Advanced proof techniques for examples and limits.

Calls and code the prover can't see

CaseWhat happens
A call to a function with a contractChecked against the contract, never the body
A call to a built-in with an extern def contract (ord)The contract's in is checked at the call and its out is assumed of the result. Every such contract is run against the runtime by a test
A call to a function with no body and no contractReturns an unknown value of its declared type. Anything it could change (an object, list or dict passed in) is forgotten afterwards, unless the function is pure. Reported as opaque:NAME
A type with no model (Path, Json, Instant, keys)An opaque value. It can be stored, passed, returned and compared with ==, nothing else
A construct the prover can't followOnly the obligations on its path are unsupported. The function's other obligations are still proven

To close a boundary, give the callee an out clause, or make it pure if it changes nothing. A proof that relied on an opaque call lists it under assumes in the JSON report, so you can see what was taken on trust.

Contracts for runtime functions

A few standard library functions have no Vary body: they are implemented by the runtime. So the prover has something to reason with, the standard library states their contract with an extern def. It declares nothing callable and generates no code. It only says what a call accepts and promises.

pure extern def chr(code: Int) -> Str {
    out (r) {
        len(r) == 1
    }
}

extern def Json.stringify(self) -> Str {
    out (r) {
        len(r) >= 2
    }
}

The Class.method form gives the contract of a method on a runtime class. pure says the call changes nothing, so the prover keeps what it knew about the arguments across the call. Without pure, anything passed in is forgotten afterwards. At a call, the in clause is checked and the out clause is assumed of the result. A test runs every such contract against the real runtime, so an axiom the runtime breaks fails the build. extern def is for the standard library only; in your own code, give the function a body and a contract.

Interfaces

A class that implements an interface must honour the interface's contracts: accept everything the interface method accepts, and promise nothing weaker. vary prove checks this for every method that appears in both, and reports it under the method name joined to the interface name with an at sign.

How enums, options and data are solved

Enums, Result, Int?, Bool?, optional objects and plain data types are decided with the solver's own datatype sort on the bundled solver, Z3 and cvc5. Lists, dicts and optionals of these values are arrays of that datatype. This is why a claim about an enum variant or an optional field usually gets a definite answer rather than unknown.