Finding holes in a design
A design can be wrong before a line of it is written. Each rule looks fine alone, and the hole is in how they meet. This chapter says what Elinvar looks for and what its answers mean. It needs no background.
Things, links, rules, and a promise
A design, as Elinvar sees it, has four parts.
- Things: people, items, groups, accounts. Sets of them.
- Links between things: who follows whom, who owns what. Relations.
- Rules: what must be true, and what a step is allowed to change.
- A promise: something that must hold whatever happens.
Take a sharing app with three rules.
- A reader shares an item with a follower.
- The reader can end the follow.
- Someone an item is shared with can leave a note on it.
The promise: nobody leaves a note on an item they can no longer open.
A hole
Share an item. End the follow. Leave a note.
Rule 3 forgot to ask whether the follow is still on. No rule is wrong by itself, and reading them one at a time will not find it. A list of steps that breaks a promise is a counterexample, and it is what Elinvar returns:
check NotesNeedAccess: FAILS in 3 steps, with 2 people and 1 item
start Person0 follows Person1. Item0 is owned by Person1.
step 1 share(Item0, Person0) shared gains Item0 -> Person0
step 2 unfollow(Person0, Person1) follows loses Person0 -> Person1
step 3 note(Item0, Person0) notes gains Item0 -> Person0
broken at step 3: Person0 notes Item0, but Item0.canOpen is {Person1}.
The sharing model runs in corpus/holes/sharing.als and crates/elinvar/tests/readme.rs, producing a shrunk story of the same shape (DESIGN.md section 9.6).
Why small cases are enough to be useful
Elinvar does not reason about every possible size. It tries every case up to a size you choose: every way three people and three items can be linked, every order six steps can happen in. That is a great many cases, and it tries all of them, not a sample.
It works because holes are rarely about size. The one above needs two people, one item, and three steps. A design that survives every case with up to three of everything has had most of its mistakes found.
What the two answers mean
A counterexample is certain. Elinvar checks each one against the rules as you wrote them before it shows it, by a separate and much simpler piece of code (DESIGN.md section 10).
“Holds” is weaker, and says so: no case up to this size breaks the promise. A larger case might. It is evidence, not proof.
There is a third answer worth knowing. If the rules contradict each other, no case satisfies them, so no case breaks the promise, and a careless tool says “holds”. Elinvar says the rules allow nothing (DESIGN.md section 7.6).
How it searches
Every question of the form “is this link present?” becomes a yes-or-no unknown: does Person0 follow Person1 at step 2? The rules and the broken promise become constraints on those unknowns. A solver for such constraints, a SAT solver, either finds values that satisfy all of them, which is a counterexample, or shows there are none (DESIGN.md section 7).
What it does not do
- It does not check code. It checks the design that was described.
- It does not prove a promise for every size or for unbounded traces (REQUIREMENTS.md section 6).