wiki:ContractReduction

Version 23 (modified by zmanchun, 11 years ago) ( diff )

--

Contract Reduction Language

$memory type

The new built-in type $memory denotes a set of memory units. The following expressions have type $memory:

  • a left-hand-side expression, when used in certain contexts, is automatically converted to $memory. The contexts are: arguments to the built-in functions $access, $read, and $write described below, or occurrence in the list of an $assigns clause
  • a[dom], where a is an expression of array type and dom is an expression of $domain type. The dimension of the array must match the dimension of the domain. This represents all memory units which are the cells in the array indexed by a tuple in dom.
  • $region(ptr), where ptr is an expression with a pointer type. This represents the set of all memory units reachable from ptr, including the memory unit pointed to by ptr itself.

* `mem1+mem2`, where `mem1` and `mem2` are expressions of type `$memory`. This is the union of the two sets. Problem this is ambiguous with numeric +, as in x+y.

$assigns clause

As in other contract specification language, this contract clause is used to specify a set of existing memory units. The claim is that if an existing memory unit is not in the set, it will not be modified in the course of the function call. The syntax is:

$assigns {<memory-list>}

where <memory-list> is a comma-separated list of expressions of type $memory.

Example:

$assigns x,a[i][j],$region(list->head),b[dom];

$depends clause

This contractual clause specifies part of the dependence relation used in POR.

$depends {e}

where e is an expression of boolean type. For each process p, the e can be evaluated in the context of p. If e evaluates to true, then p must be included in an ample set containing a call to this function.

The expression e hence defines a predicate d(s,p), where s ranges over states, and p over procs. The requirement is the following:

Let s be any state and p a proc such that a function call for this function is enabled in p. Then in any execution departing from s, no transition dependent on the execution of this function call can occur without a transition from p or a proc q satisfying d(s,q) occurring first.

The following built-in functions may be used as constituents in the boolean expression e:

  • _Bool $access(<memory-list>)
    • holds if any memory unit in the list may be read or modified by p at some point now or in the future.
  • _Bool $write(<memory-list>)
    • holds if any memory unit in the list may be modified by p at some point now or in the future.
  • _Bool $read(<memory-list>)
    • holds if any memory unit in the list may be read by p at some point now or in the future.

Default: if there is no $depends clause present, the dependency information will be obtained from Java code in the library enabler. If the library enabler does not specify anything for this function, the default rules will be used, which are sound:

  • if the body of the function is not provided, i.e., the function is a system function, the verifier will assume that execution of the function may read and/or modify any memory unit that it can reach, and decide on the partial order reduction appropriately, else
  • if the body of the function is present, the statements comprising the body may be analyzed to further restrict the reduction.

Ample set and the exact interpretation of $depends

Fix a statement S and a process q.

Let T(S,q) denote the set of transitions specified by having q execute S. We say this is a set because some statements S are nondeterministic, meaning they can generate multiple transitions. Note that T(S,q) is independent of the state. In particular, it must include all possible transitions that could be generated by S, even if not all of them are enabled in every state.

Now fix a state s and assume that the origin of S is the location of q in s.

Suppose A(s,S,q) is a set of procs which satisfies the following:

In any execution departing from s, no transition dependent on a transition in T(S,q) can occur without a transition from a proc in A(s,S,q) occurring first.

Then define AMPLE as follows:

Function AMPLE(s:State, p:proc) : set of proc is
  let AmpleProcs = {p};
  let WorkSet = {p};
  // invariant: WorkSet is a subset of AmpleProcs
  while (WorkSet not empty) {
    choose q in WorkSet;
    WorkSet := WorkSet - {q};
    forall statements S with origin the location of q in s:
      foreach r in A(s,S,q): if r is not in AmpleProcs, add r to AmpleProcs and to WorkSet
    end forall;
  }
  return AmpleProcs;
end Function AMPLE

Note: AMPLE(s,p) is the smallest set containing p and satisfying:

if q is in AMPLE(s,p) then for all statements S with origin the location of q in s, A(s,S,q) is a subset of AMPLE(s,p).

Claim: for any process p, if AMPLE(s,p) contains a process with at least one enabled transition in s, then it defines an ample set, i.e., from any execution departing from s, no transition dependent on a transition from a proc in AMPLE(s,p) can occur without a transition from a proc in AMPLE(s,p) occurring first.

Proof of Claim

Let AMPLE=AMPLE(s,p).

Let

(E) t_1, t_2, ..., t_n, t

be any execution prefix starting from s for which t is dependent on a transition from a proc in AMPLE.

ASSUME that none of the t_i are from procs in AMPLE. We aim to get a contradiction.

Say t is dependent on transition t0 in T(S0,q0), for some statement S0 and process q0 in AMPLE.

By assumption, throughout the entire execution prefix (E), q0 remains at the location it had in state s. In particular, the origin of S0 is the location of q0 in s.

Since q0 is in AMPLE, it follows from the algorithm that defines AMPLE that A(s,S0,q0) is a subset of AMPLE.

From the contract defining A, we know that no transition dependent on a transition in T(S0,q0) can occur without a transition from a proc in A(s,S0,q0) occurring first. Hence for some i, t_i is from a proc in A(s,S0,q0), and therefore t_i is in AMPLE, contradicting the ASSUMPTION. QED.

Use of $depends

In the case where S is a function call, the $depends clause in the function contract specifies the set A(s,S,p) as follows: first the depends clause specifies a predicate d(s,q) where s is a state and q is a proc. Then

A(s,S,p) = {p} U {q|d(s,q)}

Function specifiers

Both $atomic and $atom may be used as function specifiers. They designate that any call to the function is to be treated atomically or atom-ly, respectively.

Guards

The following construct is used to specify a guard for a function. The function may be a system or ordinary function. It maybe used in conjunction with $atom or $atomic. Grammatically, it is a contract clause, though it is not really part of the contract.

$guard {bool-expr}

If missing, the default is to go the library enabler for the guard. If the library enabler does not specify a guard, it defaults to $true.

Examples

  • The following means that any process that can reach the memory unit of comm should be in the ample set if the current process ($self) is to be chosen in the ample set.
    void comm_dequeue($comm comm, ....)
      $depends {$access(*comm)}
    ;
    
Note: See TracWiki for help on using the wiki.