Transitions

A transition is an atomic state change: a guard that enables it and an effect that runs when it fires.

SPL
transition name(param1 : Type1, param2 : Type2) {
    guard:    <expression> ;
    modifies: x, y ;            // optional
    effect:   <statement> ;
              <statement> ;     // as many as needed
}

Effect statements#

Assignment#

SPL
x := x + 1 ;              // simple variable
arr[i] := val ;           // indexed
node.state := ACTIVE ;    // field
Node(id).state := IDLE ;  // field of a parameterised agent instance
Memory(addr) := b ;       // call form: same as Memory[addr]

Compound assignment#

SPL
counter += 1 ;            // counter := counter + 1
balance -= amount ;       // balance := balance - amount

Skip#

SPL
skip ;

Let binding#

let names a value for the following statements of the effect; it does not change the state.

SPL
let result = dst - src ;
dst := result ;

Conditional#

SPL
if (x > 0) then {
    y := 1 ;
    z := 2 ;
} else {
    y := 0 ;
} ;

The condition needs parentheses; each branch is a braced list of statements. The else branch is optional. There is no else if: nest a second if inside the else block.

Bounded loops#

SPL
for (j : Int) in [0..n) {
    Cache(j).state := INVALID ;
} ;

for 4 times {
    counter += 1 ;
} ;

for (j : T) in [lo..hi) { … } runs the body for j from lo up to but excluding hi. for e times { … } runs it e times.

Atomic block#

SPL
atomic {
    lock := 1 ;
    owner := id ;
} ;

Braced statement lists#

The bodies of if, for, for … times and atomic are braced lists: one or more statements separated by ;, with an optional ; after the last one. An empty block { } and a doubled ;; are errors.

Nondeterministic assignment: havoc#

SPL
havoc(x) ;                          // x gets any value
havoc(x) with { x >= 0 && x < 10 } ;  // any value satisfying the constraint
havoc(arr[i]) ;                     // any assignable target
havoc(X1, X2, Memory) ;             // several targets
havoc(X1..X3) ;                     // a range: X1, X2, X3
havoc(NZCV) ;                       // the flags N, Z, C and V
havoc(caller_saved) ;               // a regset
Effects are statement lists
An effect may hold any number of statements. Each statement ends in ;, including the last one and the closing ; after an if, for or atomic block.

Examples#

SPL
type NodeState = { IDLE, VALIDATING } ;
type LineState = { INVALID, SHARED } ;

transition selectValidator(slot : Int) {
    guard:  exists (i : Int) in [0..numNodes) . nodeState[i] == IDLE ;
    effect: nodeState[slot] := VALIDATING ;
}

transition cpuReadMiss(core : Int) {
    guard:    lineState[core] == INVALID ;
    modifies: lineState ;
    effect:   lineState[core] := SHARED ;
}

transition transfer(from : Int, to : Int, amount : Int) {
    guard:    balances[from] >= amount && amount > 0 ;
    modifies: balances ;
    effect:   balances[from] -= amount ;
              balances[to] += amount ;
}

transition sub_op(dst : BV<64>, src : BV<64>) {
    guard:  true ;
    effect: let result = dst - src ;
            dst := result ;
            if (result == 0x0:BV<64>) then { ZF := 0x1:BV<1> ; } else { ZF := 0x0:BV<1> ; } ;
}
↑ ↓ to moveEnter to openEsc to close