A Tour of Temporal Typing Code, Contracts & Types · 2/6
Code, Contracts & Types · Page 2 of 6

Conformance: Code Meets Spec

What happens when you give an action both an Action(predicate) and a Python body?

That declares a conformance obligation. In every reachable state, for every argument where Requires holds, the checker verifies that the step produced by running the Python body:

  • satisfies the Action predicate,
  • satisfies every Ensures clause (where result binds the return value),
  • changes only the variables permitted by Modifies, and
  • satisfies every assert it reaches.

If someone edits the implementation later and forgets the spec (or vice versa), the check fails immediately with the exact state and action where the two part ways.

Try it: Change self.available -= 1 to self.available -= 2 (or change return True to return False) and click Check to see a FAIL conformance report!
Click Check (or press Shift+Enter) to run the front-end and check this specification. Switch to TLA⁺ to view its TLA⁺ meaning.
---- MODULE Semaphore ----
EXTENDS Integers
CONSTANT capacity
VARIABLE available

ASSUME capacity > 0
Init == available = capacity
Acquire == available > 0 /\ available' = available - 1
Release == available < capacity /\ available' = available + 1
Next == Acquire \/ Release

\* Conformance checks body transition == Action /\ Ensures(result)
Bounded == 0 <= available /\ available <= capacity
====