Chapter
11
Refinement is implication
Part IV · Abstraction
Lessons
About
Your key-value store takes three messages to do a write: a put to the primary, a sync to the backup, an ack to the client. Your product manager describes it in one line: "a write replaces a key's value". Is the three-message protocol the same thing as that line? Not similar, not inspired by: the same thing, in every behavior the model allows, including the ones with crashes in awkward places. And in one direction: every behavior of the design is a behavior of the intent, not the other way round.
This chapter turns "the same thing" into a check TLC can run. You write the one-line intent as a spec, read the abstract state off the design with a mapping, and check that the design's spec implies the intent's. Chapter 08's alternating bit protocol finally gets the intent it was built for.
Before you start
- Chapter 04 (stuttering and the shadow), chapter 08 (the alternating bit protocol) and chapter 10 (fairness).
- A working
./tla doctor(seeSTART.md). - Time: the chapter page shows the estimate, generated from the lessons.
What else is here
specs/:AtomicKV,ReplicatedKV,ReliableChannel,AlternatingBit,TaskBoard, and the refinement checks the lessons run, broken ones included.review/(11-review): a teammate adds primary failover and checks everything except the refinement.ai/1-wrong-variable/(11-ai1) andai/2-all-stutter/(11-ai2): two AI-written mappings to judge.gate/(11-gate): a write-back cache that must implement an atomic register, graded through your mapping.gate/twin/(11-gate-twin): a two-phase file save that must implement an atomic file.
Run it
From the repository root:
./tla check 11-02
./tla check 11-review
./tla check --gate 11Skills
abstraction (choosing the abstraction), intent (stating intent as properties).
Elsewhere
- Web version: https://indicogni.com/learn/tla-plus/11-refinement/
- Recaps:
CONCEPTS.md. Hints and explanation checks:HINTS.md. Predictions without answers:PREDICT.md. - Solutions:
solutions/chapters/11-refinement/, including the gate references and their mutants. - Further reading: the "Read more" lines in
CONCEPTS.md.
Beyond the lessons
- 11-review Review a teammate’s spec ·
chapters/11-refinement/review/·./tla check 11-review - 11-ai1 AI item ·
chapters/11-refinement/ai/1-wrong-variable/·./tla check 11-ai1 - 11-ai2 AI item ·
chapters/11-refinement/ai/2-all-stutter/·./tla check 11-ai2 - 11-gate Gate ·
./tla check --gate 11Hints
Hint 1
Write the actions from the requirement first, one sentence per action, and get your own cfg to pass. Then write
Safetywith one conjunct per sentence from the hardware team.Hint 2
For the mapping, ask: if the processor read the register right now, which value would a correct cache give it? It depends on whether the line holds a store that memory has not seen.
Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyis overvalid,dirty,lineandmem. For each sentence, describe the bad state it rules out, the moment right after it went wrong, and writeSafetyso that state is excluded.Refsubstitutes forregone expression overdirty,lineandmem: ask which of the two copies the processor's latest store is in. If the refinement step fails, runMCCachedRegister.cfgand read its trace. - 11-gate-twin Gate twin, another domain ·
./tla check --gate 11 --twinHints
Hint 1
Write the actions from the requirement first, one sentence per action, and get your own cfg to pass. Then write
Safetywith one conjunct per sentence from the editor's team.Hint 2
For the mapping, ask: if the user opened the file right now, after a crash and recovery that replays a committed journal, which contents would they see?
Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyis overpresent,committed,journalanddisk. For each sentence, describe the bad state it rules out, the moment right after it went wrong, and writeSafetyso that state is excluded.Refsubstitutes forfileone expression overcommitted,journalanddisk: ask which of the two copies the latest save is in. If the refinement step fails, runMCFileSave.cfgand read its trace.