| | 2 | |
| | 3 | |
| | 4 | == `$memory` type == |
| | 5 | |
| | 6 | The new built-in type `$memory` denotes a set of memory units. The following expressions have type `$memory`: |
| | 7 | * 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 |
| | 8 | * `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`. |
| | 9 | * `$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. |
| | 10 | |
| | 11 | [[* `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. |
| | 12 | |
| | 13 | == `$assigns` clause == |
| | 14 | |
| | 15 | 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: |
| | 16 | {{{ |
| | 17 | $assigns <memory-list>; |
| | 18 | }}} |
| | 19 | where `<memory-list>` is a comma-separated list of expressions of type `$memory`. |
| | 20 | |
| | 21 | Example: |
| | 22 | {{{ |
| | 23 | $assigns x,a[i][j],$region(list->head),b[dom]; |
| | 24 | }}} |
| | 25 | |
| 13 | | * `$reaches(void * obj)` |
| 14 | | * holds iff the memory unit pointed to by `obj` is reachable from `p`. This means there is a path from the variables on the call stack of `p` to the memory unit, following array elements, struct members, and pointer dereferences, pointer arithmetic. |
| 15 | | * `$reachesRegion(void * obj)` |
| 16 | | * holds iff any of the memory units reachable from `obj` (including the object pointed to by `obj` itself) is reachable from`p` |
| 17 | | * `$writes(void * obj)` |
| 18 | | * holds iff the memory unit pointed to by `obj` is not only reachable from `p` but if it is possible that `p` (or a process spawned by `p`) could write to that memory unit at some point now or in the future. |
| 19 | | * `$writesRegion(void * obj)` |
| 20 | | * like above but true if any of the memory units in the reachable region specified by `obj` may be written to |
| | 37 | * `_Bool $access($memory mem)` |
| | 38 | * holds if any memory unit in `mem` may be read or modified by `p` at some point now or in the future. |
| | 39 | * `_Bool $write($memory mem)` |
| | 40 | * holds if any memory unit in `mem` may be modified by `p` at some point now or in the future. |
| | 41 | * `_Bool $read($memory mem)` |
| | 42 | * holds if any memory unit in `mem` may be read by `p` at some point now or in the future. |
| 30 | | == `$assigns` clause == |
| 31 | | |
| 32 | | As in other contract specification language, this 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. |
| 33 | | |
| 34 | | The argument following the `$assigns` token is a comma-separated list. The elements of the list may be left-hand-side expressions, or an expression of the form |
| 35 | | {{{ |
| 36 | | $region(ptr) |
| 37 | | }}} |
| 38 | | where `ptr` is expression which has a pointer type. It denotes the set of all memory units reachable from that pointer, beginning with and including the memory unit pointer to by `ptr`. |
| 39 | | Example: |
| 40 | | {{{ |
| 41 | | $assigns x,a[i][j],$region(list->head); |
| 42 | | }}} |
| 43 | | |
| 54 | | |
| 55 | | - The following means that any process that can reach any of the memory units reachable from `a` or write any of the memory units reachable from `a` now or in the future should be in the ample set if the current process (`$self`) is to be chosen in the ample set. |
| 56 | | {{{ |
| 57 | | void strcpy(char *a, char *b) |
| 58 | | $depend $accessRegion(a) || $writeRegion(b); |
| 59 | | ; |
| 60 | | }}} |
| 61 | | |
| 62 | | - The following means that the current process itself can form the ample set. |
| 63 | | {{{ |
| 64 | | int $comm_size($comm, ...) |
| 65 | | $depend $false; |
| 66 | | ; |
| 67 | | }}} |
| 68 | | |
| 69 | | - The following means that if the argument `count` is equal to zero, then the current process forms the ample set, otherwise, any process that can reach the memory unit of object `comm` should be in the ample set. |
| 70 | | {{{ |
| 71 | | void comm_deque($comm comm, int count ....) |
| 72 | | $depend count==0 ? $false : $access(comm); |
| 73 | | ; |
| 74 | | }}} |