The reference
Carried from docs/reference.md on 3 Oct 2026; the file is the source.
Reference
One section per feature. Each example is small enough to paste into the playground; the longer ones are in docs/examples/ and tests/*_ok.vish. The compiler knows a small core; the rest is a prelude written in the language.
1. A program
A program is declarations at the top level: rows, enums, events, functions, units, flows, invariants, derived fields, scenarios, routes, effects, and trust declarations for login tokens. It may span files and namespaces. The one thing every program has is at least one unit; the smallest useful one is a unit and a scenario.
2. Types
| type | meaning |
|---|---|
bool, int, int(lo, hi) | booleans; 64-bit signed ints with no declared range; the same 64-bit ints held to a range: a call that would store one outside it is refused (OutOfRange, §5) |
id | an opaque key; an int literal may be written where an id is expected; ids have no arithmetic (as_int, as_id convert) |
string(n) | UTF-8 text of at most n bytes, written "…" with escapes \", \n, \t, \\; a call that would store longer text is refused (OutOfRange, §5) |
enum Name { a, b } | a variant type; values are Name.a; variants order by declaration; read with match v { Name.a => x, Name.b => y } (every variant once, all of them or an else arm) |
money(s) | an amount in minor units with s decimals; adds with money of the same scale, scales by int, never mixes |
instant, duration | milliseconds; instant ± duration is an instant, instant − instant a duration, duration × int a duration |
option<T> | some(e) or none; read with match o { some x => a, none => b } |
Row | a declared row as a value |
Row[n] | a keyed table of rows by id, at most n for verification |
T[n], Row[n] ordered | a positional list of at most n elements |
map<K, V>, map<K, V>[n] | an ordered map; keys are int, id, string or enum; [n] is the map’s entry bound, which a map inside a row carries (§3) |
Literals of money, instant and duration are plain ints. [] and map() are empty literals typed by their context.
Every integer is a 64-bit signed integer, from -9223372036854775808 to 9223372036854775807: int, int(lo, hi), money, instant and duration alike. A range such as int(0, 100) does not make the integer smaller, and a result computed along the way may leave it; what a call stores, passes to a contract or answers is held to it (OutOfRange, §5), and the sampler draws inside it. A result outside the 64-bit range, whether from +, -, *, /, %, negation, abs, sum or a builtin built on them, is a defect, never a wrapped value, and so are dividing by zero, a remainder by zero, and the remainder of the smallest integer by -1 (whose result would fit). verify reports it as a failure with the state and arguments; at a door, development or generated, debug or release, the call answers 500 and writes nothing (tests/overflow_bad.vish, tests/door_overflow_ok.vish).
3. Rows
row Task { id: id, title: string(64), status: Status, created: instant, closed: option<instant>, tags: id[4], home: option<Address> }
row Line { sku: string(32), qty: int(1, 999), price: money(2) }
row Order { id: id, customer: id, lines: Line[50] ordered, labels: map<string(64), string(255)>[20] } // arrives whole; stored as two tables
row Tally { counts: map<string(64), int(0, 1000000)>[100] } // a view's result
A field may be a scalar, a string, an enum, an option of one, a list of scalars, another row, an optional row, a list of rows, or a map with an entry bound. Inside a row the rows are always a list, Line[50] ordered: a keyed table (Line[50] alone) lives only in a unit’s state and is refused in a row, a reply row included. A map inside a row says how many entries it may hold, map<K, V>[n], and takes scalars, strings or rows as values; a map with no bound is refused in a row. Rows nest, through lists and maps too, but never recurse. A row kept in a keyed table needs an id: id field.
The two shapes are for what a program passes, answers and receives: a reply row, a contract’s parameter and the value a flow carries between calls, a function’s or a view’s result, an event’s payload, a scenario’s value. A row a unit stores holds neither, at any depth, and a map a unit stores holds scalars, text or options of them as its values, never a row, a list or a map: the checker refuses the state field, names the field inside the stored row (or the map’s value type), and says how to model the data instead, a table keyed by id, each row with its parent’s id and, when order matters, a position. So an order arriving with its lines is stored as a table of lines and read back whole by a view, and no nested value reaches a store or a migration (docs/examples/09_order_lines.vish, docs/examples/10_tally.vish, docs/rows-nested.md). The verifier draws a list of rows or a bounded map in a row mostly small, 0, 1 or 2 entries, and at its bound one draw in four.
Row literals name every non-derived field: Task { id: 1, title: "a", … }; a field whose value is a variable of the same name may be written once, Shipment { id: shipment, order }. A list of rows is written as a list of row literals and a map as map(k => v, …); a map literal with more entries than the map’s bound is refused.
4. Units and state
unit Todo {
caps storage, outbox;
state tasks: Task[8];
state next: int = 1;
state prices: map<id, money(2)>;
fn open(t: Task) -> bool = t.status == Status.open;
invariant all(t in tasks: as_int(t.id) < next);
contract …
}
A unit owns its state and nothing else may touch it: only the unit’s contracts change it, which is the language’s visibility rule. state fields are tables, lists, maps or scalars with optional initial values; tables start empty. A stored map’s values are scalars, text or options of them (§3): a row, a list or a map as a map’s value is refused, with the same advice. A field with no initial value starts at its type’s default: false, 0, the empty text, none, an enum’s first variant; an int(lo, hi) whose range does not hold 0 starts at lo (int(-5, -1) at -5, int(5, 10) at 5), so no default lies outside its own type. A unit may hold functions that read its state, one invariant (combine with &&) that must hold after every contract call, fixtures, machines, derived fields and a commutes declaration. caps names capabilities: outbox allows emit, storage makes the state persist.
5. Contracts
contract withdraw(amount: money(2)) {
case amount <= 0 => fail BadAmount;
case amount > balance => fail Insufficient;
else => Ok: balance -= amount;
examples { { balance: 500 } (200) => Ok { balance: 300 }; { balance: 100 } (200) => Insufficient; }
}
contract bump() => Ok: n += 1; // one guardless case: no block
contract level(item: id) -> int { outcomes Level(n), fail Unknown; } // a stub: outcomes declared, no cases
contract read() -> int => Value(n);
Cases are tried in order; the first guard that holds decides; else is the catch-all. A case names an outcome, or fail Outcome, which changes nothing and aborts an atomic flow, or stop Outcome, a success that ends the flow at this call (its writes and the earlier steps’ commit; the later steps do not run; no value). A stub declares them the same way: outcomes Added, stop AlreadyDone, fail Exists;. An outcome’s kind is one for the whole program: a name is a success, a failure or a stop everywhere it appears, as fail has always been. A contract of a unit that declares caps ids may say uses ids; and call fresh() in its cases: each call is a new id above every id the caller knows (the whole world inside a flow, which must say uses ids; the unit alone in an example or a sampled check, where the ids are 1 + the largest present, in order), so a contract can create one row per element of a list (fold(w in winners, acc = []: append(acc, Sale { id: fresh(), … }))) and answer their ids, and the door passes no ids for rows it does not choose. A carried value is written inline, Found(expr), with the return type after -> (default int); the value is computed on the pre-state. Outcome names are yours; the same name means the same thing everywhere.
Deltas after : say what changes and nothing else changes. Right-hand sides read the pre-state.
| delta | meaning |
|---|---|
x := e, x += e, x -= e, x max= e, x min= e | scalars (int, money, duration for +=/-=) |
t += [row, …], t -= [k, …] | insert rows / remove keys (keyed); append / remove first occurrences (positional) |
t[k] := row, t[k].f := e, t[k].f += e (also -=, max=, min=), remove t[k] | one row of a keyed table |
t.f := e, t.f := for x where p => e | every row’s field, or only the rows where p holds |
t := for x where p => rowexpr | replace matching rows (ids unchanged) |
emit Event(args) | append to the unit’s outbox (needs caps outbox) |
A keyed table is never assigned whole (t := [...] is refused): rows enter with +=, leave with -= or remove, and change with t[k] := row, t[k].f := e, t.f := e or t := for x where p => row.
One write to a plain field. A case writes each plain field at most once, whatever the operators. A plain field is any state field that is not a list or a table: a number, money, a duration, a flag, an enum, text, an option, an id, an instant, a map or a row. n := 1, n += 2, fee += a, fee += b and n max= 9, n += 1 are refused at the second write. A case is one step, and two writes to one place in one step are ambiguous (does the second start from the old value or from the first’s result?) and usually mean a missing guard. One delta always says the same thing: fee += a + b, n := max(n, 9) + 1. The same holds for one field of one row: two single-row writes to one column are refused when the key is written the same way (t[k].f := 1, t[k].f += 2). Keys are compared after names are resolved, so a function, row or enum imported under two names counts as written the same way. When the keys are written differently (accounts[from].balance -= amount, accounts[to].balance += amount) the checker cannot know whether they are equal, and the verifier reports the clash when they are; guard it (case from == to => fail SameAccount;). A list may take several += and -= in one case, but not a := after another write to it. A whole-row write followed by a write to one of its fields (t[k] := row, t[k].f += 1), and a column write plus a single-row write (t.f := for x where x.id != k => false, t[k].f := true), stay allowed and combine in order.
Implicit outcomes come from the language, not from a case: Unknown for a missing key, Exists for an inserted key that is present, Full for a table past its bound (a verification size: neither door answers it), WrongStatus for a move a machine forbids, OutOfRange for a call that would leave a value outside its declared type. The first four are never guarded by hand. OutOfRange may be, when the program would rather answer a failure of its own (docs/examples/08_service.vish guards its token counter with fail Exhausted before it would pass 1000). They may appear in examples and scenarios. Their names are failures everywhere: a contract may declare fail Full, but a success or a stop named Full is refused, since a flow would count it as a failure and roll it back. Removing a key is never Unknown: remove t[k] and t -= [k] on a key that is not there change nothing, and the case succeeds; when absence should fail, guard it (case !(k in t) => fail NotFound;).
Ranges and text limits are kept. A call whose writes would leave a stored value outside its declared type answers OutOfRange and changes nothing: an int outside its int(lo, hi), or text longer than its string(n) in bytes, as a field, inside a row, an option, a list, a table or a map. So does a value a flow passes into a bounded parameter, judged before any case runs, and a carried value outside the contract’s declared result type. The case is judged on what it would commit (a field it writes twice, as it would end), after every other check that can end it, and the rule holds everywhere a contract runs: in verification, at the development door and in the generated service. Money, instants and durations declare no range, and a capacity is a size, not a range: a table or a list held directly in the state answers Full past it, in verification only, and a list inside a row is held to its capacity nowhere (docs/blind-spots.md). OutOfRange must be acknowledged: verify fails when an example, a sampled call, a walk or a scenario step meets it in a contract that has no example whose outcome is OutOfRange (such as { n: 3 } () => OutOfRange;), and the failure names the contract, the place and the value. A refusal nobody expected is a missing guard or a type too narrow; one the author expects is written down like any other outcome. A delta whose right-hand side is a literal is held to the field’s type by the checker (n := 5000 on int(0, 100) is refused). A derived value and a field a world equation writes have no contract to refuse them: verify reports one outside its type as a failure naming the derived value or the equation, and the value (tests/check_range.sh).
Case bindings compute a selection once: case any(n in numbers: ok(n)) => let n = best(x in numbers: ok(x) by (x.added)); Picked(n.id): numbers[n.id].used := true;.
Examples are {before} (args) => Outcome[(value)] [{after}]. A before-state lists the fields that differ from the initial values, so {} is the initial state; an after-state lists the fields that differ from the before-state, so {} after a success means nothing changed; a fixture name may stand for a state (Two (1, 5) => Ok Two with { … }). An example with no after-state means nothing changed, and the verifier enforces it. Failures never have after-states. An example’s states and arguments fit their types all the way down, or the checker refuses the program: an int inside its range, a string within its bound in bytes, a list or table within its capacity, and the same for each element, each key and value of a map, each field of a row literal and the value inside some(…). The same holds for an initial value, the arguments of a scenario step and of a function example, and a literal a flow passes to a contract.
ensures adds a check on the post-state: items := heap_pop(items) ensures perm(append(items, result), old(items)); with old(f), result, unchanged(), emitted([…]).
Contract-level ensures. ensures expr; as a line of the contract (a stub’s or a body’s) is checked after every successful case, with result the carried value (the property then applies to the cases that carry one), bare fields the post-state, old(f) the pre-state, unchanged() the whole unit. Several lines conjoin. An interface’s contract-level ensures survive the merge with a part, so the part’s cases are held to them whatever the writer wrote; a part may add its own. See docs/blind-spots.md.
Deltas apply in order on the old state’s values; a column delta (t.f := e, t.f += e) skips a row that an earlier delta of the same case removed.
Stubs. A contract with outcomes A, fail B, C(value); and no cases is an interface stub: it declares the outcome shapes so examples, scenarios and flows type-check, and a call reports “not implemented (interface stub)” until a part supplies the cases. A contract has either cases or outcomes, never both. vishy check --interface accepts a program only if every contract is a stub.
Parts. A unit may be declared twice across the inputs: the interface, with state, fixtures, invariant and stub contracts, and a part, unit Name { contract … { cases; examples { … } } }, holding only contract bodies. The compiler merges them: the part’s header must equal the stub’s (names, bounds, return type, uses); the merged contract has the part’s cases, the stub’s declared outcomes and the examples of both, and the checker requires the cases to produce every declared outcome with its fail and value shape and nothing undeclared (the implicit outcomes excepted). A part’s examples may name the interface’s fixtures. A part with state, a body for a contract the interface does not declare, or a second body for the same contract is refused. See docs/toolchain.md, “Parts and the writer stage”.
6. Expressions
Arithmetic + - * / %, comparisons, && || !, if c then a else b, let x = e in e, match (on an option: some x => a, none => b; on an enum: one arm per variant, or an else), row fields r.f, with(r, f, e), table access t[k] (guard with k in t), len, lookup(t, k), append, range(n), columns t.f with elementwise lifting (jobs.priority > 3 is a bool column), reductions count, all, any, sum, largest, smallest, min, max, abs, clamp, percent, round_to.
Quantifiers bind a variable: all(x in t: p), any, count, first, where(x in t: p) (the matching elements; where(…).id for their ids), best(x in t: p by (k1, k2)) (the match with the smallest key tuple; bools sort false first; ties by id), fold(x in t, acc = e0: body), repeat(n, s = x0: body). There are no list comprehensions and no loops in expressions.
Strings: concat, starts_with, ends_with, contains, substr(s, start, count) (in bytes, like len; a count that ends inside a character includes that character), byte_at(s, i) (the byte at position i as an int, -1 past the end; the one string read that allocates nothing), to_upper, to_lower, trim, find, split, join, replace, int_to_string, string_to_int. Maps: map(k => v, …), get (an option), get_or, put, remove_key, has_key, keys, values, len. Time: seconds, minutes, hours, days, bucket(t, d), as_duration, as_instant.
7. Functions and the computation layer
fn fee(amount: money(2), tier: Tier) -> money(2) = if tier == Tier.gold then percent(amount, 1) else percent(amount, 3);
examples fee { (10000, Tier.basic) => 300; (10000, Tier.gold) => 100; }
fn heap_push(xs: any[], v: any) -> any[] {
var h = append(xs, v);
var i = len(xs);
repeat len(xs) + 1 {
let p = (i - 1) / 2;
if i > 0 && h[p] < h[i] { h := swap_at(h, p, i); i := p; } else { break; }
}
h
}
A function is an expression, or a block of statements followed by its result: let and var locals (var toks: Token[64] ordered = []; names the type when the value alone does not, as an empty list or none), x := e on a var, statement if with else if chains, repeat n { … } with break. x := append(x, e) and x := concat(x, e) grow x in place in the compiled code; a loop that builds a list or a string is linear. Every loop is bounded, there is no while and no recursion, so every function is total. Top-level functions may carry examples, run by verify. Blocks are for functions only; contracts stay declarative. A function is always written in Vishy, so verify runs every function a program has. A Rust body (fn f(…) -> t impl { … }) is refused where its block starts, with a message that says what to write instead: the function in Vishy. A program holds no Rust; what cannot be computed in Vishy is an effect (§18), which a program declares and only a flow calls. An algorithm that needs while or recursion is a sealed function (below). The prelude (stdlib/prelude.vish) provides perm, submultiset, sorted, is_heap, index_of, take, drop, set_at, swap_at, remove_first, insert_sorted, heap_push, heap_pop and the time helpers, all written in the language.
Sealed functions: the general-computation layer
sealed row Node { v: int, kids: Node[] }
sealed fn total(n: Node) -> int = n.v + fold(k in n.kids, acc = 0: acc + total(k));
sealed fn count_to(n: int(0, 100)) -> int(0, 100) { var i = 0; while i < n { i := i + 1; } i }
sealed fn words(s: string) -> int = len(split(s, " "));
examples total { (Node { v: 1, kids: [Node { v: 2, kids: [] }] }) => 3; }
A core function is total: no recursion (direct or through other functions), loops bounded by repeat, every string and list bounded, no return (a block ends with its result expression). That is what makes contracts and rules checkable and lets the compiler know everything. General computation, a parser, a tree walk, anything that needs recursion, lives behind a declared boundary instead: a sealed fn may call itself and other functions, loop with while, leave early with return e;, take and return string and T[] without a bound, and use sealed rows, which may contain themselves (inside a sealed function or row, Node[] is a list of rows, not a keyed table). Sealed rows exist only inside sealed functions: no unit state, contract, flow, event, view or core row may hold one, and a sealed function called from the core must return a core type.
What the seal promises and what it does not: a sealed function is pure (no unit state, no events, no effects) and its result is trusted only to its declared type, so the boundary checks it (an int(0, 9) result of 10 is a failure naming the function). Totality is not promised: verify runs a sealed function’s examples, and every call to it from a contract or flow during a sampled check, under a step budget of VISHY_FUEL steps (default 10 million, spent per call and per loop iteration, the same on both verifier paths); a function that exhausts it, or recurses deeper than 100,000 calls, fails the example or the check it was reached from. Sealed functions are never sampled on their own: their examples are their test. A generated service runs them as written and under the same budget: 10 million steps unless VISHY_FUEL in the service’s environment says otherwise. A call that runs out of steps, or recurses deeper than 100,000 calls, stops its flow with an error: the request is answered 500 with the function’s name, and the flow writes nothing. Only that call fails: the next example, check or request starts with a full budget. Every engine (both verifiers, the development door and a generated service) runs sealed functions on a stack of 1 GiB, reserved and used only as far as the calls go, so 100,000 nested calls fit, and the limit, not a stack overflow, is what stops a deeper call. The same function written in Rust would have kept running; the budget is the price of a function the verifier can run.
8. Flows
flow place(qty: int) uses clock, ids atomic {
let order = fresh();
let total = Carts.total(order);
Orders.place(now, order, qty, total);
ensures Orders.count == old(Orders.count) + 1;
}
A flow is a sequence of contract calls and effect calls, and a transaction: atomic (the default) restores the whole world if any call fails; serial does not: the failed call ends the flow and the writes of the calls before it stay, and the served door answers the failure with those writes stored and their events delivered. A step written keep Unit.c(…); in an atomic flow commits what the flow has written so far: a later failure restores the world to right after that step, not to the start (the served door then answers the failure with the kept writes stored and their events delivered), so a refused attempt can be recorded before the refusal. After a failure that keeps writes, in a serial flow or after a kept step, the verifier computes the derived values and checks the world invariants on the world the flow left, and reports a violation on that flow; it does not check the flow’s ensures. A call that answers a stop outcome ends the flow there as a success; ensures is checked only when the flow runs to its end. Units never call each other; only flows compose them. A carried value can be bound with let and passed on. uses clock binds now; uses ids allows let x = fresh();, an id absent from every table. A flow’s outcome is its last call’s. ensures is checked after the flow commits, with Unit.field and old(Unit.field). A scenario or a route may call a contract directly, Counter.bump(), which is an implicit one-call atomic flow.
uses caller binds caller: id, the verified identity of the request: the served door takes it from the bearer token (401 without one) and never from the body, the command line from VISHY_CALLER, a scenario step from as N (as 7 remove_note(1) => NotOwner;), and the verifier samples it like any argument. A flow that does not use caller cannot name it; a body that passes an identity in is what uses caller replaces.
uses identity binds identity, what a verified login token says about the person (section 18, “Login tokens”). Its type is a row the language declares in every program that trusts an issuer, as if it were written
row Identity { subject: string(255), email: option<string(254)>, email_verified: bool, issuer: string(255) }
and a contract takes it like any row: flow visit() uses caller, identity atomic { Log.note(caller, identity); }. The door fills it from the token’s claims: subject from sub, issuer from iss, email when the token carries one of at most 254 bytes, and email_verified true only when the issuer says so. For a caller with a minted token the subject is the caller id as text, the email none and the issuer "". A flow may use caller, identity or both; a view uses caller only. uses identity needs a trust declaration, and in such a program a flow parameter may not hold an Identity (a request never supplies one; the same holds for a route or a scenario step that calls a contract directly) and the program may not declare its own Identity at the root. The verifier draws the identity from the sampled caller, so that one caller id is always one identity; over a run, each trusted issuer, a caller with a minted token, and an email that is absent, verified or unverified reach each flow that uses identity (sampling, not a proof). Who a user is, their roles and what a first sign-in does are the program’s own state: packages/users is the standard package for them, and docs/start.md uses it.
9. Views
A view is a read over the world, declared in the language so that who sees what is a rule the compiler holds:
view my_issues(project: id) uses caller
= where(i in Issues.issues: i.project == project && any(m in Members.members: m.user == caller && m.project == project));
view issue_count(project: id) = count(i in Issues.issues: i.project == project);
route GET "/projects/{project}/issues" => my_issues(project);
view name(params) [uses caller] = expr;. The expression is typed like a world invariant, with Unit.field in scope, the parameters, and caller when the view uses it; its type is inferred and may be a list of rows, a row, an option or a scalar (not a unit). A view never writes: there are no deltas, and a route to it must be GET. Scenarios assert on views with name(args) => Value(v), as N before a step setting the caller. The verifier evaluates every view on reachable worlds with sampled arguments and fails on a panic (an empty first, an absent key), counted among the sampled checks; it cannot judge whether the value is right beyond the scenarios and the examples. The door serves a view route from the stored world without a transaction, as {"ok": true, "value": v}, and pages a list with limit and offset query parameters ("total" and "offset" alongside); a view served by a route cannot name a parameter limit or offset. The clients get one method per view route with the value’s type. A view is interface-owned: writers never write one.
10. World invariants and derived state
invariant all(l in Stock.levels: l.reserved <= l.on_hand);
derived Ledger.cash = sum(Payments.payments.captured) - sum(Payments.payments.refunded);
derived Stock.levels.reserved = for l => sum(where(x in CartLines.lines: x.sku == l.sku).qty);
The unit declares the field a world equation writes as ordinary state with its type (state cash: money(2) = 0; in Ledger, reserved: int in Level); the equation supplies the value and the unit’s contracts never write it (the checker refuses Ledger.cash on the left of a delta).
A top-level invariant names units’ state and must hold after every flow; the verifier samples only worlds that satisfy it. A derived field is defined by an equation and maintained by the compiler after every call or flow, never assigned; inside a unit, derived total: int = sum(accts.bal);. A unit’s invariant may not mention a world-derived field of that unit; state such a rule at the top level.
11. Machines
machine orders.status { start Status.placed; Status.placed -> Status.paid; Status.paid -> Status.shipped; Status.placed -> Status.cancelled; Status.paid -> Status.cancelled; }
Declares the legal moves of a row field; a delta that moves it any other way fails with WrongStatus. Staying in place is a move too and needs its edge. One contract advance(k, to) replaces one per transition.
A range 1..3 -> 5 names several sources at once, and only for an int field (int(lo, hi)); an enum field’s states are its variants, each edge written on its own, and Status.placed..Status.paid -> … is refused with that rule.
12. Commutativity and fixtures
commutes { started, ended }; makes the verifier apply sampled pairs of those contracts in both orders from a sampled state and report when the orders disagree. fixture Two = { accts: [ … ] }; names a state for examples.
13. Scenarios
scenario checkout {
at 1000 submit(7, 42, Kind.check) => Queued(s);
at 1500 started(s) => Started;
status(s) => Status("running\n");
Cache.lookup(42) => Hit(s);
}
A sequence of flow or contract calls from the initial world with the outcome each must produce; at N sets the clock; as N sets the caller for a flow that uses caller (and, for a flow that uses identity, the identity of a caller with a minted token); as N identity "SUBJECT" ["EMAIL" [unverified]] [issuer "ISSUER"] gives the step a verified login identity instead, its email verified unless unverified follows it and its issuer the first trust declaration’s unless named (at 1000 as 7 identity "ada" "ada@example.com" sign_in() => Registered(1);), and a step without as keeps the identity of the step before; a bare name as the expected value binds the carried value for later steps, where it may stand as an argument (not inside an expected value); Outcome(_) accepts any value. vishy run prints the trace and exits with status 3 when a step is not as expected (0 when every step is); verify stops a scenario at its first wrong step and shows the world.
14. Namespaces and files
A program may be many files. A file’s namespace is namespace x; at its top, else the directory it was given in, else the root. Inside its namespace a declaration is bare; another namespace brings it in with use money::Fee;, use money::Fee as F; or use money::*; and then names it bare (or by its alias). The qualified form money::Fee appears in use lines, in the compiler’s messages and in one statement: deliver money::Paid to … names another namespace’s event without a use, since the root declares where a slice’s events go (§18); elsewhere in source a name is bare. Rows, enums, events, functions, units, flows and effects are what a namespace exports; state and contracts belong to their unit, so there is no pub. The prelude is visible everywhere. Names may not contain __. A unit may be split across files as an interface and a part (section 5).
15. Packages
A directory with package.vishy (name, version, optional namespace, dep x = path "…" or dep x = git "…" tag "…") is a package; dependencies resolve recursively, one version per name. vishy interface prints the public surface; vishy diff old new classifies a change as patch, minor or major and refuses a version that does not cover it.
16. Storage and capacity
caps storage; on a unit makes its state persist and changes nothing else. vishy schema prints the SQLite schema; vishy service writes the application’s folder, which the vishy program serves, running each flow as a transaction over SQLite or Turso. The bound in Row[8] is for verification; a rule about capacity says cap(rows), which is the bound when verifying and unbounded in a service.
What any store under a program’s state must guarantee about a flow, its events, fresh ids, migrations, tenants and views is docs/store.md, the contract every store is held to.
17. Migrations
A program with stored units declares version N;. When a row or a stored scalar changes between versions, the compiler carries the store forward, deriving what it can and requiring the rest to be written:
version 2;
row Customer { id: id, full_name: string(64), tier: Tier, greeted: int }
migrate Customer from 1 { full_name = old.name; }
examples { { id: 1, name: "Ada" } => { id: 1, full_name: "Ada", tier: Tier.basic, greeted: 0 }; }
Derived without a declaration: a field added with a default (false, 0, the empty string, none, an enum’s first variant; an int(lo, hi) whose range does not hold 0 starts at lo, as a new unit’s state does, §4), a widened bound, a new table, a new scalar state. Never derived: losing data. A removed field needs drop field; inside the migrate block, or an assignment that reads it (a rename), and the compiler says which when a field of the same type appeared alongside (when the two types differ only in their bounds, as int(1, 28) and int(1, 4), it says so, since a plain copy may not fit). Written as migrate Row from N { field = expr; … }: a rename, a recomputed field, a narrowed type; old is the row as version N declared it, typed against that declaration, so old.name is an error when version N had no name. migrate drop Unit; allows a vanished unit’s tables to be dropped. Inside a namespace (a namespace x; line, a directory, a package) a migration names its row as every other line there does: by its bare name, or by the name a use imports it as (use shelf::Loan as L; then migrate L from 1). migrate drop U; always names a unit of the namespace it is written in, because a dropped unit is declared nowhere any more; an import that makes another U visible does not change that. A row has one migrate block per version. Examples give an old row and the new row it must become. Each value is a literal of its field’s type and inside its bounds all the way down (an int’s range, a text’s length, a list’s size, an option’s value, a nested row’s fields): the old row’s fields as version N declared them, the new row’s as declared now. Enum values in either row are written with the enums as declared now. The examples run at check time. The verifier does not sample migrations.
vishy check new.vish --from=old.vish types the migrations and runs the examples. A program given as several inputs (directories, one namespace each) gives each old input its own --from=, as in vishy check new/shelf new/lend --from=old/shelf --from=old/lend; an old directory left out reads as if its units were new. vishy service new.vish out/ --from=old.vish emits a service whose migrate carries a store at version N forward exactly once and records the version (schema_versions); a service built without --from refuses a store at another version and says which program to build it from. A service older than its store (a later version already carried the store forward) leaves it alone: every command that opens the store (its flows, dump, serve, migrate, token, outbox and deliver) refuses, names both versions, and says to run the service of the store’s version or a later one. The service computes every rewritten row before it changes anything, and when a computed value is outside its field’s type (an int’s range, a text’s length, an option’s value) it refuses, names the row’s tenant, the field and the value, and leaves the store at version N as it was. The development door refuses such a reload the same way. Examples cannot prove a computed value fits every stored row (weeks = old.days from int(1, 28) into int(1, 4) checks with an example of 3 days), so this refusal is the last guard. Not covered, by design: tables Vishy did not create, migrations that need data from other tables or outside, batched zero-downtime backfills, and anything a per-row expression cannot say; those are written by hand as an effect or a script. A rewrite (a rename) rebuilds the whole table; on a very large table run it in a window.
18. Routes and effects
route POST "/submit" => submit(client, hash, kind);
route GET "/status/{submission}" => status(submission);
effect json_len(s: string(200)) -> int
fixtures { ("[1,2,3]") => 3; ("x") => -1; }
flow count(s: string(200)) atomic { let k = json_len(s); Counter.set(k); }
A route invokes exactly one flow; path parameters and JSON fields bind its parameters by name; the response is the outcome, 200 or 409; GET routes may only invoke query flows. A parameter that is a row, a map or a list of them takes the JSON of its field ({"e": {…}}), read as a web call’s reply is read (below): by field name, within every bound, other keys ignored. A request whose argument does not fit is answered 400 with the path of the place and the rule, never the value: {"error":"`e.items`: expected a list of at most 3 items","flow":"add"}.
Signed requests. Checking the signature a service puts on the requests it posts to the application is the door’s, not the language’s: a JSON configuration given to the door names the routes each sender guards, how it signs and where its key is; the door checks each request to such a route before any decoding, binds the verified body to the flow’s one row, and runs each delivery once. The flow and the route are ordinary. The chapter “Effects and deliveries” shows one; docs/senders.md specifies it.
Login tokens. People usually sign in at an identity provider, which gives them a login token (a signed JSON Web Token). A trust declaration names a provider whose tokens the door accepts:
trust jwt issuer "https://login.example" audience env "APP_AUDIENCE";
trust jwt issuer "https://accounts.example" audience "app-123" keys "https://accounts.example/keys.json" algorithms ES256;
The clauses come in any order, each at most once. issuer "…" is required: exactly what the provider’s tokens carry in iss, 1 to 255 bytes. audience "…" or audience env "NAME" is required: the application’s id at the provider, which a token’s aud must hold, so a token issued for another application is refused. keys "https://…" or keys env "NAME" is where the provider publishes its public keys (a JSON Web Key Set); without it the door reads the address from <issuer>/.well-known/openid-configuration, and the issuer must then be an https address. algorithms names RS256, ES256 or both (both when not stated); none and shared-secret algorithms such as HS256 are refused. Keys come over https, or plain http from this machine (localhost, 127.0.0.1, [::1]) for tests. A program may trust several providers, one declaration each, never one issuer twice. Nothing in the language is specific to a provider.
Before a flow or view that uses caller or identity runs, the door reads Authorization: Bearer <token>. A token the door minted (vishy serve --mint, the service’s token) is looked up in the store. A login token must name a trusted issuer, carry a signature that issuer’s key verifies, hold the audience, and not be expired or not yet valid (60 seconds of clock allowance); otherwise the request answers 401 with the reason, never echoing the token, and while an issuer’s keys could not be fetched its tokens answer 503. Each verified (issuer, subject) pair gets a caller id of its own, kept in the store per tenant and the same on every sign-in, so uses caller keeps meaning an id; it is never an id a minted token or the service’s command line (VISHY_CALLER) has acted for, in any program, before or after it trusted an issuer, and those refuse an id a signed-in identity holds. A minted token is 128 random bits. The door reads every variable a trust declaration names when it starts, and refuses to start while one is missing or empty. docs/identity.md specifies every check and every reason; docs/deploy.md, “Sign-in”, covers keys and the identities table in production.
An effect is the declaration of something done outside the program: a name, parameters, a result type and, optionally, fixtures. It is called only from a flow, as a step of its own (let r = e(…);, then r passed to a contract); a call anywhere else, a contract, a function, a view or an argument of a contract call, is refused with that rule. In verification it returns a fixture’s value or a sampled one. What performs an effect is not in the program, and a program holds no Rust (since 4 Oct 2026): a function cannot have a Rust body (§7), an effect cannot either (impl { … } after its signature is refused, at the block), and a program names no crate (a line rust name = "version"; is refused, at the word rust). Each refusal says what to do instead. A call to a web API is an http effect (below), which needs no Rust. Pure computation is a sealed fn (§7), which the verifier runs instead of assuming: json_len above could be one. Anything else is Rust the service’s owner writes outside the program. vishy service puts one function per declared effect in the project’s src/effects.rs; until the owner writes its body the function fails the call with a sentence naming the effect (a request answers 500 and nothing is written; no value is made up). The owner adds the crates the body uses below the marker line of the project’s Cargo.toml, and generating the service again keeps the file and those lines (docs/toolchain.md). vishy serve, the development door, answers an effect as verification does, with a fixture’s value or a sampled one. The language has no I/O of its own: effects are facts a flow emits and a runtime performs.
HTTP effects. A call to a web API is declared, not written: the method, the path, where the call goes, how it proves who it is, what it sends, and the row the answer must fit. The compiler generates the request, the call and the reading of the answer. This is a general feature: any program may call any web API this way, and nothing in the language is about one service.
enum WebError { none, timeout, transport, status, decode }
row Book { title: string(120), pages: option<int(1, 5000)> }
row BookReply { ok: bool, status: int(0, 599), error: WebError, body: option<Book> }
http effect find_book(isbn: string(13)) -> BookReply
GET "/isbn/{isbn}" base env "CATALOG_URL" timeout 3000 ms
fixtures { ("0000000000000") => BookReply { ok: false, status: 404, error: WebError.status, body: none }; };
flow shelve(id: id, isbn: string(13)) atomic { let r = find_book(isbn); Shelf.add(id, isbn, r); }
http effect name(params) -> Reply METHOD "/path" clauses;. The method is GET, POST, PUT, PATCH or DELETE; a {p} in the path names a parameter. The clauses follow the path in any order, each at most once: base "https://…" or base env "NAME" (required); auth bearer env "NAME", auth basic env "USER" [env "PASSWORD"] or auth header "Header-Name" env "NAME"; query a, b; body json p or body form p; timeout N ms (1 to 60000, 10000 when not stated); fixtures { (args) => reply; … }. Every parameter is sent exactly once: in the path (an int, an id, a string or an enum, as one percent-encoded segment; a value that is empty, . or .. would name another path, so no request is made and the reply is transport), in the query (a scalar, a string or an option of one; none is left out) or as the body (a row, sent as a JSON object or as a form with outer[inner] and list[0] keys); GET and DELETE send no body. Every call sends Accept: application/json.
The reply is a declared row with the fields ok: bool, status: int(0, 599), error: E, body: option<R> in this order, and optionally problem: option<P> last, where E is an enum with the variants none, timeout, transport, status, decode in this order and R and P are rows whose strings, lists and maps all have bounds (a page of results is items: Payment[100] ordered, a list of rows; a keyed table is refused in a reply row). Every way a call can end is a value of that row, never an exception: a 2xx answer that decodes into R is ok with the body; a 2xx answer that does not decode has error decode; any other final status, a redirect included, has error status, and a problem when the answer decodes into P (no redirect is followed: it would carry a named auth header and the Idempotency-Key to whatever host it names); no complete answer within the timeout (the name lookup included) is timeout, and no answer at all (a refused connection, a failed name lookup) is transport, both with status 0. Decoding never cuts or guesses: the answer is read up to 1 MiB and fills a row by field name, extra keys ignored; a missing key or null is none for an option field and a decode failure otherwise; a string longer than its bound, an int outside its range, or a number with a fraction or an exponent where an int is declared fails the decode; a list T[n] takes an array of at most n items (a list of rows an array of objects) and a map map<K, V>[n] an object of at most n pairs, and a reply past either bound fails the decode too; an enum takes a variant’s name, and any other name becomes other when the enum has that variant.
A flow calls an http effect like an effect, binds the reply, and passes it to a later contract call: a flow cannot branch, so a contract decides what the reply means. The checker refuses a reply that is not bound or that no later contract call receives, keep on the web call (it goes on the contract call that records the reply), and a call from a contract, a function or a view. The call runs inside the flow’s transaction, in the order the flow lists it, with its timeout, which bounds the whole call, from the name lookup through the TLS handshake to the last byte of the answer; the store’s transaction stays open while it waits, which is why the timeout is short by default. A 1xx status is not a final reply: the call answers transport, with status 0, as soon as the 1xx arrives, even when a final answer follows it, because the HTTP library the door and the service use reads a 1xx as the answer and cannot read past it. So a provider that sends 100 Continue, 102 Processing or 103 Early Hints before its answer gets transport on every such call, and the contract that takes the reply must treat it as a call that may or may not have done its work (docs/http-effect.md). A call made by a flow that then fails is not undone (docs/blind-spots.md): POST, PUT, PATCH and DELETE send an Idempotency-Key header, vishy- and 32 hex digits computed from the tenant, the flow, the call’s step in the flow, the caller, the flow’s arguments, and the Idempotency-Key of the request that started the flow when it carried one, so a retried request asks the other service for the same thing again; a request whose own Idempotency-Key holds a byte outside printable ASCII (32 to 126) is refused with 400 before the flow runs. The same arguments therefore mean the same key: two separate requests that start the same flow with the same arguments, from the same caller, without their own Idempotency-Key, send the same key, and a service that honors keys answers the second with the first one’s result while the flow commits a second time; when the same arguments can mean a new call, the request must send its own key. keep (section 8) keeps a step that records the reply when a later step fails. The values read from the environment never appear in a reply, a log line or the generated code; vishy serve and the generated service refuse to start when one is missing or empty, naming the variable.
In verification no call is made: a call whose arguments equal a fixture’s gets the fixture’s reply, every time, in every walk and flow check, so a flow whose web calls all match fixtures never sees another kind; any other call gets a sampled reply of one of the five kinds, each equally likely, its fields consistent with the kind (a sampled body for a success, a status from 300 to 599 for an error status, 0 for a timeout or a transport failure). Each flow call of a walk draws its reply afresh, so a reply a contract refuses does not hide the other kinds from the flows whose calls match no fixture; this is sampling, so a short run can still miss a kind. A contract that takes a reply is also sampled on its own with any value of the reply row, against its unit’s invariant. A program with an http effect has verify end its line with ; web replies: N sampled (a success, b timeout, c transport, d error status, e decode), f from fixtures, and with , r over 1 MiB drawn again small after that when a sampled body or problem was over the 1 MiB a door reads and so drawn again with its lists of rows and maps small (§3). vishy serve and the generated service make the real call, with the same encoding, decoding, key and timeout. The whole specification, with every refusal, is docs/http-effect.md.
Deliveries. deliver Event to webhook "https://…";, deliver Event to webhook env "NAME";, deliver Event to mail "ops@example.com";, deliver Event to effect name; say where an emitted event goes. An event declared in a slice is delivered from inside the slice by its bare name and from the root by its qualified name, deliver slice::Event to … (§14). A trailing only, deliver Coded to mail "…" only;, delivers the event only: both doors keep it out of their answer and the generated default effects.rs out of its echo, while the outbox, verification, ensures emitted([…]), scenarios and vishy run see it as any event; every delivery of an event says only, or none (a mix is refused). The door answers every other event to the requester, so a value meant for one recipient, a one-time code, goes by a web call or by an event delivered only. A program declares the destinations; the service does the delivery: one outbox row per (event, delivery) written in the same store transaction as the flow’s state change, so an event is never lost and never recorded without its cause; a drainer posts each row as JSON with an Idempotency-Key (<tenant>-<row id>, stable across retries so the receiver can deduplicate), marks it delivered on a 2xx, and otherwise retries with exponential backoff (1 s, 2 s, 4 s, … levelling off at about four minutes, at most 20 attempts). Delivery is at least once. A webhook target is a URL or the name of an environment variable holding one; a mail target is an address, delivered by posting {to, subject, event} to the endpoint in VISHY_MAIL_HOOK; an effect target is a declared effect (body: string(n)) -> bool, called by the drainer with the event as JSON, delivered when it returns true, retried when it returns false or panics. The effect is how any crate becomes a destination: a broker client, a queue, a mail library, with the Rust in the service’s src/effects.rs and the choice of destination one line of Vishy:
effect publish(body: string(4000)) -> bool fixtures { ("") => false; }
deliver OrderPlaced to effect publish;
The verifier does not deliver anything; scenarios and ensures emitted([…]) are what check that the right events are emitted.
19. Verification
verify runs every example, every scenario, sampled checks of every contract against its unit’s invariant and ensures from random and reachable states, reachable walks of the flows checking atomicity, flow ensures, world invariants and capacities, and commutativity pairs. It reports each failure with the state and arguments that caused it. After the checks it requires reachability: every outcome a contract’s cases can produce, the five implicit ones excepted, must have been produced by an example or a sampled call, else the case is unreachable or unverified and verify fails. It is bounded random testing, not proof; see Limits and measurements and, for what it cannot see, docs/blind-spots.md.
Verification is partitioned by what a flow can change. A flow’s closure is the units it calls plus every unit a world-derived column carries a change into. After the flow, the verifier re-checks only the world invariants that mention a unit in that closure and recomputes only the derived columns that write one; the others cannot have changed, so their values stand. A flow’s reachable walk draws only from the flows of its component of the unit graph (vishy graph prints the components and, per flow, what its verification touches). Both verifier paths partition the same way and report the same failure, including the invariant’s number in source order.
20. Reserved names
old, out, result, self, staged, outbox, sealed, while, anything starting with __, Rust keywords, and the emitted runtime’s type names. A row’s field is the exception for Rust keywords: it may be named type, ref, async and the like, which the compiler writes as raw identifiers (r#type); crate, super, self, Self and the runtime’s type names stay refused there too.